1 // See COPYRIGHT for copyright information.
9 // Bytes per file system block - same as page size
10 #define BLKSIZE PGSIZE
12 // Maximum size of a filename (a single path component), including null
13 #define MAXNAMELEN 120
15 // Maximum size of a complete pathname, including null
16 #define MAXPATHLEN 1024
18 // Number of block pointers in an Inode
22 #define MAXFILESIZE (NDIRECT * BLKSIZE)
24 // Typedefs for block numbers and inode numbers
25 typedef int32_t blocknum_t
;
26 typedef int32_t inum_t
;
29 // File system directory entry (in memory and on disk)
31 inum_t de_inum
; // inode number of entry
32 int32_t de_namelen
; // length of filename
33 char de_name
[MAXNAMELEN
]; // filename
34 } __attribute__((packed
)); // required on some 64-bit machines
37 // File system super-block (in memory and on disk)
38 #define FS_MAGIC 0x4A0530AE // related vaguely to 'J\0S!'
41 uint32_t s_magic
; // Magic number: FS_MAGIC
42 blocknum_t s_nblocks
; // number of blocks in file system
43 inum_t s_ninodes
; // number of inodes in file system
45 struct Direntry s_root
; // directory entry for root
46 // (convenient to have around)
47 } __attribute__((packed
)); // required on some 64-bit machines
50 // File system inode (in memory and on disk; sizeof(struct Inode) == BLKSIZE)
52 uint32_t i_ftype
; // file type
53 uint32_t i_refcount
; // number of hard links
54 off_t i_size
; // file size in bytes
56 blocknum_t i_direct
[NDIRECT
]; // block pointers
58 // These fields only have meaning in memory:
59 inum_t i_inum
; // inode number
60 uint32_t i_opencount
; // number of memory references
61 uint32_t i_fsck_refcount
: 31; // used during fsck
62 unsigned i_fsck_checked
: 1;
63 } __attribute__((packed
)); // required on some 64-bit machines
65 // File types (Inode::i_type)
66 #define FTYPE_REG 1 // Regular file
67 #define FTYPE_DIR 2 // Directory
70 // Buffer cache requests
72 #define BCREQ_MAP 0 // Map this block without locking
73 #define BCREQ_MAP_RLOCK 1 // Map this block + shared lock
74 #define BCREQ_MAP_WLOCK 2 // Map this block + exclusive lock
75 #define BCREQ_UNLOCK 3 // Unlock previous RLOCK or WLOCK
76 #define BCREQ_FLUSH 4 // Flush this block's contents to disk
77 #define BCREQ_UNLOCK_FLUSH 5 // == UNLOCK + FLUSH
78 #define BCREQ_INITIALIZE 6 // Mark block as initialized
80 #define MAKE_BCREQ(blockno, reqtype) ((blockno << 4) | (reqtype))
81 #define BCREQ_BLOCKNUM(bcreq) (((bcreq) >> 4) & 0xFFFFFFF)
82 #define BCREQ_TYPE(bcreq) ((bcreq) & 0xF)
84 #endif /* !JOS_INC_FS_H */