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