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 1405312Smg147109 /* 1415312Smg147109 * Indicates whether to enable the I/O scheduling and readahead logic 1425312Smg147109 * 1 - Enable, 0 - Do not Enable. 1435312Smg147109 * Debugging purposes. 1445312Smg147109 */ 1455312Smg147109 int do_schedio = 1; 1462900Sfrankho static int hsfsfstype; 1470Sstevel@tonic-gate static int hsfsinit(int, char *); 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate static vfsdef_t vfw = { 1500Sstevel@tonic-gate VFSDEF_VERSION, 1510Sstevel@tonic-gate "hsfs", 1520Sstevel@tonic-gate hsfsinit, 1531488Srsb VSW_HASPROTO|VSW_STATS, /* We don't suppport remounting */ 1540Sstevel@tonic-gate &hsfs_proto_opttbl 1550Sstevel@tonic-gate }; 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate static struct modlfs modlfs = { 1580Sstevel@tonic-gate &mod_fsops, "filesystem for HSFS", &vfw 1590Sstevel@tonic-gate }; 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate static struct modlinkage modlinkage = { 1620Sstevel@tonic-gate MODREV_1, (void *)&modlfs, NULL 1630Sstevel@tonic-gate }; 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate char _depends_on[] = "fs/specfs"; 1660Sstevel@tonic-gate 1675312Smg147109 extern void hsched_init_caches(void); 1685312Smg147109 extern void hsched_fini_caches(void); 1695312Smg147109 1705312Smg147109 1710Sstevel@tonic-gate int 1722900Sfrankho _init(void) 1730Sstevel@tonic-gate { 1740Sstevel@tonic-gate return (mod_install(&modlinkage)); 1750Sstevel@tonic-gate } 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate int 1782900Sfrankho _fini(void) 1790Sstevel@tonic-gate { 1802900Sfrankho int error; 1812900Sfrankho 1822900Sfrankho error = mod_remove(&modlinkage); 1832900Sfrankho 1842900Sfrankho DTRACE_PROBE1(mod_remove, int, error); 1852900Sfrankho 1862900Sfrankho if (error) 1872900Sfrankho return (error); 1882900Sfrankho 1892900Sfrankho mutex_destroy(&hs_mounttab_lock); 1902900Sfrankho 1912900Sfrankho /* 1922900Sfrankho * Tear down the operations vectors 1932900Sfrankho */ 1942900Sfrankho (void) vfs_freevfsops_by_type(hsfsfstype); 1952900Sfrankho vn_freevnodeops(hsfs_vnodeops); 1962900Sfrankho 1972900Sfrankho hs_fini_hsnode_cache(); 1985312Smg147109 hsched_fini_caches(); 1992900Sfrankho return (0); 2000Sstevel@tonic-gate } 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate int 2030Sstevel@tonic-gate _info(struct modinfo *modinfop) 2040Sstevel@tonic-gate { 2050Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 2060Sstevel@tonic-gate } 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate #define BDEVFLAG(dev) ((devopsp[getmajor(dev)])->devo_cb_ops->cb_flag) 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate kmutex_t hs_mounttab_lock; 2110Sstevel@tonic-gate struct hsfs *hs_mounttab = NULL; 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate /* default mode, uid, gid */ 2140Sstevel@tonic-gate mode_t hsfs_default_mode = 0555; 2150Sstevel@tonic-gate uid_t hsfs_default_uid = 0; 2160Sstevel@tonic-gate gid_t hsfs_default_gid = 3; 2170Sstevel@tonic-gate 2185312Smg147109 extern void hsched_init(struct hsfs *fsp, int fsid, 2195312Smg147109 struct modlinkage *modlinkage); 2205312Smg147109 extern void hsched_fini(struct hsfs_queue *hqueue); 2215312Smg147109 extern void hsfs_init_kstats(struct hsfs *fsp, int fsid); 2225312Smg147109 extern void hsfs_fini_kstats(struct hsfs *fsp); 2235312Smg147109 2240Sstevel@tonic-gate static int hsfs_mount(struct vfs *vfsp, struct vnode *mvp, 2250Sstevel@tonic-gate struct mounta *uap, struct cred *cr); 2260Sstevel@tonic-gate static int hsfs_unmount(struct vfs *vfsp, int, struct cred *cr); 2270Sstevel@tonic-gate static int hsfs_root(struct vfs *vfsp, struct vnode **vpp); 2280Sstevel@tonic-gate static int hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp); 2290Sstevel@tonic-gate static int hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp); 2300Sstevel@tonic-gate static int hsfs_mountroot(struct vfs *, enum whymountroot); 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate static int hs_mountfs(struct vfs *vfsp, dev_t dev, char *path, 2330Sstevel@tonic-gate mode_t mode, int flags, struct cred *cr, int isroot); 2342900Sfrankho static int hs_getrootvp(struct vfs *vfsp, struct hsfs *fsp, size_t pathsize); 2350Sstevel@tonic-gate static int hs_findhsvol(struct hsfs *fsp, struct vnode *vp, 2360Sstevel@tonic-gate struct hs_volume *hvp); 2370Sstevel@tonic-gate static int hs_parsehsvol(struct hsfs *fsp, uchar_t *volp, 2380Sstevel@tonic-gate struct hs_volume *hvp); 2390Sstevel@tonic-gate static int hs_findisovol(struct hsfs *fsp, struct vnode *vp, 2402900Sfrankho struct hs_volume *hvp, 2412900Sfrankho struct hs_volume *svp, 2422900Sfrankho struct hs_volume *jvp); 2432900Sfrankho static int hs_joliet_level(uchar_t *volp); 2440Sstevel@tonic-gate static int hs_parseisovol(struct hsfs *fsp, uchar_t *volp, 2450Sstevel@tonic-gate struct hs_volume *hvp); 2462900Sfrankho static void hs_copylabel(struct hs_volume *, unsigned char *, int); 2470Sstevel@tonic-gate static int hs_getmdev(struct vfs *, char *fspec, int flags, dev_t *pdev, 2480Sstevel@tonic-gate mode_t *mode, cred_t *cr); 2490Sstevel@tonic-gate static int hs_findvoldesc(dev_t rdev, int desc_sec); 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate static int 2520Sstevel@tonic-gate hsfsinit(int fstype, char *name) 2530Sstevel@tonic-gate { 2540Sstevel@tonic-gate static const fs_operation_def_t hsfs_vfsops_template[] = { 2553898Srsb VFSNAME_MOUNT, { .vfs_mount = hsfs_mount }, 2563898Srsb VFSNAME_UNMOUNT, { .vfs_unmount = hsfs_unmount }, 2573898Srsb VFSNAME_ROOT, { .vfs_root = hsfs_root }, 2583898Srsb VFSNAME_STATVFS, { .vfs_statvfs = hsfs_statvfs }, 2593898Srsb VFSNAME_VGET, { .vfs_vget = hsfs_vget }, 2603898Srsb VFSNAME_MOUNTROOT, { .vfs_mountroot = hsfs_mountroot }, 2613898Srsb NULL, NULL 2620Sstevel@tonic-gate }; 2630Sstevel@tonic-gate int error; 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate error = vfs_setfsops(fstype, hsfs_vfsops_template, NULL); 2660Sstevel@tonic-gate if (error != 0) { 2670Sstevel@tonic-gate cmn_err(CE_WARN, "hsfsinit: bad vfs ops template"); 2680Sstevel@tonic-gate return (error); 2690Sstevel@tonic-gate } 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate error = vn_make_ops(name, hsfs_vnodeops_template, &hsfs_vnodeops); 2720Sstevel@tonic-gate if (error != 0) { 2730Sstevel@tonic-gate (void) vfs_freevfsops_by_type(fstype); 2740Sstevel@tonic-gate cmn_err(CE_WARN, "hsfsinit: bad vnode ops template"); 2750Sstevel@tonic-gate return (error); 2760Sstevel@tonic-gate } 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate hsfsfstype = fstype; 2790Sstevel@tonic-gate mutex_init(&hs_mounttab_lock, NULL, MUTEX_DEFAULT, NULL); 2800Sstevel@tonic-gate hs_init_hsnode_cache(); 2815312Smg147109 hsched_init_caches(); 2820Sstevel@tonic-gate return (0); 2830Sstevel@tonic-gate } 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate /*ARGSUSED*/ 2860Sstevel@tonic-gate static int 2870Sstevel@tonic-gate hsfs_mount(struct vfs *vfsp, struct vnode *mvp, 2880Sstevel@tonic-gate struct mounta *uap, struct cred *cr) 2890Sstevel@tonic-gate { 2900Sstevel@tonic-gate int vnode_busy; 2910Sstevel@tonic-gate dev_t dev; 2920Sstevel@tonic-gate struct pathname dpn; 2930Sstevel@tonic-gate int error; 2940Sstevel@tonic-gate mode_t mode; 2950Sstevel@tonic-gate int flags; /* this will hold the mount specific data */ 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate if ((error = secpolicy_fs_mount(cr, mvp, vfsp)) != 0) 2980Sstevel@tonic-gate return (error); 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate if (mvp->v_type != VDIR) 3010Sstevel@tonic-gate return (ENOTDIR); 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate /* mount option must be read only, else mount will be rejected */ 3040Sstevel@tonic-gate if (!(uap->flags & MS_RDONLY)) 3050Sstevel@tonic-gate return (EROFS); 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate /* 3080Sstevel@tonic-gate * We already told the framework that we don't support remounting. 3090Sstevel@tonic-gate */ 3100Sstevel@tonic-gate ASSERT(!(uap->flags & MS_REMOUNT)); 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate mutex_enter(&mvp->v_lock); 3130Sstevel@tonic-gate vnode_busy = (mvp->v_count != 1) || (mvp->v_flag & VROOT); 3140Sstevel@tonic-gate mutex_exit(&mvp->v_lock); 3150Sstevel@tonic-gate 3160Sstevel@tonic-gate if ((uap->flags & MS_OVERLAY) == 0 && vnode_busy) { 3170Sstevel@tonic-gate return (EBUSY); 3180Sstevel@tonic-gate } 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate /* 3210Sstevel@tonic-gate * Check for the options that actually affect things 3220Sstevel@tonic-gate * at our level. 3230Sstevel@tonic-gate */ 3240Sstevel@tonic-gate flags = 0; 3250Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NOMAPLCASE, NULL)) 3264866Sfrankho flags |= HSFSMNT_NOMAPLCASE; 3270Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NOTRAILDOT, NULL)) 3284866Sfrankho flags |= HSFSMNT_NOTRAILDOT; 3290Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NRR, NULL)) 3304866Sfrankho flags |= HSFSMNT_NORRIP; 3312900Sfrankho if (vfs_optionisset(vfsp, HOPT_NOJOLIET, NULL)) 3324866Sfrankho flags |= HSFSMNT_NOJOLIET; 3332900Sfrankho if (vfs_optionisset(vfsp, HOPT_JOLIETLONG, NULL)) 3344866Sfrankho flags |= HSFSMNT_JOLIETLONG; 3352900Sfrankho if (vfs_optionisset(vfsp, HOPT_NOVERS2, NULL)) 3364866Sfrankho flags |= HSFSMNT_NOVERS2; 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate error = pn_get(uap->dir, (uap->flags & MS_SYSSPACE) ? 3390Sstevel@tonic-gate UIO_SYSSPACE : UIO_USERSPACE, &dpn); 3400Sstevel@tonic-gate if (error) 3410Sstevel@tonic-gate return (error); 3420Sstevel@tonic-gate 3434866Sfrankho error = hs_getmdev(vfsp, uap->spec, uap->flags, &dev, &mode, cr); 3444866Sfrankho if (error != 0) { 3450Sstevel@tonic-gate pn_free(&dpn); 3460Sstevel@tonic-gate return (error); 3470Sstevel@tonic-gate } 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate /* 3500Sstevel@tonic-gate * If the device is a tape, return error 3510Sstevel@tonic-gate */ 3520Sstevel@tonic-gate if ((BDEVFLAG(dev) & D_TAPE) == D_TAPE) { 3530Sstevel@tonic-gate pn_free(&dpn); 3540Sstevel@tonic-gate return (ENOTBLK); 3550Sstevel@tonic-gate } 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate /* 3580Sstevel@tonic-gate * Mount the filesystem. 3590Sstevel@tonic-gate */ 3600Sstevel@tonic-gate error = hs_mountfs(vfsp, dev, dpn.pn_path, mode, flags, cr, 0); 3610Sstevel@tonic-gate pn_free(&dpn); 3620Sstevel@tonic-gate return (error); 3630Sstevel@tonic-gate } 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate /*ARGSUSED*/ 3660Sstevel@tonic-gate static int 3670Sstevel@tonic-gate hsfs_unmount( 3680Sstevel@tonic-gate struct vfs *vfsp, 3690Sstevel@tonic-gate int flag, 3700Sstevel@tonic-gate struct cred *cr) 3710Sstevel@tonic-gate { 3720Sstevel@tonic-gate struct hsfs **tspp; 3730Sstevel@tonic-gate struct hsfs *fsp; 3740Sstevel@tonic-gate 3750Sstevel@tonic-gate if (secpolicy_fs_unmount(cr, vfsp) != 0) 3760Sstevel@tonic-gate return (EPERM); 3770Sstevel@tonic-gate 3780Sstevel@tonic-gate /* 3790Sstevel@tonic-gate * forced unmount is not supported by this file system 3800Sstevel@tonic-gate * and thus, ENOTSUP is being returned. 3810Sstevel@tonic-gate */ 3820Sstevel@tonic-gate if (flag & MS_FORCE) 3830Sstevel@tonic-gate return (ENOTSUP); 3840Sstevel@tonic-gate 3850Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp); 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate if (fsp->hsfs_rootvp->v_count != 1) 3880Sstevel@tonic-gate return (EBUSY); 3890Sstevel@tonic-gate 3900Sstevel@tonic-gate /* destroy all old pages and hsnodes for this vfs */ 3910Sstevel@tonic-gate if (hs_synchash(vfsp)) 3920Sstevel@tonic-gate return (EBUSY); 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate mutex_enter(&hs_mounttab_lock); 3950Sstevel@tonic-gate for (tspp = &hs_mounttab; *tspp != NULL; tspp = &(*tspp)->hsfs_next) { 3960Sstevel@tonic-gate if (*tspp == fsp) 3970Sstevel@tonic-gate break; 3980Sstevel@tonic-gate } 3990Sstevel@tonic-gate if (*tspp == NULL) { 4000Sstevel@tonic-gate mutex_exit(&hs_mounttab_lock); 4010Sstevel@tonic-gate panic("hsfs_unmount: vfs not mounted?"); 4020Sstevel@tonic-gate /*NOTREACHED*/ 4030Sstevel@tonic-gate } 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate *tspp = fsp->hsfs_next; 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate mutex_exit(&hs_mounttab_lock); 4080Sstevel@tonic-gate 4095312Smg147109 hsfs_fini_kstats(fsp); 410*5331Samw (void) VOP_CLOSE(fsp->hsfs_devvp, FREAD, 1, (offset_t)0, cr, NULL); 4110Sstevel@tonic-gate VN_RELE(fsp->hsfs_devvp); 4120Sstevel@tonic-gate /* free path table space */ 4130Sstevel@tonic-gate if (fsp->hsfs_ptbl != NULL) 4144866Sfrankho kmem_free(fsp->hsfs_ptbl, (size_t)fsp->hsfs_vol.ptbl_len); 4150Sstevel@tonic-gate /* free path table index table */ 4160Sstevel@tonic-gate if (fsp->hsfs_ptbl_idx != NULL) 4170Sstevel@tonic-gate kmem_free(fsp->hsfs_ptbl_idx, (size_t) 4184866Sfrankho (fsp->hsfs_ptbl_idx_size * sizeof (struct ptable_idx))); 4190Sstevel@tonic-gate 4200Sstevel@tonic-gate /* free "mounted on" pathame */ 4210Sstevel@tonic-gate if (fsp->hsfs_fsmnt != NULL) 4220Sstevel@tonic-gate kmem_free(fsp->hsfs_fsmnt, strlen(fsp->hsfs_fsmnt) + 1); 4230Sstevel@tonic-gate 4245312Smg147109 hsched_fini(fsp->hqueue); 4255312Smg147109 kmem_free(fsp->hqueue, sizeof (struct hsfs_queue)); 4265312Smg147109 4270Sstevel@tonic-gate mutex_destroy(&fsp->hsfs_free_lock); 4280Sstevel@tonic-gate rw_destroy(&fsp->hsfs_hash_lock); 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate kmem_free(fsp, sizeof (*fsp)); 4310Sstevel@tonic-gate return (0); 4320Sstevel@tonic-gate } 4330Sstevel@tonic-gate 4340Sstevel@tonic-gate /*ARGSUSED*/ 4350Sstevel@tonic-gate static int 4360Sstevel@tonic-gate hsfs_root(struct vfs *vfsp, struct vnode **vpp) 4370Sstevel@tonic-gate { 4380Sstevel@tonic-gate *vpp = (VFS_TO_HSFS(vfsp))->hsfs_rootvp; 4390Sstevel@tonic-gate VN_HOLD(*vpp); 4400Sstevel@tonic-gate return (0); 4410Sstevel@tonic-gate } 4420Sstevel@tonic-gate 4430Sstevel@tonic-gate /*ARGSUSED*/ 4440Sstevel@tonic-gate static int 4450Sstevel@tonic-gate hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp) 4460Sstevel@tonic-gate { 4470Sstevel@tonic-gate struct hsfs *fsp; 4480Sstevel@tonic-gate dev32_t d32; 4490Sstevel@tonic-gate 4500Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp); 4510Sstevel@tonic-gate if (fsp->hsfs_magic != HSFS_MAGIC) 4520Sstevel@tonic-gate return (EINVAL); 4530Sstevel@tonic-gate bzero(sbp, sizeof (*sbp)); 4540Sstevel@tonic-gate sbp->f_bsize = vfsp->vfs_bsize; 4550Sstevel@tonic-gate sbp->f_frsize = sbp->f_bsize; /* no fragment, same as block size */ 4560Sstevel@tonic-gate sbp->f_blocks = (fsblkcnt64_t)fsp->hsfs_vol.vol_size; 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate sbp->f_bfree = (fsblkcnt64_t)0; 4590Sstevel@tonic-gate sbp->f_bavail = (fsblkcnt64_t)0; 4600Sstevel@tonic-gate sbp->f_files = (fsfilcnt64_t)-1; 4610Sstevel@tonic-gate sbp->f_ffree = (fsfilcnt64_t)0; 4620Sstevel@tonic-gate sbp->f_favail = (fsfilcnt64_t)0; 4630Sstevel@tonic-gate (void) cmpldev(&d32, vfsp->vfs_dev); 4640Sstevel@tonic-gate sbp->f_fsid = d32; 4650Sstevel@tonic-gate (void) strcpy(sbp->f_basetype, vfssw[vfsp->vfs_fstype].vsw_name); 4660Sstevel@tonic-gate sbp->f_flag = vf_to_stf(vfsp->vfs_flag); 4670Sstevel@tonic-gate sbp->f_namemax = fsp->hsfs_namemax; 4680Sstevel@tonic-gate (void) strcpy(sbp->f_fstr, fsp->hsfs_vol.vol_id); 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate return (0); 4710Sstevel@tonic-gate } 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate /* 4740Sstevel@tonic-gate * Previously nodeid was declared as uint32_t. This has been changed 4750Sstevel@tonic-gate * to conform better with the ISO9660 standard. The standard states that 4760Sstevel@tonic-gate * a LBN can be a 32 bit number, as the MAKE_NODEID macro shifts this 4770Sstevel@tonic-gate * LBN 11 places left (LBN_TO_BYTE) and then shifts the result 5 right 4780Sstevel@tonic-gate * (divide by 32) we are left with the potential of an overflow if 4790Sstevel@tonic-gate * confined to a 32 bit value. 4800Sstevel@tonic-gate */ 4810Sstevel@tonic-gate 4820Sstevel@tonic-gate static int 4830Sstevel@tonic-gate hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp) 4840Sstevel@tonic-gate { 4850Sstevel@tonic-gate struct hsfid *fid; 4860Sstevel@tonic-gate struct hsfs *fsp; 4870Sstevel@tonic-gate ino64_t nodeid; 4880Sstevel@tonic-gate int error; 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate fsp = (struct hsfs *)VFS_TO_HSFS(vfsp); 4910Sstevel@tonic-gate fid = (struct hsfid *)fidp; 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate /* 4940Sstevel@tonic-gate * Look for vnode on hashlist. 4950Sstevel@tonic-gate * If found, it's now active and the refcnt was incremented. 4960Sstevel@tonic-gate */ 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate rw_enter(&fsp->hsfs_hash_lock, RW_READER); 4990Sstevel@tonic-gate 5004866Sfrankho nodeid = fid->hf_ino; 5010Sstevel@tonic-gate 5024866Sfrankho if ((*vpp = hs_findhash(nodeid, fid->hf_dir_lbn, 5034866Sfrankho (uint_t)fid->hf_dir_off, vfsp)) == NULL) { 5040Sstevel@tonic-gate /* 5050Sstevel@tonic-gate * Not in cache, so we need to remake it. 5060Sstevel@tonic-gate * hs_remakenode() will read the directory entry 5070Sstevel@tonic-gate * and then check again to see if anyone else has 5080Sstevel@tonic-gate * put it in the cache. 5090Sstevel@tonic-gate */ 5100Sstevel@tonic-gate rw_exit(&fsp->hsfs_hash_lock); 5110Sstevel@tonic-gate error = hs_remakenode(fid->hf_dir_lbn, (uint_t)fid->hf_dir_off, 5120Sstevel@tonic-gate vfsp, vpp); 5130Sstevel@tonic-gate return (error); 5140Sstevel@tonic-gate } 5150Sstevel@tonic-gate rw_exit(&fsp->hsfs_hash_lock); 5160Sstevel@tonic-gate return (0); 5170Sstevel@tonic-gate } 5180Sstevel@tonic-gate 5190Sstevel@tonic-gate 5200Sstevel@tonic-gate #define CHECKSUM_SIZE (64 * 1024) 5210Sstevel@tonic-gate 5220Sstevel@tonic-gate /* 5230Sstevel@tonic-gate * Compute a CD-ROM fsid by checksumming the first 64K of data on the CD 5240Sstevel@tonic-gate * We use the 'fsp' argument to determine the location of the root 5250Sstevel@tonic-gate * directory entry, and we start reading from there. 5260Sstevel@tonic-gate */ 5270Sstevel@tonic-gate static int 5280Sstevel@tonic-gate compute_cdrom_id(struct hsfs *fsp, vnode_t *devvp) 5290Sstevel@tonic-gate { 5300Sstevel@tonic-gate uint_t secno; 5310Sstevel@tonic-gate struct hs_volume *hsvp = &fsp->hsfs_vol; 5320Sstevel@tonic-gate struct buf *bp; 5330Sstevel@tonic-gate int error; 5340Sstevel@tonic-gate int fsid; 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate secno = hsvp->root_dir.ext_lbn >> hsvp->lbn_secshift; 537494Sfrankho bp = bread(devvp->v_rdev, secno * 4, CHECKSUM_SIZE); 5380Sstevel@tonic-gate error = geterror(bp); 539494Sfrankho 540494Sfrankho /* 541494Sfrankho * An error on read or a partial read means we asked 542494Sfrankho * for a nonexistant/corrupted piece of the device 543494Sfrankho * (including past-the-end of the media). Don't 544494Sfrankho * try to use the checksumming method then. 545494Sfrankho */ 546494Sfrankho if (!error && bp->b_bcount == CHECKSUM_SIZE) { 5470Sstevel@tonic-gate int *ibuf = (int *)bp->b_un.b_addr; 5480Sstevel@tonic-gate int i; 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate fsid = 0; 5510Sstevel@tonic-gate 552494Sfrankho for (i = 0; i < CHECKSUM_SIZE / sizeof (int); i++) 5530Sstevel@tonic-gate fsid ^= ibuf[ i ]; 554494Sfrankho } else { 555494Sfrankho /* 556494Sfrankho * Fallback - use creation date 557494Sfrankho */ 5580Sstevel@tonic-gate fsid = hsvp->cre_date.tv_sec; 559494Sfrankho } 5600Sstevel@tonic-gate 5610Sstevel@tonic-gate brelse(bp); 5620Sstevel@tonic-gate 5630Sstevel@tonic-gate return (fsid); 5640Sstevel@tonic-gate } 5650Sstevel@tonic-gate 5660Sstevel@tonic-gate 5670Sstevel@tonic-gate /*ARGSUSED*/ 5680Sstevel@tonic-gate static int 5690Sstevel@tonic-gate hs_mountfs( 5700Sstevel@tonic-gate struct vfs *vfsp, 5710Sstevel@tonic-gate dev_t dev, 5720Sstevel@tonic-gate char *path, 5730Sstevel@tonic-gate mode_t mode, 5740Sstevel@tonic-gate int mount_flags, 5750Sstevel@tonic-gate struct cred *cr, 5760Sstevel@tonic-gate int isroot) 5770Sstevel@tonic-gate { 5780Sstevel@tonic-gate struct vnode *devvp; 5790Sstevel@tonic-gate struct hsfs *tsp; 5800Sstevel@tonic-gate struct hsfs *fsp = NULL; 5810Sstevel@tonic-gate struct vattr vap; 5820Sstevel@tonic-gate struct hsnode *hp; 5830Sstevel@tonic-gate int error; 5840Sstevel@tonic-gate struct timeval tv; 5850Sstevel@tonic-gate int fsid; 5862900Sfrankho int use_rrip; 5872900Sfrankho int use_vers2; 5882900Sfrankho int use_joliet; 5892900Sfrankho int has_rrip = 0; 5902900Sfrankho int has_vers2 = 0; 5912900Sfrankho int has_joliet = 0; 5922900Sfrankho int force_rrip_off; 5932900Sfrankho int force_vers2_off; 5942900Sfrankho int force_joliet_off; 5952900Sfrankho size_t pathbufsz = strlen(path) + 1; 5962900Sfrankho int redo_rootvp; 5972900Sfrankho 5982900Sfrankho struct hs_volume *svp; /* Supplemental VD for ISO-9660:1999 */ 5992900Sfrankho struct hs_volume *jvp; /* Joliet VD */ 6002900Sfrankho 6012900Sfrankho /* 6022900Sfrankho * The rules for which extension will be used are: 6032900Sfrankho * 1. No specific mount options given: 6042900Sfrankho * - use rrip if available 6052900Sfrankho * - use ISO9660:1999 if available 6062900Sfrankho * - use joliet if available. 6072900Sfrankho * 2. rrip/ISO9660:1999/joliet explicitly disabled via mount option: 6082900Sfrankho * - use next "lower" extension 6092900Sfrankho * 3. joliet/ISO9660:1999/rrip explicitly requested via mount option: 6102900Sfrankho * - disable rrip support even if available 6112900Sfrankho * - disable IOS9660:1999 support even if available 6122900Sfrankho * 6132900Sfrankho * We need to adjust these flags as we discover the extensions 6142900Sfrankho * present. See below. These are just the starting values. 6152900Sfrankho */ 6162900Sfrankho use_rrip = (mount_flags & HSFSMNT_NORRIP) == 0; 6172900Sfrankho use_vers2 = (mount_flags & HSFSMNT_NOVERS2) == 0; 6182900Sfrankho use_joliet = (mount_flags & HSFSMNT_NOJOLIET) == 0; 6190Sstevel@tonic-gate 6200Sstevel@tonic-gate /* 6210Sstevel@tonic-gate * Open the device 6220Sstevel@tonic-gate */ 6230Sstevel@tonic-gate devvp = makespecvp(dev, VBLK); 6240Sstevel@tonic-gate ASSERT(devvp != 0); 6250Sstevel@tonic-gate 6260Sstevel@tonic-gate /* 6270Sstevel@tonic-gate * Open the target device (file) for read only. 6280Sstevel@tonic-gate */ 629*5331Samw if (error = VOP_OPEN(&devvp, FREAD, cr, NULL)) { 6300Sstevel@tonic-gate VN_RELE(devvp); 6310Sstevel@tonic-gate return (error); 6320Sstevel@tonic-gate } 6330Sstevel@tonic-gate 6340Sstevel@tonic-gate /* 6350Sstevel@tonic-gate * Refuse to go any further if this 6360Sstevel@tonic-gate * device is being used for swapping 6370Sstevel@tonic-gate */ 6380Sstevel@tonic-gate if (IS_SWAPVP(common_specvp(devvp))) { 6390Sstevel@tonic-gate error = EBUSY; 6400Sstevel@tonic-gate goto cleanup; 6410Sstevel@tonic-gate } 6420Sstevel@tonic-gate 6430Sstevel@tonic-gate vap.va_mask = AT_SIZE; 644*5331Samw if ((error = VOP_GETATTR(devvp, &vap, ATTR_COMM, cr, NULL)) != 0) { 6450Sstevel@tonic-gate cmn_err(CE_NOTE, "Cannot get attributes of the CD-ROM driver"); 6460Sstevel@tonic-gate goto cleanup; 6470Sstevel@tonic-gate } 6480Sstevel@tonic-gate 6490Sstevel@tonic-gate /* 6500Sstevel@tonic-gate * Make sure we have a nonzero size partition. 6510Sstevel@tonic-gate * The current version of the SD driver will *not* fail the open 6520Sstevel@tonic-gate * of such a partition so we have to check for it here. 6530Sstevel@tonic-gate */ 6540Sstevel@tonic-gate if (vap.va_size == 0) { 6550Sstevel@tonic-gate error = ENXIO; 6560Sstevel@tonic-gate goto cleanup; 6570Sstevel@tonic-gate } 6580Sstevel@tonic-gate 6590Sstevel@tonic-gate /* 6600Sstevel@tonic-gate * Init a new hsfs structure. 6610Sstevel@tonic-gate */ 6620Sstevel@tonic-gate fsp = kmem_zalloc(sizeof (*fsp), KM_SLEEP); 6632900Sfrankho svp = kmem_zalloc(sizeof (*svp), KM_SLEEP); 6642900Sfrankho jvp = kmem_zalloc(sizeof (*jvp), KM_SLEEP); 6650Sstevel@tonic-gate 6660Sstevel@tonic-gate /* hardwire perms, uid, gid */ 6670Sstevel@tonic-gate fsp->hsfs_vol.vol_uid = hsfs_default_uid; 6680Sstevel@tonic-gate fsp->hsfs_vol.vol_gid = hsfs_default_gid; 6690Sstevel@tonic-gate fsp->hsfs_vol.vol_prot = hsfs_default_mode; 6702900Sfrankho svp->vol_uid = hsfs_default_uid; 6712900Sfrankho svp->vol_gid = hsfs_default_gid; 6722900Sfrankho svp->vol_prot = hsfs_default_mode; 6732900Sfrankho jvp->vol_uid = hsfs_default_uid; 6742900Sfrankho jvp->vol_gid = hsfs_default_gid; 6752900Sfrankho jvp->vol_prot = hsfs_default_mode; 6760Sstevel@tonic-gate 6770Sstevel@tonic-gate /* 6780Sstevel@tonic-gate * Look for a Standard File Structure Volume Descriptor, 6790Sstevel@tonic-gate * of which there must be at least one. 6800Sstevel@tonic-gate * If found, check for volume size consistency. 6812900Sfrankho * 6822900Sfrankho * If svp->lbn_size is != 0, we did find a ISO-9660:1999 SVD 6832900Sfrankho * If jvp->lbn_size is != 0, we did find a Joliet SVD. 6840Sstevel@tonic-gate */ 6852900Sfrankho fsp->hsfs_namemax = ISO_FILE_NAMELEN; 6862900Sfrankho fsp->hsfs_namelen = ISO_FILE_NAMELEN; 6872900Sfrankho error = hs_findisovol(fsp, devvp, &fsp->hsfs_vol, svp, jvp); 6881025Sfrankho if (error == EINVAL) /* no iso 9660 - try high sierra ... */ 6891025Sfrankho error = hs_findhsvol(fsp, devvp, &fsp->hsfs_vol); 6900Sstevel@tonic-gate 6910Sstevel@tonic-gate if (error) 6920Sstevel@tonic-gate goto cleanup; 6930Sstevel@tonic-gate 6942900Sfrankho DTRACE_PROBE4(findvol, 6952900Sfrankho struct hsfs *, fsp, 6962900Sfrankho struct hs_volume *, &fsp->hsfs_vol, 6972900Sfrankho struct hs_volume *, svp, 6982900Sfrankho struct hs_volume *, jvp); 6992900Sfrankho 7000Sstevel@tonic-gate /* 7010Sstevel@tonic-gate * Generate a file system ID from the CD-ROM, 7020Sstevel@tonic-gate * and check it for uniqueness. 7030Sstevel@tonic-gate * 7040Sstevel@tonic-gate * What we are aiming for is some chance of integrity 7050Sstevel@tonic-gate * across disk change. That is, if a client has an fhandle, 7060Sstevel@tonic-gate * it will be valid as long as the same disk is mounted. 7070Sstevel@tonic-gate */ 7080Sstevel@tonic-gate fsid = compute_cdrom_id(fsp, devvp); 7090Sstevel@tonic-gate 7100Sstevel@tonic-gate mutex_enter(&hs_mounttab_lock); 7110Sstevel@tonic-gate 7120Sstevel@tonic-gate if (fsid == 0 || fsid == -1) { 7130Sstevel@tonic-gate uniqtime(&tv); 7140Sstevel@tonic-gate fsid = tv.tv_sec; 7150Sstevel@tonic-gate } else /* make sure that the fsid is unique */ 7160Sstevel@tonic-gate for (tsp = hs_mounttab; tsp != NULL; tsp = tsp->hsfs_next) { 7170Sstevel@tonic-gate if (fsid == tsp->hsfs_vfs->vfs_fsid.val[0]) { 7180Sstevel@tonic-gate uniqtime(&tv); 7190Sstevel@tonic-gate fsid = tv.tv_sec; 7200Sstevel@tonic-gate break; 7210Sstevel@tonic-gate } 7220Sstevel@tonic-gate } 7230Sstevel@tonic-gate 7240Sstevel@tonic-gate fsp->hsfs_next = hs_mounttab; 7250Sstevel@tonic-gate hs_mounttab = fsp; 7260Sstevel@tonic-gate 7270Sstevel@tonic-gate fsp->hsfs_devvp = devvp; 7280Sstevel@tonic-gate fsp->hsfs_vfs = vfsp; 7292900Sfrankho fsp->hsfs_fsmnt = kmem_alloc(pathbufsz, KM_SLEEP); 7302900Sfrankho (void) strlcpy(fsp->hsfs_fsmnt, path, pathbufsz); 7310Sstevel@tonic-gate 7320Sstevel@tonic-gate mutex_init(&fsp->hsfs_free_lock, NULL, MUTEX_DEFAULT, NULL); 7330Sstevel@tonic-gate rw_init(&fsp->hsfs_hash_lock, NULL, RW_DEFAULT, NULL); 7340Sstevel@tonic-gate 7350Sstevel@tonic-gate vfsp->vfs_data = (caddr_t)fsp; 7360Sstevel@tonic-gate vfsp->vfs_dev = dev; 7370Sstevel@tonic-gate vfsp->vfs_fstype = hsfsfstype; 7380Sstevel@tonic-gate vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size; /* %% */ 7390Sstevel@tonic-gate vfsp->vfs_fsid.val[0] = fsid; 7400Sstevel@tonic-gate vfsp->vfs_fsid.val[1] = hsfsfstype; 7410Sstevel@tonic-gate 7422900Sfrankho if (!hs_getrootvp(vfsp, fsp, pathbufsz)) { 7432900Sfrankho DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp); 7442900Sfrankho error = EINVAL; 7452900Sfrankho goto cleanup; 7462900Sfrankho } 7472900Sfrankho DTRACE_PROBE1(rootvp, struct hsfs *, fsp); 7482900Sfrankho 7492900Sfrankho /* 7502900Sfrankho * Attempt to discover a RR extension. 7512900Sfrankho */ 7522900Sfrankho if (use_rrip) { 7532900Sfrankho hp = VTOH(fsp->hsfs_rootvp); 7542900Sfrankho hs_check_root_dirent(fsp->hsfs_rootvp, &(hp->hs_dirent)); 7552900Sfrankho } 7562900Sfrankho 7572900Sfrankho has_rrip = IS_RRIP_IMPLEMENTED(fsp); 7582900Sfrankho has_vers2 = (svp->lbn_size != 0); 7592900Sfrankho has_joliet = (jvp->lbn_size != 0); 7602900Sfrankho 7612900Sfrankho DTRACE_PROBE4(voltype__suggested, struct hsfs *, fsp, 7622900Sfrankho int, use_rrip, int, use_vers2, int, use_joliet); 7632900Sfrankho 7642900Sfrankho DTRACE_PROBE4(voltype__actual, struct hsfs *, fsp, 7652900Sfrankho int, has_rrip, int, has_vers2, int, has_joliet); 7662900Sfrankho 7672900Sfrankho DTRACE_PROBE4(findvol, 7682900Sfrankho struct hsfs *, fsp, 7692900Sfrankho struct hs_volume *, &fsp->hsfs_vol, 7702900Sfrankho struct hs_volume *, svp, 7712900Sfrankho struct hs_volume *, jvp); 7722900Sfrankho 7732900Sfrankho force_rrip_off = !use_rrip || 7742900Sfrankho (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet) || 7752900Sfrankho (vfs_optionisset(vfsp, HOPT_VERS2, NULL) && has_vers2); 7762900Sfrankho 7772900Sfrankho force_vers2_off = !use_vers2 || 7782900Sfrankho (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet); 7792900Sfrankho 7802900Sfrankho force_joliet_off = !use_joliet; 7812900Sfrankho 7822900Sfrankho DTRACE_PROBE4(voltype__force_off, struct hsfs *, fsp, 7832900Sfrankho int, force_rrip_off, int, force_vers2_off, int, force_joliet_off); 7842900Sfrankho 7852900Sfrankho /* 7862900Sfrankho * At the moment, we have references of all three possible 7872900Sfrankho * extensions (RR, ISO9660:1999/v2 and Joliet) if present. 7882900Sfrankho * 7892900Sfrankho * The "active" volume descriptor is RRIP (or ISO9660:1988). 7902900Sfrankho * We now switch to the user-requested one. 7912900Sfrankho */ 7922900Sfrankho redo_rootvp = 0; 7932900Sfrankho 7942900Sfrankho if (force_rrip_off || !has_rrip) { 7952900Sfrankho if (has_vers2 && !force_vers2_off) { 7962900Sfrankho VN_RELE(fsp->hsfs_rootvp); 7972900Sfrankho bcopy(svp, &fsp->hsfs_vol, sizeof (struct hs_volume)); 7982900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_ISO_V2; 7992900Sfrankho vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size; 8002900Sfrankho redo_rootvp = 1; 8012900Sfrankho has_joliet = 0; 8022900Sfrankho } else if (has_joliet && !force_joliet_off) { 8032900Sfrankho VN_RELE(fsp->hsfs_rootvp); 8042900Sfrankho bcopy(jvp, &fsp->hsfs_vol, sizeof (struct hs_volume)); 8052900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_JOLIET; 8062900Sfrankho vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size; 8072900Sfrankho redo_rootvp = 1; 8082900Sfrankho has_vers2 = 0; 8092900Sfrankho } 8102900Sfrankho } 8112900Sfrankho 8122900Sfrankho if (redo_rootvp) { 8132900Sfrankho /* 8142900Sfrankho * Make sure not to use Rock Ridge. 8152900Sfrankho */ 8162900Sfrankho UNSET_IMPL_BIT(fsp, RRIP_BIT); 8172900Sfrankho UNSET_SUSP_BIT(fsp); 8182900Sfrankho has_rrip = 0; 8192900Sfrankho 8202900Sfrankho if (!hs_getrootvp(vfsp, fsp, pathbufsz)) { 8212900Sfrankho DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp); 8222900Sfrankho error = EINVAL; 8232900Sfrankho goto cleanup; 8242900Sfrankho } 8252900Sfrankho DTRACE_PROBE1(rootvp, struct hsfs *, fsp); 8262900Sfrankho } 8272900Sfrankho if (IS_RRIP_IMPLEMENTED(fsp)) { 8282900Sfrankho has_vers2 = 0; 8292900Sfrankho has_joliet = 0; 8302900Sfrankho } 8312900Sfrankho if (force_vers2_off) 8322900Sfrankho has_vers2 = 0; 8332900Sfrankho if (force_joliet_off) 8342900Sfrankho has_joliet = 0; 8352900Sfrankho DTRACE_PROBE4(voltype__taken, struct hsfs *, fsp, 8362900Sfrankho int, has_rrip, int, has_vers2, int, has_joliet); 8372900Sfrankho 8382900Sfrankho /* 8392900Sfrankho * mark root node as VROOT 8402900Sfrankho */ 8412900Sfrankho fsp->hsfs_rootvp->v_flag |= VROOT; 8422900Sfrankho 8432900Sfrankho /* Here we take care of some special case stuff for mountroot */ 8442900Sfrankho if (isroot) { 8452900Sfrankho fsp->hsfs_rootvp->v_rdev = devvp->v_rdev; 8462900Sfrankho rootvp = fsp->hsfs_rootvp; 8472900Sfrankho } 8482900Sfrankho 8492900Sfrankho if (IS_RRIP_IMPLEMENTED(fsp)) { 8502900Sfrankho /* 8512900Sfrankho * if RRIP, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags 8522900Sfrankho */ 8532900Sfrankho mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT); 8542900Sfrankho 8552900Sfrankho fsp->hsfs_namemax = RRIP_FILE_NAMELEN; 8562900Sfrankho fsp->hsfs_namelen = RRIP_FILE_NAMELEN; 8572900Sfrankho 8582900Sfrankho ASSERT(vfs_optionisset(vfsp, HOPT_RR, NULL)); 8592900Sfrankho vfs_clearmntopt(vfsp, HOPT_VERS2); 8602900Sfrankho vfs_clearmntopt(vfsp, HOPT_JOLIET); 8612900Sfrankho 8622900Sfrankho } else switch (fsp->hsfs_vol_type) { 8632900Sfrankho 8642900Sfrankho case HS_VOL_TYPE_HS: 8652900Sfrankho case HS_VOL_TYPE_ISO: 8662900Sfrankho default: 8672900Sfrankho /* 8682900Sfrankho * if iso v1, don't allow trailing spaces in iso file names 8692900Sfrankho */ 8702900Sfrankho mount_flags |= HSFSMNT_NOTRAILSPACE; 8712900Sfrankho fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX; 8722900Sfrankho fsp->hsfs_namelen = ISO_FILE_NAMELEN; 8732900Sfrankho vfs_clearmntopt(vfsp, HOPT_RR); 8742900Sfrankho vfs_clearmntopt(vfsp, HOPT_VERS2); 8752900Sfrankho vfs_clearmntopt(vfsp, HOPT_JOLIET); 8762900Sfrankho break; 8772900Sfrankho 8782900Sfrankho case HS_VOL_TYPE_ISO_V2: 8792900Sfrankho /* 8802900Sfrankho * if iso v2, don't copy NOTRAILDOT to hsfs_flags 8812900Sfrankho */ 8822900Sfrankho mount_flags &= ~HSFSMNT_NOTRAILDOT; 8832900Sfrankho mount_flags |= HSFSMNT_NOMAPLCASE | HSFSMNT_NOVERSION; 8842900Sfrankho fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX; 8852900Sfrankho fsp->hsfs_namelen = ISO_NAMELEN_V2; 8862900Sfrankho vfs_setmntopt(vfsp, HOPT_VERS2, NULL, 0); 8872900Sfrankho vfs_clearmntopt(vfsp, HOPT_RR); 8882900Sfrankho vfs_clearmntopt(vfsp, HOPT_JOLIET); 8892900Sfrankho break; 8902900Sfrankho 8912900Sfrankho case HS_VOL_TYPE_JOLIET: 8922900Sfrankho /* 8932900Sfrankho * if Joliet, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags 8942900Sfrankho */ 8952900Sfrankho mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT); 8962900Sfrankho mount_flags |= HSFSMNT_NOMAPLCASE; 8972900Sfrankho if (mount_flags & HSFSMNT_JOLIETLONG) 8982900Sfrankho fsp->hsfs_namemax = JOLIET_NAMELEN_MAX*3; /* UTF-8 */ 8992900Sfrankho else 9002900Sfrankho fsp->hsfs_namemax = MAXNAMELEN-1; 9012900Sfrankho fsp->hsfs_namelen = JOLIET_NAMELEN*2; 9022900Sfrankho vfs_setmntopt(vfsp, HOPT_JOLIET, NULL, 0); 9032900Sfrankho vfs_clearmntopt(vfsp, HOPT_RR); 9042900Sfrankho vfs_clearmntopt(vfsp, HOPT_VERS2); 9052900Sfrankho break; 9062900Sfrankho } 9072900Sfrankho 9084866Sfrankho /* 9094866Sfrankho * Add the HSFSMNT_INODE pseudo mount flag to the current mount flags. 9104866Sfrankho */ 9114866Sfrankho fsp->hsfs_flags = mount_flags | (fsp->hsfs_flags & HSFSMNT_INODE); 9122900Sfrankho 9135312Smg147109 /* 9145312Smg147109 * Setup I/O Scheduling structures 9155312Smg147109 */ 9165312Smg147109 if (do_schedio) { 9175312Smg147109 fsp->hqueue = kmem_alloc(sizeof (struct hsfs_queue), KM_SLEEP); 9185312Smg147109 hsched_init(fsp, fsid, &modlinkage); 9195312Smg147109 } 9205312Smg147109 9215312Smg147109 /* 9225312Smg147109 * Setup kstats 9235312Smg147109 */ 9245312Smg147109 hsfs_init_kstats(fsp, fsid); 9255312Smg147109 9262900Sfrankho DTRACE_PROBE1(mount__done, struct hsfs *, fsp); 9272900Sfrankho 9282900Sfrankho /* 9292900Sfrankho * set the magic word 9302900Sfrankho */ 9312900Sfrankho fsp->hsfs_magic = HSFS_MAGIC; 9322900Sfrankho mutex_exit(&hs_mounttab_lock); 9332900Sfrankho 9344866Sfrankho kmem_free(svp, sizeof (*svp)); 9354866Sfrankho kmem_free(jvp, sizeof (*jvp)); 9364866Sfrankho 9372900Sfrankho return (0); 9382900Sfrankho 9392900Sfrankho cleanup: 940*5331Samw (void) VOP_CLOSE(devvp, FREAD, 1, (offset_t)0, cr, NULL); 9412900Sfrankho VN_RELE(devvp); 9422900Sfrankho if (fsp) 9432900Sfrankho kmem_free(fsp, sizeof (*fsp)); 9442900Sfrankho if (svp) 9452900Sfrankho kmem_free(svp, sizeof (*svp)); 9462900Sfrankho if (jvp) 9472900Sfrankho kmem_free(jvp, sizeof (*jvp)); 9482900Sfrankho return (error); 9492900Sfrankho } 9502900Sfrankho 9512900Sfrankho /* 9522900Sfrankho * Get the rootvp associated with fsp->hsfs_vol 9532900Sfrankho */ 9542900Sfrankho static int 9552900Sfrankho hs_getrootvp( 9562900Sfrankho struct vfs *vfsp, 9572900Sfrankho struct hsfs *fsp, 9582900Sfrankho size_t pathsize) 9592900Sfrankho { 9602900Sfrankho struct hsnode *hp; 9612900Sfrankho 9622900Sfrankho ASSERT(pathsize == strlen(fsp->hsfs_fsmnt) + 1); 9632900Sfrankho 9640Sstevel@tonic-gate /* 9650Sstevel@tonic-gate * If the root directory does not appear to be 9660Sstevel@tonic-gate * valid, use what it points to as "." instead. 9670Sstevel@tonic-gate * Some Defense Mapping Agency disks are non-conformant 9680Sstevel@tonic-gate * in this way. 9690Sstevel@tonic-gate */ 9700Sstevel@tonic-gate if (!hsfs_valid_dir(&fsp->hsfs_vol.root_dir)) { 9710Sstevel@tonic-gate hs_log_bogus_disk_warning(fsp, HSFS_ERR_BAD_ROOT_DIR, 0); 9720Sstevel@tonic-gate if (hs_remakenode(fsp->hsfs_vol.root_dir.ext_lbn, 9734866Sfrankho (uint_t)0, vfsp, &fsp->hsfs_rootvp)) { 9741025Sfrankho hs_mounttab = hs_mounttab->hsfs_next; 9751025Sfrankho mutex_destroy(&fsp->hsfs_free_lock); 9761025Sfrankho rw_destroy(&fsp->hsfs_hash_lock); 9772900Sfrankho kmem_free(fsp->hsfs_fsmnt, pathsize); 978494Sfrankho mutex_exit(&hs_mounttab_lock); 9792900Sfrankho return (0); 9800Sstevel@tonic-gate } 9810Sstevel@tonic-gate } else { 9820Sstevel@tonic-gate fsp->hsfs_rootvp = hs_makenode(&fsp->hsfs_vol.root_dir, 9834866Sfrankho fsp->hsfs_vol.root_dir.ext_lbn, 0, vfsp); 9840Sstevel@tonic-gate } 9850Sstevel@tonic-gate 9860Sstevel@tonic-gate /* XXX - ignore the path table for now */ 9870Sstevel@tonic-gate fsp->hsfs_ptbl = NULL; 9880Sstevel@tonic-gate hp = VTOH(fsp->hsfs_rootvp); 9890Sstevel@tonic-gate hp->hs_ptbl_idx = NULL; 9900Sstevel@tonic-gate 9912900Sfrankho return (1); 9920Sstevel@tonic-gate } 9930Sstevel@tonic-gate 9940Sstevel@tonic-gate /* 9950Sstevel@tonic-gate * hs_findhsvol() 9960Sstevel@tonic-gate * 9970Sstevel@tonic-gate * Locate the Standard File Structure Volume Descriptor and 9980Sstevel@tonic-gate * parse it into an hs_volume structure. 9990Sstevel@tonic-gate * 10000Sstevel@tonic-gate * XXX - May someday want to look for Coded Character Set FSVD, too. 10010Sstevel@tonic-gate */ 10020Sstevel@tonic-gate static int 10030Sstevel@tonic-gate hs_findhsvol(struct hsfs *fsp, struct vnode *vp, struct hs_volume *hvp) 10040Sstevel@tonic-gate { 10050Sstevel@tonic-gate struct buf *secbp; 10060Sstevel@tonic-gate int i; 10074866Sfrankho int n; 10080Sstevel@tonic-gate uchar_t *volp; 10090Sstevel@tonic-gate int error; 10100Sstevel@tonic-gate uint_t secno; 10110Sstevel@tonic-gate 10120Sstevel@tonic-gate secno = hs_findvoldesc(vp->v_rdev, HS_VOLDESC_SEC); 10130Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE); 10140Sstevel@tonic-gate error = geterror(secbp); 10150Sstevel@tonic-gate 10160Sstevel@tonic-gate if (error != 0) { 10170Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)", error); 10180Sstevel@tonic-gate brelse(secbp); 10190Sstevel@tonic-gate return (error); 10200Sstevel@tonic-gate } 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 10230Sstevel@tonic-gate 10244866Sfrankho /* 10254866Sfrankho * To avoid that we read the whole medium in case that someone prepares 10264866Sfrankho * a malicious "fs image", we read at most 32 blocks. 10274866Sfrankho */ 10284866Sfrankho for (n = 0; n < 32 && 10294866Sfrankho HSV_DESC_TYPE(volp) != VD_EOV; n++) { 10300Sstevel@tonic-gate for (i = 0; i < HSV_ID_STRLEN; i++) 10310Sstevel@tonic-gate if (HSV_STD_ID(volp)[i] != HSV_ID_STRING[i]) 10320Sstevel@tonic-gate goto cantfind; 10330Sstevel@tonic-gate if (HSV_STD_VER(volp) != HSV_ID_VER) 10340Sstevel@tonic-gate goto cantfind; 10350Sstevel@tonic-gate switch (HSV_DESC_TYPE(volp)) { 10360Sstevel@tonic-gate case VD_SFS: 10370Sstevel@tonic-gate /* Standard File Structure */ 10380Sstevel@tonic-gate fsp->hsfs_vol_type = HS_VOL_TYPE_HS; 10390Sstevel@tonic-gate error = hs_parsehsvol(fsp, volp, hvp); 10400Sstevel@tonic-gate brelse(secbp); 10410Sstevel@tonic-gate return (error); 10420Sstevel@tonic-gate 10430Sstevel@tonic-gate case VD_CCFS: 10440Sstevel@tonic-gate /* Coded Character File Structure */ 10450Sstevel@tonic-gate case VD_BOOT: 10460Sstevel@tonic-gate case VD_UNSPEC: 10470Sstevel@tonic-gate case VD_EOV: 10480Sstevel@tonic-gate break; 10490Sstevel@tonic-gate } 10500Sstevel@tonic-gate brelse(secbp); 10510Sstevel@tonic-gate ++secno; 10520Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE); 10530Sstevel@tonic-gate 10540Sstevel@tonic-gate error = geterror(secbp); 10550Sstevel@tonic-gate 10560Sstevel@tonic-gate if (error != 0) { 10570Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)", 10584866Sfrankho error); 10590Sstevel@tonic-gate brelse(secbp); 10600Sstevel@tonic-gate return (error); 10610Sstevel@tonic-gate } 10620Sstevel@tonic-gate 10630Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 10640Sstevel@tonic-gate } 10650Sstevel@tonic-gate cantfind: 10660Sstevel@tonic-gate brelse(secbp); 10670Sstevel@tonic-gate return (EINVAL); 10680Sstevel@tonic-gate } 10690Sstevel@tonic-gate 10700Sstevel@tonic-gate /* 10710Sstevel@tonic-gate * hs_parsehsvol 10720Sstevel@tonic-gate * 10730Sstevel@tonic-gate * Parse the Standard File Structure Volume Descriptor into 10740Sstevel@tonic-gate * an hs_volume structure. We can't just bcopy it into the 10750Sstevel@tonic-gate * structure because of byte-ordering problems. 10760Sstevel@tonic-gate * 10770Sstevel@tonic-gate */ 10780Sstevel@tonic-gate static int 10790Sstevel@tonic-gate hs_parsehsvol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp) 10800Sstevel@tonic-gate { 10810Sstevel@tonic-gate hvp->vol_size = HSV_VOL_SIZE(volp); 10820Sstevel@tonic-gate hvp->lbn_size = HSV_BLK_SIZE(volp); 10830Sstevel@tonic-gate if (hvp->lbn_size == 0) { 10840Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_parsehsvol: logical block size in the " 10854866Sfrankho "SFSVD is zero"); 10860Sstevel@tonic-gate return (EINVAL); 10870Sstevel@tonic-gate } 10880Sstevel@tonic-gate hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1; 10894866Sfrankho hvp->lbn_secshift = 10904866Sfrankho ffs((long)howmany(HS_SECTOR_SIZE, (int)hvp->lbn_size)) - 1; 10910Sstevel@tonic-gate hvp->lbn_maxoffset = hvp->lbn_size - 1; 10920Sstevel@tonic-gate hs_parse_longdate(HSV_cre_date(volp), &hvp->cre_date); 10930Sstevel@tonic-gate hs_parse_longdate(HSV_mod_date(volp), &hvp->mod_date); 10940Sstevel@tonic-gate hvp->file_struct_ver = HSV_FILE_STRUCT_VER(volp); 10950Sstevel@tonic-gate hvp->ptbl_len = HSV_PTBL_SIZE(volp); 10960Sstevel@tonic-gate hvp->vol_set_size = (ushort_t)HSV_SET_SIZE(volp); 10970Sstevel@tonic-gate hvp->vol_set_seq = (ushort_t)HSV_SET_SEQ(volp); 10980Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 10990Sstevel@tonic-gate hvp->ptbl_lbn = HSV_PTBL_MAN_LS(volp); 11000Sstevel@tonic-gate #else 11010Sstevel@tonic-gate hvp->ptbl_lbn = HSV_PTBL_MAN_MS(volp); 11020Sstevel@tonic-gate #endif 11032900Sfrankho hs_copylabel(hvp, HSV_VOL_ID(volp), 0); 11040Sstevel@tonic-gate 11050Sstevel@tonic-gate /* 11060Sstevel@tonic-gate * Make sure that lbn_size is a power of two and otherwise valid. 11070Sstevel@tonic-gate */ 11080Sstevel@tonic-gate if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) { 11090Sstevel@tonic-gate cmn_err(CE_NOTE, 11104866Sfrankho "hsfs: %d-byte logical block size not supported", 11114866Sfrankho hvp->lbn_size); 11120Sstevel@tonic-gate return (EINVAL); 11130Sstevel@tonic-gate } 11140Sstevel@tonic-gate return (hs_parsedir(fsp, HSV_ROOT_DIR(volp), &hvp->root_dir, 11154866Sfrankho (char *)NULL, (int *)NULL, HDE_ROOT_DIR_REC_SIZE)); 11160Sstevel@tonic-gate } 11170Sstevel@tonic-gate 11180Sstevel@tonic-gate /* 11190Sstevel@tonic-gate * hs_findisovol() 11200Sstevel@tonic-gate * 11210Sstevel@tonic-gate * Locate the Primary Volume Descriptor 11220Sstevel@tonic-gate * parse it into an hs_volume structure. 11230Sstevel@tonic-gate * 11242900Sfrankho * XXX - Partition not yet done 11252900Sfrankho * 11262900Sfrankho * Except for fsp->hsfs_vol_type, no fsp member may be modified. 11272900Sfrankho * fsp->hsfs_vol is modified indirectly via the *hvp argument. 11280Sstevel@tonic-gate */ 11290Sstevel@tonic-gate static int 11300Sstevel@tonic-gate hs_findisovol(struct hsfs *fsp, struct vnode *vp, 11312900Sfrankho struct hs_volume *hvp, 11322900Sfrankho struct hs_volume *svp, 11332900Sfrankho struct hs_volume *jvp) 11340Sstevel@tonic-gate { 11350Sstevel@tonic-gate struct buf *secbp; 11360Sstevel@tonic-gate int i; 11374866Sfrankho int n; 11380Sstevel@tonic-gate uchar_t *volp; 11390Sstevel@tonic-gate int error; 11400Sstevel@tonic-gate uint_t secno; 11410Sstevel@tonic-gate int foundpvd = 0; 11422900Sfrankho int foundsvd = 0; 11432900Sfrankho int foundjvd = 0; 11444866Sfrankho int pvd_sum = 0; 11450Sstevel@tonic-gate 11460Sstevel@tonic-gate secno = hs_findvoldesc(vp->v_rdev, ISO_VOLDESC_SEC); 11470Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, ISO_SECTOR_SIZE); 11480Sstevel@tonic-gate error = geterror(secbp); 11490Sstevel@tonic-gate 11500Sstevel@tonic-gate if (error != 0) { 11510Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)", error); 11520Sstevel@tonic-gate brelse(secbp); 11530Sstevel@tonic-gate return (error); 11540Sstevel@tonic-gate } 11550Sstevel@tonic-gate 11560Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 11570Sstevel@tonic-gate 11584866Sfrankho /* 11594866Sfrankho * To avoid that we read the whole medium in case that someone prepares 11604866Sfrankho * a malicious "fs image", we read at most 32 blocks. 11614866Sfrankho */ 11624866Sfrankho for (n = 0; n < 32 && 11634866Sfrankho (enum iso_voldesc_type) ISO_DESC_TYPE(volp) != ISO_VD_EOV; n++) { 11640Sstevel@tonic-gate for (i = 0; i < ISO_ID_STRLEN; i++) 11650Sstevel@tonic-gate if (ISO_STD_ID(volp)[i] != ISO_ID_STRING[i]) 11660Sstevel@tonic-gate goto cantfind; 11670Sstevel@tonic-gate switch (ISO_DESC_TYPE(volp)) { 11680Sstevel@tonic-gate case ISO_VD_PVD: 11690Sstevel@tonic-gate /* Standard File Structure */ 11702900Sfrankho if (ISO_STD_VER(volp) != ISO_ID_VER) 11712900Sfrankho goto cantfind; 11720Sstevel@tonic-gate if (foundpvd != 1) { 11730Sstevel@tonic-gate fsp->hsfs_vol_type = HS_VOL_TYPE_ISO; 11740Sstevel@tonic-gate if (error = hs_parseisovol(fsp, volp, hvp)) { 11750Sstevel@tonic-gate brelse(secbp); 11760Sstevel@tonic-gate return (error); 11770Sstevel@tonic-gate } 11780Sstevel@tonic-gate foundpvd = 1; 11794866Sfrankho for (i = 0; i < ISO_SECTOR_SIZE; i++) 11804866Sfrankho pvd_sum += volp[i]; 11810Sstevel@tonic-gate } 11820Sstevel@tonic-gate break; 11830Sstevel@tonic-gate case ISO_VD_SVD: 11840Sstevel@tonic-gate /* Supplementary Volume Descriptor */ 11852900Sfrankho if (ISO_STD_VER(volp) == ISO_ID_VER2 && 11862900Sfrankho foundsvd != 1) { 11872900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_ISO; 11882900Sfrankho if (error = hs_parseisovol(fsp, volp, svp)) { 11892900Sfrankho brelse(secbp); 11902900Sfrankho return (error); 11912900Sfrankho } 11922900Sfrankho foundsvd = 1; 11932900Sfrankho } 11942900Sfrankho if (hs_joliet_level(volp) >= 1 && foundjvd != 1) { 11952900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_ISO; 11962900Sfrankho if (error = hs_parseisovol(fsp, volp, jvp)) { 11972900Sfrankho brelse(secbp); 11982900Sfrankho return (error); 11992900Sfrankho } 12002900Sfrankho foundjvd = 1; 12012900Sfrankho } 12020Sstevel@tonic-gate break; 12030Sstevel@tonic-gate case ISO_VD_BOOT: 12040Sstevel@tonic-gate break; 12050Sstevel@tonic-gate case ISO_VD_VPD: 12060Sstevel@tonic-gate /* currently cannot handle partition */ 12070Sstevel@tonic-gate break; 12080Sstevel@tonic-gate case VD_EOV: 12090Sstevel@tonic-gate break; 12100Sstevel@tonic-gate } 12110Sstevel@tonic-gate brelse(secbp); 12120Sstevel@tonic-gate ++secno; 12130Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE); 12140Sstevel@tonic-gate error = geterror(secbp); 12150Sstevel@tonic-gate 12160Sstevel@tonic-gate if (error != 0) { 12170Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)", 12184866Sfrankho error); 12190Sstevel@tonic-gate brelse(secbp); 12200Sstevel@tonic-gate return (error); 12210Sstevel@tonic-gate } 12220Sstevel@tonic-gate 12230Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 12240Sstevel@tonic-gate } 12254866Sfrankho for (n = 0; n < 16; n++) { 12264866Sfrankho brelse(secbp); 12274866Sfrankho ++secno; 12284866Sfrankho secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE); 12294866Sfrankho error = geterror(secbp); 12304866Sfrankho 12314866Sfrankho if (error != 0) { 12324866Sfrankho cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)", 12334866Sfrankho error); 12344866Sfrankho brelse(secbp); 12354866Sfrankho return (error); 12364866Sfrankho } 12374866Sfrankho 12384866Sfrankho /* 12394866Sfrankho * Check for the signature from mkisofs that grants that 12404866Sfrankho * the current filesystem allows to use the extent lbn as 12414866Sfrankho * inode number even in pure ISO9660 mode. 12424866Sfrankho */ 12434866Sfrankho volp = (uchar_t *)secbp->b_un.b_addr; 12444866Sfrankho if (strncmp((char *)volp, "MKI ", 4) == 0) { 12454866Sfrankho int sum; 12464866Sfrankho 12474866Sfrankho sum = volp[2045]; 12484866Sfrankho sum *= 256; 12494866Sfrankho sum += volp[2046]; 12504866Sfrankho sum *= 256; 12514866Sfrankho sum += volp[2047]; 12524866Sfrankho if (sum == pvd_sum) 12534866Sfrankho fsp->hsfs_flags |= HSFSMNT_INODE; 12544866Sfrankho break; 12554866Sfrankho } 12564866Sfrankho } 12570Sstevel@tonic-gate if (foundpvd) { 12580Sstevel@tonic-gate brelse(secbp); 12590Sstevel@tonic-gate return (0); 12600Sstevel@tonic-gate } 12610Sstevel@tonic-gate cantfind: 12620Sstevel@tonic-gate brelse(secbp); 12630Sstevel@tonic-gate return (EINVAL); 12640Sstevel@tonic-gate } 12652900Sfrankho 12662900Sfrankho /* 12672900Sfrankho * Return 0 if no Joliet is found 12682900Sfrankho * else return Joliet Level 1..3 12692900Sfrankho */ 12702900Sfrankho static int 12712900Sfrankho hs_joliet_level(uchar_t *volp) 12722900Sfrankho { 12732900Sfrankho if (ISO_std_ver(volp)[0] == ISO_ID_VER && 12742900Sfrankho ISO_svd_esc(volp)[0] == '%' && 12752900Sfrankho ISO_svd_esc(volp)[1] == '/') { 12762900Sfrankho 12772900Sfrankho switch (ISO_svd_esc(volp)[2]) { 12782900Sfrankho 12792900Sfrankho case '@': 12802900Sfrankho return (1); 12812900Sfrankho case 'C': 12822900Sfrankho return (2); 12832900Sfrankho case 'E': 12842900Sfrankho return (3); 12852900Sfrankho } 12862900Sfrankho } 12872900Sfrankho return (0); 12882900Sfrankho } 12892900Sfrankho 12900Sstevel@tonic-gate /* 12910Sstevel@tonic-gate * hs_parseisovol 12920Sstevel@tonic-gate * 12930Sstevel@tonic-gate * Parse the Primary Volume Descriptor into an hs_volume structure. 12940Sstevel@tonic-gate * 12950Sstevel@tonic-gate */ 12960Sstevel@tonic-gate static int 12970Sstevel@tonic-gate hs_parseisovol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp) 12980Sstevel@tonic-gate { 12990Sstevel@tonic-gate hvp->vol_size = ISO_VOL_SIZE(volp); 13000Sstevel@tonic-gate hvp->lbn_size = ISO_BLK_SIZE(volp); 13010Sstevel@tonic-gate if (hvp->lbn_size == 0) { 13020Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_parseisovol: logical block size in the " 13034866Sfrankho "PVD is zero"); 13040Sstevel@tonic-gate return (EINVAL); 13050Sstevel@tonic-gate } 13060Sstevel@tonic-gate hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1; 13074866Sfrankho hvp->lbn_secshift = 13084866Sfrankho ffs((long)howmany(ISO_SECTOR_SIZE, (int)hvp->lbn_size)) - 1; 13090Sstevel@tonic-gate hvp->lbn_maxoffset = hvp->lbn_size - 1; 13100Sstevel@tonic-gate hs_parse_longdate(ISO_cre_date(volp), &hvp->cre_date); 13110Sstevel@tonic-gate hs_parse_longdate(ISO_mod_date(volp), &hvp->mod_date); 13120Sstevel@tonic-gate hvp->file_struct_ver = ISO_FILE_STRUCT_VER(volp); 13130Sstevel@tonic-gate hvp->ptbl_len = ISO_PTBL_SIZE(volp); 13140Sstevel@tonic-gate hvp->vol_set_size = (ushort_t)ISO_SET_SIZE(volp); 13150Sstevel@tonic-gate hvp->vol_set_seq = (ushort_t)ISO_SET_SEQ(volp); 13160Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 13170Sstevel@tonic-gate hvp->ptbl_lbn = ISO_PTBL_MAN_LS(volp); 13180Sstevel@tonic-gate #else 13190Sstevel@tonic-gate hvp->ptbl_lbn = ISO_PTBL_MAN_MS(volp); 13200Sstevel@tonic-gate #endif 13212900Sfrankho hs_copylabel(hvp, ISO_VOL_ID(volp), hs_joliet_level(volp) >= 1); 13220Sstevel@tonic-gate 13230Sstevel@tonic-gate /* 13240Sstevel@tonic-gate * Make sure that lbn_size is a power of two and otherwise valid. 13250Sstevel@tonic-gate */ 13260Sstevel@tonic-gate if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) { 13270Sstevel@tonic-gate cmn_err(CE_NOTE, 13284866Sfrankho "hsfs: %d-byte logical block size not supported", 13294866Sfrankho hvp->lbn_size); 13300Sstevel@tonic-gate return (EINVAL); 13310Sstevel@tonic-gate } 13320Sstevel@tonic-gate return (hs_parsedir(fsp, ISO_ROOT_DIR(volp), &hvp->root_dir, 13334866Sfrankho (char *)NULL, (int *)NULL, IDE_ROOT_DIR_REC_SIZE)); 13340Sstevel@tonic-gate } 13350Sstevel@tonic-gate 13360Sstevel@tonic-gate /* 13370Sstevel@tonic-gate * Common code for mount and umount. 13380Sstevel@tonic-gate * Check that the user's argument is a reasonable 13390Sstevel@tonic-gate * thing on which to mount, and return the device number if so. 13400Sstevel@tonic-gate */ 13410Sstevel@tonic-gate static int 13420Sstevel@tonic-gate hs_getmdev(struct vfs *vfsp, char *fspec, int flags, dev_t *pdev, mode_t *mode, 13430Sstevel@tonic-gate cred_t *cr) 13440Sstevel@tonic-gate { 13450Sstevel@tonic-gate int error; 13460Sstevel@tonic-gate struct vnode *vp; 13470Sstevel@tonic-gate struct vattr vap; 13480Sstevel@tonic-gate dev_t dev; 13490Sstevel@tonic-gate 13500Sstevel@tonic-gate /* 13510Sstevel@tonic-gate * Get the device to be mounted 13520Sstevel@tonic-gate */ 13530Sstevel@tonic-gate error = lookupname(fspec, (flags & MS_SYSSPACE) ? 13540Sstevel@tonic-gate UIO_SYSSPACE : UIO_USERSPACE, FOLLOW, NULLVPP, &vp); 13550Sstevel@tonic-gate if (error) { 13560Sstevel@tonic-gate if (error == ENOENT) { 13570Sstevel@tonic-gate return (ENODEV); /* needs translation */ 13580Sstevel@tonic-gate } 13590Sstevel@tonic-gate return (error); 13600Sstevel@tonic-gate } 13610Sstevel@tonic-gate if (vp->v_type != VBLK) { 13620Sstevel@tonic-gate VN_RELE(vp); 13630Sstevel@tonic-gate return (ENOTBLK); 13640Sstevel@tonic-gate } 13650Sstevel@tonic-gate /* 13660Sstevel@tonic-gate * Can we read from the device? 13670Sstevel@tonic-gate */ 1368*5331Samw if ((error = VOP_ACCESS(vp, VREAD, 0, cr, NULL)) != 0 || 13690Sstevel@tonic-gate (error = secpolicy_spec_open(cr, vp, FREAD)) != 0) { 13700Sstevel@tonic-gate VN_RELE(vp); 13710Sstevel@tonic-gate return (error); 13720Sstevel@tonic-gate } 13730Sstevel@tonic-gate 13740Sstevel@tonic-gate vap.va_mask = AT_MODE; /* get protection mode */ 1375*5331Samw (void) VOP_GETATTR(vp, &vap, 0, CRED(), NULL); 13760Sstevel@tonic-gate *mode = vap.va_mode; 13770Sstevel@tonic-gate 13780Sstevel@tonic-gate dev = *pdev = vp->v_rdev; 13790Sstevel@tonic-gate VN_RELE(vp); 13800Sstevel@tonic-gate 13810Sstevel@tonic-gate /* 13820Sstevel@tonic-gate * Ensure that this device isn't already mounted, 13830Sstevel@tonic-gate * unless this is a REMOUNT request or we are told to suppress 13840Sstevel@tonic-gate * mount checks. 13850Sstevel@tonic-gate */ 13860Sstevel@tonic-gate if ((flags & MS_NOCHECK) == 0) { 13870Sstevel@tonic-gate if (vfs_devmounting(dev, vfsp)) 13880Sstevel@tonic-gate return (EBUSY); 13890Sstevel@tonic-gate if (vfs_devismounted(dev) && !(flags & MS_REMOUNT)) 13900Sstevel@tonic-gate return (EBUSY); 13910Sstevel@tonic-gate } 13920Sstevel@tonic-gate 13930Sstevel@tonic-gate if (getmajor(*pdev) >= devcnt) 13940Sstevel@tonic-gate return (ENXIO); 13950Sstevel@tonic-gate return (0); 13960Sstevel@tonic-gate } 13970Sstevel@tonic-gate 13980Sstevel@tonic-gate static void 13992900Sfrankho hs_copylabel(struct hs_volume *hvp, unsigned char *label, int isjoliet) 14000Sstevel@tonic-gate { 14012900Sfrankho char lbuf[64]; /* hs_joliet_cp() creates 48 bytes at most */ 14022900Sfrankho 14032900Sfrankho if (isjoliet) { 14042900Sfrankho /* 14052900Sfrankho * hs_joliet_cp() will output 16..48 bytes. 14062900Sfrankho * We need to clear 'lbuf' to avoid junk chars past byte 15. 14072900Sfrankho */ 14082900Sfrankho bzero(lbuf, sizeof (lbuf)); 14092904Sfrankho (void) hs_joliet_cp((char *)label, lbuf, 32); 14102900Sfrankho label = (unsigned char *)lbuf; 14112900Sfrankho } 14120Sstevel@tonic-gate /* cdrom volid is at most 32 bytes */ 14130Sstevel@tonic-gate bcopy(label, hvp->vol_id, 32); 14140Sstevel@tonic-gate hvp->vol_id[31] = NULL; 14150Sstevel@tonic-gate } 14160Sstevel@tonic-gate 14170Sstevel@tonic-gate /* 14180Sstevel@tonic-gate * Mount root file system. 14190Sstevel@tonic-gate * "why" is ROOT_INIT on initial call, ROOT_REMOUNT if called to 14200Sstevel@tonic-gate * remount the root file system, and ROOT_UNMOUNT if called to 14210Sstevel@tonic-gate * unmount the root (e.g., as part of a system shutdown). 14220Sstevel@tonic-gate * 14230Sstevel@tonic-gate * XXX - this may be partially machine-dependent; it, along with the VFS_SWAPVP 14240Sstevel@tonic-gate * operation, goes along with auto-configuration. A mechanism should be 14250Sstevel@tonic-gate * provided by which machine-INdependent code in the kernel can say "get me the 14260Sstevel@tonic-gate * right root file system" and "get me the right initial swap area", and have 14270Sstevel@tonic-gate * that done in what may well be a machine-dependent fashion. 14280Sstevel@tonic-gate * Unfortunately, it is also file-system-type dependent (NFS gets it via 14290Sstevel@tonic-gate * bootparams calls, UFS gets it from various and sundry machine-dependent 14300Sstevel@tonic-gate * mechanisms, as SPECFS does for swap). 14310Sstevel@tonic-gate */ 14320Sstevel@tonic-gate static int 14330Sstevel@tonic-gate hsfs_mountroot(struct vfs *vfsp, enum whymountroot why) 14340Sstevel@tonic-gate { 14350Sstevel@tonic-gate int error; 14360Sstevel@tonic-gate struct hsfs *fsp; 14370Sstevel@tonic-gate struct hs_volume *fvolp; 14380Sstevel@tonic-gate static int hsfsrootdone = 0; 14390Sstevel@tonic-gate dev_t rootdev; 14400Sstevel@tonic-gate mode_t mode = 0; 14410Sstevel@tonic-gate 14420Sstevel@tonic-gate if (why == ROOT_INIT) { 14430Sstevel@tonic-gate if (hsfsrootdone++) 14440Sstevel@tonic-gate return (EBUSY); 14450Sstevel@tonic-gate rootdev = getrootdev(); 14460Sstevel@tonic-gate if (rootdev == (dev_t)NODEV) 14470Sstevel@tonic-gate return (ENODEV); 14480Sstevel@tonic-gate vfsp->vfs_dev = rootdev; 14490Sstevel@tonic-gate vfsp->vfs_flag |= VFS_RDONLY; 14500Sstevel@tonic-gate } else if (why == ROOT_REMOUNT) { 14510Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: ROOT_REMOUNT"); 14520Sstevel@tonic-gate return (0); 14530Sstevel@tonic-gate } else if (why == ROOT_UNMOUNT) { 14540Sstevel@tonic-gate return (0); 14550Sstevel@tonic-gate } 14560Sstevel@tonic-gate error = vfs_lock(vfsp); 14570Sstevel@tonic-gate if (error) { 14580Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: couldn't get vfs_lock"); 14590Sstevel@tonic-gate return (error); 14600Sstevel@tonic-gate } 14610Sstevel@tonic-gate 14620Sstevel@tonic-gate error = hs_mountfs(vfsp, rootdev, "/", mode, 1, CRED(), 1); 14630Sstevel@tonic-gate /* 14640Sstevel@tonic-gate * XXX - assumes root device is not indirect, because we don't set 14650Sstevel@tonic-gate * rootvp. Is rootvp used for anything? If so, make another arg 14660Sstevel@tonic-gate * to mountfs. 14670Sstevel@tonic-gate */ 14680Sstevel@tonic-gate if (error) { 14690Sstevel@tonic-gate vfs_unlock(vfsp); 14700Sstevel@tonic-gate if (rootvp) { 14710Sstevel@tonic-gate VN_RELE(rootvp); 14720Sstevel@tonic-gate rootvp = (struct vnode *)0; 14730Sstevel@tonic-gate } 14740Sstevel@tonic-gate return (error); 14750Sstevel@tonic-gate } 14760Sstevel@tonic-gate if (why == ROOT_INIT) 14770Sstevel@tonic-gate vfs_add((struct vnode *)0, vfsp, 14780Sstevel@tonic-gate (vfsp->vfs_flag & VFS_RDONLY) ? MS_RDONLY : 0); 14790Sstevel@tonic-gate vfs_unlock(vfsp); 14800Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp); 14810Sstevel@tonic-gate fvolp = &fsp->hsfs_vol; 14820Sstevel@tonic-gate #ifdef HSFS_CLKSET 14830Sstevel@tonic-gate if (fvolp->cre_date.tv_sec == 0) { 14844866Sfrankho cmn_err(CE_NOTE, "hsfs_mountroot: cre_date.tv_sec == 0"); 14854866Sfrankho if (fvolp->mod_date.tv_sec == 0) { 14864866Sfrankho cmn_err(CE_NOTE, 14874866Sfrankho "hsfs_mountroot: mod_date.tv_sec == 0"); 14884866Sfrankho cmn_err(CE_NOTE, "hsfs_mountroot: clkset(-1L)"); 14894866Sfrankho clkset(-1L); 14904866Sfrankho } else { 14914866Sfrankho clkset(fvolp->mod_date.tv_sec); 14924866Sfrankho } 14934866Sfrankho } else { 14940Sstevel@tonic-gate clkset(fvolp->mod_date.tv_sec); 14954866Sfrankho } 14960Sstevel@tonic-gate #else /* HSFS_CLKSET */ 14970Sstevel@tonic-gate clkset(-1L); 14980Sstevel@tonic-gate #endif /* HSFS_CLKSET */ 14990Sstevel@tonic-gate return (0); 15000Sstevel@tonic-gate } 15010Sstevel@tonic-gate 15020Sstevel@tonic-gate /* 15030Sstevel@tonic-gate * hs_findvoldesc() 15040Sstevel@tonic-gate * 15050Sstevel@tonic-gate * Return the sector where the volume descriptor lives. This is 15060Sstevel@tonic-gate * a fixed value for "normal" cd-rom's, but can change for 15070Sstevel@tonic-gate * multisession cd's. 15080Sstevel@tonic-gate * 15090Sstevel@tonic-gate * desc_sec is the same for high-sierra and iso 9660 formats, why 1510*5331Samw * there are two different #defines used in the code for this is 15110Sstevel@tonic-gate * beyond me. These are standards, cast in concrete, right? 15120Sstevel@tonic-gate * To be general, however, this function supports passing in different 15130Sstevel@tonic-gate * values. 15140Sstevel@tonic-gate */ 15150Sstevel@tonic-gate static int 15160Sstevel@tonic-gate hs_findvoldesc(dev_t rdev, int desc_sec) 15170Sstevel@tonic-gate { 15180Sstevel@tonic-gate int secno; 15190Sstevel@tonic-gate int error; 15200Sstevel@tonic-gate int rval; /* ignored */ 15210Sstevel@tonic-gate 15220Sstevel@tonic-gate #ifdef CDROMREADOFFSET 15230Sstevel@tonic-gate /* 15240Sstevel@tonic-gate * Issue the Read Offset ioctl directly to the 15250Sstevel@tonic-gate * device. Ignore any errors and set starting 15260Sstevel@tonic-gate * secno to the default, otherwise add the 15270Sstevel@tonic-gate * VOLDESC sector number to the offset. 15280Sstevel@tonic-gate */ 15290Sstevel@tonic-gate error = cdev_ioctl(rdev, CDROMREADOFFSET, (intptr_t)&secno, 15300Sstevel@tonic-gate FNATIVE|FKIOCTL|FREAD, CRED(), &rval); 15310Sstevel@tonic-gate if (error) { 15320Sstevel@tonic-gate secno = desc_sec; 15330Sstevel@tonic-gate } else { 15340Sstevel@tonic-gate secno += desc_sec; 15350Sstevel@tonic-gate } 15360Sstevel@tonic-gate #else 15370Sstevel@tonic-gate secno = desc_sec; 15380Sstevel@tonic-gate #endif 15390Sstevel@tonic-gate 15400Sstevel@tonic-gate return (secno); 15410Sstevel@tonic-gate } 1542