Annotation of src/sys/fs/cd9660/cd9660_vfsops.c, Revision 1.40.2.9
1.40.2.9! ad 1: /* $NetBSD: cd9660_vfsops.c,v 1.40.2.8 2007/09/16 19:04:27 ad Exp $ */
1.1 jdolecek 2:
3: /*-
4: * Copyright (c) 1994
5: * The Regents of the University of California. All rights reserved.
6: *
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).
11: *
12: * Redistribution and use in source and binary forms, with or without
13: * modification, are permitted provided that the following conditions
14: * are met:
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.
1.9 agc 20: * 3. Neither the name of the University nor the names of its contributors
1.1 jdolecek 21: * may be used to endorse or promote products derived from this software
22: * without specific prior written permission.
23: *
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
34: * SUCH DAMAGE.
35: *
36: * @(#)cd9660_vfsops.c 8.18 (Berkeley) 5/22/95
37: */
38:
39: #include <sys/cdefs.h>
1.40.2.9! ad 40: __KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.40.2.8 2007/09/16 19:04:27 ad Exp $");
1.1 jdolecek 41:
42: #if defined(_KERNEL_OPT)
43: #include "opt_compat_netbsd.h"
44: #endif
45:
46: #include <sys/param.h>
1.10 atatat 47: #include <sys/sysctl.h>
1.1 jdolecek 48: #include <sys/systm.h>
49: #include <sys/namei.h>
50: #include <sys/proc.h>
51: #include <sys/kernel.h>
52: #include <sys/vnode.h>
53: #include <miscfs/specfs/specdev.h>
54: #include <sys/mount.h>
55: #include <sys/buf.h>
56: #include <sys/file.h>
57: #include <sys/disklabel.h>
58: #include <sys/device.h>
59: #include <sys/ioctl.h>
60: #include <sys/cdio.h>
61: #include <sys/errno.h>
62: #include <sys/malloc.h>
63: #include <sys/pool.h>
64: #include <sys/stat.h>
65: #include <sys/conf.h>
1.18 jdolecek 66: #include <sys/dirent.h>
1.32 elad 67: #include <sys/kauth.h>
1.1 jdolecek 68:
69: #include <fs/cd9660/iso.h>
70: #include <fs/cd9660/cd9660_extern.h>
71: #include <fs/cd9660/iso_rrip.h>
72: #include <fs/cd9660/cd9660_node.h>
73: #include <fs/cd9660/cd9660_mount.h>
1.2 thorpej 74:
1.40.2.4 ad 75: MALLOC_JUSTDEFINE(M_ISOFSMNT, "ISOFS mount", "ISOFS mount structure");
1.1 jdolecek 76:
77: extern const struct vnodeopv_desc cd9660_vnodeop_opv_desc;
78: extern const struct vnodeopv_desc cd9660_specop_opv_desc;
79: extern const struct vnodeopv_desc cd9660_fifoop_opv_desc;
80:
81: const struct vnodeopv_desc * const cd9660_vnodeopv_descs[] = {
82: &cd9660_vnodeop_opv_desc,
83: &cd9660_specop_opv_desc,
84: &cd9660_fifoop_opv_desc,
85: NULL,
86: };
87:
88: struct vfsops cd9660_vfsops = {
89: MOUNT_CD9660,
1.40.2.4 ad 90: sizeof (struct iso_args),
1.1 jdolecek 91: cd9660_mount,
92: cd9660_start,
93: cd9660_unmount,
94: cd9660_root,
95: cd9660_quotactl,
1.12 christos 96: cd9660_statvfs,
1.1 jdolecek 97: cd9660_sync,
98: cd9660_vget,
99: cd9660_fhtovp,
100: cd9660_vptofh,
101: cd9660_init,
102: cd9660_reinit,
103: cd9660_done,
104: cd9660_mountroot,
1.15 hannken 105: (int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
1.20 thorpej 106: vfs_stdextattrctl,
1.40.2.6 ad 107: (void *)eopnotsupp, /* vfs_suspendctl */
1.1 jdolecek 108: cd9660_vnodeopv_descs,
1.35 christos 109: 0, /* refcount */
110: { NULL, NULL } /* list */
1.1 jdolecek 111: };
1.23 thorpej 112: VFS_ATTACH(cd9660_vfsops);
1.1 jdolecek 113:
1.24 yamt 114: static const struct genfs_ops cd9660_genfsops = {
115: .gop_size = genfs_size,
1.1 jdolecek 116: };
117:
118: /*
119: * Called by vfs_mountroot when iso is going to be mounted as root.
120: *
121: * Name is updated by mount(8) after booting.
122: */
123: #define ROOTNAME "root_device"
124:
1.26 xtraeme 125: static int iso_makemp(struct iso_mnt *isomp, struct buf *bp, int *ea_len);
126: static int iso_mountfs(struct vnode *devvp, struct mount *mp,
1.30 christos 127: struct lwp *l, struct iso_args *argp);
1.1 jdolecek 128:
129: int
130: cd9660_mountroot()
131: {
132: struct mount *mp;
1.30 christos 133: struct lwp *l = curlwp; /* XXX */
1.1 jdolecek 134: int error;
135: struct iso_args args;
136:
1.31 thorpej 137: if (device_class(root_device) != DV_DISK)
1.1 jdolecek 138: return (ENODEV);
1.22 perry 139:
1.1 jdolecek 140: if ((error = vfs_rootmountalloc(MOUNT_CD9660, "root_device", &mp))
141: != 0) {
142: vrele(rootvp);
143: return (error);
144: }
145:
146: args.flags = ISOFSMNT_ROOT;
1.30 christos 147: if ((error = iso_mountfs(rootvp, mp, l, &args)) != 0) {
1.1 jdolecek 148: mp->mnt_op->vfs_refcount--;
149: vfs_unbusy(mp);
1.40.2.5 ad 150: vfs_destroy(mp);
1.1 jdolecek 151: return (error);
152: }
1.40.2.1 ad 153: mutex_enter(&mountlist_lock);
1.1 jdolecek 154: CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
1.40.2.1 ad 155: mutex_exit(&mountlist_lock);
1.30 christos 156: (void)cd9660_statvfs(mp, &mp->mnt_stat, l);
1.1 jdolecek 157: vfs_unbusy(mp);
158: return (0);
159: }
160:
161: /*
162: * VFS Operations.
163: *
164: * mount system call
165: */
166: int
1.40.2.6 ad 167: cd9660_mount(mp, path, data, data_len, l)
1.1 jdolecek 168: struct mount *mp;
169: const char *path;
170: void *data;
1.40.2.4 ad 171: size_t *data_len;
1.30 christos 172: struct lwp *l;
1.1 jdolecek 173: {
1.40.2.6 ad 174: struct nameidata nd;
1.1 jdolecek 175: struct vnode *devvp;
1.40.2.4 ad 176: struct iso_args *args = data;
1.1 jdolecek 177: int error;
1.28 dyoung 178: struct iso_mnt *imp = VFSTOISOFS(mp);
1.22 perry 179:
1.40.2.4 ad 180: if (*data_len < sizeof *args)
181: return EINVAL;
182:
1.1 jdolecek 183: if (mp->mnt_flag & MNT_GETARGS) {
184: if (imp == NULL)
185: return EIO;
1.40.2.4 ad 186: args->fspec = NULL;
187: args->flags = imp->im_flags;
188: *data_len = sizeof (*args);
189: return 0;
1.1 jdolecek 190: }
1.22 perry 191:
1.1 jdolecek 192: if ((mp->mnt_flag & MNT_RDONLY) == 0)
193: return (EROFS);
1.22 perry 194:
1.40.2.4 ad 195: if ((mp->mnt_flag & MNT_UPDATE) && args->fspec == NULL)
1.27 jmmv 196: return EINVAL;
197:
1.1 jdolecek 198: /*
199: * Not an update, or updating the name: look up the name
200: * and verify that it refers to a sensible block device.
201: */
1.40.2.6 ad 202: NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, args->fspec, l);
203: if ((error = namei(&nd)) != 0)
1.1 jdolecek 204: return (error);
1.40.2.6 ad 205: devvp = nd.ni_vp;
1.1 jdolecek 206:
207: if (devvp->v_type != VBLK) {
208: vrele(devvp);
209: return ENOTBLK;
210: }
211: if (bdevsw_lookup(devvp->v_rdev) == NULL) {
212: vrele(devvp);
213: return ENXIO;
214: }
215: /*
216: * If mount by non-root, then verify that user has necessary
217: * permissions on the device.
218: */
1.34 ad 219: if (kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER, NULL) != 0) {
1.1 jdolecek 220: vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
1.34 ad 221: error = VOP_ACCESS(devvp, VREAD, l->l_cred, l);
1.1 jdolecek 222: VOP_UNLOCK(devvp, 0);
223: if (error) {
224: vrele(devvp);
225: return (error);
226: }
227: }
1.21 mycroft 228: if ((mp->mnt_flag & MNT_UPDATE) == 0) {
229: /*
230: * Disallow multiple mounts of the same device.
231: * Disallow mounting of a device that is currently in use
232: * (except for root, which might share swap device for
233: * miniroot).
234: */
235: error = vfs_mountedon(devvp);
236: if (error)
237: goto fail;
238: if (vcount(devvp) > 1 && devvp != rootvp) {
239: error = EBUSY;
240: goto fail;
241: }
1.30 christos 242: error = VOP_OPEN(devvp, FREAD, FSCRED, l);
1.21 mycroft 243: if (error)
244: goto fail;
1.40.2.4 ad 245: error = iso_mountfs(devvp, mp, l, args);
1.21 mycroft 246: if (error) {
247: vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
1.30 christos 248: (void)VOP_CLOSE(devvp, FREAD, NOCRED, l);
1.21 mycroft 249: VOP_UNLOCK(devvp, 0);
250: goto fail;
251: }
252: } else {
253: vrele(devvp);
1.1 jdolecek 254: if (devvp != imp->im_devvp)
1.21 mycroft 255: return (EINVAL); /* needs translation */
1.1 jdolecek 256: }
1.40.2.4 ad 257: return set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE,
1.40.2.6 ad 258: mp->mnt_op->vfs_name, mp, l);
1.21 mycroft 259:
260: fail:
261: vrele(devvp);
262: return (error);
1.1 jdolecek 263: }
264:
265: /*
266: * Make a mount point from a volume descriptor
267: */
268: static int
269: iso_makemp(isomp, bp, ea_len)
270: struct iso_mnt *isomp;
271: struct buf *bp;
272: int *ea_len;
273: {
274: struct iso_primary_descriptor *pri;
275: int logical_block_size;
276: struct iso_directory_record *rootp;
277:
278: pri = (struct iso_primary_descriptor *)bp->b_data;
1.22 perry 279:
1.1 jdolecek 280: logical_block_size = isonum_723 (pri->logical_block_size);
1.22 perry 281:
1.1 jdolecek 282: if (logical_block_size < DEV_BSIZE || logical_block_size > MAXBSIZE
283: || (logical_block_size & (logical_block_size - 1)) != 0)
284: return -1;
1.22 perry 285:
1.1 jdolecek 286: rootp = (struct iso_directory_record *)pri->root_directory_record;
1.22 perry 287:
1.1 jdolecek 288: isomp->logical_block_size = logical_block_size;
289: isomp->volume_space_size = isonum_733 (pri->volume_space_size);
290: memcpy(isomp->root, rootp, sizeof(isomp->root));
291: isomp->root_extent = isonum_733 (rootp->extent);
292: isomp->root_size = isonum_733 (rootp->size);
293: isomp->im_joliet_level = 0;
1.22 perry 294:
1.1 jdolecek 295: isomp->im_bmask = logical_block_size - 1;
296: isomp->im_bshift = 0;
297: while ((1 << isomp->im_bshift) < isomp->logical_block_size)
298: isomp->im_bshift++;
299:
300: if (ea_len != NULL)
301: *ea_len = isonum_711(rootp->ext_attr_length);
302:
303: return 0;
304: }
305:
306: /*
307: * Common code for mount and mountroot
308: */
309: static int
1.30 christos 310: iso_mountfs(devvp, mp, l, argp)
1.1 jdolecek 311: struct vnode *devvp;
312: struct mount *mp;
1.30 christos 313: struct lwp *l;
1.1 jdolecek 314: struct iso_args *argp;
315: {
316: struct iso_mnt *isomp = (struct iso_mnt *)0;
317: struct buf *bp = NULL, *pribp = NULL, *supbp = NULL;
318: dev_t dev = devvp->v_rdev;
319: int error = EINVAL;
320: int ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
321: int iso_bsize;
322: int iso_blknum;
323: int joliet_level;
324: struct iso_volume_descriptor *vdp;
325: struct iso_supplementary_descriptor *sup;
326: int sess = 0;
327: int ext_attr_length;
328: struct disklabel label;
329:
330: if (!ronly)
331: return EROFS;
1.22 perry 332:
1.21 mycroft 333: /* Flush out any old buffers remaining from a previous use. */
1.34 ad 334: if ((error = vinvalbuf(devvp, V_SAVE, l->l_cred, l, 0, 0)) != 0)
1.1 jdolecek 335: return (error);
1.22 perry 336:
1.1 jdolecek 337: /* This is the "logical sector size". The standard says this
338: * should be 2048 or the physical sector size on the device,
339: * whichever is greater. For now, we'll just use a constant.
340: */
341: iso_bsize = ISO_DEFAULT_BLOCK_SIZE;
342:
1.30 christos 343: error = VOP_IOCTL(devvp, DIOCGDINFO, &label, FREAD, FSCRED, l);
1.1 jdolecek 344: if (!error &&
345: label.d_partitions[DISKPART(dev)].p_fstype == FS_ISO9660) {
346: /* XXX more sanity checks? */
347: sess = label.d_partitions[DISKPART(dev)].p_cdsession;
348: } else {
349: /* fallback to old method */
1.30 christos 350: error = VOP_IOCTL(devvp, CDIOREADMSADDR, &sess, 0, FSCRED, l);
1.1 jdolecek 351: if (error)
352: sess = 0; /* never mind */
353: }
1.4 christos 354: #ifdef ISO_DEBUG
1.1 jdolecek 355: printf("isofs: session offset (part %d) %d\n", DISKPART(dev), sess);
356: #endif
357:
358: for (iso_blknum = 16; iso_blknum < 100; iso_blknum++) {
359: if ((error = bread(devvp, (iso_blknum+sess) * btodb(iso_bsize),
360: iso_bsize, NOCRED, &bp)) != 0)
361: goto out;
1.22 perry 362:
1.1 jdolecek 363: vdp = (struct iso_volume_descriptor *)bp->b_data;
364: if (memcmp(vdp->id, ISO_STANDARD_ID, sizeof(vdp->id)) != 0) {
365: error = EINVAL;
366: goto out;
367: }
368:
369: switch (isonum_711(vdp->type)) {
370: case ISO_VD_PRIMARY:
371: if (pribp == NULL) {
372: pribp = bp;
373: bp = NULL;
374: }
375: break;
376:
377: case ISO_VD_SUPPLEMENTARY:
378: if (supbp == NULL) {
379: supbp = bp;
380: bp = NULL;
381: }
382: break;
383:
384: default:
385: break;
386: }
387:
388: if (isonum_711 (vdp->type) == ISO_VD_END) {
1.40.2.2 ad 389: brelse(bp, 0);
1.1 jdolecek 390: bp = NULL;
391: break;
392: }
393:
394: if (bp != NULL) {
1.40.2.2 ad 395: brelse(bp, 0);
1.1 jdolecek 396: bp = NULL;
397: }
398: }
399:
400: if (pribp == NULL) {
401: error = EINVAL;
402: goto out;
403: }
404:
405: isomp = malloc(sizeof *isomp, M_ISOFSMNT, M_WAITOK);
1.3 dsl 406: memset(isomp, 0, sizeof *isomp);
1.1 jdolecek 407: if (iso_makemp(isomp, pribp, &ext_attr_length) == -1) {
408: error = EINVAL;
409: goto out;
410: }
411:
412: isomp->volume_space_size += sess;
413:
1.40.2.7 ad 414: brelse(pribp, BC_AGE);
1.1 jdolecek 415: pribp = NULL;
1.22 perry 416:
1.1 jdolecek 417: mp->mnt_data = isomp;
1.12 christos 418: mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev;
419: mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_CD9660);
420: mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
1.18 jdolecek 421: mp->mnt_stat.f_namemax = MAXNAMLEN;
1.1 jdolecek 422: mp->mnt_flag |= MNT_LOCAL;
423: mp->mnt_dev_bshift = iso_bsize;
424: mp->mnt_fs_bshift = isomp->im_bshift;
425: isomp->im_mountp = mp;
426: isomp->im_dev = dev;
427: isomp->im_devvp = devvp;
1.22 perry 428:
1.1 jdolecek 429: /* Check the Rock Ridge Extension support */
430: if (!(argp->flags & ISOFSMNT_NORRIP)) {
431: struct iso_directory_record *rootp;
432:
433: if ((error = bread(isomp->im_devvp,
434: (isomp->root_extent + ext_attr_length) <<
435: (isomp->im_bshift - DEV_BSHIFT),
436: isomp->logical_block_size, NOCRED,
437: &bp)) != 0)
438: goto out;
1.22 perry 439:
1.1 jdolecek 440: rootp = (struct iso_directory_record *)bp->b_data;
1.22 perry 441:
1.1 jdolecek 442: if ((isomp->rr_skip = cd9660_rrip_offset(rootp,isomp)) < 0) {
443: argp->flags |= ISOFSMNT_NORRIP;
444: } else {
445: argp->flags &= ~ISOFSMNT_GENS;
446: }
1.22 perry 447:
1.1 jdolecek 448: /*
449: * The contents are valid,
450: * but they will get reread as part of another vnode, so...
451: */
1.40.2.7 ad 452: brelse(bp, BC_AGE);
1.1 jdolecek 453: bp = NULL;
454: }
455: isomp->im_flags = argp->flags & (ISOFSMNT_NORRIP | ISOFSMNT_GENS |
456: ISOFSMNT_EXTATT | ISOFSMNT_NOJOLIET | ISOFSMNT_RRCASEINS);
457:
458: if (isomp->im_flags & ISOFSMNT_GENS)
459: isomp->iso_ftype = ISO_FTYPE_9660;
460: else if (isomp->im_flags & ISOFSMNT_NORRIP) {
461: isomp->iso_ftype = ISO_FTYPE_DEFAULT;
462: if (argp->flags & ISOFSMNT_NOCASETRANS)
463: isomp->im_flags |= ISOFSMNT_NOCASETRANS;
1.22 perry 464: } else
1.1 jdolecek 465: isomp->iso_ftype = ISO_FTYPE_RRIP;
466:
467: /* Check the Joliet Extension support */
468: if ((argp->flags & ISOFSMNT_NORRIP) != 0 &&
469: (argp->flags & ISOFSMNT_NOJOLIET) == 0 &&
470: supbp != NULL) {
471: joliet_level = 0;
472: sup = (struct iso_supplementary_descriptor *)supbp->b_data;
473:
474: if ((isonum_711(sup->flags) & 1) == 0) {
475: if (memcmp(sup->escape, "%/@", 3) == 0)
476: joliet_level = 1;
477: if (memcmp(sup->escape, "%/C", 3) == 0)
478: joliet_level = 2;
479: if (memcmp(sup->escape, "%/E", 3) == 0)
480: joliet_level = 3;
481: }
482: if (joliet_level != 0) {
483: if (iso_makemp(isomp, supbp, NULL) == -1) {
484: error = EINVAL;
485: goto out;
486: }
487: isomp->im_joliet_level = joliet_level;
488: }
489: }
490:
491: if (supbp != NULL) {
1.40.2.2 ad 492: brelse(supbp, 0);
1.1 jdolecek 493: supbp = NULL;
494: }
1.22 perry 495:
1.37 drochner 496: devvp->v_specmountpoint = mp;
497:
1.1 jdolecek 498: return 0;
499: out:
500: if (bp)
1.40.2.2 ad 501: brelse(bp, 0);
1.1 jdolecek 502: if (pribp)
1.40.2.2 ad 503: brelse(pribp, 0);
1.1 jdolecek 504: if (supbp)
1.40.2.2 ad 505: brelse(supbp, 0);
1.1 jdolecek 506: if (isomp) {
1.3 dsl 507: free(isomp, M_ISOFSMNT);
1.1 jdolecek 508: mp->mnt_data = NULL;
509: }
510: return error;
511: }
512:
513: /*
514: * Make a filesystem operational.
515: * Nothing to do at the moment.
516: */
517: /* ARGSUSED */
518: int
1.38 christos 519: cd9660_start(struct mount *mp, int flags,
520: struct lwp *l)
1.1 jdolecek 521: {
522: return 0;
523: }
524:
525: /*
526: * unmount system call
527: */
528: int
1.30 christos 529: cd9660_unmount(mp, mntflags, l)
1.1 jdolecek 530: struct mount *mp;
531: int mntflags;
1.30 christos 532: struct lwp *l;
1.1 jdolecek 533: {
534: struct iso_mnt *isomp;
535: int error, flags = 0;
1.22 perry 536:
1.1 jdolecek 537: if (mntflags & MNT_FORCE)
538: flags |= FORCECLOSE;
539: if ((error = vflush(mp, NULLVP, flags)) != 0)
540: return (error);
541:
542: isomp = VFSTOISOFS(mp);
543:
544: #ifdef ISODEVMAP
545: if (isomp->iso_ftype == ISO_FTYPE_RRIP)
546: iso_dunmap(isomp->im_dev);
547: #endif
548:
549: if (isomp->im_devvp->v_type != VBAD)
550: isomp->im_devvp->v_specmountpoint = NULL;
551:
552: vn_lock(isomp->im_devvp, LK_EXCLUSIVE | LK_RETRY);
1.30 christos 553: error = VOP_CLOSE(isomp->im_devvp, FREAD, NOCRED, l);
1.1 jdolecek 554: vput(isomp->im_devvp);
1.3 dsl 555: free(isomp, M_ISOFSMNT);
1.1 jdolecek 556: mp->mnt_data = NULL;
557: mp->mnt_flag &= ~MNT_LOCAL;
558: return (error);
559: }
560:
561: /*
562: * Return root of a filesystem
563: */
564: int
1.7 thorpej 565: cd9660_root(mp, vpp)
1.1 jdolecek 566: struct mount *mp;
567: struct vnode **vpp;
568: {
569: struct iso_mnt *imp = VFSTOISOFS(mp);
570: struct iso_directory_record *dp =
571: (struct iso_directory_record *)imp->root;
572: ino_t ino = isodirino(dp, imp);
1.22 perry 573:
1.1 jdolecek 574: /*
575: * With RRIP we must use the `.' entry of the root directory.
576: * Simply tell vget, that it's a relocated directory.
577: */
578: return (cd9660_vget_internal(mp, ino, vpp,
1.7 thorpej 579: imp->iso_ftype == ISO_FTYPE_RRIP, dp));
1.1 jdolecek 580: }
581:
582: /*
583: * Do operations associated with quotas, not supported
584: */
585: /* ARGSUSED */
586: int
1.36 christos 587: cd9660_quotactl(
1.38 christos 588: struct mount *mp,
589: int cmd,
590: uid_t uid,
591: void *arg,
592: struct lwp *l)
1.1 jdolecek 593: {
594:
595: return (EOPNOTSUPP);
596: }
597:
598: /*
599: * Get file system statistics.
600: */
601: int
1.36 christos 602: cd9660_statvfs(
603: struct mount *mp,
604: struct statvfs *sbp,
1.38 christos 605: struct lwp *l)
1.1 jdolecek 606: {
607: struct iso_mnt *isomp;
1.22 perry 608:
1.1 jdolecek 609: isomp = VFSTOISOFS(mp);
610:
611: sbp->f_bsize = isomp->logical_block_size;
1.12 christos 612: sbp->f_frsize = sbp->f_bsize;
1.1 jdolecek 613: sbp->f_iosize = sbp->f_bsize; /* XXX */
614: sbp->f_blocks = isomp->volume_space_size;
615: sbp->f_bfree = 0; /* total free blocks */
616: sbp->f_bavail = 0; /* blocks free for non superuser */
1.12 christos 617: sbp->f_bresvd = 0; /* total reserved blocks */
1.1 jdolecek 618: sbp->f_files = 0; /* total files */
619: sbp->f_ffree = 0; /* free file nodes */
1.25 jmmv 620: sbp->f_favail = 0; /* free file nodes for non superuser */
1.12 christos 621: sbp->f_fresvd = 0; /* reserved file nodes */
622: copy_statvfs_info(sbp, mp);
1.1 jdolecek 623: /* Use the first spare for flags: */
624: sbp->f_spare[0] = isomp->im_flags;
625: return 0;
626: }
627:
628: /* ARGSUSED */
629: int
1.36 christos 630: cd9660_sync(
1.38 christos 631: struct mount *mp,
632: int waitfor,
633: kauth_cred_t cred,
634: struct lwp *l)
1.1 jdolecek 635: {
636: return (0);
637: }
638:
639: /*
640: * File handle to vnode
641: *
642: * Have to be really careful about stale file handles:
643: * - check that the inode number is in range
644: * - call iget() to get the locked inode
645: * - check for an unallocated inode (i_mode == 0)
646: * - check that the generation number matches
647: */
648:
649: struct ifid {
650: ushort ifid_len;
651: ushort ifid_pad;
652: int ifid_ino;
653: long ifid_start;
654: };
655:
656: /* ARGSUSED */
657: int
1.7 thorpej 658: cd9660_fhtovp(mp, fhp, vpp)
1.1 jdolecek 659: struct mount *mp;
660: struct fid *fhp;
661: struct vnode **vpp;
662: {
1.33 martin 663: struct ifid ifh;
1.1 jdolecek 664: struct iso_node *ip;
665: struct vnode *nvp;
666: int error;
1.22 perry 667:
1.33 martin 668: if (fhp->fid_len != sizeof(ifh))
669: return EINVAL;
670:
671: memcpy(&ifh, fhp, sizeof(ifh));
1.1 jdolecek 672: #ifdef ISOFS_DBG
673: printf("fhtovp: ino %d, start %ld\n",
1.33 martin 674: ifh.ifid_ino, ifh.ifid_start);
1.1 jdolecek 675: #endif
1.22 perry 676:
1.33 martin 677: if ((error = VFS_VGET(mp, ifh.ifid_ino, &nvp)) != 0) {
1.1 jdolecek 678: *vpp = NULLVP;
679: return (error);
680: }
681: ip = VTOI(nvp);
682: if (ip->inode.iso_mode == 0) {
683: vput(nvp);
684: *vpp = NULLVP;
685: return (ESTALE);
686: }
687: *vpp = nvp;
688: return (0);
689: }
690:
691: int
1.7 thorpej 692: cd9660_vget(mp, ino, vpp)
1.1 jdolecek 693: struct mount *mp;
694: ino_t ino;
695: struct vnode **vpp;
696: {
697:
698: /*
699: * XXXX
700: * It would be nice if we didn't always set the `relocated' flag
701: * and force the extra read, but I don't want to think about fixing
702: * that right now.
703: */
704: return (cd9660_vget_internal(mp, ino, vpp,
705: #if 0
706: VFSTOISOFS(mp)->iso_ftype == ISO_FTYPE_RRIP,
707: #else
708: 0,
709: #endif
1.7 thorpej 710: NULL));
1.1 jdolecek 711: }
712:
713: int
1.7 thorpej 714: cd9660_vget_internal(mp, ino, vpp, relocated, isodir)
1.1 jdolecek 715: struct mount *mp;
716: ino_t ino;
717: struct vnode **vpp;
718: int relocated;
719: struct iso_directory_record *isodir;
720: {
721: struct iso_mnt *imp;
722: struct iso_node *ip;
723: #ifdef ISODEVMAP
724: struct iso_dnode *dp;
725: #endif
726: struct buf *bp;
727: struct vnode *vp, *nvp;
728: dev_t dev;
729: int error;
730:
731: imp = VFSTOISOFS(mp);
732: dev = imp->im_dev;
1.40.2.9! ad 733:
! 734: retry:
! 735: if ((*vpp = cd9660_ihashget(dev, ino, LK_EXCLUSIVE)) != NULLVP)
1.1 jdolecek 736: return (0);
737:
738: /* Allocate a new vnode/iso_node. */
739: if ((error = getnewvnode(VT_ISOFS, mp, cd9660_vnodeop_p, &vp)) != 0) {
740: *vpp = NULLVP;
741: return (error);
742: }
743: ip = pool_get(&cd9660_node_pool, PR_WAITOK);
1.40.2.9! ad 744:
! 745: /*
! 746: * If someone beat us to it, put back the freshly allocated
! 747: * vnode/inode pair and retry.
! 748: */
! 749: mutex_enter(&cd9660_hashlock);
! 750: if (cd9660_ihashget(dev, ino, 0) != NULL) {
! 751: mutex_exit(&cd9660_hashlock);
! 752: ungetnewvnode(vp);
! 753: pool_put(&cd9660_node_pool, ip);
! 754: goto retry;
! 755: }
! 756:
1.3 dsl 757: memset(ip, 0, sizeof(struct iso_node));
1.1 jdolecek 758: vp->v_data = ip;
759: ip->i_vnode = vp;
760: ip->i_dev = dev;
761: ip->i_number = ino;
1.40.2.9! ad 762: ip->i_mnt = imp;
! 763: ip->i_devvp = imp->im_devvp;
! 764: genfs_node_init(vp, &cd9660_genfsops);
1.1 jdolecek 765:
766: /*
767: * Put it onto its hash chain and lock it so that other requests for
768: * this inode will block if they arrive while we are sleeping waiting
769: * for old data structures to be purged or for the contents of the
770: * disk portion of this inode to be read.
771: */
772: cd9660_ihashins(ip);
1.40.2.9! ad 773: mutex_exit(&cd9660_hashlock);
1.1 jdolecek 774:
775: if (isodir == 0) {
776: int lbn, off;
777:
778: lbn = lblkno(imp, ino);
779: if (lbn >= imp->volume_space_size) {
780: vput(vp);
781: printf("fhtovp: lbn exceed volume space %d\n", lbn);
782: return (ESTALE);
783: }
1.22 perry 784:
1.1 jdolecek 785: off = blkoff(imp, ino);
786: if (off + ISO_DIRECTORY_RECORD_SIZE > imp->logical_block_size) {
787: vput(vp);
788: printf("fhtovp: crosses block boundary %d\n",
789: off + ISO_DIRECTORY_RECORD_SIZE);
790: return (ESTALE);
791: }
1.22 perry 792:
1.1 jdolecek 793: error = bread(imp->im_devvp,
794: lbn << (imp->im_bshift - DEV_BSHIFT),
795: imp->logical_block_size, NOCRED, &bp);
796: if (error) {
797: vput(vp);
1.40.2.2 ad 798: brelse(bp, 0);
1.1 jdolecek 799: printf("fhtovp: bread error %d\n",error);
800: return (error);
801: }
1.40 christos 802: isodir = (struct iso_directory_record *)((char *)bp->b_data + off);
1.1 jdolecek 803:
804: if (off + isonum_711(isodir->length) >
805: imp->logical_block_size) {
806: vput(vp);
807: if (bp != 0)
1.40.2.2 ad 808: brelse(bp, 0);
1.1 jdolecek 809: printf("fhtovp: directory crosses block boundary %d[off=%d/len=%d]\n",
810: off +isonum_711(isodir->length), off,
811: isonum_711(isodir->length));
812: return (ESTALE);
813: }
1.22 perry 814:
1.1 jdolecek 815: #if 0
816: if (isonum_733(isodir->extent) +
817: isonum_711(isodir->ext_attr_length) != ifhp->ifid_start) {
818: if (bp != 0)
1.40.2.2 ad 819: brelse(bp, 0);
1.1 jdolecek 820: printf("fhtovp: file start miss %d vs %d\n",
821: isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length),
822: ifhp->ifid_start);
823: return (ESTALE);
824: }
825: #endif
826: } else
827: bp = 0;
828:
829: VREF(ip->i_devvp);
830:
831: if (relocated) {
832: /*
833: * On relocated directories we must
834: * read the `.' entry out of a dir.
835: */
836: ip->iso_start = ino >> imp->im_bshift;
837: if (bp != 0)
1.40.2.2 ad 838: brelse(bp, 0);
1.29 yamt 839: if ((error = cd9660_blkatoff(vp, (off_t)0, NULL, &bp)) != 0) {
1.1 jdolecek 840: vput(vp);
841: return (error);
842: }
843: isodir = (struct iso_directory_record *)bp->b_data;
844: }
845:
846: ip->iso_extent = isonum_733(isodir->extent);
847: ip->i_size = isonum_733(isodir->size);
848: ip->iso_start = isonum_711(isodir->ext_attr_length) + ip->iso_extent;
1.22 perry 849:
1.1 jdolecek 850: /*
851: * Setup time stamp, attribute
852: */
853: vp->v_type = VNON;
854: switch (imp->iso_ftype) {
855: default: /* ISO_FTYPE_9660 */
856: {
857: struct buf *bp2;
858: int off;
859: if ((imp->im_flags & ISOFSMNT_EXTATT)
860: && (off = isonum_711(isodir->ext_attr_length)))
1.29 yamt 861: cd9660_blkatoff(vp, (off_t)-(off << imp->im_bshift),
862: NULL, &bp2);
1.1 jdolecek 863: else
864: bp2 = NULL;
865: cd9660_defattr(isodir, ip, bp2);
866: cd9660_deftstamp(isodir, ip, bp2);
867: if (bp2)
1.40.2.2 ad 868: brelse(bp2, 0);
1.1 jdolecek 869: break;
870: }
871: case ISO_FTYPE_RRIP:
872: cd9660_rrip_analyze(isodir, ip, imp);
873: break;
874: }
875:
876: if (bp != 0)
1.40.2.2 ad 877: brelse(bp, 0);
1.1 jdolecek 878:
879: /*
880: * Initialize the associated vnode
881: */
882: switch (vp->v_type = IFTOVT(ip->inode.iso_mode)) {
883: case VFIFO:
884: vp->v_op = cd9660_fifoop_p;
885: break;
886: case VCHR:
887: case VBLK:
888: /*
889: * if device, look at device number table for translation
890: */
891: #ifdef ISODEVMAP
892: if ((dp = iso_dmap(dev, ino, 0)) != NULL)
893: ip->inode.iso_rdev = dp->d_dev;
894: #endif
895: vp->v_op = cd9660_specop_p;
896: if ((nvp = checkalias(vp, ip->inode.iso_rdev, mp)) != NULL) {
897: /*
898: * Discard unneeded vnode, but save its iso_node.
899: * Note that the lock is carried over in the iso_node
900: * to the replacement vnode.
901: */
902: nvp->v_data = vp->v_data;
903: vp->v_data = NULL;
904: VOP_UNLOCK(vp, 0);
905: vp->v_op = spec_vnodeop_p;
906: vgone(vp);
907: lockmgr(&nvp->v_lock, LK_EXCLUSIVE, &nvp->v_interlock);
908: /*
909: * Reinitialize aliased inode.
910: */
911: vp = nvp;
912: ip->i_vnode = vp;
913: }
914: break;
915: case VLNK:
916: case VNON:
917: case VSOCK:
918: case VDIR:
919: case VBAD:
920: break;
921: case VREG:
922: uvm_vnp_setsize(vp, ip->i_size);
923: break;
924: }
1.22 perry 925:
1.40.2.6 ad 926: if (vp->v_type != VREG)
927: uvm_vnp_setsize(vp, 0);
928:
1.1 jdolecek 929: if (ip->iso_extent == imp->root_extent)
1.40.2.3 ad 930: vp->v_vflag |= VV_ROOT;
1.1 jdolecek 931:
932: /*
933: * XXX need generation number?
934: */
1.22 perry 935:
1.1 jdolecek 936: *vpp = vp;
937: return (0);
938: }
939:
940: /*
941: * Vnode pointer to File handle
942: */
943: /* ARGSUSED */
944: int
1.33 martin 945: cd9660_vptofh(vp, fhp, fh_size)
1.1 jdolecek 946: struct vnode *vp;
947: struct fid *fhp;
1.33 martin 948: size_t *fh_size;
1.1 jdolecek 949: {
950: struct iso_node *ip = VTOI(vp);
1.33 martin 951: struct ifid ifh;
1.22 perry 952:
1.33 martin 953: if (*fh_size < sizeof(struct ifid)) {
954: *fh_size = sizeof(struct ifid);
955: return E2BIG;
956: }
957: *fh_size = sizeof(struct ifid);
958:
959: memset(&ifh, 0, sizeof(ifh));
960: ifh.ifid_len = sizeof(struct ifid);
961: ifh.ifid_ino = ip->i_number;
962: ifh.ifid_start = ip->iso_start;
963: memcpy(fhp, &ifh, sizeof(ifh));
1.22 perry 964:
1.1 jdolecek 965: #ifdef ISOFS_DBG
966: printf("vptofh: ino %d, start %ld\n",
1.33 martin 967: ifh.ifid_ino,ifh.ifid_start);
1.1 jdolecek 968: #endif
969: return 0;
970: }
971:
1.10 atatat 972: SYSCTL_SETUP(sysctl_vfs_cd9660_setup, "sysctl vfs.cd9660 subtree setup")
1.1 jdolecek 973: {
1.10 atatat 974:
1.11 atatat 975: sysctl_createv(clog, 0, NULL, NULL,
976: CTLFLAG_PERMANENT, CTLTYPE_NODE, "vfs", NULL,
1.10 atatat 977: NULL, 0, NULL, 0,
978: CTL_VFS, CTL_EOL);
1.11 atatat 979: sysctl_createv(clog, 0, NULL, NULL,
1.14 atatat 980: CTLFLAG_PERMANENT, CTLTYPE_NODE, "cd9660",
981: SYSCTL_DESCR("ISO-9660 file system"),
1.10 atatat 982: NULL, 0, NULL, 0,
983: CTL_VFS, 14, CTL_EOL);
1.19 jdolecek 984:
985: sysctl_createv(clog, 0, NULL, NULL,
986: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.22 perry 987: CTLTYPE_INT, "utf8_joliet",
1.19 jdolecek 988: SYSCTL_DESCR("Encode Joliet file names to UTF-8"),
989: NULL, 0, &cd9660_utf8_joliet, 0,
990: CTL_VFS, 14, CD9660_UTF8_JOLIET, CTL_EOL);
991:
1.1 jdolecek 992: }
CVSweb <webmaster@jp.NetBSD.org>