Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/udfs/udf_vfsops.c
+++ new/usr/src/uts/common/fs/udfs/udf_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 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
25 25 */
26 26
27 27 #include <sys/types.h>
28 28 #include <sys/t_lock.h>
29 29 #include <sys/param.h>
30 30 #include <sys/time.h>
31 31 #include <sys/systm.h>
32 32 #include <sys/sysmacros.h>
33 33 #include <sys/resource.h>
34 34 #include <sys/signal.h>
35 35 #include <sys/cred.h>
36 36 #include <sys/user.h>
37 37 #include <sys/buf.h>
38 38 #include <sys/vfs.h>
39 39 #include <sys/vfs_opreg.h>
40 40 #include <sys/stat.h>
41 41 #include <sys/vnode.h>
42 42 #include <sys/mode.h>
43 43 #include <sys/proc.h>
44 44 #include <sys/disp.h>
45 45 #include <sys/file.h>
46 46 #include <sys/fcntl.h>
47 47 #include <sys/flock.h>
48 48 #include <sys/kmem.h>
49 49 #include <sys/uio.h>
50 50 #include <sys/dnlc.h>
51 51 #include <sys/conf.h>
52 52 #include <sys/errno.h>
53 53 #include <sys/mman.h>
54 54 #include <sys/fbuf.h>
55 55 #include <sys/pathname.h>
56 56 #include <sys/debug.h>
57 57 #include <sys/vmsystm.h>
58 58 #include <sys/cmn_err.h>
59 59 #include <sys/dirent.h>
60 60 #include <sys/errno.h>
61 61 #include <sys/modctl.h>
62 62 #include <sys/statvfs.h>
63 63 #include <sys/mount.h>
64 64 #include <sys/sunddi.h>
65 65 #include <sys/bootconf.h>
66 66 #include <sys/policy.h>
67 67
68 68 #include <vm/hat.h>
69 69 #include <vm/page.h>
70 70 #include <vm/pvn.h>
71 71 #include <vm/as.h>
72 72 #include <vm/seg.h>
73 73 #include <vm/seg_map.h>
74 74 #include <vm/seg_kmem.h>
75 75 #include <vm/seg_vn.h>
76 76 #include <vm/rm.h>
77 77 #include <vm/page.h>
78 78 #include <sys/swap.h>
79 79 #include <sys/mntent.h>
80 80
81 81
82 82 #include <fs/fs_subr.h>
83 83
84 84
85 85 #include <sys/fs/udf_volume.h>
86 86 #include <sys/fs/udf_inode.h>
87 87
88 88
89 89 extern struct vnode *common_specvp(struct vnode *vp);
90 90
91 91 extern kmutex_t ud_sync_busy;
92 92 static int32_t ud_mountfs(struct vfs *,
93 93 enum whymountroot, dev_t, char *, struct cred *, int32_t);
94 94 static struct udf_vfs *ud_validate_and_fill_superblock(dev_t,
95 95 int32_t, uint32_t);
96 96 void ud_destroy_fsp(struct udf_vfs *);
97 97 void ud_convert_to_superblock(struct udf_vfs *,
98 98 struct log_vol_int_desc *);
99 99 void ud_update_superblock(struct vfs *);
100 100 int32_t ud_get_last_block(dev_t, daddr_t *);
101 101 static int32_t ud_val_get_vat(struct udf_vfs *,
102 102 dev_t, daddr_t, struct ud_map *);
103 103 int32_t ud_read_sparing_tbls(struct udf_vfs *,
104 104 dev_t, struct ud_map *, struct pmap_typ2 *);
105 105 uint32_t ud_get_lbsize(dev_t, uint32_t *);
106 106
107 107 static int32_t udf_mount(struct vfs *,
108 108 struct vnode *, struct mounta *, struct cred *);
109 109 static int32_t udf_unmount(struct vfs *, int, struct cred *);
110 110 static int32_t udf_root(struct vfs *, struct vnode **);
111 111 static int32_t udf_statvfs(struct vfs *, struct statvfs64 *);
112 112 static int32_t udf_sync(struct vfs *, int16_t, struct cred *);
113 113 static int32_t udf_vget(struct vfs *, struct vnode **, struct fid *);
114 114 static int32_t udf_mountroot(struct vfs *vfsp, enum whymountroot);
115 115
116 116 static int udfinit(int, char *);
117 117
118 118 static mntopts_t udfs_mntopts;
119 119
120 120 static vfsdef_t vfw = {
121 121 VFSDEF_VERSION,
122 122 "udfs",
123 123 udfinit,
124 124 VSW_HASPROTO|VSW_CANREMOUNT|VSW_STATS|VSW_CANLOFI,
125 125 &udfs_mntopts
126 126 };
127 127
128 128 static mntopts_t udfs_mntopts = {
129 129 0,
130 130 NULL
131 131 };
132 132
↓ open down ↓ |
132 lines elided |
↑ open up ↑ |
133 133 /*
134 134 * Module linkage information for the kernel.
135 135 */
136 136 extern struct mod_ops mod_fsops;
137 137
138 138 static struct modlfs modlfs = {
139 139 &mod_fsops, "filesystem for UDFS", &vfw
140 140 };
141 141
142 142 static struct modlinkage modlinkage = {
143 - MODREV_1, (void *)&modlfs, NULL
143 + MODREV_1, { (void *)&modlfs, NULL }
144 144 };
145 145
146 146 int32_t udf_fstype = -1;
147 147
148 148 int
149 149 _init()
150 150 {
151 151 return (mod_install(&modlinkage));
152 152 }
153 153
154 154 int
155 155 _fini()
156 156 {
157 157 return (EBUSY);
158 158 }
159 159
160 160 int
161 161 _info(struct modinfo *modinfop)
162 162 {
163 163 return (mod_info(&modlinkage, modinfop));
164 164 }
165 165
166 166
167 167 /* -------------------- vfs routines -------------------- */
168 168
169 169 /*
170 170 * XXX - this appears only to be used by the VM code to handle the case where
171 171 * UNIX is running off the mini-root. That probably wants to be done
172 172 * differently.
173 173 */
174 174 struct vnode *rootvp;
175 175 #ifndef __lint
176 176 _NOTE(SCHEME_PROTECTS_DATA("safe sharing", rootvp))
177 177 #endif
178 178 static int32_t
179 179 udf_mount(struct vfs *vfsp, struct vnode *mvp,
180 180 struct mounta *uap, struct cred *cr)
181 181 {
182 182 dev_t dev;
183 183 struct vnode *lvp = NULL;
184 184 struct vnode *svp = NULL;
185 185 struct pathname dpn;
186 186 int32_t error;
187 187 enum whymountroot why;
188 188 int oflag, aflag;
189 189
190 190 ud_printf("udf_mount\n");
191 191
192 192 if ((error = secpolicy_fs_mount(cr, mvp, vfsp)) != 0) {
193 193 return (error);
194 194 }
195 195
196 196 if (mvp->v_type != VDIR) {
197 197 return (ENOTDIR);
198 198 }
199 199
200 200 mutex_enter(&mvp->v_lock);
201 201 if ((uap->flags & MS_REMOUNT) == 0 &&
202 202 (uap->flags & MS_OVERLAY) == 0 &&
203 203 (mvp->v_count != 1 || (mvp->v_flag & VROOT))) {
204 204 mutex_exit(&mvp->v_lock);
205 205 return (EBUSY);
206 206 }
207 207 mutex_exit(&mvp->v_lock);
208 208
209 209 if (error = pn_get(uap->dir, UIO_USERSPACE, &dpn)) {
210 210 return (error);
211 211 }
212 212
213 213 /*
214 214 * Resolve path name of the file being mounted.
215 215 */
216 216 if (error = lookupname(uap->spec, UIO_USERSPACE, FOLLOW, NULLVPP,
217 217 &svp)) {
218 218 pn_free(&dpn);
219 219 return (error);
220 220 }
221 221
222 222 error = vfs_get_lofi(vfsp, &lvp);
223 223
224 224 if (error > 0) {
225 225 if (error == ENOENT)
226 226 error = ENODEV;
227 227 goto out;
228 228 } else if (error == 0) {
229 229 dev = lvp->v_rdev;
230 230 } else {
231 231 dev = svp->v_rdev;
232 232
233 233 if (svp->v_type != VBLK) {
234 234 error = ENOTBLK;
235 235 goto out;
236 236 }
237 237 }
238 238
239 239 /*
240 240 * Ensure that this device isn't already mounted,
241 241 * unless this is a REMOUNT request
242 242 */
243 243 if (vfs_devmounting(dev, vfsp)) {
244 244 error = EBUSY;
245 245 goto out;
246 246 }
247 247 if (vfs_devismounted(dev)) {
248 248 if (uap->flags & MS_REMOUNT) {
249 249 why = ROOT_REMOUNT;
250 250 } else {
251 251 error = EBUSY;
252 252 goto out;
253 253 }
254 254 } else {
255 255 why = ROOT_INIT;
256 256 }
257 257 if (getmajor(dev) >= devcnt) {
258 258 error = ENXIO;
259 259 goto out;
260 260 }
261 261
262 262 /*
263 263 * If the device is a tape, mount it read only
264 264 */
265 265 if (devopsp[getmajor(dev)]->devo_cb_ops->cb_flag & D_TAPE) {
266 266 vfsp->vfs_flag |= VFS_RDONLY;
267 267 }
268 268
269 269 if (uap->flags & MS_RDONLY) {
270 270 vfsp->vfs_flag |= VFS_RDONLY;
271 271 }
272 272
273 273 /*
274 274 * Set mount options.
275 275 */
276 276 if (uap->flags & MS_RDONLY) {
277 277 vfs_setmntopt(vfsp, MNTOPT_RO, NULL, 0);
278 278 }
279 279 if (uap->flags & MS_NOSUID) {
280 280 vfs_setmntopt(vfsp, MNTOPT_NOSUID, NULL, 0);
281 281 }
282 282
283 283 /*
284 284 * Verify that the caller can open the device special file as
285 285 * required. It is not until this moment that we know whether
286 286 * we're mounting "ro" or not.
287 287 */
288 288 if ((vfsp->vfs_flag & VFS_RDONLY) != 0) {
289 289 oflag = FREAD;
290 290 aflag = VREAD;
291 291 } else {
292 292 oflag = FREAD | FWRITE;
293 293 aflag = VREAD | VWRITE;
294 294 }
295 295
296 296 if (lvp == NULL &&
297 297 (error = secpolicy_spec_open(cr, svp, oflag)) != 0)
298 298 goto out;
299 299
300 300 if ((error = VOP_ACCESS(svp, aflag, 0, cr, NULL)) != 0)
301 301 goto out;
302 302
303 303 /*
304 304 * Mount the filesystem.
305 305 */
306 306 error = ud_mountfs(vfsp, why, dev, dpn.pn_path, cr, 0);
307 307 out:
308 308 VN_RELE(svp);
309 309 if (lvp != NULL)
310 310 VN_RELE(lvp);
311 311 pn_free(&dpn);
312 312 return (error);
313 313 }
314 314
315 315
316 316
317 317 /*
318 318 * unmount the file system pointed
319 319 * by vfsp
320 320 */
321 321 /* ARGSUSED */
322 322 static int32_t
323 323 udf_unmount(struct vfs *vfsp, int fflag, struct cred *cr)
324 324 {
325 325 struct udf_vfs *udf_vfsp;
326 326 struct vnode *bvp, *rvp;
327 327 struct ud_inode *rip;
328 328 int32_t flag;
329 329
330 330 ud_printf("udf_unmount\n");
331 331
332 332 if (secpolicy_fs_unmount(cr, vfsp) != 0) {
333 333 return (EPERM);
334 334 }
335 335
336 336 /*
337 337 * forced unmount is not supported by this file system
338 338 * and thus, ENOTSUP, is being returned.
339 339 */
340 340 if (fflag & MS_FORCE)
341 341 return (ENOTSUP);
342 342
343 343 udf_vfsp = (struct udf_vfs *)vfsp->vfs_data;
344 344 flag = !(udf_vfsp->udf_flags & UDF_FL_RDONLY);
345 345 bvp = udf_vfsp->udf_devvp;
346 346
347 347 rvp = udf_vfsp->udf_root;
348 348 ASSERT(rvp != NULL);
349 349 rip = VTOI(rvp);
350 350
351 351 (void) ud_release_cache(udf_vfsp);
352 352
353 353
354 354 /* Flush all inodes except root */
355 355 if (ud_iflush(vfsp) < 0) {
356 356 return (EBUSY);
357 357 }
358 358
359 359 rw_enter(&rip->i_contents, RW_WRITER);
360 360 (void) ud_syncip(rip, B_INVAL, I_SYNC);
361 361 rw_exit(&rip->i_contents);
362 362
363 363 mutex_enter(&ud_sync_busy);
364 364 if ((udf_vfsp->udf_flags & UDF_FL_RDONLY) == 0) {
365 365 bflush(vfsp->vfs_dev);
366 366 mutex_enter(&udf_vfsp->udf_lock);
367 367 udf_vfsp->udf_clean = UDF_CLEAN;
368 368 mutex_exit(&udf_vfsp->udf_lock);
369 369 ud_update_superblock(vfsp);
370 370 }
371 371 mutex_exit(&ud_sync_busy);
372 372
373 373 mutex_destroy(&udf_vfsp->udf_lock);
374 374 mutex_destroy(&udf_vfsp->udf_rename_lck);
375 375
376 376 ud_delcache(rip);
377 377 ITIMES(rip);
378 378 VN_RELE(rvp);
379 379
380 380 ud_destroy_fsp(udf_vfsp);
381 381
382 382 (void) VOP_PUTPAGE(bvp, (offset_t)0, (uint32_t)0, B_INVAL, cr, NULL);
383 383 (void) VOP_CLOSE(bvp, flag, 1, (offset_t)0, cr, NULL);
384 384
385 385 (void) bfinval(vfsp->vfs_dev, 1);
386 386 VN_RELE(bvp);
387 387
388 388
389 389 return (0);
390 390 }
391 391
392 392
393 393 /*
394 394 * Get the root vp for the
395 395 * file system
396 396 */
397 397 static int32_t
398 398 udf_root(struct vfs *vfsp, struct vnode **vpp)
399 399 {
400 400 struct udf_vfs *udf_vfsp;
401 401 struct vnode *vp;
402 402
403 403 ud_printf("udf_root\n");
404 404
405 405 udf_vfsp = (struct udf_vfs *)vfsp->vfs_data;
406 406
407 407 ASSERT(udf_vfsp != NULL);
408 408 ASSERT(udf_vfsp->udf_root != NULL);
409 409
410 410 vp = udf_vfsp->udf_root;
411 411 VN_HOLD(vp);
412 412 *vpp = vp;
413 413 return (0);
414 414 }
415 415
416 416
417 417 /*
418 418 * Get file system statistics.
419 419 */
420 420 static int32_t
421 421 udf_statvfs(struct vfs *vfsp, struct statvfs64 *sp)
422 422 {
423 423 struct udf_vfs *udf_vfsp;
424 424 struct ud_part *parts;
425 425 dev32_t d32;
426 426 int32_t index;
427 427
428 428 ud_printf("udf_statvfs\n");
429 429
430 430 udf_vfsp = (struct udf_vfs *)vfsp->vfs_data;
431 431 (void) bzero(sp, sizeof (struct statvfs64));
432 432
433 433 mutex_enter(&udf_vfsp->udf_lock);
434 434 sp->f_bsize = udf_vfsp->udf_lbsize;
435 435 sp->f_frsize = udf_vfsp->udf_lbsize;
436 436 sp->f_blocks = 0;
437 437 sp->f_bfree = 0;
438 438 parts = udf_vfsp->udf_parts;
439 439 for (index = 0; index < udf_vfsp->udf_npart; index++) {
440 440 sp->f_blocks += parts->udp_nblocks;
441 441 sp->f_bfree += parts->udp_nfree;
442 442 parts++;
443 443 }
444 444 sp->f_bavail = sp->f_bfree;
445 445
446 446 /*
447 447 * Since there are no real inodes allocated
448 448 * we will approximate
449 449 * each new file will occupy :
450 450 * 38(over head each dent) + MAXNAMLEN / 2 + inode_size(==block size)
451 451 */
452 452 sp->f_ffree = sp->f_favail =
453 453 (sp->f_bavail * sp->f_bsize) / (146 + sp->f_bsize);
454 454
455 455 /*
456 456 * The total number of inodes is
457 457 * the sum of files + directories + free inodes
458 458 */
459 459 sp->f_files = sp->f_ffree + udf_vfsp->udf_nfiles + udf_vfsp->udf_ndirs;
460 460 (void) cmpldev(&d32, vfsp->vfs_dev);
461 461 sp->f_fsid = d32;
462 462 (void) strcpy(sp->f_basetype, vfssw[vfsp->vfs_fstype].vsw_name);
463 463 sp->f_flag = vf_to_stf(vfsp->vfs_flag);
464 464 sp->f_namemax = MAXNAMLEN;
465 465 (void) strcpy(sp->f_fstr, udf_vfsp->udf_volid);
466 466
467 467 mutex_exit(&udf_vfsp->udf_lock);
468 468
469 469 return (0);
470 470 }
471 471
472 472
473 473 /*
474 474 * Flush any pending I/O to file system vfsp.
475 475 * The ud_update() routine will only flush *all* udf files.
476 476 */
477 477 /*ARGSUSED*/
478 478 /* ARGSUSED */
479 479 static int32_t
480 480 udf_sync(struct vfs *vfsp, int16_t flag, struct cred *cr)
481 481 {
482 482 ud_printf("udf_sync\n");
483 483
484 484 ud_update(flag);
485 485 return (0);
486 486 }
487 487
488 488
489 489
490 490 /* ARGSUSED */
491 491 static int32_t
492 492 udf_vget(struct vfs *vfsp,
493 493 struct vnode **vpp, struct fid *fidp)
494 494 {
495 495 int32_t error = 0;
496 496 struct udf_fid *udfid;
497 497 struct udf_vfs *udf_vfsp;
498 498 struct ud_inode *ip;
499 499
500 500 ud_printf("udf_vget\n");
501 501
502 502 udf_vfsp = (struct udf_vfs *)vfsp->vfs_data;
503 503 if (udf_vfsp == NULL) {
504 504 *vpp = NULL;
505 505 return (0);
506 506 }
507 507
508 508 udfid = (struct udf_fid *)fidp;
509 509 if ((error = ud_iget(vfsp, udfid->udfid_prn,
510 510 udfid->udfid_icb_lbn, &ip, NULL, CRED())) != 0) {
511 511 *vpp = NULL;
512 512 return (error);
513 513 }
514 514
515 515 rw_enter(&ip->i_contents, RW_READER);
516 516 if ((udfid->udfid_uinq_lo != (ip->i_uniqid & 0xffffffff)) ||
517 517 (udfid->udfid_prn != ip->i_icb_prn)) {
518 518 rw_exit(&ip->i_contents);
519 519 VN_RELE(ITOV(ip));
520 520 *vpp = NULL;
521 521 return (EINVAL);
522 522 }
523 523 rw_exit(&ip->i_contents);
524 524
525 525 *vpp = ITOV(ip);
526 526 return (0);
527 527 }
528 528
529 529
530 530 /*
531 531 * Mount root file system.
532 532 * "why" is ROOT_INIT on initial call, ROOT_REMOUNT if called to
533 533 * remount the root file system, and ROOT_UNMOUNT if called to
534 534 * unmount the root (e.g., as part of a system shutdown).
535 535 *
536 536 * XXX - this may be partially machine-dependent; it, along with the VFS_SWAPVP
537 537 * operation, goes along with auto-configuration. A mechanism should be
538 538 * provided by which machine-INdependent code in the kernel can say "get me the
539 539 * right root file system" and "get me the right initial swap area", and have
540 540 * that done in what may well be a machine-dependent fashion.
541 541 * Unfortunately, it is also file-system-type dependent (NFS gets it via
542 542 * bootparams calls, UFS gets it from various and sundry machine-dependent
543 543 * mechanisms, as SPECFS does for swap).
544 544 */
545 545 /* ARGSUSED */
546 546 static int32_t
547 547 udf_mountroot(struct vfs *vfsp, enum whymountroot why)
548 548 {
549 549 dev_t rootdev;
550 550 static int32_t udf_rootdone = 0;
551 551 struct vnode *vp = NULL;
552 552 int32_t ovflags, error;
553 553 ud_printf("udf_mountroot\n");
554 554
555 555 if (why == ROOT_INIT) {
556 556 if (udf_rootdone++) {
557 557 return (EBUSY);
558 558 }
559 559 rootdev = getrootdev();
560 560 if (rootdev == (dev_t)NODEV) {
561 561 return (ENODEV);
562 562 }
563 563 vfsp->vfs_dev = rootdev;
564 564 vfsp->vfs_flag |= VFS_RDONLY;
565 565 } else if (why == ROOT_REMOUNT) {
566 566 vp = ((struct udf_vfs *)vfsp->vfs_data)->udf_devvp;
567 567 (void) dnlc_purge_vfsp(vfsp, 0);
568 568 vp = common_specvp(vp);
569 569 (void) VOP_PUTPAGE(vp, (offset_t)0,
570 570 (uint32_t)0, B_INVAL, CRED(), NULL);
571 571 binval(vfsp->vfs_dev);
572 572
573 573 ovflags = vfsp->vfs_flag;
574 574 vfsp->vfs_flag &= ~VFS_RDONLY;
575 575 vfsp->vfs_flag |= VFS_REMOUNT;
576 576 rootdev = vfsp->vfs_dev;
577 577 } else if (why == ROOT_UNMOUNT) {
578 578 ud_update(0);
579 579 vp = ((struct udf_vfs *)vfsp->vfs_data)->udf_devvp;
580 580 (void) VOP_CLOSE(vp, FREAD|FWRITE, 1,
581 581 (offset_t)0, CRED(), NULL);
582 582 return (0);
583 583 }
584 584
585 585 if ((error = vfs_lock(vfsp)) != 0) {
586 586 return (error);
587 587 }
588 588
589 589 error = ud_mountfs(vfsp, why, rootdev, "/", CRED(), 1);
590 590 if (error) {
591 591 vfs_unlock(vfsp);
592 592 if (why == ROOT_REMOUNT) {
593 593 vfsp->vfs_flag = ovflags;
594 594 }
595 595 if (rootvp) {
596 596 VN_RELE(rootvp);
597 597 rootvp = (struct vnode *)0;
598 598 }
599 599 return (error);
600 600 }
601 601
602 602 if (why == ROOT_INIT) {
603 603 vfs_add((struct vnode *)0, vfsp,
604 604 (vfsp->vfs_flag & VFS_RDONLY) ? MS_RDONLY : 0);
605 605 }
606 606 vfs_unlock(vfsp);
607 607 return (0);
608 608 }
609 609
610 610
611 611 /* ------------------------- local routines ------------------------- */
612 612
613 613
614 614 static int32_t
615 615 ud_mountfs(struct vfs *vfsp,
616 616 enum whymountroot why, dev_t dev, char *name,
617 617 struct cred *cr, int32_t isroot)
618 618 {
619 619 struct vnode *devvp = NULL;
620 620 int32_t error = 0;
621 621 int32_t needclose = 0;
622 622 struct udf_vfs *udf_vfsp = NULL;
623 623 struct log_vol_int_desc *lvid;
624 624 struct ud_inode *rip = NULL;
625 625 struct vnode *rvp = NULL;
626 626 int32_t i, lbsize;
627 627 uint32_t avd_loc;
628 628 struct ud_map *map;
629 629 int32_t desc_len;
630 630
631 631 ud_printf("ud_mountfs\n");
632 632
633 633 if (why == ROOT_INIT) {
634 634 /*
635 635 * Open the device.
636 636 */
637 637 devvp = makespecvp(dev, VBLK);
638 638
639 639 /*
640 640 * Open block device mounted on.
641 641 * When bio is fixed for vnodes this can all be vnode
642 642 * operations.
643 643 */
644 644 error = VOP_OPEN(&devvp,
645 645 (vfsp->vfs_flag & VFS_RDONLY) ? FREAD : FREAD|FWRITE,
646 646 cr, NULL);
647 647 if (error) {
648 648 goto out;
649 649 }
650 650 needclose = 1;
651 651
652 652 /*
653 653 * Refuse to go any further if this
654 654 * device is being used for swapping.
655 655 */
656 656 if (IS_SWAPVP(devvp)) {
657 657 error = EBUSY;
658 658 goto out;
659 659 }
660 660 }
661 661
662 662 /*
663 663 * check for dev already mounted on
664 664 */
665 665 if (vfsp->vfs_flag & VFS_REMOUNT) {
666 666 struct tag *ttag;
667 667 int32_t index, count;
668 668 struct buf *tpt = 0;
669 669 caddr_t addr;
670 670
671 671
672 672 /* cannot remount to RDONLY */
673 673 if (vfsp->vfs_flag & VFS_RDONLY) {
674 674 return (EINVAL);
675 675 }
676 676
677 677 if (vfsp->vfs_dev != dev) {
678 678 return (EINVAL);
679 679 }
680 680
681 681 udf_vfsp = (struct udf_vfs *)vfsp->vfs_data;
682 682 devvp = udf_vfsp->udf_devvp;
683 683
684 684 /*
685 685 * fsck may have altered the file system; discard
686 686 * as much incore data as possible. Don't flush
687 687 * if this is a rw to rw remount; it's just resetting
688 688 * the options.
689 689 */
690 690 if (udf_vfsp->udf_flags & UDF_FL_RDONLY) {
691 691 (void) dnlc_purge_vfsp(vfsp, 0);
692 692 (void) VOP_PUTPAGE(devvp, (offset_t)0, (uint_t)0,
693 693 B_INVAL, CRED(), NULL);
694 694 (void) ud_iflush(vfsp);
695 695 bflush(dev);
696 696 binval(dev);
697 697 }
698 698
699 699 /*
700 700 * We could read UDF1.50 and write UDF1.50 only
701 701 * disallow mount of any highier version
702 702 */
703 703 if ((udf_vfsp->udf_miread > UDF_150) ||
704 704 (udf_vfsp->udf_miwrite > UDF_150)) {
705 705 error = EINVAL;
706 706 goto remountout;
707 707 }
708 708
709 709 /*
710 710 * read/write to read/write; all done
711 711 */
712 712 if (udf_vfsp->udf_flags & UDF_FL_RW) {
713 713 goto remountout;
714 714 }
715 715
716 716 /*
717 717 * Does the media type allow a writable mount
718 718 */
719 719 if (udf_vfsp->udf_mtype != UDF_MT_OW) {
720 720 error = EINVAL;
721 721 goto remountout;
722 722 }
723 723
724 724 /*
725 725 * Read the metadata
726 726 * and check if it is possible to
727 727 * mount in rw mode
728 728 */
729 729 tpt = ud_bread(vfsp->vfs_dev,
730 730 udf_vfsp->udf_iseq_loc << udf_vfsp->udf_l2d_shift,
731 731 udf_vfsp->udf_iseq_len);
732 732 if (tpt->b_flags & B_ERROR) {
733 733 error = EIO;
734 734 goto remountout;
735 735 }
736 736 count = udf_vfsp->udf_iseq_len / DEV_BSIZE;
737 737 addr = tpt->b_un.b_addr;
738 738 for (index = 0; index < count; index ++) {
739 739 ttag = (struct tag *)(addr + index * DEV_BSIZE);
740 740 desc_len = udf_vfsp->udf_iseq_len - (index * DEV_BSIZE);
741 741 if (ud_verify_tag_and_desc(ttag, UD_LOG_VOL_INT,
742 742 udf_vfsp->udf_iseq_loc +
743 743 (index >> udf_vfsp->udf_l2d_shift),
744 744 1, desc_len) == 0) {
745 745 struct log_vol_int_desc *lvid;
746 746
747 747 lvid = (struct log_vol_int_desc *)ttag;
748 748
749 749 if (SWAP_32(lvid->lvid_int_type) !=
750 750 LOG_VOL_CLOSE_INT) {
751 751 error = EINVAL;
752 752 goto remountout;
753 753 }
754 754
755 755 /*
756 756 * Copy new data to old data
757 757 */
758 758 bcopy(udf_vfsp->udf_iseq->b_un.b_addr,
759 759 tpt->b_un.b_addr, udf_vfsp->udf_iseq_len);
760 760 break;
761 761 }
762 762 }
763 763
764 764 udf_vfsp->udf_flags = UDF_FL_RW;
765 765
766 766 mutex_enter(&udf_vfsp->udf_lock);
767 767 ud_sbwrite(udf_vfsp);
768 768 mutex_exit(&udf_vfsp->udf_lock);
769 769 remountout:
770 770 if (tpt != NULL) {
771 771 tpt->b_flags = B_AGE | B_STALE;
772 772 brelse(tpt);
773 773 }
774 774 return (error);
775 775 }
776 776
777 777 ASSERT(devvp != 0);
778 778 /*
779 779 * Flush back any dirty pages on the block device to
780 780 * try and keep the buffer cache in sync with the page
781 781 * cache if someone is trying to use block devices when
782 782 * they really should be using the raw device.
783 783 */
784 784 (void) VOP_PUTPAGE(common_specvp(devvp), (offset_t)0,
785 785 (uint32_t)0, B_INVAL, cr, NULL);
786 786
787 787
788 788 /*
789 789 * Check if the file system
790 790 * is a valid udfs and fill
791 791 * the required fields in udf_vfs
792 792 */
793 793 #ifndef __lint
794 794 _NOTE(NO_COMPETING_THREADS_NOW);
795 795 #endif
796 796
797 797 if ((lbsize = ud_get_lbsize(dev, &avd_loc)) == 0) {
798 798 error = EINVAL;
799 799 goto out;
800 800 }
801 801
802 802 udf_vfsp = ud_validate_and_fill_superblock(dev, lbsize, avd_loc);
803 803 if (udf_vfsp == NULL) {
804 804 error = EINVAL;
805 805 goto out;
806 806 }
807 807
808 808 /*
809 809 * Fill in vfs private data
810 810 */
811 811 vfsp->vfs_fstype = udf_fstype;
812 812 vfs_make_fsid(&vfsp->vfs_fsid, dev, udf_fstype);
813 813 vfsp->vfs_data = (caddr_t)udf_vfsp;
814 814 vfsp->vfs_dev = dev;
815 815 vfsp->vfs_flag |= VFS_NOTRUNC;
816 816 udf_vfsp->udf_devvp = devvp;
817 817
818 818 udf_vfsp->udf_fsmnt = kmem_zalloc(strlen(name) + 1, KM_SLEEP);
819 819 (void) strcpy(udf_vfsp->udf_fsmnt, name);
820 820
821 821 udf_vfsp->udf_vfs = vfsp;
822 822 udf_vfsp->udf_rdclustsz = udf_vfsp->udf_wrclustsz = maxphys;
823 823
824 824 udf_vfsp->udf_mod = 0;
825 825
826 826
827 827 lvid = udf_vfsp->udf_lvid;
828 828 if (vfsp->vfs_flag & VFS_RDONLY) {
829 829 /*
830 830 * We could read only UDF1.50
831 831 * disallow mount of any highier version
832 832 */
833 833 if (udf_vfsp->udf_miread > UDF_150) {
834 834 error = EINVAL;
835 835 goto out;
836 836 }
837 837 udf_vfsp->udf_flags = UDF_FL_RDONLY;
838 838 if (SWAP_32(lvid->lvid_int_type) == LOG_VOL_CLOSE_INT) {
839 839 udf_vfsp->udf_clean = UDF_CLEAN;
840 840 } else {
841 841 /* Do we have a VAT at the end of the recorded media */
842 842 map = udf_vfsp->udf_maps;
843 843 for (i = 0; i < udf_vfsp->udf_nmaps; i++) {
844 844 if (map->udm_flags & UDM_MAP_VPM) {
845 845 break;
846 846 }
847 847 map++;
848 848 }
849 849 if (i == udf_vfsp->udf_nmaps) {
850 850 error = ENOSPC;
851 851 goto out;
852 852 }
853 853 udf_vfsp->udf_clean = UDF_CLEAN;
854 854 }
855 855 } else {
856 856 /*
857 857 * We could read UDF1.50 and write UDF1.50 only
858 858 * disallow mount of any highier version
859 859 */
860 860 if ((udf_vfsp->udf_miread > UDF_150) ||
861 861 (udf_vfsp->udf_miwrite > UDF_150)) {
862 862 error = EINVAL;
863 863 goto out;
864 864 }
865 865 /*
866 866 * Check if the media allows
867 867 * us to mount read/write
868 868 */
869 869 if (udf_vfsp->udf_mtype != UDF_MT_OW) {
870 870 error = EACCES;
871 871 goto out;
872 872 }
873 873
874 874 /*
875 875 * Check if we have VAT on a writable media
876 876 * we cannot use the media in presence of VAT
877 877 * Dent RW mount.
878 878 */
879 879 map = udf_vfsp->udf_maps;
880 880 ASSERT(map != NULL);
881 881 for (i = 0; i < udf_vfsp->udf_nmaps; i++) {
882 882 if (map->udm_flags & UDM_MAP_VPM) {
883 883 error = EACCES;
884 884 goto out;
885 885 }
886 886 map++;
887 887 }
888 888
889 889 /*
890 890 * Check if the domain Id allows
891 891 * us to write
892 892 */
893 893 if (udf_vfsp->udf_lvd->lvd_dom_id.reg_ids[2] & 0x3) {
894 894 error = EACCES;
895 895 goto out;
896 896 }
897 897 udf_vfsp->udf_flags = UDF_FL_RW;
898 898
899 899 if (SWAP_32(lvid->lvid_int_type) == LOG_VOL_CLOSE_INT) {
900 900 udf_vfsp->udf_clean = UDF_CLEAN;
901 901 } else {
902 902 if (isroot) {
903 903 udf_vfsp->udf_clean = UDF_DIRTY;
904 904 } else {
905 905 error = ENOSPC;
906 906 goto out;
907 907 }
908 908 }
909 909 }
910 910
911 911 mutex_init(&udf_vfsp->udf_lock, NULL, MUTEX_DEFAULT, NULL);
912 912
913 913 mutex_init(&udf_vfsp->udf_rename_lck, NULL, MUTEX_DEFAULT, NULL);
914 914
915 915 #ifndef __lint
916 916 _NOTE(COMPETING_THREADS_NOW);
917 917 #endif
918 918 if (error = ud_iget(vfsp, udf_vfsp->udf_ricb_prn,
919 919 udf_vfsp->udf_ricb_loc, &rip, NULL, cr)) {
920 920 mutex_destroy(&udf_vfsp->udf_lock);
921 921 goto out;
922 922 }
923 923
924 924
925 925 /*
926 926 * Get the root inode and
927 927 * initialize the root vnode
928 928 */
929 929 rvp = ITOV(rip);
930 930 mutex_enter(&rvp->v_lock);
931 931 rvp->v_flag |= VROOT;
932 932 mutex_exit(&rvp->v_lock);
933 933 udf_vfsp->udf_root = rvp;
934 934
935 935
936 936 if (why == ROOT_INIT && isroot)
937 937 rootvp = devvp;
938 938
939 939 ud_vfs_add(udf_vfsp);
940 940
941 941 if (udf_vfsp->udf_flags == UDF_FL_RW) {
942 942 udf_vfsp->udf_clean = UDF_DIRTY;
943 943 ud_update_superblock(vfsp);
944 944 }
945 945
946 946 return (0);
947 947
948 948 out:
949 949 ud_destroy_fsp(udf_vfsp);
950 950 if (needclose) {
951 951 (void) VOP_CLOSE(devvp, (vfsp->vfs_flag & VFS_RDONLY) ?
952 952 FREAD : FREAD|FWRITE, 1, (offset_t)0, cr, NULL);
953 953 bflush(dev);
954 954 binval(dev);
955 955 }
956 956 VN_RELE(devvp);
957 957
958 958 return (error);
959 959 }
960 960
961 961
962 962 static struct udf_vfs *
963 963 ud_validate_and_fill_superblock(dev_t dev, int32_t bsize, uint32_t avd_loc)
964 964 {
965 965 int32_t error, count, index, shift;
966 966 uint32_t dummy, vds_loc;
967 967 caddr_t addr;
968 968 daddr_t blkno, lblkno;
969 969 struct buf *secbp, *bp;
970 970 struct tag *ttag;
971 971 struct anch_vol_desc_ptr *avdp;
972 972 struct file_set_desc *fsd;
973 973 struct udf_vfs *udf_vfsp = NULL;
974 974 struct pmap_hdr *hdr;
975 975 struct pmap_typ1 *typ1;
976 976 struct pmap_typ2 *typ2;
977 977 struct ud_map *map;
978 978 int32_t desc_len;
979 979
980 980 ud_printf("ud_validate_and_fill_superblock\n");
981 981
982 982 if (bsize < DEV_BSIZE) {
983 983 return (NULL);
984 984 }
985 985 shift = 0;
986 986 while ((bsize >> shift) > DEV_BSIZE) {
987 987 shift++;
988 988 }
989 989
990 990 /*
991 991 * Read Anchor Volume Descriptor
992 992 * Verify it and get the location of
993 993 * Main Volume Descriptor Sequence
994 994 */
995 995 secbp = ud_bread(dev, avd_loc << shift, ANCHOR_VOL_DESC_LEN);
996 996 if ((error = geterror(secbp)) != 0) {
997 997 cmn_err(CE_NOTE, "udfs : Could not read Anchor Volume Desc %x",
998 998 error);
999 999 brelse(secbp);
1000 1000 return (NULL);
1001 1001 }
1002 1002 avdp = (struct anch_vol_desc_ptr *)secbp->b_un.b_addr;
1003 1003 if (ud_verify_tag_and_desc(&avdp->avd_tag, UD_ANCH_VOL_DESC,
1004 1004 avd_loc, 1, ANCHOR_VOL_DESC_LEN) != 0) {
1005 1005 brelse(secbp);
1006 1006 return (NULL);
1007 1007 }
1008 1008 udf_vfsp = (struct udf_vfs *)
1009 1009 kmem_zalloc(sizeof (struct udf_vfs), KM_SLEEP);
1010 1010 udf_vfsp->udf_mvds_loc = SWAP_32(avdp->avd_main_vdse.ext_loc);
1011 1011 udf_vfsp->udf_mvds_len = SWAP_32(avdp->avd_main_vdse.ext_len);
1012 1012 udf_vfsp->udf_rvds_loc = SWAP_32(avdp->avd_res_vdse.ext_loc);
1013 1013 udf_vfsp->udf_rvds_len = SWAP_32(avdp->avd_res_vdse.ext_len);
1014 1014 secbp->b_flags = B_AGE | B_STALE;
1015 1015 brelse(secbp);
1016 1016
1017 1017 /*
1018 1018 * Read Main Volume Descriptor Sequence
1019 1019 * and process it
1020 1020 */
1021 1021 vds_loc = udf_vfsp->udf_mvds_loc;
1022 1022 secbp = ud_bread(dev, vds_loc << shift,
1023 1023 udf_vfsp->udf_mvds_len);
1024 1024 if ((error = geterror(secbp)) != 0) {
1025 1025 brelse(secbp);
1026 1026 cmn_err(CE_NOTE, "udfs : Could not read Main Volume Desc %x",
1027 1027 error);
1028 1028
1029 1029 vds_loc = udf_vfsp->udf_rvds_loc;
1030 1030 secbp = ud_bread(dev, vds_loc << shift,
1031 1031 udf_vfsp->udf_rvds_len);
1032 1032 if ((error = geterror(secbp)) != 0) {
1033 1033 brelse(secbp);
1034 1034 cmn_err(CE_NOTE,
1035 1035 "udfs : Could not read Res Volume Desc %x", error);
1036 1036 return (NULL);
1037 1037 }
1038 1038 }
1039 1039
1040 1040 udf_vfsp->udf_vds = ngeteblk(udf_vfsp->udf_mvds_len);
1041 1041 bp = udf_vfsp->udf_vds;
1042 1042 bp->b_edev = dev;
1043 1043 bp->b_dev = cmpdev(dev);
1044 1044 bp->b_blkno = vds_loc << shift;
1045 1045 bp->b_bcount = udf_vfsp->udf_mvds_len;
1046 1046 bcopy(secbp->b_un.b_addr, bp->b_un.b_addr, udf_vfsp->udf_mvds_len);
1047 1047 secbp->b_flags |= B_STALE | B_AGE;
1048 1048 brelse(secbp);
1049 1049
1050 1050
1051 1051 count = udf_vfsp->udf_mvds_len / DEV_BSIZE;
1052 1052 addr = bp->b_un.b_addr;
1053 1053 for (index = 0; index < count; index ++) {
1054 1054 ttag = (struct tag *)(addr + index * DEV_BSIZE);
1055 1055 desc_len = udf_vfsp->udf_mvds_len - (index * DEV_BSIZE);
1056 1056 if (ud_verify_tag_and_desc(ttag, UD_PRI_VOL_DESC,
1057 1057 vds_loc + (index >> shift),
1058 1058 1, desc_len) == 0) {
1059 1059 if (udf_vfsp->udf_pvd == NULL) {
1060 1060 udf_vfsp->udf_pvd =
1061 1061 (struct pri_vol_desc *)ttag;
1062 1062 } else {
1063 1063 struct pri_vol_desc *opvd, *npvd;
1064 1064
1065 1065 opvd = udf_vfsp->udf_pvd;
1066 1066 npvd = (struct pri_vol_desc *)ttag;
1067 1067
1068 1068 if ((strncmp(opvd->pvd_vsi,
1069 1069 npvd->pvd_vsi, 128) == 0) &&
1070 1070 (strncmp(opvd->pvd_vol_id,
1071 1071 npvd->pvd_vol_id, 32) == 0) &&
1072 1072 (strncmp((caddr_t)&opvd->pvd_desc_cs,
1073 1073 (caddr_t)&npvd->pvd_desc_cs,
1074 1074 sizeof (charspec_t)) == 0)) {
1075 1075
1076 1076 if (SWAP_32(opvd->pvd_vdsn) <
1077 1077 SWAP_32(npvd->pvd_vdsn)) {
1078 1078 udf_vfsp->udf_pvd = npvd;
1079 1079 }
1080 1080 } else {
1081 1081 goto out;
1082 1082 }
1083 1083 }
1084 1084 } else if (ud_verify_tag_and_desc(ttag, UD_LOG_VOL_DESC,
1085 1085 vds_loc + (index >> shift),
1086 1086 1, desc_len) == 0) {
1087 1087 struct log_vol_desc *lvd;
1088 1088
1089 1089 lvd = (struct log_vol_desc *)ttag;
1090 1090 if (strncmp(lvd->lvd_dom_id.reg_id,
1091 1091 UDF_DOMAIN_NAME, 23) != 0) {
1092 1092 printf("Domain ID in lvd is not valid\n");
1093 1093 goto out;
1094 1094 }
1095 1095
1096 1096 if (udf_vfsp->udf_lvd == NULL) {
1097 1097 udf_vfsp->udf_lvd = lvd;
1098 1098 } else {
1099 1099 struct log_vol_desc *olvd;
1100 1100
1101 1101 olvd = udf_vfsp->udf_lvd;
1102 1102 if ((strncmp((caddr_t)&olvd->lvd_desc_cs,
1103 1103 (caddr_t)&lvd->lvd_desc_cs,
1104 1104 sizeof (charspec_t)) == 0) &&
1105 1105 (strncmp(olvd->lvd_lvid,
1106 1106 lvd->lvd_lvid, 128) == 0)) {
1107 1107 if (SWAP_32(olvd->lvd_vdsn) <
1108 1108 SWAP_32(lvd->lvd_vdsn)) {
1109 1109 udf_vfsp->udf_lvd = lvd;
1110 1110 }
1111 1111 } else {
1112 1112 goto out;
1113 1113 }
1114 1114 }
1115 1115 } else if (ud_verify_tag_and_desc(ttag, UD_PART_DESC,
1116 1116 vds_loc + (index >> shift),
1117 1117 1, desc_len) == 0) {
1118 1118 int32_t i;
1119 1119 struct phdr_desc *hdr;
1120 1120 struct part_desc *pdesc;
1121 1121 struct ud_part *pnew, *pold, *part;
1122 1122
1123 1123 pdesc = (struct part_desc *)ttag;
1124 1124 pold = udf_vfsp->udf_parts;
1125 1125 for (i = 0; i < udf_vfsp->udf_npart; i++) {
1126 1126 if (pold->udp_number !=
1127 1127 SWAP_16(pdesc->pd_pnum)) {
1128 1128 pold++;
1129 1129 continue;
1130 1130 }
1131 1131
1132 1132 if (SWAP_32(pdesc->pd_vdsn) >
1133 1133 pold->udp_seqno) {
1134 1134 pold->udp_seqno =
1135 1135 SWAP_32(pdesc->pd_vdsn);
1136 1136 pold->udp_access =
1137 1137 SWAP_32(pdesc->pd_acc_type);
1138 1138 pold->udp_start =
1139 1139 SWAP_32(pdesc->pd_part_start);
1140 1140 pold->udp_length =
1141 1141 SWAP_32(pdesc->pd_part_length);
1142 1142 }
1143 1143 goto loop_end;
1144 1144 }
1145 1145 pold = udf_vfsp->udf_parts;
1146 1146 udf_vfsp->udf_npart++;
1147 1147 pnew = kmem_zalloc(udf_vfsp->udf_npart *
1148 1148 sizeof (struct ud_part), KM_SLEEP);
1149 1149 udf_vfsp->udf_parts = pnew;
1150 1150 if (pold) {
1151 1151 bcopy(pold, pnew,
1152 1152 sizeof (struct ud_part) *
1153 1153 (udf_vfsp->udf_npart - 1));
1154 1154 kmem_free(pold,
1155 1155 sizeof (struct ud_part) *
1156 1156 (udf_vfsp->udf_npart - 1));
1157 1157 }
1158 1158 part = pnew + (udf_vfsp->udf_npart - 1);
1159 1159 part->udp_number = SWAP_16(pdesc->pd_pnum);
1160 1160 part->udp_seqno = SWAP_32(pdesc->pd_vdsn);
1161 1161 part->udp_access = SWAP_32(pdesc->pd_acc_type);
1162 1162 part->udp_start = SWAP_32(pdesc->pd_part_start);
1163 1163 part->udp_length = SWAP_32(pdesc->pd_part_length);
1164 1164 part->udp_last_alloc = 0;
1165 1165
1166 1166 /*
1167 1167 * Figure out space bitmaps
1168 1168 * or space tables
1169 1169 */
1170 1170 hdr = (struct phdr_desc *)pdesc->pd_pc_use;
1171 1171 if (hdr->phdr_ust.sad_ext_len) {
1172 1172 part->udp_flags = UDP_SPACETBLS;
1173 1173 part->udp_unall_loc =
1174 1174 SWAP_32(hdr->phdr_ust.sad_ext_loc);
1175 1175 part->udp_unall_len =
1176 1176 SWAP_32(hdr->phdr_ust.sad_ext_len);
1177 1177 part->udp_freed_loc =
1178 1178 SWAP_32(hdr->phdr_fst.sad_ext_loc);
1179 1179 part->udp_freed_len =
1180 1180 SWAP_32(hdr->phdr_fst.sad_ext_len);
1181 1181 } else {
1182 1182 part->udp_flags = UDP_BITMAPS;
1183 1183 part->udp_unall_loc =
1184 1184 SWAP_32(hdr->phdr_usb.sad_ext_loc);
1185 1185 part->udp_unall_len =
1186 1186 SWAP_32(hdr->phdr_usb.sad_ext_len);
1187 1187 part->udp_freed_loc =
1188 1188 SWAP_32(hdr->phdr_fsb.sad_ext_loc);
1189 1189 part->udp_freed_len =
1190 1190 SWAP_32(hdr->phdr_fsb.sad_ext_len);
1191 1191 }
1192 1192 } else if (ud_verify_tag_and_desc(ttag, UD_TERM_DESC,
1193 1193 vds_loc + (index >> shift),
1194 1194 1, desc_len) == 0) {
1195 1195
1196 1196 break;
1197 1197 }
1198 1198 loop_end:
1199 1199 ;
1200 1200 }
1201 1201 if ((udf_vfsp->udf_pvd == NULL) ||
1202 1202 (udf_vfsp->udf_lvd == NULL) ||
1203 1203 (udf_vfsp->udf_parts == NULL)) {
1204 1204 goto out;
1205 1205 }
1206 1206
1207 1207 /*
1208 1208 * Process Primary Volume Descriptor
1209 1209 */
1210 1210 (void) strncpy(udf_vfsp->udf_volid, udf_vfsp->udf_pvd->pvd_vol_id, 32);
1211 1211 udf_vfsp->udf_volid[31] = '\0';
1212 1212 udf_vfsp->udf_tsno = SWAP_16(udf_vfsp->udf_pvd->pvd_tag.tag_sno);
1213 1213
1214 1214 /*
1215 1215 * Process Logical Volume Descriptor
1216 1216 */
1217 1217 udf_vfsp->udf_lbsize =
1218 1218 SWAP_32(udf_vfsp->udf_lvd->lvd_log_bsize);
1219 1219 udf_vfsp->udf_lbmask = udf_vfsp->udf_lbsize - 1;
1220 1220 udf_vfsp->udf_l2d_shift = shift;
1221 1221 udf_vfsp->udf_l2b_shift = shift + DEV_BSHIFT;
1222 1222
1223 1223 /*
1224 1224 * Check if the media is in
1225 1225 * proper domain.
1226 1226 */
1227 1227 if (strcmp(udf_vfsp->udf_lvd->lvd_dom_id.reg_id,
1228 1228 UDF_DOMAIN_NAME) != 0) {
1229 1229 goto out;
1230 1230 }
1231 1231
1232 1232 /*
1233 1233 * AVDS offset does not match with the lbsize
1234 1234 * in the lvd
1235 1235 */
1236 1236 if (udf_vfsp->udf_lbsize != bsize) {
1237 1237 goto out;
1238 1238 }
1239 1239
1240 1240 udf_vfsp->udf_iseq_loc =
1241 1241 SWAP_32(udf_vfsp->udf_lvd->lvd_int_seq_ext.ext_loc);
1242 1242 udf_vfsp->udf_iseq_len =
1243 1243 SWAP_32(udf_vfsp->udf_lvd->lvd_int_seq_ext.ext_len);
1244 1244
1245 1245 udf_vfsp->udf_fsd_prn =
1246 1246 SWAP_16(udf_vfsp->udf_lvd->lvd_lvcu.lad_ext_prn);
1247 1247 udf_vfsp->udf_fsd_loc =
1248 1248 SWAP_32(udf_vfsp->udf_lvd->lvd_lvcu.lad_ext_loc);
1249 1249 udf_vfsp->udf_fsd_len =
1250 1250 SWAP_32(udf_vfsp->udf_lvd->lvd_lvcu.lad_ext_len);
1251 1251
1252 1252
1253 1253 /*
1254 1254 * process paritions
1255 1255 */
1256 1256 udf_vfsp->udf_mtype = udf_vfsp->udf_parts[0].udp_access;
1257 1257 for (index = 0; index < udf_vfsp->udf_npart; index ++) {
1258 1258 if (udf_vfsp->udf_parts[index].udp_access <
1259 1259 udf_vfsp->udf_mtype) {
1260 1260 udf_vfsp->udf_mtype =
1261 1261 udf_vfsp->udf_parts[index].udp_access;
1262 1262 }
1263 1263 }
1264 1264 if ((udf_vfsp->udf_mtype < UDF_MT_RO) ||
1265 1265 (udf_vfsp->udf_mtype > UDF_MT_OW)) {
1266 1266 udf_vfsp->udf_mtype = UDF_MT_RO;
1267 1267 }
1268 1268
1269 1269 udf_vfsp->udf_nmaps = 0;
1270 1270 hdr = (struct pmap_hdr *)udf_vfsp->udf_lvd->lvd_pmaps;
1271 1271 count = SWAP_32(udf_vfsp->udf_lvd->lvd_num_pmaps);
1272 1272 for (index = 0; index < count; index++) {
1273 1273
1274 1274 if ((hdr->maph_type == MAP_TYPE1) &&
1275 1275 (hdr->maph_length == MAP_TYPE1_LEN)) {
1276 1276 typ1 = (struct pmap_typ1 *)hdr;
1277 1277
1278 1278 map = udf_vfsp->udf_maps;
1279 1279 udf_vfsp->udf_maps =
1280 1280 kmem_zalloc(sizeof (struct ud_map) *
1281 1281 (udf_vfsp->udf_nmaps + 1), KM_SLEEP);
1282 1282 if (map != NULL) {
1283 1283 bcopy(map, udf_vfsp->udf_maps,
1284 1284 sizeof (struct ud_map) *
1285 1285 udf_vfsp->udf_nmaps);
1286 1286 kmem_free(map, sizeof (struct ud_map) *
1287 1287 udf_vfsp->udf_nmaps);
1288 1288 }
1289 1289 map = udf_vfsp->udf_maps + udf_vfsp->udf_nmaps;
1290 1290 map->udm_flags = UDM_MAP_NORM;
1291 1291 map->udm_vsn = SWAP_16(typ1->map1_vsn);
1292 1292 map->udm_pn = SWAP_16(typ1->map1_pn);
1293 1293 udf_vfsp->udf_nmaps ++;
1294 1294 } else if ((hdr->maph_type == MAP_TYPE2) &&
1295 1295 (hdr->maph_length == MAP_TYPE2_LEN)) {
1296 1296 typ2 = (struct pmap_typ2 *)hdr;
1297 1297
1298 1298 if (strncmp(typ2->map2_pti.reg_id,
1299 1299 UDF_VIRT_PART, 23) == 0) {
1300 1300 /*
1301 1301 * Add this to the normal
1302 1302 * partition table so that
1303 1303 * we donot
1304 1304 */
1305 1305 map = udf_vfsp->udf_maps;
1306 1306 udf_vfsp->udf_maps =
1307 1307 kmem_zalloc(sizeof (struct ud_map) *
1308 1308 (udf_vfsp->udf_nmaps + 1), KM_SLEEP);
1309 1309 if (map != NULL) {
1310 1310 bcopy(map, udf_vfsp->udf_maps,
1311 1311 sizeof (struct ud_map) *
1312 1312 udf_vfsp->udf_nmaps);
1313 1313 kmem_free(map,
1314 1314 sizeof (struct ud_map) *
1315 1315 udf_vfsp->udf_nmaps);
1316 1316 }
1317 1317 map = udf_vfsp->udf_maps + udf_vfsp->udf_nmaps;
1318 1318 map->udm_flags = UDM_MAP_VPM;
1319 1319 map->udm_vsn = SWAP_16(typ2->map2_vsn);
1320 1320 map->udm_pn = SWAP_16(typ2->map2_pn);
1321 1321 udf_vfsp->udf_nmaps ++;
1322 1322 if (error = ud_get_last_block(dev, &lblkno)) {
1323 1323 goto out;
1324 1324 }
1325 1325 if (error = ud_val_get_vat(udf_vfsp, dev,
1326 1326 lblkno, map)) {
1327 1327 goto out;
1328 1328 }
1329 1329 } else if (strncmp(typ2->map2_pti.reg_id,
1330 1330 UDF_SPAR_PART, 23) == 0) {
1331 1331
1332 1332 if (SWAP_16(typ2->map2_pl) != 32) {
1333 1333 printf(
1334 1334 "Packet Length is not valid %x\n",
1335 1335 SWAP_16(typ2->map2_pl));
1336 1336 goto out;
1337 1337 }
1338 1338 if ((typ2->map2_nst < 1) ||
1339 1339 (typ2->map2_nst > 4)) {
1340 1340 goto out;
1341 1341 }
1342 1342 map = udf_vfsp->udf_maps;
1343 1343 udf_vfsp->udf_maps =
1344 1344 kmem_zalloc(sizeof (struct ud_map) *
1345 1345 (udf_vfsp->udf_nmaps + 1),
1346 1346 KM_SLEEP);
1347 1347 if (map != NULL) {
1348 1348 bcopy(map, udf_vfsp->udf_maps,
1349 1349 sizeof (struct ud_map) *
1350 1350 udf_vfsp->udf_nmaps);
1351 1351 kmem_free(map,
1352 1352 sizeof (struct ud_map) *
1353 1353 udf_vfsp->udf_nmaps);
1354 1354 }
1355 1355 map = udf_vfsp->udf_maps + udf_vfsp->udf_nmaps;
1356 1356 map->udm_flags = UDM_MAP_SPM;
1357 1357 map->udm_vsn = SWAP_16(typ2->map2_vsn);
1358 1358 map->udm_pn = SWAP_16(typ2->map2_pn);
1359 1359
1360 1360 udf_vfsp->udf_nmaps ++;
1361 1361
1362 1362 if (error = ud_read_sparing_tbls(udf_vfsp,
1363 1363 dev, map, typ2)) {
1364 1364 goto out;
1365 1365 }
1366 1366 } else {
1367 1367 /*
1368 1368 * Unknown type of partition
1369 1369 * Bail out
1370 1370 */
1371 1371 goto out;
1372 1372 }
1373 1373 } else {
1374 1374 /*
1375 1375 * Unknown type of partition
1376 1376 * Bail out
1377 1377 */
1378 1378 goto out;
1379 1379 }
1380 1380 hdr = (struct pmap_hdr *)(((uint8_t *)hdr) + hdr->maph_length);
1381 1381 }
1382 1382
1383 1383
1384 1384 /*
1385 1385 * Read Logical Volume Integrity Sequence
1386 1386 * and process it
1387 1387 */
1388 1388 secbp = ud_bread(dev, udf_vfsp->udf_iseq_loc << shift,
1389 1389 udf_vfsp->udf_iseq_len);
1390 1390 if ((error = geterror(secbp)) != 0) {
1391 1391 cmn_err(CE_NOTE,
1392 1392 "udfs : Could not read Logical Volume Integrity Sequence %x",
1393 1393 error);
1394 1394 brelse(secbp);
1395 1395 goto out;
1396 1396 }
1397 1397 udf_vfsp->udf_iseq = ngeteblk(udf_vfsp->udf_iseq_len);
1398 1398 bp = udf_vfsp->udf_iseq;
1399 1399 bp->b_edev = dev;
1400 1400 bp->b_dev = cmpdev(dev);
1401 1401 bp->b_blkno = udf_vfsp->udf_iseq_loc << shift;
1402 1402 bp->b_bcount = udf_vfsp->udf_iseq_len;
1403 1403 bcopy(secbp->b_un.b_addr, bp->b_un.b_addr, udf_vfsp->udf_iseq_len);
1404 1404 secbp->b_flags |= B_STALE | B_AGE;
1405 1405 brelse(secbp);
1406 1406
1407 1407 count = udf_vfsp->udf_iseq_len / DEV_BSIZE;
1408 1408 addr = bp->b_un.b_addr;
1409 1409 for (index = 0; index < count; index ++) {
1410 1410 ttag = (struct tag *)(addr + index * DEV_BSIZE);
1411 1411 desc_len = udf_vfsp->udf_iseq_len - (index * DEV_BSIZE);
1412 1412 if (ud_verify_tag_and_desc(ttag, UD_LOG_VOL_INT,
1413 1413 udf_vfsp->udf_iseq_loc + (index >> shift),
1414 1414 1, desc_len) == 0) {
1415 1415
1416 1416 struct log_vol_int_desc *lvid;
1417 1417
1418 1418 lvid = (struct log_vol_int_desc *)ttag;
1419 1419 udf_vfsp->udf_lvid = lvid;
1420 1420
1421 1421 if (SWAP_32(lvid->lvid_int_type) == LOG_VOL_CLOSE_INT) {
1422 1422 udf_vfsp->udf_clean = UDF_CLEAN;
1423 1423 } else {
1424 1424 udf_vfsp->udf_clean = UDF_DIRTY;
1425 1425 }
1426 1426
1427 1427 /*
1428 1428 * update superblock with the metadata
1429 1429 */
1430 1430 ud_convert_to_superblock(udf_vfsp, lvid);
1431 1431 break;
1432 1432 }
1433 1433 }
1434 1434
1435 1435 if (udf_vfsp->udf_lvid == NULL) {
1436 1436 goto out;
1437 1437 }
1438 1438
1439 1439 if ((blkno = ud_xlate_to_daddr(udf_vfsp,
1440 1440 udf_vfsp->udf_fsd_prn, udf_vfsp->udf_fsd_loc,
1441 1441 1, &dummy)) == 0) {
1442 1442 goto out;
1443 1443 }
1444 1444 secbp = ud_bread(dev, blkno << shift, udf_vfsp->udf_fsd_len);
1445 1445 if ((error = geterror(secbp)) != 0) {
1446 1446 cmn_err(CE_NOTE,
1447 1447 "udfs : Could not read File Set Descriptor %x", error);
1448 1448 brelse(secbp);
1449 1449 goto out;
1450 1450 }
1451 1451 fsd = (struct file_set_desc *)secbp->b_un.b_addr;
1452 1452 if (ud_verify_tag_and_desc(&fsd->fsd_tag, UD_FILE_SET_DESC,
1453 1453 udf_vfsp->udf_fsd_loc,
1454 1454 1, udf_vfsp->udf_fsd_len) != 0) {
1455 1455 secbp->b_flags = B_AGE | B_STALE;
1456 1456 brelse(secbp);
1457 1457 goto out;
1458 1458 }
1459 1459 udf_vfsp->udf_ricb_prn = SWAP_16(fsd->fsd_root_icb.lad_ext_prn);
1460 1460 udf_vfsp->udf_ricb_loc = SWAP_32(fsd->fsd_root_icb.lad_ext_loc);
1461 1461 udf_vfsp->udf_ricb_len = SWAP_32(fsd->fsd_root_icb.lad_ext_len);
1462 1462 secbp->b_flags = B_AGE | B_STALE;
1463 1463 brelse(secbp);
1464 1464 udf_vfsp->udf_root_blkno = ud_xlate_to_daddr(udf_vfsp,
1465 1465 udf_vfsp->udf_ricb_prn, udf_vfsp->udf_ricb_loc,
1466 1466 1, &dummy);
1467 1467
1468 1468 return (udf_vfsp);
1469 1469 out:
1470 1470 ud_destroy_fsp(udf_vfsp);
1471 1471
1472 1472 return (NULL);
1473 1473 }
1474 1474
1475 1475 /*
1476 1476 * release/free resources from one ud_map; map data was zalloc'd in
1477 1477 * ud_validate_and_fill_superblock() and fields may later point to
1478 1478 * valid data
1479 1479 */
1480 1480 static void
1481 1481 ud_free_map(struct ud_map *map)
1482 1482 {
1483 1483 uint32_t n;
1484 1484
1485 1485 if (map->udm_flags & UDM_MAP_VPM) {
1486 1486 if (map->udm_count) {
1487 1487 kmem_free(map->udm_count,
1488 1488 map->udm_nent * sizeof (*map->udm_count));
1489 1489 map->udm_count = NULL;
1490 1490 }
1491 1491 if (map->udm_bp) {
1492 1492 for (n = 0; n < map->udm_nent; n++) {
1493 1493 if (map->udm_bp[n])
1494 1494 brelse(map->udm_bp[n]);
1495 1495 }
1496 1496 kmem_free(map->udm_bp,
1497 1497 map->udm_nent * sizeof (*map->udm_bp));
1498 1498 map->udm_bp = NULL;
1499 1499 }
1500 1500 if (map->udm_addr) {
1501 1501 kmem_free(map->udm_addr,
1502 1502 map->udm_nent * sizeof (*map->udm_addr));
1503 1503 map->udm_addr = NULL;
1504 1504 }
1505 1505 }
1506 1506 if (map->udm_flags & UDM_MAP_SPM) {
1507 1507 for (n = 0; n < MAX_SPM; n++) {
1508 1508 if (map->udm_sbp[n]) {
1509 1509 brelse(map->udm_sbp[n]);
1510 1510 map->udm_sbp[n] = NULL;
1511 1511 map->udm_spaddr[n] = NULL;
1512 1512 }
1513 1513 }
1514 1514 }
1515 1515 }
1516 1516
1517 1517 void
1518 1518 ud_destroy_fsp(struct udf_vfs *udf_vfsp)
1519 1519 {
1520 1520 int32_t i;
1521 1521
1522 1522 ud_printf("ud_destroy_fsp\n");
1523 1523 if (udf_vfsp == NULL)
1524 1524 return;
1525 1525
1526 1526 if (udf_vfsp->udf_maps) {
1527 1527 for (i = 0; i < udf_vfsp->udf_nmaps; i++)
1528 1528 ud_free_map(&udf_vfsp->udf_maps[i]);
1529 1529
1530 1530 kmem_free(udf_vfsp->udf_maps,
1531 1531 udf_vfsp->udf_nmaps * sizeof (*udf_vfsp->udf_maps));
1532 1532 }
1533 1533
1534 1534 if (udf_vfsp->udf_parts) {
1535 1535 kmem_free(udf_vfsp->udf_parts,
1536 1536 udf_vfsp->udf_npart * sizeof (*udf_vfsp->udf_parts));
1537 1537 }
1538 1538 if (udf_vfsp->udf_iseq) {
1539 1539 udf_vfsp->udf_iseq->b_flags |= (B_STALE|B_AGE);
1540 1540 brelse(udf_vfsp->udf_iseq);
1541 1541 }
1542 1542 if (udf_vfsp->udf_vds) {
1543 1543 udf_vfsp->udf_vds->b_flags |= (B_STALE|B_AGE);
1544 1544 brelse(udf_vfsp->udf_vds);
1545 1545 }
1546 1546 if (udf_vfsp->udf_vfs)
1547 1547 ud_vfs_remove(udf_vfsp);
1548 1548 if (udf_vfsp->udf_fsmnt) {
1549 1549 kmem_free(udf_vfsp->udf_fsmnt,
1550 1550 strlen(udf_vfsp->udf_fsmnt) + 1);
1551 1551 }
1552 1552 kmem_free(udf_vfsp, sizeof (*udf_vfsp));
1553 1553 }
1554 1554
1555 1555 void
1556 1556 ud_convert_to_superblock(struct udf_vfs *udf_vfsp,
1557 1557 struct log_vol_int_desc *lvid)
1558 1558 {
1559 1559 int32_t i, c;
1560 1560 uint32_t *temp;
1561 1561 struct ud_part *ud_part;
1562 1562 struct lvid_iu *iu;
1563 1563
1564 1564 udf_vfsp->udf_maxuniq = SWAP_64(lvid->lvid_uniqid);
1565 1565 temp = lvid->lvid_fst;
1566 1566 c = SWAP_32(lvid->lvid_npart);
1567 1567 ud_part = udf_vfsp->udf_parts;
1568 1568 for (i = 0; i < c; i++) {
1569 1569 if (i >= udf_vfsp->udf_npart) {
1570 1570 continue;
1571 1571 }
1572 1572 ud_part->udp_nfree = SWAP_32(temp[i]);
1573 1573 ud_part->udp_nblocks = SWAP_32(temp[c + i]);
1574 1574 udf_vfsp->udf_freeblks += SWAP_32(temp[i]);
1575 1575 udf_vfsp->udf_totalblks += SWAP_32(temp[c + i]);
1576 1576 ud_part++;
1577 1577 }
1578 1578
1579 1579 iu = (struct lvid_iu *)(temp + c * 2);
1580 1580 udf_vfsp->udf_nfiles = SWAP_32(iu->lvidiu_nfiles);
1581 1581 udf_vfsp->udf_ndirs = SWAP_32(iu->lvidiu_ndirs);
1582 1582 udf_vfsp->udf_miread = BCD2HEX_16(SWAP_16(iu->lvidiu_mread));
1583 1583 udf_vfsp->udf_miwrite = BCD2HEX_16(SWAP_16(iu->lvidiu_mwrite));
1584 1584 udf_vfsp->udf_mawrite = BCD2HEX_16(SWAP_16(iu->lvidiu_maxwr));
1585 1585 }
1586 1586
1587 1587 void
1588 1588 ud_update_superblock(struct vfs *vfsp)
1589 1589 {
1590 1590 struct udf_vfs *udf_vfsp;
1591 1591
1592 1592 ud_printf("ud_update_superblock\n");
1593 1593
1594 1594 udf_vfsp = (struct udf_vfs *)vfsp->vfs_data;
1595 1595
1596 1596 mutex_enter(&udf_vfsp->udf_lock);
1597 1597 ud_sbwrite(udf_vfsp);
1598 1598 mutex_exit(&udf_vfsp->udf_lock);
1599 1599 }
1600 1600
1601 1601
1602 1602 #include <sys/dkio.h>
1603 1603 #include <sys/cdio.h>
1604 1604 #include <sys/vtoc.h>
1605 1605
1606 1606 /*
1607 1607 * This part of the code is known
1608 1608 * to work with only sparc. It needs
1609 1609 * to be evluated before using it with x86
1610 1610 */
1611 1611 int32_t
1612 1612 ud_get_last_block(dev_t dev, daddr_t *blkno)
1613 1613 {
1614 1614 struct vtoc vtoc;
1615 1615 struct dk_cinfo dki_info;
1616 1616 int32_t rval, error;
1617 1617
1618 1618 if ((error = cdev_ioctl(dev, DKIOCGVTOC, (intptr_t)&vtoc,
1619 1619 FKIOCTL|FREAD|FNATIVE, CRED(), &rval)) != 0) {
1620 1620 cmn_err(CE_NOTE, "Could not get the vtoc information");
1621 1621 return (error);
1622 1622 }
1623 1623
1624 1624 if (vtoc.v_sanity != VTOC_SANE) {
1625 1625 return (EINVAL);
1626 1626 }
1627 1627 if ((error = cdev_ioctl(dev, DKIOCINFO, (intptr_t)&dki_info,
1628 1628 FKIOCTL|FREAD|FNATIVE, CRED(), &rval)) != 0) {
1629 1629 cmn_err(CE_NOTE, "Could not get the slice information");
1630 1630 return (error);
1631 1631 }
1632 1632
1633 1633 if (dki_info.dki_partition > V_NUMPAR) {
1634 1634 return (EINVAL);
1635 1635 }
1636 1636
1637 1637
1638 1638 *blkno = vtoc.v_part[dki_info.dki_partition].p_size;
1639 1639
1640 1640 return (0);
1641 1641 }
1642 1642
1643 1643 /* Search sequentially N - 2, N, N - 152, N - 150 for vat icb */
1644 1644 /*
1645 1645 * int32_t ud_sub_blks[] = {2, 0, 152, 150};
1646 1646 */
1647 1647 int32_t ud_sub_blks[] = {152, 150, 2, 0};
1648 1648 int32_t ud_sub_count = 4;
1649 1649
1650 1650 /*
1651 1651 * Validate the VAT ICB
1652 1652 */
1653 1653 static int32_t
1654 1654 ud_val_get_vat(struct udf_vfs *udf_vfsp, dev_t dev,
1655 1655 daddr_t blkno, struct ud_map *udm)
1656 1656 {
1657 1657 struct buf *secbp;
1658 1658 struct file_entry *fe;
1659 1659 int32_t end_loc, i, j, ad_type;
1660 1660 struct short_ad *sad;
1661 1661 struct long_ad *lad;
1662 1662 uint32_t count, blk;
1663 1663 struct ud_part *ud_part;
1664 1664 int err = 0;
1665 1665
1666 1666 end_loc = (blkno >> udf_vfsp->udf_l2d_shift) - 1;
1667 1667
1668 1668 for (i = 0; i < ud_sub_count; i++) {
1669 1669 udm->udm_vat_icb = end_loc - ud_sub_blks[i];
1670 1670
1671 1671 secbp = ud_bread(dev,
1672 1672 udm->udm_vat_icb << udf_vfsp->udf_l2d_shift,
1673 1673 udf_vfsp->udf_lbsize);
1674 1674 ASSERT(secbp->b_un.b_addr);
1675 1675
1676 1676 fe = (struct file_entry *)secbp->b_un.b_addr;
1677 1677 if (ud_verify_tag_and_desc(&fe->fe_tag, UD_FILE_ENTRY, 0,
1678 1678 0, 0) == 0) {
1679 1679 if (ud_verify_tag_and_desc(&fe->fe_tag, UD_FILE_ENTRY,
1680 1680 SWAP_32(fe->fe_tag.tag_loc),
1681 1681 1, udf_vfsp->udf_lbsize) == 0) {
1682 1682 if (fe->fe_icb_tag.itag_ftype == 0) {
1683 1683 break;
1684 1684 }
1685 1685 }
1686 1686 }
1687 1687 secbp->b_flags |= B_AGE | B_STALE;
1688 1688 brelse(secbp);
1689 1689 }
1690 1690 if (i == ud_sub_count) {
1691 1691 return (EINVAL);
1692 1692 }
1693 1693
1694 1694 ad_type = SWAP_16(fe->fe_icb_tag.itag_flags) & 0x3;
1695 1695 if (ad_type == ICB_FLAG_ONE_AD) {
1696 1696 udm->udm_nent = 1;
1697 1697 } else if (ad_type == ICB_FLAG_SHORT_AD) {
1698 1698 udm->udm_nent =
1699 1699 SWAP_32(fe->fe_len_adesc) / sizeof (struct short_ad);
1700 1700 } else if (ad_type == ICB_FLAG_LONG_AD) {
1701 1701 udm->udm_nent =
1702 1702 SWAP_32(fe->fe_len_adesc) / sizeof (struct long_ad);
1703 1703 } else {
1704 1704 err = EINVAL;
1705 1705 goto end;
1706 1706 }
1707 1707
1708 1708 udm->udm_count = kmem_zalloc(udm->udm_nent * sizeof (*udm->udm_count),
1709 1709 KM_SLEEP);
1710 1710 udm->udm_bp = kmem_zalloc(udm->udm_nent * sizeof (*udm->udm_bp),
1711 1711 KM_SLEEP);
1712 1712 udm->udm_addr = kmem_zalloc(udm->udm_nent * sizeof (*udm->udm_addr),
1713 1713 KM_SLEEP);
1714 1714
1715 1715 if (ad_type == ICB_FLAG_ONE_AD) {
1716 1716 udm->udm_count[0] = (SWAP_64(fe->fe_info_len) - 36) /
1717 1717 sizeof (uint32_t);
1718 1718 udm->udm_bp[0] = secbp;
1719 1719 udm->udm_addr[0] = (uint32_t *)
1720 1720 &fe->fe_spec[SWAP_32(fe->fe_len_ear)];
1721 1721 return (0);
1722 1722 }
1723 1723 for (i = 0; i < udm->udm_nent; i++) {
1724 1724 if (ad_type == ICB_FLAG_SHORT_AD) {
1725 1725 sad = (struct short_ad *)
1726 1726 (fe->fe_spec + SWAP_32(fe->fe_len_ear));
1727 1727 sad += i;
1728 1728 count = SWAP_32(sad->sad_ext_len);
1729 1729 blk = SWAP_32(sad->sad_ext_loc);
1730 1730 } else {
1731 1731 lad = (struct long_ad *)
1732 1732 (fe->fe_spec + SWAP_32(fe->fe_len_ear));
1733 1733 lad += i;
1734 1734 count = SWAP_32(lad->lad_ext_len);
1735 1735 blk = SWAP_32(lad->lad_ext_loc);
1736 1736 ASSERT(SWAP_16(lad->lad_ext_prn) == udm->udm_pn);
1737 1737 }
1738 1738 if ((count & 0x3FFFFFFF) == 0) {
1739 1739 break;
1740 1740 }
1741 1741 if (i < udm->udm_nent - 1) {
1742 1742 udm->udm_count[i] = count / 4;
1743 1743 } else {
1744 1744 udm->udm_count[i] = (count - 36) / 4;
1745 1745 }
1746 1746 ud_part = udf_vfsp->udf_parts;
1747 1747 for (j = 0; j < udf_vfsp->udf_npart; j++) {
1748 1748 if (udm->udm_pn == ud_part->udp_number) {
1749 1749 blk = ud_part->udp_start + blk;
1750 1750 break;
1751 1751 }
1752 1752 }
1753 1753 if (j == udf_vfsp->udf_npart) {
1754 1754 err = EINVAL;
1755 1755 break;
1756 1756 }
1757 1757
1758 1758 count = (count + DEV_BSIZE - 1) & ~(DEV_BSIZE - 1);
1759 1759 udm->udm_bp[i] = ud_bread(dev,
1760 1760 blk << udf_vfsp->udf_l2d_shift, count);
1761 1761 if ((udm->udm_bp[i]->b_error != 0) ||
1762 1762 (udm->udm_bp[i]->b_resid)) {
1763 1763 err = EINVAL;
1764 1764 break;
1765 1765 }
1766 1766 udm->udm_addr[i] = (uint32_t *)udm->udm_bp[i]->b_un.b_addr;
1767 1767 }
1768 1768
1769 1769 end:
1770 1770 if (err)
1771 1771 ud_free_map(udm);
1772 1772 secbp->b_flags |= B_AGE | B_STALE;
1773 1773 brelse(secbp);
1774 1774 return (err);
1775 1775 }
1776 1776
1777 1777 int32_t
1778 1778 ud_read_sparing_tbls(struct udf_vfs *udf_vfsp,
1779 1779 dev_t dev, struct ud_map *map, struct pmap_typ2 *typ2)
1780 1780 {
1781 1781 int32_t index, valid = 0;
1782 1782 uint32_t sz;
1783 1783 struct buf *bp;
1784 1784 struct stbl *stbl;
1785 1785
1786 1786 map->udm_plen = SWAP_16(typ2->map2_pl);
1787 1787 map->udm_nspm = typ2->map2_nst;
1788 1788 map->udm_spsz = SWAP_32(typ2->map2_sest);
1789 1789 sz = (map->udm_spsz + udf_vfsp->udf_lbmask) & ~udf_vfsp->udf_lbmask;
1790 1790 if (sz == 0) {
1791 1791 return (0);
1792 1792 }
1793 1793
1794 1794 for (index = 0; index < map->udm_nspm; index++) {
1795 1795 map->udm_loc[index] = SWAP_32(typ2->map2_st[index]);
1796 1796
1797 1797 bp = ud_bread(dev,
1798 1798 map->udm_loc[index] << udf_vfsp->udf_l2d_shift, sz);
1799 1799 if ((bp->b_error != 0) || (bp->b_resid)) {
1800 1800 brelse(bp);
1801 1801 continue;
1802 1802 }
1803 1803 stbl = (struct stbl *)bp->b_un.b_addr;
1804 1804 if (strncmp(stbl->stbl_si.reg_id, UDF_SPAR_TBL, 23) != 0) {
1805 1805 printf("Sparing Identifier does not match\n");
1806 1806 bp->b_flags |= B_AGE | B_STALE;
1807 1807 brelse(bp);
1808 1808 continue;
1809 1809 }
1810 1810 map->udm_sbp[index] = bp;
1811 1811 map->udm_spaddr[index] = bp->b_un.b_addr;
1812 1812 #ifdef UNDEF
1813 1813 {
1814 1814 struct stbl_entry *te;
1815 1815 int32_t i, tbl_len;
1816 1816
1817 1817 te = (struct stbl_entry *)&stbl->stbl_entry;
1818 1818 tbl_len = SWAP_16(stbl->stbl_len);
1819 1819
1820 1820 printf("%x %x\n", tbl_len, SWAP_32(stbl->stbl_seqno));
1821 1821 printf("%x %x\n", bp->b_un.b_addr, te);
1822 1822
1823 1823 for (i = 0; i < tbl_len; i++) {
1824 1824 printf("%x %x\n", SWAP_32(te->sent_ol), SWAP_32(te->sent_ml));
1825 1825 te ++;
1826 1826 }
1827 1827 }
1828 1828 #endif
1829 1829 valid ++;
1830 1830 }
1831 1831
1832 1832 if (valid) {
1833 1833 return (0);
1834 1834 }
1835 1835 return (EINVAL);
1836 1836 }
1837 1837
1838 1838 uint32_t
1839 1839 ud_get_lbsize(dev_t dev, uint32_t *loc)
1840 1840 {
1841 1841 int32_t bsize, shift, index, end_index;
1842 1842 daddr_t last_block;
1843 1843 uint32_t avd_loc;
1844 1844 struct buf *bp;
1845 1845 struct anch_vol_desc_ptr *avdp;
1846 1846 uint32_t session_offset = 0;
1847 1847 int32_t rval;
1848 1848
1849 1849 if (ud_get_last_block(dev, &last_block) != 0) {
1850 1850 end_index = 1;
1851 1851 } else {
1852 1852 end_index = 3;
1853 1853 }
1854 1854
1855 1855 if (cdev_ioctl(dev, CDROMREADOFFSET, (intptr_t)&session_offset,
1856 1856 FKIOCTL|FREAD|FNATIVE, CRED(), &rval) != 0) {
1857 1857 session_offset = 0;
1858 1858 }
1859 1859
1860 1860 for (index = 0; index < end_index; index++) {
1861 1861
1862 1862 for (bsize = DEV_BSIZE, shift = 0;
1863 1863 bsize <= MAXBSIZE; bsize <<= 1, shift++) {
1864 1864
1865 1865 if (index == 0) {
1866 1866 avd_loc = 256;
1867 1867 if (bsize <= 2048) {
1868 1868 avd_loc +=
1869 1869 session_offset * 2048 / bsize;
1870 1870 } else {
1871 1871 avd_loc +=
1872 1872 session_offset / (bsize / 2048);
1873 1873 }
1874 1874 } else if (index == 1) {
1875 1875 avd_loc = last_block - (1 << shift);
1876 1876 } else {
1877 1877 avd_loc = last_block - (256 << shift);
1878 1878 }
1879 1879
1880 1880 bp = ud_bread(dev, avd_loc << shift,
1881 1881 ANCHOR_VOL_DESC_LEN);
1882 1882 if (geterror(bp) != 0) {
1883 1883 brelse(bp);
1884 1884 continue;
1885 1885 }
1886 1886
1887 1887 /*
1888 1888 * Verify if we have avdp here
1889 1889 */
1890 1890 avdp = (struct anch_vol_desc_ptr *)bp->b_un.b_addr;
1891 1891 if (ud_verify_tag_and_desc(&avdp->avd_tag,
1892 1892 UD_ANCH_VOL_DESC, avd_loc,
1893 1893 1, ANCHOR_VOL_DESC_LEN) != 0) {
1894 1894 bp->b_flags |= B_AGE | B_STALE;
1895 1895 brelse(bp);
1896 1896 continue;
1897 1897 }
1898 1898 bp->b_flags |= B_AGE | B_STALE;
1899 1899 brelse(bp);
1900 1900 *loc = avd_loc;
1901 1901 return (bsize);
1902 1902 }
1903 1903 }
1904 1904
↓ open down ↓ |
1751 lines elided |
↑ open up ↑ |
1905 1905 /*
1906 1906 * Did not find AVD at all the locations
1907 1907 */
1908 1908 return (0);
1909 1909 }
1910 1910
1911 1911 static int
1912 1912 udfinit(int fstype, char *name)
1913 1913 {
1914 1914 static const fs_operation_def_t udf_vfsops_template[] = {
1915 - VFSNAME_MOUNT, { .vfs_mount = udf_mount },
1916 - VFSNAME_UNMOUNT, { .vfs_unmount = udf_unmount },
1917 - VFSNAME_ROOT, { .vfs_root = udf_root },
1918 - VFSNAME_STATVFS, { .vfs_statvfs = udf_statvfs },
1919 - VFSNAME_SYNC, { .vfs_sync = udf_sync },
1920 - VFSNAME_VGET, { .vfs_vget = udf_vget },
1921 - VFSNAME_MOUNTROOT, { .vfs_mountroot = udf_mountroot },
1922 - NULL, NULL
1915 + { VFSNAME_MOUNT, { .vfs_mount = udf_mount } },
1916 + { VFSNAME_UNMOUNT, { .vfs_unmount = udf_unmount } },
1917 + { VFSNAME_ROOT, { .vfs_root = udf_root } },
1918 + { VFSNAME_STATVFS, { .vfs_statvfs = udf_statvfs } },
1919 + { VFSNAME_SYNC, { .vfs_sync = udf_sync } },
1920 + { VFSNAME_VGET, { .vfs_vget = udf_vget } },
1921 + { VFSNAME_MOUNTROOT, { .vfs_mountroot = udf_mountroot } },
1922 + { NULL, { NULL } }
1923 1923 };
1924 1924 extern struct vnodeops *udf_vnodeops;
1925 1925 extern const fs_operation_def_t udf_vnodeops_template[];
1926 1926 int error;
1927 1927
1928 1928 ud_printf("udfinit\n");
1929 1929
1930 1930 error = vfs_setfsops(fstype, udf_vfsops_template, NULL);
1931 1931 if (error != 0) {
1932 1932 cmn_err(CE_WARN, "udfinit: bad vfs ops template");
1933 1933 return (error);
1934 1934 }
1935 1935
1936 1936 error = vn_make_ops(name, udf_vnodeops_template, &udf_vnodeops);
1937 1937 if (error != 0) {
1938 1938 (void) vfs_freevfsops_by_type(fstype);
1939 1939 cmn_err(CE_WARN, "udfinit: bad vnode ops template");
1940 1940 return (error);
1941 1941 }
1942 1942
1943 1943 udf_fstype = fstype;
1944 1944
1945 1945 ud_init_inodes();
1946 1946
1947 1947 return (0);
1948 1948 }
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX