read race fixed.
[mit-jos.git] / inc / fs.h
blob04a3a2b91747e22b23d0784eb44304b7613adb82
1 // See COPYRIGHT for copyright information.
3 #ifndef JOS_INC_FS_H
4 #define JOS_INC_FS_H
6 #include <inc/types.h>
8 // File nodes (both in-memory and on-disk)
10 // Bytes per file system block - same as page size
11 #define BLKSIZE PGSIZE
12 #define BLKBITSIZE (BLKSIZE * 8)
14 // Maximum size of a filename (a single path component), including null
15 // Must be a multiple of 4
16 #define MAXNAMELEN 128
18 // Maximum size of a complete pathname, including null
19 #define MAXPATHLEN 1024
21 // Number of block pointers in a File descriptor
22 #define NDIRECT 10
23 // Number of direct block pointers in an indirect block
24 #define NINDIRECT (BLKSIZE / 4)
26 #define MAXFILESIZE (NINDIRECT * BLKSIZE)
28 struct File {
29 char f_name[MAXNAMELEN]; // filename
30 off_t f_size; // file size in bytes
31 uint32_t f_type; // file type
33 // Block pointers.
34 // A block is allocated iff its value is != 0.
35 uint32_t f_direct[NDIRECT]; // direct blocks
36 uint32_t f_indirect; // indirect block
38 // Points to the directory in which this file lives.
39 // Meaningful only in memory; the value on disk can be garbage.
40 // dir_lookup() sets the value when required.
41 struct File *f_dir;
43 // Pad out to 256 bytes; must do arithmetic in case we're compiling
44 // fsformat on a 64-bit machine.
45 uint8_t f_pad[256 - MAXNAMELEN - 8 - 4*NDIRECT - 4 - sizeof(struct File*)];
46 } __attribute__((packed)); // required only on some 64-bit machines
48 // An inode block contains exactly BLKFILES 'struct File's
49 #define BLKFILES (BLKSIZE / sizeof(struct File))
51 // File types
52 #define FTYPE_REG 0 // Regular file
53 #define FTYPE_DIR 1 // Directory
56 // File system super-block (both in-memory and on-disk)
58 #define FS_MAGIC 0x4A0530AE // related vaguely to 'J\0S!'
60 struct Super {
61 uint32_t s_magic; // Magic number: FS_MAGIC
62 uint32_t s_nblocks; // Total number of blocks on disk
63 struct File s_root; // Root directory node
66 // Definitions for requests from clients to file system
68 #define FSREQ_OPEN 1
69 #define FSREQ_MAP 2
70 #define FSREQ_SET_SIZE 3
71 #define FSREQ_CLOSE 4
72 #define FSREQ_DIRTY 5
73 #define FSREQ_REMOVE 6
74 #define FSREQ_SYNC 7
76 struct Fsreq_open {
77 char req_path[MAXPATHLEN];
78 int req_omode;
81 struct Fsreq_map {
82 int req_fileid;
83 off_t req_offset;
86 struct Fsreq_set_size {
87 int req_fileid;
88 off_t req_size;
91 struct Fsreq_close {
92 int req_fileid;
95 struct Fsreq_dirty {
96 int req_fileid;
97 off_t req_offset;
100 struct Fsreq_remove {
101 char req_path[MAXPATHLEN];
104 #endif /* !JOS_INC_FS_H */