|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: ! 25: /* $NetBSD: cd9660_util.c,v 1.8 1994/12/13 22:33:25 mycroft Exp $ */ ! 26: ! 27: /*- ! 28: * Copyright (c) 1994 ! 29: * The Regents of the University of California. All rights reserved. ! 30: * ! 31: * This code is derived from software contributed to Berkeley ! 32: * by Pace Willisson ([email protected]). The Rock Ridge Extension ! 33: * Support code is derived from software contributed to Berkeley ! 34: * by Atsushi Murai ([email protected]). ! 35: * ! 36: * Redistribution and use in source and binary forms, with or without ! 37: * modification, are permitted provided that the following conditions ! 38: * are met: ! 39: * 1. Redistributions of source code must retain the above copyright ! 40: * notice, this list of conditions and the following disclaimer. ! 41: * 2. Redistributions in binary form must reproduce the above copyright ! 42: * notice, this list of conditions and the following disclaimer in the ! 43: * documentation and/or other materials provided with the distribution. ! 44: * 3. All advertising materials mentioning features or use of this software ! 45: * must display the following acknowledgement: ! 46: * This product includes software developed by the University of ! 47: * California, Berkeley and its contributors. ! 48: * 4. Neither the name of the University nor the names of its contributors ! 49: * may be used to endorse or promote products derived from this software ! 50: * without specific prior written permission. ! 51: * ! 52: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ! 53: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! 54: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ! 55: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ! 56: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ! 57: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ! 58: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! 59: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ! 60: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 61: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 62: * SUCH DAMAGE. ! 63: * ! 64: * @(#)cd9660_util.c 8.3 (Berkeley) 12/5/94 ! 65: */ ! 66: ! 67: #include <sys/param.h> ! 68: #include <sys/systm.h> ! 69: #include <sys/namei.h> ! 70: #include <sys/resourcevar.h> ! 71: #include <sys/kernel.h> ! 72: #include <sys/file.h> ! 73: #include <sys/stat.h> ! 74: #include <sys/buf.h> ! 75: #include <sys/proc.h> ! 76: #include <sys/conf.h> ! 77: #include <sys/mount.h> ! 78: #include <sys/vnode.h> ! 79: #include <miscfs/specfs/specdev.h> /* XXX */ ! 80: #include <miscfs/fifofs/fifo.h> /* XXX */ ! 81: #include <sys/malloc.h> ! 82: #include <sys/dir.h> ! 83: #include <sys/attr.h> ! 84: ! 85: #include <isofs/cd9660/iso.h> ! 86: #include <isofs/cd9660/cd9660_node.h> ! 87: #include <isofs/cd9660/iso_rrip.h> ! 88: ! 89: /* ! 90: * translate and compare a filename ! 91: * Note: Version number plus ';' may be omitted. ! 92: */ ! 93: int ! 94: isofncmp(fn, fnlen, isofn, isolen) ! 95: u_char *fn, *isofn; ! 96: int fnlen, isolen; ! 97: { ! 98: int i, j; ! 99: char c; ! 100: ! 101: while (--fnlen >= 0) { ! 102: if (--isolen < 0) ! 103: return *fn; ! 104: if ((c = *isofn++) == ';') { ! 105: switch (*fn++) { ! 106: default: ! 107: return *--fn; ! 108: case 0: ! 109: return 0; ! 110: case ';': ! 111: break; ! 112: } ! 113: for (i = 0; --fnlen >= 0; i = i * 10 + *fn++ - '0') { ! 114: if (*fn < '0' || *fn > '9') { ! 115: return -1; ! 116: } ! 117: } ! 118: for (j = 0; --isolen >= 0; j = j * 10 + *isofn++ - '0'); ! 119: return i - j; ! 120: } ! 121: if (c != *fn) { ! 122: if (c >= 'A' && c <= 'Z') { ! 123: if (c + ('a' - 'A') != *fn) { ! 124: if (*fn >= 'a' && *fn <= 'z') ! 125: return *fn - ('a' - 'A') - c; ! 126: else ! 127: return *fn - c; ! 128: } ! 129: } else ! 130: return *fn - c; ! 131: } ! 132: fn++; ! 133: } ! 134: if (isolen > 0) { ! 135: switch (*isofn) { ! 136: default: ! 137: return -1; ! 138: case '.': ! 139: if (isofn[1] != ';') ! 140: return -1; ! 141: case ';': ! 142: return 0; ! 143: } ! 144: } ! 145: return 0; ! 146: } ! 147: ! 148: /* ! 149: * translate a filename ! 150: */ ! 151: void ! 152: isofntrans(infn, infnlen, outfn, outfnlen, original, assoc) ! 153: u_char *infn, *outfn; ! 154: int infnlen; ! 155: u_short *outfnlen; ! 156: int original; ! 157: int assoc; ! 158: { ! 159: int fnidx = 0; ! 160: ! 161: if (assoc) { ! 162: *outfn++ = ASSOCCHAR; ! 163: fnidx++; ! 164: infnlen++; ! 165: } ! 166: for (; fnidx < infnlen; fnidx++) { ! 167: char c = *infn++; ! 168: ! 169: if (!original && c >= 'A' && c <= 'Z') ! 170: *outfn++ = c + ('a' - 'A'); ! 171: else if (!original && c == '.' && *infn == ';') ! 172: break; ! 173: else if (!original && c == ';') ! 174: break; ! 175: else ! 176: *outfn++ = c; ! 177: } ! 178: *outfnlen = fnidx; ! 179: } ! 180: ! 181: ! 182: int ! 183: attrcalcsize(struct attrlist *attrlist) ! 184: { ! 185: int size; ! 186: attrgroup_t a; ! 187: ! 188: #if ((ATTR_CMN_NAME | ATTR_CMN_DEVID | ATTR_CMN_FSID | ATTR_CMN_OBJTYPE | \ ! 189: ATTR_CMN_OBJTAG | ATTR_CMN_OBJID | ATTR_CMN_OBJPERMANENTID | ATTR_CMN_PAROBJID | \ ! 190: ATTR_CMN_SCRIPT | ATTR_CMN_CRTIME | ATTR_CMN_MODTIME | ATTR_CMN_CHGTIME | \ ! 191: ATTR_CMN_ACCTIME | ATTR_CMN_BKUPTIME | ATTR_CMN_FNDRINFO | ATTR_CMN_OWNERID | \ ! 192: ATTR_CMN_GRPID | ATTR_CMN_ACCESSMASK | ATTR_CMN_NAMEDATTRCOUNT | ATTR_CMN_NAMEDATTRLIST| \ ! 193: ATTR_CMN_FLAGS) != ATTR_CMN_VALIDMASK) ! 194: #warning AttributeBlockSize: Missing bits in common mask computation! ! 195: #endif ! 196: ASSERT((attrlist->commonattr & ~ATTR_CMN_VALIDMASK) == 0); ! 197: ! 198: #if ((ATTR_VOL_FSTYPE | ATTR_VOL_SIGNATURE | ATTR_VOL_SIZE | ATTR_VOL_SPACEFREE | \ ! 199: ATTR_VOL_SPACEAVAIL | ATTR_VOL_MINALLOCATION | ATTR_VOL_ALLOCATIONCLUMP | ATTR_VOL_IOBLOCKSIZE | \ ! 200: ATTR_VOL_OBJCOUNT | ATTR_VOL_FILECOUNT | ATTR_VOL_DIRCOUNT | ATTR_VOL_MAXOBJCOUNT | \ ! 201: ATTR_VOL_MOUNTPOINT | ATTR_VOL_NAME | ATTR_VOL_MOUNTFLAGS | ATTR_VOL_INFO) != ATTR_VOL_VALIDMASK) ! 202: #warning AttributeBlockSize: Missing bits in volume mask computation! ! 203: #endif ! 204: ASSERT((attrlist->volattr & ~ATTR_VOL_VALIDMASK) == 0); ! 205: ! 206: #if ((ATTR_DIR_LINKCOUNT | ATTR_DIR_ENTRYCOUNT) != ATTR_DIR_VALIDMASK) ! 207: #warning AttributeBlockSize: Missing bits in directory mask computation! ! 208: #endif ! 209: ASSERT((attrlist->dirattr & ~ATTR_DIR_VALIDMASK) == 0); ! 210: #if ((ATTR_FILE_LINKCOUNT | ATTR_FILE_TOTALSIZE | ATTR_FILE_ALLOCSIZE | ATTR_FILE_IOBLOCKSIZE | \ ! 211: ATTR_FILE_CLUMPSIZE | ATTR_FILE_DEVTYPE | ATTR_FILE_FILETYPE | ATTR_FILE_FORKCOUNT | \ ! 212: ATTR_FILE_FORKLIST | ATTR_FILE_DATALENGTH | ATTR_FILE_DATAALLOCSIZE | ATTR_FILE_DATAEXTENTS | \ ! 213: ATTR_FILE_RSRCLENGTH | ATTR_FILE_RSRCALLOCSIZE | ATTR_FILE_RSRCEXTENTS) != ATTR_FILE_VALIDMASK) ! 214: #warning AttributeBlockSize: Missing bits in file mask computation! ! 215: #endif ! 216: ASSERT((attrlist->fileattr & ~ATTR_FILE_VALIDMASK) == 0); ! 217: ! 218: #if ((ATTR_FORK_TOTALSIZE | ATTR_FORK_ALLOCSIZE) != ATTR_FORK_VALIDMASK) ! 219: #warning AttributeBlockSize: Missing bits in fork mask computation! ! 220: #endif ! 221: ASSERT((attrlist->forkattr & ~ATTR_FORK_VALIDMASK) == 0); ! 222: ! 223: size = 0; ! 224: ! 225: if ((a = attrlist->commonattr) != 0) { ! 226: if (a & ATTR_CMN_NAME) size += sizeof(struct attrreference); ! 227: if (a & ATTR_CMN_DEVID) size += sizeof(dev_t); ! 228: if (a & ATTR_CMN_FSID) size += sizeof(fsid_t); ! 229: if (a & ATTR_CMN_OBJTYPE) size += sizeof(fsobj_type_t); ! 230: if (a & ATTR_CMN_OBJTAG) size += sizeof(fsobj_tag_t); ! 231: if (a & ATTR_CMN_OBJID) size += sizeof(fsobj_id_t); ! 232: if (a & ATTR_CMN_OBJPERMANENTID) size += sizeof(fsobj_id_t); ! 233: if (a & ATTR_CMN_PAROBJID) size += sizeof(fsobj_id_t); ! 234: if (a & ATTR_CMN_SCRIPT) size += sizeof(text_encoding_t); ! 235: if (a & ATTR_CMN_CRTIME) size += sizeof(struct timespec); ! 236: if (a & ATTR_CMN_MODTIME) size += sizeof(struct timespec); ! 237: if (a & ATTR_CMN_CHGTIME) size += sizeof(struct timespec); ! 238: if (a & ATTR_CMN_ACCTIME) size += sizeof(struct timespec); ! 239: if (a & ATTR_CMN_BKUPTIME) size += sizeof(struct timespec); ! 240: if (a & ATTR_CMN_FNDRINFO) size += 32 * sizeof(u_int8_t); ! 241: if (a & ATTR_CMN_OWNERID) size += sizeof(uid_t); ! 242: if (a & ATTR_CMN_GRPID) size += sizeof(gid_t); ! 243: if (a & ATTR_CMN_ACCESSMASK) size += sizeof(u_long); ! 244: if (a & ATTR_CMN_NAMEDATTRCOUNT) size += sizeof(u_long); ! 245: if (a & ATTR_CMN_NAMEDATTRLIST) size += sizeof(struct attrreference); ! 246: if (a & ATTR_CMN_FLAGS) size += sizeof(u_long); ! 247: }; ! 248: if ((a = attrlist->volattr) != 0) { ! 249: if (a & ATTR_VOL_FSTYPE) size += sizeof(u_long); ! 250: if (a & ATTR_VOL_SIGNATURE) size += sizeof(u_long); ! 251: if (a & ATTR_VOL_SIZE) size += sizeof(off_t); ! 252: if (a & ATTR_VOL_SPACEFREE) size += sizeof(off_t); ! 253: if (a & ATTR_VOL_SPACEAVAIL) size += sizeof(off_t); ! 254: if (a & ATTR_VOL_MINALLOCATION) size += sizeof(off_t); ! 255: if (a & ATTR_VOL_ALLOCATIONCLUMP) size += sizeof(off_t); ! 256: if (a & ATTR_VOL_IOBLOCKSIZE) size += sizeof(size_t); ! 257: if (a & ATTR_VOL_OBJCOUNT) size += sizeof(u_long); ! 258: if (a & ATTR_VOL_FILECOUNT) size += sizeof(u_long); ! 259: if (a & ATTR_VOL_DIRCOUNT) size += sizeof(u_long); ! 260: if (a & ATTR_VOL_MAXOBJCOUNT) size += sizeof(u_long); ! 261: if (a & ATTR_VOL_MOUNTPOINT) size += sizeof(struct attrreference); ! 262: if (a & ATTR_VOL_NAME) size += sizeof(struct attrreference); ! 263: if (a & ATTR_VOL_MOUNTFLAGS) size += sizeof(u_long); ! 264: }; ! 265: if ((a = attrlist->dirattr) != 0) { ! 266: if (a & ATTR_DIR_LINKCOUNT) size += sizeof(u_long); ! 267: if (a & ATTR_DIR_ENTRYCOUNT) size += sizeof(u_long); ! 268: }; ! 269: if ((a = attrlist->fileattr) != 0) { ! 270: if (a & ATTR_FILE_LINKCOUNT) size += sizeof(u_long); ! 271: if (a & ATTR_FILE_TOTALSIZE) size += sizeof(off_t); ! 272: if (a & ATTR_FILE_ALLOCSIZE) size += sizeof(off_t); ! 273: if (a & ATTR_FILE_IOBLOCKSIZE) size += sizeof(size_t); ! 274: if (a & ATTR_FILE_CLUMPSIZE) size += sizeof(off_t); ! 275: if (a & ATTR_FILE_DEVTYPE) size += sizeof(u_long); ! 276: if (a & ATTR_FILE_FILETYPE) size += sizeof(u_long); ! 277: if (a & ATTR_FILE_FORKCOUNT) size += sizeof(u_long); ! 278: if (a & ATTR_FILE_FORKLIST) size += sizeof(struct attrreference); ! 279: if (a & ATTR_FILE_DATALENGTH) size += sizeof(off_t); ! 280: if (a & ATTR_FILE_DATAALLOCSIZE) size += sizeof(off_t); ! 281: if (a & ATTR_FILE_DATAEXTENTS) size += sizeof(extentrecord); ! 282: if (a & ATTR_FILE_RSRCLENGTH) size += sizeof(off_t); ! 283: if (a & ATTR_FILE_RSRCALLOCSIZE) size += sizeof(off_t); ! 284: if (a & ATTR_FILE_RSRCEXTENTS) size += sizeof(extentrecord); ! 285: }; ! 286: if ((a = attrlist->forkattr) != 0) { ! 287: if (a & ATTR_FORK_TOTALSIZE) size += sizeof(off_t); ! 288: if (a & ATTR_FORK_ALLOCSIZE) size += sizeof(off_t); ! 289: }; ! 290: ! 291: return size; ! 292: } ! 293: ! 294: ! 295: ! 296: void ! 297: packvolattr (struct attrlist *alist, ! 298: struct iso_node *ip, /* ip for root directory */ ! 299: void **attrbufptrptr, ! 300: void **varbufptrptr) ! 301: { ! 302: void *attrbufptr; ! 303: void *varbufptr; ! 304: struct iso_mnt *imp; ! 305: attrgroup_t a; ! 306: u_long attrlength; ! 307: ! 308: attrbufptr = *attrbufptrptr; ! 309: varbufptr = *varbufptrptr; ! 310: imp = ip->i_mnt; ! 311: ! 312: if ((a = alist->commonattr) != 0) { ! 313: if (a & ATTR_CMN_NAME) { ! 314: attrlength = strlen( imp->volume_id ) + 1; ! 315: ((struct attrreference *)attrbufptr)->attr_dataoffset = varbufptr - attrbufptr; ! 316: ((struct attrreference *)attrbufptr)->attr_length = attrlength; ! 317: (void) strncpy((unsigned char *)varbufptr, imp->volume_id, attrlength); ! 318: ! 319: /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */ ! 320: varbufptr += attrlength + ((4 - (attrlength & 3)) & 3); ! 321: ++((struct attrreference *)attrbufptr); ! 322: }; ! 323: if (a & ATTR_CMN_DEVID) *((dev_t *)attrbufptr)++ = imp->im_devvp->v_rdev; ! 324: if (a & ATTR_CMN_FSID) *((fsid_t *)attrbufptr)++ = ITOV(ip)->v_mount->mnt_stat.f_fsid; ! 325: if (a & ATTR_CMN_OBJTYPE) *((fsobj_type_t *)attrbufptr)++ = 0; ! 326: if (a & ATTR_CMN_OBJTAG) *((fsobj_tag_t *)attrbufptr)++ = VT_ISOFS; ! 327: if (a & ATTR_CMN_OBJID) { ! 328: ((fsobj_id_t *)attrbufptr)->fid_objno = 0; ! 329: ((fsobj_id_t *)attrbufptr)->fid_generation = 0; ! 330: ++((fsobj_id_t *)attrbufptr); ! 331: }; ! 332: if (a & ATTR_CMN_OBJPERMANENTID) { ! 333: ((fsobj_id_t *)attrbufptr)->fid_objno = 0; ! 334: ((fsobj_id_t *)attrbufptr)->fid_generation = 0; ! 335: ++((fsobj_id_t *)attrbufptr); ! 336: }; ! 337: if (a & ATTR_CMN_PAROBJID) { ! 338: ((fsobj_id_t *)attrbufptr)->fid_objno = 0; ! 339: ((fsobj_id_t *)attrbufptr)->fid_generation = 0; ! 340: ++((fsobj_id_t *)attrbufptr); ! 341: }; ! 342: if (a & ATTR_CMN_SCRIPT) *((text_encoding_t *)attrbufptr)++ = 0; ! 343: if (a & ATTR_CMN_CRTIME) *((struct timespec *)attrbufptr)++ = imp->creation_date; ! 344: if (a & ATTR_CMN_MODTIME) *((struct timespec *)attrbufptr)++ = imp->modification_date; ! 345: if (a & ATTR_CMN_CHGTIME) *((struct timespec *)attrbufptr)++ = imp->modification_date; ! 346: if (a & ATTR_CMN_ACCTIME) *((struct timespec *)attrbufptr)++ = imp->modification_date; ! 347: if (a & ATTR_CMN_BKUPTIME) { ! 348: ((struct timespec *)attrbufptr)->tv_sec = 0; ! 349: ((struct timespec *)attrbufptr)->tv_nsec = 0; ! 350: ++((struct timespec *)attrbufptr); ! 351: }; ! 352: if (a & ATTR_CMN_FNDRINFO) { ! 353: bzero (attrbufptr, 32 * sizeof(u_int8_t)); ! 354: attrbufptr += 32 * sizeof(u_int8_t); ! 355: }; ! 356: if (a & ATTR_CMN_OWNERID) *((uid_t *)attrbufptr)++ = ip->inode.iso_uid; ! 357: if (a & ATTR_CMN_GRPID) *((gid_t *)attrbufptr)++ = ip->inode.iso_gid; ! 358: if (a & ATTR_CMN_ACCESSMASK) *((u_long *)attrbufptr)++ = (u_long)ip->inode.iso_mode; ! 359: if (a & ATTR_CMN_FLAGS) *((u_long *)attrbufptr)++ = 0; ! 360: }; ! 361: ! 362: if ((a = alist->volattr) != 0) { ! 363: off_t blocksize = (off_t)imp->logical_block_size; ! 364: ! 365: if (a & ATTR_VOL_FSTYPE) *((u_long *)attrbufptr)++ = (u_long)imp->im_mountp->mnt_vfc->vfc_typenum; ! 366: if (a & ATTR_VOL_SIGNATURE) *((u_long *)attrbufptr)++ = (u_long)ISO9660SIGNATURE; ! 367: if (a & ATTR_VOL_SIZE) *((off_t *)attrbufptr)++ = (off_t)imp->volume_space_size * blocksize; ! 368: if (a & ATTR_VOL_SPACEFREE) *((off_t *)attrbufptr)++ = 0; ! 369: if (a & ATTR_VOL_SPACEAVAIL) *((off_t *)attrbufptr)++ = 0; ! 370: if (a & ATTR_VOL_MINALLOCATION) *((off_t *)attrbufptr)++ = blocksize; ! 371: if (a & ATTR_VOL_ALLOCATIONCLUMP) *((off_t *)attrbufptr)++ = blocksize; ! 372: if (a & ATTR_VOL_IOBLOCKSIZE) *((size_t *)attrbufptr)++ = blocksize; ! 373: if (a & ATTR_VOL_OBJCOUNT) *((u_long *)attrbufptr)++ = 0; ! 374: if (a & ATTR_VOL_FILECOUNT) *((u_long *)attrbufptr)++ = 0; ! 375: if (a & ATTR_VOL_DIRCOUNT) *((u_long *)attrbufptr)++ = 0; ! 376: if (a & ATTR_VOL_MAXOBJCOUNT) *((u_long *)attrbufptr)++ = 0xFFFFFFFF; ! 377: if (a & ATTR_VOL_NAME) { ! 378: attrlength = strlen( imp->volume_id ) + 1; ! 379: ((struct attrreference *)attrbufptr)->attr_dataoffset = varbufptr - attrbufptr; ! 380: ((struct attrreference *)attrbufptr)->attr_length = attrlength; ! 381: (void) strncpy((unsigned char *)varbufptr, imp->volume_id, attrlength); ! 382: ! 383: /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */ ! 384: varbufptr += attrlength + ((4 - (attrlength & 3)) & 3); ! 385: ++((struct attrreference *)attrbufptr); ! 386: }; ! 387: if (a & ATTR_VOL_MOUNTFLAGS) *((u_long *)attrbufptr)++ = (u_long)imp->im_mountp->mnt_flag; ! 388: }; ! 389: ! 390: *attrbufptrptr = attrbufptr; ! 391: *varbufptrptr = varbufptr; ! 392: } ! 393: ! 394: ! 395: void ! 396: packcommonattr (struct attrlist *alist, ! 397: struct iso_node *ip, ! 398: void **attrbufptrptr, ! 399: void **varbufptrptr) ! 400: { ! 401: void *attrbufptr; ! 402: void *varbufptr; ! 403: attrgroup_t a; ! 404: u_long attrlength; ! 405: ! 406: attrbufptr = *attrbufptrptr; ! 407: varbufptr = *varbufptrptr; ! 408: ! 409: if ((a = alist->commonattr) != 0) { ! 410: struct iso_mnt *imp = ip->i_mnt; ! 411: ! 412: if (a & ATTR_CMN_NAME) { ! 413: /* special case root since we know how to get it's name */ ! 414: if (ITOV(ip)->v_flag & VROOT) { ! 415: attrlength = strlen( imp->volume_id ) + 1; ! 416: (void) strncpy((unsigned char *)varbufptr, imp->volume_id, attrlength); ! 417: } else { ! 418: attrlength = strlen(ip->i_name) + 1; ! 419: (void) strncpy((unsigned char *)varbufptr, ip->i_name, attrlength); ! 420: } ! 421: ! 422: ((struct attrreference *)attrbufptr)->attr_dataoffset = varbufptr - attrbufptr; ! 423: ((struct attrreference *)attrbufptr)->attr_length = attrlength; ! 424: /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */ ! 425: varbufptr += attrlength + ((4 - (attrlength & 3)) & 3); ! 426: ++((struct attrreference *)attrbufptr); ! 427: }; ! 428: if (a & ATTR_CMN_DEVID) *((dev_t *)attrbufptr)++ = ip->i_dev; ! 429: if (a & ATTR_CMN_FSID) *((fsid_t *)attrbufptr)++ = ITOV(ip)->v_mount->mnt_stat.f_fsid; ! 430: if (a & ATTR_CMN_OBJTYPE) *((fsobj_type_t *)attrbufptr)++ = ITOV(ip)->v_type; ! 431: if (a & ATTR_CMN_OBJTAG) *((fsobj_tag_t *)attrbufptr)++ = ITOV(ip)->v_tag; ! 432: if (a & ATTR_CMN_OBJID) { ! 433: if (ITOV(ip)->v_flag & VROOT) ! 434: ((fsobj_id_t *)attrbufptr)->fid_objno = 2; /* force root to be 2 */ ! 435: else ! 436: ((fsobj_id_t *)attrbufptr)->fid_objno = ip->i_number; ! 437: ((fsobj_id_t *)attrbufptr)->fid_generation = 0; ! 438: ++((fsobj_id_t *)attrbufptr); ! 439: }; ! 440: if (a & ATTR_CMN_OBJPERMANENTID) { ! 441: if (ITOV(ip)->v_flag & VROOT) ! 442: ((fsobj_id_t *)attrbufptr)->fid_objno = 2; /* force root to be 2 */ ! 443: else ! 444: ((fsobj_id_t *)attrbufptr)->fid_objno = ip->i_number; ! 445: ((fsobj_id_t *)attrbufptr)->fid_generation = 0; ! 446: ++((fsobj_id_t *)attrbufptr); ! 447: }; ! 448: if (a & ATTR_CMN_PAROBJID) { ! 449: struct iso_directory_record *dp = (struct iso_directory_record *)imp->root; ! 450: ino_t rootino = isodirino(dp, imp); ! 451: ! 452: if (ip->i_number == rootino) ! 453: ((fsobj_id_t *)attrbufptr)->fid_objno = 1; /* force root parent to be 1 */ ! 454: else if (ip->i_parent == rootino) ! 455: ((fsobj_id_t *)attrbufptr)->fid_objno = 2; /* force root to be 2 */ ! 456: else ! 457: ((fsobj_id_t *)attrbufptr)->fid_objno = ip->i_parent; ! 458: ((fsobj_id_t *)attrbufptr)->fid_generation = 0; ! 459: ++((fsobj_id_t *)attrbufptr); ! 460: }; ! 461: if (a & ATTR_CMN_SCRIPT) *((text_encoding_t *)attrbufptr)++ = 0; ! 462: if (a & ATTR_CMN_CRTIME) *((struct timespec *)attrbufptr)++ = ip->inode.iso_mtime; ! 463: if (a & ATTR_CMN_MODTIME) *((struct timespec *)attrbufptr)++ = ip->inode.iso_mtime; ! 464: if (a & ATTR_CMN_CHGTIME) *((struct timespec *)attrbufptr)++ = ip->inode.iso_ctime; ! 465: if (a & ATTR_CMN_ACCTIME) *((struct timespec *)attrbufptr)++ = ip->inode.iso_atime; ! 466: if (a & ATTR_CMN_BKUPTIME) { ! 467: ((struct timespec *)attrbufptr)->tv_sec = 0; ! 468: ((struct timespec *)attrbufptr)->tv_nsec = 0; ! 469: ++((struct timespec *)attrbufptr); ! 470: }; ! 471: if (a & ATTR_CMN_FNDRINFO) { ! 472: struct finder_info finfo = {0}; ! 473: ! 474: finfo.fdFlags = ip->i_FinderFlags; ! 475: if (ITOV(ip)->v_type == VREG) { ! 476: finfo.fdType = ip->i_FileType; ! 477: finfo.fdCreator = ip->i_Creator; ! 478: } ! 479: bcopy (&finfo, attrbufptr, sizeof(finfo)); ! 480: attrbufptr += sizeof(finfo); ! 481: bzero (attrbufptr, EXTFNDRINFOSIZE); ! 482: attrbufptr += EXTFNDRINFOSIZE; ! 483: }; ! 484: if (a & ATTR_CMN_OWNERID) *((uid_t *)attrbufptr)++ = ip->inode.iso_uid; ! 485: if (a & ATTR_CMN_GRPID) *((gid_t *)attrbufptr)++ = ip->inode.iso_gid; ! 486: if (a & ATTR_CMN_ACCESSMASK) *((u_long *)attrbufptr)++ = (u_long)ip->inode.iso_mode; ! 487: if (a & ATTR_CMN_FLAGS) *((u_long *)attrbufptr)++ = 0; /* could also use ip->i_flag */ ! 488: }; ! 489: ! 490: *attrbufptrptr = attrbufptr; ! 491: *varbufptrptr = varbufptr; ! 492: } ! 493: ! 494: ! 495: void ! 496: packdirattr(struct attrlist *alist, ! 497: struct iso_node *ip, ! 498: void **attrbufptrptr, ! 499: void **varbufptrptr) ! 500: { ! 501: void *attrbufptr; ! 502: attrgroup_t a; ! 503: ! 504: attrbufptr = *attrbufptrptr; ! 505: ! 506: a = alist->dirattr; ! 507: if ((ITOV(ip)->v_type == VDIR) && (a != 0)) { ! 508: if (a & ATTR_DIR_LINKCOUNT) *((u_long *)attrbufptr)++ = ip->inode.iso_links; ! 509: if (a & ATTR_DIR_ENTRYCOUNT) *((u_long *)attrbufptr)++ = 2; /* XXX */ ! 510: }; ! 511: ! 512: *attrbufptrptr = attrbufptr; ! 513: } ! 514: ! 515: ! 516: void ! 517: packfileattr(struct attrlist *alist, ! 518: struct iso_node *ip, ! 519: void **attrbufptrptr, ! 520: void **varbufptrptr) ! 521: { ! 522: void *attrbufptr = *attrbufptrptr; ! 523: void *varbufptr = *varbufptrptr; ! 524: attrgroup_t a = alist->fileattr; ! 525: ! 526: if ((ITOV(ip)->v_type == VREG) && (a != 0)) { ! 527: if (a & ATTR_FILE_LINKCOUNT) *((u_long *)attrbufptr)++ = ip->inode.iso_links; ! 528: if (a & ATTR_FILE_TOTALSIZE) *((off_t *)attrbufptr)++ = (off_t)ip->i_size; ! 529: if (a & ATTR_FILE_ALLOCSIZE) *((off_t *)attrbufptr)++ = (off_t)ip->i_size; ! 530: if (a & ATTR_FILE_IOBLOCKSIZE) *((u_long *)attrbufptr)++ = ip->i_mnt->logical_block_size; ! 531: if (a & ATTR_FILE_CLUMPSIZE) *((u_long *)attrbufptr)++ = ip->i_mnt->logical_block_size; ! 532: if (a & ATTR_FILE_DEVTYPE) *((u_long *)attrbufptr)++ = (u_long)ip->inode.iso_rdev; ! 533: if (0 /* XXX associated file */) { ! 534: if (a & ATTR_FILE_RSRCLENGTH) *((off_t *)attrbufptr)++ = ip->i_size; ! 535: if (a & ATTR_FILE_RSRCALLOCSIZE) *((off_t *)attrbufptr)++ = ip->i_size; ! 536: if (a & ATTR_FILE_DATALENGTH) *((off_t *)attrbufptr)++ = (off_t)0; ! 537: if (a & ATTR_FILE_DATAALLOCSIZE) *((off_t *)attrbufptr)++ = (off_t)0; ! 538: } else { ! 539: if (a & ATTR_FILE_DATALENGTH) *((off_t *)attrbufptr)++ = (off_t)ip->i_size; ! 540: if (a & ATTR_FILE_DATAALLOCSIZE) *((off_t *)attrbufptr)++ = (off_t)ip->i_size; ! 541: if (a & ATTR_FILE_RSRCLENGTH) *((off_t *)attrbufptr)++ = (off_t)0; ! 542: if (a & ATTR_FILE_RSRCALLOCSIZE) *((off_t *)attrbufptr)++ = (off_t)0; ! 543: }; ! 544: }; ! 545: ! 546: *attrbufptrptr = attrbufptr; ! 547: *varbufptrptr = varbufptr; ! 548: } ! 549: ! 550: ! 551: void ! 552: packattrblk(struct attrlist *alist, ! 553: struct vnode *vp, ! 554: void **attrbufptrptr, ! 555: void **varbufptrptr) ! 556: { ! 557: struct iso_node *ip = VTOI(vp); ! 558: ! 559: if (alist->volattr != 0) { ! 560: packvolattr(alist, ip, attrbufptrptr, varbufptrptr); ! 561: } else { ! 562: packcommonattr(alist, ip, attrbufptrptr, varbufptrptr); ! 563: ! 564: switch (ITOV(ip)->v_type) { ! 565: case VDIR: ! 566: packdirattr(alist, ip, attrbufptrptr, varbufptrptr); ! 567: break; ! 568: ! 569: case VREG: ! 570: packfileattr(alist, ip, attrbufptrptr, varbufptrptr); ! 571: break; ! 572: ! 573: #if 0 /* XXX PPD TBC */ ! 574: case VFORK: ! 575: packforkattr(alist, ip, attrbufptrptr, varbufptrptr); ! 576: break; ! 577: #endif ! 578: ! 579: /* Without this the compiler complains about VNON,VBLK,VCHR,VLNK,VSOCK,VFIFO,VBAD and VSTR ! 580: not being handled... ! 581: */ ! 582: default: ! 583: /* XXX PPD - Panic? */ ! 584: break; ! 585: }; ! 586: }; ! 587: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.