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/label/g_label_ufs.c

Version: -  FREEBSD  -  FREEBSD11  -  FREEBSD10  -  FREEBSD9  -  FREEBSD92  -  FREEBSD91  -  FREEBSD90  -  FREEBSD8  -  FREEBSD82  -  FREEBSD81  -  FREEBSD80  -  FREEBSD7  -  FREEBSD74  -  FREEBSD73  -  FREEBSD72  -  FREEBSD71  -  FREEBSD70  -  FREEBSD6  -  FREEBSD64  -  FREEBSD63  -  FREEBSD62  -  FREEBSD61  -  FREEBSD60  -  FREEBSD5  -  FREEBSD55  -  FREEBSD54  -  FREEBSD53  -  FREEBSD52  -  FREEBSD51  -  FREEBSD50  -  FREEBSD4  -  FREEBSD3  -  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  * Copyright (c) 2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
    4  * All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  *
   15  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
   16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
   19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   25  * SUCH DAMAGE.
   26  */
   27 
   28 #include <sys/cdefs.h>
   29 __FBSDID("$FreeBSD: src/sys/geom/label/g_label_ufs.c,v 1.3.2.3 2006/03/08 14:20:14 pjd Exp $");
   30 
   31 #include <sys/param.h>
   32 #include <sys/systm.h>
   33 #include <sys/kernel.h>
   34 #include <sys/malloc.h>
   35 
   36 #include <ufs/ufs/dinode.h>
   37 #include <ufs/ffs/fs.h>
   38 
   39 #include <geom/geom.h>
   40 #include <geom/label/g_label.h>
   41 
   42 #define G_LABEL_UFS_DIR "ufs"
   43 
   44 static const int superblocks[] = SBLOCKSEARCH;
   45 
   46 static void
   47 g_label_ufs_taste(struct g_consumer *cp, char *label, size_t size)
   48 {
   49         struct g_provider *pp;
   50         int sb, superblock;
   51         struct fs *fs;
   52 
   53         g_topology_assert_not();
   54         pp = cp->provider;
   55         label[0] = '\0';
   56 
   57         if (SBLOCKSIZE % cp->provider->sectorsize != 0)
   58                 return;
   59 
   60         /*
   61          * Walk through the standard places that superblocks hide and look
   62          * for UFS magic. If we find magic, then check that the size in the
   63          * superblock corresponds to the size of the underlying provider.
   64          * Finally, look for a volume label and create an appropriate
   65          * provider based on that.
   66          */
   67         for (sb = 0; (superblock = superblocks[sb]) != -1; sb++) {
   68                 /*
   69                  * Take care not to issue an invalid I/O request. The offset of
   70                  * the superblock candidate must be multiples of the provider's
   71                  * sector size, otherwise an FFS can't exist on the provider
   72                  * anyway.
   73                  */
   74                 if (superblock % cp->provider->sectorsize != 0)
   75                         continue;
   76 
   77                 fs = (struct fs *)g_read_data(cp, superblock, SBLOCKSIZE, NULL);
   78                 if (fs == NULL)
   79                         continue;
   80                 /* Check for magic and make sure things are the right size */
   81                 if (fs->fs_magic == FS_UFS1_MAGIC &&
   82                     fs->fs_old_size * fs->fs_fsize == (int32_t)pp->mediasize) {
   83                         /* Valid UFS1. */
   84                 } else if (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_fsize > 0 &&
   85                     pp->mediasize / fs->fs_fsize == fs->fs_size) {
   86                         /* Valid UFS2. */
   87                 } else {
   88                         g_free(fs);
   89                         continue;
   90                 }
   91                 if (fs->fs_sblockloc != superblock || fs->fs_ncg < 1 ||
   92                     fs->fs_bsize < MINBSIZE ||
   93                     fs->fs_bsize < sizeof(struct fs)) {
   94                         g_free(fs);
   95                         continue;
   96                 }
   97                 G_LABEL_DEBUG(1, "%s file system detected on %s.",
   98                     fs->fs_magic == FS_UFS1_MAGIC ? "UFS1" : "UFS2", pp->name);
   99                 /* Check for volume label */
  100                 if (fs->fs_volname[0] == '\0') {
  101                         g_free(fs);
  102                         continue;
  103                 }
  104                 strlcpy(label, fs->fs_volname, size);
  105                 g_free(fs);
  106                 break;
  107         }
  108 }
  109 
  110 const struct g_label_desc g_label_ufs = {
  111         .ld_taste = g_label_ufs_taste,
  112         .ld_dir = G_LABEL_UFS_DIR
  113 };

Cache object: 55eb049de7e9c60689d7e05df62580d4


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