xref: /xv6-public/fs.h (revision 0c7f4838)
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 // Inodes per block.
35 #define IPB           (BSIZE / sizeof(struct dinode))
36 
37 // Block containing inode i
38 #define IBLOCK(i)     ((i) / IPB + 2)
39 
40 // Bitmap bits per block
41 #define BPB           (BSIZE*8)
42 
43 // Block containing bit for block b
44 #define BBLOCK(b, ninodes) (b/BPB + (ninodes)/IPB + 3)
45 
46 // PAGEBREAK: 10
47 // Directory is a file containing a sequence of dirent structures.
48 #define DIRSIZ 14
49 
50 struct dirent {
51   ushort inum;
52   char name[DIRSIZ];
53 };
54 
55