2006-09-07 14:12:30 +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
|
|
|
|
|
|
|
// Block 0 is unused.
|
|
|
|
// Block 1 is super block.
|
|
|
|
// Inodes start at block 2.
|
2006-07-21 13:18:04 +00:00
|
|
|
|
2006-08-09 01:09:36 +00:00
|
|
|
#define BSIZE 512 // block size
|
|
|
|
|
2006-09-07 14:12:30 +00:00
|
|
|
// File system super block
|
|
|
|
struct superblock {
|
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.
|
2006-07-21 13:18:04 +00:00
|
|
|
};
|
|
|
|
|
2006-08-25 01:11:30 +00:00
|
|
|
#define NADDRS (NDIRECT+1)
|
2006-08-24 02:44:41 +00:00
|
|
|
#define NDIRECT 12
|
|
|
|
#define INDIRECT 12
|
|
|
|
#define NINDIRECT (BSIZE / sizeof(uint))
|
|
|
|
#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
|
|
|
|
short major; // Major device number (T_DEV only)
|
|
|
|
short minor; // Minor device number (T_DEV only)
|
|
|
|
short nlink; // Number of links to inode in file system
|
|
|
|
uint size; // Size of file (bytes)
|
|
|
|
uint addrs[NADDRS]; // 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
|
|
|
#define T_DIR 1 // Directory
|
|
|
|
#define T_FILE 2 // File
|
|
|
|
#define T_DEV 3 // Special device
|
|
|
|
|
|
|
|
// Inodes per block.
|
|
|
|
#define IPB (BSIZE / sizeof(struct dinode))
|
|
|
|
|
|
|
|
// Block containing inode i
|
|
|
|
#define IBLOCK(i) ((i) / IPB + 2)
|
|
|
|
|
|
|
|
// Bitmap bits per block
|
|
|
|
#define BPB (BSIZE*8)
|
2006-07-21 13:18:04 +00:00
|
|
|
|
2006-09-07 14:12:30 +00:00
|
|
|
// Block containing bit for block b
|
|
|
|
#define BBLOCK(b, ninodes) (b/BPB + (ninodes)/IPB + 3)
|
2006-07-21 13:18:04 +00:00
|
|
|
|
2006-09-08 14:31:17 +00:00
|
|
|
// PAGEBREAK: 10
|
|
|
|
// 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
|
|
|
|