Chris Mason | 6cbd557 | 2007-06-12 09:07:21 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Oracle. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public |
| 6 | * License v2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public |
| 14 | * License along with this program; if not, write to the |
| 15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 16 | * Boston, MA 021110-1307, USA. |
| 17 | */ |
| 18 | |
Chris Mason | dc17ff8 | 2008-01-08 15:46:30 -0500 | [diff] [blame] | 19 | #ifndef __BTRFS_CTREE__ |
| 20 | #define __BTRFS_CTREE__ |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 21 | |
Chris Mason | 6da6aba | 2007-12-18 16:15:09 -0500 | [diff] [blame] | 22 | #include <linux/version.h> |
Chris Mason | 810191f | 2007-10-15 16:18:55 -0400 | [diff] [blame] | 23 | #include <linux/mm.h> |
| 24 | #include <linux/highmem.h> |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 25 | #include <linux/fs.h> |
Chris Mason | 08607c1 | 2007-06-08 15:33:54 -0400 | [diff] [blame] | 26 | #include <linux/workqueue.h> |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 27 | #include <linux/completion.h> |
Chris Mason | 479965d | 2007-10-15 16:14:27 -0400 | [diff] [blame] | 28 | #include <asm/kmap_types.h> |
Chris Mason | 8ef9762 | 2007-03-26 10:15:30 -0400 | [diff] [blame] | 29 | #include "bit-radix.h" |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 30 | #include "extent_io.h" |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 31 | #include "extent_map.h" |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 32 | |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 33 | struct btrfs_trans_handle; |
Chris Mason | 79154b1 | 2007-03-22 15:59:16 -0400 | [diff] [blame] | 34 | struct btrfs_transaction; |
Chris Mason | 35b7e47 | 2007-05-02 15:53:43 -0400 | [diff] [blame] | 35 | extern struct kmem_cache *btrfs_trans_handle_cachep; |
| 36 | extern struct kmem_cache *btrfs_transaction_cachep; |
| 37 | extern struct kmem_cache *btrfs_bit_radix_cachep; |
Chris Mason | 2c90e5d | 2007-04-02 10:50:19 -0400 | [diff] [blame] | 38 | extern struct kmem_cache *btrfs_path_cachep; |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 39 | |
Chris Mason | 47b0c4f | 2008-02-04 10:10:43 -0500 | [diff] [blame] | 40 | #define BTRFS_MAGIC "_B4RfS_M" |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 41 | |
Chris Mason | f6dbff5 | 2007-12-13 11:13:32 -0500 | [diff] [blame] | 42 | #define BTRFS_MAX_LEVEL 8 |
Chris Mason | 6407bf6 | 2007-03-27 06:33:00 -0400 | [diff] [blame] | 43 | #define BTRFS_ROOT_TREE_OBJECTID 1ULL |
Chris Mason | 0cf6c62 | 2007-06-09 09:22:25 -0400 | [diff] [blame] | 44 | #define BTRFS_EXTENT_TREE_OBJECTID 2ULL |
| 45 | #define BTRFS_FS_TREE_OBJECTID 3ULL |
| 46 | #define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL |
Chris Mason | f6dbff5 | 2007-12-13 11:13:32 -0500 | [diff] [blame] | 47 | #define BTRFS_FIRST_FREE_OBJECTID 256ULL |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 48 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 49 | /* |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 50 | * we can actually store much bigger names, but lets not confuse the rest |
| 51 | * of linux |
| 52 | */ |
| 53 | #define BTRFS_NAME_LEN 255 |
| 54 | |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 55 | /* 32 bytes in various csum fields */ |
| 56 | #define BTRFS_CSUM_SIZE 32 |
Chris Mason | 509659c | 2007-05-10 12:36:17 -0400 | [diff] [blame] | 57 | /* four bytes for CRC32 */ |
| 58 | #define BTRFS_CRC32_SIZE 4 |
Chris Mason | 3954401 | 2007-12-12 14:38:19 -0500 | [diff] [blame] | 59 | #define BTRFS_EMPTY_DIR_SIZE 0 |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 60 | |
Chris Mason | fabb568 | 2007-06-07 22:13:21 -0400 | [diff] [blame] | 61 | #define BTRFS_FT_UNKNOWN 0 |
| 62 | #define BTRFS_FT_REG_FILE 1 |
| 63 | #define BTRFS_FT_DIR 2 |
| 64 | #define BTRFS_FT_CHRDEV 3 |
| 65 | #define BTRFS_FT_BLKDEV 4 |
| 66 | #define BTRFS_FT_FIFO 5 |
| 67 | #define BTRFS_FT_SOCK 6 |
| 68 | #define BTRFS_FT_SYMLINK 7 |
Josef Bacik | 5103e94 | 2007-11-16 11:45:54 -0500 | [diff] [blame] | 69 | #define BTRFS_FT_XATTR 8 |
| 70 | #define BTRFS_FT_MAX 9 |
Chris Mason | fabb568 | 2007-06-07 22:13:21 -0400 | [diff] [blame] | 71 | |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 72 | /* |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 73 | * the key defines the order in the tree, and so it also defines (optimal) |
| 74 | * block layout. objectid corresonds to the inode number. The flags |
| 75 | * tells us things about the object, and is a kind of stream selector. |
| 76 | * so for a given inode, keys with flags of 1 might refer to the inode |
| 77 | * data, flags of 2 may point to file data in the btree and flags == 3 |
| 78 | * may point to extents. |
| 79 | * |
| 80 | * offset is the starting byte offset for this key in the stream. |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 81 | * |
| 82 | * btrfs_disk_key is in disk byte order. struct btrfs_key is always |
| 83 | * in cpu native order. Otherwise they are identical and their sizes |
| 84 | * should be the same (ie both packed) |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 85 | */ |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 86 | struct btrfs_disk_key { |
| 87 | __le64 objectid; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 88 | u8 type; |
Chris Mason | 70b2bef | 2007-04-17 15:39:32 -0400 | [diff] [blame] | 89 | __le64 offset; |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 90 | } __attribute__ ((__packed__)); |
| 91 | |
| 92 | struct btrfs_key { |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 93 | u64 objectid; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 94 | u8 type; |
Chris Mason | 70b2bef | 2007-04-17 15:39:32 -0400 | [diff] [blame] | 95 | u64 offset; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 96 | } __attribute__ ((__packed__)); |
| 97 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 98 | #define BTRFS_FSID_SIZE 16 |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 99 | /* |
| 100 | * every tree block (leaf or node) starts with this header. |
| 101 | */ |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 102 | struct btrfs_header { |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 103 | u8 csum[BTRFS_CSUM_SIZE]; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 104 | u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 105 | __le64 bytenr; /* which block this node is supposed to live in */ |
Chris Mason | 7f5c151 | 2007-03-23 15:56:19 -0400 | [diff] [blame] | 106 | __le64 generation; |
Chris Mason | 4d77567 | 2007-04-20 20:23:12 -0400 | [diff] [blame] | 107 | __le64 owner; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 108 | __le32 nritems; |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 109 | __le16 flags; |
Chris Mason | 9a6f11e | 2007-03-27 09:06:38 -0400 | [diff] [blame] | 110 | u8 level; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 111 | } __attribute__ ((__packed__)); |
| 112 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 113 | #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \ |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 114 | sizeof(struct btrfs_header)) / \ |
Chris Mason | 74493f7 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 115 | sizeof(struct btrfs_key_ptr)) |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 116 | #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 117 | #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize)) |
Chris Mason | 236454d | 2007-04-19 13:37:44 -0400 | [diff] [blame] | 118 | #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \ |
| 119 | sizeof(struct btrfs_item) - \ |
| 120 | sizeof(struct btrfs_file_extent_item)) |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 121 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 122 | /* |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 123 | * the super block basically lists the main trees of the FS |
| 124 | * it currently lacks any block count etc etc |
| 125 | */ |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 126 | struct btrfs_super_block { |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 127 | u8 csum[BTRFS_CSUM_SIZE]; |
Chris Mason | 87cbda5 | 2007-03-28 19:44:27 -0400 | [diff] [blame] | 128 | /* the first 3 fields must match struct btrfs_header */ |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 129 | u8 fsid[16]; /* FS specific uuid */ |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 130 | __le64 bytenr; /* this block number */ |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 131 | __le64 magic; |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 132 | __le64 generation; |
| 133 | __le64 root; |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 134 | __le64 total_bytes; |
| 135 | __le64 bytes_used; |
Chris Mason | 2e635a2 | 2007-03-21 11:12:56 -0400 | [diff] [blame] | 136 | __le64 root_dir_objectid; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 137 | __le32 sectorsize; |
| 138 | __le32 nodesize; |
| 139 | __le32 leafsize; |
Chris Mason | 87ee04e | 2007-11-30 11:30:34 -0500 | [diff] [blame] | 140 | __le32 stripesize; |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 141 | u8 root_level; |
Chris Mason | cfaa729 | 2007-02-21 17:04:57 -0500 | [diff] [blame] | 142 | } __attribute__ ((__packed__)); |
| 143 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 144 | /* |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 145 | * 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] | 146 | * the item in the leaf (relative to the start of the data area) |
| 147 | */ |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 148 | struct btrfs_item { |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 149 | struct btrfs_disk_key key; |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 150 | __le32 offset; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 151 | __le32 size; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 152 | } __attribute__ ((__packed__)); |
| 153 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 154 | /* |
| 155 | * leaves have an item area and a data area: |
| 156 | * [item0, item1....itemN] [free space] [dataN...data1, data0] |
| 157 | * |
| 158 | * The data is separate from the items to get the keys closer together |
| 159 | * during searches. |
| 160 | */ |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 161 | struct btrfs_leaf { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 162 | struct btrfs_header header; |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 163 | struct btrfs_item items[]; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 164 | } __attribute__ ((__packed__)); |
| 165 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 166 | /* |
| 167 | * all non-leaf blocks are nodes, they hold only keys and pointers to |
| 168 | * other blocks |
| 169 | */ |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 170 | struct btrfs_key_ptr { |
| 171 | struct btrfs_disk_key key; |
| 172 | __le64 blockptr; |
Chris Mason | 74493f7 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 173 | __le64 generation; |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 174 | } __attribute__ ((__packed__)); |
| 175 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 176 | struct btrfs_node { |
Chris Mason | bb492bb | 2007-03-12 12:29:44 -0400 | [diff] [blame] | 177 | struct btrfs_header header; |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 178 | struct btrfs_key_ptr ptrs[]; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 179 | } __attribute__ ((__packed__)); |
| 180 | |
Chris Mason | fec577f | 2007-02-26 10:40:21 -0500 | [diff] [blame] | 181 | /* |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 182 | * btrfs_paths remember the path taken from the root down to the leaf. |
| 183 | * 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] | 184 | * to any other levels that are present. |
| 185 | * |
| 186 | * The slots array records the index of the item or block pointer |
| 187 | * used while walking the tree. |
| 188 | */ |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 189 | struct btrfs_path { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 190 | struct extent_buffer *nodes[BTRFS_MAX_LEVEL]; |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 191 | int slots[BTRFS_MAX_LEVEL]; |
Chris Mason | 3c69fae | 2007-08-07 15:52:22 -0400 | [diff] [blame] | 192 | int reada; |
Chris Mason | 6702ed4 | 2007-08-07 16:15:09 -0400 | [diff] [blame] | 193 | int lowest_level; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 194 | }; |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 195 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 196 | /* |
| 197 | * items in the extent btree are used to record the objectid of the |
| 198 | * owner of the block and the number of references |
| 199 | */ |
| 200 | struct btrfs_extent_item { |
| 201 | __le32 refs; |
Chris Mason | 74493f7 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 202 | } __attribute__ ((__packed__)); |
| 203 | |
| 204 | struct btrfs_extent_ref { |
| 205 | __le64 root; |
| 206 | __le64 generation; |
| 207 | __le64 objectid; |
| 208 | __le64 offset; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 209 | } __attribute__ ((__packed__)); |
| 210 | |
Chris Mason | 3954401 | 2007-12-12 14:38:19 -0500 | [diff] [blame] | 211 | struct btrfs_inode_ref { |
| 212 | __le16 name_len; |
| 213 | /* name goes here */ |
| 214 | } __attribute__ ((__packed__)); |
| 215 | |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 216 | struct btrfs_inode_timespec { |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 217 | __le64 sec; |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 218 | __le32 nsec; |
| 219 | } __attribute__ ((__packed__)); |
| 220 | |
| 221 | /* |
| 222 | * there is no padding here on purpose. If you want to extent the inode, |
| 223 | * make a new item type |
| 224 | */ |
| 225 | struct btrfs_inode_item { |
| 226 | __le64 generation; |
| 227 | __le64 size; |
| 228 | __le64 nblocks; |
Chris Mason | 31f3c99 | 2007-04-30 15:25:45 -0400 | [diff] [blame] | 229 | __le64 block_group; |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 230 | __le32 nlink; |
| 231 | __le32 uid; |
| 232 | __le32 gid; |
| 233 | __le32 mode; |
| 234 | __le32 rdev; |
| 235 | __le16 flags; |
| 236 | __le16 compat_flags; |
| 237 | struct btrfs_inode_timespec atime; |
| 238 | struct btrfs_inode_timespec ctime; |
| 239 | struct btrfs_inode_timespec mtime; |
| 240 | struct btrfs_inode_timespec otime; |
| 241 | } __attribute__ ((__packed__)); |
| 242 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 243 | struct btrfs_dir_item { |
Chris Mason | d6e4a42 | 2007-04-06 15:37:36 -0400 | [diff] [blame] | 244 | struct btrfs_disk_key location; |
Josef Bacik | 5103e94 | 2007-11-16 11:45:54 -0500 | [diff] [blame] | 245 | __le16 data_len; |
Chris Mason | a8a2ee0 | 2007-03-16 08:46:49 -0400 | [diff] [blame] | 246 | __le16 name_len; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 247 | u8 type; |
| 248 | } __attribute__ ((__packed__)); |
| 249 | |
| 250 | struct btrfs_root_item { |
Chris Mason | d6e4a42 | 2007-04-06 15:37:36 -0400 | [diff] [blame] | 251 | struct btrfs_inode_item inode; |
| 252 | __le64 root_dirid; |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 253 | __le64 bytenr; |
| 254 | __le64 byte_limit; |
| 255 | __le64 bytes_used; |
Chris Mason | 5eda7b5 | 2007-06-22 14:16:25 -0400 | [diff] [blame] | 256 | __le32 flags; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 257 | __le32 refs; |
Chris Mason | 5eda7b5 | 2007-06-22 14:16:25 -0400 | [diff] [blame] | 258 | struct btrfs_disk_key drop_progress; |
| 259 | u8 drop_level; |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 260 | u8 level; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 261 | } __attribute__ ((__packed__)); |
| 262 | |
Chris Mason | 236454d | 2007-04-19 13:37:44 -0400 | [diff] [blame] | 263 | #define BTRFS_FILE_EXTENT_REG 0 |
| 264 | #define BTRFS_FILE_EXTENT_INLINE 1 |
| 265 | |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 266 | struct btrfs_file_extent_item { |
Chris Mason | 71951f3 | 2007-03-27 09:16:29 -0400 | [diff] [blame] | 267 | __le64 generation; |
Chris Mason | 236454d | 2007-04-19 13:37:44 -0400 | [diff] [blame] | 268 | u8 type; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 269 | /* |
| 270 | * disk space consumed by the extent, checksum blocks are included |
| 271 | * in these numbers |
| 272 | */ |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 273 | __le64 disk_bytenr; |
| 274 | __le64 disk_num_bytes; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 275 | /* |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 276 | * the logical offset in file blocks (no csums) |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 277 | * this extent record is for. This allows a file extent to point |
| 278 | * into the middle of an existing extent on disk, sharing it |
| 279 | * between two snapshots (useful if some bytes in the middle of the |
| 280 | * extent have changed |
| 281 | */ |
| 282 | __le64 offset; |
| 283 | /* |
| 284 | * the logical number of file blocks (no csums included) |
| 285 | */ |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 286 | __le64 num_bytes; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 287 | } __attribute__ ((__packed__)); |
| 288 | |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 289 | struct btrfs_csum_item { |
Chris Mason | 509659c | 2007-05-10 12:36:17 -0400 | [diff] [blame] | 290 | u8 csum; |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 291 | } __attribute__ ((__packed__)); |
| 292 | |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 293 | /* tag for the radix tree of block groups in ram */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 294 | #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024) |
Chris Mason | 1e2677e | 2007-05-29 16:52:18 -0400 | [diff] [blame] | 295 | |
| 296 | |
| 297 | #define BTRFS_BLOCK_GROUP_DATA 1 |
Chris Mason | f84a8b3 | 2007-11-06 10:26:29 -0500 | [diff] [blame] | 298 | #define BTRFS_BLOCK_GROUP_MIXED 2 |
| 299 | |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 300 | struct btrfs_block_group_item { |
| 301 | __le64 used; |
Chris Mason | 1e2677e | 2007-05-29 16:52:18 -0400 | [diff] [blame] | 302 | u8 flags; |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 303 | } __attribute__ ((__packed__)); |
| 304 | |
| 305 | struct btrfs_block_group_cache { |
| 306 | struct btrfs_key key; |
| 307 | struct btrfs_block_group_item item; |
Chris Mason | be74417 | 2007-05-06 10:15:01 -0400 | [diff] [blame] | 308 | int data; |
Chris Mason | e37c9e6 | 2007-05-09 20:13:14 -0400 | [diff] [blame] | 309 | int cached; |
Yan | 324ae4d | 2007-11-16 14:57:08 -0500 | [diff] [blame] | 310 | u64 pinned; |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 311 | }; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 312 | struct btrfs_fs_info { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 313 | u8 fsid[BTRFS_FSID_SIZE]; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 314 | struct btrfs_root *extent_root; |
| 315 | struct btrfs_root *tree_root; |
Chris Mason | 0f7d52f | 2007-04-09 10:42:37 -0400 | [diff] [blame] | 316 | struct radix_tree_root fs_roots_radix; |
Chris Mason | 1a5bc16 | 2007-10-15 16:15:26 -0400 | [diff] [blame] | 317 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 318 | struct extent_io_tree free_space_cache; |
| 319 | struct extent_io_tree block_group_cache; |
| 320 | struct extent_io_tree pinned_extents; |
| 321 | struct extent_io_tree pending_del; |
| 322 | struct extent_io_tree extent_ins; |
Chris Mason | 1a5bc16 | 2007-10-15 16:15:26 -0400 | [diff] [blame] | 323 | |
Chris Mason | 293ffd5 | 2007-03-20 15:57:25 -0400 | [diff] [blame] | 324 | u64 generation; |
Josef Bacik | 15ee9bc | 2007-08-10 16:22:09 -0400 | [diff] [blame] | 325 | u64 last_trans_committed; |
Chris Mason | b6cda9b | 2007-12-14 15:30:32 -0500 | [diff] [blame] | 326 | unsigned long mount_opt; |
Chris Mason | c59f895 | 2007-12-17 20:14:04 -0500 | [diff] [blame] | 327 | u64 max_extent; |
Chris Mason | 6f568d3 | 2008-01-29 16:03:38 -0500 | [diff] [blame] | 328 | u64 max_inline; |
Chris Mason | 8f662a7 | 2008-01-02 10:01:11 -0500 | [diff] [blame] | 329 | u64 alloc_start; |
Chris Mason | 79154b1 | 2007-03-22 15:59:16 -0400 | [diff] [blame] | 330 | struct btrfs_transaction *running_transaction; |
Chris Mason | 4b52dff | 2007-06-26 10:06:50 -0400 | [diff] [blame] | 331 | struct btrfs_super_block super_copy; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 332 | struct extent_buffer *sb_buffer; |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 333 | struct super_block *sb; |
Chris Mason | d98237b | 2007-03-28 13:57:48 -0400 | [diff] [blame] | 334 | struct inode *btree_inode; |
Chris Mason | 19c00dd | 2007-10-15 16:19:22 -0400 | [diff] [blame] | 335 | spinlock_t hash_lock; |
Chris Mason | 79154b1 | 2007-03-22 15:59:16 -0400 | [diff] [blame] | 336 | struct mutex trans_mutex; |
Chris Mason | d561c02 | 2007-03-23 19:47:49 -0400 | [diff] [blame] | 337 | struct mutex fs_mutex; |
Chris Mason | 8fd1779 | 2007-04-19 21:01:03 -0400 | [diff] [blame] | 338 | struct list_head trans_list; |
Chris Mason | 19c00dd | 2007-10-15 16:19:22 -0400 | [diff] [blame] | 339 | struct list_head hashers; |
Chris Mason | facda1e | 2007-06-08 18:11:48 -0400 | [diff] [blame] | 340 | struct list_head dead_roots; |
Chris Mason | 6da6aba | 2007-12-18 16:15:09 -0500 | [diff] [blame] | 341 | #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18) |
| 342 | struct work_struct trans_work; |
| 343 | #else |
Chris Mason | 08607c1 | 2007-06-08 15:33:54 -0400 | [diff] [blame] | 344 | struct delayed_work trans_work; |
Chris Mason | 6da6aba | 2007-12-18 16:15:09 -0500 | [diff] [blame] | 345 | #endif |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 346 | struct kobject super_kobj; |
| 347 | struct completion kobj_unregister; |
Chris Mason | e66f709 | 2007-04-20 13:16:02 -0400 | [diff] [blame] | 348 | int do_barriers; |
Chris Mason | facda1e | 2007-06-08 18:11:48 -0400 | [diff] [blame] | 349 | int closing; |
Chris Mason | e2008b6 | 2008-01-08 15:46:30 -0500 | [diff] [blame] | 350 | unsigned long throttles; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 351 | |
Yan | 324ae4d | 2007-11-16 14:57:08 -0500 | [diff] [blame] | 352 | u64 total_pinned; |
Chris Mason | 1832a6d | 2007-12-21 16:27:21 -0500 | [diff] [blame] | 353 | spinlock_t delalloc_lock; |
Chris Mason | cee36a0 | 2008-01-15 08:40:48 -0500 | [diff] [blame] | 354 | spinlock_t new_trans_lock; |
Chris Mason | 1832a6d | 2007-12-21 16:27:21 -0500 | [diff] [blame] | 355 | u64 delalloc_bytes; |
Chris Mason | e18e480 | 2008-01-18 10:54:22 -0500 | [diff] [blame] | 356 | u64 last_alloc; |
Chris Mason | 4529ba4 | 2008-01-31 16:45:07 -0500 | [diff] [blame] | 357 | u64 last_data_alloc; |
Yan | 324ae4d | 2007-11-16 14:57:08 -0500 | [diff] [blame] | 358 | }; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 359 | /* |
| 360 | * 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] | 361 | * and for the extent tree extent_root root. |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 362 | */ |
| 363 | struct btrfs_root { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 364 | struct extent_buffer *node; |
| 365 | struct extent_buffer *commit_root; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 366 | struct btrfs_root_item root_item; |
| 367 | struct btrfs_key root_key; |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 368 | struct btrfs_fs_info *fs_info; |
Chris Mason | 0f7d52f | 2007-04-09 10:42:37 -0400 | [diff] [blame] | 369 | struct inode *inode; |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 370 | struct kobject root_kobj; |
| 371 | struct completion kobj_unregister; |
Chris Mason | 0f7d52f | 2007-04-09 10:42:37 -0400 | [diff] [blame] | 372 | u64 objectid; |
| 373 | u64 last_trans; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 374 | |
| 375 | /* data allocations are done in sectorsize units */ |
| 376 | u32 sectorsize; |
| 377 | |
| 378 | /* node allocations are done in nodesize units */ |
| 379 | u32 nodesize; |
| 380 | |
| 381 | /* leaf allocations are done in leafsize units */ |
| 382 | u32 leafsize; |
| 383 | |
Chris Mason | 87ee04e | 2007-11-30 11:30:34 -0500 | [diff] [blame] | 384 | u32 stripesize; |
| 385 | |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 386 | u32 type; |
Chris Mason | 1b05da2 | 2007-04-10 12:13:09 -0400 | [diff] [blame] | 387 | u64 highest_inode; |
| 388 | u64 last_inode_alloc; |
Chris Mason | 9f3a742 | 2007-08-07 15:52:19 -0400 | [diff] [blame] | 389 | int ref_cows; |
Chris Mason | 6702ed4 | 2007-08-07 16:15:09 -0400 | [diff] [blame] | 390 | struct btrfs_key defrag_progress; |
| 391 | int defrag_running; |
| 392 | int defrag_level; |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 393 | char *name; |
Chris Mason | 4313b39 | 2008-01-03 09:08:48 -0500 | [diff] [blame] | 394 | int in_sysfs; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 395 | }; |
| 396 | |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 397 | /* |
| 398 | * inode items have the data typically returned from stat and store other |
| 399 | * info about object characteristics. There is one for every file and dir in |
| 400 | * the FS |
| 401 | */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 402 | #define BTRFS_INODE_ITEM_KEY 1 |
Chris Mason | 3954401 | 2007-12-12 14:38:19 -0500 | [diff] [blame] | 403 | #define BTRFS_INODE_REF_KEY 2 |
| 404 | #define BTRFS_XATTR_ITEM_KEY 8 |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 405 | /* reserve 2-15 close to the inode for later flexibility */ |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 406 | |
| 407 | /* |
| 408 | * dir items are the name -> inode pointers in a directory. There is one |
| 409 | * for every name in a directory. |
| 410 | */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 411 | #define BTRFS_DIR_ITEM_KEY 16 |
| 412 | #define BTRFS_DIR_INDEX_KEY 17 |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 413 | /* |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 414 | * extent data is for file data |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 415 | */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 416 | #define BTRFS_EXTENT_DATA_KEY 18 |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 417 | /* |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 418 | * csum items have the checksums for data in the extents |
| 419 | */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 420 | #define BTRFS_CSUM_ITEM_KEY 19 |
| 421 | |
| 422 | /* reserve 20-31 for other file stuff */ |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 423 | |
| 424 | /* |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 425 | * root items point to tree roots. There are typically in the root |
| 426 | * tree used by the super block to find all the other trees |
| 427 | */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 428 | #define BTRFS_ROOT_ITEM_KEY 32 |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 429 | /* |
| 430 | * extent items are in the extent map tree. These record which blocks |
| 431 | * are used, and how many references there are to each block |
| 432 | */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 433 | #define BTRFS_EXTENT_ITEM_KEY 33 |
Chris Mason | 74493f7 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 434 | #define BTRFS_EXTENT_REF_KEY 34 |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 435 | |
| 436 | /* |
| 437 | * block groups give us hints into the extent allocation trees. Which |
| 438 | * blocks are free etc etc |
| 439 | */ |
Chris Mason | 74493f7 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 440 | #define BTRFS_BLOCK_GROUP_ITEM_KEY 50 |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 441 | |
| 442 | /* |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 443 | * string items are for debugging. They just store a short string of |
| 444 | * data in the FS |
| 445 | */ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 446 | #define BTRFS_STRING_ITEM_KEY 253 |
| 447 | |
Chris Mason | 21ad10c | 2008-01-09 09:23:21 -0500 | [diff] [blame] | 448 | #define BTRFS_MOUNT_NODATASUM (1 << 0) |
| 449 | #define BTRFS_MOUNT_NODATACOW (1 << 1) |
| 450 | #define BTRFS_MOUNT_NOBARRIER (1 << 2) |
Chris Mason | e18e480 | 2008-01-18 10:54:22 -0500 | [diff] [blame] | 451 | #define BTRFS_MOUNT_SSD (1 << 3) |
Chris Mason | b6cda9b | 2007-12-14 15:30:32 -0500 | [diff] [blame] | 452 | |
| 453 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) |
| 454 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) |
| 455 | #define btrfs_test_opt(root, opt) ((root)->fs_info->mount_opt & \ |
| 456 | BTRFS_MOUNT_##opt) |
Yan | b98b676 | 2008-01-08 15:54:37 -0500 | [diff] [blame] | 457 | /* |
| 458 | * Inode flags |
| 459 | */ |
Yan | fdebe2b | 2008-01-14 13:26:08 -0500 | [diff] [blame] | 460 | #define BTRFS_INODE_NODATASUM (1 << 0) |
| 461 | #define BTRFS_INODE_NODATACOW (1 << 1) |
| 462 | #define BTRFS_INODE_READONLY (1 << 2) |
Yan | b98b676 | 2008-01-08 15:54:37 -0500 | [diff] [blame] | 463 | #define btrfs_clear_flag(inode, flag) (BTRFS_I(inode)->flags &= \ |
| 464 | ~BTRFS_INODE_##flag) |
| 465 | #define btrfs_set_flag(inode, flag) (BTRFS_I(inode)->flags |= \ |
| 466 | BTRFS_INODE_##flag) |
| 467 | #define btrfs_test_flag(inode, flag) (BTRFS_I(inode)->flags & \ |
| 468 | BTRFS_INODE_##flag) |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 469 | /* some macros to generate set/get funcs for the struct fields. This |
| 470 | * assumes there is a lefoo_to_cpu for every type, so lets make a simple |
| 471 | * one for u8: |
| 472 | */ |
| 473 | #define le8_to_cpu(v) (v) |
| 474 | #define cpu_to_le8(v) (v) |
| 475 | #define __le8 u8 |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 476 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 477 | #define read_eb_member(eb, ptr, type, member, result) ( \ |
| 478 | read_extent_buffer(eb, (char *)(result), \ |
| 479 | ((unsigned long)(ptr)) + \ |
| 480 | offsetof(type, member), \ |
| 481 | sizeof(((type *)0)->member))) |
| 482 | |
| 483 | #define write_eb_member(eb, ptr, type, member, result) ( \ |
| 484 | write_extent_buffer(eb, (char *)(result), \ |
| 485 | ((unsigned long)(ptr)) + \ |
| 486 | offsetof(type, member), \ |
| 487 | sizeof(((type *)0)->member))) |
| 488 | |
Chris Mason | 0f82731 | 2007-10-15 16:18:56 -0400 | [diff] [blame] | 489 | #ifndef BTRFS_SETGET_FUNCS |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 490 | #define BTRFS_SETGET_FUNCS(name, type, member, bits) \ |
Chris Mason | 0f82731 | 2007-10-15 16:18:56 -0400 | [diff] [blame] | 491 | u##bits btrfs_##name(struct extent_buffer *eb, type *s); \ |
| 492 | void btrfs_set_##name(struct extent_buffer *eb, type *s, u##bits val); |
| 493 | #endif |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 494 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 495 | #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \ |
| 496 | static inline u##bits btrfs_##name(struct extent_buffer *eb) \ |
| 497 | { \ |
Chris Mason | 810191f | 2007-10-15 16:18:55 -0400 | [diff] [blame] | 498 | char *kaddr = kmap_atomic(eb->first_page, KM_USER0); \ |
Chris Mason | 6d36dcd | 2007-10-15 16:14:37 -0400 | [diff] [blame] | 499 | unsigned long offset = offsetof(type, member); \ |
Chris Mason | 810191f | 2007-10-15 16:18:55 -0400 | [diff] [blame] | 500 | u##bits res; \ |
| 501 | __le##bits *tmp = (__le##bits *)(kaddr + offset); \ |
| 502 | res = le##bits##_to_cpu(*tmp); \ |
| 503 | kunmap_atomic(kaddr, KM_USER0); \ |
| 504 | return res; \ |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 505 | } \ |
| 506 | static inline void btrfs_set_##name(struct extent_buffer *eb, \ |
| 507 | u##bits val) \ |
| 508 | { \ |
Chris Mason | 810191f | 2007-10-15 16:18:55 -0400 | [diff] [blame] | 509 | char *kaddr = kmap_atomic(eb->first_page, KM_USER0); \ |
Chris Mason | 6d36dcd | 2007-10-15 16:14:37 -0400 | [diff] [blame] | 510 | unsigned long offset = offsetof(type, member); \ |
Chris Mason | 810191f | 2007-10-15 16:18:55 -0400 | [diff] [blame] | 511 | __le##bits *tmp = (__le##bits *)(kaddr + offset); \ |
| 512 | *tmp = cpu_to_le##bits(val); \ |
| 513 | kunmap_atomic(kaddr, KM_USER0); \ |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 514 | } |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 515 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 516 | #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \ |
| 517 | static inline u##bits btrfs_##name(type *s) \ |
| 518 | { \ |
| 519 | return le##bits##_to_cpu(s->member); \ |
| 520 | } \ |
| 521 | static inline void btrfs_set_##name(type *s, u##bits val) \ |
| 522 | { \ |
| 523 | s->member = cpu_to_le##bits(val); \ |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 524 | } |
| 525 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 526 | /* struct btrfs_block_group_item */ |
| 527 | BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item, |
| 528 | used, 64); |
| 529 | BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item, |
| 530 | used, 64); |
Chris Mason | edbd8d4 | 2007-12-21 16:27:24 -0500 | [diff] [blame] | 531 | BTRFS_SETGET_FUNCS(disk_block_group_flags, struct btrfs_block_group_item, |
| 532 | flags, 8); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 533 | |
Chris Mason | 3954401 | 2007-12-12 14:38:19 -0500 | [diff] [blame] | 534 | /* struct btrfs_inode_ref */ |
| 535 | BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16); |
| 536 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 537 | /* struct btrfs_inode_item */ |
| 538 | BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64); |
| 539 | BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64); |
| 540 | BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64); |
| 541 | BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64); |
| 542 | BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32); |
| 543 | BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32); |
| 544 | BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32); |
| 545 | BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32); |
| 546 | BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 32); |
| 547 | BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16); |
| 548 | BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item, |
| 549 | compat_flags, 16); |
| 550 | |
| 551 | static inline struct btrfs_inode_timespec * |
| 552 | btrfs_inode_atime(struct btrfs_inode_item *inode_item) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 553 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 554 | unsigned long ptr = (unsigned long)inode_item; |
| 555 | ptr += offsetof(struct btrfs_inode_item, atime); |
| 556 | return (struct btrfs_inode_timespec *)ptr; |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 557 | } |
| 558 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 559 | static inline struct btrfs_inode_timespec * |
| 560 | btrfs_inode_mtime(struct btrfs_inode_item *inode_item) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 561 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 562 | unsigned long ptr = (unsigned long)inode_item; |
| 563 | ptr += offsetof(struct btrfs_inode_item, mtime); |
| 564 | return (struct btrfs_inode_timespec *)ptr; |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 565 | } |
| 566 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 567 | static inline struct btrfs_inode_timespec * |
| 568 | btrfs_inode_ctime(struct btrfs_inode_item *inode_item) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 569 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 570 | unsigned long ptr = (unsigned long)inode_item; |
| 571 | ptr += offsetof(struct btrfs_inode_item, ctime); |
| 572 | return (struct btrfs_inode_timespec *)ptr; |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 573 | } |
| 574 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 575 | static inline struct btrfs_inode_timespec * |
| 576 | btrfs_inode_otime(struct btrfs_inode_item *inode_item) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 577 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 578 | unsigned long ptr = (unsigned long)inode_item; |
| 579 | ptr += offsetof(struct btrfs_inode_item, otime); |
| 580 | return (struct btrfs_inode_timespec *)ptr; |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 581 | } |
| 582 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 583 | BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_inode_timespec, sec, 64); |
| 584 | BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_inode_timespec, nsec, 32); |
| 585 | |
| 586 | /* struct btrfs_extent_item */ |
| 587 | BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32); |
Chris Mason | 74493f7 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 588 | |
| 589 | /* struct btrfs_extent_ref */ |
| 590 | BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64); |
| 591 | BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64); |
| 592 | BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64); |
| 593 | BTRFS_SETGET_FUNCS(ref_offset, struct btrfs_extent_ref, offset, 64); |
| 594 | |
Chris Mason | 7bb8631 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 595 | BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64); |
| 596 | BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref, |
Chris Mason | 74493f7 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 597 | generation, 64); |
Chris Mason | 7bb8631 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 598 | BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref, |
| 599 | objectid, 64); |
| 600 | BTRFS_SETGET_STACK_FUNCS(stack_ref_offset, struct btrfs_extent_ref, offset, 64); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 601 | |
| 602 | BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item, |
| 603 | refs, 32); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 604 | |
| 605 | /* struct btrfs_node */ |
| 606 | BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64); |
Chris Mason | 74493f7 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 607 | BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 608 | |
| 609 | static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 610 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 611 | unsigned long ptr; |
| 612 | ptr = offsetof(struct btrfs_node, ptrs) + |
| 613 | sizeof(struct btrfs_key_ptr) * nr; |
| 614 | return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr); |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 615 | } |
| 616 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 617 | static inline void btrfs_set_node_blockptr(struct extent_buffer *eb, |
| 618 | int nr, u64 val) |
Chris Mason | 31f3c99 | 2007-04-30 15:25:45 -0400 | [diff] [blame] | 619 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 620 | unsigned long ptr; |
| 621 | ptr = offsetof(struct btrfs_node, ptrs) + |
| 622 | sizeof(struct btrfs_key_ptr) * nr; |
| 623 | btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val); |
Chris Mason | 31f3c99 | 2007-04-30 15:25:45 -0400 | [diff] [blame] | 624 | } |
| 625 | |
Chris Mason | 74493f7 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 626 | static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr) |
| 627 | { |
| 628 | unsigned long ptr; |
| 629 | ptr = offsetof(struct btrfs_node, ptrs) + |
| 630 | sizeof(struct btrfs_key_ptr) * nr; |
| 631 | return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr); |
| 632 | } |
| 633 | |
| 634 | static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb, |
| 635 | int nr, u64 val) |
| 636 | { |
| 637 | unsigned long ptr; |
| 638 | ptr = offsetof(struct btrfs_node, ptrs) + |
| 639 | sizeof(struct btrfs_key_ptr) * nr; |
| 640 | btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val); |
| 641 | } |
| 642 | |
Chris Mason | 810191f | 2007-10-15 16:18:55 -0400 | [diff] [blame] | 643 | static inline unsigned long btrfs_node_key_ptr_offset(int nr) |
Chris Mason | 31f3c99 | 2007-04-30 15:25:45 -0400 | [diff] [blame] | 644 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 645 | return offsetof(struct btrfs_node, ptrs) + |
| 646 | sizeof(struct btrfs_key_ptr) * nr; |
Chris Mason | 31f3c99 | 2007-04-30 15:25:45 -0400 | [diff] [blame] | 647 | } |
| 648 | |
Chris Mason | e644d02 | 2007-11-06 15:09:29 -0500 | [diff] [blame] | 649 | void btrfs_node_key(struct extent_buffer *eb, |
| 650 | struct btrfs_disk_key *disk_key, int nr); |
| 651 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 652 | static inline void btrfs_set_node_key(struct extent_buffer *eb, |
| 653 | struct btrfs_disk_key *disk_key, int nr) |
| 654 | { |
| 655 | unsigned long ptr; |
| 656 | ptr = btrfs_node_key_ptr_offset(nr); |
| 657 | write_eb_member(eb, (struct btrfs_key_ptr *)ptr, |
| 658 | struct btrfs_key_ptr, key, disk_key); |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 659 | } |
| 660 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 661 | /* struct btrfs_item */ |
| 662 | BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32); |
| 663 | BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32); |
| 664 | |
| 665 | static inline unsigned long btrfs_item_nr_offset(int nr) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 666 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 667 | return offsetof(struct btrfs_leaf, items) + |
| 668 | sizeof(struct btrfs_item) * nr; |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 669 | } |
| 670 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 671 | static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb, |
| 672 | int nr) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 673 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 674 | return (struct btrfs_item *)btrfs_item_nr_offset(nr); |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 675 | } |
| 676 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 677 | static inline u32 btrfs_item_end(struct extent_buffer *eb, |
| 678 | struct btrfs_item *item) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 679 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 680 | return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item); |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 681 | } |
| 682 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 683 | static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 684 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 685 | return btrfs_item_end(eb, btrfs_item_nr(eb, nr)); |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 686 | } |
| 687 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 688 | static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 689 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 690 | return btrfs_item_offset(eb, btrfs_item_nr(eb, nr)); |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 691 | } |
| 692 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 693 | static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 694 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 695 | return btrfs_item_size(eb, btrfs_item_nr(eb, nr)); |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 696 | } |
| 697 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 698 | static inline void btrfs_item_key(struct extent_buffer *eb, |
| 699 | struct btrfs_disk_key *disk_key, int nr) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 700 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 701 | struct btrfs_item *item = btrfs_item_nr(eb, nr); |
| 702 | read_eb_member(eb, item, struct btrfs_item, key, disk_key); |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 703 | } |
| 704 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 705 | static inline void btrfs_set_item_key(struct extent_buffer *eb, |
| 706 | struct btrfs_disk_key *disk_key, int nr) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 707 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 708 | struct btrfs_item *item = btrfs_item_nr(eb, nr); |
| 709 | write_eb_member(eb, item, struct btrfs_item, key, disk_key); |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 710 | } |
| 711 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 712 | /* struct btrfs_dir_item */ |
Josef Bacik | 5103e94 | 2007-11-16 11:45:54 -0500 | [diff] [blame] | 713 | BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 714 | BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8); |
| 715 | BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16); |
| 716 | |
| 717 | static inline void btrfs_dir_item_key(struct extent_buffer *eb, |
| 718 | struct btrfs_dir_item *item, |
| 719 | struct btrfs_disk_key *key) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 720 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 721 | read_eb_member(eb, item, struct btrfs_dir_item, location, key); |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 722 | } |
| 723 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 724 | static inline void btrfs_set_dir_item_key(struct extent_buffer *eb, |
| 725 | struct btrfs_dir_item *item, |
| 726 | struct btrfs_disk_key *key) |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 727 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 728 | write_eb_member(eb, item, struct btrfs_dir_item, location, key); |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 729 | } |
| 730 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 731 | /* struct btrfs_disk_key */ |
| 732 | BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, |
| 733 | objectid, 64); |
| 734 | BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64); |
| 735 | BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8); |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 736 | |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 737 | static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, |
| 738 | struct btrfs_disk_key *disk) |
| 739 | { |
| 740 | cpu->offset = le64_to_cpu(disk->offset); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 741 | cpu->type = disk->type; |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 742 | cpu->objectid = le64_to_cpu(disk->objectid); |
| 743 | } |
| 744 | |
| 745 | static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, |
| 746 | struct btrfs_key *cpu) |
| 747 | { |
| 748 | disk->offset = cpu_to_le64(cpu->offset); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 749 | disk->type = cpu->type; |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 750 | disk->objectid = cpu_to_le64(cpu->objectid); |
| 751 | } |
| 752 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 753 | static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb, |
| 754 | struct btrfs_key *key, int nr) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 755 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 756 | struct btrfs_disk_key disk_key; |
| 757 | btrfs_node_key(eb, &disk_key, nr); |
| 758 | btrfs_disk_key_to_cpu(key, &disk_key); |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 759 | } |
| 760 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 761 | static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb, |
| 762 | struct btrfs_key *key, int nr) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 763 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 764 | struct btrfs_disk_key disk_key; |
| 765 | btrfs_item_key(eb, &disk_key, nr); |
| 766 | btrfs_disk_key_to_cpu(key, &disk_key); |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 767 | } |
| 768 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 769 | static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb, |
| 770 | struct btrfs_dir_item *item, |
| 771 | struct btrfs_key *key) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 772 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 773 | struct btrfs_disk_key disk_key; |
| 774 | btrfs_dir_item_key(eb, item, &disk_key); |
| 775 | btrfs_disk_key_to_cpu(key, &disk_key); |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 776 | } |
| 777 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 778 | |
| 779 | static inline u8 btrfs_key_type(struct btrfs_key *key) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 780 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 781 | return key->type; |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 782 | } |
| 783 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 784 | static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 785 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 786 | key->type = val; |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 787 | } |
| 788 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 789 | /* struct btrfs_header */ |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 790 | BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 791 | BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header, |
| 792 | generation, 64); |
| 793 | BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64); |
| 794 | BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32); |
| 795 | BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 16); |
| 796 | BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8); |
| 797 | |
| 798 | static inline u8 *btrfs_header_fsid(struct extent_buffer *eb) |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 799 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 800 | unsigned long ptr = offsetof(struct btrfs_header, fsid); |
| 801 | return (u8 *)ptr; |
Chris Mason | e2fa722 | 2007-03-12 16:22:34 -0400 | [diff] [blame] | 802 | } |
| 803 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 804 | static inline u8 *btrfs_super_fsid(struct extent_buffer *eb) |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 805 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 806 | unsigned long ptr = offsetof(struct btrfs_super_block, fsid); |
| 807 | return (u8 *)ptr; |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 808 | } |
| 809 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 810 | static inline u8 *btrfs_header_csum(struct extent_buffer *eb) |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 811 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 812 | unsigned long ptr = offsetof(struct btrfs_header, csum); |
| 813 | return (u8 *)ptr; |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 814 | } |
| 815 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 816 | static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb) |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 817 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 818 | return NULL; |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 819 | } |
| 820 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 821 | static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb) |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 822 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 823 | return NULL; |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 824 | } |
| 825 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 826 | static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 827 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 828 | return NULL; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 829 | } |
| 830 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 831 | static inline int btrfs_is_leaf(struct extent_buffer *eb) |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 832 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 833 | return (btrfs_header_level(eb) == 0); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 834 | } |
| 835 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 836 | /* struct btrfs_root_item */ |
| 837 | BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32); |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 838 | BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64); |
| 839 | BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 840 | |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 841 | BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64); |
| 842 | BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 843 | BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64); |
| 844 | BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32); |
| 845 | BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32); |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 846 | BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64); |
| 847 | BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 848 | |
| 849 | /* struct btrfs_super_block */ |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 850 | BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 851 | BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block, |
| 852 | generation, 64); |
| 853 | BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64); |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 854 | BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block, |
| 855 | root_level, 8); |
| 856 | BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block, |
| 857 | total_bytes, 64); |
| 858 | BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block, |
| 859 | bytes_used, 64); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 860 | BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block, |
| 861 | sectorsize, 32); |
| 862 | BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block, |
| 863 | nodesize, 32); |
| 864 | BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block, |
| 865 | leafsize, 32); |
Chris Mason | 87ee04e | 2007-11-30 11:30:34 -0500 | [diff] [blame] | 866 | BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block, |
| 867 | stripesize, 32); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 868 | BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block, |
| 869 | root_dir_objectid, 64); |
| 870 | |
| 871 | static inline unsigned long btrfs_leaf_data(struct extent_buffer *l) |
Chris Mason | 7f5c151 | 2007-03-23 15:56:19 -0400 | [diff] [blame] | 872 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 873 | return offsetof(struct btrfs_leaf, items); |
Chris Mason | 7f5c151 | 2007-03-23 15:56:19 -0400 | [diff] [blame] | 874 | } |
| 875 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 876 | /* struct btrfs_file_extent_item */ |
| 877 | BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); |
Chris Mason | 7f5c151 | 2007-03-23 15:56:19 -0400 | [diff] [blame] | 878 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 879 | static inline unsigned long btrfs_file_extent_inline_start(struct |
Chris Mason | 236454d | 2007-04-19 13:37:44 -0400 | [diff] [blame] | 880 | btrfs_file_extent_item *e) |
| 881 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 882 | unsigned long offset = (unsigned long)e; |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 883 | offset += offsetof(struct btrfs_file_extent_item, disk_bytenr); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 884 | return offset; |
Chris Mason | 236454d | 2007-04-19 13:37:44 -0400 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize) |
| 888 | { |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 889 | return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize; |
Chris Mason | 236454d | 2007-04-19 13:37:44 -0400 | [diff] [blame] | 890 | } |
| 891 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 892 | static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb, |
| 893 | struct btrfs_item *e) |
Chris Mason | 236454d | 2007-04-19 13:37:44 -0400 | [diff] [blame] | 894 | { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 895 | unsigned long offset; |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 896 | offset = offsetof(struct btrfs_file_extent_item, disk_bytenr); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 897 | return btrfs_item_size(eb, e) - offset; |
Chris Mason | 236454d | 2007-04-19 13:37:44 -0400 | [diff] [blame] | 898 | } |
| 899 | |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 900 | BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item, |
| 901 | disk_bytenr, 64); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 902 | BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item, |
| 903 | generation, 64); |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 904 | BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item, |
| 905 | disk_num_bytes, 64); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 906 | BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item, |
| 907 | offset, 64); |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 908 | BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item, |
| 909 | num_bytes, 64); |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 910 | |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 911 | static inline struct btrfs_root *btrfs_sb(struct super_block *sb) |
| 912 | { |
| 913 | return sb->s_fs_info; |
| 914 | } |
| 915 | |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 916 | static inline int btrfs_set_root_name(struct btrfs_root *root, |
| 917 | const char *name, int len) |
| 918 | { |
| 919 | /* if we already have a name just free it */ |
| 920 | if (root->name) |
| 921 | kfree(root->name); |
| 922 | |
| 923 | root->name = kmalloc(len+1, GFP_KERNEL); |
| 924 | if (!root->name) |
| 925 | return -ENOMEM; |
| 926 | |
| 927 | memcpy(root->name, name, len); |
| 928 | root->name[len] ='\0'; |
| 929 | |
| 930 | return 0; |
| 931 | } |
| 932 | |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 933 | static inline u32 btrfs_level_size(struct btrfs_root *root, int level) { |
| 934 | if (level == 0) |
| 935 | return root->leafsize; |
| 936 | return root->nodesize; |
| 937 | } |
| 938 | |
Chris Mason | 4beb1b8 | 2007-03-14 10:31:29 -0400 | [diff] [blame] | 939 | /* helper function to cast into the data area of the leaf. */ |
| 940 | #define btrfs_item_ptr(leaf, slot, type) \ |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 941 | ((type *)(btrfs_leaf_data(leaf) + \ |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 942 | btrfs_item_offset_nr(leaf, slot))) |
| 943 | |
| 944 | #define btrfs_item_ptr_offset(leaf, slot) \ |
| 945 | ((unsigned long)(btrfs_leaf_data(leaf) + \ |
| 946 | btrfs_item_offset_nr(leaf, slot))) |
Chris Mason | 4beb1b8 | 2007-03-14 10:31:29 -0400 | [diff] [blame] | 947 | |
Chris Mason | 6da6aba | 2007-12-18 16:15:09 -0500 | [diff] [blame] | 948 | static inline struct dentry *fdentry(struct file *file) { |
| 949 | #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18) |
| 950 | return file->f_dentry; |
| 951 | #else |
| 952 | return file->f_path.dentry; |
| 953 | #endif |
| 954 | } |
| 955 | |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 956 | /* extent-tree.c */ |
Chris Mason | be20aa9 | 2007-12-17 20:14:01 -0500 | [diff] [blame] | 957 | u32 btrfs_count_snapshots_in_path(struct btrfs_root *root, |
| 958 | struct btrfs_path *count_path, |
| 959 | u64 first_extent); |
Chris Mason | e9d0b13 | 2007-08-10 14:06:19 -0400 | [diff] [blame] | 960 | int btrfs_extent_post_op(struct btrfs_trans_handle *trans, |
| 961 | struct btrfs_root *root); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 962 | int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy); |
Chris Mason | 5276aed | 2007-06-11 21:33:38 -0400 | [diff] [blame] | 963 | struct btrfs_block_group_cache *btrfs_lookup_block_group(struct |
| 964 | btrfs_fs_info *info, |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 965 | u64 bytenr); |
Chris Mason | 31f3c99 | 2007-04-30 15:25:45 -0400 | [diff] [blame] | 966 | struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root, |
| 967 | struct btrfs_block_group_cache |
Chris Mason | be74417 | 2007-05-06 10:15:01 -0400 | [diff] [blame] | 968 | *hint, u64 search_start, |
Chris Mason | de428b6 | 2007-05-18 13:28:27 -0400 | [diff] [blame] | 969 | int data, int owner); |
Chris Mason | c5739bb | 2007-04-10 09:27:04 -0400 | [diff] [blame] | 970 | int btrfs_inc_root_ref(struct btrfs_trans_handle *trans, |
Chris Mason | 7bb8631 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 971 | struct btrfs_root *root, u64 owner_objectid); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 972 | struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 973 | struct btrfs_root *root, u32 size, |
Chris Mason | 7bb8631 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 974 | u64 root_objectid, |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 975 | u64 hint, u64 empty_size); |
Chris Mason | 7bb8631 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 976 | struct extent_buffer *__btrfs_alloc_free_block(struct btrfs_trans_handle *trans, |
| 977 | struct btrfs_root *root, |
| 978 | u32 blocksize, |
| 979 | u64 root_objectid, |
| 980 | u64 ref_generation, |
| 981 | u64 first_objectid, |
| 982 | int level, |
| 983 | u64 hint, |
| 984 | u64 empty_size); |
Chris Mason | edbd8d4 | 2007-12-21 16:27:24 -0500 | [diff] [blame] | 985 | int btrfs_grow_extent_tree(struct btrfs_trans_handle *trans, |
| 986 | struct btrfs_root *root, u64 new_size); |
| 987 | int btrfs_shrink_extent_tree(struct btrfs_root *root, u64 new_size); |
Chris Mason | 7bb8631 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 988 | int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans, |
| 989 | struct btrfs_root *root, |
| 990 | struct btrfs_path *path, u64 bytenr, |
| 991 | u64 root_objectid, u64 ref_generation, |
| 992 | u64 owner, u64 owner_offset); |
Chris Mason | 4d77567 | 2007-04-20 20:23:12 -0400 | [diff] [blame] | 993 | int btrfs_alloc_extent(struct btrfs_trans_handle *trans, |
Chris Mason | 7bb8631 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 994 | struct btrfs_root *root, |
| 995 | u64 num_bytes, u64 root_objectid, u64 ref_generation, |
| 996 | u64 owner, u64 owner_offset, |
| 997 | u64 empty_size, u64 hint_byte, |
Chris Mason | be08c1b | 2007-05-03 09:06:49 -0400 | [diff] [blame] | 998 | u64 search_end, struct btrfs_key *ins, int data); |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 999 | int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 1000 | struct extent_buffer *buf); |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 1001 | int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root |
Chris Mason | 7bb8631 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 1002 | *root, u64 bytenr, u64 num_bytes, |
| 1003 | u64 root_objectid, u64 ref_generation, |
| 1004 | u64 owner_objectid, u64 owner_offset, int pin); |
Chris Mason | ccd467d | 2007-06-28 15:57:36 -0400 | [diff] [blame] | 1005 | int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, |
| 1006 | struct btrfs_root *root, |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 1007 | struct extent_io_tree *unpin); |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 1008 | int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, |
| 1009 | struct btrfs_root *root, |
Chris Mason | 7bb8631 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 1010 | u64 bytenr, u64 num_bytes, |
| 1011 | u64 root_objectid, u64 ref_generation, |
| 1012 | u64 owner, u64 owner_offset); |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 1013 | int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, |
| 1014 | struct btrfs_root *root); |
| 1015 | int btrfs_free_block_groups(struct btrfs_fs_info *info); |
| 1016 | int btrfs_read_block_groups(struct btrfs_root *root); |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1017 | /* ctree.c */ |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 1018 | int btrfs_cow_block(struct btrfs_trans_handle *trans, |
| 1019 | struct btrfs_root *root, struct extent_buffer *buf, |
| 1020 | struct extent_buffer *parent, int parent_slot, |
| 1021 | struct extent_buffer **cow_ret); |
Chris Mason | be20aa9 | 2007-12-17 20:14:01 -0500 | [diff] [blame] | 1022 | int btrfs_copy_root(struct btrfs_trans_handle *trans, |
| 1023 | struct btrfs_root *root, |
| 1024 | struct extent_buffer *buf, |
| 1025 | struct extent_buffer **cow_ret, u64 new_root_objectid); |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 1026 | int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root |
| 1027 | *root, struct btrfs_path *path, u32 data_size); |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 1028 | int btrfs_truncate_item(struct btrfs_trans_handle *trans, |
| 1029 | struct btrfs_root *root, |
| 1030 | struct btrfs_path *path, |
Chris Mason | 179e29e | 2007-11-01 11:28:41 -0400 | [diff] [blame] | 1031 | u32 new_size, int from_end); |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 1032 | int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root |
| 1033 | *root, struct btrfs_key *key, struct btrfs_path *p, int |
| 1034 | ins_len, int cow); |
Chris Mason | 6702ed4 | 2007-08-07 16:15:09 -0400 | [diff] [blame] | 1035 | int btrfs_realloc_node(struct btrfs_trans_handle *trans, |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 1036 | struct btrfs_root *root, struct extent_buffer *parent, |
Chris Mason | a6b6e75 | 2007-10-15 16:22:39 -0400 | [diff] [blame] | 1037 | int start_slot, int cache_only, u64 *last_ret, |
| 1038 | struct btrfs_key *progress); |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 1039 | void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p); |
Chris Mason | 2c90e5d | 2007-04-02 10:50:19 -0400 | [diff] [blame] | 1040 | struct btrfs_path *btrfs_alloc_path(void); |
| 1041 | void btrfs_free_path(struct btrfs_path *p); |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 1042 | void btrfs_init_path(struct btrfs_path *p); |
Chris Mason | 85e21ba | 2008-01-29 15:11:36 -0500 | [diff] [blame] | 1043 | int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
| 1044 | struct btrfs_path *path, int slot, int nr); |
| 1045 | |
| 1046 | static inline int btrfs_del_item(struct btrfs_trans_handle *trans, |
| 1047 | struct btrfs_root *root, |
| 1048 | struct btrfs_path *path) |
| 1049 | { |
| 1050 | return btrfs_del_items(trans, root, path, path->slots[0], 1); |
| 1051 | } |
| 1052 | |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 1053 | int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root |
| 1054 | *root, struct btrfs_key *key, void *data, u32 data_size); |
Chris Mason | 9c58309 | 2008-01-29 15:15:18 -0500 | [diff] [blame] | 1055 | int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, |
| 1056 | struct btrfs_root *root, |
| 1057 | struct btrfs_path *path, |
| 1058 | struct btrfs_key *cpu_key, u32 *data_size, int nr); |
| 1059 | |
| 1060 | static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, |
| 1061 | struct btrfs_root *root, |
| 1062 | struct btrfs_path *path, |
| 1063 | struct btrfs_key *key, |
| 1064 | u32 data_size) |
| 1065 | { |
| 1066 | return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1); |
| 1067 | } |
| 1068 | |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 1069 | int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); |
Chris Mason | 7bb8631 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 1070 | int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 1071 | int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf); |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 1072 | int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root |
Chris Mason | 9f3a742 | 2007-08-07 15:52:19 -0400 | [diff] [blame] | 1073 | *root); |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1074 | /* root-item.c */ |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 1075 | int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
| 1076 | struct btrfs_key *key); |
| 1077 | int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root |
| 1078 | *root, struct btrfs_key *key, struct btrfs_root_item |
| 1079 | *item); |
| 1080 | int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root |
| 1081 | *root, struct btrfs_key *key, struct btrfs_root_item |
| 1082 | *item); |
| 1083 | int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct |
| 1084 | btrfs_root_item *item, struct btrfs_key *key); |
Chris Mason | 5ce14bb | 2007-09-11 11:15:39 -0400 | [diff] [blame] | 1085 | int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid, |
| 1086 | struct btrfs_root *latest_root); |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1087 | /* dir-item.c */ |
Chris Mason | e089f05 | 2007-03-16 16:20:31 -0400 | [diff] [blame] | 1088 | 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] | 1089 | *root, const char *name, int name_len, u64 dir, |
| 1090 | struct btrfs_key *location, u8 type); |
Chris Mason | 7e38180 | 2007-04-19 15:36:27 -0400 | [diff] [blame] | 1091 | struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, |
| 1092 | struct btrfs_root *root, |
| 1093 | struct btrfs_path *path, u64 dir, |
| 1094 | const char *name, int name_len, |
| 1095 | int mod); |
| 1096 | struct btrfs_dir_item * |
| 1097 | btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans, |
| 1098 | struct btrfs_root *root, |
| 1099 | struct btrfs_path *path, u64 dir, |
| 1100 | u64 objectid, const char *name, int name_len, |
| 1101 | int mod); |
| 1102 | struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root, |
| 1103 | struct btrfs_path *path, |
Chris Mason | 7f5c151 | 2007-03-23 15:56:19 -0400 | [diff] [blame] | 1104 | const char *name, int name_len); |
Chris Mason | 7e38180 | 2007-04-19 15:36:27 -0400 | [diff] [blame] | 1105 | int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans, |
| 1106 | struct btrfs_root *root, |
| 1107 | struct btrfs_path *path, |
| 1108 | struct btrfs_dir_item *di); |
Josef Bacik | 5103e94 | 2007-11-16 11:45:54 -0500 | [diff] [blame] | 1109 | int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, |
| 1110 | struct btrfs_root *root, const char *name, |
| 1111 | u16 name_len, const void *data, u16 data_len, |
| 1112 | u64 dir); |
| 1113 | struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans, |
| 1114 | struct btrfs_root *root, |
| 1115 | struct btrfs_path *path, u64 dir, |
| 1116 | const char *name, u16 name_len, |
| 1117 | int mod); |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1118 | /* inode-map.c */ |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 1119 | int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, |
| 1120 | struct btrfs_root *fs_root, |
| 1121 | u64 dirid, u64 *objectid); |
Chris Mason | 5be6f7f | 2007-04-05 13:35:25 -0400 | [diff] [blame] | 1122 | int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid); |
| 1123 | |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1124 | /* inode-item.c */ |
Chris Mason | 3954401 | 2007-12-12 14:38:19 -0500 | [diff] [blame] | 1125 | int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans, |
| 1126 | struct btrfs_root *root, |
| 1127 | const char *name, int name_len, |
| 1128 | u64 inode_objectid, u64 ref_objectid); |
| 1129 | int btrfs_del_inode_ref(struct btrfs_trans_handle *trans, |
| 1130 | struct btrfs_root *root, |
| 1131 | const char *name, int name_len, |
| 1132 | u64 inode_objectid, u64 ref_objectid); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 1133 | int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans, |
| 1134 | struct btrfs_root *root, |
| 1135 | struct btrfs_path *path, u64 objectid); |
Chris Mason | 293ffd5 | 2007-03-20 15:57:25 -0400 | [diff] [blame] | 1136 | int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root |
Chris Mason | d6e4a42 | 2007-04-06 15:37:36 -0400 | [diff] [blame] | 1137 | *root, struct btrfs_path *path, |
| 1138 | struct btrfs_key *location, int mod); |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1139 | |
| 1140 | /* file-item.c */ |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 1141 | int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1142 | struct btrfs_root *root, |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 1143 | u64 objectid, u64 pos, u64 offset, |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 1144 | u64 disk_num_bytes, |
| 1145 | u64 num_bytes); |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 1146 | int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, |
| 1147 | struct btrfs_root *root, |
| 1148 | struct btrfs_path *path, u64 objectid, |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 1149 | u64 bytenr, int mod); |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 1150 | int btrfs_csum_file_block(struct btrfs_trans_handle *trans, |
| 1151 | struct btrfs_root *root, |
Chris Mason | f578d4b | 2007-10-25 15:42:56 -0400 | [diff] [blame] | 1152 | struct inode *inode, |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 1153 | u64 objectid, u64 offset, |
| 1154 | char *data, size_t len); |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 1155 | struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, |
| 1156 | struct btrfs_root *root, |
| 1157 | struct btrfs_path *path, |
| 1158 | u64 objectid, u64 offset, |
| 1159 | int cow); |
Chris Mason | 1de037a | 2007-05-29 15:17:08 -0400 | [diff] [blame] | 1160 | int btrfs_csum_truncate(struct btrfs_trans_handle *trans, |
| 1161 | struct btrfs_root *root, struct btrfs_path *path, |
| 1162 | u64 isize); |
Chris Mason | 39279cc | 2007-06-12 06:35:45 -0400 | [diff] [blame] | 1163 | /* inode.c */ |
Chris Mason | 9069218 | 2008-02-08 13:49:28 -0500 | [diff] [blame^] | 1164 | static inline void dec_i_blocks(struct inode *inode, u64 dec) |
| 1165 | { |
| 1166 | dec = dec >> 9; |
| 1167 | if (dec <= inode->i_blocks) |
| 1168 | inode->i_blocks -= dec; |
| 1169 | else |
| 1170 | inode->i_blocks = 0; |
| 1171 | } |
| 1172 | |
Chris Mason | edbd8d4 | 2007-12-21 16:27:24 -0500 | [diff] [blame] | 1173 | unsigned long btrfs_force_ra(struct address_space *mapping, |
| 1174 | struct file_ra_state *ra, struct file *file, |
| 1175 | pgoff_t offset, pgoff_t last_index); |
Chris Mason | 1832a6d | 2007-12-21 16:27:21 -0500 | [diff] [blame] | 1176 | int btrfs_check_free_space(struct btrfs_root *root, u64 num_required, |
| 1177 | int for_del); |
Chris Mason | 9ebefb18 | 2007-06-15 13:50:00 -0400 | [diff] [blame] | 1178 | int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page); |
| 1179 | int btrfs_readpage(struct file *file, struct page *page); |
Chris Mason | 39279cc | 2007-06-12 06:35:45 -0400 | [diff] [blame] | 1180 | void btrfs_delete_inode(struct inode *inode); |
Chris Mason | 2da98f0 | 2008-01-16 11:44:43 -0500 | [diff] [blame] | 1181 | void btrfs_put_inode(struct inode *inode); |
Chris Mason | 39279cc | 2007-06-12 06:35:45 -0400 | [diff] [blame] | 1182 | void btrfs_read_locked_inode(struct inode *inode); |
| 1183 | int btrfs_write_inode(struct inode *inode, int wait); |
| 1184 | void btrfs_dirty_inode(struct inode *inode); |
| 1185 | struct inode *btrfs_alloc_inode(struct super_block *sb); |
| 1186 | void btrfs_destroy_inode(struct inode *inode); |
| 1187 | int btrfs_init_cachep(void); |
| 1188 | void btrfs_destroy_cachep(void); |
Christoph Hellwig | 34287aa | 2007-09-14 10:22:47 -0400 | [diff] [blame] | 1189 | long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
Chris Mason | 39279cc | 2007-06-12 06:35:45 -0400 | [diff] [blame] | 1190 | struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid, |
| 1191 | struct btrfs_root *root); |
Chris Mason | dc17ff8 | 2008-01-08 15:46:30 -0500 | [diff] [blame] | 1192 | struct inode *btrfs_ilookup(struct super_block *s, u64 objectid, |
| 1193 | u64 root_objectid); |
Chris Mason | 39279cc | 2007-06-12 06:35:45 -0400 | [diff] [blame] | 1194 | int btrfs_commit_write(struct file *file, struct page *page, |
| 1195 | unsigned from, unsigned to); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 1196 | struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page, |
| 1197 | size_t page_offset, u64 start, u64 end, |
| 1198 | int create); |
| 1199 | int btrfs_update_inode(struct btrfs_trans_handle *trans, |
| 1200 | struct btrfs_root *root, |
| 1201 | struct inode *inode); |
Chris Mason | 39279cc | 2007-06-12 06:35:45 -0400 | [diff] [blame] | 1202 | /* file.c */ |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 1203 | int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end); |
Chris Mason | 5f56406 | 2008-01-22 16:47:59 -0500 | [diff] [blame] | 1204 | int btrfs_check_file(struct btrfs_root *root, struct inode *inode); |
Chris Mason | 39279cc | 2007-06-12 06:35:45 -0400 | [diff] [blame] | 1205 | extern struct file_operations btrfs_file_operations; |
| 1206 | int btrfs_drop_extents(struct btrfs_trans_handle *trans, |
| 1207 | struct btrfs_root *root, struct inode *inode, |
Chris Mason | 00f5c79 | 2007-11-30 10:09:33 -0500 | [diff] [blame] | 1208 | u64 start, u64 end, u64 inline_limit, u64 *hint_block); |
Chris Mason | 6702ed4 | 2007-08-07 16:15:09 -0400 | [diff] [blame] | 1209 | /* tree-defrag.c */ |
| 1210 | int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, |
| 1211 | struct btrfs_root *root, int cache_only); |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 1212 | |
| 1213 | /* sysfs.c */ |
| 1214 | int btrfs_init_sysfs(void); |
| 1215 | void btrfs_exit_sysfs(void); |
| 1216 | int btrfs_sysfs_add_super(struct btrfs_fs_info *fs); |
| 1217 | int btrfs_sysfs_add_root(struct btrfs_root *root); |
| 1218 | void btrfs_sysfs_del_root(struct btrfs_root *root); |
| 1219 | void btrfs_sysfs_del_super(struct btrfs_fs_info *root); |
| 1220 | |
Josef Bacik | 5103e94 | 2007-11-16 11:45:54 -0500 | [diff] [blame] | 1221 | /* xattr.c */ |
| 1222 | ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size); |
| 1223 | int btrfs_delete_xattrs(struct btrfs_trans_handle *trans, |
| 1224 | struct btrfs_root *root, struct inode *inode); |
Chris Mason | edbd8d4 | 2007-12-21 16:27:24 -0500 | [diff] [blame] | 1225 | /* super.c */ |
| 1226 | u64 btrfs_parse_size(char *str); |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 1227 | #endif |