fsZ.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. /*
  2. * include/fsZ.h
  3. *
  4. * Copyright (C) 2017 bzt (bztsrc@gitlab)
  5. *
  6. * Permission is hereby granted, free of charge, to any person
  7. * obtaining a copy of this software and associated documentation
  8. * files (the "Software"), to deal in the Software without
  9. * restriction, including without limitation the rights to use, copy,
  10. * modify, merge, publish, distribute, sublicense, and/or sell copies
  11. * of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  21. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  22. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  24. * DEALINGS IN THE SOFTWARE.
  25. *
  26. * IMPORTANT NOTE: the on disk format of FS/Z is MIT licensed, you
  27. * can use it without any restrictions and free of charge. The right
  28. * to create and use disks and images with FS/Z and implement programs
  29. * to do so is hereby granted to everybody. The filesystem driver for
  30. * it in OS/Z on the other hand licensed under CC-by-nc-sa.
  31. *
  32. * @brief FS/Z filesystem defines and structures for on disk format
  33. */
  34. #ifndef _FS_Z_H_
  35. #define _FS_Z_H_ 1
  36. #define FSZ_VERSION_MAJOR 1
  37. #define FSZ_VERSION_MINOR 0
  38. #define FSZ_SECSIZE 4096
  39. /* logical sector numbers are 128 bits wide to be future proof, and are relative to
  40. * the superblock. Current implementation only supports 64 bits, that gives you the
  41. * capacity of 64 Zettabytes with 4096 bytes sector size. */
  42. /* for CRC32 the Castagnoli method is used, polynomial 0x1EDC6F41 (differs to ANSI
  43. * CRC32a in EFI GPT and in gzip) but has hardware support on many architectures */
  44. /*********************************************************
  45. * 1st sector, the super block *
  46. *********************************************************/
  47. typedef struct {
  48. uint8_t loader[512]; /* 0 reserved for loader code */
  49. uint8_t magic[4]; /* 512 */
  50. uint8_t version_major; /* 516 */
  51. uint8_t version_minor; /* 517 */
  52. uint8_t logsec; /* 518 logical sector size, 0=2048,1=4096(default),2=8192... */
  53. uint8_t flags; /* 519 bit 0..3: file system features, bit 4..7: encryption algorithm */
  54. uint32_t enchash; /* 520 password CRC32, to avoid decryption with bad passwords */
  55. uint16_t maxmounts; /* 524 number of maximum mounts allowed to next fsck */
  56. uint16_t currmounts; /* 526 current mount counter */
  57. uint64_t numsec; /* 528 total number of logical sectors */
  58. uint64_t numsec_hi; /* 128 bit */
  59. uint64_t freesec; /* 544 first free sector if fs is defragmented, otherwise */
  60. uint64_t freesec_hi; /* it's the last used sector+1 */
  61. uint64_t rootdirfid; /* 560 logical sector number of root directory's inode, usually LSN 1 */
  62. uint64_t rootdirfid_hi;
  63. uint64_t freesecfid; /* 576 inode to free records (FSZ_SectorList allocated) */
  64. uint64_t freesecfid_hi;
  65. uint64_t badsecfid; /* 592 inode to bad sectors table (FSZ_SectorList allocated) */
  66. uint64_t badsecfid_hi;
  67. uint64_t indexfid; /* 608 inode to search index. Zero if not indexed */
  68. uint64_t indexfid_hi;
  69. uint64_t metafid; /* 624 inode to meta labels file. Zero if there're no meta labels at all */
  70. uint64_t metafid_hi;
  71. uint64_t journalfid; /* 640 inode to journal file. Zero if journaling is turned off */
  72. uint64_t journalfid_hi;
  73. uint64_t journalhead; /* 656 logical sector offset inside journal file where buffer starts */
  74. uint64_t journaltail; /* 664 logical sector offset inside journal file where buffer ends */
  75. uint64_t journalmax; /* 672 number of logical sectors in journal file */
  76. uint8_t encrypt[32]; /* 680 encryption mask for AES or zero */
  77. uint64_t createdate; /* 712 creation timestamp UTC */
  78. uint64_t lastmountdate; /* 720 last time fs was mounted */
  79. uint64_t lastumountdate; /* 728 time when superblock was written to disk, must be zero when its mounted */
  80. uint64_t lastcheckdate; /* 736 last time fs was checked with fsck */
  81. uint8_t uuid[16]; /* 744 filesystem UUID */
  82. uint8_t reserved[256]; /* 760 reserved for future use */
  83. uint8_t magic2[4]; /*1016 */
  84. uint32_t checksum; /*1020 CRC32 of bytes at 512-1020 */
  85. uint8_t raidspecific[FSZ_SECSIZE-1024];
  86. } __attribute__((packed)) FSZ_SuperBlock;
  87. #define FSZ_MAGIC "FS/Z"
  88. /* feature flags */
  89. #define FSZ_SB_BIGINODE (1<<0) /* indicates inode size is 2048 (ACL size 96 instead of 32) */
  90. #define FSZ_SB_JOURNAL_DATA (1<<1) /* also put file content records in journal file, not just metadata */
  91. #define FSZ_SB_EALG_SHACBC (0<<4) /* encrypted with SHA-XOR-CBC */
  92. #define FSZ_SB_EALG_AESCBC (1<<4) /* encrypted with AES-256-CBC */
  93. #define FSZ_SB_EALG(x) ((x>>4)&15)
  94. /*********************************************************
  95. * I-node sector *
  96. *********************************************************/
  97. /* fid: file id, logical sector number where the sector contains an inode structure. */
  98. /* sizeof = 16, one Access Control Entry, UUID without the last byte */
  99. typedef struct {
  100. uint32_t Data1;
  101. uint16_t Data2;
  102. uint16_t Data3;
  103. uint8_t Data4[7];
  104. uint8_t access;
  105. } __attribute__((packed)) FSZ_Access;
  106. /* access rights are stored in the last byte. Make sure this matches
  107. * the system access flags A_* in sys/types.h */
  108. #define FSZ_READ (1<<0)
  109. #define FSZ_WRITE (1<<1)
  110. #define FSZ_EXEC (1<<2) /* execute or search */
  111. #define FSZ_APPEND (1<<3)
  112. #define FSZ_DELETE (1<<4)
  113. #define FSZ_GROUP (1<<5)
  114. #define FSZ_SUID (1<<6) /* Set user id on execution */
  115. #define FSZ_SGID (1<<7) /* Inherit ACL, no set group per se in OS/Z */
  116. /* sizeof = 32 */
  117. typedef struct {
  118. uint64_t sec;
  119. uint64_t sec_hi;
  120. uint64_t numsec;
  121. uint32_t numsec_hi;
  122. uint32_t chksum;
  123. } __attribute__((packed)) FSZ_SectorList;
  124. /* used at several places, like free and bad block list inodes, and with FSZ_IN_FLAG_SECLIST* mappings. */
  125. /* sizeof = 16 */
  126. typedef struct {
  127. uint64_t sec;
  128. uint32_t sec_hi;
  129. uint32_t chksum;
  130. } __attribute__((packed)) FSZ_SectorDir;
  131. /* used with FSZ_IN_FLAG_SD* mappings. */
  132. /* file version structure. You can use this to point to version5, version4 etc. */
  133. /* sizeof = 64 */
  134. typedef struct {
  135. uint64_t sec;
  136. uint64_t sec_hi;
  137. uint64_t size;
  138. uint64_t size_hi;
  139. uint64_t modifydate;
  140. uint64_t flags;
  141. FSZ_Access owner;
  142. } __attribute__((packed)) FSZ_Version;
  143. /* sizeof = 4096 */
  144. typedef struct {
  145. uint8_t magic[4]; /* 0 magic 'FSIN' */
  146. uint32_t checksum; /* 4 CRC32, filetype to inlinedata (exclusive) */
  147. uint8_t filetype[4]; /* 8 first 4 bytes of mime main type, eg: text,imag,vide,audi,appl etc. */
  148. uint8_t mimetype[60]; /* 12 mime sub type, eg.: plain, html, gif, jpeg etc. (*) */
  149. uint64_t createdate; /* 72 number of microseconds since 1970. jan. 1 00:00:00 UTC, inode creation time */
  150. uint64_t changedate; /* 80 number of microseconds since 1970. jan. 1 00:00:00 UTC, inode status change time */
  151. uint64_t accessdate; /* 88 last data access time (if implemented, otherwise zero) */
  152. uint64_t numblocks; /* 96 number of blocks allocated for this inode (**) */
  153. uint64_t numlinks; /* 104 number of references to this inode */
  154. uint64_t metasec; /* 112 logical sector number of meta label block */
  155. uint64_t metasec_hi;
  156. FSZ_Version version5; /* 128 previous oldest version (if versioning enabled) */
  157. FSZ_Version version4; /* 192 all the same format as the current one */
  158. FSZ_Version version3; /* 256 see FSZ_Version structure above */
  159. FSZ_Version version2; /* 320 */
  160. FSZ_Version version1; /* 384 */
  161. /* FSZ_Version current; I haven't used FSZ_Version struct here to save typing when referencing */
  162. uint64_t sec; /* 448 current (or only) version (***) */
  163. uint64_t sec_hi;
  164. uint64_t size; /* 464 file size */
  165. uint64_t size_hi;
  166. uint64_t modifydate;/* 480 */
  167. uint64_t flags; /* 488 see FSZ_IN_FLAG_* (***) */
  168. /* owner is the last in FSZ_Version to followed by ACL, so it can be considered to be the first
  169. * entry in the Access Control List. It is the control ACE, specifies who can modify the ACL. */
  170. FSZ_Access owner; /* 496 */
  171. union {
  172. struct {
  173. FSZ_Access groups[32];/* 512 List of 32 FSZ_Access entries, groups */
  174. uint8_t inlinedata[FSZ_SECSIZE-1024];
  175. } small;
  176. struct {
  177. FSZ_Access groups[96];/* 512 List of 96 FSZ_Access entries, groups */
  178. uint8_t inlinedata[FSZ_SECSIZE-2048];
  179. } big;
  180. } data;
  181. } __attribute__((packed)) FSZ_Inode;
  182. #define FSZ_IN_MAGIC "FSIN"
  183. /* (*) according to IANA, all, more than 1700 mime types are unique on 4+60 bytes. */
  184. /* regular files, 4th character never ':' */
  185. #define FSZ_FILETYPE_REG_TEXT "text" /* main part of mime type */
  186. #define FSZ_FILETYPE_REG_IMAGE "imag"
  187. #define FSZ_FILETYPE_REG_VIDEO "vide"
  188. #define FSZ_FILETYPE_REG_AUDIO "audi"
  189. #define FSZ_FILETYPE_REG_APP "appl"
  190. #define FSZ_FILETYPE_REG_BOOT "boot" /* same as "appl", except file cannot be relocated during defrag */
  191. /* special entities, 4th character always ':' */
  192. #define FSZ_FILETYPE_DIR "dir:" /* directory */
  193. #define FSZ_FILETYPE_UNION "uni:" /* directory union, inlined data is a zero separated list of paths with jokers */
  194. #define FSZ_FILETYPE_INTERNAL "int:" /* internal files, like free and bad sectors and meta info */
  195. #define FSZ_FILETYPE_SYMLINK "lnk:" /* symbolic link, inlined data is a path */
  196. #define FSZ_FILETYPE_PIPE "pip:" /* named pipe (FIFO) */
  197. #define FSZ_FILETYPE_DEV "dev:" /* device */
  198. #define FSZ_FILETYPE_SOCK "sck:" /* socket */
  199. /* mime types for filesystem specific files */
  200. /* for FSZ_FILETYPE_DIR */
  201. #define FSZ_MIMETYPE_DIR_ROOT "fs-root" /* root directory (for recovery it has a special mime type) */
  202. /* for FSZ_FILETYPE_INTERNAL */
  203. #define FSZ_MIMETYPE_INT_FREELST "fs-free-sectors" /* for free sector list */
  204. #define FSZ_MIMETYPE_INT_BADLST "fs-bad-sectors" /* for bad sector list */
  205. #define FSZ_MIMETYPE_INT_INDEX "fs-search-index" /* search cache */
  206. #define FSZ_MIMETYPE_INT_META "fs-meta-labels" /* meta labels */
  207. #define FSZ_MIMETYPE_INT_JOURNAL "fs-journal" /* journaling records (contains only metadata) */
  208. #define FSZ_MIMETYPE_INT_JOURDAT "fs-journal-data" /* journaling records (file contents also journaled) */
  209. /* (**) numblocks counts sector directories, indirect sector lists and data sectors, but
  210. * not zero sectors (holes) for all versions alltogether */
  211. /* flags */
  212. #define FSZ_IN_FLAG_LEVEL(x) ((x)&15) /* a szektorcímfordítás szintjeinek a száma */
  213. #define FSZ_IN_FLAG_SECLIST (1<<4) /* a szektorcímfordítás szektorlistát használ szektorkönyvtár helyett */
  214. #define FSZ_IN_FLAG_CHKSUM (1<<5) /* file has content data checksums too */
  215. #define FSZ_IN_FLAG_HIST (1<<7) /* indicates that previous file versions are kept */
  216. /* bits 8 to 63 are reserved for future use */
  217. /* (***) logical sector address to data sector translation. These file sizes
  218. * were calculated with 4096 sector size. That is configurable in the FSZ_SuperBlock's logsec.
  219. * Sector directory supports 2^128 LSNs, except when FSZ_IN_FLAG_CHECKSUM is set on the
  220. * file version, in which case FSZ_SDEntry used so LSNs are limited to "only" 2^96 bits.
  221. * If even that's not enough, you can use FSZ_SectorList (extents) to store file data, which
  222. * store contiguous runs of sectors with separated checksum fields (FSZ_SectorList). */
  223. /* data size < sector size - 1024 (3072 bytes, current version only)
  224. FSZ_IN_FLAG_LEVEL = 0, FSZ_IN_FLAG_SECLIST = 0, FSZ_Inode.sec points to itself.
  225. the data is included in the inode sector at 1024 (or 2048 if BIGINODE)
  226. with BIGINODE, this format supports 2048 bytes mapping.
  227. FSZ_Inode.sec -> FSZ_Inode.sec; data */
  228. /* data size < sector size (4096)
  229. FSZ_IN_FLAG_LEVEL = 0, FSZ_IN_FLAG_SECLIST = 0, sec points to data sector directly
  230. FSZ_Inode.sec -> data */
  231. /* data size < (sector size - 1024) * sector size / 16 (768k, current version only)
  232. FSZ_IN_FLAG_LEVEL = 1, FSZ_IN_FLAG_SECLIST = 0, FSZ_Inode.sec points to itself,
  233. sector directory inlined.
  234. with BIGINODE, this format supports 512k mapping.
  235. FSZ_Inode.sec -> FSZ_Inode.sec; sd -> data */
  236. /* data size < sector size * sector size / 16 (1 M)
  237. FSZ_IN_FLAG_LEVEL = 1, FSZ_IN_FLAG_SECLIST = 0, sec points to a sector directory,
  238. which is a sector with up to 256 sector addresses
  239. FSZ_Inode.sec -> sd -> data */
  240. /* data size < sector size * sector size / 16 * sector size / 16 (256 M)
  241. FSZ_IN_FLAG_LEVEL = 2, FSZ_IN_FLAG_SECLIST = 0, sec points to a sector directory,
  242. which is a sector with up to 256 sector
  243. directory addresses, which in turn point
  244. to 256*256 sector addresses
  245. FSZ_Inode.sec -> sd -> sd -> data */
  246. /* data size < (64 G)
  247. FSZ_Inode.sec -> sd -> sd -> sd -> data */
  248. /* data size < (16 T)
  249. FSZ_Inode.sec -> sd -> sd -> sd -> sd -> data */
  250. /* data size < (4 Peta, equals 4096 Terra)
  251. FSZ_Inode.sec -> sd -> sd -> sd -> sd -> sd -> data */
  252. /* data size < (1 Exa, equals 1024 Peta)
  253. FSZ_Inode.sec -> sd -> sd -> sd -> sd -> sd -> sd -> data */
  254. /* data size < (256 Exa)
  255. FSZ_Inode.sec -> sd -> sd -> sd -> sd -> sd -> sd -> sd -> data */
  256. /* as sector list contains a number of sectors field it's impossible to tell
  257. * how big file it can store, so we measure it by the number of file fragments */
  258. /* inlined sector list ((sector size - 1024) / 32, up to 96 entries, current version only)
  259. FSZ_IN_FLAG_LEVEL = 0, FSZ_IN_FLAG_SECLIST = 16, FSZ_Inode.sec points to itself,
  260. FSZ_SectorList entries inlined.
  261. FSZ_Inode.sec -> FSZ_Inode.sec; sl -> data */
  262. /* normal sector list sector size / 32, up to 128 entries)
  263. FSZ_IN_FLAG_LEVEL = 0, FSZ_IN_FLAG_SECLIST = 16, sec points to a sector,
  264. which contains FSZ_SectorList entries.
  265. FSZ_Inode.sec -> sl -> data */
  266. /* indirect sector list (up to 32768 entries)
  267. FSZ_IN_FLAG_LEVEL = 1, FSZ_IN_FLAG_SECLIST = 16, sec points to a sector directory,
  268. where each sector points to FSZ_SectorLists
  269. FSZ_Inode.sec -> sd -> sl -> data */
  270. /* double-indirect sector list (up to 8388608 entries)
  271. FSZ_IN_FLAG_LEVEL = 1, FSZ_IN_FLAG_SECLIST = 16, sec points to a sector directory,
  272. pointing to sector directories with FSZ_SectorLists
  273. FSZ_Inode.sec -> sd -> sd -> sl -> data */
  274. /* triple-indirect sector list (up to 2147483648 entries)
  275. FSZ_Inode.sec -> sd -> sd -> sd -> sl -> data */
  276. /*********************************************************
  277. * Directory *
  278. *********************************************************/
  279. /* first entry is the header. */
  280. /* sizeof = 128 */
  281. typedef struct {
  282. uint8_t magic[4];
  283. uint32_t checksum; /* CRC32 of entries from byte 16 to the end */
  284. uint8_t display_type;
  285. uint8_t sorting_order;
  286. uint8_t reserved0[6];
  287. uint64_t numentries;
  288. uint64_t numentries_hi;
  289. uint64_t fid;
  290. uint64_t fid_hi;
  291. uint8_t reserved[79];
  292. uint8_t flags;
  293. } __attribute__((packed)) FSZ_DirEntHeader;
  294. #define FSZ_DIR_MAGIC "FSDR"
  295. #define FSZ_DIR_FLAG_UNSORTED (1<<0)
  296. #define FSZ_DIR_FLAG_HASHED (2<<0)
  297. enum {
  298. FSZ_DIR_DSP_DEFAULT, /* use global configuration */
  299. FSZ_DIR_DSP_DETAILED,
  300. FSZ_DIR_DSP_LIST,
  301. FSZ_DIR_DSP_ICONS,
  302. FSZ_DIR_DSP_PREVIEW
  303. };
  304. enum {
  305. FSZ_DIR_SORT_DEFAULT, /* use global configuration */
  306. FSZ_DIR_SORT_NAME_ASC,
  307. FSZ_DIR_SORT_NAME_DESC,
  308. FSZ_DIR_SORT_SIZE_ASC,
  309. FSZ_DIR_SORT_SIZE_DESC,
  310. FSZ_DIR_SORT_TIME_ASC,
  311. FSZ_DIR_SORT_TIME_DESC
  312. };
  313. /* directory entries are fixed in size and lexicographically ordered.
  314. * this means a bit slower writes, but also incredibly faster look ups. */
  315. /* sizeof = 128 */
  316. typedef struct {
  317. uint64_t fid;
  318. uint64_t fid_hi;
  319. unsigned char name[112]; /* zero terminated UTF-8 string */
  320. } __attribute__((packed)) FSZ_DirEnt;
  321. /* names must not contain zero, '/' and ';'. If the entry points to a
  322. * directory i-node, then name must be suffixed by '/' */
  323. /*********************************************************
  324. * Directory union *
  325. *********************************************************/
  326. /* inlined data is a list of zero terminated UTF-8 paths that may contain the
  327. * '...' joker directory. Terminated by and empty path.
  328. * Example union for /usr/bin: inlinedata=/bin(zero)/usr/.../bin(zero)(zero)
  329. */
  330. /*********************************************************
  331. * Search index *
  332. *********************************************************/
  333. /* superblock indexfid points to a directory with type "dir:fs-search-index"
  334. * that directory contains files, with mime type names, like "imagjpeg/". Names
  335. * starting with "dir:" or "int:" not allowed. Those directory entries must
  336. * point to files of type "int:fs-search-index", which is a list of fid and
  337. * path pairs. Each record starts witha 16 byte fid (to the original i-node),
  338. * followed by a zero terminated UTF-8 path. */
  339. /*********************************************************
  340. * Meta labels *
  341. *********************************************************/
  342. /* meta labels are stored in two places. Meta label file (pointed by metafid in superblock)
  343. * records the UTF-8 encoded keys for 16 bit meta ids, the same way as unions. Each key is
  344. * terminated by a zero and cannot be longer than 255 bytes, and the entire list is terminated
  345. * by an empty string. Meta label sectors in i-nodes point to the starting logical sector with
  346. * contiguous meta values in a key id value pairs (with possibly binary values), filled up
  347. * with zeros to be multiple of sector size.
  348. */
  349. /* Normally meta labels do not exceed logical sector size. But when they do, the allocation
  350. * must be careful to allocate contiguous sectors for a meta block. This complicates things
  351. * a bit when large meta label blocks (>4096) are written, but simplifies a lot on read by
  352. * eliminating the need of translating LSNs for meta labels file. As meta labels are read more
  353. * often than written, and usually one meta is smaller than 4096, this is intentional.
  354. */
  355. /* sizeof = 32 */
  356. typedef struct {
  357. uint8_t magic[4];
  358. uint32_t checksum; /* CRC32 of entries from byte 8 to end */
  359. uint16_t numentries; /* number of meta label key-value pairs */
  360. uint16_t size; /* total size of the meta label values in bytes */
  361. uint32_t reserved;
  362. uint64_t fid; /* back reference to the i-node */
  363. uint64_t fid_hi;
  364. } __attribute__((packed)) FSZ_MetaHeader;
  365. #define FSZ_META_MAGIC "FSMT"
  366. typedef struct {
  367. uint16_t key;
  368. uint16_t size;
  369. } __attribute__((packed)) FSZ_MetaLabel;
  370. /* followed by size bytes, the actual data */
  371. /*********************************************************
  372. * Journal data *
  373. *********************************************************/
  374. /* If journal file is specified in SB, then journalhead, journaltail is used to create a circular
  375. * buffer. Journal file must be allocated with FSZ_IN_FLAG_SECLIST and one extent. Each write
  376. * transaction contains a header and data sectors. Only meta data is journaled, unless the
  377. * FSZ_SB_JOURNAL_DATA flag is set in the superblock, when both meta and file data written. */
  378. /* sizeof = 32 */
  379. typedef struct {
  380. uint8_t magic[4];
  381. uint32_t checksum; /* CRC32 of entries from byte 8 to end */
  382. uint64_t numentries; /* number of extents written in this transaction */
  383. uint64_t transdate; /* transaction's date and time timestamp */
  384. uint64_t reserved;
  385. } __attribute__((packed)) FSZ_JournalTransaction;
  386. /* followed by 32 bytes long FSZ_SectorList entries, padded to logical sector size,
  387. * followed by the data sectors pointed by those FSZ_SectorList entries */
  388. #define FSZ_JT_MAGIC "FSTR"
  389. /*********************************************************
  390. * Encryption *
  391. *********************************************************/
  392. /* Encryption can be applied to the disk and to individual files (if enchash is not zero):
  393. * enckey=sha256(sha256(password+salt)-4 bytes xored with encrypt[])
  394. * if EALG_SHACBC: XOR SHA blocks, very fast, and pretty good cyclic block cipher, uses enckey as iv
  395. * if EALG_AESCBC: AES-256-CBC, key=enckey, iv=substr(enckey,enckey[0]&15,16)
  396. * This way the encrypted disk/file doesn't need to be rewritten when password changes. Also you can
  397. * re-encrypt the disk without changing the password. The enchash CRC is only used to avoid decryption with
  398. * bad password. Checksum is stored in the first cipher block to make it harder to decrypt.
  399. */
  400. #endif /* fsZ.h */