kernel/fs.h

62 lines
1// On-disk file system format.2// Both the kernel and user programs use this header file.345#define ROOTINO  1   // root i-number6#define BSIZE 1024  // block size78// Disk layout:9// [ boot block | super block | log | inode blocks |10//                                          free bit map | data blocks]11//12// mkfs computes the super block and builds an initial file system. The13// super block describes the disk layout:14struct superblock {15  uint magic;        // Must be FSMAGIC16  uint size;         // Size of file system image (blocks)17  uint nblocks;      // Number of data blocks18  uint ninodes;      // Number of inodes.19  uint nlog;         // Number of log blocks20  uint logstart;     // Block number of first log block21  uint inodestart;   // Block number of first inode block22  uint bmapstart;    // Block number of first free map block23};2425#define FSMAGIC 0x102030402627#define NDIRECT 1228#define NINDIRECT (BSIZE / sizeof(uint))29#define MAXFILE (NDIRECT + NINDIRECT)3031// On-disk inode structure32struct dinode {33  short type;           // File type34  short major;          // Major device number (T_DEVICE only)35  short minor;          // Minor device number (T_DEVICE only)36  short nlink;          // Number of links to inode in file system37  uint size;            // Size of file (bytes)38  uint addrs[NDIRECT+1];   // Data block addresses39};4041// Inodes per block.42#define IPB           (BSIZE / sizeof(struct dinode))4344// Block containing inode i45#define IBLOCK(i, sb)     ((i) / IPB + sb.inodestart)4647// Bitmap bits per block48#define BPB           (BSIZE*8)4950// Block of free map containing bit for block b51#define BBLOCK(b, sb) ((b)/BPB + sb.bmapstart)5253// Directory is a file containing a sequence of dirent structures.54#define DIRSIZ 145556// The name field may have DIRSIZ characters and not end in a NUL57// character.58struct dirent {59  ushort inum;60  char name[DIRSIZ] __attribute__((nonstring));61};6263