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