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