Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/hsfs/hsfs_vfsops.c
+++ new/usr/src/uts/common/fs/hsfs/hsfs_vfsops.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
24 24 * Copyright 2013 Joyent, Inc. All rights reserved.
25 25 */
26 26
27 27 /*
28 28 * VFS operations for High Sierra filesystem
29 29 */
30 30
31 31 #include <sys/types.h>
32 32 #include <sys/isa_defs.h>
33 33 #include <sys/t_lock.h>
34 34 #include <sys/param.h>
35 35 #include <sys/systm.h>
36 36 #include <sys/sysmacros.h>
37 37 #include <sys/kmem.h>
38 38 #include <sys/signal.h>
39 39 #include <sys/user.h>
40 40 #include <sys/proc.h>
41 41 #include <sys/disp.h>
42 42 #include <sys/buf.h>
43 43 #include <sys/pathname.h>
44 44 #include <sys/vfs.h>
45 45 #include <sys/vfs_opreg.h>
46 46 #include <sys/vnode.h>
47 47 #include <sys/file.h>
48 48 #include <sys/uio.h>
49 49 #include <sys/conf.h>
50 50 #include <sys/policy.h>
51 51
52 52 #include <vm/page.h>
53 53
54 54 #include <sys/fs/snode.h>
55 55 #include <sys/fs/hsfs_spec.h>
56 56 #include <sys/fs/hsfs_isospec.h>
57 57 #include <sys/fs/hsfs_node.h>
58 58 #include <sys/fs/hsfs_impl.h>
59 59 #include <sys/fs/hsfs_susp.h>
60 60 #include <sys/fs/hsfs_rrip.h>
61 61
62 62 #include <sys/statvfs.h>
63 63 #include <sys/mount.h>
64 64 #include <sys/mntent.h>
65 65 #include <sys/swap.h>
66 66 #include <sys/errno.h>
67 67 #include <sys/debug.h>
68 68 #include "fs/fs_subr.h"
69 69 #include <sys/cmn_err.h>
70 70 #include <sys/bootconf.h>
71 71
72 72 #include <sys/sdt.h>
73 73
74 74 /*
75 75 * These are needed for the CDROMREADOFFSET Code
76 76 */
77 77 #include <sys/cdio.h>
78 78 #include <sys/sunddi.h>
79 79
80 80 #define HSFS_CLKSET
81 81
82 82 #include <sys/modctl.h>
83 83
84 84 /*
85 85 * Options for mount.
86 86 */
87 87 #define HOPT_GLOBAL MNTOPT_GLOBAL
88 88 #define HOPT_NOGLOBAL MNTOPT_NOGLOBAL
89 89 #define HOPT_MAPLCASE "maplcase"
90 90 #define HOPT_NOMAPLCASE "nomaplcase"
91 91 #define HOPT_NOTRAILDOT "notraildot"
92 92 #define HOPT_TRAILDOT "traildot"
93 93 #define HOPT_NRR "nrr"
94 94 #define HOPT_RR "rr"
95 95 #define HOPT_JOLIET "joliet"
96 96 #define HOPT_NOJOLIET "nojoliet"
97 97 #define HOPT_JOLIETLONG "jolietlong"
98 98 #define HOPT_VERS2 "vers2"
99 99 #define HOPT_NOVERS2 "novers2"
100 100 #define HOPT_RO MNTOPT_RO
101 101
102 102 static char *global_cancel[] = { HOPT_NOGLOBAL, NULL };
103 103 static char *noglobal_cancel[] = { HOPT_GLOBAL, NULL };
104 104 static char *mapl_cancel[] = { HOPT_NOMAPLCASE, NULL };
105 105 static char *nomapl_cancel[] = { HOPT_MAPLCASE, NULL };
106 106 static char *ro_cancel[] = { MNTOPT_RW, NULL };
107 107 static char *rr_cancel[] = { HOPT_NRR, NULL };
108 108 static char *nrr_cancel[] = { HOPT_RR, NULL };
109 109 static char *joliet_cancel[] = { HOPT_NOJOLIET, NULL };
110 110 static char *nojoliet_cancel[] = { HOPT_JOLIET, NULL };
111 111 static char *vers2_cancel[] = { HOPT_NOVERS2, NULL };
112 112 static char *novers2_cancel[] = { HOPT_VERS2, NULL };
113 113 static char *trail_cancel[] = { HOPT_NOTRAILDOT, NULL };
114 114 static char *notrail_cancel[] = { HOPT_TRAILDOT, NULL };
115 115
116 116 static mntopt_t hsfs_options[] = {
117 117 { HOPT_GLOBAL, global_cancel, NULL, 0, NULL },
118 118 { HOPT_NOGLOBAL, noglobal_cancel, NULL, MO_DEFAULT, NULL },
119 119 { HOPT_MAPLCASE, mapl_cancel, NULL, MO_DEFAULT, NULL },
120 120 { HOPT_NOMAPLCASE, nomapl_cancel, NULL, 0, NULL },
121 121 { HOPT_RO, ro_cancel, NULL, MO_DEFAULT, NULL },
122 122 { HOPT_RR, rr_cancel, NULL, MO_DEFAULT, NULL },
123 123 { HOPT_NRR, nrr_cancel, NULL, 0, NULL },
124 124 { HOPT_JOLIET, joliet_cancel, NULL, 0, NULL },
125 125 { HOPT_NOJOLIET, nojoliet_cancel, NULL, 0, NULL },
126 126 { HOPT_JOLIETLONG, NULL, NULL, 0, NULL },
127 127 { HOPT_VERS2, vers2_cancel, NULL, 0, NULL },
128 128 { HOPT_NOVERS2, novers2_cancel, NULL, 0, NULL },
129 129 { HOPT_TRAILDOT, trail_cancel, NULL, MO_DEFAULT, NULL },
130 130 { HOPT_NOTRAILDOT, notrail_cancel, NULL, 0, NULL },
131 131 { "sector", NULL, "0", MO_HASVALUE, NULL},
132 132 };
133 133
134 134 static mntopts_t hsfs_proto_opttbl = {
135 135 sizeof (hsfs_options) / sizeof (mntopt_t),
136 136 hsfs_options
137 137 };
138 138
139 139 /*
140 140 * Indicates whether to enable the I/O scheduling and readahead logic
141 141 * 1 - Enable, 0 - Do not Enable.
142 142 * Debugging purposes.
143 143 */
144 144 int do_schedio = 1;
145 145 static int hsfsfstype;
146 146 static int hsfsinit(int, char *);
147 147
148 148 static vfsdef_t vfw = {
149 149 VFSDEF_VERSION,
150 150 "hsfs",
151 151 hsfsinit,
↓ open down ↓ |
151 lines elided |
↑ open up ↑ |
152 152 /* We don't suppport remounting */
153 153 VSW_HASPROTO|VSW_STATS|VSW_CANLOFI,
154 154 &hsfs_proto_opttbl
155 155 };
156 156
157 157 static struct modlfs modlfs = {
158 158 &mod_fsops, "filesystem for HSFS", &vfw
159 159 };
160 160
161 161 static struct modlinkage modlinkage = {
162 - MODREV_1, (void *)&modlfs, NULL
162 + MODREV_1, { (void *)&modlfs, NULL }
163 163 };
164 164
165 165 extern void hsched_init_caches(void);
166 166 extern void hsched_fini_caches(void);
167 167
168 168
169 169 int
170 170 _init(void)
171 171 {
172 172 return (mod_install(&modlinkage));
173 173 }
174 174
175 175 int
176 176 _fini(void)
177 177 {
178 178 int error;
179 179
180 180 error = mod_remove(&modlinkage);
181 181
182 182 DTRACE_PROBE1(mod_remove, int, error);
183 183
184 184 if (error)
185 185 return (error);
186 186
187 187 mutex_destroy(&hs_mounttab_lock);
188 188
189 189 /*
190 190 * Tear down the operations vectors
191 191 */
192 192 (void) vfs_freevfsops_by_type(hsfsfstype);
193 193 vn_freevnodeops(hsfs_vnodeops);
194 194
195 195 hs_fini_hsnode_cache();
196 196 hsched_fini_caches();
197 197 return (0);
198 198 }
199 199
200 200 int
201 201 _info(struct modinfo *modinfop)
202 202 {
203 203 return (mod_info(&modlinkage, modinfop));
204 204 }
205 205
206 206 #define BDEVFLAG(dev) ((devopsp[getmajor(dev)])->devo_cb_ops->cb_flag)
207 207
208 208 kmutex_t hs_mounttab_lock;
209 209 struct hsfs *hs_mounttab = NULL;
210 210
211 211 /* default mode, uid, gid */
212 212 mode_t hsfs_default_mode = 0555;
213 213 uid_t hsfs_default_uid = 0;
214 214 gid_t hsfs_default_gid = 3;
215 215
216 216 extern void hsched_init(struct hsfs *fsp, int fsid,
217 217 struct modlinkage *modlinkage);
218 218 extern void hsched_fini(struct hsfs_queue *hqueue);
219 219 extern void hsfs_init_kstats(struct hsfs *fsp, int fsid);
220 220 extern void hsfs_fini_kstats(struct hsfs *fsp);
221 221
222 222 static int hsfs_mount(struct vfs *vfsp, struct vnode *mvp,
223 223 struct mounta *uap, struct cred *cr);
224 224 static int hsfs_unmount(struct vfs *vfsp, int, struct cred *cr);
225 225 static int hsfs_root(struct vfs *vfsp, struct vnode **vpp);
226 226 static int hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp);
227 227 static int hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp);
228 228 static int hsfs_mountroot(struct vfs *, enum whymountroot);
229 229
230 230 static int hs_mountfs(struct vfs *vfsp, dev_t dev, char *path,
231 231 mode_t mode, int flags, struct cred *cr, int isroot);
232 232 static int hs_getrootvp(struct vfs *vfsp, struct hsfs *fsp, size_t pathsize);
233 233 static int hs_findhsvol(struct hsfs *fsp, struct vnode *vp,
234 234 struct hs_volume *hvp);
235 235 static int hs_parsehsvol(struct hsfs *fsp, uchar_t *volp,
236 236 struct hs_volume *hvp);
237 237 static int hs_findisovol(struct hsfs *fsp, struct vnode *vp,
238 238 struct hs_volume *hvp,
239 239 struct hs_volume *svp,
240 240 struct hs_volume *jvp);
241 241 static int hs_joliet_level(uchar_t *volp);
242 242 static int hs_parseisovol(struct hsfs *fsp, uchar_t *volp,
↓ open down ↓ |
70 lines elided |
↑ open up ↑ |
243 243 struct hs_volume *hvp);
244 244 static void hs_copylabel(struct hs_volume *, unsigned char *, int);
245 245 static int hs_getmdev(struct vfs *, char *fspec, int flags, dev_t *pdev,
246 246 mode_t *mode, cred_t *cr);
247 247 static int hs_findvoldesc(dev_t rdev, int desc_sec);
248 248
249 249 static int
250 250 hsfsinit(int fstype, char *name)
251 251 {
252 252 static const fs_operation_def_t hsfs_vfsops_template[] = {
253 - VFSNAME_MOUNT, { .vfs_mount = hsfs_mount },
254 - VFSNAME_UNMOUNT, { .vfs_unmount = hsfs_unmount },
255 - VFSNAME_ROOT, { .vfs_root = hsfs_root },
256 - VFSNAME_STATVFS, { .vfs_statvfs = hsfs_statvfs },
257 - VFSNAME_VGET, { .vfs_vget = hsfs_vget },
258 - VFSNAME_MOUNTROOT, { .vfs_mountroot = hsfs_mountroot },
259 - NULL, NULL
253 + { VFSNAME_MOUNT, { .vfs_mount = hsfs_mount } },
254 + { VFSNAME_UNMOUNT, { .vfs_unmount = hsfs_unmount } },
255 + { VFSNAME_ROOT, { .vfs_root = hsfs_root } },
256 + { VFSNAME_STATVFS, { .vfs_statvfs = hsfs_statvfs } },
257 + { VFSNAME_VGET, { .vfs_vget = hsfs_vget } },
258 + { VFSNAME_MOUNTROOT, { .vfs_mountroot = hsfs_mountroot } },
259 + { NULL, { NULL } }
260 260 };
261 261 int error;
262 262
263 263 error = vfs_setfsops(fstype, hsfs_vfsops_template, NULL);
264 264 if (error != 0) {
265 265 cmn_err(CE_WARN, "hsfsinit: bad vfs ops template");
266 266 return (error);
267 267 }
268 268
269 269 error = vn_make_ops(name, hsfs_vnodeops_template, &hsfs_vnodeops);
270 270 if (error != 0) {
271 271 (void) vfs_freevfsops_by_type(fstype);
272 272 cmn_err(CE_WARN, "hsfsinit: bad vnode ops template");
273 273 return (error);
274 274 }
275 275
276 276 hsfsfstype = fstype;
277 277 mutex_init(&hs_mounttab_lock, NULL, MUTEX_DEFAULT, NULL);
278 278 hs_init_hsnode_cache();
279 279 hsched_init_caches();
280 280 return (0);
281 281 }
282 282
283 283 /*ARGSUSED*/
284 284 static int
285 285 hsfs_mount(struct vfs *vfsp, struct vnode *mvp,
286 286 struct mounta *uap, struct cred *cr)
287 287 {
288 288 int vnode_busy;
289 289 dev_t dev;
290 290 struct pathname dpn;
291 291 int error;
292 292 mode_t mode;
293 293 int flags; /* this will hold the mount specific data */
294 294
295 295 if ((error = secpolicy_fs_mount(cr, mvp, vfsp)) != 0)
296 296 return (error);
297 297
298 298 if (mvp->v_type != VDIR)
299 299 return (ENOTDIR);
300 300
301 301 /* mount option must be read only, else mount will be rejected */
302 302 if (!(uap->flags & MS_RDONLY))
303 303 return (EROFS);
304 304
305 305 /*
306 306 * We already told the framework that we don't support remounting.
307 307 */
308 308 ASSERT(!(uap->flags & MS_REMOUNT));
309 309
310 310 mutex_enter(&mvp->v_lock);
311 311 vnode_busy = (mvp->v_count != 1) || (mvp->v_flag & VROOT);
312 312 mutex_exit(&mvp->v_lock);
313 313
314 314 if ((uap->flags & MS_OVERLAY) == 0 && vnode_busy) {
315 315 return (EBUSY);
316 316 }
317 317
318 318 /*
319 319 * Check for the options that actually affect things
320 320 * at our level.
321 321 */
322 322 flags = 0;
323 323 if (vfs_optionisset(vfsp, HOPT_NOMAPLCASE, NULL))
324 324 flags |= HSFSMNT_NOMAPLCASE;
325 325 if (vfs_optionisset(vfsp, HOPT_NOTRAILDOT, NULL))
326 326 flags |= HSFSMNT_NOTRAILDOT;
327 327 if (vfs_optionisset(vfsp, HOPT_NRR, NULL))
328 328 flags |= HSFSMNT_NORRIP;
329 329 if (vfs_optionisset(vfsp, HOPT_NOJOLIET, NULL))
330 330 flags |= HSFSMNT_NOJOLIET;
331 331 if (vfs_optionisset(vfsp, HOPT_JOLIETLONG, NULL))
332 332 flags |= HSFSMNT_JOLIETLONG;
333 333 if (vfs_optionisset(vfsp, HOPT_NOVERS2, NULL))
334 334 flags |= HSFSMNT_NOVERS2;
335 335
336 336 error = pn_get(uap->dir, (uap->flags & MS_SYSSPACE) ?
337 337 UIO_SYSSPACE : UIO_USERSPACE, &dpn);
338 338 if (error)
339 339 return (error);
340 340
341 341 error = hs_getmdev(vfsp, uap->spec, uap->flags, &dev, &mode, cr);
342 342 if (error != 0) {
343 343 pn_free(&dpn);
344 344 return (error);
345 345 }
346 346
347 347 /*
348 348 * If the device is a tape, return error
349 349 */
350 350 if ((BDEVFLAG(dev) & D_TAPE) == D_TAPE) {
351 351 pn_free(&dpn);
352 352 return (ENOTBLK);
353 353 }
354 354
355 355 /*
356 356 * Mount the filesystem.
357 357 */
358 358 error = hs_mountfs(vfsp, dev, dpn.pn_path, mode, flags, cr, 0);
359 359 pn_free(&dpn);
360 360 return (error);
361 361 }
362 362
363 363 /*ARGSUSED*/
364 364 static int
365 365 hsfs_unmount(
366 366 struct vfs *vfsp,
367 367 int flag,
368 368 struct cred *cr)
369 369 {
370 370 struct hsfs **tspp;
371 371 struct hsfs *fsp;
372 372
373 373 if (secpolicy_fs_unmount(cr, vfsp) != 0)
374 374 return (EPERM);
375 375
376 376 /*
377 377 * forced unmount is not supported by this file system
378 378 * and thus, ENOTSUP is being returned.
379 379 */
380 380 if (flag & MS_FORCE)
381 381 return (ENOTSUP);
382 382
383 383 fsp = VFS_TO_HSFS(vfsp);
384 384
385 385 if (fsp->hsfs_rootvp->v_count != 1)
386 386 return (EBUSY);
387 387
388 388 /* destroy all old pages and hsnodes for this vfs */
389 389 if (hs_synchash(vfsp))
390 390 return (EBUSY);
391 391
392 392 mutex_enter(&hs_mounttab_lock);
393 393 for (tspp = &hs_mounttab; *tspp != NULL; tspp = &(*tspp)->hsfs_next) {
394 394 if (*tspp == fsp)
395 395 break;
396 396 }
397 397 if (*tspp == NULL) {
398 398 mutex_exit(&hs_mounttab_lock);
399 399 panic("hsfs_unmount: vfs not mounted?");
400 400 /*NOTREACHED*/
401 401 }
402 402
403 403 *tspp = fsp->hsfs_next;
404 404
405 405 mutex_exit(&hs_mounttab_lock);
406 406
407 407 hsfs_fini_kstats(fsp);
408 408 (void) VOP_CLOSE(fsp->hsfs_devvp, FREAD, 1, (offset_t)0, cr, NULL);
409 409 VN_RELE(fsp->hsfs_devvp);
410 410 /* free path table space */
411 411 if (fsp->hsfs_ptbl != NULL)
412 412 kmem_free(fsp->hsfs_ptbl, (size_t)fsp->hsfs_vol.ptbl_len);
413 413 /* free path table index table */
414 414 if (fsp->hsfs_ptbl_idx != NULL)
415 415 kmem_free(fsp->hsfs_ptbl_idx, (size_t)
416 416 (fsp->hsfs_ptbl_idx_size * sizeof (struct ptable_idx)));
417 417
418 418 /* free "mounted on" pathame */
419 419 if (fsp->hsfs_fsmnt != NULL)
420 420 kmem_free(fsp->hsfs_fsmnt, strlen(fsp->hsfs_fsmnt) + 1);
421 421
422 422 hsched_fini(fsp->hqueue);
423 423 kmem_free(fsp->hqueue, sizeof (struct hsfs_queue));
424 424
425 425 mutex_destroy(&fsp->hsfs_free_lock);
426 426 rw_destroy(&fsp->hsfs_hash_lock);
427 427
428 428 kmem_free(fsp, sizeof (*fsp));
429 429 return (0);
430 430 }
431 431
432 432 /*ARGSUSED*/
433 433 static int
434 434 hsfs_root(struct vfs *vfsp, struct vnode **vpp)
435 435 {
436 436 *vpp = (VFS_TO_HSFS(vfsp))->hsfs_rootvp;
437 437 VN_HOLD(*vpp);
438 438 return (0);
439 439 }
440 440
441 441 /*ARGSUSED*/
442 442 static int
443 443 hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp)
444 444 {
445 445 struct hsfs *fsp;
446 446 dev32_t d32;
447 447
448 448 fsp = VFS_TO_HSFS(vfsp);
449 449 if (fsp->hsfs_magic != HSFS_MAGIC)
450 450 return (EINVAL);
451 451 bzero(sbp, sizeof (*sbp));
452 452 sbp->f_bsize = vfsp->vfs_bsize;
453 453 sbp->f_frsize = sbp->f_bsize; /* no fragment, same as block size */
454 454 sbp->f_blocks = (fsblkcnt64_t)fsp->hsfs_vol.vol_size;
455 455
456 456 sbp->f_bfree = (fsblkcnt64_t)0;
457 457 sbp->f_bavail = (fsblkcnt64_t)0;
458 458 sbp->f_files = (fsfilcnt64_t)-1;
459 459 sbp->f_ffree = (fsfilcnt64_t)0;
460 460 sbp->f_favail = (fsfilcnt64_t)0;
461 461 (void) cmpldev(&d32, vfsp->vfs_dev);
462 462 sbp->f_fsid = d32;
463 463 (void) strcpy(sbp->f_basetype, vfssw[vfsp->vfs_fstype].vsw_name);
464 464 sbp->f_flag = vf_to_stf(vfsp->vfs_flag);
465 465 sbp->f_namemax = fsp->hsfs_namemax;
466 466 (void) strcpy(sbp->f_fstr, fsp->hsfs_vol.vol_id);
467 467
468 468 return (0);
469 469 }
470 470
471 471 /*
472 472 * Previously nodeid was declared as uint32_t. This has been changed
473 473 * to conform better with the ISO9660 standard. The standard states that
474 474 * a LBN can be a 32 bit number, as the MAKE_NODEID macro shifts this
475 475 * LBN 11 places left (LBN_TO_BYTE) and then shifts the result 5 right
476 476 * (divide by 32) we are left with the potential of an overflow if
477 477 * confined to a 32 bit value.
478 478 */
479 479
480 480 static int
481 481 hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp)
482 482 {
483 483 struct hsfid *fid;
484 484 struct hsfs *fsp;
485 485 ino64_t nodeid;
486 486 int error;
487 487
488 488 fsp = (struct hsfs *)VFS_TO_HSFS(vfsp);
489 489 fid = (struct hsfid *)fidp;
490 490
491 491 /*
492 492 * Look for vnode on hashlist.
493 493 * If found, it's now active and the refcnt was incremented.
494 494 */
495 495
496 496 rw_enter(&fsp->hsfs_hash_lock, RW_READER);
497 497
498 498 nodeid = fid->hf_ino;
499 499
500 500 if ((*vpp = hs_findhash(nodeid, fid->hf_dir_lbn,
501 501 (uint_t)fid->hf_dir_off, vfsp)) == NULL) {
502 502 /*
503 503 * Not in cache, so we need to remake it.
504 504 * hs_remakenode() will read the directory entry
505 505 * and then check again to see if anyone else has
506 506 * put it in the cache.
507 507 */
508 508 rw_exit(&fsp->hsfs_hash_lock);
509 509 error = hs_remakenode(fid->hf_dir_lbn, (uint_t)fid->hf_dir_off,
510 510 vfsp, vpp);
511 511 return (error);
512 512 }
513 513 rw_exit(&fsp->hsfs_hash_lock);
514 514 return (0);
515 515 }
516 516
517 517
518 518 #define CHECKSUM_SIZE (64 * 1024)
519 519
520 520 /*
521 521 * Compute a CD-ROM fsid by checksumming the first 64K of data on the CD
522 522 * We use the 'fsp' argument to determine the location of the root
523 523 * directory entry, and we start reading from there.
524 524 */
525 525 static int
526 526 compute_cdrom_id(struct hsfs *fsp, vnode_t *devvp)
527 527 {
528 528 uint_t secno;
529 529 struct hs_volume *hsvp = &fsp->hsfs_vol;
530 530 struct buf *bp;
531 531 int error;
532 532 int fsid;
533 533
534 534 secno = hsvp->root_dir.ext_lbn >> hsvp->lbn_secshift;
535 535 bp = bread(devvp->v_rdev, secno * 4, CHECKSUM_SIZE);
536 536 error = geterror(bp);
537 537
538 538 /*
539 539 * An error on read or a partial read means we asked
540 540 * for a nonexistant/corrupted piece of the device
541 541 * (including past-the-end of the media). Don't
542 542 * try to use the checksumming method then.
543 543 */
544 544 if (!error && bp->b_bcount == CHECKSUM_SIZE) {
545 545 int *ibuf = (int *)bp->b_un.b_addr;
546 546 int i;
547 547
548 548 fsid = 0;
549 549
550 550 for (i = 0; i < CHECKSUM_SIZE / sizeof (int); i++)
551 551 fsid ^= ibuf[ i ];
552 552 } else {
553 553 /*
554 554 * Fallback - use creation date
555 555 */
556 556 fsid = hsvp->cre_date.tv_sec;
557 557 }
558 558
559 559 brelse(bp);
560 560
561 561 return (fsid);
562 562 }
563 563
564 564
565 565 /*ARGSUSED*/
566 566 static int
567 567 hs_mountfs(
568 568 struct vfs *vfsp,
569 569 dev_t dev,
570 570 char *path,
571 571 mode_t mode,
572 572 int mount_flags,
573 573 struct cred *cr,
574 574 int isroot)
575 575 {
576 576 struct vnode *devvp;
577 577 struct hsfs *tsp;
578 578 struct hsfs *fsp = NULL;
579 579 struct vattr vap;
580 580 struct hsnode *hp;
581 581 int error;
582 582 struct timeval tv;
583 583 int fsid;
584 584 int use_rrip;
585 585 int use_vers2;
586 586 int use_joliet;
587 587 int has_rrip = 0;
588 588 int has_vers2 = 0;
589 589 int has_joliet = 0;
590 590 int force_rrip_off;
591 591 int force_vers2_off;
592 592 int force_joliet_off;
593 593 size_t pathbufsz = strlen(path) + 1;
594 594 int redo_rootvp;
595 595
596 596 struct hs_volume *svp = NULL; /* Supplemental VD for ISO-9660:1999 */
597 597 struct hs_volume *jvp = NULL; /* Joliet VD */
598 598
599 599 /*
600 600 * The rules for which extension will be used are:
601 601 * 1. No specific mount options given:
602 602 * - use rrip if available
603 603 * - use ISO9660:1999 if available
604 604 * - use joliet if available.
605 605 * 2. rrip/ISO9660:1999/joliet explicitly disabled via mount option:
606 606 * - use next "lower" extension
607 607 * 3. joliet/ISO9660:1999/rrip explicitly requested via mount option:
608 608 * - disable rrip support even if available
609 609 * - disable IOS9660:1999 support even if available
610 610 *
611 611 * We need to adjust these flags as we discover the extensions
612 612 * present. See below. These are just the starting values.
613 613 */
614 614 use_rrip = (mount_flags & HSFSMNT_NORRIP) == 0;
615 615 use_vers2 = (mount_flags & HSFSMNT_NOVERS2) == 0;
616 616 use_joliet = (mount_flags & HSFSMNT_NOJOLIET) == 0;
617 617
618 618 /*
619 619 * Open the device
620 620 */
621 621 devvp = makespecvp(dev, VBLK);
622 622 ASSERT(devvp != 0);
623 623
624 624 /*
625 625 * Open the target device (file) for read only.
626 626 */
627 627 if (error = VOP_OPEN(&devvp, FREAD, cr, NULL)) {
628 628 VN_RELE(devvp);
629 629 return (error);
630 630 }
631 631
632 632 /*
633 633 * Refuse to go any further if this
634 634 * device is being used for swapping
635 635 */
636 636 if (IS_SWAPVP(common_specvp(devvp))) {
637 637 error = EBUSY;
638 638 goto cleanup;
639 639 }
640 640
641 641 vap.va_mask = AT_SIZE;
642 642 if ((error = VOP_GETATTR(devvp, &vap, ATTR_COMM, cr, NULL)) != 0) {
643 643 cmn_err(CE_NOTE, "Cannot get attributes of the CD-ROM driver");
644 644 goto cleanup;
645 645 }
646 646
647 647 /*
648 648 * Make sure we have a nonzero size partition.
649 649 * The current version of the SD driver will *not* fail the open
650 650 * of such a partition so we have to check for it here.
651 651 */
652 652 if (vap.va_size == 0) {
653 653 error = ENXIO;
654 654 goto cleanup;
655 655 }
656 656
657 657 /*
658 658 * Init a new hsfs structure.
659 659 */
660 660 fsp = kmem_zalloc(sizeof (*fsp), KM_SLEEP);
661 661 svp = kmem_zalloc(sizeof (*svp), KM_SLEEP);
662 662 jvp = kmem_zalloc(sizeof (*jvp), KM_SLEEP);
663 663
664 664 /* hardwire perms, uid, gid */
665 665 fsp->hsfs_vol.vol_uid = hsfs_default_uid;
666 666 fsp->hsfs_vol.vol_gid = hsfs_default_gid;
667 667 fsp->hsfs_vol.vol_prot = hsfs_default_mode;
668 668 svp->vol_uid = hsfs_default_uid;
669 669 svp->vol_gid = hsfs_default_gid;
670 670 svp->vol_prot = hsfs_default_mode;
671 671 jvp->vol_uid = hsfs_default_uid;
672 672 jvp->vol_gid = hsfs_default_gid;
673 673 jvp->vol_prot = hsfs_default_mode;
674 674
675 675 /*
676 676 * Look for a Standard File Structure Volume Descriptor,
677 677 * of which there must be at least one.
678 678 * If found, check for volume size consistency.
679 679 *
680 680 * If svp->lbn_size is != 0, we did find a ISO-9660:1999 SVD
681 681 * If jvp->lbn_size is != 0, we did find a Joliet SVD.
682 682 */
683 683 fsp->hsfs_namemax = ISO_FILE_NAMELEN;
684 684 fsp->hsfs_namelen = ISO_FILE_NAMELEN;
685 685 error = hs_findisovol(fsp, devvp, &fsp->hsfs_vol, svp, jvp);
686 686 if (error == EINVAL) /* no iso 9660 - try high sierra ... */
687 687 error = hs_findhsvol(fsp, devvp, &fsp->hsfs_vol);
688 688
689 689 if (error)
690 690 goto cleanup;
691 691
692 692 DTRACE_PROBE4(findvol,
693 693 struct hsfs *, fsp,
694 694 struct hs_volume *, &fsp->hsfs_vol,
695 695 struct hs_volume *, svp,
696 696 struct hs_volume *, jvp);
697 697
698 698 /*
699 699 * Generate a file system ID from the CD-ROM,
700 700 * and check it for uniqueness.
701 701 *
702 702 * What we are aiming for is some chance of integrity
703 703 * across disk change. That is, if a client has an fhandle,
704 704 * it will be valid as long as the same disk is mounted.
705 705 */
706 706 fsid = compute_cdrom_id(fsp, devvp);
707 707
708 708 mutex_enter(&hs_mounttab_lock);
709 709
710 710 if (fsid == 0 || fsid == -1) {
711 711 uniqtime(&tv);
712 712 fsid = tv.tv_sec;
713 713 } else /* make sure that the fsid is unique */
714 714 for (tsp = hs_mounttab; tsp != NULL; tsp = tsp->hsfs_next) {
715 715 if (fsid == tsp->hsfs_vfs->vfs_fsid.val[0]) {
716 716 uniqtime(&tv);
717 717 fsid = tv.tv_sec;
718 718 break;
719 719 }
720 720 }
721 721
722 722 fsp->hsfs_next = hs_mounttab;
723 723 hs_mounttab = fsp;
724 724
725 725 fsp->hsfs_devvp = devvp;
726 726 fsp->hsfs_vfs = vfsp;
727 727 fsp->hsfs_fsmnt = kmem_alloc(pathbufsz, KM_SLEEP);
728 728 (void) strlcpy(fsp->hsfs_fsmnt, path, pathbufsz);
729 729
730 730 mutex_init(&fsp->hsfs_free_lock, NULL, MUTEX_DEFAULT, NULL);
731 731 rw_init(&fsp->hsfs_hash_lock, NULL, RW_DEFAULT, NULL);
732 732
733 733 vfsp->vfs_data = (caddr_t)fsp;
734 734 vfsp->vfs_dev = dev;
735 735 vfsp->vfs_fstype = hsfsfstype;
736 736 vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size; /* %% */
737 737 vfsp->vfs_fsid.val[0] = fsid;
738 738 vfsp->vfs_fsid.val[1] = hsfsfstype;
739 739
740 740 if (!hs_getrootvp(vfsp, fsp, pathbufsz)) {
741 741 DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp);
742 742 error = EINVAL;
743 743 goto cleanup;
744 744 }
745 745 DTRACE_PROBE1(rootvp, struct hsfs *, fsp);
746 746
747 747 /*
748 748 * Attempt to discover a RR extension.
749 749 */
750 750 if (use_rrip) {
751 751 hp = VTOH(fsp->hsfs_rootvp);
752 752 hs_check_root_dirent(fsp->hsfs_rootvp, &(hp->hs_dirent));
753 753 }
754 754
755 755 has_rrip = IS_RRIP_IMPLEMENTED(fsp);
756 756 has_vers2 = (svp->lbn_size != 0);
757 757 has_joliet = (jvp->lbn_size != 0);
758 758
759 759 DTRACE_PROBE4(voltype__suggested, struct hsfs *, fsp,
760 760 int, use_rrip, int, use_vers2, int, use_joliet);
761 761
762 762 DTRACE_PROBE4(voltype__actual, struct hsfs *, fsp,
763 763 int, has_rrip, int, has_vers2, int, has_joliet);
764 764
765 765 DTRACE_PROBE4(findvol,
766 766 struct hsfs *, fsp,
767 767 struct hs_volume *, &fsp->hsfs_vol,
768 768 struct hs_volume *, svp,
769 769 struct hs_volume *, jvp);
770 770
771 771 force_rrip_off = !use_rrip ||
772 772 (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet) ||
773 773 (vfs_optionisset(vfsp, HOPT_VERS2, NULL) && has_vers2);
774 774
775 775 force_vers2_off = !use_vers2 ||
776 776 (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet);
777 777
778 778 force_joliet_off = !use_joliet;
779 779
780 780 DTRACE_PROBE4(voltype__force_off, struct hsfs *, fsp,
781 781 int, force_rrip_off, int, force_vers2_off, int, force_joliet_off);
782 782
783 783 /*
784 784 * At the moment, we have references of all three possible
785 785 * extensions (RR, ISO9660:1999/v2 and Joliet) if present.
786 786 *
787 787 * The "active" volume descriptor is RRIP (or ISO9660:1988).
788 788 * We now switch to the user-requested one.
789 789 */
790 790 redo_rootvp = 0;
791 791
792 792 if (force_rrip_off || !has_rrip) {
793 793 if (has_vers2 && !force_vers2_off) {
794 794 VN_RELE(fsp->hsfs_rootvp);
795 795 bcopy(svp, &fsp->hsfs_vol, sizeof (struct hs_volume));
796 796 fsp->hsfs_vol_type = HS_VOL_TYPE_ISO_V2;
797 797 vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size;
798 798 redo_rootvp = 1;
799 799 has_joliet = 0;
800 800 } else if (has_joliet && !force_joliet_off) {
801 801 VN_RELE(fsp->hsfs_rootvp);
802 802 bcopy(jvp, &fsp->hsfs_vol, sizeof (struct hs_volume));
803 803 fsp->hsfs_vol_type = HS_VOL_TYPE_JOLIET;
804 804 vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size;
805 805 redo_rootvp = 1;
806 806 has_vers2 = 0;
807 807 }
808 808 }
809 809
810 810 if (redo_rootvp) {
811 811 /*
812 812 * Make sure not to use Rock Ridge.
813 813 */
814 814 UNSET_IMPL_BIT(fsp, RRIP_BIT);
815 815 UNSET_SUSP_BIT(fsp);
816 816 has_rrip = 0;
817 817
818 818 if (!hs_getrootvp(vfsp, fsp, pathbufsz)) {
819 819 DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp);
820 820 error = EINVAL;
821 821 goto cleanup;
822 822 }
823 823 DTRACE_PROBE1(rootvp, struct hsfs *, fsp);
824 824 }
825 825 if (IS_RRIP_IMPLEMENTED(fsp)) {
826 826 has_vers2 = 0;
827 827 has_joliet = 0;
828 828 }
829 829 if (force_vers2_off)
830 830 has_vers2 = 0;
831 831 if (force_joliet_off)
832 832 has_joliet = 0;
833 833 DTRACE_PROBE4(voltype__taken, struct hsfs *, fsp,
834 834 int, has_rrip, int, has_vers2, int, has_joliet);
835 835
836 836 /*
837 837 * mark root node as VROOT
838 838 */
839 839 fsp->hsfs_rootvp->v_flag |= VROOT;
840 840
841 841 /* Here we take care of some special case stuff for mountroot */
842 842 if (isroot) {
843 843 fsp->hsfs_rootvp->v_rdev = devvp->v_rdev;
844 844 rootvp = fsp->hsfs_rootvp;
845 845 }
846 846
847 847 if (IS_RRIP_IMPLEMENTED(fsp)) {
848 848 /*
849 849 * if RRIP, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags
850 850 */
851 851 mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT);
852 852
853 853 fsp->hsfs_namemax = RRIP_FILE_NAMELEN;
854 854 fsp->hsfs_namelen = RRIP_FILE_NAMELEN;
855 855
856 856 ASSERT(vfs_optionisset(vfsp, HOPT_RR, NULL));
857 857 vfs_clearmntopt(vfsp, HOPT_VERS2);
858 858 vfs_clearmntopt(vfsp, HOPT_JOLIET);
859 859
860 860 } else switch (fsp->hsfs_vol_type) {
861 861
862 862 case HS_VOL_TYPE_HS:
863 863 case HS_VOL_TYPE_ISO:
864 864 default:
865 865 /*
866 866 * if iso v1, don't allow trailing spaces in iso file names
867 867 */
868 868 mount_flags |= HSFSMNT_NOTRAILSPACE;
869 869 fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX;
870 870 fsp->hsfs_namelen = ISO_FILE_NAMELEN;
871 871 vfs_clearmntopt(vfsp, HOPT_RR);
872 872 vfs_clearmntopt(vfsp, HOPT_VERS2);
873 873 vfs_clearmntopt(vfsp, HOPT_JOLIET);
874 874 break;
875 875
876 876 case HS_VOL_TYPE_ISO_V2:
877 877 /*
878 878 * if iso v2, don't copy NOTRAILDOT to hsfs_flags
879 879 */
880 880 mount_flags &= ~HSFSMNT_NOTRAILDOT;
881 881 mount_flags |= HSFSMNT_NOMAPLCASE | HSFSMNT_NOVERSION;
882 882 fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX;
883 883 fsp->hsfs_namelen = ISO_NAMELEN_V2;
884 884 vfs_setmntopt(vfsp, HOPT_VERS2, NULL, 0);
885 885 vfs_clearmntopt(vfsp, HOPT_RR);
886 886 vfs_clearmntopt(vfsp, HOPT_JOLIET);
887 887 break;
888 888
889 889 case HS_VOL_TYPE_JOLIET:
890 890 /*
891 891 * if Joliet, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags
892 892 */
893 893 mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT);
894 894 mount_flags |= HSFSMNT_NOMAPLCASE;
895 895 if (mount_flags & HSFSMNT_JOLIETLONG)
896 896 fsp->hsfs_namemax = JOLIET_NAMELEN_MAX*3; /* UTF-8 */
897 897 else
898 898 fsp->hsfs_namemax = MAXNAMELEN-1;
899 899 fsp->hsfs_namelen = JOLIET_NAMELEN*2;
900 900 vfs_setmntopt(vfsp, HOPT_JOLIET, NULL, 0);
901 901 vfs_clearmntopt(vfsp, HOPT_RR);
902 902 vfs_clearmntopt(vfsp, HOPT_VERS2);
903 903 break;
904 904 }
905 905
906 906 /*
907 907 * Add the HSFSMNT_INODE pseudo mount flag to the current mount flags.
908 908 */
909 909 fsp->hsfs_flags = mount_flags | (fsp->hsfs_flags & HSFSMNT_INODE);
910 910
911 911 /*
912 912 * Setup I/O Scheduling structures
913 913 */
914 914 if (do_schedio) {
915 915 fsp->hqueue = kmem_alloc(sizeof (struct hsfs_queue), KM_SLEEP);
916 916 hsched_init(fsp, fsid, &modlinkage);
917 917 }
918 918
919 919 /*
920 920 * Setup kstats
921 921 */
922 922 hsfs_init_kstats(fsp, fsid);
923 923
924 924 DTRACE_PROBE1(mount__done, struct hsfs *, fsp);
925 925
926 926 /*
927 927 * set the magic word
928 928 */
929 929 fsp->hsfs_magic = HSFS_MAGIC;
930 930 mutex_exit(&hs_mounttab_lock);
931 931
932 932 kmem_free(svp, sizeof (*svp));
933 933 kmem_free(jvp, sizeof (*jvp));
934 934
935 935 return (0);
936 936
937 937 cleanup:
938 938 (void) VOP_CLOSE(devvp, FREAD, 1, (offset_t)0, cr, NULL);
939 939 VN_RELE(devvp);
940 940 if (fsp)
941 941 kmem_free(fsp, sizeof (*fsp));
942 942 if (svp)
943 943 kmem_free(svp, sizeof (*svp));
944 944 if (jvp)
945 945 kmem_free(jvp, sizeof (*jvp));
946 946 return (error);
947 947 }
948 948
949 949 /*
950 950 * Get the rootvp associated with fsp->hsfs_vol
951 951 */
952 952 static int
953 953 hs_getrootvp(
954 954 struct vfs *vfsp,
955 955 struct hsfs *fsp,
956 956 size_t pathsize)
957 957 {
958 958 struct hsnode *hp;
959 959
960 960 ASSERT(pathsize == strlen(fsp->hsfs_fsmnt) + 1);
961 961
962 962 /*
963 963 * If the root directory does not appear to be
964 964 * valid, use what it points to as "." instead.
965 965 * Some Defense Mapping Agency disks are non-conformant
966 966 * in this way.
967 967 */
968 968 if (!hsfs_valid_dir(&fsp->hsfs_vol.root_dir)) {
969 969 hs_log_bogus_disk_warning(fsp, HSFS_ERR_BAD_ROOT_DIR, 0);
970 970 if (hs_remakenode(fsp->hsfs_vol.root_dir.ext_lbn,
971 971 (uint_t)0, vfsp, &fsp->hsfs_rootvp)) {
972 972 hs_mounttab = hs_mounttab->hsfs_next;
973 973 mutex_destroy(&fsp->hsfs_free_lock);
974 974 rw_destroy(&fsp->hsfs_hash_lock);
975 975 kmem_free(fsp->hsfs_fsmnt, pathsize);
976 976 mutex_exit(&hs_mounttab_lock);
977 977 return (0);
978 978 }
979 979 } else {
980 980 fsp->hsfs_rootvp = hs_makenode(&fsp->hsfs_vol.root_dir,
981 981 fsp->hsfs_vol.root_dir.ext_lbn, 0, vfsp);
982 982 }
983 983
984 984 /* XXX - ignore the path table for now */
985 985 fsp->hsfs_ptbl = NULL;
986 986 hp = VTOH(fsp->hsfs_rootvp);
987 987 hp->hs_ptbl_idx = NULL;
988 988
989 989 return (1);
990 990 }
991 991
992 992 /*
993 993 * hs_findhsvol()
994 994 *
995 995 * Locate the Standard File Structure Volume Descriptor and
996 996 * parse it into an hs_volume structure.
997 997 *
998 998 * XXX - May someday want to look for Coded Character Set FSVD, too.
999 999 */
1000 1000 static int
1001 1001 hs_findhsvol(struct hsfs *fsp, struct vnode *vp, struct hs_volume *hvp)
1002 1002 {
1003 1003 struct buf *secbp;
1004 1004 int i;
1005 1005 int n;
1006 1006 uchar_t *volp;
1007 1007 int error;
1008 1008 uint_t secno;
1009 1009
1010 1010 secno = hs_findvoldesc(vp->v_rdev, HS_VOLDESC_SEC);
1011 1011 secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
1012 1012 error = geterror(secbp);
1013 1013
1014 1014 if (error != 0) {
1015 1015 cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)", error);
1016 1016 brelse(secbp);
1017 1017 return (error);
1018 1018 }
1019 1019
1020 1020 volp = (uchar_t *)secbp->b_un.b_addr;
1021 1021
1022 1022 /*
1023 1023 * To avoid that we read the whole medium in case that someone prepares
1024 1024 * a malicious "fs image", we read at most 32 blocks.
1025 1025 */
1026 1026 for (n = 0; n < 32 &&
1027 1027 HSV_DESC_TYPE(volp) != VD_EOV; n++) {
1028 1028 for (i = 0; i < HSV_ID_STRLEN; i++)
1029 1029 if (HSV_STD_ID(volp)[i] != HSV_ID_STRING[i])
1030 1030 goto cantfind;
1031 1031 if (HSV_STD_VER(volp) != HSV_ID_VER)
1032 1032 goto cantfind;
1033 1033 switch (HSV_DESC_TYPE(volp)) {
1034 1034 case VD_SFS:
1035 1035 /* Standard File Structure */
1036 1036 fsp->hsfs_vol_type = HS_VOL_TYPE_HS;
1037 1037 error = hs_parsehsvol(fsp, volp, hvp);
1038 1038 brelse(secbp);
1039 1039 return (error);
1040 1040
1041 1041 case VD_CCFS:
1042 1042 /* Coded Character File Structure */
1043 1043 case VD_BOOT:
1044 1044 case VD_UNSPEC:
1045 1045 case VD_EOV:
1046 1046 break;
1047 1047 }
1048 1048 brelse(secbp);
1049 1049 ++secno;
1050 1050 secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
1051 1051
1052 1052 error = geterror(secbp);
1053 1053
1054 1054 if (error != 0) {
1055 1055 cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)",
1056 1056 error);
1057 1057 brelse(secbp);
1058 1058 return (error);
1059 1059 }
1060 1060
1061 1061 volp = (uchar_t *)secbp->b_un.b_addr;
1062 1062 }
1063 1063 cantfind:
1064 1064 brelse(secbp);
1065 1065 return (EINVAL);
1066 1066 }
1067 1067
1068 1068 /*
1069 1069 * hs_parsehsvol
1070 1070 *
1071 1071 * Parse the Standard File Structure Volume Descriptor into
1072 1072 * an hs_volume structure. We can't just bcopy it into the
1073 1073 * structure because of byte-ordering problems.
1074 1074 *
1075 1075 */
1076 1076 static int
1077 1077 hs_parsehsvol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp)
1078 1078 {
1079 1079 hvp->vol_size = HSV_VOL_SIZE(volp);
1080 1080 hvp->lbn_size = HSV_BLK_SIZE(volp);
1081 1081 if (hvp->lbn_size == 0) {
1082 1082 cmn_err(CE_NOTE, "hs_parsehsvol: logical block size in the "
1083 1083 "SFSVD is zero");
1084 1084 return (EINVAL);
1085 1085 }
1086 1086 hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1;
1087 1087 hvp->lbn_secshift =
1088 1088 ffs((long)howmany(HS_SECTOR_SIZE, (int)hvp->lbn_size)) - 1;
1089 1089 hvp->lbn_maxoffset = hvp->lbn_size - 1;
1090 1090 hs_parse_longdate(HSV_cre_date(volp), &hvp->cre_date);
1091 1091 hs_parse_longdate(HSV_mod_date(volp), &hvp->mod_date);
1092 1092 hvp->file_struct_ver = HSV_FILE_STRUCT_VER(volp);
1093 1093 hvp->ptbl_len = HSV_PTBL_SIZE(volp);
1094 1094 hvp->vol_set_size = (ushort_t)HSV_SET_SIZE(volp);
1095 1095 hvp->vol_set_seq = (ushort_t)HSV_SET_SEQ(volp);
1096 1096 #if defined(_LITTLE_ENDIAN)
1097 1097 hvp->ptbl_lbn = HSV_PTBL_MAN_LS(volp);
1098 1098 #else
1099 1099 hvp->ptbl_lbn = HSV_PTBL_MAN_MS(volp);
1100 1100 #endif
1101 1101 hs_copylabel(hvp, HSV_VOL_ID(volp), 0);
1102 1102
1103 1103 /*
1104 1104 * Make sure that lbn_size is a power of two and otherwise valid.
1105 1105 */
1106 1106 if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) {
1107 1107 cmn_err(CE_NOTE,
1108 1108 "hsfs: %d-byte logical block size not supported",
1109 1109 hvp->lbn_size);
1110 1110 return (EINVAL);
1111 1111 }
1112 1112 return (hs_parsedir(fsp, HSV_ROOT_DIR(volp), &hvp->root_dir,
1113 1113 (char *)NULL, (int *)NULL, HDE_ROOT_DIR_REC_SIZE));
1114 1114 }
1115 1115
1116 1116 /*
1117 1117 * hs_findisovol()
1118 1118 *
1119 1119 * Locate the Primary Volume Descriptor
1120 1120 * parse it into an hs_volume structure.
1121 1121 *
1122 1122 * XXX - Partition not yet done
1123 1123 *
1124 1124 * Except for fsp->hsfs_vol_type, no fsp member may be modified.
1125 1125 * fsp->hsfs_vol is modified indirectly via the *hvp argument.
1126 1126 */
1127 1127 static int
1128 1128 hs_findisovol(struct hsfs *fsp, struct vnode *vp,
1129 1129 struct hs_volume *hvp,
1130 1130 struct hs_volume *svp,
1131 1131 struct hs_volume *jvp)
1132 1132 {
1133 1133 struct buf *secbp;
1134 1134 int i;
1135 1135 int n;
1136 1136 uchar_t *volp;
1137 1137 int error;
1138 1138 uint_t secno;
1139 1139 int foundpvd = 0;
1140 1140 int foundsvd = 0;
1141 1141 int foundjvd = 0;
1142 1142 int pvd_sum = 0;
1143 1143
1144 1144 secno = hs_findvoldesc(vp->v_rdev, ISO_VOLDESC_SEC);
1145 1145 secbp = bread(vp->v_rdev, secno * 4, ISO_SECTOR_SIZE);
1146 1146 error = geterror(secbp);
1147 1147
1148 1148 if (error != 0) {
1149 1149 cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)", error);
1150 1150 brelse(secbp);
1151 1151 return (error);
1152 1152 }
1153 1153
1154 1154 volp = (uchar_t *)secbp->b_un.b_addr;
1155 1155
1156 1156 /*
1157 1157 * To avoid that we read the whole medium in case that someone prepares
1158 1158 * a malicious "fs image", we read at most 32 blocks.
1159 1159 */
1160 1160 for (n = 0; n < 32 && ISO_DESC_TYPE(volp) != ISO_VD_EOV; n++) {
1161 1161 for (i = 0; i < ISO_ID_STRLEN; i++)
1162 1162 if (ISO_STD_ID(volp)[i] != ISO_ID_STRING[i])
1163 1163 goto cantfind;
1164 1164 switch (ISO_DESC_TYPE(volp)) {
1165 1165 case ISO_VD_PVD:
1166 1166 /* Standard File Structure */
1167 1167 if (ISO_STD_VER(volp) != ISO_ID_VER)
1168 1168 goto cantfind;
1169 1169 if (foundpvd != 1) {
1170 1170 fsp->hsfs_vol_type = HS_VOL_TYPE_ISO;
1171 1171 if (error = hs_parseisovol(fsp, volp, hvp)) {
1172 1172 brelse(secbp);
1173 1173 return (error);
1174 1174 }
1175 1175 foundpvd = 1;
1176 1176 for (i = 0; i < ISO_SECTOR_SIZE; i++)
1177 1177 pvd_sum += volp[i];
1178 1178 }
1179 1179 break;
1180 1180 case ISO_VD_SVD:
1181 1181 /* Supplementary Volume Descriptor */
1182 1182 if (ISO_STD_VER(volp) == ISO_ID_VER2 &&
1183 1183 foundsvd != 1) {
1184 1184 fsp->hsfs_vol_type = HS_VOL_TYPE_ISO;
1185 1185 if (error = hs_parseisovol(fsp, volp, svp)) {
1186 1186 brelse(secbp);
1187 1187 return (error);
1188 1188 }
1189 1189 foundsvd = 1;
1190 1190 }
1191 1191 if (hs_joliet_level(volp) >= 1 && foundjvd != 1) {
1192 1192 fsp->hsfs_vol_type = HS_VOL_TYPE_ISO;
1193 1193 if (error = hs_parseisovol(fsp, volp, jvp)) {
1194 1194 brelse(secbp);
1195 1195 return (error);
1196 1196 }
1197 1197 foundjvd = 1;
1198 1198 }
1199 1199 break;
1200 1200 case ISO_VD_BOOT:
1201 1201 break;
1202 1202 case ISO_VD_VPD:
1203 1203 /* currently cannot handle partition */
1204 1204 break;
1205 1205 case VD_EOV:
1206 1206 break;
1207 1207 }
1208 1208 brelse(secbp);
1209 1209 ++secno;
1210 1210 secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
1211 1211 error = geterror(secbp);
1212 1212
1213 1213 if (error != 0) {
1214 1214 cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)",
1215 1215 error);
1216 1216 brelse(secbp);
1217 1217 return (error);
1218 1218 }
1219 1219
1220 1220 volp = (uchar_t *)secbp->b_un.b_addr;
1221 1221 }
1222 1222 for (n = 0; n < 16; n++) {
1223 1223 brelse(secbp);
1224 1224 ++secno;
1225 1225 secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
1226 1226 error = geterror(secbp);
1227 1227
1228 1228 if (error != 0) {
1229 1229 cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)",
1230 1230 error);
1231 1231 brelse(secbp);
1232 1232 return (error);
1233 1233 }
1234 1234
1235 1235 /*
1236 1236 * Check for the signature from mkisofs that grants that
1237 1237 * the current filesystem allows to use the extent lbn as
1238 1238 * inode number even in pure ISO9660 mode.
1239 1239 */
1240 1240 volp = (uchar_t *)secbp->b_un.b_addr;
1241 1241 if (strncmp((char *)volp, "MKI ", 4) == 0) {
1242 1242 int sum;
1243 1243
1244 1244 sum = volp[2045];
1245 1245 sum *= 256;
1246 1246 sum += volp[2046];
1247 1247 sum *= 256;
1248 1248 sum += volp[2047];
1249 1249 if (sum == pvd_sum)
1250 1250 fsp->hsfs_flags |= HSFSMNT_INODE;
1251 1251 break;
1252 1252 }
1253 1253 }
1254 1254 if (foundpvd) {
1255 1255 brelse(secbp);
1256 1256 return (0);
1257 1257 }
1258 1258 cantfind:
1259 1259 brelse(secbp);
1260 1260 return (EINVAL);
1261 1261 }
1262 1262
1263 1263 /*
1264 1264 * Return 0 if no Joliet is found
1265 1265 * else return Joliet Level 1..3
1266 1266 */
1267 1267 static int
1268 1268 hs_joliet_level(uchar_t *volp)
1269 1269 {
1270 1270 if (ISO_std_ver(volp)[0] == ISO_ID_VER &&
1271 1271 ISO_svd_esc(volp)[0] == '%' &&
1272 1272 ISO_svd_esc(volp)[1] == '/') {
1273 1273
1274 1274 switch (ISO_svd_esc(volp)[2]) {
1275 1275
1276 1276 case '@':
1277 1277 return (1);
1278 1278 case 'C':
1279 1279 return (2);
1280 1280 case 'E':
1281 1281 return (3);
1282 1282 }
1283 1283 }
1284 1284 return (0);
1285 1285 }
1286 1286
1287 1287 /*
1288 1288 * hs_parseisovol
1289 1289 *
1290 1290 * Parse the Primary Volume Descriptor into an hs_volume structure.
1291 1291 *
1292 1292 */
1293 1293 static int
1294 1294 hs_parseisovol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp)
1295 1295 {
1296 1296 hvp->vol_size = ISO_VOL_SIZE(volp);
1297 1297 hvp->lbn_size = ISO_BLK_SIZE(volp);
1298 1298 if (hvp->lbn_size == 0) {
1299 1299 cmn_err(CE_NOTE, "hs_parseisovol: logical block size in the "
1300 1300 "PVD is zero");
1301 1301 return (EINVAL);
1302 1302 }
1303 1303 hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1;
1304 1304 hvp->lbn_secshift =
1305 1305 ffs((long)howmany(ISO_SECTOR_SIZE, (int)hvp->lbn_size)) - 1;
1306 1306 hvp->lbn_maxoffset = hvp->lbn_size - 1;
1307 1307 hs_parse_longdate(ISO_cre_date(volp), &hvp->cre_date);
1308 1308 hs_parse_longdate(ISO_mod_date(volp), &hvp->mod_date);
1309 1309 hvp->file_struct_ver = ISO_FILE_STRUCT_VER(volp);
1310 1310 hvp->ptbl_len = ISO_PTBL_SIZE(volp);
1311 1311 hvp->vol_set_size = (ushort_t)ISO_SET_SIZE(volp);
1312 1312 hvp->vol_set_seq = (ushort_t)ISO_SET_SEQ(volp);
1313 1313 #if defined(_LITTLE_ENDIAN)
1314 1314 hvp->ptbl_lbn = ISO_PTBL_MAN_LS(volp);
1315 1315 #else
1316 1316 hvp->ptbl_lbn = ISO_PTBL_MAN_MS(volp);
1317 1317 #endif
1318 1318 hs_copylabel(hvp, ISO_VOL_ID(volp), hs_joliet_level(volp) >= 1);
1319 1319
1320 1320 /*
1321 1321 * Make sure that lbn_size is a power of two and otherwise valid.
1322 1322 */
1323 1323 if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) {
1324 1324 cmn_err(CE_NOTE,
1325 1325 "hsfs: %d-byte logical block size not supported",
1326 1326 hvp->lbn_size);
1327 1327 return (EINVAL);
1328 1328 }
1329 1329 return (hs_parsedir(fsp, ISO_ROOT_DIR(volp), &hvp->root_dir,
1330 1330 (char *)NULL, (int *)NULL, IDE_ROOT_DIR_REC_SIZE));
1331 1331 }
1332 1332
1333 1333 /*
1334 1334 * Common code for mount and umount.
1335 1335 * Check that the user's argument is a reasonable
1336 1336 * thing on which to mount, and return the device number if so.
1337 1337 */
1338 1338 static int
1339 1339 hs_getmdev(struct vfs *vfsp, char *fspec, int flags, dev_t *pdev, mode_t *mode,
1340 1340 cred_t *cr)
1341 1341 {
1342 1342 int error;
1343 1343 struct vnode *svp = NULL;
1344 1344 struct vnode *lvp = NULL;
1345 1345 struct vnode *bvp;
1346 1346 struct vattr vap;
1347 1347 dev_t dev;
1348 1348 enum uio_seg fromspace = (flags & MS_SYSSPACE) ?
1349 1349 UIO_SYSSPACE : UIO_USERSPACE;
1350 1350
1351 1351 /*
1352 1352 * Look up the device/file to be mounted.
1353 1353 */
1354 1354 error = lookupname(fspec, fromspace, FOLLOW, NULLVPP, &svp);
1355 1355 if (error) {
1356 1356 if (error == ENOENT)
1357 1357 error = ENODEV;
1358 1358 goto out;
1359 1359 }
1360 1360
1361 1361 error = vfs_get_lofi(vfsp, &lvp);
1362 1362
1363 1363 if (error > 0) {
1364 1364 if (error == ENOENT)
1365 1365 error = ENODEV;
1366 1366 goto out;
1367 1367 } else if (error == 0) {
1368 1368 bvp = lvp;
1369 1369 } else {
1370 1370 bvp = svp;
1371 1371
1372 1372 if (bvp->v_type != VBLK) {
1373 1373 error = ENOTBLK;
1374 1374 goto out;
1375 1375 }
1376 1376
1377 1377 if ((error = secpolicy_spec_open(cr, bvp, FREAD)) != 0)
1378 1378 goto out;
1379 1379 }
1380 1380
1381 1381 /*
1382 1382 * Can we read from the device/file ?
1383 1383 */
1384 1384 if ((error = VOP_ACCESS(svp, VREAD, 0, cr, NULL)) != 0)
1385 1385 goto out;
1386 1386
1387 1387 vap.va_mask = AT_MODE; /* get protection mode */
1388 1388 (void) VOP_GETATTR(bvp, &vap, 0, CRED(), NULL);
1389 1389 *mode = vap.va_mode;
1390 1390
1391 1391 dev = *pdev = bvp->v_rdev;
1392 1392
1393 1393 error = EBUSY;
1394 1394
1395 1395 /*
1396 1396 * Ensure that this device isn't already mounted,
1397 1397 * unless this is a REMOUNT request or we are told to suppress
1398 1398 * mount checks.
1399 1399 */
1400 1400 if ((flags & MS_NOCHECK) == 0) {
1401 1401 if (vfs_devmounting(dev, vfsp))
1402 1402 goto out;
1403 1403 if (vfs_devismounted(dev) && !(flags & MS_REMOUNT))
1404 1404 goto out;
1405 1405 }
1406 1406
1407 1407 if (getmajor(*pdev) >= devcnt) {
1408 1408 error = ENXIO;
1409 1409 goto out;
1410 1410 }
1411 1411
1412 1412 error = 0;
1413 1413 out:
1414 1414 if (svp != NULL)
1415 1415 VN_RELE(svp);
1416 1416 if (lvp != NULL)
1417 1417 VN_RELE(lvp);
1418 1418 return (error);
1419 1419 }
1420 1420
1421 1421 static void
1422 1422 hs_copylabel(struct hs_volume *hvp, unsigned char *label, int isjoliet)
1423 1423 {
1424 1424 char lbuf[64]; /* hs_joliet_cp() creates 48 bytes at most */
1425 1425
1426 1426 if (isjoliet) {
1427 1427 /*
1428 1428 * hs_joliet_cp() will output 16..48 bytes.
1429 1429 * We need to clear 'lbuf' to avoid junk chars past byte 15.
1430 1430 */
1431 1431 bzero(lbuf, sizeof (lbuf));
1432 1432 (void) hs_joliet_cp((char *)label, lbuf, 32);
1433 1433 label = (unsigned char *)lbuf;
1434 1434 }
1435 1435 /* cdrom volid is at most 32 bytes */
1436 1436 bcopy(label, hvp->vol_id, 32);
1437 1437 hvp->vol_id[31] = NULL;
1438 1438 }
1439 1439
1440 1440 /*
1441 1441 * Mount root file system.
1442 1442 * "why" is ROOT_INIT on initial call, ROOT_REMOUNT if called to
1443 1443 * remount the root file system, and ROOT_UNMOUNT if called to
1444 1444 * unmount the root (e.g., as part of a system shutdown).
1445 1445 *
1446 1446 * XXX - this may be partially machine-dependent; it, along with the VFS_SWAPVP
1447 1447 * operation, goes along with auto-configuration. A mechanism should be
1448 1448 * provided by which machine-INdependent code in the kernel can say "get me the
1449 1449 * right root file system" and "get me the right initial swap area", and have
1450 1450 * that done in what may well be a machine-dependent fashion.
1451 1451 * Unfortunately, it is also file-system-type dependent (NFS gets it via
1452 1452 * bootparams calls, UFS gets it from various and sundry machine-dependent
1453 1453 * mechanisms, as SPECFS does for swap).
1454 1454 */
1455 1455 static int
1456 1456 hsfs_mountroot(struct vfs *vfsp, enum whymountroot why)
1457 1457 {
1458 1458 int error;
1459 1459 struct hsfs *fsp;
1460 1460 struct hs_volume *fvolp;
1461 1461 static int hsfsrootdone = 0;
1462 1462 dev_t rootdev;
1463 1463 mode_t mode = 0;
1464 1464
1465 1465 if (why == ROOT_INIT) {
1466 1466 if (hsfsrootdone++)
1467 1467 return (EBUSY);
1468 1468 rootdev = getrootdev();
1469 1469 if (rootdev == (dev_t)NODEV)
1470 1470 return (ENODEV);
1471 1471 vfsp->vfs_dev = rootdev;
1472 1472 vfsp->vfs_flag |= VFS_RDONLY;
1473 1473 } else if (why == ROOT_REMOUNT) {
1474 1474 cmn_err(CE_NOTE, "hsfs_mountroot: ROOT_REMOUNT");
1475 1475 return (0);
1476 1476 } else if (why == ROOT_UNMOUNT) {
1477 1477 return (0);
1478 1478 }
1479 1479 error = vfs_lock(vfsp);
1480 1480 if (error) {
1481 1481 cmn_err(CE_NOTE, "hsfs_mountroot: couldn't get vfs_lock");
1482 1482 return (error);
1483 1483 }
1484 1484
1485 1485 error = hs_mountfs(vfsp, rootdev, "/", mode, 1, CRED(), 1);
1486 1486 /*
1487 1487 * XXX - assumes root device is not indirect, because we don't set
1488 1488 * rootvp. Is rootvp used for anything? If so, make another arg
1489 1489 * to mountfs.
1490 1490 */
1491 1491 if (error) {
1492 1492 vfs_unlock(vfsp);
1493 1493 if (rootvp) {
1494 1494 VN_RELE(rootvp);
1495 1495 rootvp = (struct vnode *)0;
1496 1496 }
1497 1497 return (error);
1498 1498 }
1499 1499 if (why == ROOT_INIT)
1500 1500 vfs_add((struct vnode *)0, vfsp,
1501 1501 (vfsp->vfs_flag & VFS_RDONLY) ? MS_RDONLY : 0);
1502 1502 vfs_unlock(vfsp);
1503 1503 fsp = VFS_TO_HSFS(vfsp);
1504 1504 fvolp = &fsp->hsfs_vol;
1505 1505 #ifdef HSFS_CLKSET
1506 1506 if (fvolp->cre_date.tv_sec == 0) {
1507 1507 cmn_err(CE_NOTE, "hsfs_mountroot: cre_date.tv_sec == 0");
1508 1508 if (fvolp->mod_date.tv_sec == 0) {
1509 1509 cmn_err(CE_NOTE,
1510 1510 "hsfs_mountroot: mod_date.tv_sec == 0");
1511 1511 cmn_err(CE_NOTE, "hsfs_mountroot: clkset(-1L)");
1512 1512 clkset(-1L);
1513 1513 } else {
1514 1514 clkset(fvolp->mod_date.tv_sec);
1515 1515 }
1516 1516 } else {
1517 1517 clkset(fvolp->mod_date.tv_sec);
1518 1518 }
1519 1519 #else /* HSFS_CLKSET */
1520 1520 clkset(-1L);
1521 1521 #endif /* HSFS_CLKSET */
1522 1522 return (0);
1523 1523 }
1524 1524
1525 1525 /*
1526 1526 * hs_findvoldesc()
1527 1527 *
1528 1528 * Return the sector where the volume descriptor lives. This is
1529 1529 * a fixed value for "normal" cd-rom's, but can change for
1530 1530 * multisession cd's.
1531 1531 *
1532 1532 * desc_sec is the same for high-sierra and iso 9660 formats, why
1533 1533 * there are two different #defines used in the code for this is
1534 1534 * beyond me. These are standards, cast in concrete, right?
1535 1535 * To be general, however, this function supports passing in different
1536 1536 * values.
1537 1537 */
1538 1538 static int
1539 1539 hs_findvoldesc(dev_t rdev, int desc_sec)
1540 1540 {
1541 1541 int secno;
1542 1542 int error;
1543 1543 int rval; /* ignored */
1544 1544
1545 1545 #ifdef CDROMREADOFFSET
1546 1546 /*
1547 1547 * Issue the Read Offset ioctl directly to the
1548 1548 * device. Ignore any errors and set starting
1549 1549 * secno to the default, otherwise add the
1550 1550 * VOLDESC sector number to the offset.
1551 1551 */
1552 1552 error = cdev_ioctl(rdev, CDROMREADOFFSET, (intptr_t)&secno,
1553 1553 FNATIVE|FKIOCTL|FREAD, CRED(), &rval);
1554 1554 if (error) {
1555 1555 secno = desc_sec;
1556 1556 } else {
1557 1557 secno += desc_sec;
1558 1558 }
1559 1559 #else
1560 1560 secno = desc_sec;
1561 1561 #endif
1562 1562
1563 1563 return (secno);
1564 1564 }
↓ open down ↓ |
1295 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX