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