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*12633Sjohn.levon@sun.com * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate /*
260Sstevel@tonic-gate * VFS operations for High Sierra filesystem
270Sstevel@tonic-gate */
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/isa_defs.h>
310Sstevel@tonic-gate #include <sys/t_lock.h>
320Sstevel@tonic-gate #include <sys/param.h>
330Sstevel@tonic-gate #include <sys/systm.h>
340Sstevel@tonic-gate #include <sys/sysmacros.h>
350Sstevel@tonic-gate #include <sys/kmem.h>
360Sstevel@tonic-gate #include <sys/signal.h>
370Sstevel@tonic-gate #include <sys/user.h>
380Sstevel@tonic-gate #include <sys/proc.h>
390Sstevel@tonic-gate #include <sys/disp.h>
400Sstevel@tonic-gate #include <sys/buf.h>
410Sstevel@tonic-gate #include <sys/pathname.h>
420Sstevel@tonic-gate #include <sys/vfs.h>
433898Srsb #include <sys/vfs_opreg.h>
440Sstevel@tonic-gate #include <sys/vnode.h>
450Sstevel@tonic-gate #include <sys/file.h>
460Sstevel@tonic-gate #include <sys/uio.h>
470Sstevel@tonic-gate #include <sys/conf.h>
480Sstevel@tonic-gate #include <sys/policy.h>
490Sstevel@tonic-gate
500Sstevel@tonic-gate #include <vm/page.h>
510Sstevel@tonic-gate
520Sstevel@tonic-gate #include <sys/fs/snode.h>
530Sstevel@tonic-gate #include <sys/fs/hsfs_spec.h>
540Sstevel@tonic-gate #include <sys/fs/hsfs_isospec.h>
550Sstevel@tonic-gate #include <sys/fs/hsfs_node.h>
560Sstevel@tonic-gate #include <sys/fs/hsfs_impl.h>
570Sstevel@tonic-gate #include <sys/fs/hsfs_susp.h>
580Sstevel@tonic-gate #include <sys/fs/hsfs_rrip.h>
590Sstevel@tonic-gate
600Sstevel@tonic-gate #include <sys/statvfs.h>
610Sstevel@tonic-gate #include <sys/mount.h>
620Sstevel@tonic-gate #include <sys/mntent.h>
630Sstevel@tonic-gate #include <sys/swap.h>
640Sstevel@tonic-gate #include <sys/errno.h>
650Sstevel@tonic-gate #include <sys/debug.h>
660Sstevel@tonic-gate #include "fs/fs_subr.h"
670Sstevel@tonic-gate #include <sys/cmn_err.h>
680Sstevel@tonic-gate #include <sys/bootconf.h>
690Sstevel@tonic-gate
702900Sfrankho #include <sys/sdt.h>
712900Sfrankho
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"
932900Sfrankho #define HOPT_JOLIET "joliet"
942900Sfrankho #define HOPT_NOJOLIET "nojoliet"
952900Sfrankho #define HOPT_JOLIETLONG "jolietlong"
962900Sfrankho #define HOPT_VERS2 "vers2"
972900Sfrankho #define HOPT_NOVERS2 "novers2"
980Sstevel@tonic-gate #define HOPT_RO MNTOPT_RO
990Sstevel@tonic-gate
1000Sstevel@tonic-gate static char *global_cancel[] = { HOPT_NOGLOBAL, NULL };
1010Sstevel@tonic-gate static char *noglobal_cancel[] = { HOPT_GLOBAL, NULL };
1020Sstevel@tonic-gate static char *mapl_cancel[] = { HOPT_NOMAPLCASE, NULL };
1030Sstevel@tonic-gate static char *nomapl_cancel[] = { HOPT_MAPLCASE, NULL };
1040Sstevel@tonic-gate static char *ro_cancel[] = { MNTOPT_RW, NULL };
1050Sstevel@tonic-gate static char *rr_cancel[] = { HOPT_NRR, NULL };
1060Sstevel@tonic-gate static char *nrr_cancel[] = { HOPT_RR, NULL };
1072900Sfrankho static char *joliet_cancel[] = { HOPT_NOJOLIET, NULL };
1082900Sfrankho static char *nojoliet_cancel[] = { HOPT_JOLIET, NULL };
1092900Sfrankho static char *vers2_cancel[] = { HOPT_NOVERS2, NULL };
1102900Sfrankho static char *novers2_cancel[] = { HOPT_VERS2, NULL };
1110Sstevel@tonic-gate static char *trail_cancel[] = { HOPT_NOTRAILDOT, NULL };
1120Sstevel@tonic-gate static char *notrail_cancel[] = { HOPT_TRAILDOT, NULL };
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate static mntopt_t hsfs_options[] = {
1150Sstevel@tonic-gate { HOPT_GLOBAL, global_cancel, NULL, 0, NULL },
1160Sstevel@tonic-gate { HOPT_NOGLOBAL, noglobal_cancel, NULL, MO_DEFAULT, NULL },
1170Sstevel@tonic-gate { HOPT_MAPLCASE, mapl_cancel, NULL, MO_DEFAULT, NULL },
1180Sstevel@tonic-gate { HOPT_NOMAPLCASE, nomapl_cancel, NULL, 0, NULL },
1190Sstevel@tonic-gate { HOPT_RO, ro_cancel, NULL, MO_DEFAULT, NULL },
1200Sstevel@tonic-gate { HOPT_RR, rr_cancel, NULL, MO_DEFAULT, NULL },
1210Sstevel@tonic-gate { HOPT_NRR, nrr_cancel, NULL, 0, NULL },
1222900Sfrankho { HOPT_JOLIET, joliet_cancel, NULL, 0, NULL },
1232900Sfrankho { HOPT_NOJOLIET, nojoliet_cancel, NULL, 0, NULL },
1242900Sfrankho { HOPT_JOLIETLONG, NULL, NULL, 0, NULL },
1252900Sfrankho { HOPT_VERS2, vers2_cancel, NULL, 0, NULL },
1262900Sfrankho { HOPT_NOVERS2, novers2_cancel, NULL, 0, NULL },
1270Sstevel@tonic-gate { HOPT_TRAILDOT, trail_cancel, NULL, MO_DEFAULT, NULL },
1280Sstevel@tonic-gate { HOPT_NOTRAILDOT, notrail_cancel, NULL, 0, NULL },
1292900Sfrankho { "sector", NULL, "0", MO_HASVALUE, NULL},
1300Sstevel@tonic-gate };
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate static mntopts_t hsfs_proto_opttbl = {
1330Sstevel@tonic-gate sizeof (hsfs_options) / sizeof (mntopt_t),
1340Sstevel@tonic-gate hsfs_options
1350Sstevel@tonic-gate };
1360Sstevel@tonic-gate
1375312Smg147109 /*
1385312Smg147109 * Indicates whether to enable the I/O scheduling and readahead logic
1395312Smg147109 * 1 - Enable, 0 - Do not Enable.
1405312Smg147109 * Debugging purposes.
1415312Smg147109 */
1425312Smg147109 int do_schedio = 1;
1432900Sfrankho static int hsfsfstype;
1440Sstevel@tonic-gate static int hsfsinit(int, char *);
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate static vfsdef_t vfw = {
1470Sstevel@tonic-gate VFSDEF_VERSION,
1480Sstevel@tonic-gate "hsfs",
1490Sstevel@tonic-gate hsfsinit,
1506855Sjohnlev /* We don't suppport remounting */
151*12633Sjohn.levon@sun.com VSW_HASPROTO|VSW_STATS|VSW_CANLOFI|VSW_ZMOUNT,
1520Sstevel@tonic-gate &hsfs_proto_opttbl
1530Sstevel@tonic-gate };
1540Sstevel@tonic-gate
1550Sstevel@tonic-gate static struct modlfs modlfs = {
1560Sstevel@tonic-gate &mod_fsops, "filesystem for HSFS", &vfw
1570Sstevel@tonic-gate };
1580Sstevel@tonic-gate
1590Sstevel@tonic-gate static struct modlinkage modlinkage = {
1600Sstevel@tonic-gate MODREV_1, (void *)&modlfs, NULL
1610Sstevel@tonic-gate };
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate char _depends_on[] = "fs/specfs";
1640Sstevel@tonic-gate
1655312Smg147109 extern void hsched_init_caches(void);
1665312Smg147109 extern void hsched_fini_caches(void);
1675312Smg147109
1685312Smg147109
1690Sstevel@tonic-gate int
_init(void)1702900Sfrankho _init(void)
1710Sstevel@tonic-gate {
1720Sstevel@tonic-gate return (mod_install(&modlinkage));
1730Sstevel@tonic-gate }
1740Sstevel@tonic-gate
1750Sstevel@tonic-gate int
_fini(void)1762900Sfrankho _fini(void)
1770Sstevel@tonic-gate {
1782900Sfrankho int error;
1792900Sfrankho
1802900Sfrankho error = mod_remove(&modlinkage);
1812900Sfrankho
1822900Sfrankho DTRACE_PROBE1(mod_remove, int, error);
1832900Sfrankho
1842900Sfrankho if (error)
1852900Sfrankho return (error);
1862900Sfrankho
1872900Sfrankho mutex_destroy(&hs_mounttab_lock);
1882900Sfrankho
1892900Sfrankho /*
1902900Sfrankho * Tear down the operations vectors
1912900Sfrankho */
1922900Sfrankho (void) vfs_freevfsops_by_type(hsfsfstype);
1932900Sfrankho vn_freevnodeops(hsfs_vnodeops);
1942900Sfrankho
1952900Sfrankho hs_fini_hsnode_cache();
1965312Smg147109 hsched_fini_caches();
1972900Sfrankho return (0);
1980Sstevel@tonic-gate }
1990Sstevel@tonic-gate
2000Sstevel@tonic-gate int
_info(struct modinfo * modinfop)2010Sstevel@tonic-gate _info(struct modinfo *modinfop)
2020Sstevel@tonic-gate {
2030Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
2040Sstevel@tonic-gate }
2050Sstevel@tonic-gate
2060Sstevel@tonic-gate #define BDEVFLAG(dev) ((devopsp[getmajor(dev)])->devo_cb_ops->cb_flag)
2070Sstevel@tonic-gate
2080Sstevel@tonic-gate kmutex_t hs_mounttab_lock;
2090Sstevel@tonic-gate struct hsfs *hs_mounttab = NULL;
2100Sstevel@tonic-gate
2110Sstevel@tonic-gate /* default mode, uid, gid */
2120Sstevel@tonic-gate mode_t hsfs_default_mode = 0555;
2130Sstevel@tonic-gate uid_t hsfs_default_uid = 0;
2140Sstevel@tonic-gate gid_t hsfs_default_gid = 3;
2150Sstevel@tonic-gate
2165312Smg147109 extern void hsched_init(struct hsfs *fsp, int fsid,
2175312Smg147109 struct modlinkage *modlinkage);
2185312Smg147109 extern void hsched_fini(struct hsfs_queue *hqueue);
2195312Smg147109 extern void hsfs_init_kstats(struct hsfs *fsp, int fsid);
2205312Smg147109 extern void hsfs_fini_kstats(struct hsfs *fsp);
2215312Smg147109
2220Sstevel@tonic-gate static int hsfs_mount(struct vfs *vfsp, struct vnode *mvp,
2230Sstevel@tonic-gate struct mounta *uap, struct cred *cr);
2240Sstevel@tonic-gate static int hsfs_unmount(struct vfs *vfsp, int, struct cred *cr);
2250Sstevel@tonic-gate static int hsfs_root(struct vfs *vfsp, struct vnode **vpp);
2260Sstevel@tonic-gate static int hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp);
2270Sstevel@tonic-gate static int hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp);
2280Sstevel@tonic-gate static int hsfs_mountroot(struct vfs *, enum whymountroot);
2290Sstevel@tonic-gate
2300Sstevel@tonic-gate static int hs_mountfs(struct vfs *vfsp, dev_t dev, char *path,
2310Sstevel@tonic-gate mode_t mode, int flags, struct cred *cr, int isroot);
2322900Sfrankho static int hs_getrootvp(struct vfs *vfsp, struct hsfs *fsp, size_t pathsize);
2330Sstevel@tonic-gate static int hs_findhsvol(struct hsfs *fsp, struct vnode *vp,
2340Sstevel@tonic-gate struct hs_volume *hvp);
2350Sstevel@tonic-gate static int hs_parsehsvol(struct hsfs *fsp, uchar_t *volp,
2360Sstevel@tonic-gate struct hs_volume *hvp);
2370Sstevel@tonic-gate static int hs_findisovol(struct hsfs *fsp, struct vnode *vp,
2382900Sfrankho struct hs_volume *hvp,
2392900Sfrankho struct hs_volume *svp,
2402900Sfrankho struct hs_volume *jvp);
2412900Sfrankho static int hs_joliet_level(uchar_t *volp);
2420Sstevel@tonic-gate static int hs_parseisovol(struct hsfs *fsp, uchar_t *volp,
2430Sstevel@tonic-gate struct hs_volume *hvp);
2442900Sfrankho static void hs_copylabel(struct hs_volume *, unsigned char *, int);
2450Sstevel@tonic-gate static int hs_getmdev(struct vfs *, char *fspec, int flags, dev_t *pdev,
2460Sstevel@tonic-gate mode_t *mode, cred_t *cr);
2470Sstevel@tonic-gate static int hs_findvoldesc(dev_t rdev, int desc_sec);
2480Sstevel@tonic-gate
2490Sstevel@tonic-gate static int
hsfsinit(int fstype,char * name)2500Sstevel@tonic-gate hsfsinit(int fstype, char *name)
2510Sstevel@tonic-gate {
2520Sstevel@tonic-gate static const fs_operation_def_t hsfs_vfsops_template[] = {
2533898Srsb VFSNAME_MOUNT, { .vfs_mount = hsfs_mount },
2543898Srsb VFSNAME_UNMOUNT, { .vfs_unmount = hsfs_unmount },
2553898Srsb VFSNAME_ROOT, { .vfs_root = hsfs_root },
2563898Srsb VFSNAME_STATVFS, { .vfs_statvfs = hsfs_statvfs },
2573898Srsb VFSNAME_VGET, { .vfs_vget = hsfs_vget },
2583898Srsb VFSNAME_MOUNTROOT, { .vfs_mountroot = hsfs_mountroot },
2593898Srsb NULL, NULL
2600Sstevel@tonic-gate };
2610Sstevel@tonic-gate int error;
2620Sstevel@tonic-gate
2630Sstevel@tonic-gate error = vfs_setfsops(fstype, hsfs_vfsops_template, NULL);
2640Sstevel@tonic-gate if (error != 0) {
2650Sstevel@tonic-gate cmn_err(CE_WARN, "hsfsinit: bad vfs ops template");
2660Sstevel@tonic-gate return (error);
2670Sstevel@tonic-gate }
2680Sstevel@tonic-gate
2690Sstevel@tonic-gate error = vn_make_ops(name, hsfs_vnodeops_template, &hsfs_vnodeops);
2700Sstevel@tonic-gate if (error != 0) {
2710Sstevel@tonic-gate (void) vfs_freevfsops_by_type(fstype);
2720Sstevel@tonic-gate cmn_err(CE_WARN, "hsfsinit: bad vnode ops template");
2730Sstevel@tonic-gate return (error);
2740Sstevel@tonic-gate }
2750Sstevel@tonic-gate
2760Sstevel@tonic-gate hsfsfstype = fstype;
2770Sstevel@tonic-gate mutex_init(&hs_mounttab_lock, NULL, MUTEX_DEFAULT, NULL);
2780Sstevel@tonic-gate hs_init_hsnode_cache();
2795312Smg147109 hsched_init_caches();
2800Sstevel@tonic-gate return (0);
2810Sstevel@tonic-gate }
2820Sstevel@tonic-gate
2830Sstevel@tonic-gate /*ARGSUSED*/
2840Sstevel@tonic-gate static int
hsfs_mount(struct vfs * vfsp,struct vnode * mvp,struct mounta * uap,struct cred * cr)2850Sstevel@tonic-gate hsfs_mount(struct vfs *vfsp, struct vnode *mvp,
2860Sstevel@tonic-gate struct mounta *uap, struct cred *cr)
2870Sstevel@tonic-gate {
2880Sstevel@tonic-gate int vnode_busy;
2890Sstevel@tonic-gate dev_t dev;
2900Sstevel@tonic-gate struct pathname dpn;
2910Sstevel@tonic-gate int error;
2920Sstevel@tonic-gate mode_t mode;
2930Sstevel@tonic-gate int flags; /* this will hold the mount specific data */
2940Sstevel@tonic-gate
2950Sstevel@tonic-gate if ((error = secpolicy_fs_mount(cr, mvp, vfsp)) != 0)
2960Sstevel@tonic-gate return (error);
2970Sstevel@tonic-gate
2980Sstevel@tonic-gate if (mvp->v_type != VDIR)
2990Sstevel@tonic-gate return (ENOTDIR);
3000Sstevel@tonic-gate
3010Sstevel@tonic-gate /* mount option must be read only, else mount will be rejected */
3020Sstevel@tonic-gate if (!(uap->flags & MS_RDONLY))
3030Sstevel@tonic-gate return (EROFS);
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate /*
3060Sstevel@tonic-gate * We already told the framework that we don't support remounting.
3070Sstevel@tonic-gate */
3080Sstevel@tonic-gate ASSERT(!(uap->flags & MS_REMOUNT));
3090Sstevel@tonic-gate
3100Sstevel@tonic-gate mutex_enter(&mvp->v_lock);
3110Sstevel@tonic-gate vnode_busy = (mvp->v_count != 1) || (mvp->v_flag & VROOT);
3120Sstevel@tonic-gate mutex_exit(&mvp->v_lock);
3130Sstevel@tonic-gate
3140Sstevel@tonic-gate if ((uap->flags & MS_OVERLAY) == 0 && vnode_busy) {
3150Sstevel@tonic-gate return (EBUSY);
3160Sstevel@tonic-gate }
3170Sstevel@tonic-gate
3180Sstevel@tonic-gate /*
3190Sstevel@tonic-gate * Check for the options that actually affect things
3200Sstevel@tonic-gate * at our level.
3210Sstevel@tonic-gate */
3220Sstevel@tonic-gate flags = 0;
3230Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NOMAPLCASE, NULL))
3244866Sfrankho flags |= HSFSMNT_NOMAPLCASE;
3250Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NOTRAILDOT, NULL))
3264866Sfrankho flags |= HSFSMNT_NOTRAILDOT;
3270Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NRR, NULL))
3284866Sfrankho flags |= HSFSMNT_NORRIP;
3292900Sfrankho if (vfs_optionisset(vfsp, HOPT_NOJOLIET, NULL))
3304866Sfrankho flags |= HSFSMNT_NOJOLIET;
3312900Sfrankho if (vfs_optionisset(vfsp, HOPT_JOLIETLONG, NULL))
3324866Sfrankho flags |= HSFSMNT_JOLIETLONG;
3332900Sfrankho if (vfs_optionisset(vfsp, HOPT_NOVERS2, NULL))
3344866Sfrankho flags |= HSFSMNT_NOVERS2;
3350Sstevel@tonic-gate
3360Sstevel@tonic-gate error = pn_get(uap->dir, (uap->flags & MS_SYSSPACE) ?
3370Sstevel@tonic-gate UIO_SYSSPACE : UIO_USERSPACE, &dpn);
3380Sstevel@tonic-gate if (error)
3390Sstevel@tonic-gate return (error);
3400Sstevel@tonic-gate
3414866Sfrankho error = hs_getmdev(vfsp, uap->spec, uap->flags, &dev, &mode, cr);
3424866Sfrankho if (error != 0) {
3430Sstevel@tonic-gate pn_free(&dpn);
3440Sstevel@tonic-gate return (error);
3450Sstevel@tonic-gate }
3460Sstevel@tonic-gate
3470Sstevel@tonic-gate /*
3480Sstevel@tonic-gate * If the device is a tape, return error
3490Sstevel@tonic-gate */
3500Sstevel@tonic-gate if ((BDEVFLAG(dev) & D_TAPE) == D_TAPE) {
3510Sstevel@tonic-gate pn_free(&dpn);
3520Sstevel@tonic-gate return (ENOTBLK);
3530Sstevel@tonic-gate }
3540Sstevel@tonic-gate
3550Sstevel@tonic-gate /*
3560Sstevel@tonic-gate * Mount the filesystem.
3570Sstevel@tonic-gate */
3580Sstevel@tonic-gate error = hs_mountfs(vfsp, dev, dpn.pn_path, mode, flags, cr, 0);
3590Sstevel@tonic-gate pn_free(&dpn);
3600Sstevel@tonic-gate return (error);
3610Sstevel@tonic-gate }
3620Sstevel@tonic-gate
3630Sstevel@tonic-gate /*ARGSUSED*/
3640Sstevel@tonic-gate static int
hsfs_unmount(struct vfs * vfsp,int flag,struct cred * cr)3650Sstevel@tonic-gate hsfs_unmount(
3660Sstevel@tonic-gate struct vfs *vfsp,
3670Sstevel@tonic-gate int flag,
3680Sstevel@tonic-gate struct cred *cr)
3690Sstevel@tonic-gate {
3700Sstevel@tonic-gate struct hsfs **tspp;
3710Sstevel@tonic-gate struct hsfs *fsp;
3720Sstevel@tonic-gate
3730Sstevel@tonic-gate if (secpolicy_fs_unmount(cr, vfsp) != 0)
3740Sstevel@tonic-gate return (EPERM);
3750Sstevel@tonic-gate
3760Sstevel@tonic-gate /*
3770Sstevel@tonic-gate * forced unmount is not supported by this file system
3780Sstevel@tonic-gate * and thus, ENOTSUP is being returned.
3790Sstevel@tonic-gate */
3800Sstevel@tonic-gate if (flag & MS_FORCE)
3810Sstevel@tonic-gate return (ENOTSUP);
3820Sstevel@tonic-gate
3830Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp);
3840Sstevel@tonic-gate
3850Sstevel@tonic-gate if (fsp->hsfs_rootvp->v_count != 1)
3860Sstevel@tonic-gate return (EBUSY);
3870Sstevel@tonic-gate
3880Sstevel@tonic-gate /* destroy all old pages and hsnodes for this vfs */
3890Sstevel@tonic-gate if (hs_synchash(vfsp))
3900Sstevel@tonic-gate return (EBUSY);
3910Sstevel@tonic-gate
3920Sstevel@tonic-gate mutex_enter(&hs_mounttab_lock);
3930Sstevel@tonic-gate for (tspp = &hs_mounttab; *tspp != NULL; tspp = &(*tspp)->hsfs_next) {
3940Sstevel@tonic-gate if (*tspp == fsp)
3950Sstevel@tonic-gate break;
3960Sstevel@tonic-gate }
3970Sstevel@tonic-gate if (*tspp == NULL) {
3980Sstevel@tonic-gate mutex_exit(&hs_mounttab_lock);
3990Sstevel@tonic-gate panic("hsfs_unmount: vfs not mounted?");
4000Sstevel@tonic-gate /*NOTREACHED*/
4010Sstevel@tonic-gate }
4020Sstevel@tonic-gate
4030Sstevel@tonic-gate *tspp = fsp->hsfs_next;
4040Sstevel@tonic-gate
4050Sstevel@tonic-gate mutex_exit(&hs_mounttab_lock);
4060Sstevel@tonic-gate
4075312Smg147109 hsfs_fini_kstats(fsp);
4085331Samw (void) VOP_CLOSE(fsp->hsfs_devvp, FREAD, 1, (offset_t)0, cr, NULL);
4090Sstevel@tonic-gate VN_RELE(fsp->hsfs_devvp);
4100Sstevel@tonic-gate /* free path table space */
4110Sstevel@tonic-gate if (fsp->hsfs_ptbl != NULL)
4124866Sfrankho kmem_free(fsp->hsfs_ptbl, (size_t)fsp->hsfs_vol.ptbl_len);
4130Sstevel@tonic-gate /* free path table index table */
4140Sstevel@tonic-gate if (fsp->hsfs_ptbl_idx != NULL)
4150Sstevel@tonic-gate kmem_free(fsp->hsfs_ptbl_idx, (size_t)
4164866Sfrankho (fsp->hsfs_ptbl_idx_size * sizeof (struct ptable_idx)));
4170Sstevel@tonic-gate
4180Sstevel@tonic-gate /* free "mounted on" pathame */
4190Sstevel@tonic-gate if (fsp->hsfs_fsmnt != NULL)
4200Sstevel@tonic-gate kmem_free(fsp->hsfs_fsmnt, strlen(fsp->hsfs_fsmnt) + 1);
4210Sstevel@tonic-gate
4225312Smg147109 hsched_fini(fsp->hqueue);
4235312Smg147109 kmem_free(fsp->hqueue, sizeof (struct hsfs_queue));
4245312Smg147109
4250Sstevel@tonic-gate mutex_destroy(&fsp->hsfs_free_lock);
4260Sstevel@tonic-gate rw_destroy(&fsp->hsfs_hash_lock);
4270Sstevel@tonic-gate
4280Sstevel@tonic-gate kmem_free(fsp, sizeof (*fsp));
4290Sstevel@tonic-gate return (0);
4300Sstevel@tonic-gate }
4310Sstevel@tonic-gate
4320Sstevel@tonic-gate /*ARGSUSED*/
4330Sstevel@tonic-gate static int
hsfs_root(struct vfs * vfsp,struct vnode ** vpp)4340Sstevel@tonic-gate hsfs_root(struct vfs *vfsp, struct vnode **vpp)
4350Sstevel@tonic-gate {
4360Sstevel@tonic-gate *vpp = (VFS_TO_HSFS(vfsp))->hsfs_rootvp;
4370Sstevel@tonic-gate VN_HOLD(*vpp);
4380Sstevel@tonic-gate return (0);
4390Sstevel@tonic-gate }
4400Sstevel@tonic-gate
4410Sstevel@tonic-gate /*ARGSUSED*/
4420Sstevel@tonic-gate static int
hsfs_statvfs(struct vfs * vfsp,struct statvfs64 * sbp)4430Sstevel@tonic-gate hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp)
4440Sstevel@tonic-gate {
4450Sstevel@tonic-gate struct hsfs *fsp;
4460Sstevel@tonic-gate dev32_t d32;
4470Sstevel@tonic-gate
4480Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp);
4490Sstevel@tonic-gate if (fsp->hsfs_magic != HSFS_MAGIC)
4500Sstevel@tonic-gate return (EINVAL);
4510Sstevel@tonic-gate bzero(sbp, sizeof (*sbp));
4520Sstevel@tonic-gate sbp->f_bsize = vfsp->vfs_bsize;
4530Sstevel@tonic-gate sbp->f_frsize = sbp->f_bsize; /* no fragment, same as block size */
4540Sstevel@tonic-gate sbp->f_blocks = (fsblkcnt64_t)fsp->hsfs_vol.vol_size;
4550Sstevel@tonic-gate
4560Sstevel@tonic-gate sbp->f_bfree = (fsblkcnt64_t)0;
4570Sstevel@tonic-gate sbp->f_bavail = (fsblkcnt64_t)0;
4580Sstevel@tonic-gate sbp->f_files = (fsfilcnt64_t)-1;
4590Sstevel@tonic-gate sbp->f_ffree = (fsfilcnt64_t)0;
4600Sstevel@tonic-gate sbp->f_favail = (fsfilcnt64_t)0;
4610Sstevel@tonic-gate (void) cmpldev(&d32, vfsp->vfs_dev);
4620Sstevel@tonic-gate sbp->f_fsid = d32;
4630Sstevel@tonic-gate (void) strcpy(sbp->f_basetype, vfssw[vfsp->vfs_fstype].vsw_name);
4640Sstevel@tonic-gate sbp->f_flag = vf_to_stf(vfsp->vfs_flag);
4650Sstevel@tonic-gate sbp->f_namemax = fsp->hsfs_namemax;
4660Sstevel@tonic-gate (void) strcpy(sbp->f_fstr, fsp->hsfs_vol.vol_id);
4670Sstevel@tonic-gate
4680Sstevel@tonic-gate return (0);
4690Sstevel@tonic-gate }
4700Sstevel@tonic-gate
4710Sstevel@tonic-gate /*
4720Sstevel@tonic-gate * Previously nodeid was declared as uint32_t. This has been changed
4730Sstevel@tonic-gate * to conform better with the ISO9660 standard. The standard states that
4740Sstevel@tonic-gate * a LBN can be a 32 bit number, as the MAKE_NODEID macro shifts this
4750Sstevel@tonic-gate * LBN 11 places left (LBN_TO_BYTE) and then shifts the result 5 right
4760Sstevel@tonic-gate * (divide by 32) we are left with the potential of an overflow if
4770Sstevel@tonic-gate * confined to a 32 bit value.
4780Sstevel@tonic-gate */
4790Sstevel@tonic-gate
4800Sstevel@tonic-gate static int
hsfs_vget(struct vfs * vfsp,struct vnode ** vpp,struct fid * fidp)4810Sstevel@tonic-gate hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp)
4820Sstevel@tonic-gate {
4830Sstevel@tonic-gate struct hsfid *fid;
4840Sstevel@tonic-gate struct hsfs *fsp;
4850Sstevel@tonic-gate ino64_t nodeid;
4860Sstevel@tonic-gate int error;
4870Sstevel@tonic-gate
4880Sstevel@tonic-gate fsp = (struct hsfs *)VFS_TO_HSFS(vfsp);
4890Sstevel@tonic-gate fid = (struct hsfid *)fidp;
4900Sstevel@tonic-gate
4910Sstevel@tonic-gate /*
4920Sstevel@tonic-gate * Look for vnode on hashlist.
4930Sstevel@tonic-gate * If found, it's now active and the refcnt was incremented.
4940Sstevel@tonic-gate */
4950Sstevel@tonic-gate
4960Sstevel@tonic-gate rw_enter(&fsp->hsfs_hash_lock, RW_READER);
4970Sstevel@tonic-gate
4984866Sfrankho nodeid = fid->hf_ino;
4990Sstevel@tonic-gate
5004866Sfrankho if ((*vpp = hs_findhash(nodeid, fid->hf_dir_lbn,
5014866Sfrankho (uint_t)fid->hf_dir_off, vfsp)) == NULL) {
5020Sstevel@tonic-gate /*
5030Sstevel@tonic-gate * Not in cache, so we need to remake it.
5040Sstevel@tonic-gate * hs_remakenode() will read the directory entry
5050Sstevel@tonic-gate * and then check again to see if anyone else has
5060Sstevel@tonic-gate * put it in the cache.
5070Sstevel@tonic-gate */
5080Sstevel@tonic-gate rw_exit(&fsp->hsfs_hash_lock);
5090Sstevel@tonic-gate error = hs_remakenode(fid->hf_dir_lbn, (uint_t)fid->hf_dir_off,
5100Sstevel@tonic-gate vfsp, vpp);
5110Sstevel@tonic-gate return (error);
5120Sstevel@tonic-gate }
5130Sstevel@tonic-gate rw_exit(&fsp->hsfs_hash_lock);
5140Sstevel@tonic-gate return (0);
5150Sstevel@tonic-gate }
5160Sstevel@tonic-gate
5170Sstevel@tonic-gate
5180Sstevel@tonic-gate #define CHECKSUM_SIZE (64 * 1024)
5190Sstevel@tonic-gate
5200Sstevel@tonic-gate /*
5210Sstevel@tonic-gate * Compute a CD-ROM fsid by checksumming the first 64K of data on the CD
5220Sstevel@tonic-gate * We use the 'fsp' argument to determine the location of the root
5230Sstevel@tonic-gate * directory entry, and we start reading from there.
5240Sstevel@tonic-gate */
5250Sstevel@tonic-gate static int
compute_cdrom_id(struct hsfs * fsp,vnode_t * devvp)5260Sstevel@tonic-gate compute_cdrom_id(struct hsfs *fsp, vnode_t *devvp)
5270Sstevel@tonic-gate {
5280Sstevel@tonic-gate uint_t secno;
5290Sstevel@tonic-gate struct hs_volume *hsvp = &fsp->hsfs_vol;
5300Sstevel@tonic-gate struct buf *bp;
5310Sstevel@tonic-gate int error;
5320Sstevel@tonic-gate int fsid;
5330Sstevel@tonic-gate
5340Sstevel@tonic-gate secno = hsvp->root_dir.ext_lbn >> hsvp->lbn_secshift;
535494Sfrankho bp = bread(devvp->v_rdev, secno * 4, CHECKSUM_SIZE);
5360Sstevel@tonic-gate error = geterror(bp);
537494Sfrankho
538494Sfrankho /*
539494Sfrankho * An error on read or a partial read means we asked
540494Sfrankho * for a nonexistant/corrupted piece of the device
541494Sfrankho * (including past-the-end of the media). Don't
542494Sfrankho * try to use the checksumming method then.
543494Sfrankho */
544494Sfrankho if (!error && bp->b_bcount == CHECKSUM_SIZE) {
5450Sstevel@tonic-gate int *ibuf = (int *)bp->b_un.b_addr;
5460Sstevel@tonic-gate int i;
5470Sstevel@tonic-gate
5480Sstevel@tonic-gate fsid = 0;
5490Sstevel@tonic-gate
550494Sfrankho for (i = 0; i < CHECKSUM_SIZE / sizeof (int); i++)
5510Sstevel@tonic-gate fsid ^= ibuf[ i ];
552494Sfrankho } else {
553494Sfrankho /*
554494Sfrankho * Fallback - use creation date
555494Sfrankho */
5560Sstevel@tonic-gate fsid = hsvp->cre_date.tv_sec;
557494Sfrankho }
5580Sstevel@tonic-gate
5590Sstevel@tonic-gate brelse(bp);
5600Sstevel@tonic-gate
5610Sstevel@tonic-gate return (fsid);
5620Sstevel@tonic-gate }
5630Sstevel@tonic-gate
5640Sstevel@tonic-gate
5650Sstevel@tonic-gate /*ARGSUSED*/
5660Sstevel@tonic-gate static int
hs_mountfs(struct vfs * vfsp,dev_t dev,char * path,mode_t mode,int mount_flags,struct cred * cr,int isroot)5670Sstevel@tonic-gate hs_mountfs(
5680Sstevel@tonic-gate struct vfs *vfsp,
5690Sstevel@tonic-gate dev_t dev,
5700Sstevel@tonic-gate char *path,
5710Sstevel@tonic-gate mode_t mode,
5720Sstevel@tonic-gate int mount_flags,
5730Sstevel@tonic-gate struct cred *cr,
5740Sstevel@tonic-gate int isroot)
5750Sstevel@tonic-gate {
5760Sstevel@tonic-gate struct vnode *devvp;
5770Sstevel@tonic-gate struct hsfs *tsp;
5780Sstevel@tonic-gate struct hsfs *fsp = NULL;
5790Sstevel@tonic-gate struct vattr vap;
5800Sstevel@tonic-gate struct hsnode *hp;
5810Sstevel@tonic-gate int error;
5820Sstevel@tonic-gate struct timeval tv;
5830Sstevel@tonic-gate int fsid;
5842900Sfrankho int use_rrip;
5852900Sfrankho int use_vers2;
5862900Sfrankho int use_joliet;
5872900Sfrankho int has_rrip = 0;
5882900Sfrankho int has_vers2 = 0;
5892900Sfrankho int has_joliet = 0;
5902900Sfrankho int force_rrip_off;
5912900Sfrankho int force_vers2_off;
5922900Sfrankho int force_joliet_off;
5932900Sfrankho size_t pathbufsz = strlen(path) + 1;
5942900Sfrankho int redo_rootvp;
5952900Sfrankho
5966894Sdanmcd struct hs_volume *svp = NULL; /* Supplemental VD for ISO-9660:1999 */
5976894Sdanmcd struct hs_volume *jvp = NULL; /* Joliet VD */
5982900Sfrankho
5992900Sfrankho /*
6002900Sfrankho * The rules for which extension will be used are:
6012900Sfrankho * 1. No specific mount options given:
6022900Sfrankho * - use rrip if available
6032900Sfrankho * - use ISO9660:1999 if available
6042900Sfrankho * - use joliet if available.
6052900Sfrankho * 2. rrip/ISO9660:1999/joliet explicitly disabled via mount option:
6062900Sfrankho * - use next "lower" extension
6072900Sfrankho * 3. joliet/ISO9660:1999/rrip explicitly requested via mount option:
6082900Sfrankho * - disable rrip support even if available
6092900Sfrankho * - disable IOS9660:1999 support even if available
6102900Sfrankho *
6112900Sfrankho * We need to adjust these flags as we discover the extensions
6122900Sfrankho * present. See below. These are just the starting values.
6132900Sfrankho */
6142900Sfrankho use_rrip = (mount_flags & HSFSMNT_NORRIP) == 0;
6152900Sfrankho use_vers2 = (mount_flags & HSFSMNT_NOVERS2) == 0;
6162900Sfrankho use_joliet = (mount_flags & HSFSMNT_NOJOLIET) == 0;
6170Sstevel@tonic-gate
6180Sstevel@tonic-gate /*
6190Sstevel@tonic-gate * Open the device
6200Sstevel@tonic-gate */
6210Sstevel@tonic-gate devvp = makespecvp(dev, VBLK);
6220Sstevel@tonic-gate ASSERT(devvp != 0);
6230Sstevel@tonic-gate
6240Sstevel@tonic-gate /*
6250Sstevel@tonic-gate * Open the target device (file) for read only.
6260Sstevel@tonic-gate */
6275331Samw if (error = VOP_OPEN(&devvp, FREAD, cr, NULL)) {
6280Sstevel@tonic-gate VN_RELE(devvp);
6290Sstevel@tonic-gate return (error);
6300Sstevel@tonic-gate }
6310Sstevel@tonic-gate
6320Sstevel@tonic-gate /*
6330Sstevel@tonic-gate * Refuse to go any further if this
6340Sstevel@tonic-gate * device is being used for swapping
6350Sstevel@tonic-gate */
6360Sstevel@tonic-gate if (IS_SWAPVP(common_specvp(devvp))) {
6370Sstevel@tonic-gate error = EBUSY;
6380Sstevel@tonic-gate goto cleanup;
6390Sstevel@tonic-gate }
6400Sstevel@tonic-gate
6410Sstevel@tonic-gate vap.va_mask = AT_SIZE;
6425331Samw if ((error = VOP_GETATTR(devvp, &vap, ATTR_COMM, cr, NULL)) != 0) {
6430Sstevel@tonic-gate cmn_err(CE_NOTE, "Cannot get attributes of the CD-ROM driver");
6440Sstevel@tonic-gate goto cleanup;
6450Sstevel@tonic-gate }
6460Sstevel@tonic-gate
6470Sstevel@tonic-gate /*
6480Sstevel@tonic-gate * Make sure we have a nonzero size partition.
6490Sstevel@tonic-gate * The current version of the SD driver will *not* fail the open
6500Sstevel@tonic-gate * of such a partition so we have to check for it here.
6510Sstevel@tonic-gate */
6520Sstevel@tonic-gate if (vap.va_size == 0) {
6530Sstevel@tonic-gate error = ENXIO;
6540Sstevel@tonic-gate goto cleanup;
6550Sstevel@tonic-gate }
6560Sstevel@tonic-gate
6570Sstevel@tonic-gate /*
6580Sstevel@tonic-gate * Init a new hsfs structure.
6590Sstevel@tonic-gate */
6600Sstevel@tonic-gate fsp = kmem_zalloc(sizeof (*fsp), KM_SLEEP);
6612900Sfrankho svp = kmem_zalloc(sizeof (*svp), KM_SLEEP);
6622900Sfrankho jvp = kmem_zalloc(sizeof (*jvp), KM_SLEEP);
6630Sstevel@tonic-gate
6640Sstevel@tonic-gate /* hardwire perms, uid, gid */
6650Sstevel@tonic-gate fsp->hsfs_vol.vol_uid = hsfs_default_uid;
6660Sstevel@tonic-gate fsp->hsfs_vol.vol_gid = hsfs_default_gid;
6670Sstevel@tonic-gate fsp->hsfs_vol.vol_prot = hsfs_default_mode;
6682900Sfrankho svp->vol_uid = hsfs_default_uid;
6692900Sfrankho svp->vol_gid = hsfs_default_gid;
6702900Sfrankho svp->vol_prot = hsfs_default_mode;
6712900Sfrankho jvp->vol_uid = hsfs_default_uid;
6722900Sfrankho jvp->vol_gid = hsfs_default_gid;
6732900Sfrankho jvp->vol_prot = hsfs_default_mode;
6740Sstevel@tonic-gate
6750Sstevel@tonic-gate /*
6760Sstevel@tonic-gate * Look for a Standard File Structure Volume Descriptor,
6770Sstevel@tonic-gate * of which there must be at least one.
6780Sstevel@tonic-gate * If found, check for volume size consistency.
6792900Sfrankho *
6802900Sfrankho * If svp->lbn_size is != 0, we did find a ISO-9660:1999 SVD
6812900Sfrankho * If jvp->lbn_size is != 0, we did find a Joliet SVD.
6820Sstevel@tonic-gate */
6832900Sfrankho fsp->hsfs_namemax = ISO_FILE_NAMELEN;
6842900Sfrankho fsp->hsfs_namelen = ISO_FILE_NAMELEN;
6852900Sfrankho error = hs_findisovol(fsp, devvp, &fsp->hsfs_vol, svp, jvp);
6861025Sfrankho if (error == EINVAL) /* no iso 9660 - try high sierra ... */
6871025Sfrankho error = hs_findhsvol(fsp, devvp, &fsp->hsfs_vol);
6880Sstevel@tonic-gate
6890Sstevel@tonic-gate if (error)
6900Sstevel@tonic-gate goto cleanup;
6910Sstevel@tonic-gate
6922900Sfrankho DTRACE_PROBE4(findvol,
6932900Sfrankho struct hsfs *, fsp,
6942900Sfrankho struct hs_volume *, &fsp->hsfs_vol,
6952900Sfrankho struct hs_volume *, svp,
6962900Sfrankho struct hs_volume *, jvp);
6972900Sfrankho
6980Sstevel@tonic-gate /*
6990Sstevel@tonic-gate * Generate a file system ID from the CD-ROM,
7000Sstevel@tonic-gate * and check it for uniqueness.
7010Sstevel@tonic-gate *
7020Sstevel@tonic-gate * What we are aiming for is some chance of integrity
7030Sstevel@tonic-gate * across disk change. That is, if a client has an fhandle,
7040Sstevel@tonic-gate * it will be valid as long as the same disk is mounted.
7050Sstevel@tonic-gate */
7060Sstevel@tonic-gate fsid = compute_cdrom_id(fsp, devvp);
7070Sstevel@tonic-gate
7080Sstevel@tonic-gate mutex_enter(&hs_mounttab_lock);
7090Sstevel@tonic-gate
7100Sstevel@tonic-gate if (fsid == 0 || fsid == -1) {
7110Sstevel@tonic-gate uniqtime(&tv);
7120Sstevel@tonic-gate fsid = tv.tv_sec;
7130Sstevel@tonic-gate } else /* make sure that the fsid is unique */
7140Sstevel@tonic-gate for (tsp = hs_mounttab; tsp != NULL; tsp = tsp->hsfs_next) {
7150Sstevel@tonic-gate if (fsid == tsp->hsfs_vfs->vfs_fsid.val[0]) {
7160Sstevel@tonic-gate uniqtime(&tv);
7170Sstevel@tonic-gate fsid = tv.tv_sec;
7180Sstevel@tonic-gate break;
7190Sstevel@tonic-gate }
7200Sstevel@tonic-gate }
7210Sstevel@tonic-gate
7220Sstevel@tonic-gate fsp->hsfs_next = hs_mounttab;
7230Sstevel@tonic-gate hs_mounttab = fsp;
7240Sstevel@tonic-gate
7250Sstevel@tonic-gate fsp->hsfs_devvp = devvp;
7260Sstevel@tonic-gate fsp->hsfs_vfs = vfsp;
7272900Sfrankho fsp->hsfs_fsmnt = kmem_alloc(pathbufsz, KM_SLEEP);
7282900Sfrankho (void) strlcpy(fsp->hsfs_fsmnt, path, pathbufsz);
7290Sstevel@tonic-gate
7300Sstevel@tonic-gate mutex_init(&fsp->hsfs_free_lock, NULL, MUTEX_DEFAULT, NULL);
7310Sstevel@tonic-gate rw_init(&fsp->hsfs_hash_lock, NULL, RW_DEFAULT, NULL);
7320Sstevel@tonic-gate
7330Sstevel@tonic-gate vfsp->vfs_data = (caddr_t)fsp;
7340Sstevel@tonic-gate vfsp->vfs_dev = dev;
7350Sstevel@tonic-gate vfsp->vfs_fstype = hsfsfstype;
7360Sstevel@tonic-gate vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size; /* %% */
7370Sstevel@tonic-gate vfsp->vfs_fsid.val[0] = fsid;
7380Sstevel@tonic-gate vfsp->vfs_fsid.val[1] = hsfsfstype;
7390Sstevel@tonic-gate
7402900Sfrankho if (!hs_getrootvp(vfsp, fsp, pathbufsz)) {
7412900Sfrankho DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp);
7422900Sfrankho error = EINVAL;
7432900Sfrankho goto cleanup;
7442900Sfrankho }
7452900Sfrankho DTRACE_PROBE1(rootvp, struct hsfs *, fsp);
7462900Sfrankho
7472900Sfrankho /*
7482900Sfrankho * Attempt to discover a RR extension.
7492900Sfrankho */
7502900Sfrankho if (use_rrip) {
7512900Sfrankho hp = VTOH(fsp->hsfs_rootvp);
7522900Sfrankho hs_check_root_dirent(fsp->hsfs_rootvp, &(hp->hs_dirent));
7532900Sfrankho }
7542900Sfrankho
7552900Sfrankho has_rrip = IS_RRIP_IMPLEMENTED(fsp);
7562900Sfrankho has_vers2 = (svp->lbn_size != 0);
7572900Sfrankho has_joliet = (jvp->lbn_size != 0);
7582900Sfrankho
7592900Sfrankho DTRACE_PROBE4(voltype__suggested, struct hsfs *, fsp,
7602900Sfrankho int, use_rrip, int, use_vers2, int, use_joliet);
7612900Sfrankho
7622900Sfrankho DTRACE_PROBE4(voltype__actual, struct hsfs *, fsp,
7632900Sfrankho int, has_rrip, int, has_vers2, int, has_joliet);
7642900Sfrankho
7652900Sfrankho DTRACE_PROBE4(findvol,
7662900Sfrankho struct hsfs *, fsp,
7672900Sfrankho struct hs_volume *, &fsp->hsfs_vol,
7682900Sfrankho struct hs_volume *, svp,
7692900Sfrankho struct hs_volume *, jvp);
7702900Sfrankho
7712900Sfrankho force_rrip_off = !use_rrip ||
7722900Sfrankho (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet) ||
7732900Sfrankho (vfs_optionisset(vfsp, HOPT_VERS2, NULL) && has_vers2);
7742900Sfrankho
7752900Sfrankho force_vers2_off = !use_vers2 ||
7762900Sfrankho (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet);
7772900Sfrankho
7782900Sfrankho force_joliet_off = !use_joliet;
7792900Sfrankho
7802900Sfrankho DTRACE_PROBE4(voltype__force_off, struct hsfs *, fsp,
7812900Sfrankho int, force_rrip_off, int, force_vers2_off, int, force_joliet_off);
7822900Sfrankho
7832900Sfrankho /*
7842900Sfrankho * At the moment, we have references of all three possible
7852900Sfrankho * extensions (RR, ISO9660:1999/v2 and Joliet) if present.
7862900Sfrankho *
7872900Sfrankho * The "active" volume descriptor is RRIP (or ISO9660:1988).
7882900Sfrankho * We now switch to the user-requested one.
7892900Sfrankho */
7902900Sfrankho redo_rootvp = 0;
7912900Sfrankho
7922900Sfrankho if (force_rrip_off || !has_rrip) {
7932900Sfrankho if (has_vers2 && !force_vers2_off) {
7942900Sfrankho VN_RELE(fsp->hsfs_rootvp);
7952900Sfrankho bcopy(svp, &fsp->hsfs_vol, sizeof (struct hs_volume));
7962900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_ISO_V2;
7972900Sfrankho vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size;
7982900Sfrankho redo_rootvp = 1;
7992900Sfrankho has_joliet = 0;
8002900Sfrankho } else if (has_joliet && !force_joliet_off) {
8012900Sfrankho VN_RELE(fsp->hsfs_rootvp);
8022900Sfrankho bcopy(jvp, &fsp->hsfs_vol, sizeof (struct hs_volume));
8032900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_JOLIET;
8042900Sfrankho vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size;
8052900Sfrankho redo_rootvp = 1;
8062900Sfrankho has_vers2 = 0;
8072900Sfrankho }
8082900Sfrankho }
8092900Sfrankho
8102900Sfrankho if (redo_rootvp) {
8112900Sfrankho /*
8122900Sfrankho * Make sure not to use Rock Ridge.
8132900Sfrankho */
8142900Sfrankho UNSET_IMPL_BIT(fsp, RRIP_BIT);
8152900Sfrankho UNSET_SUSP_BIT(fsp);
8162900Sfrankho has_rrip = 0;
8172900Sfrankho
8182900Sfrankho if (!hs_getrootvp(vfsp, fsp, pathbufsz)) {
8192900Sfrankho DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp);
8202900Sfrankho error = EINVAL;
8212900Sfrankho goto cleanup;
8222900Sfrankho }
8232900Sfrankho DTRACE_PROBE1(rootvp, struct hsfs *, fsp);
8242900Sfrankho }
8252900Sfrankho if (IS_RRIP_IMPLEMENTED(fsp)) {
8262900Sfrankho has_vers2 = 0;
8272900Sfrankho has_joliet = 0;
8282900Sfrankho }
8292900Sfrankho if (force_vers2_off)
8302900Sfrankho has_vers2 = 0;
8312900Sfrankho if (force_joliet_off)
8322900Sfrankho has_joliet = 0;
8332900Sfrankho DTRACE_PROBE4(voltype__taken, struct hsfs *, fsp,
8342900Sfrankho int, has_rrip, int, has_vers2, int, has_joliet);
8352900Sfrankho
8362900Sfrankho /*
8372900Sfrankho * mark root node as VROOT
8382900Sfrankho */
8392900Sfrankho fsp->hsfs_rootvp->v_flag |= VROOT;
8402900Sfrankho
8412900Sfrankho /* Here we take care of some special case stuff for mountroot */
8422900Sfrankho if (isroot) {
8432900Sfrankho fsp->hsfs_rootvp->v_rdev = devvp->v_rdev;
8442900Sfrankho rootvp = fsp->hsfs_rootvp;
8452900Sfrankho }
8462900Sfrankho
8472900Sfrankho if (IS_RRIP_IMPLEMENTED(fsp)) {
8482900Sfrankho /*
8492900Sfrankho * if RRIP, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags
8502900Sfrankho */
8512900Sfrankho mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT);
8522900Sfrankho
8532900Sfrankho fsp->hsfs_namemax = RRIP_FILE_NAMELEN;
8542900Sfrankho fsp->hsfs_namelen = RRIP_FILE_NAMELEN;
8552900Sfrankho
8562900Sfrankho ASSERT(vfs_optionisset(vfsp, HOPT_RR, NULL));
8572900Sfrankho vfs_clearmntopt(vfsp, HOPT_VERS2);
8582900Sfrankho vfs_clearmntopt(vfsp, HOPT_JOLIET);
8592900Sfrankho
8602900Sfrankho } else switch (fsp->hsfs_vol_type) {
8612900Sfrankho
8622900Sfrankho case HS_VOL_TYPE_HS:
8632900Sfrankho case HS_VOL_TYPE_ISO:
8642900Sfrankho default:
8652900Sfrankho /*
8662900Sfrankho * if iso v1, don't allow trailing spaces in iso file names
8672900Sfrankho */
8682900Sfrankho mount_flags |= HSFSMNT_NOTRAILSPACE;
8692900Sfrankho fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX;
8702900Sfrankho fsp->hsfs_namelen = ISO_FILE_NAMELEN;
8712900Sfrankho vfs_clearmntopt(vfsp, HOPT_RR);
8722900Sfrankho vfs_clearmntopt(vfsp, HOPT_VERS2);
8732900Sfrankho vfs_clearmntopt(vfsp, HOPT_JOLIET);
8742900Sfrankho break;
8752900Sfrankho
8762900Sfrankho case HS_VOL_TYPE_ISO_V2:
8772900Sfrankho /*
8782900Sfrankho * if iso v2, don't copy NOTRAILDOT to hsfs_flags
8792900Sfrankho */
8802900Sfrankho mount_flags &= ~HSFSMNT_NOTRAILDOT;
8812900Sfrankho mount_flags |= HSFSMNT_NOMAPLCASE | HSFSMNT_NOVERSION;
8822900Sfrankho fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX;
8832900Sfrankho fsp->hsfs_namelen = ISO_NAMELEN_V2;
8842900Sfrankho vfs_setmntopt(vfsp, HOPT_VERS2, NULL, 0);
8852900Sfrankho vfs_clearmntopt(vfsp, HOPT_RR);
8862900Sfrankho vfs_clearmntopt(vfsp, HOPT_JOLIET);
8872900Sfrankho break;
8882900Sfrankho
8892900Sfrankho case HS_VOL_TYPE_JOLIET:
8902900Sfrankho /*
8912900Sfrankho * if Joliet, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags
8922900Sfrankho */
8932900Sfrankho mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT);
8942900Sfrankho mount_flags |= HSFSMNT_NOMAPLCASE;
8952900Sfrankho if (mount_flags & HSFSMNT_JOLIETLONG)
8962900Sfrankho fsp->hsfs_namemax = JOLIET_NAMELEN_MAX*3; /* UTF-8 */
8972900Sfrankho else
8982900Sfrankho fsp->hsfs_namemax = MAXNAMELEN-1;
8992900Sfrankho fsp->hsfs_namelen = JOLIET_NAMELEN*2;
9002900Sfrankho vfs_setmntopt(vfsp, HOPT_JOLIET, NULL, 0);
9012900Sfrankho vfs_clearmntopt(vfsp, HOPT_RR);
9022900Sfrankho vfs_clearmntopt(vfsp, HOPT_VERS2);
9032900Sfrankho break;
9042900Sfrankho }
9052900Sfrankho
9064866Sfrankho /*
9074866Sfrankho * Add the HSFSMNT_INODE pseudo mount flag to the current mount flags.
9084866Sfrankho */
9094866Sfrankho fsp->hsfs_flags = mount_flags | (fsp->hsfs_flags & HSFSMNT_INODE);
9102900Sfrankho
9115312Smg147109 /*
9125312Smg147109 * Setup I/O Scheduling structures
9135312Smg147109 */
9145312Smg147109 if (do_schedio) {
9155312Smg147109 fsp->hqueue = kmem_alloc(sizeof (struct hsfs_queue), KM_SLEEP);
9165312Smg147109 hsched_init(fsp, fsid, &modlinkage);
9175312Smg147109 }
9185312Smg147109
9195312Smg147109 /*
9205312Smg147109 * Setup kstats
9215312Smg147109 */
9225312Smg147109 hsfs_init_kstats(fsp, fsid);
9235312Smg147109
9242900Sfrankho DTRACE_PROBE1(mount__done, struct hsfs *, fsp);
9252900Sfrankho
9262900Sfrankho /*
9272900Sfrankho * set the magic word
9282900Sfrankho */
9292900Sfrankho fsp->hsfs_magic = HSFS_MAGIC;
9302900Sfrankho mutex_exit(&hs_mounttab_lock);
9312900Sfrankho
9324866Sfrankho kmem_free(svp, sizeof (*svp));
9334866Sfrankho kmem_free(jvp, sizeof (*jvp));
9344866Sfrankho
9352900Sfrankho return (0);
9362900Sfrankho
9372900Sfrankho cleanup:
9385331Samw (void) VOP_CLOSE(devvp, FREAD, 1, (offset_t)0, cr, NULL);
9392900Sfrankho VN_RELE(devvp);
9402900Sfrankho if (fsp)
9412900Sfrankho kmem_free(fsp, sizeof (*fsp));
9422900Sfrankho if (svp)
9432900Sfrankho kmem_free(svp, sizeof (*svp));
9442900Sfrankho if (jvp)
9452900Sfrankho kmem_free(jvp, sizeof (*jvp));
9462900Sfrankho return (error);
9472900Sfrankho }
9482900Sfrankho
9492900Sfrankho /*
9502900Sfrankho * Get the rootvp associated with fsp->hsfs_vol
9512900Sfrankho */
9522900Sfrankho static int
hs_getrootvp(struct vfs * vfsp,struct hsfs * fsp,size_t pathsize)9532900Sfrankho hs_getrootvp(
9542900Sfrankho struct vfs *vfsp,
9552900Sfrankho struct hsfs *fsp,
9562900Sfrankho size_t pathsize)
9572900Sfrankho {
9582900Sfrankho struct hsnode *hp;
9592900Sfrankho
9602900Sfrankho ASSERT(pathsize == strlen(fsp->hsfs_fsmnt) + 1);
9612900Sfrankho
9620Sstevel@tonic-gate /*
9630Sstevel@tonic-gate * If the root directory does not appear to be
9640Sstevel@tonic-gate * valid, use what it points to as "." instead.
9650Sstevel@tonic-gate * Some Defense Mapping Agency disks are non-conformant
9660Sstevel@tonic-gate * in this way.
9670Sstevel@tonic-gate */
9680Sstevel@tonic-gate if (!hsfs_valid_dir(&fsp->hsfs_vol.root_dir)) {
9690Sstevel@tonic-gate hs_log_bogus_disk_warning(fsp, HSFS_ERR_BAD_ROOT_DIR, 0);
9700Sstevel@tonic-gate if (hs_remakenode(fsp->hsfs_vol.root_dir.ext_lbn,
9714866Sfrankho (uint_t)0, vfsp, &fsp->hsfs_rootvp)) {
9721025Sfrankho hs_mounttab = hs_mounttab->hsfs_next;
9731025Sfrankho mutex_destroy(&fsp->hsfs_free_lock);
9741025Sfrankho rw_destroy(&fsp->hsfs_hash_lock);
9752900Sfrankho kmem_free(fsp->hsfs_fsmnt, pathsize);
976494Sfrankho mutex_exit(&hs_mounttab_lock);
9772900Sfrankho return (0);
9780Sstevel@tonic-gate }
9790Sstevel@tonic-gate } else {
9800Sstevel@tonic-gate fsp->hsfs_rootvp = hs_makenode(&fsp->hsfs_vol.root_dir,
9814866Sfrankho fsp->hsfs_vol.root_dir.ext_lbn, 0, vfsp);
9820Sstevel@tonic-gate }
9830Sstevel@tonic-gate
9840Sstevel@tonic-gate /* XXX - ignore the path table for now */
9850Sstevel@tonic-gate fsp->hsfs_ptbl = NULL;
9860Sstevel@tonic-gate hp = VTOH(fsp->hsfs_rootvp);
9870Sstevel@tonic-gate hp->hs_ptbl_idx = NULL;
9880Sstevel@tonic-gate
9892900Sfrankho return (1);
9900Sstevel@tonic-gate }
9910Sstevel@tonic-gate
9920Sstevel@tonic-gate /*
9930Sstevel@tonic-gate * hs_findhsvol()
9940Sstevel@tonic-gate *
9950Sstevel@tonic-gate * Locate the Standard File Structure Volume Descriptor and
9960Sstevel@tonic-gate * parse it into an hs_volume structure.
9970Sstevel@tonic-gate *
9980Sstevel@tonic-gate * XXX - May someday want to look for Coded Character Set FSVD, too.
9990Sstevel@tonic-gate */
10000Sstevel@tonic-gate static int
hs_findhsvol(struct hsfs * fsp,struct vnode * vp,struct hs_volume * hvp)10010Sstevel@tonic-gate hs_findhsvol(struct hsfs *fsp, struct vnode *vp, struct hs_volume *hvp)
10020Sstevel@tonic-gate {
10030Sstevel@tonic-gate struct buf *secbp;
10040Sstevel@tonic-gate int i;
10054866Sfrankho int n;
10060Sstevel@tonic-gate uchar_t *volp;
10070Sstevel@tonic-gate int error;
10080Sstevel@tonic-gate uint_t secno;
10090Sstevel@tonic-gate
10100Sstevel@tonic-gate secno = hs_findvoldesc(vp->v_rdev, HS_VOLDESC_SEC);
10110Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
10120Sstevel@tonic-gate error = geterror(secbp);
10130Sstevel@tonic-gate
10140Sstevel@tonic-gate if (error != 0) {
10150Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)", error);
10160Sstevel@tonic-gate brelse(secbp);
10170Sstevel@tonic-gate return (error);
10180Sstevel@tonic-gate }
10190Sstevel@tonic-gate
10200Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr;
10210Sstevel@tonic-gate
10224866Sfrankho /*
10234866Sfrankho * To avoid that we read the whole medium in case that someone prepares
10244866Sfrankho * a malicious "fs image", we read at most 32 blocks.
10254866Sfrankho */
10264866Sfrankho for (n = 0; n < 32 &&
10274866Sfrankho HSV_DESC_TYPE(volp) != VD_EOV; n++) {
10280Sstevel@tonic-gate for (i = 0; i < HSV_ID_STRLEN; i++)
10290Sstevel@tonic-gate if (HSV_STD_ID(volp)[i] != HSV_ID_STRING[i])
10300Sstevel@tonic-gate goto cantfind;
10310Sstevel@tonic-gate if (HSV_STD_VER(volp) != HSV_ID_VER)
10320Sstevel@tonic-gate goto cantfind;
10330Sstevel@tonic-gate switch (HSV_DESC_TYPE(volp)) {
10340Sstevel@tonic-gate case VD_SFS:
10350Sstevel@tonic-gate /* Standard File Structure */
10360Sstevel@tonic-gate fsp->hsfs_vol_type = HS_VOL_TYPE_HS;
10370Sstevel@tonic-gate error = hs_parsehsvol(fsp, volp, hvp);
10380Sstevel@tonic-gate brelse(secbp);
10390Sstevel@tonic-gate return (error);
10400Sstevel@tonic-gate
10410Sstevel@tonic-gate case VD_CCFS:
10420Sstevel@tonic-gate /* Coded Character File Structure */
10430Sstevel@tonic-gate case VD_BOOT:
10440Sstevel@tonic-gate case VD_UNSPEC:
10450Sstevel@tonic-gate case VD_EOV:
10460Sstevel@tonic-gate break;
10470Sstevel@tonic-gate }
10480Sstevel@tonic-gate brelse(secbp);
10490Sstevel@tonic-gate ++secno;
10500Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
10510Sstevel@tonic-gate
10520Sstevel@tonic-gate error = geterror(secbp);
10530Sstevel@tonic-gate
10540Sstevel@tonic-gate if (error != 0) {
10550Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)",
10564866Sfrankho error);
10570Sstevel@tonic-gate brelse(secbp);
10580Sstevel@tonic-gate return (error);
10590Sstevel@tonic-gate }
10600Sstevel@tonic-gate
10610Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr;
10620Sstevel@tonic-gate }
10630Sstevel@tonic-gate cantfind:
10640Sstevel@tonic-gate brelse(secbp);
10650Sstevel@tonic-gate return (EINVAL);
10660Sstevel@tonic-gate }
10670Sstevel@tonic-gate
10680Sstevel@tonic-gate /*
10690Sstevel@tonic-gate * hs_parsehsvol
10700Sstevel@tonic-gate *
10710Sstevel@tonic-gate * Parse the Standard File Structure Volume Descriptor into
10720Sstevel@tonic-gate * an hs_volume structure. We can't just bcopy it into the
10730Sstevel@tonic-gate * structure because of byte-ordering problems.
10740Sstevel@tonic-gate *
10750Sstevel@tonic-gate */
10760Sstevel@tonic-gate static int
hs_parsehsvol(struct hsfs * fsp,uchar_t * volp,struct hs_volume * hvp)10770Sstevel@tonic-gate hs_parsehsvol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp)
10780Sstevel@tonic-gate {
10790Sstevel@tonic-gate hvp->vol_size = HSV_VOL_SIZE(volp);
10800Sstevel@tonic-gate hvp->lbn_size = HSV_BLK_SIZE(volp);
10810Sstevel@tonic-gate if (hvp->lbn_size == 0) {
10820Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_parsehsvol: logical block size in the "
10834866Sfrankho "SFSVD is zero");
10840Sstevel@tonic-gate return (EINVAL);
10850Sstevel@tonic-gate }
10860Sstevel@tonic-gate hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1;
10874866Sfrankho hvp->lbn_secshift =
10884866Sfrankho ffs((long)howmany(HS_SECTOR_SIZE, (int)hvp->lbn_size)) - 1;
10890Sstevel@tonic-gate hvp->lbn_maxoffset = hvp->lbn_size - 1;
10900Sstevel@tonic-gate hs_parse_longdate(HSV_cre_date(volp), &hvp->cre_date);
10910Sstevel@tonic-gate hs_parse_longdate(HSV_mod_date(volp), &hvp->mod_date);
10920Sstevel@tonic-gate hvp->file_struct_ver = HSV_FILE_STRUCT_VER(volp);
10930Sstevel@tonic-gate hvp->ptbl_len = HSV_PTBL_SIZE(volp);
10940Sstevel@tonic-gate hvp->vol_set_size = (ushort_t)HSV_SET_SIZE(volp);
10950Sstevel@tonic-gate hvp->vol_set_seq = (ushort_t)HSV_SET_SEQ(volp);
10960Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
10970Sstevel@tonic-gate hvp->ptbl_lbn = HSV_PTBL_MAN_LS(volp);
10980Sstevel@tonic-gate #else
10990Sstevel@tonic-gate hvp->ptbl_lbn = HSV_PTBL_MAN_MS(volp);
11000Sstevel@tonic-gate #endif
11012900Sfrankho hs_copylabel(hvp, HSV_VOL_ID(volp), 0);
11020Sstevel@tonic-gate
11030Sstevel@tonic-gate /*
11040Sstevel@tonic-gate * Make sure that lbn_size is a power of two and otherwise valid.
11050Sstevel@tonic-gate */
11060Sstevel@tonic-gate if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) {
11070Sstevel@tonic-gate cmn_err(CE_NOTE,
11084866Sfrankho "hsfs: %d-byte logical block size not supported",
11094866Sfrankho hvp->lbn_size);
11100Sstevel@tonic-gate return (EINVAL);
11110Sstevel@tonic-gate }
11120Sstevel@tonic-gate return (hs_parsedir(fsp, HSV_ROOT_DIR(volp), &hvp->root_dir,
11134866Sfrankho (char *)NULL, (int *)NULL, HDE_ROOT_DIR_REC_SIZE));
11140Sstevel@tonic-gate }
11150Sstevel@tonic-gate
11160Sstevel@tonic-gate /*
11170Sstevel@tonic-gate * hs_findisovol()
11180Sstevel@tonic-gate *
11190Sstevel@tonic-gate * Locate the Primary Volume Descriptor
11200Sstevel@tonic-gate * parse it into an hs_volume structure.
11210Sstevel@tonic-gate *
11222900Sfrankho * XXX - Partition not yet done
11232900Sfrankho *
11242900Sfrankho * Except for fsp->hsfs_vol_type, no fsp member may be modified.
11252900Sfrankho * fsp->hsfs_vol is modified indirectly via the *hvp argument.
11260Sstevel@tonic-gate */
11270Sstevel@tonic-gate static int
hs_findisovol(struct hsfs * fsp,struct vnode * vp,struct hs_volume * hvp,struct hs_volume * svp,struct hs_volume * jvp)11280Sstevel@tonic-gate hs_findisovol(struct hsfs *fsp, struct vnode *vp,
11292900Sfrankho struct hs_volume *hvp,
11302900Sfrankho struct hs_volume *svp,
11312900Sfrankho struct hs_volume *jvp)
11320Sstevel@tonic-gate {
11330Sstevel@tonic-gate struct buf *secbp;
11340Sstevel@tonic-gate int i;
11354866Sfrankho int n;
11360Sstevel@tonic-gate uchar_t *volp;
11370Sstevel@tonic-gate int error;
11380Sstevel@tonic-gate uint_t secno;
11390Sstevel@tonic-gate int foundpvd = 0;
11402900Sfrankho int foundsvd = 0;
11412900Sfrankho int foundjvd = 0;
11424866Sfrankho int pvd_sum = 0;
11430Sstevel@tonic-gate
11440Sstevel@tonic-gate secno = hs_findvoldesc(vp->v_rdev, ISO_VOLDESC_SEC);
11450Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, ISO_SECTOR_SIZE);
11460Sstevel@tonic-gate error = geterror(secbp);
11470Sstevel@tonic-gate
11480Sstevel@tonic-gate if (error != 0) {
11490Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)", error);
11500Sstevel@tonic-gate brelse(secbp);
11510Sstevel@tonic-gate return (error);
11520Sstevel@tonic-gate }
11530Sstevel@tonic-gate
11540Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr;
11550Sstevel@tonic-gate
11564866Sfrankho /*
11574866Sfrankho * To avoid that we read the whole medium in case that someone prepares
11584866Sfrankho * a malicious "fs image", we read at most 32 blocks.
11594866Sfrankho */
11604866Sfrankho for (n = 0; n < 32 &&
11614866Sfrankho (enum iso_voldesc_type) ISO_DESC_TYPE(volp) != ISO_VD_EOV; n++) {
11620Sstevel@tonic-gate for (i = 0; i < ISO_ID_STRLEN; i++)
11630Sstevel@tonic-gate if (ISO_STD_ID(volp)[i] != ISO_ID_STRING[i])
11640Sstevel@tonic-gate goto cantfind;
11650Sstevel@tonic-gate switch (ISO_DESC_TYPE(volp)) {
11660Sstevel@tonic-gate case ISO_VD_PVD:
11670Sstevel@tonic-gate /* Standard File Structure */
11682900Sfrankho if (ISO_STD_VER(volp) != ISO_ID_VER)
11692900Sfrankho goto cantfind;
11700Sstevel@tonic-gate if (foundpvd != 1) {
11710Sstevel@tonic-gate fsp->hsfs_vol_type = HS_VOL_TYPE_ISO;
11720Sstevel@tonic-gate if (error = hs_parseisovol(fsp, volp, hvp)) {
11730Sstevel@tonic-gate brelse(secbp);
11740Sstevel@tonic-gate return (error);
11750Sstevel@tonic-gate }
11760Sstevel@tonic-gate foundpvd = 1;
11774866Sfrankho for (i = 0; i < ISO_SECTOR_SIZE; i++)
11784866Sfrankho pvd_sum += volp[i];
11790Sstevel@tonic-gate }
11800Sstevel@tonic-gate break;
11810Sstevel@tonic-gate case ISO_VD_SVD:
11820Sstevel@tonic-gate /* Supplementary Volume Descriptor */
11832900Sfrankho if (ISO_STD_VER(volp) == ISO_ID_VER2 &&
11842900Sfrankho foundsvd != 1) {
11852900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_ISO;
11862900Sfrankho if (error = hs_parseisovol(fsp, volp, svp)) {
11872900Sfrankho brelse(secbp);
11882900Sfrankho return (error);
11892900Sfrankho }
11902900Sfrankho foundsvd = 1;
11912900Sfrankho }
11922900Sfrankho if (hs_joliet_level(volp) >= 1 && foundjvd != 1) {
11932900Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_ISO;
11942900Sfrankho if (error = hs_parseisovol(fsp, volp, jvp)) {
11952900Sfrankho brelse(secbp);
11962900Sfrankho return (error);
11972900Sfrankho }
11982900Sfrankho foundjvd = 1;
11992900Sfrankho }
12000Sstevel@tonic-gate break;
12010Sstevel@tonic-gate case ISO_VD_BOOT:
12020Sstevel@tonic-gate break;
12030Sstevel@tonic-gate case ISO_VD_VPD:
12040Sstevel@tonic-gate /* currently cannot handle partition */
12050Sstevel@tonic-gate break;
12060Sstevel@tonic-gate case VD_EOV:
12070Sstevel@tonic-gate break;
12080Sstevel@tonic-gate }
12090Sstevel@tonic-gate brelse(secbp);
12100Sstevel@tonic-gate ++secno;
12110Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
12120Sstevel@tonic-gate error = geterror(secbp);
12130Sstevel@tonic-gate
12140Sstevel@tonic-gate if (error != 0) {
12150Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)",
12164866Sfrankho error);
12170Sstevel@tonic-gate brelse(secbp);
12180Sstevel@tonic-gate return (error);
12190Sstevel@tonic-gate }
12200Sstevel@tonic-gate
12210Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr;
12220Sstevel@tonic-gate }
12234866Sfrankho for (n = 0; n < 16; n++) {
12244866Sfrankho brelse(secbp);
12254866Sfrankho ++secno;
12264866Sfrankho secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
12274866Sfrankho error = geterror(secbp);
12284866Sfrankho
12294866Sfrankho if (error != 0) {
12304866Sfrankho cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)",
12314866Sfrankho error);
12324866Sfrankho brelse(secbp);
12334866Sfrankho return (error);
12344866Sfrankho }
12354866Sfrankho
12364866Sfrankho /*
12374866Sfrankho * Check for the signature from mkisofs that grants that
12384866Sfrankho * the current filesystem allows to use the extent lbn as
12394866Sfrankho * inode number even in pure ISO9660 mode.
12404866Sfrankho */
12414866Sfrankho volp = (uchar_t *)secbp->b_un.b_addr;
12424866Sfrankho if (strncmp((char *)volp, "MKI ", 4) == 0) {
12434866Sfrankho int sum;
12444866Sfrankho
12454866Sfrankho sum = volp[2045];
12464866Sfrankho sum *= 256;
12474866Sfrankho sum += volp[2046];
12484866Sfrankho sum *= 256;
12494866Sfrankho sum += volp[2047];
12504866Sfrankho if (sum == pvd_sum)
12514866Sfrankho fsp->hsfs_flags |= HSFSMNT_INODE;
12524866Sfrankho break;
12534866Sfrankho }
12544866Sfrankho }
12550Sstevel@tonic-gate if (foundpvd) {
12560Sstevel@tonic-gate brelse(secbp);
12570Sstevel@tonic-gate return (0);
12580Sstevel@tonic-gate }
12590Sstevel@tonic-gate cantfind:
12600Sstevel@tonic-gate brelse(secbp);
12610Sstevel@tonic-gate return (EINVAL);
12620Sstevel@tonic-gate }
12632900Sfrankho
12642900Sfrankho /*
12652900Sfrankho * Return 0 if no Joliet is found
12662900Sfrankho * else return Joliet Level 1..3
12672900Sfrankho */
12682900Sfrankho static int
hs_joliet_level(uchar_t * volp)12692900Sfrankho hs_joliet_level(uchar_t *volp)
12702900Sfrankho {
12712900Sfrankho if (ISO_std_ver(volp)[0] == ISO_ID_VER &&
12722900Sfrankho ISO_svd_esc(volp)[0] == '%' &&
12732900Sfrankho ISO_svd_esc(volp)[1] == '/') {
12742900Sfrankho
12752900Sfrankho switch (ISO_svd_esc(volp)[2]) {
12762900Sfrankho
12772900Sfrankho case '@':
12782900Sfrankho return (1);
12792900Sfrankho case 'C':
12802900Sfrankho return (2);
12812900Sfrankho case 'E':
12822900Sfrankho return (3);
12832900Sfrankho }
12842900Sfrankho }
12852900Sfrankho return (0);
12862900Sfrankho }
12872900Sfrankho
12880Sstevel@tonic-gate /*
12890Sstevel@tonic-gate * hs_parseisovol
12900Sstevel@tonic-gate *
12910Sstevel@tonic-gate * Parse the Primary Volume Descriptor into an hs_volume structure.
12920Sstevel@tonic-gate *
12930Sstevel@tonic-gate */
12940Sstevel@tonic-gate static int
hs_parseisovol(struct hsfs * fsp,uchar_t * volp,struct hs_volume * hvp)12950Sstevel@tonic-gate hs_parseisovol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp)
12960Sstevel@tonic-gate {
12970Sstevel@tonic-gate hvp->vol_size = ISO_VOL_SIZE(volp);
12980Sstevel@tonic-gate hvp->lbn_size = ISO_BLK_SIZE(volp);
12990Sstevel@tonic-gate if (hvp->lbn_size == 0) {
13000Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_parseisovol: logical block size in the "
13014866Sfrankho "PVD is zero");
13020Sstevel@tonic-gate return (EINVAL);
13030Sstevel@tonic-gate }
13040Sstevel@tonic-gate hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1;
13054866Sfrankho hvp->lbn_secshift =
13064866Sfrankho ffs((long)howmany(ISO_SECTOR_SIZE, (int)hvp->lbn_size)) - 1;
13070Sstevel@tonic-gate hvp->lbn_maxoffset = hvp->lbn_size - 1;
13080Sstevel@tonic-gate hs_parse_longdate(ISO_cre_date(volp), &hvp->cre_date);
13090Sstevel@tonic-gate hs_parse_longdate(ISO_mod_date(volp), &hvp->mod_date);
13100Sstevel@tonic-gate hvp->file_struct_ver = ISO_FILE_STRUCT_VER(volp);
13110Sstevel@tonic-gate hvp->ptbl_len = ISO_PTBL_SIZE(volp);
13120Sstevel@tonic-gate hvp->vol_set_size = (ushort_t)ISO_SET_SIZE(volp);
13130Sstevel@tonic-gate hvp->vol_set_seq = (ushort_t)ISO_SET_SEQ(volp);
13140Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
13150Sstevel@tonic-gate hvp->ptbl_lbn = ISO_PTBL_MAN_LS(volp);
13160Sstevel@tonic-gate #else
13170Sstevel@tonic-gate hvp->ptbl_lbn = ISO_PTBL_MAN_MS(volp);
13180Sstevel@tonic-gate #endif
13192900Sfrankho hs_copylabel(hvp, ISO_VOL_ID(volp), hs_joliet_level(volp) >= 1);
13200Sstevel@tonic-gate
13210Sstevel@tonic-gate /*
13220Sstevel@tonic-gate * Make sure that lbn_size is a power of two and otherwise valid.
13230Sstevel@tonic-gate */
13240Sstevel@tonic-gate if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) {
13250Sstevel@tonic-gate cmn_err(CE_NOTE,
13264866Sfrankho "hsfs: %d-byte logical block size not supported",
13274866Sfrankho hvp->lbn_size);
13280Sstevel@tonic-gate return (EINVAL);
13290Sstevel@tonic-gate }
13300Sstevel@tonic-gate return (hs_parsedir(fsp, ISO_ROOT_DIR(volp), &hvp->root_dir,
13314866Sfrankho (char *)NULL, (int *)NULL, IDE_ROOT_DIR_REC_SIZE));
13320Sstevel@tonic-gate }
13330Sstevel@tonic-gate
13340Sstevel@tonic-gate /*
13350Sstevel@tonic-gate * Common code for mount and umount.
13360Sstevel@tonic-gate * Check that the user's argument is a reasonable
13370Sstevel@tonic-gate * thing on which to mount, and return the device number if so.
13380Sstevel@tonic-gate */
13390Sstevel@tonic-gate static int
hs_getmdev(struct vfs * vfsp,char * fspec,int flags,dev_t * pdev,mode_t * mode,cred_t * cr)13400Sstevel@tonic-gate hs_getmdev(struct vfs *vfsp, char *fspec, int flags, dev_t *pdev, mode_t *mode,
13410Sstevel@tonic-gate cred_t *cr)
13420Sstevel@tonic-gate {
13430Sstevel@tonic-gate int error;
13446734Sjohnlev struct vnode *svp = NULL;
13456734Sjohnlev struct vnode *lvp = NULL;
13466734Sjohnlev struct vnode *bvp;
13470Sstevel@tonic-gate struct vattr vap;
13480Sstevel@tonic-gate dev_t dev;
13496734Sjohnlev enum uio_seg fromspace = (flags & MS_SYSSPACE) ?
13506734Sjohnlev UIO_SYSSPACE : UIO_USERSPACE;
13510Sstevel@tonic-gate
13520Sstevel@tonic-gate /*
13536734Sjohnlev * Look up the device/file to be mounted.
13540Sstevel@tonic-gate */
13556734Sjohnlev error = lookupname(fspec, fromspace, FOLLOW, NULLVPP, &svp);
13560Sstevel@tonic-gate if (error) {
13576734Sjohnlev if (error == ENOENT)
13586734Sjohnlev error = ENODEV;
13596734Sjohnlev goto out;
13600Sstevel@tonic-gate }
13610Sstevel@tonic-gate
13626734Sjohnlev error = vfs_get_lofi(vfsp, &lvp);
13636734Sjohnlev
13646734Sjohnlev if (error > 0) {
13656734Sjohnlev if (error == ENOENT)
13666734Sjohnlev error = ENODEV;
13676734Sjohnlev goto out;
13686734Sjohnlev } else if (error == 0) {
13696734Sjohnlev bvp = lvp;
13706734Sjohnlev } else {
13716734Sjohnlev bvp = svp;
13726734Sjohnlev
13736734Sjohnlev if (bvp->v_type != VBLK) {
13746734Sjohnlev error = ENOTBLK;
13756734Sjohnlev goto out;
13766734Sjohnlev }
13776734Sjohnlev
13786734Sjohnlev if ((error = secpolicy_spec_open(cr, bvp, FREAD)) != 0)
13796734Sjohnlev goto out;
13806734Sjohnlev }
13816734Sjohnlev
13826734Sjohnlev /*
13836734Sjohnlev * Can we read from the device/file ?
13846734Sjohnlev */
13856734Sjohnlev if ((error = VOP_ACCESS(svp, VREAD, 0, cr, NULL)) != 0)
13866734Sjohnlev goto out;
13876734Sjohnlev
13880Sstevel@tonic-gate vap.va_mask = AT_MODE; /* get protection mode */
13896734Sjohnlev (void) VOP_GETATTR(bvp, &vap, 0, CRED(), NULL);
13900Sstevel@tonic-gate *mode = vap.va_mode;
13910Sstevel@tonic-gate
13926734Sjohnlev dev = *pdev = bvp->v_rdev;
13936734Sjohnlev
13946734Sjohnlev error = EBUSY;
13950Sstevel@tonic-gate
13960Sstevel@tonic-gate /*
13970Sstevel@tonic-gate * Ensure that this device isn't already mounted,
13980Sstevel@tonic-gate * unless this is a REMOUNT request or we are told to suppress
13990Sstevel@tonic-gate * mount checks.
14000Sstevel@tonic-gate */
14010Sstevel@tonic-gate if ((flags & MS_NOCHECK) == 0) {
14020Sstevel@tonic-gate if (vfs_devmounting(dev, vfsp))
14036734Sjohnlev goto out;
14040Sstevel@tonic-gate if (vfs_devismounted(dev) && !(flags & MS_REMOUNT))
14056734Sjohnlev goto out;
14060Sstevel@tonic-gate }
14070Sstevel@tonic-gate
14086734Sjohnlev if (getmajor(*pdev) >= devcnt) {
14096734Sjohnlev error = ENXIO;
14106734Sjohnlev goto out;
14116734Sjohnlev }
14126734Sjohnlev
14136734Sjohnlev error = 0;
14146734Sjohnlev out:
14156734Sjohnlev if (svp != NULL)
14166734Sjohnlev VN_RELE(svp);
14176734Sjohnlev if (lvp != NULL)
14186734Sjohnlev VN_RELE(lvp);
14196734Sjohnlev return (error);
14200Sstevel@tonic-gate }
14210Sstevel@tonic-gate
14220Sstevel@tonic-gate static void
hs_copylabel(struct hs_volume * hvp,unsigned char * label,int isjoliet)14232900Sfrankho hs_copylabel(struct hs_volume *hvp, unsigned char *label, int isjoliet)
14240Sstevel@tonic-gate {
14252900Sfrankho char lbuf[64]; /* hs_joliet_cp() creates 48 bytes at most */
14262900Sfrankho
14272900Sfrankho if (isjoliet) {
14282900Sfrankho /*
14292900Sfrankho * hs_joliet_cp() will output 16..48 bytes.
14302900Sfrankho * We need to clear 'lbuf' to avoid junk chars past byte 15.
14312900Sfrankho */
14322900Sfrankho bzero(lbuf, sizeof (lbuf));
14332904Sfrankho (void) hs_joliet_cp((char *)label, lbuf, 32);
14342900Sfrankho label = (unsigned char *)lbuf;
14352900Sfrankho }
14360Sstevel@tonic-gate /* cdrom volid is at most 32 bytes */
14370Sstevel@tonic-gate bcopy(label, hvp->vol_id, 32);
14380Sstevel@tonic-gate hvp->vol_id[31] = NULL;
14390Sstevel@tonic-gate }
14400Sstevel@tonic-gate
14410Sstevel@tonic-gate /*
14420Sstevel@tonic-gate * Mount root file system.
14430Sstevel@tonic-gate * "why" is ROOT_INIT on initial call, ROOT_REMOUNT if called to
14440Sstevel@tonic-gate * remount the root file system, and ROOT_UNMOUNT if called to
14450Sstevel@tonic-gate * unmount the root (e.g., as part of a system shutdown).
14460Sstevel@tonic-gate *
14470Sstevel@tonic-gate * XXX - this may be partially machine-dependent; it, along with the VFS_SWAPVP
14480Sstevel@tonic-gate * operation, goes along with auto-configuration. A mechanism should be
14490Sstevel@tonic-gate * provided by which machine-INdependent code in the kernel can say "get me the
14500Sstevel@tonic-gate * right root file system" and "get me the right initial swap area", and have
14510Sstevel@tonic-gate * that done in what may well be a machine-dependent fashion.
14520Sstevel@tonic-gate * Unfortunately, it is also file-system-type dependent (NFS gets it via
14530Sstevel@tonic-gate * bootparams calls, UFS gets it from various and sundry machine-dependent
14540Sstevel@tonic-gate * mechanisms, as SPECFS does for swap).
14550Sstevel@tonic-gate */
14560Sstevel@tonic-gate static int
hsfs_mountroot(struct vfs * vfsp,enum whymountroot why)14570Sstevel@tonic-gate hsfs_mountroot(struct vfs *vfsp, enum whymountroot why)
14580Sstevel@tonic-gate {
14590Sstevel@tonic-gate int error;
14600Sstevel@tonic-gate struct hsfs *fsp;
14610Sstevel@tonic-gate struct hs_volume *fvolp;
14620Sstevel@tonic-gate static int hsfsrootdone = 0;
14630Sstevel@tonic-gate dev_t rootdev;
14640Sstevel@tonic-gate mode_t mode = 0;
14650Sstevel@tonic-gate
14660Sstevel@tonic-gate if (why == ROOT_INIT) {
14670Sstevel@tonic-gate if (hsfsrootdone++)
14680Sstevel@tonic-gate return (EBUSY);
14690Sstevel@tonic-gate rootdev = getrootdev();
14700Sstevel@tonic-gate if (rootdev == (dev_t)NODEV)
14710Sstevel@tonic-gate return (ENODEV);
14720Sstevel@tonic-gate vfsp->vfs_dev = rootdev;
14730Sstevel@tonic-gate vfsp->vfs_flag |= VFS_RDONLY;
14740Sstevel@tonic-gate } else if (why == ROOT_REMOUNT) {
14750Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: ROOT_REMOUNT");
14760Sstevel@tonic-gate return (0);
14770Sstevel@tonic-gate } else if (why == ROOT_UNMOUNT) {
14780Sstevel@tonic-gate return (0);
14790Sstevel@tonic-gate }
14800Sstevel@tonic-gate error = vfs_lock(vfsp);
14810Sstevel@tonic-gate if (error) {
14820Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: couldn't get vfs_lock");
14830Sstevel@tonic-gate return (error);
14840Sstevel@tonic-gate }
14850Sstevel@tonic-gate
14860Sstevel@tonic-gate error = hs_mountfs(vfsp, rootdev, "/", mode, 1, CRED(), 1);
14870Sstevel@tonic-gate /*
14880Sstevel@tonic-gate * XXX - assumes root device is not indirect, because we don't set
14890Sstevel@tonic-gate * rootvp. Is rootvp used for anything? If so, make another arg
14900Sstevel@tonic-gate * to mountfs.
14910Sstevel@tonic-gate */
14920Sstevel@tonic-gate if (error) {
14930Sstevel@tonic-gate vfs_unlock(vfsp);
14940Sstevel@tonic-gate if (rootvp) {
14950Sstevel@tonic-gate VN_RELE(rootvp);
14960Sstevel@tonic-gate rootvp = (struct vnode *)0;
14970Sstevel@tonic-gate }
14980Sstevel@tonic-gate return (error);
14990Sstevel@tonic-gate }
15000Sstevel@tonic-gate if (why == ROOT_INIT)
15010Sstevel@tonic-gate vfs_add((struct vnode *)0, vfsp,
15020Sstevel@tonic-gate (vfsp->vfs_flag & VFS_RDONLY) ? MS_RDONLY : 0);
15030Sstevel@tonic-gate vfs_unlock(vfsp);
15040Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp);
15050Sstevel@tonic-gate fvolp = &fsp->hsfs_vol;
15060Sstevel@tonic-gate #ifdef HSFS_CLKSET
15070Sstevel@tonic-gate if (fvolp->cre_date.tv_sec == 0) {
15084866Sfrankho cmn_err(CE_NOTE, "hsfs_mountroot: cre_date.tv_sec == 0");
15094866Sfrankho if (fvolp->mod_date.tv_sec == 0) {
15104866Sfrankho cmn_err(CE_NOTE,
15114866Sfrankho "hsfs_mountroot: mod_date.tv_sec == 0");
15124866Sfrankho cmn_err(CE_NOTE, "hsfs_mountroot: clkset(-1L)");
15134866Sfrankho clkset(-1L);
15144866Sfrankho } else {
15154866Sfrankho clkset(fvolp->mod_date.tv_sec);
15164866Sfrankho }
15174866Sfrankho } else {
15180Sstevel@tonic-gate clkset(fvolp->mod_date.tv_sec);
15194866Sfrankho }
15200Sstevel@tonic-gate #else /* HSFS_CLKSET */
15210Sstevel@tonic-gate clkset(-1L);
15220Sstevel@tonic-gate #endif /* HSFS_CLKSET */
15230Sstevel@tonic-gate return (0);
15240Sstevel@tonic-gate }
15250Sstevel@tonic-gate
15260Sstevel@tonic-gate /*
15270Sstevel@tonic-gate * hs_findvoldesc()
15280Sstevel@tonic-gate *
15290Sstevel@tonic-gate * Return the sector where the volume descriptor lives. This is
15300Sstevel@tonic-gate * a fixed value for "normal" cd-rom's, but can change for
15310Sstevel@tonic-gate * multisession cd's.
15320Sstevel@tonic-gate *
15330Sstevel@tonic-gate * desc_sec is the same for high-sierra and iso 9660 formats, why
15345331Samw * there are two different #defines used in the code for this is
15350Sstevel@tonic-gate * beyond me. These are standards, cast in concrete, right?
15360Sstevel@tonic-gate * To be general, however, this function supports passing in different
15370Sstevel@tonic-gate * values.
15380Sstevel@tonic-gate */
15390Sstevel@tonic-gate static int
hs_findvoldesc(dev_t rdev,int desc_sec)15400Sstevel@tonic-gate hs_findvoldesc(dev_t rdev, int desc_sec)
15410Sstevel@tonic-gate {
15420Sstevel@tonic-gate int secno;
15430Sstevel@tonic-gate int error;
15440Sstevel@tonic-gate int rval; /* ignored */
15450Sstevel@tonic-gate
15460Sstevel@tonic-gate #ifdef CDROMREADOFFSET
15470Sstevel@tonic-gate /*
15480Sstevel@tonic-gate * Issue the Read Offset ioctl directly to the
15490Sstevel@tonic-gate * device. Ignore any errors and set starting
15500Sstevel@tonic-gate * secno to the default, otherwise add the
15510Sstevel@tonic-gate * VOLDESC sector number to the offset.
15520Sstevel@tonic-gate */
15530Sstevel@tonic-gate error = cdev_ioctl(rdev, CDROMREADOFFSET, (intptr_t)&secno,
15540Sstevel@tonic-gate FNATIVE|FKIOCTL|FREAD, CRED(), &rval);
15550Sstevel@tonic-gate if (error) {
15560Sstevel@tonic-gate secno = desc_sec;
15570Sstevel@tonic-gate } else {
15580Sstevel@tonic-gate secno += desc_sec;
15590Sstevel@tonic-gate }
15600Sstevel@tonic-gate #else
15610Sstevel@tonic-gate secno = desc_sec;
15620Sstevel@tonic-gate #endif
15630Sstevel@tonic-gate
15640Sstevel@tonic-gate return (secno);
15650Sstevel@tonic-gate }
1566