proc->thread stage 4: rework the VFS and DEVICE subsystems to take thread
[dragonfly.git] / sys / vfs / isofs / cd9660 / cd9660_vnops.c
CommitLineData
984263bc
MD
1/*-
2 * Copyright (c) 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley
6 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
7 * Support code is derived from software contributed to Berkeley
8 * by Atsushi Murai (amurai@spec.co.jp).
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)cd9660_vnops.c 8.19 (Berkeley) 5/27/95
39 * $FreeBSD: src/sys/isofs/cd9660/cd9660_vnops.c,v 1.62 1999/12/15 23:01:51 eivind Exp $
dadab5e9 40 * $DragonFly: src/sys/vfs/isofs/cd9660/cd9660_vnops.c,v 1.3 2003/06/25 03:55:56 dillon Exp $
984263bc
MD
41 */
42
43#include <sys/param.h>
44#include <sys/systm.h>
dadab5e9 45#include <sys/proc.h>
984263bc
MD
46#include <sys/namei.h>
47#include <sys/kernel.h>
48#include <sys/stat.h>
49#include <sys/buf.h>
50#include <sys/mount.h>
51#include <sys/vnode.h>
52#include <miscfs/fifofs/fifo.h>
53#include <sys/malloc.h>
54#include <sys/dirent.h>
55#include <sys/unistd.h>
56#include <sys/filio.h>
57
58#include <vm/vm.h>
59#include <vm/vm_zone.h>
60#include <vm/vnode_pager.h>
61
62#include <isofs/cd9660/iso.h>
63#include <isofs/cd9660/cd9660_node.h>
64#include <isofs/cd9660/iso_rrip.h>
65
66static int cd9660_setattr __P((struct vop_setattr_args *));
67static int cd9660_access __P((struct vop_access_args *));
68static int cd9660_getattr __P((struct vop_getattr_args *));
69static int cd9660_ioctl __P((struct vop_ioctl_args *));
70static int cd9660_pathconf __P((struct vop_pathconf_args *));
71static int cd9660_read __P((struct vop_read_args *));
72struct isoreaddir;
73static int iso_uiodir __P((struct isoreaddir *idp, struct dirent *dp,
74 off_t off));
75static int iso_shipdir __P((struct isoreaddir *idp));
76static int cd9660_readdir __P((struct vop_readdir_args *));
77static int cd9660_readlink __P((struct vop_readlink_args *ap));
78static int cd9660_strategy __P((struct vop_strategy_args *));
79static int cd9660_print __P((struct vop_print_args *));
80static int cd9660_getpages __P((struct vop_getpages_args *));
81static int cd9660_putpages __P((struct vop_putpages_args *));
82
83/*
84 * Setattr call. Only allowed for block and character special devices.
85 */
86int
87cd9660_setattr(ap)
88 struct vop_setattr_args /* {
89 struct vnodeop_desc *a_desc;
90 struct vnode *a_vp;
91 struct vattr *a_vap;
92 struct ucred *a_cred;
93 struct proc *a_p;
94 } */ *ap;
95{
96 struct vnode *vp = ap->a_vp;
97 struct vattr *vap = ap->a_vap;
98
99 if (vap->va_flags != (u_long)VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
100 vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
101 vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL)
102 return (EROFS);
103 if (vap->va_size != (u_quad_t)VNOVAL) {
104 switch (vp->v_type) {
105 case VDIR:
106 return (EISDIR);
107 case VLNK:
108 case VREG:
109 return (EROFS);
110 case VCHR:
111 case VBLK:
112 case VSOCK:
113 case VFIFO:
114 case VNON:
115 case VBAD:
116 return (0);
117 }
118 }
119 return (0);
120}
121
122/*
123 * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC.
124 * The mode is shifted to select the owner/group/other fields. The
125 * super user is granted all permissions.
126 */
127/* ARGSUSED */
128static int
129cd9660_access(ap)
130 struct vop_access_args /* {
131 struct vnode *a_vp;
132 int a_mode;
133 struct ucred *a_cred;
134 struct proc *a_p;
135 } */ *ap;
136{
137 struct vnode *vp = ap->a_vp;
138 struct iso_node *ip = VTOI(vp);
139 struct ucred *cred = ap->a_cred;
140 mode_t mask, mode = ap->a_mode;
141 gid_t *gp;
142 int i;
143
144 /*
145 * Disallow write attempts unless the file is a socket,
146 * fifo, or a block or character device resident on the
147 * file system.
148 */
149 if (mode & VWRITE) {
150 switch (vp->v_type) {
151 case VDIR:
152 case VLNK:
153 case VREG:
154 return (EROFS);
155 /* NOT REACHED */
156 default:
157 break;
158 }
159 }
160
161 /* User id 0 always gets access. */
162 if (cred->cr_uid == 0)
163 return (0);
164
165 mask = 0;
166
167 /* Otherwise, check the owner. */
168 if (cred->cr_uid == ip->inode.iso_uid) {
169 if (mode & VEXEC)
170 mask |= S_IXUSR;
171 if (mode & VREAD)
172 mask |= S_IRUSR;
173 if (mode & VWRITE)
174 mask |= S_IWUSR;
175 return ((ip->inode.iso_mode & mask) == mask ? 0 : EACCES);
176 }
177
178 /* Otherwise, check the groups. */
179 for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++)
180 if (ip->inode.iso_gid == *gp) {
181 if (mode & VEXEC)
182 mask |= S_IXGRP;
183 if (mode & VREAD)
184 mask |= S_IRGRP;
185 if (mode & VWRITE)
186 mask |= S_IWGRP;
187 return ((ip->inode.iso_mode & mask) == mask ?
188 0 : EACCES);
189 }
190
191 /* Otherwise, check everyone else. */
192 if (mode & VEXEC)
193 mask |= S_IXOTH;
194 if (mode & VREAD)
195 mask |= S_IROTH;
196 if (mode & VWRITE)
197 mask |= S_IWOTH;
198 return ((ip->inode.iso_mode & mask) == mask ? 0 : EACCES);
199}
200
201static int
202cd9660_getattr(ap)
203 struct vop_getattr_args /* {
204 struct vnode *a_vp;
205 struct vattr *a_vap;
206 struct ucred *a_cred;
dadab5e9 207 struct thread *a_td;
984263bc
MD
208 } */ *ap;
209
210{
211 struct vnode *vp = ap->a_vp;
212 register struct vattr *vap = ap->a_vap;
213 register struct iso_node *ip = VTOI(vp);
214
215 vap->va_fsid = dev2udev(ip->i_dev);
216 vap->va_fileid = ip->i_number;
217
218 vap->va_mode = ip->inode.iso_mode;
219 vap->va_nlink = ip->inode.iso_links;
220 vap->va_uid = ip->inode.iso_uid;
221 vap->va_gid = ip->inode.iso_gid;
222 vap->va_atime = ip->inode.iso_atime;
223 vap->va_mtime = ip->inode.iso_mtime;
224 vap->va_ctime = ip->inode.iso_ctime;
225 vap->va_rdev = ip->inode.iso_rdev;
226
227 vap->va_size = (u_quad_t) ip->i_size;
228 if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) {
229 struct vop_readlink_args rdlnk;
230 struct iovec aiov;
231 struct uio auio;
232 char *cp;
233
234 MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
235 aiov.iov_base = cp;
236 aiov.iov_len = MAXPATHLEN;
237 auio.uio_iov = &aiov;
238 auio.uio_iovcnt = 1;
239 auio.uio_offset = 0;
240 auio.uio_rw = UIO_READ;
241 auio.uio_segflg = UIO_SYSSPACE;
dadab5e9 242 auio.uio_td = ap->a_td;
984263bc
MD
243 auio.uio_resid = MAXPATHLEN;
244 rdlnk.a_uio = &auio;
245 rdlnk.a_vp = ap->a_vp;
246 rdlnk.a_cred = ap->a_cred;
247 if (cd9660_readlink(&rdlnk) == 0)
248 vap->va_size = MAXPATHLEN - auio.uio_resid;
249 FREE(cp, M_TEMP);
250 }
251 vap->va_flags = 0;
252 vap->va_gen = 1;
253 vap->va_blocksize = ip->i_mnt->logical_block_size;
254 vap->va_bytes = (u_quad_t) ip->i_size;
255 vap->va_type = vp->v_type;
256 vap->va_filerev = 0;
257 return (0);
258}
259
260/*
261 * Vnode op for ioctl.
262 */
263static int
264cd9660_ioctl(ap)
265 struct vop_ioctl_args /* {
266 struct vnode *a_vp;
267 int a_command;
268 caddr_t a_data;
269 int a_fflag;
270 struct ucred *a_cred;
271 struct proc *a_p;
272 } */ *ap;
273{
274 struct vnode *vp = ap->a_vp;
275 struct iso_node *ip = VTOI(vp);
276
277 switch (ap->a_command) {
278
279 case FIOGETLBA:
280 *(int *)(ap->a_data) = ip->iso_start;
281 return 0;
282 default:
283 return (ENOTTY);
284 }
285}
286
287/*
288 * Vnode op for reading.
289 */
290static int
291cd9660_read(ap)
292 struct vop_read_args /* {
293 struct vnode *a_vp;
294 struct uio *a_uio;
295 int a_ioflag;
296 struct ucred *a_cred;
297 } */ *ap;
298{
299 struct vnode *vp = ap->a_vp;
300 register struct uio *uio = ap->a_uio;
301 register struct iso_node *ip = VTOI(vp);
302 register struct iso_mnt *imp;
303 struct buf *bp;
304 daddr_t lbn, rablock;
305 off_t diff;
306 int rasize, error = 0;
307 int seqcount;
308 long size, n, on;
309
310 seqcount = ap->a_ioflag >> 16;
311
312 if (uio->uio_resid == 0)
313 return (0);
314 if (uio->uio_offset < 0)
315 return (EINVAL);
316 ip->i_flag |= IN_ACCESS;
317 imp = ip->i_mnt;
318 do {
319 lbn = lblkno(imp, uio->uio_offset);
320 on = blkoff(imp, uio->uio_offset);
321 n = min((u_int)(imp->logical_block_size - on),
322 uio->uio_resid);
323 diff = (off_t)ip->i_size - uio->uio_offset;
324 if (diff <= 0)
325 return (0);
326 if (diff < n)
327 n = diff;
328 size = blksize(imp, ip, lbn);
329 rablock = lbn + 1;
330 if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
331 if (lblktosize(imp, rablock) < ip->i_size)
332 error = cluster_read(vp, (off_t)ip->i_size,
333 lbn, size, NOCRED, uio->uio_resid,
334 (ap->a_ioflag >> 16), &bp);
335 else
336 error = bread(vp, lbn, size, NOCRED, &bp);
337 } else {
338 if (seqcount > 1 &&
339 lblktosize(imp, rablock) < ip->i_size) {
340 rasize = blksize(imp, ip, rablock);
341 error = breadn(vp, lbn, size, &rablock,
342 &rasize, 1, NOCRED, &bp);
343 } else
344 error = bread(vp, lbn, size, NOCRED, &bp);
345 }
346 n = min(n, size - bp->b_resid);
347 if (error) {
348 brelse(bp);
349 return (error);
350 }
351
352 error = uiomove(bp->b_data + on, (int)n, uio);
353 brelse(bp);
354 } while (error == 0 && uio->uio_resid > 0 && n != 0);
355 return (error);
356}
357
358/*
359 * Structure for reading directories
360 */
361struct isoreaddir {
362 struct dirent saveent;
363 struct dirent assocent;
364 struct dirent current;
365 off_t saveoff;
366 off_t assocoff;
367 off_t curroff;
368 struct uio *uio;
369 off_t uio_off;
370 int eofflag;
371 u_long *cookies;
372 int ncookies;
373};
374
375int
376iso_uiodir(idp,dp,off)
377 struct isoreaddir *idp;
378 struct dirent *dp;
379 off_t off;
380{
381 int error;
382
383 dp->d_name[dp->d_namlen] = 0;
384 dp->d_reclen = GENERIC_DIRSIZ(dp);
385
386 if (idp->uio->uio_resid < dp->d_reclen) {
387 idp->eofflag = 0;
388 return (-1);
389 }
390
391 if (idp->cookies) {
392 if (idp->ncookies <= 0) {
393 idp->eofflag = 0;
394 return (-1);
395 }
396
397 *idp->cookies++ = off;
398 --idp->ncookies;
399 }
400
401 if ((error = uiomove((caddr_t) dp,dp->d_reclen,idp->uio)) != 0)
402 return (error);
403 idp->uio_off = off;
404 return (0);
405}
406
407int
408iso_shipdir(idp)
409 struct isoreaddir *idp;
410{
411 struct dirent *dp;
412 int cl, sl, assoc;
413 int error;
414 char *cname, *sname;
415
416 cl = idp->current.d_namlen;
417 cname = idp->current.d_name;
418assoc = (cl > 1) && (*cname == ASSOCCHAR);
419 if (assoc) {
420 cl--;
421 cname++;
422 }
423
424 dp = &idp->saveent;
425 sname = dp->d_name;
426 if (!(sl = dp->d_namlen)) {
427 dp = &idp->assocent;
428 sname = dp->d_name + 1;
429 sl = dp->d_namlen - 1;
430 }
431 if (sl > 0) {
432 if (sl != cl
433 || bcmp(sname,cname,sl)) {
434 if (idp->assocent.d_namlen) {
435 if ((error = iso_uiodir(idp,&idp->assocent,idp->assocoff)) != 0)
436 return (error);
437 idp->assocent.d_namlen = 0;
438 }
439 if (idp->saveent.d_namlen) {
440 if ((error = iso_uiodir(idp,&idp->saveent,idp->saveoff)) != 0)
441 return (error);
442 idp->saveent.d_namlen = 0;
443 }
444 }
445 }
446 idp->current.d_reclen = GENERIC_DIRSIZ(&idp->current);
447 if (assoc) {
448 idp->assocoff = idp->curroff;
449 bcopy(&idp->current,&idp->assocent,idp->current.d_reclen);
450 } else {
451 idp->saveoff = idp->curroff;
452 bcopy(&idp->current,&idp->saveent,idp->current.d_reclen);
453 }
454 return (0);
455}
456
457/*
458 * Vnode op for readdir
459 */
460static int
461cd9660_readdir(ap)
462 struct vop_readdir_args /* {
463 struct vnode *a_vp;
464 struct uio *a_uio;
465 struct ucred *a_cred;
466 int *a_eofflag;
467 int *a_ncookies;
468 u_long *a_cookies;
469 } */ *ap;
470{
471 register struct uio *uio = ap->a_uio;
472 struct isoreaddir *idp;
473 struct vnode *vdp = ap->a_vp;
474 struct iso_node *dp;
475 struct iso_mnt *imp;
476 struct buf *bp = NULL;
477 struct iso_directory_record *ep;
478 int entryoffsetinblock;
479 doff_t endsearch;
480 u_long bmask;
481 int error = 0;
482 int reclen;
483 u_short namelen;
484 int ncookies = 0;
485 u_long *cookies = NULL;
486
487 dp = VTOI(vdp);
488 imp = dp->i_mnt;
489 bmask = imp->im_bmask;
490
491 MALLOC(idp, struct isoreaddir *, sizeof(*idp), M_TEMP, M_WAITOK);
492 idp->saveent.d_namlen = idp->assocent.d_namlen = 0;
493 /*
494 * XXX
495 * Is it worth trying to figure out the type?
496 */
497 idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type =
498 DT_UNKNOWN;
499 idp->uio = uio;
500 if (ap->a_ncookies == NULL) {
501 idp->cookies = NULL;
502 } else {
503 /*
504 * Guess the number of cookies needed.
505 */
506 ncookies = uio->uio_resid / 16;
507 MALLOC(cookies, u_long *, ncookies * sizeof(u_int), M_TEMP,
508 M_WAITOK);
509 idp->cookies = cookies;
510 idp->ncookies = ncookies;
511 }
512 idp->eofflag = 1;
513 idp->curroff = uio->uio_offset;
514
515 if ((entryoffsetinblock = idp->curroff & bmask) &&
516 (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) {
517 FREE(idp, M_TEMP);
518 return (error);
519 }
520 endsearch = dp->i_size;
521
522 while (idp->curroff < endsearch) {
523 /*
524 * If offset is on a block boundary,
525 * read the next directory block.
526 * Release previous if it exists.
527 */
528 if ((idp->curroff & bmask) == 0) {
529 if (bp != NULL)
530 brelse(bp);
531 if ((error =
532 cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp)) != 0)
533 break;
534 entryoffsetinblock = 0;
535 }
536 /*
537 * Get pointer to next entry.
538 */
539 ep = (struct iso_directory_record *)
540 ((char *)bp->b_data + entryoffsetinblock);
541
542 reclen = isonum_711(ep->length);
543 if (reclen == 0) {
544 /* skip to next block, if any */
545 idp->curroff =
546 (idp->curroff & ~bmask) + imp->logical_block_size;
547 continue;
548 }
549
550 if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
551 error = EINVAL;
552 /* illegal entry, stop */
553 break;
554 }
555
556 if (entryoffsetinblock + reclen > imp->logical_block_size) {
557 error = EINVAL;
558 /* illegal directory, so stop looking */
559 break;
560 }
561
562 idp->current.d_namlen = isonum_711(ep->name_len);
563
564 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) {
565 error = EINVAL;
566 /* illegal entry, stop */
567 break;
568 }
569
570 if (isonum_711(ep->flags)&2)
571 idp->current.d_fileno = isodirino(ep, imp);
572 else
573 idp->current.d_fileno = dbtob(bp->b_blkno) +
574 entryoffsetinblock;
575
576 idp->curroff += reclen;
577
578 switch (imp->iso_ftype) {
579 case ISO_FTYPE_RRIP:
580 cd9660_rrip_getname(ep,idp->current.d_name, &namelen,
581 &idp->current.d_fileno,imp);
582 idp->current.d_namlen = (u_char)namelen;
583 if (idp->current.d_namlen)
584 error = iso_uiodir(idp,&idp->current,idp->curroff);
585 break;
586 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/
587 strcpy(idp->current.d_name,"..");
588 if (idp->current.d_namlen == 1 && ep->name[0] == 0) {
589 idp->current.d_namlen = 1;
590 error = iso_uiodir(idp,&idp->current,idp->curroff);
591 } else if (idp->current.d_namlen == 1 && ep->name[0] == 1) {
592 idp->current.d_namlen = 2;
593 error = iso_uiodir(idp,&idp->current,idp->curroff);
594 } else {
595 isofntrans(ep->name,idp->current.d_namlen,
596 idp->current.d_name, &namelen,
597 imp->iso_ftype == ISO_FTYPE_9660,
598 isonum_711(ep->flags)&4,
599 imp->joliet_level);
600 idp->current.d_namlen = (u_char)namelen;
601 if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
602 error = iso_shipdir(idp);
603 else
604 error = iso_uiodir(idp,&idp->current,idp->curroff);
605 }
606 }
607 if (error)
608 break;
609
610 entryoffsetinblock += reclen;
611 }
612
613 if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
614 idp->current.d_namlen = 0;
615 error = iso_shipdir(idp);
616 }
617 if (error < 0)
618 error = 0;
619
620 if (ap->a_ncookies != NULL) {
621 if (error)
622 free(cookies, M_TEMP);
623 else {
624 /*
625 * Work out the number of cookies actually used.
626 */
627 *ap->a_ncookies = ncookies - idp->ncookies;
628 *ap->a_cookies = cookies;
629 }
630 }
631
632 if (bp)
633 brelse (bp);
634
635 uio->uio_offset = idp->uio_off;
636 *ap->a_eofflag = idp->eofflag;
637
638 FREE(idp, M_TEMP);
639
640 return (error);
641}
642
643/*
644 * Return target name of a symbolic link
645 * Shouldn't we get the parent vnode and read the data from there?
646 * This could eventually result in deadlocks in cd9660_lookup.
647 * But otherwise the block read here is in the block buffer two times.
648 */
649typedef struct iso_directory_record ISODIR;
650typedef struct iso_node ISONODE;
651typedef struct iso_mnt ISOMNT;
652static int
653cd9660_readlink(ap)
654 struct vop_readlink_args /* {
655 struct vnode *a_vp;
656 struct uio *a_uio;
657 struct ucred *a_cred;
658 } */ *ap;
659{
660 ISONODE *ip;
661 ISODIR *dirp;
662 ISOMNT *imp;
663 struct buf *bp;
664 struct uio *uio;
665 u_short symlen;
666 int error;
667 char *symname;
668
669 ip = VTOI(ap->a_vp);
670 imp = ip->i_mnt;
671 uio = ap->a_uio;
672
673 if (imp->iso_ftype != ISO_FTYPE_RRIP)
674 return (EINVAL);
675
676 /*
677 * Get parents directory record block that this inode included.
678 */
679 error = bread(imp->im_devvp,
680 (ip->i_number >> imp->im_bshift) <<
681 (imp->im_bshift - DEV_BSHIFT),
682 imp->logical_block_size, NOCRED, &bp);
683 if (error) {
684 brelse(bp);
685 return (EINVAL);
686 }
687
688 /*
689 * Setup the directory pointer for this inode
690 */
691 dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask));
692
693 /*
694 * Just make sure, we have a right one....
695 * 1: Check not cross boundary on block
696 */
697 if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
698 > (unsigned)imp->logical_block_size) {
699 brelse(bp);
700 return (EINVAL);
701 }
702
703 /*
704 * Now get a buffer
705 * Abuse a namei buffer for now.
706 */
707 if (uio->uio_segflg == UIO_SYSSPACE)
708 symname = uio->uio_iov->iov_base;
709 else
710 symname = zalloc(namei_zone);
711
712 /*
713 * Ok, we just gathering a symbolic name in SL record.
714 */
715 if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
716 if (uio->uio_segflg != UIO_SYSSPACE)
717 zfree(namei_zone, symname);
718 brelse(bp);
719 return (EINVAL);
720 }
721 /*
722 * Don't forget before you leave from home ;-)
723 */
724 brelse(bp);
725
726 /*
727 * return with the symbolic name to caller's.
728 */
729 if (uio->uio_segflg != UIO_SYSSPACE) {
730 error = uiomove(symname, symlen, uio);
731 zfree(namei_zone, symname);
732 return (error);
733 }
734 uio->uio_resid -= symlen;
735 uio->uio_iov->iov_base += symlen;
736 uio->uio_iov->iov_len -= symlen;
737 return (0);
738}
739
740/*
741 * Calculate the logical to physical mapping if not done already,
742 * then call the device strategy routine.
743 */
744static int
745cd9660_strategy(ap)
746 struct vop_strategy_args /* {
747 struct buf *a_vp;
748 struct buf *a_bp;
749 } */ *ap;
750{
751 register struct buf *bp = ap->a_bp;
752 register struct vnode *vp = bp->b_vp;
753 register struct iso_node *ip;
754 int error;
755
756 ip = VTOI(vp);
757 if (vp->v_type == VBLK || vp->v_type == VCHR)
758 panic("cd9660_strategy: spec");
759 if (bp->b_blkno == bp->b_lblkno) {
760 if ((error =
761 VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL, NULL))) {
762 bp->b_error = error;
763 bp->b_flags |= B_ERROR;
764 biodone(bp);
765 return (error);
766 }
767 if ((long)bp->b_blkno == -1)
768 clrbuf(bp);
769 }
770 if ((long)bp->b_blkno == -1) {
771 biodone(bp);
772 return (0);
773 }
774 vp = ip->i_devvp;
775 bp->b_dev = vp->v_rdev;
776 VOP_STRATEGY(vp, bp);
777 return (0);
778}
779
780/*
781 * Print out the contents of an inode.
782 */
783static int
784cd9660_print(ap)
785 struct vop_print_args /* {
786 struct vnode *a_vp;
787 } */ *ap;
788{
789
790 printf("tag VT_ISOFS, isofs vnode\n");
791 return (0);
792}
793
794/*
795 * Return POSIX pathconf information applicable to cd9660 filesystems.
796 */
797static int
798cd9660_pathconf(ap)
799 struct vop_pathconf_args /* {
800 struct vnode *a_vp;
801 int a_name;
802 register_t *a_retval;
803 } */ *ap;
804{
805
806 switch (ap->a_name) {
807 case _PC_LINK_MAX:
808 *ap->a_retval = 1;
809 return (0);
810 case _PC_NAME_MAX:
811 if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP)
812 *ap->a_retval = NAME_MAX;
813 else
814 *ap->a_retval = 37;
815 return (0);
816 case _PC_PATH_MAX:
817 *ap->a_retval = PATH_MAX;
818 return (0);
819 case _PC_PIPE_BUF:
820 *ap->a_retval = PIPE_BUF;
821 return (0);
822 case _PC_CHOWN_RESTRICTED:
823 *ap->a_retval = 1;
824 return (0);
825 case _PC_NO_TRUNC:
826 *ap->a_retval = 1;
827 return (0);
828 default:
829 return (EINVAL);
830 }
831 /* NOTREACHED */
832}
833
834/*
835 * get page routine
836 *
837 * XXX By default, wimp out... note that a_offset is ignored (and always
838 * XXX has been).
839 */
840int
841cd9660_getpages(ap)
842 struct vop_getpages_args *ap;
843{
844 return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
845 ap->a_reqpage);
846}
847
848/*
849 * put page routine
850 *
851 * XXX By default, wimp out... note that a_offset is ignored (and always
852 * XXX has been).
853 */
854int
855cd9660_putpages(ap)
856 struct vop_putpages_args *ap;
857{
858 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
859 ap->a_sync, ap->a_rtvals);
860}
861
862/*
863 * Global vfs data structures for cd9660
864 */
865vop_t **cd9660_vnodeop_p;
866static struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
867 { &vop_default_desc, (vop_t *) vop_defaultop },
868 { &vop_access_desc, (vop_t *) cd9660_access },
869 { &vop_bmap_desc, (vop_t *) cd9660_bmap },
870 { &vop_cachedlookup_desc, (vop_t *) cd9660_lookup },
871 { &vop_getattr_desc, (vop_t *) cd9660_getattr },
872 { &vop_inactive_desc, (vop_t *) cd9660_inactive },
873 { &vop_ioctl_desc, (vop_t *) cd9660_ioctl },
874 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
875 { &vop_lock_desc, (vop_t *) vop_stdlock },
876 { &vop_lookup_desc, (vop_t *) vfs_cache_lookup },
877 { &vop_pathconf_desc, (vop_t *) cd9660_pathconf },
878 { &vop_print_desc, (vop_t *) cd9660_print },
879 { &vop_read_desc, (vop_t *) cd9660_read },
880 { &vop_readdir_desc, (vop_t *) cd9660_readdir },
881 { &vop_readlink_desc, (vop_t *) cd9660_readlink },
882 { &vop_reclaim_desc, (vop_t *) cd9660_reclaim },
883 { &vop_setattr_desc, (vop_t *) cd9660_setattr },
884 { &vop_strategy_desc, (vop_t *) cd9660_strategy },
885 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
886 { &vop_getpages_desc, (vop_t *) cd9660_getpages },
887 { &vop_putpages_desc, (vop_t *) cd9660_putpages },
888 { NULL, NULL }
889};
890static struct vnodeopv_desc cd9660_vnodeop_opv_desc =
891 { &cd9660_vnodeop_p, cd9660_vnodeop_entries };
892VNODEOP_SET(cd9660_vnodeop_opv_desc);
893
894/*
895 * Special device vnode ops
896 */
897vop_t **cd9660_specop_p;
898static struct vnodeopv_entry_desc cd9660_specop_entries[] = {
899 { &vop_default_desc, (vop_t *) spec_vnoperate },
900 { &vop_access_desc, (vop_t *) cd9660_access },
901 { &vop_getattr_desc, (vop_t *) cd9660_getattr },
902 { &vop_inactive_desc, (vop_t *) cd9660_inactive },
903 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
904 { &vop_lock_desc, (vop_t *) vop_stdlock },
905 { &vop_print_desc, (vop_t *) cd9660_print },
906 { &vop_reclaim_desc, (vop_t *) cd9660_reclaim },
907 { &vop_setattr_desc, (vop_t *) cd9660_setattr },
908 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
909 { NULL, NULL }
910};
911static struct vnodeopv_desc cd9660_specop_opv_desc =
912 { &cd9660_specop_p, cd9660_specop_entries };
913VNODEOP_SET(cd9660_specop_opv_desc);
914
915vop_t **cd9660_fifoop_p;
916static struct vnodeopv_entry_desc cd9660_fifoop_entries[] = {
917 { &vop_default_desc, (vop_t *) fifo_vnoperate },
918 { &vop_access_desc, (vop_t *) cd9660_access },
919 { &vop_getattr_desc, (vop_t *) cd9660_getattr },
920 { &vop_inactive_desc, (vop_t *) cd9660_inactive },
921 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
922 { &vop_lock_desc, (vop_t *) vop_stdlock },
923 { &vop_print_desc, (vop_t *) cd9660_print },
924 { &vop_reclaim_desc, (vop_t *) cd9660_reclaim },
925 { &vop_setattr_desc, (vop_t *) cd9660_setattr },
926 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
927 { NULL, NULL }
928};
929static struct vnodeopv_desc cd9660_fifoop_opv_desc =
930 { &cd9660_fifoop_p, cd9660_fifoop_entries };
931
932VNODEOP_SET(cd9660_fifoop_opv_desc);