xref: /xv6-public/fs.h (revision 2ce40d70)
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 };
17 
18 #define NADDRS (NDIRECT+1)
19 #define NDIRECT 12
20 #define INDIRECT 12
21 #define NINDIRECT (BSIZE / sizeof(uint))
22 #define MAXFILE (NDIRECT  + NINDIRECT)
23 
24 // On-disk inode structure
25 struct dinode {
26   short type;           // File type
27   short major;          // Major device number (T_DEV only)
28   short minor;          // Minor device number (T_DEV only)
29   short nlink;          // Number of links to inode in file system
30   uint size;            // Size of file (bytes)
31   uint addrs[NADDRS];   // Data block addresses
32 };
33 
34 #define T_DIR  1   // Directory
35 #define T_FILE 2   // File
36 #define T_DEV  3   // Special device
37 
38 // Inodes per block.
39 #define IPB           (BSIZE / sizeof(struct dinode))
40 
41 // Block containing inode i
42 #define IBLOCK(i)     ((i) / IPB + 2)
43 
44 // Bitmap bits per block
45 #define BPB           (BSIZE*8)
46 
47 // Block containing bit for block b
48 #define BBLOCK(b, ninodes) (b/BPB + (ninodes)/IPB + 3)
49 
50 // PAGEBREAK: 10
51 // Directory is a file containing a sequence of dirent structures.
52 #define DIRSIZ 14
53 
54 struct dirent {
55   ushort inum;
56   char name[DIRSIZ];
57 };
58 
59