nilfs2_ondisk.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /*
  2. * nilfs2_ondisk.h - NILFS2 on-disk structures
  3. *
  4. * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published
  8. * by the Free Software Foundation; either version 2.1 of the License, or
  9. * (at your option) any later version.
  10. */
  11. /*
  12. * linux/include/linux/ext2_fs.h
  13. *
  14. * Copyright (C) 1992, 1993, 1994, 1995
  15. * Remy Card (card@masi.ibp.fr)
  16. * Laboratoire MASI - Institut Blaise Pascal
  17. * Universite Pierre et Marie Curie (Paris VI)
  18. *
  19. * from
  20. *
  21. * linux/include/linux/minix_fs.h
  22. *
  23. * Copyright (C) 1991, 1992 Linus Torvalds
  24. */
  25. #ifndef _LINUX_NILFS2_ONDISK_H
  26. #define _LINUX_NILFS2_ONDISK_H
  27. #include <linux/types.h>
  28. #include <linux/magic.h>
  29. #define NILFS_INODE_BMAP_SIZE 7
  30. /**
  31. * struct nilfs_inode - structure of an inode on disk
  32. * @i_blocks: blocks count
  33. * @i_size: size in bytes
  34. * @i_ctime: creation time (seconds)
  35. * @i_mtime: modification time (seconds)
  36. * @i_ctime_nsec: creation time (nano seconds)
  37. * @i_mtime_nsec: modification time (nano seconds)
  38. * @i_uid: user id
  39. * @i_gid: group id
  40. * @i_mode: file mode
  41. * @i_links_count: links count
  42. * @i_flags: file flags
  43. * @i_bmap: block mapping
  44. * @i_xattr: extended attributes
  45. * @i_generation: file generation (for NFS)
  46. * @i_pad: padding
  47. */
  48. struct nilfs_inode {
  49. __le64 i_blocks;
  50. __le64 i_size;
  51. __le64 i_ctime;
  52. __le64 i_mtime;
  53. __le32 i_ctime_nsec;
  54. __le32 i_mtime_nsec;
  55. __le32 i_uid;
  56. __le32 i_gid;
  57. __le16 i_mode;
  58. __le16 i_links_count;
  59. __le32 i_flags;
  60. __le64 i_bmap[NILFS_INODE_BMAP_SIZE];
  61. #define i_device_code i_bmap[0]
  62. __le64 i_xattr;
  63. __le32 i_generation;
  64. __le32 i_pad;
  65. };
  66. #define NILFS_MIN_INODE_SIZE 128
  67. /**
  68. * struct nilfs_super_root - structure of super root
  69. * @sr_sum: check sum
  70. * @sr_bytes: byte count of the structure
  71. * @sr_flags: flags (reserved)
  72. * @sr_nongc_ctime: write time of the last segment not for cleaner operation
  73. * @sr_dat: DAT file inode
  74. * @sr_cpfile: checkpoint file inode
  75. * @sr_sufile: segment usage file inode
  76. */
  77. struct nilfs_super_root {
  78. __le32 sr_sum;
  79. __le16 sr_bytes;
  80. __le16 sr_flags;
  81. __le64 sr_nongc_ctime;
  82. struct nilfs_inode sr_dat;
  83. struct nilfs_inode sr_cpfile;
  84. struct nilfs_inode sr_sufile;
  85. };
  86. #define NILFS_SR_MDT_OFFSET(inode_size, i) \
  87. ((unsigned long)&((struct nilfs_super_root *)0)->sr_dat + \
  88. (inode_size) * (i))
  89. #define NILFS_SR_DAT_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 0)
  90. #define NILFS_SR_CPFILE_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 1)
  91. #define NILFS_SR_SUFILE_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 2)
  92. #define NILFS_SR_BYTES(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 3)
  93. /*
  94. * Maximal mount counts
  95. */
  96. #define NILFS_DFL_MAX_MNT_COUNT 50 /* 50 mounts */
  97. /*
  98. * File system states (sbp->s_state, nilfs->ns_mount_state)
  99. */
  100. #define NILFS_VALID_FS 0x0001 /* Unmounted cleanly */
  101. #define NILFS_ERROR_FS 0x0002 /* Errors detected */
  102. #define NILFS_RESIZE_FS 0x0004 /* Resize required */
  103. /*
  104. * Mount flags (sbi->s_mount_opt)
  105. */
  106. #define NILFS_MOUNT_ERROR_MODE 0x0070 /* Error mode mask */
  107. #define NILFS_MOUNT_ERRORS_CONT 0x0010 /* Continue on errors */
  108. #define NILFS_MOUNT_ERRORS_RO 0x0020 /* Remount fs ro on errors */
  109. #define NILFS_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
  110. #define NILFS_MOUNT_BARRIER 0x1000 /* Use block barriers */
  111. #define NILFS_MOUNT_STRICT_ORDER 0x2000 /*
  112. * Apply strict in-order
  113. * semantics also for data
  114. */
  115. #define NILFS_MOUNT_NORECOVERY 0x4000 /*
  116. * Disable write access during
  117. * mount-time recovery
  118. */
  119. #define NILFS_MOUNT_DISCARD 0x8000 /* Issue DISCARD requests */
  120. /**
  121. * struct nilfs_super_block - structure of super block on disk
  122. */
  123. struct nilfs_super_block {
  124. /*00*/ __le32 s_rev_level; /* Revision level */
  125. __le16 s_minor_rev_level; /* minor revision level */
  126. __le16 s_magic; /* Magic signature */
  127. __le16 s_bytes; /*
  128. * Bytes count of CRC calculation
  129. * for this structure. s_reserved
  130. * is excluded.
  131. */
  132. __le16 s_flags; /* flags */
  133. __le32 s_crc_seed; /* Seed value of CRC calculation */
  134. /*10*/ __le32 s_sum; /* Check sum of super block */
  135. __le32 s_log_block_size; /*
  136. * Block size represented as follows
  137. * blocksize =
  138. * 1 << (s_log_block_size + 10)
  139. */
  140. __le64 s_nsegments; /* Number of segments in filesystem */
  141. /*20*/ __le64 s_dev_size; /* block device size in bytes */
  142. __le64 s_first_data_block; /* 1st seg disk block number */
  143. /*30*/ __le32 s_blocks_per_segment; /* number of blocks per full segment */
  144. __le32 s_r_segments_percentage; /* Reserved segments percentage */
  145. __le64 s_last_cno; /* Last checkpoint number */
  146. /*40*/ __le64 s_last_pseg; /* disk block addr pseg written last */
  147. __le64 s_last_seq; /* seq. number of seg written last */
  148. /*50*/ __le64 s_free_blocks_count; /* Free blocks count */
  149. __le64 s_ctime; /*
  150. * Creation time (execution time of
  151. * newfs)
  152. */
  153. /*60*/ __le64 s_mtime; /* Mount time */
  154. __le64 s_wtime; /* Write time */
  155. /*70*/ __le16 s_mnt_count; /* Mount count */
  156. __le16 s_max_mnt_count; /* Maximal mount count */
  157. __le16 s_state; /* File system state */
  158. __le16 s_errors; /* Behaviour when detecting errors */
  159. __le64 s_lastcheck; /* time of last check */
  160. /*80*/ __le32 s_checkinterval; /* max. time between checks */
  161. __le32 s_creator_os; /* OS */
  162. __le16 s_def_resuid; /* Default uid for reserved blocks */
  163. __le16 s_def_resgid; /* Default gid for reserved blocks */
  164. __le32 s_first_ino; /* First non-reserved inode */
  165. /*90*/ __le16 s_inode_size; /* Size of an inode */
  166. __le16 s_dat_entry_size; /* Size of a dat entry */
  167. __le16 s_checkpoint_size; /* Size of a checkpoint */
  168. __le16 s_segment_usage_size; /* Size of a segment usage */
  169. /*98*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */
  170. /*A8*/ char s_volume_name[80]; /* volume name */
  171. /*F8*/ __le32 s_c_interval; /* Commit interval of segment */
  172. __le32 s_c_block_max; /*
  173. * Threshold of data amount for
  174. * the segment construction
  175. */
  176. /*100*/ __le64 s_feature_compat; /* Compatible feature set */
  177. __le64 s_feature_compat_ro; /* Read-only compatible feature set */
  178. __le64 s_feature_incompat; /* Incompatible feature set */
  179. __u32 s_reserved[186]; /* padding to the end of the block */
  180. };
  181. /*
  182. * Codes for operating systems
  183. */
  184. #define NILFS_OS_LINUX 0
  185. /* Codes from 1 to 4 are reserved to keep compatibility with ext2 creator-OS */
  186. /*
  187. * Revision levels
  188. */
  189. #define NILFS_CURRENT_REV 2 /* current major revision */
  190. #define NILFS_MINOR_REV 0 /* minor revision */
  191. #define NILFS_MIN_SUPP_REV 2 /* minimum supported revision */
  192. /*
  193. * Feature set definitions
  194. *
  195. * If there is a bit set in the incompatible feature set that the kernel
  196. * doesn't know about, it should refuse to mount the filesystem.
  197. */
  198. #define NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT 0x00000001ULL
  199. #define NILFS_FEATURE_COMPAT_SUPP 0ULL
  200. #define NILFS_FEATURE_COMPAT_RO_SUPP NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT
  201. #define NILFS_FEATURE_INCOMPAT_SUPP 0ULL
  202. /*
  203. * Bytes count of super_block for CRC-calculation
  204. */
  205. #define NILFS_SB_BYTES \
  206. ((long)&((struct nilfs_super_block *)0)->s_reserved)
  207. /*
  208. * Special inode number
  209. */
  210. #define NILFS_ROOT_INO 2 /* Root file inode */
  211. #define NILFS_DAT_INO 3 /* DAT file */
  212. #define NILFS_CPFILE_INO 4 /* checkpoint file */
  213. #define NILFS_SUFILE_INO 5 /* segment usage file */
  214. #define NILFS_IFILE_INO 6 /* ifile */
  215. #define NILFS_ATIME_INO 7 /* Atime file (reserved) */
  216. #define NILFS_XATTR_INO 8 /* Xattribute file (reserved) */
  217. #define NILFS_SKETCH_INO 10 /* Sketch file */
  218. #define NILFS_USER_INO 11 /* Fisrt user's file inode number */
  219. #define NILFS_SB_OFFSET_BYTES 1024 /* byte offset of nilfs superblock */
  220. #define NILFS_SEG_MIN_BLOCKS 16 /*
  221. * Minimum number of blocks in
  222. * a full segment
  223. */
  224. #define NILFS_PSEG_MIN_BLOCKS 2 /*
  225. * Minimum number of blocks in
  226. * a partial segment
  227. */
  228. #define NILFS_MIN_NRSVSEGS 8 /*
  229. * Minimum number of reserved
  230. * segments
  231. */
  232. /*
  233. * We call DAT, cpfile, and sufile root metadata files. Inodes of
  234. * these files are written in super root block instead of ifile, and
  235. * garbage collector doesn't keep any past versions of these files.
  236. */
  237. #define NILFS_ROOT_METADATA_FILE(ino) \
  238. ((ino) >= NILFS_DAT_INO && (ino) <= NILFS_SUFILE_INO)
  239. /*
  240. * bytes offset of secondary super block
  241. */
  242. #define NILFS_SB2_OFFSET_BYTES(devsize) ((((devsize) >> 12) - 1) << 12)
  243. /*
  244. * Maximal count of links to a file
  245. */
  246. #define NILFS_LINK_MAX 32000
  247. /*
  248. * Structure of a directory entry
  249. * (Same as ext2)
  250. */
  251. #define NILFS_NAME_LEN 255
  252. /*
  253. * Block size limitations
  254. */
  255. #define NILFS_MIN_BLOCK_SIZE 1024
  256. #define NILFS_MAX_BLOCK_SIZE 65536
  257. /*
  258. * The new version of the directory entry. Since V0 structures are
  259. * stored in intel byte order, and the name_len field could never be
  260. * bigger than 255 chars, it's safe to reclaim the extra byte for the
  261. * file_type field.
  262. */
  263. struct nilfs_dir_entry {
  264. __le64 inode; /* Inode number */
  265. __le16 rec_len; /* Directory entry length */
  266. __u8 name_len; /* Name length */
  267. __u8 file_type; /* Dir entry type (file, dir, etc) */
  268. char name[NILFS_NAME_LEN]; /* File name */
  269. char pad;
  270. };
  271. /*
  272. * NILFS directory file types. Only the low 3 bits are used. The
  273. * other bits are reserved for now.
  274. */
  275. enum {
  276. NILFS_FT_UNKNOWN,
  277. NILFS_FT_REG_FILE,
  278. NILFS_FT_DIR,
  279. NILFS_FT_CHRDEV,
  280. NILFS_FT_BLKDEV,
  281. NILFS_FT_FIFO,
  282. NILFS_FT_SOCK,
  283. NILFS_FT_SYMLINK,
  284. NILFS_FT_MAX
  285. };
  286. /*
  287. * NILFS_DIR_PAD defines the directory entries boundaries
  288. *
  289. * NOTE: It must be a multiple of 8
  290. */
  291. #define NILFS_DIR_PAD 8
  292. #define NILFS_DIR_ROUND (NILFS_DIR_PAD - 1)
  293. #define NILFS_DIR_REC_LEN(name_len) (((name_len) + 12 + NILFS_DIR_ROUND) & \
  294. ~NILFS_DIR_ROUND)
  295. #define NILFS_MAX_REC_LEN ((1 << 16) - 1)
  296. /**
  297. * struct nilfs_finfo - file information
  298. * @fi_ino: inode number
  299. * @fi_cno: checkpoint number
  300. * @fi_nblocks: number of blocks (including intermediate blocks)
  301. * @fi_ndatablk: number of file data blocks
  302. */
  303. struct nilfs_finfo {
  304. __le64 fi_ino;
  305. __le64 fi_cno;
  306. __le32 fi_nblocks;
  307. __le32 fi_ndatablk;
  308. };
  309. /**
  310. * struct nilfs_binfo_v - information on a data block (except DAT)
  311. * @bi_vblocknr: virtual block number
  312. * @bi_blkoff: block offset
  313. */
  314. struct nilfs_binfo_v {
  315. __le64 bi_vblocknr;
  316. __le64 bi_blkoff;
  317. };
  318. /**
  319. * struct nilfs_binfo_dat - information on a DAT node block
  320. * @bi_blkoff: block offset
  321. * @bi_level: level
  322. * @bi_pad: padding
  323. */
  324. struct nilfs_binfo_dat {
  325. __le64 bi_blkoff;
  326. __u8 bi_level;
  327. __u8 bi_pad[7];
  328. };
  329. /**
  330. * union nilfs_binfo: block information
  331. * @bi_v: nilfs_binfo_v structure
  332. * @bi_dat: nilfs_binfo_dat structure
  333. */
  334. union nilfs_binfo {
  335. struct nilfs_binfo_v bi_v;
  336. struct nilfs_binfo_dat bi_dat;
  337. };
  338. /**
  339. * struct nilfs_segment_summary - segment summary header
  340. * @ss_datasum: checksum of data
  341. * @ss_sumsum: checksum of segment summary
  342. * @ss_magic: magic number
  343. * @ss_bytes: size of this structure in bytes
  344. * @ss_flags: flags
  345. * @ss_seq: sequence number
  346. * @ss_create: creation timestamp
  347. * @ss_next: next segment
  348. * @ss_nblocks: number of blocks
  349. * @ss_nfinfo: number of finfo structures
  350. * @ss_sumbytes: total size of segment summary in bytes
  351. * @ss_pad: padding
  352. * @ss_cno: checkpoint number
  353. */
  354. struct nilfs_segment_summary {
  355. __le32 ss_datasum;
  356. __le32 ss_sumsum;
  357. __le32 ss_magic;
  358. __le16 ss_bytes;
  359. __le16 ss_flags;
  360. __le64 ss_seq;
  361. __le64 ss_create;
  362. __le64 ss_next;
  363. __le32 ss_nblocks;
  364. __le32 ss_nfinfo;
  365. __le32 ss_sumbytes;
  366. __le32 ss_pad;
  367. __le64 ss_cno;
  368. /* array of finfo structures */
  369. };
  370. #define NILFS_SEGSUM_MAGIC 0x1eaffa11 /* segment summary magic number */
  371. /*
  372. * Segment summary flags
  373. */
  374. #define NILFS_SS_LOGBGN 0x0001 /* begins a logical segment */
  375. #define NILFS_SS_LOGEND 0x0002 /* ends a logical segment */
  376. #define NILFS_SS_SR 0x0004 /* has super root */
  377. #define NILFS_SS_SYNDT 0x0008 /* includes data only updates */
  378. #define NILFS_SS_GC 0x0010 /* segment written for cleaner operation */
  379. /**
  380. * struct nilfs_btree_node - header of B-tree node block
  381. * @bn_flags: flags
  382. * @bn_level: level
  383. * @bn_nchildren: number of children
  384. * @bn_pad: padding
  385. */
  386. struct nilfs_btree_node {
  387. __u8 bn_flags;
  388. __u8 bn_level;
  389. __le16 bn_nchildren;
  390. __le32 bn_pad;
  391. };
  392. /* flags */
  393. #define NILFS_BTREE_NODE_ROOT 0x01
  394. /* level */
  395. #define NILFS_BTREE_LEVEL_DATA 0
  396. #define NILFS_BTREE_LEVEL_NODE_MIN (NILFS_BTREE_LEVEL_DATA + 1)
  397. #define NILFS_BTREE_LEVEL_MAX 14 /* Max level (exclusive) */
  398. /**
  399. * struct nilfs_direct_node - header of built-in bmap array
  400. * @dn_flags: flags
  401. * @dn_pad: padding
  402. */
  403. struct nilfs_direct_node {
  404. __u8 dn_flags;
  405. __u8 pad[7];
  406. };
  407. /**
  408. * struct nilfs_palloc_group_desc - block group descriptor
  409. * @pg_nfrees: number of free entries in block group
  410. */
  411. struct nilfs_palloc_group_desc {
  412. __le32 pg_nfrees;
  413. };
  414. /**
  415. * struct nilfs_dat_entry - disk address translation entry
  416. * @de_blocknr: block number
  417. * @de_start: start checkpoint number
  418. * @de_end: end checkpoint number
  419. * @de_rsv: reserved for future use
  420. */
  421. struct nilfs_dat_entry {
  422. __le64 de_blocknr;
  423. __le64 de_start;
  424. __le64 de_end;
  425. __le64 de_rsv;
  426. };
  427. #define NILFS_MIN_DAT_ENTRY_SIZE 32
  428. /**
  429. * struct nilfs_snapshot_list - snapshot list
  430. * @ssl_next: next checkpoint number on snapshot list
  431. * @ssl_prev: previous checkpoint number on snapshot list
  432. */
  433. struct nilfs_snapshot_list {
  434. __le64 ssl_next;
  435. __le64 ssl_prev;
  436. };
  437. /**
  438. * struct nilfs_checkpoint - checkpoint structure
  439. * @cp_flags: flags
  440. * @cp_checkpoints_count: checkpoints count in a block
  441. * @cp_snapshot_list: snapshot list
  442. * @cp_cno: checkpoint number
  443. * @cp_create: creation timestamp
  444. * @cp_nblk_inc: number of blocks incremented by this checkpoint
  445. * @cp_inodes_count: inodes count
  446. * @cp_blocks_count: blocks count
  447. * @cp_ifile_inode: inode of ifile
  448. */
  449. struct nilfs_checkpoint {
  450. __le32 cp_flags;
  451. __le32 cp_checkpoints_count;
  452. struct nilfs_snapshot_list cp_snapshot_list;
  453. __le64 cp_cno;
  454. __le64 cp_create;
  455. __le64 cp_nblk_inc;
  456. __le64 cp_inodes_count;
  457. __le64 cp_blocks_count;
  458. /*
  459. * Do not change the byte offset of ifile inode.
  460. * To keep the compatibility of the disk format,
  461. * additional fields should be added behind cp_ifile_inode.
  462. */
  463. struct nilfs_inode cp_ifile_inode;
  464. };
  465. #define NILFS_MIN_CHECKPOINT_SIZE (64 + NILFS_MIN_INODE_SIZE)
  466. /* checkpoint flags */
  467. enum {
  468. NILFS_CHECKPOINT_SNAPSHOT,
  469. NILFS_CHECKPOINT_INVALID,
  470. NILFS_CHECKPOINT_SKETCH,
  471. NILFS_CHECKPOINT_MINOR,
  472. };
  473. #define NILFS_CHECKPOINT_FNS(flag, name) \
  474. static inline void \
  475. nilfs_checkpoint_set_##name(struct nilfs_checkpoint *cp) \
  476. { \
  477. cp->cp_flags = cpu_to_le32(le32_to_cpu(cp->cp_flags) | \
  478. (1UL << NILFS_CHECKPOINT_##flag)); \
  479. } \
  480. static inline void \
  481. nilfs_checkpoint_clear_##name(struct nilfs_checkpoint *cp) \
  482. { \
  483. cp->cp_flags = cpu_to_le32(le32_to_cpu(cp->cp_flags) & \
  484. ~(1UL << NILFS_CHECKPOINT_##flag)); \
  485. } \
  486. static inline int \
  487. nilfs_checkpoint_##name(const struct nilfs_checkpoint *cp) \
  488. { \
  489. return !!(le32_to_cpu(cp->cp_flags) & \
  490. (1UL << NILFS_CHECKPOINT_##flag)); \
  491. }
  492. NILFS_CHECKPOINT_FNS(SNAPSHOT, snapshot)
  493. NILFS_CHECKPOINT_FNS(INVALID, invalid)
  494. NILFS_CHECKPOINT_FNS(MINOR, minor)
  495. /**
  496. * struct nilfs_cpfile_header - checkpoint file header
  497. * @ch_ncheckpoints: number of checkpoints
  498. * @ch_nsnapshots: number of snapshots
  499. * @ch_snapshot_list: snapshot list
  500. */
  501. struct nilfs_cpfile_header {
  502. __le64 ch_ncheckpoints;
  503. __le64 ch_nsnapshots;
  504. struct nilfs_snapshot_list ch_snapshot_list;
  505. };
  506. #define NILFS_CPFILE_FIRST_CHECKPOINT_OFFSET \
  507. ((sizeof(struct nilfs_cpfile_header) + \
  508. sizeof(struct nilfs_checkpoint) - 1) / \
  509. sizeof(struct nilfs_checkpoint))
  510. /**
  511. * struct nilfs_segment_usage - segment usage
  512. * @su_lastmod: last modified timestamp
  513. * @su_nblocks: number of blocks in segment
  514. * @su_flags: flags
  515. */
  516. struct nilfs_segment_usage {
  517. __le64 su_lastmod;
  518. __le32 su_nblocks;
  519. __le32 su_flags;
  520. };
  521. #define NILFS_MIN_SEGMENT_USAGE_SIZE 16
  522. /* segment usage flag */
  523. enum {
  524. NILFS_SEGMENT_USAGE_ACTIVE,
  525. NILFS_SEGMENT_USAGE_DIRTY,
  526. NILFS_SEGMENT_USAGE_ERROR,
  527. };
  528. #define NILFS_SEGMENT_USAGE_FNS(flag, name) \
  529. static inline void \
  530. nilfs_segment_usage_set_##name(struct nilfs_segment_usage *su) \
  531. { \
  532. su->su_flags = cpu_to_le32(le32_to_cpu(su->su_flags) | \
  533. (1UL << NILFS_SEGMENT_USAGE_##flag));\
  534. } \
  535. static inline void \
  536. nilfs_segment_usage_clear_##name(struct nilfs_segment_usage *su) \
  537. { \
  538. su->su_flags = \
  539. cpu_to_le32(le32_to_cpu(su->su_flags) & \
  540. ~(1UL << NILFS_SEGMENT_USAGE_##flag)); \
  541. } \
  542. static inline int \
  543. nilfs_segment_usage_##name(const struct nilfs_segment_usage *su) \
  544. { \
  545. return !!(le32_to_cpu(su->su_flags) & \
  546. (1UL << NILFS_SEGMENT_USAGE_##flag)); \
  547. }
  548. NILFS_SEGMENT_USAGE_FNS(ACTIVE, active)
  549. NILFS_SEGMENT_USAGE_FNS(DIRTY, dirty)
  550. NILFS_SEGMENT_USAGE_FNS(ERROR, error)
  551. static inline void
  552. nilfs_segment_usage_set_clean(struct nilfs_segment_usage *su)
  553. {
  554. su->su_lastmod = cpu_to_le64(0);
  555. su->su_nblocks = cpu_to_le32(0);
  556. su->su_flags = cpu_to_le32(0);
  557. }
  558. static inline int
  559. nilfs_segment_usage_clean(const struct nilfs_segment_usage *su)
  560. {
  561. return !le32_to_cpu(su->su_flags);
  562. }
  563. /**
  564. * struct nilfs_sufile_header - segment usage file header
  565. * @sh_ncleansegs: number of clean segments
  566. * @sh_ndirtysegs: number of dirty segments
  567. * @sh_last_alloc: last allocated segment number
  568. */
  569. struct nilfs_sufile_header {
  570. __le64 sh_ncleansegs;
  571. __le64 sh_ndirtysegs;
  572. __le64 sh_last_alloc;
  573. /* ... */
  574. };
  575. #define NILFS_SUFILE_FIRST_SEGMENT_USAGE_OFFSET \
  576. ((sizeof(struct nilfs_sufile_header) + \
  577. sizeof(struct nilfs_segment_usage) - 1) / \
  578. sizeof(struct nilfs_segment_usage))
  579. #endif /* _LINUX_NILFS2_ONDISK_H */