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/geom/geom_vol_ffs.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2002, 2003 Gordon Tetlow
    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/5.1/sys/geom/geom_vol_ffs.c 114518 2003-05-02 08:21:02Z phk $
   27  */
   28 
   29 #include <sys/param.h>
   30 #include <sys/errno.h>
   31 #include <sys/systm.h>
   32 #include <sys/kernel.h>
   33 #include <sys/malloc.h>
   34 #include <sys/bio.h>
   35 #include <sys/lock.h>
   36 #include <sys/mutex.h>
   37 
   38 #include <ufs/ufs/dinode.h>
   39 #include <ufs/ffs/fs.h>
   40 
   41 #include <geom/geom.h>
   42 #include <geom/geom_slice.h>
   43 
   44 #define VOL_FFS_CLASS_NAME "VOL_FFS"
   45 
   46 static int superblocks[] = SBLOCKSEARCH;
   47 
   48 struct g_vol_ffs_softc {
   49         char *  vol;
   50 };
   51 
   52 static int
   53 g_vol_ffs_start(struct bio *bp __unused)
   54 {
   55         return(0);
   56 }
   57 
   58 static struct g_geom *
   59 g_vol_ffs_taste(struct g_class *mp, struct g_provider *pp, int flags)
   60 {
   61         struct g_geom *gp;
   62         struct g_consumer *cp;
   63         struct g_vol_ffs_softc *ms;
   64         int error, sb, superblock;
   65         struct fs *fs;
   66 
   67         g_trace(G_T_TOPOLOGY, "vol_taste(%s,%s)", mp->name, pp->name);
   68         g_topology_assert();
   69 
   70         /* 
   71          * XXX This is a really weak way to make sure we don't recurse.
   72          * Probably ought to use BIO_GETATTR to check for this.
   73          */
   74         if (flags == G_TF_NORMAL &&
   75             !strcmp(pp->geom->class->name, VOL_FFS_CLASS_NAME))
   76                 return (NULL);
   77 
   78         gp = g_slice_new(mp, 1, pp, &cp, &ms, sizeof(*ms), g_vol_ffs_start);
   79         if (gp == NULL)
   80                 return (NULL);
   81         g_topology_unlock();
   82         /*
   83          * Walk through the standard places that superblocks hide and look
   84          * for UFS magic. If we find magic, then check that the size in the
   85          * superblock corresponds to the size of the underlying provider.
   86          * Finally, look for a volume label and create an appropriate 
   87          * provider based on that.
   88          */
   89         for (sb=0; (superblock = superblocks[sb]) != -1; sb++) {
   90                 fs = (struct fs *) g_read_data(cp, superblock,
   91                         SBLOCKSIZE, &error);
   92                 if (fs == NULL || error != 0)
   93                         continue;
   94                 /* Check for magic and make sure things are the right size */
   95                 if (fs->fs_magic == FS_UFS1_MAGIC) {
   96                         if (fs->fs_old_size * fs->fs_fsize !=
   97                             (int32_t) pp->mediasize) {
   98                                 g_free(fs);
   99                                 continue;
  100                         }
  101                 } else if (fs->fs_magic == FS_UFS2_MAGIC) {
  102                         if (fs->fs_size * fs->fs_fsize !=
  103                             (int64_t) pp->mediasize) {
  104                                 g_free(fs);
  105                                 continue;
  106                         }
  107                 } else {
  108                         g_free(fs);
  109                         continue;
  110                 }
  111                 /* Check for volume label */
  112                 if (fs->fs_volname[0] == '\0') {
  113                         g_free(fs);
  114                         continue;
  115                 }
  116                 /* XXX We need to check for namespace conflicts. */
  117                 /* XXX How do you handle a mirror set? */
  118                 /* XXX We don't validate the volume name. */
  119                 g_topology_lock();
  120                 /* Alright, we have a label and a volume name, reconfig. */
  121                 g_slice_config(gp, 0, G_SLICE_CONFIG_SET, (off_t) 0,
  122                     pp->mediasize, pp->sectorsize, "vol/%s",
  123                     fs->fs_volname);
  124                 g_free(fs);
  125                 g_topology_unlock();
  126                 break;
  127         }
  128         g_topology_lock();
  129         g_access_rel(cp, -1, 0, 0);
  130         if (LIST_EMPTY(&gp->provider)) {
  131                 g_slice_spoiled(cp);
  132                 return (NULL);
  133         }
  134         return (gp);
  135 }
  136 
  137 static struct g_class g_vol_ffs_class   = {
  138         .name = VOL_FFS_CLASS_NAME,
  139         .taste = g_vol_ffs_taste,
  140         G_CLASS_INITIALIZER
  141 };
  142 
  143 DECLARE_GEOM_CLASS(g_vol_ffs_class, g_vol_ffs);

Cache object: c94401d2644c0040d8ba74671f53309e


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