10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51025Sfrankho * Common Development and Distribution License (the "License"). 61025Sfrankho * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 221488Srsb * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * VFS operations for High Sierra filesystem 300Sstevel@tonic-gate */ 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/isa_defs.h> 340Sstevel@tonic-gate #include <sys/t_lock.h> 350Sstevel@tonic-gate #include <sys/param.h> 360Sstevel@tonic-gate #include <sys/systm.h> 370Sstevel@tonic-gate #include <sys/sysmacros.h> 380Sstevel@tonic-gate #include <sys/kmem.h> 390Sstevel@tonic-gate #include <sys/signal.h> 400Sstevel@tonic-gate #include <sys/user.h> 410Sstevel@tonic-gate #include <sys/proc.h> 420Sstevel@tonic-gate #include <sys/disp.h> 430Sstevel@tonic-gate #include <sys/buf.h> 440Sstevel@tonic-gate #include <sys/pathname.h> 450Sstevel@tonic-gate #include <sys/vfs.h> 460Sstevel@tonic-gate #include <sys/vnode.h> 470Sstevel@tonic-gate #include <sys/file.h> 480Sstevel@tonic-gate #include <sys/uio.h> 490Sstevel@tonic-gate #include <sys/conf.h> 500Sstevel@tonic-gate #include <sys/policy.h> 510Sstevel@tonic-gate 520Sstevel@tonic-gate #include <vm/page.h> 530Sstevel@tonic-gate 540Sstevel@tonic-gate #include <sys/fs/snode.h> 550Sstevel@tonic-gate #include <sys/fs/hsfs_spec.h> 560Sstevel@tonic-gate #include <sys/fs/hsfs_isospec.h> 570Sstevel@tonic-gate #include <sys/fs/hsfs_node.h> 580Sstevel@tonic-gate #include <sys/fs/hsfs_impl.h> 590Sstevel@tonic-gate #include <sys/fs/hsfs_susp.h> 600Sstevel@tonic-gate #include <sys/fs/hsfs_rrip.h> 610Sstevel@tonic-gate 620Sstevel@tonic-gate #include <sys/statvfs.h> 630Sstevel@tonic-gate #include <sys/mount.h> 640Sstevel@tonic-gate #include <sys/mntent.h> 650Sstevel@tonic-gate #include <sys/swap.h> 660Sstevel@tonic-gate #include <sys/errno.h> 670Sstevel@tonic-gate #include <sys/debug.h> 680Sstevel@tonic-gate #include "fs/fs_subr.h" 690Sstevel@tonic-gate #include <sys/cmn_err.h> 700Sstevel@tonic-gate #include <sys/bootconf.h> 710Sstevel@tonic-gate 72*2900Sfrankho #include <sys/sdt.h> 73*2900Sfrankho 740Sstevel@tonic-gate /* 750Sstevel@tonic-gate * These are needed for the CDROMREADOFFSET Code 760Sstevel@tonic-gate */ 770Sstevel@tonic-gate #include <sys/cdio.h> 780Sstevel@tonic-gate #include <sys/sunddi.h> 790Sstevel@tonic-gate 800Sstevel@tonic-gate #define HSFS_CLKSET 810Sstevel@tonic-gate 820Sstevel@tonic-gate #include <sys/modctl.h> 830Sstevel@tonic-gate 840Sstevel@tonic-gate /* 850Sstevel@tonic-gate * Options for mount. 860Sstevel@tonic-gate */ 870Sstevel@tonic-gate #define HOPT_GLOBAL MNTOPT_GLOBAL 880Sstevel@tonic-gate #define HOPT_NOGLOBAL MNTOPT_NOGLOBAL 890Sstevel@tonic-gate #define HOPT_MAPLCASE "maplcase" 900Sstevel@tonic-gate #define HOPT_NOMAPLCASE "nomaplcase" 910Sstevel@tonic-gate #define HOPT_NOTRAILDOT "notraildot" 920Sstevel@tonic-gate #define HOPT_TRAILDOT "traildot" 930Sstevel@tonic-gate #define HOPT_NRR "nrr" 940Sstevel@tonic-gate #define HOPT_RR "rr" 95*2900Sfrankho #define HOPT_JOLIET "joliet" 96*2900Sfrankho #define HOPT_NOJOLIET "nojoliet" 97*2900Sfrankho #define HOPT_JOLIETLONG "jolietlong" 98*2900Sfrankho #define HOPT_VERS2 "vers2" 99*2900Sfrankho #define HOPT_NOVERS2 "novers2" 1000Sstevel@tonic-gate #define HOPT_RO MNTOPT_RO 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate static char *global_cancel[] = { HOPT_NOGLOBAL, NULL }; 1030Sstevel@tonic-gate static char *noglobal_cancel[] = { HOPT_GLOBAL, NULL }; 1040Sstevel@tonic-gate static char *mapl_cancel[] = { HOPT_NOMAPLCASE, NULL }; 1050Sstevel@tonic-gate static char *nomapl_cancel[] = { HOPT_MAPLCASE, NULL }; 1060Sstevel@tonic-gate static char *ro_cancel[] = { MNTOPT_RW, NULL }; 1070Sstevel@tonic-gate static char *rr_cancel[] = { HOPT_NRR, NULL }; 1080Sstevel@tonic-gate static char *nrr_cancel[] = { HOPT_RR, NULL }; 109*2900Sfrankho static char *joliet_cancel[] = { HOPT_NOJOLIET, NULL }; 110*2900Sfrankho static char *nojoliet_cancel[] = { HOPT_JOLIET, NULL }; 111*2900Sfrankho static char *vers2_cancel[] = { HOPT_NOVERS2, NULL }; 112*2900Sfrankho static char *novers2_cancel[] = { HOPT_VERS2, NULL }; 1130Sstevel@tonic-gate static char *trail_cancel[] = { HOPT_NOTRAILDOT, NULL }; 1140Sstevel@tonic-gate static char *notrail_cancel[] = { HOPT_TRAILDOT, NULL }; 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate static mntopt_t hsfs_options[] = { 1170Sstevel@tonic-gate { HOPT_GLOBAL, global_cancel, NULL, 0, NULL }, 1180Sstevel@tonic-gate { HOPT_NOGLOBAL, noglobal_cancel, NULL, MO_DEFAULT, NULL }, 1190Sstevel@tonic-gate { HOPT_MAPLCASE, mapl_cancel, NULL, MO_DEFAULT, NULL }, 1200Sstevel@tonic-gate { HOPT_NOMAPLCASE, nomapl_cancel, NULL, 0, NULL }, 1210Sstevel@tonic-gate { HOPT_RO, ro_cancel, NULL, MO_DEFAULT, NULL }, 1220Sstevel@tonic-gate { HOPT_RR, rr_cancel, NULL, MO_DEFAULT, NULL }, 1230Sstevel@tonic-gate { HOPT_NRR, nrr_cancel, NULL, 0, NULL }, 124*2900Sfrankho { HOPT_JOLIET, joliet_cancel, NULL, 0, NULL }, 125*2900Sfrankho { HOPT_NOJOLIET, nojoliet_cancel, NULL, 0, NULL }, 126*2900Sfrankho { HOPT_JOLIETLONG, NULL, NULL, 0, NULL }, 127*2900Sfrankho { HOPT_VERS2, vers2_cancel, NULL, 0, NULL }, 128*2900Sfrankho { HOPT_NOVERS2, novers2_cancel, NULL, 0, NULL }, 1290Sstevel@tonic-gate { HOPT_TRAILDOT, trail_cancel, NULL, MO_DEFAULT, NULL }, 1300Sstevel@tonic-gate { HOPT_NOTRAILDOT, notrail_cancel, NULL, 0, NULL }, 131*2900Sfrankho { "sector", NULL, "0", MO_HASVALUE, NULL}, 1320Sstevel@tonic-gate }; 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate static mntopts_t hsfs_proto_opttbl = { 1350Sstevel@tonic-gate sizeof (hsfs_options) / sizeof (mntopt_t), 1360Sstevel@tonic-gate hsfs_options 1370Sstevel@tonic-gate }; 1380Sstevel@tonic-gate 139*2900Sfrankho static int hsfsfstype; 1400Sstevel@tonic-gate static int hsfsinit(int, char *); 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate static vfsdef_t vfw = { 1430Sstevel@tonic-gate VFSDEF_VERSION, 1440Sstevel@tonic-gate "hsfs", 1450Sstevel@tonic-gate hsfsinit, 1461488Srsb VSW_HASPROTO|VSW_STATS, /* We don't suppport remounting */ 1470Sstevel@tonic-gate &hsfs_proto_opttbl 1480Sstevel@tonic-gate }; 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate static struct modlfs modlfs = { 1510Sstevel@tonic-gate &mod_fsops, "filesystem for HSFS", &vfw 1520Sstevel@tonic-gate }; 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate static struct modlinkage modlinkage = { 1550Sstevel@tonic-gate MODREV_1, (void *)&modlfs, NULL 1560Sstevel@tonic-gate }; 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate char _depends_on[] = "fs/specfs"; 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate int 161*2900Sfrankho _init(void) 1620Sstevel@tonic-gate { 1630Sstevel@tonic-gate return (mod_install(&modlinkage)); 1640Sstevel@tonic-gate } 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate int 167*2900Sfrankho _fini(void) 1680Sstevel@tonic-gate { 169*2900Sfrankho int error; 170*2900Sfrankho 171*2900Sfrankho error = mod_remove(&modlinkage); 172*2900Sfrankho 173*2900Sfrankho DTRACE_PROBE1(mod_remove, int, error); 174*2900Sfrankho 175*2900Sfrankho if (error) 176*2900Sfrankho return (error); 177*2900Sfrankho 178*2900Sfrankho mutex_destroy(&hs_mounttab_lock); 179*2900Sfrankho 180*2900Sfrankho /* 181*2900Sfrankho * Tear down the operations vectors 182*2900Sfrankho */ 183*2900Sfrankho (void) vfs_freevfsops_by_type(hsfsfstype); 184*2900Sfrankho vn_freevnodeops(hsfs_vnodeops); 185*2900Sfrankho 186*2900Sfrankho hs_fini_hsnode_cache(); 187*2900Sfrankho return (0); 1880Sstevel@tonic-gate } 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate int 1910Sstevel@tonic-gate _info(struct modinfo *modinfop) 1920Sstevel@tonic-gate { 1930Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1940Sstevel@tonic-gate } 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate #define BDEVFLAG(dev) ((devopsp[getmajor(dev)])->devo_cb_ops->cb_flag) 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate kmutex_t hs_mounttab_lock; 1990Sstevel@tonic-gate struct hsfs *hs_mounttab = NULL; 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate /* default mode, uid, gid */ 2020Sstevel@tonic-gate mode_t hsfs_default_mode = 0555; 2030Sstevel@tonic-gate uid_t hsfs_default_uid = 0; 2040Sstevel@tonic-gate gid_t hsfs_default_gid = 3; 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate static int hsfs_mount(struct vfs *vfsp, struct vnode *mvp, 2070Sstevel@tonic-gate struct mounta *uap, struct cred *cr); 2080Sstevel@tonic-gate static int hsfs_unmount(struct vfs *vfsp, int, struct cred *cr); 2090Sstevel@tonic-gate static int hsfs_root(struct vfs *vfsp, struct vnode **vpp); 2100Sstevel@tonic-gate static int hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp); 2110Sstevel@tonic-gate static int hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp); 2120Sstevel@tonic-gate static int hsfs_mountroot(struct vfs *, enum whymountroot); 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate static int hs_mountfs(struct vfs *vfsp, dev_t dev, char *path, 2150Sstevel@tonic-gate mode_t mode, int flags, struct cred *cr, int isroot); 216*2900Sfrankho static int hs_getrootvp(struct vfs *vfsp, struct hsfs *fsp, size_t pathsize); 2170Sstevel@tonic-gate static int hs_findhsvol(struct hsfs *fsp, struct vnode *vp, 2180Sstevel@tonic-gate struct hs_volume *hvp); 2190Sstevel@tonic-gate static int hs_parsehsvol(struct hsfs *fsp, uchar_t *volp, 2200Sstevel@tonic-gate struct hs_volume *hvp); 2210Sstevel@tonic-gate static int hs_findisovol(struct hsfs *fsp, struct vnode *vp, 222*2900Sfrankho struct hs_volume *hvp, 223*2900Sfrankho struct hs_volume *svp, 224*2900Sfrankho struct hs_volume *jvp); 225*2900Sfrankho static int hs_joliet_level(uchar_t *volp); 2260Sstevel@tonic-gate static int hs_parseisovol(struct hsfs *fsp, uchar_t *volp, 2270Sstevel@tonic-gate struct hs_volume *hvp); 228*2900Sfrankho static void hs_copylabel(struct hs_volume *, unsigned char *, int); 2290Sstevel@tonic-gate static int hs_getmdev(struct vfs *, char *fspec, int flags, dev_t *pdev, 2300Sstevel@tonic-gate mode_t *mode, cred_t *cr); 2310Sstevel@tonic-gate static int hs_findvoldesc(dev_t rdev, int desc_sec); 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate static int 2340Sstevel@tonic-gate hsfsinit(int fstype, char *name) 2350Sstevel@tonic-gate { 2360Sstevel@tonic-gate static const fs_operation_def_t hsfs_vfsops_template[] = { 2370Sstevel@tonic-gate VFSNAME_MOUNT, hsfs_mount, 2380Sstevel@tonic-gate VFSNAME_UNMOUNT, hsfs_unmount, 2390Sstevel@tonic-gate VFSNAME_ROOT, hsfs_root, 2400Sstevel@tonic-gate VFSNAME_STATVFS, hsfs_statvfs, 2410Sstevel@tonic-gate VFSNAME_VGET, hsfs_vget, 2420Sstevel@tonic-gate VFSNAME_MOUNTROOT, hsfs_mountroot, 2430Sstevel@tonic-gate NULL, NULL 2440Sstevel@tonic-gate }; 2450Sstevel@tonic-gate int error; 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate error = vfs_setfsops(fstype, hsfs_vfsops_template, NULL); 2480Sstevel@tonic-gate if (error != 0) { 2490Sstevel@tonic-gate cmn_err(CE_WARN, "hsfsinit: bad vfs ops template"); 2500Sstevel@tonic-gate return (error); 2510Sstevel@tonic-gate } 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate error = vn_make_ops(name, hsfs_vnodeops_template, &hsfs_vnodeops); 2540Sstevel@tonic-gate if (error != 0) { 2550Sstevel@tonic-gate (void) vfs_freevfsops_by_type(fstype); 2560Sstevel@tonic-gate cmn_err(CE_WARN, "hsfsinit: bad vnode ops template"); 2570Sstevel@tonic-gate return (error); 2580Sstevel@tonic-gate } 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate hsfsfstype = fstype; 2610Sstevel@tonic-gate mutex_init(&hs_mounttab_lock, NULL, MUTEX_DEFAULT, NULL); 2620Sstevel@tonic-gate hs_init_hsnode_cache(); 2630Sstevel@tonic-gate return (0); 2640Sstevel@tonic-gate } 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate /*ARGSUSED*/ 2670Sstevel@tonic-gate static int 2680Sstevel@tonic-gate hsfs_mount(struct vfs *vfsp, struct vnode *mvp, 2690Sstevel@tonic-gate struct mounta *uap, struct cred *cr) 2700Sstevel@tonic-gate { 2710Sstevel@tonic-gate int vnode_busy; 2720Sstevel@tonic-gate dev_t dev; 2730Sstevel@tonic-gate struct pathname dpn; 2740Sstevel@tonic-gate int error; 2750Sstevel@tonic-gate mode_t mode; 2760Sstevel@tonic-gate int flags; /* this will hold the mount specific data */ 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate if ((error = secpolicy_fs_mount(cr, mvp, vfsp)) != 0) 2790Sstevel@tonic-gate return (error); 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate if (mvp->v_type != VDIR) 2820Sstevel@tonic-gate return (ENOTDIR); 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate /* mount option must be read only, else mount will be rejected */ 2850Sstevel@tonic-gate if (!(uap->flags & MS_RDONLY)) 2860Sstevel@tonic-gate return (EROFS); 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate /* 2890Sstevel@tonic-gate * We already told the framework that we don't support remounting. 2900Sstevel@tonic-gate */ 2910Sstevel@tonic-gate ASSERT(!(uap->flags & MS_REMOUNT)); 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate mutex_enter(&mvp->v_lock); 2940Sstevel@tonic-gate vnode_busy = (mvp->v_count != 1) || (mvp->v_flag & VROOT); 2950Sstevel@tonic-gate mutex_exit(&mvp->v_lock); 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate if ((uap->flags & MS_OVERLAY) == 0 && vnode_busy) { 2980Sstevel@tonic-gate return (EBUSY); 2990Sstevel@tonic-gate } 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate /* 3020Sstevel@tonic-gate * Check for the options that actually affect things 3030Sstevel@tonic-gate * at our level. 3040Sstevel@tonic-gate */ 3050Sstevel@tonic-gate flags = 0; 3060Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NOMAPLCASE, NULL)) 3070Sstevel@tonic-gate flags |= HSFSMNT_NOMAPLCASE; 3080Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NOTRAILDOT, NULL)) 3090Sstevel@tonic-gate flags |= HSFSMNT_NOTRAILDOT; 3100Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NRR, NULL)) 3110Sstevel@tonic-gate flags |= HSFSMNT_NORRIP; 312*2900Sfrankho if (vfs_optionisset(vfsp, HOPT_NOJOLIET, NULL)) 313*2900Sfrankho flags |= HSFSMNT_NOJOLIET; 314*2900Sfrankho if (vfs_optionisset(vfsp, HOPT_JOLIETLONG, NULL)) 315*2900Sfrankho flags |= HSFSMNT_JOLIETLONG; 316*2900Sfrankho if (vfs_optionisset(vfsp, HOPT_NOVERS2, NULL)) 317*2900Sfrankho flags |= HSFSMNT_NOVERS2; 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate error = pn_get(uap->dir, (uap->flags & MS_SYSSPACE) ? 3200Sstevel@tonic-gate UIO_SYSSPACE : UIO_USERSPACE, &dpn); 3210Sstevel@tonic-gate if (error) 3220Sstevel@tonic-gate return (error); 3230Sstevel@tonic-gate 3240Sstevel@tonic-gate if ((error = hs_getmdev(vfsp, uap->spec, uap->flags, &dev, 3250Sstevel@tonic-gate &mode, cr)) != 0) { 3260Sstevel@tonic-gate pn_free(&dpn); 3270Sstevel@tonic-gate return (error); 3280Sstevel@tonic-gate } 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate /* 3310Sstevel@tonic-gate * If the device is a tape, return error 3320Sstevel@tonic-gate */ 3330Sstevel@tonic-gate if ((BDEVFLAG(dev) & D_TAPE) == D_TAPE) { 3340Sstevel@tonic-gate pn_free(&dpn); 3350Sstevel@tonic-gate return (ENOTBLK); 3360Sstevel@tonic-gate } 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate /* 3390Sstevel@tonic-gate * Mount the filesystem. 3400Sstevel@tonic-gate */ 3410Sstevel@tonic-gate error = hs_mountfs(vfsp, dev, dpn.pn_path, mode, flags, cr, 0); 3420Sstevel@tonic-gate pn_free(&dpn); 3430Sstevel@tonic-gate return (error); 3440Sstevel@tonic-gate } 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate /*ARGSUSED*/ 3470Sstevel@tonic-gate static int 3480Sstevel@tonic-gate hsfs_unmount( 3490Sstevel@tonic-gate struct vfs *vfsp, 3500Sstevel@tonic-gate int flag, 3510Sstevel@tonic-gate struct cred *cr) 3520Sstevel@tonic-gate { 3530Sstevel@tonic-gate struct hsfs **tspp; 3540Sstevel@tonic-gate struct hsfs *fsp; 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate if (secpolicy_fs_unmount(cr, vfsp) != 0) 3570Sstevel@tonic-gate return (EPERM); 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate /* 3600Sstevel@tonic-gate * forced unmount is not supported by this file system 3610Sstevel@tonic-gate * and thus, ENOTSUP is being returned. 3620Sstevel@tonic-gate */ 3630Sstevel@tonic-gate if (flag & MS_FORCE) 3640Sstevel@tonic-gate return (ENOTSUP); 3650Sstevel@tonic-gate 3660Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp); 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate if (fsp->hsfs_rootvp->v_count != 1) 3690Sstevel@tonic-gate return (EBUSY); 3700Sstevel@tonic-gate 3710Sstevel@tonic-gate /* destroy all old pages and hsnodes for this vfs */ 3720Sstevel@tonic-gate if (hs_synchash(vfsp)) 3730Sstevel@tonic-gate return (EBUSY); 3740Sstevel@tonic-gate 3750Sstevel@tonic-gate mutex_enter(&hs_mounttab_lock); 3760Sstevel@tonic-gate for (tspp = &hs_mounttab; *tspp != NULL; tspp = &(*tspp)->hsfs_next) { 3770Sstevel@tonic-gate if (*tspp == fsp) 3780Sstevel@tonic-gate break; 3790Sstevel@tonic-gate } 3800Sstevel@tonic-gate if (*tspp == NULL) { 3810Sstevel@tonic-gate mutex_exit(&hs_mounttab_lock); 3820Sstevel@tonic-gate panic("hsfs_unmount: vfs not mounted?"); 3830Sstevel@tonic-gate /*NOTREACHED*/ 3840Sstevel@tonic-gate } 3850Sstevel@tonic-gate 3860Sstevel@tonic-gate *tspp = fsp->hsfs_next; 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate mutex_exit(&hs_mounttab_lock); 3890Sstevel@tonic-gate 3900Sstevel@tonic-gate (void) VOP_CLOSE(fsp->hsfs_devvp, FREAD, 1, (offset_t)0, cr); 3910Sstevel@tonic-gate VN_RELE(fsp->hsfs_devvp); 3920Sstevel@tonic-gate /* free path table space */ 3930Sstevel@tonic-gate if (fsp->hsfs_ptbl != NULL) 3940Sstevel@tonic-gate kmem_free(fsp->hsfs_ptbl, 3950Sstevel@tonic-gate (size_t)fsp->hsfs_vol.ptbl_len); 3960Sstevel@tonic-gate /* free path table index table */ 3970Sstevel@tonic-gate if (fsp->hsfs_ptbl_idx != NULL) 3980Sstevel@tonic-gate kmem_free(fsp->hsfs_ptbl_idx, (size_t) 3990Sstevel@tonic-gate (fsp->hsfs_ptbl_idx_size * sizeof (struct ptable_idx))); 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate /* free "mounted on" pathame */ 4020Sstevel@tonic-gate if (fsp->hsfs_fsmnt != NULL) 4030Sstevel@tonic-gate kmem_free(fsp->hsfs_fsmnt, strlen(fsp->hsfs_fsmnt) + 1); 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate mutex_destroy(&fsp->hsfs_free_lock); 4060Sstevel@tonic-gate rw_destroy(&fsp->hsfs_hash_lock); 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate kmem_free(fsp, sizeof (*fsp)); 4090Sstevel@tonic-gate return (0); 4100Sstevel@tonic-gate } 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate /*ARGSUSED*/ 4130Sstevel@tonic-gate static int 4140Sstevel@tonic-gate hsfs_root(struct vfs *vfsp, struct vnode **vpp) 4150Sstevel@tonic-gate { 4160Sstevel@tonic-gate *vpp = (VFS_TO_HSFS(vfsp))->hsfs_rootvp; 4170Sstevel@tonic-gate VN_HOLD(*vpp); 4180Sstevel@tonic-gate return (0); 4190Sstevel@tonic-gate } 4200Sstevel@tonic-gate 4210Sstevel@tonic-gate /*ARGSUSED*/ 4220Sstevel@tonic-gate static int 4230Sstevel@tonic-gate hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp) 4240Sstevel@tonic-gate { 4250Sstevel@tonic-gate struct hsfs *fsp; 4260Sstevel@tonic-gate dev32_t d32; 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp); 4290Sstevel@tonic-gate if (fsp->hsfs_magic != HSFS_MAGIC) 4300Sstevel@tonic-gate return (EINVAL); 4310Sstevel@tonic-gate bzero(sbp, sizeof (*sbp)); 4320Sstevel@tonic-gate sbp->f_bsize = vfsp->vfs_bsize; 4330Sstevel@tonic-gate sbp->f_frsize = sbp->f_bsize; /* no fragment, same as block size */ 4340Sstevel@tonic-gate sbp->f_blocks = (fsblkcnt64_t)fsp->hsfs_vol.vol_size; 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate sbp->f_bfree = (fsblkcnt64_t)0; 4370Sstevel@tonic-gate sbp->f_bavail = (fsblkcnt64_t)0; 4380Sstevel@tonic-gate sbp->f_files = (fsfilcnt64_t)-1; 4390Sstevel@tonic-gate sbp->f_ffree = (fsfilcnt64_t)0; 4400Sstevel@tonic-gate sbp->f_favail = (fsfilcnt64_t)0; 4410Sstevel@tonic-gate (void) cmpldev(&d32, vfsp->vfs_dev); 4420Sstevel@tonic-gate sbp->f_fsid = d32; 4430Sstevel@tonic-gate (void) strcpy(sbp->f_basetype, vfssw[vfsp->vfs_fstype].vsw_name); 4440Sstevel@tonic-gate sbp->f_flag = vf_to_stf(vfsp->vfs_flag); 4450Sstevel@tonic-gate sbp->f_namemax = fsp->hsfs_namemax; 4460Sstevel@tonic-gate (void) strcpy(sbp->f_fstr, fsp->hsfs_vol.vol_id); 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate return (0); 4490Sstevel@tonic-gate } 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate /* 4520Sstevel@tonic-gate * Previously nodeid was declared as uint32_t. This has been changed 4530Sstevel@tonic-gate * to conform better with the ISO9660 standard. The standard states that 4540Sstevel@tonic-gate * a LBN can be a 32 bit number, as the MAKE_NODEID macro shifts this 4550Sstevel@tonic-gate * LBN 11 places left (LBN_TO_BYTE) and then shifts the result 5 right 4560Sstevel@tonic-gate * (divide by 32) we are left with the potential of an overflow if 4570Sstevel@tonic-gate * confined to a 32 bit value. 4580Sstevel@tonic-gate */ 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate static int 4610Sstevel@tonic-gate hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp) 4620Sstevel@tonic-gate { 4630Sstevel@tonic-gate struct hsfid *fid; 4640Sstevel@tonic-gate struct hsfs *fsp; 4650Sstevel@tonic-gate ino64_t nodeid; 4660Sstevel@tonic-gate int error; 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate fsp = (struct hsfs *)VFS_TO_HSFS(vfsp); 4690Sstevel@tonic-gate fid = (struct hsfid *)fidp; 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate /* 4720Sstevel@tonic-gate * Look for vnode on hashlist. 4730Sstevel@tonic-gate * If found, it's now active and the refcnt was incremented. 4740Sstevel@tonic-gate */ 4750Sstevel@tonic-gate 4760Sstevel@tonic-gate rw_enter(&fsp->hsfs_hash_lock, RW_READER); 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate nodeid = (ino64_t)MAKE_NODEID(fid->hf_dir_lbn, fid->hf_dir_off, vfsp); 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate if ((*vpp = hs_findhash(nodeid, vfsp)) == NULL) { 4810Sstevel@tonic-gate /* 4820Sstevel@tonic-gate * Not in cache, so we need to remake it. 4830Sstevel@tonic-gate * hs_remakenode() will read the directory entry 4840Sstevel@tonic-gate * and then check again to see if anyone else has 4850Sstevel@tonic-gate * put it in the cache. 4860Sstevel@tonic-gate */ 4870Sstevel@tonic-gate rw_exit(&fsp->hsfs_hash_lock); 4880Sstevel@tonic-gate error = hs_remakenode(fid->hf_dir_lbn, (uint_t)fid->hf_dir_off, 4890Sstevel@tonic-gate vfsp, vpp); 4900Sstevel@tonic-gate return (error); 4910Sstevel@tonic-gate } 4920Sstevel@tonic-gate rw_exit(&fsp->hsfs_hash_lock); 4930Sstevel@tonic-gate return (0); 4940Sstevel@tonic-gate } 4950Sstevel@tonic-gate 4960Sstevel@tonic-gate 4970Sstevel@tonic-gate #define CHECKSUM_SIZE (64 * 1024) 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate /* 5000Sstevel@tonic-gate * Compute a CD-ROM fsid by checksumming the first 64K of data on the CD 5010Sstevel@tonic-gate * We use the 'fsp' argument to determine the location of the root 5020Sstevel@tonic-gate * directory entry, and we start reading from there. 5030Sstevel@tonic-gate */ 5040Sstevel@tonic-gate static int 5050Sstevel@tonic-gate compute_cdrom_id(struct hsfs *fsp, vnode_t *devvp) 5060Sstevel@tonic-gate { 5070Sstevel@tonic-gate uint_t secno; 5080Sstevel@tonic-gate struct hs_volume *hsvp = &fsp->hsfs_vol; 5090Sstevel@tonic-gate struct buf *bp; 5100Sstevel@tonic-gate int error; 5110Sstevel@tonic-gate int fsid; 5120Sstevel@tonic-gate 5130Sstevel@tonic-gate secno = hsvp->root_dir.ext_lbn >> hsvp->lbn_secshift; 514494Sfrankho bp = bread(devvp->v_rdev, secno * 4, CHECKSUM_SIZE); 5150Sstevel@tonic-gate error = geterror(bp); 516494Sfrankho 517494Sfrankho /* 518494Sfrankho * An error on read or a partial read means we asked 519494Sfrankho * for a nonexistant/corrupted piece of the device 520494Sfrankho * (including past-the-end of the media). Don't 521494Sfrankho * try to use the checksumming method then. 522494Sfrankho */ 523494Sfrankho if (!error && bp->b_bcount == CHECKSUM_SIZE) { 5240Sstevel@tonic-gate int *ibuf = (int *)bp->b_un.b_addr; 5250Sstevel@tonic-gate int i; 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate fsid = 0; 5280Sstevel@tonic-gate 529494Sfrankho for (i = 0; i < CHECKSUM_SIZE / sizeof (int); i++) 5300Sstevel@tonic-gate fsid ^= ibuf[ i ]; 531494Sfrankho } else { 532494Sfrankho /* 533494Sfrankho * Fallback - use creation date 534494Sfrankho */ 5350Sstevel@tonic-gate fsid = hsvp->cre_date.tv_sec; 536494Sfrankho } 5370Sstevel@tonic-gate 5380Sstevel@tonic-gate brelse(bp); 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate return (fsid); 5410Sstevel@tonic-gate } 5420Sstevel@tonic-gate 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate /*ARGSUSED*/ 5450Sstevel@tonic-gate static int 5460Sstevel@tonic-gate hs_mountfs( 5470Sstevel@tonic-gate struct vfs *vfsp, 5480Sstevel@tonic-gate dev_t dev, 5490Sstevel@tonic-gate char *path, 5500Sstevel@tonic-gate mode_t mode, 5510Sstevel@tonic-gate int mount_flags, 5520Sstevel@tonic-gate struct cred *cr, 5530Sstevel@tonic-gate int isroot) 5540Sstevel@tonic-gate { 5550Sstevel@tonic-gate struct vnode *devvp; 5560Sstevel@tonic-gate struct hsfs *tsp; 5570Sstevel@tonic-gate struct hsfs *fsp = NULL; 5580Sstevel@tonic-gate struct vattr vap; 5590Sstevel@tonic-gate struct hsnode *hp; 5600Sstevel@tonic-gate int error; 5610Sstevel@tonic-gate struct timeval tv; 5620Sstevel@tonic-gate int fsid; 563*2900Sfrankho int use_rrip; 564*2900Sfrankho int use_vers2; 565*2900Sfrankho int use_joliet; 566*2900Sfrankho int has_rrip = 0; 567*2900Sfrankho int has_vers2 = 0; 568*2900Sfrankho int has_joliet = 0; 569*2900Sfrankho int force_rrip_off; 570*2900Sfrankho int force_vers2_off; 571*2900Sfrankho int force_joliet_off; 572*2900Sfrankho size_t pathbufsz = strlen(path) + 1; 573*2900Sfrankho int redo_rootvp; 574*2900Sfrankho 575*2900Sfrankho struct hs_volume *svp; /* Supplemental VD for ISO-9660:1999 */ 576*2900Sfrankho struct hs_volume *jvp; /* Joliet VD */ 577*2900Sfrankho 578*2900Sfrankho /* 579*2900Sfrankho * The rules for which extension will be used are: 580*2900Sfrankho * 1. No specific mount options given: 581*2900Sfrankho * - use rrip if available 582*2900Sfrankho * - use ISO9660:1999 if available 583*2900Sfrankho * - use joliet if available. 584*2900Sfrankho * 2. rrip/ISO9660:1999/joliet explicitly disabled via mount option: 585*2900Sfrankho * - use next "lower" extension 586*2900Sfrankho * 3. joliet/ISO9660:1999/rrip explicitly requested via mount option: 587*2900Sfrankho * - disable rrip support even if available 588*2900Sfrankho * - disable IOS9660:1999 support even if available 589*2900Sfrankho * 590*2900Sfrankho * We need to adjust these flags as we discover the extensions 591*2900Sfrankho * present. See below. These are just the starting values. 592*2900Sfrankho */ 593*2900Sfrankho use_rrip = (mount_flags & HSFSMNT_NORRIP) == 0; 594*2900Sfrankho use_vers2 = (mount_flags & HSFSMNT_NOVERS2) == 0; 595*2900Sfrankho use_joliet = (mount_flags & HSFSMNT_NOJOLIET) == 0; 5960Sstevel@tonic-gate 5970Sstevel@tonic-gate /* 5980Sstevel@tonic-gate * Open the device 5990Sstevel@tonic-gate */ 6000Sstevel@tonic-gate devvp = makespecvp(dev, VBLK); 6010Sstevel@tonic-gate ASSERT(devvp != 0); 6020Sstevel@tonic-gate 6030Sstevel@tonic-gate /* 6040Sstevel@tonic-gate * Open the target device (file) for read only. 6050Sstevel@tonic-gate */ 6060Sstevel@tonic-gate if (error = VOP_OPEN(&devvp, FREAD, cr)) { 6070Sstevel@tonic-gate VN_RELE(devvp); 6080Sstevel@tonic-gate return (error); 6090Sstevel@tonic-gate } 6100Sstevel@tonic-gate 6110Sstevel@tonic-gate /* 6120Sstevel@tonic-gate * Refuse to go any further if this 6130Sstevel@tonic-gate * device is being used for swapping 6140Sstevel@tonic-gate */ 6150Sstevel@tonic-gate if (IS_SWAPVP(common_specvp(devvp))) { 6160Sstevel@tonic-gate error = EBUSY; 6170Sstevel@tonic-gate goto cleanup; 6180Sstevel@tonic-gate } 6190Sstevel@tonic-gate 6200Sstevel@tonic-gate vap.va_mask = AT_SIZE; 6210Sstevel@tonic-gate if ((error = VOP_GETATTR(devvp, &vap, ATTR_COMM, cr)) != 0) { 6220Sstevel@tonic-gate cmn_err(CE_NOTE, "Cannot get attributes of the CD-ROM driver"); 6230Sstevel@tonic-gate goto cleanup; 6240Sstevel@tonic-gate } 6250Sstevel@tonic-gate 6260Sstevel@tonic-gate /* 6270Sstevel@tonic-gate * Make sure we have a nonzero size partition. 6280Sstevel@tonic-gate * The current version of the SD driver will *not* fail the open 6290Sstevel@tonic-gate * of such a partition so we have to check for it here. 6300Sstevel@tonic-gate */ 6310Sstevel@tonic-gate if (vap.va_size == 0) { 6320Sstevel@tonic-gate error = ENXIO; 6330Sstevel@tonic-gate goto cleanup; 6340Sstevel@tonic-gate } 6350Sstevel@tonic-gate 6360Sstevel@tonic-gate /* 6370Sstevel@tonic-gate * Init a new hsfs structure. 6380Sstevel@tonic-gate */ 6390Sstevel@tonic-gate fsp = kmem_zalloc(sizeof (*fsp), KM_SLEEP); 640*2900Sfrankho svp = kmem_zalloc(sizeof (*svp), KM_SLEEP); 641*2900Sfrankho jvp = kmem_zalloc(sizeof (*jvp), KM_SLEEP); 6420Sstevel@tonic-gate 6430Sstevel@tonic-gate /* hardwire perms, uid, gid */ 6440Sstevel@tonic-gate fsp->hsfs_vol.vol_uid = hsfs_default_uid; 6450Sstevel@tonic-gate fsp->hsfs_vol.vol_gid = hsfs_default_gid; 6460Sstevel@tonic-gate fsp->hsfs_vol.vol_prot = hsfs_default_mode; 647*2900Sfrankho svp->vol_uid = hsfs_default_uid; 648*2900Sfrankho svp->vol_gid = hsfs_default_gid; 649*2900Sfrankho svp->vol_prot = hsfs_default_mode; 650*2900Sfrankho jvp->vol_uid = hsfs_default_uid; 651*2900Sfrankho jvp->vol_gid = hsfs_default_gid; 652*2900Sfrankho jvp->vol_prot = hsfs_default_mode; 6530Sstevel@tonic-gate 6540Sstevel@tonic-gate /* 6550Sstevel@tonic-gate * Look for a Standard File Structure Volume Descriptor, 6560Sstevel@tonic-gate * of which there must be at least one. 6570Sstevel@tonic-gate * If found, check for volume size consistency. 658*2900Sfrankho * 659*2900Sfrankho * If svp->lbn_size is != 0, we did find a ISO-9660:1999 SVD 660*2900Sfrankho * If jvp->lbn_size is != 0, we did find a Joliet SVD. 6610Sstevel@tonic-gate */ 662*2900Sfrankho fsp->hsfs_namemax = ISO_FILE_NAMELEN; 663*2900Sfrankho fsp->hsfs_namelen = ISO_FILE_NAMELEN; 664*2900Sfrankho error = hs_findisovol(fsp, devvp, &fsp->hsfs_vol, svp, jvp); 6651025Sfrankho if (error == EINVAL) /* no iso 9660 - try high sierra ... */ 6661025Sfrankho error = hs_findhsvol(fsp, devvp, &fsp->hsfs_vol); 6670Sstevel@tonic-gate 6680Sstevel@tonic-gate if (error) 6690Sstevel@tonic-gate goto cleanup; 6700Sstevel@tonic-gate 671*2900Sfrankho DTRACE_PROBE4(findvol, 672*2900Sfrankho struct hsfs *, fsp, 673*2900Sfrankho struct hs_volume *, &fsp->hsfs_vol, 674*2900Sfrankho struct hs_volume *, svp, 675*2900Sfrankho struct hs_volume *, jvp); 676*2900Sfrankho 6770Sstevel@tonic-gate /* 6780Sstevel@tonic-gate * Generate a file system ID from the CD-ROM, 6790Sstevel@tonic-gate * and check it for uniqueness. 6800Sstevel@tonic-gate * 6810Sstevel@tonic-gate * What we are aiming for is some chance of integrity 6820Sstevel@tonic-gate * across disk change. That is, if a client has an fhandle, 6830Sstevel@tonic-gate * it will be valid as long as the same disk is mounted. 6840Sstevel@tonic-gate */ 6850Sstevel@tonic-gate fsid = compute_cdrom_id(fsp, devvp); 6860Sstevel@tonic-gate 6870Sstevel@tonic-gate mutex_enter(&hs_mounttab_lock); 6880Sstevel@tonic-gate 6890Sstevel@tonic-gate if (fsid == 0 || fsid == -1) { 6900Sstevel@tonic-gate uniqtime(&tv); 6910Sstevel@tonic-gate fsid = tv.tv_sec; 6920Sstevel@tonic-gate } else /* make sure that the fsid is unique */ 6930Sstevel@tonic-gate for (tsp = hs_mounttab; tsp != NULL; tsp = tsp->hsfs_next) { 6940Sstevel@tonic-gate if (fsid == tsp->hsfs_vfs->vfs_fsid.val[0]) { 6950Sstevel@tonic-gate uniqtime(&tv); 6960Sstevel@tonic-gate fsid = tv.tv_sec; 6970Sstevel@tonic-gate break; 6980Sstevel@tonic-gate } 6990Sstevel@tonic-gate } 7000Sstevel@tonic-gate 7010Sstevel@tonic-gate fsp->hsfs_next = hs_mounttab; 7020Sstevel@tonic-gate hs_mounttab = fsp; 7030Sstevel@tonic-gate 7040Sstevel@tonic-gate fsp->hsfs_devvp = devvp; 7050Sstevel@tonic-gate fsp->hsfs_vfs = vfsp; 706*2900Sfrankho fsp->hsfs_fsmnt = kmem_alloc(pathbufsz, KM_SLEEP); 707*2900Sfrankho (void) strlcpy(fsp->hsfs_fsmnt, path, pathbufsz); 7080Sstevel@tonic-gate 7090Sstevel@tonic-gate mutex_init(&fsp->hsfs_free_lock, NULL, MUTEX_DEFAULT, NULL); 7100Sstevel@tonic-gate rw_init(&fsp->hsfs_hash_lock, NULL, RW_DEFAULT, NULL); 7110Sstevel@tonic-gate 7120Sstevel@tonic-gate vfsp->vfs_data = (caddr_t)fsp; 7130Sstevel@tonic-gate vfsp->vfs_dev = dev; 7140Sstevel@tonic-gate vfsp->vfs_fstype = hsfsfstype; 7150Sstevel@tonic-gate vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size; /* %% */ 7160Sstevel@tonic-gate vfsp->vfs_fsid.val[0] = fsid; 7170Sstevel@tonic-gate vfsp->vfs_fsid.val[1] = hsfsfstype; 7180Sstevel@tonic-gate 719*2900Sfrankho if (!hs_getrootvp(vfsp, fsp, pathbufsz)) { 720*2900Sfrankho DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp); 721*2900Sfrankho error = EINVAL; 722*2900Sfrankho goto cleanup; 723*2900Sfrankho } 724*2900Sfrankho DTRACE_PROBE1(rootvp, struct hsfs *, fsp); 725*2900Sfrankho 726*2900Sfrankho /* 727*2900Sfrankho * Attempt to discover a RR extension. 728*2900Sfrankho */ 729*2900Sfrankho if (use_rrip) { 730*2900Sfrankho hp = VTOH(fsp->hsfs_rootvp); 731*2900Sfrankho hs_check_root_dirent(fsp->hsfs_rootvp, &(hp->hs_dirent)); 732*2900Sfrankho } 733*2900Sfrankho 734*2900Sfrankho has_rrip = IS_RRIP_IMPLEMENTED(fsp); 735*2900Sfrankho has_vers2 = (svp->lbn_size != 0); 736*2900Sfrankho has_joliet = (jvp->lbn_size != 0); 737*2900Sfrankho 738*2900Sfrankho DTRACE_PROBE4(voltype__suggested, struct hsfs *, fsp, 739*2900Sfrankho int, use_rrip, int, use_vers2, int, use_joliet); 740*2900Sfrankho 741*2900Sfrankho DTRACE_PROBE4(voltype__actual, struct hsfs *, fsp, 742*2900Sfrankho int, has_rrip, int, has_vers2, int, has_joliet); 743*2900Sfrankho 744*2900Sfrankho DTRACE_PROBE4(findvol, 745*2900Sfrankho struct hsfs *, fsp, 746*2900Sfrankho struct hs_volume *, &fsp->hsfs_vol, 747*2900Sfrankho struct hs_volume *, svp, 748*2900Sfrankho struct hs_volume *, jvp); 749*2900Sfrankho 750*2900Sfrankho force_rrip_off = !use_rrip || 751*2900Sfrankho (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet) || 752*2900Sfrankho (vfs_optionisset(vfsp, HOPT_VERS2, NULL) && has_vers2); 753*2900Sfrankho 754*2900Sfrankho force_vers2_off = !use_vers2 || 755*2900Sfrankho (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet); 756*2900Sfrankho 757*2900Sfrankho force_joliet_off = !use_joliet; 758*2900Sfrankho 759*2900Sfrankho DTRACE_PROBE4(voltype__force_off, struct hsfs *, fsp, 760*2900Sfrankho int, force_rrip_off, int, force_vers2_off, int, force_joliet_off); 761*2900Sfrankho 762*2900Sfrankho /* 763*2900Sfrankho * At the moment, we have references of all three possible 764*2900Sfrankho * extensions (RR, ISO9660:1999/v2 and Joliet) if present. 765*2900Sfrankho * 766*2900Sfrankho * The "active" volume descriptor is RRIP (or ISO9660:1988). 767*2900Sfrankho * We now switch to the user-requested one. 768*2900Sfrankho */ 769*2900Sfrankho redo_rootvp = 0; 770*2900Sfrankho 771*2900Sfrankho if (force_rrip_off || !has_rrip) { 772*2900Sfrankho if (has_vers2 && !force_vers2_off) { 773*2900Sfrankho VN_RELE(fsp->hsfs_rootvp); 774*2900Sfrankho bcopy(svp, &fsp->hsfs_vol, sizeof (struct hs_volume)); 775*2900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_ISO_V2; 776*2900Sfrankho vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size; 777*2900Sfrankho redo_rootvp = 1; 778*2900Sfrankho has_joliet = 0; 779*2900Sfrankho } else if (has_joliet && !force_joliet_off) { 780*2900Sfrankho VN_RELE(fsp->hsfs_rootvp); 781*2900Sfrankho bcopy(jvp, &fsp->hsfs_vol, sizeof (struct hs_volume)); 782*2900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_JOLIET; 783*2900Sfrankho vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size; 784*2900Sfrankho redo_rootvp = 1; 785*2900Sfrankho has_vers2 = 0; 786*2900Sfrankho } 787*2900Sfrankho } 788*2900Sfrankho 789*2900Sfrankho if (redo_rootvp) { 790*2900Sfrankho /* 791*2900Sfrankho * Make sure not to use Rock Ridge. 792*2900Sfrankho */ 793*2900Sfrankho UNSET_IMPL_BIT(fsp, RRIP_BIT); 794*2900Sfrankho UNSET_SUSP_BIT(fsp); 795*2900Sfrankho has_rrip = 0; 796*2900Sfrankho 797*2900Sfrankho if (!hs_getrootvp(vfsp, fsp, pathbufsz)) { 798*2900Sfrankho DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp); 799*2900Sfrankho error = EINVAL; 800*2900Sfrankho goto cleanup; 801*2900Sfrankho } 802*2900Sfrankho DTRACE_PROBE1(rootvp, struct hsfs *, fsp); 803*2900Sfrankho } 804*2900Sfrankho if (IS_RRIP_IMPLEMENTED(fsp)) { 805*2900Sfrankho has_vers2 = 0; 806*2900Sfrankho has_joliet = 0; 807*2900Sfrankho } 808*2900Sfrankho if (force_vers2_off) 809*2900Sfrankho has_vers2 = 0; 810*2900Sfrankho if (force_joliet_off) 811*2900Sfrankho has_joliet = 0; 812*2900Sfrankho DTRACE_PROBE4(voltype__taken, struct hsfs *, fsp, 813*2900Sfrankho int, has_rrip, int, has_vers2, int, has_joliet); 814*2900Sfrankho 815*2900Sfrankho /* 816*2900Sfrankho * mark root node as VROOT 817*2900Sfrankho */ 818*2900Sfrankho fsp->hsfs_rootvp->v_flag |= VROOT; 819*2900Sfrankho 820*2900Sfrankho /* Here we take care of some special case stuff for mountroot */ 821*2900Sfrankho if (isroot) { 822*2900Sfrankho fsp->hsfs_rootvp->v_rdev = devvp->v_rdev; 823*2900Sfrankho rootvp = fsp->hsfs_rootvp; 824*2900Sfrankho } 825*2900Sfrankho 826*2900Sfrankho if (IS_RRIP_IMPLEMENTED(fsp)) { 827*2900Sfrankho /* 828*2900Sfrankho * if RRIP, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags 829*2900Sfrankho */ 830*2900Sfrankho mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT); 831*2900Sfrankho 832*2900Sfrankho fsp->hsfs_namemax = RRIP_FILE_NAMELEN; 833*2900Sfrankho fsp->hsfs_namelen = RRIP_FILE_NAMELEN; 834*2900Sfrankho 835*2900Sfrankho ASSERT(vfs_optionisset(vfsp, HOPT_RR, NULL)); 836*2900Sfrankho vfs_clearmntopt(vfsp, HOPT_VERS2); 837*2900Sfrankho vfs_clearmntopt(vfsp, HOPT_JOLIET); 838*2900Sfrankho 839*2900Sfrankho } else switch (fsp->hsfs_vol_type) { 840*2900Sfrankho 841*2900Sfrankho case HS_VOL_TYPE_HS: 842*2900Sfrankho case HS_VOL_TYPE_ISO: 843*2900Sfrankho default: 844*2900Sfrankho /* 845*2900Sfrankho * if iso v1, don't allow trailing spaces in iso file names 846*2900Sfrankho */ 847*2900Sfrankho mount_flags |= HSFSMNT_NOTRAILSPACE; 848*2900Sfrankho fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX; 849*2900Sfrankho fsp->hsfs_namelen = ISO_FILE_NAMELEN; 850*2900Sfrankho vfs_clearmntopt(vfsp, HOPT_RR); 851*2900Sfrankho vfs_clearmntopt(vfsp, HOPT_VERS2); 852*2900Sfrankho vfs_clearmntopt(vfsp, HOPT_JOLIET); 853*2900Sfrankho break; 854*2900Sfrankho 855*2900Sfrankho case HS_VOL_TYPE_ISO_V2: 856*2900Sfrankho /* 857*2900Sfrankho * if iso v2, don't copy NOTRAILDOT to hsfs_flags 858*2900Sfrankho */ 859*2900Sfrankho mount_flags &= ~HSFSMNT_NOTRAILDOT; 860*2900Sfrankho mount_flags |= HSFSMNT_NOMAPLCASE | HSFSMNT_NOVERSION; 861*2900Sfrankho fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX; 862*2900Sfrankho fsp->hsfs_namelen = ISO_NAMELEN_V2; 863*2900Sfrankho vfs_setmntopt(vfsp, HOPT_VERS2, NULL, 0); 864*2900Sfrankho vfs_clearmntopt(vfsp, HOPT_RR); 865*2900Sfrankho vfs_clearmntopt(vfsp, HOPT_JOLIET); 866*2900Sfrankho break; 867*2900Sfrankho 868*2900Sfrankho case HS_VOL_TYPE_JOLIET: 869*2900Sfrankho /* 870*2900Sfrankho * if Joliet, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags 871*2900Sfrankho */ 872*2900Sfrankho mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT); 873*2900Sfrankho mount_flags |= HSFSMNT_NOMAPLCASE; 874*2900Sfrankho if (mount_flags & HSFSMNT_JOLIETLONG) 875*2900Sfrankho fsp->hsfs_namemax = JOLIET_NAMELEN_MAX*3; /* UTF-8 */ 876*2900Sfrankho else 877*2900Sfrankho fsp->hsfs_namemax = MAXNAMELEN-1; 878*2900Sfrankho fsp->hsfs_namelen = JOLIET_NAMELEN*2; 879*2900Sfrankho vfs_setmntopt(vfsp, HOPT_JOLIET, NULL, 0); 880*2900Sfrankho vfs_clearmntopt(vfsp, HOPT_RR); 881*2900Sfrankho vfs_clearmntopt(vfsp, HOPT_VERS2); 882*2900Sfrankho break; 883*2900Sfrankho } 884*2900Sfrankho 885*2900Sfrankho fsp->hsfs_flags = mount_flags; 886*2900Sfrankho 887*2900Sfrankho DTRACE_PROBE1(mount__done, struct hsfs *, fsp); 888*2900Sfrankho 889*2900Sfrankho /* 890*2900Sfrankho * set the magic word 891*2900Sfrankho */ 892*2900Sfrankho fsp->hsfs_magic = HSFS_MAGIC; 893*2900Sfrankho mutex_exit(&hs_mounttab_lock); 894*2900Sfrankho 895*2900Sfrankho return (0); 896*2900Sfrankho 897*2900Sfrankho cleanup: 898*2900Sfrankho (void) VOP_CLOSE(devvp, FREAD, 1, (offset_t)0, cr); 899*2900Sfrankho VN_RELE(devvp); 900*2900Sfrankho if (fsp) 901*2900Sfrankho kmem_free(fsp, sizeof (*fsp)); 902*2900Sfrankho if (svp) 903*2900Sfrankho kmem_free(svp, sizeof (*svp)); 904*2900Sfrankho if (jvp) 905*2900Sfrankho kmem_free(jvp, sizeof (*jvp)); 906*2900Sfrankho return (error); 907*2900Sfrankho } 908*2900Sfrankho 909*2900Sfrankho /* 910*2900Sfrankho * Get the rootvp associated with fsp->hsfs_vol 911*2900Sfrankho */ 912*2900Sfrankho static int 913*2900Sfrankho hs_getrootvp( 914*2900Sfrankho struct vfs *vfsp, 915*2900Sfrankho struct hsfs *fsp, 916*2900Sfrankho size_t pathsize) 917*2900Sfrankho { 918*2900Sfrankho struct hsnode *hp; 919*2900Sfrankho 920*2900Sfrankho ASSERT(pathsize == strlen(fsp->hsfs_fsmnt) + 1); 921*2900Sfrankho 9220Sstevel@tonic-gate /* 9230Sstevel@tonic-gate * If the root directory does not appear to be 9240Sstevel@tonic-gate * valid, use what it points to as "." instead. 9250Sstevel@tonic-gate * Some Defense Mapping Agency disks are non-conformant 9260Sstevel@tonic-gate * in this way. 9270Sstevel@tonic-gate */ 9280Sstevel@tonic-gate if (!hsfs_valid_dir(&fsp->hsfs_vol.root_dir)) { 9290Sstevel@tonic-gate hs_log_bogus_disk_warning(fsp, HSFS_ERR_BAD_ROOT_DIR, 0); 9300Sstevel@tonic-gate if (hs_remakenode(fsp->hsfs_vol.root_dir.ext_lbn, 9310Sstevel@tonic-gate (uint_t)0, vfsp, &fsp->hsfs_rootvp)) { 9321025Sfrankho hs_mounttab = hs_mounttab->hsfs_next; 9331025Sfrankho mutex_destroy(&fsp->hsfs_free_lock); 9341025Sfrankho rw_destroy(&fsp->hsfs_hash_lock); 935*2900Sfrankho kmem_free(fsp->hsfs_fsmnt, pathsize); 936494Sfrankho mutex_exit(&hs_mounttab_lock); 937*2900Sfrankho return (0); 9380Sstevel@tonic-gate } 9390Sstevel@tonic-gate } else { 9400Sstevel@tonic-gate fsp->hsfs_rootvp = hs_makenode(&fsp->hsfs_vol.root_dir, 9410Sstevel@tonic-gate fsp->hsfs_vol.root_dir.ext_lbn, 0, vfsp); 9420Sstevel@tonic-gate } 9430Sstevel@tonic-gate 9440Sstevel@tonic-gate /* XXX - ignore the path table for now */ 9450Sstevel@tonic-gate fsp->hsfs_ptbl = NULL; 9460Sstevel@tonic-gate hp = VTOH(fsp->hsfs_rootvp); 9470Sstevel@tonic-gate hp->hs_ptbl_idx = NULL; 9480Sstevel@tonic-gate 949*2900Sfrankho return (1); 9500Sstevel@tonic-gate } 9510Sstevel@tonic-gate 9520Sstevel@tonic-gate /* 9530Sstevel@tonic-gate * hs_findhsvol() 9540Sstevel@tonic-gate * 9550Sstevel@tonic-gate * Locate the Standard File Structure Volume Descriptor and 9560Sstevel@tonic-gate * parse it into an hs_volume structure. 9570Sstevel@tonic-gate * 9580Sstevel@tonic-gate * XXX - May someday want to look for Coded Character Set FSVD, too. 9590Sstevel@tonic-gate */ 9600Sstevel@tonic-gate static int 9610Sstevel@tonic-gate hs_findhsvol(struct hsfs *fsp, struct vnode *vp, struct hs_volume *hvp) 9620Sstevel@tonic-gate { 9630Sstevel@tonic-gate struct buf *secbp; 9640Sstevel@tonic-gate int i; 9650Sstevel@tonic-gate uchar_t *volp; 9660Sstevel@tonic-gate int error; 9670Sstevel@tonic-gate uint_t secno; 9680Sstevel@tonic-gate 9690Sstevel@tonic-gate secno = hs_findvoldesc(vp->v_rdev, HS_VOLDESC_SEC); 9700Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE); 9710Sstevel@tonic-gate error = geterror(secbp); 9720Sstevel@tonic-gate 9730Sstevel@tonic-gate if (error != 0) { 9740Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)", error); 9750Sstevel@tonic-gate brelse(secbp); 9760Sstevel@tonic-gate return (error); 9770Sstevel@tonic-gate } 9780Sstevel@tonic-gate 9790Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 9800Sstevel@tonic-gate 9810Sstevel@tonic-gate while (HSV_DESC_TYPE(volp) != VD_EOV) { 9820Sstevel@tonic-gate for (i = 0; i < HSV_ID_STRLEN; i++) 9830Sstevel@tonic-gate if (HSV_STD_ID(volp)[i] != HSV_ID_STRING[i]) 9840Sstevel@tonic-gate goto cantfind; 9850Sstevel@tonic-gate if (HSV_STD_VER(volp) != HSV_ID_VER) 9860Sstevel@tonic-gate goto cantfind; 9870Sstevel@tonic-gate switch (HSV_DESC_TYPE(volp)) { 9880Sstevel@tonic-gate case VD_SFS: 9890Sstevel@tonic-gate /* Standard File Structure */ 9900Sstevel@tonic-gate fsp->hsfs_vol_type = HS_VOL_TYPE_HS; 9910Sstevel@tonic-gate error = hs_parsehsvol(fsp, volp, hvp); 9920Sstevel@tonic-gate brelse(secbp); 9930Sstevel@tonic-gate return (error); 9940Sstevel@tonic-gate 9950Sstevel@tonic-gate case VD_CCFS: 9960Sstevel@tonic-gate /* Coded Character File Structure */ 9970Sstevel@tonic-gate case VD_BOOT: 9980Sstevel@tonic-gate case VD_UNSPEC: 9990Sstevel@tonic-gate case VD_EOV: 10000Sstevel@tonic-gate break; 10010Sstevel@tonic-gate } 10020Sstevel@tonic-gate brelse(secbp); 10030Sstevel@tonic-gate ++secno; 10040Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE); 10050Sstevel@tonic-gate 10060Sstevel@tonic-gate error = geterror(secbp); 10070Sstevel@tonic-gate 10080Sstevel@tonic-gate if (error != 0) { 10090Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)", 10100Sstevel@tonic-gate error); 10110Sstevel@tonic-gate brelse(secbp); 10120Sstevel@tonic-gate return (error); 10130Sstevel@tonic-gate } 10140Sstevel@tonic-gate 10150Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 10160Sstevel@tonic-gate } 10170Sstevel@tonic-gate cantfind: 10180Sstevel@tonic-gate brelse(secbp); 10190Sstevel@tonic-gate return (EINVAL); 10200Sstevel@tonic-gate } 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate /* 10230Sstevel@tonic-gate * hs_parsehsvol 10240Sstevel@tonic-gate * 10250Sstevel@tonic-gate * Parse the Standard File Structure Volume Descriptor into 10260Sstevel@tonic-gate * an hs_volume structure. We can't just bcopy it into the 10270Sstevel@tonic-gate * structure because of byte-ordering problems. 10280Sstevel@tonic-gate * 10290Sstevel@tonic-gate */ 10300Sstevel@tonic-gate static int 10310Sstevel@tonic-gate hs_parsehsvol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp) 10320Sstevel@tonic-gate { 10330Sstevel@tonic-gate hvp->vol_size = HSV_VOL_SIZE(volp); 10340Sstevel@tonic-gate hvp->lbn_size = HSV_BLK_SIZE(volp); 10350Sstevel@tonic-gate if (hvp->lbn_size == 0) { 10360Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_parsehsvol: logical block size in the " 10370Sstevel@tonic-gate "SFSVD is zero"); 10380Sstevel@tonic-gate return (EINVAL); 10390Sstevel@tonic-gate } 10400Sstevel@tonic-gate hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1; 10410Sstevel@tonic-gate hvp->lbn_secshift = ffs((long)howmany(HS_SECTOR_SIZE, 10420Sstevel@tonic-gate (int)hvp->lbn_size)) - 1; 10430Sstevel@tonic-gate hvp->lbn_maxoffset = hvp->lbn_size - 1; 10440Sstevel@tonic-gate hs_parse_longdate(HSV_cre_date(volp), &hvp->cre_date); 10450Sstevel@tonic-gate hs_parse_longdate(HSV_mod_date(volp), &hvp->mod_date); 10460Sstevel@tonic-gate hvp->file_struct_ver = HSV_FILE_STRUCT_VER(volp); 10470Sstevel@tonic-gate hvp->ptbl_len = HSV_PTBL_SIZE(volp); 10480Sstevel@tonic-gate hvp->vol_set_size = (ushort_t)HSV_SET_SIZE(volp); 10490Sstevel@tonic-gate hvp->vol_set_seq = (ushort_t)HSV_SET_SEQ(volp); 10500Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 10510Sstevel@tonic-gate hvp->ptbl_lbn = HSV_PTBL_MAN_LS(volp); 10520Sstevel@tonic-gate #else 10530Sstevel@tonic-gate hvp->ptbl_lbn = HSV_PTBL_MAN_MS(volp); 10540Sstevel@tonic-gate #endif 1055*2900Sfrankho hs_copylabel(hvp, HSV_VOL_ID(volp), 0); 10560Sstevel@tonic-gate 10570Sstevel@tonic-gate /* 10580Sstevel@tonic-gate * Make sure that lbn_size is a power of two and otherwise valid. 10590Sstevel@tonic-gate */ 10600Sstevel@tonic-gate if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) { 10610Sstevel@tonic-gate cmn_err(CE_NOTE, 10620Sstevel@tonic-gate "hsfs: %d-byte logical block size not supported", 10630Sstevel@tonic-gate hvp->lbn_size); 10640Sstevel@tonic-gate return (EINVAL); 10650Sstevel@tonic-gate } 10660Sstevel@tonic-gate return (hs_parsedir(fsp, HSV_ROOT_DIR(volp), &hvp->root_dir, 1067*2900Sfrankho (char *)NULL, (int *)NULL, HDE_ROOT_DIR_REC_SIZE)); 10680Sstevel@tonic-gate } 10690Sstevel@tonic-gate 10700Sstevel@tonic-gate /* 10710Sstevel@tonic-gate * hs_findisovol() 10720Sstevel@tonic-gate * 10730Sstevel@tonic-gate * Locate the Primary Volume Descriptor 10740Sstevel@tonic-gate * parse it into an hs_volume structure. 10750Sstevel@tonic-gate * 1076*2900Sfrankho * XXX - Partition not yet done 1077*2900Sfrankho * 1078*2900Sfrankho * Except for fsp->hsfs_vol_type, no fsp member may be modified. 1079*2900Sfrankho * fsp->hsfs_vol is modified indirectly via the *hvp argument. 10800Sstevel@tonic-gate */ 10810Sstevel@tonic-gate static int 10820Sstevel@tonic-gate hs_findisovol(struct hsfs *fsp, struct vnode *vp, 1083*2900Sfrankho struct hs_volume *hvp, 1084*2900Sfrankho struct hs_volume *svp, 1085*2900Sfrankho struct hs_volume *jvp) 10860Sstevel@tonic-gate { 10870Sstevel@tonic-gate struct buf *secbp; 10880Sstevel@tonic-gate int i; 10890Sstevel@tonic-gate uchar_t *volp; 10900Sstevel@tonic-gate int error; 10910Sstevel@tonic-gate uint_t secno; 10920Sstevel@tonic-gate int foundpvd = 0; 1093*2900Sfrankho int foundsvd = 0; 1094*2900Sfrankho int foundjvd = 0; 10950Sstevel@tonic-gate 10960Sstevel@tonic-gate secno = hs_findvoldesc(vp->v_rdev, ISO_VOLDESC_SEC); 10970Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, ISO_SECTOR_SIZE); 10980Sstevel@tonic-gate error = geterror(secbp); 10990Sstevel@tonic-gate 11000Sstevel@tonic-gate if (error != 0) { 11010Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)", error); 11020Sstevel@tonic-gate brelse(secbp); 11030Sstevel@tonic-gate return (error); 11040Sstevel@tonic-gate } 11050Sstevel@tonic-gate 11060Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 11070Sstevel@tonic-gate 11080Sstevel@tonic-gate while ((enum iso_voldesc_type) ISO_DESC_TYPE(volp) != ISO_VD_EOV) { 11090Sstevel@tonic-gate for (i = 0; i < ISO_ID_STRLEN; i++) 11100Sstevel@tonic-gate if (ISO_STD_ID(volp)[i] != ISO_ID_STRING[i]) 11110Sstevel@tonic-gate goto cantfind; 11120Sstevel@tonic-gate switch (ISO_DESC_TYPE(volp)) { 11130Sstevel@tonic-gate case ISO_VD_PVD: 11140Sstevel@tonic-gate /* Standard File Structure */ 1115*2900Sfrankho if (ISO_STD_VER(volp) != ISO_ID_VER) 1116*2900Sfrankho goto cantfind; 11170Sstevel@tonic-gate if (foundpvd != 1) { 11180Sstevel@tonic-gate fsp->hsfs_vol_type = HS_VOL_TYPE_ISO; 11190Sstevel@tonic-gate if (error = hs_parseisovol(fsp, volp, hvp)) { 11200Sstevel@tonic-gate brelse(secbp); 11210Sstevel@tonic-gate return (error); 11220Sstevel@tonic-gate } 11230Sstevel@tonic-gate foundpvd = 1; 11240Sstevel@tonic-gate } 11250Sstevel@tonic-gate break; 11260Sstevel@tonic-gate case ISO_VD_SVD: 11270Sstevel@tonic-gate /* Supplementary Volume Descriptor */ 1128*2900Sfrankho if (ISO_STD_VER(volp) == ISO_ID_VER2 && 1129*2900Sfrankho foundsvd != 1) { 1130*2900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_ISO; 1131*2900Sfrankho if (error = hs_parseisovol(fsp, volp, svp)) { 1132*2900Sfrankho brelse(secbp); 1133*2900Sfrankho return (error); 1134*2900Sfrankho } 1135*2900Sfrankho foundsvd = 1; 1136*2900Sfrankho } 1137*2900Sfrankho if (hs_joliet_level(volp) >= 1 && foundjvd != 1) { 1138*2900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_ISO; 1139*2900Sfrankho if (error = hs_parseisovol(fsp, volp, jvp)) { 1140*2900Sfrankho brelse(secbp); 1141*2900Sfrankho return (error); 1142*2900Sfrankho } 1143*2900Sfrankho foundjvd = 1; 1144*2900Sfrankho } 11450Sstevel@tonic-gate break; 11460Sstevel@tonic-gate case ISO_VD_BOOT: 11470Sstevel@tonic-gate break; 11480Sstevel@tonic-gate case ISO_VD_VPD: 11490Sstevel@tonic-gate /* currently cannot handle partition */ 11500Sstevel@tonic-gate break; 11510Sstevel@tonic-gate case VD_EOV: 11520Sstevel@tonic-gate break; 11530Sstevel@tonic-gate } 11540Sstevel@tonic-gate brelse(secbp); 11550Sstevel@tonic-gate ++secno; 11560Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE); 11570Sstevel@tonic-gate error = geterror(secbp); 11580Sstevel@tonic-gate 11590Sstevel@tonic-gate if (error != 0) { 11600Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)", 11610Sstevel@tonic-gate error); 11620Sstevel@tonic-gate brelse(secbp); 11630Sstevel@tonic-gate return (error); 11640Sstevel@tonic-gate } 11650Sstevel@tonic-gate 11660Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 11670Sstevel@tonic-gate } 11680Sstevel@tonic-gate if (foundpvd) { 11690Sstevel@tonic-gate brelse(secbp); 11700Sstevel@tonic-gate return (0); 11710Sstevel@tonic-gate } 11720Sstevel@tonic-gate cantfind: 11730Sstevel@tonic-gate brelse(secbp); 11740Sstevel@tonic-gate return (EINVAL); 11750Sstevel@tonic-gate } 1176*2900Sfrankho 1177*2900Sfrankho /* 1178*2900Sfrankho * Return 0 if no Joliet is found 1179*2900Sfrankho * else return Joliet Level 1..3 1180*2900Sfrankho */ 1181*2900Sfrankho static int 1182*2900Sfrankho hs_joliet_level(uchar_t *volp) 1183*2900Sfrankho { 1184*2900Sfrankho if (ISO_std_ver(volp)[0] == ISO_ID_VER && 1185*2900Sfrankho ISO_svd_esc(volp)[0] == '%' && 1186*2900Sfrankho ISO_svd_esc(volp)[1] == '/') { 1187*2900Sfrankho 1188*2900Sfrankho switch (ISO_svd_esc(volp)[2]) { 1189*2900Sfrankho 1190*2900Sfrankho case '@': 1191*2900Sfrankho return (1); 1192*2900Sfrankho case 'C': 1193*2900Sfrankho return (2); 1194*2900Sfrankho case 'E': 1195*2900Sfrankho return (3); 1196*2900Sfrankho } 1197*2900Sfrankho } 1198*2900Sfrankho return (0); 1199*2900Sfrankho } 1200*2900Sfrankho 12010Sstevel@tonic-gate /* 12020Sstevel@tonic-gate * hs_parseisovol 12030Sstevel@tonic-gate * 12040Sstevel@tonic-gate * Parse the Primary Volume Descriptor into an hs_volume structure. 12050Sstevel@tonic-gate * 12060Sstevel@tonic-gate */ 12070Sstevel@tonic-gate static int 12080Sstevel@tonic-gate hs_parseisovol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp) 12090Sstevel@tonic-gate { 12100Sstevel@tonic-gate hvp->vol_size = ISO_VOL_SIZE(volp); 12110Sstevel@tonic-gate hvp->lbn_size = ISO_BLK_SIZE(volp); 12120Sstevel@tonic-gate if (hvp->lbn_size == 0) { 12130Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_parseisovol: logical block size in the " 12140Sstevel@tonic-gate "PVD is zero"); 12150Sstevel@tonic-gate return (EINVAL); 12160Sstevel@tonic-gate } 12170Sstevel@tonic-gate hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1; 12180Sstevel@tonic-gate hvp->lbn_secshift = ffs((long)howmany(ISO_SECTOR_SIZE, 12190Sstevel@tonic-gate (int)hvp->lbn_size)) - 1; 12200Sstevel@tonic-gate hvp->lbn_maxoffset = hvp->lbn_size - 1; 12210Sstevel@tonic-gate hs_parse_longdate(ISO_cre_date(volp), &hvp->cre_date); 12220Sstevel@tonic-gate hs_parse_longdate(ISO_mod_date(volp), &hvp->mod_date); 12230Sstevel@tonic-gate hvp->file_struct_ver = ISO_FILE_STRUCT_VER(volp); 12240Sstevel@tonic-gate hvp->ptbl_len = ISO_PTBL_SIZE(volp); 12250Sstevel@tonic-gate hvp->vol_set_size = (ushort_t)ISO_SET_SIZE(volp); 12260Sstevel@tonic-gate hvp->vol_set_seq = (ushort_t)ISO_SET_SEQ(volp); 12270Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 12280Sstevel@tonic-gate hvp->ptbl_lbn = ISO_PTBL_MAN_LS(volp); 12290Sstevel@tonic-gate #else 12300Sstevel@tonic-gate hvp->ptbl_lbn = ISO_PTBL_MAN_MS(volp); 12310Sstevel@tonic-gate #endif 1232*2900Sfrankho hs_copylabel(hvp, ISO_VOL_ID(volp), hs_joliet_level(volp) >= 1); 12330Sstevel@tonic-gate 12340Sstevel@tonic-gate /* 12350Sstevel@tonic-gate * Make sure that lbn_size is a power of two and otherwise valid. 12360Sstevel@tonic-gate */ 12370Sstevel@tonic-gate if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) { 12380Sstevel@tonic-gate cmn_err(CE_NOTE, 12390Sstevel@tonic-gate "hsfs: %d-byte logical block size not supported", 12400Sstevel@tonic-gate hvp->lbn_size); 12410Sstevel@tonic-gate return (EINVAL); 12420Sstevel@tonic-gate } 12430Sstevel@tonic-gate return (hs_parsedir(fsp, ISO_ROOT_DIR(volp), &hvp->root_dir, 1244*2900Sfrankho (char *)NULL, (int *)NULL, IDE_ROOT_DIR_REC_SIZE)); 12450Sstevel@tonic-gate } 12460Sstevel@tonic-gate 12470Sstevel@tonic-gate /* 12480Sstevel@tonic-gate * Common code for mount and umount. 12490Sstevel@tonic-gate * Check that the user's argument is a reasonable 12500Sstevel@tonic-gate * thing on which to mount, and return the device number if so. 12510Sstevel@tonic-gate */ 12520Sstevel@tonic-gate static int 12530Sstevel@tonic-gate hs_getmdev(struct vfs *vfsp, char *fspec, int flags, dev_t *pdev, mode_t *mode, 12540Sstevel@tonic-gate cred_t *cr) 12550Sstevel@tonic-gate { 12560Sstevel@tonic-gate int error; 12570Sstevel@tonic-gate struct vnode *vp; 12580Sstevel@tonic-gate struct vattr vap; 12590Sstevel@tonic-gate dev_t dev; 12600Sstevel@tonic-gate 12610Sstevel@tonic-gate /* 12620Sstevel@tonic-gate * Get the device to be mounted 12630Sstevel@tonic-gate */ 12640Sstevel@tonic-gate error = lookupname(fspec, (flags & MS_SYSSPACE) ? 12650Sstevel@tonic-gate UIO_SYSSPACE : UIO_USERSPACE, FOLLOW, NULLVPP, &vp); 12660Sstevel@tonic-gate if (error) { 12670Sstevel@tonic-gate if (error == ENOENT) { 12680Sstevel@tonic-gate return (ENODEV); /* needs translation */ 12690Sstevel@tonic-gate } 12700Sstevel@tonic-gate return (error); 12710Sstevel@tonic-gate } 12720Sstevel@tonic-gate if (vp->v_type != VBLK) { 12730Sstevel@tonic-gate VN_RELE(vp); 12740Sstevel@tonic-gate return (ENOTBLK); 12750Sstevel@tonic-gate } 12760Sstevel@tonic-gate /* 12770Sstevel@tonic-gate * Can we read from the device? 12780Sstevel@tonic-gate */ 12790Sstevel@tonic-gate if ((error = VOP_ACCESS(vp, VREAD, 0, cr)) != 0 || 12800Sstevel@tonic-gate (error = secpolicy_spec_open(cr, vp, FREAD)) != 0) { 12810Sstevel@tonic-gate VN_RELE(vp); 12820Sstevel@tonic-gate return (error); 12830Sstevel@tonic-gate } 12840Sstevel@tonic-gate 12850Sstevel@tonic-gate vap.va_mask = AT_MODE; /* get protection mode */ 12860Sstevel@tonic-gate (void) VOP_GETATTR(vp, &vap, 0, CRED()); 12870Sstevel@tonic-gate *mode = vap.va_mode; 12880Sstevel@tonic-gate 12890Sstevel@tonic-gate dev = *pdev = vp->v_rdev; 12900Sstevel@tonic-gate VN_RELE(vp); 12910Sstevel@tonic-gate 12920Sstevel@tonic-gate /* 12930Sstevel@tonic-gate * Ensure that this device isn't already mounted, 12940Sstevel@tonic-gate * unless this is a REMOUNT request or we are told to suppress 12950Sstevel@tonic-gate * mount checks. 12960Sstevel@tonic-gate */ 12970Sstevel@tonic-gate if ((flags & MS_NOCHECK) == 0) { 12980Sstevel@tonic-gate if (vfs_devmounting(dev, vfsp)) 12990Sstevel@tonic-gate return (EBUSY); 13000Sstevel@tonic-gate if (vfs_devismounted(dev) && !(flags & MS_REMOUNT)) 13010Sstevel@tonic-gate return (EBUSY); 13020Sstevel@tonic-gate } 13030Sstevel@tonic-gate 13040Sstevel@tonic-gate if (getmajor(*pdev) >= devcnt) 13050Sstevel@tonic-gate return (ENXIO); 13060Sstevel@tonic-gate return (0); 13070Sstevel@tonic-gate } 13080Sstevel@tonic-gate 13090Sstevel@tonic-gate static void 1310*2900Sfrankho hs_copylabel(struct hs_volume *hvp, unsigned char *label, int isjoliet) 13110Sstevel@tonic-gate { 1312*2900Sfrankho char lbuf[64]; /* hs_joliet_cp() creates 48 bytes at most */ 1313*2900Sfrankho 1314*2900Sfrankho if (isjoliet) { 1315*2900Sfrankho /* 1316*2900Sfrankho * hs_joliet_cp() will output 16..48 bytes. 1317*2900Sfrankho * We need to clear 'lbuf' to avoid junk chars past byte 15. 1318*2900Sfrankho */ 1319*2900Sfrankho bzero(lbuf, sizeof (lbuf)); 1320*2900Sfrankho hs_joliet_cp((char *)label, lbuf, 32); 1321*2900Sfrankho label = (unsigned char *)lbuf; 1322*2900Sfrankho } 13230Sstevel@tonic-gate /* cdrom volid is at most 32 bytes */ 13240Sstevel@tonic-gate bcopy(label, hvp->vol_id, 32); 13250Sstevel@tonic-gate hvp->vol_id[31] = NULL; 13260Sstevel@tonic-gate } 13270Sstevel@tonic-gate 13280Sstevel@tonic-gate /* 13290Sstevel@tonic-gate * Mount root file system. 13300Sstevel@tonic-gate * "why" is ROOT_INIT on initial call, ROOT_REMOUNT if called to 13310Sstevel@tonic-gate * remount the root file system, and ROOT_UNMOUNT if called to 13320Sstevel@tonic-gate * unmount the root (e.g., as part of a system shutdown). 13330Sstevel@tonic-gate * 13340Sstevel@tonic-gate * XXX - this may be partially machine-dependent; it, along with the VFS_SWAPVP 13350Sstevel@tonic-gate * operation, goes along with auto-configuration. A mechanism should be 13360Sstevel@tonic-gate * provided by which machine-INdependent code in the kernel can say "get me the 13370Sstevel@tonic-gate * right root file system" and "get me the right initial swap area", and have 13380Sstevel@tonic-gate * that done in what may well be a machine-dependent fashion. 13390Sstevel@tonic-gate * Unfortunately, it is also file-system-type dependent (NFS gets it via 13400Sstevel@tonic-gate * bootparams calls, UFS gets it from various and sundry machine-dependent 13410Sstevel@tonic-gate * mechanisms, as SPECFS does for swap). 13420Sstevel@tonic-gate */ 13430Sstevel@tonic-gate static int 13440Sstevel@tonic-gate hsfs_mountroot(struct vfs *vfsp, enum whymountroot why) 13450Sstevel@tonic-gate { 13460Sstevel@tonic-gate int error; 13470Sstevel@tonic-gate struct hsfs *fsp; 13480Sstevel@tonic-gate struct hs_volume *fvolp; 13490Sstevel@tonic-gate static int hsfsrootdone = 0; 13500Sstevel@tonic-gate dev_t rootdev; 13510Sstevel@tonic-gate mode_t mode = 0; 13520Sstevel@tonic-gate 13530Sstevel@tonic-gate if (why == ROOT_INIT) { 13540Sstevel@tonic-gate if (hsfsrootdone++) 13550Sstevel@tonic-gate return (EBUSY); 13560Sstevel@tonic-gate rootdev = getrootdev(); 13570Sstevel@tonic-gate if (rootdev == (dev_t)NODEV) 13580Sstevel@tonic-gate return (ENODEV); 13590Sstevel@tonic-gate vfsp->vfs_dev = rootdev; 13600Sstevel@tonic-gate vfsp->vfs_flag |= VFS_RDONLY; 13610Sstevel@tonic-gate } else if (why == ROOT_REMOUNT) { 13620Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: ROOT_REMOUNT"); 13630Sstevel@tonic-gate return (0); 13640Sstevel@tonic-gate } else if (why == ROOT_UNMOUNT) { 13650Sstevel@tonic-gate return (0); 13660Sstevel@tonic-gate } 13670Sstevel@tonic-gate error = vfs_lock(vfsp); 13680Sstevel@tonic-gate if (error) { 13690Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: couldn't get vfs_lock"); 13700Sstevel@tonic-gate return (error); 13710Sstevel@tonic-gate } 13720Sstevel@tonic-gate 13730Sstevel@tonic-gate error = hs_mountfs(vfsp, rootdev, "/", mode, 1, CRED(), 1); 13740Sstevel@tonic-gate /* 13750Sstevel@tonic-gate * XXX - assumes root device is not indirect, because we don't set 13760Sstevel@tonic-gate * rootvp. Is rootvp used for anything? If so, make another arg 13770Sstevel@tonic-gate * to mountfs. 13780Sstevel@tonic-gate */ 13790Sstevel@tonic-gate if (error) { 13800Sstevel@tonic-gate vfs_unlock(vfsp); 13810Sstevel@tonic-gate if (rootvp) { 13820Sstevel@tonic-gate VN_RELE(rootvp); 13830Sstevel@tonic-gate rootvp = (struct vnode *)0; 13840Sstevel@tonic-gate } 13850Sstevel@tonic-gate return (error); 13860Sstevel@tonic-gate } 13870Sstevel@tonic-gate if (why == ROOT_INIT) 13880Sstevel@tonic-gate vfs_add((struct vnode *)0, vfsp, 13890Sstevel@tonic-gate (vfsp->vfs_flag & VFS_RDONLY) ? MS_RDONLY : 0); 13900Sstevel@tonic-gate vfs_unlock(vfsp); 13910Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp); 13920Sstevel@tonic-gate fvolp = &fsp->hsfs_vol; 13930Sstevel@tonic-gate #ifdef HSFS_CLKSET 13940Sstevel@tonic-gate if (fvolp->cre_date.tv_sec == 0) { 13950Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: cre_date.tv_sec == 0"); 13960Sstevel@tonic-gate if (fvolp->mod_date.tv_sec == 0) { 13970Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: mod_date.tv_sec == 0"); 13980Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: clkset(-1L)"); 13990Sstevel@tonic-gate clkset(-1L); 14000Sstevel@tonic-gate } else 14010Sstevel@tonic-gate clkset(fvolp->mod_date.tv_sec); 14020Sstevel@tonic-gate } else 14030Sstevel@tonic-gate clkset(fvolp->mod_date.tv_sec); 14040Sstevel@tonic-gate #else /* HSFS_CLKSET */ 14050Sstevel@tonic-gate clkset(-1L); 14060Sstevel@tonic-gate #endif /* HSFS_CLKSET */ 14070Sstevel@tonic-gate return (0); 14080Sstevel@tonic-gate } 14090Sstevel@tonic-gate 14100Sstevel@tonic-gate /* 14110Sstevel@tonic-gate * hs_findvoldesc() 14120Sstevel@tonic-gate * 14130Sstevel@tonic-gate * Return the sector where the volume descriptor lives. This is 14140Sstevel@tonic-gate * a fixed value for "normal" cd-rom's, but can change for 14150Sstevel@tonic-gate * multisession cd's. 14160Sstevel@tonic-gate * 14170Sstevel@tonic-gate * desc_sec is the same for high-sierra and iso 9660 formats, why 14180Sstevel@tonic-gate * there are two differnt #defines used in the code for this is 14190Sstevel@tonic-gate * beyond me. These are standards, cast in concrete, right? 14200Sstevel@tonic-gate * To be general, however, this function supports passing in different 14210Sstevel@tonic-gate * values. 14220Sstevel@tonic-gate */ 14230Sstevel@tonic-gate static int 14240Sstevel@tonic-gate hs_findvoldesc(dev_t rdev, int desc_sec) 14250Sstevel@tonic-gate { 14260Sstevel@tonic-gate int secno; 14270Sstevel@tonic-gate int error; 14280Sstevel@tonic-gate int rval; /* ignored */ 14290Sstevel@tonic-gate 14300Sstevel@tonic-gate #ifdef CDROMREADOFFSET 14310Sstevel@tonic-gate /* 14320Sstevel@tonic-gate * Issue the Read Offset ioctl directly to the 14330Sstevel@tonic-gate * device. Ignore any errors and set starting 14340Sstevel@tonic-gate * secno to the default, otherwise add the 14350Sstevel@tonic-gate * VOLDESC sector number to the offset. 14360Sstevel@tonic-gate */ 14370Sstevel@tonic-gate error = cdev_ioctl(rdev, CDROMREADOFFSET, (intptr_t)&secno, 14380Sstevel@tonic-gate FNATIVE|FKIOCTL|FREAD, CRED(), &rval); 14390Sstevel@tonic-gate if (error) { 14400Sstevel@tonic-gate secno = desc_sec; 14410Sstevel@tonic-gate } else { 14420Sstevel@tonic-gate secno += desc_sec; 14430Sstevel@tonic-gate } 14440Sstevel@tonic-gate #else 14450Sstevel@tonic-gate secno = desc_sec; 14460Sstevel@tonic-gate #endif 14470Sstevel@tonic-gate 14480Sstevel@tonic-gate return (secno); 14490Sstevel@tonic-gate } 1450