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