1 1.5 andvar /* $NetBSD: nilfs_fs.h,v 1.5 2024/12/26 21:16:26 andvar Exp $ */ 2 1.1 reinoud 3 1.1 reinoud /* 4 1.1 reinoud * Copyright (c) 2008, 2009 Reinoud Zandijk 5 1.1 reinoud * All rights reserved. 6 1.1 reinoud * 7 1.1 reinoud * Redistribution and use in source and binary forms, with or without 8 1.1 reinoud * modification, are permitted provided that the following conditions 9 1.1 reinoud * are met: 10 1.1 reinoud * 1. Redistributions of source code must retain the above copyright 11 1.1 reinoud * notice, this list of conditions and the following disclaimer. 12 1.1 reinoud * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 reinoud * notice, this list of conditions and the following disclaimer in the 14 1.1 reinoud * documentation and/or other materials provided with the distribution. 15 1.1 reinoud * 16 1.1 reinoud * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 1.1 reinoud * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 1.1 reinoud * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 1.1 reinoud * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 1.1 reinoud * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 1.1 reinoud * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 1.1 reinoud * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 1.1 reinoud * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 1.1 reinoud * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 1.1 reinoud * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 1.1 reinoud * 27 1.1 reinoud * NilFS on disc structures 28 1.1 reinoud * 29 1.1 reinoud * Original definitions written by Koji Sato <koji (at) osrg.net> 30 1.1 reinoud * and Ryusuke Konishi <ryusuke (at) osrg.net> 31 1.1 reinoud */ 32 1.1 reinoud 33 1.1 reinoud #ifndef _NILFS_FS_H 34 1.1 reinoud #define _NILFS_FS_H 35 1.1 reinoud 36 1.1 reinoud /* 37 1.1 reinoud * NiLFS stores ext2fs compatible flags in its Inode. NetBSD uses a comparable 38 1.1 reinoud * mechanism with file flags to be mutated with chflags(2). 39 1.1 reinoud * 40 1.1 reinoud * For completion, i mention all ext2-fs flags currently stored in NiLFS 41 1.1 reinoud * inodes. 42 1.1 reinoud */ 43 1.1 reinoud #define NILFS_SECRM_FL 0x00000001 /* no mapping; delete securely */ 44 1.1 reinoud #define NILFS_UNRM_FL 0x00000002 /* no mapping; allow undelete */ 45 1.1 reinoud #define NILFS_SYNC_FL 0x00000008 /* no mapping; sychrone update */ 46 1.1 reinoud #define NILFS_IMMUTABLE_FL 0x00000010 /* SF_IMMUTABLE | UF_IMMUTABLE */ 47 1.1 reinoud #define NILFS_APPEND_FL 0x00000020 /* SF_APPEND | UF_APPEND */ 48 1.1 reinoud #define NILFS_NODUMP_FL 0x00000040 /* UF_NODUMP */ 49 1.1 reinoud #define NILFS_NOATIME_FL 0x00000080 /* no mapping; no atime update */ 50 1.1 reinoud /* intermediate bits are reserved for compression settings */ 51 1.1 reinoud #define NILFS_NOTAIL_FL 0x00008000 /* no mapping; dont merge tail */ 52 1.1 reinoud #define NILFS_DIRSYNC_FL 0x00010000 /* no mapping; dirsync */ 53 1.1 reinoud 54 1.1 reinoud #define NILFS_FL_USER_VISIBLE 0x0003DFFF /* flags visible to user */ 55 1.1 reinoud #define NILFS_FL_USER_MODIFIABLE 0x000380FF /* flags modifiable by user */ 56 1.1 reinoud 57 1.1 reinoud 58 1.1 reinoud 59 1.1 reinoud /* 60 1.1 reinoud * NiLFS stores files in hierarchical B-trees in tupels of (dkey, dptr). 61 1.1 reinoud * Entries in a level N btree point to a btree of level N-1. As dkey value the 62 1.1 reinoud * first block number to be found in the level N-1 btree is taken. 63 1.1 reinoud * 64 1.1 reinoud * To conserve disk space and to reduce an extra lookup, small B-tree's of 65 1.1 reinoud * level 0 consisting of only the first [0..NILFS_DIRECT_KEY_MAX> entries are 66 1.1 reinoud * stored directly into the inode without dkey. Otherwise the entries point to 67 1.1 reinoud * the B-tree's of level N-1. 68 1.1 reinoud * 69 1.1 reinoud * In all B-trees, but of the system DAT-file, the dptr values are virtual 70 1.1 reinoud * block numbers. The dptr values in the B-tree of the system DAT-file are 71 1.1 reinoud * physical block numbers since the DAT performs virtual to physical block 72 1.1 reinoud * mapping. 73 1.1 reinoud */ 74 1.1 reinoud 75 1.1 reinoud #define NILFS_INODE_BMAP_SIZE 7 76 1.1 reinoud 77 1.1 reinoud #define NILFS_BMAP_SIZE (NILFS_INODE_BMAP_SIZE * sizeof(uint64_t)) 78 1.1 reinoud #define NILFS_BMAP_INVALID_PTR 0 79 1.1 reinoud 80 1.1 reinoud #define NILFS_DIRECT_NBLOCKS (NILFS_BMAP_SIZE / sizeof(uint64_t) - 1) 81 1.1 reinoud #define NILFS_DIRECT_KEY_MIN 0 82 1.1 reinoud #define NILFS_DIRECT_KEY_MAX (NILFS_DIRECT_NBLOCKS - 1) 83 1.1 reinoud 84 1.1 reinoud #define NILFS_BMAP_SMALL_LOW NILFS_DIRECT_KEY_MIN 85 1.1 reinoud #define NILFS_BMAP_SMALL_HIGH NILFS_DIRECT_KEY_MAX 86 1.1 reinoud #define NILFS_BMAP_LARGE_LOW NILFS_BTREE_ROOT_NCHILDREN_MAX 87 1.1 reinoud #define NILFS_BMAP_LARGE_HIGH NILFS_BTREE_KEY_MAX 88 1.1 reinoud 89 1.1 reinoud 90 1.1 reinoud /* 91 1.1 reinoud * B-tree header found on all btree blocks and in the direct-entry. Its size 92 1.1 reinoud * should be 64 bits. In a direct entry, it is followed by 64 bits block 93 1.1 reinoud * numbers for the translation of block [0..NILFS_DIRECT_KEY_MAX>. In large 94 1.1 reinoud * bmaps its followed by pairs of 64 bit dkey and 64 bit dptr. 95 1.1 reinoud */ 96 1.1 reinoud 97 1.1 reinoud struct nilfs_btree_node { 98 1.1 reinoud uint8_t bn_flags; /* btree flags */ 99 1.1 reinoud uint8_t bn_level; /* level of btree */ 100 1.1 reinoud uint16_t bn_nchildren; /* number of children in this record */ 101 1.1 reinoud uint32_t bn_pad; /* pad to 64 bits */ 102 1.1 reinoud }; 103 1.1 reinoud 104 1.1 reinoud 105 1.1 reinoud /* btree flags stored in nilfs_btree_node->bn_flags */ 106 1.1 reinoud #define NILFS_BTREE_NODE_ROOT 0x01 107 1.1 reinoud #define NILFS_BMAP_LARGE 0x01 /* equivalent to BTREE_NODE_ROOT */ 108 1.1 reinoud 109 1.1 reinoud /* btree levels stored in nilfs_btree_node->bn_level */ 110 1.1 reinoud #define NILFS_BTREE_LEVEL_DATA 0 111 1.1 reinoud #define NILFS_BTREE_LEVEL_NODE_MIN (NILFS_BTREE_LEVEL_DATA + 1) 112 1.1 reinoud #define NILFS_BTREE_LEVEL_MAX 14 113 1.1 reinoud 114 1.1 reinoud /* 115 1.1 reinoud * Calculate number of entries that fit into the `direct' space 116 1.1 reinoud */ 117 1.1 reinoud #define NILFS_BTREE_ROOT_SIZE NILFS_BMAP_SIZE 118 1.1 reinoud #define NILFS_BTREE_ROOT_NCHILDREN_MAX \ 119 1.1 reinoud ((NILFS_BTREE_ROOT_SIZE - sizeof(struct nilfs_btree_node)) / \ 120 1.1 reinoud (sizeof(uint64_t /* dkey */) + sizeof(uint64_t /* dptr */))) 121 1.1 reinoud #define NILFS_BTREE_ROOT_NCHILDREN_MIN 0 122 1.1 reinoud 123 1.1 reinoud /* 124 1.1 reinoud * Calculate number of entries that fit into a non LEVEL_DATA nodes. Each of 125 1.1 reinoud * those nodes are padded with one extra 64 bit (extension?) 126 1.1 reinoud */ 127 1.1 reinoud #define NILFS_BTREE_NODE_EXTRA_PAD_SIZE (sizeof(uint64_t)) 128 1.1 reinoud #define NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) \ 129 1.1 reinoud (((nodesize) - sizeof(struct nilfs_btree_node) - \ 130 1.1 reinoud NILFS_BTREE_NODE_EXTRA_PAD_SIZE) / \ 131 1.1 reinoud (sizeof(uint64_t /* dkey */) + sizeof(uint64_t /* dptr */))) 132 1.1 reinoud #define NILFS_BTREE_NODE_NCHILDREN_MIN(nodesize) \ 133 1.1 reinoud ((NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) - 1) / 2 + 1) 134 1.1 reinoud #define NILFS_BTREE_KEY_MIN ( (uint64_t) 0) 135 1.1 reinoud #define NILFS_BTREE_KEY_MAX (~(uint64_t) 0) 136 1.1 reinoud 137 1.1 reinoud 138 1.1 reinoud /* 139 1.1 reinoud * NiLFS inode structure. There are a few dedicated inode numbers that are 140 1.1 reinoud * defined here first. 141 1.1 reinoud */ 142 1.1 reinoud 143 1.1 reinoud #define NILFS_ROOT_INO 2 /* Root file inode */ 144 1.1 reinoud #define NILFS_DAT_INO 3 /* DAT file */ 145 1.1 reinoud #define NILFS_CPFILE_INO 4 /* checkpoint file */ 146 1.1 reinoud #define NILFS_SUFILE_INO 5 /* segment usage file */ 147 1.1 reinoud #define NILFS_IFILE_INO 6 /* ifile */ 148 1.1 reinoud #define NILFS_ATIME_INO 7 /* Atime file (reserved) */ 149 1.1 reinoud #define NILFS_XATTR_INO 8 /* Xattribute file (reserved) */ 150 1.1 reinoud #define NILFS_SKETCH_INO 10 /* Sketch file (obsolete) */ 151 1.1 reinoud #define NILFS_USER_INO 11 /* First user's file inode number */ 152 1.1 reinoud 153 1.1 reinoud struct nilfs_inode { 154 1.1 reinoud uint64_t i_blocks; /* size in device blocks */ 155 1.1 reinoud uint64_t i_size; /* size in bytes */ 156 1.1 reinoud uint64_t i_ctime; /* creation time in seconds part */ 157 1.1 reinoud uint64_t i_mtime; /* modification time in seconds part */ 158 1.1 reinoud uint32_t i_ctime_nsec; /* creation time nanoseconds part */ 159 1.1 reinoud uint32_t i_mtime_nsec; /* modification time in nanoseconds */ 160 1.1 reinoud uint32_t i_uid; /* user id */ 161 1.1 reinoud uint32_t i_gid; /* group id */ 162 1.1 reinoud uint16_t i_mode; /* file mode */ 163 1.1 reinoud uint16_t i_links_count; /* number of references to the inode */ 164 1.1 reinoud uint32_t i_flags; /* NILFS_*_FL flags */ 165 1.1 reinoud uint64_t i_bmap[NILFS_INODE_BMAP_SIZE]; /* btree direct/large */ 166 1.1 reinoud #define i_device_code i_bmap[0] /* 64 bits composed of major+minor */ 167 1.1 reinoud uint64_t i_xattr; /* reserved for extended attributes */ 168 1.1 reinoud uint32_t i_generation; /* file generation for NFS */ 169 1.1 reinoud uint32_t i_pad; /* make it 64 bits aligned */ 170 1.1 reinoud }; 171 1.1 reinoud 172 1.1 reinoud 173 1.1 reinoud /* 174 1.1 reinoud * In NiLFS each checkpoint/snapshot has a super root. 175 1.1 reinoud * 176 1.1 reinoud * The super root holds the inodes of the three system files: `dat', `cp' and 177 1.1 reinoud * 'su' files. All other FS state is defined by those. 178 1.1 reinoud * 179 1.1 reinoud * It is crc checksum'ed and time stamped. 180 1.1 reinoud */ 181 1.1 reinoud 182 1.1 reinoud struct nilfs_super_root { 183 1.1 reinoud uint32_t sr_sum; /* check-sum */ 184 1.1 reinoud uint16_t sr_bytes; /* byte count of this structure */ 185 1.1 reinoud uint16_t sr_flags; /* reserved for flags */ 186 1.1 reinoud uint64_t sr_nongc_ctime; /* timestamp, not for cleaner(?) */ 187 1.1 reinoud struct nilfs_inode sr_dat; /* DAT, virt->phys translation inode */ 188 1.1 reinoud struct nilfs_inode sr_cpfile; /* CP, checkpoints inode */ 189 1.1 reinoud struct nilfs_inode sr_sufile; /* SU, segment usage inode */ 190 1.1 reinoud }; 191 1.1 reinoud 192 1.1 reinoud #define NILFS_SR_MDT_OFFSET(inode_size, i) \ 193 1.1 reinoud ((uint32_t)&((struct nilfs_super_root *)0)->sr_dat + \ 194 1.1 reinoud (inode_size) * (i)) 195 1.1 reinoud #define NILFS_SR_DAT_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 0) 196 1.1 reinoud #define NILFS_SR_CPFILE_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 1) 197 1.1 reinoud #define NILFS_SR_SUFILE_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 2) 198 1.1 reinoud #define NILFS_SR_BYTES (sizeof(struct nilfs_super_root)) 199 1.1 reinoud 200 1.1 reinoud 201 1.1 reinoud 202 1.1 reinoud /* 203 1.1 reinoud * NiLFS has a superblock that describes the basic structure and mount 204 1.1 reinoud * history. It also records some sizes of structures found on the disc for 205 1.1 reinoud * sanity checks. 206 1.1 reinoud * 207 1.1 reinoud * The superblock is stored at two places: NILFS_SB_OFFSET_BYTES and 208 1.1 reinoud * NILFS_SB2_OFFSET_BYTES. 209 1.1 reinoud */ 210 1.1 reinoud 211 1.1 reinoud #define NILFS_DFL_MAX_MNT_COUNT 50 /* default 50 mounts before fsck */ 212 1.1 reinoud #define NILFS_EIO_RETRY_COUNT 4 /* then give up, not used yet */ 213 1.1 reinoud 214 1.1 reinoud /* File system states stored on disc in superblock's sbp->s_state */ 215 1.1 reinoud #define NILFS_VALID_FS 0x0001 /* cleanly unmounted and all is ok */ 216 1.1 reinoud #define NILFS_ERROR_FS 0x0002 /* there were errors detected, fsck */ 217 1.1 reinoud #define NILFS_RESIZE_FS 0x0004 /* resize required, XXX unknown flag*/ 218 1.1 reinoud #define NILFS_MOUNT_STATE_BITS "\20\1VALID_FS\2ERROR_FS\3RESIZE_FS" 219 1.1 reinoud 220 1.1 reinoud /* Mount option flags passed in Linux; Not used but here for reference */ 221 1.1 reinoud #define NILFS_MOUNT_ERROR_MODE 0x0070 /* error mode mask */ 222 1.1 reinoud #define NILFS_MOUNT_ERRORS_CONT 0x0010 /* continue on errors */ 223 1.1 reinoud #define NILFS_MOUNT_ERRORS_RO 0x0020 /* remount fs ro on errors */ 224 1.1 reinoud #define NILFS_MOUNT_ERRORS_PANIC 0x0040 /* panic on errors */ 225 1.1 reinoud #define NILFS_MOUNT_SNAPSHOT 0x0080 /* snapshot flag */ 226 1.1 reinoud #define NILFS_MOUNT_BARRIER 0x1000 /* use block barriers XXX what is this? */ 227 1.1 reinoud #define NILFS_MOUNT_STRICT_ORDER 0x2000 /* apply strict in-order; */ 228 1.1 reinoud /* semantics also for data */ 229 1.1 reinoud 230 1.1 reinoud struct nilfs_super_block { 231 1.1 reinoud uint32_t s_rev_level; /* major disk format revision */ 232 1.1 reinoud uint16_t s_minor_rev_level; /* minor disc format revision */ 233 1.1 reinoud uint16_t s_magic; /* magic value for identification */ 234 1.1 reinoud 235 1.1 reinoud uint16_t s_bytes; /* byte count of CRC calculation 236 1.1 reinoud for this structure. s_reserved 237 1.1 reinoud is excluded! */ 238 1.1 reinoud uint16_t s_flags; /* linux mount flags, XXX can they 239 1.1 reinoud be ignored? */ 240 1.1 reinoud uint32_t s_crc_seed; /* seed value of CRC calculation */ 241 1.1 reinoud uint32_t s_sum; /* check sum of super block */ 242 1.1 reinoud 243 1.1 reinoud /* Block size represented as follows 244 1.1 reinoud blocksize = 1 << (s_log_block_size + 10) */ 245 1.1 reinoud uint32_t s_log_block_size; 246 1.1 reinoud uint64_t s_nsegments; /* number of segm. in filesystem */ 247 1.1 reinoud uint64_t s_dev_size; /* block device size in bytes */ 248 1.1 reinoud uint64_t s_first_data_block; /* 1st seg disk block number */ 249 1.1 reinoud uint32_t s_blocks_per_segment; /* number of blocks per segment */ 250 1.1 reinoud uint32_t s_r_segments_percentage; /* reserved segments percentage */ 251 1.1 reinoud 252 1.1 reinoud uint64_t s_last_cno; /* last checkpoint number */ 253 1.1 reinoud uint64_t s_last_pseg; /* addr part. segm. written last */ 254 1.1 reinoud uint64_t s_last_seq; /* seq.number of seg written last */ 255 1.1 reinoud uint64_t s_free_blocks_count; /* free blocks count */ 256 1.1 reinoud 257 1.1 reinoud uint64_t s_ctime; /* creation time (execution time 258 1.1 reinoud of newfs) */ 259 1.1 reinoud uint64_t s_mtime; /* mount time */ 260 1.1 reinoud uint64_t s_wtime; /* write time */ 261 1.1 reinoud uint16_t s_mnt_count; /* mount count */ 262 1.1 reinoud uint16_t s_max_mnt_count; /* maximal mount count */ 263 1.1 reinoud uint16_t s_state; /* file system state */ 264 1.1 reinoud uint16_t s_errors; /* behaviour on detecting errors */ 265 1.1 reinoud uint64_t s_lastcheck; /* time of last checked */ 266 1.1 reinoud 267 1.1 reinoud uint32_t s_checkinterval; /* max. time between checks */ 268 1.1 reinoud uint32_t s_creator_os; /* OS that created it */ 269 1.1 reinoud uint16_t s_def_resuid; /* default uid for reserv. blocks */ 270 1.1 reinoud uint16_t s_def_resgid; /* default gid for reserv. blocks */ 271 1.1 reinoud uint32_t s_first_ino; /* first non-reserved inode */ 272 1.1 reinoud 273 1.1 reinoud uint16_t s_inode_size; /* size of an inode */ 274 1.1 reinoud uint16_t s_dat_entry_size; /* size of a dat entry */ 275 1.1 reinoud uint16_t s_checkpoint_size; /* size of a checkpoint */ 276 1.1 reinoud uint16_t s_segment_usage_size; /* size of a segment usage */ 277 1.1 reinoud 278 1.1 reinoud uint8_t s_uuid[16]; /* 128-bit uuid for volume */ 279 1.2 reinoud char s_volume_name[80]; /* volume name */ 280 1.1 reinoud 281 1.1 reinoud uint32_t s_c_interval; /* commit interval of segment */ 282 1.1 reinoud uint32_t s_c_block_max; /* threshold of data amount for 283 1.1 reinoud the segment construction */ 284 1.1 reinoud uint32_t s_reserved[192]; /* padding to end of the block */ 285 1.1 reinoud }; 286 1.1 reinoud 287 1.1 reinoud #define NILFS_SUPER_MAGIC 0x3434 /* NILFS filesystem magic number */ 288 1.1 reinoud #define NILFS_SB_OFFSET_BYTES 1024 /* byte offset of nilfs superblock */ 289 1.1 reinoud #define NILFS_SB2_OFFSET_BYTES(devsize) ((((devsize) >> 12) - 1) << 12) 290 1.1 reinoud 291 1.1 reinoud 292 1.1 reinoud /* codes for operating systems in superblock */ 293 1.1 reinoud #define NILFS_OS_LINUX 0 294 1.1 reinoud #define NILFS_OS_UNK1 1 /* ext2 */ 295 1.1 reinoud #define NILFS_OS_UNK2 2 /* ext2 */ 296 1.1 reinoud #define NILFS_OS_UNK3 3 /* ext2 */ 297 1.1 reinoud #define NILFS_OS_NETBSD 10 /* temp */ 298 1.1 reinoud 299 1.1 reinoud /* NiLFS revision levels */ 300 1.1 reinoud #define NILFS_CURRENT_REV 2 /* current major revision */ 301 1.1 reinoud #define NILFS_MINOR_REV 0 /* minor revision */ 302 1.1 reinoud 303 1.1 reinoud /* Bytes count of super_block for CRC-calculation */ 304 1.1 reinoud #define NILFS_SB_BYTES \ 305 1.1 reinoud ((uint32_t)&((struct nilfs_super_block *)0)->s_reserved) 306 1.1 reinoud 307 1.1 reinoud /* Maximal count of links to a file */ 308 1.1 reinoud #define NILFS_LINK_MAX 32000 309 1.1 reinoud 310 1.1 reinoud 311 1.1 reinoud /* 312 1.1 reinoud * Structure of a directory entry, same as ext2. 313 1.1 reinoud * 314 1.1 reinoud * The `file_type' is chosen there since filenames are limited to 256 bytes 315 1.1 reinoud * and the name_len in ext2 is a two byter. 316 1.1 reinoud * 317 1.1 reinoud * Note that they can't span blocks; the rec_len fills out. 318 1.1 reinoud */ 319 1.1 reinoud 320 1.1 reinoud #define NILFS_NAME_LEN 255 321 1.1 reinoud struct nilfs_dir_entry { 322 1.1 reinoud uint64_t inode; /* inode number */ 323 1.1 reinoud uint16_t rec_len; /* directory entry length */ 324 1.1 reinoud uint8_t name_len; /* name length */ 325 1.1 reinoud uint8_t file_type; 326 1.1 reinoud char name[NILFS_NAME_LEN]; /* file name */ 327 1.1 reinoud char pad; 328 1.1 reinoud }; 329 1.1 reinoud 330 1.1 reinoud /* 331 1.1 reinoud * NILFS directory file types. Only the low 3 bits are used. The 332 1.1 reinoud * other bits are reserved for now. 333 1.1 reinoud */ 334 1.1 reinoud enum { 335 1.1 reinoud NILFS_FT_UNKNOWN, 336 1.1 reinoud NILFS_FT_REG_FILE, 337 1.1 reinoud NILFS_FT_DIR, 338 1.1 reinoud NILFS_FT_CHRDEV, 339 1.1 reinoud NILFS_FT_BLKDEV, 340 1.1 reinoud NILFS_FT_FIFO, 341 1.1 reinoud NILFS_FT_SOCK, 342 1.1 reinoud NILFS_FT_SYMLINK, 343 1.1 reinoud NILFS_FT_MAX 344 1.1 reinoud }; 345 1.1 reinoud 346 1.1 reinoud /* 347 1.1 reinoud * NILFS_DIR_PAD defines the directory entries boundaries 348 1.1 reinoud * 349 1.1 reinoud * NOTE: It must be a multiple of 8 350 1.1 reinoud */ 351 1.1 reinoud #define NILFS_DIR_PAD 8 352 1.1 reinoud #define NILFS_DIR_ROUND (NILFS_DIR_PAD - 1) 353 1.1 reinoud #define NILFS_DIR_REC_LEN(name_len) (((name_len) + 12 + NILFS_DIR_ROUND) & \ 354 1.1 reinoud ~NILFS_DIR_ROUND) 355 1.1 reinoud 356 1.1 reinoud /* 357 1.1 reinoud * NiLFS devides the disc into fixed length segments. Each segment is filled 358 1.1 reinoud * with one or more partial segments of variable lengths. 359 1.1 reinoud * 360 1.1 reinoud * Each partial segment has a segment summary header followed by updates of 361 1.1 reinoud * files and optionally a super root. 362 1.1 reinoud */ 363 1.1 reinoud 364 1.1 reinoud struct nilfs_finfo { 365 1.1 reinoud uint64_t fi_ino; /* inode number */ 366 1.1 reinoud uint64_t fi_cno; /* checkpoint associated with this */ 367 1.1 reinoud uint32_t fi_nblocks; /* size in blocks of this finfo */ 368 1.1 reinoud uint32_t fi_ndatablk; /* number of data blocks */ 369 1.1 reinoud /* For the DAT file */ 370 1.1 reinoud /* fi_ndatablk * nilfs_binfo.bi_dat.bi_blkoff */ 371 1.1 reinoud /* fi_nblocks - fi_ndatablks * nilfs_binfo.bi_dat */ 372 1.1 reinoud /* Other files */ 373 1.1 reinoud /* fi_ndatablk * nilfs_binfo.bi_v */ 374 1.1 reinoud /* fi_nblocks - fi_ndatablks * nilfs_binfo.bi_v.bi_vblocknr */ 375 1.1 reinoud }; 376 1.1 reinoud 377 1.1 reinoud 378 1.1 reinoud /* 379 1.1 reinoud * Virtual to physical block translation information. For data blocks it maps 380 1.1 reinoud * logical block number bi_blkoff to virtual block nr bi_vblocknr. For non 381 1.1 reinoud * datablocks it is the virtual block number assigned to an inserted btree 382 1.1 reinoud * level and thus has no bi_blkoff. The physical block number is the next 383 1.1 reinoud * available data block in the partial segment after all the finfo's. 384 1.1 reinoud */ 385 1.1 reinoud struct nilfs_binfo_v { 386 1.1 reinoud uint64_t bi_vblocknr; /* assigned virtual block number */ 387 1.1 reinoud uint64_t bi_blkoff; /* for file's logical block number */ 388 1.1 reinoud }; 389 1.1 reinoud 390 1.1 reinoud 391 1.1 reinoud /* 392 1.1 reinoud * DAT allocation. For data blocks just the logical block number that maps on 393 1.1 reinoud * the next available data block in the partial segment after the finfo's. 394 1.1 reinoud * Intermediate btree blocks are looked up by their blkoffset dkey and their 395 1.1 reinoud * level and given the next available data block. 396 1.1 reinoud */ 397 1.1 reinoud struct nilfs_binfo_dat { 398 1.1 reinoud uint64_t bi_blkoff; /* DAT file's logical block number */ 399 1.1 reinoud uint8_t bi_level; /* btree level */ 400 1.1 reinoud uint8_t bi_pad[7]; 401 1.1 reinoud }; 402 1.1 reinoud 403 1.1 reinoud 404 1.1 reinoud /* Convenience union for both types of binfo's */ 405 1.1 reinoud union nilfs_binfo { 406 1.1 reinoud struct nilfs_binfo_v bi_v; 407 1.1 reinoud struct nilfs_binfo_dat bi_dat; 408 1.1 reinoud }; 409 1.1 reinoud 410 1.1 reinoud 411 1.1 reinoud /* The (partial) segment summary itself */ 412 1.1 reinoud struct nilfs_segment_summary { 413 1.1 reinoud uint32_t ss_datasum; /* CRC of complete data block */ 414 1.1 reinoud uint32_t ss_sumsum; /* CRC of segment summary only */ 415 1.1 reinoud uint32_t ss_magic; /* magic to identify segment summary */ 416 1.1 reinoud uint16_t ss_bytes; /* size of segment summary structure */ 417 1.1 reinoud uint16_t ss_flags; /* NILFS_SS_* flags */ 418 1.1 reinoud uint64_t ss_seq; /* sequence number of this segm. sum */ 419 1.1 reinoud uint64_t ss_create; /* creation timestamp in seconds */ 420 1.1 reinoud uint64_t ss_next; /* blocknumber of next segment */ 421 1.1 reinoud uint32_t ss_nblocks; /* number of blocks follow */ 422 1.1 reinoud uint32_t ss_nfinfo; /* number of finfo structures follow */ 423 1.1 reinoud uint32_t ss_sumbytes; /* total size of segment summary */ 424 1.1 reinoud uint32_t ss_pad; 425 1.2 reinoud uint64_t ss_cno; /* latest checkpoint number known */ 426 1.1 reinoud /* stream of finfo structures */ 427 1.1 reinoud }; 428 1.1 reinoud 429 1.1 reinoud #define NILFS_SEGSUM_MAGIC 0x1eaffa11 /* segment summary magic number */ 430 1.1 reinoud 431 1.1 reinoud /* Segment summary flags */ 432 1.1 reinoud #define NILFS_SS_LOGBGN 0x0001 /* begins a logical segment */ 433 1.1 reinoud #define NILFS_SS_LOGEND 0x0002 /* ends a logical segment */ 434 1.1 reinoud #define NILFS_SS_SR 0x0004 /* has super root */ 435 1.1 reinoud #define NILFS_SS_SYNDT 0x0008 /* includes data only updates */ 436 1.1 reinoud #define NILFS_SS_GC 0x0010 /* segment written for cleaner operation */ 437 1.1 reinoud #define NILFS_SS_FLAG_BITS "\20\1LOGBGN\2LOGEND\3SR\4SYNDT\5GC" 438 1.1 reinoud 439 1.5 andvar /* Segment summary constraints */ 440 1.1 reinoud #define NILFS_SEG_MIN_BLOCKS 16 /* minimum number of blocks in a 441 1.1 reinoud full segment */ 442 1.1 reinoud #define NILFS_PSEG_MIN_BLOCKS 2 /* minimum number of blocks in a 443 1.1 reinoud partial segment */ 444 1.1 reinoud #define NILFS_MIN_NRSVSEGS 8 /* minimum number of reserved 445 1.1 reinoud segments */ 446 1.1 reinoud 447 1.1 reinoud /* 448 1.1 reinoud * Structure of DAT/inode file. 449 1.1 reinoud * 450 1.4 andvar * A DAT file is divided into groups. The maximum number of groups is the 451 1.1 reinoud * number of block group descriptors that fit into one block; this descriptor 452 1.1 reinoud * only gives the number of free entries in the associated group. 453 1.1 reinoud * 454 1.1 reinoud * Each group has a block sized bitmap indicating if an entry is taken or 455 1.1 reinoud * empty. Each bit stands for a DAT entry. 456 1.1 reinoud * 457 1.1 reinoud * The inode file has exactly the same format only the entries are inode 458 1.1 reinoud * entries. 459 1.1 reinoud */ 460 1.1 reinoud 461 1.1 reinoud struct nilfs_block_group_desc { 462 1.1 reinoud uint32_t bg_nfrees; /* num. free entries in block group */ 463 1.1 reinoud }; 464 1.1 reinoud 465 1.1 reinoud 466 1.1 reinoud /* DAT entry in a super root's DAT file */ 467 1.1 reinoud struct nilfs_dat_entry { 468 1.1 reinoud uint64_t de_blocknr; /* block number */ 469 1.1 reinoud uint64_t de_start; /* valid from checkpoint */ 470 1.1 reinoud uint64_t de_end; /* valid till checkpoint */ 471 1.1 reinoud uint64_t de_rsv; /* reserved for future use */ 472 1.1 reinoud }; 473 1.1 reinoud 474 1.1 reinoud 475 1.1 reinoud /* 476 1.1 reinoud * Structure of CP file. 477 1.1 reinoud * 478 1.1 reinoud * A snapshot is just a checkpoint only its protected against removal by the 479 1.1 reinoud * cleaner. The snapshots are kept on a double linked list of checkpoints. 480 1.1 reinoud */ 481 1.1 reinoud 482 1.1 reinoud struct nilfs_snapshot_list { 483 1.1 reinoud uint64_t ssl_next; /* checkpoint nr. forward */ 484 1.1 reinoud uint64_t ssl_prev; /* checkpoint nr. back */ 485 1.1 reinoud }; 486 1.1 reinoud 487 1.1 reinoud 488 1.1 reinoud /* checkpoint entry structure */ 489 1.1 reinoud struct nilfs_checkpoint { 490 1.1 reinoud uint32_t cp_flags; /* NILFS_CHECKPOINT_* flags */ 491 1.1 reinoud uint32_t cp_checkpoints_count; /* ZERO, not used anymore? */ 492 1.1 reinoud struct nilfs_snapshot_list cp_snapshot_list; /* list of snapshots */ 493 1.1 reinoud uint64_t cp_cno; /* checkpoint number */ 494 1.1 reinoud uint64_t cp_create; /* creation timestamp */ 495 1.1 reinoud uint64_t cp_nblk_inc; /* number of blocks incremented */ 496 1.1 reinoud uint64_t cp_inodes_count; /* number of inodes in this cp. */ 497 1.1 reinoud uint64_t cp_blocks_count; /* reserved (might be deleted) */ 498 1.1 reinoud struct nilfs_inode cp_ifile_inode; /* inode file inode */ 499 1.1 reinoud }; 500 1.1 reinoud 501 1.1 reinoud /* checkpoint flags */ 502 1.1 reinoud #define NILFS_CHECKPOINT_SNAPSHOT 1 503 1.1 reinoud #define NILFS_CHECKPOINT_INVALID 2 504 1.1 reinoud #define NILFS_CHECKPOINT_SKETCH 4 505 1.1 reinoud #define NILFS_CHECKPOINT_MINOR 8 506 1.1 reinoud #define NILFS_CHECKPOINT_BITS "\20\1SNAPSHOT\2INVALID\3SKETCH\4MINOR" 507 1.1 reinoud 508 1.1 reinoud 509 1.1 reinoud /* header of the checkpoint file */ 510 1.1 reinoud struct nilfs_cpfile_header { 511 1.1 reinoud uint64_t ch_ncheckpoints; /* number of checkpoints */ 512 1.1 reinoud uint64_t ch_nsnapshots; /* number of snapshots */ 513 1.1 reinoud struct nilfs_snapshot_list ch_snapshot_list; /* snapshot list */ 514 1.1 reinoud }; 515 1.1 reinoud 516 1.3 mbalmer /* to accommodate with the header */ 517 1.1 reinoud #define NILFS_CPFILE_FIRST_CHECKPOINT_OFFSET \ 518 1.1 reinoud ((sizeof(struct nilfs_cpfile_header) + \ 519 1.1 reinoud sizeof(struct nilfs_checkpoint) - 1) / \ 520 1.1 reinoud sizeof(struct nilfs_checkpoint)) 521 1.1 reinoud 522 1.1 reinoud 523 1.1 reinoud /* 524 1.1 reinoud * Structure of SU file. 525 1.1 reinoud * 526 1.1 reinoud * The segment usage file sums up how each of the segments are used. They are 527 1.1 reinoud * indexed by their segment number. 528 1.1 reinoud */ 529 1.1 reinoud 530 1.1 reinoud /* segment usage entry */ 531 1.1 reinoud struct nilfs_segment_usage { 532 1.1 reinoud uint64_t su_lastmod; /* last modified timestamp */ 533 1.1 reinoud uint32_t su_nblocks; /* number of blocks in segment */ 534 1.1 reinoud uint32_t su_flags; /* NILFS_SEGMENT_USAGE_* flags */ 535 1.1 reinoud }; 536 1.1 reinoud 537 1.1 reinoud /* segment usage flag */ 538 1.1 reinoud #define NILFS_SEGMENT_USAGE_ACTIVE 1 539 1.1 reinoud #define NILFS_SEGMENT_USAGE_DIRTY 2 540 1.1 reinoud #define NILFS_SEGMENT_USAGE_ERROR 4 541 1.1 reinoud #define NILFS_SEGMENT_USAGE_BITS "\20\1ACTIVE\2DIRTY\3ERROR" 542 1.1 reinoud 543 1.1 reinoud 544 1.1 reinoud /* header of the segment usage file */ 545 1.1 reinoud struct nilfs_sufile_header { 546 1.1 reinoud uint64_t sh_ncleansegs; /* number of segments marked clean */ 547 1.1 reinoud uint64_t sh_ndirtysegs; /* number of segments marked dirty */ 548 1.1 reinoud uint64_t sh_last_alloc; /* last allocated segment number */ 549 1.1 reinoud /* ... */ 550 1.1 reinoud }; 551 1.1 reinoud 552 1.3 mbalmer /* to accommodate with the header */ 553 1.1 reinoud #define NILFS_SUFILE_FIRST_SEGMENT_USAGE_OFFSET \ 554 1.1 reinoud ((sizeof(struct nilfs_sufile_header) + \ 555 1.1 reinoud sizeof(struct nilfs_segment_usage) - 1) / \ 556 1.1 reinoud sizeof(struct nilfs_segment_usage)) 557 1.1 reinoud 558 1.1 reinoud 559 1.1 reinoud #endif 560 1.1 reinoud 561