root/kernel/fs.h

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

INCLUDED FROM


   1 // On-disk file system format.
   2 // Both the kernel and user programs use this header file.
   3 
   4 #define ROOTINO 1    // root i-number
   5 #define BSIZE   1024 // block size
   6 
   7 // Disk layout:
   8 // [ boot block | super block | log | inode blocks |
   9 //                                          free bit map | data blocks]
  10 //
  11 // mkfs computes the super block and builds an initial file system. The
  12 // super block describes the disk layout:
  13 struct superblock {
  14   uint magic;      // Must be FSMAGIC
  15   uint size;       // Size of file system image (blocks)
  16   uint nblocks;    // Number of data blocks
  17   uint ninodes;    // Number of inodes.
  18   uint nlog;       // Number of log blocks
  19   uint logstart;   // Block number of first log block
  20   uint inodestart; // Block number of first inode block
  21   uint bmapstart;  // Block number of first free map block
  22 };
  23 
  24 #define FSMAGIC 0x10203040
  25 
  26 #define NDIRECT   12
  27 #define NINDIRECT (BSIZE / sizeof(uint))
  28 #define MAXFILE   (NDIRECT + NINDIRECT)
  29 #define NLINK_MAX 32767 // nlink is a short; refuse links past its maximum
  30 
  31 // On-disk inode structure
  32 struct dinode {
  33   short type;              // File type
  34   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 system
  37   uint size;               // Size of file (bytes)
  38   uint addrs[NDIRECT + 1]; // Data block addresses
  39 };
  40 
  41 // Inodes per block.
  42 #define IPB (BSIZE / sizeof(struct dinode))
  43 
  44 // Block containing inode i
  45 #define IBLOCK(i, sb) ((i) / IPB + sb.inodestart)
  46 
  47 // Bitmap bits per block
  48 #define BPB (BSIZE * 8)
  49 
  50 // Block of free map containing bit for block b
  51 #define BBLOCK(b, sb) ((b) / BPB + sb.bmapstart)
  52 
  53 // Directory is a file containing a sequence of dirent structures.
  54 #define DIRSIZ 14
  55 
  56 // The name field may have DIRSIZ characters and not end in a NUL
  57 // character.
  58 struct dirent {
  59   ushort inum;
  60   char name[DIRSIZ] __attribute__((nonstring));
  61 };

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