Skip to content

fs.h

TIP

On-disk file system format. Both the kernel and user programs use this header file.

#define ROOTINO  1
#define BSIZE 1024

TIP

Disk layout: [ boot block | super block | log | inode blocks | free bit map | data blocks] mkfs computes the super block and builds an initial file system. The super block describes the disk layout:

struct superblock {
  uint magic;
  uint size;
  uint nblocks;
  uint ninodes;
  uint nlog;
  uint logstart;
  uint inodestart;
  uint bmapstart;
};

#define FSMAGIC 0x10203040

#define NDIRECT 12
#define NINDIRECT (BSIZE / sizeof(uint))
#define MAXFILE (NDIRECT + NINDIRECT)

TIP

On-disk inode structure

struct dinode {
  short type;
  short major;
  short minor;
  short nlink;
  uint size;
  uint addrs[NDIRECT+1];
};

TIP

Inodes per block.

#define IPB           (BSIZE / sizeof(struct dinode))

TIP

Block containing inode i

#define IBLOCK(i, sb)     ((i) / IPB + sb.inodestart)

TIP

Bitmap bits per block

#define BPB           (BSIZE*8)

TIP

Block of free map containing bit for block b

#define BBLOCK(b, sb) ((b)/BPB + sb.bmapstart)

TIP

Directory is a file containing a sequence of dirent structures.

#define DIRSIZ 14

struct dirent {
  ushort inum;
  char name[DIRSIZ];
};