Deleted Added
full compact
cd9660_node.c (50477) cd9660_node.c (60041)
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1994, 1995
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley
6 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
7 * Support code is derived from software contributed to Berkeley
8 * by Atsushi Murai (amurai@spec.co.jp).
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)cd9660_node.c 8.2 (Berkeley) 1/23/94
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1994, 1995
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley
6 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
7 * Support code is derived from software contributed to Berkeley
8 * by Atsushi Murai (amurai@spec.co.jp).
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)cd9660_node.c 8.2 (Berkeley) 1/23/94
39 * $FreeBSD: head/sys/fs/cd9660/cd9660_node.c 50477 1999-08-28 01:08:13Z peter $
39 * $FreeBSD: head/sys/fs/cd9660/cd9660_node.c 60041 2000-05-05 09:59:14Z phk $
40 */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/mount.h>
45#include <sys/proc.h>
40 */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/mount.h>
45#include <sys/proc.h>
46#include <sys/bio.h>
46#include <sys/buf.h>
47#include <sys/vnode.h>
48#include <sys/malloc.h>
49#include <sys/stat.h>
50
51#include <isofs/cd9660/iso.h>
52#include <isofs/cd9660/cd9660_node.h>
53#include <isofs/cd9660/cd9660_mount.h>
54
55/*
56 * Structures associated with iso_node caching.
57 */
58static struct iso_node **isohashtbl;
59static u_long isohash;
60#define INOHASH(device, inum) ((minor(device) + ((inum)>>12)) & isohash)
61#ifndef NULL_SIMPLELOCKS
62static struct simplelock cd9660_ihash_slock;
63#endif
64
65static void cd9660_ihashrem __P((struct iso_node *));
66static unsigned cd9660_chars2ui __P((unsigned char *begin, int len));
67
68/*
69 * Initialize hash links for inodes and dnodes.
70 */
71int
72cd9660_init(vfsp)
73 struct vfsconf *vfsp;
74{
75
76 isohashtbl = hashinit(desiredvnodes, M_ISOFSMNT, &isohash);
77 simple_lock_init(&cd9660_ihash_slock);
78 return (0);
79}
80
81
82/*
83 * Use the device/inum pair to find the incore inode, and return a pointer
84 * to it. If it is in core, but locked, wait for it.
85 */
86struct vnode *
87cd9660_ihashget(dev, inum)
88 dev_t dev;
89 ino_t inum;
90{
91 struct proc *p = curproc; /* XXX */
92 struct iso_node *ip;
93 struct vnode *vp;
94
95loop:
96 simple_lock(&cd9660_ihash_slock);
97 for (ip = isohashtbl[INOHASH(dev, inum)]; ip; ip = ip->i_next) {
98 if (inum == ip->i_number && dev == ip->i_dev) {
99 vp = ITOV(ip);
100 simple_lock(&vp->v_interlock);
101 simple_unlock(&cd9660_ihash_slock);
102 if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, p))
103 goto loop;
104 return (vp);
105 }
106 }
107 simple_unlock(&cd9660_ihash_slock);
108 return (NULL);
109}
110
111/*
112 * Insert the inode into the hash table, and return it locked.
113 */
114void
115cd9660_ihashins(ip)
116 struct iso_node *ip;
117{
118 struct proc *p = curproc; /* XXX */
119 struct iso_node **ipp, *iq;
120
121 simple_lock(&cd9660_ihash_slock);
122 ipp = &isohashtbl[INOHASH(ip->i_dev, ip->i_number)];
123 if ((iq = *ipp) != NULL)
124 iq->i_prev = &ip->i_next;
125 ip->i_next = iq;
126 ip->i_prev = ipp;
127 *ipp = ip;
128 simple_unlock(&cd9660_ihash_slock);
129
130 lockmgr(&ip->i_lock, LK_EXCLUSIVE, (struct simplelock *)0, p);
131}
132
133/*
134 * Remove the inode from the hash table.
135 */
136static void
137cd9660_ihashrem(ip)
138 register struct iso_node *ip;
139{
140 register struct iso_node *iq;
141
142 simple_lock(&cd9660_ihash_slock);
143 if ((iq = ip->i_next) != NULL)
144 iq->i_prev = ip->i_prev;
145 *ip->i_prev = iq;
146#ifdef DIAGNOSTIC
147 ip->i_next = NULL;
148 ip->i_prev = NULL;
149#endif
150 simple_unlock(&cd9660_ihash_slock);
151}
152
153/*
154 * Last reference to an inode, write the inode out and if necessary,
155 * truncate and deallocate the file.
156 */
157int
158cd9660_inactive(ap)
159 struct vop_inactive_args /* {
160 struct vnode *a_vp;
161 struct proc *a_p;
162 } */ *ap;
163{
164 struct vnode *vp = ap->a_vp;
165 struct proc *p = ap->a_p;
166 register struct iso_node *ip = VTOI(vp);
167 int error = 0;
168
169 if (prtactive && vp->v_usecount != 0)
170 vprint("cd9660_inactive: pushing active", vp);
171
172 ip->i_flag = 0;
173 VOP_UNLOCK(vp, 0, p);
174 /*
175 * If we are done with the inode, reclaim it
176 * so that it can be reused immediately.
177 */
178 if (ip->inode.iso_mode == 0)
179 vrecycle(vp, (struct simplelock *)0, p);
180 return error;
181}
182
183/*
184 * Reclaim an inode so that it can be used for other purposes.
185 */
186int
187cd9660_reclaim(ap)
188 struct vop_reclaim_args /* {
189 struct vnode *a_vp;
190 struct proc *a_p;
191 } */ *ap;
192{
193 register struct vnode *vp = ap->a_vp;
194 register struct iso_node *ip = VTOI(vp);
195
196 if (prtactive && vp->v_usecount != 0)
197 vprint("cd9660_reclaim: pushing active", vp);
198 /*
199 * Remove the inode from its hash chain.
200 */
201 cd9660_ihashrem(ip);
202 /*
203 * Purge old data structures associated with the inode.
204 */
205 cache_purge(vp);
206 if (ip->i_devvp) {
207 vrele(ip->i_devvp);
208 ip->i_devvp = 0;
209 }
210 FREE(vp->v_data, M_ISOFSNODE);
211 vp->v_data = NULL;
212 return (0);
213}
214
215/*
216 * File attributes
217 */
218void
219cd9660_defattr(isodir, inop, bp, ftype)
220 struct iso_directory_record *isodir;
221 struct iso_node *inop;
222 struct buf *bp;
223 enum ISO_FTYPE ftype;
224{
225 struct buf *bp2 = NULL;
226 struct iso_mnt *imp;
227 struct iso_extended_attributes *ap = NULL;
228 int off;
229
230 /* high sierra does not have timezone data, flag is one byte ahead */
231 if (isonum_711(ftype == ISO_FTYPE_HIGH_SIERRA?
232 &isodir->date[6]: isodir->flags)&2) {
233 inop->inode.iso_mode = S_IFDIR;
234 /*
235 * If we return 2, fts() will assume there are no subdirectories
236 * (just links for the path and .), so instead we return 1.
237 */
238 inop->inode.iso_links = 1;
239 } else {
240 inop->inode.iso_mode = S_IFREG;
241 inop->inode.iso_links = 1;
242 }
243 if (!bp
244 && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
245 && (off = isonum_711(isodir->ext_attr_length))) {
246 cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift), NULL,
247 &bp2);
248 bp = bp2;
249 }
250 if (bp) {
251 ap = (struct iso_extended_attributes *)bp->b_data;
252
253 if (isonum_711(ap->version) == 1) {
254 if (!(ap->perm[0]&0x40))
255 inop->inode.iso_mode |= VEXEC >> 6;
256 if (!(ap->perm[0]&0x10))
257 inop->inode.iso_mode |= VREAD >> 6;
258 if (!(ap->perm[0]&4))
259 inop->inode.iso_mode |= VEXEC >> 3;
260 if (!(ap->perm[0]&1))
261 inop->inode.iso_mode |= VREAD >> 3;
262 if (!(ap->perm[1]&0x40))
263 inop->inode.iso_mode |= VEXEC;
264 if (!(ap->perm[1]&0x10))
265 inop->inode.iso_mode |= VREAD;
266 inop->inode.iso_uid = isonum_723(ap->owner); /* what about 0? */
267 inop->inode.iso_gid = isonum_723(ap->group); /* what about 0? */
268 } else
269 ap = NULL;
270 }
271 if (!ap) {
272 inop->inode.iso_mode |= VREAD|VEXEC|(VREAD|VEXEC)>>3|(VREAD|VEXEC)>>6;
273 inop->inode.iso_uid = (uid_t)0;
274 inop->inode.iso_gid = (gid_t)0;
275 }
276 if (bp2)
277 brelse(bp2);
278}
279
280/*
281 * Time stamps
282 */
283void
284cd9660_deftstamp(isodir,inop,bp,ftype)
285 struct iso_directory_record *isodir;
286 struct iso_node *inop;
287 struct buf *bp;
288 enum ISO_FTYPE ftype;
289{
290 struct buf *bp2 = NULL;
291 struct iso_mnt *imp;
292 struct iso_extended_attributes *ap = NULL;
293 int off;
294
295 if (!bp
296 && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
297 && (off = isonum_711(isodir->ext_attr_length))) {
298 cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift), NULL,
299 &bp2);
300 bp = bp2;
301 }
302 if (bp) {
303 ap = (struct iso_extended_attributes *)bp->b_data;
304
305 if (ftype != ISO_FTYPE_HIGH_SIERRA
306 && isonum_711(ap->version) == 1) {
307 if (!cd9660_tstamp_conv17(ap->ftime,&inop->inode.iso_atime))
308 cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_atime);
309 if (!cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_ctime))
310 inop->inode.iso_ctime = inop->inode.iso_atime;
311 if (!cd9660_tstamp_conv17(ap->mtime,&inop->inode.iso_mtime))
312 inop->inode.iso_mtime = inop->inode.iso_ctime;
313 } else
314 ap = NULL;
315 }
316 if (!ap) {
317 cd9660_tstamp_conv7(isodir->date,&inop->inode.iso_ctime,ftype);
318 inop->inode.iso_atime = inop->inode.iso_ctime;
319 inop->inode.iso_mtime = inop->inode.iso_ctime;
320 }
321 if (bp2)
322 brelse(bp2);
323}
324
325int
326cd9660_tstamp_conv7(pi,pu,ftype)
327 u_char *pi;
328 struct timespec *pu;
329 enum ISO_FTYPE ftype;
330{
331 int crtime, days;
332 int y, m, d, hour, minute, second, tz;
333
334 y = pi[0] + 1900;
335 m = pi[1];
336 d = pi[2];
337 hour = pi[3];
338 minute = pi[4];
339 second = pi[5];
340 if(ftype != ISO_FTYPE_HIGH_SIERRA)
341 tz = pi[6];
342 else
343 /* original high sierra misses timezone data */
344 tz = 0;
345
346 if (y < 1970) {
347 pu->tv_sec = 0;
348 pu->tv_nsec = 0;
349 return 0;
350 } else {
351#ifdef ORIGINAL
352 /* computes day number relative to Sept. 19th,1989 */
353 /* don't even *THINK* about changing formula. It works! */
354 days = 367*(y-1980)-7*(y+(m+9)/12)/4-3*((y+(m-9)/7)/100+1)/4+275*m/9+d-100;
355#else
356 /*
357 * Changed :-) to make it relative to Jan. 1st, 1970
358 * and to disambiguate negative division
359 */
360 days = 367*(y-1960)-7*(y+(m+9)/12)/4-3*((y+(m+9)/12-1)/100+1)/4+275*m/9+d-239;
361#endif
362 crtime = ((((days * 24) + hour) * 60 + minute) * 60) + second;
363
364 /* timezone offset is unreliable on some disks */
365 if (-48 <= tz && tz <= 52)
366 crtime -= tz * 15 * 60;
367 }
368 pu->tv_sec = crtime;
369 pu->tv_nsec = 0;
370 return 1;
371}
372
373static u_int
374cd9660_chars2ui(begin,len)
375 u_char *begin;
376 int len;
377{
378 u_int rc;
379
380 for (rc = 0; --len >= 0;) {
381 rc *= 10;
382 rc += *begin++ - '0';
383 }
384 return rc;
385}
386
387int
388cd9660_tstamp_conv17(pi,pu)
389 u_char *pi;
390 struct timespec *pu;
391{
392 u_char buf[7];
393
394 /* year:"0001"-"9999" -> -1900 */
395 buf[0] = cd9660_chars2ui(pi,4) - 1900;
396
397 /* month: " 1"-"12" -> 1 - 12 */
398 buf[1] = cd9660_chars2ui(pi + 4,2);
399
400 /* day: " 1"-"31" -> 1 - 31 */
401 buf[2] = cd9660_chars2ui(pi + 6,2);
402
403 /* hour: " 0"-"23" -> 0 - 23 */
404 buf[3] = cd9660_chars2ui(pi + 8,2);
405
406 /* minute:" 0"-"59" -> 0 - 59 */
407 buf[4] = cd9660_chars2ui(pi + 10,2);
408
409 /* second:" 0"-"59" -> 0 - 59 */
410 buf[5] = cd9660_chars2ui(pi + 12,2);
411
412 /* difference of GMT */
413 buf[6] = pi[16];
414
415 return cd9660_tstamp_conv7(buf, pu, ISO_FTYPE_DEFAULT);
416}
417
418ino_t
419isodirino(isodir, imp)
420 struct iso_directory_record *isodir;
421 struct iso_mnt *imp;
422{
423 ino_t ino;
424
425 ino = (isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length))
426 << imp->im_bshift;
427 return (ino);
428}
47#include <sys/buf.h>
48#include <sys/vnode.h>
49#include <sys/malloc.h>
50#include <sys/stat.h>
51
52#include <isofs/cd9660/iso.h>
53#include <isofs/cd9660/cd9660_node.h>
54#include <isofs/cd9660/cd9660_mount.h>
55
56/*
57 * Structures associated with iso_node caching.
58 */
59static struct iso_node **isohashtbl;
60static u_long isohash;
61#define INOHASH(device, inum) ((minor(device) + ((inum)>>12)) & isohash)
62#ifndef NULL_SIMPLELOCKS
63static struct simplelock cd9660_ihash_slock;
64#endif
65
66static void cd9660_ihashrem __P((struct iso_node *));
67static unsigned cd9660_chars2ui __P((unsigned char *begin, int len));
68
69/*
70 * Initialize hash links for inodes and dnodes.
71 */
72int
73cd9660_init(vfsp)
74 struct vfsconf *vfsp;
75{
76
77 isohashtbl = hashinit(desiredvnodes, M_ISOFSMNT, &isohash);
78 simple_lock_init(&cd9660_ihash_slock);
79 return (0);
80}
81
82
83/*
84 * Use the device/inum pair to find the incore inode, and return a pointer
85 * to it. If it is in core, but locked, wait for it.
86 */
87struct vnode *
88cd9660_ihashget(dev, inum)
89 dev_t dev;
90 ino_t inum;
91{
92 struct proc *p = curproc; /* XXX */
93 struct iso_node *ip;
94 struct vnode *vp;
95
96loop:
97 simple_lock(&cd9660_ihash_slock);
98 for (ip = isohashtbl[INOHASH(dev, inum)]; ip; ip = ip->i_next) {
99 if (inum == ip->i_number && dev == ip->i_dev) {
100 vp = ITOV(ip);
101 simple_lock(&vp->v_interlock);
102 simple_unlock(&cd9660_ihash_slock);
103 if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, p))
104 goto loop;
105 return (vp);
106 }
107 }
108 simple_unlock(&cd9660_ihash_slock);
109 return (NULL);
110}
111
112/*
113 * Insert the inode into the hash table, and return it locked.
114 */
115void
116cd9660_ihashins(ip)
117 struct iso_node *ip;
118{
119 struct proc *p = curproc; /* XXX */
120 struct iso_node **ipp, *iq;
121
122 simple_lock(&cd9660_ihash_slock);
123 ipp = &isohashtbl[INOHASH(ip->i_dev, ip->i_number)];
124 if ((iq = *ipp) != NULL)
125 iq->i_prev = &ip->i_next;
126 ip->i_next = iq;
127 ip->i_prev = ipp;
128 *ipp = ip;
129 simple_unlock(&cd9660_ihash_slock);
130
131 lockmgr(&ip->i_lock, LK_EXCLUSIVE, (struct simplelock *)0, p);
132}
133
134/*
135 * Remove the inode from the hash table.
136 */
137static void
138cd9660_ihashrem(ip)
139 register struct iso_node *ip;
140{
141 register struct iso_node *iq;
142
143 simple_lock(&cd9660_ihash_slock);
144 if ((iq = ip->i_next) != NULL)
145 iq->i_prev = ip->i_prev;
146 *ip->i_prev = iq;
147#ifdef DIAGNOSTIC
148 ip->i_next = NULL;
149 ip->i_prev = NULL;
150#endif
151 simple_unlock(&cd9660_ihash_slock);
152}
153
154/*
155 * Last reference to an inode, write the inode out and if necessary,
156 * truncate and deallocate the file.
157 */
158int
159cd9660_inactive(ap)
160 struct vop_inactive_args /* {
161 struct vnode *a_vp;
162 struct proc *a_p;
163 } */ *ap;
164{
165 struct vnode *vp = ap->a_vp;
166 struct proc *p = ap->a_p;
167 register struct iso_node *ip = VTOI(vp);
168 int error = 0;
169
170 if (prtactive && vp->v_usecount != 0)
171 vprint("cd9660_inactive: pushing active", vp);
172
173 ip->i_flag = 0;
174 VOP_UNLOCK(vp, 0, p);
175 /*
176 * If we are done with the inode, reclaim it
177 * so that it can be reused immediately.
178 */
179 if (ip->inode.iso_mode == 0)
180 vrecycle(vp, (struct simplelock *)0, p);
181 return error;
182}
183
184/*
185 * Reclaim an inode so that it can be used for other purposes.
186 */
187int
188cd9660_reclaim(ap)
189 struct vop_reclaim_args /* {
190 struct vnode *a_vp;
191 struct proc *a_p;
192 } */ *ap;
193{
194 register struct vnode *vp = ap->a_vp;
195 register struct iso_node *ip = VTOI(vp);
196
197 if (prtactive && vp->v_usecount != 0)
198 vprint("cd9660_reclaim: pushing active", vp);
199 /*
200 * Remove the inode from its hash chain.
201 */
202 cd9660_ihashrem(ip);
203 /*
204 * Purge old data structures associated with the inode.
205 */
206 cache_purge(vp);
207 if (ip->i_devvp) {
208 vrele(ip->i_devvp);
209 ip->i_devvp = 0;
210 }
211 FREE(vp->v_data, M_ISOFSNODE);
212 vp->v_data = NULL;
213 return (0);
214}
215
216/*
217 * File attributes
218 */
219void
220cd9660_defattr(isodir, inop, bp, ftype)
221 struct iso_directory_record *isodir;
222 struct iso_node *inop;
223 struct buf *bp;
224 enum ISO_FTYPE ftype;
225{
226 struct buf *bp2 = NULL;
227 struct iso_mnt *imp;
228 struct iso_extended_attributes *ap = NULL;
229 int off;
230
231 /* high sierra does not have timezone data, flag is one byte ahead */
232 if (isonum_711(ftype == ISO_FTYPE_HIGH_SIERRA?
233 &isodir->date[6]: isodir->flags)&2) {
234 inop->inode.iso_mode = S_IFDIR;
235 /*
236 * If we return 2, fts() will assume there are no subdirectories
237 * (just links for the path and .), so instead we return 1.
238 */
239 inop->inode.iso_links = 1;
240 } else {
241 inop->inode.iso_mode = S_IFREG;
242 inop->inode.iso_links = 1;
243 }
244 if (!bp
245 && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
246 && (off = isonum_711(isodir->ext_attr_length))) {
247 cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift), NULL,
248 &bp2);
249 bp = bp2;
250 }
251 if (bp) {
252 ap = (struct iso_extended_attributes *)bp->b_data;
253
254 if (isonum_711(ap->version) == 1) {
255 if (!(ap->perm[0]&0x40))
256 inop->inode.iso_mode |= VEXEC >> 6;
257 if (!(ap->perm[0]&0x10))
258 inop->inode.iso_mode |= VREAD >> 6;
259 if (!(ap->perm[0]&4))
260 inop->inode.iso_mode |= VEXEC >> 3;
261 if (!(ap->perm[0]&1))
262 inop->inode.iso_mode |= VREAD >> 3;
263 if (!(ap->perm[1]&0x40))
264 inop->inode.iso_mode |= VEXEC;
265 if (!(ap->perm[1]&0x10))
266 inop->inode.iso_mode |= VREAD;
267 inop->inode.iso_uid = isonum_723(ap->owner); /* what about 0? */
268 inop->inode.iso_gid = isonum_723(ap->group); /* what about 0? */
269 } else
270 ap = NULL;
271 }
272 if (!ap) {
273 inop->inode.iso_mode |= VREAD|VEXEC|(VREAD|VEXEC)>>3|(VREAD|VEXEC)>>6;
274 inop->inode.iso_uid = (uid_t)0;
275 inop->inode.iso_gid = (gid_t)0;
276 }
277 if (bp2)
278 brelse(bp2);
279}
280
281/*
282 * Time stamps
283 */
284void
285cd9660_deftstamp(isodir,inop,bp,ftype)
286 struct iso_directory_record *isodir;
287 struct iso_node *inop;
288 struct buf *bp;
289 enum ISO_FTYPE ftype;
290{
291 struct buf *bp2 = NULL;
292 struct iso_mnt *imp;
293 struct iso_extended_attributes *ap = NULL;
294 int off;
295
296 if (!bp
297 && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
298 && (off = isonum_711(isodir->ext_attr_length))) {
299 cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift), NULL,
300 &bp2);
301 bp = bp2;
302 }
303 if (bp) {
304 ap = (struct iso_extended_attributes *)bp->b_data;
305
306 if (ftype != ISO_FTYPE_HIGH_SIERRA
307 && isonum_711(ap->version) == 1) {
308 if (!cd9660_tstamp_conv17(ap->ftime,&inop->inode.iso_atime))
309 cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_atime);
310 if (!cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_ctime))
311 inop->inode.iso_ctime = inop->inode.iso_atime;
312 if (!cd9660_tstamp_conv17(ap->mtime,&inop->inode.iso_mtime))
313 inop->inode.iso_mtime = inop->inode.iso_ctime;
314 } else
315 ap = NULL;
316 }
317 if (!ap) {
318 cd9660_tstamp_conv7(isodir->date,&inop->inode.iso_ctime,ftype);
319 inop->inode.iso_atime = inop->inode.iso_ctime;
320 inop->inode.iso_mtime = inop->inode.iso_ctime;
321 }
322 if (bp2)
323 brelse(bp2);
324}
325
326int
327cd9660_tstamp_conv7(pi,pu,ftype)
328 u_char *pi;
329 struct timespec *pu;
330 enum ISO_FTYPE ftype;
331{
332 int crtime, days;
333 int y, m, d, hour, minute, second, tz;
334
335 y = pi[0] + 1900;
336 m = pi[1];
337 d = pi[2];
338 hour = pi[3];
339 minute = pi[4];
340 second = pi[5];
341 if(ftype != ISO_FTYPE_HIGH_SIERRA)
342 tz = pi[6];
343 else
344 /* original high sierra misses timezone data */
345 tz = 0;
346
347 if (y < 1970) {
348 pu->tv_sec = 0;
349 pu->tv_nsec = 0;
350 return 0;
351 } else {
352#ifdef ORIGINAL
353 /* computes day number relative to Sept. 19th,1989 */
354 /* don't even *THINK* about changing formula. It works! */
355 days = 367*(y-1980)-7*(y+(m+9)/12)/4-3*((y+(m-9)/7)/100+1)/4+275*m/9+d-100;
356#else
357 /*
358 * Changed :-) to make it relative to Jan. 1st, 1970
359 * and to disambiguate negative division
360 */
361 days = 367*(y-1960)-7*(y+(m+9)/12)/4-3*((y+(m+9)/12-1)/100+1)/4+275*m/9+d-239;
362#endif
363 crtime = ((((days * 24) + hour) * 60 + minute) * 60) + second;
364
365 /* timezone offset is unreliable on some disks */
366 if (-48 <= tz && tz <= 52)
367 crtime -= tz * 15 * 60;
368 }
369 pu->tv_sec = crtime;
370 pu->tv_nsec = 0;
371 return 1;
372}
373
374static u_int
375cd9660_chars2ui(begin,len)
376 u_char *begin;
377 int len;
378{
379 u_int rc;
380
381 for (rc = 0; --len >= 0;) {
382 rc *= 10;
383 rc += *begin++ - '0';
384 }
385 return rc;
386}
387
388int
389cd9660_tstamp_conv17(pi,pu)
390 u_char *pi;
391 struct timespec *pu;
392{
393 u_char buf[7];
394
395 /* year:"0001"-"9999" -> -1900 */
396 buf[0] = cd9660_chars2ui(pi,4) - 1900;
397
398 /* month: " 1"-"12" -> 1 - 12 */
399 buf[1] = cd9660_chars2ui(pi + 4,2);
400
401 /* day: " 1"-"31" -> 1 - 31 */
402 buf[2] = cd9660_chars2ui(pi + 6,2);
403
404 /* hour: " 0"-"23" -> 0 - 23 */
405 buf[3] = cd9660_chars2ui(pi + 8,2);
406
407 /* minute:" 0"-"59" -> 0 - 59 */
408 buf[4] = cd9660_chars2ui(pi + 10,2);
409
410 /* second:" 0"-"59" -> 0 - 59 */
411 buf[5] = cd9660_chars2ui(pi + 12,2);
412
413 /* difference of GMT */
414 buf[6] = pi[16];
415
416 return cd9660_tstamp_conv7(buf, pu, ISO_FTYPE_DEFAULT);
417}
418
419ino_t
420isodirino(isodir, imp)
421 struct iso_directory_record *isodir;
422 struct iso_mnt *imp;
423{
424 ino_t ino;
425
426 ino = (isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length))
427 << imp->im_bshift;
428 return (ino);
429}