1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _BCACHEFS_INODE_FORMAT_H 3 #define _BCACHEFS_INODE_FORMAT_H 4 5 #define BLOCKDEV_INODE_MAX 4096 6 #define BCACHEFS_ROOT_INO 4096 7 8 struct bch_inode { 9 struct bch_val v; 10 11 __le64 bi_hash_seed; 12 __le32 bi_flags; 13 __le16 bi_mode; 14 __u8 fields[]; 15 } __packed __aligned(8); 16 17 struct bch_inode_v2 { 18 struct bch_val v; 19 20 __le64 bi_journal_seq; 21 __le64 bi_hash_seed; 22 __le64 bi_flags; 23 __le16 bi_mode; 24 __u8 fields[]; 25 } __packed __aligned(8); 26 27 struct bch_inode_v3 { 28 struct bch_val v; 29 30 __le64 bi_journal_seq; 31 __le64 bi_hash_seed; 32 __le64 bi_flags; 33 __le64 bi_sectors; 34 __le64 bi_size; 35 __le64 bi_version; 36 __u8 fields[]; 37 } __packed __aligned(8); 38 39 #define INODEv3_FIELDS_START_INITIAL 6 40 #define INODEv3_FIELDS_START_CUR (offsetof(struct bch_inode_v3, fields) / sizeof(__u64)) 41 42 struct bch_inode_generation { 43 struct bch_val v; 44 45 __le32 bi_generation; 46 __le32 pad; 47 } __packed __aligned(8); 48 49 /* 50 * bi_subvol and bi_parent_subvol are only set for subvolume roots: 51 */ 52 53 #define BCH_INODE_FIELDS_v2() \ 54 x(bi_atime, 96) \ 55 x(bi_ctime, 96) \ 56 x(bi_mtime, 96) \ 57 x(bi_otime, 96) \ 58 x(bi_size, 64) \ 59 x(bi_sectors, 64) \ 60 x(bi_uid, 32) \ 61 x(bi_gid, 32) \ 62 x(bi_nlink, 32) \ 63 x(bi_generation, 32) \ 64 x(bi_dev, 32) \ 65 x(bi_data_checksum, 8) \ 66 x(bi_compression, 8) \ 67 x(bi_project, 32) \ 68 x(bi_background_compression, 8) \ 69 x(bi_data_replicas, 8) \ 70 x(bi_promote_target, 16) \ 71 x(bi_foreground_target, 16) \ 72 x(bi_background_target, 16) \ 73 x(bi_erasure_code, 16) \ 74 x(bi_fields_set, 16) \ 75 x(bi_dir, 64) \ 76 x(bi_dir_offset, 64) \ 77 x(bi_subvol, 32) \ 78 x(bi_parent_subvol, 32) 79 80 #define BCH_INODE_FIELDS_v3() \ 81 x(bi_atime, 96) \ 82 x(bi_ctime, 96) \ 83 x(bi_mtime, 96) \ 84 x(bi_otime, 96) \ 85 x(bi_uid, 32) \ 86 x(bi_gid, 32) \ 87 x(bi_nlink, 32) \ 88 x(bi_generation, 32) \ 89 x(bi_dev, 32) \ 90 x(bi_data_checksum, 8) \ 91 x(bi_compression, 8) \ 92 x(bi_project, 32) \ 93 x(bi_background_compression, 8) \ 94 x(bi_data_replicas, 8) \ 95 x(bi_promote_target, 16) \ 96 x(bi_foreground_target, 16) \ 97 x(bi_background_target, 16) \ 98 x(bi_erasure_code, 16) \ 99 x(bi_fields_set, 16) \ 100 x(bi_dir, 64) \ 101 x(bi_dir_offset, 64) \ 102 x(bi_subvol, 32) \ 103 x(bi_parent_subvol, 32) \ 104 x(bi_nocow, 8) \ 105 x(bi_depth, 32) \ 106 x(bi_inodes_32bit, 8) 107 108 /* subset of BCH_INODE_FIELDS */ 109 #define BCH_INODE_OPTS() \ 110 x(data_checksum, 8) \ 111 x(compression, 8) \ 112 x(project, 32) \ 113 x(background_compression, 8) \ 114 x(data_replicas, 8) \ 115 x(promote_target, 16) \ 116 x(foreground_target, 16) \ 117 x(background_target, 16) \ 118 x(erasure_code, 16) \ 119 x(nocow, 8) \ 120 x(inodes_32bit, 8) 121 122 enum inode_opt_id { 123 #define x(name, ...) \ 124 Inode_opt_##name, 125 BCH_INODE_OPTS() 126 #undef x 127 Inode_opt_nr, 128 }; 129 130 #define BCH_INODE_FLAGS() \ 131 x(sync, 0) \ 132 x(immutable, 1) \ 133 x(append, 2) \ 134 x(nodump, 3) \ 135 x(noatime, 4) \ 136 x(i_size_dirty, 5) \ 137 x(i_sectors_dirty, 6) \ 138 x(unlinked, 7) \ 139 x(backptr_untrusted, 8) \ 140 x(has_child_snapshot, 9) 141 142 /* bits 20+ reserved for packed fields below: */ 143 144 enum bch_inode_flags { 145 #define x(t, n) BCH_INODE_##t = 1U << n, 146 BCH_INODE_FLAGS() 147 #undef x 148 }; 149 150 enum __bch_inode_flags { 151 #define x(t, n) __BCH_INODE_##t = n, 152 BCH_INODE_FLAGS() 153 #undef x 154 }; 155 156 LE32_BITMASK(INODEv1_STR_HASH, struct bch_inode, bi_flags, 20, 24); 157 LE32_BITMASK(INODEv1_NR_FIELDS, struct bch_inode, bi_flags, 24, 31); 158 LE32_BITMASK(INODEv1_NEW_VARINT,struct bch_inode, bi_flags, 31, 32); 159 160 LE64_BITMASK(INODEv2_STR_HASH, struct bch_inode_v2, bi_flags, 20, 24); 161 LE64_BITMASK(INODEv2_NR_FIELDS, struct bch_inode_v2, bi_flags, 24, 31); 162 163 LE64_BITMASK(INODEv3_STR_HASH, struct bch_inode_v3, bi_flags, 20, 24); 164 LE64_BITMASK(INODEv3_NR_FIELDS, struct bch_inode_v3, bi_flags, 24, 31); 165 166 LE64_BITMASK(INODEv3_FIELDS_START, 167 struct bch_inode_v3, bi_flags, 31, 36); 168 LE64_BITMASK(INODEv3_MODE, struct bch_inode_v3, bi_flags, 36, 52); 169 170 struct bch_inode_alloc_cursor { 171 struct bch_val v; 172 __u8 bits; 173 __u8 pad; 174 __le32 gen; 175 __le64 idx; 176 }; 177 178 #endif /* _BCACHEFS_INODE_FORMAT_H */ 179