The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/fs/cd9660/cd9660_vnops.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * SPDX-License-Identifier: BSD-3-Clause
    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@blitz.com).  The Rock Ridge Extension
    9  * Support code is derived from software contributed to Berkeley
   10  * by Atsushi Murai (amurai@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.19 (Berkeley) 5/27/95
   37  */
   38 
   39 #include <sys/cdefs.h>
   40 __FBSDID("$FreeBSD$");
   41 
   42 #include <sys/param.h>
   43 #include <sys/systm.h>
   44 #include <sys/namei.h>
   45 #include <sys/kernel.h>
   46 #include <sys/conf.h>
   47 #include <sys/stat.h>
   48 #include <sys/bio.h>
   49 #include <sys/buf.h>
   50 #include <sys/mount.h>
   51 #include <sys/vnode.h>
   52 #include <sys/malloc.h>
   53 #include <sys/dirent.h>
   54 #include <sys/unistd.h>
   55 #include <sys/filio.h>
   56 #include <sys/sysctl.h>
   57 
   58 #include <vm/vm.h>
   59 #include <vm/vnode_pager.h>
   60 #include <vm/uma.h>
   61 
   62 #include <fs/cd9660/iso.h>
   63 #include <fs/cd9660/cd9660_node.h>
   64 #include <fs/cd9660/iso_rrip.h>
   65 
   66 static vop_setattr_t    cd9660_setattr;
   67 static vop_open_t       cd9660_open;
   68 static vop_access_t     cd9660_access;
   69 static vop_getattr_t    cd9660_getattr;
   70 static vop_ioctl_t      cd9660_ioctl;
   71 static vop_pathconf_t   cd9660_pathconf;
   72 static vop_read_t       cd9660_read;
   73 struct isoreaddir;
   74 static int iso_uiodir(struct isoreaddir *idp, struct dirent *dp, off_t off);
   75 static int iso_shipdir(struct isoreaddir *idp);
   76 static vop_readdir_t    cd9660_readdir;
   77 static vop_readlink_t   cd9660_readlink;
   78 static vop_strategy_t   cd9660_strategy;
   79 static vop_vptofh_t     cd9660_vptofh;
   80 static vop_getpages_t   cd9660_getpages;
   81 
   82 /*
   83  * Setattr call. Only allowed for block and character special devices.
   84  */
   85 static int
   86 cd9660_setattr(struct vop_setattr_args *ap)
   87 {
   88         struct vnode *vp = ap->a_vp;
   89         struct vattr *vap = ap->a_vap;
   90 
   91         if (vap->va_flags != (u_long)VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
   92             vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
   93             vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL)
   94                 return (EROFS);
   95         if (vap->va_size != (u_quad_t)VNOVAL) {
   96                 switch (vp->v_type) {
   97                 case VDIR:
   98                         return (EISDIR);
   99                 case VLNK:
  100                 case VREG:
  101                         return (EROFS);
  102                 case VCHR:
  103                 case VBLK:
  104                 case VSOCK:
  105                 case VFIFO:
  106                 case VNON:
  107                 case VBAD:
  108                 case VMARKER:
  109                         return (0);
  110                 }
  111         }
  112         return (0);
  113 }
  114 
  115 /*
  116  * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC.
  117  * The mode is shifted to select the owner/group/other fields. The
  118  * super user is granted all permissions.
  119  */
  120 /* ARGSUSED */
  121 static int
  122 cd9660_access(struct vop_access_args *ap)
  123 {
  124         struct vnode *vp = ap->a_vp;
  125         struct iso_node *ip = VTOI(vp);
  126         accmode_t accmode = ap->a_accmode;
  127 
  128         if (vp->v_type == VCHR || vp->v_type == VBLK)
  129                 return (EOPNOTSUPP);
  130 
  131         /*
  132          * Disallow write attempts unless the file is a socket,
  133          * fifo, or a block or character device resident on the
  134          * filesystem.
  135          */
  136         if (accmode & VWRITE) {
  137                 switch (vp->v_type) {
  138                 case VDIR:
  139                 case VLNK:
  140                 case VREG:
  141                         return (EROFS);
  142                         /* NOT REACHED */
  143                 default:
  144                         break;
  145                 }
  146         }
  147 
  148         return (vaccess(vp->v_type, ip->inode.iso_mode, ip->inode.iso_uid,
  149             ip->inode.iso_gid, ap->a_accmode, ap->a_cred));
  150 }
  151 
  152 static int
  153 cd9660_open(struct vop_open_args *ap)
  154 {
  155         struct vnode *vp = ap->a_vp;
  156         struct iso_node *ip = VTOI(vp);
  157 
  158         if (vp->v_type == VCHR || vp->v_type == VBLK)
  159                 return (EOPNOTSUPP);
  160 
  161         vnode_create_vobject(vp, ip->i_size, ap->a_td);
  162         return (0);
  163 }
  164 
  165 static int
  166 cd9660_getattr(struct vop_getattr_args *ap)
  167 
  168 {
  169         struct vnode *vp = ap->a_vp;
  170         struct vattr *vap = ap->a_vap;
  171         struct iso_node *ip = VTOI(vp);
  172 
  173         vap->va_fsid    = dev2udev(ip->i_mnt->im_dev);
  174         vap->va_fileid  = ip->i_number;
  175 
  176         vap->va_mode    = ip->inode.iso_mode;
  177         vap->va_nlink   = ip->inode.iso_links;
  178         vap->va_uid     = ip->inode.iso_uid;
  179         vap->va_gid     = ip->inode.iso_gid;
  180         vap->va_atime   = ip->inode.iso_atime;
  181         vap->va_mtime   = ip->inode.iso_mtime;
  182         vap->va_ctime   = ip->inode.iso_ctime;
  183         vap->va_rdev    = ip->inode.iso_rdev;
  184 
  185         vap->va_size    = (u_quad_t) ip->i_size;
  186         if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) {
  187                 struct vop_readlink_args rdlnk;
  188                 struct iovec aiov;
  189                 struct uio auio;
  190                 char *cp;
  191 
  192                 cp = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
  193                 aiov.iov_base = cp;
  194                 aiov.iov_len = MAXPATHLEN;
  195                 auio.uio_iov = &aiov;
  196                 auio.uio_iovcnt = 1;
  197                 auio.uio_offset = 0;
  198                 auio.uio_rw = UIO_READ;
  199                 auio.uio_segflg = UIO_SYSSPACE;
  200                 auio.uio_td = curthread;
  201                 auio.uio_resid = MAXPATHLEN;
  202                 rdlnk.a_uio = &auio;
  203                 rdlnk.a_vp = ap->a_vp;
  204                 rdlnk.a_cred = ap->a_cred;
  205                 if (cd9660_readlink(&rdlnk) == 0)
  206                         vap->va_size = MAXPATHLEN - auio.uio_resid;
  207                 free(cp, M_TEMP);
  208         }
  209         vap->va_flags   = 0;
  210         vap->va_gen = 1;
  211         vap->va_blocksize = ip->i_mnt->logical_block_size;
  212         vap->va_bytes   = (u_quad_t) ip->i_size;
  213         vap->va_type    = vp->v_type;
  214         vap->va_filerev = 0;
  215         return (0);
  216 }
  217 
  218 /*
  219  * Vnode op for ioctl.
  220  */
  221 static int
  222 cd9660_ioctl(struct vop_ioctl_args *ap)
  223 {
  224         struct vnode *vp;
  225         struct iso_node *ip;
  226         int error;
  227 
  228         vp = ap->a_vp;
  229         vn_lock(vp, LK_SHARED | LK_RETRY);
  230         if (VN_IS_DOOMED(vp)) {
  231                 VOP_UNLOCK(vp);
  232                 return (EBADF);
  233         }
  234         if (vp->v_type == VCHR || vp->v_type == VBLK) {
  235                 VOP_UNLOCK(vp);
  236                 return (EOPNOTSUPP);
  237         }
  238 
  239         ip = VTOI(vp);
  240         error = 0;
  241 
  242         switch (ap->a_command) {
  243         case FIOGETLBA:
  244                 *(int *)(ap->a_data) = ip->iso_start;
  245                 break;
  246         default:
  247                 error = ENOTTY;
  248                 break;
  249         }
  250 
  251         VOP_UNLOCK(vp);
  252         return (error);
  253 }
  254 
  255 /*
  256  * Vnode op for reading.
  257  */
  258 static int
  259 cd9660_read(struct vop_read_args *ap)
  260 {
  261         struct vnode *vp = ap->a_vp;
  262         struct uio *uio = ap->a_uio;
  263         struct iso_node *ip = VTOI(vp);
  264         struct iso_mnt *imp;
  265         struct buf *bp;
  266         daddr_t lbn, rablock;
  267         off_t diff;
  268         int rasize, error = 0;
  269         int seqcount;
  270         long size, n, on;
  271 
  272         if (vp->v_type == VCHR || vp->v_type == VBLK)
  273                 return (EOPNOTSUPP);
  274 
  275         seqcount = ap->a_ioflag >> IO_SEQSHIFT;
  276 
  277         if (uio->uio_resid == 0)
  278                 return (0);
  279         if (uio->uio_offset < 0)
  280                 return (EINVAL);
  281         imp = ip->i_mnt;
  282         do {
  283                 lbn = lblkno(imp, uio->uio_offset);
  284                 on = blkoff(imp, uio->uio_offset);
  285                 n = MIN(imp->logical_block_size - on, uio->uio_resid);
  286                 diff = (off_t)ip->i_size - uio->uio_offset;
  287                 if (diff <= 0)
  288                         return (0);
  289                 if (diff < n)
  290                         n = diff;
  291                 size = blksize(imp, ip, lbn);
  292                 rablock = lbn + 1;
  293                 if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
  294                         if (lblktosize(imp, rablock) < ip->i_size)
  295                                 error = cluster_read(vp, (off_t)ip->i_size,
  296                                          lbn, size, NOCRED, uio->uio_resid,
  297                                          (ap->a_ioflag >> 16), 0, &bp);
  298                         else
  299                                 error = bread(vp, lbn, size, NOCRED, &bp);
  300                 } else {
  301                         if (seqcount > 1 &&
  302                             lblktosize(imp, rablock) < ip->i_size) {
  303                                 rasize = blksize(imp, ip, rablock);
  304                                 error = breadn(vp, lbn, size, &rablock,
  305                                                &rasize, 1, NOCRED, &bp);
  306                         } else
  307                                 error = bread(vp, lbn, size, NOCRED, &bp);
  308                 }
  309                 if (error != 0)
  310                         return (error);
  311                 n = MIN(n, size - bp->b_resid);
  312 
  313                 error = uiomove(bp->b_data + on, (int)n, uio);
  314                 brelse(bp);
  315         } while (error == 0 && uio->uio_resid > 0 && n != 0);
  316         return (error);
  317 }
  318 
  319 /*
  320  * Structure for reading directories
  321  */
  322 struct isoreaddir {
  323         struct dirent saveent;
  324         struct dirent assocent;
  325         struct dirent current;
  326         off_t saveoff;
  327         off_t assocoff;
  328         off_t curroff;
  329         struct uio *uio;
  330         off_t uio_off;
  331         int eofflag;
  332         uint64_t *cookies;
  333         int ncookies;
  334 };
  335 
  336 static int
  337 iso_uiodir(struct isoreaddir *idp, struct dirent *dp, off_t off)
  338 {
  339         int error;
  340 
  341         dp->d_reclen = GENERIC_DIRSIZ(dp);
  342         dirent_terminate(dp);
  343 
  344         if (idp->uio->uio_resid < dp->d_reclen) {
  345                 idp->eofflag = 0;
  346                 return (-1);
  347         }
  348 
  349         if (idp->cookies) {
  350                 if (idp->ncookies <= 0) {
  351                         idp->eofflag = 0;
  352                         return (-1);
  353                 }
  354 
  355                 *idp->cookies++ = off;
  356                 --idp->ncookies;
  357         }
  358 
  359         if ((error = uiomove(dp, dp->d_reclen, idp->uio)) != 0)
  360                 return (error);
  361         idp->uio_off = off;
  362         return (0);
  363 }
  364 
  365 static int
  366 iso_shipdir(struct isoreaddir *idp)
  367 {
  368         struct dirent *dp;
  369         int cl, sl, assoc;
  370         int error;
  371         char *cname, *sname;
  372 
  373         cl = idp->current.d_namlen;
  374         cname = idp->current.d_name;
  375         assoc = (cl > 1) && (*cname == ASSOCCHAR);
  376         if (assoc) {
  377                 cl--;
  378                 cname++;
  379         }
  380 
  381         dp = &idp->saveent;
  382         sname = dp->d_name;
  383         if (!(sl = dp->d_namlen)) {
  384                 dp = &idp->assocent;
  385                 sname = dp->d_name + 1;
  386                 sl = dp->d_namlen - 1;
  387         }
  388         if (sl > 0) {
  389                 if (sl != cl
  390                     || bcmp(sname,cname,sl)) {
  391                         if (idp->assocent.d_namlen) {
  392                                 if ((error = iso_uiodir(idp,&idp->assocent,idp->assocoff)) != 0)
  393                                         return (error);
  394                                 idp->assocent.d_namlen = 0;
  395                         }
  396                         if (idp->saveent.d_namlen) {
  397                                 if ((error = iso_uiodir(idp,&idp->saveent,idp->saveoff)) != 0)
  398                                         return (error);
  399                                 idp->saveent.d_namlen = 0;
  400                         }
  401                 }
  402         }
  403         idp->current.d_reclen = GENERIC_DIRSIZ(&idp->current);
  404         if (assoc) {
  405                 idp->assocoff = idp->curroff;
  406                 memcpy(&idp->assocent, &idp->current, idp->current.d_reclen);
  407         } else {
  408                 idp->saveoff = idp->curroff;
  409                 memcpy(&idp->saveent, &idp->current, idp->current.d_reclen);
  410         }
  411         return (0);
  412 }
  413 
  414 /*
  415  * Vnode op for readdir
  416  */
  417 static int
  418 cd9660_readdir(struct vop_readdir_args *ap)
  419 {
  420         struct uio *uio = ap->a_uio;
  421         struct isoreaddir *idp;
  422         struct vnode *vdp = ap->a_vp;
  423         struct iso_node *dp;
  424         struct iso_mnt *imp;
  425         struct buf *bp = NULL;
  426         struct iso_directory_record *ep;
  427         int entryoffsetinblock;
  428         doff_t endsearch;
  429         u_long bmask;
  430         int error = 0;
  431         int reclen;
  432         u_short namelen;
  433         u_int ncookies = 0;
  434         uint64_t *cookies = NULL;
  435         cd_ino_t ino;
  436 
  437         dp = VTOI(vdp);
  438         imp = dp->i_mnt;
  439         bmask = imp->im_bmask;
  440 
  441         idp = malloc(sizeof(*idp), M_TEMP, M_WAITOK);
  442         idp->saveent.d_namlen = idp->assocent.d_namlen = 0;
  443         /*
  444          * XXX
  445          * Is it worth trying to figure out the type?
  446          */
  447         idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type =
  448             DT_UNKNOWN;
  449         idp->uio = uio;
  450         if (ap->a_ncookies == NULL) {
  451                 idp->cookies = NULL;
  452         } else {
  453                 /*
  454                  * Guess the number of cookies needed.
  455                  */
  456                 ncookies = uio->uio_resid / 16;
  457                 cookies = malloc(ncookies * sizeof(*cookies), M_TEMP, M_WAITOK);
  458                 idp->cookies = cookies;
  459                 idp->ncookies = ncookies;
  460         }
  461         idp->eofflag = 1;
  462         idp->curroff = uio->uio_offset;
  463         idp->uio_off = uio->uio_offset;
  464 
  465         if ((entryoffsetinblock = idp->curroff & bmask) &&
  466             (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) {
  467                 free(idp, M_TEMP);
  468                 return (error);
  469         }
  470         endsearch = dp->i_size;
  471 
  472         while (idp->curroff < endsearch) {
  473                 /*
  474                  * If offset is on a block boundary,
  475                  * read the next directory block.
  476                  * Release previous if it exists.
  477                  */
  478                 if ((idp->curroff & bmask) == 0) {
  479                         if (bp != NULL)
  480                                 brelse(bp);
  481                         if ((error =
  482                             cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp)) != 0)
  483                                 break;
  484                         entryoffsetinblock = 0;
  485                 }
  486                 /*
  487                  * Get pointer to next entry.
  488                  */
  489                 ep = (struct iso_directory_record *)
  490                         ((char *)bp->b_data + entryoffsetinblock);
  491 
  492                 reclen = isonum_711(ep->length);
  493                 if (reclen == 0) {
  494                         /* skip to next block, if any */
  495                         idp->curroff =
  496                             (idp->curroff & ~bmask) + imp->logical_block_size;
  497                         continue;
  498                 }
  499 
  500                 if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
  501                         error = EINVAL;
  502                         /* illegal entry, stop */
  503                         break;
  504                 }
  505 
  506                 if (entryoffsetinblock + reclen > imp->logical_block_size) {
  507                         error = EINVAL;
  508                         /* illegal directory, so stop looking */
  509                         break;
  510                 }
  511 
  512                 idp->current.d_namlen = isonum_711(ep->name_len);
  513 
  514                 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) {
  515                         error = EINVAL;
  516                         /* illegal entry, stop */
  517                         break;
  518                 }
  519 
  520                 if (isonum_711(ep->flags)&2)
  521                         idp->current.d_fileno = isodirino(ep, imp);
  522                 else
  523                         idp->current.d_fileno = dbtob(bp->b_blkno) +
  524                                 entryoffsetinblock;
  525 
  526                 idp->curroff += reclen;
  527                 /* NOTE: d_off is the offset of *next* entry. */
  528                 idp->current.d_off = idp->curroff;
  529 
  530                 switch (imp->iso_ftype) {
  531                 case ISO_FTYPE_RRIP:
  532                         ino = idp->current.d_fileno;
  533                         cd9660_rrip_getname(ep, idp->current.d_name, &namelen,
  534                             &ino, imp);
  535                         idp->current.d_fileno = ino;
  536                         idp->current.d_namlen = (u_char)namelen;
  537                         if (idp->current.d_namlen)
  538                                 error = iso_uiodir(idp,&idp->current,idp->curroff);
  539                         break;
  540                 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/
  541                         strcpy(idp->current.d_name,"..");
  542                         if (idp->current.d_namlen == 1 && ep->name[0] == 0) {
  543                                 idp->current.d_namlen = 1;
  544                                 error = iso_uiodir(idp,&idp->current,idp->curroff);
  545                         } else if (idp->current.d_namlen == 1 && ep->name[0] == 1) {
  546                                 idp->current.d_namlen = 2;
  547                                 error = iso_uiodir(idp,&idp->current,idp->curroff);
  548                         } else {
  549                                 isofntrans(ep->name,idp->current.d_namlen,
  550                                            idp->current.d_name, &namelen,
  551                                            imp->iso_ftype == ISO_FTYPE_9660,
  552                                            isonum_711(ep->flags)&4,
  553                                            imp->joliet_level,
  554                                            imp->im_flags,
  555                                            imp->im_d2l);
  556                                 idp->current.d_namlen = (u_char)namelen;
  557                                 if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
  558                                         error = iso_shipdir(idp);
  559                                 else
  560                                         error = iso_uiodir(idp,&idp->current,idp->curroff);
  561                         }
  562                 }
  563                 if (error)
  564                         break;
  565 
  566                 entryoffsetinblock += reclen;
  567         }
  568 
  569         if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
  570                 idp->current.d_namlen = 0;
  571                 error = iso_shipdir(idp);
  572         }
  573         if (error < 0)
  574                 error = 0;
  575 
  576         if (ap->a_ncookies != NULL) {
  577                 if (error)
  578                         free(cookies, M_TEMP);
  579                 else {
  580                         /*
  581                          * Work out the number of cookies actually used.
  582                          */
  583                         *ap->a_ncookies = ncookies - idp->ncookies;
  584                         *ap->a_cookies = cookies;
  585                 }
  586         }
  587 
  588         if (bp)
  589                 brelse (bp);
  590 
  591         uio->uio_offset = idp->uio_off;
  592         *ap->a_eofflag = idp->eofflag;
  593 
  594         free(idp, M_TEMP);
  595 
  596         return (error);
  597 }
  598 
  599 /*
  600  * Return target name of a symbolic link
  601  * Shouldn't we get the parent vnode and read the data from there?
  602  * This could eventually result in deadlocks in cd9660_lookup.
  603  * But otherwise the block read here is in the block buffer two times.
  604  */
  605 typedef struct iso_directory_record ISODIR;
  606 typedef struct iso_node             ISONODE;
  607 typedef struct iso_mnt              ISOMNT;
  608 static int
  609 cd9660_readlink(struct vop_readlink_args *ap)
  610 {
  611         ISONODE *ip;
  612         ISODIR  *dirp;
  613         ISOMNT  *imp;
  614         struct  buf *bp;
  615         struct  uio *uio;
  616         u_short symlen;
  617         int     error;
  618         char    *symname;
  619 
  620         ip  = VTOI(ap->a_vp);
  621         imp = ip->i_mnt;
  622         uio = ap->a_uio;
  623 
  624         if (imp->iso_ftype != ISO_FTYPE_RRIP)
  625                 return (EINVAL);
  626 
  627         /*
  628          * Get parents directory record block that this inode included.
  629          */
  630         error = bread(imp->im_devvp,
  631                       (ip->i_number >> imp->im_bshift) <<
  632                       (imp->im_bshift - DEV_BSHIFT),
  633                       imp->logical_block_size, NOCRED, &bp);
  634         if (error) {
  635                 return (EINVAL);
  636         }
  637 
  638         /*
  639          * Setup the directory pointer for this inode
  640          */
  641         dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask));
  642 
  643         /*
  644          * Just make sure, we have a right one....
  645          *   1: Check not cross boundary on block
  646          */
  647         if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
  648             > (unsigned)imp->logical_block_size) {
  649                 brelse(bp);
  650                 return (EINVAL);
  651         }
  652 
  653         /*
  654          * Now get a buffer
  655          * Abuse a namei buffer for now.
  656          */
  657         if (uio->uio_segflg == UIO_SYSSPACE)
  658                 symname = uio->uio_iov->iov_base;
  659         else
  660                 symname = uma_zalloc(namei_zone, M_WAITOK);
  661 
  662         /*
  663          * Ok, we just gathering a symbolic name in SL record.
  664          */
  665         if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
  666                 if (uio->uio_segflg != UIO_SYSSPACE)
  667                         uma_zfree(namei_zone, symname);
  668                 brelse(bp);
  669                 return (EINVAL);
  670         }
  671         /*
  672          * Don't forget before you leave from home ;-)
  673          */
  674         brelse(bp);
  675 
  676         /*
  677          * return with the symbolic name to caller's.
  678          */
  679         if (uio->uio_segflg != UIO_SYSSPACE) {
  680                 error = uiomove(symname, symlen, uio);
  681                 uma_zfree(namei_zone, symname);
  682                 return (error);
  683         }
  684         uio->uio_resid -= symlen;
  685         uio->uio_iov->iov_base = (char *)uio->uio_iov->iov_base + symlen;
  686         uio->uio_iov->iov_len -= symlen;
  687         return (0);
  688 }
  689 
  690 /*
  691  * Calculate the logical to physical mapping if not done already,
  692  * then call the device strategy routine.
  693  */
  694 static int
  695 cd9660_strategy(struct vop_strategy_args *ap)
  696 {
  697         struct buf *bp = ap->a_bp;
  698         struct vnode *vp = ap->a_vp;
  699         struct iso_node *ip;
  700         struct bufobj *bo;
  701 
  702         ip = VTOI(vp);
  703         if (vp->v_type == VBLK || vp->v_type == VCHR)
  704                 panic("cd9660_strategy: spec");
  705         if (bp->b_blkno == bp->b_lblkno) {
  706                 bp->b_blkno = (ip->iso_start + bp->b_lblkno) <<
  707                     (ip->i_mnt->im_bshift - DEV_BSHIFT);
  708         }
  709         bp->b_iooffset = dbtob(bp->b_blkno);
  710         bo = ip->i_mnt->im_bo;
  711         BO_STRATEGY(bo, bp);
  712         return (0);
  713 }
  714 
  715 /*
  716  * Return POSIX pathconf information applicable to cd9660 filesystems.
  717  */
  718 static int
  719 cd9660_pathconf(struct vop_pathconf_args *ap)
  720 {
  721 
  722         switch (ap->a_name) {
  723         case _PC_FILESIZEBITS:
  724                 *ap->a_retval = 32;
  725                 return (0);
  726         case _PC_LINK_MAX:
  727                 *ap->a_retval = 1;
  728                 return (0);
  729         case _PC_NAME_MAX:
  730                 if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP)
  731                         *ap->a_retval = NAME_MAX;
  732                 else
  733                         *ap->a_retval = 37;
  734                 return (0);
  735         case _PC_SYMLINK_MAX:
  736                 if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP) {
  737                         *ap->a_retval = MAXPATHLEN;
  738                         return (0);
  739                 }
  740                 return (EINVAL);
  741         case _PC_NO_TRUNC:
  742                 *ap->a_retval = 1;
  743                 return (0);
  744         default:
  745                 return (vop_stdpathconf(ap));
  746         }
  747         /* NOTREACHED */
  748 }
  749 
  750 /*
  751  * Vnode pointer to File handle
  752  */
  753 static int
  754 cd9660_vptofh(struct vop_vptofh_args *ap)
  755 {
  756         struct ifid ifh;
  757         struct iso_node *ip = VTOI(ap->a_vp);
  758 
  759         ifh.ifid_len = sizeof(struct ifid);
  760 
  761         ifh.ifid_ino = ip->i_number;
  762         ifh.ifid_start = ip->iso_start;
  763         /*
  764          * This intentionally uses sizeof(ifh) in order to not copy stack
  765          * garbage on ILP32.
  766          */
  767         memcpy(ap->a_fhp, &ifh, sizeof(ifh));
  768 
  769 #ifdef  ISOFS_DBG
  770         printf("vptofh: ino %jd, start %ld\n",
  771             (uintmax_t)ifh.ifid_ino, ifh.ifid_start);
  772 #endif
  773 
  774         return (0);
  775 }
  776 
  777 SYSCTL_NODE(_vfs, OID_AUTO, cd9660, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
  778     "cd9660 filesystem");
  779 static int use_buf_pager = 1;
  780 SYSCTL_INT(_vfs_cd9660, OID_AUTO, use_buf_pager, CTLFLAG_RWTUN,
  781     &use_buf_pager, 0,
  782     "Use buffer pager instead of bmap");
  783 
  784 static daddr_t
  785 cd9660_gbp_getblkno(struct vnode *vp, vm_ooffset_t off)
  786 {
  787 
  788         return (lblkno(VTOI(vp)->i_mnt, off));
  789 }
  790 
  791 static int
  792 cd9660_gbp_getblksz(struct vnode *vp, daddr_t lbn, long *sz)
  793 {
  794         struct iso_node *ip;
  795 
  796         ip = VTOI(vp);
  797         *sz = blksize(ip->i_mnt, ip, lbn);
  798         return (0);
  799 }
  800 
  801 static int
  802 cd9660_getpages(struct vop_getpages_args *ap)
  803 {
  804         struct vnode *vp;
  805 
  806         vp = ap->a_vp;
  807         if (vp->v_type == VCHR || vp->v_type == VBLK)
  808                 return (EOPNOTSUPP);
  809 
  810         if (use_buf_pager)
  811                 return (vfs_bio_getpages(vp, ap->a_m, ap->a_count,
  812                     ap->a_rbehind, ap->a_rahead, cd9660_gbp_getblkno,
  813                     cd9660_gbp_getblksz));
  814         return (vnode_pager_generic_getpages(vp, ap->a_m, ap->a_count,
  815             ap->a_rbehind, ap->a_rahead, NULL, NULL));
  816 }
  817 
  818 /*
  819  * Global vfs data structures for cd9660
  820  */
  821 struct vop_vector cd9660_vnodeops = {
  822         .vop_default =          &default_vnodeops,
  823         .vop_open =             cd9660_open,
  824         .vop_access =           cd9660_access,
  825         .vop_bmap =             cd9660_bmap,
  826         .vop_cachedlookup =     cd9660_lookup,
  827         .vop_getattr =          cd9660_getattr,
  828         .vop_inactive =         cd9660_inactive,
  829         .vop_ioctl =            cd9660_ioctl,
  830         .vop_lookup =           vfs_cache_lookup,
  831         .vop_pathconf =         cd9660_pathconf,
  832         .vop_read =             cd9660_read,
  833         .vop_readdir =          cd9660_readdir,
  834         .vop_readlink =         cd9660_readlink,
  835         .vop_reclaim =          cd9660_reclaim,
  836         .vop_setattr =          cd9660_setattr,
  837         .vop_strategy =         cd9660_strategy,
  838         .vop_vptofh =           cd9660_vptofh,
  839         .vop_getpages =         cd9660_getpages,
  840 };
  841 VFS_VOP_VECTOR_REGISTER(cd9660_vnodeops);
  842 
  843 /*
  844  * Special device vnode ops
  845  */
  846 
  847 struct vop_vector cd9660_fifoops = {
  848         .vop_default =          &fifo_specops,
  849         .vop_access =           cd9660_access,
  850         .vop_getattr =          cd9660_getattr,
  851         .vop_inactive =         cd9660_inactive,
  852         .vop_reclaim =          cd9660_reclaim,
  853         .vop_setattr =          cd9660_setattr,
  854         .vop_vptofh =           cd9660_vptofh,
  855 };
  856 VFS_VOP_VECTOR_REGISTER(cd9660_fifoops);

Cache object: 31c6c0338b2f5659232e4813a81251f7


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.