fs.h (1516B)
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 // Blocks 2 through sb.ninodes/IPB hold inodes. 7 // Then free bitmap blocks holding sb.size bits. 8 // Then sb.nblocks data blocks. 9 // Then sb.nlog log blocks. 10 11 #define ROOTINO 1 // root i-number 12 #define BSIZE 512 // block size 13 14 // File system super block 15 struct superblock { 16 uint size; // Size of file system image (blocks) 17 uint nblocks; // Number of data blocks 18 uint ninodes; // Number of inodes. 19 uint nlog; // Number of log blocks 20 }; 21 22 #define NDIRECT 12 23 #define NINDIRECT (BSIZE / sizeof(uint)) 24 #define MAXFILE (NDIRECT + NINDIRECT) 25 26 // On-disk inode structure 27 struct dinode { 28 short type; // File type 29 short major; // Major device number (T_DEV only) 30 short minor; // Minor device number (T_DEV only) 31 short nlink; // Number of links to inode in file system 32 uint size; // Size of file (bytes) 33 uint addrs[NDIRECT+1]; // Data block addresses 34 }; 35 36 // Inodes per block. 37 #define IPB (BSIZE / sizeof(struct dinode)) 38 39 // Block containing inode i 40 #define IBLOCK(i) ((i) / IPB + 2) 41 42 // Bitmap bits per block 43 #define BPB (BSIZE*8) 44 45 // Block containing bit for block b 46 #define BBLOCK(b, ninodes) (b/BPB + (ninodes)/IPB + 3) 47 48 // Directory is a file containing a sequence of dirent structures. 49 #define DIRSIZ 14 50 51 struct dirent { 52 ushort inum; 53 char name[DIRSIZ]; 54 }; 55