cd9660_vfsops.c revision 1.1 1 /* $NetBSD: cd9660_vfsops.c,v 1.1 2002/12/23 17:52:09 jdolecek Exp $ */
2
3 /*-
4 * Copyright (c) 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley
8 * by Pace Willisson (pace (at) blitz.com). The Rock Ridge Extension
9 * Support code is derived from software contributed to Berkeley
10 * by Atsushi Murai (amurai (at) spec.co.jp).
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * @(#)cd9660_vfsops.c 8.18 (Berkeley) 5/22/95
41 */
42
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.1 2002/12/23 17:52:09 jdolecek Exp $");
45
46 #if defined(_KERNEL_OPT)
47 #include "opt_compat_netbsd.h"
48 #endif
49
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/namei.h>
53 #include <sys/proc.h>
54 #include <sys/kernel.h>
55 #include <sys/vnode.h>
56 #include <miscfs/specfs/specdev.h>
57 #include <sys/mount.h>
58 #include <sys/buf.h>
59 #include <sys/file.h>
60 #include <sys/disklabel.h>
61 #include <sys/device.h>
62 #include <sys/ioctl.h>
63 #include <sys/cdio.h>
64 #include <sys/errno.h>
65 #include <sys/malloc.h>
66 #include <sys/pool.h>
67 #include <sys/stat.h>
68 #include <sys/conf.h>
69
70 #include <fs/cd9660/iso.h>
71 #include <fs/cd9660/cd9660_extern.h>
72 #include <fs/cd9660/iso_rrip.h>
73 #include <fs/cd9660/cd9660_node.h>
74 #include <fs/cd9660/cd9660_mount.h>
75
76 extern const struct vnodeopv_desc cd9660_vnodeop_opv_desc;
77 extern const struct vnodeopv_desc cd9660_specop_opv_desc;
78 extern const struct vnodeopv_desc cd9660_fifoop_opv_desc;
79
80 const struct vnodeopv_desc * const cd9660_vnodeopv_descs[] = {
81 &cd9660_vnodeop_opv_desc,
82 &cd9660_specop_opv_desc,
83 &cd9660_fifoop_opv_desc,
84 NULL,
85 };
86
87 struct vfsops cd9660_vfsops = {
88 MOUNT_CD9660,
89 cd9660_mount,
90 cd9660_start,
91 cd9660_unmount,
92 cd9660_root,
93 cd9660_quotactl,
94 cd9660_statfs,
95 cd9660_sync,
96 cd9660_vget,
97 cd9660_fhtovp,
98 cd9660_vptofh,
99 cd9660_init,
100 cd9660_reinit,
101 cd9660_done,
102 cd9660_sysctl,
103 cd9660_mountroot,
104 cd9660_check_export,
105 cd9660_vnodeopv_descs,
106 };
107
108 struct genfs_ops cd9660_genfsops = {
109 genfs_size,
110 };
111
112 /*
113 * Called by vfs_mountroot when iso is going to be mounted as root.
114 *
115 * Name is updated by mount(8) after booting.
116 */
117 #define ROOTNAME "root_device"
118
119 static int iso_makemp __P((struct iso_mnt *isomp, struct buf *bp, int *ea_len));
120 static int iso_mountfs __P((struct vnode *devvp, struct mount *mp,
121 struct proc *p, struct iso_args *argp));
122
123 int
124 cd9660_mountroot()
125 {
126 struct mount *mp;
127 struct proc *p = curproc; /* XXX */
128 int error;
129 struct iso_args args;
130
131 if (root_device->dv_class != DV_DISK)
132 return (ENODEV);
133
134 /*
135 * Get vnodes for swapdev and rootdev.
136 */
137 if (bdevvp(rootdev, &rootvp))
138 panic("cd9660_mountroot: can't setup rootvp");
139
140 if ((error = vfs_rootmountalloc(MOUNT_CD9660, "root_device", &mp))
141 != 0) {
142 vrele(rootvp);
143 return (error);
144 }
145
146 args.flags = ISOFSMNT_ROOT;
147 if ((error = iso_mountfs(rootvp, mp, p, &args)) != 0) {
148 mp->mnt_op->vfs_refcount--;
149 vfs_unbusy(mp);
150 free(mp, M_MOUNT);
151 vrele(rootvp);
152 return (error);
153 }
154 simple_lock(&mountlist_slock);
155 CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
156 simple_unlock(&mountlist_slock);
157 (void)cd9660_statfs(mp, &mp->mnt_stat, p);
158 vfs_unbusy(mp);
159 inittodr(0);
160 return (0);
161 }
162
163 /*
164 * VFS Operations.
165 *
166 * mount system call
167 */
168 int
169 cd9660_mount(mp, path, data, ndp, p)
170 struct mount *mp;
171 const char *path;
172 void *data;
173 struct nameidata *ndp;
174 struct proc *p;
175 {
176 struct vnode *devvp;
177 struct iso_args args;
178 size_t size;
179 int error;
180 struct iso_mnt *imp = NULL;
181
182 if (mp->mnt_flag & MNT_GETARGS) {
183 imp = VFSTOISOFS(mp);
184 if (imp == NULL)
185 return EIO;
186 args.fspec = NULL;
187 args.flags = imp->im_flags;
188 vfs_showexport(mp, &args.export, &imp->im_export);
189 return copyout(&args, data, sizeof(args));
190 }
191 error = copyin(data, (caddr_t)&args, sizeof (struct iso_args));
192 if (error)
193 return (error);
194
195 if ((mp->mnt_flag & MNT_RDONLY) == 0)
196 return (EROFS);
197
198 /*
199 * If updating, check whether changing from read-only to
200 * read/write; if there is no device name, that's all we do.
201 */
202 if (mp->mnt_flag & MNT_UPDATE) {
203 imp = VFSTOISOFS(mp);
204 if (args.fspec == 0)
205 return (vfs_export(mp, &imp->im_export, &args.export));
206 }
207 /*
208 * Not an update, or updating the name: look up the name
209 * and verify that it refers to a sensible block device.
210 */
211 NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p);
212 if ((error = namei(ndp)) != 0)
213 return (error);
214 devvp = ndp->ni_vp;
215
216 if (devvp->v_type != VBLK) {
217 vrele(devvp);
218 return ENOTBLK;
219 }
220 if (bdevsw_lookup(devvp->v_rdev) == NULL) {
221 vrele(devvp);
222 return ENXIO;
223 }
224 /*
225 * If mount by non-root, then verify that user has necessary
226 * permissions on the device.
227 */
228 if (p->p_ucred->cr_uid != 0) {
229 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
230 error = VOP_ACCESS(devvp, VREAD, p->p_ucred, p);
231 VOP_UNLOCK(devvp, 0);
232 if (error) {
233 vrele(devvp);
234 return (error);
235 }
236 }
237 if ((mp->mnt_flag & MNT_UPDATE) == 0)
238 error = iso_mountfs(devvp, mp, p, &args);
239 else {
240 if (devvp != imp->im_devvp)
241 error = EINVAL; /* needs translation */
242 else
243 vrele(devvp);
244 }
245 if (error) {
246 vrele(devvp);
247 return error;
248 }
249 imp = VFSTOISOFS(mp);
250 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
251 memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
252 (void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
253 &size);
254 memset(mp->mnt_stat.f_mntfromname + size, 0, MNAMELEN - size);
255 return 0;
256 }
257
258 /*
259 * Make a mount point from a volume descriptor
260 */
261 static int
262 iso_makemp(isomp, bp, ea_len)
263 struct iso_mnt *isomp;
264 struct buf *bp;
265 int *ea_len;
266 {
267 struct iso_primary_descriptor *pri;
268 int logical_block_size;
269 struct iso_directory_record *rootp;
270
271 pri = (struct iso_primary_descriptor *)bp->b_data;
272
273 logical_block_size = isonum_723 (pri->logical_block_size);
274
275 if (logical_block_size < DEV_BSIZE || logical_block_size > MAXBSIZE
276 || (logical_block_size & (logical_block_size - 1)) != 0)
277 return -1;
278
279 rootp = (struct iso_directory_record *)pri->root_directory_record;
280
281 isomp->logical_block_size = logical_block_size;
282 isomp->volume_space_size = isonum_733 (pri->volume_space_size);
283 memcpy(isomp->root, rootp, sizeof(isomp->root));
284 isomp->root_extent = isonum_733 (rootp->extent);
285 isomp->root_size = isonum_733 (rootp->size);
286 isomp->im_joliet_level = 0;
287
288 isomp->im_bmask = logical_block_size - 1;
289 isomp->im_bshift = 0;
290 while ((1 << isomp->im_bshift) < isomp->logical_block_size)
291 isomp->im_bshift++;
292
293 if (ea_len != NULL)
294 *ea_len = isonum_711(rootp->ext_attr_length);
295
296 return 0;
297 }
298
299 /*
300 * Common code for mount and mountroot
301 */
302 static int
303 iso_mountfs(devvp, mp, p, argp)
304 struct vnode *devvp;
305 struct mount *mp;
306 struct proc *p;
307 struct iso_args *argp;
308 {
309 struct iso_mnt *isomp = (struct iso_mnt *)0;
310 struct buf *bp = NULL, *pribp = NULL, *supbp = NULL;
311 dev_t dev = devvp->v_rdev;
312 int error = EINVAL;
313 int needclose = 0;
314 int ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
315 int iso_bsize;
316 int iso_blknum;
317 int joliet_level;
318 struct iso_volume_descriptor *vdp;
319 struct iso_supplementary_descriptor *sup;
320 int sess = 0;
321 int ext_attr_length;
322 struct disklabel label;
323
324 if (!ronly)
325 return EROFS;
326
327 /*
328 * Disallow multiple mounts of the same device.
329 * Disallow mounting of a device that is currently in use
330 * (except for root, which might share swap device for miniroot).
331 * Flush out any old buffers remaining from a previous use.
332 */
333 if ((error = vfs_mountedon(devvp)) != 0)
334 return error;
335 if (vcount(devvp) > 1 && devvp != rootvp)
336 return EBUSY;
337 if ((error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0)) != 0)
338 return (error);
339
340 error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p);
341 if (error)
342 return error;
343 needclose = 1;
344
345 /* This is the "logical sector size". The standard says this
346 * should be 2048 or the physical sector size on the device,
347 * whichever is greater. For now, we'll just use a constant.
348 */
349 iso_bsize = ISO_DEFAULT_BLOCK_SIZE;
350
351 error = VOP_IOCTL(devvp, DIOCGDINFO, (caddr_t)&label, FREAD, FSCRED, p);
352 if (!error &&
353 label.d_partitions[DISKPART(dev)].p_fstype == FS_ISO9660) {
354 /* XXX more sanity checks? */
355 sess = label.d_partitions[DISKPART(dev)].p_cdsession;
356 } else {
357 /* fallback to old method */
358 error = VOP_IOCTL(devvp, CDIOREADMSADDR, (caddr_t)&sess, 0,
359 FSCRED, p);
360 if (error)
361 sess = 0; /* never mind */
362 }
363 #ifdef DEBUG
364 printf("isofs: session offset (part %d) %d\n", DISKPART(dev), sess);
365 #endif
366
367 for (iso_blknum = 16; iso_blknum < 100; iso_blknum++) {
368 if ((error = bread(devvp, (iso_blknum+sess) * btodb(iso_bsize),
369 iso_bsize, NOCRED, &bp)) != 0)
370 goto out;
371
372 vdp = (struct iso_volume_descriptor *)bp->b_data;
373 if (memcmp(vdp->id, ISO_STANDARD_ID, sizeof(vdp->id)) != 0) {
374 error = EINVAL;
375 goto out;
376 }
377
378 switch (isonum_711(vdp->type)) {
379 case ISO_VD_PRIMARY:
380 if (pribp == NULL) {
381 pribp = bp;
382 bp = NULL;
383 }
384 break;
385
386 case ISO_VD_SUPPLEMENTARY:
387 if (supbp == NULL) {
388 supbp = bp;
389 bp = NULL;
390 }
391 break;
392
393 default:
394 break;
395 }
396
397 if (isonum_711 (vdp->type) == ISO_VD_END) {
398 brelse(bp);
399 bp = NULL;
400 break;
401 }
402
403 if (bp != NULL) {
404 brelse(bp);
405 bp = NULL;
406 }
407 }
408
409 if (pribp == NULL) {
410 error = EINVAL;
411 goto out;
412 }
413
414 isomp = malloc(sizeof *isomp, M_ISOFSMNT, M_WAITOK);
415 memset((caddr_t)isomp, 0, sizeof *isomp);
416 if (iso_makemp(isomp, pribp, &ext_attr_length) == -1) {
417 error = EINVAL;
418 goto out;
419 }
420
421 isomp->volume_space_size += sess;
422
423 pribp->b_flags |= B_AGE;
424 brelse(pribp);
425 pribp = NULL;
426
427 mp->mnt_data = isomp;
428 mp->mnt_stat.f_fsid.val[0] = (long)dev;
429 mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_CD9660);
430 mp->mnt_maxsymlinklen = 0;
431 mp->mnt_flag |= MNT_LOCAL;
432 mp->mnt_dev_bshift = iso_bsize;
433 mp->mnt_fs_bshift = isomp->im_bshift;
434 isomp->im_mountp = mp;
435 isomp->im_dev = dev;
436 isomp->im_devvp = devvp;
437
438 devvp->v_specmountpoint = mp;
439
440 /* Check the Rock Ridge Extension support */
441 if (!(argp->flags & ISOFSMNT_NORRIP)) {
442 struct iso_directory_record *rootp;
443
444 if ((error = bread(isomp->im_devvp,
445 (isomp->root_extent + ext_attr_length) <<
446 (isomp->im_bshift - DEV_BSHIFT),
447 isomp->logical_block_size, NOCRED,
448 &bp)) != 0)
449 goto out;
450
451 rootp = (struct iso_directory_record *)bp->b_data;
452
453 if ((isomp->rr_skip = cd9660_rrip_offset(rootp,isomp)) < 0) {
454 argp->flags |= ISOFSMNT_NORRIP;
455 } else {
456 argp->flags &= ~ISOFSMNT_GENS;
457 }
458
459 /*
460 * The contents are valid,
461 * but they will get reread as part of another vnode, so...
462 */
463 bp->b_flags |= B_AGE;
464 brelse(bp);
465 bp = NULL;
466 }
467 isomp->im_flags = argp->flags & (ISOFSMNT_NORRIP | ISOFSMNT_GENS |
468 ISOFSMNT_EXTATT | ISOFSMNT_NOJOLIET | ISOFSMNT_RRCASEINS);
469
470 if (isomp->im_flags & ISOFSMNT_GENS)
471 isomp->iso_ftype = ISO_FTYPE_9660;
472 else if (isomp->im_flags & ISOFSMNT_NORRIP) {
473 isomp->iso_ftype = ISO_FTYPE_DEFAULT;
474 if (argp->flags & ISOFSMNT_NOCASETRANS)
475 isomp->im_flags |= ISOFSMNT_NOCASETRANS;
476 } else
477 isomp->iso_ftype = ISO_FTYPE_RRIP;
478
479 /* Check the Joliet Extension support */
480 if ((argp->flags & ISOFSMNT_NORRIP) != 0 &&
481 (argp->flags & ISOFSMNT_NOJOLIET) == 0 &&
482 supbp != NULL) {
483 joliet_level = 0;
484 sup = (struct iso_supplementary_descriptor *)supbp->b_data;
485
486 if ((isonum_711(sup->flags) & 1) == 0) {
487 if (memcmp(sup->escape, "%/@", 3) == 0)
488 joliet_level = 1;
489 if (memcmp(sup->escape, "%/C", 3) == 0)
490 joliet_level = 2;
491 if (memcmp(sup->escape, "%/E", 3) == 0)
492 joliet_level = 3;
493 }
494 if (joliet_level != 0) {
495 if (iso_makemp(isomp, supbp, NULL) == -1) {
496 error = EINVAL;
497 goto out;
498 }
499 isomp->im_joliet_level = joliet_level;
500 }
501 }
502
503 if (supbp != NULL) {
504 brelse(supbp);
505 supbp = NULL;
506 }
507
508 return 0;
509 out:
510 if (bp)
511 brelse(bp);
512 if (pribp)
513 brelse(pribp);
514 if (supbp)
515 brelse(supbp);
516 if (needclose) {
517 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
518 (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
519 VOP_UNLOCK(devvp, 0);
520 }
521 if (isomp) {
522 free((caddr_t)isomp, M_ISOFSMNT);
523 mp->mnt_data = NULL;
524 }
525 return error;
526 }
527
528 /*
529 * Make a filesystem operational.
530 * Nothing to do at the moment.
531 */
532 /* ARGSUSED */
533 int
534 cd9660_start(mp, flags, p)
535 struct mount *mp;
536 int flags;
537 struct proc *p;
538 {
539 return 0;
540 }
541
542 /*
543 * unmount system call
544 */
545 int
546 cd9660_unmount(mp, mntflags, p)
547 struct mount *mp;
548 int mntflags;
549 struct proc *p;
550 {
551 struct iso_mnt *isomp;
552 int error, flags = 0;
553
554 if (mntflags & MNT_FORCE)
555 flags |= FORCECLOSE;
556 #if 0
557 mntflushbuf(mp, 0);
558 if (mntinvalbuf(mp))
559 return EBUSY;
560 #endif
561 if ((error = vflush(mp, NULLVP, flags)) != 0)
562 return (error);
563
564 isomp = VFSTOISOFS(mp);
565
566 #ifdef ISODEVMAP
567 if (isomp->iso_ftype == ISO_FTYPE_RRIP)
568 iso_dunmap(isomp->im_dev);
569 #endif
570
571 if (isomp->im_devvp->v_type != VBAD)
572 isomp->im_devvp->v_specmountpoint = NULL;
573
574 vn_lock(isomp->im_devvp, LK_EXCLUSIVE | LK_RETRY);
575 error = VOP_CLOSE(isomp->im_devvp, FREAD, NOCRED, p);
576 vput(isomp->im_devvp);
577 free((caddr_t)isomp, M_ISOFSMNT);
578 mp->mnt_data = NULL;
579 mp->mnt_flag &= ~MNT_LOCAL;
580 return (error);
581 }
582
583 /*
584 * Return root of a filesystem
585 */
586 int
587 cd9660_root(mp, vpp)
588 struct mount *mp;
589 struct vnode **vpp;
590 {
591 struct iso_mnt *imp = VFSTOISOFS(mp);
592 struct iso_directory_record *dp =
593 (struct iso_directory_record *)imp->root;
594 ino_t ino = isodirino(dp, imp);
595
596 /*
597 * With RRIP we must use the `.' entry of the root directory.
598 * Simply tell vget, that it's a relocated directory.
599 */
600 return (cd9660_vget_internal(mp, ino, vpp,
601 imp->iso_ftype == ISO_FTYPE_RRIP, dp));
602 }
603
604 /*
605 * Do operations associated with quotas, not supported
606 */
607 /* ARGSUSED */
608 int
609 cd9660_quotactl(mp, cmd, uid, arg, p)
610 struct mount *mp;
611 int cmd;
612 uid_t uid;
613 caddr_t arg;
614 struct proc *p;
615 {
616
617 return (EOPNOTSUPP);
618 }
619
620 /*
621 * Get file system statistics.
622 */
623 int
624 cd9660_statfs(mp, sbp, p)
625 struct mount *mp;
626 struct statfs *sbp;
627 struct proc *p;
628 {
629 struct iso_mnt *isomp;
630
631 isomp = VFSTOISOFS(mp);
632
633 #ifdef COMPAT_09
634 sbp->f_type = 5;
635 #else
636 sbp->f_type = 0;
637 #endif
638 sbp->f_bsize = isomp->logical_block_size;
639 sbp->f_iosize = sbp->f_bsize; /* XXX */
640 sbp->f_blocks = isomp->volume_space_size;
641 sbp->f_bfree = 0; /* total free blocks */
642 sbp->f_bavail = 0; /* blocks free for non superuser */
643 sbp->f_files = 0; /* total files */
644 sbp->f_ffree = 0; /* free file nodes */
645 if (sbp != &mp->mnt_stat) {
646 memcpy(sbp->f_mntonname, mp->mnt_stat.f_mntonname, MNAMELEN);
647 memcpy(sbp->f_mntfromname, mp->mnt_stat.f_mntfromname, MNAMELEN);
648 }
649 strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
650 /* Use the first spare for flags: */
651 sbp->f_spare[0] = isomp->im_flags;
652 return 0;
653 }
654
655 /* ARGSUSED */
656 int
657 cd9660_sync(mp, waitfor, cred, p)
658 struct mount *mp;
659 int waitfor;
660 struct ucred *cred;
661 struct proc *p;
662 {
663 return (0);
664 }
665
666 /*
667 * File handle to vnode
668 *
669 * Have to be really careful about stale file handles:
670 * - check that the inode number is in range
671 * - call iget() to get the locked inode
672 * - check for an unallocated inode (i_mode == 0)
673 * - check that the generation number matches
674 */
675
676 struct ifid {
677 ushort ifid_len;
678 ushort ifid_pad;
679 int ifid_ino;
680 long ifid_start;
681 };
682
683 /* ARGSUSED */
684 int
685 cd9660_fhtovp(mp, fhp, vpp)
686 struct mount *mp;
687 struct fid *fhp;
688 struct vnode **vpp;
689 {
690 struct ifid *ifhp = (struct ifid *)fhp;
691 struct iso_node *ip;
692 struct vnode *nvp;
693 int error;
694
695 #ifdef ISOFS_DBG
696 printf("fhtovp: ino %d, start %ld\n",
697 ifhp->ifid_ino, ifhp->ifid_start);
698 #endif
699
700 if ((error = VFS_VGET(mp, ifhp->ifid_ino, &nvp)) != 0) {
701 *vpp = NULLVP;
702 return (error);
703 }
704 ip = VTOI(nvp);
705 if (ip->inode.iso_mode == 0) {
706 vput(nvp);
707 *vpp = NULLVP;
708 return (ESTALE);
709 }
710 *vpp = nvp;
711 return (0);
712 }
713
714 /* ARGSUSED */
715 int
716 cd9660_check_export(mp, nam, exflagsp, credanonp)
717 struct mount *mp;
718 struct mbuf *nam;
719 int *exflagsp;
720 struct ucred **credanonp;
721 {
722 struct netcred *np;
723 struct iso_mnt *imp = VFSTOISOFS(mp);
724
725 #ifdef ISOFS_DBG
726 printf("check_export: ino %d, start %ld\n",
727 ifhp->ifid_ino, ifhp->ifid_start);
728 #endif
729
730 /*
731 * Get the export permission structure for this <mp, client> tuple.
732 */
733 np = vfs_export_lookup(mp, &imp->im_export, nam);
734 if (np == NULL)
735 return (EACCES);
736
737 *exflagsp = np->netc_exflags;
738 *credanonp = &np->netc_anon;
739 return (0);
740 }
741
742 int
743 cd9660_vget(mp, ino, vpp)
744 struct mount *mp;
745 ino_t ino;
746 struct vnode **vpp;
747 {
748
749 /*
750 * XXXX
751 * It would be nice if we didn't always set the `relocated' flag
752 * and force the extra read, but I don't want to think about fixing
753 * that right now.
754 */
755 return (cd9660_vget_internal(mp, ino, vpp,
756 #if 0
757 VFSTOISOFS(mp)->iso_ftype == ISO_FTYPE_RRIP,
758 #else
759 0,
760 #endif
761 NULL));
762 }
763
764 int
765 cd9660_vget_internal(mp, ino, vpp, relocated, isodir)
766 struct mount *mp;
767 ino_t ino;
768 struct vnode **vpp;
769 int relocated;
770 struct iso_directory_record *isodir;
771 {
772 struct iso_mnt *imp;
773 struct iso_node *ip;
774 #ifdef ISODEVMAP
775 struct iso_dnode *dp;
776 #endif
777 struct buf *bp;
778 struct vnode *vp, *nvp;
779 dev_t dev;
780 int error;
781
782 imp = VFSTOISOFS(mp);
783 dev = imp->im_dev;
784 if ((*vpp = cd9660_ihashget(dev, ino)) != NULLVP)
785 return (0);
786
787 /* Allocate a new vnode/iso_node. */
788 if ((error = getnewvnode(VT_ISOFS, mp, cd9660_vnodeop_p, &vp)) != 0) {
789 *vpp = NULLVP;
790 return (error);
791 }
792 ip = pool_get(&cd9660_node_pool, PR_WAITOK);
793 memset((caddr_t)ip, 0, sizeof(struct iso_node));
794 vp->v_data = ip;
795 ip->i_vnode = vp;
796 ip->i_dev = dev;
797 ip->i_number = ino;
798
799 /*
800 * Put it onto its hash chain and lock it so that other requests for
801 * this inode will block if they arrive while we are sleeping waiting
802 * for old data structures to be purged or for the contents of the
803 * disk portion of this inode to be read.
804 */
805 cd9660_ihashins(ip);
806
807 if (isodir == 0) {
808 int lbn, off;
809
810 lbn = lblkno(imp, ino);
811 if (lbn >= imp->volume_space_size) {
812 vput(vp);
813 printf("fhtovp: lbn exceed volume space %d\n", lbn);
814 return (ESTALE);
815 }
816
817 off = blkoff(imp, ino);
818 if (off + ISO_DIRECTORY_RECORD_SIZE > imp->logical_block_size) {
819 vput(vp);
820 printf("fhtovp: crosses block boundary %d\n",
821 off + ISO_DIRECTORY_RECORD_SIZE);
822 return (ESTALE);
823 }
824
825 error = bread(imp->im_devvp,
826 lbn << (imp->im_bshift - DEV_BSHIFT),
827 imp->logical_block_size, NOCRED, &bp);
828 if (error) {
829 vput(vp);
830 brelse(bp);
831 printf("fhtovp: bread error %d\n",error);
832 return (error);
833 }
834 isodir = (struct iso_directory_record *)(bp->b_data + off);
835
836 if (off + isonum_711(isodir->length) >
837 imp->logical_block_size) {
838 vput(vp);
839 if (bp != 0)
840 brelse(bp);
841 printf("fhtovp: directory crosses block boundary %d[off=%d/len=%d]\n",
842 off +isonum_711(isodir->length), off,
843 isonum_711(isodir->length));
844 return (ESTALE);
845 }
846
847 #if 0
848 if (isonum_733(isodir->extent) +
849 isonum_711(isodir->ext_attr_length) != ifhp->ifid_start) {
850 if (bp != 0)
851 brelse(bp);
852 printf("fhtovp: file start miss %d vs %d\n",
853 isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length),
854 ifhp->ifid_start);
855 return (ESTALE);
856 }
857 #endif
858 } else
859 bp = 0;
860
861 ip->i_mnt = imp;
862 ip->i_devvp = imp->im_devvp;
863 VREF(ip->i_devvp);
864
865 if (relocated) {
866 /*
867 * On relocated directories we must
868 * read the `.' entry out of a dir.
869 */
870 ip->iso_start = ino >> imp->im_bshift;
871 if (bp != 0)
872 brelse(bp);
873 if ((error = VOP_BLKATOFF(vp, (off_t)0, NULL, &bp)) != 0) {
874 vput(vp);
875 return (error);
876 }
877 isodir = (struct iso_directory_record *)bp->b_data;
878 }
879
880 ip->iso_extent = isonum_733(isodir->extent);
881 ip->i_size = isonum_733(isodir->size);
882 ip->iso_start = isonum_711(isodir->ext_attr_length) + ip->iso_extent;
883
884 /*
885 * Setup time stamp, attribute
886 */
887 vp->v_type = VNON;
888 switch (imp->iso_ftype) {
889 default: /* ISO_FTYPE_9660 */
890 {
891 struct buf *bp2;
892 int off;
893 if ((imp->im_flags & ISOFSMNT_EXTATT)
894 && (off = isonum_711(isodir->ext_attr_length)))
895 VOP_BLKATOFF(vp, (off_t)-(off << imp->im_bshift), NULL,
896 &bp2);
897 else
898 bp2 = NULL;
899 cd9660_defattr(isodir, ip, bp2);
900 cd9660_deftstamp(isodir, ip, bp2);
901 if (bp2)
902 brelse(bp2);
903 break;
904 }
905 case ISO_FTYPE_RRIP:
906 cd9660_rrip_analyze(isodir, ip, imp);
907 break;
908 }
909
910 if (bp != 0)
911 brelse(bp);
912
913 /*
914 * Initialize the associated vnode
915 */
916 switch (vp->v_type = IFTOVT(ip->inode.iso_mode)) {
917 case VFIFO:
918 vp->v_op = cd9660_fifoop_p;
919 break;
920 case VCHR:
921 case VBLK:
922 /*
923 * if device, look at device number table for translation
924 */
925 #ifdef ISODEVMAP
926 if ((dp = iso_dmap(dev, ino, 0)) != NULL)
927 ip->inode.iso_rdev = dp->d_dev;
928 #endif
929 vp->v_op = cd9660_specop_p;
930 if ((nvp = checkalias(vp, ip->inode.iso_rdev, mp)) != NULL) {
931 /*
932 * Discard unneeded vnode, but save its iso_node.
933 * Note that the lock is carried over in the iso_node
934 * to the replacement vnode.
935 */
936 nvp->v_data = vp->v_data;
937 vp->v_data = NULL;
938 VOP_UNLOCK(vp, 0);
939 vp->v_op = spec_vnodeop_p;
940 vrele(vp);
941 vgone(vp);
942 lockmgr(&nvp->v_lock, LK_EXCLUSIVE, &nvp->v_interlock);
943 /*
944 * Reinitialize aliased inode.
945 */
946 vp = nvp;
947 ip->i_vnode = vp;
948 }
949 break;
950 case VLNK:
951 case VNON:
952 case VSOCK:
953 case VDIR:
954 case VBAD:
955 break;
956 case VREG:
957 uvm_vnp_setsize(vp, ip->i_size);
958 break;
959 }
960
961 if (ip->iso_extent == imp->root_extent)
962 vp->v_flag |= VROOT;
963
964 /*
965 * XXX need generation number?
966 */
967
968 genfs_node_init(vp, &cd9660_genfsops);
969 *vpp = vp;
970 return (0);
971 }
972
973 /*
974 * Vnode pointer to File handle
975 */
976 /* ARGSUSED */
977 int
978 cd9660_vptofh(vp, fhp)
979 struct vnode *vp;
980 struct fid *fhp;
981 {
982 struct iso_node *ip = VTOI(vp);
983 struct ifid *ifhp;
984
985 ifhp = (struct ifid *)fhp;
986 ifhp->ifid_len = sizeof(struct ifid);
987
988 ifhp->ifid_ino = ip->i_number;
989 ifhp->ifid_start = ip->iso_start;
990
991 #ifdef ISOFS_DBG
992 printf("vptofh: ino %d, start %ld\n",
993 ifhp->ifid_ino,ifhp->ifid_start);
994 #endif
995 return 0;
996 }
997
998 int
999 cd9660_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
1000 int *name;
1001 u_int namelen;
1002 void *oldp;
1003 size_t *oldlenp;
1004 void *newp;
1005 size_t newlen;
1006 struct proc *p;
1007 {
1008 return (EOPNOTSUPP);
1009 }
1010