1 /* $NetBSD: cd9660_node.c,v 1.34 2014/11/10 18:46:33 maxv Exp $ */
4 * Copyright (c) 1982, 1986, 1989, 1994
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley
8 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
9 * Support code is derived from software contributed to Berkeley
10 * by Atsushi Murai (amurai@spec.co.jp).
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)cd9660_node.c 8.8 (Berkeley) 5/22/95
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: cd9660_node.c,v 1.34 2014/11/10 18:46:33 maxv Exp $");
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/mount.h>
48 #include <sys/vnode.h>
49 #include <sys/namei.h>
50 #include <sys/kernel.h>
54 #include <fs/cd9660/iso.h>
55 #include <fs/cd9660/cd9660_extern.h>
56 #include <fs/cd9660/cd9660_node.h>
57 #include <fs/cd9660/cd9660_mount.h>
58 #include <fs/cd9660/iso_rrip.h>
60 extern int prtactive
; /* 1 => print out reclaim of active vnodes */
62 struct pool cd9660_node_pool
;
64 static u_int
cd9660_chars2ui(const u_char
*, int);
67 * Initialize pool for nodes.
73 malloc_type_attach(M_ISOFSMNT
);
74 pool_init(&cd9660_node_pool
, sizeof(struct iso_node
), 0, 0, 0,
75 "cd9660nopl", &pool_allocator_nointr
, IPL_NONE
);
94 pool_destroy(&cd9660_node_pool
);
95 malloc_type_detach(M_ISOFSMNT
);
99 * Last reference to an inode, write the inode out and if necessary,
100 * truncate and deallocate the file.
103 cd9660_inactive(void *v
)
105 struct vop_inactive_args
/* {
109 struct vnode
*vp
= ap
->a_vp
;
110 struct iso_node
*ip
= VTOI(vp
);
114 * If we are done with the inode, reclaim it
115 * so that it can be reused immediately.
118 *ap
->a_recycle
= (ip
->inode
.iso_mode
== 0);
124 * Reclaim an inode so that it can be used for other purposes.
127 cd9660_reclaim(void *v
)
129 struct vop_reclaim_args
/* {
133 struct vnode
*vp
= ap
->a_vp
;
134 struct iso_node
*ip
= VTOI(vp
);
136 if (prtactive
&& vp
->v_usecount
> 1)
137 vprint("cd9660_reclaim: pushing active", vp
);
139 * Remove the inode from the vnode cache.
141 vcache_remove(vp
->v_mount
, &ip
->i_number
, sizeof(ip
->i_number
));
143 * Purge old data structures associated with the inode.
145 genfs_node_destroy(vp
);
146 pool_put(&cd9660_node_pool
, vp
->v_data
);
155 cd9660_defattr(struct iso_directory_record
*isodir
, struct iso_node
*inop
,
158 struct buf
*bp2
= NULL
;
160 struct iso_extended_attributes
*ap
= NULL
;
163 if (isonum_711(isodir
->flags
)&2) {
164 inop
->inode
.iso_mode
= S_IFDIR
;
166 * If we return 2, fts() will assume there are no subdirectories
167 * (just links for the path and .), so instead we return 1.
169 inop
->inode
.iso_links
= 1;
171 inop
->inode
.iso_mode
= S_IFREG
;
172 inop
->inode
.iso_links
= 1;
175 && ((imp
= inop
->i_mnt
)->im_flags
& ISOFSMNT_EXTATT
)
176 && (off
= isonum_711(isodir
->ext_attr_length
))) {
177 cd9660_blkatoff(ITOV(inop
), (off_t
)-(off
<< imp
->im_bshift
),
182 ap
= (struct iso_extended_attributes
*)bp
->b_data
;
184 if (isonum_711(ap
->version
) == 1) {
185 if (!(ap
->perm
[1]&0x10))
186 inop
->inode
.iso_mode
|= S_IRUSR
;
187 if (!(ap
->perm
[1]&0x40))
188 inop
->inode
.iso_mode
|= S_IXUSR
;
189 if (!(ap
->perm
[0]&0x01))
190 inop
->inode
.iso_mode
|= S_IRGRP
;
191 if (!(ap
->perm
[0]&0x04))
192 inop
->inode
.iso_mode
|= S_IXGRP
;
193 if (!(ap
->perm
[0]&0x10))
194 inop
->inode
.iso_mode
|= S_IROTH
;
195 if (!(ap
->perm
[0]&0x40))
196 inop
->inode
.iso_mode
|= S_IXOTH
;
197 inop
->inode
.iso_uid
= isonum_723(ap
->owner
); /* what about 0? */
198 inop
->inode
.iso_gid
= isonum_723(ap
->group
); /* what about 0? */
203 inop
->inode
.iso_mode
|=
204 S_IRUSR
|S_IXUSR
|S_IRGRP
|S_IXGRP
|S_IROTH
|S_IXOTH
;
205 inop
->inode
.iso_uid
= (uid_t
)0;
206 inop
->inode
.iso_gid
= (gid_t
)0;
216 cd9660_deftstamp(struct iso_directory_record
*isodir
, struct iso_node
*inop
,
219 struct buf
*bp2
= NULL
;
221 struct iso_extended_attributes
*ap
= NULL
;
225 && ((imp
= inop
->i_mnt
)->im_flags
& ISOFSMNT_EXTATT
)
226 && (off
= isonum_711(isodir
->ext_attr_length
))) {
227 cd9660_blkatoff(ITOV(inop
), (off_t
)-(off
<< imp
->im_bshift
),
232 ap
= (struct iso_extended_attributes
*)bp
->b_data
;
234 if (isonum_711(ap
->version
) == 1) {
235 if (!cd9660_tstamp_conv17(ap
->ftime
,&inop
->inode
.iso_atime
))
236 cd9660_tstamp_conv17(ap
->ctime
,&inop
->inode
.iso_atime
);
237 if (!cd9660_tstamp_conv17(ap
->ctime
,&inop
->inode
.iso_ctime
))
238 inop
->inode
.iso_ctime
= inop
->inode
.iso_atime
;
239 if (!cd9660_tstamp_conv17(ap
->mtime
,&inop
->inode
.iso_mtime
))
240 inop
->inode
.iso_mtime
= inop
->inode
.iso_ctime
;
245 cd9660_tstamp_conv7(isodir
->date
,&inop
->inode
.iso_ctime
);
246 inop
->inode
.iso_atime
= inop
->inode
.iso_ctime
;
247 inop
->inode
.iso_mtime
= inop
->inode
.iso_ctime
;
254 cd9660_tstamp_conv7(const u_char
*pi
, struct timespec
*pu
)
257 int y
, m
, d
, hour
, minute
, second
, tz
;
273 /* computes day number relative to Sept. 19th,1989 */
274 /* don't even *THINK* about changing formula. It works! */
275 days
= 367*(y
-1980)-7*(y
+(m
+9)/12)/4-3*((y
+(m
-9)/7)/100+1)/4+275*m
/9+d
-100;
278 * Changed :-) to make it relative to Jan. 1st, 1970
279 * and to disambiguate negative division
281 days
= 367*(y
-1960)-7*(y
+(m
+9)/12)/4-3*((y
+(m
+9)/12-1)/100+1)/4+275*m
/9+d
-239;
283 crtime
= ((((days
* 24) + hour
) * 60 + minute
) * 60) + second
;
285 /* timezone offset is unreliable on some disks */
286 if (-48 <= tz
&& tz
<= 52)
287 crtime
-= tz
* 15 * 60;
295 cd9660_chars2ui(const u_char
*begin
, int len
)
299 for (rc
= 0; --len
>= 0;) {
301 rc
+= *begin
++ - '0';
307 cd9660_tstamp_conv17(const u_char
*pi
, struct timespec
*pu
)
311 /* year:"0001"-"9999" -> -1900 */
312 tbuf
[0] = cd9660_chars2ui(pi
,4) - 1900;
314 /* month: " 1"-"12" -> 1 - 12 */
315 tbuf
[1] = cd9660_chars2ui(pi
+ 4,2);
317 /* day: " 1"-"31" -> 1 - 31 */
318 tbuf
[2] = cd9660_chars2ui(pi
+ 6,2);
320 /* hour: " 0"-"23" -> 0 - 23 */
321 tbuf
[3] = cd9660_chars2ui(pi
+ 8,2);
323 /* minute:" 0"-"59" -> 0 - 59 */
324 tbuf
[4] = cd9660_chars2ui(pi
+ 10,2);
326 /* second:" 0"-"59" -> 0 - 59 */
327 tbuf
[5] = cd9660_chars2ui(pi
+ 12,2);
329 /* difference of GMT */
332 return cd9660_tstamp_conv7(tbuf
,pu
);
336 isodirino(struct iso_directory_record
*isodir
, struct iso_mnt
*imp
)
341 * Note there is an inverse calculation in
342 * cd9660_vfsops.c:cd9660_loadvnode():
343 * ip->iso_start = ino >> imp->im_bshift;
344 * and also a calculation of the isodir pointer
345 * from an inode in cd9660_vnops.c:cd9660_readlink()
347 ino
= ((ino_t
)isonum_733(isodir
->extent
) +
348 isonum_711(isodir
->ext_attr_length
)) << imp
->im_bshift
;