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 /* 223898Srsb * Copyright 2007 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> 463898Srsb #include <sys/vfs_opreg.h> 470Sstevel@tonic-gate #include <sys/vnode.h> 480Sstevel@tonic-gate #include <sys/file.h> 490Sstevel@tonic-gate #include <sys/uio.h> 500Sstevel@tonic-gate #include <sys/conf.h> 510Sstevel@tonic-gate #include <sys/policy.h> 520Sstevel@tonic-gate 530Sstevel@tonic-gate #include <vm/page.h> 540Sstevel@tonic-gate 550Sstevel@tonic-gate #include <sys/fs/snode.h> 560Sstevel@tonic-gate #include <sys/fs/hsfs_spec.h> 570Sstevel@tonic-gate #include <sys/fs/hsfs_isospec.h> 580Sstevel@tonic-gate #include <sys/fs/hsfs_node.h> 590Sstevel@tonic-gate #include <sys/fs/hsfs_impl.h> 600Sstevel@tonic-gate #include <sys/fs/hsfs_susp.h> 610Sstevel@tonic-gate #include <sys/fs/hsfs_rrip.h> 620Sstevel@tonic-gate 630Sstevel@tonic-gate #include <sys/statvfs.h> 640Sstevel@tonic-gate #include <sys/mount.h> 650Sstevel@tonic-gate #include <sys/mntent.h> 660Sstevel@tonic-gate #include <sys/swap.h> 670Sstevel@tonic-gate #include <sys/errno.h> 680Sstevel@tonic-gate #include <sys/debug.h> 690Sstevel@tonic-gate #include "fs/fs_subr.h" 700Sstevel@tonic-gate #include <sys/cmn_err.h> 710Sstevel@tonic-gate #include <sys/bootconf.h> 720Sstevel@tonic-gate 732900Sfrankho #include <sys/sdt.h> 742900Sfrankho 750Sstevel@tonic-gate /* 760Sstevel@tonic-gate * These are needed for the CDROMREADOFFSET Code 770Sstevel@tonic-gate */ 780Sstevel@tonic-gate #include <sys/cdio.h> 790Sstevel@tonic-gate #include <sys/sunddi.h> 800Sstevel@tonic-gate 810Sstevel@tonic-gate #define HSFS_CLKSET 820Sstevel@tonic-gate 830Sstevel@tonic-gate #include <sys/modctl.h> 840Sstevel@tonic-gate 850Sstevel@tonic-gate /* 860Sstevel@tonic-gate * Options for mount. 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate #define HOPT_GLOBAL MNTOPT_GLOBAL 890Sstevel@tonic-gate #define HOPT_NOGLOBAL MNTOPT_NOGLOBAL 900Sstevel@tonic-gate #define HOPT_MAPLCASE "maplcase" 910Sstevel@tonic-gate #define HOPT_NOMAPLCASE "nomaplcase" 920Sstevel@tonic-gate #define HOPT_NOTRAILDOT "notraildot" 930Sstevel@tonic-gate #define HOPT_TRAILDOT "traildot" 940Sstevel@tonic-gate #define HOPT_NRR "nrr" 950Sstevel@tonic-gate #define HOPT_RR "rr" 962900Sfrankho #define HOPT_JOLIET "joliet" 972900Sfrankho #define HOPT_NOJOLIET "nojoliet" 982900Sfrankho #define HOPT_JOLIETLONG "jolietlong" 992900Sfrankho #define HOPT_VERS2 "vers2" 1002900Sfrankho #define HOPT_NOVERS2 "novers2" 1010Sstevel@tonic-gate #define HOPT_RO MNTOPT_RO 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate static char *global_cancel[] = { HOPT_NOGLOBAL, NULL }; 1040Sstevel@tonic-gate static char *noglobal_cancel[] = { HOPT_GLOBAL, NULL }; 1050Sstevel@tonic-gate static char *mapl_cancel[] = { HOPT_NOMAPLCASE, NULL }; 1060Sstevel@tonic-gate static char *nomapl_cancel[] = { HOPT_MAPLCASE, NULL }; 1070Sstevel@tonic-gate static char *ro_cancel[] = { MNTOPT_RW, NULL }; 1080Sstevel@tonic-gate static char *rr_cancel[] = { HOPT_NRR, NULL }; 1090Sstevel@tonic-gate static char *nrr_cancel[] = { HOPT_RR, NULL }; 1102900Sfrankho static char *joliet_cancel[] = { HOPT_NOJOLIET, NULL }; 1112900Sfrankho static char *nojoliet_cancel[] = { HOPT_JOLIET, NULL }; 1122900Sfrankho static char *vers2_cancel[] = { HOPT_NOVERS2, NULL }; 1132900Sfrankho static char *novers2_cancel[] = { HOPT_VERS2, NULL }; 1140Sstevel@tonic-gate static char *trail_cancel[] = { HOPT_NOTRAILDOT, NULL }; 1150Sstevel@tonic-gate static char *notrail_cancel[] = { HOPT_TRAILDOT, NULL }; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate static mntopt_t hsfs_options[] = { 1180Sstevel@tonic-gate { HOPT_GLOBAL, global_cancel, NULL, 0, NULL }, 1190Sstevel@tonic-gate { HOPT_NOGLOBAL, noglobal_cancel, NULL, MO_DEFAULT, NULL }, 1200Sstevel@tonic-gate { HOPT_MAPLCASE, mapl_cancel, NULL, MO_DEFAULT, NULL }, 1210Sstevel@tonic-gate { HOPT_NOMAPLCASE, nomapl_cancel, NULL, 0, NULL }, 1220Sstevel@tonic-gate { HOPT_RO, ro_cancel, NULL, MO_DEFAULT, NULL }, 1230Sstevel@tonic-gate { HOPT_RR, rr_cancel, NULL, MO_DEFAULT, NULL }, 1240Sstevel@tonic-gate { HOPT_NRR, nrr_cancel, NULL, 0, NULL }, 1252900Sfrankho { HOPT_JOLIET, joliet_cancel, NULL, 0, NULL }, 1262900Sfrankho { HOPT_NOJOLIET, nojoliet_cancel, NULL, 0, NULL }, 1272900Sfrankho { HOPT_JOLIETLONG, NULL, NULL, 0, NULL }, 1282900Sfrankho { HOPT_VERS2, vers2_cancel, NULL, 0, NULL }, 1292900Sfrankho { HOPT_NOVERS2, novers2_cancel, NULL, 0, NULL }, 1300Sstevel@tonic-gate { HOPT_TRAILDOT, trail_cancel, NULL, MO_DEFAULT, NULL }, 1310Sstevel@tonic-gate { HOPT_NOTRAILDOT, notrail_cancel, NULL, 0, NULL }, 1322900Sfrankho { "sector", NULL, "0", MO_HASVALUE, NULL}, 1330Sstevel@tonic-gate }; 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate static mntopts_t hsfs_proto_opttbl = { 1360Sstevel@tonic-gate sizeof (hsfs_options) / sizeof (mntopt_t), 1370Sstevel@tonic-gate hsfs_options 1380Sstevel@tonic-gate }; 1390Sstevel@tonic-gate 1402900Sfrankho static int hsfsfstype; 1410Sstevel@tonic-gate static int hsfsinit(int, char *); 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate static vfsdef_t vfw = { 1440Sstevel@tonic-gate VFSDEF_VERSION, 1450Sstevel@tonic-gate "hsfs", 1460Sstevel@tonic-gate hsfsinit, 1471488Srsb VSW_HASPROTO|VSW_STATS, /* We don't suppport remounting */ 1480Sstevel@tonic-gate &hsfs_proto_opttbl 1490Sstevel@tonic-gate }; 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate static struct modlfs modlfs = { 1520Sstevel@tonic-gate &mod_fsops, "filesystem for HSFS", &vfw 1530Sstevel@tonic-gate }; 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate static struct modlinkage modlinkage = { 1560Sstevel@tonic-gate MODREV_1, (void *)&modlfs, NULL 1570Sstevel@tonic-gate }; 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate char _depends_on[] = "fs/specfs"; 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate int 1622900Sfrankho _init(void) 1630Sstevel@tonic-gate { 1640Sstevel@tonic-gate return (mod_install(&modlinkage)); 1650Sstevel@tonic-gate } 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate int 1682900Sfrankho _fini(void) 1690Sstevel@tonic-gate { 1702900Sfrankho int error; 1712900Sfrankho 1722900Sfrankho error = mod_remove(&modlinkage); 1732900Sfrankho 1742900Sfrankho DTRACE_PROBE1(mod_remove, int, error); 1752900Sfrankho 1762900Sfrankho if (error) 1772900Sfrankho return (error); 1782900Sfrankho 1792900Sfrankho mutex_destroy(&hs_mounttab_lock); 1802900Sfrankho 1812900Sfrankho /* 1822900Sfrankho * Tear down the operations vectors 1832900Sfrankho */ 1842900Sfrankho (void) vfs_freevfsops_by_type(hsfsfstype); 1852900Sfrankho vn_freevnodeops(hsfs_vnodeops); 1862900Sfrankho 1872900Sfrankho hs_fini_hsnode_cache(); 1882900Sfrankho return (0); 1890Sstevel@tonic-gate } 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate int 1920Sstevel@tonic-gate _info(struct modinfo *modinfop) 1930Sstevel@tonic-gate { 1940Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1950Sstevel@tonic-gate } 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate #define BDEVFLAG(dev) ((devopsp[getmajor(dev)])->devo_cb_ops->cb_flag) 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate kmutex_t hs_mounttab_lock; 2000Sstevel@tonic-gate struct hsfs *hs_mounttab = NULL; 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate /* default mode, uid, gid */ 2030Sstevel@tonic-gate mode_t hsfs_default_mode = 0555; 2040Sstevel@tonic-gate uid_t hsfs_default_uid = 0; 2050Sstevel@tonic-gate gid_t hsfs_default_gid = 3; 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate static int hsfs_mount(struct vfs *vfsp, struct vnode *mvp, 2080Sstevel@tonic-gate struct mounta *uap, struct cred *cr); 2090Sstevel@tonic-gate static int hsfs_unmount(struct vfs *vfsp, int, struct cred *cr); 2100Sstevel@tonic-gate static int hsfs_root(struct vfs *vfsp, struct vnode **vpp); 2110Sstevel@tonic-gate static int hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp); 2120Sstevel@tonic-gate static int hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp); 2130Sstevel@tonic-gate static int hsfs_mountroot(struct vfs *, enum whymountroot); 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate static int hs_mountfs(struct vfs *vfsp, dev_t dev, char *path, 2160Sstevel@tonic-gate mode_t mode, int flags, struct cred *cr, int isroot); 2172900Sfrankho static int hs_getrootvp(struct vfs *vfsp, struct hsfs *fsp, size_t pathsize); 2180Sstevel@tonic-gate static int hs_findhsvol(struct hsfs *fsp, struct vnode *vp, 2190Sstevel@tonic-gate struct hs_volume *hvp); 2200Sstevel@tonic-gate static int hs_parsehsvol(struct hsfs *fsp, uchar_t *volp, 2210Sstevel@tonic-gate struct hs_volume *hvp); 2220Sstevel@tonic-gate static int hs_findisovol(struct hsfs *fsp, struct vnode *vp, 2232900Sfrankho struct hs_volume *hvp, 2242900Sfrankho struct hs_volume *svp, 2252900Sfrankho struct hs_volume *jvp); 2262900Sfrankho static int hs_joliet_level(uchar_t *volp); 2270Sstevel@tonic-gate static int hs_parseisovol(struct hsfs *fsp, uchar_t *volp, 2280Sstevel@tonic-gate struct hs_volume *hvp); 2292900Sfrankho static void hs_copylabel(struct hs_volume *, unsigned char *, int); 2300Sstevel@tonic-gate static int hs_getmdev(struct vfs *, char *fspec, int flags, dev_t *pdev, 2310Sstevel@tonic-gate mode_t *mode, cred_t *cr); 2320Sstevel@tonic-gate static int hs_findvoldesc(dev_t rdev, int desc_sec); 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate static int 2350Sstevel@tonic-gate hsfsinit(int fstype, char *name) 2360Sstevel@tonic-gate { 2370Sstevel@tonic-gate static const fs_operation_def_t hsfs_vfsops_template[] = { 2383898Srsb VFSNAME_MOUNT, { .vfs_mount = hsfs_mount }, 2393898Srsb VFSNAME_UNMOUNT, { .vfs_unmount = hsfs_unmount }, 2403898Srsb VFSNAME_ROOT, { .vfs_root = hsfs_root }, 2413898Srsb VFSNAME_STATVFS, { .vfs_statvfs = hsfs_statvfs }, 2423898Srsb VFSNAME_VGET, { .vfs_vget = hsfs_vget }, 2433898Srsb VFSNAME_MOUNTROOT, { .vfs_mountroot = hsfs_mountroot }, 2443898Srsb NULL, NULL 2450Sstevel@tonic-gate }; 2460Sstevel@tonic-gate int error; 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate error = vfs_setfsops(fstype, hsfs_vfsops_template, NULL); 2490Sstevel@tonic-gate if (error != 0) { 2500Sstevel@tonic-gate cmn_err(CE_WARN, "hsfsinit: bad vfs ops template"); 2510Sstevel@tonic-gate return (error); 2520Sstevel@tonic-gate } 2530Sstevel@tonic-gate 2540Sstevel@tonic-gate error = vn_make_ops(name, hsfs_vnodeops_template, &hsfs_vnodeops); 2550Sstevel@tonic-gate if (error != 0) { 2560Sstevel@tonic-gate (void) vfs_freevfsops_by_type(fstype); 2570Sstevel@tonic-gate cmn_err(CE_WARN, "hsfsinit: bad vnode ops template"); 2580Sstevel@tonic-gate return (error); 2590Sstevel@tonic-gate } 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate hsfsfstype = fstype; 2620Sstevel@tonic-gate mutex_init(&hs_mounttab_lock, NULL, MUTEX_DEFAULT, NULL); 2630Sstevel@tonic-gate hs_init_hsnode_cache(); 2640Sstevel@tonic-gate return (0); 2650Sstevel@tonic-gate } 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate /*ARGSUSED*/ 2680Sstevel@tonic-gate static int 2690Sstevel@tonic-gate hsfs_mount(struct vfs *vfsp, struct vnode *mvp, 2700Sstevel@tonic-gate struct mounta *uap, struct cred *cr) 2710Sstevel@tonic-gate { 2720Sstevel@tonic-gate int vnode_busy; 2730Sstevel@tonic-gate dev_t dev; 2740Sstevel@tonic-gate struct pathname dpn; 2750Sstevel@tonic-gate int error; 2760Sstevel@tonic-gate mode_t mode; 2770Sstevel@tonic-gate int flags; /* this will hold the mount specific data */ 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate if ((error = secpolicy_fs_mount(cr, mvp, vfsp)) != 0) 2800Sstevel@tonic-gate return (error); 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate if (mvp->v_type != VDIR) 2830Sstevel@tonic-gate return (ENOTDIR); 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate /* mount option must be read only, else mount will be rejected */ 2860Sstevel@tonic-gate if (!(uap->flags & MS_RDONLY)) 2870Sstevel@tonic-gate return (EROFS); 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate /* 2900Sstevel@tonic-gate * We already told the framework that we don't support remounting. 2910Sstevel@tonic-gate */ 2920Sstevel@tonic-gate ASSERT(!(uap->flags & MS_REMOUNT)); 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate mutex_enter(&mvp->v_lock); 2950Sstevel@tonic-gate vnode_busy = (mvp->v_count != 1) || (mvp->v_flag & VROOT); 2960Sstevel@tonic-gate mutex_exit(&mvp->v_lock); 2970Sstevel@tonic-gate 2980Sstevel@tonic-gate if ((uap->flags & MS_OVERLAY) == 0 && vnode_busy) { 2990Sstevel@tonic-gate return (EBUSY); 3000Sstevel@tonic-gate } 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate /* 3030Sstevel@tonic-gate * Check for the options that actually affect things 3040Sstevel@tonic-gate * at our level. 3050Sstevel@tonic-gate */ 3060Sstevel@tonic-gate flags = 0; 3070Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NOMAPLCASE, NULL)) 308*4866Sfrankho flags |= HSFSMNT_NOMAPLCASE; 3090Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NOTRAILDOT, NULL)) 310*4866Sfrankho flags |= HSFSMNT_NOTRAILDOT; 3110Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NRR, NULL)) 312*4866Sfrankho flags |= HSFSMNT_NORRIP; 3132900Sfrankho if (vfs_optionisset(vfsp, HOPT_NOJOLIET, NULL)) 314*4866Sfrankho flags |= HSFSMNT_NOJOLIET; 3152900Sfrankho if (vfs_optionisset(vfsp, HOPT_JOLIETLONG, NULL)) 316*4866Sfrankho flags |= HSFSMNT_JOLIETLONG; 3172900Sfrankho if (vfs_optionisset(vfsp, HOPT_NOVERS2, NULL)) 318*4866Sfrankho flags |= HSFSMNT_NOVERS2; 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate error = pn_get(uap->dir, (uap->flags & MS_SYSSPACE) ? 3210Sstevel@tonic-gate UIO_SYSSPACE : UIO_USERSPACE, &dpn); 3220Sstevel@tonic-gate if (error) 3230Sstevel@tonic-gate return (error); 3240Sstevel@tonic-gate 325*4866Sfrankho error = hs_getmdev(vfsp, uap->spec, uap->flags, &dev, &mode, cr); 326*4866Sfrankho if (error != 0) { 3270Sstevel@tonic-gate pn_free(&dpn); 3280Sstevel@tonic-gate return (error); 3290Sstevel@tonic-gate } 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate /* 3320Sstevel@tonic-gate * If the device is a tape, return error 3330Sstevel@tonic-gate */ 3340Sstevel@tonic-gate if ((BDEVFLAG(dev) & D_TAPE) == D_TAPE) { 3350Sstevel@tonic-gate pn_free(&dpn); 3360Sstevel@tonic-gate return (ENOTBLK); 3370Sstevel@tonic-gate } 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate /* 3400Sstevel@tonic-gate * Mount the filesystem. 3410Sstevel@tonic-gate */ 3420Sstevel@tonic-gate error = hs_mountfs(vfsp, dev, dpn.pn_path, mode, flags, cr, 0); 3430Sstevel@tonic-gate pn_free(&dpn); 3440Sstevel@tonic-gate return (error); 3450Sstevel@tonic-gate } 3460Sstevel@tonic-gate 3470Sstevel@tonic-gate /*ARGSUSED*/ 3480Sstevel@tonic-gate static int 3490Sstevel@tonic-gate hsfs_unmount( 3500Sstevel@tonic-gate struct vfs *vfsp, 3510Sstevel@tonic-gate int flag, 3520Sstevel@tonic-gate struct cred *cr) 3530Sstevel@tonic-gate { 3540Sstevel@tonic-gate struct hsfs **tspp; 3550Sstevel@tonic-gate struct hsfs *fsp; 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate if (secpolicy_fs_unmount(cr, vfsp) != 0) 3580Sstevel@tonic-gate return (EPERM); 3590Sstevel@tonic-gate 3600Sstevel@tonic-gate /* 3610Sstevel@tonic-gate * forced unmount is not supported by this file system 3620Sstevel@tonic-gate * and thus, ENOTSUP is being returned. 3630Sstevel@tonic-gate */ 3640Sstevel@tonic-gate if (flag & MS_FORCE) 3650Sstevel@tonic-gate return (ENOTSUP); 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp); 3680Sstevel@tonic-gate 3690Sstevel@tonic-gate if (fsp->hsfs_rootvp->v_count != 1) 3700Sstevel@tonic-gate return (EBUSY); 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate /* destroy all old pages and hsnodes for this vfs */ 3730Sstevel@tonic-gate if (hs_synchash(vfsp)) 3740Sstevel@tonic-gate return (EBUSY); 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate mutex_enter(&hs_mounttab_lock); 3770Sstevel@tonic-gate for (tspp = &hs_mounttab; *tspp != NULL; tspp = &(*tspp)->hsfs_next) { 3780Sstevel@tonic-gate if (*tspp == fsp) 3790Sstevel@tonic-gate break; 3800Sstevel@tonic-gate } 3810Sstevel@tonic-gate if (*tspp == NULL) { 3820Sstevel@tonic-gate mutex_exit(&hs_mounttab_lock); 3830Sstevel@tonic-gate panic("hsfs_unmount: vfs not mounted?"); 3840Sstevel@tonic-gate /*NOTREACHED*/ 3850Sstevel@tonic-gate } 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate *tspp = fsp->hsfs_next; 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate mutex_exit(&hs_mounttab_lock); 3900Sstevel@tonic-gate 3910Sstevel@tonic-gate (void) VOP_CLOSE(fsp->hsfs_devvp, FREAD, 1, (offset_t)0, cr); 3920Sstevel@tonic-gate VN_RELE(fsp->hsfs_devvp); 3930Sstevel@tonic-gate /* free path table space */ 3940Sstevel@tonic-gate if (fsp->hsfs_ptbl != NULL) 395*4866Sfrankho kmem_free(fsp->hsfs_ptbl, (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) 399*4866Sfrankho (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 478*4866Sfrankho nodeid = fid->hf_ino; 4790Sstevel@tonic-gate 480*4866Sfrankho if ((*vpp = hs_findhash(nodeid, fid->hf_dir_lbn, 481*4866Sfrankho (uint_t)fid->hf_dir_off, vfsp)) == NULL) { 4820Sstevel@tonic-gate /* 4830Sstevel@tonic-gate * Not in cache, so we need to remake it. 4840Sstevel@tonic-gate * hs_remakenode() will read the directory entry 4850Sstevel@tonic-gate * and then check again to see if anyone else has 4860Sstevel@tonic-gate * put it in the cache. 4870Sstevel@tonic-gate */ 4880Sstevel@tonic-gate rw_exit(&fsp->hsfs_hash_lock); 4890Sstevel@tonic-gate error = hs_remakenode(fid->hf_dir_lbn, (uint_t)fid->hf_dir_off, 4900Sstevel@tonic-gate vfsp, vpp); 4910Sstevel@tonic-gate return (error); 4920Sstevel@tonic-gate } 4930Sstevel@tonic-gate rw_exit(&fsp->hsfs_hash_lock); 4940Sstevel@tonic-gate return (0); 4950Sstevel@tonic-gate } 4960Sstevel@tonic-gate 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate #define CHECKSUM_SIZE (64 * 1024) 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate /* 5010Sstevel@tonic-gate * Compute a CD-ROM fsid by checksumming the first 64K of data on the CD 5020Sstevel@tonic-gate * We use the 'fsp' argument to determine the location of the root 5030Sstevel@tonic-gate * directory entry, and we start reading from there. 5040Sstevel@tonic-gate */ 5050Sstevel@tonic-gate static int 5060Sstevel@tonic-gate compute_cdrom_id(struct hsfs *fsp, vnode_t *devvp) 5070Sstevel@tonic-gate { 5080Sstevel@tonic-gate uint_t secno; 5090Sstevel@tonic-gate struct hs_volume *hsvp = &fsp->hsfs_vol; 5100Sstevel@tonic-gate struct buf *bp; 5110Sstevel@tonic-gate int error; 5120Sstevel@tonic-gate int fsid; 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate secno = hsvp->root_dir.ext_lbn >> hsvp->lbn_secshift; 515494Sfrankho bp = bread(devvp->v_rdev, secno * 4, CHECKSUM_SIZE); 5160Sstevel@tonic-gate error = geterror(bp); 517494Sfrankho 518494Sfrankho /* 519494Sfrankho * An error on read or a partial read means we asked 520494Sfrankho * for a nonexistant/corrupted piece of the device 521494Sfrankho * (including past-the-end of the media). Don't 522494Sfrankho * try to use the checksumming method then. 523494Sfrankho */ 524494Sfrankho if (!error && bp->b_bcount == CHECKSUM_SIZE) { 5250Sstevel@tonic-gate int *ibuf = (int *)bp->b_un.b_addr; 5260Sstevel@tonic-gate int i; 5270Sstevel@tonic-gate 5280Sstevel@tonic-gate fsid = 0; 5290Sstevel@tonic-gate 530494Sfrankho for (i = 0; i < CHECKSUM_SIZE / sizeof (int); i++) 5310Sstevel@tonic-gate fsid ^= ibuf[ i ]; 532494Sfrankho } else { 533494Sfrankho /* 534494Sfrankho * Fallback - use creation date 535494Sfrankho */ 5360Sstevel@tonic-gate fsid = hsvp->cre_date.tv_sec; 537494Sfrankho } 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate brelse(bp); 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate return (fsid); 5420Sstevel@tonic-gate } 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate 5450Sstevel@tonic-gate /*ARGSUSED*/ 5460Sstevel@tonic-gate static int 5470Sstevel@tonic-gate hs_mountfs( 5480Sstevel@tonic-gate struct vfs *vfsp, 5490Sstevel@tonic-gate dev_t dev, 5500Sstevel@tonic-gate char *path, 5510Sstevel@tonic-gate mode_t mode, 5520Sstevel@tonic-gate int mount_flags, 5530Sstevel@tonic-gate struct cred *cr, 5540Sstevel@tonic-gate int isroot) 5550Sstevel@tonic-gate { 5560Sstevel@tonic-gate struct vnode *devvp; 5570Sstevel@tonic-gate struct hsfs *tsp; 5580Sstevel@tonic-gate struct hsfs *fsp = NULL; 5590Sstevel@tonic-gate struct vattr vap; 5600Sstevel@tonic-gate struct hsnode *hp; 5610Sstevel@tonic-gate int error; 5620Sstevel@tonic-gate struct timeval tv; 5630Sstevel@tonic-gate int fsid; 5642900Sfrankho int use_rrip; 5652900Sfrankho int use_vers2; 5662900Sfrankho int use_joliet; 5672900Sfrankho int has_rrip = 0; 5682900Sfrankho int has_vers2 = 0; 5692900Sfrankho int has_joliet = 0; 5702900Sfrankho int force_rrip_off; 5712900Sfrankho int force_vers2_off; 5722900Sfrankho int force_joliet_off; 5732900Sfrankho size_t pathbufsz = strlen(path) + 1; 5742900Sfrankho int redo_rootvp; 5752900Sfrankho 5762900Sfrankho struct hs_volume *svp; /* Supplemental VD for ISO-9660:1999 */ 5772900Sfrankho struct hs_volume *jvp; /* Joliet VD */ 5782900Sfrankho 5792900Sfrankho /* 5802900Sfrankho * The rules for which extension will be used are: 5812900Sfrankho * 1. No specific mount options given: 5822900Sfrankho * - use rrip if available 5832900Sfrankho * - use ISO9660:1999 if available 5842900Sfrankho * - use joliet if available. 5852900Sfrankho * 2. rrip/ISO9660:1999/joliet explicitly disabled via mount option: 5862900Sfrankho * - use next "lower" extension 5872900Sfrankho * 3. joliet/ISO9660:1999/rrip explicitly requested via mount option: 5882900Sfrankho * - disable rrip support even if available 5892900Sfrankho * - disable IOS9660:1999 support even if available 5902900Sfrankho * 5912900Sfrankho * We need to adjust these flags as we discover the extensions 5922900Sfrankho * present. See below. These are just the starting values. 5932900Sfrankho */ 5942900Sfrankho use_rrip = (mount_flags & HSFSMNT_NORRIP) == 0; 5952900Sfrankho use_vers2 = (mount_flags & HSFSMNT_NOVERS2) == 0; 5962900Sfrankho use_joliet = (mount_flags & HSFSMNT_NOJOLIET) == 0; 5970Sstevel@tonic-gate 5980Sstevel@tonic-gate /* 5990Sstevel@tonic-gate * Open the device 6000Sstevel@tonic-gate */ 6010Sstevel@tonic-gate devvp = makespecvp(dev, VBLK); 6020Sstevel@tonic-gate ASSERT(devvp != 0); 6030Sstevel@tonic-gate 6040Sstevel@tonic-gate /* 6050Sstevel@tonic-gate * Open the target device (file) for read only. 6060Sstevel@tonic-gate */ 6070Sstevel@tonic-gate if (error = VOP_OPEN(&devvp, FREAD, cr)) { 6080Sstevel@tonic-gate VN_RELE(devvp); 6090Sstevel@tonic-gate return (error); 6100Sstevel@tonic-gate } 6110Sstevel@tonic-gate 6120Sstevel@tonic-gate /* 6130Sstevel@tonic-gate * Refuse to go any further if this 6140Sstevel@tonic-gate * device is being used for swapping 6150Sstevel@tonic-gate */ 6160Sstevel@tonic-gate if (IS_SWAPVP(common_specvp(devvp))) { 6170Sstevel@tonic-gate error = EBUSY; 6180Sstevel@tonic-gate goto cleanup; 6190Sstevel@tonic-gate } 6200Sstevel@tonic-gate 6210Sstevel@tonic-gate vap.va_mask = AT_SIZE; 6220Sstevel@tonic-gate if ((error = VOP_GETATTR(devvp, &vap, ATTR_COMM, cr)) != 0) { 6230Sstevel@tonic-gate cmn_err(CE_NOTE, "Cannot get attributes of the CD-ROM driver"); 6240Sstevel@tonic-gate goto cleanup; 6250Sstevel@tonic-gate } 6260Sstevel@tonic-gate 6270Sstevel@tonic-gate /* 6280Sstevel@tonic-gate * Make sure we have a nonzero size partition. 6290Sstevel@tonic-gate * The current version of the SD driver will *not* fail the open 6300Sstevel@tonic-gate * of such a partition so we have to check for it here. 6310Sstevel@tonic-gate */ 6320Sstevel@tonic-gate if (vap.va_size == 0) { 6330Sstevel@tonic-gate error = ENXIO; 6340Sstevel@tonic-gate goto cleanup; 6350Sstevel@tonic-gate } 6360Sstevel@tonic-gate 6370Sstevel@tonic-gate /* 6380Sstevel@tonic-gate * Init a new hsfs structure. 6390Sstevel@tonic-gate */ 6400Sstevel@tonic-gate fsp = kmem_zalloc(sizeof (*fsp), KM_SLEEP); 6412900Sfrankho svp = kmem_zalloc(sizeof (*svp), KM_SLEEP); 6422900Sfrankho jvp = kmem_zalloc(sizeof (*jvp), KM_SLEEP); 6430Sstevel@tonic-gate 6440Sstevel@tonic-gate /* hardwire perms, uid, gid */ 6450Sstevel@tonic-gate fsp->hsfs_vol.vol_uid = hsfs_default_uid; 6460Sstevel@tonic-gate fsp->hsfs_vol.vol_gid = hsfs_default_gid; 6470Sstevel@tonic-gate fsp->hsfs_vol.vol_prot = hsfs_default_mode; 6482900Sfrankho svp->vol_uid = hsfs_default_uid; 6492900Sfrankho svp->vol_gid = hsfs_default_gid; 6502900Sfrankho svp->vol_prot = hsfs_default_mode; 6512900Sfrankho jvp->vol_uid = hsfs_default_uid; 6522900Sfrankho jvp->vol_gid = hsfs_default_gid; 6532900Sfrankho jvp->vol_prot = hsfs_default_mode; 6540Sstevel@tonic-gate 6550Sstevel@tonic-gate /* 6560Sstevel@tonic-gate * Look for a Standard File Structure Volume Descriptor, 6570Sstevel@tonic-gate * of which there must be at least one. 6580Sstevel@tonic-gate * If found, check for volume size consistency. 6592900Sfrankho * 6602900Sfrankho * If svp->lbn_size is != 0, we did find a ISO-9660:1999 SVD 6612900Sfrankho * If jvp->lbn_size is != 0, we did find a Joliet SVD. 6620Sstevel@tonic-gate */ 6632900Sfrankho fsp->hsfs_namemax = ISO_FILE_NAMELEN; 6642900Sfrankho fsp->hsfs_namelen = ISO_FILE_NAMELEN; 6652900Sfrankho error = hs_findisovol(fsp, devvp, &fsp->hsfs_vol, svp, jvp); 6661025Sfrankho if (error == EINVAL) /* no iso 9660 - try high sierra ... */ 6671025Sfrankho error = hs_findhsvol(fsp, devvp, &fsp->hsfs_vol); 6680Sstevel@tonic-gate 6690Sstevel@tonic-gate if (error) 6700Sstevel@tonic-gate goto cleanup; 6710Sstevel@tonic-gate 6722900Sfrankho DTRACE_PROBE4(findvol, 6732900Sfrankho struct hsfs *, fsp, 6742900Sfrankho struct hs_volume *, &fsp->hsfs_vol, 6752900Sfrankho struct hs_volume *, svp, 6762900Sfrankho struct hs_volume *, jvp); 6772900Sfrankho 6780Sstevel@tonic-gate /* 6790Sstevel@tonic-gate * Generate a file system ID from the CD-ROM, 6800Sstevel@tonic-gate * and check it for uniqueness. 6810Sstevel@tonic-gate * 6820Sstevel@tonic-gate * What we are aiming for is some chance of integrity 6830Sstevel@tonic-gate * across disk change. That is, if a client has an fhandle, 6840Sstevel@tonic-gate * it will be valid as long as the same disk is mounted. 6850Sstevel@tonic-gate */ 6860Sstevel@tonic-gate fsid = compute_cdrom_id(fsp, devvp); 6870Sstevel@tonic-gate 6880Sstevel@tonic-gate mutex_enter(&hs_mounttab_lock); 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate if (fsid == 0 || fsid == -1) { 6910Sstevel@tonic-gate uniqtime(&tv); 6920Sstevel@tonic-gate fsid = tv.tv_sec; 6930Sstevel@tonic-gate } else /* make sure that the fsid is unique */ 6940Sstevel@tonic-gate for (tsp = hs_mounttab; tsp != NULL; tsp = tsp->hsfs_next) { 6950Sstevel@tonic-gate if (fsid == tsp->hsfs_vfs->vfs_fsid.val[0]) { 6960Sstevel@tonic-gate uniqtime(&tv); 6970Sstevel@tonic-gate fsid = tv.tv_sec; 6980Sstevel@tonic-gate break; 6990Sstevel@tonic-gate } 7000Sstevel@tonic-gate } 7010Sstevel@tonic-gate 7020Sstevel@tonic-gate fsp->hsfs_next = hs_mounttab; 7030Sstevel@tonic-gate hs_mounttab = fsp; 7040Sstevel@tonic-gate 7050Sstevel@tonic-gate fsp->hsfs_devvp = devvp; 7060Sstevel@tonic-gate fsp->hsfs_vfs = vfsp; 7072900Sfrankho fsp->hsfs_fsmnt = kmem_alloc(pathbufsz, KM_SLEEP); 7082900Sfrankho (void) strlcpy(fsp->hsfs_fsmnt, path, pathbufsz); 7090Sstevel@tonic-gate 7100Sstevel@tonic-gate mutex_init(&fsp->hsfs_free_lock, NULL, MUTEX_DEFAULT, NULL); 7110Sstevel@tonic-gate rw_init(&fsp->hsfs_hash_lock, NULL, RW_DEFAULT, NULL); 7120Sstevel@tonic-gate 7130Sstevel@tonic-gate vfsp->vfs_data = (caddr_t)fsp; 7140Sstevel@tonic-gate vfsp->vfs_dev = dev; 7150Sstevel@tonic-gate vfsp->vfs_fstype = hsfsfstype; 7160Sstevel@tonic-gate vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size; /* %% */ 7170Sstevel@tonic-gate vfsp->vfs_fsid.val[0] = fsid; 7180Sstevel@tonic-gate vfsp->vfs_fsid.val[1] = hsfsfstype; 7190Sstevel@tonic-gate 7202900Sfrankho if (!hs_getrootvp(vfsp, fsp, pathbufsz)) { 7212900Sfrankho DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp); 7222900Sfrankho error = EINVAL; 7232900Sfrankho goto cleanup; 7242900Sfrankho } 7252900Sfrankho DTRACE_PROBE1(rootvp, struct hsfs *, fsp); 7262900Sfrankho 7272900Sfrankho /* 7282900Sfrankho * Attempt to discover a RR extension. 7292900Sfrankho */ 7302900Sfrankho if (use_rrip) { 7312900Sfrankho hp = VTOH(fsp->hsfs_rootvp); 7322900Sfrankho hs_check_root_dirent(fsp->hsfs_rootvp, &(hp->hs_dirent)); 7332900Sfrankho } 7342900Sfrankho 7352900Sfrankho has_rrip = IS_RRIP_IMPLEMENTED(fsp); 7362900Sfrankho has_vers2 = (svp->lbn_size != 0); 7372900Sfrankho has_joliet = (jvp->lbn_size != 0); 7382900Sfrankho 7392900Sfrankho DTRACE_PROBE4(voltype__suggested, struct hsfs *, fsp, 7402900Sfrankho int, use_rrip, int, use_vers2, int, use_joliet); 7412900Sfrankho 7422900Sfrankho DTRACE_PROBE4(voltype__actual, struct hsfs *, fsp, 7432900Sfrankho int, has_rrip, int, has_vers2, int, has_joliet); 7442900Sfrankho 7452900Sfrankho DTRACE_PROBE4(findvol, 7462900Sfrankho struct hsfs *, fsp, 7472900Sfrankho struct hs_volume *, &fsp->hsfs_vol, 7482900Sfrankho struct hs_volume *, svp, 7492900Sfrankho struct hs_volume *, jvp); 7502900Sfrankho 7512900Sfrankho force_rrip_off = !use_rrip || 7522900Sfrankho (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet) || 7532900Sfrankho (vfs_optionisset(vfsp, HOPT_VERS2, NULL) && has_vers2); 7542900Sfrankho 7552900Sfrankho force_vers2_off = !use_vers2 || 7562900Sfrankho (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet); 7572900Sfrankho 7582900Sfrankho force_joliet_off = !use_joliet; 7592900Sfrankho 7602900Sfrankho DTRACE_PROBE4(voltype__force_off, struct hsfs *, fsp, 7612900Sfrankho int, force_rrip_off, int, force_vers2_off, int, force_joliet_off); 7622900Sfrankho 7632900Sfrankho /* 7642900Sfrankho * At the moment, we have references of all three possible 7652900Sfrankho * extensions (RR, ISO9660:1999/v2 and Joliet) if present. 7662900Sfrankho * 7672900Sfrankho * The "active" volume descriptor is RRIP (or ISO9660:1988). 7682900Sfrankho * We now switch to the user-requested one. 7692900Sfrankho */ 7702900Sfrankho redo_rootvp = 0; 7712900Sfrankho 7722900Sfrankho if (force_rrip_off || !has_rrip) { 7732900Sfrankho if (has_vers2 && !force_vers2_off) { 7742900Sfrankho VN_RELE(fsp->hsfs_rootvp); 7752900Sfrankho bcopy(svp, &fsp->hsfs_vol, sizeof (struct hs_volume)); 7762900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_ISO_V2; 7772900Sfrankho vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size; 7782900Sfrankho redo_rootvp = 1; 7792900Sfrankho has_joliet = 0; 7802900Sfrankho } else if (has_joliet && !force_joliet_off) { 7812900Sfrankho VN_RELE(fsp->hsfs_rootvp); 7822900Sfrankho bcopy(jvp, &fsp->hsfs_vol, sizeof (struct hs_volume)); 7832900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_JOLIET; 7842900Sfrankho vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size; 7852900Sfrankho redo_rootvp = 1; 7862900Sfrankho has_vers2 = 0; 7872900Sfrankho } 7882900Sfrankho } 7892900Sfrankho 7902900Sfrankho if (redo_rootvp) { 7912900Sfrankho /* 7922900Sfrankho * Make sure not to use Rock Ridge. 7932900Sfrankho */ 7942900Sfrankho UNSET_IMPL_BIT(fsp, RRIP_BIT); 7952900Sfrankho UNSET_SUSP_BIT(fsp); 7962900Sfrankho has_rrip = 0; 7972900Sfrankho 7982900Sfrankho if (!hs_getrootvp(vfsp, fsp, pathbufsz)) { 7992900Sfrankho DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp); 8002900Sfrankho error = EINVAL; 8012900Sfrankho goto cleanup; 8022900Sfrankho } 8032900Sfrankho DTRACE_PROBE1(rootvp, struct hsfs *, fsp); 8042900Sfrankho } 8052900Sfrankho if (IS_RRIP_IMPLEMENTED(fsp)) { 8062900Sfrankho has_vers2 = 0; 8072900Sfrankho has_joliet = 0; 8082900Sfrankho } 8092900Sfrankho if (force_vers2_off) 8102900Sfrankho has_vers2 = 0; 8112900Sfrankho if (force_joliet_off) 8122900Sfrankho has_joliet = 0; 8132900Sfrankho DTRACE_PROBE4(voltype__taken, struct hsfs *, fsp, 8142900Sfrankho int, has_rrip, int, has_vers2, int, has_joliet); 8152900Sfrankho 8162900Sfrankho /* 8172900Sfrankho * mark root node as VROOT 8182900Sfrankho */ 8192900Sfrankho fsp->hsfs_rootvp->v_flag |= VROOT; 8202900Sfrankho 8212900Sfrankho /* Here we take care of some special case stuff for mountroot */ 8222900Sfrankho if (isroot) { 8232900Sfrankho fsp->hsfs_rootvp->v_rdev = devvp->v_rdev; 8242900Sfrankho rootvp = fsp->hsfs_rootvp; 8252900Sfrankho } 8262900Sfrankho 8272900Sfrankho if (IS_RRIP_IMPLEMENTED(fsp)) { 8282900Sfrankho /* 8292900Sfrankho * if RRIP, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags 8302900Sfrankho */ 8312900Sfrankho mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT); 8322900Sfrankho 8332900Sfrankho fsp->hsfs_namemax = RRIP_FILE_NAMELEN; 8342900Sfrankho fsp->hsfs_namelen = RRIP_FILE_NAMELEN; 8352900Sfrankho 8362900Sfrankho ASSERT(vfs_optionisset(vfsp, HOPT_RR, NULL)); 8372900Sfrankho vfs_clearmntopt(vfsp, HOPT_VERS2); 8382900Sfrankho vfs_clearmntopt(vfsp, HOPT_JOLIET); 8392900Sfrankho 8402900Sfrankho } else switch (fsp->hsfs_vol_type) { 8412900Sfrankho 8422900Sfrankho case HS_VOL_TYPE_HS: 8432900Sfrankho case HS_VOL_TYPE_ISO: 8442900Sfrankho default: 8452900Sfrankho /* 8462900Sfrankho * if iso v1, don't allow trailing spaces in iso file names 8472900Sfrankho */ 8482900Sfrankho mount_flags |= HSFSMNT_NOTRAILSPACE; 8492900Sfrankho fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX; 8502900Sfrankho fsp->hsfs_namelen = ISO_FILE_NAMELEN; 8512900Sfrankho vfs_clearmntopt(vfsp, HOPT_RR); 8522900Sfrankho vfs_clearmntopt(vfsp, HOPT_VERS2); 8532900Sfrankho vfs_clearmntopt(vfsp, HOPT_JOLIET); 8542900Sfrankho break; 8552900Sfrankho 8562900Sfrankho case HS_VOL_TYPE_ISO_V2: 8572900Sfrankho /* 8582900Sfrankho * if iso v2, don't copy NOTRAILDOT to hsfs_flags 8592900Sfrankho */ 8602900Sfrankho mount_flags &= ~HSFSMNT_NOTRAILDOT; 8612900Sfrankho mount_flags |= HSFSMNT_NOMAPLCASE | HSFSMNT_NOVERSION; 8622900Sfrankho fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX; 8632900Sfrankho fsp->hsfs_namelen = ISO_NAMELEN_V2; 8642900Sfrankho vfs_setmntopt(vfsp, HOPT_VERS2, NULL, 0); 8652900Sfrankho vfs_clearmntopt(vfsp, HOPT_RR); 8662900Sfrankho vfs_clearmntopt(vfsp, HOPT_JOLIET); 8672900Sfrankho break; 8682900Sfrankho 8692900Sfrankho case HS_VOL_TYPE_JOLIET: 8702900Sfrankho /* 8712900Sfrankho * if Joliet, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags 8722900Sfrankho */ 8732900Sfrankho mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT); 8742900Sfrankho mount_flags |= HSFSMNT_NOMAPLCASE; 8752900Sfrankho if (mount_flags & HSFSMNT_JOLIETLONG) 8762900Sfrankho fsp->hsfs_namemax = JOLIET_NAMELEN_MAX*3; /* UTF-8 */ 8772900Sfrankho else 8782900Sfrankho fsp->hsfs_namemax = MAXNAMELEN-1; 8792900Sfrankho fsp->hsfs_namelen = JOLIET_NAMELEN*2; 8802900Sfrankho vfs_setmntopt(vfsp, HOPT_JOLIET, NULL, 0); 8812900Sfrankho vfs_clearmntopt(vfsp, HOPT_RR); 8822900Sfrankho vfs_clearmntopt(vfsp, HOPT_VERS2); 8832900Sfrankho break; 8842900Sfrankho } 8852900Sfrankho 886*4866Sfrankho /* 887*4866Sfrankho * Add the HSFSMNT_INODE pseudo mount flag to the current mount flags. 888*4866Sfrankho */ 889*4866Sfrankho fsp->hsfs_flags = mount_flags | (fsp->hsfs_flags & HSFSMNT_INODE); 8902900Sfrankho 8912900Sfrankho DTRACE_PROBE1(mount__done, struct hsfs *, fsp); 8922900Sfrankho 8932900Sfrankho /* 8942900Sfrankho * set the magic word 8952900Sfrankho */ 8962900Sfrankho fsp->hsfs_magic = HSFS_MAGIC; 8972900Sfrankho mutex_exit(&hs_mounttab_lock); 8982900Sfrankho 899*4866Sfrankho kmem_free(svp, sizeof (*svp)); 900*4866Sfrankho kmem_free(jvp, sizeof (*jvp)); 901*4866Sfrankho 9022900Sfrankho return (0); 9032900Sfrankho 9042900Sfrankho cleanup: 9052900Sfrankho (void) VOP_CLOSE(devvp, FREAD, 1, (offset_t)0, cr); 9062900Sfrankho VN_RELE(devvp); 9072900Sfrankho if (fsp) 9082900Sfrankho kmem_free(fsp, sizeof (*fsp)); 9092900Sfrankho if (svp) 9102900Sfrankho kmem_free(svp, sizeof (*svp)); 9112900Sfrankho if (jvp) 9122900Sfrankho kmem_free(jvp, sizeof (*jvp)); 9132900Sfrankho return (error); 9142900Sfrankho } 9152900Sfrankho 9162900Sfrankho /* 9172900Sfrankho * Get the rootvp associated with fsp->hsfs_vol 9182900Sfrankho */ 9192900Sfrankho static int 9202900Sfrankho hs_getrootvp( 9212900Sfrankho struct vfs *vfsp, 9222900Sfrankho struct hsfs *fsp, 9232900Sfrankho size_t pathsize) 9242900Sfrankho { 9252900Sfrankho struct hsnode *hp; 9262900Sfrankho 9272900Sfrankho ASSERT(pathsize == strlen(fsp->hsfs_fsmnt) + 1); 9282900Sfrankho 9290Sstevel@tonic-gate /* 9300Sstevel@tonic-gate * If the root directory does not appear to be 9310Sstevel@tonic-gate * valid, use what it points to as "." instead. 9320Sstevel@tonic-gate * Some Defense Mapping Agency disks are non-conformant 9330Sstevel@tonic-gate * in this way. 9340Sstevel@tonic-gate */ 9350Sstevel@tonic-gate if (!hsfs_valid_dir(&fsp->hsfs_vol.root_dir)) { 9360Sstevel@tonic-gate hs_log_bogus_disk_warning(fsp, HSFS_ERR_BAD_ROOT_DIR, 0); 9370Sstevel@tonic-gate if (hs_remakenode(fsp->hsfs_vol.root_dir.ext_lbn, 938*4866Sfrankho (uint_t)0, vfsp, &fsp->hsfs_rootvp)) { 9391025Sfrankho hs_mounttab = hs_mounttab->hsfs_next; 9401025Sfrankho mutex_destroy(&fsp->hsfs_free_lock); 9411025Sfrankho rw_destroy(&fsp->hsfs_hash_lock); 9422900Sfrankho kmem_free(fsp->hsfs_fsmnt, pathsize); 943494Sfrankho mutex_exit(&hs_mounttab_lock); 9442900Sfrankho return (0); 9450Sstevel@tonic-gate } 9460Sstevel@tonic-gate } else { 9470Sstevel@tonic-gate fsp->hsfs_rootvp = hs_makenode(&fsp->hsfs_vol.root_dir, 948*4866Sfrankho fsp->hsfs_vol.root_dir.ext_lbn, 0, vfsp); 9490Sstevel@tonic-gate } 9500Sstevel@tonic-gate 9510Sstevel@tonic-gate /* XXX - ignore the path table for now */ 9520Sstevel@tonic-gate fsp->hsfs_ptbl = NULL; 9530Sstevel@tonic-gate hp = VTOH(fsp->hsfs_rootvp); 9540Sstevel@tonic-gate hp->hs_ptbl_idx = NULL; 9550Sstevel@tonic-gate 9562900Sfrankho return (1); 9570Sstevel@tonic-gate } 9580Sstevel@tonic-gate 9590Sstevel@tonic-gate /* 9600Sstevel@tonic-gate * hs_findhsvol() 9610Sstevel@tonic-gate * 9620Sstevel@tonic-gate * Locate the Standard File Structure Volume Descriptor and 9630Sstevel@tonic-gate * parse it into an hs_volume structure. 9640Sstevel@tonic-gate * 9650Sstevel@tonic-gate * XXX - May someday want to look for Coded Character Set FSVD, too. 9660Sstevel@tonic-gate */ 9670Sstevel@tonic-gate static int 9680Sstevel@tonic-gate hs_findhsvol(struct hsfs *fsp, struct vnode *vp, struct hs_volume *hvp) 9690Sstevel@tonic-gate { 9700Sstevel@tonic-gate struct buf *secbp; 9710Sstevel@tonic-gate int i; 972*4866Sfrankho int n; 9730Sstevel@tonic-gate uchar_t *volp; 9740Sstevel@tonic-gate int error; 9750Sstevel@tonic-gate uint_t secno; 9760Sstevel@tonic-gate 9770Sstevel@tonic-gate secno = hs_findvoldesc(vp->v_rdev, HS_VOLDESC_SEC); 9780Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE); 9790Sstevel@tonic-gate error = geterror(secbp); 9800Sstevel@tonic-gate 9810Sstevel@tonic-gate if (error != 0) { 9820Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)", error); 9830Sstevel@tonic-gate brelse(secbp); 9840Sstevel@tonic-gate return (error); 9850Sstevel@tonic-gate } 9860Sstevel@tonic-gate 9870Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 9880Sstevel@tonic-gate 989*4866Sfrankho /* 990*4866Sfrankho * To avoid that we read the whole medium in case that someone prepares 991*4866Sfrankho * a malicious "fs image", we read at most 32 blocks. 992*4866Sfrankho */ 993*4866Sfrankho for (n = 0; n < 32 && 994*4866Sfrankho HSV_DESC_TYPE(volp) != VD_EOV; n++) { 9950Sstevel@tonic-gate for (i = 0; i < HSV_ID_STRLEN; i++) 9960Sstevel@tonic-gate if (HSV_STD_ID(volp)[i] != HSV_ID_STRING[i]) 9970Sstevel@tonic-gate goto cantfind; 9980Sstevel@tonic-gate if (HSV_STD_VER(volp) != HSV_ID_VER) 9990Sstevel@tonic-gate goto cantfind; 10000Sstevel@tonic-gate switch (HSV_DESC_TYPE(volp)) { 10010Sstevel@tonic-gate case VD_SFS: 10020Sstevel@tonic-gate /* Standard File Structure */ 10030Sstevel@tonic-gate fsp->hsfs_vol_type = HS_VOL_TYPE_HS; 10040Sstevel@tonic-gate error = hs_parsehsvol(fsp, volp, hvp); 10050Sstevel@tonic-gate brelse(secbp); 10060Sstevel@tonic-gate return (error); 10070Sstevel@tonic-gate 10080Sstevel@tonic-gate case VD_CCFS: 10090Sstevel@tonic-gate /* Coded Character File Structure */ 10100Sstevel@tonic-gate case VD_BOOT: 10110Sstevel@tonic-gate case VD_UNSPEC: 10120Sstevel@tonic-gate case VD_EOV: 10130Sstevel@tonic-gate break; 10140Sstevel@tonic-gate } 10150Sstevel@tonic-gate brelse(secbp); 10160Sstevel@tonic-gate ++secno; 10170Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE); 10180Sstevel@tonic-gate 10190Sstevel@tonic-gate error = geterror(secbp); 10200Sstevel@tonic-gate 10210Sstevel@tonic-gate if (error != 0) { 10220Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)", 1023*4866Sfrankho error); 10240Sstevel@tonic-gate brelse(secbp); 10250Sstevel@tonic-gate return (error); 10260Sstevel@tonic-gate } 10270Sstevel@tonic-gate 10280Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 10290Sstevel@tonic-gate } 10300Sstevel@tonic-gate cantfind: 10310Sstevel@tonic-gate brelse(secbp); 10320Sstevel@tonic-gate return (EINVAL); 10330Sstevel@tonic-gate } 10340Sstevel@tonic-gate 10350Sstevel@tonic-gate /* 10360Sstevel@tonic-gate * hs_parsehsvol 10370Sstevel@tonic-gate * 10380Sstevel@tonic-gate * Parse the Standard File Structure Volume Descriptor into 10390Sstevel@tonic-gate * an hs_volume structure. We can't just bcopy it into the 10400Sstevel@tonic-gate * structure because of byte-ordering problems. 10410Sstevel@tonic-gate * 10420Sstevel@tonic-gate */ 10430Sstevel@tonic-gate static int 10440Sstevel@tonic-gate hs_parsehsvol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp) 10450Sstevel@tonic-gate { 10460Sstevel@tonic-gate hvp->vol_size = HSV_VOL_SIZE(volp); 10470Sstevel@tonic-gate hvp->lbn_size = HSV_BLK_SIZE(volp); 10480Sstevel@tonic-gate if (hvp->lbn_size == 0) { 10490Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_parsehsvol: logical block size in the " 1050*4866Sfrankho "SFSVD is zero"); 10510Sstevel@tonic-gate return (EINVAL); 10520Sstevel@tonic-gate } 10530Sstevel@tonic-gate hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1; 1054*4866Sfrankho hvp->lbn_secshift = 1055*4866Sfrankho ffs((long)howmany(HS_SECTOR_SIZE, (int)hvp->lbn_size)) - 1; 10560Sstevel@tonic-gate hvp->lbn_maxoffset = hvp->lbn_size - 1; 10570Sstevel@tonic-gate hs_parse_longdate(HSV_cre_date(volp), &hvp->cre_date); 10580Sstevel@tonic-gate hs_parse_longdate(HSV_mod_date(volp), &hvp->mod_date); 10590Sstevel@tonic-gate hvp->file_struct_ver = HSV_FILE_STRUCT_VER(volp); 10600Sstevel@tonic-gate hvp->ptbl_len = HSV_PTBL_SIZE(volp); 10610Sstevel@tonic-gate hvp->vol_set_size = (ushort_t)HSV_SET_SIZE(volp); 10620Sstevel@tonic-gate hvp->vol_set_seq = (ushort_t)HSV_SET_SEQ(volp); 10630Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 10640Sstevel@tonic-gate hvp->ptbl_lbn = HSV_PTBL_MAN_LS(volp); 10650Sstevel@tonic-gate #else 10660Sstevel@tonic-gate hvp->ptbl_lbn = HSV_PTBL_MAN_MS(volp); 10670Sstevel@tonic-gate #endif 10682900Sfrankho hs_copylabel(hvp, HSV_VOL_ID(volp), 0); 10690Sstevel@tonic-gate 10700Sstevel@tonic-gate /* 10710Sstevel@tonic-gate * Make sure that lbn_size is a power of two and otherwise valid. 10720Sstevel@tonic-gate */ 10730Sstevel@tonic-gate if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) { 10740Sstevel@tonic-gate cmn_err(CE_NOTE, 1075*4866Sfrankho "hsfs: %d-byte logical block size not supported", 1076*4866Sfrankho hvp->lbn_size); 10770Sstevel@tonic-gate return (EINVAL); 10780Sstevel@tonic-gate } 10790Sstevel@tonic-gate return (hs_parsedir(fsp, HSV_ROOT_DIR(volp), &hvp->root_dir, 1080*4866Sfrankho (char *)NULL, (int *)NULL, HDE_ROOT_DIR_REC_SIZE)); 10810Sstevel@tonic-gate } 10820Sstevel@tonic-gate 10830Sstevel@tonic-gate /* 10840Sstevel@tonic-gate * hs_findisovol() 10850Sstevel@tonic-gate * 10860Sstevel@tonic-gate * Locate the Primary Volume Descriptor 10870Sstevel@tonic-gate * parse it into an hs_volume structure. 10880Sstevel@tonic-gate * 10892900Sfrankho * XXX - Partition not yet done 10902900Sfrankho * 10912900Sfrankho * Except for fsp->hsfs_vol_type, no fsp member may be modified. 10922900Sfrankho * fsp->hsfs_vol is modified indirectly via the *hvp argument. 10930Sstevel@tonic-gate */ 10940Sstevel@tonic-gate static int 10950Sstevel@tonic-gate hs_findisovol(struct hsfs *fsp, struct vnode *vp, 10962900Sfrankho struct hs_volume *hvp, 10972900Sfrankho struct hs_volume *svp, 10982900Sfrankho struct hs_volume *jvp) 10990Sstevel@tonic-gate { 11000Sstevel@tonic-gate struct buf *secbp; 11010Sstevel@tonic-gate int i; 1102*4866Sfrankho int n; 11030Sstevel@tonic-gate uchar_t *volp; 11040Sstevel@tonic-gate int error; 11050Sstevel@tonic-gate uint_t secno; 11060Sstevel@tonic-gate int foundpvd = 0; 11072900Sfrankho int foundsvd = 0; 11082900Sfrankho int foundjvd = 0; 1109*4866Sfrankho int pvd_sum = 0; 11100Sstevel@tonic-gate 11110Sstevel@tonic-gate secno = hs_findvoldesc(vp->v_rdev, ISO_VOLDESC_SEC); 11120Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, ISO_SECTOR_SIZE); 11130Sstevel@tonic-gate error = geterror(secbp); 11140Sstevel@tonic-gate 11150Sstevel@tonic-gate if (error != 0) { 11160Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)", error); 11170Sstevel@tonic-gate brelse(secbp); 11180Sstevel@tonic-gate return (error); 11190Sstevel@tonic-gate } 11200Sstevel@tonic-gate 11210Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 11220Sstevel@tonic-gate 1123*4866Sfrankho /* 1124*4866Sfrankho * To avoid that we read the whole medium in case that someone prepares 1125*4866Sfrankho * a malicious "fs image", we read at most 32 blocks. 1126*4866Sfrankho */ 1127*4866Sfrankho for (n = 0; n < 32 && 1128*4866Sfrankho (enum iso_voldesc_type) ISO_DESC_TYPE(volp) != ISO_VD_EOV; n++) { 11290Sstevel@tonic-gate for (i = 0; i < ISO_ID_STRLEN; i++) 11300Sstevel@tonic-gate if (ISO_STD_ID(volp)[i] != ISO_ID_STRING[i]) 11310Sstevel@tonic-gate goto cantfind; 11320Sstevel@tonic-gate switch (ISO_DESC_TYPE(volp)) { 11330Sstevel@tonic-gate case ISO_VD_PVD: 11340Sstevel@tonic-gate /* Standard File Structure */ 11352900Sfrankho if (ISO_STD_VER(volp) != ISO_ID_VER) 11362900Sfrankho goto cantfind; 11370Sstevel@tonic-gate if (foundpvd != 1) { 11380Sstevel@tonic-gate fsp->hsfs_vol_type = HS_VOL_TYPE_ISO; 11390Sstevel@tonic-gate if (error = hs_parseisovol(fsp, volp, hvp)) { 11400Sstevel@tonic-gate brelse(secbp); 11410Sstevel@tonic-gate return (error); 11420Sstevel@tonic-gate } 11430Sstevel@tonic-gate foundpvd = 1; 1144*4866Sfrankho for (i = 0; i < ISO_SECTOR_SIZE; i++) 1145*4866Sfrankho pvd_sum += volp[i]; 11460Sstevel@tonic-gate } 11470Sstevel@tonic-gate break; 11480Sstevel@tonic-gate case ISO_VD_SVD: 11490Sstevel@tonic-gate /* Supplementary Volume Descriptor */ 11502900Sfrankho if (ISO_STD_VER(volp) == ISO_ID_VER2 && 11512900Sfrankho foundsvd != 1) { 11522900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_ISO; 11532900Sfrankho if (error = hs_parseisovol(fsp, volp, svp)) { 11542900Sfrankho brelse(secbp); 11552900Sfrankho return (error); 11562900Sfrankho } 11572900Sfrankho foundsvd = 1; 11582900Sfrankho } 11592900Sfrankho if (hs_joliet_level(volp) >= 1 && foundjvd != 1) { 11602900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_ISO; 11612900Sfrankho if (error = hs_parseisovol(fsp, volp, jvp)) { 11622900Sfrankho brelse(secbp); 11632900Sfrankho return (error); 11642900Sfrankho } 11652900Sfrankho foundjvd = 1; 11662900Sfrankho } 11670Sstevel@tonic-gate break; 11680Sstevel@tonic-gate case ISO_VD_BOOT: 11690Sstevel@tonic-gate break; 11700Sstevel@tonic-gate case ISO_VD_VPD: 11710Sstevel@tonic-gate /* currently cannot handle partition */ 11720Sstevel@tonic-gate break; 11730Sstevel@tonic-gate case VD_EOV: 11740Sstevel@tonic-gate break; 11750Sstevel@tonic-gate } 11760Sstevel@tonic-gate brelse(secbp); 11770Sstevel@tonic-gate ++secno; 11780Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE); 11790Sstevel@tonic-gate error = geterror(secbp); 11800Sstevel@tonic-gate 11810Sstevel@tonic-gate if (error != 0) { 11820Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)", 1183*4866Sfrankho error); 11840Sstevel@tonic-gate brelse(secbp); 11850Sstevel@tonic-gate return (error); 11860Sstevel@tonic-gate } 11870Sstevel@tonic-gate 11880Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 11890Sstevel@tonic-gate } 1190*4866Sfrankho for (n = 0; n < 16; n++) { 1191*4866Sfrankho brelse(secbp); 1192*4866Sfrankho ++secno; 1193*4866Sfrankho secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE); 1194*4866Sfrankho error = geterror(secbp); 1195*4866Sfrankho 1196*4866Sfrankho if (error != 0) { 1197*4866Sfrankho cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)", 1198*4866Sfrankho error); 1199*4866Sfrankho brelse(secbp); 1200*4866Sfrankho return (error); 1201*4866Sfrankho } 1202*4866Sfrankho 1203*4866Sfrankho /* 1204*4866Sfrankho * Check for the signature from mkisofs that grants that 1205*4866Sfrankho * the current filesystem allows to use the extent lbn as 1206*4866Sfrankho * inode number even in pure ISO9660 mode. 1207*4866Sfrankho */ 1208*4866Sfrankho volp = (uchar_t *)secbp->b_un.b_addr; 1209*4866Sfrankho if (strncmp((char *)volp, "MKI ", 4) == 0) { 1210*4866Sfrankho int sum; 1211*4866Sfrankho 1212*4866Sfrankho sum = volp[2045]; 1213*4866Sfrankho sum *= 256; 1214*4866Sfrankho sum += volp[2046]; 1215*4866Sfrankho sum *= 256; 1216*4866Sfrankho sum += volp[2047]; 1217*4866Sfrankho if (sum == pvd_sum) 1218*4866Sfrankho fsp->hsfs_flags |= HSFSMNT_INODE; 1219*4866Sfrankho break; 1220*4866Sfrankho } 1221*4866Sfrankho } 12220Sstevel@tonic-gate if (foundpvd) { 12230Sstevel@tonic-gate brelse(secbp); 12240Sstevel@tonic-gate return (0); 12250Sstevel@tonic-gate } 12260Sstevel@tonic-gate cantfind: 12270Sstevel@tonic-gate brelse(secbp); 12280Sstevel@tonic-gate return (EINVAL); 12290Sstevel@tonic-gate } 12302900Sfrankho 12312900Sfrankho /* 12322900Sfrankho * Return 0 if no Joliet is found 12332900Sfrankho * else return Joliet Level 1..3 12342900Sfrankho */ 12352900Sfrankho static int 12362900Sfrankho hs_joliet_level(uchar_t *volp) 12372900Sfrankho { 12382900Sfrankho if (ISO_std_ver(volp)[0] == ISO_ID_VER && 12392900Sfrankho ISO_svd_esc(volp)[0] == '%' && 12402900Sfrankho ISO_svd_esc(volp)[1] == '/') { 12412900Sfrankho 12422900Sfrankho switch (ISO_svd_esc(volp)[2]) { 12432900Sfrankho 12442900Sfrankho case '@': 12452900Sfrankho return (1); 12462900Sfrankho case 'C': 12472900Sfrankho return (2); 12482900Sfrankho case 'E': 12492900Sfrankho return (3); 12502900Sfrankho } 12512900Sfrankho } 12522900Sfrankho return (0); 12532900Sfrankho } 12542900Sfrankho 12550Sstevel@tonic-gate /* 12560Sstevel@tonic-gate * hs_parseisovol 12570Sstevel@tonic-gate * 12580Sstevel@tonic-gate * Parse the Primary Volume Descriptor into an hs_volume structure. 12590Sstevel@tonic-gate * 12600Sstevel@tonic-gate */ 12610Sstevel@tonic-gate static int 12620Sstevel@tonic-gate hs_parseisovol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp) 12630Sstevel@tonic-gate { 12640Sstevel@tonic-gate hvp->vol_size = ISO_VOL_SIZE(volp); 12650Sstevel@tonic-gate hvp->lbn_size = ISO_BLK_SIZE(volp); 12660Sstevel@tonic-gate if (hvp->lbn_size == 0) { 12670Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_parseisovol: logical block size in the " 1268*4866Sfrankho "PVD is zero"); 12690Sstevel@tonic-gate return (EINVAL); 12700Sstevel@tonic-gate } 12710Sstevel@tonic-gate hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1; 1272*4866Sfrankho hvp->lbn_secshift = 1273*4866Sfrankho ffs((long)howmany(ISO_SECTOR_SIZE, (int)hvp->lbn_size)) - 1; 12740Sstevel@tonic-gate hvp->lbn_maxoffset = hvp->lbn_size - 1; 12750Sstevel@tonic-gate hs_parse_longdate(ISO_cre_date(volp), &hvp->cre_date); 12760Sstevel@tonic-gate hs_parse_longdate(ISO_mod_date(volp), &hvp->mod_date); 12770Sstevel@tonic-gate hvp->file_struct_ver = ISO_FILE_STRUCT_VER(volp); 12780Sstevel@tonic-gate hvp->ptbl_len = ISO_PTBL_SIZE(volp); 12790Sstevel@tonic-gate hvp->vol_set_size = (ushort_t)ISO_SET_SIZE(volp); 12800Sstevel@tonic-gate hvp->vol_set_seq = (ushort_t)ISO_SET_SEQ(volp); 12810Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 12820Sstevel@tonic-gate hvp->ptbl_lbn = ISO_PTBL_MAN_LS(volp); 12830Sstevel@tonic-gate #else 12840Sstevel@tonic-gate hvp->ptbl_lbn = ISO_PTBL_MAN_MS(volp); 12850Sstevel@tonic-gate #endif 12862900Sfrankho hs_copylabel(hvp, ISO_VOL_ID(volp), hs_joliet_level(volp) >= 1); 12870Sstevel@tonic-gate 12880Sstevel@tonic-gate /* 12890Sstevel@tonic-gate * Make sure that lbn_size is a power of two and otherwise valid. 12900Sstevel@tonic-gate */ 12910Sstevel@tonic-gate if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) { 12920Sstevel@tonic-gate cmn_err(CE_NOTE, 1293*4866Sfrankho "hsfs: %d-byte logical block size not supported", 1294*4866Sfrankho hvp->lbn_size); 12950Sstevel@tonic-gate return (EINVAL); 12960Sstevel@tonic-gate } 12970Sstevel@tonic-gate return (hs_parsedir(fsp, ISO_ROOT_DIR(volp), &hvp->root_dir, 1298*4866Sfrankho (char *)NULL, (int *)NULL, IDE_ROOT_DIR_REC_SIZE)); 12990Sstevel@tonic-gate } 13000Sstevel@tonic-gate 13010Sstevel@tonic-gate /* 13020Sstevel@tonic-gate * Common code for mount and umount. 13030Sstevel@tonic-gate * Check that the user's argument is a reasonable 13040Sstevel@tonic-gate * thing on which to mount, and return the device number if so. 13050Sstevel@tonic-gate */ 13060Sstevel@tonic-gate static int 13070Sstevel@tonic-gate hs_getmdev(struct vfs *vfsp, char *fspec, int flags, dev_t *pdev, mode_t *mode, 13080Sstevel@tonic-gate cred_t *cr) 13090Sstevel@tonic-gate { 13100Sstevel@tonic-gate int error; 13110Sstevel@tonic-gate struct vnode *vp; 13120Sstevel@tonic-gate struct vattr vap; 13130Sstevel@tonic-gate dev_t dev; 13140Sstevel@tonic-gate 13150Sstevel@tonic-gate /* 13160Sstevel@tonic-gate * Get the device to be mounted 13170Sstevel@tonic-gate */ 13180Sstevel@tonic-gate error = lookupname(fspec, (flags & MS_SYSSPACE) ? 13190Sstevel@tonic-gate UIO_SYSSPACE : UIO_USERSPACE, FOLLOW, NULLVPP, &vp); 13200Sstevel@tonic-gate if (error) { 13210Sstevel@tonic-gate if (error == ENOENT) { 13220Sstevel@tonic-gate return (ENODEV); /* needs translation */ 13230Sstevel@tonic-gate } 13240Sstevel@tonic-gate return (error); 13250Sstevel@tonic-gate } 13260Sstevel@tonic-gate if (vp->v_type != VBLK) { 13270Sstevel@tonic-gate VN_RELE(vp); 13280Sstevel@tonic-gate return (ENOTBLK); 13290Sstevel@tonic-gate } 13300Sstevel@tonic-gate /* 13310Sstevel@tonic-gate * Can we read from the device? 13320Sstevel@tonic-gate */ 13330Sstevel@tonic-gate if ((error = VOP_ACCESS(vp, VREAD, 0, cr)) != 0 || 13340Sstevel@tonic-gate (error = secpolicy_spec_open(cr, vp, FREAD)) != 0) { 13350Sstevel@tonic-gate VN_RELE(vp); 13360Sstevel@tonic-gate return (error); 13370Sstevel@tonic-gate } 13380Sstevel@tonic-gate 13390Sstevel@tonic-gate vap.va_mask = AT_MODE; /* get protection mode */ 13400Sstevel@tonic-gate (void) VOP_GETATTR(vp, &vap, 0, CRED()); 13410Sstevel@tonic-gate *mode = vap.va_mode; 13420Sstevel@tonic-gate 13430Sstevel@tonic-gate dev = *pdev = vp->v_rdev; 13440Sstevel@tonic-gate VN_RELE(vp); 13450Sstevel@tonic-gate 13460Sstevel@tonic-gate /* 13470Sstevel@tonic-gate * Ensure that this device isn't already mounted, 13480Sstevel@tonic-gate * unless this is a REMOUNT request or we are told to suppress 13490Sstevel@tonic-gate * mount checks. 13500Sstevel@tonic-gate */ 13510Sstevel@tonic-gate if ((flags & MS_NOCHECK) == 0) { 13520Sstevel@tonic-gate if (vfs_devmounting(dev, vfsp)) 13530Sstevel@tonic-gate return (EBUSY); 13540Sstevel@tonic-gate if (vfs_devismounted(dev) && !(flags & MS_REMOUNT)) 13550Sstevel@tonic-gate return (EBUSY); 13560Sstevel@tonic-gate } 13570Sstevel@tonic-gate 13580Sstevel@tonic-gate if (getmajor(*pdev) >= devcnt) 13590Sstevel@tonic-gate return (ENXIO); 13600Sstevel@tonic-gate return (0); 13610Sstevel@tonic-gate } 13620Sstevel@tonic-gate 13630Sstevel@tonic-gate static void 13642900Sfrankho hs_copylabel(struct hs_volume *hvp, unsigned char *label, int isjoliet) 13650Sstevel@tonic-gate { 13662900Sfrankho char lbuf[64]; /* hs_joliet_cp() creates 48 bytes at most */ 13672900Sfrankho 13682900Sfrankho if (isjoliet) { 13692900Sfrankho /* 13702900Sfrankho * hs_joliet_cp() will output 16..48 bytes. 13712900Sfrankho * We need to clear 'lbuf' to avoid junk chars past byte 15. 13722900Sfrankho */ 13732900Sfrankho bzero(lbuf, sizeof (lbuf)); 13742904Sfrankho (void) hs_joliet_cp((char *)label, lbuf, 32); 13752900Sfrankho label = (unsigned char *)lbuf; 13762900Sfrankho } 13770Sstevel@tonic-gate /* cdrom volid is at most 32 bytes */ 13780Sstevel@tonic-gate bcopy(label, hvp->vol_id, 32); 13790Sstevel@tonic-gate hvp->vol_id[31] = NULL; 13800Sstevel@tonic-gate } 13810Sstevel@tonic-gate 13820Sstevel@tonic-gate /* 13830Sstevel@tonic-gate * Mount root file system. 13840Sstevel@tonic-gate * "why" is ROOT_INIT on initial call, ROOT_REMOUNT if called to 13850Sstevel@tonic-gate * remount the root file system, and ROOT_UNMOUNT if called to 13860Sstevel@tonic-gate * unmount the root (e.g., as part of a system shutdown). 13870Sstevel@tonic-gate * 13880Sstevel@tonic-gate * XXX - this may be partially machine-dependent; it, along with the VFS_SWAPVP 13890Sstevel@tonic-gate * operation, goes along with auto-configuration. A mechanism should be 13900Sstevel@tonic-gate * provided by which machine-INdependent code in the kernel can say "get me the 13910Sstevel@tonic-gate * right root file system" and "get me the right initial swap area", and have 13920Sstevel@tonic-gate * that done in what may well be a machine-dependent fashion. 13930Sstevel@tonic-gate * Unfortunately, it is also file-system-type dependent (NFS gets it via 13940Sstevel@tonic-gate * bootparams calls, UFS gets it from various and sundry machine-dependent 13950Sstevel@tonic-gate * mechanisms, as SPECFS does for swap). 13960Sstevel@tonic-gate */ 13970Sstevel@tonic-gate static int 13980Sstevel@tonic-gate hsfs_mountroot(struct vfs *vfsp, enum whymountroot why) 13990Sstevel@tonic-gate { 14000Sstevel@tonic-gate int error; 14010Sstevel@tonic-gate struct hsfs *fsp; 14020Sstevel@tonic-gate struct hs_volume *fvolp; 14030Sstevel@tonic-gate static int hsfsrootdone = 0; 14040Sstevel@tonic-gate dev_t rootdev; 14050Sstevel@tonic-gate mode_t mode = 0; 14060Sstevel@tonic-gate 14070Sstevel@tonic-gate if (why == ROOT_INIT) { 14080Sstevel@tonic-gate if (hsfsrootdone++) 14090Sstevel@tonic-gate return (EBUSY); 14100Sstevel@tonic-gate rootdev = getrootdev(); 14110Sstevel@tonic-gate if (rootdev == (dev_t)NODEV) 14120Sstevel@tonic-gate return (ENODEV); 14130Sstevel@tonic-gate vfsp->vfs_dev = rootdev; 14140Sstevel@tonic-gate vfsp->vfs_flag |= VFS_RDONLY; 14150Sstevel@tonic-gate } else if (why == ROOT_REMOUNT) { 14160Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: ROOT_REMOUNT"); 14170Sstevel@tonic-gate return (0); 14180Sstevel@tonic-gate } else if (why == ROOT_UNMOUNT) { 14190Sstevel@tonic-gate return (0); 14200Sstevel@tonic-gate } 14210Sstevel@tonic-gate error = vfs_lock(vfsp); 14220Sstevel@tonic-gate if (error) { 14230Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: couldn't get vfs_lock"); 14240Sstevel@tonic-gate return (error); 14250Sstevel@tonic-gate } 14260Sstevel@tonic-gate 14270Sstevel@tonic-gate error = hs_mountfs(vfsp, rootdev, "/", mode, 1, CRED(), 1); 14280Sstevel@tonic-gate /* 14290Sstevel@tonic-gate * XXX - assumes root device is not indirect, because we don't set 14300Sstevel@tonic-gate * rootvp. Is rootvp used for anything? If so, make another arg 14310Sstevel@tonic-gate * to mountfs. 14320Sstevel@tonic-gate */ 14330Sstevel@tonic-gate if (error) { 14340Sstevel@tonic-gate vfs_unlock(vfsp); 14350Sstevel@tonic-gate if (rootvp) { 14360Sstevel@tonic-gate VN_RELE(rootvp); 14370Sstevel@tonic-gate rootvp = (struct vnode *)0; 14380Sstevel@tonic-gate } 14390Sstevel@tonic-gate return (error); 14400Sstevel@tonic-gate } 14410Sstevel@tonic-gate if (why == ROOT_INIT) 14420Sstevel@tonic-gate vfs_add((struct vnode *)0, vfsp, 14430Sstevel@tonic-gate (vfsp->vfs_flag & VFS_RDONLY) ? MS_RDONLY : 0); 14440Sstevel@tonic-gate vfs_unlock(vfsp); 14450Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp); 14460Sstevel@tonic-gate fvolp = &fsp->hsfs_vol; 14470Sstevel@tonic-gate #ifdef HSFS_CLKSET 14480Sstevel@tonic-gate if (fvolp->cre_date.tv_sec == 0) { 1449*4866Sfrankho cmn_err(CE_NOTE, "hsfs_mountroot: cre_date.tv_sec == 0"); 1450*4866Sfrankho if (fvolp->mod_date.tv_sec == 0) { 1451*4866Sfrankho cmn_err(CE_NOTE, 1452*4866Sfrankho "hsfs_mountroot: mod_date.tv_sec == 0"); 1453*4866Sfrankho cmn_err(CE_NOTE, "hsfs_mountroot: clkset(-1L)"); 1454*4866Sfrankho clkset(-1L); 1455*4866Sfrankho } else { 1456*4866Sfrankho clkset(fvolp->mod_date.tv_sec); 1457*4866Sfrankho } 1458*4866Sfrankho } else { 14590Sstevel@tonic-gate clkset(fvolp->mod_date.tv_sec); 1460*4866Sfrankho } 14610Sstevel@tonic-gate #else /* HSFS_CLKSET */ 14620Sstevel@tonic-gate clkset(-1L); 14630Sstevel@tonic-gate #endif /* HSFS_CLKSET */ 14640Sstevel@tonic-gate return (0); 14650Sstevel@tonic-gate } 14660Sstevel@tonic-gate 14670Sstevel@tonic-gate /* 14680Sstevel@tonic-gate * hs_findvoldesc() 14690Sstevel@tonic-gate * 14700Sstevel@tonic-gate * Return the sector where the volume descriptor lives. This is 14710Sstevel@tonic-gate * a fixed value for "normal" cd-rom's, but can change for 14720Sstevel@tonic-gate * multisession cd's. 14730Sstevel@tonic-gate * 14740Sstevel@tonic-gate * desc_sec is the same for high-sierra and iso 9660 formats, why 14750Sstevel@tonic-gate * there are two differnt #defines used in the code for this is 14760Sstevel@tonic-gate * beyond me. These are standards, cast in concrete, right? 14770Sstevel@tonic-gate * To be general, however, this function supports passing in different 14780Sstevel@tonic-gate * values. 14790Sstevel@tonic-gate */ 14800Sstevel@tonic-gate static int 14810Sstevel@tonic-gate hs_findvoldesc(dev_t rdev, int desc_sec) 14820Sstevel@tonic-gate { 14830Sstevel@tonic-gate int secno; 14840Sstevel@tonic-gate int error; 14850Sstevel@tonic-gate int rval; /* ignored */ 14860Sstevel@tonic-gate 14870Sstevel@tonic-gate #ifdef CDROMREADOFFSET 14880Sstevel@tonic-gate /* 14890Sstevel@tonic-gate * Issue the Read Offset ioctl directly to the 14900Sstevel@tonic-gate * device. Ignore any errors and set starting 14910Sstevel@tonic-gate * secno to the default, otherwise add the 14920Sstevel@tonic-gate * VOLDESC sector number to the offset. 14930Sstevel@tonic-gate */ 14940Sstevel@tonic-gate error = cdev_ioctl(rdev, CDROMREADOFFSET, (intptr_t)&secno, 14950Sstevel@tonic-gate FNATIVE|FKIOCTL|FREAD, CRED(), &rval); 14960Sstevel@tonic-gate if (error) { 14970Sstevel@tonic-gate secno = desc_sec; 14980Sstevel@tonic-gate } else { 14990Sstevel@tonic-gate secno += desc_sec; 15000Sstevel@tonic-gate } 15010Sstevel@tonic-gate #else 15020Sstevel@tonic-gate secno = desc_sec; 15030Sstevel@tonic-gate #endif 15040Sstevel@tonic-gate 15050Sstevel@tonic-gate return (secno); 15060Sstevel@tonic-gate } 1507