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