added base src
[xv6-db.git] / fs.h
blob1e6137bc3c51247c3ea0bddbf7d6ca6a616f035d
1 // On-disk file system format.
2 // Both the kernel and user programs use this header file.
4 // Block 0 is unused.
5 // Block 1 is super block.
6 // Inodes start at block 2.
8 #define ROOTINO 1 // root i-number
9 #define BSIZE 512 // block size
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.
18 #define NDIRECT 12
19 #define NINDIRECT (BSIZE / sizeof(uint))
20 #define MAXFILE (NDIRECT + NINDIRECT)
22 // On-disk inode structure
23 struct dinode {
24 short type; // File type
25 short major; // Major device number (T_DEV only)
26 short minor; // Minor device number (T_DEV only)
27 short nlink; // Number of links to inode in file system
28 uint size; // Size of file (bytes)
29 uint addrs[NDIRECT+1]; // Data block addresses
32 // Inodes per block.
33 #define IPB (BSIZE / sizeof(struct dinode))
35 // Block containing inode i
36 #define IBLOCK(i) ((i) / IPB + 2)
38 // Bitmap bits per block
39 #define BPB (BSIZE*8)
41 // Block containing bit for block b
42 #define BBLOCK(b, ninodes) (b/BPB + (ninodes)/IPB + 3)
44 // Directory is a file containing a sequence of dirent structures.
45 #define DIRSIZ 14
47 struct dirent {
48 ushort inum;
49 char name[DIRSIZ];