nilfs2_ondisk.h 18 KB

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