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