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