1 2 #ifndef __FS_O2FS_H__ 3 #define __FS_O2FS_H__ 4 5 /* 6 * *** Disk Layout *** 7 * 8 * +---------------------+ 9 * | Super Blocks (4MBs) | 10 * +---------------------+ 11 * | | 12 * . 13 * . 14 * . 15 * | | 16 * +---------------------+ 17 * | Super Blocks (4MBs) | 18 * +---------------------+ 19 * 20 */ 21 22 #define MAXUSERNAMELEN 32 23 #define MAXNAMELEN 255 24 25 /* 26 * *** Version History *** 27 * 1.0 Initial release 28 */ 29 30 #define O2FS_VERSION_MAJOR 1 31 #define O2FS_VERSION_MINOR 0 32 33 /* 34 * Object ID: Pointer to a block node 35 */ 36 typedef struct ObjID { 37 uint8_t hash[32]; 38 uint64_t device; 39 uint64_t offset; 40 } ObjID; 41 42 /* 43 * Super block 44 */ 45 typedef struct SuperBlock 46 { 47 uint8_t magic[8]; /* Superblock Magic */ 48 uint16_t versionMajor; /* Major Version Number */ 49 uint16_t versionMinor; /* Minor Version Number */ 50 uint32_t _rsvd0; 51 uint64_t features; /* Feature Flags */ 52 uint64_t blockCount; /* Total Blocks */ 53 uint64_t blockSize; /* Block Size in Bytes */ 54 uint64_t bitmapSize; /* Free Bitmap Size in Bytes */ 55 uint64_t bitmapOffset; /* Free Bitmap Offset */ 56 57 uint64_t version; /* Snapshot version */ 58 ObjID root; /* Root Tree */ 59 60 uint8_t hash[32]; 61 } SuperBlock; 62 63 #define SUPERBLOCK_MAGIC "SUPRBLOK" 64 65 /* 66 * Block Pointer: Address raw blocks on the disk 67 */ 68 typedef struct BPtr { 69 uint8_t hash[32]; 70 uint64_t device; 71 uint64_t offset; 72 uint64_t _rsvd0; 73 uint64_t _rsvd1; 74 } BPtr; 75 76 77 #define O2FS_DIRECT_PTR (64) 78 79 /* 80 * Block Nodes: Contain indirect pointers to pieces of a file 81 */ 82 typedef struct BNode 83 { 84 uint8_t magic[8]; 85 uint16_t versionMajor; 86 uint16_t versionMinor; 87 uint32_t flags; 88 uint64_t size; 89 90 BPtr direct[O2FS_DIRECT_PTR]; 91 } BNode; 92 93 #define BNODE_MAGIC "BLOKNODE" 94 95 /* 96 * Directory entries are exactly 512 bytes 97 */ 98 typedef struct BDirEntry 99 { 100 uint8_t magic[8]; 101 ObjID objId; 102 uint64_t size; 103 uint64_t flags; 104 uint64_t ctime; 105 uint64_t mtime; 106 uint8_t user[MAXUSERNAMELEN]; // Not null terminated 107 uint8_t group[MAXUSERNAMELEN]; 108 uint8_t padding[104]; 109 uint8_t name[MAXNAMELEN+1]; // Null terminated 110 } BDirEntry; 111 112 #define BDIR_MAGIC "DIRENTRY" 113 114 #endif /* __FS_O2FS_H__ */ 115 116