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 /* 22*1488Srsb * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * VFS operations for High Sierra filesystem 300Sstevel@tonic-gate */ 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/isa_defs.h> 340Sstevel@tonic-gate #include <sys/t_lock.h> 350Sstevel@tonic-gate #include <sys/param.h> 360Sstevel@tonic-gate #include <sys/systm.h> 370Sstevel@tonic-gate #include <sys/sysmacros.h> 380Sstevel@tonic-gate #include <sys/kmem.h> 390Sstevel@tonic-gate #include <sys/signal.h> 400Sstevel@tonic-gate #include <sys/user.h> 410Sstevel@tonic-gate #include <sys/proc.h> 420Sstevel@tonic-gate #include <sys/disp.h> 430Sstevel@tonic-gate #include <sys/buf.h> 440Sstevel@tonic-gate #include <sys/pathname.h> 450Sstevel@tonic-gate #include <sys/vfs.h> 460Sstevel@tonic-gate #include <sys/vnode.h> 470Sstevel@tonic-gate #include <sys/file.h> 480Sstevel@tonic-gate #include <sys/uio.h> 490Sstevel@tonic-gate #include <sys/conf.h> 500Sstevel@tonic-gate #include <sys/policy.h> 510Sstevel@tonic-gate 520Sstevel@tonic-gate #include <vm/page.h> 530Sstevel@tonic-gate 540Sstevel@tonic-gate #include <sys/fs/snode.h> 550Sstevel@tonic-gate #include <sys/fs/hsfs_spec.h> 560Sstevel@tonic-gate #include <sys/fs/hsfs_isospec.h> 570Sstevel@tonic-gate #include <sys/fs/hsfs_node.h> 580Sstevel@tonic-gate #include <sys/fs/hsfs_impl.h> 590Sstevel@tonic-gate #include <sys/fs/hsfs_susp.h> 600Sstevel@tonic-gate #include <sys/fs/hsfs_rrip.h> 610Sstevel@tonic-gate 620Sstevel@tonic-gate #include <sys/statvfs.h> 630Sstevel@tonic-gate #include <sys/mount.h> 640Sstevel@tonic-gate #include <sys/mntent.h> 650Sstevel@tonic-gate #include <sys/swap.h> 660Sstevel@tonic-gate #include <sys/errno.h> 670Sstevel@tonic-gate #include <sys/debug.h> 680Sstevel@tonic-gate #include "fs/fs_subr.h" 690Sstevel@tonic-gate #include <sys/cmn_err.h> 700Sstevel@tonic-gate #include <sys/bootconf.h> 710Sstevel@tonic-gate 720Sstevel@tonic-gate /* 730Sstevel@tonic-gate * These are needed for the CDROMREADOFFSET Code 740Sstevel@tonic-gate */ 750Sstevel@tonic-gate #include <sys/cdio.h> 760Sstevel@tonic-gate #include <sys/sunddi.h> 770Sstevel@tonic-gate 780Sstevel@tonic-gate #define HSFS_CLKSET 790Sstevel@tonic-gate 800Sstevel@tonic-gate #include <sys/modctl.h> 810Sstevel@tonic-gate 820Sstevel@tonic-gate /* 830Sstevel@tonic-gate * Options for mount. 840Sstevel@tonic-gate */ 850Sstevel@tonic-gate #define HOPT_GLOBAL MNTOPT_GLOBAL 860Sstevel@tonic-gate #define HOPT_NOGLOBAL MNTOPT_NOGLOBAL 870Sstevel@tonic-gate #define HOPT_MAPLCASE "maplcase" 880Sstevel@tonic-gate #define HOPT_NOMAPLCASE "nomaplcase" 890Sstevel@tonic-gate #define HOPT_NOTRAILDOT "notraildot" 900Sstevel@tonic-gate #define HOPT_TRAILDOT "traildot" 910Sstevel@tonic-gate #define HOPT_NRR "nrr" 920Sstevel@tonic-gate #define HOPT_RR "rr" 930Sstevel@tonic-gate #define HOPT_RO MNTOPT_RO 940Sstevel@tonic-gate 950Sstevel@tonic-gate static char *global_cancel[] = { HOPT_NOGLOBAL, NULL }; 960Sstevel@tonic-gate static char *noglobal_cancel[] = { HOPT_GLOBAL, NULL }; 970Sstevel@tonic-gate static char *mapl_cancel[] = { HOPT_NOMAPLCASE, NULL }; 980Sstevel@tonic-gate static char *nomapl_cancel[] = { HOPT_MAPLCASE, NULL }; 990Sstevel@tonic-gate static char *ro_cancel[] = { MNTOPT_RW, NULL }; 1000Sstevel@tonic-gate static char *rr_cancel[] = { HOPT_NRR, NULL }; 1010Sstevel@tonic-gate static char *nrr_cancel[] = { HOPT_RR, NULL }; 1020Sstevel@tonic-gate static char *trail_cancel[] = { HOPT_NOTRAILDOT, NULL }; 1030Sstevel@tonic-gate static char *notrail_cancel[] = { HOPT_TRAILDOT, NULL }; 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate static mntopt_t hsfs_options[] = { 1060Sstevel@tonic-gate { HOPT_GLOBAL, global_cancel, NULL, 0, NULL }, 1070Sstevel@tonic-gate { HOPT_NOGLOBAL, noglobal_cancel, NULL, MO_DEFAULT, NULL }, 1080Sstevel@tonic-gate { HOPT_MAPLCASE, mapl_cancel, NULL, MO_DEFAULT, NULL }, 1090Sstevel@tonic-gate { HOPT_NOMAPLCASE, nomapl_cancel, NULL, 0, NULL }, 1100Sstevel@tonic-gate { HOPT_RO, ro_cancel, NULL, MO_DEFAULT, NULL }, 1110Sstevel@tonic-gate { HOPT_RR, rr_cancel, NULL, MO_DEFAULT, NULL }, 1120Sstevel@tonic-gate { HOPT_NRR, nrr_cancel, NULL, 0, NULL }, 1130Sstevel@tonic-gate { HOPT_TRAILDOT, trail_cancel, NULL, MO_DEFAULT, NULL }, 1140Sstevel@tonic-gate { HOPT_NOTRAILDOT, notrail_cancel, NULL, 0, NULL }, 1150Sstevel@tonic-gate }; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate static mntopts_t hsfs_proto_opttbl = { 1180Sstevel@tonic-gate sizeof (hsfs_options) / sizeof (mntopt_t), 1190Sstevel@tonic-gate hsfs_options 1200Sstevel@tonic-gate }; 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate static int hsfsinit(int, char *); 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate static vfsdef_t vfw = { 1250Sstevel@tonic-gate VFSDEF_VERSION, 1260Sstevel@tonic-gate "hsfs", 1270Sstevel@tonic-gate hsfsinit, 128*1488Srsb VSW_HASPROTO|VSW_STATS, /* We don't suppport remounting */ 1290Sstevel@tonic-gate &hsfs_proto_opttbl 1300Sstevel@tonic-gate }; 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate static struct modlfs modlfs = { 1330Sstevel@tonic-gate &mod_fsops, "filesystem for HSFS", &vfw 1340Sstevel@tonic-gate }; 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate static struct modlinkage modlinkage = { 1370Sstevel@tonic-gate MODREV_1, (void *)&modlfs, NULL 1380Sstevel@tonic-gate }; 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate char _depends_on[] = "fs/specfs"; 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate int 1430Sstevel@tonic-gate _init() 1440Sstevel@tonic-gate { 1450Sstevel@tonic-gate return (mod_install(&modlinkage)); 1460Sstevel@tonic-gate } 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate int 1490Sstevel@tonic-gate _fini() 1500Sstevel@tonic-gate { 1510Sstevel@tonic-gate return (EBUSY); 1520Sstevel@tonic-gate } 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate int 1550Sstevel@tonic-gate _info(struct modinfo *modinfop) 1560Sstevel@tonic-gate { 1570Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1580Sstevel@tonic-gate } 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate #define BDEVFLAG(dev) ((devopsp[getmajor(dev)])->devo_cb_ops->cb_flag) 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate kmutex_t hs_mounttab_lock; 1630Sstevel@tonic-gate struct hsfs *hs_mounttab = NULL; 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate /* default mode, uid, gid */ 1660Sstevel@tonic-gate mode_t hsfs_default_mode = 0555; 1670Sstevel@tonic-gate uid_t hsfs_default_uid = 0; 1680Sstevel@tonic-gate gid_t hsfs_default_gid = 3; 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate static int hsfs_mount(struct vfs *vfsp, struct vnode *mvp, 1710Sstevel@tonic-gate struct mounta *uap, struct cred *cr); 1720Sstevel@tonic-gate static int hsfs_unmount(struct vfs *vfsp, int, struct cred *cr); 1730Sstevel@tonic-gate static int hsfs_root(struct vfs *vfsp, struct vnode **vpp); 1740Sstevel@tonic-gate static int hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp); 1750Sstevel@tonic-gate static int hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp); 1760Sstevel@tonic-gate static int hsfs_mountroot(struct vfs *, enum whymountroot); 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate static int hs_mountfs(struct vfs *vfsp, dev_t dev, char *path, 1790Sstevel@tonic-gate mode_t mode, int flags, struct cred *cr, int isroot); 1800Sstevel@tonic-gate static int hs_findhsvol(struct hsfs *fsp, struct vnode *vp, 1810Sstevel@tonic-gate struct hs_volume *hvp); 1820Sstevel@tonic-gate static int hs_parsehsvol(struct hsfs *fsp, uchar_t *volp, 1830Sstevel@tonic-gate struct hs_volume *hvp); 1840Sstevel@tonic-gate static int hs_findisovol(struct hsfs *fsp, struct vnode *vp, 1850Sstevel@tonic-gate struct hs_volume *hvp); 1860Sstevel@tonic-gate static int hs_parseisovol(struct hsfs *fsp, uchar_t *volp, 1870Sstevel@tonic-gate struct hs_volume *hvp); 1880Sstevel@tonic-gate static void hs_copylabel(struct hs_volume *, unsigned char *); 1890Sstevel@tonic-gate static int hs_getmdev(struct vfs *, char *fspec, int flags, dev_t *pdev, 1900Sstevel@tonic-gate mode_t *mode, cred_t *cr); 1910Sstevel@tonic-gate static int hs_findvoldesc(dev_t rdev, int desc_sec); 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate static int hsfsfstype; 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate static int 1960Sstevel@tonic-gate hsfsinit(int fstype, char *name) 1970Sstevel@tonic-gate { 1980Sstevel@tonic-gate static const fs_operation_def_t hsfs_vfsops_template[] = { 1990Sstevel@tonic-gate VFSNAME_MOUNT, hsfs_mount, 2000Sstevel@tonic-gate VFSNAME_UNMOUNT, hsfs_unmount, 2010Sstevel@tonic-gate VFSNAME_ROOT, hsfs_root, 2020Sstevel@tonic-gate VFSNAME_STATVFS, hsfs_statvfs, 2030Sstevel@tonic-gate VFSNAME_VGET, hsfs_vget, 2040Sstevel@tonic-gate VFSNAME_MOUNTROOT, hsfs_mountroot, 2050Sstevel@tonic-gate NULL, NULL 2060Sstevel@tonic-gate }; 2070Sstevel@tonic-gate int error; 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate error = vfs_setfsops(fstype, hsfs_vfsops_template, NULL); 2100Sstevel@tonic-gate if (error != 0) { 2110Sstevel@tonic-gate cmn_err(CE_WARN, "hsfsinit: bad vfs ops template"); 2120Sstevel@tonic-gate return (error); 2130Sstevel@tonic-gate } 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate error = vn_make_ops(name, hsfs_vnodeops_template, &hsfs_vnodeops); 2160Sstevel@tonic-gate if (error != 0) { 2170Sstevel@tonic-gate (void) vfs_freevfsops_by_type(fstype); 2180Sstevel@tonic-gate cmn_err(CE_WARN, "hsfsinit: bad vnode ops template"); 2190Sstevel@tonic-gate return (error); 2200Sstevel@tonic-gate } 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate hsfsfstype = fstype; 2230Sstevel@tonic-gate mutex_init(&hs_mounttab_lock, NULL, MUTEX_DEFAULT, NULL); 2240Sstevel@tonic-gate hs_init_hsnode_cache(); 2250Sstevel@tonic-gate return (0); 2260Sstevel@tonic-gate } 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate /*ARGSUSED*/ 2290Sstevel@tonic-gate static int 2300Sstevel@tonic-gate hsfs_mount(struct vfs *vfsp, struct vnode *mvp, 2310Sstevel@tonic-gate struct mounta *uap, struct cred *cr) 2320Sstevel@tonic-gate { 2330Sstevel@tonic-gate int vnode_busy; 2340Sstevel@tonic-gate dev_t dev; 2350Sstevel@tonic-gate struct pathname dpn; 2360Sstevel@tonic-gate int error; 2370Sstevel@tonic-gate mode_t mode; 2380Sstevel@tonic-gate int flags; /* this will hold the mount specific data */ 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate if ((error = secpolicy_fs_mount(cr, mvp, vfsp)) != 0) 2410Sstevel@tonic-gate return (error); 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate if (mvp->v_type != VDIR) 2440Sstevel@tonic-gate return (ENOTDIR); 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate /* mount option must be read only, else mount will be rejected */ 2470Sstevel@tonic-gate if (!(uap->flags & MS_RDONLY)) 2480Sstevel@tonic-gate return (EROFS); 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate /* 2510Sstevel@tonic-gate * We already told the framework that we don't support remounting. 2520Sstevel@tonic-gate */ 2530Sstevel@tonic-gate ASSERT(!(uap->flags & MS_REMOUNT)); 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate mutex_enter(&mvp->v_lock); 2560Sstevel@tonic-gate vnode_busy = (mvp->v_count != 1) || (mvp->v_flag & VROOT); 2570Sstevel@tonic-gate mutex_exit(&mvp->v_lock); 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate if ((uap->flags & MS_OVERLAY) == 0 && vnode_busy) { 2600Sstevel@tonic-gate return (EBUSY); 2610Sstevel@tonic-gate } 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate /* 2640Sstevel@tonic-gate * Check for the options that actually affect things 2650Sstevel@tonic-gate * at our level. 2660Sstevel@tonic-gate */ 2670Sstevel@tonic-gate flags = 0; 2680Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NOMAPLCASE, NULL)) 2690Sstevel@tonic-gate flags |= HSFSMNT_NOMAPLCASE; 2700Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NOTRAILDOT, NULL)) 2710Sstevel@tonic-gate flags |= HSFSMNT_NOTRAILDOT; 2720Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NRR, NULL)) 2730Sstevel@tonic-gate flags |= HSFSMNT_NORRIP; 2740Sstevel@tonic-gate 2750Sstevel@tonic-gate error = pn_get(uap->dir, (uap->flags & MS_SYSSPACE) ? 2760Sstevel@tonic-gate UIO_SYSSPACE : UIO_USERSPACE, &dpn); 2770Sstevel@tonic-gate if (error) 2780Sstevel@tonic-gate return (error); 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate if ((error = hs_getmdev(vfsp, uap->spec, uap->flags, &dev, 2810Sstevel@tonic-gate &mode, cr)) != 0) { 2820Sstevel@tonic-gate pn_free(&dpn); 2830Sstevel@tonic-gate return (error); 2840Sstevel@tonic-gate } 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate /* 2870Sstevel@tonic-gate * If the device is a tape, return error 2880Sstevel@tonic-gate */ 2890Sstevel@tonic-gate if ((BDEVFLAG(dev) & D_TAPE) == D_TAPE) { 2900Sstevel@tonic-gate pn_free(&dpn); 2910Sstevel@tonic-gate return (ENOTBLK); 2920Sstevel@tonic-gate } 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate /* 2950Sstevel@tonic-gate * Mount the filesystem. 2960Sstevel@tonic-gate */ 2970Sstevel@tonic-gate error = hs_mountfs(vfsp, dev, dpn.pn_path, mode, flags, cr, 0); 2980Sstevel@tonic-gate pn_free(&dpn); 2990Sstevel@tonic-gate return (error); 3000Sstevel@tonic-gate } 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate /*ARGSUSED*/ 3030Sstevel@tonic-gate static int 3040Sstevel@tonic-gate hsfs_unmount( 3050Sstevel@tonic-gate struct vfs *vfsp, 3060Sstevel@tonic-gate int flag, 3070Sstevel@tonic-gate struct cred *cr) 3080Sstevel@tonic-gate { 3090Sstevel@tonic-gate struct hsfs **tspp; 3100Sstevel@tonic-gate struct hsfs *fsp; 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate if (secpolicy_fs_unmount(cr, vfsp) != 0) 3130Sstevel@tonic-gate return (EPERM); 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate /* 3160Sstevel@tonic-gate * forced unmount is not supported by this file system 3170Sstevel@tonic-gate * and thus, ENOTSUP is being returned. 3180Sstevel@tonic-gate */ 3190Sstevel@tonic-gate if (flag & MS_FORCE) 3200Sstevel@tonic-gate return (ENOTSUP); 3210Sstevel@tonic-gate 3220Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp); 3230Sstevel@tonic-gate 3240Sstevel@tonic-gate if (fsp->hsfs_rootvp->v_count != 1) 3250Sstevel@tonic-gate return (EBUSY); 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate /* destroy all old pages and hsnodes for this vfs */ 3280Sstevel@tonic-gate if (hs_synchash(vfsp)) 3290Sstevel@tonic-gate return (EBUSY); 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate mutex_enter(&hs_mounttab_lock); 3320Sstevel@tonic-gate for (tspp = &hs_mounttab; *tspp != NULL; tspp = &(*tspp)->hsfs_next) { 3330Sstevel@tonic-gate if (*tspp == fsp) 3340Sstevel@tonic-gate break; 3350Sstevel@tonic-gate } 3360Sstevel@tonic-gate if (*tspp == NULL) { 3370Sstevel@tonic-gate mutex_exit(&hs_mounttab_lock); 3380Sstevel@tonic-gate panic("hsfs_unmount: vfs not mounted?"); 3390Sstevel@tonic-gate /*NOTREACHED*/ 3400Sstevel@tonic-gate } 3410Sstevel@tonic-gate 3420Sstevel@tonic-gate *tspp = fsp->hsfs_next; 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate mutex_exit(&hs_mounttab_lock); 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate (void) VOP_CLOSE(fsp->hsfs_devvp, FREAD, 1, (offset_t)0, cr); 3470Sstevel@tonic-gate VN_RELE(fsp->hsfs_devvp); 3480Sstevel@tonic-gate /* free path table space */ 3490Sstevel@tonic-gate if (fsp->hsfs_ptbl != NULL) 3500Sstevel@tonic-gate kmem_free(fsp->hsfs_ptbl, 3510Sstevel@tonic-gate (size_t)fsp->hsfs_vol.ptbl_len); 3520Sstevel@tonic-gate /* free path table index table */ 3530Sstevel@tonic-gate if (fsp->hsfs_ptbl_idx != NULL) 3540Sstevel@tonic-gate kmem_free(fsp->hsfs_ptbl_idx, (size_t) 3550Sstevel@tonic-gate (fsp->hsfs_ptbl_idx_size * sizeof (struct ptable_idx))); 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate /* free "mounted on" pathame */ 3580Sstevel@tonic-gate if (fsp->hsfs_fsmnt != NULL) 3590Sstevel@tonic-gate kmem_free(fsp->hsfs_fsmnt, strlen(fsp->hsfs_fsmnt) + 1); 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate mutex_destroy(&fsp->hsfs_free_lock); 3620Sstevel@tonic-gate rw_destroy(&fsp->hsfs_hash_lock); 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate kmem_free(fsp, sizeof (*fsp)); 3650Sstevel@tonic-gate return (0); 3660Sstevel@tonic-gate } 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate /*ARGSUSED*/ 3690Sstevel@tonic-gate static int 3700Sstevel@tonic-gate hsfs_root(struct vfs *vfsp, struct vnode **vpp) 3710Sstevel@tonic-gate { 3720Sstevel@tonic-gate *vpp = (VFS_TO_HSFS(vfsp))->hsfs_rootvp; 3730Sstevel@tonic-gate VN_HOLD(*vpp); 3740Sstevel@tonic-gate return (0); 3750Sstevel@tonic-gate } 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate /*ARGSUSED*/ 3780Sstevel@tonic-gate static int 3790Sstevel@tonic-gate hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp) 3800Sstevel@tonic-gate { 3810Sstevel@tonic-gate struct hsfs *fsp; 3820Sstevel@tonic-gate dev32_t d32; 3830Sstevel@tonic-gate 3840Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp); 3850Sstevel@tonic-gate if (fsp->hsfs_magic != HSFS_MAGIC) 3860Sstevel@tonic-gate return (EINVAL); 3870Sstevel@tonic-gate bzero(sbp, sizeof (*sbp)); 3880Sstevel@tonic-gate sbp->f_bsize = vfsp->vfs_bsize; 3890Sstevel@tonic-gate sbp->f_frsize = sbp->f_bsize; /* no fragment, same as block size */ 3900Sstevel@tonic-gate sbp->f_blocks = (fsblkcnt64_t)fsp->hsfs_vol.vol_size; 3910Sstevel@tonic-gate 3920Sstevel@tonic-gate sbp->f_bfree = (fsblkcnt64_t)0; 3930Sstevel@tonic-gate sbp->f_bavail = (fsblkcnt64_t)0; 3940Sstevel@tonic-gate sbp->f_files = (fsfilcnt64_t)-1; 3950Sstevel@tonic-gate sbp->f_ffree = (fsfilcnt64_t)0; 3960Sstevel@tonic-gate sbp->f_favail = (fsfilcnt64_t)0; 3970Sstevel@tonic-gate (void) cmpldev(&d32, vfsp->vfs_dev); 3980Sstevel@tonic-gate sbp->f_fsid = d32; 3990Sstevel@tonic-gate (void) strcpy(sbp->f_basetype, vfssw[vfsp->vfs_fstype].vsw_name); 4000Sstevel@tonic-gate sbp->f_flag = vf_to_stf(vfsp->vfs_flag); 4010Sstevel@tonic-gate sbp->f_namemax = fsp->hsfs_namemax; 4020Sstevel@tonic-gate (void) strcpy(sbp->f_fstr, fsp->hsfs_vol.vol_id); 4030Sstevel@tonic-gate 4040Sstevel@tonic-gate return (0); 4050Sstevel@tonic-gate } 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate /* 4080Sstevel@tonic-gate * Previously nodeid was declared as uint32_t. This has been changed 4090Sstevel@tonic-gate * to conform better with the ISO9660 standard. The standard states that 4100Sstevel@tonic-gate * a LBN can be a 32 bit number, as the MAKE_NODEID macro shifts this 4110Sstevel@tonic-gate * LBN 11 places left (LBN_TO_BYTE) and then shifts the result 5 right 4120Sstevel@tonic-gate * (divide by 32) we are left with the potential of an overflow if 4130Sstevel@tonic-gate * confined to a 32 bit value. 4140Sstevel@tonic-gate */ 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate static int 4170Sstevel@tonic-gate hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp) 4180Sstevel@tonic-gate { 4190Sstevel@tonic-gate struct hsfid *fid; 4200Sstevel@tonic-gate struct hsfs *fsp; 4210Sstevel@tonic-gate ino64_t nodeid; 4220Sstevel@tonic-gate int error; 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate fsp = (struct hsfs *)VFS_TO_HSFS(vfsp); 4250Sstevel@tonic-gate fid = (struct hsfid *)fidp; 4260Sstevel@tonic-gate 4270Sstevel@tonic-gate /* 4280Sstevel@tonic-gate * Look for vnode on hashlist. 4290Sstevel@tonic-gate * If found, it's now active and the refcnt was incremented. 4300Sstevel@tonic-gate */ 4310Sstevel@tonic-gate 4320Sstevel@tonic-gate rw_enter(&fsp->hsfs_hash_lock, RW_READER); 4330Sstevel@tonic-gate 4340Sstevel@tonic-gate nodeid = (ino64_t)MAKE_NODEID(fid->hf_dir_lbn, fid->hf_dir_off, vfsp); 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate if ((*vpp = hs_findhash(nodeid, vfsp)) == NULL) { 4370Sstevel@tonic-gate /* 4380Sstevel@tonic-gate * Not in cache, so we need to remake it. 4390Sstevel@tonic-gate * hs_remakenode() will read the directory entry 4400Sstevel@tonic-gate * and then check again to see if anyone else has 4410Sstevel@tonic-gate * put it in the cache. 4420Sstevel@tonic-gate */ 4430Sstevel@tonic-gate rw_exit(&fsp->hsfs_hash_lock); 4440Sstevel@tonic-gate error = hs_remakenode(fid->hf_dir_lbn, (uint_t)fid->hf_dir_off, 4450Sstevel@tonic-gate vfsp, vpp); 4460Sstevel@tonic-gate return (error); 4470Sstevel@tonic-gate } 4480Sstevel@tonic-gate rw_exit(&fsp->hsfs_hash_lock); 4490Sstevel@tonic-gate return (0); 4500Sstevel@tonic-gate } 4510Sstevel@tonic-gate 4520Sstevel@tonic-gate 4530Sstevel@tonic-gate #define CHECKSUM_SIZE (64 * 1024) 4540Sstevel@tonic-gate 4550Sstevel@tonic-gate /* 4560Sstevel@tonic-gate * Compute a CD-ROM fsid by checksumming the first 64K of data on the CD 4570Sstevel@tonic-gate * We use the 'fsp' argument to determine the location of the root 4580Sstevel@tonic-gate * directory entry, and we start reading from there. 4590Sstevel@tonic-gate */ 4600Sstevel@tonic-gate static int 4610Sstevel@tonic-gate compute_cdrom_id(struct hsfs *fsp, vnode_t *devvp) 4620Sstevel@tonic-gate { 4630Sstevel@tonic-gate uint_t secno; 4640Sstevel@tonic-gate struct hs_volume *hsvp = &fsp->hsfs_vol; 4650Sstevel@tonic-gate struct buf *bp; 4660Sstevel@tonic-gate int error; 4670Sstevel@tonic-gate int fsid; 4680Sstevel@tonic-gate 4690Sstevel@tonic-gate secno = hsvp->root_dir.ext_lbn >> hsvp->lbn_secshift; 470494Sfrankho bp = bread(devvp->v_rdev, secno * 4, CHECKSUM_SIZE); 4710Sstevel@tonic-gate error = geterror(bp); 472494Sfrankho 473494Sfrankho /* 474494Sfrankho * An error on read or a partial read means we asked 475494Sfrankho * for a nonexistant/corrupted piece of the device 476494Sfrankho * (including past-the-end of the media). Don't 477494Sfrankho * try to use the checksumming method then. 478494Sfrankho */ 479494Sfrankho if (!error && bp->b_bcount == CHECKSUM_SIZE) { 4800Sstevel@tonic-gate int *ibuf = (int *)bp->b_un.b_addr; 4810Sstevel@tonic-gate int i; 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate fsid = 0; 4840Sstevel@tonic-gate 485494Sfrankho for (i = 0; i < CHECKSUM_SIZE / sizeof (int); i++) 4860Sstevel@tonic-gate fsid ^= ibuf[ i ]; 487494Sfrankho } else { 488494Sfrankho /* 489494Sfrankho * Fallback - use creation date 490494Sfrankho */ 4910Sstevel@tonic-gate fsid = hsvp->cre_date.tv_sec; 492494Sfrankho } 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate brelse(bp); 4950Sstevel@tonic-gate 4960Sstevel@tonic-gate return (fsid); 4970Sstevel@tonic-gate } 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate /*ARGSUSED*/ 5010Sstevel@tonic-gate static int 5020Sstevel@tonic-gate hs_mountfs( 5030Sstevel@tonic-gate struct vfs *vfsp, 5040Sstevel@tonic-gate dev_t dev, 5050Sstevel@tonic-gate char *path, 5060Sstevel@tonic-gate mode_t mode, 5070Sstevel@tonic-gate int mount_flags, 5080Sstevel@tonic-gate struct cred *cr, 5090Sstevel@tonic-gate int isroot) 5100Sstevel@tonic-gate { 5110Sstevel@tonic-gate struct vnode *devvp; 5120Sstevel@tonic-gate struct hsfs *tsp; 5130Sstevel@tonic-gate struct hsfs *fsp = NULL; 5140Sstevel@tonic-gate struct vattr vap; 5150Sstevel@tonic-gate struct hsnode *hp; 5160Sstevel@tonic-gate int error; 5170Sstevel@tonic-gate struct timeval tv; 5180Sstevel@tonic-gate int fsid; 5190Sstevel@tonic-gate int use_rrip = (mount_flags & HSFSMNT_NORRIP) == 0; 5200Sstevel@tonic-gate 5210Sstevel@tonic-gate /* 5220Sstevel@tonic-gate * Open the device 5230Sstevel@tonic-gate */ 5240Sstevel@tonic-gate devvp = makespecvp(dev, VBLK); 5250Sstevel@tonic-gate ASSERT(devvp != 0); 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate /* 5280Sstevel@tonic-gate * Open the target device (file) for read only. 5290Sstevel@tonic-gate */ 5300Sstevel@tonic-gate if (error = VOP_OPEN(&devvp, FREAD, cr)) { 5310Sstevel@tonic-gate VN_RELE(devvp); 5320Sstevel@tonic-gate return (error); 5330Sstevel@tonic-gate } 5340Sstevel@tonic-gate 5350Sstevel@tonic-gate /* 5360Sstevel@tonic-gate * Refuse to go any further if this 5370Sstevel@tonic-gate * device is being used for swapping 5380Sstevel@tonic-gate */ 5390Sstevel@tonic-gate if (IS_SWAPVP(common_specvp(devvp))) { 5400Sstevel@tonic-gate error = EBUSY; 5410Sstevel@tonic-gate goto cleanup; 5420Sstevel@tonic-gate } 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate vap.va_mask = AT_SIZE; 5450Sstevel@tonic-gate if ((error = VOP_GETATTR(devvp, &vap, ATTR_COMM, cr)) != 0) { 5460Sstevel@tonic-gate cmn_err(CE_NOTE, "Cannot get attributes of the CD-ROM driver"); 5470Sstevel@tonic-gate goto cleanup; 5480Sstevel@tonic-gate } 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate /* 5510Sstevel@tonic-gate * Make sure we have a nonzero size partition. 5520Sstevel@tonic-gate * The current version of the SD driver will *not* fail the open 5530Sstevel@tonic-gate * of such a partition so we have to check for it here. 5540Sstevel@tonic-gate */ 5550Sstevel@tonic-gate if (vap.va_size == 0) { 5560Sstevel@tonic-gate error = ENXIO; 5570Sstevel@tonic-gate goto cleanup; 5580Sstevel@tonic-gate } 5590Sstevel@tonic-gate 5600Sstevel@tonic-gate /* 5610Sstevel@tonic-gate * Init a new hsfs structure. 5620Sstevel@tonic-gate */ 5630Sstevel@tonic-gate fsp = kmem_zalloc(sizeof (*fsp), KM_SLEEP); 5640Sstevel@tonic-gate 5650Sstevel@tonic-gate /* hardwire perms, uid, gid */ 5660Sstevel@tonic-gate fsp->hsfs_vol.vol_uid = hsfs_default_uid; 5670Sstevel@tonic-gate fsp->hsfs_vol.vol_gid = hsfs_default_gid; 5680Sstevel@tonic-gate fsp->hsfs_vol.vol_prot = hsfs_default_mode; 5690Sstevel@tonic-gate 5700Sstevel@tonic-gate /* 5710Sstevel@tonic-gate * Look for a Standard File Structure Volume Descriptor, 5720Sstevel@tonic-gate * of which there must be at least one. 5730Sstevel@tonic-gate * If found, check for volume size consistency. 5740Sstevel@tonic-gate */ 5751025Sfrankho error = hs_findisovol(fsp, devvp, &fsp->hsfs_vol); 5761025Sfrankho if (error == EINVAL) /* no iso 9660 - try high sierra ... */ 5771025Sfrankho error = hs_findhsvol(fsp, devvp, &fsp->hsfs_vol); 5780Sstevel@tonic-gate 5790Sstevel@tonic-gate if (error) 5800Sstevel@tonic-gate goto cleanup; 5810Sstevel@tonic-gate 5820Sstevel@tonic-gate /* 5830Sstevel@tonic-gate * Generate a file system ID from the CD-ROM, 5840Sstevel@tonic-gate * and check it for uniqueness. 5850Sstevel@tonic-gate * 5860Sstevel@tonic-gate * What we are aiming for is some chance of integrity 5870Sstevel@tonic-gate * across disk change. That is, if a client has an fhandle, 5880Sstevel@tonic-gate * it will be valid as long as the same disk is mounted. 5890Sstevel@tonic-gate */ 5900Sstevel@tonic-gate fsid = compute_cdrom_id(fsp, devvp); 5910Sstevel@tonic-gate 5920Sstevel@tonic-gate mutex_enter(&hs_mounttab_lock); 5930Sstevel@tonic-gate 5940Sstevel@tonic-gate if (fsid == 0 || fsid == -1) { 5950Sstevel@tonic-gate uniqtime(&tv); 5960Sstevel@tonic-gate fsid = tv.tv_sec; 5970Sstevel@tonic-gate } else /* make sure that the fsid is unique */ 5980Sstevel@tonic-gate for (tsp = hs_mounttab; tsp != NULL; tsp = tsp->hsfs_next) { 5990Sstevel@tonic-gate if (fsid == tsp->hsfs_vfs->vfs_fsid.val[0]) { 6000Sstevel@tonic-gate uniqtime(&tv); 6010Sstevel@tonic-gate fsid = tv.tv_sec; 6020Sstevel@tonic-gate break; 6030Sstevel@tonic-gate } 6040Sstevel@tonic-gate } 6050Sstevel@tonic-gate 6060Sstevel@tonic-gate fsp->hsfs_next = hs_mounttab; 6070Sstevel@tonic-gate hs_mounttab = fsp; 6080Sstevel@tonic-gate 6090Sstevel@tonic-gate fsp->hsfs_devvp = devvp; 6100Sstevel@tonic-gate fsp->hsfs_vfs = vfsp; 6110Sstevel@tonic-gate fsp->hsfs_fsmnt = kmem_alloc(strlen(path) + 1, KM_SLEEP); 6120Sstevel@tonic-gate (void) strcpy(fsp->hsfs_fsmnt, path); 6130Sstevel@tonic-gate 6140Sstevel@tonic-gate mutex_init(&fsp->hsfs_free_lock, NULL, MUTEX_DEFAULT, NULL); 6150Sstevel@tonic-gate rw_init(&fsp->hsfs_hash_lock, NULL, RW_DEFAULT, NULL); 6160Sstevel@tonic-gate 6170Sstevel@tonic-gate vfsp->vfs_data = (caddr_t)fsp; 6180Sstevel@tonic-gate vfsp->vfs_dev = dev; 6190Sstevel@tonic-gate vfsp->vfs_fstype = hsfsfstype; 6200Sstevel@tonic-gate vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size; /* %% */ 6210Sstevel@tonic-gate vfsp->vfs_fsid.val[0] = fsid; 6220Sstevel@tonic-gate vfsp->vfs_fsid.val[1] = hsfsfstype; 6230Sstevel@tonic-gate 6240Sstevel@tonic-gate /* 6250Sstevel@tonic-gate * If the root directory does not appear to be 6260Sstevel@tonic-gate * valid, use what it points to as "." instead. 6270Sstevel@tonic-gate * Some Defense Mapping Agency disks are non-conformant 6280Sstevel@tonic-gate * in this way. 6290Sstevel@tonic-gate */ 6300Sstevel@tonic-gate if (!hsfs_valid_dir(&fsp->hsfs_vol.root_dir)) { 6310Sstevel@tonic-gate hs_log_bogus_disk_warning(fsp, HSFS_ERR_BAD_ROOT_DIR, 0); 6320Sstevel@tonic-gate if (hs_remakenode(fsp->hsfs_vol.root_dir.ext_lbn, 6330Sstevel@tonic-gate (uint_t)0, vfsp, &fsp->hsfs_rootvp)) { 6340Sstevel@tonic-gate error = EINVAL; 6351025Sfrankho hs_mounttab = hs_mounttab->hsfs_next; 6361025Sfrankho mutex_destroy(&fsp->hsfs_free_lock); 6371025Sfrankho rw_destroy(&fsp->hsfs_hash_lock); 6381025Sfrankho kmem_free(fsp->hsfs_fsmnt, strlen(path) + 1); 639494Sfrankho mutex_exit(&hs_mounttab_lock); 6400Sstevel@tonic-gate goto cleanup; 6410Sstevel@tonic-gate } 6420Sstevel@tonic-gate } else { 6430Sstevel@tonic-gate fsp->hsfs_rootvp = hs_makenode(&fsp->hsfs_vol.root_dir, 6440Sstevel@tonic-gate fsp->hsfs_vol.root_dir.ext_lbn, 0, vfsp); 6450Sstevel@tonic-gate } 6460Sstevel@tonic-gate 6470Sstevel@tonic-gate /* mark vnode as VROOT */ 6480Sstevel@tonic-gate fsp->hsfs_rootvp->v_flag |= VROOT; 6490Sstevel@tonic-gate 6500Sstevel@tonic-gate /* Here we take care of some special case stuff for mountroot */ 6510Sstevel@tonic-gate if (isroot) { 6520Sstevel@tonic-gate fsp->hsfs_rootvp->v_rdev = devvp->v_rdev; 6530Sstevel@tonic-gate rootvp = fsp->hsfs_rootvp; 6540Sstevel@tonic-gate } 6550Sstevel@tonic-gate 6560Sstevel@tonic-gate /* XXX - ignore the path table for now */ 6570Sstevel@tonic-gate fsp->hsfs_ptbl = NULL; 6580Sstevel@tonic-gate hp = VTOH(fsp->hsfs_rootvp); 6590Sstevel@tonic-gate hp->hs_ptbl_idx = NULL; 6600Sstevel@tonic-gate 6610Sstevel@tonic-gate if (use_rrip) 6620Sstevel@tonic-gate hs_check_root_dirent(fsp->hsfs_rootvp, &(hp->hs_dirent)); 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate fsp->hsfs_namemax = IS_RRIP_IMPLEMENTED(fsp) 6650Sstevel@tonic-gate ? RRIP_FILE_NAMELEN 6660Sstevel@tonic-gate : ISO_FILE_NAMELEN; 6670Sstevel@tonic-gate /* 6680Sstevel@tonic-gate * if RRIP, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags 6690Sstevel@tonic-gate */ 6700Sstevel@tonic-gate if (IS_RRIP_IMPLEMENTED(fsp)) 6710Sstevel@tonic-gate mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT); 6720Sstevel@tonic-gate 6730Sstevel@tonic-gate fsp->hsfs_flags = mount_flags; 6740Sstevel@tonic-gate 6750Sstevel@tonic-gate /* set the magic word */ 6760Sstevel@tonic-gate fsp->hsfs_magic = HSFS_MAGIC; 6770Sstevel@tonic-gate mutex_exit(&hs_mounttab_lock); 6780Sstevel@tonic-gate 6790Sstevel@tonic-gate return (0); 6800Sstevel@tonic-gate 6810Sstevel@tonic-gate cleanup: 6820Sstevel@tonic-gate (void) VOP_CLOSE(devvp, FREAD, 1, (offset_t)0, cr); 6830Sstevel@tonic-gate VN_RELE(devvp); 6840Sstevel@tonic-gate if (fsp) 6850Sstevel@tonic-gate kmem_free(fsp, sizeof (*fsp)); 6860Sstevel@tonic-gate return (error); 6870Sstevel@tonic-gate } 6880Sstevel@tonic-gate 6890Sstevel@tonic-gate /* 6900Sstevel@tonic-gate * hs_findhsvol() 6910Sstevel@tonic-gate * 6920Sstevel@tonic-gate * Locate the Standard File Structure Volume Descriptor and 6930Sstevel@tonic-gate * parse it into an hs_volume structure. 6940Sstevel@tonic-gate * 6950Sstevel@tonic-gate * XXX - May someday want to look for Coded Character Set FSVD, too. 6960Sstevel@tonic-gate */ 6970Sstevel@tonic-gate static int 6980Sstevel@tonic-gate hs_findhsvol(struct hsfs *fsp, struct vnode *vp, struct hs_volume *hvp) 6990Sstevel@tonic-gate { 7000Sstevel@tonic-gate struct buf *secbp; 7010Sstevel@tonic-gate int i; 7020Sstevel@tonic-gate uchar_t *volp; 7030Sstevel@tonic-gate int error; 7040Sstevel@tonic-gate uint_t secno; 7050Sstevel@tonic-gate 7060Sstevel@tonic-gate secno = hs_findvoldesc(vp->v_rdev, HS_VOLDESC_SEC); 7070Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE); 7080Sstevel@tonic-gate error = geterror(secbp); 7090Sstevel@tonic-gate 7100Sstevel@tonic-gate if (error != 0) { 7110Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)", error); 7120Sstevel@tonic-gate brelse(secbp); 7130Sstevel@tonic-gate return (error); 7140Sstevel@tonic-gate } 7150Sstevel@tonic-gate 7160Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 7170Sstevel@tonic-gate 7180Sstevel@tonic-gate while (HSV_DESC_TYPE(volp) != VD_EOV) { 7190Sstevel@tonic-gate for (i = 0; i < HSV_ID_STRLEN; i++) 7200Sstevel@tonic-gate if (HSV_STD_ID(volp)[i] != HSV_ID_STRING[i]) 7210Sstevel@tonic-gate goto cantfind; 7220Sstevel@tonic-gate if (HSV_STD_VER(volp) != HSV_ID_VER) 7230Sstevel@tonic-gate goto cantfind; 7240Sstevel@tonic-gate switch (HSV_DESC_TYPE(volp)) { 7250Sstevel@tonic-gate case VD_SFS: 7260Sstevel@tonic-gate /* Standard File Structure */ 7270Sstevel@tonic-gate fsp->hsfs_vol_type = HS_VOL_TYPE_HS; 7280Sstevel@tonic-gate error = hs_parsehsvol(fsp, volp, hvp); 7290Sstevel@tonic-gate brelse(secbp); 7300Sstevel@tonic-gate return (error); 7310Sstevel@tonic-gate 7320Sstevel@tonic-gate case VD_CCFS: 7330Sstevel@tonic-gate /* Coded Character File Structure */ 7340Sstevel@tonic-gate case VD_BOOT: 7350Sstevel@tonic-gate case VD_UNSPEC: 7360Sstevel@tonic-gate case VD_EOV: 7370Sstevel@tonic-gate break; 7380Sstevel@tonic-gate } 7390Sstevel@tonic-gate brelse(secbp); 7400Sstevel@tonic-gate ++secno; 7410Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE); 7420Sstevel@tonic-gate 7430Sstevel@tonic-gate error = geterror(secbp); 7440Sstevel@tonic-gate 7450Sstevel@tonic-gate if (error != 0) { 7460Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)", 7470Sstevel@tonic-gate error); 7480Sstevel@tonic-gate brelse(secbp); 7490Sstevel@tonic-gate return (error); 7500Sstevel@tonic-gate } 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 7530Sstevel@tonic-gate } 7540Sstevel@tonic-gate cantfind: 7550Sstevel@tonic-gate brelse(secbp); 7560Sstevel@tonic-gate return (EINVAL); 7570Sstevel@tonic-gate } 7580Sstevel@tonic-gate 7590Sstevel@tonic-gate /* 7600Sstevel@tonic-gate * hs_parsehsvol 7610Sstevel@tonic-gate * 7620Sstevel@tonic-gate * Parse the Standard File Structure Volume Descriptor into 7630Sstevel@tonic-gate * an hs_volume structure. We can't just bcopy it into the 7640Sstevel@tonic-gate * structure because of byte-ordering problems. 7650Sstevel@tonic-gate * 7660Sstevel@tonic-gate */ 7670Sstevel@tonic-gate static int 7680Sstevel@tonic-gate hs_parsehsvol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp) 7690Sstevel@tonic-gate { 7700Sstevel@tonic-gate hvp->vol_size = HSV_VOL_SIZE(volp); 7710Sstevel@tonic-gate hvp->lbn_size = HSV_BLK_SIZE(volp); 7720Sstevel@tonic-gate if (hvp->lbn_size == 0) { 7730Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_parsehsvol: logical block size in the " 7740Sstevel@tonic-gate "SFSVD is zero"); 7750Sstevel@tonic-gate return (EINVAL); 7760Sstevel@tonic-gate } 7770Sstevel@tonic-gate hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1; 7780Sstevel@tonic-gate hvp->lbn_secshift = ffs((long)howmany(HS_SECTOR_SIZE, 7790Sstevel@tonic-gate (int)hvp->lbn_size)) - 1; 7800Sstevel@tonic-gate hvp->lbn_maxoffset = hvp->lbn_size - 1; 7810Sstevel@tonic-gate hs_parse_longdate(HSV_cre_date(volp), &hvp->cre_date); 7820Sstevel@tonic-gate hs_parse_longdate(HSV_mod_date(volp), &hvp->mod_date); 7830Sstevel@tonic-gate hvp->file_struct_ver = HSV_FILE_STRUCT_VER(volp); 7840Sstevel@tonic-gate hvp->ptbl_len = HSV_PTBL_SIZE(volp); 7850Sstevel@tonic-gate hvp->vol_set_size = (ushort_t)HSV_SET_SIZE(volp); 7860Sstevel@tonic-gate hvp->vol_set_seq = (ushort_t)HSV_SET_SEQ(volp); 7870Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 7880Sstevel@tonic-gate hvp->ptbl_lbn = HSV_PTBL_MAN_LS(volp); 7890Sstevel@tonic-gate #else 7900Sstevel@tonic-gate hvp->ptbl_lbn = HSV_PTBL_MAN_MS(volp); 7910Sstevel@tonic-gate #endif 7920Sstevel@tonic-gate hs_copylabel(hvp, HSV_VOL_ID(volp)); 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate /* 7950Sstevel@tonic-gate * Make sure that lbn_size is a power of two and otherwise valid. 7960Sstevel@tonic-gate */ 7970Sstevel@tonic-gate if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) { 7980Sstevel@tonic-gate cmn_err(CE_NOTE, 7990Sstevel@tonic-gate "hsfs: %d-byte logical block size not supported", 8000Sstevel@tonic-gate hvp->lbn_size); 8010Sstevel@tonic-gate return (EINVAL); 8020Sstevel@tonic-gate } 8030Sstevel@tonic-gate return (hs_parsedir(fsp, HSV_ROOT_DIR(volp), &hvp->root_dir, 8040Sstevel@tonic-gate (char *)NULL, (int *)NULL)); 8050Sstevel@tonic-gate } 8060Sstevel@tonic-gate 8070Sstevel@tonic-gate /* 8080Sstevel@tonic-gate * hs_findisovol() 8090Sstevel@tonic-gate * 8100Sstevel@tonic-gate * Locate the Primary Volume Descriptor 8110Sstevel@tonic-gate * parse it into an hs_volume structure. 8120Sstevel@tonic-gate * 8130Sstevel@tonic-gate * XXX - Supplementary, Partition not yet done 8140Sstevel@tonic-gate */ 8150Sstevel@tonic-gate static int 8160Sstevel@tonic-gate hs_findisovol(struct hsfs *fsp, struct vnode *vp, 8170Sstevel@tonic-gate struct hs_volume *hvp) 8180Sstevel@tonic-gate { 8190Sstevel@tonic-gate struct buf *secbp; 8200Sstevel@tonic-gate int i; 8210Sstevel@tonic-gate uchar_t *volp; 8220Sstevel@tonic-gate int error; 8230Sstevel@tonic-gate uint_t secno; 8240Sstevel@tonic-gate int foundpvd = 0; 8250Sstevel@tonic-gate 8260Sstevel@tonic-gate secno = hs_findvoldesc(vp->v_rdev, ISO_VOLDESC_SEC); 8270Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, ISO_SECTOR_SIZE); 8280Sstevel@tonic-gate error = geterror(secbp); 8290Sstevel@tonic-gate 8300Sstevel@tonic-gate if (error != 0) { 8310Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)", error); 8320Sstevel@tonic-gate brelse(secbp); 8330Sstevel@tonic-gate return (error); 8340Sstevel@tonic-gate } 8350Sstevel@tonic-gate 8360Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 8370Sstevel@tonic-gate 8380Sstevel@tonic-gate while ((enum iso_voldesc_type) ISO_DESC_TYPE(volp) != ISO_VD_EOV) { 8390Sstevel@tonic-gate for (i = 0; i < ISO_ID_STRLEN; i++) 8400Sstevel@tonic-gate if (ISO_STD_ID(volp)[i] != ISO_ID_STRING[i]) 8410Sstevel@tonic-gate goto cantfind; 8420Sstevel@tonic-gate if (ISO_STD_VER(volp) != ISO_ID_VER) 8430Sstevel@tonic-gate goto cantfind; 8440Sstevel@tonic-gate switch (ISO_DESC_TYPE(volp)) { 8450Sstevel@tonic-gate case ISO_VD_PVD: 8460Sstevel@tonic-gate /* Standard File Structure */ 8470Sstevel@tonic-gate if (foundpvd != 1) { 8480Sstevel@tonic-gate fsp->hsfs_vol_type = HS_VOL_TYPE_ISO; 8490Sstevel@tonic-gate if (error = hs_parseisovol(fsp, volp, hvp)) { 8500Sstevel@tonic-gate brelse(secbp); 8510Sstevel@tonic-gate return (error); 8520Sstevel@tonic-gate } 8530Sstevel@tonic-gate foundpvd = 1; 8540Sstevel@tonic-gate } 8550Sstevel@tonic-gate break; 8560Sstevel@tonic-gate case ISO_VD_SVD: 8570Sstevel@tonic-gate /* Supplementary Volume Descriptor */ 8580Sstevel@tonic-gate break; 8590Sstevel@tonic-gate case ISO_VD_BOOT: 8600Sstevel@tonic-gate break; 8610Sstevel@tonic-gate case ISO_VD_VPD: 8620Sstevel@tonic-gate /* currently cannot handle partition */ 8630Sstevel@tonic-gate break; 8640Sstevel@tonic-gate case VD_EOV: 8650Sstevel@tonic-gate break; 8660Sstevel@tonic-gate } 8670Sstevel@tonic-gate brelse(secbp); 8680Sstevel@tonic-gate ++secno; 8690Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE); 8700Sstevel@tonic-gate error = geterror(secbp); 8710Sstevel@tonic-gate 8720Sstevel@tonic-gate if (error != 0) { 8730Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)", 8740Sstevel@tonic-gate error); 8750Sstevel@tonic-gate brelse(secbp); 8760Sstevel@tonic-gate return (error); 8770Sstevel@tonic-gate } 8780Sstevel@tonic-gate 8790Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr; 8800Sstevel@tonic-gate } 8810Sstevel@tonic-gate if (foundpvd) { 8820Sstevel@tonic-gate brelse(secbp); 8830Sstevel@tonic-gate return (0); 8840Sstevel@tonic-gate } 8850Sstevel@tonic-gate cantfind: 8860Sstevel@tonic-gate brelse(secbp); 8870Sstevel@tonic-gate return (EINVAL); 8880Sstevel@tonic-gate } 8890Sstevel@tonic-gate /* 8900Sstevel@tonic-gate * hs_parseisovol 8910Sstevel@tonic-gate * 8920Sstevel@tonic-gate * Parse the Primary Volume Descriptor into an hs_volume structure. 8930Sstevel@tonic-gate * 8940Sstevel@tonic-gate */ 8950Sstevel@tonic-gate static int 8960Sstevel@tonic-gate hs_parseisovol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp) 8970Sstevel@tonic-gate { 8980Sstevel@tonic-gate hvp->vol_size = ISO_VOL_SIZE(volp); 8990Sstevel@tonic-gate hvp->lbn_size = ISO_BLK_SIZE(volp); 9000Sstevel@tonic-gate if (hvp->lbn_size == 0) { 9010Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_parseisovol: logical block size in the " 9020Sstevel@tonic-gate "PVD is zero"); 9030Sstevel@tonic-gate return (EINVAL); 9040Sstevel@tonic-gate } 9050Sstevel@tonic-gate hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1; 9060Sstevel@tonic-gate hvp->lbn_secshift = ffs((long)howmany(ISO_SECTOR_SIZE, 9070Sstevel@tonic-gate (int)hvp->lbn_size)) - 1; 9080Sstevel@tonic-gate hvp->lbn_maxoffset = hvp->lbn_size - 1; 9090Sstevel@tonic-gate hs_parse_longdate(ISO_cre_date(volp), &hvp->cre_date); 9100Sstevel@tonic-gate hs_parse_longdate(ISO_mod_date(volp), &hvp->mod_date); 9110Sstevel@tonic-gate hvp->file_struct_ver = ISO_FILE_STRUCT_VER(volp); 9120Sstevel@tonic-gate hvp->ptbl_len = ISO_PTBL_SIZE(volp); 9130Sstevel@tonic-gate hvp->vol_set_size = (ushort_t)ISO_SET_SIZE(volp); 9140Sstevel@tonic-gate hvp->vol_set_seq = (ushort_t)ISO_SET_SEQ(volp); 9150Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 9160Sstevel@tonic-gate hvp->ptbl_lbn = ISO_PTBL_MAN_LS(volp); 9170Sstevel@tonic-gate #else 9180Sstevel@tonic-gate hvp->ptbl_lbn = ISO_PTBL_MAN_MS(volp); 9190Sstevel@tonic-gate #endif 9200Sstevel@tonic-gate hs_copylabel(hvp, ISO_VOL_ID(volp)); 9210Sstevel@tonic-gate 9220Sstevel@tonic-gate /* 9230Sstevel@tonic-gate * Make sure that lbn_size is a power of two and otherwise valid. 9240Sstevel@tonic-gate */ 9250Sstevel@tonic-gate if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) { 9260Sstevel@tonic-gate cmn_err(CE_NOTE, 9270Sstevel@tonic-gate "hsfs: %d-byte logical block size not supported", 9280Sstevel@tonic-gate hvp->lbn_size); 9290Sstevel@tonic-gate return (EINVAL); 9300Sstevel@tonic-gate } 9310Sstevel@tonic-gate return (hs_parsedir(fsp, ISO_ROOT_DIR(volp), &hvp->root_dir, 9320Sstevel@tonic-gate (char *)NULL, (int *)NULL)); 9330Sstevel@tonic-gate } 9340Sstevel@tonic-gate 9350Sstevel@tonic-gate /* 9360Sstevel@tonic-gate * Common code for mount and umount. 9370Sstevel@tonic-gate * Check that the user's argument is a reasonable 9380Sstevel@tonic-gate * thing on which to mount, and return the device number if so. 9390Sstevel@tonic-gate */ 9400Sstevel@tonic-gate static int 9410Sstevel@tonic-gate hs_getmdev(struct vfs *vfsp, char *fspec, int flags, dev_t *pdev, mode_t *mode, 9420Sstevel@tonic-gate cred_t *cr) 9430Sstevel@tonic-gate { 9440Sstevel@tonic-gate int error; 9450Sstevel@tonic-gate struct vnode *vp; 9460Sstevel@tonic-gate struct vattr vap; 9470Sstevel@tonic-gate dev_t dev; 9480Sstevel@tonic-gate 9490Sstevel@tonic-gate /* 9500Sstevel@tonic-gate * Get the device to be mounted 9510Sstevel@tonic-gate */ 9520Sstevel@tonic-gate error = lookupname(fspec, (flags & MS_SYSSPACE) ? 9530Sstevel@tonic-gate UIO_SYSSPACE : UIO_USERSPACE, FOLLOW, NULLVPP, &vp); 9540Sstevel@tonic-gate if (error) { 9550Sstevel@tonic-gate if (error == ENOENT) { 9560Sstevel@tonic-gate return (ENODEV); /* needs translation */ 9570Sstevel@tonic-gate } 9580Sstevel@tonic-gate return (error); 9590Sstevel@tonic-gate } 9600Sstevel@tonic-gate if (vp->v_type != VBLK) { 9610Sstevel@tonic-gate VN_RELE(vp); 9620Sstevel@tonic-gate return (ENOTBLK); 9630Sstevel@tonic-gate } 9640Sstevel@tonic-gate /* 9650Sstevel@tonic-gate * Can we read from the device? 9660Sstevel@tonic-gate */ 9670Sstevel@tonic-gate if ((error = VOP_ACCESS(vp, VREAD, 0, cr)) != 0 || 9680Sstevel@tonic-gate (error = secpolicy_spec_open(cr, vp, FREAD)) != 0) { 9690Sstevel@tonic-gate VN_RELE(vp); 9700Sstevel@tonic-gate return (error); 9710Sstevel@tonic-gate } 9720Sstevel@tonic-gate 9730Sstevel@tonic-gate vap.va_mask = AT_MODE; /* get protection mode */ 9740Sstevel@tonic-gate (void) VOP_GETATTR(vp, &vap, 0, CRED()); 9750Sstevel@tonic-gate *mode = vap.va_mode; 9760Sstevel@tonic-gate 9770Sstevel@tonic-gate dev = *pdev = vp->v_rdev; 9780Sstevel@tonic-gate VN_RELE(vp); 9790Sstevel@tonic-gate 9800Sstevel@tonic-gate /* 9810Sstevel@tonic-gate * Ensure that this device isn't already mounted, 9820Sstevel@tonic-gate * unless this is a REMOUNT request or we are told to suppress 9830Sstevel@tonic-gate * mount checks. 9840Sstevel@tonic-gate */ 9850Sstevel@tonic-gate if ((flags & MS_NOCHECK) == 0) { 9860Sstevel@tonic-gate if (vfs_devmounting(dev, vfsp)) 9870Sstevel@tonic-gate return (EBUSY); 9880Sstevel@tonic-gate if (vfs_devismounted(dev) && !(flags & MS_REMOUNT)) 9890Sstevel@tonic-gate return (EBUSY); 9900Sstevel@tonic-gate } 9910Sstevel@tonic-gate 9920Sstevel@tonic-gate if (getmajor(*pdev) >= devcnt) 9930Sstevel@tonic-gate return (ENXIO); 9940Sstevel@tonic-gate return (0); 9950Sstevel@tonic-gate } 9960Sstevel@tonic-gate 9970Sstevel@tonic-gate static void 9980Sstevel@tonic-gate hs_copylabel(struct hs_volume *hvp, unsigned char *label) 9990Sstevel@tonic-gate { 10000Sstevel@tonic-gate /* cdrom volid is at most 32 bytes */ 10010Sstevel@tonic-gate bcopy(label, hvp->vol_id, 32); 10020Sstevel@tonic-gate hvp->vol_id[31] = NULL; 10030Sstevel@tonic-gate } 10040Sstevel@tonic-gate 10050Sstevel@tonic-gate /* 10060Sstevel@tonic-gate * Mount root file system. 10070Sstevel@tonic-gate * "why" is ROOT_INIT on initial call, ROOT_REMOUNT if called to 10080Sstevel@tonic-gate * remount the root file system, and ROOT_UNMOUNT if called to 10090Sstevel@tonic-gate * unmount the root (e.g., as part of a system shutdown). 10100Sstevel@tonic-gate * 10110Sstevel@tonic-gate * XXX - this may be partially machine-dependent; it, along with the VFS_SWAPVP 10120Sstevel@tonic-gate * operation, goes along with auto-configuration. A mechanism should be 10130Sstevel@tonic-gate * provided by which machine-INdependent code in the kernel can say "get me the 10140Sstevel@tonic-gate * right root file system" and "get me the right initial swap area", and have 10150Sstevel@tonic-gate * that done in what may well be a machine-dependent fashion. 10160Sstevel@tonic-gate * Unfortunately, it is also file-system-type dependent (NFS gets it via 10170Sstevel@tonic-gate * bootparams calls, UFS gets it from various and sundry machine-dependent 10180Sstevel@tonic-gate * mechanisms, as SPECFS does for swap). 10190Sstevel@tonic-gate */ 10200Sstevel@tonic-gate static int 10210Sstevel@tonic-gate hsfs_mountroot(struct vfs *vfsp, enum whymountroot why) 10220Sstevel@tonic-gate { 10230Sstevel@tonic-gate int error; 10240Sstevel@tonic-gate struct hsfs *fsp; 10250Sstevel@tonic-gate struct hs_volume *fvolp; 10260Sstevel@tonic-gate static int hsfsrootdone = 0; 10270Sstevel@tonic-gate dev_t rootdev; 10280Sstevel@tonic-gate mode_t mode = 0; 10290Sstevel@tonic-gate 10300Sstevel@tonic-gate if (why == ROOT_INIT) { 10310Sstevel@tonic-gate if (hsfsrootdone++) 10320Sstevel@tonic-gate return (EBUSY); 10330Sstevel@tonic-gate rootdev = getrootdev(); 10340Sstevel@tonic-gate if (rootdev == (dev_t)NODEV) 10350Sstevel@tonic-gate return (ENODEV); 10360Sstevel@tonic-gate vfsp->vfs_dev = rootdev; 10370Sstevel@tonic-gate vfsp->vfs_flag |= VFS_RDONLY; 10380Sstevel@tonic-gate } else if (why == ROOT_REMOUNT) { 10390Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: ROOT_REMOUNT"); 10400Sstevel@tonic-gate return (0); 10410Sstevel@tonic-gate } else if (why == ROOT_UNMOUNT) { 10420Sstevel@tonic-gate return (0); 10430Sstevel@tonic-gate } 10440Sstevel@tonic-gate error = vfs_lock(vfsp); 10450Sstevel@tonic-gate if (error) { 10460Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: couldn't get vfs_lock"); 10470Sstevel@tonic-gate return (error); 10480Sstevel@tonic-gate } 10490Sstevel@tonic-gate 10500Sstevel@tonic-gate error = hs_mountfs(vfsp, rootdev, "/", mode, 1, CRED(), 1); 10510Sstevel@tonic-gate /* 10520Sstevel@tonic-gate * XXX - assumes root device is not indirect, because we don't set 10530Sstevel@tonic-gate * rootvp. Is rootvp used for anything? If so, make another arg 10540Sstevel@tonic-gate * to mountfs. 10550Sstevel@tonic-gate */ 10560Sstevel@tonic-gate if (error) { 10570Sstevel@tonic-gate vfs_unlock(vfsp); 10580Sstevel@tonic-gate if (rootvp) { 10590Sstevel@tonic-gate VN_RELE(rootvp); 10600Sstevel@tonic-gate rootvp = (struct vnode *)0; 10610Sstevel@tonic-gate } 10620Sstevel@tonic-gate return (error); 10630Sstevel@tonic-gate } 10640Sstevel@tonic-gate if (why == ROOT_INIT) 10650Sstevel@tonic-gate vfs_add((struct vnode *)0, vfsp, 10660Sstevel@tonic-gate (vfsp->vfs_flag & VFS_RDONLY) ? MS_RDONLY : 0); 10670Sstevel@tonic-gate vfs_unlock(vfsp); 10680Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp); 10690Sstevel@tonic-gate fvolp = &fsp->hsfs_vol; 10700Sstevel@tonic-gate #ifdef HSFS_CLKSET 10710Sstevel@tonic-gate if (fvolp->cre_date.tv_sec == 0) { 10720Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: cre_date.tv_sec == 0"); 10730Sstevel@tonic-gate if (fvolp->mod_date.tv_sec == 0) { 10740Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: mod_date.tv_sec == 0"); 10750Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: clkset(-1L)"); 10760Sstevel@tonic-gate clkset(-1L); 10770Sstevel@tonic-gate } else 10780Sstevel@tonic-gate clkset(fvolp->mod_date.tv_sec); 10790Sstevel@tonic-gate } else 10800Sstevel@tonic-gate clkset(fvolp->mod_date.tv_sec); 10810Sstevel@tonic-gate #else /* HSFS_CLKSET */ 10820Sstevel@tonic-gate clkset(-1L); 10830Sstevel@tonic-gate #endif /* HSFS_CLKSET */ 10840Sstevel@tonic-gate return (0); 10850Sstevel@tonic-gate } 10860Sstevel@tonic-gate 10870Sstevel@tonic-gate /* 10880Sstevel@tonic-gate * hs_findvoldesc() 10890Sstevel@tonic-gate * 10900Sstevel@tonic-gate * Return the sector where the volume descriptor lives. This is 10910Sstevel@tonic-gate * a fixed value for "normal" cd-rom's, but can change for 10920Sstevel@tonic-gate * multisession cd's. 10930Sstevel@tonic-gate * 10940Sstevel@tonic-gate * desc_sec is the same for high-sierra and iso 9660 formats, why 10950Sstevel@tonic-gate * there are two differnt #defines used in the code for this is 10960Sstevel@tonic-gate * beyond me. These are standards, cast in concrete, right? 10970Sstevel@tonic-gate * To be general, however, this function supports passing in different 10980Sstevel@tonic-gate * values. 10990Sstevel@tonic-gate */ 11000Sstevel@tonic-gate static int 11010Sstevel@tonic-gate hs_findvoldesc(dev_t rdev, int desc_sec) 11020Sstevel@tonic-gate { 11030Sstevel@tonic-gate int secno; 11040Sstevel@tonic-gate int error; 11050Sstevel@tonic-gate int rval; /* ignored */ 11060Sstevel@tonic-gate 11070Sstevel@tonic-gate #ifdef CDROMREADOFFSET 11080Sstevel@tonic-gate /* 11090Sstevel@tonic-gate * Issue the Read Offset ioctl directly to the 11100Sstevel@tonic-gate * device. Ignore any errors and set starting 11110Sstevel@tonic-gate * secno to the default, otherwise add the 11120Sstevel@tonic-gate * VOLDESC sector number to the offset. 11130Sstevel@tonic-gate */ 11140Sstevel@tonic-gate error = cdev_ioctl(rdev, CDROMREADOFFSET, (intptr_t)&secno, 11150Sstevel@tonic-gate FNATIVE|FKIOCTL|FREAD, CRED(), &rval); 11160Sstevel@tonic-gate if (error) { 11170Sstevel@tonic-gate secno = desc_sec; 11180Sstevel@tonic-gate } else { 11190Sstevel@tonic-gate secno += desc_sec; 11200Sstevel@tonic-gate } 11210Sstevel@tonic-gate #else 11220Sstevel@tonic-gate secno = desc_sec; 11230Sstevel@tonic-gate #endif 11240Sstevel@tonic-gate 11250Sstevel@tonic-gate return (secno); 11260Sstevel@tonic-gate } 1127