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/ufs/ext2fs/ext2fs.h

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 /*      $NetBSD: ext2fs.h,v 1.15 2004/03/22 19:23:08 bouyer Exp $       */
    2 
    3 /*
    4  * Copyright (c) 1982, 1986, 1993
    5  *      The Regents of the University of California.  All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. Neither the name of the University nor the names of its contributors
   16  *    may be used to endorse or promote products derived from this software
   17  *    without specific prior written permission.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29  * SUCH DAMAGE.
   30  *
   31  *      @(#)fs.h        8.10 (Berkeley) 10/27/94
   32  *  Modified for ext2fs by Manuel Bouyer.
   33  */
   34 
   35 /*
   36  * Copyright (c) 1997 Manuel Bouyer.
   37  *
   38  * Redistribution and use in source and binary forms, with or without
   39  * modification, are permitted provided that the following conditions
   40  * are met:
   41  * 1. Redistributions of source code must retain the above copyright
   42  *    notice, this list of conditions and the following disclaimer.
   43  * 2. Redistributions in binary form must reproduce the above copyright
   44  *    notice, this list of conditions and the following disclaimer in the
   45  *    documentation and/or other materials provided with the distribution.
   46  * 3. All advertising materials mentioning features or use of this software
   47  *    must display the following acknowledgement:
   48  *      This product includes software developed by Manuel Bouyer.
   49  * 4. The name of the author may not be used to endorse or promote products
   50  *    derived from this software without specific prior written permission.
   51  *
   52  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   53  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   54  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   55  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   56  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   57  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   58  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   59  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   60  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   61  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   62  *
   63  *      @(#)fs.h        8.10 (Berkeley) 10/27/94
   64  *  Modified for ext2fs by Manuel Bouyer.
   65  */
   66 
   67 #ifndef _UFS_EXT2FS_EXT2FS_H_
   68 #define _UFS_EXT2FS_EXT2FS_H_
   69 
   70 #include <machine/bswap.h>
   71 
   72 /*
   73  * Each disk drive contains some number of file systems.
   74  * A file system consists of a number of cylinder groups.
   75  * Each cylinder group has inodes and data.
   76  *
   77  * A file system is described by its super-block, which in turn
   78  * describes the cylinder groups.  The super-block is critical
   79  * data and is replicated in each cylinder group to protect against
   80  * catastrophic loss.  This is done at `newfs' time and the critical
   81  * super-block data does not change, so the copies need not be
   82  * referenced further unless disaster strikes.
   83  *
   84  * The first boot and super blocks are given in absolute disk addresses.
   85  * The byte-offset forms are preferred, as they don't imply a sector size.
   86  */
   87 #define BBSIZE          1024
   88 #define SBSIZE          1024
   89 #define BBOFF           ((off_t)(0))
   90 #define SBOFF           ((off_t)(BBOFF + BBSIZE))
   91 #define BBLOCK          ((daddr_t)(0))
   92 #define SBLOCK          ((daddr_t)(BBLOCK + BBSIZE / DEV_BSIZE))
   93 
   94 /*
   95  * Addresses stored in inodes are capable of addressing blocks
   96  * XXX
   97  */
   98 
   99 /*
  100  * MINBSIZE is the smallest allowable block size.
  101  * MINBSIZE must be big enough to hold a cylinder group block,
  102  * thus changes to (struct cg) must keep its size within MINBSIZE.
  103  * Note that super blocks are always of size SBSIZE,
  104  * and that both SBSIZE and MAXBSIZE must be >= MINBSIZE.
  105  */
  106 #define LOG_MINBSIZE 10
  107 #define MINBSIZE        (1 << LOG_MINBSIZE)
  108 
  109 /*
  110  * The path name on which the file system is mounted is maintained
  111  * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in
  112  * the super block for this name.
  113  */
  114 #define MAXMNTLEN       512
  115 
  116 /*
  117  * MINFREE gives the minimum acceptable percentage of file system
  118  * blocks which may be free. If the freelist drops below this level
  119  * only the superuser may continue to allocate blocks. This may
  120  * be set to 0 if no reserve of free blocks is deemed necessary,
  121  * however throughput drops by fifty percent if the file system
  122  * is run at between 95% and 100% full; thus the minimum default
  123  * value of fs_minfree is 5%. However, to get good clustering
  124  * performance, 10% is a better choice. hence we use 10% as our
  125  * default value. With 10% free space, fragmentation is not a
  126  * problem, so we choose to optimize for time.
  127  */
  128 #define MINFREE         5
  129 
  130 /*
  131  * Super block for an ext2fs file system.
  132  */
  133 struct ext2fs {
  134         u_int32_t  e2fs_icount;         /* Inode count */
  135         u_int32_t  e2fs_bcount;         /* blocks count */
  136         u_int32_t  e2fs_rbcount;        /* reserved blocks count */
  137         u_int32_t  e2fs_fbcount;        /* free blocks count */
  138         u_int32_t  e2fs_ficount;        /* free inodes count */
  139         u_int32_t  e2fs_first_dblock;   /* first data block */
  140         u_int32_t  e2fs_log_bsize;      /* block size = 1024*(2^e2fs_log_bsize) */
  141         u_int32_t  e2fs_fsize;          /* fragment size */
  142         u_int32_t  e2fs_bpg;            /* blocks per group */
  143         u_int32_t  e2fs_fpg;            /* frags per group */
  144         u_int32_t  e2fs_ipg;            /* inodes per group */
  145         u_int32_t  e2fs_mtime;          /* mount time */
  146         u_int32_t  e2fs_wtime;          /* write time */
  147         u_int16_t  e2fs_mnt_count;      /* mount count */
  148         u_int16_t  e2fs_max_mnt_count;  /* max mount count */
  149         u_int16_t  e2fs_magic;          /* magic number */
  150         u_int16_t  e2fs_state;          /* file system state */
  151         u_int16_t  e2fs_beh;            /* behavior on errors */
  152         u_int16_t  e2fs_minrev;         /* minor revision level */
  153         u_int32_t  e2fs_lastfsck;       /* time of last fsck */
  154         u_int32_t  e2fs_fsckintv;       /* max time between fscks */
  155         u_int32_t  e2fs_creator;        /* creator OS */
  156         u_int32_t  e2fs_rev;            /* revision level */
  157         u_int16_t  e2fs_ruid;           /* default uid for reserved blocks */
  158         u_int16_t  e2fs_rgid;           /* default gid for reserved blocks */
  159         /* EXT2_DYNAMIC_REV superblocks */
  160         u_int32_t  e2fs_first_ino;      /* first non-reserved inode */
  161         u_int16_t  e2fs_inode_size;     /* size of inode structure */
  162         u_int16_t  e2fs_block_group_nr; /* block grp number of this sblk*/
  163         u_int32_t  e2fs_features_compat; /*  compatible feature set */
  164         u_int32_t  e2fs_features_incompat; /* incompatible feature set */
  165         u_int32_t  e2fs_features_rocompat; /* RO-compatible feature set */
  166         u_int8_t   e2fs_uuid[16];       /* 128-bit uuid for volume */
  167         char       e2fs_vname[16];      /* volume name */
  168         char       e2fs_fsmnt[64];      /* name mounted on */
  169         u_int32_t  e2fs_algo;           /* For compression */
  170         u_int8_t   e2fs_prealloc;       /* # of blocks to preallocate */
  171         u_int8_t   e2fs_dir_prealloc;   /* # of blocks to preallocate for dir */
  172         u_int16_t  pad1;
  173         u_int32_t  reserved2[204];
  174 };
  175 
  176 
  177 /* in-memory data for ext2fs */
  178 struct m_ext2fs {
  179         struct ext2fs e2fs;
  180         u_char  e2fs_fsmnt[MAXMNTLEN];  /* name mounted on */
  181         int8_t  e2fs_ronly;     /* mounted read-only flag */
  182         int8_t  e2fs_fmod;      /* super block modified flag */
  183         int32_t e2fs_bsize;     /* block size */
  184         int32_t e2fs_bshift;    /* ``lblkno'' calc of logical blkno */
  185         int32_t e2fs_bmask;     /* ``blkoff'' calc of blk offsets */
  186         int64_t e2fs_qbmask;    /* ~fs_bmask - for use with quad size */
  187         int32_t e2fs_fsbtodb;   /* fsbtodb and dbtofsb shift constant */
  188         int32_t e2fs_ncg;       /* number of cylinder groups */
  189         int32_t e2fs_ngdb;      /* number of group descriptor block */
  190         int32_t e2fs_ipb;       /* number of inodes per block */
  191         int32_t e2fs_itpg;      /* number of inode table per group */
  192         struct  ext2_gd *e2fs_gd; /* group descripors */
  193 };
  194 
  195 
  196 
  197 /*
  198  * Filesystem identification
  199  */
  200 #define E2FS_MAGIC      0xef53  /* the ext2fs magic number */
  201 #define E2FS_REV0       0       /* revision levels */
  202 #define E2FS_REV1       1       /* revision levels */
  203 
  204 /* compatible/imcompatible features */
  205 #define EXT2F_COMPAT_PREALLOC           0x0001
  206 
  207 #define EXT2F_ROCOMPAT_SPARSESUPER      0x0001
  208 #define EXT2F_ROCOMPAT_LARGEFILE        0x0002
  209 #define EXT2F_ROCOMPAT_BTREE_DIR        0x0004
  210 
  211 #define EXT2F_INCOMPAT_COMP             0x0001
  212 #define EXT2F_INCOMPAT_FTYPE            0x0002
  213 
  214 /* features supported in this implementation */
  215 #define EXT2F_COMPAT_SUPP               0x0000
  216 #define EXT2F_ROCOMPAT_SUPP             EXT2F_ROCOMPAT_SPARSESUPER
  217 #define EXT2F_INCOMPAT_SUPP             EXT2F_INCOMPAT_FTYPE
  218 
  219 /*
  220  * OS identification
  221  */
  222 #define E2FS_OS_LINUX 0
  223 #define E2FS_OS_HURD  1
  224 #define E2FS_OS_MASIX 2
  225 
  226 /*
  227  * Filesystem clean flags
  228  */
  229 #define E2FS_ISCLEAN    0x01
  230 #define E2FS_ERRORS     0x02
  231 
  232 /* ext2 file system block group descriptor */
  233 
  234 struct ext2_gd {
  235         u_int32_t ext2bgd_b_bitmap;     /* blocks bitmap block */
  236         u_int32_t ext2bgd_i_bitmap;     /* inodes bitmap block */
  237         u_int32_t ext2bgd_i_tables;     /* inodes table block  */
  238         u_int16_t ext2bgd_nbfree;       /* number of free blocks */
  239         u_int16_t ext2bgd_nifree;       /* number of free inodes */
  240         u_int16_t ext2bgd_ndirs;        /* number of directories */
  241         u_int16_t reserved;
  242         u_int32_t reserved2[3];
  243 
  244 };
  245 
  246 
  247 /*
  248  * If the EXT2F_ROCOMPAT_SPARSESUPER flag is set, the cylinder group has a
  249  * copy of the super and cylinder group descriptors blocks only if it's
  250  * a power of 3, 5 or 7
  251  */
  252 
  253 static __inline__ int cg_has_sb __P((int)) __attribute__((__unused__));
  254 static __inline int
  255 cg_has_sb(i)
  256         int i;
  257 {
  258         int a3 ,a5 , a7;
  259 
  260         if (i == 0 || i == 1)
  261                 return 1;
  262         for (a3 = 3, a5 = 5, a7 = 7;
  263             a3 <= i || a5 <= i || a7 <= i;
  264             a3 *= 3, a5 *= 5, a7 *= 7)
  265                 if (i == a3 || i == a5 || i == a7)
  266                         return 1;
  267         return 0;
  268 }
  269 
  270 /* EXT2FS metadatas are stored in little-endian byte order. These macros
  271  * helps reading theses metadatas
  272  */
  273 
  274 #if BYTE_ORDER == LITTLE_ENDIAN
  275 #       define h2fs16(x) (x)
  276 #       define h2fs32(x) (x)
  277 #       define h2fs64(x) (x)
  278 #       define fs2h16(x) (x)
  279 #       define fs2h32(x) (x)
  280 #       define fs2h64(x) (x)
  281 #       define e2fs_sbload(old, new) memcpy((new), (old), SBSIZE);
  282 #       define e2fs_cgload(old, new, size) memcpy((new), (old), (size));
  283 #       define e2fs_sbsave(old, new) memcpy((new), (old), SBSIZE);
  284 #       define e2fs_cgsave(old, new, size) memcpy((new), (old), (size));
  285 #else
  286 void e2fs_sb_bswap __P((struct ext2fs *, struct ext2fs *));
  287 void e2fs_cg_bswap __P((struct ext2_gd *, struct ext2_gd *, int));
  288 #       define h2fs16(x) bswap16(x)
  289 #       define h2fs32(x) bswap32(x)
  290 #       define h2fs64(x) bswap64(x)
  291 #       define fs2h16(x) bswap16(x)
  292 #       define fs2h32(x) bswap32(x)
  293 #       define fs2h64(x) bswap64(x)
  294 #       define e2fs_sbload(old, new) e2fs_sb_bswap((old), (new))
  295 #       define e2fs_cgload(old, new, size) e2fs_cg_bswap((old), (new), (size));
  296 #       define e2fs_sbsave(old, new) e2fs_sb_bswap((old), (new))
  297 #       define e2fs_cgsave(old, new, size) e2fs_cg_bswap((old), (new), (size));
  298 #endif
  299 
  300 /*
  301  * Turn file system block numbers into disk block addresses.
  302  * This maps file system blocks to device size blocks.
  303  */
  304 #define fsbtodb(fs, b)  ((b) << (fs)->e2fs_fsbtodb)
  305 #define dbtofsb(fs, b)  ((b) >> (fs)->e2fs_fsbtodb)
  306 
  307 /*
  308  * Macros for handling inode numbers:
  309  *       inode number to file system block offset.
  310  *       inode number to cylinder group number.
  311  *       inode number to file system block address.
  312  */
  313 #define ino_to_cg(fs, x)        (((x) - 1) / (fs)->e2fs.e2fs_ipg)
  314 #define ino_to_fsba(fs, x)                                              \
  315         ((fs)->e2fs_gd[ino_to_cg(fs, x)].ext2bgd_i_tables + \
  316         (((x)-1) % (fs)->e2fs.e2fs_ipg)/(fs)->e2fs_ipb)
  317 #define ino_to_fsbo(fs, x)      (((x)-1) % (fs)->e2fs_ipb)
  318 
  319 /*
  320  * Give cylinder group number for a file system block.
  321  * Give cylinder group block number for a file system block.
  322  */
  323 #define dtog(fs, d) (((d) - (fs)->e2fs.e2fs_first_dblock) / (fs)->e2fs.e2fs_fpg)
  324 #define dtogd(fs, d) \
  325         (((d) - (fs)->e2fs.e2fs_first_dblock) % (fs)->e2fs.e2fs_fpg)
  326 
  327 /*
  328  * The following macros optimize certain frequently calculated
  329  * quantities by using shifts and masks in place of divisions
  330  * modulos and multiplications.
  331  */
  332 #define blkoff(fs, loc)         /* calculates (loc % fs->e2fs_bsize) */ \
  333         ((loc) & (fs)->e2fs_qbmask)
  334 #define lblktosize(fs, blk)     /* calculates (blk * fs->e2fs_bsize) */ \
  335         ((blk) << (fs)->e2fs_bshift)
  336 #define lblkno(fs, loc)         /* calculates (loc / fs->e2fs_bsize) */ \
  337         ((loc) >> (fs)->e2fs_bshift)
  338 #define blkroundup(fs, size)    /* calculates roundup(size, fs->e2fs_bsize) */ \
  339         (((size) + (fs)->e2fs_qbmask) & (fs)->e2fs_bmask)
  340 #define fragroundup(fs, size)   /* calculates roundup(size, fs->e2fs_bsize) */ \
  341         (((size) + (fs)->e2fs_qbmask) & (fs)->e2fs_bmask)
  342 /* 
  343  * Determine the number of available frags given a
  344  * percentage to hold in reserve.
  345  */   
  346 #define freespace(fs) \
  347    ((fs)->e2fs.e2fs_fbcount - (fs)->e2fs.e2fs_rbcount) 
  348 
  349 /*
  350  * Number of indirects in a file system block.
  351  */
  352 #define NINDIR(fs)      ((fs)->e2fs_bsize / sizeof(u_int32_t))
  353 
  354 #endif /* !_UFS_EXT2FS_EXT2FS_H_ */

Cache object: cba7e4ef881b11038cda7bb16c37de1e


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