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