root/kern/include/kern/sfs.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
   3  *      The President and Fellows of Harvard College.
   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  * 3. Neither the name of the University nor the names of its contributors
  14  *    may be used to endorse or promote products derived from this software
  15  *    without specific prior written permission.
  16  *
  17  * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
  18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
  21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27  * SUCH DAMAGE.
  28  */
  29 
  30 #ifndef _KERN_SFS_H_
  31 #define _KERN_SFS_H_
  32 
  33 
  34 /*
  35  * SFS definitions visible to userspace. This covers the on-disk format
  36  * and is used by tools that work on SFS volumes, such as mksfs.
  37  */
  38 
  39 #define SFS_MAGIC         0xabadf001    /* magic number identifying us */
  40 #define SFS_BLOCKSIZE     512           /* size of our blocks */
  41 #define SFS_VOLNAME_SIZE  32            /* max length of volume name */
  42 #define SFS_NDIRECT       15            /* # of direct blocks in inode */
  43 #define SFS_DBPERIDB      128           /* # direct blks per indirect blk */
  44 #define SFS_NAMELEN       60            /* max length of filename */
  45 #define SFS_SB_LOCATION    0            /* block the superblock lives in */
  46 #define SFS_ROOT_LOCATION  1            /* loc'n of the root dir inode */
  47 #define SFS_MAP_LOCATION   2            /* 1st block of the freemap */
  48 #define SFS_NOINO          0            /* inode # for free dir entry */
  49 
  50 /* Number of bits in a block */
  51 #define SFS_BLOCKBITS (SFS_BLOCKSIZE * CHAR_BIT)
  52 
  53 /* Utility macro */
  54 #define SFS_ROUNDUP(a,b)       ((((a)+(b)-1)/(b))*b)
  55 
  56 /* Size of bitmap (in bits) */
  57 #define SFS_BITMAPSIZE(nblocks) SFS_ROUNDUP(nblocks, SFS_BLOCKBITS)
  58 
  59 /* Size of bitmap (in blocks) */
  60 #define SFS_BITBLOCKS(nblocks)  (SFS_BITMAPSIZE(nblocks)/SFS_BLOCKBITS)
  61 
  62 /* File types for sfi_type */
  63 #define SFS_TYPE_INVAL    0       /* Should not appear on disk */
  64 #define SFS_TYPE_FILE     1
  65 #define SFS_TYPE_DIR      2
  66 
  67 /*
  68  * On-disk superblock
  69  */
  70 struct sfs_super {
  71         uint32_t sp_magic;              /* Magic number, should be SFS_MAGIC */
  72         uint32_t sp_nblocks;                    /* Number of blocks in fs */
  73         char sp_volname[SFS_VOLNAME_SIZE];      /* Name of this volume */
  74         uint32_t reserved[118];
  75 };
  76 
  77 /*
  78  * On-disk inode
  79  */
  80 struct sfs_inode {
  81         uint32_t sfi_size;                      /* Size of this file (bytes) */
  82         uint16_t sfi_type;                      /* One of SFS_TYPE_* above */
  83         uint16_t sfi_linkcount;                 /* # hard links to this file */
  84         uint32_t sfi_direct[SFS_NDIRECT];       /* Direct blocks */
  85         uint32_t sfi_indirect;                  /* Indirect block */
  86         uint32_t sfi_waste[128-3-SFS_NDIRECT];  /* unused space, set to 0 */
  87 };
  88 
  89 /*
  90  * On-disk directory entry
  91  */
  92 struct sfs_dir {
  93         uint32_t sfd_ino;                       /* Inode number */
  94         char sfd_name[SFS_NAMELEN];             /* Filename */
  95 };
  96 
  97 
  98 #endif /* _KERN_SFS_H_ */

/* [<][>][^][v][top][bottom][index][help] */