1 // On-disk file system format. 2 // Both the kernel and user programs use this header file. 3 4 // Block 0 is unused. 5 // Block 1 is super block. 6 // Inodes start at block 2. 7 8 #define ROOTINO 1 // root i-number 9 #define BSIZE 512 // block size 10 11 // File system super block 12 struct superblock { 13 uint size; // Size of file system image (blocks) 14 uint nblocks; // Number of data blocks 15 uint ninodes; // Number of inodes. 16 uint nlog; // Number of log blocks 17 }; 18 19 #define NDIRECT 12 20 #define NINDIRECT (BSIZE / sizeof(uint)) 21 #define MAXFILE (NDIRECT + NINDIRECT) 22 23 // On-disk inode structure 24 struct dinode { 25 short type; // File type 26 short major; // Major device number (T_DEV only) 27 short minor; // Minor device number (T_DEV only) 28 short nlink; // Number of links to inode in file system 29 uint size; // Size of file (bytes) 30 uint addrs[NDIRECT+1]; // Data block addresses 31 }; 32 33 // Inodes per block. 34 #define IPB (BSIZE / sizeof(struct dinode)) 35 36 // Block containing inode i 37 #define IBLOCK(i) ((i) / IPB + 2) 38 39 // Bitmap bits per block 40 #define BPB (BSIZE*8) 41 42 // Block containing bit for block b 43 #define BBLOCK(b, ninodes) (b/BPB + (ninodes)/IPB + 3) 44 45 // Directory is a file containing a sequence of dirent structures. 46 #define DIRSIZ 14 47 48 struct dirent { 49 ushort inum; 50 char name[DIRSIZ]; 51 }; 52 53