os161-1.99
 All Data Structures
sfs.h
00001 /*
00002  * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
00003  *      The President and Fellows of Harvard College.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00030 #ifndef _KERN_SFS_H_
00031 #define _KERN_SFS_H_
00032 
00033 
00034 /*
00035  * SFS definitions visible to userspace. This covers the on-disk format
00036  * and is used by tools that work on SFS volumes, such as mksfs.
00037  */
00038 
00039 #define SFS_MAGIC         0xabadf001    /* magic number identifying us */
00040 #define SFS_BLOCKSIZE     512           /* size of our blocks */
00041 #define SFS_VOLNAME_SIZE  32            /* max length of volume name */
00042 #define SFS_NDIRECT       15            /* # of direct blocks in inode */
00043 #define SFS_DBPERIDB      128           /* # direct blks per indirect blk */
00044 #define SFS_NAMELEN       60            /* max length of filename */
00045 #define SFS_SB_LOCATION    0            /* block the superblock lives in */
00046 #define SFS_ROOT_LOCATION  1            /* loc'n of the root dir inode */
00047 #define SFS_MAP_LOCATION   2            /* 1st block of the freemap */
00048 #define SFS_NOINO          0            /* inode # for free dir entry */
00049 
00050 /* Number of bits in a block */
00051 #define SFS_BLOCKBITS (SFS_BLOCKSIZE * CHAR_BIT)
00052 
00053 /* Utility macro */
00054 #define SFS_ROUNDUP(a,b)       ((((a)+(b)-1)/(b))*b)
00055 
00056 /* Size of bitmap (in bits) */
00057 #define SFS_BITMAPSIZE(nblocks) SFS_ROUNDUP(nblocks, SFS_BLOCKBITS)
00058 
00059 /* Size of bitmap (in blocks) */
00060 #define SFS_BITBLOCKS(nblocks)  (SFS_BITMAPSIZE(nblocks)/SFS_BLOCKBITS)
00061 
00062 /* File types for sfi_type */
00063 #define SFS_TYPE_INVAL    0       /* Should not appear on disk */
00064 #define SFS_TYPE_FILE     1
00065 #define SFS_TYPE_DIR      2
00066 
00067 /*
00068  * On-disk superblock
00069  */
00070 struct sfs_super {
00071         uint32_t sp_magic;              /* Magic number, should be SFS_MAGIC */
00072         uint32_t sp_nblocks;                    /* Number of blocks in fs */
00073         char sp_volname[SFS_VOLNAME_SIZE];      /* Name of this volume */
00074         uint32_t reserved[118];
00075 };
00076 
00077 /*
00078  * On-disk inode
00079  */
00080 struct sfs_inode {
00081         uint32_t sfi_size;                      /* Size of this file (bytes) */
00082         uint16_t sfi_type;                      /* One of SFS_TYPE_* above */
00083         uint16_t sfi_linkcount;                 /* # hard links to this file */
00084         uint32_t sfi_direct[SFS_NDIRECT];       /* Direct blocks */
00085         uint32_t sfi_indirect;                  /* Indirect block */
00086         uint32_t sfi_waste[128-3-SFS_NDIRECT];  /* unused space, set to 0 */
00087 };
00088 
00089 /*
00090  * On-disk directory entry
00091  */
00092 struct sfs_dir {
00093         uint32_t sfd_ino;                       /* Inode number */
00094         char sfd_name[SFS_NAMELEN];             /* Filename */
00095 };
00096 
00097 
00098 #endif /* _KERN_SFS_H_ */
 All Data Structures