xref: /xv6-public/fs.h (revision 41948359)
1 // On-disk file system format.
2 // This header is shared between kernel and user space.
3 
4 // Block 0 is unused.
5 // Block 1 is super block.
6 // Inodes start at block 2.
7 
8 #define BSIZE 512  // block size
9 
10 // File system super block
11 struct superblock {
12   uint size;         // Size of file system image (blocks)
13   uint nblocks;      // Number of data blocks
14   uint ninodes;      // Number of inodes.
15 };
16 
17 #define NADDRS (NDIRECT+1)
18 #define NDIRECT 12
19 #define INDIRECT 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[NADDRS];   // Data block addresses
31 };
32 
33 #define T_DIR  1   // Directory
34 #define T_FILE 2   // File
35 #define T_DEV  3   // Special device
36 
37 // Inodes per block.
38 #define IPB           (BSIZE / sizeof(struct dinode))
39 
40 // Block containing inode i
41 #define IBLOCK(i)     ((i) / IPB + 2)
42 
43 // Bitmap bits per block
44 #define BPB           (BSIZE*8)
45 
46 // Block containing bit for block b
47 #define BBLOCK(b, ninodes) (b/BPB + (ninodes)/IPB + 3)
48 
49 // PAGEBREAK: 10
50 // Directory is a file containing a sequence of dirent structures.
51 #define DIRSIZ 14
52 
53 struct dirent {
54   ushort inum;
55   char name[DIRSIZ];
56 };
57 
58 extern uint rootdev;  // Device number of root file system
59 
60