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