inode.c (26609b619fa2301eb7eb5855a7005d99f8a07a73) | inode.c (a3e70fb287ee62ee14512a69e9a3e1870a057e11) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2 3#include "bcachefs.h" 4#include "bkey_methods.h" 5#include "btree_update.h" 6#include "error.h" 7#include "extents.h" 8#include "inode.h" --- 84 unchanged lines hidden (view full) --- 93 unsigned nr_fields = 0, last_nonzero_fieldnr = 0; 94 95 bkey_inode_init(&packed->inode.k_i); 96 packed->inode.k.p.inode = inode->bi_inum; 97 packed->inode.v.bi_hash_seed = inode->bi_hash_seed; 98 packed->inode.v.bi_flags = cpu_to_le32(inode->bi_flags); 99 packed->inode.v.bi_mode = cpu_to_le16(inode->bi_mode); 100 | 1// SPDX-License-Identifier: GPL-2.0 2 3#include "bcachefs.h" 4#include "bkey_methods.h" 5#include "btree_update.h" 6#include "error.h" 7#include "extents.h" 8#include "inode.h" --- 84 unchanged lines hidden (view full) --- 93 unsigned nr_fields = 0, last_nonzero_fieldnr = 0; 94 95 bkey_inode_init(&packed->inode.k_i); 96 packed->inode.k.p.inode = inode->bi_inum; 97 packed->inode.v.bi_hash_seed = inode->bi_hash_seed; 98 packed->inode.v.bi_flags = cpu_to_le32(inode->bi_flags); 99 packed->inode.v.bi_mode = cpu_to_le16(inode->bi_mode); 100 |
101#define BCH_INODE_FIELD(_name, _bits) \ | 101#define x(_name, _bits) \ |
102 out += inode_encode_field(out, end, 0, inode->_name); \ 103 nr_fields++; \ 104 \ 105 if (inode->_name) { \ 106 last_nonzero_field = out; \ 107 last_nonzero_fieldnr = nr_fields; \ 108 } 109 110 BCH_INODE_FIELDS() | 102 out += inode_encode_field(out, end, 0, inode->_name); \ 103 nr_fields++; \ 104 \ 105 if (inode->_name) { \ 106 last_nonzero_field = out; \ 107 last_nonzero_fieldnr = nr_fields; \ 108 } 109 110 BCH_INODE_FIELDS() |
111#undef BCH_INODE_FIELD | 111#undef x |
112 113 out = last_nonzero_field; 114 nr_fields = last_nonzero_fieldnr; 115 116 set_bkey_val_bytes(&packed->inode.k, out - (u8 *) &packed->inode.v); 117 memset(out, 0, 118 (u8 *) &packed->inode.v + 119 bkey_val_bytes(&packed->inode.k) - out); --- 5 unchanged lines hidden (view full) --- 125 126 int ret = bch2_inode_unpack(inode_i_to_s_c(&packed->inode), 127 &unpacked); 128 BUG_ON(ret); 129 BUG_ON(unpacked.bi_inum != inode->bi_inum); 130 BUG_ON(unpacked.bi_hash_seed != inode->bi_hash_seed); 131 BUG_ON(unpacked.bi_mode != inode->bi_mode); 132 | 112 113 out = last_nonzero_field; 114 nr_fields = last_nonzero_fieldnr; 115 116 set_bkey_val_bytes(&packed->inode.k, out - (u8 *) &packed->inode.v); 117 memset(out, 0, 118 (u8 *) &packed->inode.v + 119 bkey_val_bytes(&packed->inode.k) - out); --- 5 unchanged lines hidden (view full) --- 125 126 int ret = bch2_inode_unpack(inode_i_to_s_c(&packed->inode), 127 &unpacked); 128 BUG_ON(ret); 129 BUG_ON(unpacked.bi_inum != inode->bi_inum); 130 BUG_ON(unpacked.bi_hash_seed != inode->bi_hash_seed); 131 BUG_ON(unpacked.bi_mode != inode->bi_mode); 132 |
133#define BCH_INODE_FIELD(_name, _bits) BUG_ON(unpacked._name != inode->_name); | 133#define x(_name, _bits) BUG_ON(unpacked._name != inode->_name); |
134 BCH_INODE_FIELDS() | 134 BCH_INODE_FIELDS() |
135#undef BCH_INODE_FIELD | 135#undef x |
136 } 137} 138 139int bch2_inode_unpack(struct bkey_s_c_inode inode, 140 struct bch_inode_unpacked *unpacked) 141{ 142 const u8 *in = inode.v->fields; 143 const u8 *end = (void *) inode.v + bkey_val_bytes(inode.k); 144 u64 field[2]; 145 unsigned fieldnr = 0, field_bits; 146 int ret; 147 148 unpacked->bi_inum = inode.k->p.inode; 149 unpacked->bi_hash_seed = inode.v->bi_hash_seed; 150 unpacked->bi_flags = le32_to_cpu(inode.v->bi_flags); 151 unpacked->bi_mode = le16_to_cpu(inode.v->bi_mode); 152 | 136 } 137} 138 139int bch2_inode_unpack(struct bkey_s_c_inode inode, 140 struct bch_inode_unpacked *unpacked) 141{ 142 const u8 *in = inode.v->fields; 143 const u8 *end = (void *) inode.v + bkey_val_bytes(inode.k); 144 u64 field[2]; 145 unsigned fieldnr = 0, field_bits; 146 int ret; 147 148 unpacked->bi_inum = inode.k->p.inode; 149 unpacked->bi_hash_seed = inode.v->bi_hash_seed; 150 unpacked->bi_flags = le32_to_cpu(inode.v->bi_flags); 151 unpacked->bi_mode = le16_to_cpu(inode.v->bi_mode); 152 |
153#define BCH_INODE_FIELD(_name, _bits) \ | 153#define x(_name, _bits) \ |
154 if (fieldnr++ == INODE_NR_FIELDS(inode.v)) { \ 155 unsigned offset = offsetof(struct bch_inode_unpacked, _name);\ 156 memset((void *) unpacked + offset, 0, \ 157 sizeof(*unpacked) - offset); \ 158 return 0; \ 159 } \ 160 \ 161 ret = inode_decode_field(in, end, field, &field_bits); \ 162 if (ret < 0) \ 163 return ret; \ 164 \ 165 if (field_bits > sizeof(unpacked->_name) * 8) \ 166 return -1; \ 167 \ 168 unpacked->_name = field[1]; \ 169 in += ret; 170 171 BCH_INODE_FIELDS() | 154 if (fieldnr++ == INODE_NR_FIELDS(inode.v)) { \ 155 unsigned offset = offsetof(struct bch_inode_unpacked, _name);\ 156 memset((void *) unpacked + offset, 0, \ 157 sizeof(*unpacked) - offset); \ 158 return 0; \ 159 } \ 160 \ 161 ret = inode_decode_field(in, end, field, &field_bits); \ 162 if (ret < 0) \ 163 return ret; \ 164 \ 165 if (field_bits > sizeof(unpacked->_name) * 8) \ 166 return -1; \ 167 \ 168 unpacked->_name = field[1]; \ 169 in += ret; 170 171 BCH_INODE_FIELDS() |
172#undef BCH_INODE_FIELD | 172#undef x |
173 174 /* XXX: signal if there were more fields than expected? */ 175 176 return 0; 177} 178 179const char *bch2_inode_invalid(const struct bch_fs *c, struct bkey_s_c k) 180{ --- 34 unchanged lines hidden (view full) --- 215 struct bkey_s_c_inode inode = bkey_s_c_to_inode(k); 216 struct bch_inode_unpacked unpacked; 217 218 if (bch2_inode_unpack(inode, &unpacked)) { 219 pr_buf(out, "(unpack error)"); 220 return; 221 } 222 | 173 174 /* XXX: signal if there were more fields than expected? */ 175 176 return 0; 177} 178 179const char *bch2_inode_invalid(const struct bch_fs *c, struct bkey_s_c k) 180{ --- 34 unchanged lines hidden (view full) --- 215 struct bkey_s_c_inode inode = bkey_s_c_to_inode(k); 216 struct bch_inode_unpacked unpacked; 217 218 if (bch2_inode_unpack(inode, &unpacked)) { 219 pr_buf(out, "(unpack error)"); 220 return; 221 } 222 |
223#define BCH_INODE_FIELD(_name, _bits) \ | 223#define x(_name, _bits) \ |
224 pr_buf(out, #_name ": %llu ", (u64) unpacked._name); 225 BCH_INODE_FIELDS() | 224 pr_buf(out, #_name ": %llu ", (u64) unpacked._name); 225 BCH_INODE_FIELDS() |
226#undef BCH_INODE_FIELD | 226#undef x |
227} 228 229const char *bch2_inode_generation_invalid(const struct bch_fs *c, 230 struct bkey_s_c k) 231{ 232 if (k.k->p.offset) 233 return "nonzero offset"; 234 --- 25 unchanged lines hidden (view full) --- 260 inode_u->bi_gid = gid; 261 inode_u->bi_dev = rdev; 262 inode_u->bi_atime = now; 263 inode_u->bi_mtime = now; 264 inode_u->bi_ctime = now; 265 inode_u->bi_otime = now; 266 267 if (parent) { | 227} 228 229const char *bch2_inode_generation_invalid(const struct bch_fs *c, 230 struct bkey_s_c k) 231{ 232 if (k.k->p.offset) 233 return "nonzero offset"; 234 --- 25 unchanged lines hidden (view full) --- 260 inode_u->bi_gid = gid; 261 inode_u->bi_dev = rdev; 262 inode_u->bi_atime = now; 263 inode_u->bi_mtime = now; 264 inode_u->bi_ctime = now; 265 inode_u->bi_otime = now; 266 267 if (parent) { |
268#define BCH_INODE_FIELD(_name) inode_u->_name = parent->_name; | 268#define x(_name) inode_u->_name = parent->_name; |
269 BCH_INODE_FIELDS_INHERIT() | 269 BCH_INODE_FIELDS_INHERIT() |
270#undef BCH_INODE_FIELD | 270#undef x |
271 } 272} 273 274static inline u32 bkey_generation(struct bkey_s_c k) 275{ 276 switch (k.k->type) { 277 case KEY_TYPE_inode: 278 BUG(); --- 212 unchanged lines hidden --- | 271 } 272} 273 274static inline u32 bkey_generation(struct bkey_s_c k) 275{ 276 switch (k.k->type) { 277 case KEY_TYPE_inode: 278 BUG(); --- 212 unchanged lines hidden --- |