2006-09-07 16:12:30 +02:00
|
|
|
// On-disk file system format.
|
2007-08-24 21:52:49 +02:00
|
|
|
// Both the kernel and user programs use this header file.
|
2006-09-07 16:12:30 +02:00
|
|
|
|
2011-10-11 12:41:37 +02:00
|
|
|
// Block 0 is unused.
|
|
|
|
// Block 1 is super block.
|
|
|
|
// Blocks 2 through sb.ninodes/IPB hold inodes.
|
|
|
|
// Then free bitmap blocks holding sb.size bits.
|
|
|
|
// Then sb.nblocks data blocks.
|
|
|
|
// Then sb.nlog log blocks.
|
2006-07-21 15:18:04 +02:00
|
|
|
|
2008-10-08 20:57:13 +02:00
|
|
|
#define ROOTINO 1 // root i-number
|
2006-08-09 03:09:36 +02:00
|
|
|
#define BSIZE 512 // block size
|
|
|
|
|
2006-09-07 16:12:30 +02:00
|
|
|
// File system super block
|
|
|
|
struct superblock {
|
2006-09-08 15:55:43 +02:00
|
|
|
uint size; // Size of file system image (blocks)
|
|
|
|
uint nblocks; // Number of data blocks
|
2006-09-07 16:12:30 +02:00
|
|
|
uint ninodes; // Number of inodes.
|
2011-07-28 02:35:46 +02:00
|
|
|
uint nlog; // Number of log blocks
|
2006-07-21 15:18:04 +02:00
|
|
|
};
|
|
|
|
|
2006-08-24 04:44:41 +02:00
|
|
|
#define NDIRECT 12
|
|
|
|
#define NINDIRECT (BSIZE / sizeof(uint))
|
2009-05-31 02:59:37 +02:00
|
|
|
#define MAXFILE (NDIRECT + NINDIRECT)
|
2006-07-21 15:18:04 +02:00
|
|
|
|
2006-09-07 16:12:30 +02:00
|
|
|
// On-disk inode structure
|
2006-07-21 15:18:04 +02:00
|
|
|
struct dinode {
|
2006-09-07 16:12:30 +02: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)
|
2009-05-31 02:59:37 +02:00
|
|
|
uint addrs[NDIRECT+1]; // Data block addresses
|
2006-07-21 15:18:04 +02:00
|
|
|
};
|
2006-08-08 20:07:37 +02:00
|
|
|
|
2006-09-07 16:12:30 +02:00
|
|
|
// 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 15:18:04 +02:00
|
|
|
|
2006-09-07 16:12:30 +02:00
|
|
|
// Block containing bit for block b
|
|
|
|
#define BBLOCK(b, ninodes) (b/BPB + (ninodes)/IPB + 3)
|
2006-07-21 15:18:04 +02:00
|
|
|
|
2006-09-08 16:31:17 +02:00
|
|
|
// Directory is a file containing a sequence of dirent structures.
|
2006-07-22 00:10:40 +02:00
|
|
|
#define DIRSIZ 14
|
|
|
|
|
2006-07-21 15:18:04 +02:00
|
|
|
struct dirent {
|
|
|
|
ushort inum;
|
2006-07-22 00:10:40 +02:00
|
|
|
char name[DIRSIZ];
|
2006-07-21 15:18:04 +02:00
|
|
|
};
|
2006-08-15 17:53:46 +02:00
|
|
|
|