blob: 52144b04f1af100ee2ad2f927a38da18c6a21fe4 [file] [log] [blame]
Chris Mason6cbd5572007-06-12 09:07:21 -04001/*
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 Masondc17ff82008-01-08 15:46:30 -050019#ifndef __BTRFS_CTREE__
20#define __BTRFS_CTREE__
Chris Masoneb60cea2007-02-02 09:18:22 -050021
Chris Mason6da6aba2007-12-18 16:15:09 -050022#include <linux/version.h>
Chris Mason810191f2007-10-15 16:18:55 -040023#include <linux/mm.h>
24#include <linux/highmem.h>
Chris Masone20d96d2007-03-22 12:13:20 -040025#include <linux/fs.h>
Chris Mason08607c12007-06-08 15:33:54 -040026#include <linux/workqueue.h>
Josef Bacik58176a92007-08-29 15:47:34 -040027#include <linux/completion.h>
Chris Mason479965d2007-10-15 16:14:27 -040028#include <asm/kmap_types.h>
Chris Mason8ef97622007-03-26 10:15:30 -040029#include "bit-radix.h"
Chris Masond1310b22008-01-24 16:13:08 -050030#include "extent_io.h"
Chris Mason5f39d392007-10-15 16:14:19 -040031#include "extent_map.h"
Chris Masone20d96d2007-03-22 12:13:20 -040032
Chris Masone089f052007-03-16 16:20:31 -040033struct btrfs_trans_handle;
Chris Mason79154b12007-03-22 15:59:16 -040034struct btrfs_transaction;
Chris Mason35b7e472007-05-02 15:53:43 -040035extern struct kmem_cache *btrfs_trans_handle_cachep;
36extern struct kmem_cache *btrfs_transaction_cachep;
37extern struct kmem_cache *btrfs_bit_radix_cachep;
Chris Mason2c90e5d2007-04-02 10:50:19 -040038extern struct kmem_cache *btrfs_path_cachep;
Chris Masone089f052007-03-16 16:20:31 -040039
Chris Mason47b0c4f2008-02-04 10:10:43 -050040#define BTRFS_MAGIC "_B4RfS_M"
Chris Masoneb60cea2007-02-02 09:18:22 -050041
Chris Masonf6dbff52007-12-13 11:13:32 -050042#define BTRFS_MAX_LEVEL 8
Chris Mason6407bf62007-03-27 06:33:00 -040043#define BTRFS_ROOT_TREE_OBJECTID 1ULL
Chris Mason0cf6c622007-06-09 09:22:25 -040044#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
45#define BTRFS_FS_TREE_OBJECTID 3ULL
46#define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL
Chris Masonf6dbff52007-12-13 11:13:32 -050047#define BTRFS_FIRST_FREE_OBJECTID 256ULL
Chris Mason3768f362007-03-13 16:47:54 -040048
Chris Masonfec577f2007-02-26 10:40:21 -050049/*
Chris Masone20d96d2007-03-22 12:13:20 -040050 * 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 Masonf254e522007-03-29 15:15:27 -040055/* 32 bytes in various csum fields */
56#define BTRFS_CSUM_SIZE 32
Chris Mason509659c2007-05-10 12:36:17 -040057/* four bytes for CRC32 */
58#define BTRFS_CRC32_SIZE 4
Chris Mason39544012007-12-12 14:38:19 -050059#define BTRFS_EMPTY_DIR_SIZE 0
Chris Masonf254e522007-03-29 15:15:27 -040060
Chris Masonfabb5682007-06-07 22:13:21 -040061#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 Bacik5103e942007-11-16 11:45:54 -050069#define BTRFS_FT_XATTR 8
70#define BTRFS_FT_MAX 9
Chris Masonfabb5682007-06-07 22:13:21 -040071
Chris Masone20d96d2007-03-22 12:13:20 -040072/*
Chris Masonfec577f2007-02-26 10:40:21 -050073 * 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 Masone2fa7222007-03-12 16:22:34 -040081 *
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 Masonfec577f2007-02-26 10:40:21 -050085 */
Chris Masone2fa7222007-03-12 16:22:34 -040086struct btrfs_disk_key {
87 __le64 objectid;
Chris Mason5f39d392007-10-15 16:14:19 -040088 u8 type;
Chris Mason70b2bef2007-04-17 15:39:32 -040089 __le64 offset;
Chris Masone2fa7222007-03-12 16:22:34 -040090} __attribute__ ((__packed__));
91
92struct btrfs_key {
Chris Masoneb60cea2007-02-02 09:18:22 -050093 u64 objectid;
Chris Mason5f39d392007-10-15 16:14:19 -040094 u8 type;
Chris Mason70b2bef2007-04-17 15:39:32 -040095 u64 offset;
Chris Masoneb60cea2007-02-02 09:18:22 -050096} __attribute__ ((__packed__));
97
Chris Mason5f39d392007-10-15 16:14:19 -040098#define BTRFS_FSID_SIZE 16
Chris Masonfec577f2007-02-26 10:40:21 -050099/*
100 * every tree block (leaf or node) starts with this header.
101 */
Chris Masonbb492bb2007-03-12 12:29:44 -0400102struct btrfs_header {
Chris Masonf254e522007-03-29 15:15:27 -0400103 u8 csum[BTRFS_CSUM_SIZE];
Chris Mason5f39d392007-10-15 16:14:19 -0400104 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
Chris Masondb945352007-10-15 16:15:53 -0400105 __le64 bytenr; /* which block this node is supposed to live in */
Chris Mason7f5c1512007-03-23 15:56:19 -0400106 __le64 generation;
Chris Mason4d775672007-04-20 20:23:12 -0400107 __le64 owner;
Chris Mason5f39d392007-10-15 16:14:19 -0400108 __le32 nritems;
Chris Masonbb492bb2007-03-12 12:29:44 -0400109 __le16 flags;
Chris Mason9a6f11e2007-03-27 09:06:38 -0400110 u8 level;
Chris Masoneb60cea2007-02-02 09:18:22 -0500111} __attribute__ ((__packed__));
112
Chris Mason5f39d392007-10-15 16:14:19 -0400113#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
Chris Mason123abc82007-03-14 14:14:43 -0400114 sizeof(struct btrfs_header)) / \
Chris Mason74493f72007-12-11 09:25:06 -0500115 sizeof(struct btrfs_key_ptr))
Chris Mason123abc82007-03-14 14:14:43 -0400116#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
Chris Mason5f39d392007-10-15 16:14:19 -0400117#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
Chris Mason236454d2007-04-19 13:37:44 -0400118#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 Masoneb60cea2007-02-02 09:18:22 -0500121
Chris Masonfec577f2007-02-26 10:40:21 -0500122/*
Chris Masonfec577f2007-02-26 10:40:21 -0500123 * the super block basically lists the main trees of the FS
124 * it currently lacks any block count etc etc
125 */
Chris Mason234b63a2007-03-13 10:46:10 -0400126struct btrfs_super_block {
Chris Masonf254e522007-03-29 15:15:27 -0400127 u8 csum[BTRFS_CSUM_SIZE];
Chris Mason87cbda52007-03-28 19:44:27 -0400128 /* the first 3 fields must match struct btrfs_header */
Chris Mason3768f362007-03-13 16:47:54 -0400129 u8 fsid[16]; /* FS specific uuid */
Chris Masondb945352007-10-15 16:15:53 -0400130 __le64 bytenr; /* this block number */
Chris Mason3768f362007-03-13 16:47:54 -0400131 __le64 magic;
Chris Mason3768f362007-03-13 16:47:54 -0400132 __le64 generation;
133 __le64 root;
Chris Masondb945352007-10-15 16:15:53 -0400134 __le64 total_bytes;
135 __le64 bytes_used;
Chris Mason2e635a22007-03-21 11:12:56 -0400136 __le64 root_dir_objectid;
Chris Mason5f39d392007-10-15 16:14:19 -0400137 __le32 sectorsize;
138 __le32 nodesize;
139 __le32 leafsize;
Chris Mason87ee04e2007-11-30 11:30:34 -0500140 __le32 stripesize;
Chris Masondb945352007-10-15 16:15:53 -0400141 u8 root_level;
Chris Masoncfaa7292007-02-21 17:04:57 -0500142} __attribute__ ((__packed__));
143
Chris Masonfec577f2007-02-26 10:40:21 -0500144/*
Chris Mason62e27492007-03-15 12:56:47 -0400145 * A leaf is full of items. offset and size tell us where to find
Chris Masonfec577f2007-02-26 10:40:21 -0500146 * the item in the leaf (relative to the start of the data area)
147 */
Chris Mason0783fcf2007-03-12 20:12:07 -0400148struct btrfs_item {
Chris Masone2fa7222007-03-12 16:22:34 -0400149 struct btrfs_disk_key key;
Chris Mason123abc82007-03-14 14:14:43 -0400150 __le32 offset;
Chris Mason5f39d392007-10-15 16:14:19 -0400151 __le32 size;
Chris Masoneb60cea2007-02-02 09:18:22 -0500152} __attribute__ ((__packed__));
153
Chris Masonfec577f2007-02-26 10:40:21 -0500154/*
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 Mason234b63a2007-03-13 10:46:10 -0400161struct btrfs_leaf {
Chris Masonbb492bb2007-03-12 12:29:44 -0400162 struct btrfs_header header;
Chris Mason123abc82007-03-14 14:14:43 -0400163 struct btrfs_item items[];
Chris Masoneb60cea2007-02-02 09:18:22 -0500164} __attribute__ ((__packed__));
165
Chris Masonfec577f2007-02-26 10:40:21 -0500166/*
167 * all non-leaf blocks are nodes, they hold only keys and pointers to
168 * other blocks
169 */
Chris Mason123abc82007-03-14 14:14:43 -0400170struct btrfs_key_ptr {
171 struct btrfs_disk_key key;
172 __le64 blockptr;
Chris Mason74493f72007-12-11 09:25:06 -0500173 __le64 generation;
Chris Mason123abc82007-03-14 14:14:43 -0400174} __attribute__ ((__packed__));
175
Chris Mason234b63a2007-03-13 10:46:10 -0400176struct btrfs_node {
Chris Masonbb492bb2007-03-12 12:29:44 -0400177 struct btrfs_header header;
Chris Mason123abc82007-03-14 14:14:43 -0400178 struct btrfs_key_ptr ptrs[];
Chris Masoneb60cea2007-02-02 09:18:22 -0500179} __attribute__ ((__packed__));
180
Chris Masonfec577f2007-02-26 10:40:21 -0500181/*
Chris Mason234b63a2007-03-13 10:46:10 -0400182 * 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 Masonfec577f2007-02-26 10:40:21 -0500184 * 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 Mason234b63a2007-03-13 10:46:10 -0400189struct btrfs_path {
Chris Mason5f39d392007-10-15 16:14:19 -0400190 struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
Chris Mason234b63a2007-03-13 10:46:10 -0400191 int slots[BTRFS_MAX_LEVEL];
Chris Mason3c69fae2007-08-07 15:52:22 -0400192 int reada;
Chris Mason6702ed42007-08-07 16:15:09 -0400193 int lowest_level;
Chris Masoneb60cea2007-02-02 09:18:22 -0500194};
Chris Mason5de08d72007-02-24 06:24:44 -0500195
Chris Mason62e27492007-03-15 12:56:47 -0400196/*
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 */
200struct btrfs_extent_item {
201 __le32 refs;
Chris Mason74493f72007-12-11 09:25:06 -0500202} __attribute__ ((__packed__));
203
204struct btrfs_extent_ref {
205 __le64 root;
206 __le64 generation;
207 __le64 objectid;
208 __le64 offset;
Chris Mason62e27492007-03-15 12:56:47 -0400209} __attribute__ ((__packed__));
210
Chris Mason39544012007-12-12 14:38:19 -0500211struct btrfs_inode_ref {
212 __le16 name_len;
213 /* name goes here */
214} __attribute__ ((__packed__));
215
Chris Mason1e1d2702007-03-15 19:03:33 -0400216struct btrfs_inode_timespec {
Chris Masonf254e522007-03-29 15:15:27 -0400217 __le64 sec;
Chris Mason1e1d2702007-03-15 19:03:33 -0400218 __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 */
225struct btrfs_inode_item {
226 __le64 generation;
227 __le64 size;
228 __le64 nblocks;
Chris Mason31f3c992007-04-30 15:25:45 -0400229 __le64 block_group;
Chris Mason1e1d2702007-03-15 19:03:33 -0400230 __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 Mason62e27492007-03-15 12:56:47 -0400243struct btrfs_dir_item {
Chris Masond6e4a422007-04-06 15:37:36 -0400244 struct btrfs_disk_key location;
Josef Bacik5103e942007-11-16 11:45:54 -0500245 __le16 data_len;
Chris Masona8a2ee02007-03-16 08:46:49 -0400246 __le16 name_len;
Chris Mason62e27492007-03-15 12:56:47 -0400247 u8 type;
248} __attribute__ ((__packed__));
249
250struct btrfs_root_item {
Chris Masond6e4a422007-04-06 15:37:36 -0400251 struct btrfs_inode_item inode;
252 __le64 root_dirid;
Chris Masondb945352007-10-15 16:15:53 -0400253 __le64 bytenr;
254 __le64 byte_limit;
255 __le64 bytes_used;
Chris Mason5eda7b52007-06-22 14:16:25 -0400256 __le32 flags;
Chris Mason62e27492007-03-15 12:56:47 -0400257 __le32 refs;
Chris Mason5eda7b52007-06-22 14:16:25 -0400258 struct btrfs_disk_key drop_progress;
259 u8 drop_level;
Chris Masondb945352007-10-15 16:15:53 -0400260 u8 level;
Chris Mason9f5fae22007-03-20 14:38:32 -0400261} __attribute__ ((__packed__));
262
Chris Mason236454d2007-04-19 13:37:44 -0400263#define BTRFS_FILE_EXTENT_REG 0
264#define BTRFS_FILE_EXTENT_INLINE 1
265
Chris Mason9f5fae22007-03-20 14:38:32 -0400266struct btrfs_file_extent_item {
Chris Mason71951f32007-03-27 09:16:29 -0400267 __le64 generation;
Chris Mason236454d2007-04-19 13:37:44 -0400268 u8 type;
Chris Mason9f5fae22007-03-20 14:38:32 -0400269 /*
270 * disk space consumed by the extent, checksum blocks are included
271 * in these numbers
272 */
Chris Masondb945352007-10-15 16:15:53 -0400273 __le64 disk_bytenr;
274 __le64 disk_num_bytes;
Chris Mason9f5fae22007-03-20 14:38:32 -0400275 /*
Chris Masondee26a92007-03-26 16:00:06 -0400276 * the logical offset in file blocks (no csums)
Chris Mason9f5fae22007-03-20 14:38:32 -0400277 * 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 Masondb945352007-10-15 16:15:53 -0400286 __le64 num_bytes;
Chris Mason9f5fae22007-03-20 14:38:32 -0400287} __attribute__ ((__packed__));
288
Chris Masonf254e522007-03-29 15:15:27 -0400289struct btrfs_csum_item {
Chris Mason509659c2007-05-10 12:36:17 -0400290 u8 csum;
Chris Masonf254e522007-03-29 15:15:27 -0400291} __attribute__ ((__packed__));
292
Chris Mason9078a3e2007-04-26 16:46:15 -0400293/* tag for the radix tree of block groups in ram */
Chris Mason9078a3e2007-04-26 16:46:15 -0400294#define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
Chris Mason1e2677e2007-05-29 16:52:18 -0400295
296
297#define BTRFS_BLOCK_GROUP_DATA 1
Chris Masonf84a8b32007-11-06 10:26:29 -0500298#define BTRFS_BLOCK_GROUP_MIXED 2
299
Chris Mason9078a3e2007-04-26 16:46:15 -0400300struct btrfs_block_group_item {
301 __le64 used;
Chris Mason1e2677e2007-05-29 16:52:18 -0400302 u8 flags;
Chris Mason9078a3e2007-04-26 16:46:15 -0400303} __attribute__ ((__packed__));
304
305struct btrfs_block_group_cache {
306 struct btrfs_key key;
307 struct btrfs_block_group_item item;
Chris Masonbe744172007-05-06 10:15:01 -0400308 int data;
Chris Masone37c9e62007-05-09 20:13:14 -0400309 int cached;
Yan324ae4d2007-11-16 14:57:08 -0500310 u64 pinned;
Chris Mason9078a3e2007-04-26 16:46:15 -0400311};
Chris Mason9f5fae22007-03-20 14:38:32 -0400312struct btrfs_fs_info {
Chris Mason5f39d392007-10-15 16:14:19 -0400313 u8 fsid[BTRFS_FSID_SIZE];
Chris Mason9f5fae22007-03-20 14:38:32 -0400314 struct btrfs_root *extent_root;
315 struct btrfs_root *tree_root;
Chris Mason0f7d52f2007-04-09 10:42:37 -0400316 struct radix_tree_root fs_roots_radix;
Chris Mason1a5bc162007-10-15 16:15:26 -0400317
Chris Masond1310b22008-01-24 16:13:08 -0500318 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 Mason1a5bc162007-10-15 16:15:26 -0400323
Chris Mason293ffd52007-03-20 15:57:25 -0400324 u64 generation;
Josef Bacik15ee9bc2007-08-10 16:22:09 -0400325 u64 last_trans_committed;
Chris Masonb6cda9b2007-12-14 15:30:32 -0500326 unsigned long mount_opt;
Chris Masonc59f8952007-12-17 20:14:04 -0500327 u64 max_extent;
Chris Mason6f568d32008-01-29 16:03:38 -0500328 u64 max_inline;
Chris Mason8f662a72008-01-02 10:01:11 -0500329 u64 alloc_start;
Chris Mason79154b12007-03-22 15:59:16 -0400330 struct btrfs_transaction *running_transaction;
Chris Mason4b52dff2007-06-26 10:06:50 -0400331 struct btrfs_super_block super_copy;
Chris Mason5f39d392007-10-15 16:14:19 -0400332 struct extent_buffer *sb_buffer;
Chris Masone20d96d2007-03-22 12:13:20 -0400333 struct super_block *sb;
Chris Masond98237b2007-03-28 13:57:48 -0400334 struct inode *btree_inode;
Chris Mason19c00dd2007-10-15 16:19:22 -0400335 spinlock_t hash_lock;
Chris Mason79154b12007-03-22 15:59:16 -0400336 struct mutex trans_mutex;
Chris Masond561c022007-03-23 19:47:49 -0400337 struct mutex fs_mutex;
Chris Mason8fd17792007-04-19 21:01:03 -0400338 struct list_head trans_list;
Chris Mason19c00dd2007-10-15 16:19:22 -0400339 struct list_head hashers;
Chris Masonfacda1e2007-06-08 18:11:48 -0400340 struct list_head dead_roots;
Chris Mason6da6aba2007-12-18 16:15:09 -0500341#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
342 struct work_struct trans_work;
343#else
Chris Mason08607c12007-06-08 15:33:54 -0400344 struct delayed_work trans_work;
Chris Mason6da6aba2007-12-18 16:15:09 -0500345#endif
Josef Bacik58176a92007-08-29 15:47:34 -0400346 struct kobject super_kobj;
347 struct completion kobj_unregister;
Chris Masone66f7092007-04-20 13:16:02 -0400348 int do_barriers;
Chris Masonfacda1e2007-06-08 18:11:48 -0400349 int closing;
Chris Masone2008b62008-01-08 15:46:30 -0500350 unsigned long throttles;
Chris Mason62e27492007-03-15 12:56:47 -0400351
Yan324ae4d2007-11-16 14:57:08 -0500352 u64 total_pinned;
Chris Mason1832a6d2007-12-21 16:27:21 -0500353 spinlock_t delalloc_lock;
Chris Masoncee36a02008-01-15 08:40:48 -0500354 spinlock_t new_trans_lock;
Chris Mason1832a6d2007-12-21 16:27:21 -0500355 u64 delalloc_bytes;
Chris Masone18e4802008-01-18 10:54:22 -0500356 u64 last_alloc;
Chris Mason4529ba42008-01-31 16:45:07 -0500357 u64 last_data_alloc;
Yan324ae4d2007-11-16 14:57:08 -0500358};
Chris Mason62e27492007-03-15 12:56:47 -0400359/*
360 * in ram representation of the tree. extent_root is used for all allocations
Chris Masonf2458e12007-04-25 15:52:25 -0400361 * and for the extent tree extent_root root.
Chris Mason62e27492007-03-15 12:56:47 -0400362 */
363struct btrfs_root {
Chris Mason5f39d392007-10-15 16:14:19 -0400364 struct extent_buffer *node;
365 struct extent_buffer *commit_root;
Chris Mason62e27492007-03-15 12:56:47 -0400366 struct btrfs_root_item root_item;
367 struct btrfs_key root_key;
Chris Mason9f5fae22007-03-20 14:38:32 -0400368 struct btrfs_fs_info *fs_info;
Chris Mason0f7d52f2007-04-09 10:42:37 -0400369 struct inode *inode;
Josef Bacik58176a92007-08-29 15:47:34 -0400370 struct kobject root_kobj;
371 struct completion kobj_unregister;
Chris Mason0f7d52f2007-04-09 10:42:37 -0400372 u64 objectid;
373 u64 last_trans;
Chris Mason5f39d392007-10-15 16:14:19 -0400374
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 Mason87ee04e2007-11-30 11:30:34 -0500384 u32 stripesize;
385
Chris Mason9f5fae22007-03-20 14:38:32 -0400386 u32 type;
Chris Mason1b05da22007-04-10 12:13:09 -0400387 u64 highest_inode;
388 u64 last_inode_alloc;
Chris Mason9f3a7422007-08-07 15:52:19 -0400389 int ref_cows;
Chris Mason6702ed42007-08-07 16:15:09 -0400390 struct btrfs_key defrag_progress;
391 int defrag_running;
392 int defrag_level;
Josef Bacik58176a92007-08-29 15:47:34 -0400393 char *name;
Chris Mason4313b392008-01-03 09:08:48 -0500394 int in_sysfs;
Chris Mason62e27492007-03-15 12:56:47 -0400395};
396
Chris Mason1e1d2702007-03-15 19:03:33 -0400397/*
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 Mason9078a3e2007-04-26 16:46:15 -0400402#define BTRFS_INODE_ITEM_KEY 1
Chris Mason39544012007-12-12 14:38:19 -0500403#define BTRFS_INODE_REF_KEY 2
404#define BTRFS_XATTR_ITEM_KEY 8
Chris Mason9078a3e2007-04-26 16:46:15 -0400405/* reserve 2-15 close to the inode for later flexibility */
Chris Mason1e1d2702007-03-15 19:03:33 -0400406
407/*
408 * dir items are the name -> inode pointers in a directory. There is one
409 * for every name in a directory.
410 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400411#define BTRFS_DIR_ITEM_KEY 16
412#define BTRFS_DIR_INDEX_KEY 17
Chris Mason1e1d2702007-03-15 19:03:33 -0400413/*
Chris Mason9078a3e2007-04-26 16:46:15 -0400414 * extent data is for file data
Chris Mason1e1d2702007-03-15 19:03:33 -0400415 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400416#define BTRFS_EXTENT_DATA_KEY 18
Chris Mason1e1d2702007-03-15 19:03:33 -0400417/*
Chris Masonf254e522007-03-29 15:15:27 -0400418 * csum items have the checksums for data in the extents
419 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400420#define BTRFS_CSUM_ITEM_KEY 19
421
422/* reserve 20-31 for other file stuff */
Chris Masonf254e522007-03-29 15:15:27 -0400423
424/*
Chris Mason1e1d2702007-03-15 19:03:33 -0400425 * 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 Mason9078a3e2007-04-26 16:46:15 -0400428#define BTRFS_ROOT_ITEM_KEY 32
Chris Mason1e1d2702007-03-15 19:03:33 -0400429/*
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 Mason9078a3e2007-04-26 16:46:15 -0400433#define BTRFS_EXTENT_ITEM_KEY 33
Chris Mason74493f72007-12-11 09:25:06 -0500434#define BTRFS_EXTENT_REF_KEY 34
Chris Mason9078a3e2007-04-26 16:46:15 -0400435
436/*
437 * block groups give us hints into the extent allocation trees. Which
438 * blocks are free etc etc
439 */
Chris Mason74493f72007-12-11 09:25:06 -0500440#define BTRFS_BLOCK_GROUP_ITEM_KEY 50
Chris Mason9f5fae22007-03-20 14:38:32 -0400441
442/*
Chris Mason1e1d2702007-03-15 19:03:33 -0400443 * string items are for debugging. They just store a short string of
444 * data in the FS
445 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400446#define BTRFS_STRING_ITEM_KEY 253
447
Chris Mason21ad10c2008-01-09 09:23:21 -0500448#define BTRFS_MOUNT_NODATASUM (1 << 0)
449#define BTRFS_MOUNT_NODATACOW (1 << 1)
450#define BTRFS_MOUNT_NOBARRIER (1 << 2)
Chris Masone18e4802008-01-18 10:54:22 -0500451#define BTRFS_MOUNT_SSD (1 << 3)
Chris Masonb6cda9b2007-12-14 15:30:32 -0500452
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)
Yanb98b6762008-01-08 15:54:37 -0500457/*
458 * Inode flags
459 */
Yanfdebe2b2008-01-14 13:26:08 -0500460#define BTRFS_INODE_NODATASUM (1 << 0)
461#define BTRFS_INODE_NODATACOW (1 << 1)
462#define BTRFS_INODE_READONLY (1 << 2)
Yanb98b6762008-01-08 15:54:37 -0500463#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 Mason5f39d392007-10-15 16:14:19 -0400469/* 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 Mason9078a3e2007-04-26 16:46:15 -0400476
Chris Mason5f39d392007-10-15 16:14:19 -0400477#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 Mason0f827312007-10-15 16:18:56 -0400489#ifndef BTRFS_SETGET_FUNCS
Chris Mason5f39d392007-10-15 16:14:19 -0400490#define BTRFS_SETGET_FUNCS(name, type, member, bits) \
Chris Mason0f827312007-10-15 16:18:56 -0400491u##bits btrfs_##name(struct extent_buffer *eb, type *s); \
492void btrfs_set_##name(struct extent_buffer *eb, type *s, u##bits val);
493#endif
Chris Mason9078a3e2007-04-26 16:46:15 -0400494
Chris Mason5f39d392007-10-15 16:14:19 -0400495#define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
496static inline u##bits btrfs_##name(struct extent_buffer *eb) \
497{ \
Chris Mason810191f2007-10-15 16:18:55 -0400498 char *kaddr = kmap_atomic(eb->first_page, KM_USER0); \
Chris Mason6d36dcd2007-10-15 16:14:37 -0400499 unsigned long offset = offsetof(type, member); \
Chris Mason810191f2007-10-15 16:18:55 -0400500 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 Mason5f39d392007-10-15 16:14:19 -0400505} \
506static inline void btrfs_set_##name(struct extent_buffer *eb, \
507 u##bits val) \
508{ \
Chris Mason810191f2007-10-15 16:18:55 -0400509 char *kaddr = kmap_atomic(eb->first_page, KM_USER0); \
Chris Mason6d36dcd2007-10-15 16:14:37 -0400510 unsigned long offset = offsetof(type, member); \
Chris Mason810191f2007-10-15 16:18:55 -0400511 __le##bits *tmp = (__le##bits *)(kaddr + offset); \
512 *tmp = cpu_to_le##bits(val); \
513 kunmap_atomic(kaddr, KM_USER0); \
Chris Mason9078a3e2007-04-26 16:46:15 -0400514}
Chris Mason1e1d2702007-03-15 19:03:33 -0400515
Chris Mason5f39d392007-10-15 16:14:19 -0400516#define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
517static inline u##bits btrfs_##name(type *s) \
518{ \
519 return le##bits##_to_cpu(s->member); \
520} \
521static inline void btrfs_set_##name(type *s, u##bits val) \
522{ \
523 s->member = cpu_to_le##bits(val); \
Chris Mason1e1d2702007-03-15 19:03:33 -0400524}
525
Chris Mason5f39d392007-10-15 16:14:19 -0400526/* struct btrfs_block_group_item */
527BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
528 used, 64);
529BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
530 used, 64);
Chris Masonedbd8d42007-12-21 16:27:24 -0500531BTRFS_SETGET_FUNCS(disk_block_group_flags, struct btrfs_block_group_item,
532 flags, 8);
Chris Mason5f39d392007-10-15 16:14:19 -0400533
Chris Mason39544012007-12-12 14:38:19 -0500534/* struct btrfs_inode_ref */
535BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
536
Chris Mason5f39d392007-10-15 16:14:19 -0400537/* struct btrfs_inode_item */
538BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
539BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
540BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64);
541BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
542BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
543BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
544BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
545BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
546BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 32);
547BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16);
548BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item,
549 compat_flags, 16);
550
551static inline struct btrfs_inode_timespec *
552btrfs_inode_atime(struct btrfs_inode_item *inode_item)
Chris Mason1e1d2702007-03-15 19:03:33 -0400553{
Chris Mason5f39d392007-10-15 16:14:19 -0400554 unsigned long ptr = (unsigned long)inode_item;
555 ptr += offsetof(struct btrfs_inode_item, atime);
556 return (struct btrfs_inode_timespec *)ptr;
Chris Mason1e1d2702007-03-15 19:03:33 -0400557}
558
Chris Mason5f39d392007-10-15 16:14:19 -0400559static inline struct btrfs_inode_timespec *
560btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
Chris Mason1e1d2702007-03-15 19:03:33 -0400561{
Chris Mason5f39d392007-10-15 16:14:19 -0400562 unsigned long ptr = (unsigned long)inode_item;
563 ptr += offsetof(struct btrfs_inode_item, mtime);
564 return (struct btrfs_inode_timespec *)ptr;
Chris Mason1e1d2702007-03-15 19:03:33 -0400565}
566
Chris Mason5f39d392007-10-15 16:14:19 -0400567static inline struct btrfs_inode_timespec *
568btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
Chris Mason1e1d2702007-03-15 19:03:33 -0400569{
Chris Mason5f39d392007-10-15 16:14:19 -0400570 unsigned long ptr = (unsigned long)inode_item;
571 ptr += offsetof(struct btrfs_inode_item, ctime);
572 return (struct btrfs_inode_timespec *)ptr;
Chris Mason1e1d2702007-03-15 19:03:33 -0400573}
574
Chris Mason5f39d392007-10-15 16:14:19 -0400575static inline struct btrfs_inode_timespec *
576btrfs_inode_otime(struct btrfs_inode_item *inode_item)
Chris Mason1e1d2702007-03-15 19:03:33 -0400577{
Chris Mason5f39d392007-10-15 16:14:19 -0400578 unsigned long ptr = (unsigned long)inode_item;
579 ptr += offsetof(struct btrfs_inode_item, otime);
580 return (struct btrfs_inode_timespec *)ptr;
Chris Mason1e1d2702007-03-15 19:03:33 -0400581}
582
Chris Mason5f39d392007-10-15 16:14:19 -0400583BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_inode_timespec, sec, 64);
584BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_inode_timespec, nsec, 32);
585
586/* struct btrfs_extent_item */
587BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
Chris Mason74493f72007-12-11 09:25:06 -0500588
589/* struct btrfs_extent_ref */
590BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
591BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
592BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
593BTRFS_SETGET_FUNCS(ref_offset, struct btrfs_extent_ref, offset, 64);
594
Chris Mason7bb86312007-12-11 09:25:06 -0500595BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
596BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref,
Chris Mason74493f72007-12-11 09:25:06 -0500597 generation, 64);
Chris Mason7bb86312007-12-11 09:25:06 -0500598BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref,
599 objectid, 64);
600BTRFS_SETGET_STACK_FUNCS(stack_ref_offset, struct btrfs_extent_ref, offset, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400601
602BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
603 refs, 32);
Chris Mason5f39d392007-10-15 16:14:19 -0400604
605/* struct btrfs_node */
606BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
Chris Mason74493f72007-12-11 09:25:06 -0500607BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400608
609static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400610{
Chris Mason5f39d392007-10-15 16:14:19 -0400611 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 Mason1e1d2702007-03-15 19:03:33 -0400615}
616
Chris Mason5f39d392007-10-15 16:14:19 -0400617static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
618 int nr, u64 val)
Chris Mason31f3c992007-04-30 15:25:45 -0400619{
Chris Mason5f39d392007-10-15 16:14:19 -0400620 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 Mason31f3c992007-04-30 15:25:45 -0400624}
625
Chris Mason74493f72007-12-11 09:25:06 -0500626static 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
634static 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 Mason810191f2007-10-15 16:18:55 -0400643static inline unsigned long btrfs_node_key_ptr_offset(int nr)
Chris Mason31f3c992007-04-30 15:25:45 -0400644{
Chris Mason5f39d392007-10-15 16:14:19 -0400645 return offsetof(struct btrfs_node, ptrs) +
646 sizeof(struct btrfs_key_ptr) * nr;
Chris Mason31f3c992007-04-30 15:25:45 -0400647}
648
Chris Masone644d022007-11-06 15:09:29 -0500649void btrfs_node_key(struct extent_buffer *eb,
650 struct btrfs_disk_key *disk_key, int nr);
651
Chris Mason5f39d392007-10-15 16:14:19 -0400652static 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 Mason1e1d2702007-03-15 19:03:33 -0400659}
660
Chris Mason5f39d392007-10-15 16:14:19 -0400661/* struct btrfs_item */
662BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
663BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
664
665static inline unsigned long btrfs_item_nr_offset(int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400666{
Chris Mason5f39d392007-10-15 16:14:19 -0400667 return offsetof(struct btrfs_leaf, items) +
668 sizeof(struct btrfs_item) * nr;
Chris Mason1e1d2702007-03-15 19:03:33 -0400669}
670
Chris Mason5f39d392007-10-15 16:14:19 -0400671static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
672 int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400673{
Chris Mason5f39d392007-10-15 16:14:19 -0400674 return (struct btrfs_item *)btrfs_item_nr_offset(nr);
Chris Mason1e1d2702007-03-15 19:03:33 -0400675}
676
Chris Mason5f39d392007-10-15 16:14:19 -0400677static inline u32 btrfs_item_end(struct extent_buffer *eb,
678 struct btrfs_item *item)
Chris Mason1e1d2702007-03-15 19:03:33 -0400679{
Chris Mason5f39d392007-10-15 16:14:19 -0400680 return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
Chris Mason1e1d2702007-03-15 19:03:33 -0400681}
682
Chris Mason5f39d392007-10-15 16:14:19 -0400683static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400684{
Chris Mason5f39d392007-10-15 16:14:19 -0400685 return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
Chris Mason1e1d2702007-03-15 19:03:33 -0400686}
687
Chris Mason5f39d392007-10-15 16:14:19 -0400688static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400689{
Chris Mason5f39d392007-10-15 16:14:19 -0400690 return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
Chris Mason1e1d2702007-03-15 19:03:33 -0400691}
692
Chris Mason5f39d392007-10-15 16:14:19 -0400693static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400694{
Chris Mason5f39d392007-10-15 16:14:19 -0400695 return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
Chris Mason1e1d2702007-03-15 19:03:33 -0400696}
697
Chris Mason5f39d392007-10-15 16:14:19 -0400698static inline void btrfs_item_key(struct extent_buffer *eb,
699 struct btrfs_disk_key *disk_key, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400700{
Chris Mason5f39d392007-10-15 16:14:19 -0400701 struct btrfs_item *item = btrfs_item_nr(eb, nr);
702 read_eb_member(eb, item, struct btrfs_item, key, disk_key);
Chris Mason1e1d2702007-03-15 19:03:33 -0400703}
704
Chris Mason5f39d392007-10-15 16:14:19 -0400705static inline void btrfs_set_item_key(struct extent_buffer *eb,
706 struct btrfs_disk_key *disk_key, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400707{
Chris Mason5f39d392007-10-15 16:14:19 -0400708 struct btrfs_item *item = btrfs_item_nr(eb, nr);
709 write_eb_member(eb, item, struct btrfs_item, key, disk_key);
Chris Mason1e1d2702007-03-15 19:03:33 -0400710}
711
Chris Mason5f39d392007-10-15 16:14:19 -0400712/* struct btrfs_dir_item */
Josef Bacik5103e942007-11-16 11:45:54 -0500713BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
Chris Mason5f39d392007-10-15 16:14:19 -0400714BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
715BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
716
717static inline void btrfs_dir_item_key(struct extent_buffer *eb,
718 struct btrfs_dir_item *item,
719 struct btrfs_disk_key *key)
Chris Mason1e1d2702007-03-15 19:03:33 -0400720{
Chris Mason5f39d392007-10-15 16:14:19 -0400721 read_eb_member(eb, item, struct btrfs_dir_item, location, key);
Chris Mason1e1d2702007-03-15 19:03:33 -0400722}
723
Chris Mason5f39d392007-10-15 16:14:19 -0400724static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
725 struct btrfs_dir_item *item,
726 struct btrfs_disk_key *key)
Chris Mason1e1d2702007-03-15 19:03:33 -0400727{
Chris Mason5f39d392007-10-15 16:14:19 -0400728 write_eb_member(eb, item, struct btrfs_dir_item, location, key);
Chris Mason1e1d2702007-03-15 19:03:33 -0400729}
730
Chris Mason5f39d392007-10-15 16:14:19 -0400731/* struct btrfs_disk_key */
732BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
733 objectid, 64);
734BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
735BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
Chris Mason1d4f6402007-03-15 15:18:43 -0400736
Chris Masone2fa7222007-03-12 16:22:34 -0400737static 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 Mason5f39d392007-10-15 16:14:19 -0400741 cpu->type = disk->type;
Chris Masone2fa7222007-03-12 16:22:34 -0400742 cpu->objectid = le64_to_cpu(disk->objectid);
743}
744
745static 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 Mason5f39d392007-10-15 16:14:19 -0400749 disk->type = cpu->type;
Chris Masone2fa7222007-03-12 16:22:34 -0400750 disk->objectid = cpu_to_le64(cpu->objectid);
751}
752
Chris Mason5f39d392007-10-15 16:14:19 -0400753static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
754 struct btrfs_key *key, int nr)
Chris Masone2fa7222007-03-12 16:22:34 -0400755{
Chris Mason5f39d392007-10-15 16:14:19 -0400756 struct btrfs_disk_key disk_key;
757 btrfs_node_key(eb, &disk_key, nr);
758 btrfs_disk_key_to_cpu(key, &disk_key);
Chris Masone2fa7222007-03-12 16:22:34 -0400759}
760
Chris Mason5f39d392007-10-15 16:14:19 -0400761static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
762 struct btrfs_key *key, int nr)
Chris Masone2fa7222007-03-12 16:22:34 -0400763{
Chris Mason5f39d392007-10-15 16:14:19 -0400764 struct btrfs_disk_key disk_key;
765 btrfs_item_key(eb, &disk_key, nr);
766 btrfs_disk_key_to_cpu(key, &disk_key);
Chris Masone2fa7222007-03-12 16:22:34 -0400767}
768
Chris Mason5f39d392007-10-15 16:14:19 -0400769static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
770 struct btrfs_dir_item *item,
771 struct btrfs_key *key)
Chris Masone2fa7222007-03-12 16:22:34 -0400772{
Chris Mason5f39d392007-10-15 16:14:19 -0400773 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 Masone2fa7222007-03-12 16:22:34 -0400776}
777
Chris Mason5f39d392007-10-15 16:14:19 -0400778
779static inline u8 btrfs_key_type(struct btrfs_key *key)
Chris Masone2fa7222007-03-12 16:22:34 -0400780{
Chris Mason5f39d392007-10-15 16:14:19 -0400781 return key->type;
Chris Masone2fa7222007-03-12 16:22:34 -0400782}
783
Chris Mason5f39d392007-10-15 16:14:19 -0400784static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
Chris Masone2fa7222007-03-12 16:22:34 -0400785{
Chris Mason5f39d392007-10-15 16:14:19 -0400786 key->type = val;
Chris Masone2fa7222007-03-12 16:22:34 -0400787}
788
Chris Mason5f39d392007-10-15 16:14:19 -0400789/* struct btrfs_header */
Chris Masondb945352007-10-15 16:15:53 -0400790BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400791BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
792 generation, 64);
793BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
794BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
795BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 16);
796BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
797
798static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
Chris Masone2fa7222007-03-12 16:22:34 -0400799{
Chris Mason5f39d392007-10-15 16:14:19 -0400800 unsigned long ptr = offsetof(struct btrfs_header, fsid);
801 return (u8 *)ptr;
Chris Masone2fa7222007-03-12 16:22:34 -0400802}
803
Chris Mason5f39d392007-10-15 16:14:19 -0400804static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
Chris Masona429e512007-04-18 16:15:28 -0400805{
Chris Mason5f39d392007-10-15 16:14:19 -0400806 unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
807 return (u8 *)ptr;
Chris Masona429e512007-04-18 16:15:28 -0400808}
809
Chris Mason5f39d392007-10-15 16:14:19 -0400810static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
Chris Masona429e512007-04-18 16:15:28 -0400811{
Chris Mason5f39d392007-10-15 16:14:19 -0400812 unsigned long ptr = offsetof(struct btrfs_header, csum);
813 return (u8 *)ptr;
Chris Masona429e512007-04-18 16:15:28 -0400814}
815
Chris Mason5f39d392007-10-15 16:14:19 -0400816static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
Chris Masona429e512007-04-18 16:15:28 -0400817{
Chris Mason5f39d392007-10-15 16:14:19 -0400818 return NULL;
Chris Masona429e512007-04-18 16:15:28 -0400819}
820
Chris Mason5f39d392007-10-15 16:14:19 -0400821static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
Chris Masona429e512007-04-18 16:15:28 -0400822{
Chris Mason5f39d392007-10-15 16:14:19 -0400823 return NULL;
Chris Masona429e512007-04-18 16:15:28 -0400824}
825
Chris Mason5f39d392007-10-15 16:14:19 -0400826static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
Chris Mason7518a232007-03-12 12:01:18 -0400827{
Chris Mason5f39d392007-10-15 16:14:19 -0400828 return NULL;
Chris Mason7518a232007-03-12 12:01:18 -0400829}
830
Chris Mason5f39d392007-10-15 16:14:19 -0400831static inline int btrfs_is_leaf(struct extent_buffer *eb)
Chris Mason7518a232007-03-12 12:01:18 -0400832{
Chris Mason5f39d392007-10-15 16:14:19 -0400833 return (btrfs_header_level(eb) == 0);
Chris Mason7518a232007-03-12 12:01:18 -0400834}
835
Chris Mason5f39d392007-10-15 16:14:19 -0400836/* struct btrfs_root_item */
837BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
Chris Masondb945352007-10-15 16:15:53 -0400838BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
839BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
Chris Mason5f39d392007-10-15 16:14:19 -0400840
Chris Masondb945352007-10-15 16:15:53 -0400841BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
842BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
Chris Mason5f39d392007-10-15 16:14:19 -0400843BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
844BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
845BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
Chris Masondb945352007-10-15 16:15:53 -0400846BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
847BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400848
849/* struct btrfs_super_block */
Chris Masondb945352007-10-15 16:15:53 -0400850BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400851BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
852 generation, 64);
853BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
Chris Masondb945352007-10-15 16:15:53 -0400854BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
855 root_level, 8);
856BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
857 total_bytes, 64);
858BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
859 bytes_used, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400860BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
861 sectorsize, 32);
862BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
863 nodesize, 32);
864BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
865 leafsize, 32);
Chris Mason87ee04e2007-11-30 11:30:34 -0500866BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
867 stripesize, 32);
Chris Mason5f39d392007-10-15 16:14:19 -0400868BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
869 root_dir_objectid, 64);
870
871static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
Chris Mason7f5c1512007-03-23 15:56:19 -0400872{
Chris Mason5f39d392007-10-15 16:14:19 -0400873 return offsetof(struct btrfs_leaf, items);
Chris Mason7f5c1512007-03-23 15:56:19 -0400874}
875
Chris Mason5f39d392007-10-15 16:14:19 -0400876/* struct btrfs_file_extent_item */
877BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
Chris Mason7f5c1512007-03-23 15:56:19 -0400878
Chris Mason5f39d392007-10-15 16:14:19 -0400879static inline unsigned long btrfs_file_extent_inline_start(struct
Chris Mason236454d2007-04-19 13:37:44 -0400880 btrfs_file_extent_item *e)
881{
Chris Mason5f39d392007-10-15 16:14:19 -0400882 unsigned long offset = (unsigned long)e;
Chris Masondb945352007-10-15 16:15:53 -0400883 offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
Chris Mason5f39d392007-10-15 16:14:19 -0400884 return offset;
Chris Mason236454d2007-04-19 13:37:44 -0400885}
886
887static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
888{
Chris Masondb945352007-10-15 16:15:53 -0400889 return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
Chris Mason236454d2007-04-19 13:37:44 -0400890}
891
Chris Mason5f39d392007-10-15 16:14:19 -0400892static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
893 struct btrfs_item *e)
Chris Mason236454d2007-04-19 13:37:44 -0400894{
Chris Mason5f39d392007-10-15 16:14:19 -0400895 unsigned long offset;
Chris Masondb945352007-10-15 16:15:53 -0400896 offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
Chris Mason5f39d392007-10-15 16:14:19 -0400897 return btrfs_item_size(eb, e) - offset;
Chris Mason236454d2007-04-19 13:37:44 -0400898}
899
Chris Masondb945352007-10-15 16:15:53 -0400900BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
901 disk_bytenr, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400902BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
903 generation, 64);
Chris Masondb945352007-10-15 16:15:53 -0400904BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
905 disk_num_bytes, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400906BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
907 offset, 64);
Chris Masondb945352007-10-15 16:15:53 -0400908BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
909 num_bytes, 64);
Chris Mason9f5fae22007-03-20 14:38:32 -0400910
Chris Masone20d96d2007-03-22 12:13:20 -0400911static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
912{
913 return sb->s_fs_info;
914}
915
Josef Bacik58176a92007-08-29 15:47:34 -0400916static 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 Masondb945352007-10-15 16:15:53 -0400933static 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 Mason4beb1b82007-03-14 10:31:29 -0400939/* helper function to cast into the data area of the leaf. */
940#define btrfs_item_ptr(leaf, slot, type) \
Chris Mason123abc82007-03-14 14:14:43 -0400941 ((type *)(btrfs_leaf_data(leaf) + \
Chris Mason5f39d392007-10-15 16:14:19 -0400942 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 Mason4beb1b82007-03-14 10:31:29 -0400947
Chris Mason6da6aba2007-12-18 16:15:09 -0500948static 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 Masonb18c6682007-04-17 13:26:50 -0400956/* extent-tree.c */
Chris Masonbe20aa92007-12-17 20:14:01 -0500957u32 btrfs_count_snapshots_in_path(struct btrfs_root *root,
958 struct btrfs_path *count_path,
959 u64 first_extent);
Chris Masone9d0b132007-08-10 14:06:19 -0400960int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
961 struct btrfs_root *root);
Chris Masond1310b22008-01-24 16:13:08 -0500962int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
Chris Mason5276aed2007-06-11 21:33:38 -0400963struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
964 btrfs_fs_info *info,
Chris Masondb945352007-10-15 16:15:53 -0400965 u64 bytenr);
Chris Mason31f3c992007-04-30 15:25:45 -0400966struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
967 struct btrfs_block_group_cache
Chris Masonbe744172007-05-06 10:15:01 -0400968 *hint, u64 search_start,
Chris Masonde428b62007-05-18 13:28:27 -0400969 int data, int owner);
Chris Masonc5739bb2007-04-10 09:27:04 -0400970int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
Chris Mason7bb86312007-12-11 09:25:06 -0500971 struct btrfs_root *root, u64 owner_objectid);
Chris Mason5f39d392007-10-15 16:14:19 -0400972struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
Chris Masondb945352007-10-15 16:15:53 -0400973 struct btrfs_root *root, u32 size,
Chris Mason7bb86312007-12-11 09:25:06 -0500974 u64 root_objectid,
Chris Masondb945352007-10-15 16:15:53 -0400975 u64 hint, u64 empty_size);
Chris Mason7bb86312007-12-11 09:25:06 -0500976struct 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 Masonedbd8d42007-12-21 16:27:24 -0500985int btrfs_grow_extent_tree(struct btrfs_trans_handle *trans,
986 struct btrfs_root *root, u64 new_size);
987int btrfs_shrink_extent_tree(struct btrfs_root *root, u64 new_size);
Chris Mason7bb86312007-12-11 09:25:06 -0500988int 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 Mason4d775672007-04-20 20:23:12 -0400993int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
Chris Mason7bb86312007-12-11 09:25:06 -0500994 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 Masonbe08c1b2007-05-03 09:06:49 -0400998 u64 search_end, struct btrfs_key *ins, int data);
Chris Masone089f052007-03-16 16:20:31 -0400999int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
Chris Mason5f39d392007-10-15 16:14:19 -04001000 struct extent_buffer *buf);
Chris Masone089f052007-03-16 16:20:31 -04001001int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Mason7bb86312007-12-11 09:25:06 -05001002 *root, u64 bytenr, u64 num_bytes,
1003 u64 root_objectid, u64 ref_generation,
1004 u64 owner_objectid, u64 owner_offset, int pin);
Chris Masonccd467d2007-06-28 15:57:36 -04001005int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
1006 struct btrfs_root *root,
Chris Masond1310b22008-01-24 16:13:08 -05001007 struct extent_io_tree *unpin);
Chris Masonb18c6682007-04-17 13:26:50 -04001008int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
1009 struct btrfs_root *root,
Chris Mason7bb86312007-12-11 09:25:06 -05001010 u64 bytenr, u64 num_bytes,
1011 u64 root_objectid, u64 ref_generation,
1012 u64 owner, u64 owner_offset);
Chris Mason9078a3e2007-04-26 16:46:15 -04001013int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1014 struct btrfs_root *root);
1015int btrfs_free_block_groups(struct btrfs_fs_info *info);
1016int btrfs_read_block_groups(struct btrfs_root *root);
Chris Masondee26a92007-03-26 16:00:06 -04001017/* ctree.c */
Chris Mason5f39d392007-10-15 16:14:19 -04001018int 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 Masonbe20aa92007-12-17 20:14:01 -05001022int 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 Mason6567e832007-04-16 09:22:45 -04001026int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1027 *root, struct btrfs_path *path, u32 data_size);
Chris Masonb18c6682007-04-17 13:26:50 -04001028int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1029 struct btrfs_root *root,
1030 struct btrfs_path *path,
Chris Mason179e29e2007-11-01 11:28:41 -04001031 u32 new_size, int from_end);
Chris Masone089f052007-03-16 16:20:31 -04001032int 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 Mason6702ed42007-08-07 16:15:09 -04001035int btrfs_realloc_node(struct btrfs_trans_handle *trans,
Chris Mason5f39d392007-10-15 16:14:19 -04001036 struct btrfs_root *root, struct extent_buffer *parent,
Chris Masona6b6e752007-10-15 16:22:39 -04001037 int start_slot, int cache_only, u64 *last_ret,
1038 struct btrfs_key *progress);
Chris Mason234b63a2007-03-13 10:46:10 -04001039void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
Chris Mason2c90e5d2007-04-02 10:50:19 -04001040struct btrfs_path *btrfs_alloc_path(void);
1041void btrfs_free_path(struct btrfs_path *p);
Chris Mason234b63a2007-03-13 10:46:10 -04001042void btrfs_init_path(struct btrfs_path *p);
Chris Mason85e21ba2008-01-29 15:11:36 -05001043int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1044 struct btrfs_path *path, int slot, int nr);
1045
1046static 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 Masone089f052007-03-16 16:20:31 -04001053int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1054 *root, struct btrfs_key *key, void *data, u32 data_size);
Chris Mason9c583092008-01-29 15:15:18 -05001055int 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
1060static 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 Mason234b63a2007-03-13 10:46:10 -04001069int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
Chris Mason7bb86312007-12-11 09:25:06 -05001070int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
Chris Mason5f39d392007-10-15 16:14:19 -04001071int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
Chris Masone089f052007-03-16 16:20:31 -04001072int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Mason9f3a7422007-08-07 15:52:19 -04001073 *root);
Chris Masondee26a92007-03-26 16:00:06 -04001074/* root-item.c */
Chris Masone089f052007-03-16 16:20:31 -04001075int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1076 struct btrfs_key *key);
1077int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1078 *root, struct btrfs_key *key, struct btrfs_root_item
1079 *item);
1080int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1081 *root, struct btrfs_key *key, struct btrfs_root_item
1082 *item);
1083int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1084 btrfs_root_item *item, struct btrfs_key *key);
Chris Mason5ce14bb2007-09-11 11:15:39 -04001085int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
1086 struct btrfs_root *latest_root);
Chris Masondee26a92007-03-26 16:00:06 -04001087/* dir-item.c */
Chris Masone089f052007-03-16 16:20:31 -04001088int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Masond6e4a422007-04-06 15:37:36 -04001089 *root, const char *name, int name_len, u64 dir,
1090 struct btrfs_key *location, u8 type);
Chris Mason7e381802007-04-19 15:36:27 -04001091struct 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);
1096struct btrfs_dir_item *
1097btrfs_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);
1102struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
1103 struct btrfs_path *path,
Chris Mason7f5c1512007-03-23 15:56:19 -04001104 const char *name, int name_len);
Chris Mason7e381802007-04-19 15:36:27 -04001105int 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 Bacik5103e942007-11-16 11:45:54 -05001109int 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);
1113struct 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 Masondee26a92007-03-26 16:00:06 -04001118/* inode-map.c */
Chris Mason9f5fae22007-03-20 14:38:32 -04001119int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1120 struct btrfs_root *fs_root,
1121 u64 dirid, u64 *objectid);
Chris Mason5be6f7f2007-04-05 13:35:25 -04001122int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
1123
Chris Masondee26a92007-03-26 16:00:06 -04001124/* inode-item.c */
Chris Mason39544012007-12-12 14:38:19 -05001125int 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);
1129int 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 Mason5f39d392007-10-15 16:14:19 -04001133int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
1134 struct btrfs_root *root,
1135 struct btrfs_path *path, u64 objectid);
Chris Mason293ffd52007-03-20 15:57:25 -04001136int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Masond6e4a422007-04-06 15:37:36 -04001137 *root, struct btrfs_path *path,
1138 struct btrfs_key *location, int mod);
Chris Masondee26a92007-03-26 16:00:06 -04001139
1140/* file-item.c */
Chris Masonb18c6682007-04-17 13:26:50 -04001141int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
Chris Masondee26a92007-03-26 16:00:06 -04001142 struct btrfs_root *root,
Chris Masonb18c6682007-04-17 13:26:50 -04001143 u64 objectid, u64 pos, u64 offset,
Chris Masondb945352007-10-15 16:15:53 -04001144 u64 disk_num_bytes,
1145 u64 num_bytes);
Chris Masondee26a92007-03-26 16:00:06 -04001146int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
1147 struct btrfs_root *root,
1148 struct btrfs_path *path, u64 objectid,
Chris Masondb945352007-10-15 16:15:53 -04001149 u64 bytenr, int mod);
Chris Masonf254e522007-03-29 15:15:27 -04001150int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
1151 struct btrfs_root *root,
Chris Masonf578d4b2007-10-25 15:42:56 -04001152 struct inode *inode,
Chris Masonf254e522007-03-29 15:15:27 -04001153 u64 objectid, u64 offset,
1154 char *data, size_t len);
Chris Masonb18c6682007-04-17 13:26:50 -04001155struct 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 Mason1de037a2007-05-29 15:17:08 -04001160int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
1161 struct btrfs_root *root, struct btrfs_path *path,
1162 u64 isize);
Chris Mason39279cc2007-06-12 06:35:45 -04001163/* inode.c */
Chris Mason90692182008-02-08 13:49:28 -05001164static 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 Masonedbd8d42007-12-21 16:27:24 -05001173unsigned 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 Mason1832a6d2007-12-21 16:27:21 -05001176int btrfs_check_free_space(struct btrfs_root *root, u64 num_required,
1177 int for_del);
Chris Mason9ebefb182007-06-15 13:50:00 -04001178int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page);
1179int btrfs_readpage(struct file *file, struct page *page);
Chris Mason39279cc2007-06-12 06:35:45 -04001180void btrfs_delete_inode(struct inode *inode);
Chris Mason2da98f02008-01-16 11:44:43 -05001181void btrfs_put_inode(struct inode *inode);
Chris Mason39279cc2007-06-12 06:35:45 -04001182void btrfs_read_locked_inode(struct inode *inode);
1183int btrfs_write_inode(struct inode *inode, int wait);
1184void btrfs_dirty_inode(struct inode *inode);
1185struct inode *btrfs_alloc_inode(struct super_block *sb);
1186void btrfs_destroy_inode(struct inode *inode);
1187int btrfs_init_cachep(void);
1188void btrfs_destroy_cachep(void);
Christoph Hellwig34287aa2007-09-14 10:22:47 -04001189long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
Chris Mason39279cc2007-06-12 06:35:45 -04001190struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
1191 struct btrfs_root *root);
Chris Masondc17ff82008-01-08 15:46:30 -05001192struct inode *btrfs_ilookup(struct super_block *s, u64 objectid,
1193 u64 root_objectid);
Chris Mason39279cc2007-06-12 06:35:45 -04001194int btrfs_commit_write(struct file *file, struct page *page,
1195 unsigned from, unsigned to);
Chris Masona52d9a82007-08-27 16:49:44 -04001196struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
1197 size_t page_offset, u64 start, u64 end,
1198 int create);
1199int btrfs_update_inode(struct btrfs_trans_handle *trans,
1200 struct btrfs_root *root,
1201 struct inode *inode);
Chris Mason39279cc2007-06-12 06:35:45 -04001202/* file.c */
Chris Masona52d9a82007-08-27 16:49:44 -04001203int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end);
Chris Mason5f564062008-01-22 16:47:59 -05001204int btrfs_check_file(struct btrfs_root *root, struct inode *inode);
Chris Mason39279cc2007-06-12 06:35:45 -04001205extern struct file_operations btrfs_file_operations;
1206int btrfs_drop_extents(struct btrfs_trans_handle *trans,
1207 struct btrfs_root *root, struct inode *inode,
Chris Mason00f5c792007-11-30 10:09:33 -05001208 u64 start, u64 end, u64 inline_limit, u64 *hint_block);
Chris Mason6702ed42007-08-07 16:15:09 -04001209/* tree-defrag.c */
1210int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
1211 struct btrfs_root *root, int cache_only);
Josef Bacik58176a92007-08-29 15:47:34 -04001212
1213/* sysfs.c */
1214int btrfs_init_sysfs(void);
1215void btrfs_exit_sysfs(void);
1216int btrfs_sysfs_add_super(struct btrfs_fs_info *fs);
1217int btrfs_sysfs_add_root(struct btrfs_root *root);
1218void btrfs_sysfs_del_root(struct btrfs_root *root);
1219void btrfs_sysfs_del_super(struct btrfs_fs_info *root);
1220
Josef Bacik5103e942007-11-16 11:45:54 -05001221/* xattr.c */
1222ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
1223int btrfs_delete_xattrs(struct btrfs_trans_handle *trans,
1224 struct btrfs_root *root, struct inode *inode);
Chris Masonedbd8d42007-12-21 16:27:24 -05001225/* super.c */
1226u64 btrfs_parse_size(char *str);
Chris Masoneb60cea2007-02-02 09:18:22 -05001227#endif