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