2016-08-25 13:13:00 +00:00
|
|
|
// On-disk file system format.
|
2007-08-24 19:52:49 +00:00
|
|
|
// Both the kernel and user programs use this header file.
|
2006-09-07 14:12:30 +00:00
|
|
|
|
2006-07-21 13:18:04 +00:00
|
|
|
|
2019-06-06 17:54:03 +00:00
|
|
|
#define ROOTINO 1 // root i-number
|
|
|
|
#define BSIZE 1024 // block size
|
2006-08-09 01:09:36 +00:00
|
|
|
|
2015-06-27 16:39:13 +00:00
|
|
|
// Disk layout:
|
2016-09-02 18:59:00 +00:00
|
|
|
// [ boot block | super block | log | inode blocks |
|
|
|
|
// free bit map | data blocks]
|
2015-06-27 16:39:13 +00:00
|
|
|
//
|
2016-09-02 18:59:00 +00:00
|
|
|
// mkfs computes the super block and builds an initial file system. The
|
|
|
|
// super block describes the disk layout:
|
2006-09-07 14:12:30 +00:00
|
|
|
struct superblock {
|
2019-06-04 09:57:47 +00:00
|
|
|
uint magic; // Must be FSMAGIC
|
2006-09-08 13:55:43 +00:00
|
|
|
uint size; // Size of file system image (blocks)
|
|
|
|
uint nblocks; // Number of data blocks
|
2006-09-07 14:12:30 +00:00
|
|
|
uint ninodes; // Number of inodes.
|
2011-07-28 00:35:46 +00:00
|
|
|
uint nlog; // Number of log blocks
|
2015-06-27 16:39:13 +00:00
|
|
|
uint logstart; // Block number of first log block
|
|
|
|
uint inodestart; // Block number of first inode block
|
|
|
|
uint bmapstart; // Block number of first free map block
|
2006-07-21 13:18:04 +00:00
|
|
|
};
|
|
|
|
|
2019-06-04 09:57:47 +00:00
|
|
|
#define FSMAGIC 0x10203040
|
|
|
|
|
2006-08-24 02:44:41 +00:00
|
|
|
#define NDIRECT 12
|
|
|
|
#define NINDIRECT (BSIZE / sizeof(uint))
|
2009-05-31 00:59:37 +00:00
|
|
|
#define MAXFILE (NDIRECT + NINDIRECT)
|
2006-07-21 13:18:04 +00:00
|
|
|
|
2006-09-07 14:12:30 +00:00
|
|
|
// On-disk inode structure
|
2006-07-21 13:18:04 +00:00
|
|
|
struct dinode {
|
2006-09-07 14:12:30 +00:00
|
|
|
short type; // File type
|
2019-06-13 14:29:27 +00:00
|
|
|
short major; // Major device number (T_DEVICE only)
|
|
|
|
short minor; // Minor device number (T_DEVICE only)
|
2006-09-07 14:12:30 +00:00
|
|
|
short nlink; // Number of links to inode in file system
|
|
|
|
uint size; // Size of file (bytes)
|
2009-05-31 00:59:37 +00:00
|
|
|
uint addrs[NDIRECT+1]; // Data block addresses
|
2006-07-21 13:18:04 +00:00
|
|
|
};
|
2006-08-08 18:07:37 +00:00
|
|
|
|
2006-09-07 14:12:30 +00:00
|
|
|
// Inodes per block.
|
|
|
|
#define IPB (BSIZE / sizeof(struct dinode))
|
|
|
|
|
|
|
|
// Block containing inode i
|
2015-06-27 16:39:13 +00:00
|
|
|
#define IBLOCK(i, sb) ((i) / IPB + sb.inodestart)
|
2006-09-07 14:12:30 +00:00
|
|
|
|
|
|
|
// Bitmap bits per block
|
|
|
|
#define BPB (BSIZE*8)
|
2006-07-21 13:18:04 +00:00
|
|
|
|
2015-06-27 16:39:13 +00:00
|
|
|
// Block of free map containing bit for block b
|
2019-06-06 17:54:03 +00:00
|
|
|
#define BBLOCK(b, sb) ((b)/BPB + sb.bmapstart)
|
2006-07-21 13:18:04 +00:00
|
|
|
|
2006-09-08 14:31:17 +00:00
|
|
|
// Directory is a file containing a sequence of dirent structures.
|
2006-07-21 22:10:40 +00:00
|
|
|
#define DIRSIZ 14
|
|
|
|
|
2006-07-21 13:18:04 +00:00
|
|
|
struct dirent {
|
|
|
|
ushort inum;
|
2006-07-21 22:10:40 +00:00
|
|
|
char name[DIRSIZ];
|
2006-07-21 13:18:04 +00:00
|
|
|
};
|
2006-08-15 15:53:46 +00:00
|
|
|
|