Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 1 | #ifndef __BTRFS__ |
| 2 | #define __BTRFS__ |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 3 | |
Chris Mason | ed2ff2c | 2007-03-01 18:59:40 -0500 | [diff] [blame] | 4 | #include "list.h" |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 5 | #include "kerncompat.h" |
Chris Mason | ed2ff2c | 2007-03-01 18:59:40 -0500 | [diff] [blame] | 6 | |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 7 | struct btrfs_trans_handle; |
| 8 | |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 9 | #define BTRFS_MAGIC "_BtRfS_M" |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 10 | |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 11 | #define BTRFS_ROOT_TREE_OBJECTID 1 |
| 12 | #define BTRFS_EXTENT_TREE_OBJECTID 2 |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 13 | #define BTRFS_INODE_MAP_OBJECTID 3 |
| 14 | #define BTRFS_FS_TREE_OBJECTID 4 |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 15 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 16 | /* |
| 17 | * the key defines the order in the tree, and so it also defines (optimal) |
| 18 | * block layout. objectid corresonds to the inode number. The flags |
| 19 | * tells us things about the object, and is a kind of stream selector. |
| 20 | * so for a given inode, keys with flags of 1 might refer to the inode |
| 21 | * data, flags of 2 may point to file data in the btree and flags == 3 |
| 22 | * may point to extents. |
| 23 | * |
| 24 | * offset is the starting byte offset for this key in the stream. |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 25 | * |
| 26 | * btrfs_disk_key is in disk byte order. struct btrfs_key is always |
| 27 | * in cpu native order. Otherwise they are identical and their sizes |
| 28 | * should be the same (ie both packed) |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 29 | */ |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 30 | struct btrfs_disk_key { |
| 31 | __le64 objectid; |
Chris Mason | a1516c8 | 2007-03-14 14:26:53 -0400 | [diff] [blame] | 32 | __le32 flags; |
Chris Mason | a8a2ee0 | 2007-03-16 08:46:49 -0400 | [diff] [blame] | 33 | __le64 offset; |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 34 | } __attribute__ ((__packed__)); |
| 35 | |
| 36 | struct btrfs_key { |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 37 | u64 objectid; |
Chris Mason | a1516c8 | 2007-03-14 14:26:53 -0400 | [diff] [blame] | 38 | u32 flags; |
Chris Mason | a8a2ee0 | 2007-03-16 08:46:49 -0400 | [diff] [blame] | 39 | u64 offset; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 40 | } __attribute__ ((__packed__)); |
| 41 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 42 | /* |
| 43 | * every tree block (leaf or node) starts with this header. |
| 44 | */ |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 45 | struct btrfs_header { |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 46 | u8 fsid[16]; /* FS specific uuid */ |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 47 | __le64 blocknr; /* which block this node is supposed to live in */ |
| 48 | __le64 parentid; /* objectid of the tree root */ |
| 49 | __le32 csum; |
| 50 | __le32 ham; |
| 51 | __le16 nritems; |
| 52 | __le16 flags; |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 53 | /* generation flags to be added */ |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 54 | } __attribute__ ((__packed__)); |
| 55 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 56 | #define BTRFS_MAX_LEVEL 8 |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 57 | #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \ |
| 58 | sizeof(struct btrfs_header)) / \ |
| 59 | (sizeof(struct btrfs_disk_key) + sizeof(u64))) |
| 60 | #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) |
| 61 | #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize)) |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 62 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 63 | struct btrfs_buffer; |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 64 | /* |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 65 | * the super block basically lists the main trees of the FS |
| 66 | * it currently lacks any block count etc etc |
| 67 | */ |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 68 | struct btrfs_super_block { |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 69 | u8 fsid[16]; /* FS specific uuid */ |
| 70 | __le64 blocknr; /* this block number */ |
| 71 | __le32 csum; |
| 72 | __le64 magic; |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 73 | __le32 blocksize; |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 74 | __le64 generation; |
| 75 | __le64 root; |
| 76 | __le64 total_blocks; |
| 77 | __le64 blocks_used; |
Chris Mason | cfaa729 | 2007-02-21 17:04:57 -0500 | [diff] [blame] | 78 | } __attribute__ ((__packed__)); |
| 79 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 80 | /* |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 81 | * A leaf is full of items. offset and size tell us where to find |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 82 | * the item in the leaf (relative to the start of the data area) |
| 83 | */ |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 84 | struct btrfs_item { |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 85 | struct btrfs_disk_key key; |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 86 | __le32 offset; |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 87 | __le16 size; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 88 | } __attribute__ ((__packed__)); |
| 89 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 90 | /* |
| 91 | * leaves have an item area and a data area: |
| 92 | * [item0, item1....itemN] [free space] [dataN...data1, data0] |
| 93 | * |
| 94 | * The data is separate from the items to get the keys closer together |
| 95 | * during searches. |
| 96 | */ |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 97 | struct btrfs_leaf { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 98 | struct btrfs_header header; |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 99 | struct btrfs_item items[]; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 100 | } __attribute__ ((__packed__)); |
| 101 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 102 | /* |
| 103 | * all non-leaf blocks are nodes, they hold only keys and pointers to |
| 104 | * other blocks |
| 105 | */ |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 106 | struct btrfs_key_ptr { |
| 107 | struct btrfs_disk_key key; |
| 108 | __le64 blockptr; |
| 109 | } __attribute__ ((__packed__)); |
| 110 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 111 | struct btrfs_node { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 112 | struct btrfs_header header; |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 113 | struct btrfs_key_ptr ptrs[]; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 114 | } __attribute__ ((__packed__)); |
| 115 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 116 | /* |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 117 | * btrfs_paths remember the path taken from the root down to the leaf. |
| 118 | * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 119 | * to any other levels that are present. |
| 120 | * |
| 121 | * The slots array records the index of the item or block pointer |
| 122 | * used while walking the tree. |
| 123 | */ |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 124 | struct btrfs_path { |
| 125 | struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL]; |
| 126 | int slots[BTRFS_MAX_LEVEL]; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 127 | }; |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 128 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 129 | /* |
| 130 | * items in the extent btree are used to record the objectid of the |
| 131 | * owner of the block and the number of references |
| 132 | */ |
| 133 | struct btrfs_extent_item { |
| 134 | __le32 refs; |
| 135 | __le64 owner; |
| 136 | } __attribute__ ((__packed__)); |
| 137 | |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 138 | struct btrfs_inode_timespec { |
| 139 | __le32 sec; |
| 140 | __le32 nsec; |
| 141 | } __attribute__ ((__packed__)); |
| 142 | |
| 143 | /* |
| 144 | * there is no padding here on purpose. If you want to extent the inode, |
| 145 | * make a new item type |
| 146 | */ |
| 147 | struct btrfs_inode_item { |
| 148 | __le64 generation; |
| 149 | __le64 size; |
| 150 | __le64 nblocks; |
| 151 | __le32 nlink; |
| 152 | __le32 uid; |
| 153 | __le32 gid; |
| 154 | __le32 mode; |
| 155 | __le32 rdev; |
| 156 | __le16 flags; |
| 157 | __le16 compat_flags; |
| 158 | struct btrfs_inode_timespec atime; |
| 159 | struct btrfs_inode_timespec ctime; |
| 160 | struct btrfs_inode_timespec mtime; |
| 161 | struct btrfs_inode_timespec otime; |
| 162 | } __attribute__ ((__packed__)); |
| 163 | |
| 164 | /* inline data is just a blob of bytes */ |
| 165 | struct btrfs_inline_data_item { |
| 166 | u8 data; |
| 167 | } __attribute__ ((__packed__)); |
| 168 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 169 | struct btrfs_dir_item { |
| 170 | __le64 objectid; |
| 171 | __le16 flags; |
Chris Mason | a8a2ee0 | 2007-03-16 08:46:49 -0400 | [diff] [blame] | 172 | __le16 name_len; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 173 | u8 type; |
| 174 | } __attribute__ ((__packed__)); |
| 175 | |
| 176 | struct btrfs_root_item { |
| 177 | __le64 blocknr; |
| 178 | __le32 flags; |
| 179 | __le64 block_limit; |
| 180 | __le64 blocks_used; |
| 181 | __le32 refs; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 182 | } __attribute__ ((__packed__)); |
| 183 | |
| 184 | struct btrfs_file_extent_item { |
| 185 | /* |
| 186 | * disk space consumed by the extent, checksum blocks are included |
| 187 | * in these numbers |
| 188 | */ |
| 189 | __le64 disk_blocknr; |
| 190 | __le64 disk_num_blocks; |
| 191 | /* |
| 192 | * the logical offset in file bytes (no csums) |
| 193 | * this extent record is for. This allows a file extent to point |
| 194 | * into the middle of an existing extent on disk, sharing it |
| 195 | * between two snapshots (useful if some bytes in the middle of the |
| 196 | * extent have changed |
| 197 | */ |
| 198 | __le64 offset; |
| 199 | /* |
| 200 | * the logical number of file blocks (no csums included) |
| 201 | */ |
| 202 | __le64 num_blocks; |
| 203 | } __attribute__ ((__packed__)); |
| 204 | |
| 205 | struct btrfs_inode_map_item { |
| 206 | struct btrfs_disk_key key; |
| 207 | } __attribute__ ((__packed__)); |
| 208 | |
| 209 | struct btrfs_fs_info { |
| 210 | struct btrfs_root *fs_root; |
| 211 | struct btrfs_root *extent_root; |
| 212 | struct btrfs_root *tree_root; |
| 213 | struct btrfs_root *inode_root; |
| 214 | struct btrfs_key current_insert; |
| 215 | struct btrfs_key last_insert; |
| 216 | struct radix_tree_root cache_radix; |
| 217 | struct radix_tree_root pinned_radix; |
| 218 | struct list_head trans; |
| 219 | struct list_head cache; |
| 220 | u64 last_inode_alloc; |
| 221 | u64 last_inode_alloc_dirid; |
Chris Mason | 293ffd5 | 2007-03-20 15:57:25 -0400 | [diff] [blame] | 222 | u64 generation; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 223 | int cache_size; |
| 224 | int fp; |
| 225 | struct btrfs_trans_handle *running_transaction; |
Chris Mason | 1261ec4 | 2007-03-20 20:35:03 -0400 | [diff] [blame^] | 226 | struct btrfs_super_block *disk_super; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | /* |
| 230 | * in ram representation of the tree. extent_root is used for all allocations |
| 231 | * and for the extent tree extent_root root. current_insert is used |
| 232 | * only for the extent tree. |
| 233 | */ |
| 234 | struct btrfs_root { |
| 235 | struct btrfs_buffer *node; |
| 236 | struct btrfs_buffer *commit_root; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 237 | struct btrfs_root_item root_item; |
| 238 | struct btrfs_key root_key; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 239 | struct btrfs_fs_info *fs_info; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 240 | u32 blocksize; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 241 | int ref_cows; |
| 242 | u32 type; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 243 | }; |
| 244 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 245 | /* the lower bits in the key flags defines the item type */ |
| 246 | #define BTRFS_KEY_TYPE_MAX 256 |
| 247 | #define BTRFS_KEY_TYPE_MASK (BTRFS_KEY_TYPE_MAX - 1) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 248 | |
| 249 | /* |
| 250 | * inode items have the data typically returned from stat and store other |
| 251 | * info about object characteristics. There is one for every file and dir in |
| 252 | * the FS |
| 253 | */ |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 254 | #define BTRFS_INODE_ITEM_KEY 1 |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 255 | |
| 256 | /* |
| 257 | * dir items are the name -> inode pointers in a directory. There is one |
| 258 | * for every name in a directory. |
| 259 | */ |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 260 | #define BTRFS_DIR_ITEM_KEY 2 |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 261 | /* |
| 262 | * inline data is file data that fits in the btree. |
| 263 | */ |
| 264 | #define BTRFS_INLINE_DATA_KEY 3 |
| 265 | /* |
| 266 | * extent data is for data that can't fit in the btree. It points to |
| 267 | * a (hopefully) huge chunk of disk |
| 268 | */ |
| 269 | #define BTRFS_EXTENT_DATA_KEY 4 |
| 270 | /* |
| 271 | * root items point to tree roots. There are typically in the root |
| 272 | * tree used by the super block to find all the other trees |
| 273 | */ |
| 274 | #define BTRFS_ROOT_ITEM_KEY 5 |
| 275 | /* |
| 276 | * extent items are in the extent map tree. These record which blocks |
| 277 | * are used, and how many references there are to each block |
| 278 | */ |
| 279 | #define BTRFS_EXTENT_ITEM_KEY 6 |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 280 | |
| 281 | /* |
| 282 | * the inode map records which inode numbers are in use and where |
| 283 | * they actually live on disk |
| 284 | */ |
| 285 | #define BTRFS_INODE_MAP_ITEM_KEY 7 |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 286 | /* |
| 287 | * string items are for debugging. They just store a short string of |
| 288 | * data in the FS |
| 289 | */ |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 290 | #define BTRFS_STRING_ITEM_KEY 8 |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 291 | |
| 292 | static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i) |
| 293 | { |
| 294 | return le64_to_cpu(i->generation); |
| 295 | } |
| 296 | |
| 297 | static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i, |
| 298 | u64 val) |
| 299 | { |
| 300 | i->generation = cpu_to_le64(val); |
| 301 | } |
| 302 | |
| 303 | static inline u64 btrfs_inode_size(struct btrfs_inode_item *i) |
| 304 | { |
| 305 | return le64_to_cpu(i->size); |
| 306 | } |
| 307 | |
| 308 | static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val) |
| 309 | { |
| 310 | i->size = cpu_to_le64(val); |
| 311 | } |
| 312 | |
| 313 | static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i) |
| 314 | { |
| 315 | return le64_to_cpu(i->nblocks); |
| 316 | } |
| 317 | |
| 318 | static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val) |
| 319 | { |
| 320 | i->nblocks = cpu_to_le64(val); |
| 321 | } |
| 322 | |
| 323 | static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i) |
| 324 | { |
| 325 | return le32_to_cpu(i->nlink); |
| 326 | } |
| 327 | |
| 328 | static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val) |
| 329 | { |
| 330 | i->nlink = cpu_to_le32(val); |
| 331 | } |
| 332 | |
| 333 | static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i) |
| 334 | { |
| 335 | return le32_to_cpu(i->uid); |
| 336 | } |
| 337 | |
| 338 | static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val) |
| 339 | { |
| 340 | i->uid = cpu_to_le32(val); |
| 341 | } |
| 342 | |
| 343 | static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i) |
| 344 | { |
| 345 | return le32_to_cpu(i->gid); |
| 346 | } |
| 347 | |
| 348 | static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val) |
| 349 | { |
| 350 | i->gid = cpu_to_le32(val); |
| 351 | } |
| 352 | |
| 353 | static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i) |
| 354 | { |
| 355 | return le32_to_cpu(i->mode); |
| 356 | } |
| 357 | |
| 358 | static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val) |
| 359 | { |
| 360 | i->mode = cpu_to_le32(val); |
| 361 | } |
| 362 | |
| 363 | static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i) |
| 364 | { |
| 365 | return le32_to_cpu(i->rdev); |
| 366 | } |
| 367 | |
| 368 | static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val) |
| 369 | { |
| 370 | i->rdev = cpu_to_le32(val); |
| 371 | } |
| 372 | |
| 373 | static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i) |
| 374 | { |
| 375 | return le16_to_cpu(i->flags); |
| 376 | } |
| 377 | |
| 378 | static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val) |
| 379 | { |
| 380 | i->flags = cpu_to_le16(val); |
| 381 | } |
| 382 | |
| 383 | static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i) |
| 384 | { |
| 385 | return le16_to_cpu(i->compat_flags); |
| 386 | } |
| 387 | |
| 388 | static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i, |
| 389 | u16 val) |
| 390 | { |
| 391 | i->compat_flags = cpu_to_le16(val); |
| 392 | } |
| 393 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 394 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 395 | static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei) |
Chris Mason | cf27e1e | 2007-03-13 09:49:06 -0400 | [diff] [blame] | 396 | { |
| 397 | return le64_to_cpu(ei->owner); |
| 398 | } |
| 399 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 400 | static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val) |
Chris Mason | cf27e1e | 2007-03-13 09:49:06 -0400 | [diff] [blame] | 401 | { |
| 402 | ei->owner = cpu_to_le64(val); |
| 403 | } |
| 404 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 405 | static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei) |
Chris Mason | cf27e1e | 2007-03-13 09:49:06 -0400 | [diff] [blame] | 406 | { |
| 407 | return le32_to_cpu(ei->refs); |
| 408 | } |
| 409 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 410 | static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val) |
Chris Mason | cf27e1e | 2007-03-13 09:49:06 -0400 | [diff] [blame] | 411 | { |
| 412 | ei->refs = cpu_to_le32(val); |
| 413 | } |
| 414 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 415 | static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr) |
Chris Mason | 1d4f8a0 | 2007-03-13 09:28:32 -0400 | [diff] [blame] | 416 | { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 417 | return le64_to_cpu(n->ptrs[nr].blockptr); |
Chris Mason | 1d4f8a0 | 2007-03-13 09:28:32 -0400 | [diff] [blame] | 418 | } |
| 419 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 420 | static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr, |
| 421 | u64 val) |
Chris Mason | 1d4f8a0 | 2007-03-13 09:28:32 -0400 | [diff] [blame] | 422 | { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 423 | n->ptrs[nr].blockptr = cpu_to_le64(val); |
Chris Mason | 1d4f8a0 | 2007-03-13 09:28:32 -0400 | [diff] [blame] | 424 | } |
| 425 | |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 426 | static inline u32 btrfs_item_offset(struct btrfs_item *item) |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 427 | { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 428 | return le32_to_cpu(item->offset); |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 429 | } |
| 430 | |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 431 | static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val) |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 432 | { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 433 | item->offset = cpu_to_le32(val); |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 434 | } |
| 435 | |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 436 | static inline u32 btrfs_item_end(struct btrfs_item *item) |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 437 | { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 438 | return le32_to_cpu(item->offset) + le16_to_cpu(item->size); |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | static inline u16 btrfs_item_size(struct btrfs_item *item) |
| 442 | { |
| 443 | return le16_to_cpu(item->size); |
| 444 | } |
| 445 | |
| 446 | static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val) |
| 447 | { |
| 448 | item->size = cpu_to_le16(val); |
| 449 | } |
| 450 | |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 451 | static inline u64 btrfs_dir_objectid(struct btrfs_dir_item *d) |
| 452 | { |
| 453 | return le64_to_cpu(d->objectid); |
| 454 | } |
| 455 | |
| 456 | static inline void btrfs_set_dir_objectid(struct btrfs_dir_item *d, u64 val) |
| 457 | { |
| 458 | d->objectid = cpu_to_le64(val); |
| 459 | } |
| 460 | |
| 461 | static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d) |
| 462 | { |
| 463 | return le16_to_cpu(d->flags); |
| 464 | } |
| 465 | |
| 466 | static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val) |
| 467 | { |
| 468 | d->flags = cpu_to_le16(val); |
| 469 | } |
| 470 | |
| 471 | static inline u8 btrfs_dir_type(struct btrfs_dir_item *d) |
| 472 | { |
| 473 | return d->type; |
| 474 | } |
| 475 | |
| 476 | static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val) |
| 477 | { |
| 478 | d->type = val; |
| 479 | } |
| 480 | |
Chris Mason | a8a2ee0 | 2007-03-16 08:46:49 -0400 | [diff] [blame] | 481 | static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d) |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 482 | { |
Chris Mason | a8a2ee0 | 2007-03-16 08:46:49 -0400 | [diff] [blame] | 483 | return le16_to_cpu(d->name_len); |
| 484 | } |
| 485 | |
| 486 | static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val) |
| 487 | { |
| 488 | d->name_len = cpu_to_le16(val); |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 489 | } |
| 490 | |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 491 | static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, |
| 492 | struct btrfs_disk_key *disk) |
| 493 | { |
| 494 | cpu->offset = le64_to_cpu(disk->offset); |
| 495 | cpu->flags = le32_to_cpu(disk->flags); |
| 496 | cpu->objectid = le64_to_cpu(disk->objectid); |
| 497 | } |
| 498 | |
| 499 | static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, |
| 500 | struct btrfs_key *cpu) |
| 501 | { |
| 502 | disk->offset = cpu_to_le64(cpu->offset); |
| 503 | disk->flags = cpu_to_le32(cpu->flags); |
| 504 | disk->objectid = cpu_to_le64(cpu->objectid); |
| 505 | } |
| 506 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 507 | static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 508 | { |
| 509 | return le64_to_cpu(disk->objectid); |
| 510 | } |
| 511 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 512 | static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk, |
| 513 | u64 val) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 514 | { |
| 515 | disk->objectid = cpu_to_le64(val); |
| 516 | } |
| 517 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 518 | static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 519 | { |
| 520 | return le64_to_cpu(disk->offset); |
| 521 | } |
| 522 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 523 | static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk, |
| 524 | u64 val) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 525 | { |
| 526 | disk->offset = cpu_to_le64(val); |
| 527 | } |
| 528 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 529 | static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 530 | { |
| 531 | return le32_to_cpu(disk->flags); |
| 532 | } |
| 533 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 534 | static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk, |
| 535 | u32 val) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 536 | { |
| 537 | disk->flags = cpu_to_le32(val); |
| 538 | } |
| 539 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 540 | static inline u32 btrfs_key_type(struct btrfs_key *key) |
| 541 | { |
| 542 | return key->flags & BTRFS_KEY_TYPE_MASK; |
| 543 | } |
| 544 | |
| 545 | static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key) |
| 546 | { |
| 547 | return le32_to_cpu(key->flags) & BTRFS_KEY_TYPE_MASK; |
| 548 | } |
| 549 | |
| 550 | static inline void btrfs_set_key_type(struct btrfs_key *key, u32 type) |
| 551 | { |
| 552 | BUG_ON(type >= BTRFS_KEY_TYPE_MAX); |
| 553 | key->flags = (key->flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type; |
| 554 | } |
| 555 | |
| 556 | static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u32 type) |
| 557 | { |
| 558 | u32 flags = btrfs_disk_key_flags(key); |
| 559 | BUG_ON(type >= BTRFS_KEY_TYPE_MAX); |
| 560 | flags = (flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type; |
| 561 | btrfs_set_disk_key_flags(key, flags); |
| 562 | } |
| 563 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 564 | static inline u64 btrfs_header_blocknr(struct btrfs_header *h) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 565 | { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 566 | return le64_to_cpu(h->blocknr); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 567 | } |
| 568 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 569 | static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 570 | { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 571 | h->blocknr = cpu_to_le64(blocknr); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 572 | } |
| 573 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 574 | static inline u64 btrfs_header_parentid(struct btrfs_header *h) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 575 | { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 576 | return le64_to_cpu(h->parentid); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 577 | } |
| 578 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 579 | static inline void btrfs_set_header_parentid(struct btrfs_header *h, |
| 580 | u64 parentid) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 581 | { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 582 | h->parentid = cpu_to_le64(parentid); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 583 | } |
| 584 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 585 | static inline u16 btrfs_header_nritems(struct btrfs_header *h) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 586 | { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 587 | return le16_to_cpu(h->nritems); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 588 | } |
| 589 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 590 | static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 591 | { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 592 | h->nritems = cpu_to_le16(val); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 593 | } |
| 594 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 595 | static inline u16 btrfs_header_flags(struct btrfs_header *h) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 596 | { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 597 | return le16_to_cpu(h->flags); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 598 | } |
| 599 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 600 | static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 601 | { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 602 | h->flags = cpu_to_le16(val); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 603 | } |
| 604 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 605 | static inline int btrfs_header_level(struct btrfs_header *h) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 606 | { |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 607 | return btrfs_header_flags(h) & (BTRFS_MAX_LEVEL - 1); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 608 | } |
| 609 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 610 | static inline void btrfs_set_header_level(struct btrfs_header *h, int level) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 611 | { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 612 | u16 flags; |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 613 | BUG_ON(level > BTRFS_MAX_LEVEL); |
| 614 | flags = btrfs_header_flags(h) & ~(BTRFS_MAX_LEVEL - 1); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 615 | btrfs_set_header_flags(h, flags | level); |
| 616 | } |
| 617 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 618 | static inline int btrfs_is_leaf(struct btrfs_node *n) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 619 | { |
| 620 | return (btrfs_header_level(&n->header) == 0); |
| 621 | } |
| 622 | |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 623 | static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item) |
| 624 | { |
| 625 | return le64_to_cpu(item->blocknr); |
| 626 | } |
| 627 | |
| 628 | static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val) |
| 629 | { |
| 630 | item->blocknr = cpu_to_le64(val); |
| 631 | } |
| 632 | |
| 633 | static inline u32 btrfs_root_refs(struct btrfs_root_item *item) |
| 634 | { |
| 635 | return le32_to_cpu(item->refs); |
| 636 | } |
| 637 | |
| 638 | static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val) |
| 639 | { |
| 640 | item->refs = cpu_to_le32(val); |
| 641 | } |
| 642 | |
| 643 | static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s) |
| 644 | { |
| 645 | return le64_to_cpu(s->blocknr); |
| 646 | } |
| 647 | |
| 648 | static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val) |
| 649 | { |
| 650 | s->blocknr = cpu_to_le64(val); |
| 651 | } |
| 652 | |
| 653 | static inline u64 btrfs_super_root(struct btrfs_super_block *s) |
| 654 | { |
| 655 | return le64_to_cpu(s->root); |
| 656 | } |
| 657 | |
| 658 | static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val) |
| 659 | { |
| 660 | s->root = cpu_to_le64(val); |
| 661 | } |
| 662 | |
| 663 | static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s) |
| 664 | { |
| 665 | return le64_to_cpu(s->total_blocks); |
| 666 | } |
| 667 | |
| 668 | static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s, |
| 669 | u64 val) |
| 670 | { |
| 671 | s->total_blocks = cpu_to_le64(val); |
| 672 | } |
| 673 | |
| 674 | static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s) |
| 675 | { |
| 676 | return le64_to_cpu(s->blocks_used); |
| 677 | } |
| 678 | |
| 679 | static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s, |
| 680 | u64 val) |
| 681 | { |
| 682 | s->blocks_used = cpu_to_le64(val); |
| 683 | } |
| 684 | |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 685 | static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s) |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 686 | { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 687 | return le32_to_cpu(s->blocksize); |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s, |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 691 | u32 val) |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 692 | { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 693 | s->blocksize = cpu_to_le32(val); |
| 694 | } |
| 695 | |
| 696 | static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l) |
| 697 | { |
| 698 | return (u8 *)l->items; |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 699 | } |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 700 | |
| 701 | static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item |
| 702 | *e) |
| 703 | { |
| 704 | return le64_to_cpu(e->disk_blocknr); |
| 705 | } |
| 706 | |
| 707 | static inline void btrfs_set_file_extent_disk_blocknr(struct |
| 708 | btrfs_file_extent_item |
| 709 | *e, u64 val) |
| 710 | { |
| 711 | e->disk_blocknr = cpu_to_le64(val); |
| 712 | } |
| 713 | |
| 714 | static inline u64 btrfs_file_extent_disk_num_blocks(struct |
| 715 | btrfs_file_extent_item *e) |
| 716 | { |
| 717 | return le64_to_cpu(e->disk_num_blocks); |
| 718 | } |
| 719 | |
| 720 | static inline void btrfs_set_file_extent_disk_num_blocks(struct |
| 721 | btrfs_file_extent_item |
| 722 | *e, u64 val) |
| 723 | { |
| 724 | e->disk_num_blocks = cpu_to_le64(val); |
| 725 | } |
| 726 | |
| 727 | static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e) |
| 728 | { |
| 729 | return le64_to_cpu(e->offset); |
| 730 | } |
| 731 | |
| 732 | static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item |
| 733 | *e, u64 val) |
| 734 | { |
| 735 | e->offset = cpu_to_le64(val); |
| 736 | } |
| 737 | |
| 738 | static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item |
| 739 | *e) |
| 740 | { |
| 741 | return le64_to_cpu(e->num_blocks); |
| 742 | } |
| 743 | |
| 744 | static inline void btrfs_set_file_extent_num_blocks(struct |
| 745 | btrfs_file_extent_item *e, |
| 746 | u64 val) |
| 747 | { |
| 748 | e->num_blocks = cpu_to_le64(val); |
| 749 | } |
| 750 | |
Chris Mason | 4beb1b8 | 2007-03-14 10:31:29 -0400 | [diff] [blame] | 751 | /* helper function to cast into the data area of the leaf. */ |
| 752 | #define btrfs_item_ptr(leaf, slot, type) \ |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 753 | ((type *)(btrfs_leaf_data(leaf) + \ |
| 754 | btrfs_item_offset((leaf)->items + (slot)))) |
Chris Mason | 4beb1b8 | 2007-03-14 10:31:29 -0400 | [diff] [blame] | 755 | |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 756 | struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, |
| 757 | struct btrfs_root *root); |
| 758 | int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
| 759 | struct btrfs_buffer *buf); |
| 760 | int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root |
| 761 | *root, u64 blocknr, u64 num_blocks, int pin); |
| 762 | int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root |
| 763 | *root, struct btrfs_key *key, struct btrfs_path *p, int |
| 764 | ins_len, int cow); |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 765 | void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p); |
| 766 | void btrfs_init_path(struct btrfs_path *p); |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 767 | int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
| 768 | struct btrfs_path *path); |
| 769 | int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root |
| 770 | *root, struct btrfs_key *key, void *data, u32 data_size); |
| 771 | int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root |
| 772 | *root, struct btrfs_path *path, struct btrfs_key |
| 773 | *cpu_key, u32 data_size); |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 774 | int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 775 | int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf); |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 776 | int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root |
| 777 | *root, struct btrfs_buffer *snap); |
| 778 | int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct |
| 779 | btrfs_root *root); |
| 780 | int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
| 781 | struct btrfs_key *key); |
| 782 | int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root |
| 783 | *root, struct btrfs_key *key, struct btrfs_root_item |
| 784 | *item); |
| 785 | int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root |
| 786 | *root, struct btrfs_key *key, struct btrfs_root_item |
| 787 | *item); |
| 788 | int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct |
| 789 | btrfs_root_item *item, struct btrfs_key *key); |
| 790 | int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root |
| 791 | *root, char *name, int name_len, u64 dir, u64 |
| 792 | objectid, u8 type); |
| 793 | int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root |
| 794 | *root, struct btrfs_path *path, u64 dir, char *name, |
| 795 | int name_len, int mod); |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 796 | int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path, |
| 797 | char *name, int name_len); |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 798 | int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, |
| 799 | struct btrfs_root *fs_root, |
| 800 | u64 dirid, u64 *objectid); |
| 801 | int btrfs_insert_inode_map(struct btrfs_trans_handle *trans, |
| 802 | struct btrfs_root *root, |
| 803 | u64 objectid, struct btrfs_key *location); |
| 804 | int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans, |
| 805 | struct btrfs_root *root, struct btrfs_path *path, |
| 806 | u64 objectid, int mod); |
Chris Mason | 293ffd5 | 2007-03-20 15:57:25 -0400 | [diff] [blame] | 807 | int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root |
| 808 | *root, u64 objectid, struct btrfs_inode_item |
| 809 | *inode_item); |
| 810 | int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root |
| 811 | *root, struct btrfs_path *path, u64 objectid, int mod); |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 812 | #endif |