Merge branch 'vendor/OPENSSL'
[dragonfly.git] / sys / vfs / isofs / cd9660 / cd9660_vnops.c
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. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *      @(#)cd9660_vnops.c      8.19 (Berkeley) 5/27/95
35  * $FreeBSD: src/sys/isofs/cd9660/cd9660_vnops.c,v 1.62 1999/12/15 23:01:51 eivind Exp $
36  */
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/proc.h>
41 #include <sys/namei.h>
42 #include <sys/kernel.h>
43 #include <sys/stat.h>
44 #include <sys/buf.h>
45 #include <sys/mount.h>
46 #include <sys/vnode.h>
47 #include <vfs/fifofs/fifo.h>
48 #include <sys/malloc.h>
49 #include <sys/dirent.h>
50 #include <sys/unistd.h>
51 #include <sys/filio.h>
52 #include <sys/lockf.h>
53 #include <sys/objcache.h>
54
55 #include <vm/vm.h>
56 #include <vm/vnode_pager.h>
57
58 #include <sys/buf2.h>
59
60 #include "iso.h"
61 #include "cd9660_node.h"
62 #include "iso_rrip.h"
63
64 static int cd9660_access (struct vop_access_args *);
65 static int cd9660_advlock (struct vop_advlock_args *);
66 static int cd9660_getattr (struct vop_getattr_args *);
67 static int cd9660_ioctl (struct vop_ioctl_args *);
68 static int cd9660_pathconf (struct vop_pathconf_args *);
69 static int cd9660_open (struct vop_open_args *);
70 static int cd9660_read (struct vop_read_args *);
71 static int cd9660_setattr (struct vop_setattr_args *);
72 struct isoreaddir;
73 static int iso_uiodir (struct isoreaddir *idp, struct dirent *dp,
74                            off_t off);
75 static int iso_shipdir (struct isoreaddir *idp);
76 static int cd9660_readdir (struct vop_readdir_args *);
77 static int cd9660_readlink (struct vop_readlink_args *ap);
78 static int cd9660_strategy (struct vop_strategy_args *);
79 static int cd9660_print (struct vop_print_args *);
80
81 /*
82  * Setattr call. Only allowed for block and character special devices.
83  *
84  * cd9660_setattr(struct vnode *a_vp, struct vattr *a_vap,
85  *                struct ucred *a_cred, struct proc *a_p)
86  */
87 int
88 cd9660_setattr(struct vop_setattr_args *ap)
89 {
90         struct vnode *vp = ap->a_vp;
91         struct vattr *vap = ap->a_vap;
92
93         if (vap->va_flags != (u_long)VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
94             vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
95             vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL)
96                 return (EROFS);
97         if (vap->va_size != (u_quad_t)VNOVAL) {
98                 switch (vp->v_type) {
99                 case VDIR:
100                         return (EISDIR);
101                 case VLNK:
102                 case VREG:
103                 case VDATABASE:
104                         return (EROFS);
105                 case VCHR:
106                 case VBLK:
107                 case VSOCK:
108                 case VFIFO:
109                 default:
110                         return (0);
111                 }
112         }
113         return (0);
114 }
115
116 /*
117  * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC.
118  * The mode is shifted to select the owner/group/other fields. The
119  * super user is granted all permissions.
120  *
121  * cd9660_access(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
122  *               struct proc *a_p)
123  */
124 /* ARGSUSED */
125 static int
126 cd9660_access(struct vop_access_args *ap)
127 {
128         struct vnode *vp = ap->a_vp;
129         struct iso_node *ip = VTOI(vp);
130
131         KKASSERT(vp->v_mount->mnt_flag & MNT_RDONLY);
132         return (vop_helper_access(ap, ip->inode.iso_uid, ip->inode.iso_gid,
133                         ip->inode.iso_mode, 0));
134 }
135
136 /*
137  * cd9660_getattr(struct vnode *a_vp, struct vattr *a_vap)
138  */
139 static int
140 cd9660_getattr(struct vop_getattr_args *ap)
141 {
142         struct vnode *vp = ap->a_vp;
143         struct vattr *vap = ap->a_vap;
144         struct iso_node *ip = VTOI(vp);
145
146         vap->va_fsid    = dev2udev(ip->i_dev);
147         vap->va_fileid  = ip->i_number;
148
149         vap->va_mode    = ip->inode.iso_mode;
150         vap->va_nlink   = ip->inode.iso_links;
151         vap->va_uid     = ip->inode.iso_uid;
152         vap->va_gid     = ip->inode.iso_gid;
153         vap->va_atime   = ip->inode.iso_atime;
154         vap->va_mtime   = ip->inode.iso_mtime;
155         vap->va_ctime   = ip->inode.iso_ctime;
156         vap->va_rmajor  = umajor(ip->inode.iso_rdev);
157         vap->va_rminor  = uminor(ip->inode.iso_rdev);
158
159         vap->va_size    = (u_quad_t)(unsigned long)ip->i_size;
160         if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) {
161                 struct vop_readlink_args rdlnk;
162                 struct iovec aiov;
163                 struct uio auio;
164                 char *cp;
165
166                 cp = kmalloc(MAXPATHLEN, M_TEMP, M_WAITOK);
167                 aiov.iov_base = cp;
168                 aiov.iov_len = MAXPATHLEN;
169                 auio.uio_iov = &aiov;
170                 auio.uio_iovcnt = 1;
171                 auio.uio_offset = 0;
172                 auio.uio_rw = UIO_READ;
173                 auio.uio_segflg = UIO_SYSSPACE;
174                 auio.uio_td = curthread;
175                 auio.uio_resid = MAXPATHLEN;
176                 rdlnk.a_uio = &auio;
177                 rdlnk.a_vp = ap->a_vp;
178                 rdlnk.a_cred = proc0.p_ucred; /* use root cred */
179                 if (cd9660_readlink(&rdlnk) == 0)
180                         vap->va_size = MAXPATHLEN - auio.uio_resid;
181                 kfree(cp, M_TEMP);
182         }
183         vap->va_flags   = 0;
184         vap->va_gen = 1;
185         vap->va_blocksize = ip->i_mnt->logical_block_size;
186         vap->va_bytes   = (u_quad_t) ip->i_size;
187         vap->va_type    = vp->v_type;
188         vap->va_filerev = 0;
189         return (0);
190 }
191
192 /*
193  * Vnode op for ioctl.
194  *
195  * cd9660_ioctl(struct vnode *a_vp, int a_command, caddr_t a_data,
196  *              int a_fflag, struct ucred *a_cred, struct proc *a_p)
197  */
198 static int
199 cd9660_ioctl(struct vop_ioctl_args *ap)
200 {
201         struct vnode *vp = ap->a_vp;
202         struct iso_node *ip = VTOI(vp);
203
204         switch (ap->a_command) {
205
206         case FIOGETLBA:
207                 *(int *)(ap->a_data) = ip->iso_start;
208                 return 0;
209         default:
210                 return (ENOTTY);
211         }
212 }
213
214 /*
215  * open is called when the kernel intends to read or memory map a vnode.
216  */
217 static int
218 cd9660_open(struct vop_open_args *ap)
219 {
220         return(vop_stdopen(ap));
221 }
222
223 /*
224  * Vnode op for reading.
225  *
226  * cd9660_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
227  *              struct ucred *a_cred)
228  */
229 static int
230 cd9660_read(struct vop_read_args *ap)
231 {
232         struct vnode *vp = ap->a_vp;
233         struct uio *uio = ap->a_uio;
234         struct iso_node *ip = VTOI(vp);
235         struct iso_mnt *imp;
236         struct buf *bp;
237         daddr_t lbn, rablock;
238         off_t raoffset;
239         off_t loffset;
240         off_t diff;
241         int rasize, error = 0;
242         int seqcount;
243         long size, n, on;
244
245         seqcount = ap->a_ioflag >> 16;
246
247         if (uio->uio_resid == 0)
248                 return (0);
249         if (uio->uio_offset < 0)
250                 return (EINVAL);
251         ip->i_flag |= IN_ACCESS;
252         imp = ip->i_mnt;
253         do {
254                 lbn = lblkno(imp, uio->uio_offset);
255                 loffset = lblktooff(imp, lbn);
256                 on = blkoff(imp, uio->uio_offset);
257                 n = szmin((u_int)(imp->logical_block_size - on),
258                           uio->uio_resid);
259                 diff = (off_t)ip->i_size - uio->uio_offset;
260                 if (diff <= 0)
261                         return (0);
262                 if (diff < n)
263                         n = diff;
264                 size = blksize(imp, ip, lbn);
265                 rablock = lbn + 1;
266                 raoffset = lblktooff(imp, rablock);
267                 if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
268                         if (raoffset < ip->i_size) {
269                                 error = cluster_read(vp, (off_t)ip->i_size,
270                                                      loffset, size,
271                                                      uio->uio_resid,
272                                                      (ap->a_ioflag >> 16) *
273                                                       BKVASIZE,
274                                                      &bp);
275                         } else {
276                                 error = bread(vp, loffset, size, &bp);
277                         }
278                 } else {
279                         if (seqcount > 1 &&
280                             lblktosize(imp, rablock) < ip->i_size) {
281                                 rasize = blksize(imp, ip, rablock);
282                                 error = breadn(vp, loffset, size, &raoffset,
283                                                &rasize, 1, &bp);
284                         } else
285                                 error = bread(vp, loffset, size, &bp);
286                 }
287                 n = imin(n, size - bp->b_resid);
288                 if (error) {
289                         brelse(bp);
290                         return (error);
291                 }
292
293                 error = uiomove(bp->b_data + on, (int)n, uio);
294                 brelse(bp);
295         } while (error == 0 && uio->uio_resid > 0 && n != 0);
296         return (error);
297 }
298
299 /* struct dirent + enough space for the maximum supported size */
300 struct iso_dirent {
301         struct dirent de;
302         char de_name[_DIRENT_RECLEN(NAME_MAX) - sizeof(struct dirent)];
303 };
304
305 /*
306  * Structure for reading directories
307  */
308 struct isoreaddir {
309         struct iso_dirent saveent;
310         struct iso_dirent assocent;
311         struct iso_dirent current;
312         off_t saveoff;
313         off_t assocoff;
314         off_t curroff;
315         struct uio *uio;
316         off_t uio_off;
317         int eofflag;
318         off_t *cookies;
319         int ncookies;
320 };
321
322 int
323 iso_uiodir(struct isoreaddir *idp, struct dirent *dp, off_t off)
324 {
325         int error;
326
327         dp->d_name[dp->d_namlen] = 0;
328
329         if (idp->uio->uio_resid < _DIRENT_DIRSIZ(dp)) {
330                 idp->eofflag = 0;
331                 return (-1);
332         }
333
334         if (idp->cookies) {
335                 if (idp->ncookies <= 0) {
336                         idp->eofflag = 0;
337                         return (-1);
338                 }
339
340                 *idp->cookies++ = off;
341                 --idp->ncookies;
342         }
343
344         if ((error = uiomove((caddr_t) dp,_DIRENT_DIRSIZ(dp),idp->uio)) != 0)
345                 return (error);
346         idp->uio_off = off;
347         return (0);
348 }
349
350 int
351 iso_shipdir(struct isoreaddir *idp)
352 {
353         struct dirent *dp;
354         int cl, sl, assoc;
355         int error;
356         char *cname, *sname;
357
358         cl = idp->current.de.d_namlen;
359         cname = idp->current.de.d_name;
360 assoc = (cl > 1) && (*cname == ASSOCCHAR);
361         if (assoc) {
362                 cl--;
363                 cname++;
364         }
365
366         dp = &idp->saveent.de;
367         sname = dp->d_name;
368         if (!(sl = dp->d_namlen)) {
369                 dp = &idp->assocent.de;
370                 sname = dp->d_name + 1;
371                 sl = dp->d_namlen - 1;
372         }
373         if (sl > 0) {
374                 if (sl != cl
375                     || bcmp(sname,cname,sl)) {
376                         if (idp->assocent.de.d_namlen) {
377                                 if ((error = iso_uiodir(idp,&idp->assocent.de,idp->assocoff)) != 0)
378                                         return (error);
379                                 idp->assocent.de.d_namlen = 0;
380                         }
381                         if (idp->saveent.de.d_namlen) {
382                                 if ((error = iso_uiodir(idp,&idp->saveent.de,idp->saveoff)) != 0)
383                                         return (error);
384                                 idp->saveent.de.d_namlen = 0;
385                         }
386                 }
387         }
388         if (assoc) {
389                 idp->assocoff = idp->curroff;
390                 bcopy(&idp->current,&idp->assocent,_DIRENT_DIRSIZ(&idp->current.de));
391         } else {
392                 idp->saveoff = idp->curroff;
393                 bcopy(&idp->current,&idp->saveent,_DIRENT_DIRSIZ(&idp->current.de));
394         }
395         return (0);
396 }
397
398 /*
399  * Vnode op for readdir
400  *
401  * cd9660_readdir(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred,
402  *                int *a_eofflag, int *a_ncookies, off_t *a_cookies)
403  */
404 static int
405 cd9660_readdir(struct vop_readdir_args *ap)
406 {
407         struct uio *uio = ap->a_uio;
408         struct isoreaddir *idp;
409         struct vnode *vdp = ap->a_vp;
410         struct iso_node *dp;
411         struct iso_mnt *imp;
412         struct buf *bp = NULL;
413         struct iso_directory_record *ep;
414         int entryoffsetinblock;
415         doff_t endsearch;
416         u_long bmask;
417         int error = 0;
418         int reclen;
419         u_short namelen;
420         int ncookies = 0;
421         off_t *cookies = NULL;
422
423         dp = VTOI(vdp);
424         imp = dp->i_mnt;
425         bmask = imp->im_bmask;
426
427         error = vn_lock(vdp, LK_EXCLUSIVE | LK_RETRY | LK_FAILRECLAIM);
428         if (error)
429                 return (error);
430
431         idp = kmalloc(sizeof(*idp), M_TEMP, M_WAITOK);
432         idp->saveent.de.d_namlen = idp->assocent.de.d_namlen = 0;
433         /*
434          * XXX
435          * Is it worth trying to figure out the type?
436          */
437         idp->saveent.de.d_type = DT_UNKNOWN;
438         idp->assocent.de.d_type = DT_UNKNOWN;
439         idp->current.de.d_type = DT_UNKNOWN;
440         idp->uio = uio;
441         if (ap->a_ncookies == NULL) {
442                 idp->cookies = NULL;
443         } else {
444                 /*
445                  * Guess the number of cookies needed.  Guess at least
446                  * 1 to avoid a degenerate case in malloc, and cap at
447                  * a reasonable limit.
448                  */
449                 ncookies = uio->uio_resid / 16 + 1;
450                 if (ncookies > 1024)
451                         ncookies = 1024;
452                 cookies = kmalloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK);
453                 idp->cookies = cookies;
454                 idp->ncookies = ncookies;
455         }
456         idp->eofflag = 1;
457         idp->curroff = uio->uio_offset;
458
459         if ((entryoffsetinblock = idp->curroff & bmask) &&
460             (error = cd9660_devblkatoff(vdp, idp->curroff, NULL, &bp))) {
461                 kfree(idp, M_TEMP);
462                 goto done;
463         }
464         endsearch = dp->i_size;
465
466         while (idp->curroff < endsearch) {
467                 /*
468                  * If offset is on a block boundary,
469                  * read the next directory block.
470                  * Release previous if it exists.
471                  */
472                 if ((idp->curroff & bmask) == 0) {
473                         if (bp != NULL)
474                                 brelse(bp);
475                         if ((error =
476                             cd9660_devblkatoff(vdp, idp->curroff, NULL, &bp)) != 0)
477                                 break;
478                         entryoffsetinblock = 0;
479                 }
480                 /*
481                  * Get pointer to next entry.
482                  */
483                 ep = (struct iso_directory_record *)
484                         ((char *)bp->b_data + entryoffsetinblock);
485
486                 reclen = isonum_711(ep->length);
487                 if (reclen == 0) {
488                         /* skip to next block, if any */
489                         idp->curroff =
490                             (idp->curroff & ~bmask) + imp->logical_block_size;
491                         continue;
492                 }
493
494                 if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
495                         error = EINVAL;
496                         /* illegal entry, stop */
497                         break;
498                 }
499
500                 if (entryoffsetinblock + reclen > imp->logical_block_size) {
501                         error = EINVAL;
502                         /* illegal directory, so stop looking */
503                         break;
504                 }
505
506                 idp->current.de.d_namlen = isonum_711(ep->name_len);
507
508                 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.de.d_namlen) {
509                         error = EINVAL;
510                         /* illegal entry, stop */
511                         break;
512                 }
513
514                 if (isonum_711(ep->flags)&2)
515                         idp->current.de.d_ino = isodirino(ep, imp);
516                 else
517                         idp->current.de.d_ino = bp->b_bio1.bio_offset +
518                                                 entryoffsetinblock;
519
520                 idp->curroff += reclen;
521
522                 switch (imp->iso_ftype) {
523                 case ISO_FTYPE_RRIP:
524                 {
525                         ino_t cur_fileno = idp->current.de.d_ino;       
526                         cd9660_rrip_getname(ep,idp->current.de.d_name, &namelen,
527                                            &cur_fileno,imp);
528                         idp->current.de.d_ino = cur_fileno;
529                         idp->current.de.d_namlen = namelen;
530                         if (idp->current.de.d_namlen)
531                                 error = iso_uiodir(idp,&idp->current.de,idp->curroff);
532                         break;
533                 }
534                 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/
535                         strcpy(idp->current.de.d_name,"..");
536                         if (idp->current.de.d_namlen == 1 && ep->name[0] == 0) {
537                                 idp->current.de.d_namlen = 1;
538                                 error = iso_uiodir(idp,&idp->current.de,idp->curroff);
539                         } else if (idp->current.de.d_namlen == 1 && ep->name[0] == 1) {
540                                 idp->current.de.d_namlen = 2;
541                                 error = iso_uiodir(idp,&idp->current.de,idp->curroff);
542                         } else {
543                                 isofntrans(ep->name,idp->current.de.d_namlen,
544                                            idp->current.de.d_name, &namelen,
545                                            imp->iso_ftype == ISO_FTYPE_9660,
546                                            isonum_711(ep->flags)&4,
547                                            imp->joliet_level,
548                                            imp->im_flags,
549                                            imp->im_d2l);
550                                 idp->current.de.d_namlen = namelen;
551                                 if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
552                                         error = iso_shipdir(idp);
553                                 else
554                                         error = iso_uiodir(idp,&idp->current.de,idp->curroff);
555                         }
556                 }
557                 if (error)
558                         break;
559
560                 entryoffsetinblock += reclen;
561         }
562
563         if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
564                 idp->current.de.d_namlen = 0;
565                 error = iso_shipdir(idp);
566         }
567         if (error < 0)
568                 error = 0;
569
570         if (ap->a_ncookies != NULL) {
571                 if (error)
572                         kfree(cookies, M_TEMP);
573                 else {
574                         /*
575                          * Work out the number of cookies actually used.
576                          */
577                         *ap->a_ncookies = ncookies - idp->ncookies;
578                         *ap->a_cookies = cookies;
579                 }
580         }
581
582         if (bp)
583                 brelse (bp);
584
585         uio->uio_offset = idp->uio_off;
586         *ap->a_eofflag = idp->eofflag;
587
588         kfree(idp, M_TEMP);
589
590 done:
591         vn_unlock(vdp);
592         return (error);
593 }
594
595 /*
596  * Return target name of a symbolic link
597  * Shouldn't we get the parent vnode and read the data from there?
598  * This could eventually result in deadlocks in cd9660_lookup.
599  * But otherwise the block read here is in the block buffer two times.
600  */
601 typedef struct iso_directory_record ISODIR;
602 typedef struct iso_node             ISONODE;
603 typedef struct iso_mnt              ISOMNT;
604 /*
605  * cd9660_readlink(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred)
606  */
607 static int
608 cd9660_readlink(struct vop_readlink_args *ap)
609 {
610         ISONODE *ip;
611         ISODIR  *dirp;
612         ISOMNT  *imp;
613         struct  buf *bp;
614         struct  uio *uio;
615         u_short symlen;
616         int     error;
617         char    *symname;
618
619         ip  = VTOI(ap->a_vp);
620         imp = ip->i_mnt;
621         uio = ap->a_uio;
622
623         if (imp->iso_ftype != ISO_FTYPE_RRIP)
624                 return (EINVAL);
625
626         /*
627          * Get parents directory record block that this inode included.
628          */
629         error = bread(imp->im_devvp,
630                         (off_t)ip->i_number & ~((1 << imp->im_bshift) - 1),
631                       imp->logical_block_size, &bp);
632         if (error) {
633                 brelse(bp);
634                 return (EINVAL);
635         }
636
637         /*
638          * Setup the directory pointer for this inode
639          */
640         dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask));
641
642         /*
643          * Just make sure, we have a right one....
644          *   1: Check not cross boundary on block
645          */
646         if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
647             > (unsigned)imp->logical_block_size) {
648                 brelse(bp);
649                 return (EINVAL);
650         }
651
652         /*
653          * Now get a buffer
654          * Abuse a namei buffer for now.
655          */
656         if (uio->uio_segflg == UIO_SYSSPACE)
657                 symname = uio->uio_iov->iov_base;
658         else
659                 symname = objcache_get(namei_oc, M_WAITOK);
660         
661         /*
662          * Ok, we just gathering a symbolic name in SL record.
663          */
664         if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
665                 if (uio->uio_segflg != UIO_SYSSPACE)
666                         objcache_put(namei_oc, symname);
667                 brelse(bp);
668                 return (EINVAL);
669         }
670         /*
671          * Don't forget before you leave from home ;-)
672          */
673         brelse(bp);
674
675         /*
676          * return with the symbolic name to caller's.
677          */
678         if (uio->uio_segflg != UIO_SYSSPACE) {
679                 error = uiomove(symname, symlen, uio);
680                 objcache_put(namei_oc, symname);
681                 return (error);
682         }
683         uio->uio_resid -= symlen;
684         uio->uio_iov->iov_base = (char *)uio->uio_iov->iov_base + symlen;
685         uio->uio_iov->iov_len -= symlen;
686         return (0);
687 }
688
689 /*
690  * Calculate the logical to physical mapping if not done already,
691  * then call the device strategy routine.
692  *
693  * cd9660_strategy(struct buf *a_vp, struct buf *a_bio)
694  */
695 static int
696 cd9660_strategy(struct vop_strategy_args *ap)
697 {
698         struct bio *bio = ap->a_bio;
699         struct bio *nbio;
700         struct buf *bp = bio->bio_buf;
701         struct vnode *vp = ap->a_vp;
702         struct iso_node *ip;
703         int error;
704
705         ip = VTOI(vp);
706         if (vp->v_type == VBLK || vp->v_type == VCHR)
707                 panic("cd9660_strategy: spec");
708         nbio = push_bio(bio);
709         if (nbio->bio_offset == NOOFFSET) {
710                 error = VOP_BMAP(vp, bio->bio_offset,
711                                  &nbio->bio_offset, NULL, NULL, bp->b_cmd);
712                 if (error) {
713                         bp->b_error = error;
714                         bp->b_flags |= B_ERROR;
715                         /* I/O was never started on nbio, must biodone(bio) */
716                         biodone(bio);
717                         return (error);
718                 }
719                 if (nbio->bio_offset == NOOFFSET)
720                         clrbuf(bp);
721         }
722         if (nbio->bio_offset == NOOFFSET) {
723                 /* I/O was never started on nbio, must biodone(bio) */
724                 biodone(bio);
725                 return (0);
726         }
727         vp = ip->i_devvp;
728         vn_strategy(vp, nbio);
729         return (0);
730 }
731
732 /*
733  * Print out the contents of an inode.
734  *
735  * cd9660_print(struct vnode *a_vp)
736  */
737 static int
738 cd9660_print(struct vop_print_args *ap)
739 {
740         kprintf("tag VT_ISOFS, isofs vnode\n");
741         return (0);
742 }
743
744 /*
745  * Return POSIX pathconf information applicable to cd9660 filesystems.
746  *
747  * cd9660_pathconf(struct vnode *a_vp, int a_name, register_t *a_retval)
748  */
749 static int
750 cd9660_pathconf(struct vop_pathconf_args *ap)
751 {
752         switch (ap->a_name) {
753         case _PC_LINK_MAX:
754                 *ap->a_retval = 1;
755                 return (0);
756         case _PC_NAME_MAX:
757                 if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP)
758                         *ap->a_retval = NAME_MAX;
759                 else
760                         *ap->a_retval = 37;
761                 return (0);
762         case _PC_PATH_MAX:
763                 *ap->a_retval = PATH_MAX;
764                 return (0);
765         case _PC_PIPE_BUF:
766                 *ap->a_retval = PIPE_BUF;
767                 return (0);
768         case _PC_CHOWN_RESTRICTED:
769                 *ap->a_retval = 1;
770                 return (0);
771         case _PC_NO_TRUNC:
772                 *ap->a_retval = 1;
773                 return (0);
774         default:
775                 return (EINVAL);
776         }
777         /* NOTREACHED */
778 }
779
780 /*
781  * Advisory lock support
782  */
783 static int
784 cd9660_advlock(struct vop_advlock_args *ap)
785 {
786         struct iso_node *ip = VTOI(ap->a_vp);
787         return (lf_advlock(ap, &(ip->i_lockf), ip->i_size));
788 }
789
790
791 /*
792  * Global vfs data structures for cd9660
793  */
794 struct vop_ops cd9660_vnode_vops = {
795         .vop_default =          vop_defaultop,
796         .vop_open =             cd9660_open,
797         .vop_access =           cd9660_access,
798         .vop_advlock =          cd9660_advlock,
799         .vop_bmap =             cd9660_bmap,
800         .vop_old_lookup =       cd9660_lookup,
801         .vop_getattr =          cd9660_getattr,
802         .vop_inactive =         cd9660_inactive,
803         .vop_ioctl =            cd9660_ioctl,
804         .vop_pathconf =         cd9660_pathconf,
805         .vop_print =            cd9660_print,
806         .vop_read =             cd9660_read,
807         .vop_readdir =          cd9660_readdir,
808         .vop_readlink =         cd9660_readlink,
809         .vop_reclaim =          cd9660_reclaim,
810         .vop_setattr =          cd9660_setattr,
811         .vop_strategy =         cd9660_strategy,
812         .vop_getpages =         vop_stdgetpages,
813         .vop_putpages =         vop_stdputpages
814 };
815
816 /*
817  * Special device vnode ops
818  */
819 struct vop_ops cd9660_spec_vops = {
820         .vop_default =          vop_defaultop,
821         .vop_read =             vop_stdnoread,
822         .vop_access =           cd9660_access,
823         .vop_getattr =          cd9660_getattr,
824         .vop_inactive =         cd9660_inactive,
825         .vop_print =            cd9660_print,
826         .vop_reclaim =          cd9660_reclaim,
827         .vop_setattr =          cd9660_setattr,
828 };
829
830 struct vop_ops cd9660_fifo_vops = {
831         .vop_default =          fifo_vnoperate,
832         .vop_access =           cd9660_access,
833         .vop_getattr =          cd9660_getattr,
834         .vop_inactive =         cd9660_inactive,
835         .vop_print =            cd9660_print,
836         .vop_reclaim =          cd9660_reclaim,
837         .vop_setattr =          cd9660_setattr,
838 };
839