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