17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
554e0249cSfrankho * Common Development and Distribution License (the "License").
654e0249cSfrankho * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
220fbb751dSJohn Levon * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
2389b43686SBayard Bell * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
24*8cd81a20SJerry Jelinek * Copyright 2013 Joyent, Inc. All rights reserved.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate * VFS operations for High Sierra filesystem
297c478bd9Sstevel@tonic-gate */
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
337c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
347c478bd9Sstevel@tonic-gate #include <sys/param.h>
357c478bd9Sstevel@tonic-gate #include <sys/systm.h>
367c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
377c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
387c478bd9Sstevel@tonic-gate #include <sys/signal.h>
397c478bd9Sstevel@tonic-gate #include <sys/user.h>
407c478bd9Sstevel@tonic-gate #include <sys/proc.h>
417c478bd9Sstevel@tonic-gate #include <sys/disp.h>
427c478bd9Sstevel@tonic-gate #include <sys/buf.h>
437c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
447c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
45aa59c4cbSrsb #include <sys/vfs_opreg.h>
467c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
477c478bd9Sstevel@tonic-gate #include <sys/file.h>
487c478bd9Sstevel@tonic-gate #include <sys/uio.h>
497c478bd9Sstevel@tonic-gate #include <sys/conf.h>
507c478bd9Sstevel@tonic-gate #include <sys/policy.h>
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate #include <vm/page.h>
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate #include <sys/fs/snode.h>
557c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_spec.h>
567c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_isospec.h>
577c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_node.h>
587c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_impl.h>
597c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_susp.h>
607c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_rrip.h>
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate #include <sys/statvfs.h>
637c478bd9Sstevel@tonic-gate #include <sys/mount.h>
647c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
657c478bd9Sstevel@tonic-gate #include <sys/swap.h>
667c478bd9Sstevel@tonic-gate #include <sys/errno.h>
677c478bd9Sstevel@tonic-gate #include <sys/debug.h>
687c478bd9Sstevel@tonic-gate #include "fs/fs_subr.h"
697c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
707c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
717c478bd9Sstevel@tonic-gate
72fc1c62b8Sfrankho #include <sys/sdt.h>
73fc1c62b8Sfrankho
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate * These are needed for the CDROMREADOFFSET Code
767c478bd9Sstevel@tonic-gate */
777c478bd9Sstevel@tonic-gate #include <sys/cdio.h>
787c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate #define HSFS_CLKSET
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate * Options for mount.
867c478bd9Sstevel@tonic-gate */
877c478bd9Sstevel@tonic-gate #define HOPT_GLOBAL MNTOPT_GLOBAL
887c478bd9Sstevel@tonic-gate #define HOPT_NOGLOBAL MNTOPT_NOGLOBAL
897c478bd9Sstevel@tonic-gate #define HOPT_MAPLCASE "maplcase"
907c478bd9Sstevel@tonic-gate #define HOPT_NOMAPLCASE "nomaplcase"
917c478bd9Sstevel@tonic-gate #define HOPT_NOTRAILDOT "notraildot"
927c478bd9Sstevel@tonic-gate #define HOPT_TRAILDOT "traildot"
937c478bd9Sstevel@tonic-gate #define HOPT_NRR "nrr"
947c478bd9Sstevel@tonic-gate #define HOPT_RR "rr"
95fc1c62b8Sfrankho #define HOPT_JOLIET "joliet"
96fc1c62b8Sfrankho #define HOPT_NOJOLIET "nojoliet"
97fc1c62b8Sfrankho #define HOPT_JOLIETLONG "jolietlong"
98fc1c62b8Sfrankho #define HOPT_VERS2 "vers2"
99fc1c62b8Sfrankho #define HOPT_NOVERS2 "novers2"
1007c478bd9Sstevel@tonic-gate #define HOPT_RO MNTOPT_RO
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate static char *global_cancel[] = { HOPT_NOGLOBAL, NULL };
1037c478bd9Sstevel@tonic-gate static char *noglobal_cancel[] = { HOPT_GLOBAL, NULL };
1047c478bd9Sstevel@tonic-gate static char *mapl_cancel[] = { HOPT_NOMAPLCASE, NULL };
1057c478bd9Sstevel@tonic-gate static char *nomapl_cancel[] = { HOPT_MAPLCASE, NULL };
1067c478bd9Sstevel@tonic-gate static char *ro_cancel[] = { MNTOPT_RW, NULL };
1077c478bd9Sstevel@tonic-gate static char *rr_cancel[] = { HOPT_NRR, NULL };
1087c478bd9Sstevel@tonic-gate static char *nrr_cancel[] = { HOPT_RR, NULL };
109fc1c62b8Sfrankho static char *joliet_cancel[] = { HOPT_NOJOLIET, NULL };
110fc1c62b8Sfrankho static char *nojoliet_cancel[] = { HOPT_JOLIET, NULL };
111fc1c62b8Sfrankho static char *vers2_cancel[] = { HOPT_NOVERS2, NULL };
112fc1c62b8Sfrankho static char *novers2_cancel[] = { HOPT_VERS2, NULL };
1137c478bd9Sstevel@tonic-gate static char *trail_cancel[] = { HOPT_NOTRAILDOT, NULL };
1147c478bd9Sstevel@tonic-gate static char *notrail_cancel[] = { HOPT_TRAILDOT, NULL };
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate static mntopt_t hsfs_options[] = {
1177c478bd9Sstevel@tonic-gate { HOPT_GLOBAL, global_cancel, NULL, 0, NULL },
1187c478bd9Sstevel@tonic-gate { HOPT_NOGLOBAL, noglobal_cancel, NULL, MO_DEFAULT, NULL },
1197c478bd9Sstevel@tonic-gate { HOPT_MAPLCASE, mapl_cancel, NULL, MO_DEFAULT, NULL },
1207c478bd9Sstevel@tonic-gate { HOPT_NOMAPLCASE, nomapl_cancel, NULL, 0, NULL },
1217c478bd9Sstevel@tonic-gate { HOPT_RO, ro_cancel, NULL, MO_DEFAULT, NULL },
1227c478bd9Sstevel@tonic-gate { HOPT_RR, rr_cancel, NULL, MO_DEFAULT, NULL },
1237c478bd9Sstevel@tonic-gate { HOPT_NRR, nrr_cancel, NULL, 0, NULL },
124fc1c62b8Sfrankho { HOPT_JOLIET, joliet_cancel, NULL, 0, NULL },
125fc1c62b8Sfrankho { HOPT_NOJOLIET, nojoliet_cancel, NULL, 0, NULL },
126fc1c62b8Sfrankho { HOPT_JOLIETLONG, NULL, NULL, 0, NULL },
127fc1c62b8Sfrankho { HOPT_VERS2, vers2_cancel, NULL, 0, NULL },
128fc1c62b8Sfrankho { HOPT_NOVERS2, novers2_cancel, NULL, 0, NULL },
1297c478bd9Sstevel@tonic-gate { HOPT_TRAILDOT, trail_cancel, NULL, MO_DEFAULT, NULL },
1307c478bd9Sstevel@tonic-gate { HOPT_NOTRAILDOT, notrail_cancel, NULL, 0, NULL },
131fc1c62b8Sfrankho { "sector", NULL, "0", MO_HASVALUE, NULL},
1327c478bd9Sstevel@tonic-gate };
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate static mntopts_t hsfs_proto_opttbl = {
1357c478bd9Sstevel@tonic-gate sizeof (hsfs_options) / sizeof (mntopt_t),
1367c478bd9Sstevel@tonic-gate hsfs_options
1377c478bd9Sstevel@tonic-gate };
1387c478bd9Sstevel@tonic-gate
13984b82766Smg147109 /*
14084b82766Smg147109 * Indicates whether to enable the I/O scheduling and readahead logic
14184b82766Smg147109 * 1 - Enable, 0 - Do not Enable.
14284b82766Smg147109 * Debugging purposes.
14384b82766Smg147109 */
14484b82766Smg147109 int do_schedio = 1;
145fc1c62b8Sfrankho static int hsfsfstype;
1467c478bd9Sstevel@tonic-gate static int hsfsinit(int, char *);
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate static vfsdef_t vfw = {
1497c478bd9Sstevel@tonic-gate VFSDEF_VERSION,
1507c478bd9Sstevel@tonic-gate "hsfs",
1517c478bd9Sstevel@tonic-gate hsfsinit,
15243d5cd3dSjohnlev /* We don't suppport remounting */
153*8cd81a20SJerry Jelinek VSW_HASPROTO|VSW_STATS|VSW_CANLOFI,
1547c478bd9Sstevel@tonic-gate &hsfs_proto_opttbl
1557c478bd9Sstevel@tonic-gate };
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate static struct modlfs modlfs = {
1587c478bd9Sstevel@tonic-gate &mod_fsops, "filesystem for HSFS", &vfw
1597c478bd9Sstevel@tonic-gate };
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
1627c478bd9Sstevel@tonic-gate MODREV_1, (void *)&modlfs, NULL
1637c478bd9Sstevel@tonic-gate };
1647c478bd9Sstevel@tonic-gate
16584b82766Smg147109 extern void hsched_init_caches(void);
16684b82766Smg147109 extern void hsched_fini_caches(void);
16784b82766Smg147109
16884b82766Smg147109
1697c478bd9Sstevel@tonic-gate int
_init(void)170fc1c62b8Sfrankho _init(void)
1717c478bd9Sstevel@tonic-gate {
1727c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage));
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate int
_fini(void)176fc1c62b8Sfrankho _fini(void)
1777c478bd9Sstevel@tonic-gate {
178fc1c62b8Sfrankho int error;
179fc1c62b8Sfrankho
180fc1c62b8Sfrankho error = mod_remove(&modlinkage);
181fc1c62b8Sfrankho
182fc1c62b8Sfrankho DTRACE_PROBE1(mod_remove, int, error);
183fc1c62b8Sfrankho
184fc1c62b8Sfrankho if (error)
185fc1c62b8Sfrankho return (error);
186fc1c62b8Sfrankho
187fc1c62b8Sfrankho mutex_destroy(&hs_mounttab_lock);
188fc1c62b8Sfrankho
189fc1c62b8Sfrankho /*
190fc1c62b8Sfrankho * Tear down the operations vectors
191fc1c62b8Sfrankho */
192fc1c62b8Sfrankho (void) vfs_freevfsops_by_type(hsfsfstype);
193fc1c62b8Sfrankho vn_freevnodeops(hsfs_vnodeops);
194fc1c62b8Sfrankho
195fc1c62b8Sfrankho hs_fini_hsnode_cache();
19684b82766Smg147109 hsched_fini_caches();
197fc1c62b8Sfrankho return (0);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)2017c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
2027c478bd9Sstevel@tonic-gate {
2037c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate #define BDEVFLAG(dev) ((devopsp[getmajor(dev)])->devo_cb_ops->cb_flag)
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate kmutex_t hs_mounttab_lock;
2097c478bd9Sstevel@tonic-gate struct hsfs *hs_mounttab = NULL;
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate /* default mode, uid, gid */
2127c478bd9Sstevel@tonic-gate mode_t hsfs_default_mode = 0555;
2137c478bd9Sstevel@tonic-gate uid_t hsfs_default_uid = 0;
2147c478bd9Sstevel@tonic-gate gid_t hsfs_default_gid = 3;
2157c478bd9Sstevel@tonic-gate
21684b82766Smg147109 extern void hsched_init(struct hsfs *fsp, int fsid,
21784b82766Smg147109 struct modlinkage *modlinkage);
21884b82766Smg147109 extern void hsched_fini(struct hsfs_queue *hqueue);
21984b82766Smg147109 extern void hsfs_init_kstats(struct hsfs *fsp, int fsid);
22084b82766Smg147109 extern void hsfs_fini_kstats(struct hsfs *fsp);
22184b82766Smg147109
2227c478bd9Sstevel@tonic-gate static int hsfs_mount(struct vfs *vfsp, struct vnode *mvp,
2237c478bd9Sstevel@tonic-gate struct mounta *uap, struct cred *cr);
2247c478bd9Sstevel@tonic-gate static int hsfs_unmount(struct vfs *vfsp, int, struct cred *cr);
2257c478bd9Sstevel@tonic-gate static int hsfs_root(struct vfs *vfsp, struct vnode **vpp);
2267c478bd9Sstevel@tonic-gate static int hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp);
2277c478bd9Sstevel@tonic-gate static int hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp);
2287c478bd9Sstevel@tonic-gate static int hsfs_mountroot(struct vfs *, enum whymountroot);
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate static int hs_mountfs(struct vfs *vfsp, dev_t dev, char *path,
2317c478bd9Sstevel@tonic-gate mode_t mode, int flags, struct cred *cr, int isroot);
232fc1c62b8Sfrankho static int hs_getrootvp(struct vfs *vfsp, struct hsfs *fsp, size_t pathsize);
2337c478bd9Sstevel@tonic-gate static int hs_findhsvol(struct hsfs *fsp, struct vnode *vp,
2347c478bd9Sstevel@tonic-gate struct hs_volume *hvp);
2357c478bd9Sstevel@tonic-gate static int hs_parsehsvol(struct hsfs *fsp, uchar_t *volp,
2367c478bd9Sstevel@tonic-gate struct hs_volume *hvp);
2377c478bd9Sstevel@tonic-gate static int hs_findisovol(struct hsfs *fsp, struct vnode *vp,
238fc1c62b8Sfrankho struct hs_volume *hvp,
239fc1c62b8Sfrankho struct hs_volume *svp,
240fc1c62b8Sfrankho struct hs_volume *jvp);
241fc1c62b8Sfrankho static int hs_joliet_level(uchar_t *volp);
2427c478bd9Sstevel@tonic-gate static int hs_parseisovol(struct hsfs *fsp, uchar_t *volp,
2437c478bd9Sstevel@tonic-gate struct hs_volume *hvp);
244fc1c62b8Sfrankho static void hs_copylabel(struct hs_volume *, unsigned char *, int);
2457c478bd9Sstevel@tonic-gate static int hs_getmdev(struct vfs *, char *fspec, int flags, dev_t *pdev,
2467c478bd9Sstevel@tonic-gate mode_t *mode, cred_t *cr);
2477c478bd9Sstevel@tonic-gate static int hs_findvoldesc(dev_t rdev, int desc_sec);
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate static int
hsfsinit(int fstype,char * name)2507c478bd9Sstevel@tonic-gate hsfsinit(int fstype, char *name)
2517c478bd9Sstevel@tonic-gate {
2527c478bd9Sstevel@tonic-gate static const fs_operation_def_t hsfs_vfsops_template[] = {
253aa59c4cbSrsb VFSNAME_MOUNT, { .vfs_mount = hsfs_mount },
254aa59c4cbSrsb VFSNAME_UNMOUNT, { .vfs_unmount = hsfs_unmount },
255aa59c4cbSrsb VFSNAME_ROOT, { .vfs_root = hsfs_root },
256aa59c4cbSrsb VFSNAME_STATVFS, { .vfs_statvfs = hsfs_statvfs },
257aa59c4cbSrsb VFSNAME_VGET, { .vfs_vget = hsfs_vget },
258aa59c4cbSrsb VFSNAME_MOUNTROOT, { .vfs_mountroot = hsfs_mountroot },
2597c478bd9Sstevel@tonic-gate NULL, NULL
2607c478bd9Sstevel@tonic-gate };
2617c478bd9Sstevel@tonic-gate int error;
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate error = vfs_setfsops(fstype, hsfs_vfsops_template, NULL);
2647c478bd9Sstevel@tonic-gate if (error != 0) {
2657c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "hsfsinit: bad vfs ops template");
2667c478bd9Sstevel@tonic-gate return (error);
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate error = vn_make_ops(name, hsfs_vnodeops_template, &hsfs_vnodeops);
2707c478bd9Sstevel@tonic-gate if (error != 0) {
2717c478bd9Sstevel@tonic-gate (void) vfs_freevfsops_by_type(fstype);
2727c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "hsfsinit: bad vnode ops template");
2737c478bd9Sstevel@tonic-gate return (error);
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate hsfsfstype = fstype;
2777c478bd9Sstevel@tonic-gate mutex_init(&hs_mounttab_lock, NULL, MUTEX_DEFAULT, NULL);
2787c478bd9Sstevel@tonic-gate hs_init_hsnode_cache();
27984b82766Smg147109 hsched_init_caches();
2807c478bd9Sstevel@tonic-gate return (0);
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate
2837c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2847c478bd9Sstevel@tonic-gate static int
hsfs_mount(struct vfs * vfsp,struct vnode * mvp,struct mounta * uap,struct cred * cr)2857c478bd9Sstevel@tonic-gate hsfs_mount(struct vfs *vfsp, struct vnode *mvp,
2867c478bd9Sstevel@tonic-gate struct mounta *uap, struct cred *cr)
2877c478bd9Sstevel@tonic-gate {
2887c478bd9Sstevel@tonic-gate int vnode_busy;
2897c478bd9Sstevel@tonic-gate dev_t dev;
2907c478bd9Sstevel@tonic-gate struct pathname dpn;
2917c478bd9Sstevel@tonic-gate int error;
2927c478bd9Sstevel@tonic-gate mode_t mode;
2937c478bd9Sstevel@tonic-gate int flags; /* this will hold the mount specific data */
2947c478bd9Sstevel@tonic-gate
2957c478bd9Sstevel@tonic-gate if ((error = secpolicy_fs_mount(cr, mvp, vfsp)) != 0)
2967c478bd9Sstevel@tonic-gate return (error);
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate if (mvp->v_type != VDIR)
2997c478bd9Sstevel@tonic-gate return (ENOTDIR);
3007c478bd9Sstevel@tonic-gate
3017c478bd9Sstevel@tonic-gate /* mount option must be read only, else mount will be rejected */
3027c478bd9Sstevel@tonic-gate if (!(uap->flags & MS_RDONLY))
3037c478bd9Sstevel@tonic-gate return (EROFS);
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate /*
3067c478bd9Sstevel@tonic-gate * We already told the framework that we don't support remounting.
3077c478bd9Sstevel@tonic-gate */
3087c478bd9Sstevel@tonic-gate ASSERT(!(uap->flags & MS_REMOUNT));
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate mutex_enter(&mvp->v_lock);
3117c478bd9Sstevel@tonic-gate vnode_busy = (mvp->v_count != 1) || (mvp->v_flag & VROOT);
3127c478bd9Sstevel@tonic-gate mutex_exit(&mvp->v_lock);
3137c478bd9Sstevel@tonic-gate
3147c478bd9Sstevel@tonic-gate if ((uap->flags & MS_OVERLAY) == 0 && vnode_busy) {
3157c478bd9Sstevel@tonic-gate return (EBUSY);
3167c478bd9Sstevel@tonic-gate }
3177c478bd9Sstevel@tonic-gate
3187c478bd9Sstevel@tonic-gate /*
3197c478bd9Sstevel@tonic-gate * Check for the options that actually affect things
3207c478bd9Sstevel@tonic-gate * at our level.
3217c478bd9Sstevel@tonic-gate */
3227c478bd9Sstevel@tonic-gate flags = 0;
3237c478bd9Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NOMAPLCASE, NULL))
3247c478bd9Sstevel@tonic-gate flags |= HSFSMNT_NOMAPLCASE;
3257c478bd9Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NOTRAILDOT, NULL))
3267c478bd9Sstevel@tonic-gate flags |= HSFSMNT_NOTRAILDOT;
3277c478bd9Sstevel@tonic-gate if (vfs_optionisset(vfsp, HOPT_NRR, NULL))
3287c478bd9Sstevel@tonic-gate flags |= HSFSMNT_NORRIP;
329fc1c62b8Sfrankho if (vfs_optionisset(vfsp, HOPT_NOJOLIET, NULL))
330fc1c62b8Sfrankho flags |= HSFSMNT_NOJOLIET;
331fc1c62b8Sfrankho if (vfs_optionisset(vfsp, HOPT_JOLIETLONG, NULL))
332fc1c62b8Sfrankho flags |= HSFSMNT_JOLIETLONG;
333fc1c62b8Sfrankho if (vfs_optionisset(vfsp, HOPT_NOVERS2, NULL))
334fc1c62b8Sfrankho flags |= HSFSMNT_NOVERS2;
3357c478bd9Sstevel@tonic-gate
3367c478bd9Sstevel@tonic-gate error = pn_get(uap->dir, (uap->flags & MS_SYSSPACE) ?
3377c478bd9Sstevel@tonic-gate UIO_SYSSPACE : UIO_USERSPACE, &dpn);
3387c478bd9Sstevel@tonic-gate if (error)
3397c478bd9Sstevel@tonic-gate return (error);
3407c478bd9Sstevel@tonic-gate
341d10b6702Sfrankho error = hs_getmdev(vfsp, uap->spec, uap->flags, &dev, &mode, cr);
342d10b6702Sfrankho if (error != 0) {
3437c478bd9Sstevel@tonic-gate pn_free(&dpn);
3447c478bd9Sstevel@tonic-gate return (error);
3457c478bd9Sstevel@tonic-gate }
3467c478bd9Sstevel@tonic-gate
3477c478bd9Sstevel@tonic-gate /*
3487c478bd9Sstevel@tonic-gate * If the device is a tape, return error
3497c478bd9Sstevel@tonic-gate */
3507c478bd9Sstevel@tonic-gate if ((BDEVFLAG(dev) & D_TAPE) == D_TAPE) {
3517c478bd9Sstevel@tonic-gate pn_free(&dpn);
3527c478bd9Sstevel@tonic-gate return (ENOTBLK);
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate /*
3567c478bd9Sstevel@tonic-gate * Mount the filesystem.
3577c478bd9Sstevel@tonic-gate */
3587c478bd9Sstevel@tonic-gate error = hs_mountfs(vfsp, dev, dpn.pn_path, mode, flags, cr, 0);
3597c478bd9Sstevel@tonic-gate pn_free(&dpn);
3607c478bd9Sstevel@tonic-gate return (error);
3617c478bd9Sstevel@tonic-gate }
3627c478bd9Sstevel@tonic-gate
3637c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3647c478bd9Sstevel@tonic-gate static int
hsfs_unmount(struct vfs * vfsp,int flag,struct cred * cr)3657c478bd9Sstevel@tonic-gate hsfs_unmount(
3667c478bd9Sstevel@tonic-gate struct vfs *vfsp,
3677c478bd9Sstevel@tonic-gate int flag,
3687c478bd9Sstevel@tonic-gate struct cred *cr)
3697c478bd9Sstevel@tonic-gate {
3707c478bd9Sstevel@tonic-gate struct hsfs **tspp;
3717c478bd9Sstevel@tonic-gate struct hsfs *fsp;
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate if (secpolicy_fs_unmount(cr, vfsp) != 0)
3747c478bd9Sstevel@tonic-gate return (EPERM);
3757c478bd9Sstevel@tonic-gate
3767c478bd9Sstevel@tonic-gate /*
3777c478bd9Sstevel@tonic-gate * forced unmount is not supported by this file system
3787c478bd9Sstevel@tonic-gate * and thus, ENOTSUP is being returned.
3797c478bd9Sstevel@tonic-gate */
3807c478bd9Sstevel@tonic-gate if (flag & MS_FORCE)
3817c478bd9Sstevel@tonic-gate return (ENOTSUP);
3827c478bd9Sstevel@tonic-gate
3837c478bd9Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp);
3847c478bd9Sstevel@tonic-gate
3857c478bd9Sstevel@tonic-gate if (fsp->hsfs_rootvp->v_count != 1)
3867c478bd9Sstevel@tonic-gate return (EBUSY);
3877c478bd9Sstevel@tonic-gate
3887c478bd9Sstevel@tonic-gate /* destroy all old pages and hsnodes for this vfs */
3897c478bd9Sstevel@tonic-gate if (hs_synchash(vfsp))
3907c478bd9Sstevel@tonic-gate return (EBUSY);
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate mutex_enter(&hs_mounttab_lock);
3937c478bd9Sstevel@tonic-gate for (tspp = &hs_mounttab; *tspp != NULL; tspp = &(*tspp)->hsfs_next) {
3947c478bd9Sstevel@tonic-gate if (*tspp == fsp)
3957c478bd9Sstevel@tonic-gate break;
3967c478bd9Sstevel@tonic-gate }
3977c478bd9Sstevel@tonic-gate if (*tspp == NULL) {
3987c478bd9Sstevel@tonic-gate mutex_exit(&hs_mounttab_lock);
3997c478bd9Sstevel@tonic-gate panic("hsfs_unmount: vfs not mounted?");
4007c478bd9Sstevel@tonic-gate /*NOTREACHED*/
4017c478bd9Sstevel@tonic-gate }
4027c478bd9Sstevel@tonic-gate
4037c478bd9Sstevel@tonic-gate *tspp = fsp->hsfs_next;
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate mutex_exit(&hs_mounttab_lock);
4067c478bd9Sstevel@tonic-gate
40784b82766Smg147109 hsfs_fini_kstats(fsp);
408da6c28aaSamw (void) VOP_CLOSE(fsp->hsfs_devvp, FREAD, 1, (offset_t)0, cr, NULL);
4097c478bd9Sstevel@tonic-gate VN_RELE(fsp->hsfs_devvp);
4107c478bd9Sstevel@tonic-gate /* free path table space */
4117c478bd9Sstevel@tonic-gate if (fsp->hsfs_ptbl != NULL)
412d10b6702Sfrankho kmem_free(fsp->hsfs_ptbl, (size_t)fsp->hsfs_vol.ptbl_len);
4137c478bd9Sstevel@tonic-gate /* free path table index table */
4147c478bd9Sstevel@tonic-gate if (fsp->hsfs_ptbl_idx != NULL)
4157c478bd9Sstevel@tonic-gate kmem_free(fsp->hsfs_ptbl_idx, (size_t)
4167c478bd9Sstevel@tonic-gate (fsp->hsfs_ptbl_idx_size * sizeof (struct ptable_idx)));
4177c478bd9Sstevel@tonic-gate
4187c478bd9Sstevel@tonic-gate /* free "mounted on" pathame */
4197c478bd9Sstevel@tonic-gate if (fsp->hsfs_fsmnt != NULL)
4207c478bd9Sstevel@tonic-gate kmem_free(fsp->hsfs_fsmnt, strlen(fsp->hsfs_fsmnt) + 1);
4217c478bd9Sstevel@tonic-gate
42284b82766Smg147109 hsched_fini(fsp->hqueue);
42384b82766Smg147109 kmem_free(fsp->hqueue, sizeof (struct hsfs_queue));
42484b82766Smg147109
4257c478bd9Sstevel@tonic-gate mutex_destroy(&fsp->hsfs_free_lock);
4267c478bd9Sstevel@tonic-gate rw_destroy(&fsp->hsfs_hash_lock);
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate kmem_free(fsp, sizeof (*fsp));
4297c478bd9Sstevel@tonic-gate return (0);
4307c478bd9Sstevel@tonic-gate }
4317c478bd9Sstevel@tonic-gate
4327c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4337c478bd9Sstevel@tonic-gate static int
hsfs_root(struct vfs * vfsp,struct vnode ** vpp)4347c478bd9Sstevel@tonic-gate hsfs_root(struct vfs *vfsp, struct vnode **vpp)
4357c478bd9Sstevel@tonic-gate {
4367c478bd9Sstevel@tonic-gate *vpp = (VFS_TO_HSFS(vfsp))->hsfs_rootvp;
4377c478bd9Sstevel@tonic-gate VN_HOLD(*vpp);
4387c478bd9Sstevel@tonic-gate return (0);
4397c478bd9Sstevel@tonic-gate }
4407c478bd9Sstevel@tonic-gate
4417c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4427c478bd9Sstevel@tonic-gate static int
hsfs_statvfs(struct vfs * vfsp,struct statvfs64 * sbp)4437c478bd9Sstevel@tonic-gate hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp)
4447c478bd9Sstevel@tonic-gate {
4457c478bd9Sstevel@tonic-gate struct hsfs *fsp;
4467c478bd9Sstevel@tonic-gate dev32_t d32;
4477c478bd9Sstevel@tonic-gate
4487c478bd9Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp);
4497c478bd9Sstevel@tonic-gate if (fsp->hsfs_magic != HSFS_MAGIC)
4507c478bd9Sstevel@tonic-gate return (EINVAL);
4517c478bd9Sstevel@tonic-gate bzero(sbp, sizeof (*sbp));
4527c478bd9Sstevel@tonic-gate sbp->f_bsize = vfsp->vfs_bsize;
4537c478bd9Sstevel@tonic-gate sbp->f_frsize = sbp->f_bsize; /* no fragment, same as block size */
4547c478bd9Sstevel@tonic-gate sbp->f_blocks = (fsblkcnt64_t)fsp->hsfs_vol.vol_size;
4557c478bd9Sstevel@tonic-gate
4567c478bd9Sstevel@tonic-gate sbp->f_bfree = (fsblkcnt64_t)0;
4577c478bd9Sstevel@tonic-gate sbp->f_bavail = (fsblkcnt64_t)0;
4587c478bd9Sstevel@tonic-gate sbp->f_files = (fsfilcnt64_t)-1;
4597c478bd9Sstevel@tonic-gate sbp->f_ffree = (fsfilcnt64_t)0;
4607c478bd9Sstevel@tonic-gate sbp->f_favail = (fsfilcnt64_t)0;
4617c478bd9Sstevel@tonic-gate (void) cmpldev(&d32, vfsp->vfs_dev);
4627c478bd9Sstevel@tonic-gate sbp->f_fsid = d32;
4637c478bd9Sstevel@tonic-gate (void) strcpy(sbp->f_basetype, vfssw[vfsp->vfs_fstype].vsw_name);
4647c478bd9Sstevel@tonic-gate sbp->f_flag = vf_to_stf(vfsp->vfs_flag);
4657c478bd9Sstevel@tonic-gate sbp->f_namemax = fsp->hsfs_namemax;
4667c478bd9Sstevel@tonic-gate (void) strcpy(sbp->f_fstr, fsp->hsfs_vol.vol_id);
4677c478bd9Sstevel@tonic-gate
4687c478bd9Sstevel@tonic-gate return (0);
4697c478bd9Sstevel@tonic-gate }
4707c478bd9Sstevel@tonic-gate
4717c478bd9Sstevel@tonic-gate /*
4727c478bd9Sstevel@tonic-gate * Previously nodeid was declared as uint32_t. This has been changed
4737c478bd9Sstevel@tonic-gate * to conform better with the ISO9660 standard. The standard states that
4747c478bd9Sstevel@tonic-gate * a LBN can be a 32 bit number, as the MAKE_NODEID macro shifts this
4757c478bd9Sstevel@tonic-gate * LBN 11 places left (LBN_TO_BYTE) and then shifts the result 5 right
4767c478bd9Sstevel@tonic-gate * (divide by 32) we are left with the potential of an overflow if
4777c478bd9Sstevel@tonic-gate * confined to a 32 bit value.
4787c478bd9Sstevel@tonic-gate */
4797c478bd9Sstevel@tonic-gate
4807c478bd9Sstevel@tonic-gate static int
hsfs_vget(struct vfs * vfsp,struct vnode ** vpp,struct fid * fidp)4817c478bd9Sstevel@tonic-gate hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp)
4827c478bd9Sstevel@tonic-gate {
4837c478bd9Sstevel@tonic-gate struct hsfid *fid;
4847c478bd9Sstevel@tonic-gate struct hsfs *fsp;
4857c478bd9Sstevel@tonic-gate ino64_t nodeid;
4867c478bd9Sstevel@tonic-gate int error;
4877c478bd9Sstevel@tonic-gate
4887c478bd9Sstevel@tonic-gate fsp = (struct hsfs *)VFS_TO_HSFS(vfsp);
4897c478bd9Sstevel@tonic-gate fid = (struct hsfid *)fidp;
4907c478bd9Sstevel@tonic-gate
4917c478bd9Sstevel@tonic-gate /*
4927c478bd9Sstevel@tonic-gate * Look for vnode on hashlist.
4937c478bd9Sstevel@tonic-gate * If found, it's now active and the refcnt was incremented.
4947c478bd9Sstevel@tonic-gate */
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gate rw_enter(&fsp->hsfs_hash_lock, RW_READER);
4977c478bd9Sstevel@tonic-gate
498d10b6702Sfrankho nodeid = fid->hf_ino;
4997c478bd9Sstevel@tonic-gate
500d10b6702Sfrankho if ((*vpp = hs_findhash(nodeid, fid->hf_dir_lbn,
501d10b6702Sfrankho (uint_t)fid->hf_dir_off, vfsp)) == NULL) {
5027c478bd9Sstevel@tonic-gate /*
5037c478bd9Sstevel@tonic-gate * Not in cache, so we need to remake it.
5047c478bd9Sstevel@tonic-gate * hs_remakenode() will read the directory entry
5057c478bd9Sstevel@tonic-gate * and then check again to see if anyone else has
5067c478bd9Sstevel@tonic-gate * put it in the cache.
5077c478bd9Sstevel@tonic-gate */
5087c478bd9Sstevel@tonic-gate rw_exit(&fsp->hsfs_hash_lock);
5097c478bd9Sstevel@tonic-gate error = hs_remakenode(fid->hf_dir_lbn, (uint_t)fid->hf_dir_off,
5107c478bd9Sstevel@tonic-gate vfsp, vpp);
5117c478bd9Sstevel@tonic-gate return (error);
5127c478bd9Sstevel@tonic-gate }
5137c478bd9Sstevel@tonic-gate rw_exit(&fsp->hsfs_hash_lock);
5147c478bd9Sstevel@tonic-gate return (0);
5157c478bd9Sstevel@tonic-gate }
5167c478bd9Sstevel@tonic-gate
5177c478bd9Sstevel@tonic-gate
5187c478bd9Sstevel@tonic-gate #define CHECKSUM_SIZE (64 * 1024)
5197c478bd9Sstevel@tonic-gate
5207c478bd9Sstevel@tonic-gate /*
5217c478bd9Sstevel@tonic-gate * Compute a CD-ROM fsid by checksumming the first 64K of data on the CD
5227c478bd9Sstevel@tonic-gate * We use the 'fsp' argument to determine the location of the root
5237c478bd9Sstevel@tonic-gate * directory entry, and we start reading from there.
5247c478bd9Sstevel@tonic-gate */
5257c478bd9Sstevel@tonic-gate static int
compute_cdrom_id(struct hsfs * fsp,vnode_t * devvp)5267c478bd9Sstevel@tonic-gate compute_cdrom_id(struct hsfs *fsp, vnode_t *devvp)
5277c478bd9Sstevel@tonic-gate {
5287c478bd9Sstevel@tonic-gate uint_t secno;
5297c478bd9Sstevel@tonic-gate struct hs_volume *hsvp = &fsp->hsfs_vol;
5307c478bd9Sstevel@tonic-gate struct buf *bp;
5317c478bd9Sstevel@tonic-gate int error;
5327c478bd9Sstevel@tonic-gate int fsid;
5337c478bd9Sstevel@tonic-gate
5347c478bd9Sstevel@tonic-gate secno = hsvp->root_dir.ext_lbn >> hsvp->lbn_secshift;
535cf83459aSfrankho bp = bread(devvp->v_rdev, secno * 4, CHECKSUM_SIZE);
5367c478bd9Sstevel@tonic-gate error = geterror(bp);
537cf83459aSfrankho
538cf83459aSfrankho /*
539cf83459aSfrankho * An error on read or a partial read means we asked
540cf83459aSfrankho * for a nonexistant/corrupted piece of the device
541cf83459aSfrankho * (including past-the-end of the media). Don't
542cf83459aSfrankho * try to use the checksumming method then.
543cf83459aSfrankho */
544cf83459aSfrankho if (!error && bp->b_bcount == CHECKSUM_SIZE) {
5457c478bd9Sstevel@tonic-gate int *ibuf = (int *)bp->b_un.b_addr;
5467c478bd9Sstevel@tonic-gate int i;
5477c478bd9Sstevel@tonic-gate
5487c478bd9Sstevel@tonic-gate fsid = 0;
5497c478bd9Sstevel@tonic-gate
550cf83459aSfrankho for (i = 0; i < CHECKSUM_SIZE / sizeof (int); i++)
5517c478bd9Sstevel@tonic-gate fsid ^= ibuf[ i ];
552cf83459aSfrankho } else {
553cf83459aSfrankho /*
554cf83459aSfrankho * Fallback - use creation date
555cf83459aSfrankho */
5567c478bd9Sstevel@tonic-gate fsid = hsvp->cre_date.tv_sec;
557cf83459aSfrankho }
5587c478bd9Sstevel@tonic-gate
5597c478bd9Sstevel@tonic-gate brelse(bp);
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate return (fsid);
5627c478bd9Sstevel@tonic-gate }
5637c478bd9Sstevel@tonic-gate
5647c478bd9Sstevel@tonic-gate
5657c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5667c478bd9Sstevel@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)5677c478bd9Sstevel@tonic-gate hs_mountfs(
5687c478bd9Sstevel@tonic-gate struct vfs *vfsp,
5697c478bd9Sstevel@tonic-gate dev_t dev,
5707c478bd9Sstevel@tonic-gate char *path,
5717c478bd9Sstevel@tonic-gate mode_t mode,
5727c478bd9Sstevel@tonic-gate int mount_flags,
5737c478bd9Sstevel@tonic-gate struct cred *cr,
5747c478bd9Sstevel@tonic-gate int isroot)
5757c478bd9Sstevel@tonic-gate {
5767c478bd9Sstevel@tonic-gate struct vnode *devvp;
5777c478bd9Sstevel@tonic-gate struct hsfs *tsp;
5787c478bd9Sstevel@tonic-gate struct hsfs *fsp = NULL;
5797c478bd9Sstevel@tonic-gate struct vattr vap;
5807c478bd9Sstevel@tonic-gate struct hsnode *hp;
5817c478bd9Sstevel@tonic-gate int error;
5827c478bd9Sstevel@tonic-gate struct timeval tv;
5837c478bd9Sstevel@tonic-gate int fsid;
584fc1c62b8Sfrankho int use_rrip;
585fc1c62b8Sfrankho int use_vers2;
586fc1c62b8Sfrankho int use_joliet;
587fc1c62b8Sfrankho int has_rrip = 0;
588fc1c62b8Sfrankho int has_vers2 = 0;
589fc1c62b8Sfrankho int has_joliet = 0;
590fc1c62b8Sfrankho int force_rrip_off;
591fc1c62b8Sfrankho int force_vers2_off;
592fc1c62b8Sfrankho int force_joliet_off;
593fc1c62b8Sfrankho size_t pathbufsz = strlen(path) + 1;
594fc1c62b8Sfrankho int redo_rootvp;
595fc1c62b8Sfrankho
59676a4d1fdSdanmcd struct hs_volume *svp = NULL; /* Supplemental VD for ISO-9660:1999 */
59776a4d1fdSdanmcd struct hs_volume *jvp = NULL; /* Joliet VD */
598fc1c62b8Sfrankho
599fc1c62b8Sfrankho /*
600fc1c62b8Sfrankho * The rules for which extension will be used are:
601fc1c62b8Sfrankho * 1. No specific mount options given:
602fc1c62b8Sfrankho * - use rrip if available
603fc1c62b8Sfrankho * - use ISO9660:1999 if available
604fc1c62b8Sfrankho * - use joliet if available.
605fc1c62b8Sfrankho * 2. rrip/ISO9660:1999/joliet explicitly disabled via mount option:
606fc1c62b8Sfrankho * - use next "lower" extension
607fc1c62b8Sfrankho * 3. joliet/ISO9660:1999/rrip explicitly requested via mount option:
608fc1c62b8Sfrankho * - disable rrip support even if available
609fc1c62b8Sfrankho * - disable IOS9660:1999 support even if available
610fc1c62b8Sfrankho *
611fc1c62b8Sfrankho * We need to adjust these flags as we discover the extensions
612fc1c62b8Sfrankho * present. See below. These are just the starting values.
613fc1c62b8Sfrankho */
614fc1c62b8Sfrankho use_rrip = (mount_flags & HSFSMNT_NORRIP) == 0;
615fc1c62b8Sfrankho use_vers2 = (mount_flags & HSFSMNT_NOVERS2) == 0;
616fc1c62b8Sfrankho use_joliet = (mount_flags & HSFSMNT_NOJOLIET) == 0;
6177c478bd9Sstevel@tonic-gate
6187c478bd9Sstevel@tonic-gate /*
6197c478bd9Sstevel@tonic-gate * Open the device
6207c478bd9Sstevel@tonic-gate */
6217c478bd9Sstevel@tonic-gate devvp = makespecvp(dev, VBLK);
6227c478bd9Sstevel@tonic-gate ASSERT(devvp != 0);
6237c478bd9Sstevel@tonic-gate
6247c478bd9Sstevel@tonic-gate /*
6257c478bd9Sstevel@tonic-gate * Open the target device (file) for read only.
6267c478bd9Sstevel@tonic-gate */
627da6c28aaSamw if (error = VOP_OPEN(&devvp, FREAD, cr, NULL)) {
6287c478bd9Sstevel@tonic-gate VN_RELE(devvp);
6297c478bd9Sstevel@tonic-gate return (error);
6307c478bd9Sstevel@tonic-gate }
6317c478bd9Sstevel@tonic-gate
6327c478bd9Sstevel@tonic-gate /*
6337c478bd9Sstevel@tonic-gate * Refuse to go any further if this
6347c478bd9Sstevel@tonic-gate * device is being used for swapping
6357c478bd9Sstevel@tonic-gate */
6367c478bd9Sstevel@tonic-gate if (IS_SWAPVP(common_specvp(devvp))) {
6377c478bd9Sstevel@tonic-gate error = EBUSY;
6387c478bd9Sstevel@tonic-gate goto cleanup;
6397c478bd9Sstevel@tonic-gate }
6407c478bd9Sstevel@tonic-gate
6417c478bd9Sstevel@tonic-gate vap.va_mask = AT_SIZE;
642da6c28aaSamw if ((error = VOP_GETATTR(devvp, &vap, ATTR_COMM, cr, NULL)) != 0) {
6437c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "Cannot get attributes of the CD-ROM driver");
6447c478bd9Sstevel@tonic-gate goto cleanup;
6457c478bd9Sstevel@tonic-gate }
6467c478bd9Sstevel@tonic-gate
6477c478bd9Sstevel@tonic-gate /*
6487c478bd9Sstevel@tonic-gate * Make sure we have a nonzero size partition.
6497c478bd9Sstevel@tonic-gate * The current version of the SD driver will *not* fail the open
6507c478bd9Sstevel@tonic-gate * of such a partition so we have to check for it here.
6517c478bd9Sstevel@tonic-gate */
6527c478bd9Sstevel@tonic-gate if (vap.va_size == 0) {
6537c478bd9Sstevel@tonic-gate error = ENXIO;
6547c478bd9Sstevel@tonic-gate goto cleanup;
6557c478bd9Sstevel@tonic-gate }
6567c478bd9Sstevel@tonic-gate
6577c478bd9Sstevel@tonic-gate /*
6587c478bd9Sstevel@tonic-gate * Init a new hsfs structure.
6597c478bd9Sstevel@tonic-gate */
6607c478bd9Sstevel@tonic-gate fsp = kmem_zalloc(sizeof (*fsp), KM_SLEEP);
661fc1c62b8Sfrankho svp = kmem_zalloc(sizeof (*svp), KM_SLEEP);
662fc1c62b8Sfrankho jvp = kmem_zalloc(sizeof (*jvp), KM_SLEEP);
6637c478bd9Sstevel@tonic-gate
6647c478bd9Sstevel@tonic-gate /* hardwire perms, uid, gid */
6657c478bd9Sstevel@tonic-gate fsp->hsfs_vol.vol_uid = hsfs_default_uid;
6667c478bd9Sstevel@tonic-gate fsp->hsfs_vol.vol_gid = hsfs_default_gid;
6677c478bd9Sstevel@tonic-gate fsp->hsfs_vol.vol_prot = hsfs_default_mode;
668fc1c62b8Sfrankho svp->vol_uid = hsfs_default_uid;
669fc1c62b8Sfrankho svp->vol_gid = hsfs_default_gid;
670fc1c62b8Sfrankho svp->vol_prot = hsfs_default_mode;
671fc1c62b8Sfrankho jvp->vol_uid = hsfs_default_uid;
672fc1c62b8Sfrankho jvp->vol_gid = hsfs_default_gid;
673fc1c62b8Sfrankho jvp->vol_prot = hsfs_default_mode;
6747c478bd9Sstevel@tonic-gate
6757c478bd9Sstevel@tonic-gate /*
6767c478bd9Sstevel@tonic-gate * Look for a Standard File Structure Volume Descriptor,
6777c478bd9Sstevel@tonic-gate * of which there must be at least one.
6787c478bd9Sstevel@tonic-gate * If found, check for volume size consistency.
679fc1c62b8Sfrankho *
680fc1c62b8Sfrankho * If svp->lbn_size is != 0, we did find a ISO-9660:1999 SVD
681fc1c62b8Sfrankho * If jvp->lbn_size is != 0, we did find a Joliet SVD.
6827c478bd9Sstevel@tonic-gate */
683fc1c62b8Sfrankho fsp->hsfs_namemax = ISO_FILE_NAMELEN;
684fc1c62b8Sfrankho fsp->hsfs_namelen = ISO_FILE_NAMELEN;
685fc1c62b8Sfrankho error = hs_findisovol(fsp, devvp, &fsp->hsfs_vol, svp, jvp);
68654e0249cSfrankho if (error == EINVAL) /* no iso 9660 - try high sierra ... */
68754e0249cSfrankho error = hs_findhsvol(fsp, devvp, &fsp->hsfs_vol);
6887c478bd9Sstevel@tonic-gate
6897c478bd9Sstevel@tonic-gate if (error)
6907c478bd9Sstevel@tonic-gate goto cleanup;
6917c478bd9Sstevel@tonic-gate
692fc1c62b8Sfrankho DTRACE_PROBE4(findvol,
693fc1c62b8Sfrankho struct hsfs *, fsp,
694fc1c62b8Sfrankho struct hs_volume *, &fsp->hsfs_vol,
695fc1c62b8Sfrankho struct hs_volume *, svp,
696fc1c62b8Sfrankho struct hs_volume *, jvp);
697fc1c62b8Sfrankho
6987c478bd9Sstevel@tonic-gate /*
6997c478bd9Sstevel@tonic-gate * Generate a file system ID from the CD-ROM,
7007c478bd9Sstevel@tonic-gate * and check it for uniqueness.
7017c478bd9Sstevel@tonic-gate *
7027c478bd9Sstevel@tonic-gate * What we are aiming for is some chance of integrity
7037c478bd9Sstevel@tonic-gate * across disk change. That is, if a client has an fhandle,
7047c478bd9Sstevel@tonic-gate * it will be valid as long as the same disk is mounted.
7057c478bd9Sstevel@tonic-gate */
7067c478bd9Sstevel@tonic-gate fsid = compute_cdrom_id(fsp, devvp);
7077c478bd9Sstevel@tonic-gate
7087c478bd9Sstevel@tonic-gate mutex_enter(&hs_mounttab_lock);
7097c478bd9Sstevel@tonic-gate
7107c478bd9Sstevel@tonic-gate if (fsid == 0 || fsid == -1) {
7117c478bd9Sstevel@tonic-gate uniqtime(&tv);
7127c478bd9Sstevel@tonic-gate fsid = tv.tv_sec;
7137c478bd9Sstevel@tonic-gate } else /* make sure that the fsid is unique */
7147c478bd9Sstevel@tonic-gate for (tsp = hs_mounttab; tsp != NULL; tsp = tsp->hsfs_next) {
7157c478bd9Sstevel@tonic-gate if (fsid == tsp->hsfs_vfs->vfs_fsid.val[0]) {
7167c478bd9Sstevel@tonic-gate uniqtime(&tv);
7177c478bd9Sstevel@tonic-gate fsid = tv.tv_sec;
7187c478bd9Sstevel@tonic-gate break;
7197c478bd9Sstevel@tonic-gate }
7207c478bd9Sstevel@tonic-gate }
7217c478bd9Sstevel@tonic-gate
7227c478bd9Sstevel@tonic-gate fsp->hsfs_next = hs_mounttab;
7237c478bd9Sstevel@tonic-gate hs_mounttab = fsp;
7247c478bd9Sstevel@tonic-gate
7257c478bd9Sstevel@tonic-gate fsp->hsfs_devvp = devvp;
7267c478bd9Sstevel@tonic-gate fsp->hsfs_vfs = vfsp;
727fc1c62b8Sfrankho fsp->hsfs_fsmnt = kmem_alloc(pathbufsz, KM_SLEEP);
728fc1c62b8Sfrankho (void) strlcpy(fsp->hsfs_fsmnt, path, pathbufsz);
7297c478bd9Sstevel@tonic-gate
7307c478bd9Sstevel@tonic-gate mutex_init(&fsp->hsfs_free_lock, NULL, MUTEX_DEFAULT, NULL);
7317c478bd9Sstevel@tonic-gate rw_init(&fsp->hsfs_hash_lock, NULL, RW_DEFAULT, NULL);
7327c478bd9Sstevel@tonic-gate
7337c478bd9Sstevel@tonic-gate vfsp->vfs_data = (caddr_t)fsp;
7347c478bd9Sstevel@tonic-gate vfsp->vfs_dev = dev;
7357c478bd9Sstevel@tonic-gate vfsp->vfs_fstype = hsfsfstype;
7367c478bd9Sstevel@tonic-gate vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size; /* %% */
7377c478bd9Sstevel@tonic-gate vfsp->vfs_fsid.val[0] = fsid;
7387c478bd9Sstevel@tonic-gate vfsp->vfs_fsid.val[1] = hsfsfstype;
7397c478bd9Sstevel@tonic-gate
740fc1c62b8Sfrankho if (!hs_getrootvp(vfsp, fsp, pathbufsz)) {
741fc1c62b8Sfrankho DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp);
7427c478bd9Sstevel@tonic-gate error = EINVAL;
7437c478bd9Sstevel@tonic-gate goto cleanup;
7447c478bd9Sstevel@tonic-gate }
745fc1c62b8Sfrankho DTRACE_PROBE1(rootvp, struct hsfs *, fsp);
746fc1c62b8Sfrankho
747fc1c62b8Sfrankho /*
748fc1c62b8Sfrankho * Attempt to discover a RR extension.
749fc1c62b8Sfrankho */
750fc1c62b8Sfrankho if (use_rrip) {
751fc1c62b8Sfrankho hp = VTOH(fsp->hsfs_rootvp);
752fc1c62b8Sfrankho hs_check_root_dirent(fsp->hsfs_rootvp, &(hp->hs_dirent));
7537c478bd9Sstevel@tonic-gate }
7547c478bd9Sstevel@tonic-gate
755fc1c62b8Sfrankho has_rrip = IS_RRIP_IMPLEMENTED(fsp);
756fc1c62b8Sfrankho has_vers2 = (svp->lbn_size != 0);
757fc1c62b8Sfrankho has_joliet = (jvp->lbn_size != 0);
758fc1c62b8Sfrankho
759fc1c62b8Sfrankho DTRACE_PROBE4(voltype__suggested, struct hsfs *, fsp,
760fc1c62b8Sfrankho int, use_rrip, int, use_vers2, int, use_joliet);
761fc1c62b8Sfrankho
762fc1c62b8Sfrankho DTRACE_PROBE4(voltype__actual, struct hsfs *, fsp,
763fc1c62b8Sfrankho int, has_rrip, int, has_vers2, int, has_joliet);
764fc1c62b8Sfrankho
765fc1c62b8Sfrankho DTRACE_PROBE4(findvol,
766fc1c62b8Sfrankho struct hsfs *, fsp,
767fc1c62b8Sfrankho struct hs_volume *, &fsp->hsfs_vol,
768fc1c62b8Sfrankho struct hs_volume *, svp,
769fc1c62b8Sfrankho struct hs_volume *, jvp);
770fc1c62b8Sfrankho
771fc1c62b8Sfrankho force_rrip_off = !use_rrip ||
772fc1c62b8Sfrankho (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet) ||
773fc1c62b8Sfrankho (vfs_optionisset(vfsp, HOPT_VERS2, NULL) && has_vers2);
774fc1c62b8Sfrankho
775fc1c62b8Sfrankho force_vers2_off = !use_vers2 ||
776fc1c62b8Sfrankho (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet);
777fc1c62b8Sfrankho
778fc1c62b8Sfrankho force_joliet_off = !use_joliet;
779fc1c62b8Sfrankho
780fc1c62b8Sfrankho DTRACE_PROBE4(voltype__force_off, struct hsfs *, fsp,
781fc1c62b8Sfrankho int, force_rrip_off, int, force_vers2_off, int, force_joliet_off);
782fc1c62b8Sfrankho
783fc1c62b8Sfrankho /*
784fc1c62b8Sfrankho * At the moment, we have references of all three possible
785fc1c62b8Sfrankho * extensions (RR, ISO9660:1999/v2 and Joliet) if present.
786fc1c62b8Sfrankho *
787fc1c62b8Sfrankho * The "active" volume descriptor is RRIP (or ISO9660:1988).
788fc1c62b8Sfrankho * We now switch to the user-requested one.
789fc1c62b8Sfrankho */
790fc1c62b8Sfrankho redo_rootvp = 0;
791fc1c62b8Sfrankho
792fc1c62b8Sfrankho if (force_rrip_off || !has_rrip) {
793fc1c62b8Sfrankho if (has_vers2 && !force_vers2_off) {
794fc1c62b8Sfrankho VN_RELE(fsp->hsfs_rootvp);
795fc1c62b8Sfrankho bcopy(svp, &fsp->hsfs_vol, sizeof (struct hs_volume));
796fc1c62b8Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_ISO_V2;
797fc1c62b8Sfrankho vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size;
798fc1c62b8Sfrankho redo_rootvp = 1;
799fc1c62b8Sfrankho has_joliet = 0;
800fc1c62b8Sfrankho } else if (has_joliet && !force_joliet_off) {
801fc1c62b8Sfrankho VN_RELE(fsp->hsfs_rootvp);
802fc1c62b8Sfrankho bcopy(jvp, &fsp->hsfs_vol, sizeof (struct hs_volume));
803fc1c62b8Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_JOLIET;
804fc1c62b8Sfrankho vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size;
805fc1c62b8Sfrankho redo_rootvp = 1;
806fc1c62b8Sfrankho has_vers2 = 0;
807fc1c62b8Sfrankho }
808fc1c62b8Sfrankho }
809fc1c62b8Sfrankho
810fc1c62b8Sfrankho if (redo_rootvp) {
811fc1c62b8Sfrankho /*
812fc1c62b8Sfrankho * Make sure not to use Rock Ridge.
813fc1c62b8Sfrankho */
814fc1c62b8Sfrankho UNSET_IMPL_BIT(fsp, RRIP_BIT);
815fc1c62b8Sfrankho UNSET_SUSP_BIT(fsp);
816fc1c62b8Sfrankho has_rrip = 0;
817fc1c62b8Sfrankho
818fc1c62b8Sfrankho if (!hs_getrootvp(vfsp, fsp, pathbufsz)) {
819fc1c62b8Sfrankho DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp);
820fc1c62b8Sfrankho error = EINVAL;
821fc1c62b8Sfrankho goto cleanup;
822fc1c62b8Sfrankho }
823fc1c62b8Sfrankho DTRACE_PROBE1(rootvp, struct hsfs *, fsp);
824fc1c62b8Sfrankho }
825fc1c62b8Sfrankho if (IS_RRIP_IMPLEMENTED(fsp)) {
826fc1c62b8Sfrankho has_vers2 = 0;
827fc1c62b8Sfrankho has_joliet = 0;
828fc1c62b8Sfrankho }
829fc1c62b8Sfrankho if (force_vers2_off)
830fc1c62b8Sfrankho has_vers2 = 0;
831fc1c62b8Sfrankho if (force_joliet_off)
832fc1c62b8Sfrankho has_joliet = 0;
833fc1c62b8Sfrankho DTRACE_PROBE4(voltype__taken, struct hsfs *, fsp,
834fc1c62b8Sfrankho int, has_rrip, int, has_vers2, int, has_joliet);
835fc1c62b8Sfrankho
836fc1c62b8Sfrankho /*
837fc1c62b8Sfrankho * mark root node as VROOT
838fc1c62b8Sfrankho */
8397c478bd9Sstevel@tonic-gate fsp->hsfs_rootvp->v_flag |= VROOT;
8407c478bd9Sstevel@tonic-gate
8417c478bd9Sstevel@tonic-gate /* Here we take care of some special case stuff for mountroot */
8427c478bd9Sstevel@tonic-gate if (isroot) {
8437c478bd9Sstevel@tonic-gate fsp->hsfs_rootvp->v_rdev = devvp->v_rdev;
8447c478bd9Sstevel@tonic-gate rootvp = fsp->hsfs_rootvp;
8457c478bd9Sstevel@tonic-gate }
8467c478bd9Sstevel@tonic-gate
847fc1c62b8Sfrankho if (IS_RRIP_IMPLEMENTED(fsp)) {
8487c478bd9Sstevel@tonic-gate /*
8497c478bd9Sstevel@tonic-gate * if RRIP, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags
8507c478bd9Sstevel@tonic-gate */
8517c478bd9Sstevel@tonic-gate mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT);
8527c478bd9Sstevel@tonic-gate
853fc1c62b8Sfrankho fsp->hsfs_namemax = RRIP_FILE_NAMELEN;
854fc1c62b8Sfrankho fsp->hsfs_namelen = RRIP_FILE_NAMELEN;
855fc1c62b8Sfrankho
856fc1c62b8Sfrankho ASSERT(vfs_optionisset(vfsp, HOPT_RR, NULL));
857fc1c62b8Sfrankho vfs_clearmntopt(vfsp, HOPT_VERS2);
858fc1c62b8Sfrankho vfs_clearmntopt(vfsp, HOPT_JOLIET);
859fc1c62b8Sfrankho
860fc1c62b8Sfrankho } else switch (fsp->hsfs_vol_type) {
861fc1c62b8Sfrankho
862fc1c62b8Sfrankho case HS_VOL_TYPE_HS:
863fc1c62b8Sfrankho case HS_VOL_TYPE_ISO:
864fc1c62b8Sfrankho default:
865fc1c62b8Sfrankho /*
866fc1c62b8Sfrankho * if iso v1, don't allow trailing spaces in iso file names
867fc1c62b8Sfrankho */
868fc1c62b8Sfrankho mount_flags |= HSFSMNT_NOTRAILSPACE;
869fc1c62b8Sfrankho fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX;
870fc1c62b8Sfrankho fsp->hsfs_namelen = ISO_FILE_NAMELEN;
871fc1c62b8Sfrankho vfs_clearmntopt(vfsp, HOPT_RR);
872fc1c62b8Sfrankho vfs_clearmntopt(vfsp, HOPT_VERS2);
873fc1c62b8Sfrankho vfs_clearmntopt(vfsp, HOPT_JOLIET);
874fc1c62b8Sfrankho break;
875fc1c62b8Sfrankho
876fc1c62b8Sfrankho case HS_VOL_TYPE_ISO_V2:
877fc1c62b8Sfrankho /*
878fc1c62b8Sfrankho * if iso v2, don't copy NOTRAILDOT to hsfs_flags
879fc1c62b8Sfrankho */
880fc1c62b8Sfrankho mount_flags &= ~HSFSMNT_NOTRAILDOT;
881fc1c62b8Sfrankho mount_flags |= HSFSMNT_NOMAPLCASE | HSFSMNT_NOVERSION;
882fc1c62b8Sfrankho fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX;
883fc1c62b8Sfrankho fsp->hsfs_namelen = ISO_NAMELEN_V2;
884fc1c62b8Sfrankho vfs_setmntopt(vfsp, HOPT_VERS2, NULL, 0);
885fc1c62b8Sfrankho vfs_clearmntopt(vfsp, HOPT_RR);
886fc1c62b8Sfrankho vfs_clearmntopt(vfsp, HOPT_JOLIET);
887fc1c62b8Sfrankho break;
888fc1c62b8Sfrankho
889fc1c62b8Sfrankho case HS_VOL_TYPE_JOLIET:
890fc1c62b8Sfrankho /*
891fc1c62b8Sfrankho * if Joliet, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags
892fc1c62b8Sfrankho */
893fc1c62b8Sfrankho mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT);
894fc1c62b8Sfrankho mount_flags |= HSFSMNT_NOMAPLCASE;
895fc1c62b8Sfrankho if (mount_flags & HSFSMNT_JOLIETLONG)
896fc1c62b8Sfrankho fsp->hsfs_namemax = JOLIET_NAMELEN_MAX*3; /* UTF-8 */
897fc1c62b8Sfrankho else
898fc1c62b8Sfrankho fsp->hsfs_namemax = MAXNAMELEN-1;
899fc1c62b8Sfrankho fsp->hsfs_namelen = JOLIET_NAMELEN*2;
900fc1c62b8Sfrankho vfs_setmntopt(vfsp, HOPT_JOLIET, NULL, 0);
901fc1c62b8Sfrankho vfs_clearmntopt(vfsp, HOPT_RR);
902fc1c62b8Sfrankho vfs_clearmntopt(vfsp, HOPT_VERS2);
903fc1c62b8Sfrankho break;
904fc1c62b8Sfrankho }
905fc1c62b8Sfrankho
906d10b6702Sfrankho /*
907d10b6702Sfrankho * Add the HSFSMNT_INODE pseudo mount flag to the current mount flags.
908d10b6702Sfrankho */
909d10b6702Sfrankho fsp->hsfs_flags = mount_flags | (fsp->hsfs_flags & HSFSMNT_INODE);
9107c478bd9Sstevel@tonic-gate
91184b82766Smg147109 /*
91284b82766Smg147109 * Setup I/O Scheduling structures
91384b82766Smg147109 */
91484b82766Smg147109 if (do_schedio) {
91584b82766Smg147109 fsp->hqueue = kmem_alloc(sizeof (struct hsfs_queue), KM_SLEEP);
91684b82766Smg147109 hsched_init(fsp, fsid, &modlinkage);
91784b82766Smg147109 }
91884b82766Smg147109
91984b82766Smg147109 /*
92084b82766Smg147109 * Setup kstats
92184b82766Smg147109 */
92284b82766Smg147109 hsfs_init_kstats(fsp, fsid);
92384b82766Smg147109
924fc1c62b8Sfrankho DTRACE_PROBE1(mount__done, struct hsfs *, fsp);
925fc1c62b8Sfrankho
926fc1c62b8Sfrankho /*
927fc1c62b8Sfrankho * set the magic word
928fc1c62b8Sfrankho */
9297c478bd9Sstevel@tonic-gate fsp->hsfs_magic = HSFS_MAGIC;
9307c478bd9Sstevel@tonic-gate mutex_exit(&hs_mounttab_lock);
9317c478bd9Sstevel@tonic-gate
932d10b6702Sfrankho kmem_free(svp, sizeof (*svp));
933d10b6702Sfrankho kmem_free(jvp, sizeof (*jvp));
934d10b6702Sfrankho
9357c478bd9Sstevel@tonic-gate return (0);
9367c478bd9Sstevel@tonic-gate
9377c478bd9Sstevel@tonic-gate cleanup:
938da6c28aaSamw (void) VOP_CLOSE(devvp, FREAD, 1, (offset_t)0, cr, NULL);
9397c478bd9Sstevel@tonic-gate VN_RELE(devvp);
9407c478bd9Sstevel@tonic-gate if (fsp)
9417c478bd9Sstevel@tonic-gate kmem_free(fsp, sizeof (*fsp));
942fc1c62b8Sfrankho if (svp)
943fc1c62b8Sfrankho kmem_free(svp, sizeof (*svp));
944fc1c62b8Sfrankho if (jvp)
945fc1c62b8Sfrankho kmem_free(jvp, sizeof (*jvp));
9467c478bd9Sstevel@tonic-gate return (error);
9477c478bd9Sstevel@tonic-gate }
9487c478bd9Sstevel@tonic-gate
9497c478bd9Sstevel@tonic-gate /*
950fc1c62b8Sfrankho * Get the rootvp associated with fsp->hsfs_vol
951fc1c62b8Sfrankho */
952fc1c62b8Sfrankho static int
hs_getrootvp(struct vfs * vfsp,struct hsfs * fsp,size_t pathsize)953fc1c62b8Sfrankho hs_getrootvp(
954fc1c62b8Sfrankho struct vfs *vfsp,
955fc1c62b8Sfrankho struct hsfs *fsp,
956fc1c62b8Sfrankho size_t pathsize)
957fc1c62b8Sfrankho {
958fc1c62b8Sfrankho struct hsnode *hp;
959fc1c62b8Sfrankho
960fc1c62b8Sfrankho ASSERT(pathsize == strlen(fsp->hsfs_fsmnt) + 1);
961fc1c62b8Sfrankho
962fc1c62b8Sfrankho /*
963fc1c62b8Sfrankho * If the root directory does not appear to be
964fc1c62b8Sfrankho * valid, use what it points to as "." instead.
965fc1c62b8Sfrankho * Some Defense Mapping Agency disks are non-conformant
966fc1c62b8Sfrankho * in this way.
967fc1c62b8Sfrankho */
968fc1c62b8Sfrankho if (!hsfs_valid_dir(&fsp->hsfs_vol.root_dir)) {
969fc1c62b8Sfrankho hs_log_bogus_disk_warning(fsp, HSFS_ERR_BAD_ROOT_DIR, 0);
970fc1c62b8Sfrankho if (hs_remakenode(fsp->hsfs_vol.root_dir.ext_lbn,
971fc1c62b8Sfrankho (uint_t)0, vfsp, &fsp->hsfs_rootvp)) {
972fc1c62b8Sfrankho hs_mounttab = hs_mounttab->hsfs_next;
973fc1c62b8Sfrankho mutex_destroy(&fsp->hsfs_free_lock);
974fc1c62b8Sfrankho rw_destroy(&fsp->hsfs_hash_lock);
975fc1c62b8Sfrankho kmem_free(fsp->hsfs_fsmnt, pathsize);
976fc1c62b8Sfrankho mutex_exit(&hs_mounttab_lock);
977fc1c62b8Sfrankho return (0);
978fc1c62b8Sfrankho }
979fc1c62b8Sfrankho } else {
980fc1c62b8Sfrankho fsp->hsfs_rootvp = hs_makenode(&fsp->hsfs_vol.root_dir,
981fc1c62b8Sfrankho fsp->hsfs_vol.root_dir.ext_lbn, 0, vfsp);
982fc1c62b8Sfrankho }
983fc1c62b8Sfrankho
984fc1c62b8Sfrankho /* XXX - ignore the path table for now */
985fc1c62b8Sfrankho fsp->hsfs_ptbl = NULL;
986fc1c62b8Sfrankho hp = VTOH(fsp->hsfs_rootvp);
987fc1c62b8Sfrankho hp->hs_ptbl_idx = NULL;
988fc1c62b8Sfrankho
989fc1c62b8Sfrankho return (1);
990fc1c62b8Sfrankho }
991fc1c62b8Sfrankho
992fc1c62b8Sfrankho /*
9937c478bd9Sstevel@tonic-gate * hs_findhsvol()
9947c478bd9Sstevel@tonic-gate *
9957c478bd9Sstevel@tonic-gate * Locate the Standard File Structure Volume Descriptor and
9967c478bd9Sstevel@tonic-gate * parse it into an hs_volume structure.
9977c478bd9Sstevel@tonic-gate *
9987c478bd9Sstevel@tonic-gate * XXX - May someday want to look for Coded Character Set FSVD, too.
9997c478bd9Sstevel@tonic-gate */
10007c478bd9Sstevel@tonic-gate static int
hs_findhsvol(struct hsfs * fsp,struct vnode * vp,struct hs_volume * hvp)10017c478bd9Sstevel@tonic-gate hs_findhsvol(struct hsfs *fsp, struct vnode *vp, struct hs_volume *hvp)
10027c478bd9Sstevel@tonic-gate {
10037c478bd9Sstevel@tonic-gate struct buf *secbp;
10047c478bd9Sstevel@tonic-gate int i;
1005d10b6702Sfrankho int n;
10067c478bd9Sstevel@tonic-gate uchar_t *volp;
10077c478bd9Sstevel@tonic-gate int error;
10087c478bd9Sstevel@tonic-gate uint_t secno;
10097c478bd9Sstevel@tonic-gate
10107c478bd9Sstevel@tonic-gate secno = hs_findvoldesc(vp->v_rdev, HS_VOLDESC_SEC);
10117c478bd9Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
10127c478bd9Sstevel@tonic-gate error = geterror(secbp);
10137c478bd9Sstevel@tonic-gate
10147c478bd9Sstevel@tonic-gate if (error != 0) {
10157c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)", error);
10167c478bd9Sstevel@tonic-gate brelse(secbp);
10177c478bd9Sstevel@tonic-gate return (error);
10187c478bd9Sstevel@tonic-gate }
10197c478bd9Sstevel@tonic-gate
10207c478bd9Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr;
10217c478bd9Sstevel@tonic-gate
1022d10b6702Sfrankho /*
1023d10b6702Sfrankho * To avoid that we read the whole medium in case that someone prepares
1024d10b6702Sfrankho * a malicious "fs image", we read at most 32 blocks.
1025d10b6702Sfrankho */
1026d10b6702Sfrankho for (n = 0; n < 32 &&
1027d10b6702Sfrankho HSV_DESC_TYPE(volp) != VD_EOV; n++) {
10287c478bd9Sstevel@tonic-gate for (i = 0; i < HSV_ID_STRLEN; i++)
10297c478bd9Sstevel@tonic-gate if (HSV_STD_ID(volp)[i] != HSV_ID_STRING[i])
10307c478bd9Sstevel@tonic-gate goto cantfind;
10317c478bd9Sstevel@tonic-gate if (HSV_STD_VER(volp) != HSV_ID_VER)
10327c478bd9Sstevel@tonic-gate goto cantfind;
10337c478bd9Sstevel@tonic-gate switch (HSV_DESC_TYPE(volp)) {
10347c478bd9Sstevel@tonic-gate case VD_SFS:
10357c478bd9Sstevel@tonic-gate /* Standard File Structure */
10367c478bd9Sstevel@tonic-gate fsp->hsfs_vol_type = HS_VOL_TYPE_HS;
10377c478bd9Sstevel@tonic-gate error = hs_parsehsvol(fsp, volp, hvp);
10387c478bd9Sstevel@tonic-gate brelse(secbp);
10397c478bd9Sstevel@tonic-gate return (error);
10407c478bd9Sstevel@tonic-gate
10417c478bd9Sstevel@tonic-gate case VD_CCFS:
10427c478bd9Sstevel@tonic-gate /* Coded Character File Structure */
10437c478bd9Sstevel@tonic-gate case VD_BOOT:
10447c478bd9Sstevel@tonic-gate case VD_UNSPEC:
10457c478bd9Sstevel@tonic-gate case VD_EOV:
10467c478bd9Sstevel@tonic-gate break;
10477c478bd9Sstevel@tonic-gate }
10487c478bd9Sstevel@tonic-gate brelse(secbp);
10497c478bd9Sstevel@tonic-gate ++secno;
10507c478bd9Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
10517c478bd9Sstevel@tonic-gate
10527c478bd9Sstevel@tonic-gate error = geterror(secbp);
10537c478bd9Sstevel@tonic-gate
10547c478bd9Sstevel@tonic-gate if (error != 0) {
10557c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)",
10567c478bd9Sstevel@tonic-gate error);
10577c478bd9Sstevel@tonic-gate brelse(secbp);
10587c478bd9Sstevel@tonic-gate return (error);
10597c478bd9Sstevel@tonic-gate }
10607c478bd9Sstevel@tonic-gate
10617c478bd9Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr;
10627c478bd9Sstevel@tonic-gate }
10637c478bd9Sstevel@tonic-gate cantfind:
10647c478bd9Sstevel@tonic-gate brelse(secbp);
10657c478bd9Sstevel@tonic-gate return (EINVAL);
10667c478bd9Sstevel@tonic-gate }
10677c478bd9Sstevel@tonic-gate
10687c478bd9Sstevel@tonic-gate /*
10697c478bd9Sstevel@tonic-gate * hs_parsehsvol
10707c478bd9Sstevel@tonic-gate *
10717c478bd9Sstevel@tonic-gate * Parse the Standard File Structure Volume Descriptor into
10727c478bd9Sstevel@tonic-gate * an hs_volume structure. We can't just bcopy it into the
10737c478bd9Sstevel@tonic-gate * structure because of byte-ordering problems.
10747c478bd9Sstevel@tonic-gate *
10757c478bd9Sstevel@tonic-gate */
10767c478bd9Sstevel@tonic-gate static int
hs_parsehsvol(struct hsfs * fsp,uchar_t * volp,struct hs_volume * hvp)10777c478bd9Sstevel@tonic-gate hs_parsehsvol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp)
10787c478bd9Sstevel@tonic-gate {
10797c478bd9Sstevel@tonic-gate hvp->vol_size = HSV_VOL_SIZE(volp);
10807c478bd9Sstevel@tonic-gate hvp->lbn_size = HSV_BLK_SIZE(volp);
10817c478bd9Sstevel@tonic-gate if (hvp->lbn_size == 0) {
10827c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_parsehsvol: logical block size in the "
10837c478bd9Sstevel@tonic-gate "SFSVD is zero");
10847c478bd9Sstevel@tonic-gate return (EINVAL);
10857c478bd9Sstevel@tonic-gate }
10867c478bd9Sstevel@tonic-gate hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1;
1087d10b6702Sfrankho hvp->lbn_secshift =
1088d10b6702Sfrankho ffs((long)howmany(HS_SECTOR_SIZE, (int)hvp->lbn_size)) - 1;
10897c478bd9Sstevel@tonic-gate hvp->lbn_maxoffset = hvp->lbn_size - 1;
10907c478bd9Sstevel@tonic-gate hs_parse_longdate(HSV_cre_date(volp), &hvp->cre_date);
10917c478bd9Sstevel@tonic-gate hs_parse_longdate(HSV_mod_date(volp), &hvp->mod_date);
10927c478bd9Sstevel@tonic-gate hvp->file_struct_ver = HSV_FILE_STRUCT_VER(volp);
10937c478bd9Sstevel@tonic-gate hvp->ptbl_len = HSV_PTBL_SIZE(volp);
10947c478bd9Sstevel@tonic-gate hvp->vol_set_size = (ushort_t)HSV_SET_SIZE(volp);
10957c478bd9Sstevel@tonic-gate hvp->vol_set_seq = (ushort_t)HSV_SET_SEQ(volp);
10967c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
10977c478bd9Sstevel@tonic-gate hvp->ptbl_lbn = HSV_PTBL_MAN_LS(volp);
10987c478bd9Sstevel@tonic-gate #else
10997c478bd9Sstevel@tonic-gate hvp->ptbl_lbn = HSV_PTBL_MAN_MS(volp);
11007c478bd9Sstevel@tonic-gate #endif
1101fc1c62b8Sfrankho hs_copylabel(hvp, HSV_VOL_ID(volp), 0);
11027c478bd9Sstevel@tonic-gate
11037c478bd9Sstevel@tonic-gate /*
11047c478bd9Sstevel@tonic-gate * Make sure that lbn_size is a power of two and otherwise valid.
11057c478bd9Sstevel@tonic-gate */
11067c478bd9Sstevel@tonic-gate if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) {
11077c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE,
11087c478bd9Sstevel@tonic-gate "hsfs: %d-byte logical block size not supported",
11097c478bd9Sstevel@tonic-gate hvp->lbn_size);
11107c478bd9Sstevel@tonic-gate return (EINVAL);
11117c478bd9Sstevel@tonic-gate }
11127c478bd9Sstevel@tonic-gate return (hs_parsedir(fsp, HSV_ROOT_DIR(volp), &hvp->root_dir,
1113fc1c62b8Sfrankho (char *)NULL, (int *)NULL, HDE_ROOT_DIR_REC_SIZE));
11147c478bd9Sstevel@tonic-gate }
11157c478bd9Sstevel@tonic-gate
11167c478bd9Sstevel@tonic-gate /*
11177c478bd9Sstevel@tonic-gate * hs_findisovol()
11187c478bd9Sstevel@tonic-gate *
11197c478bd9Sstevel@tonic-gate * Locate the Primary Volume Descriptor
11207c478bd9Sstevel@tonic-gate * parse it into an hs_volume structure.
11217c478bd9Sstevel@tonic-gate *
1122fc1c62b8Sfrankho * XXX - Partition not yet done
1123fc1c62b8Sfrankho *
1124fc1c62b8Sfrankho * Except for fsp->hsfs_vol_type, no fsp member may be modified.
1125fc1c62b8Sfrankho * fsp->hsfs_vol is modified indirectly via the *hvp argument.
11267c478bd9Sstevel@tonic-gate */
11277c478bd9Sstevel@tonic-gate static int
hs_findisovol(struct hsfs * fsp,struct vnode * vp,struct hs_volume * hvp,struct hs_volume * svp,struct hs_volume * jvp)11287c478bd9Sstevel@tonic-gate hs_findisovol(struct hsfs *fsp, struct vnode *vp,
1129fc1c62b8Sfrankho struct hs_volume *hvp,
1130fc1c62b8Sfrankho struct hs_volume *svp,
1131fc1c62b8Sfrankho struct hs_volume *jvp)
11327c478bd9Sstevel@tonic-gate {
11337c478bd9Sstevel@tonic-gate struct buf *secbp;
11347c478bd9Sstevel@tonic-gate int i;
1135d10b6702Sfrankho int n;
11367c478bd9Sstevel@tonic-gate uchar_t *volp;
11377c478bd9Sstevel@tonic-gate int error;
11387c478bd9Sstevel@tonic-gate uint_t secno;
11397c478bd9Sstevel@tonic-gate int foundpvd = 0;
1140fc1c62b8Sfrankho int foundsvd = 0;
1141fc1c62b8Sfrankho int foundjvd = 0;
1142d10b6702Sfrankho int pvd_sum = 0;
11437c478bd9Sstevel@tonic-gate
11447c478bd9Sstevel@tonic-gate secno = hs_findvoldesc(vp->v_rdev, ISO_VOLDESC_SEC);
11457c478bd9Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, ISO_SECTOR_SIZE);
11467c478bd9Sstevel@tonic-gate error = geterror(secbp);
11477c478bd9Sstevel@tonic-gate
11487c478bd9Sstevel@tonic-gate if (error != 0) {
11497c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)", error);
11507c478bd9Sstevel@tonic-gate brelse(secbp);
11517c478bd9Sstevel@tonic-gate return (error);
11527c478bd9Sstevel@tonic-gate }
11537c478bd9Sstevel@tonic-gate
11547c478bd9Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr;
11557c478bd9Sstevel@tonic-gate
1156d10b6702Sfrankho /*
1157d10b6702Sfrankho * To avoid that we read the whole medium in case that someone prepares
1158d10b6702Sfrankho * a malicious "fs image", we read at most 32 blocks.
1159d10b6702Sfrankho */
11600c79d02bSRichard Lowe for (n = 0; n < 32 && ISO_DESC_TYPE(volp) != ISO_VD_EOV; n++) {
11617c478bd9Sstevel@tonic-gate for (i = 0; i < ISO_ID_STRLEN; i++)
11627c478bd9Sstevel@tonic-gate if (ISO_STD_ID(volp)[i] != ISO_ID_STRING[i])
11637c478bd9Sstevel@tonic-gate goto cantfind;
11647c478bd9Sstevel@tonic-gate switch (ISO_DESC_TYPE(volp)) {
11657c478bd9Sstevel@tonic-gate case ISO_VD_PVD:
11667c478bd9Sstevel@tonic-gate /* Standard File Structure */
1167fc1c62b8Sfrankho if (ISO_STD_VER(volp) != ISO_ID_VER)
1168fc1c62b8Sfrankho goto cantfind;
11697c478bd9Sstevel@tonic-gate if (foundpvd != 1) {
11707c478bd9Sstevel@tonic-gate fsp->hsfs_vol_type = HS_VOL_TYPE_ISO;
11717c478bd9Sstevel@tonic-gate if (error = hs_parseisovol(fsp, volp, hvp)) {
11727c478bd9Sstevel@tonic-gate brelse(secbp);
11737c478bd9Sstevel@tonic-gate return (error);
11747c478bd9Sstevel@tonic-gate }
11757c478bd9Sstevel@tonic-gate foundpvd = 1;
1176d10b6702Sfrankho for (i = 0; i < ISO_SECTOR_SIZE; i++)
1177d10b6702Sfrankho pvd_sum += volp[i];
11787c478bd9Sstevel@tonic-gate }
11797c478bd9Sstevel@tonic-gate break;
11807c478bd9Sstevel@tonic-gate case ISO_VD_SVD:
11817c478bd9Sstevel@tonic-gate /* Supplementary Volume Descriptor */
1182fc1c62b8Sfrankho if (ISO_STD_VER(volp) == ISO_ID_VER2 &&
1183fc1c62b8Sfrankho foundsvd != 1) {
1184fc1c62b8Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_ISO;
1185fc1c62b8Sfrankho if (error = hs_parseisovol(fsp, volp, svp)) {
1186fc1c62b8Sfrankho brelse(secbp);
1187fc1c62b8Sfrankho return (error);
1188fc1c62b8Sfrankho }
1189fc1c62b8Sfrankho foundsvd = 1;
1190fc1c62b8Sfrankho }
1191fc1c62b8Sfrankho if (hs_joliet_level(volp) >= 1 && foundjvd != 1) {
1192fc1c62b8Sfrankho fsp->hsfs_vol_type = HS_VOL_TYPE_ISO;
1193fc1c62b8Sfrankho if (error = hs_parseisovol(fsp, volp, jvp)) {
1194fc1c62b8Sfrankho brelse(secbp);
1195fc1c62b8Sfrankho return (error);
1196fc1c62b8Sfrankho }
1197fc1c62b8Sfrankho foundjvd = 1;
1198fc1c62b8Sfrankho }
11997c478bd9Sstevel@tonic-gate break;
12007c478bd9Sstevel@tonic-gate case ISO_VD_BOOT:
12017c478bd9Sstevel@tonic-gate break;
12027c478bd9Sstevel@tonic-gate case ISO_VD_VPD:
12037c478bd9Sstevel@tonic-gate /* currently cannot handle partition */
12047c478bd9Sstevel@tonic-gate break;
12057c478bd9Sstevel@tonic-gate case VD_EOV:
12067c478bd9Sstevel@tonic-gate break;
12077c478bd9Sstevel@tonic-gate }
12087c478bd9Sstevel@tonic-gate brelse(secbp);
12097c478bd9Sstevel@tonic-gate ++secno;
12107c478bd9Sstevel@tonic-gate secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
12117c478bd9Sstevel@tonic-gate error = geterror(secbp);
12127c478bd9Sstevel@tonic-gate
12137c478bd9Sstevel@tonic-gate if (error != 0) {
12147c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)",
12157c478bd9Sstevel@tonic-gate error);
12167c478bd9Sstevel@tonic-gate brelse(secbp);
12177c478bd9Sstevel@tonic-gate return (error);
12187c478bd9Sstevel@tonic-gate }
12197c478bd9Sstevel@tonic-gate
12207c478bd9Sstevel@tonic-gate volp = (uchar_t *)secbp->b_un.b_addr;
12217c478bd9Sstevel@tonic-gate }
1222d10b6702Sfrankho for (n = 0; n < 16; n++) {
1223d10b6702Sfrankho brelse(secbp);
1224d10b6702Sfrankho ++secno;
1225d10b6702Sfrankho secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
1226d10b6702Sfrankho error = geterror(secbp);
1227d10b6702Sfrankho
1228d10b6702Sfrankho if (error != 0) {
1229d10b6702Sfrankho cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)",
1230d10b6702Sfrankho error);
1231d10b6702Sfrankho brelse(secbp);
1232d10b6702Sfrankho return (error);
1233d10b6702Sfrankho }
1234d10b6702Sfrankho
1235d10b6702Sfrankho /*
1236d10b6702Sfrankho * Check for the signature from mkisofs that grants that
1237d10b6702Sfrankho * the current filesystem allows to use the extent lbn as
1238d10b6702Sfrankho * inode number even in pure ISO9660 mode.
1239d10b6702Sfrankho */
1240d10b6702Sfrankho volp = (uchar_t *)secbp->b_un.b_addr;
1241d10b6702Sfrankho if (strncmp((char *)volp, "MKI ", 4) == 0) {
1242d10b6702Sfrankho int sum;
1243d10b6702Sfrankho
1244d10b6702Sfrankho sum = volp[2045];
1245d10b6702Sfrankho sum *= 256;
1246d10b6702Sfrankho sum += volp[2046];
1247d10b6702Sfrankho sum *= 256;
1248d10b6702Sfrankho sum += volp[2047];
1249d10b6702Sfrankho if (sum == pvd_sum)
1250d10b6702Sfrankho fsp->hsfs_flags |= HSFSMNT_INODE;
1251d10b6702Sfrankho break;
1252d10b6702Sfrankho }
1253d10b6702Sfrankho }
12547c478bd9Sstevel@tonic-gate if (foundpvd) {
12557c478bd9Sstevel@tonic-gate brelse(secbp);
12567c478bd9Sstevel@tonic-gate return (0);
12577c478bd9Sstevel@tonic-gate }
12587c478bd9Sstevel@tonic-gate cantfind:
12597c478bd9Sstevel@tonic-gate brelse(secbp);
12607c478bd9Sstevel@tonic-gate return (EINVAL);
12617c478bd9Sstevel@tonic-gate }
1262fc1c62b8Sfrankho
1263fc1c62b8Sfrankho /*
1264fc1c62b8Sfrankho * Return 0 if no Joliet is found
1265fc1c62b8Sfrankho * else return Joliet Level 1..3
1266fc1c62b8Sfrankho */
1267fc1c62b8Sfrankho static int
hs_joliet_level(uchar_t * volp)1268fc1c62b8Sfrankho hs_joliet_level(uchar_t *volp)
1269fc1c62b8Sfrankho {
1270fc1c62b8Sfrankho if (ISO_std_ver(volp)[0] == ISO_ID_VER &&
1271fc1c62b8Sfrankho ISO_svd_esc(volp)[0] == '%' &&
1272fc1c62b8Sfrankho ISO_svd_esc(volp)[1] == '/') {
1273fc1c62b8Sfrankho
1274fc1c62b8Sfrankho switch (ISO_svd_esc(volp)[2]) {
1275fc1c62b8Sfrankho
1276fc1c62b8Sfrankho case '@':
1277fc1c62b8Sfrankho return (1);
1278fc1c62b8Sfrankho case 'C':
1279fc1c62b8Sfrankho return (2);
1280fc1c62b8Sfrankho case 'E':
1281fc1c62b8Sfrankho return (3);
1282fc1c62b8Sfrankho }
1283fc1c62b8Sfrankho }
1284fc1c62b8Sfrankho return (0);
1285fc1c62b8Sfrankho }
1286fc1c62b8Sfrankho
12877c478bd9Sstevel@tonic-gate /*
12887c478bd9Sstevel@tonic-gate * hs_parseisovol
12897c478bd9Sstevel@tonic-gate *
12907c478bd9Sstevel@tonic-gate * Parse the Primary Volume Descriptor into an hs_volume structure.
12917c478bd9Sstevel@tonic-gate *
12927c478bd9Sstevel@tonic-gate */
12937c478bd9Sstevel@tonic-gate static int
hs_parseisovol(struct hsfs * fsp,uchar_t * volp,struct hs_volume * hvp)12947c478bd9Sstevel@tonic-gate hs_parseisovol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp)
12957c478bd9Sstevel@tonic-gate {
12967c478bd9Sstevel@tonic-gate hvp->vol_size = ISO_VOL_SIZE(volp);
12977c478bd9Sstevel@tonic-gate hvp->lbn_size = ISO_BLK_SIZE(volp);
12987c478bd9Sstevel@tonic-gate if (hvp->lbn_size == 0) {
12997c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_parseisovol: logical block size in the "
13007c478bd9Sstevel@tonic-gate "PVD is zero");
13017c478bd9Sstevel@tonic-gate return (EINVAL);
13027c478bd9Sstevel@tonic-gate }
13037c478bd9Sstevel@tonic-gate hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1;
1304d10b6702Sfrankho hvp->lbn_secshift =
1305d10b6702Sfrankho ffs((long)howmany(ISO_SECTOR_SIZE, (int)hvp->lbn_size)) - 1;
13067c478bd9Sstevel@tonic-gate hvp->lbn_maxoffset = hvp->lbn_size - 1;
13077c478bd9Sstevel@tonic-gate hs_parse_longdate(ISO_cre_date(volp), &hvp->cre_date);
13087c478bd9Sstevel@tonic-gate hs_parse_longdate(ISO_mod_date(volp), &hvp->mod_date);
13097c478bd9Sstevel@tonic-gate hvp->file_struct_ver = ISO_FILE_STRUCT_VER(volp);
13107c478bd9Sstevel@tonic-gate hvp->ptbl_len = ISO_PTBL_SIZE(volp);
13117c478bd9Sstevel@tonic-gate hvp->vol_set_size = (ushort_t)ISO_SET_SIZE(volp);
13127c478bd9Sstevel@tonic-gate hvp->vol_set_seq = (ushort_t)ISO_SET_SEQ(volp);
13137c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
13147c478bd9Sstevel@tonic-gate hvp->ptbl_lbn = ISO_PTBL_MAN_LS(volp);
13157c478bd9Sstevel@tonic-gate #else
13167c478bd9Sstevel@tonic-gate hvp->ptbl_lbn = ISO_PTBL_MAN_MS(volp);
13177c478bd9Sstevel@tonic-gate #endif
1318fc1c62b8Sfrankho hs_copylabel(hvp, ISO_VOL_ID(volp), hs_joliet_level(volp) >= 1);
13197c478bd9Sstevel@tonic-gate
13207c478bd9Sstevel@tonic-gate /*
13217c478bd9Sstevel@tonic-gate * Make sure that lbn_size is a power of two and otherwise valid.
13227c478bd9Sstevel@tonic-gate */
13237c478bd9Sstevel@tonic-gate if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) {
13247c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE,
13257c478bd9Sstevel@tonic-gate "hsfs: %d-byte logical block size not supported",
13267c478bd9Sstevel@tonic-gate hvp->lbn_size);
13277c478bd9Sstevel@tonic-gate return (EINVAL);
13287c478bd9Sstevel@tonic-gate }
13297c478bd9Sstevel@tonic-gate return (hs_parsedir(fsp, ISO_ROOT_DIR(volp), &hvp->root_dir,
1330fc1c62b8Sfrankho (char *)NULL, (int *)NULL, IDE_ROOT_DIR_REC_SIZE));
13317c478bd9Sstevel@tonic-gate }
13327c478bd9Sstevel@tonic-gate
13337c478bd9Sstevel@tonic-gate /*
13347c478bd9Sstevel@tonic-gate * Common code for mount and umount.
13357c478bd9Sstevel@tonic-gate * Check that the user's argument is a reasonable
13367c478bd9Sstevel@tonic-gate * thing on which to mount, and return the device number if so.
13377c478bd9Sstevel@tonic-gate */
13387c478bd9Sstevel@tonic-gate static int
hs_getmdev(struct vfs * vfsp,char * fspec,int flags,dev_t * pdev,mode_t * mode,cred_t * cr)13397c478bd9Sstevel@tonic-gate hs_getmdev(struct vfs *vfsp, char *fspec, int flags, dev_t *pdev, mode_t *mode,
13407c478bd9Sstevel@tonic-gate cred_t *cr)
13417c478bd9Sstevel@tonic-gate {
13427c478bd9Sstevel@tonic-gate int error;
134393239addSjohnlev struct vnode *svp = NULL;
134493239addSjohnlev struct vnode *lvp = NULL;
134593239addSjohnlev struct vnode *bvp;
13467c478bd9Sstevel@tonic-gate struct vattr vap;
13477c478bd9Sstevel@tonic-gate dev_t dev;
134893239addSjohnlev enum uio_seg fromspace = (flags & MS_SYSSPACE) ?
134993239addSjohnlev UIO_SYSSPACE : UIO_USERSPACE;
13507c478bd9Sstevel@tonic-gate
13517c478bd9Sstevel@tonic-gate /*
135293239addSjohnlev * Look up the device/file to be mounted.
13537c478bd9Sstevel@tonic-gate */
135493239addSjohnlev error = lookupname(fspec, fromspace, FOLLOW, NULLVPP, &svp);
13557c478bd9Sstevel@tonic-gate if (error) {
135693239addSjohnlev if (error == ENOENT)
135793239addSjohnlev error = ENODEV;
135893239addSjohnlev goto out;
13597c478bd9Sstevel@tonic-gate }
136093239addSjohnlev
136193239addSjohnlev error = vfs_get_lofi(vfsp, &lvp);
136293239addSjohnlev
136393239addSjohnlev if (error > 0) {
136493239addSjohnlev if (error == ENOENT)
136593239addSjohnlev error = ENODEV;
136693239addSjohnlev goto out;
136793239addSjohnlev } else if (error == 0) {
136893239addSjohnlev bvp = lvp;
136993239addSjohnlev } else {
137093239addSjohnlev bvp = svp;
137193239addSjohnlev
137293239addSjohnlev if (bvp->v_type != VBLK) {
137393239addSjohnlev error = ENOTBLK;
137493239addSjohnlev goto out;
13757c478bd9Sstevel@tonic-gate }
137693239addSjohnlev
137793239addSjohnlev if ((error = secpolicy_spec_open(cr, bvp, FREAD)) != 0)
137893239addSjohnlev goto out;
13797c478bd9Sstevel@tonic-gate }
138093239addSjohnlev
13817c478bd9Sstevel@tonic-gate /*
138293239addSjohnlev * Can we read from the device/file ?
13837c478bd9Sstevel@tonic-gate */
138493239addSjohnlev if ((error = VOP_ACCESS(svp, VREAD, 0, cr, NULL)) != 0)
138593239addSjohnlev goto out;
13867c478bd9Sstevel@tonic-gate
13877c478bd9Sstevel@tonic-gate vap.va_mask = AT_MODE; /* get protection mode */
138893239addSjohnlev (void) VOP_GETATTR(bvp, &vap, 0, CRED(), NULL);
13897c478bd9Sstevel@tonic-gate *mode = vap.va_mode;
13907c478bd9Sstevel@tonic-gate
139193239addSjohnlev dev = *pdev = bvp->v_rdev;
139293239addSjohnlev
139393239addSjohnlev error = EBUSY;
13947c478bd9Sstevel@tonic-gate
13957c478bd9Sstevel@tonic-gate /*
13967c478bd9Sstevel@tonic-gate * Ensure that this device isn't already mounted,
13977c478bd9Sstevel@tonic-gate * unless this is a REMOUNT request or we are told to suppress
13987c478bd9Sstevel@tonic-gate * mount checks.
13997c478bd9Sstevel@tonic-gate */
14007c478bd9Sstevel@tonic-gate if ((flags & MS_NOCHECK) == 0) {
14017c478bd9Sstevel@tonic-gate if (vfs_devmounting(dev, vfsp))
140293239addSjohnlev goto out;
14037c478bd9Sstevel@tonic-gate if (vfs_devismounted(dev) && !(flags & MS_REMOUNT))
140493239addSjohnlev goto out;
14057c478bd9Sstevel@tonic-gate }
14067c478bd9Sstevel@tonic-gate
140793239addSjohnlev if (getmajor(*pdev) >= devcnt) {
140893239addSjohnlev error = ENXIO;
140993239addSjohnlev goto out;
141093239addSjohnlev }
141193239addSjohnlev
141293239addSjohnlev error = 0;
141393239addSjohnlev out:
141493239addSjohnlev if (svp != NULL)
141593239addSjohnlev VN_RELE(svp);
141693239addSjohnlev if (lvp != NULL)
141793239addSjohnlev VN_RELE(lvp);
141893239addSjohnlev return (error);
14197c478bd9Sstevel@tonic-gate }
14207c478bd9Sstevel@tonic-gate
14217c478bd9Sstevel@tonic-gate static void
hs_copylabel(struct hs_volume * hvp,unsigned char * label,int isjoliet)1422fc1c62b8Sfrankho hs_copylabel(struct hs_volume *hvp, unsigned char *label, int isjoliet)
14237c478bd9Sstevel@tonic-gate {
1424fc1c62b8Sfrankho char lbuf[64]; /* hs_joliet_cp() creates 48 bytes at most */
1425fc1c62b8Sfrankho
1426fc1c62b8Sfrankho if (isjoliet) {
1427fc1c62b8Sfrankho /*
1428fc1c62b8Sfrankho * hs_joliet_cp() will output 16..48 bytes.
1429fc1c62b8Sfrankho * We need to clear 'lbuf' to avoid junk chars past byte 15.
1430fc1c62b8Sfrankho */
1431fc1c62b8Sfrankho bzero(lbuf, sizeof (lbuf));
1432cce73247Sfrankho (void) hs_joliet_cp((char *)label, lbuf, 32);
1433fc1c62b8Sfrankho label = (unsigned char *)lbuf;
1434fc1c62b8Sfrankho }
14357c478bd9Sstevel@tonic-gate /* cdrom volid is at most 32 bytes */
14367c478bd9Sstevel@tonic-gate bcopy(label, hvp->vol_id, 32);
14377c478bd9Sstevel@tonic-gate hvp->vol_id[31] = NULL;
14387c478bd9Sstevel@tonic-gate }
14397c478bd9Sstevel@tonic-gate
14407c478bd9Sstevel@tonic-gate /*
14417c478bd9Sstevel@tonic-gate * Mount root file system.
14427c478bd9Sstevel@tonic-gate * "why" is ROOT_INIT on initial call, ROOT_REMOUNT if called to
14437c478bd9Sstevel@tonic-gate * remount the root file system, and ROOT_UNMOUNT if called to
14447c478bd9Sstevel@tonic-gate * unmount the root (e.g., as part of a system shutdown).
14457c478bd9Sstevel@tonic-gate *
14467c478bd9Sstevel@tonic-gate * XXX - this may be partially machine-dependent; it, along with the VFS_SWAPVP
14477c478bd9Sstevel@tonic-gate * operation, goes along with auto-configuration. A mechanism should be
14487c478bd9Sstevel@tonic-gate * provided by which machine-INdependent code in the kernel can say "get me the
14497c478bd9Sstevel@tonic-gate * right root file system" and "get me the right initial swap area", and have
14507c478bd9Sstevel@tonic-gate * that done in what may well be a machine-dependent fashion.
14517c478bd9Sstevel@tonic-gate * Unfortunately, it is also file-system-type dependent (NFS gets it via
14527c478bd9Sstevel@tonic-gate * bootparams calls, UFS gets it from various and sundry machine-dependent
14537c478bd9Sstevel@tonic-gate * mechanisms, as SPECFS does for swap).
14547c478bd9Sstevel@tonic-gate */
14557c478bd9Sstevel@tonic-gate static int
hsfs_mountroot(struct vfs * vfsp,enum whymountroot why)14567c478bd9Sstevel@tonic-gate hsfs_mountroot(struct vfs *vfsp, enum whymountroot why)
14577c478bd9Sstevel@tonic-gate {
14587c478bd9Sstevel@tonic-gate int error;
14597c478bd9Sstevel@tonic-gate struct hsfs *fsp;
14607c478bd9Sstevel@tonic-gate struct hs_volume *fvolp;
14617c478bd9Sstevel@tonic-gate static int hsfsrootdone = 0;
14627c478bd9Sstevel@tonic-gate dev_t rootdev;
14637c478bd9Sstevel@tonic-gate mode_t mode = 0;
14647c478bd9Sstevel@tonic-gate
14657c478bd9Sstevel@tonic-gate if (why == ROOT_INIT) {
14667c478bd9Sstevel@tonic-gate if (hsfsrootdone++)
14677c478bd9Sstevel@tonic-gate return (EBUSY);
14687c478bd9Sstevel@tonic-gate rootdev = getrootdev();
14697c478bd9Sstevel@tonic-gate if (rootdev == (dev_t)NODEV)
14707c478bd9Sstevel@tonic-gate return (ENODEV);
14717c478bd9Sstevel@tonic-gate vfsp->vfs_dev = rootdev;
14727c478bd9Sstevel@tonic-gate vfsp->vfs_flag |= VFS_RDONLY;
14737c478bd9Sstevel@tonic-gate } else if (why == ROOT_REMOUNT) {
14747c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: ROOT_REMOUNT");
14757c478bd9Sstevel@tonic-gate return (0);
14767c478bd9Sstevel@tonic-gate } else if (why == ROOT_UNMOUNT) {
14777c478bd9Sstevel@tonic-gate return (0);
14787c478bd9Sstevel@tonic-gate }
14797c478bd9Sstevel@tonic-gate error = vfs_lock(vfsp);
14807c478bd9Sstevel@tonic-gate if (error) {
14817c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: couldn't get vfs_lock");
14827c478bd9Sstevel@tonic-gate return (error);
14837c478bd9Sstevel@tonic-gate }
14847c478bd9Sstevel@tonic-gate
14857c478bd9Sstevel@tonic-gate error = hs_mountfs(vfsp, rootdev, "/", mode, 1, CRED(), 1);
14867c478bd9Sstevel@tonic-gate /*
14877c478bd9Sstevel@tonic-gate * XXX - assumes root device is not indirect, because we don't set
14887c478bd9Sstevel@tonic-gate * rootvp. Is rootvp used for anything? If so, make another arg
14897c478bd9Sstevel@tonic-gate * to mountfs.
14907c478bd9Sstevel@tonic-gate */
14917c478bd9Sstevel@tonic-gate if (error) {
14927c478bd9Sstevel@tonic-gate vfs_unlock(vfsp);
14937c478bd9Sstevel@tonic-gate if (rootvp) {
14947c478bd9Sstevel@tonic-gate VN_RELE(rootvp);
14957c478bd9Sstevel@tonic-gate rootvp = (struct vnode *)0;
14967c478bd9Sstevel@tonic-gate }
14977c478bd9Sstevel@tonic-gate return (error);
14987c478bd9Sstevel@tonic-gate }
14997c478bd9Sstevel@tonic-gate if (why == ROOT_INIT)
15007c478bd9Sstevel@tonic-gate vfs_add((struct vnode *)0, vfsp,
15017c478bd9Sstevel@tonic-gate (vfsp->vfs_flag & VFS_RDONLY) ? MS_RDONLY : 0);
15027c478bd9Sstevel@tonic-gate vfs_unlock(vfsp);
15037c478bd9Sstevel@tonic-gate fsp = VFS_TO_HSFS(vfsp);
15047c478bd9Sstevel@tonic-gate fvolp = &fsp->hsfs_vol;
15057c478bd9Sstevel@tonic-gate #ifdef HSFS_CLKSET
15067c478bd9Sstevel@tonic-gate if (fvolp->cre_date.tv_sec == 0) {
15077c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: cre_date.tv_sec == 0");
15087c478bd9Sstevel@tonic-gate if (fvolp->mod_date.tv_sec == 0) {
1509d10b6702Sfrankho cmn_err(CE_NOTE,
1510d10b6702Sfrankho "hsfs_mountroot: mod_date.tv_sec == 0");
15117c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "hsfs_mountroot: clkset(-1L)");
15127c478bd9Sstevel@tonic-gate clkset(-1L);
1513d10b6702Sfrankho } else {
15147c478bd9Sstevel@tonic-gate clkset(fvolp->mod_date.tv_sec);
1515d10b6702Sfrankho }
1516d10b6702Sfrankho } else {
15177c478bd9Sstevel@tonic-gate clkset(fvolp->mod_date.tv_sec);
1518d10b6702Sfrankho }
15197c478bd9Sstevel@tonic-gate #else /* HSFS_CLKSET */
15207c478bd9Sstevel@tonic-gate clkset(-1L);
15217c478bd9Sstevel@tonic-gate #endif /* HSFS_CLKSET */
15227c478bd9Sstevel@tonic-gate return (0);
15237c478bd9Sstevel@tonic-gate }
15247c478bd9Sstevel@tonic-gate
15257c478bd9Sstevel@tonic-gate /*
15267c478bd9Sstevel@tonic-gate * hs_findvoldesc()
15277c478bd9Sstevel@tonic-gate *
15287c478bd9Sstevel@tonic-gate * Return the sector where the volume descriptor lives. This is
15297c478bd9Sstevel@tonic-gate * a fixed value for "normal" cd-rom's, but can change for
15307c478bd9Sstevel@tonic-gate * multisession cd's.
15317c478bd9Sstevel@tonic-gate *
15327c478bd9Sstevel@tonic-gate * desc_sec is the same for high-sierra and iso 9660 formats, why
1533da6c28aaSamw * there are two different #defines used in the code for this is
15347c478bd9Sstevel@tonic-gate * beyond me. These are standards, cast in concrete, right?
15357c478bd9Sstevel@tonic-gate * To be general, however, this function supports passing in different
15367c478bd9Sstevel@tonic-gate * values.
15377c478bd9Sstevel@tonic-gate */
15387c478bd9Sstevel@tonic-gate static int
hs_findvoldesc(dev_t rdev,int desc_sec)15397c478bd9Sstevel@tonic-gate hs_findvoldesc(dev_t rdev, int desc_sec)
15407c478bd9Sstevel@tonic-gate {
15417c478bd9Sstevel@tonic-gate int secno;
15427c478bd9Sstevel@tonic-gate int error;
15437c478bd9Sstevel@tonic-gate int rval; /* ignored */
15447c478bd9Sstevel@tonic-gate
15457c478bd9Sstevel@tonic-gate #ifdef CDROMREADOFFSET
15467c478bd9Sstevel@tonic-gate /*
15477c478bd9Sstevel@tonic-gate * Issue the Read Offset ioctl directly to the
15487c478bd9Sstevel@tonic-gate * device. Ignore any errors and set starting
15497c478bd9Sstevel@tonic-gate * secno to the default, otherwise add the
15507c478bd9Sstevel@tonic-gate * VOLDESC sector number to the offset.
15517c478bd9Sstevel@tonic-gate */
15527c478bd9Sstevel@tonic-gate error = cdev_ioctl(rdev, CDROMREADOFFSET, (intptr_t)&secno,
15537c478bd9Sstevel@tonic-gate FNATIVE|FKIOCTL|FREAD, CRED(), &rval);
15547c478bd9Sstevel@tonic-gate if (error) {
15557c478bd9Sstevel@tonic-gate secno = desc_sec;
15567c478bd9Sstevel@tonic-gate } else {
15577c478bd9Sstevel@tonic-gate secno += desc_sec;
15587c478bd9Sstevel@tonic-gate }
15597c478bd9Sstevel@tonic-gate #else
15607c478bd9Sstevel@tonic-gate secno = desc_sec;
15617c478bd9Sstevel@tonic-gate #endif
15627c478bd9Sstevel@tonic-gate
15637c478bd9Sstevel@tonic-gate return (secno);
15647c478bd9Sstevel@tonic-gate }
1565