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
|
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}
|