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 | d602557 | 2007-03-30 14:27:56 -0400 | [diff] [blame] | 5 | #include <linux/buffer_head.h> |
Chris Mason | d6e4a42 | 2007-04-06 15:37:36 -0400 | [diff] [blame] | 6 | #include <linux/kobject.h> |
Chris Mason | 8ef9762 | 2007-03-26 10:15:30 -0400 | [diff] [blame] | 7 | #include "bit-radix.h" |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 8 | |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 9 | struct btrfs_trans_handle; |
Chris Mason | 79154b1 | 2007-03-22 15:59:16 -0400 | [diff] [blame] | 10 | struct btrfs_transaction; |
Chris Mason | 35b7e47 | 2007-05-02 15:53:43 -0400 | [diff] [blame] | 11 | extern struct kmem_cache *btrfs_trans_handle_cachep; |
| 12 | extern struct kmem_cache *btrfs_transaction_cachep; |
| 13 | extern struct kmem_cache *btrfs_bit_radix_cachep; |
Chris Mason | 2c90e5d | 2007-04-02 10:50:19 -0400 | [diff] [blame] | 14 | extern struct kmem_cache *btrfs_path_cachep; |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 15 | |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 16 | #define BTRFS_MAGIC "_BtRfS_M" |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 17 | |
Chris Mason | 6407bf6 | 2007-03-27 06:33:00 -0400 | [diff] [blame] | 18 | #define BTRFS_ROOT_TREE_OBJECTID 1ULL |
Chris Mason | 0bd93ba | 2007-04-11 13:57:44 -0400 | [diff] [blame] | 19 | #define BTRFS_DEV_TREE_OBJECTID 2ULL |
| 20 | #define BTRFS_EXTENT_TREE_OBJECTID 3ULL |
| 21 | #define BTRFS_FS_TREE_OBJECTID 4ULL |
| 22 | #define BTRFS_ROOT_TREE_DIR_OBJECTID 5ULL |
| 23 | #define BTRFS_FIRST_FREE_OBJECTID 6ULL |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 24 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 25 | /* |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 26 | * we can actually store much bigger names, but lets not confuse the rest |
| 27 | * of linux |
| 28 | */ |
| 29 | #define BTRFS_NAME_LEN 255 |
| 30 | |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 31 | /* 32 bytes in various csum fields */ |
| 32 | #define BTRFS_CSUM_SIZE 32 |
Chris Mason | 509659c | 2007-05-10 12:36:17 -0400 | [diff] [blame] | 33 | /* four bytes for CRC32 */ |
| 34 | #define BTRFS_CRC32_SIZE 4 |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 35 | |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 36 | /* |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 37 | * the key defines the order in the tree, and so it also defines (optimal) |
| 38 | * block layout. objectid corresonds to the inode number. The flags |
| 39 | * tells us things about the object, and is a kind of stream selector. |
| 40 | * so for a given inode, keys with flags of 1 might refer to the inode |
| 41 | * data, flags of 2 may point to file data in the btree and flags == 3 |
| 42 | * may point to extents. |
| 43 | * |
| 44 | * offset is the starting byte offset for this key in the stream. |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 45 | * |
| 46 | * btrfs_disk_key is in disk byte order. struct btrfs_key is always |
| 47 | * in cpu native order. Otherwise they are identical and their sizes |
| 48 | * should be the same (ie both packed) |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 49 | */ |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 50 | struct btrfs_disk_key { |
| 51 | __le64 objectid; |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 52 | __le32 flags; |
Chris Mason | 70b2bef | 2007-04-17 15:39:32 -0400 | [diff] [blame] | 53 | __le64 offset; |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 54 | } __attribute__ ((__packed__)); |
| 55 | |
| 56 | struct btrfs_key { |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 57 | u64 objectid; |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 58 | u32 flags; |
Chris Mason | 70b2bef | 2007-04-17 15:39:32 -0400 | [diff] [blame] | 59 | u64 offset; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 60 | } __attribute__ ((__packed__)); |
| 61 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 62 | /* |
| 63 | * every tree block (leaf or node) starts with this header. |
| 64 | */ |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 65 | struct btrfs_header { |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 66 | u8 csum[BTRFS_CSUM_SIZE]; |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 67 | u8 fsid[16]; /* FS specific uuid */ |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 68 | __le64 blocknr; /* which block this node is supposed to live in */ |
Chris Mason | 7f5c151 | 2007-03-23 15:56:19 -0400 | [diff] [blame] | 69 | __le64 generation; |
Chris Mason | 4d77567 | 2007-04-20 20:23:12 -0400 | [diff] [blame] | 70 | __le64 owner; |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 71 | __le16 nritems; |
| 72 | __le16 flags; |
Chris Mason | 9a6f11e | 2007-03-27 09:06:38 -0400 | [diff] [blame] | 73 | u8 level; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 74 | } __attribute__ ((__packed__)); |
| 75 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 76 | #define BTRFS_MAX_LEVEL 8 |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 77 | #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \ |
| 78 | sizeof(struct btrfs_header)) / \ |
| 79 | (sizeof(struct btrfs_disk_key) + sizeof(u64))) |
| 80 | #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) |
| 81 | #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize)) |
Chris Mason | 236454d | 2007-04-19 13:37:44 -0400 | [diff] [blame] | 82 | #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \ |
| 83 | sizeof(struct btrfs_item) - \ |
| 84 | sizeof(struct btrfs_file_extent_item)) |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 85 | |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 86 | struct buffer_head; |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 87 | /* |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 88 | * the super block basically lists the main trees of the FS |
| 89 | * it currently lacks any block count etc etc |
| 90 | */ |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 91 | struct btrfs_super_block { |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 92 | u8 csum[BTRFS_CSUM_SIZE]; |
Chris Mason | 87cbda5 | 2007-03-28 19:44:27 -0400 | [diff] [blame] | 93 | /* the first 3 fields must match struct btrfs_header */ |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 94 | u8 fsid[16]; /* FS specific uuid */ |
| 95 | __le64 blocknr; /* this block number */ |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 96 | __le64 magic; |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 97 | __le32 blocksize; |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 98 | __le64 generation; |
| 99 | __le64 root; |
| 100 | __le64 total_blocks; |
| 101 | __le64 blocks_used; |
Chris Mason | 2e635a2 | 2007-03-21 11:12:56 -0400 | [diff] [blame] | 102 | __le64 root_dir_objectid; |
Chris Mason | b4100d6 | 2007-04-12 12:14:00 -0400 | [diff] [blame] | 103 | __le64 last_device_id; |
Chris Mason | 0bd93ba | 2007-04-11 13:57:44 -0400 | [diff] [blame] | 104 | /* fields below here vary with the underlying disk */ |
| 105 | __le64 device_block_start; |
| 106 | __le64 device_num_blocks; |
| 107 | __le64 device_root; |
Chris Mason | b4100d6 | 2007-04-12 12:14:00 -0400 | [diff] [blame] | 108 | __le64 device_id; |
Chris Mason | cfaa729 | 2007-02-21 17:04:57 -0500 | [diff] [blame] | 109 | } __attribute__ ((__packed__)); |
| 110 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 111 | /* |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 112 | * 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] | 113 | * the item in the leaf (relative to the start of the data area) |
| 114 | */ |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 115 | struct btrfs_item { |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 116 | struct btrfs_disk_key key; |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 117 | __le32 offset; |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 118 | __le16 size; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 119 | } __attribute__ ((__packed__)); |
| 120 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 121 | /* |
| 122 | * leaves have an item area and a data area: |
| 123 | * [item0, item1....itemN] [free space] [dataN...data1, data0] |
| 124 | * |
| 125 | * The data is separate from the items to get the keys closer together |
| 126 | * during searches. |
| 127 | */ |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 128 | struct btrfs_leaf { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 129 | struct btrfs_header header; |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 130 | struct btrfs_item items[]; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 131 | } __attribute__ ((__packed__)); |
| 132 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 133 | /* |
| 134 | * all non-leaf blocks are nodes, they hold only keys and pointers to |
| 135 | * other blocks |
| 136 | */ |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 137 | struct btrfs_key_ptr { |
| 138 | struct btrfs_disk_key key; |
| 139 | __le64 blockptr; |
| 140 | } __attribute__ ((__packed__)); |
| 141 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 142 | struct btrfs_node { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 143 | struct btrfs_header header; |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 144 | struct btrfs_key_ptr ptrs[]; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 145 | } __attribute__ ((__packed__)); |
| 146 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 147 | /* |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 148 | * btrfs_paths remember the path taken from the root down to the leaf. |
| 149 | * 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] | 150 | * to any other levels that are present. |
| 151 | * |
| 152 | * The slots array records the index of the item or block pointer |
| 153 | * used while walking the tree. |
| 154 | */ |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 155 | struct btrfs_path { |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 156 | struct buffer_head *nodes[BTRFS_MAX_LEVEL]; |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 157 | int slots[BTRFS_MAX_LEVEL]; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 158 | }; |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 159 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 160 | /* |
| 161 | * items in the extent btree are used to record the objectid of the |
| 162 | * owner of the block and the number of references |
| 163 | */ |
| 164 | struct btrfs_extent_item { |
| 165 | __le32 refs; |
Chris Mason | 4d77567 | 2007-04-20 20:23:12 -0400 | [diff] [blame] | 166 | __le64 owner; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 167 | } __attribute__ ((__packed__)); |
| 168 | |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 169 | struct btrfs_inode_timespec { |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 170 | __le64 sec; |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 171 | __le32 nsec; |
| 172 | } __attribute__ ((__packed__)); |
| 173 | |
| 174 | /* |
| 175 | * there is no padding here on purpose. If you want to extent the inode, |
| 176 | * make a new item type |
| 177 | */ |
| 178 | struct btrfs_inode_item { |
| 179 | __le64 generation; |
| 180 | __le64 size; |
| 181 | __le64 nblocks; |
Chris Mason | 31f3c99 | 2007-04-30 15:25:45 -0400 | [diff] [blame] | 182 | __le64 block_group; |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 183 | __le32 nlink; |
| 184 | __le32 uid; |
| 185 | __le32 gid; |
| 186 | __le32 mode; |
| 187 | __le32 rdev; |
| 188 | __le16 flags; |
| 189 | __le16 compat_flags; |
| 190 | struct btrfs_inode_timespec atime; |
| 191 | struct btrfs_inode_timespec ctime; |
| 192 | struct btrfs_inode_timespec mtime; |
| 193 | struct btrfs_inode_timespec otime; |
| 194 | } __attribute__ ((__packed__)); |
| 195 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 196 | struct btrfs_dir_item { |
Chris Mason | d6e4a42 | 2007-04-06 15:37:36 -0400 | [diff] [blame] | 197 | struct btrfs_disk_key location; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 198 | __le16 flags; |
Chris Mason | a8a2ee0 | 2007-03-16 08:46:49 -0400 | [diff] [blame] | 199 | __le16 name_len; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 200 | u8 type; |
| 201 | } __attribute__ ((__packed__)); |
| 202 | |
| 203 | struct btrfs_root_item { |
Chris Mason | d6e4a42 | 2007-04-06 15:37:36 -0400 | [diff] [blame] | 204 | struct btrfs_inode_item inode; |
| 205 | __le64 root_dirid; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 206 | __le64 blocknr; |
| 207 | __le32 flags; |
| 208 | __le64 block_limit; |
| 209 | __le64 blocks_used; |
| 210 | __le32 refs; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 211 | } __attribute__ ((__packed__)); |
| 212 | |
Chris Mason | 236454d | 2007-04-19 13:37:44 -0400 | [diff] [blame] | 213 | #define BTRFS_FILE_EXTENT_REG 0 |
| 214 | #define BTRFS_FILE_EXTENT_INLINE 1 |
| 215 | |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 216 | struct btrfs_file_extent_item { |
Chris Mason | 71951f3 | 2007-03-27 09:16:29 -0400 | [diff] [blame] | 217 | __le64 generation; |
Chris Mason | 236454d | 2007-04-19 13:37:44 -0400 | [diff] [blame] | 218 | u8 type; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 219 | /* |
| 220 | * disk space consumed by the extent, checksum blocks are included |
| 221 | * in these numbers |
| 222 | */ |
| 223 | __le64 disk_blocknr; |
| 224 | __le64 disk_num_blocks; |
| 225 | /* |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 226 | * the logical offset in file blocks (no csums) |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 227 | * this extent record is for. This allows a file extent to point |
| 228 | * into the middle of an existing extent on disk, sharing it |
| 229 | * between two snapshots (useful if some bytes in the middle of the |
| 230 | * extent have changed |
| 231 | */ |
| 232 | __le64 offset; |
| 233 | /* |
| 234 | * the logical number of file blocks (no csums included) |
| 235 | */ |
| 236 | __le64 num_blocks; |
| 237 | } __attribute__ ((__packed__)); |
| 238 | |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 239 | struct btrfs_csum_item { |
Chris Mason | 509659c | 2007-05-10 12:36:17 -0400 | [diff] [blame] | 240 | u8 csum; |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 241 | } __attribute__ ((__packed__)); |
| 242 | |
Chris Mason | 0bd93ba | 2007-04-11 13:57:44 -0400 | [diff] [blame] | 243 | struct btrfs_device_item { |
| 244 | __le16 pathlen; |
Chris Mason | b4100d6 | 2007-04-12 12:14:00 -0400 | [diff] [blame] | 245 | __le64 device_id; |
Chris Mason | 0bd93ba | 2007-04-11 13:57:44 -0400 | [diff] [blame] | 246 | } __attribute__ ((__packed__)); |
| 247 | |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 248 | /* tag for the radix tree of block groups in ram */ |
| 249 | #define BTRFS_BLOCK_GROUP_DIRTY 0 |
Chris Mason | 31f3c99 | 2007-04-30 15:25:45 -0400 | [diff] [blame] | 250 | #define BTRFS_BLOCK_GROUP_AVAIL 1 |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 251 | #define BTRFS_BLOCK_GROUP_HINTS 8 |
| 252 | #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024) |
| 253 | struct btrfs_block_group_item { |
| 254 | __le64 used; |
| 255 | } __attribute__ ((__packed__)); |
| 256 | |
| 257 | struct btrfs_block_group_cache { |
| 258 | struct btrfs_key key; |
| 259 | struct btrfs_block_group_item item; |
Chris Mason | 3e1ad54 | 2007-05-07 20:03:49 -0400 | [diff] [blame] | 260 | struct radix_tree_root *radix; |
Chris Mason | cd1bc46 | 2007-04-27 10:08:34 -0400 | [diff] [blame] | 261 | u64 first_free; |
| 262 | u64 last_alloc; |
Chris Mason | be74417 | 2007-05-06 10:15:01 -0400 | [diff] [blame] | 263 | u64 pinned; |
Chris Mason | e37c9e6 | 2007-05-09 20:13:14 -0400 | [diff] [blame] | 264 | u64 last_prealloc; |
Chris Mason | be74417 | 2007-05-06 10:15:01 -0400 | [diff] [blame] | 265 | int data; |
Chris Mason | e37c9e6 | 2007-05-09 20:13:14 -0400 | [diff] [blame] | 266 | int cached; |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 267 | }; |
| 268 | |
Chris Mason | 87cbda5 | 2007-03-28 19:44:27 -0400 | [diff] [blame] | 269 | struct crypto_hash; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 270 | struct btrfs_fs_info { |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 271 | struct btrfs_root *extent_root; |
| 272 | struct btrfs_root *tree_root; |
Chris Mason | 0bd93ba | 2007-04-11 13:57:44 -0400 | [diff] [blame] | 273 | struct btrfs_root *dev_root; |
Chris Mason | 0f7d52f | 2007-04-09 10:42:37 -0400 | [diff] [blame] | 274 | struct radix_tree_root fs_roots_radix; |
Chris Mason | 8ef9762 | 2007-03-26 10:15:30 -0400 | [diff] [blame] | 275 | struct radix_tree_root pending_del_radix; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 276 | struct radix_tree_root pinned_radix; |
Chris Mason | 7eccb90 | 2007-04-11 15:53:25 -0400 | [diff] [blame] | 277 | struct radix_tree_root dev_radix; |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 278 | struct radix_tree_root block_group_radix; |
Chris Mason | be74417 | 2007-05-06 10:15:01 -0400 | [diff] [blame] | 279 | struct radix_tree_root block_group_data_radix; |
Chris Mason | e37c9e6 | 2007-05-09 20:13:14 -0400 | [diff] [blame] | 280 | struct radix_tree_root extent_map_radix; |
Chris Mason | f2458e1 | 2007-04-25 15:52:25 -0400 | [diff] [blame] | 281 | |
| 282 | u64 extent_tree_insert[BTRFS_MAX_LEVEL * 3]; |
| 283 | int extent_tree_insert_nr; |
| 284 | u64 extent_tree_prealloc[BTRFS_MAX_LEVEL * 3]; |
| 285 | int extent_tree_prealloc_nr; |
| 286 | |
Chris Mason | 293ffd5 | 2007-03-20 15:57:25 -0400 | [diff] [blame] | 287 | u64 generation; |
Chris Mason | 79154b1 | 2007-03-22 15:59:16 -0400 | [diff] [blame] | 288 | struct btrfs_transaction *running_transaction; |
Chris Mason | 1261ec4 | 2007-03-20 20:35:03 -0400 | [diff] [blame] | 289 | struct btrfs_super_block *disk_super; |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 290 | struct buffer_head *sb_buffer; |
| 291 | struct super_block *sb; |
Chris Mason | d98237b | 2007-03-28 13:57:48 -0400 | [diff] [blame] | 292 | struct inode *btree_inode; |
Chris Mason | 79154b1 | 2007-03-22 15:59:16 -0400 | [diff] [blame] | 293 | struct mutex trans_mutex; |
Chris Mason | d561c02 | 2007-03-23 19:47:49 -0400 | [diff] [blame] | 294 | struct mutex fs_mutex; |
Chris Mason | 8fd1779 | 2007-04-19 21:01:03 -0400 | [diff] [blame] | 295 | struct list_head trans_list; |
Chris Mason | 87cbda5 | 2007-03-28 19:44:27 -0400 | [diff] [blame] | 296 | struct crypto_hash *hash_tfm; |
| 297 | spinlock_t hash_lock; |
Chris Mason | e66f709 | 2007-04-20 13:16:02 -0400 | [diff] [blame] | 298 | int do_barriers; |
Chris Mason | d6e4a42 | 2007-04-06 15:37:36 -0400 | [diff] [blame] | 299 | struct kobject kobj; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 300 | }; |
| 301 | |
| 302 | /* |
| 303 | * in ram representation of the tree. extent_root is used for all allocations |
Chris Mason | f2458e1 | 2007-04-25 15:52:25 -0400 | [diff] [blame] | 304 | * and for the extent tree extent_root root. |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 305 | */ |
| 306 | struct btrfs_root { |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 307 | struct buffer_head *node; |
| 308 | struct buffer_head *commit_root; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 309 | struct btrfs_root_item root_item; |
| 310 | struct btrfs_key root_key; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 311 | struct btrfs_fs_info *fs_info; |
Chris Mason | 0f7d52f | 2007-04-09 10:42:37 -0400 | [diff] [blame] | 312 | struct inode *inode; |
| 313 | u64 objectid; |
| 314 | u64 last_trans; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 315 | u32 blocksize; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 316 | int ref_cows; |
| 317 | u32 type; |
Chris Mason | 1b05da2 | 2007-04-10 12:13:09 -0400 | [diff] [blame] | 318 | u64 highest_inode; |
| 319 | u64 last_inode_alloc; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 320 | }; |
| 321 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 322 | /* the lower bits in the key flags defines the item type */ |
| 323 | #define BTRFS_KEY_TYPE_MAX 256 |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 324 | #define BTRFS_KEY_TYPE_SHIFT 24 |
| 325 | #define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \ |
| 326 | BTRFS_KEY_TYPE_SHIFT) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 327 | |
| 328 | /* |
| 329 | * inode items have the data typically returned from stat and store other |
| 330 | * info about object characteristics. There is one for every file and dir in |
| 331 | * the FS |
| 332 | */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 333 | #define BTRFS_INODE_ITEM_KEY 1 |
| 334 | |
| 335 | /* reserve 2-15 close to the inode for later flexibility */ |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 336 | |
| 337 | /* |
| 338 | * dir items are the name -> inode pointers in a directory. There is one |
| 339 | * for every name in a directory. |
| 340 | */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 341 | #define BTRFS_DIR_ITEM_KEY 16 |
| 342 | #define BTRFS_DIR_INDEX_KEY 17 |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 343 | /* |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 344 | * extent data is for file data |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 345 | */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 346 | #define BTRFS_EXTENT_DATA_KEY 18 |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 347 | /* |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 348 | * csum items have the checksums for data in the extents |
| 349 | */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 350 | #define BTRFS_CSUM_ITEM_KEY 19 |
| 351 | |
| 352 | /* reserve 20-31 for other file stuff */ |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 353 | |
| 354 | /* |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 355 | * root items point to tree roots. There are typically in the root |
| 356 | * tree used by the super block to find all the other trees |
| 357 | */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 358 | #define BTRFS_ROOT_ITEM_KEY 32 |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 359 | /* |
| 360 | * extent items are in the extent map tree. These record which blocks |
| 361 | * are used, and how many references there are to each block |
| 362 | */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 363 | #define BTRFS_EXTENT_ITEM_KEY 33 |
| 364 | |
| 365 | /* |
| 366 | * block groups give us hints into the extent allocation trees. Which |
| 367 | * blocks are free etc etc |
| 368 | */ |
| 369 | #define BTRFS_BLOCK_GROUP_ITEM_KEY 34 |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 370 | |
| 371 | /* |
Chris Mason | 0bd93ba | 2007-04-11 13:57:44 -0400 | [diff] [blame] | 372 | * dev items list the devices that make up the FS |
| 373 | */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 374 | #define BTRFS_DEV_ITEM_KEY 35 |
Chris Mason | 0bd93ba | 2007-04-11 13:57:44 -0400 | [diff] [blame] | 375 | |
| 376 | /* |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 377 | * string items are for debugging. They just store a short string of |
| 378 | * data in the FS |
| 379 | */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 380 | #define BTRFS_STRING_ITEM_KEY 253 |
| 381 | |
| 382 | |
| 383 | static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi) |
| 384 | { |
| 385 | return le64_to_cpu(bi->used); |
| 386 | } |
| 387 | |
| 388 | static inline void btrfs_set_block_group_used(struct |
| 389 | btrfs_block_group_item *bi, |
| 390 | u64 val) |
| 391 | { |
| 392 | bi->used = cpu_to_le64(val); |
| 393 | } |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 394 | |
| 395 | static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i) |
| 396 | { |
| 397 | return le64_to_cpu(i->generation); |
| 398 | } |
| 399 | |
| 400 | static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i, |
| 401 | u64 val) |
| 402 | { |
| 403 | i->generation = cpu_to_le64(val); |
| 404 | } |
| 405 | |
| 406 | static inline u64 btrfs_inode_size(struct btrfs_inode_item *i) |
| 407 | { |
| 408 | return le64_to_cpu(i->size); |
| 409 | } |
| 410 | |
| 411 | static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val) |
| 412 | { |
| 413 | i->size = cpu_to_le64(val); |
| 414 | } |
| 415 | |
| 416 | static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i) |
| 417 | { |
| 418 | return le64_to_cpu(i->nblocks); |
| 419 | } |
| 420 | |
| 421 | static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val) |
| 422 | { |
| 423 | i->nblocks = cpu_to_le64(val); |
| 424 | } |
| 425 | |
Chris Mason | 31f3c99 | 2007-04-30 15:25:45 -0400 | [diff] [blame] | 426 | static inline u64 btrfs_inode_block_group(struct btrfs_inode_item *i) |
| 427 | { |
| 428 | return le64_to_cpu(i->block_group); |
| 429 | } |
| 430 | |
| 431 | static inline void btrfs_set_inode_block_group(struct btrfs_inode_item *i, |
| 432 | u64 val) |
| 433 | { |
| 434 | i->block_group = cpu_to_le64(val); |
| 435 | } |
| 436 | |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 437 | static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i) |
| 438 | { |
| 439 | return le32_to_cpu(i->nlink); |
| 440 | } |
| 441 | |
| 442 | static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val) |
| 443 | { |
| 444 | i->nlink = cpu_to_le32(val); |
| 445 | } |
| 446 | |
| 447 | static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i) |
| 448 | { |
| 449 | return le32_to_cpu(i->uid); |
| 450 | } |
| 451 | |
| 452 | static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val) |
| 453 | { |
| 454 | i->uid = cpu_to_le32(val); |
| 455 | } |
| 456 | |
| 457 | static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i) |
| 458 | { |
| 459 | return le32_to_cpu(i->gid); |
| 460 | } |
| 461 | |
| 462 | static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val) |
| 463 | { |
| 464 | i->gid = cpu_to_le32(val); |
| 465 | } |
| 466 | |
| 467 | static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i) |
| 468 | { |
| 469 | return le32_to_cpu(i->mode); |
| 470 | } |
| 471 | |
| 472 | static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val) |
| 473 | { |
| 474 | i->mode = cpu_to_le32(val); |
| 475 | } |
| 476 | |
| 477 | static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i) |
| 478 | { |
| 479 | return le32_to_cpu(i->rdev); |
| 480 | } |
| 481 | |
| 482 | static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val) |
| 483 | { |
| 484 | i->rdev = cpu_to_le32(val); |
| 485 | } |
| 486 | |
| 487 | static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i) |
| 488 | { |
| 489 | return le16_to_cpu(i->flags); |
| 490 | } |
| 491 | |
| 492 | static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val) |
| 493 | { |
| 494 | i->flags = cpu_to_le16(val); |
| 495 | } |
| 496 | |
| 497 | static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i) |
| 498 | { |
| 499 | return le16_to_cpu(i->compat_flags); |
| 500 | } |
| 501 | |
| 502 | static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i, |
| 503 | u16 val) |
| 504 | { |
| 505 | i->compat_flags = cpu_to_le16(val); |
| 506 | } |
| 507 | |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 508 | static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts) |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 509 | { |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 510 | return le64_to_cpu(ts->sec); |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts, |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 514 | u64 val) |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 515 | { |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 516 | ts->sec = cpu_to_le64(val); |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts) |
| 520 | { |
| 521 | return le32_to_cpu(ts->nsec); |
| 522 | } |
| 523 | |
| 524 | static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts, |
| 525 | u32 val) |
| 526 | { |
| 527 | ts->nsec = cpu_to_le32(val); |
| 528 | } |
| 529 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 530 | static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei) |
Chris Mason | cf27e1e | 2007-03-13 09:49:06 -0400 | [diff] [blame] | 531 | { |
| 532 | return le32_to_cpu(ei->refs); |
| 533 | } |
| 534 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 535 | 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] | 536 | { |
| 537 | ei->refs = cpu_to_le32(val); |
| 538 | } |
| 539 | |
Chris Mason | 4d77567 | 2007-04-20 20:23:12 -0400 | [diff] [blame] | 540 | static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei) |
| 541 | { |
| 542 | return le64_to_cpu(ei->owner); |
| 543 | } |
| 544 | |
| 545 | static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val) |
| 546 | { |
| 547 | ei->owner = cpu_to_le64(val); |
| 548 | } |
| 549 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 550 | static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr) |
Chris Mason | 1d4f8a0 | 2007-03-13 09:28:32 -0400 | [diff] [blame] | 551 | { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 552 | return le64_to_cpu(n->ptrs[nr].blockptr); |
Chris Mason | 1d4f8a0 | 2007-03-13 09:28:32 -0400 | [diff] [blame] | 553 | } |
| 554 | |
Chris Mason | 4d77567 | 2007-04-20 20:23:12 -0400 | [diff] [blame] | 555 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 556 | static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr, |
| 557 | u64 val) |
Chris Mason | 1d4f8a0 | 2007-03-13 09:28:32 -0400 | [diff] [blame] | 558 | { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 559 | n->ptrs[nr].blockptr = cpu_to_le64(val); |
Chris Mason | 1d4f8a0 | 2007-03-13 09:28:32 -0400 | [diff] [blame] | 560 | } |
| 561 | |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 562 | static inline u32 btrfs_item_offset(struct btrfs_item *item) |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 563 | { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 564 | return le32_to_cpu(item->offset); |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 565 | } |
| 566 | |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 567 | 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] | 568 | { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 569 | item->offset = cpu_to_le32(val); |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 570 | } |
| 571 | |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 572 | static inline u32 btrfs_item_end(struct btrfs_item *item) |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 573 | { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 574 | return le32_to_cpu(item->offset) + le16_to_cpu(item->size); |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | static inline u16 btrfs_item_size(struct btrfs_item *item) |
| 578 | { |
| 579 | return le16_to_cpu(item->size); |
| 580 | } |
| 581 | |
| 582 | static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val) |
| 583 | { |
| 584 | item->size = cpu_to_le16(val); |
| 585 | } |
| 586 | |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 587 | static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d) |
| 588 | { |
| 589 | return le16_to_cpu(d->flags); |
| 590 | } |
| 591 | |
| 592 | static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val) |
| 593 | { |
| 594 | d->flags = cpu_to_le16(val); |
| 595 | } |
| 596 | |
| 597 | static inline u8 btrfs_dir_type(struct btrfs_dir_item *d) |
| 598 | { |
| 599 | return d->type; |
| 600 | } |
| 601 | |
| 602 | static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val) |
| 603 | { |
| 604 | d->type = val; |
| 605 | } |
| 606 | |
Chris Mason | a8a2ee0 | 2007-03-16 08:46:49 -0400 | [diff] [blame] | 607 | static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d) |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 608 | { |
Chris Mason | a8a2ee0 | 2007-03-16 08:46:49 -0400 | [diff] [blame] | 609 | return le16_to_cpu(d->name_len); |
| 610 | } |
| 611 | |
| 612 | static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val) |
| 613 | { |
| 614 | d->name_len = cpu_to_le16(val); |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 615 | } |
| 616 | |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 617 | static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, |
| 618 | struct btrfs_disk_key *disk) |
| 619 | { |
| 620 | cpu->offset = le64_to_cpu(disk->offset); |
| 621 | cpu->flags = le32_to_cpu(disk->flags); |
| 622 | cpu->objectid = le64_to_cpu(disk->objectid); |
| 623 | } |
| 624 | |
| 625 | static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, |
| 626 | struct btrfs_key *cpu) |
| 627 | { |
| 628 | disk->offset = cpu_to_le64(cpu->offset); |
| 629 | disk->flags = cpu_to_le32(cpu->flags); |
| 630 | disk->objectid = cpu_to_le64(cpu->objectid); |
| 631 | } |
| 632 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 633 | static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 634 | { |
| 635 | return le64_to_cpu(disk->objectid); |
| 636 | } |
| 637 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 638 | static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk, |
| 639 | u64 val) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 640 | { |
| 641 | disk->objectid = cpu_to_le64(val); |
| 642 | } |
| 643 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 644 | static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 645 | { |
| 646 | return le64_to_cpu(disk->offset); |
| 647 | } |
| 648 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 649 | static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk, |
| 650 | u64 val) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 651 | { |
| 652 | disk->offset = cpu_to_le64(val); |
| 653 | } |
| 654 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 655 | static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 656 | { |
| 657 | return le32_to_cpu(disk->flags); |
| 658 | } |
| 659 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 660 | static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk, |
| 661 | u32 val) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 662 | { |
| 663 | disk->flags = cpu_to_le32(val); |
| 664 | } |
| 665 | |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 666 | static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key) |
| 667 | { |
| 668 | return le32_to_cpu(key->flags) >> BTRFS_KEY_TYPE_SHIFT; |
| 669 | } |
| 670 | |
| 671 | static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, |
| 672 | u32 val) |
| 673 | { |
| 674 | u32 flags = btrfs_disk_key_flags(key); |
| 675 | BUG_ON(val >= BTRFS_KEY_TYPE_MAX); |
| 676 | val = val << BTRFS_KEY_TYPE_SHIFT; |
| 677 | flags = (flags & ~BTRFS_KEY_TYPE_MASK) | val; |
| 678 | btrfs_set_disk_key_flags(key, flags); |
| 679 | } |
| 680 | |
| 681 | static inline u32 btrfs_key_type(struct btrfs_key *key) |
| 682 | { |
| 683 | return key->flags >> BTRFS_KEY_TYPE_SHIFT; |
| 684 | } |
| 685 | |
| 686 | static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val) |
| 687 | { |
| 688 | BUG_ON(val >= BTRFS_KEY_TYPE_MAX); |
| 689 | val = val << BTRFS_KEY_TYPE_SHIFT; |
| 690 | key->flags = (key->flags & ~(BTRFS_KEY_TYPE_MASK)) | val; |
| 691 | } |
| 692 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 693 | static inline u64 btrfs_header_blocknr(struct btrfs_header *h) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 694 | { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 695 | return le64_to_cpu(h->blocknr); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 696 | } |
| 697 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 698 | 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] | 699 | { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 700 | h->blocknr = cpu_to_le64(blocknr); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 701 | } |
| 702 | |
Chris Mason | 7f5c151 | 2007-03-23 15:56:19 -0400 | [diff] [blame] | 703 | static inline u64 btrfs_header_generation(struct btrfs_header *h) |
| 704 | { |
| 705 | return le64_to_cpu(h->generation); |
| 706 | } |
| 707 | |
| 708 | static inline void btrfs_set_header_generation(struct btrfs_header *h, |
| 709 | u64 val) |
| 710 | { |
| 711 | h->generation = cpu_to_le64(val); |
| 712 | } |
| 713 | |
Chris Mason | 4d77567 | 2007-04-20 20:23:12 -0400 | [diff] [blame] | 714 | static inline u64 btrfs_header_owner(struct btrfs_header *h) |
| 715 | { |
| 716 | return le64_to_cpu(h->owner); |
| 717 | } |
| 718 | |
| 719 | static inline void btrfs_set_header_owner(struct btrfs_header *h, |
| 720 | u64 val) |
| 721 | { |
| 722 | h->owner = cpu_to_le64(val); |
| 723 | } |
| 724 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 725 | static inline u16 btrfs_header_nritems(struct btrfs_header *h) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 726 | { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 727 | return le16_to_cpu(h->nritems); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 728 | } |
| 729 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 730 | 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] | 731 | { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 732 | h->nritems = cpu_to_le16(val); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 733 | } |
| 734 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 735 | static inline u16 btrfs_header_flags(struct btrfs_header *h) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 736 | { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 737 | return le16_to_cpu(h->flags); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 738 | } |
| 739 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 740 | 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] | 741 | { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 742 | h->flags = cpu_to_le16(val); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 743 | } |
| 744 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 745 | static inline int btrfs_header_level(struct btrfs_header *h) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 746 | { |
Chris Mason | 9a6f11e | 2007-03-27 09:06:38 -0400 | [diff] [blame] | 747 | return h->level; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 748 | } |
| 749 | |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 750 | 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] | 751 | { |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 752 | BUG_ON(level > BTRFS_MAX_LEVEL); |
Chris Mason | 9a6f11e | 2007-03-27 09:06:38 -0400 | [diff] [blame] | 753 | h->level = level; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 754 | } |
| 755 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 756 | static inline int btrfs_is_leaf(struct btrfs_node *n) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 757 | { |
| 758 | return (btrfs_header_level(&n->header) == 0); |
| 759 | } |
| 760 | |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 761 | static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item) |
| 762 | { |
| 763 | return le64_to_cpu(item->blocknr); |
| 764 | } |
| 765 | |
| 766 | static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val) |
| 767 | { |
| 768 | item->blocknr = cpu_to_le64(val); |
| 769 | } |
| 770 | |
Chris Mason | d6e4a42 | 2007-04-06 15:37:36 -0400 | [diff] [blame] | 771 | static inline u64 btrfs_root_dirid(struct btrfs_root_item *item) |
| 772 | { |
| 773 | return le64_to_cpu(item->root_dirid); |
| 774 | } |
| 775 | |
| 776 | static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val) |
| 777 | { |
| 778 | item->root_dirid = cpu_to_le64(val); |
| 779 | } |
| 780 | |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 781 | static inline u32 btrfs_root_refs(struct btrfs_root_item *item) |
| 782 | { |
| 783 | return le32_to_cpu(item->refs); |
| 784 | } |
| 785 | |
| 786 | static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val) |
| 787 | { |
| 788 | item->refs = cpu_to_le32(val); |
| 789 | } |
| 790 | |
| 791 | static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s) |
| 792 | { |
| 793 | return le64_to_cpu(s->blocknr); |
| 794 | } |
| 795 | |
| 796 | static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val) |
| 797 | { |
| 798 | s->blocknr = cpu_to_le64(val); |
| 799 | } |
| 800 | |
Chris Mason | 0f7d52f | 2007-04-09 10:42:37 -0400 | [diff] [blame] | 801 | static inline u64 btrfs_super_generation(struct btrfs_super_block *s) |
| 802 | { |
| 803 | return le64_to_cpu(s->generation); |
| 804 | } |
| 805 | |
| 806 | static inline void btrfs_set_super_generation(struct btrfs_super_block *s, |
| 807 | u64 val) |
| 808 | { |
| 809 | s->generation = cpu_to_le64(val); |
| 810 | } |
| 811 | |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 812 | static inline u64 btrfs_super_root(struct btrfs_super_block *s) |
| 813 | { |
| 814 | return le64_to_cpu(s->root); |
| 815 | } |
| 816 | |
| 817 | static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val) |
| 818 | { |
| 819 | s->root = cpu_to_le64(val); |
| 820 | } |
| 821 | |
| 822 | static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s) |
| 823 | { |
| 824 | return le64_to_cpu(s->total_blocks); |
| 825 | } |
| 826 | |
| 827 | static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s, |
| 828 | u64 val) |
| 829 | { |
| 830 | s->total_blocks = cpu_to_le64(val); |
| 831 | } |
| 832 | |
| 833 | static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s) |
| 834 | { |
| 835 | return le64_to_cpu(s->blocks_used); |
| 836 | } |
| 837 | |
| 838 | static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s, |
| 839 | u64 val) |
| 840 | { |
| 841 | s->blocks_used = cpu_to_le64(val); |
| 842 | } |
| 843 | |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 844 | static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s) |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 845 | { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 846 | return le32_to_cpu(s->blocksize); |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s, |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 850 | u32 val) |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 851 | { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 852 | s->blocksize = cpu_to_le32(val); |
| 853 | } |
| 854 | |
Chris Mason | 2e635a2 | 2007-03-21 11:12:56 -0400 | [diff] [blame] | 855 | static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s) |
| 856 | { |
| 857 | return le64_to_cpu(s->root_dir_objectid); |
| 858 | } |
| 859 | |
| 860 | static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64 |
| 861 | val) |
| 862 | { |
| 863 | s->root_dir_objectid = cpu_to_le64(val); |
| 864 | } |
| 865 | |
Chris Mason | b4100d6 | 2007-04-12 12:14:00 -0400 | [diff] [blame] | 866 | static inline u64 btrfs_super_last_device_id(struct btrfs_super_block *s) |
| 867 | { |
| 868 | return le64_to_cpu(s->last_device_id); |
| 869 | } |
| 870 | |
| 871 | static inline void btrfs_set_super_last_device_id(struct btrfs_super_block *s, |
| 872 | u64 val) |
| 873 | { |
| 874 | s->last_device_id = cpu_to_le64(val); |
| 875 | } |
| 876 | |
| 877 | static inline u64 btrfs_super_device_id(struct btrfs_super_block *s) |
| 878 | { |
| 879 | return le64_to_cpu(s->device_id); |
| 880 | } |
| 881 | |
| 882 | static inline void btrfs_set_super_device_id(struct btrfs_super_block *s, |
| 883 | u64 val) |
| 884 | { |
| 885 | s->device_id = cpu_to_le64(val); |
| 886 | } |
| 887 | |
Chris Mason | 0bd93ba | 2007-04-11 13:57:44 -0400 | [diff] [blame] | 888 | static inline u64 btrfs_super_device_block_start(struct btrfs_super_block *s) |
| 889 | { |
| 890 | return le64_to_cpu(s->device_block_start); |
| 891 | } |
| 892 | |
| 893 | static inline void btrfs_set_super_device_block_start(struct btrfs_super_block |
| 894 | *s, u64 val) |
| 895 | { |
| 896 | s->device_block_start = cpu_to_le64(val); |
| 897 | } |
| 898 | |
| 899 | static inline u64 btrfs_super_device_num_blocks(struct btrfs_super_block *s) |
| 900 | { |
| 901 | return le64_to_cpu(s->device_num_blocks); |
| 902 | } |
| 903 | |
| 904 | static inline void btrfs_set_super_device_num_blocks(struct btrfs_super_block |
| 905 | *s, u64 val) |
| 906 | { |
| 907 | s->device_num_blocks = cpu_to_le64(val); |
| 908 | } |
| 909 | |
| 910 | static inline u64 btrfs_super_device_root(struct btrfs_super_block *s) |
| 911 | { |
| 912 | return le64_to_cpu(s->device_root); |
| 913 | } |
| 914 | |
| 915 | static inline void btrfs_set_super_device_root(struct btrfs_super_block |
| 916 | *s, u64 val) |
| 917 | { |
| 918 | s->device_root = cpu_to_le64(val); |
| 919 | } |
| 920 | |
| 921 | |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 922 | static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l) |
| 923 | { |
| 924 | return (u8 *)l->items; |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 925 | } |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 926 | |
Chris Mason | 236454d | 2007-04-19 13:37:44 -0400 | [diff] [blame] | 927 | static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e) |
| 928 | { |
| 929 | return e->type; |
| 930 | } |
| 931 | static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e, |
| 932 | u8 val) |
| 933 | { |
| 934 | e->type = val; |
| 935 | } |
| 936 | |
| 937 | static inline char *btrfs_file_extent_inline_start(struct |
| 938 | btrfs_file_extent_item *e) |
| 939 | { |
| 940 | return (char *)(&e->disk_blocknr); |
| 941 | } |
| 942 | |
| 943 | static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize) |
| 944 | { |
| 945 | return (unsigned long)(&((struct |
| 946 | btrfs_file_extent_item *)NULL)->disk_blocknr) + datasize; |
| 947 | } |
| 948 | |
| 949 | static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e) |
| 950 | { |
| 951 | struct btrfs_file_extent_item *fe = NULL; |
| 952 | return btrfs_item_size(e) - (unsigned long)(&fe->disk_blocknr); |
| 953 | } |
| 954 | |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 955 | static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item |
| 956 | *e) |
| 957 | { |
| 958 | return le64_to_cpu(e->disk_blocknr); |
| 959 | } |
| 960 | |
| 961 | static inline void btrfs_set_file_extent_disk_blocknr(struct |
| 962 | btrfs_file_extent_item |
| 963 | *e, u64 val) |
| 964 | { |
| 965 | e->disk_blocknr = cpu_to_le64(val); |
| 966 | } |
| 967 | |
Chris Mason | 71951f3 | 2007-03-27 09:16:29 -0400 | [diff] [blame] | 968 | static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e) |
| 969 | { |
| 970 | return le64_to_cpu(e->generation); |
| 971 | } |
| 972 | |
| 973 | static inline void btrfs_set_file_extent_generation(struct |
| 974 | btrfs_file_extent_item *e, |
| 975 | u64 val) |
| 976 | { |
| 977 | e->generation = cpu_to_le64(val); |
| 978 | } |
| 979 | |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 980 | static inline u64 btrfs_file_extent_disk_num_blocks(struct |
| 981 | btrfs_file_extent_item *e) |
| 982 | { |
| 983 | return le64_to_cpu(e->disk_num_blocks); |
| 984 | } |
| 985 | |
| 986 | static inline void btrfs_set_file_extent_disk_num_blocks(struct |
| 987 | btrfs_file_extent_item |
| 988 | *e, u64 val) |
| 989 | { |
| 990 | e->disk_num_blocks = cpu_to_le64(val); |
| 991 | } |
| 992 | |
| 993 | static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e) |
| 994 | { |
| 995 | return le64_to_cpu(e->offset); |
| 996 | } |
| 997 | |
| 998 | static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item |
| 999 | *e, u64 val) |
| 1000 | { |
| 1001 | e->offset = cpu_to_le64(val); |
| 1002 | } |
| 1003 | |
| 1004 | static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item |
| 1005 | *e) |
| 1006 | { |
| 1007 | return le64_to_cpu(e->num_blocks); |
| 1008 | } |
| 1009 | |
| 1010 | static inline void btrfs_set_file_extent_num_blocks(struct |
| 1011 | btrfs_file_extent_item *e, |
| 1012 | u64 val) |
| 1013 | { |
| 1014 | e->num_blocks = cpu_to_le64(val); |
| 1015 | } |
| 1016 | |
Chris Mason | 0bd93ba | 2007-04-11 13:57:44 -0400 | [diff] [blame] | 1017 | static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d) |
| 1018 | { |
| 1019 | return le16_to_cpu(d->pathlen); |
| 1020 | } |
| 1021 | |
| 1022 | static inline void btrfs_set_device_pathlen(struct btrfs_device_item *d, |
| 1023 | u16 val) |
| 1024 | { |
| 1025 | d->pathlen = cpu_to_le16(val); |
| 1026 | } |
| 1027 | |
Chris Mason | b4100d6 | 2007-04-12 12:14:00 -0400 | [diff] [blame] | 1028 | static inline u64 btrfs_device_id(struct btrfs_device_item *d) |
| 1029 | { |
| 1030 | return le64_to_cpu(d->device_id); |
| 1031 | } |
| 1032 | |
| 1033 | static inline void btrfs_set_device_id(struct btrfs_device_item *d, |
| 1034 | u64 val) |
| 1035 | { |
| 1036 | d->device_id = cpu_to_le64(val); |
| 1037 | } |
| 1038 | |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 1039 | static inline struct btrfs_root *btrfs_sb(struct super_block *sb) |
| 1040 | { |
| 1041 | return sb->s_fs_info; |
| 1042 | } |
| 1043 | |
Chris Mason | d602557 | 2007-03-30 14:27:56 -0400 | [diff] [blame] | 1044 | static inline void btrfs_check_bounds(void *vptr, size_t len, |
| 1045 | void *vcontainer, size_t container_len) |
| 1046 | { |
| 1047 | char *ptr = vptr; |
| 1048 | char *container = vcontainer; |
| 1049 | WARN_ON(ptr < container); |
| 1050 | WARN_ON(ptr + len > container + container_len); |
| 1051 | } |
| 1052 | |
| 1053 | static inline void btrfs_memcpy(struct btrfs_root *root, |
| 1054 | void *dst_block, |
| 1055 | void *dst, const void *src, size_t nr) |
| 1056 | { |
| 1057 | btrfs_check_bounds(dst, nr, dst_block, root->fs_info->sb->s_blocksize); |
| 1058 | memcpy(dst, src, nr); |
| 1059 | } |
| 1060 | |
| 1061 | static inline void btrfs_memmove(struct btrfs_root *root, |
| 1062 | void *dst_block, |
| 1063 | void *dst, void *src, size_t nr) |
| 1064 | { |
| 1065 | btrfs_check_bounds(dst, nr, dst_block, root->fs_info->sb->s_blocksize); |
| 1066 | memmove(dst, src, nr); |
| 1067 | } |
| 1068 | |
| 1069 | static inline void btrfs_mark_buffer_dirty(struct buffer_head *bh) |
| 1070 | { |
| 1071 | WARN_ON(!atomic_read(&bh->b_count)); |
| 1072 | mark_buffer_dirty(bh); |
| 1073 | } |
| 1074 | |
Chris Mason | 4beb1b8 | 2007-03-14 10:31:29 -0400 | [diff] [blame] | 1075 | /* helper function to cast into the data area of the leaf. */ |
| 1076 | #define btrfs_item_ptr(leaf, slot, type) \ |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 1077 | ((type *)(btrfs_leaf_data(leaf) + \ |
| 1078 | btrfs_item_offset((leaf)->items + (slot)))) |
Chris Mason | 4beb1b8 | 2007-03-14 10:31:29 -0400 | [diff] [blame] | 1079 | |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 1080 | /* extent-tree.c */ |
Chris Mason | 31f3c99 | 2007-04-30 15:25:45 -0400 | [diff] [blame] | 1081 | struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root, |
| 1082 | struct btrfs_block_group_cache |
Chris Mason | be74417 | 2007-05-06 10:15:01 -0400 | [diff] [blame] | 1083 | *hint, u64 search_start, |
Chris Mason | de428b6 | 2007-05-18 13:28:27 -0400 | [diff] [blame^] | 1084 | int data, int owner); |
Chris Mason | c5739bb | 2007-04-10 09:27:04 -0400 | [diff] [blame] | 1085 | int btrfs_inc_root_ref(struct btrfs_trans_handle *trans, |
| 1086 | struct btrfs_root *root); |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 1087 | struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, |
Chris Mason | 31f3c99 | 2007-04-30 15:25:45 -0400 | [diff] [blame] | 1088 | struct btrfs_root *root, u64 hint); |
Chris Mason | 4d77567 | 2007-04-20 20:23:12 -0400 | [diff] [blame] | 1089 | int btrfs_alloc_extent(struct btrfs_trans_handle *trans, |
| 1090 | struct btrfs_root *root, u64 owner, |
Chris Mason | c62a192 | 2007-04-24 12:07:39 -0400 | [diff] [blame] | 1091 | u64 num_blocks, u64 search_start, |
Chris Mason | be08c1b | 2007-05-03 09:06:49 -0400 | [diff] [blame] | 1092 | u64 search_end, struct btrfs_key *ins, int data); |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 1093 | 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] | 1094 | struct buffer_head *buf); |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 1095 | int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root |
| 1096 | *root, u64 blocknr, u64 num_blocks, int pin); |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1097 | int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct |
| 1098 | btrfs_root *root); |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 1099 | int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, |
| 1100 | struct btrfs_root *root, |
| 1101 | u64 blocknr, u64 num_blocks); |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 1102 | int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, |
| 1103 | struct btrfs_root *root); |
| 1104 | int btrfs_free_block_groups(struct btrfs_fs_info *info); |
| 1105 | int btrfs_read_block_groups(struct btrfs_root *root); |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1106 | /* ctree.c */ |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 1107 | int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root |
| 1108 | *root, struct btrfs_path *path, u32 data_size); |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 1109 | int btrfs_truncate_item(struct btrfs_trans_handle *trans, |
| 1110 | struct btrfs_root *root, |
| 1111 | struct btrfs_path *path, |
| 1112 | u32 new_size); |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 1113 | int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root |
| 1114 | *root, struct btrfs_key *key, struct btrfs_path *p, int |
| 1115 | ins_len, int cow); |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 1116 | void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p); |
Chris Mason | 2c90e5d | 2007-04-02 10:50:19 -0400 | [diff] [blame] | 1117 | struct btrfs_path *btrfs_alloc_path(void); |
| 1118 | void btrfs_free_path(struct btrfs_path *p); |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 1119 | void btrfs_init_path(struct btrfs_path *p); |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 1120 | int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
| 1121 | struct btrfs_path *path); |
| 1122 | int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root |
| 1123 | *root, struct btrfs_key *key, void *data, u32 data_size); |
| 1124 | int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root |
| 1125 | *root, struct btrfs_path *path, struct btrfs_key |
| 1126 | *cpu_key, u32 data_size); |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 1127 | int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 1128 | 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] | 1129 | int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 1130 | *root, struct buffer_head *snap); |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1131 | /* root-item.c */ |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 1132 | int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
| 1133 | struct btrfs_key *key); |
| 1134 | int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root |
| 1135 | *root, struct btrfs_key *key, struct btrfs_root_item |
| 1136 | *item); |
| 1137 | int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root |
| 1138 | *root, struct btrfs_key *key, struct btrfs_root_item |
| 1139 | *item); |
| 1140 | int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct |
| 1141 | btrfs_root_item *item, struct btrfs_key *key); |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1142 | /* dir-item.c */ |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 1143 | int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root |
Chris Mason | d6e4a42 | 2007-04-06 15:37:36 -0400 | [diff] [blame] | 1144 | *root, const char *name, int name_len, u64 dir, |
| 1145 | struct btrfs_key *location, u8 type); |
Chris Mason | 7e38180 | 2007-04-19 15:36:27 -0400 | [diff] [blame] | 1146 | struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, |
| 1147 | struct btrfs_root *root, |
| 1148 | struct btrfs_path *path, u64 dir, |
| 1149 | const char *name, int name_len, |
| 1150 | int mod); |
| 1151 | struct btrfs_dir_item * |
| 1152 | btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans, |
| 1153 | struct btrfs_root *root, |
| 1154 | struct btrfs_path *path, u64 dir, |
| 1155 | u64 objectid, const char *name, int name_len, |
| 1156 | int mod); |
| 1157 | struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root, |
| 1158 | struct btrfs_path *path, |
Chris Mason | 7f5c151 | 2007-03-23 15:56:19 -0400 | [diff] [blame] | 1159 | const char *name, int name_len); |
Chris Mason | 7e38180 | 2007-04-19 15:36:27 -0400 | [diff] [blame] | 1160 | int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans, |
| 1161 | struct btrfs_root *root, |
| 1162 | struct btrfs_path *path, |
| 1163 | struct btrfs_dir_item *di); |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1164 | /* inode-map.c */ |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 1165 | int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, |
| 1166 | struct btrfs_root *fs_root, |
| 1167 | u64 dirid, u64 *objectid); |
Chris Mason | 5be6f7f | 2007-04-05 13:35:25 -0400 | [diff] [blame] | 1168 | int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid); |
| 1169 | |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1170 | /* inode-item.c */ |
Chris Mason | 293ffd5 | 2007-03-20 15:57:25 -0400 | [diff] [blame] | 1171 | int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root |
| 1172 | *root, u64 objectid, struct btrfs_inode_item |
| 1173 | *inode_item); |
| 1174 | int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root |
Chris Mason | d6e4a42 | 2007-04-06 15:37:36 -0400 | [diff] [blame] | 1175 | *root, struct btrfs_path *path, |
| 1176 | struct btrfs_key *location, int mod); |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1177 | |
| 1178 | /* file-item.c */ |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 1179 | int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1180 | struct btrfs_root *root, |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 1181 | u64 objectid, u64 pos, u64 offset, |
| 1182 | u64 num_blocks); |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1183 | int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, |
| 1184 | struct btrfs_root *root, |
| 1185 | struct btrfs_path *path, u64 objectid, |
Chris Mason | 9773a78 | 2007-03-27 11:26:26 -0400 | [diff] [blame] | 1186 | u64 blocknr, int mod); |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 1187 | int btrfs_csum_file_block(struct btrfs_trans_handle *trans, |
| 1188 | struct btrfs_root *root, |
| 1189 | u64 objectid, u64 offset, |
| 1190 | char *data, size_t len); |
| 1191 | int btrfs_csum_verify_file_block(struct btrfs_root *root, |
| 1192 | u64 objectid, u64 offset, |
| 1193 | char *data, size_t len); |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 1194 | struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, |
| 1195 | struct btrfs_root *root, |
| 1196 | struct btrfs_path *path, |
| 1197 | u64 objectid, u64 offset, |
| 1198 | int cow); |
Chris Mason | d6e4a42 | 2007-04-06 15:37:36 -0400 | [diff] [blame] | 1199 | /* super.c */ |
| 1200 | extern struct subsystem btrfs_subsys; |
| 1201 | |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 1202 | #endif |