Blame


1 4338ef2e 2024-05-18 benni #ifndef FILE_SUFS_H
2 4338ef2e 2024-05-18 benni #define FILE_SUFS_H
3 4338ef2e 2024-05-18 benni #include <stdint.h>
4 4338ef2e 2024-05-18 benni
5 4338ef2e 2024-05-18 benni #define SUFS_MAGIC 0x01020304
6 4338ef2e 2024-05-18 benni #define SUFS_BOOTSIZE 65536
7 4338ef2e 2024-05-18 benni #define SUFS_NDIRECT 6
8 4338ef2e 2024-05-18 benni #define SUFS_NINDIR 3
9 4338ef2e 2024-05-18 benni #define SUFS_NBLOCKS (SUFS_NDIRECT + SUFS_NINDIR)
10 4338ef2e 2024-05-18 benni #define SUFS_INO_INVAL 0
11 4338ef2e 2024-05-18 benni #define SUFS_INO_ROOT 1
12 4338ef2e 2024-05-18 benni
13 4338ef2e 2024-05-18 benni typedef uint64_t sufs_ino_t;
14 4338ef2e 2024-05-18 benni
15 4338ef2e 2024-05-18 benni struct sufs_superblock {
16 4338ef2e 2024-05-18 benni uint32_t magic; // 0 magic number
17 4338ef2e 2024-05-18 benni uint32_t bsize; // 4 block size
18 4338ef2e 2024-05-18 benni uint64_t nino; // 8 number of inodes
19 4338ef2e 2024-05-18 benni uint64_t ndata; // 16 number of data blocks
20 4338ef2e 2024-05-18 benni uint32_t ibmoff; // 24 inode bitmap offset
21 4338ef2e 2024-05-18 benni uint32_t dbmoff; // 28 data bitmap offset
22 4338ef2e 2024-05-18 benni uint32_t ioff; // 32 inode blocks offset
23 4338ef2e 2024-05-18 benni uint32_t doff; // 36 data blocks offset
24 4338ef2e 2024-05-18 benni uint8_t clean; // 40 cleanly umounted?
25 4338ef2e 2024-05-18 benni
26 4338ef2e 2024-05-18 benni char spare[512 - 2 * 8 - 6 * 4 - 1];
27 4338ef2e 2024-05-18 benni };
28 4338ef2e 2024-05-18 benni
29 4338ef2e 2024-05-18 benni struct sufs_inode {
30 4338ef2e 2024-05-18 benni uint16_t mode; // 0 type+perms
31 4338ef2e 2024-05-18 benni uint16_t spare; // 2 spare
32 4338ef2e 2024-05-18 benni uint32_t uid; // 4 user ID
33 4338ef2e 2024-05-18 benni uint32_t gid; // 8 group ID
34 4338ef2e 2024-05-18 benni uint32_t nlink; // 12 number of links
35 4338ef2e 2024-05-18 benni uint64_t size; // 16 size
36 4338ef2e 2024-05-18 benni uint64_t blocks; // 24 number of blocks
37 4338ef2e 2024-05-18 benni int64_t atime; // 32 access time
38 4338ef2e 2024-05-18 benni int64_t mtime; // 40 modify time
39 4338ef2e 2024-05-18 benni int64_t ctime; // 48 change time
40 4338ef2e 2024-05-18 benni uint64_t direct[SUFS_NDIRECT]; // 56 direct blocks
41 4338ef2e 2024-05-18 benni uint64_t indir[SUFS_NINDIR]; // 104 indirect blocks
42 4338ef2e 2024-05-18 benni };
43 4338ef2e 2024-05-18 benni
44 4338ef2e 2024-05-18 benni struct sufs_dirent {
45 4338ef2e 2024-05-18 benni uint64_t ino; // 0 inode number
46 4338ef2e 2024-05-18 benni uint16_t size; // 8 size of entry
47 4338ef2e 2024-05-18 benni uint8_t len; // 10 name length
48 4338ef2e 2024-05-18 benni char name[]; // 11 name
49 4338ef2e 2024-05-18 benni } __attribute__((packed));
50 4338ef2e 2024-05-18 benni
51 4338ef2e 2024-05-18 benni #define STASSERT(x) _Static_assert(x, #x)
52 4338ef2e 2024-05-18 benni
53 4338ef2e 2024-05-18 benni STASSERT(sizeof(struct sufs_superblock) == 512);
54 4338ef2e 2024-05-18 benni STASSERT(sizeof(struct sufs_inode) == 128);
55 4338ef2e 2024-05-18 benni
56 4338ef2e 2024-05-18 benni #define sufs_ipb(sb) ((sb).bsize / sizeof (struct sufs_inode))
57 4338ef2e 2024-05-18 benni #define sufs_iblk(sb, ino) ((sb).ioff + ((ino) / sufs_ipb (sb)))
58 4338ef2e 2024-05-18 benni #define sufs_ioff(sb, ino) (((ino) & (sufs_ipb(sb) - 1)) * sizeof (struct sufs_inode))
59 4338ef2e 2024-05-18 benni
60 4338ef2e 2024-05-18 benni #endif // FILE_SUFS_H