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