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/hpfs/hpfs_vfsops.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  * Copyright (c) 1998, 1999 Semen Ustimenko (semenu@FreeBSD.org)
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   24  * SUCH DAMAGE.
   25  *
   26  * $FreeBSD: releng/6.0/sys/fs/hpfs/hpfs_vfsops.c 150746 2005-09-30 06:26:42Z delphij $
   27  */
   28 
   29 
   30 #include <sys/param.h>
   31 #include <sys/systm.h>
   32 #include <sys/namei.h>
   33 #include <sys/conf.h>
   34 #include <sys/proc.h>
   35 #include <sys/kernel.h>
   36 #include <sys/vnode.h>
   37 #include <sys/mount.h>
   38 #include <sys/bio.h>
   39 #include <sys/buf.h>
   40 #include <sys/fcntl.h>
   41 #include <sys/malloc.h>
   42 
   43 #include <geom/geom.h>
   44 #include <geom/geom_vfs.h>
   45 
   46 #include <vm/vm.h>
   47 #include <vm/vm_param.h>
   48 #include <vm/vm_page.h>
   49 #include <vm/vm_object.h>
   50 #include <vm/vm_extern.h>
   51 
   52 #include <fs/hpfs/hpfs.h>
   53 #include <fs/hpfs/hpfsmount.h>
   54 #include <fs/hpfs/hpfs_subr.h>
   55 
   56 MALLOC_DEFINE(M_HPFSMNT, "HPFS mount", "HPFS mount structure");
   57 MALLOC_DEFINE(M_HPFSNO, "HPFS node", "HPFS node structure");
   58 
   59 struct sockaddr;
   60 
   61 static int      hpfs_mountfs(register struct vnode *, struct mount *, 
   62                                   struct thread *);
   63 
   64 static vfs_fhtovp_t     hpfs_fhtovp;
   65 static vfs_vget_t       hpfs_vget;
   66 static vfs_cmount_t     hpfs_cmount;
   67 static vfs_mount_t      hpfs_mount;
   68 static vfs_root_t       hpfs_root;
   69 static vfs_statfs_t     hpfs_statfs;
   70 static vfs_unmount_t    hpfs_unmount;
   71 static vfs_vptofh_t     hpfs_vptofh;
   72 
   73 static int
   74 hpfs_cmount ( 
   75         struct mntarg *ma,
   76         void *data,
   77         int flags,
   78         struct thread *td )
   79 {
   80         struct hpfs_args args;
   81         int error;
   82 
   83         error = copyin(data, (caddr_t)&args, sizeof (struct hpfs_args));
   84         if (error)
   85                 return (error);
   86 
   87         ma = mount_argsu(ma, "from", args.fspec, MAXPATHLEN);
   88         ma = mount_arg(ma, "export", &args.export, sizeof args.export);
   89         ma = mount_argf(ma, "uid", "%d", args.uid);
   90         ma = mount_argf(ma, "gid", "%d", args.gid);
   91         ma = mount_argf(ma, "mode", "%d", args.mode);
   92         if (args.flags & HPFSMNT_TABLES) {
   93                 ma = mount_arg(ma, "d2u", args.d2u, sizeof args.d2u);
   94                 ma = mount_arg(ma, "u2d", args.u2d, sizeof args.u2d);
   95         }
   96 
   97         error = kernel_mount(ma, flags);
   98 
   99         return (error);
  100 }
  101 
  102 static const char *hpfs_opts[] = {
  103         "from", "export", "uid", "gid", "mode", "d2u", "u2d", NULL
  104 };
  105 
  106 static int
  107 hpfs_mount ( 
  108         struct mount *mp,
  109         struct thread *td )
  110 {
  111         int             err = 0, error;
  112         struct vnode    *devvp;
  113         struct hpfsmount *hpmp = 0;
  114         struct nameidata ndp;
  115         struct export_args export;
  116         char *from;
  117 
  118         dprintf(("hpfs_omount():\n"));
  119         /*
  120          ***
  121          * Mounting non-root filesystem or updating a filesystem
  122          ***
  123          */
  124         if (vfs_filteropt(mp->mnt_optnew, hpfs_opts))
  125                 return (EINVAL);
  126 
  127         from = vfs_getopts(mp->mnt_optnew, "from", &error);
  128         if (error)
  129                 return (error);
  130 
  131         /*
  132          * If updating, check whether changing from read-only to
  133          * read/write; if there is no device name, that's all we do.
  134          */
  135         if (mp->mnt_flag & MNT_UPDATE) {
  136                 dprintf(("hpfs_omount: MNT_UPDATE: "));
  137 
  138                 hpmp = VFSTOHPFS(mp);
  139 
  140                 if (from == NULL) {
  141                         error = vfs_copyopt(mp->mnt_optnew, "export",
  142                             &export, sizeof export);
  143                         if (error)
  144                                 return (error);
  145                         dprintf(("export 0x%x\n",args.export.ex_flags));
  146                         err = vfs_export(mp, &export);
  147                         if (err) {
  148                                 printf("hpfs_omount: vfs_export failed %d\n",
  149                                         err);
  150                         }
  151                         goto success;
  152                 } else {
  153                         dprintf(("name [FAILED]\n"));
  154                         err = EINVAL;
  155                         goto success;
  156                 }
  157                 dprintf(("\n"));
  158         }
  159 
  160         /*
  161          * Not an update, or updating the name: look up the name
  162          * and verify that it refers to a sensible block device.
  163          */
  164         NDINIT(&ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, from, td);
  165         err = namei(&ndp);
  166         if (err) {
  167                 /* can't get devvp!*/
  168                 goto error_1;
  169         }
  170 
  171         devvp = ndp.ni_vp;
  172 
  173         if (!vn_isdisk(devvp, &err)) {
  174                 vput(devvp);
  175                 return (err);
  176         }
  177 
  178         /*
  179          ********************
  180          * NEW MOUNT
  181          ********************
  182          */
  183 
  184         /*
  185          * Since this is a new mount, we want the names for
  186          * the device and the mount point copied in.  If an
  187          * error occurs, the mountpoint is discarded by the
  188          * upper level code.  Note that vfs_omount() handles
  189          * copying the mountpoint f_mntonname for us, so we
  190          * don't have to do it here unless we want to set it
  191          * to something other than "path" for some rason.
  192          */
  193         /* Save "mounted from" info for mount point (NULL pad)*/
  194         vfs_mountedfrom(mp, from);
  195 
  196         err = hpfs_mountfs(devvp, mp, td);
  197         if (err) {
  198                 vrele(devvp);
  199                 goto error_1;
  200         }
  201 
  202         goto success;
  203 
  204 error_1:        /* no state to back out*/
  205         /* XXX: Missing NDFREE(&ndp, ...) */
  206 
  207 success:
  208         return( err);
  209 }
  210 
  211 /*
  212  * Common code for mount and mountroot
  213  */
  214 int
  215 hpfs_mountfs(devvp, mp, td)
  216         register struct vnode *devvp;
  217         struct mount *mp;
  218         struct thread *td;
  219 {
  220         int error, ronly, v;
  221         struct sublock *sup;
  222         struct spblock *spp;
  223         struct hpfsmount *hpmp;
  224         struct buf *bp = NULL;
  225         struct vnode *vp;
  226         struct cdev *dev = devvp->v_rdev;
  227         struct g_consumer *cp;
  228         struct bufobj *bo;
  229 
  230         if (mp->mnt_flag & MNT_ROOTFS)
  231                 return (EOPNOTSUPP);
  232         dprintf(("hpfs_mountfs():\n"));
  233         ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
  234         /* XXX: use VOP_ACCESS to check FS perms */
  235         DROP_GIANT();
  236         g_topology_lock();
  237         error = g_vfs_open(devvp, &cp, "hpfs", ronly ? 0 : 1);
  238         g_topology_unlock();
  239         PICKUP_GIANT();
  240         VOP_UNLOCK(devvp, 0, td);
  241         if (error)
  242                 return (error);
  243 
  244         bo = &devvp->v_bufobj;
  245         bo->bo_private = cp;
  246         bo->bo_ops = g_vfs_bufops;
  247 
  248         /*
  249          * Do actual mount
  250          */
  251         hpmp = malloc(sizeof(struct hpfsmount), M_HPFSMNT, M_WAITOK | M_ZERO);
  252 
  253         hpmp->hpm_cp = cp;
  254         hpmp->hpm_bo = bo;
  255 
  256         /* Read in SuperBlock */
  257         error = bread(devvp, SUBLOCK, SUSIZE, NOCRED, &bp);
  258         if (error)
  259                 goto failed;
  260         bcopy(bp->b_data, &hpmp->hpm_su, sizeof(struct sublock));
  261         brelse(bp); bp = NULL;
  262 
  263         /* Read in SpareBlock */
  264         error = bread(devvp, SPBLOCK, SPSIZE, NOCRED, &bp);
  265         if (error)
  266                 goto failed;
  267         bcopy(bp->b_data, &hpmp->hpm_sp, sizeof(struct spblock));
  268         brelse(bp); bp = NULL;
  269 
  270         sup = &hpmp->hpm_su;
  271         spp = &hpmp->hpm_sp;
  272 
  273         /* Check magic */
  274         if (sup->su_magic != SU_MAGIC) {
  275                 printf("hpfs_mountfs: SuperBlock MAGIC DOESN'T MATCH\n");
  276                 error = EINVAL;
  277                 goto failed;
  278         }
  279         if (spp->sp_magic != SP_MAGIC) {
  280                 printf("hpfs_mountfs: SpareBlock MAGIC DOESN'T MATCH\n");
  281                 error = EINVAL;
  282                 goto failed;
  283         }
  284 
  285         mp->mnt_data = (qaddr_t)hpmp;
  286         hpmp->hpm_devvp = devvp;
  287         hpmp->hpm_dev = devvp->v_rdev;
  288         hpmp->hpm_mp = mp;
  289         if (1 == vfs_scanopt(mp->mnt_optnew, "uid", "%d", &v))
  290                 hpmp->hpm_uid = v;
  291         if (1 == vfs_scanopt(mp->mnt_optnew, "gid", "%d", &v))
  292                 hpmp->hpm_gid = v;
  293         if (1 == vfs_scanopt(mp->mnt_optnew, "mode", "%d", &v))
  294                 hpmp->hpm_mode = v;
  295 
  296         error = hpfs_bminit(hpmp);
  297         if (error)
  298                 goto failed;
  299 
  300         error = hpfs_cpinit(mp, hpmp);
  301         if (error) {
  302                 hpfs_bmdeinit(hpmp);
  303                 goto failed;
  304         }
  305 
  306         error = hpfs_root(mp, LK_EXCLUSIVE, &vp, td);
  307         if (error) {
  308                 hpfs_cpdeinit(hpmp);
  309                 hpfs_bmdeinit(hpmp);
  310                 goto failed;
  311         }
  312 
  313         vput(vp);
  314 
  315         mp->mnt_stat.f_fsid.val[0] = (long)dev2udev(dev);
  316         mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
  317         mp->mnt_maxsymlinklen = 0;
  318         mp->mnt_flag |= MNT_LOCAL;
  319         return (0);
  320 
  321 failed:
  322         if (bp)
  323                 brelse (bp);
  324         mp->mnt_data = (qaddr_t)NULL;
  325         g_vfs_close(cp, td);
  326         return (error);
  327 }
  328 
  329 static int
  330 hpfs_unmount( 
  331         struct mount *mp,
  332         int mntflags,
  333         struct thread *td)
  334 {
  335         int error, flags, ronly;
  336         register struct hpfsmount *hpmp = VFSTOHPFS(mp);
  337 
  338         dprintf(("hpfs_unmount():\n"));
  339 
  340         ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
  341 
  342         flags = 0;
  343         if(mntflags & MNT_FORCE)
  344                 flags |= FORCECLOSE;
  345 
  346         dprintf(("hpfs_unmount: vflushing...\n"));
  347         
  348         error = vflush(mp, 0, flags, td);
  349         if (error) {
  350                 printf("hpfs_unmount: vflush failed: %d\n",error);
  351                 return (error);
  352         }
  353 
  354         vinvalbuf(hpmp->hpm_devvp, V_SAVE, td, 0, 0);
  355         g_vfs_close(hpmp->hpm_cp, td);
  356         vrele(hpmp->hpm_devvp);
  357 
  358         dprintf(("hpfs_umount: freeing memory...\n"));
  359         hpfs_cpdeinit(hpmp);
  360         hpfs_bmdeinit(hpmp);
  361         mp->mnt_data = (qaddr_t)0;
  362         mp->mnt_flag &= ~MNT_LOCAL;
  363         FREE(hpmp, M_HPFSMNT);
  364 
  365         return (0);
  366 }
  367 
  368 static int
  369 hpfs_root(
  370         struct mount *mp,
  371         int flags,
  372         struct vnode **vpp,
  373         struct thread *td )
  374 {
  375         int error = 0;
  376         struct hpfsmount *hpmp = VFSTOHPFS(mp);
  377 
  378         dprintf(("hpfs_root():\n"));
  379         error = VFS_VGET(mp, (ino_t)hpmp->hpm_su.su_rootfno, LK_EXCLUSIVE, vpp);
  380         if(error) {
  381                 printf("hpfs_root: VFS_VGET failed: %d\n",error);
  382                 return (error);
  383         }
  384 
  385         return (error);
  386 }
  387 
  388 static int
  389 hpfs_statfs(
  390         struct mount *mp,
  391         struct statfs *sbp,
  392         struct thread *td)
  393 {
  394         struct hpfsmount *hpmp = VFSTOHPFS(mp);
  395 
  396         dprintf(("hpfs_statfs(): HPFS%d.%d\n",
  397                 hpmp->hpm_su.su_hpfsver, hpmp->hpm_su.su_fnctver));
  398 
  399         sbp->f_type = mp->mnt_vfc->vfc_typenum;
  400         sbp->f_bsize = DEV_BSIZE;
  401         sbp->f_iosize = DEV_BSIZE;
  402         sbp->f_blocks = hpmp->hpm_su.su_btotal;
  403         sbp->f_bfree = sbp->f_bavail = hpmp->hpm_bavail;
  404         sbp->f_ffree = 0;
  405         sbp->f_files = 0;
  406         sbp->f_flags = mp->mnt_flag;
  407         
  408         return (0);
  409 }
  410 
  411 /*ARGSUSED*/
  412 static int
  413 hpfs_fhtovp(
  414         struct mount *mp,
  415         struct fid *fhp,
  416         struct vnode **vpp)
  417 {
  418         struct vnode *nvp;
  419         struct hpfid *hpfhp = (struct hpfid *)fhp;
  420         int error;
  421 
  422         if ((error = VFS_VGET(mp, hpfhp->hpfid_ino, LK_EXCLUSIVE, &nvp)) != 0) {
  423                 *vpp = NULLVP;
  424                 return (error);
  425         }
  426         /* XXX as unlink/rmdir/mkdir/creat are not currently possible
  427          * with HPFS, we don't need to check anything else for now */
  428         *vpp = nvp;
  429 
  430         return (0);
  431 }
  432 
  433 static int
  434 hpfs_vptofh(
  435         struct vnode *vp,
  436         struct fid *fhp)
  437 {
  438         register struct hpfsnode *hpp;
  439         register struct hpfid *hpfhp;
  440 
  441         hpp = VTOHP(vp);
  442         hpfhp = (struct hpfid *)fhp;
  443         hpfhp->hpfid_len = sizeof(struct hpfid);
  444         hpfhp->hpfid_ino = hpp->h_no;
  445         /* hpfhp->hpfid_gen = hpp->h_gen; */
  446         return (0);
  447 }
  448 
  449 static int
  450 hpfs_vget(
  451         struct mount *mp,
  452         ino_t ino,
  453         int flags,
  454         struct vnode **vpp) 
  455 {
  456         struct hpfsmount *hpmp = VFSTOHPFS(mp);
  457         struct vnode *vp;
  458         struct hpfsnode *hp;
  459         struct buf *bp;
  460         int error;
  461 
  462         dprintf(("hpfs_vget(0x%x): ",ino));
  463 
  464         error = vfs_hash_get(mp, ino, flags, curthread, vpp, NULL, NULL);
  465         if (error || *vpp != NULL)
  466                 return (error);
  467 
  468         *vpp = NULL;
  469         hp = NULL;
  470         vp = NULL;
  471 
  472         /*
  473          * We have to lock node creation for a while,
  474          * but then we have to call getnewvnode(), 
  475          * this may cause hpfs_reclaim() to be called,
  476          * this may need to VOP_VGET() parent dir for
  477          * update reasons, and if parent is not in
  478          * hash, we have to lock node creation...
  479          * To solve this, we MALLOC, getnewvnode and init while
  480          * not locked (probability of node appearence
  481          * at that time is little, and anyway - we'll
  482          * check for it).
  483          */
  484         MALLOC(hp, struct hpfsnode *, sizeof(struct hpfsnode), 
  485                 M_HPFSNO, M_WAITOK);
  486 
  487         error = getnewvnode("hpfs", hpmp->hpm_mp, &hpfs_vnodeops, &vp);
  488         if (error) {
  489                 printf("hpfs_vget: can't get new vnode\n");
  490                 FREE(hp, M_HPFSNO);
  491                 return (error);
  492         }
  493 
  494         dprintf(("prenew "));
  495 
  496         vp->v_data = hp;
  497 
  498         if (ino == (ino_t)hpmp->hpm_su.su_rootfno) 
  499                 vp->v_vflag |= VV_ROOT;
  500 
  501 
  502         mtx_init(&hp->h_interlock, "hpfsnode interlock", NULL, MTX_DEF);
  503 
  504         hp->h_flag = H_INVAL;
  505         hp->h_vp = vp;
  506         hp->h_hpmp = hpmp;
  507         hp->h_no = ino;
  508         hp->h_dev = hpmp->hpm_dev;
  509         hp->h_uid = hpmp->hpm_uid;
  510         hp->h_gid = hpmp->hpm_uid;
  511         hp->h_mode = hpmp->hpm_mode;
  512         hp->h_devvp = hpmp->hpm_devvp;
  513 
  514         error = vfs_hash_insert(vp, ino, flags, curthread, vpp, NULL, NULL);
  515         if (error || *vpp != NULL)
  516                 return (error);
  517 
  518         error = bread(hpmp->hpm_devvp, ino, FNODESIZE, NOCRED, &bp);
  519         if (error) {
  520                 printf("hpfs_vget: can't read ino %d\n",ino);
  521                 vput(vp);
  522                 return (error);
  523         }
  524         bcopy(bp->b_data, &hp->h_fn, sizeof(struct fnode));
  525         brelse(bp);
  526 
  527         if (hp->h_fn.fn_magic != FN_MAGIC) {
  528                 printf("hpfs_vget: MAGIC DOESN'T MATCH\n");
  529                 vput(vp);
  530                 return (EINVAL);
  531         }
  532 
  533         vp->v_type = hp->h_fn.fn_flag ? VDIR:VREG;
  534         hp->h_flag &= ~H_INVAL;
  535 
  536         *vpp = vp;
  537 
  538         return (0);
  539 }
  540 
  541 static struct vfsops hpfs_vfsops = {
  542         .vfs_fhtovp =           hpfs_fhtovp,
  543         .vfs_cmount =           hpfs_cmount,
  544         .vfs_mount =            hpfs_mount,
  545         .vfs_root =             hpfs_root,
  546         .vfs_statfs =           hpfs_statfs,
  547         .vfs_unmount =          hpfs_unmount,
  548         .vfs_vget =             hpfs_vget,
  549         .vfs_vptofh =           hpfs_vptofh,
  550 };
  551 VFS_SET(hpfs_vfsops, hpfs, 0);

Cache object: bfbc9a5e69f2ea9c2bc0f16454e89d73


[ 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.