cd9660_vnops.c revision 1.17.2.2 1 /* $NetBSD: cd9660_vnops.c,v 1.17.2.2 2005/11/18 08:44:54 yamt 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_vnops.c 8.15 (Berkeley) 5/27/95
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: cd9660_vnops.c,v 1.17.2.2 2005/11/18 08:44:54 yamt Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/namei.h>
45 #include <sys/resourcevar.h>
46 #include <sys/kernel.h>
47 #include <sys/file.h>
48 #include <sys/stat.h>
49 #include <sys/buf.h>
50 #include <sys/proc.h>
51 #include <sys/mount.h>
52 #include <sys/vnode.h>
53 #include <sys/malloc.h>
54 #include <sys/dirent.h>
55
56 #include <miscfs/fifofs/fifo.h>
57 #include <miscfs/genfs/genfs.h>
58 #include <miscfs/specfs/specdev.h>
59
60 #include <fs/cd9660/iso.h>
61 #include <fs/cd9660/cd9660_extern.h>
62 #include <fs/cd9660/cd9660_node.h>
63 #include <fs/cd9660/iso_rrip.h>
64 #include <fs/cd9660/cd9660_mount.h>
65
66 #include <uvm/uvm_readahead.h>
67
68 /*
69 * Structure for reading directories
70 */
71 struct isoreaddir {
72 struct dirent saveent;
73 struct dirent assocent;
74 struct dirent current;
75 off_t saveoff;
76 off_t assocoff;
77 off_t curroff;
78 struct uio *uio;
79 off_t uio_off;
80 int eofflag;
81 off_t *cookies;
82 int ncookies;
83 };
84
85 int iso_uiodir(struct isoreaddir *, struct dirent *, off_t);
86 int iso_shipdir(struct isoreaddir *);
87
88 #if 0
89 /*
90 * Mknod vnode call
91 * Actually remap the device number
92 */
93 int
94 cd9660_mknod(ndp, vap, cred, p)
95 struct nameidata *ndp;
96 struct ucred *cred;
97 struct vattr *vap;
98 struct proc *p;
99 {
100 #ifndef ISODEVMAP
101 PNBUF_PUT(ndp->ni_pnbuf);
102 vput(ndp->ni_dvp);
103 vput(ndp->ni_vp);
104 return (EINVAL);
105 #else
106 struct vnode *vp;
107 struct iso_node *ip;
108 struct iso_dnode *dp;
109
110 vp = ndp->ni_vp;
111 ip = VTOI(vp);
112
113 if (ip->i_mnt->iso_ftype != ISO_FTYPE_RRIP
114 || vap->va_type != vp->v_type
115 || (vap->va_type != VCHR && vap->va_type != VBLK)) {
116 PNBUF_PUT(ndp->ni_pnbuf);
117 vput(ndp->ni_dvp);
118 vput(ndp->ni_vp);
119 return (EINVAL);
120 }
121
122 dp = iso_dmap(ip->i_dev, ip->i_number, 1);
123 if (ip->inode.iso_rdev == vap->va_rdev ||
124 vap->va_rdev == (dev_t)VNOVAL) {
125 /* same as the unmapped one, delete the mapping */
126 LIST_REMOVE(dp, d_hash);
127 FREE(dp, M_CACHE);
128 } else
129 /* enter new mapping */
130 dp->d_dev = vap->va_rdev;
131
132 /*
133 * Remove inode so that it will be reloaded by iget and
134 * checked to see if it is an alias of an existing entry
135 * in the inode cache.
136 */
137 vput(vp);
138 vp->v_type = VNON;
139 vgone(vp);
140 return (0);
141 #endif
142 }
143 #endif
144
145 /*
146 * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC.
147 * The mode is shifted to select the owner/group/other fields. The
148 * super user is granted all permissions.
149 */
150 int
151 cd9660_access(v)
152 void *v;
153 {
154 struct vop_access_args /* {
155 struct vnode *a_vp;
156 int a_mode;
157 struct ucred *a_cred;
158 struct proc *a_p;
159 } */ *ap = v;
160 struct vnode *vp = ap->a_vp;
161 struct iso_node *ip = VTOI(vp);
162
163 /*
164 * Disallow write attempts unless the file is a socket,
165 * fifo, or a block or character device resident on the
166 * file system.
167 */
168 if (ap->a_mode & VWRITE) {
169 switch (vp->v_type) {
170 case VDIR:
171 case VLNK:
172 case VREG:
173 return (EROFS);
174 default:
175 break;
176 }
177 }
178
179 return (vaccess(vp->v_type, ip->inode.iso_mode & ALLPERMS,
180 ip->inode.iso_uid, ip->inode.iso_gid, ap->a_mode, ap->a_cred));
181 }
182
183 int
184 cd9660_getattr(v)
185 void *v;
186 {
187 struct vop_getattr_args /* {
188 struct vnode *a_vp;
189 struct vattr *a_vap;
190 struct ucred *a_cred;
191 struct proc *a_p;
192 } */ *ap = v;
193 struct vnode *vp = ap->a_vp;
194 struct iso_node *ip = VTOI(vp);
195 struct vattr *vap = ap->a_vap;
196
197 vap->va_fsid = ip->i_dev;
198 vap->va_fileid = ip->i_number;
199
200 vap->va_mode = ip->inode.iso_mode & ALLPERMS;
201 vap->va_nlink = ip->inode.iso_links;
202 vap->va_uid = ip->inode.iso_uid;
203 vap->va_gid = ip->inode.iso_gid;
204 vap->va_atime = ip->inode.iso_atime;
205 vap->va_mtime = ip->inode.iso_mtime;
206 vap->va_ctime = ip->inode.iso_ctime;
207 vap->va_rdev = ip->inode.iso_rdev;
208
209 vap->va_size = (u_quad_t) ip->i_size;
210 if (ip->i_size == 0 && vp->v_type == VLNK) {
211 struct vop_readlink_args rdlnk;
212 struct iovec aiov;
213 struct uio auio;
214 char *cp;
215
216 MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
217 aiov.iov_base = cp;
218 aiov.iov_len = MAXPATHLEN;
219 auio.uio_iov = &aiov;
220 auio.uio_iovcnt = 1;
221 auio.uio_offset = 0;
222 auio.uio_rw = UIO_READ;
223 auio.uio_segflg = UIO_SYSSPACE;
224 auio.uio_procp = NULL;
225 auio.uio_resid = MAXPATHLEN;
226 rdlnk.a_uio = &auio;
227 rdlnk.a_vp = ap->a_vp;
228 rdlnk.a_cred = ap->a_cred;
229 if (cd9660_readlink(&rdlnk) == 0)
230 vap->va_size = MAXPATHLEN - auio.uio_resid;
231 FREE(cp, M_TEMP);
232 }
233 vap->va_flags = 0;
234 vap->va_gen = 1;
235 vap->va_blocksize = ip->i_mnt->logical_block_size;
236 vap->va_bytes = (u_quad_t) ip->i_size;
237 vap->va_type = vp->v_type;
238 return (0);
239 }
240
241 /*
242 * Vnode op for reading.
243 */
244 int
245 cd9660_read(v)
246 void *v;
247 {
248 struct vop_read_args /* {
249 struct vnode *a_vp;
250 struct uio *a_uio;
251 int a_ioflag;
252 struct ucred *a_cred;
253 } */ *ap = v;
254 struct vnode *vp = ap->a_vp;
255 struct uio *uio = ap->a_uio;
256 struct iso_node *ip = VTOI(vp);
257 struct iso_mnt *imp;
258 struct buf *bp;
259 daddr_t lbn, rablock;
260 off_t diff;
261 int rasize, error = 0;
262 long size, n, on;
263
264 if (uio->uio_resid == 0)
265 return (0);
266 if (uio->uio_offset < 0)
267 return (EINVAL);
268 if (uio->uio_offset >= ip->i_size)
269 return 0;
270 ip->i_flag |= IN_ACCESS;
271 imp = ip->i_mnt;
272
273 if (vp->v_type == VREG) {
274 const int advice = IO_ADV_DECODE(ap->a_ioflag);
275 error = 0;
276
277 while (uio->uio_resid > 0) {
278 void *win;
279 int flags;
280 vsize_t bytelen = MIN(ip->i_size - uio->uio_offset,
281 uio->uio_resid);
282
283 if (bytelen == 0)
284 break;
285 win = ubc_alloc(&vp->v_uobj, uio->uio_offset,
286 &bytelen, UBC_READ);
287 uvm_ra_request(&vp->v_ractx, advice, &vp->v_uobj,
288 uio->uio_offset, bytelen);
289 error = uiomove(win, bytelen, uio);
290 flags = UBC_WANT_UNMAP(vp) ? UBC_UNMAP : 0;
291 ubc_release(win, flags);
292 if (error)
293 break;
294 }
295 goto out;
296 }
297
298 do {
299 lbn = lblkno(imp, uio->uio_offset);
300 on = blkoff(imp, uio->uio_offset);
301 n = MIN(imp->logical_block_size - on, uio->uio_resid);
302 diff = (off_t)ip->i_size - uio->uio_offset;
303 if (diff <= 0)
304 return (0);
305 if (diff < n)
306 n = diff;
307 size = blksize(imp, ip, lbn);
308 rablock = lbn + 1;
309 if (lblktosize(imp, rablock) < ip->i_size) {
310 rasize = blksize(imp, ip, rablock);
311 error = breadn(vp, lbn, size, &rablock,
312 &rasize, 1, NOCRED, &bp);
313 } else {
314 error = bread(vp, lbn, size, NOCRED, &bp);
315 }
316 n = MIN(n, size - bp->b_resid);
317 if (error) {
318 brelse(bp);
319 return (error);
320 }
321
322 error = uiomove(bp->b_data + on, (int)n, uio);
323 brelse(bp);
324 } while (error == 0 && uio->uio_resid > 0 && n != 0);
325
326 out:
327 return (error);
328 }
329
330 int
331 iso_uiodir(idp, dp, off)
332 struct isoreaddir *idp;
333 struct dirent *dp;
334 off_t off;
335 {
336 int error;
337
338 dp->d_name[dp->d_namlen] = 0;
339 dp->d_reclen = _DIRENT_SIZE(dp);
340
341 if (idp->uio->uio_resid < dp->d_reclen) {
342 idp->eofflag = 0;
343 return (-1);
344 }
345
346 if (idp->cookies) {
347 if (idp->ncookies <= 0) {
348 idp->eofflag = 0;
349 return (-1);
350 }
351
352 *idp->cookies++ = off;
353 --idp->ncookies;
354 }
355
356 if ((error = uiomove(dp, dp->d_reclen, idp->uio)) != 0)
357 return (error);
358 idp->uio_off = off;
359 return (0);
360 }
361
362 int
363 iso_shipdir(idp)
364 struct isoreaddir *idp;
365 {
366 struct dirent *dp;
367 int cl, sl, assoc;
368 int error;
369 char *cname, *sname;
370
371 cl = idp->current.d_namlen;
372 cname = idp->current.d_name;
373
374 if ((assoc = cl > 1 && *cname == ASSOCCHAR)) {
375 cl--;
376 cname++;
377 }
378
379 dp = &idp->saveent;
380 sname = dp->d_name;
381 if (!(sl = dp->d_namlen)) {
382 dp = &idp->assocent;
383 sname = dp->d_name + 1;
384 sl = dp->d_namlen - 1;
385 }
386 if (sl > 0) {
387 if (sl != cl
388 || memcmp(sname, cname, sl)) {
389 if (idp->assocent.d_namlen) {
390 error = iso_uiodir(idp, &idp->assocent,
391 idp->assocoff);
392 if (error)
393 return (error);
394 idp->assocent.d_namlen = 0;
395 }
396 if (idp->saveent.d_namlen) {
397 error = iso_uiodir(idp, &idp->saveent,
398 idp->saveoff);
399 if (error)
400 return (error);
401 idp->saveent.d_namlen = 0;
402 }
403 }
404 }
405 idp->current.d_reclen = _DIRENT_SIZE(&idp->current);
406 if (assoc) {
407 idp->assocoff = idp->curroff;
408 memcpy(&idp->assocent, &idp->current, idp->current.d_reclen);
409 } else {
410 idp->saveoff = idp->curroff;
411 memcpy(&idp->saveent, &idp->current, idp->current.d_reclen);
412 }
413 return (0);
414 }
415
416 /*
417 * Vnode op for readdir
418 */
419 int
420 cd9660_readdir(v)
421 void *v;
422 {
423 struct vop_readdir_args /* {
424 struct vnode *a_vp;
425 struct uio *a_uio;
426 struct ucred *a_cred;
427 int *a_eofflag;
428 off_t **a_cookies;
429 int *a_ncookies;
430 } */ *ap = v;
431 struct uio *uio = ap->a_uio;
432 struct isoreaddir *idp;
433 struct vnode *vdp = ap->a_vp;
434 struct iso_node *dp;
435 struct iso_mnt *imp;
436 struct buf *bp = NULL;
437 struct iso_directory_record *ep;
438 int entryoffsetinblock;
439 doff_t endsearch;
440 u_long bmask;
441 int error = 0;
442 int reclen;
443 u_short namelen;
444 off_t *cookies = NULL;
445 int ncookies = 0;
446
447 if (vdp->v_type != VDIR)
448 return (ENOTDIR);
449
450 dp = VTOI(vdp);
451 imp = dp->i_mnt;
452 bmask = imp->im_bmask;
453
454 MALLOC(idp, struct isoreaddir *, sizeof(*idp), M_TEMP, M_WAITOK);
455 idp->saveent.d_namlen = idp->assocent.d_namlen = 0;
456 /*
457 * XXX
458 * Is it worth trying to figure out the type?
459 */
460 idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type =
461 DT_UNKNOWN;
462 idp->uio = uio;
463 if (ap->a_ncookies == NULL)
464 idp->cookies = NULL;
465 else {
466 ncookies = uio->uio_resid / 16;
467 cookies = malloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK);
468 idp->cookies = cookies;
469 idp->ncookies = ncookies;
470 }
471 idp->eofflag = 1;
472 idp->curroff = uio->uio_offset;
473
474 if ((entryoffsetinblock = idp->curroff & bmask) &&
475 (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) {
476 FREE(idp, M_TEMP);
477 return (error);
478 }
479 endsearch = dp->i_size;
480
481 while (idp->curroff < endsearch) {
482 /*
483 * If offset is on a block boundary,
484 * read the next directory block.
485 * Release previous if it exists.
486 */
487 if ((idp->curroff & bmask) == 0) {
488 if (bp != NULL)
489 brelse(bp);
490 error = cd9660_blkatoff(vdp, (off_t)idp->curroff,
491 NULL, &bp);
492 if (error)
493 break;
494 entryoffsetinblock = 0;
495 }
496 /*
497 * Get pointer to next entry.
498 */
499 ep = (struct iso_directory_record *)
500 ((char *)bp->b_data + entryoffsetinblock);
501
502 reclen = isonum_711(ep->length);
503 if (reclen == 0) {
504 /* skip to next block, if any */
505 idp->curroff =
506 (idp->curroff & ~bmask) + imp->logical_block_size;
507 continue;
508 }
509
510 if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
511 error = EINVAL;
512 /* illegal entry, stop */
513 break;
514 }
515
516 if (entryoffsetinblock + reclen > imp->logical_block_size) {
517 error = EINVAL;
518 /* illegal directory, so stop looking */
519 break;
520 }
521
522 idp->current.d_namlen = isonum_711(ep->name_len);
523
524 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) {
525 error = EINVAL;
526 /* illegal entry, stop */
527 break;
528 }
529
530 if (isonum_711(ep->flags)&2)
531 idp->current.d_fileno = isodirino(ep, imp);
532 else
533 idp->current.d_fileno = dbtob(bp->b_blkno) +
534 entryoffsetinblock;
535
536 idp->curroff += reclen;
537
538 switch (imp->iso_ftype) {
539 case ISO_FTYPE_RRIP:
540 cd9660_rrip_getname(ep, idp->current.d_name, &namelen,
541 &idp->current.d_fileno, imp);
542 idp->current.d_namlen = (u_char)namelen;
543 if (idp->current.d_namlen)
544 error = iso_uiodir(idp, &idp->current,
545 idp->curroff);
546 break;
547 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 */
548 isofntrans(ep->name, idp->current.d_namlen,
549 idp->current.d_name, &namelen,
550 imp->iso_ftype == ISO_FTYPE_9660,
551 (imp->im_flags & ISOFSMNT_NOCASETRANS) == 0,
552 isonum_711(ep->flags)&4,
553 imp->im_joliet_level);
554 switch (idp->current.d_name[0]) {
555 case 0:
556 idp->current.d_name[0] = '.';
557 idp->current.d_namlen = 1;
558 error = iso_uiodir(idp, &idp->current,
559 idp->curroff);
560 break;
561 case 1:
562 strlcpy(idp->current.d_name, "..",
563 sizeof(idp->current.d_name));
564 idp->current.d_namlen = 2;
565 error = iso_uiodir(idp, &idp->current,
566 idp->curroff);
567 break;
568 default:
569 idp->current.d_namlen = (u_char)namelen;
570 if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
571 error = iso_shipdir(idp);
572 else
573 error = iso_uiodir(idp, &idp->current,
574 idp->curroff);
575 break;
576 }
577 }
578 if (error)
579 break;
580
581 entryoffsetinblock += reclen;
582 }
583
584 if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
585 idp->current.d_namlen = 0;
586 error = iso_shipdir(idp);
587 }
588 if (error < 0)
589 error = 0;
590
591 if (ap->a_ncookies != NULL) {
592 if (error)
593 free(cookies, M_TEMP);
594 else {
595 /*
596 * Work out the number of cookies actually used.
597 */
598 *ap->a_ncookies = ncookies - idp->ncookies;
599 *ap->a_cookies = cookies;
600 }
601 }
602
603 if (bp)
604 brelse (bp);
605
606 uio->uio_offset = idp->uio_off;
607 *ap->a_eofflag = idp->eofflag;
608
609 FREE(idp, M_TEMP);
610
611 return (error);
612 }
613
614 /*
615 * Return target name of a symbolic link
616 * Shouldn't we get the parent vnode and read the data from there?
617 * This could eventually result in deadlocks in cd9660_lookup.
618 * But otherwise the block read here is in the block buffer two times.
619 */
620 typedef struct iso_directory_record ISODIR;
621 typedef struct iso_node ISONODE;
622 typedef struct iso_mnt ISOMNT;
623 int
624 cd9660_readlink(v)
625 void *v;
626 {
627 struct vop_readlink_args /* {
628 struct vnode *a_vp;
629 struct uio *a_uio;
630 struct ucred *a_cred;
631 } */ *ap = v;
632 ISONODE *ip;
633 ISODIR *dirp;
634 ISOMNT *imp;
635 struct buf *bp;
636 struct uio *uio;
637 u_short symlen;
638 int error;
639 char *symname;
640
641 ip = VTOI(ap->a_vp);
642 imp = ip->i_mnt;
643 uio = ap->a_uio;
644
645 if (imp->iso_ftype != ISO_FTYPE_RRIP)
646 return (EINVAL);
647
648 /*
649 * Get parents directory record block that this inode included.
650 */
651 error = bread(imp->im_devvp,
652 (ip->i_number >> imp->im_bshift) <<
653 (imp->im_bshift - DEV_BSHIFT),
654 imp->logical_block_size, NOCRED, &bp);
655 if (error) {
656 brelse(bp);
657 return (EINVAL);
658 }
659
660 /*
661 * Setup the directory pointer for this inode
662 */
663 dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask));
664
665 /*
666 * Just make sure, we have a right one....
667 * 1: Check not cross boundary on block
668 */
669 if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
670 > imp->logical_block_size) {
671 brelse(bp);
672 return (EINVAL);
673 }
674
675 /*
676 * Now get a buffer
677 * Abuse a namei buffer for now.
678 */
679 if (uio->uio_segflg == UIO_SYSSPACE &&
680 uio->uio_iov->iov_len >= MAXPATHLEN)
681 symname = uio->uio_iov->iov_base;
682 else
683 symname = PNBUF_GET();
684
685 /*
686 * Ok, we just gathering a symbolic name in SL record.
687 */
688 if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
689 if (uio->uio_segflg != UIO_SYSSPACE ||
690 uio->uio_iov->iov_len < MAXPATHLEN)
691 PNBUF_PUT(symname);
692 brelse(bp);
693 return (EINVAL);
694 }
695 /*
696 * Don't forget before you leave from home ;-)
697 */
698 brelse(bp);
699
700 /*
701 * return with the symbolic name to caller's.
702 */
703 if (uio->uio_segflg != UIO_SYSSPACE ||
704 uio->uio_iov->iov_len < MAXPATHLEN) {
705 error = uiomove(symname, symlen, uio);
706 PNBUF_PUT(symname);
707 return (error);
708 }
709 uio->uio_resid -= symlen;
710 uio->uio_iov->iov_base = (char *)uio->uio_iov->iov_base + symlen;
711 uio->uio_iov->iov_len -= symlen;
712 return (0);
713 }
714
715 int
716 cd9660_link(v)
717 void *v;
718 {
719 struct vop_link_args /* {
720 struct vnode *a_dvp;
721 struct vnode *a_vp;
722 struct componentname *a_cnp;
723 } */ *ap = v;
724
725 VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
726 vput(ap->a_dvp);
727 return (EROFS);
728 }
729
730 int
731 cd9660_symlink(v)
732 void *v;
733 {
734 struct vop_symlink_args /* {
735 struct vnode *a_dvp;
736 struct vnode **a_vpp;
737 struct componentname *a_cnp;
738 struct vattr *a_vap;
739 char *a_target;
740 } */ *ap = v;
741
742 VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
743 vput(ap->a_dvp);
744 return (EROFS);
745 }
746
747 /*
748 * Calculate the logical to physical mapping if not done already,
749 * then call the device strategy routine.
750 */
751 int
752 cd9660_strategy(v)
753 void *v;
754 {
755 struct vop_strategy_args /* {
756 struct vnode *a_vp;
757 struct buf *a_bp;
758 } */ *ap = v;
759 struct buf *bp = ap->a_bp;
760 struct vnode *vp = ap->a_vp;
761 struct iso_node *ip;
762 int error;
763
764 ip = VTOI(vp);
765 if (vp->v_type == VBLK || vp->v_type == VCHR)
766 panic("cd9660_strategy: spec");
767 if (bp->b_blkno == bp->b_lblkno) {
768 error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL);
769 if (error) {
770 bp->b_error = error;
771 bp->b_flags |= B_ERROR;
772 biodone(bp);
773 return (error);
774 }
775 if ((long)bp->b_blkno == -1)
776 clrbuf(bp);
777 }
778 if ((long)bp->b_blkno == -1) {
779 biodone(bp);
780 return (0);
781 }
782 vp = ip->i_devvp;
783 return (VOP_STRATEGY(vp, bp));
784 }
785
786 /*
787 * Print out the contents of an inode.
788 */
789 /*ARGSUSED*/
790 int
791 cd9660_print(v)
792 void *v;
793 {
794
795 printf("tag VT_ISOFS, isofs vnode\n");
796 return (0);
797 }
798
799 /*
800 * Return POSIX pathconf information applicable to cd9660 filesystems.
801 */
802 int
803 cd9660_pathconf(v)
804 void *v;
805 {
806 struct vop_pathconf_args /* {
807 struct vnode *a_vp;
808 int a_name;
809 register_t *a_retval;
810 } */ *ap = v;
811 switch (ap->a_name) {
812 case _PC_LINK_MAX:
813 *ap->a_retval = 1;
814 return (0);
815 case _PC_NAME_MAX:
816 if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP)
817 *ap->a_retval = NAME_MAX;
818 else
819 *ap->a_retval = 37;
820 return (0);
821 case _PC_PATH_MAX:
822 *ap->a_retval = PATH_MAX;
823 return (0);
824 case _PC_PIPE_BUF:
825 *ap->a_retval = PIPE_BUF;
826 return (0);
827 case _PC_CHOWN_RESTRICTED:
828 *ap->a_retval = 1;
829 return (0);
830 case _PC_NO_TRUNC:
831 *ap->a_retval = 1;
832 return (0);
833 case _PC_SYNC_IO:
834 *ap->a_retval = 1;
835 return (0);
836 case _PC_FILESIZEBITS:
837 *ap->a_retval = 32;
838 return (0);
839 default:
840 return (EINVAL);
841 }
842 /* NOTREACHED */
843 }
844
845 /*
846 * Allow changing the size for special files (and fifos).
847 */
848 int
849 cd9660_setattr(v)
850 void *v;
851 {
852 struct vop_setattr_args /* {
853 struct vnodeop_desc *a_desc;
854 struct vnode *a_vp;
855 struct vattr *a_vap;
856 struct ucred *a_cred;
857 struct proc *a_p;
858 } */ *ap = v;
859 struct vattr *vap = ap->a_vap;
860 struct vnode *vp = ap->a_vp;
861
862 /*
863 * Only size is changeable.
864 */
865 if (vap->va_type != VNON
866 || vap->va_nlink != (nlink_t)VNOVAL
867 || vap->va_fsid != VNOVAL
868 || vap->va_fileid != VNOVAL
869 || vap->va_blocksize != VNOVAL
870 || vap->va_rdev != (dev_t)VNOVAL
871 || (int)vap->va_bytes != VNOVAL
872 || vap->va_gen != VNOVAL
873 || vap->va_flags != VNOVAL
874 || vap->va_uid != (uid_t)VNOVAL
875 || vap->va_gid != (gid_t)VNOVAL
876 || vap->va_atime.tv_sec != VNOVAL
877 || vap->va_mtime.tv_sec != VNOVAL
878 || vap->va_mode != (mode_t)VNOVAL)
879 return EOPNOTSUPP;
880
881 if (vap->va_size != VNOVAL
882 && vp->v_type != VCHR
883 && vp->v_type != VBLK
884 && vp->v_type != VFIFO)
885 return EOPNOTSUPP;
886
887 return 0;
888 }
889
890 /*
891 * Global vfs data structures for isofs
892 */
893 #define cd9660_create genfs_eopnotsupp
894 #define cd9660_mknod genfs_eopnotsupp
895 #define cd9660_write genfs_eopnotsupp
896 #define cd9660_lease_check genfs_lease_check
897 #define cd9660_fsync genfs_nullop
898 #define cd9660_remove genfs_eopnotsupp
899 #define cd9660_rename genfs_eopnotsupp
900 #define cd9660_mkdir genfs_eopnotsupp
901 #define cd9660_rmdir genfs_eopnotsupp
902 #define cd9660_advlock genfs_einval
903 #define cd9660_bwrite genfs_eopnotsupp
904 #define cd9660_revoke genfs_revoke
905
906 /*
907 * Global vfs data structures for cd9660
908 */
909 int (**cd9660_vnodeop_p)(void *);
910 const struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
911 { &vop_default_desc, vn_default_error },
912 { &vop_lookup_desc, cd9660_lookup }, /* lookup */
913 { &vop_create_desc, cd9660_create }, /* create */
914 { &vop_mknod_desc, cd9660_mknod }, /* mknod */
915 { &vop_open_desc, cd9660_open }, /* open */
916 { &vop_close_desc, cd9660_close }, /* close */
917 { &vop_access_desc, cd9660_access }, /* access */
918 { &vop_getattr_desc, cd9660_getattr }, /* getattr */
919 { &vop_setattr_desc, cd9660_setattr }, /* setattr */
920 { &vop_read_desc, cd9660_read }, /* read */
921 { &vop_write_desc, cd9660_write }, /* write */
922 { &vop_lease_desc, cd9660_lease_check }, /* lease */
923 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */
924 { &vop_ioctl_desc, cd9660_ioctl }, /* ioctl */
925 { &vop_poll_desc, cd9660_poll }, /* poll */
926 { &vop_revoke_desc, cd9660_revoke }, /* revoke */
927 { &vop_mmap_desc, cd9660_mmap }, /* mmap */
928 { &vop_fsync_desc, cd9660_fsync }, /* fsync */
929 { &vop_seek_desc, cd9660_seek }, /* seek */
930 { &vop_remove_desc, cd9660_remove }, /* remove */
931 { &vop_link_desc, cd9660_link }, /* link */
932 { &vop_rename_desc, cd9660_rename }, /* rename */
933 { &vop_mkdir_desc, cd9660_mkdir }, /* mkdir */
934 { &vop_rmdir_desc, cd9660_rmdir }, /* rmdir */
935 { &vop_symlink_desc, cd9660_symlink }, /* symlink */
936 { &vop_readdir_desc, cd9660_readdir }, /* readdir */
937 { &vop_readlink_desc, cd9660_readlink }, /* readlink */
938 { &vop_abortop_desc, cd9660_abortop }, /* abortop */
939 { &vop_inactive_desc, cd9660_inactive }, /* inactive */
940 { &vop_reclaim_desc, cd9660_reclaim }, /* reclaim */
941 { &vop_lock_desc, genfs_lock }, /* lock */
942 { &vop_unlock_desc, genfs_unlock }, /* unlock */
943 { &vop_bmap_desc, cd9660_bmap }, /* bmap */
944 { &vop_strategy_desc, cd9660_strategy }, /* strategy */
945 { &vop_print_desc, cd9660_print }, /* print */
946 { &vop_islocked_desc, genfs_islocked }, /* islocked */
947 { &vop_pathconf_desc, cd9660_pathconf }, /* pathconf */
948 { &vop_advlock_desc, cd9660_advlock }, /* advlock */
949 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
950 { &vop_getpages_desc, genfs_getpages }, /* getpages */
951 { &vop_putpages_desc, genfs_putpages }, /* putpages */
952 { NULL, NULL }
953 };
954 const struct vnodeopv_desc cd9660_vnodeop_opv_desc =
955 { &cd9660_vnodeop_p, cd9660_vnodeop_entries };
956
957 /*
958 * Special device vnode ops
959 */
960 int (**cd9660_specop_p)(void *);
961 const struct vnodeopv_entry_desc cd9660_specop_entries[] = {
962 { &vop_default_desc, vn_default_error },
963 { &vop_lookup_desc, spec_lookup }, /* lookup */
964 { &vop_create_desc, spec_create }, /* create */
965 { &vop_mknod_desc, spec_mknod }, /* mknod */
966 { &vop_open_desc, spec_open }, /* open */
967 { &vop_close_desc, spec_close }, /* close */
968 { &vop_access_desc, cd9660_access }, /* access */
969 { &vop_getattr_desc, cd9660_getattr }, /* getattr */
970 { &vop_setattr_desc, cd9660_setattr }, /* setattr */
971 { &vop_read_desc, spec_read }, /* read */
972 { &vop_write_desc, spec_write }, /* write */
973 { &vop_lease_desc, spec_lease_check }, /* lease */
974 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */
975 { &vop_ioctl_desc, spec_ioctl }, /* ioctl */
976 { &vop_poll_desc, spec_poll }, /* poll */
977 { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */
978 { &vop_revoke_desc, spec_revoke }, /* revoke */
979 { &vop_mmap_desc, spec_mmap }, /* mmap */
980 { &vop_fsync_desc, spec_fsync }, /* fsync */
981 { &vop_seek_desc, spec_seek }, /* seek */
982 { &vop_remove_desc, spec_remove }, /* remove */
983 { &vop_link_desc, spec_link }, /* link */
984 { &vop_rename_desc, spec_rename }, /* rename */
985 { &vop_mkdir_desc, spec_mkdir }, /* mkdir */
986 { &vop_rmdir_desc, spec_rmdir }, /* rmdir */
987 { &vop_symlink_desc, spec_symlink }, /* symlink */
988 { &vop_readdir_desc, spec_readdir }, /* readdir */
989 { &vop_readlink_desc, spec_readlink }, /* readlink */
990 { &vop_abortop_desc, spec_abortop }, /* abortop */
991 { &vop_inactive_desc, cd9660_inactive }, /* inactive */
992 { &vop_reclaim_desc, cd9660_reclaim }, /* reclaim */
993 { &vop_lock_desc, genfs_lock }, /* lock */
994 { &vop_unlock_desc, genfs_unlock }, /* unlock */
995 { &vop_bmap_desc, spec_bmap }, /* bmap */
996 { &vop_strategy_desc, spec_strategy }, /* strategy */
997 { &vop_print_desc, cd9660_print }, /* print */
998 { &vop_islocked_desc, genfs_islocked }, /* islocked */
999 { &vop_pathconf_desc, spec_pathconf }, /* pathconf */
1000 { &vop_advlock_desc, spec_advlock }, /* advlock */
1001 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
1002 { &vop_getpages_desc, spec_getpages }, /* getpages */
1003 { &vop_putpages_desc, spec_putpages }, /* putpages */
1004 { NULL, NULL }
1005 };
1006 const struct vnodeopv_desc cd9660_specop_opv_desc =
1007 { &cd9660_specop_p, cd9660_specop_entries };
1008
1009 int (**cd9660_fifoop_p)(void *);
1010 const struct vnodeopv_entry_desc cd9660_fifoop_entries[] = {
1011 { &vop_default_desc, vn_default_error },
1012 { &vop_lookup_desc, fifo_lookup }, /* lookup */
1013 { &vop_create_desc, fifo_create }, /* create */
1014 { &vop_mknod_desc, fifo_mknod }, /* mknod */
1015 { &vop_open_desc, fifo_open }, /* open */
1016 { &vop_close_desc, fifo_close }, /* close */
1017 { &vop_access_desc, cd9660_access }, /* access */
1018 { &vop_getattr_desc, cd9660_getattr }, /* getattr */
1019 { &vop_setattr_desc, cd9660_setattr }, /* setattr */
1020 { &vop_read_desc, fifo_read }, /* read */
1021 { &vop_write_desc, fifo_write }, /* write */
1022 { &vop_lease_desc, fifo_lease_check }, /* lease */
1023 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */
1024 { &vop_ioctl_desc, fifo_ioctl }, /* ioctl */
1025 { &vop_poll_desc, fifo_poll }, /* poll */
1026 { &vop_kqfilter_desc, fifo_kqfilter }, /* kqfilter */
1027 { &vop_revoke_desc, fifo_revoke }, /* revoke */
1028 { &vop_mmap_desc, fifo_mmap }, /* mmap */
1029 { &vop_fsync_desc, fifo_fsync }, /* fsync */
1030 { &vop_seek_desc, fifo_seek }, /* seek */
1031 { &vop_remove_desc, fifo_remove }, /* remove */
1032 { &vop_link_desc, fifo_link } , /* link */
1033 { &vop_rename_desc, fifo_rename }, /* rename */
1034 { &vop_mkdir_desc, fifo_mkdir }, /* mkdir */
1035 { &vop_rmdir_desc, fifo_rmdir }, /* rmdir */
1036 { &vop_symlink_desc, fifo_symlink }, /* symlink */
1037 { &vop_readdir_desc, fifo_readdir }, /* readdir */
1038 { &vop_readlink_desc, fifo_readlink }, /* readlink */
1039 { &vop_abortop_desc, fifo_abortop }, /* abortop */
1040 { &vop_inactive_desc, cd9660_inactive }, /* inactive */
1041 { &vop_reclaim_desc, cd9660_reclaim }, /* reclaim */
1042 { &vop_lock_desc, genfs_lock }, /* lock */
1043 { &vop_unlock_desc, genfs_unlock }, /* unlock */
1044 { &vop_bmap_desc, fifo_bmap }, /* bmap */
1045 { &vop_strategy_desc, fifo_strategy }, /* strategy */
1046 { &vop_print_desc, cd9660_print }, /* print */
1047 { &vop_islocked_desc, genfs_islocked }, /* islocked */
1048 { &vop_pathconf_desc, fifo_pathconf }, /* pathconf */
1049 { &vop_advlock_desc, fifo_advlock }, /* advlock */
1050 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
1051 { &vop_putpages_desc, fifo_putpages }, /* putpages */
1052 { NULL, NULL }
1053 };
1054 const struct vnodeopv_desc cd9660_fifoop_opv_desc =
1055 { &cd9660_fifoop_p, cd9660_fifoop_entries };
1056