xv6-riscv-kernel/kernel/fs.h

63 lines
1.8 KiB
C
Raw Normal View History

#pragma once
#include "types.h"
// 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
2024-06-15 16:55:06 +02:00
#define ROOTINO 1 // root i-number
#define BSIZE 1024 // block size
2006-08-09 03:09:36 +02:00
// 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:
2006-09-07 16:12:30 +02:00
struct superblock {
2024-06-15 16:55:06 +02:00
u32 magic; // Must be FSMAGIC
u32 size; // Size of file system image (blocks)
u32 nblocks; // Number of data blocks
u32 ninodes; // Number of inodes.
u32 nlog; // Number of log blocks
u32 logstart; // Block number of first log block
u32 inodestart; // Block number of first inode block
u32 bmapstart; // Block number of first free map block
};
#define FSMAGIC 0x10203040
2024-06-15 16:55:06 +02:00
#define NDIRECT 12
2024-05-24 11:26:40 +02:00
#define NINDIRECT (BSIZE / sizeof(u32))
2024-06-15 16:55:06 +02:00
#define MAXFILE (NDIRECT + NINDIRECT)
2006-09-07 16:12:30 +02:00
// On-disk inode structure
struct dinode {
2024-06-15 16:55:06 +02:00
short type; // File type
short major; // Major device number (T_DEVICE only)
short minor; // Minor device number (T_DEVICE only)
short nlink; // Number of links to inode in file system
u32 size; // Size of file (bytes)
u32 addrs[NDIRECT + 1]; // Data block addresses
};
2006-08-08 20:07:37 +02:00
2006-09-07 16:12:30 +02:00
// Inodes per block.
2024-06-15 16:55:06 +02:00
#define IPB (BSIZE / sizeof(struct dinode))
2006-09-07 16:12:30 +02:00
// Block containing inode i
2024-06-15 16:55:06 +02:00
#define IBLOCK(i, sb) ((i) / IPB + sb.inodestart)
2006-09-07 16:12:30 +02:00
// Bitmap bits per block
2024-06-15 16:55:06 +02:00
#define BPB (BSIZE * 8)
// Block of free map containing bit for block b
2024-06-15 16:55:06 +02:00
#define BBLOCK(b, sb) ((b) / BPB + sb.bmapstart)
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
struct dirent {
2024-06-15 16:55:06 +02:00
u16 inum;
2006-07-22 00:10:40 +02:00
char name[DIRSIZ];
};