blob: 1453d995fef67ccb66d4701c4dae01444c2c1dfd [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 Mason0b86a832008-03-24 15:01:56 -040043
44/* holds pointers to all of the tree roots */
Chris Mason6407bf62007-03-27 06:33:00 -040045#define BTRFS_ROOT_TREE_OBJECTID 1ULL
Chris Mason0b86a832008-03-24 15:01:56 -040046
47/* stores information about which extents are in use, and reference counts */
Chris Mason0cf6c622007-06-09 09:22:25 -040048#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
Chris Mason0b86a832008-03-24 15:01:56 -040049
50/* one per subvolume, storing files and directories */
Chris Mason0cf6c622007-06-09 09:22:25 -040051#define BTRFS_FS_TREE_OBJECTID 3ULL
Chris Mason0b86a832008-03-24 15:01:56 -040052
53/* directory objectid inside the root tree */
Chris Mason0cf6c622007-06-09 09:22:25 -040054#define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL
Chris Mason0b86a832008-03-24 15:01:56 -040055
56
57/*
58 * chunk tree stores translations from logical -> physical block numbering
59 * the super block points to the chunk tree
60 */
61#define BTRFS_CHUNK_TREE_OBJECTID 5ULL
62
63/*
64 * stores information about which areas of a given device are in use.
65 * one per device. The tree of tree roots points to the device tree
66 */
67#define BTRFS_DEV_TREE_OBJECTID 6ULL
68
69/*
70 * All files have objectids higher than this.
71 */
Chris Masonf6dbff52007-12-13 11:13:32 -050072#define BTRFS_FIRST_FREE_OBJECTID 256ULL
Chris Mason3768f362007-03-13 16:47:54 -040073
Chris Mason0b86a832008-03-24 15:01:56 -040074
75/*
76 * the device items go into the chunk tree. The key is in the form
77 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
78 */
79#define BTRFS_DEV_ITEMS_OBJECTID 1ULL
80
Chris Masonfec577f2007-02-26 10:40:21 -050081/*
Chris Masone20d96d2007-03-22 12:13:20 -040082 * we can actually store much bigger names, but lets not confuse the rest
83 * of linux
84 */
85#define BTRFS_NAME_LEN 255
86
Chris Masonf254e522007-03-29 15:15:27 -040087/* 32 bytes in various csum fields */
88#define BTRFS_CSUM_SIZE 32
Chris Mason509659c2007-05-10 12:36:17 -040089/* four bytes for CRC32 */
90#define BTRFS_CRC32_SIZE 4
Chris Mason39544012007-12-12 14:38:19 -050091#define BTRFS_EMPTY_DIR_SIZE 0
Chris Masonf254e522007-03-29 15:15:27 -040092
Chris Masonfabb5682007-06-07 22:13:21 -040093#define BTRFS_FT_UNKNOWN 0
94#define BTRFS_FT_REG_FILE 1
95#define BTRFS_FT_DIR 2
96#define BTRFS_FT_CHRDEV 3
97#define BTRFS_FT_BLKDEV 4
98#define BTRFS_FT_FIFO 5
99#define BTRFS_FT_SOCK 6
100#define BTRFS_FT_SYMLINK 7
Josef Bacik5103e942007-11-16 11:45:54 -0500101#define BTRFS_FT_XATTR 8
102#define BTRFS_FT_MAX 9
Chris Masonfabb5682007-06-07 22:13:21 -0400103
Chris Masone20d96d2007-03-22 12:13:20 -0400104/*
Chris Masonfec577f2007-02-26 10:40:21 -0500105 * the key defines the order in the tree, and so it also defines (optimal)
106 * block layout. objectid corresonds to the inode number. The flags
107 * tells us things about the object, and is a kind of stream selector.
108 * so for a given inode, keys with flags of 1 might refer to the inode
109 * data, flags of 2 may point to file data in the btree and flags == 3
110 * may point to extents.
111 *
112 * offset is the starting byte offset for this key in the stream.
Chris Masone2fa7222007-03-12 16:22:34 -0400113 *
114 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
115 * in cpu native order. Otherwise they are identical and their sizes
116 * should be the same (ie both packed)
Chris Masonfec577f2007-02-26 10:40:21 -0500117 */
Chris Masone2fa7222007-03-12 16:22:34 -0400118struct btrfs_disk_key {
119 __le64 objectid;
Chris Mason5f39d392007-10-15 16:14:19 -0400120 u8 type;
Chris Mason70b2bef2007-04-17 15:39:32 -0400121 __le64 offset;
Chris Masone2fa7222007-03-12 16:22:34 -0400122} __attribute__ ((__packed__));
123
124struct btrfs_key {
Chris Masoneb60cea2007-02-02 09:18:22 -0500125 u64 objectid;
Chris Mason5f39d392007-10-15 16:14:19 -0400126 u8 type;
Chris Mason70b2bef2007-04-17 15:39:32 -0400127 u64 offset;
Chris Masoneb60cea2007-02-02 09:18:22 -0500128} __attribute__ ((__packed__));
129
Chris Mason0b86a832008-03-24 15:01:56 -0400130struct btrfs_mapping_tree {
131 struct extent_map_tree map_tree;
132};
133
134#define BTRFS_DEV_UUID_SIZE 16
135struct btrfs_dev_item {
136 /* the internal btrfs device id */
137 __le64 devid;
138
139 /* size of the device */
140 __le64 total_bytes;
141
142 /* bytes used */
143 __le64 bytes_used;
144
145 /* optimal io alignment for this device */
146 __le32 io_align;
147
148 /* optimal io width for this device */
149 __le32 io_width;
150
151 /* minimal io size for this device */
152 __le32 sector_size;
153
154 /* the kernel device number */
155 __le64 rdev;
156
157 /* type and info about this device */
158 __le64 type;
159
160 /* partition number, 0 for whole dev */
161 __le32 partition;
162
163 /* length of the name data at the end of the item */
164 __le16 name_len;
165
166 /* physical drive uuid (or lvm uuid) */
167 u8 uuid[BTRFS_DEV_UUID_SIZE];
168 /* name goes here */
169} __attribute__ ((__packed__));
170
171struct btrfs_stripe {
172 __le64 devid;
173 __le64 offset;
174} __attribute__ ((__packed__));
175
176struct btrfs_chunk {
177 __le64 owner;
178 __le64 stripe_len;
179 __le64 type;
180
181 /* optimal io alignment for this chunk */
182 __le32 io_align;
183
184 /* optimal io width for this chunk */
185 __le32 io_width;
186
187 /* minimal io size for this chunk */
188 __le32 sector_size;
189
190 /* 2^16 stripes is quite a lot, a second limit is the size of a single
191 * item in the btree
192 */
193 __le16 num_stripes;
194 struct btrfs_stripe stripe;
195 /* additional stripes go here */
196} __attribute__ ((__packed__));
197
198static inline unsigned long btrfs_chunk_item_size(int num_stripes)
199{
200 BUG_ON(num_stripes == 0);
201 return sizeof(struct btrfs_chunk) +
202 sizeof(struct btrfs_stripe) * (num_stripes - 1);
203}
204
Chris Mason5f39d392007-10-15 16:14:19 -0400205#define BTRFS_FSID_SIZE 16
Chris Masonfec577f2007-02-26 10:40:21 -0500206/*
207 * every tree block (leaf or node) starts with this header.
208 */
Chris Masonbb492bb2007-03-12 12:29:44 -0400209struct btrfs_header {
Chris Masonf254e522007-03-29 15:15:27 -0400210 u8 csum[BTRFS_CSUM_SIZE];
Chris Mason5f39d392007-10-15 16:14:19 -0400211 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
Chris Masondb945352007-10-15 16:15:53 -0400212 __le64 bytenr; /* which block this node is supposed to live in */
Chris Mason7f5c1512007-03-23 15:56:19 -0400213 __le64 generation;
Chris Mason4d775672007-04-20 20:23:12 -0400214 __le64 owner;
Chris Mason5f39d392007-10-15 16:14:19 -0400215 __le32 nritems;
Chris Masonbb492bb2007-03-12 12:29:44 -0400216 __le16 flags;
Chris Mason9a6f11e2007-03-27 09:06:38 -0400217 u8 level;
Chris Masoneb60cea2007-02-02 09:18:22 -0500218} __attribute__ ((__packed__));
219
Chris Mason5f39d392007-10-15 16:14:19 -0400220#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
Chris Mason123abc82007-03-14 14:14:43 -0400221 sizeof(struct btrfs_header)) / \
Chris Mason74493f72007-12-11 09:25:06 -0500222 sizeof(struct btrfs_key_ptr))
Chris Mason123abc82007-03-14 14:14:43 -0400223#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
Chris Mason5f39d392007-10-15 16:14:19 -0400224#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
Chris Mason236454df2007-04-19 13:37:44 -0400225#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
226 sizeof(struct btrfs_item) - \
227 sizeof(struct btrfs_file_extent_item))
Chris Masoneb60cea2007-02-02 09:18:22 -0500228
Chris Mason0b86a832008-03-24 15:01:56 -0400229
230/*
231 * this is a very generous portion of the super block, giving us
232 * room to translate 14 chunks with 3 stripes each.
233 */
234#define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
235
Chris Masonfec577f2007-02-26 10:40:21 -0500236/*
Chris Masonfec577f2007-02-26 10:40:21 -0500237 * the super block basically lists the main trees of the FS
238 * it currently lacks any block count etc etc
239 */
Chris Mason234b63a2007-03-13 10:46:10 -0400240struct btrfs_super_block {
Chris Masonf254e522007-03-29 15:15:27 -0400241 u8 csum[BTRFS_CSUM_SIZE];
Chris Mason87cbda52007-03-28 19:44:27 -0400242 /* the first 3 fields must match struct btrfs_header */
Chris Mason3768f362007-03-13 16:47:54 -0400243 u8 fsid[16]; /* FS specific uuid */
Chris Masondb945352007-10-15 16:15:53 -0400244 __le64 bytenr; /* this block number */
Chris Mason3768f362007-03-13 16:47:54 -0400245 __le64 magic;
Chris Mason3768f362007-03-13 16:47:54 -0400246 __le64 generation;
247 __le64 root;
Chris Mason0b86a832008-03-24 15:01:56 -0400248 __le64 chunk_root;
Chris Masondb945352007-10-15 16:15:53 -0400249 __le64 total_bytes;
250 __le64 bytes_used;
Chris Mason2e635a22007-03-21 11:12:56 -0400251 __le64 root_dir_objectid;
Chris Mason5f39d392007-10-15 16:14:19 -0400252 __le32 sectorsize;
253 __le32 nodesize;
254 __le32 leafsize;
Chris Mason87ee04e2007-11-30 11:30:34 -0500255 __le32 stripesize;
Chris Mason0b86a832008-03-24 15:01:56 -0400256 __le32 sys_chunk_array_size;
Chris Masondb945352007-10-15 16:15:53 -0400257 u8 root_level;
Chris Mason0b86a832008-03-24 15:01:56 -0400258 u8 chunk_root_level;
259 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
Chris Masoncfaa7292007-02-21 17:04:57 -0500260} __attribute__ ((__packed__));
261
Chris Masonfec577f2007-02-26 10:40:21 -0500262/*
Chris Mason62e27492007-03-15 12:56:47 -0400263 * A leaf is full of items. offset and size tell us where to find
Chris Masonfec577f2007-02-26 10:40:21 -0500264 * the item in the leaf (relative to the start of the data area)
265 */
Chris Mason0783fcf2007-03-12 20:12:07 -0400266struct btrfs_item {
Chris Masone2fa7222007-03-12 16:22:34 -0400267 struct btrfs_disk_key key;
Chris Mason123abc82007-03-14 14:14:43 -0400268 __le32 offset;
Chris Mason5f39d392007-10-15 16:14:19 -0400269 __le32 size;
Chris Masoneb60cea2007-02-02 09:18:22 -0500270} __attribute__ ((__packed__));
271
Chris Masonfec577f2007-02-26 10:40:21 -0500272/*
273 * leaves have an item area and a data area:
274 * [item0, item1....itemN] [free space] [dataN...data1, data0]
275 *
276 * The data is separate from the items to get the keys closer together
277 * during searches.
278 */
Chris Mason234b63a2007-03-13 10:46:10 -0400279struct btrfs_leaf {
Chris Masonbb492bb2007-03-12 12:29:44 -0400280 struct btrfs_header header;
Chris Mason123abc82007-03-14 14:14:43 -0400281 struct btrfs_item items[];
Chris Masoneb60cea2007-02-02 09:18:22 -0500282} __attribute__ ((__packed__));
283
Chris Masonfec577f2007-02-26 10:40:21 -0500284/*
285 * all non-leaf blocks are nodes, they hold only keys and pointers to
286 * other blocks
287 */
Chris Mason123abc82007-03-14 14:14:43 -0400288struct btrfs_key_ptr {
289 struct btrfs_disk_key key;
290 __le64 blockptr;
Chris Mason74493f72007-12-11 09:25:06 -0500291 __le64 generation;
Chris Mason123abc82007-03-14 14:14:43 -0400292} __attribute__ ((__packed__));
293
Chris Mason234b63a2007-03-13 10:46:10 -0400294struct btrfs_node {
Chris Masonbb492bb2007-03-12 12:29:44 -0400295 struct btrfs_header header;
Chris Mason123abc82007-03-14 14:14:43 -0400296 struct btrfs_key_ptr ptrs[];
Chris Masoneb60cea2007-02-02 09:18:22 -0500297} __attribute__ ((__packed__));
298
Chris Masonfec577f2007-02-26 10:40:21 -0500299/*
Chris Mason234b63a2007-03-13 10:46:10 -0400300 * btrfs_paths remember the path taken from the root down to the leaf.
301 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
Chris Masonfec577f2007-02-26 10:40:21 -0500302 * to any other levels that are present.
303 *
304 * The slots array records the index of the item or block pointer
305 * used while walking the tree.
306 */
Chris Mason234b63a2007-03-13 10:46:10 -0400307struct btrfs_path {
Chris Mason5f39d392007-10-15 16:14:19 -0400308 struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
Chris Mason234b63a2007-03-13 10:46:10 -0400309 int slots[BTRFS_MAX_LEVEL];
Chris Mason3c69fae2007-08-07 15:52:22 -0400310 int reada;
Chris Mason6702ed42007-08-07 16:15:09 -0400311 int lowest_level;
Chris Masoneb60cea2007-02-02 09:18:22 -0500312};
Chris Mason5de08d72007-02-24 06:24:44 -0500313
Chris Mason62e27492007-03-15 12:56:47 -0400314/*
315 * items in the extent btree are used to record the objectid of the
316 * owner of the block and the number of references
317 */
318struct btrfs_extent_item {
319 __le32 refs;
Chris Mason74493f72007-12-11 09:25:06 -0500320} __attribute__ ((__packed__));
321
322struct btrfs_extent_ref {
323 __le64 root;
324 __le64 generation;
325 __le64 objectid;
326 __le64 offset;
Chris Mason62e27492007-03-15 12:56:47 -0400327} __attribute__ ((__packed__));
328
Chris Mason0b86a832008-03-24 15:01:56 -0400329/* dev extents record free space on individual devices. The owner
330 * field points back to the chunk allocation mapping tree that allocated
331 * the extent
332 */
333struct btrfs_dev_extent {
334 __le64 owner;
335 __le64 length;
336} __attribute__ ((__packed__));
337
338
Chris Mason39544012007-12-12 14:38:19 -0500339struct btrfs_inode_ref {
340 __le16 name_len;
341 /* name goes here */
342} __attribute__ ((__packed__));
343
Chris Mason0b86a832008-03-24 15:01:56 -0400344struct btrfs_timespec {
Chris Masonf254e522007-03-29 15:15:27 -0400345 __le64 sec;
Chris Mason1e1d2702007-03-15 19:03:33 -0400346 __le32 nsec;
347} __attribute__ ((__packed__));
348
349/*
350 * there is no padding here on purpose. If you want to extent the inode,
351 * make a new item type
352 */
353struct btrfs_inode_item {
354 __le64 generation;
355 __le64 size;
356 __le64 nblocks;
Chris Mason31f3c992007-04-30 15:25:45 -0400357 __le64 block_group;
Chris Mason1e1d2702007-03-15 19:03:33 -0400358 __le32 nlink;
359 __le32 uid;
360 __le32 gid;
361 __le32 mode;
Chris Mason0b86a832008-03-24 15:01:56 -0400362 __le64 rdev;
Chris Mason1e1d2702007-03-15 19:03:33 -0400363 __le16 flags;
364 __le16 compat_flags;
Chris Mason0b86a832008-03-24 15:01:56 -0400365 struct btrfs_timespec atime;
366 struct btrfs_timespec ctime;
367 struct btrfs_timespec mtime;
368 struct btrfs_timespec otime;
Chris Mason1e1d2702007-03-15 19:03:33 -0400369} __attribute__ ((__packed__));
370
Chris Mason62e27492007-03-15 12:56:47 -0400371struct btrfs_dir_item {
Chris Masond6e4a422007-04-06 15:37:36 -0400372 struct btrfs_disk_key location;
Josef Bacik5103e942007-11-16 11:45:54 -0500373 __le16 data_len;
Chris Masona8a2ee02007-03-16 08:46:49 -0400374 __le16 name_len;
Chris Mason62e27492007-03-15 12:56:47 -0400375 u8 type;
376} __attribute__ ((__packed__));
377
378struct btrfs_root_item {
Chris Masond6e4a422007-04-06 15:37:36 -0400379 struct btrfs_inode_item inode;
380 __le64 root_dirid;
Chris Masondb945352007-10-15 16:15:53 -0400381 __le64 bytenr;
382 __le64 byte_limit;
383 __le64 bytes_used;
Chris Mason5eda7b52007-06-22 14:16:25 -0400384 __le32 flags;
Chris Mason62e27492007-03-15 12:56:47 -0400385 __le32 refs;
Chris Mason5eda7b52007-06-22 14:16:25 -0400386 struct btrfs_disk_key drop_progress;
387 u8 drop_level;
Chris Masondb945352007-10-15 16:15:53 -0400388 u8 level;
Chris Mason9f5fae22007-03-20 14:38:32 -0400389} __attribute__ ((__packed__));
390
Chris Mason236454df2007-04-19 13:37:44 -0400391#define BTRFS_FILE_EXTENT_REG 0
392#define BTRFS_FILE_EXTENT_INLINE 1
393
Chris Mason9f5fae22007-03-20 14:38:32 -0400394struct btrfs_file_extent_item {
Chris Mason71951f32007-03-27 09:16:29 -0400395 __le64 generation;
Chris Mason236454df2007-04-19 13:37:44 -0400396 u8 type;
Chris Mason9f5fae22007-03-20 14:38:32 -0400397 /*
398 * disk space consumed by the extent, checksum blocks are included
399 * in these numbers
400 */
Chris Masondb945352007-10-15 16:15:53 -0400401 __le64 disk_bytenr;
402 __le64 disk_num_bytes;
Chris Mason9f5fae22007-03-20 14:38:32 -0400403 /*
Chris Masondee26a92007-03-26 16:00:06 -0400404 * the logical offset in file blocks (no csums)
Chris Mason9f5fae22007-03-20 14:38:32 -0400405 * this extent record is for. This allows a file extent to point
406 * into the middle of an existing extent on disk, sharing it
407 * between two snapshots (useful if some bytes in the middle of the
408 * extent have changed
409 */
410 __le64 offset;
411 /*
412 * the logical number of file blocks (no csums included)
413 */
Chris Masondb945352007-10-15 16:15:53 -0400414 __le64 num_bytes;
Chris Mason9f5fae22007-03-20 14:38:32 -0400415} __attribute__ ((__packed__));
416
Chris Masonf254e522007-03-29 15:15:27 -0400417struct btrfs_csum_item {
Chris Mason509659c2007-05-10 12:36:17 -0400418 u8 csum;
Chris Masonf254e522007-03-29 15:15:27 -0400419} __attribute__ ((__packed__));
420
Chris Mason0b86a832008-03-24 15:01:56 -0400421/* different types of block groups (and chunks) */
422#define BTRFS_BLOCK_GROUP_DATA (1 << 0)
423#define BTRFS_BLOCK_GROUP_SYSTEM (1 << 1)
424#define BTRFS_BLOCK_GROUP_METADATA (1 << 2)
Chris Mason1e2677e2007-05-29 16:52:18 -0400425
426
Chris Mason9078a3e2007-04-26 16:46:15 -0400427struct btrfs_block_group_item {
428 __le64 used;
Chris Mason0b86a832008-03-24 15:01:56 -0400429 __le64 chunk_tree;
430 __le64 chunk_objectid;
431 __le64 flags;
Chris Mason9078a3e2007-04-26 16:46:15 -0400432} __attribute__ ((__packed__));
433
434struct btrfs_block_group_cache {
435 struct btrfs_key key;
436 struct btrfs_block_group_item item;
Yan324ae4d2007-11-16 14:57:08 -0500437 u64 pinned;
Chris Mason0b86a832008-03-24 15:01:56 -0400438 u64 flags;
439 int cached;
Chris Mason9078a3e2007-04-26 16:46:15 -0400440};
Chris Mason0b86a832008-03-24 15:01:56 -0400441
442struct btrfs_device;
Chris Mason9f5fae22007-03-20 14:38:32 -0400443struct btrfs_fs_info {
Chris Mason5f39d392007-10-15 16:14:19 -0400444 u8 fsid[BTRFS_FSID_SIZE];
Chris Mason9f5fae22007-03-20 14:38:32 -0400445 struct btrfs_root *extent_root;
446 struct btrfs_root *tree_root;
Chris Mason0b86a832008-03-24 15:01:56 -0400447 struct btrfs_root *chunk_root;
448 struct btrfs_root *dev_root;
Chris Mason0f7d52f2007-04-09 10:42:37 -0400449 struct radix_tree_root fs_roots_radix;
Chris Mason1a5bc162007-10-15 16:15:26 -0400450
Chris Masond1310b22008-01-24 16:13:08 -0500451 struct extent_io_tree free_space_cache;
452 struct extent_io_tree block_group_cache;
453 struct extent_io_tree pinned_extents;
454 struct extent_io_tree pending_del;
455 struct extent_io_tree extent_ins;
Chris Mason1a5bc162007-10-15 16:15:26 -0400456
Chris Mason0b86a832008-03-24 15:01:56 -0400457 /* logical->physical extent mapping */
458 struct btrfs_mapping_tree mapping_tree;
459
Chris Mason293ffd52007-03-20 15:57:25 -0400460 u64 generation;
Josef Bacik15ee9bc2007-08-10 16:22:09 -0400461 u64 last_trans_committed;
Chris Masonb6cda9b2007-12-14 15:30:32 -0500462 unsigned long mount_opt;
Chris Masonc59f8952007-12-17 20:14:04 -0500463 u64 max_extent;
Chris Mason6f568d32008-01-29 16:03:38 -0500464 u64 max_inline;
Chris Mason8f662a72008-01-02 10:01:11 -0500465 u64 alloc_start;
Chris Mason79154b12007-03-22 15:59:16 -0400466 struct btrfs_transaction *running_transaction;
Chris Mason4b52dff2007-06-26 10:06:50 -0400467 struct btrfs_super_block super_copy;
Chris Mason5f39d392007-10-15 16:14:19 -0400468 struct extent_buffer *sb_buffer;
Chris Mason0b86a832008-03-24 15:01:56 -0400469 struct block_device *__bdev;
Chris Masone20d96d2007-03-22 12:13:20 -0400470 struct super_block *sb;
Chris Masond98237b2007-03-28 13:57:48 -0400471 struct inode *btree_inode;
Chris Mason19c00dd2007-10-15 16:19:22 -0400472 spinlock_t hash_lock;
Chris Mason79154b12007-03-22 15:59:16 -0400473 struct mutex trans_mutex;
Chris Masond561c022007-03-23 19:47:49 -0400474 struct mutex fs_mutex;
Chris Mason8fd17792007-04-19 21:01:03 -0400475 struct list_head trans_list;
Chris Mason19c00dd2007-10-15 16:19:22 -0400476 struct list_head hashers;
Chris Masonfacda1e2007-06-08 18:11:48 -0400477 struct list_head dead_roots;
Chris Mason6da6aba2007-12-18 16:15:09 -0500478#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
479 struct work_struct trans_work;
480#else
Chris Mason08607c12007-06-08 15:33:54 -0400481 struct delayed_work trans_work;
Chris Mason6da6aba2007-12-18 16:15:09 -0500482#endif
Josef Bacik58176a92007-08-29 15:47:34 -0400483 struct kobject super_kobj;
484 struct completion kobj_unregister;
Chris Masone66f7092007-04-20 13:16:02 -0400485 int do_barriers;
Chris Masonfacda1e2007-06-08 18:11:48 -0400486 int closing;
Chris Masone2008b62008-01-08 15:46:30 -0500487 unsigned long throttles;
Chris Mason62e27492007-03-15 12:56:47 -0400488
Yan324ae4d2007-11-16 14:57:08 -0500489 u64 total_pinned;
Chris Mason0b86a832008-03-24 15:01:56 -0400490 struct list_head dirty_cowonly_roots;
491
492 struct list_head devices;
493 struct list_head *last_device;
Chris Mason1832a6d2007-12-21 16:27:21 -0500494 spinlock_t delalloc_lock;
Chris Masoncee36a02008-01-15 08:40:48 -0500495 spinlock_t new_trans_lock;
Chris Mason1832a6d2007-12-21 16:27:21 -0500496 u64 delalloc_bytes;
Chris Masone18e4802008-01-18 10:54:22 -0500497 u64 last_alloc;
Chris Mason4529ba42008-01-31 16:45:07 -0500498 u64 last_data_alloc;
Yan324ae4d2007-11-16 14:57:08 -0500499};
Chris Mason0b86a832008-03-24 15:01:56 -0400500
Chris Mason62e27492007-03-15 12:56:47 -0400501/*
502 * in ram representation of the tree. extent_root is used for all allocations
Chris Masonf2458e12007-04-25 15:52:25 -0400503 * and for the extent tree extent_root root.
Chris Mason62e27492007-03-15 12:56:47 -0400504 */
505struct btrfs_root {
Chris Mason5f39d392007-10-15 16:14:19 -0400506 struct extent_buffer *node;
507 struct extent_buffer *commit_root;
Chris Mason62e27492007-03-15 12:56:47 -0400508 struct btrfs_root_item root_item;
509 struct btrfs_key root_key;
Chris Mason9f5fae22007-03-20 14:38:32 -0400510 struct btrfs_fs_info *fs_info;
Chris Mason0f7d52f2007-04-09 10:42:37 -0400511 struct inode *inode;
Josef Bacik58176a92007-08-29 15:47:34 -0400512 struct kobject root_kobj;
513 struct completion kobj_unregister;
Chris Mason0f7d52f2007-04-09 10:42:37 -0400514 u64 objectid;
515 u64 last_trans;
Chris Mason5f39d392007-10-15 16:14:19 -0400516
517 /* data allocations are done in sectorsize units */
518 u32 sectorsize;
519
520 /* node allocations are done in nodesize units */
521 u32 nodesize;
522
523 /* leaf allocations are done in leafsize units */
524 u32 leafsize;
525
Chris Mason87ee04e2007-11-30 11:30:34 -0500526 u32 stripesize;
527
Chris Mason9f5fae22007-03-20 14:38:32 -0400528 u32 type;
Chris Mason1b05da22007-04-10 12:13:09 -0400529 u64 highest_inode;
530 u64 last_inode_alloc;
Chris Mason9f3a7422007-08-07 15:52:19 -0400531 int ref_cows;
Chris Mason0b86a832008-03-24 15:01:56 -0400532 int track_dirty;
Chris Mason6702ed42007-08-07 16:15:09 -0400533 struct btrfs_key defrag_progress;
534 int defrag_running;
535 int defrag_level;
Josef Bacik58176a92007-08-29 15:47:34 -0400536 char *name;
Chris Mason4313b392008-01-03 09:08:48 -0500537 int in_sysfs;
Chris Mason0b86a832008-03-24 15:01:56 -0400538
539 /* the dirty list is only used by non-reference counted roots */
540 struct list_head dirty_list;
Chris Mason62e27492007-03-15 12:56:47 -0400541};
542
Chris Mason1e1d2702007-03-15 19:03:33 -0400543/*
Chris Mason0b86a832008-03-24 15:01:56 -0400544
Chris Mason1e1d2702007-03-15 19:03:33 -0400545 * inode items have the data typically returned from stat and store other
546 * info about object characteristics. There is one for every file and dir in
547 * the FS
548 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400549#define BTRFS_INODE_ITEM_KEY 1
Chris Mason39544012007-12-12 14:38:19 -0500550#define BTRFS_INODE_REF_KEY 2
551#define BTRFS_XATTR_ITEM_KEY 8
Chris Mason9078a3e2007-04-26 16:46:15 -0400552/* reserve 2-15 close to the inode for later flexibility */
Chris Mason1e1d2702007-03-15 19:03:33 -0400553
554/*
555 * dir items are the name -> inode pointers in a directory. There is one
556 * for every name in a directory.
557 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400558#define BTRFS_DIR_ITEM_KEY 16
559#define BTRFS_DIR_INDEX_KEY 17
Chris Mason1e1d2702007-03-15 19:03:33 -0400560/*
Chris Mason9078a3e2007-04-26 16:46:15 -0400561 * extent data is for file data
Chris Mason1e1d2702007-03-15 19:03:33 -0400562 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400563#define BTRFS_EXTENT_DATA_KEY 18
Chris Mason1e1d2702007-03-15 19:03:33 -0400564/*
Chris Masonf254e522007-03-29 15:15:27 -0400565 * csum items have the checksums for data in the extents
566 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400567#define BTRFS_CSUM_ITEM_KEY 19
568
569/* reserve 20-31 for other file stuff */
Chris Masonf254e522007-03-29 15:15:27 -0400570
571/*
Chris Mason1e1d2702007-03-15 19:03:33 -0400572 * root items point to tree roots. There are typically in the root
573 * tree used by the super block to find all the other trees
574 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400575#define BTRFS_ROOT_ITEM_KEY 32
Chris Mason1e1d2702007-03-15 19:03:33 -0400576/*
577 * extent items are in the extent map tree. These record which blocks
578 * are used, and how many references there are to each block
579 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400580#define BTRFS_EXTENT_ITEM_KEY 33
Chris Mason74493f72007-12-11 09:25:06 -0500581#define BTRFS_EXTENT_REF_KEY 34
Chris Mason9078a3e2007-04-26 16:46:15 -0400582
583/*
584 * block groups give us hints into the extent allocation trees. Which
585 * blocks are free etc etc
586 */
Chris Mason74493f72007-12-11 09:25:06 -0500587#define BTRFS_BLOCK_GROUP_ITEM_KEY 50
Chris Mason9f5fae22007-03-20 14:38:32 -0400588
Chris Mason0b86a832008-03-24 15:01:56 -0400589#define BTRFS_DEV_EXTENT_KEY 75
590#define BTRFS_DEV_ITEM_KEY 76
591#define BTRFS_CHUNK_ITEM_KEY 77
592
Chris Mason9f5fae22007-03-20 14:38:32 -0400593/*
Chris Mason1e1d2702007-03-15 19:03:33 -0400594 * string items are for debugging. They just store a short string of
595 * data in the FS
596 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400597#define BTRFS_STRING_ITEM_KEY 253
598
Chris Mason21ad10c2008-01-09 09:23:21 -0500599#define BTRFS_MOUNT_NODATASUM (1 << 0)
600#define BTRFS_MOUNT_NODATACOW (1 << 1)
601#define BTRFS_MOUNT_NOBARRIER (1 << 2)
Chris Masone18e4802008-01-18 10:54:22 -0500602#define BTRFS_MOUNT_SSD (1 << 3)
Chris Masonb6cda9b2007-12-14 15:30:32 -0500603
604#define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
605#define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
606#define btrfs_test_opt(root, opt) ((root)->fs_info->mount_opt & \
607 BTRFS_MOUNT_##opt)
Yanb98b6762008-01-08 15:54:37 -0500608/*
609 * Inode flags
610 */
Yanfdebe2b2008-01-14 13:26:08 -0500611#define BTRFS_INODE_NODATASUM (1 << 0)
612#define BTRFS_INODE_NODATACOW (1 << 1)
613#define BTRFS_INODE_READONLY (1 << 2)
Yanb98b6762008-01-08 15:54:37 -0500614#define btrfs_clear_flag(inode, flag) (BTRFS_I(inode)->flags &= \
615 ~BTRFS_INODE_##flag)
616#define btrfs_set_flag(inode, flag) (BTRFS_I(inode)->flags |= \
617 BTRFS_INODE_##flag)
618#define btrfs_test_flag(inode, flag) (BTRFS_I(inode)->flags & \
619 BTRFS_INODE_##flag)
Chris Mason5f39d392007-10-15 16:14:19 -0400620/* some macros to generate set/get funcs for the struct fields. This
621 * assumes there is a lefoo_to_cpu for every type, so lets make a simple
622 * one for u8:
623 */
624#define le8_to_cpu(v) (v)
625#define cpu_to_le8(v) (v)
626#define __le8 u8
Chris Mason9078a3e2007-04-26 16:46:15 -0400627
Chris Mason5f39d392007-10-15 16:14:19 -0400628#define read_eb_member(eb, ptr, type, member, result) ( \
629 read_extent_buffer(eb, (char *)(result), \
630 ((unsigned long)(ptr)) + \
631 offsetof(type, member), \
632 sizeof(((type *)0)->member)))
633
634#define write_eb_member(eb, ptr, type, member, result) ( \
635 write_extent_buffer(eb, (char *)(result), \
636 ((unsigned long)(ptr)) + \
637 offsetof(type, member), \
638 sizeof(((type *)0)->member)))
639
Chris Mason0f827312007-10-15 16:18:56 -0400640#ifndef BTRFS_SETGET_FUNCS
Chris Mason5f39d392007-10-15 16:14:19 -0400641#define BTRFS_SETGET_FUNCS(name, type, member, bits) \
Chris Mason0f827312007-10-15 16:18:56 -0400642u##bits btrfs_##name(struct extent_buffer *eb, type *s); \
643void btrfs_set_##name(struct extent_buffer *eb, type *s, u##bits val);
644#endif
Chris Mason9078a3e2007-04-26 16:46:15 -0400645
Chris Mason5f39d392007-10-15 16:14:19 -0400646#define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
647static inline u##bits btrfs_##name(struct extent_buffer *eb) \
648{ \
David Millerdf68b8a2008-02-15 10:40:52 -0500649 type *p = kmap_atomic(eb->first_page, KM_USER0); \
650 u##bits res = le##bits##_to_cpu(p->member); \
651 kunmap_atomic(p, KM_USER0); \
Chris Mason810191f2007-10-15 16:18:55 -0400652 return res; \
Chris Mason5f39d392007-10-15 16:14:19 -0400653} \
654static inline void btrfs_set_##name(struct extent_buffer *eb, \
655 u##bits val) \
656{ \
David Millerdf68b8a2008-02-15 10:40:52 -0500657 type *p = kmap_atomic(eb->first_page, KM_USER0); \
658 p->member = cpu_to_le##bits(val); \
659 kunmap_atomic(p, KM_USER0); \
Chris Mason9078a3e2007-04-26 16:46:15 -0400660}
Chris Mason1e1d2702007-03-15 19:03:33 -0400661
Chris Mason5f39d392007-10-15 16:14:19 -0400662#define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
663static inline u##bits btrfs_##name(type *s) \
664{ \
665 return le##bits##_to_cpu(s->member); \
666} \
667static inline void btrfs_set_##name(type *s, u##bits val) \
668{ \
669 s->member = cpu_to_le##bits(val); \
Chris Mason1e1d2702007-03-15 19:03:33 -0400670}
671
Chris Mason0b86a832008-03-24 15:01:56 -0400672BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
673BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
674BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
675BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
676BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
677BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
678BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
679BTRFS_SETGET_FUNCS(device_rdev, struct btrfs_dev_item, rdev, 64);
680BTRFS_SETGET_FUNCS(device_partition, struct btrfs_dev_item, partition, 32);
681BTRFS_SETGET_FUNCS(device_name_len, struct btrfs_dev_item, name_len, 16);
682
683static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
684{
685 return (char *)d + offsetof(struct btrfs_dev_item, uuid);
686}
687
688static inline char *btrfs_device_name(struct btrfs_dev_item *d)
689{
690 return (char *)(d + 1);
691}
692
693BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
694BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
695BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
696BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
697BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
698BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
699BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
700BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
701BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
702
703BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
704BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
705 stripe_len, 64);
706BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
707 io_align, 32);
708BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
709 io_width, 32);
710BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
711 sector_size, 32);
712BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
713BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
714 num_stripes, 16);
715BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
716BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
717
718static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
719 int nr)
720{
721 unsigned long offset = (unsigned long)c;
722 offset += offsetof(struct btrfs_chunk, stripe);
723 offset += nr * sizeof(struct btrfs_stripe);
724 return (struct btrfs_stripe *)offset;
725}
726
727static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
728 struct btrfs_chunk *c, int nr)
729{
730 return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
731}
732
733static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
734 struct btrfs_chunk *c, int nr,
735 u64 val)
736{
737 btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
738}
739
740static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
741 struct btrfs_chunk *c, int nr)
742{
743 return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
744}
745
746static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
747 struct btrfs_chunk *c, int nr,
748 u64 val)
749{
750 btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
751}
752
Chris Mason5f39d392007-10-15 16:14:19 -0400753/* struct btrfs_block_group_item */
754BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
755 used, 64);
756BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
757 used, 64);
Chris Mason0b86a832008-03-24 15:01:56 -0400758BTRFS_SETGET_STACK_FUNCS(block_group_chunk_tree, struct btrfs_block_group_item,
759 chunk_tree, 64);
760BTRFS_SETGET_FUNCS(disk_block_group_chunk_tree, struct btrfs_block_group_item,
761 chunk_tree, 64);
762BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
763 struct btrfs_block_group_item, chunk_objectid, 64);
764BTRFS_SETGET_FUNCS(disk_block_group_chunk_objecitd,
765 struct btrfs_block_group_item, chunk_objectid, 64);
766BTRFS_SETGET_FUNCS(disk_block_group_flags,
767 struct btrfs_block_group_item, flags, 64);
768BTRFS_SETGET_STACK_FUNCS(block_group_flags,
769 struct btrfs_block_group_item, flags, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400770
Chris Mason39544012007-12-12 14:38:19 -0500771/* struct btrfs_inode_ref */
772BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
773
Chris Mason5f39d392007-10-15 16:14:19 -0400774/* struct btrfs_inode_item */
775BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
776BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
777BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64);
778BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
779BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
780BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
781BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
782BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
Chris Mason0b86a832008-03-24 15:01:56 -0400783BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400784BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16);
785BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item,
786 compat_flags, 16);
787
Chris Mason0b86a832008-03-24 15:01:56 -0400788static inline struct btrfs_timespec *
Chris Mason5f39d392007-10-15 16:14:19 -0400789btrfs_inode_atime(struct btrfs_inode_item *inode_item)
Chris Mason1e1d2702007-03-15 19:03:33 -0400790{
Chris Mason5f39d392007-10-15 16:14:19 -0400791 unsigned long ptr = (unsigned long)inode_item;
792 ptr += offsetof(struct btrfs_inode_item, atime);
Chris Mason0b86a832008-03-24 15:01:56 -0400793 return (struct btrfs_timespec *)ptr;
Chris Mason1e1d2702007-03-15 19:03:33 -0400794}
795
Chris Mason0b86a832008-03-24 15:01:56 -0400796static inline struct btrfs_timespec *
Chris Mason5f39d392007-10-15 16:14:19 -0400797btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
Chris Mason1e1d2702007-03-15 19:03:33 -0400798{
Chris Mason5f39d392007-10-15 16:14:19 -0400799 unsigned long ptr = (unsigned long)inode_item;
800 ptr += offsetof(struct btrfs_inode_item, mtime);
Chris Mason0b86a832008-03-24 15:01:56 -0400801 return (struct btrfs_timespec *)ptr;
Chris Mason1e1d2702007-03-15 19:03:33 -0400802}
803
Chris Mason0b86a832008-03-24 15:01:56 -0400804static inline struct btrfs_timespec *
Chris Mason5f39d392007-10-15 16:14:19 -0400805btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
Chris Mason1e1d2702007-03-15 19:03:33 -0400806{
Chris Mason5f39d392007-10-15 16:14:19 -0400807 unsigned long ptr = (unsigned long)inode_item;
808 ptr += offsetof(struct btrfs_inode_item, ctime);
Chris Mason0b86a832008-03-24 15:01:56 -0400809 return (struct btrfs_timespec *)ptr;
Chris Mason1e1d2702007-03-15 19:03:33 -0400810}
811
Chris Mason0b86a832008-03-24 15:01:56 -0400812static inline struct btrfs_timespec *
Chris Mason5f39d392007-10-15 16:14:19 -0400813btrfs_inode_otime(struct btrfs_inode_item *inode_item)
Chris Mason1e1d2702007-03-15 19:03:33 -0400814{
Chris Mason5f39d392007-10-15 16:14:19 -0400815 unsigned long ptr = (unsigned long)inode_item;
816 ptr += offsetof(struct btrfs_inode_item, otime);
Chris Mason0b86a832008-03-24 15:01:56 -0400817 return (struct btrfs_timespec *)ptr;
Chris Mason1e1d2702007-03-15 19:03:33 -0400818}
819
Chris Mason0b86a832008-03-24 15:01:56 -0400820BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
821BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
Chris Mason5f39d392007-10-15 16:14:19 -0400822
823/* struct btrfs_extent_item */
824BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
Chris Mason74493f72007-12-11 09:25:06 -0500825
Chris Mason0b86a832008-03-24 15:01:56 -0400826/* struct btrfs_dev_extent */
827BTRFS_SETGET_FUNCS(dev_extent_owner, struct btrfs_dev_extent, owner, 64);
828BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
829
Chris Mason74493f72007-12-11 09:25:06 -0500830/* struct btrfs_extent_ref */
831BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
832BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
833BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
834BTRFS_SETGET_FUNCS(ref_offset, struct btrfs_extent_ref, offset, 64);
835
Chris Mason7bb86312007-12-11 09:25:06 -0500836BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
837BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref,
Chris Mason74493f72007-12-11 09:25:06 -0500838 generation, 64);
Chris Mason7bb86312007-12-11 09:25:06 -0500839BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref,
840 objectid, 64);
841BTRFS_SETGET_STACK_FUNCS(stack_ref_offset, struct btrfs_extent_ref, offset, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400842
843BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
844 refs, 32);
Chris Mason5f39d392007-10-15 16:14:19 -0400845
846/* struct btrfs_node */
847BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
Chris Mason74493f72007-12-11 09:25:06 -0500848BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400849
850static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400851{
Chris Mason5f39d392007-10-15 16:14:19 -0400852 unsigned long ptr;
853 ptr = offsetof(struct btrfs_node, ptrs) +
854 sizeof(struct btrfs_key_ptr) * nr;
855 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
Chris Mason1e1d2702007-03-15 19:03:33 -0400856}
857
Chris Mason5f39d392007-10-15 16:14:19 -0400858static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
859 int nr, u64 val)
Chris Mason31f3c992007-04-30 15:25:45 -0400860{
Chris Mason5f39d392007-10-15 16:14:19 -0400861 unsigned long ptr;
862 ptr = offsetof(struct btrfs_node, ptrs) +
863 sizeof(struct btrfs_key_ptr) * nr;
864 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
Chris Mason31f3c992007-04-30 15:25:45 -0400865}
866
Chris Mason74493f72007-12-11 09:25:06 -0500867static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
868{
869 unsigned long ptr;
870 ptr = offsetof(struct btrfs_node, ptrs) +
871 sizeof(struct btrfs_key_ptr) * nr;
872 return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
873}
874
875static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
876 int nr, u64 val)
877{
878 unsigned long ptr;
879 ptr = offsetof(struct btrfs_node, ptrs) +
880 sizeof(struct btrfs_key_ptr) * nr;
881 btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
882}
883
Chris Mason810191f2007-10-15 16:18:55 -0400884static inline unsigned long btrfs_node_key_ptr_offset(int nr)
Chris Mason31f3c992007-04-30 15:25:45 -0400885{
Chris Mason5f39d392007-10-15 16:14:19 -0400886 return offsetof(struct btrfs_node, ptrs) +
887 sizeof(struct btrfs_key_ptr) * nr;
Chris Mason31f3c992007-04-30 15:25:45 -0400888}
889
Chris Masone644d022007-11-06 15:09:29 -0500890void btrfs_node_key(struct extent_buffer *eb,
891 struct btrfs_disk_key *disk_key, int nr);
892
Chris Mason5f39d392007-10-15 16:14:19 -0400893static inline void btrfs_set_node_key(struct extent_buffer *eb,
894 struct btrfs_disk_key *disk_key, int nr)
895{
896 unsigned long ptr;
897 ptr = btrfs_node_key_ptr_offset(nr);
898 write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
899 struct btrfs_key_ptr, key, disk_key);
Chris Mason1e1d2702007-03-15 19:03:33 -0400900}
901
Chris Mason5f39d392007-10-15 16:14:19 -0400902/* struct btrfs_item */
903BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
904BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
905
906static inline unsigned long btrfs_item_nr_offset(int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400907{
Chris Mason5f39d392007-10-15 16:14:19 -0400908 return offsetof(struct btrfs_leaf, items) +
909 sizeof(struct btrfs_item) * nr;
Chris Mason1e1d2702007-03-15 19:03:33 -0400910}
911
Chris Mason5f39d392007-10-15 16:14:19 -0400912static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
913 int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400914{
Chris Mason5f39d392007-10-15 16:14:19 -0400915 return (struct btrfs_item *)btrfs_item_nr_offset(nr);
Chris Mason1e1d2702007-03-15 19:03:33 -0400916}
917
Chris Mason5f39d392007-10-15 16:14:19 -0400918static inline u32 btrfs_item_end(struct extent_buffer *eb,
919 struct btrfs_item *item)
Chris Mason1e1d2702007-03-15 19:03:33 -0400920{
Chris Mason5f39d392007-10-15 16:14:19 -0400921 return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
Chris Mason1e1d2702007-03-15 19:03:33 -0400922}
923
Chris Mason5f39d392007-10-15 16:14:19 -0400924static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400925{
Chris Mason5f39d392007-10-15 16:14:19 -0400926 return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
Chris Mason1e1d2702007-03-15 19:03:33 -0400927}
928
Chris Mason5f39d392007-10-15 16:14:19 -0400929static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400930{
Chris Mason5f39d392007-10-15 16:14:19 -0400931 return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
Chris Mason1e1d2702007-03-15 19:03:33 -0400932}
933
Chris Mason5f39d392007-10-15 16:14:19 -0400934static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400935{
Chris Mason5f39d392007-10-15 16:14:19 -0400936 return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
Chris Mason1e1d2702007-03-15 19:03:33 -0400937}
938
Chris Mason5f39d392007-10-15 16:14:19 -0400939static inline void btrfs_item_key(struct extent_buffer *eb,
940 struct btrfs_disk_key *disk_key, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400941{
Chris Mason5f39d392007-10-15 16:14:19 -0400942 struct btrfs_item *item = btrfs_item_nr(eb, nr);
943 read_eb_member(eb, item, struct btrfs_item, key, disk_key);
Chris Mason1e1d2702007-03-15 19:03:33 -0400944}
945
Chris Mason5f39d392007-10-15 16:14:19 -0400946static inline void btrfs_set_item_key(struct extent_buffer *eb,
947 struct btrfs_disk_key *disk_key, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400948{
Chris Mason5f39d392007-10-15 16:14:19 -0400949 struct btrfs_item *item = btrfs_item_nr(eb, nr);
950 write_eb_member(eb, item, struct btrfs_item, key, disk_key);
Chris Mason1e1d2702007-03-15 19:03:33 -0400951}
952
Chris Mason5f39d392007-10-15 16:14:19 -0400953/* struct btrfs_dir_item */
Josef Bacik5103e942007-11-16 11:45:54 -0500954BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
Chris Mason5f39d392007-10-15 16:14:19 -0400955BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
956BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
957
958static inline void btrfs_dir_item_key(struct extent_buffer *eb,
959 struct btrfs_dir_item *item,
960 struct btrfs_disk_key *key)
Chris Mason1e1d2702007-03-15 19:03:33 -0400961{
Chris Mason5f39d392007-10-15 16:14:19 -0400962 read_eb_member(eb, item, struct btrfs_dir_item, location, key);
Chris Mason1e1d2702007-03-15 19:03:33 -0400963}
964
Chris Mason5f39d392007-10-15 16:14:19 -0400965static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
966 struct btrfs_dir_item *item,
967 struct btrfs_disk_key *key)
Chris Mason1e1d2702007-03-15 19:03:33 -0400968{
Chris Mason5f39d392007-10-15 16:14:19 -0400969 write_eb_member(eb, item, struct btrfs_dir_item, location, key);
Chris Mason1e1d2702007-03-15 19:03:33 -0400970}
971
Chris Mason5f39d392007-10-15 16:14:19 -0400972/* struct btrfs_disk_key */
973BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
974 objectid, 64);
975BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
976BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
Chris Mason1d4f6402007-03-15 15:18:43 -0400977
Chris Masone2fa7222007-03-12 16:22:34 -0400978static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
979 struct btrfs_disk_key *disk)
980{
981 cpu->offset = le64_to_cpu(disk->offset);
Chris Mason5f39d392007-10-15 16:14:19 -0400982 cpu->type = disk->type;
Chris Masone2fa7222007-03-12 16:22:34 -0400983 cpu->objectid = le64_to_cpu(disk->objectid);
984}
985
986static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
987 struct btrfs_key *cpu)
988{
989 disk->offset = cpu_to_le64(cpu->offset);
Chris Mason5f39d392007-10-15 16:14:19 -0400990 disk->type = cpu->type;
Chris Masone2fa7222007-03-12 16:22:34 -0400991 disk->objectid = cpu_to_le64(cpu->objectid);
992}
993
Chris Mason5f39d392007-10-15 16:14:19 -0400994static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
995 struct btrfs_key *key, int nr)
Chris Masone2fa7222007-03-12 16:22:34 -0400996{
Chris Mason5f39d392007-10-15 16:14:19 -0400997 struct btrfs_disk_key disk_key;
998 btrfs_node_key(eb, &disk_key, nr);
999 btrfs_disk_key_to_cpu(key, &disk_key);
Chris Masone2fa7222007-03-12 16:22:34 -04001000}
1001
Chris Mason5f39d392007-10-15 16:14:19 -04001002static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
1003 struct btrfs_key *key, int nr)
Chris Masone2fa7222007-03-12 16:22:34 -04001004{
Chris Mason5f39d392007-10-15 16:14:19 -04001005 struct btrfs_disk_key disk_key;
1006 btrfs_item_key(eb, &disk_key, nr);
1007 btrfs_disk_key_to_cpu(key, &disk_key);
Chris Masone2fa7222007-03-12 16:22:34 -04001008}
1009
Chris Mason5f39d392007-10-15 16:14:19 -04001010static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
1011 struct btrfs_dir_item *item,
1012 struct btrfs_key *key)
Chris Masone2fa7222007-03-12 16:22:34 -04001013{
Chris Mason5f39d392007-10-15 16:14:19 -04001014 struct btrfs_disk_key disk_key;
1015 btrfs_dir_item_key(eb, item, &disk_key);
1016 btrfs_disk_key_to_cpu(key, &disk_key);
Chris Masone2fa7222007-03-12 16:22:34 -04001017}
1018
Chris Mason5f39d392007-10-15 16:14:19 -04001019
1020static inline u8 btrfs_key_type(struct btrfs_key *key)
Chris Masone2fa7222007-03-12 16:22:34 -04001021{
Chris Mason5f39d392007-10-15 16:14:19 -04001022 return key->type;
Chris Masone2fa7222007-03-12 16:22:34 -04001023}
1024
Chris Mason5f39d392007-10-15 16:14:19 -04001025static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
Chris Masone2fa7222007-03-12 16:22:34 -04001026{
Chris Mason5f39d392007-10-15 16:14:19 -04001027 key->type = val;
Chris Masone2fa7222007-03-12 16:22:34 -04001028}
1029
Chris Mason5f39d392007-10-15 16:14:19 -04001030/* struct btrfs_header */
Chris Masondb945352007-10-15 16:15:53 -04001031BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
Chris Mason5f39d392007-10-15 16:14:19 -04001032BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
1033 generation, 64);
1034BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
1035BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
1036BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 16);
1037BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
1038
1039static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
Chris Masone2fa7222007-03-12 16:22:34 -04001040{
Chris Mason5f39d392007-10-15 16:14:19 -04001041 unsigned long ptr = offsetof(struct btrfs_header, fsid);
1042 return (u8 *)ptr;
Chris Masone2fa7222007-03-12 16:22:34 -04001043}
1044
Chris Mason5f39d392007-10-15 16:14:19 -04001045static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
Chris Masona429e512007-04-18 16:15:28 -04001046{
Chris Mason5f39d392007-10-15 16:14:19 -04001047 unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
1048 return (u8 *)ptr;
Chris Masona429e512007-04-18 16:15:28 -04001049}
1050
Chris Mason5f39d392007-10-15 16:14:19 -04001051static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
Chris Masona429e512007-04-18 16:15:28 -04001052{
Chris Mason5f39d392007-10-15 16:14:19 -04001053 unsigned long ptr = offsetof(struct btrfs_header, csum);
1054 return (u8 *)ptr;
Chris Masona429e512007-04-18 16:15:28 -04001055}
1056
Chris Mason5f39d392007-10-15 16:14:19 -04001057static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
Chris Masona429e512007-04-18 16:15:28 -04001058{
Chris Mason5f39d392007-10-15 16:14:19 -04001059 return NULL;
Chris Masona429e512007-04-18 16:15:28 -04001060}
1061
Chris Mason5f39d392007-10-15 16:14:19 -04001062static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
Chris Masona429e512007-04-18 16:15:28 -04001063{
Chris Mason5f39d392007-10-15 16:14:19 -04001064 return NULL;
Chris Masona429e512007-04-18 16:15:28 -04001065}
1066
Chris Mason5f39d392007-10-15 16:14:19 -04001067static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
Chris Mason7518a232007-03-12 12:01:18 -04001068{
Chris Mason5f39d392007-10-15 16:14:19 -04001069 return NULL;
Chris Mason7518a232007-03-12 12:01:18 -04001070}
1071
Chris Mason5f39d392007-10-15 16:14:19 -04001072static inline int btrfs_is_leaf(struct extent_buffer *eb)
Chris Mason7518a232007-03-12 12:01:18 -04001073{
Chris Mason5f39d392007-10-15 16:14:19 -04001074 return (btrfs_header_level(eb) == 0);
Chris Mason7518a232007-03-12 12:01:18 -04001075}
1076
Chris Mason5f39d392007-10-15 16:14:19 -04001077/* struct btrfs_root_item */
1078BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
Chris Masondb945352007-10-15 16:15:53 -04001079BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
1080BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
Chris Mason5f39d392007-10-15 16:14:19 -04001081
Chris Masondb945352007-10-15 16:15:53 -04001082BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
1083BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
Chris Mason5f39d392007-10-15 16:14:19 -04001084BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
1085BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
1086BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
Chris Masondb945352007-10-15 16:15:53 -04001087BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
1088BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
Chris Mason5f39d392007-10-15 16:14:19 -04001089
1090/* struct btrfs_super_block */
Chris Masondb945352007-10-15 16:15:53 -04001091BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
Chris Mason5f39d392007-10-15 16:14:19 -04001092BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
1093 generation, 64);
1094BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
Chris Mason0b86a832008-03-24 15:01:56 -04001095BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
1096 struct btrfs_super_block, sys_chunk_array_size, 32);
Chris Masondb945352007-10-15 16:15:53 -04001097BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
1098 root_level, 8);
Chris Mason0b86a832008-03-24 15:01:56 -04001099BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
1100 chunk_root, 64);
1101BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
1102 chunk_root_level, 64);
Chris Masondb945352007-10-15 16:15:53 -04001103BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
1104 total_bytes, 64);
1105BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
1106 bytes_used, 64);
Chris Mason5f39d392007-10-15 16:14:19 -04001107BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
1108 sectorsize, 32);
1109BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
1110 nodesize, 32);
1111BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
1112 leafsize, 32);
Chris Mason87ee04e2007-11-30 11:30:34 -05001113BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
1114 stripesize, 32);
Chris Mason5f39d392007-10-15 16:14:19 -04001115BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
1116 root_dir_objectid, 64);
1117
1118static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
Chris Mason7f5c1512007-03-23 15:56:19 -04001119{
Chris Mason5f39d392007-10-15 16:14:19 -04001120 return offsetof(struct btrfs_leaf, items);
Chris Mason7f5c1512007-03-23 15:56:19 -04001121}
1122
Chris Mason5f39d392007-10-15 16:14:19 -04001123/* struct btrfs_file_extent_item */
1124BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
Chris Mason7f5c1512007-03-23 15:56:19 -04001125
Chris Mason5f39d392007-10-15 16:14:19 -04001126static inline unsigned long btrfs_file_extent_inline_start(struct
Chris Mason236454df2007-04-19 13:37:44 -04001127 btrfs_file_extent_item *e)
1128{
Chris Mason5f39d392007-10-15 16:14:19 -04001129 unsigned long offset = (unsigned long)e;
Chris Masondb945352007-10-15 16:15:53 -04001130 offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
Chris Mason5f39d392007-10-15 16:14:19 -04001131 return offset;
Chris Mason236454df2007-04-19 13:37:44 -04001132}
1133
1134static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
1135{
Chris Masondb945352007-10-15 16:15:53 -04001136 return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
Chris Mason236454df2007-04-19 13:37:44 -04001137}
1138
Chris Mason5f39d392007-10-15 16:14:19 -04001139static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
1140 struct btrfs_item *e)
Chris Mason236454df2007-04-19 13:37:44 -04001141{
Chris Mason5f39d392007-10-15 16:14:19 -04001142 unsigned long offset;
Chris Masondb945352007-10-15 16:15:53 -04001143 offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
Chris Mason5f39d392007-10-15 16:14:19 -04001144 return btrfs_item_size(eb, e) - offset;
Chris Mason236454df2007-04-19 13:37:44 -04001145}
1146
Chris Masondb945352007-10-15 16:15:53 -04001147BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
1148 disk_bytenr, 64);
Chris Mason5f39d392007-10-15 16:14:19 -04001149BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
1150 generation, 64);
Chris Masondb945352007-10-15 16:15:53 -04001151BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
1152 disk_num_bytes, 64);
Chris Mason5f39d392007-10-15 16:14:19 -04001153BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
1154 offset, 64);
Chris Masondb945352007-10-15 16:15:53 -04001155BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
1156 num_bytes, 64);
Chris Mason9f5fae22007-03-20 14:38:32 -04001157
Chris Masone20d96d2007-03-22 12:13:20 -04001158static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
1159{
1160 return sb->s_fs_info;
1161}
1162
Josef Bacik58176a92007-08-29 15:47:34 -04001163static inline int btrfs_set_root_name(struct btrfs_root *root,
1164 const char *name, int len)
1165{
1166 /* if we already have a name just free it */
1167 if (root->name)
1168 kfree(root->name);
1169
1170 root->name = kmalloc(len+1, GFP_KERNEL);
1171 if (!root->name)
1172 return -ENOMEM;
1173
1174 memcpy(root->name, name, len);
1175 root->name[len] ='\0';
1176
1177 return 0;
1178}
1179
Chris Masondb945352007-10-15 16:15:53 -04001180static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
1181 if (level == 0)
1182 return root->leafsize;
1183 return root->nodesize;
1184}
1185
Chris Mason4beb1b82007-03-14 10:31:29 -04001186/* helper function to cast into the data area of the leaf. */
1187#define btrfs_item_ptr(leaf, slot, type) \
Chris Mason123abc82007-03-14 14:14:43 -04001188 ((type *)(btrfs_leaf_data(leaf) + \
Chris Mason5f39d392007-10-15 16:14:19 -04001189 btrfs_item_offset_nr(leaf, slot)))
1190
1191#define btrfs_item_ptr_offset(leaf, slot) \
1192 ((unsigned long)(btrfs_leaf_data(leaf) + \
1193 btrfs_item_offset_nr(leaf, slot)))
Chris Mason4beb1b82007-03-14 10:31:29 -04001194
Chris Mason6da6aba2007-12-18 16:15:09 -05001195static inline struct dentry *fdentry(struct file *file) {
1196#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
1197 return file->f_dentry;
1198#else
1199 return file->f_path.dentry;
1200#endif
1201}
1202
Chris Masonb18c6682007-04-17 13:26:50 -04001203/* extent-tree.c */
Chris Masonbe20aa92007-12-17 20:14:01 -05001204u32 btrfs_count_snapshots_in_path(struct btrfs_root *root,
1205 struct btrfs_path *count_path,
1206 u64 first_extent);
Chris Masone9d0b132007-08-10 14:06:19 -04001207int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
1208 struct btrfs_root *root);
Chris Masond1310b22008-01-24 16:13:08 -05001209int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
Chris Mason5276aed2007-06-11 21:33:38 -04001210struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
1211 btrfs_fs_info *info,
Chris Masondb945352007-10-15 16:15:53 -04001212 u64 bytenr);
Chris Mason31f3c992007-04-30 15:25:45 -04001213struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
1214 struct btrfs_block_group_cache
Chris Masonbe744172007-05-06 10:15:01 -04001215 *hint, u64 search_start,
Chris Masonde428b62007-05-18 13:28:27 -04001216 int data, int owner);
Chris Masonc5739bb2007-04-10 09:27:04 -04001217int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
Chris Mason7bb86312007-12-11 09:25:06 -05001218 struct btrfs_root *root, u64 owner_objectid);
Chris Mason5f39d392007-10-15 16:14:19 -04001219struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
Chris Masondb945352007-10-15 16:15:53 -04001220 struct btrfs_root *root, u32 size,
Chris Mason7bb86312007-12-11 09:25:06 -05001221 u64 root_objectid,
Chris Masondb945352007-10-15 16:15:53 -04001222 u64 hint, u64 empty_size);
Chris Mason7bb86312007-12-11 09:25:06 -05001223struct extent_buffer *__btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1224 struct btrfs_root *root,
1225 u32 blocksize,
1226 u64 root_objectid,
1227 u64 ref_generation,
1228 u64 first_objectid,
1229 int level,
1230 u64 hint,
1231 u64 empty_size);
Chris Masonedbd8d42007-12-21 16:27:24 -05001232int btrfs_grow_extent_tree(struct btrfs_trans_handle *trans,
1233 struct btrfs_root *root, u64 new_size);
1234int btrfs_shrink_extent_tree(struct btrfs_root *root, u64 new_size);
Chris Mason7bb86312007-12-11 09:25:06 -05001235int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans,
1236 struct btrfs_root *root,
1237 struct btrfs_path *path, u64 bytenr,
1238 u64 root_objectid, u64 ref_generation,
1239 u64 owner, u64 owner_offset);
Chris Mason4d775672007-04-20 20:23:12 -04001240int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
Chris Mason7bb86312007-12-11 09:25:06 -05001241 struct btrfs_root *root,
1242 u64 num_bytes, u64 root_objectid, u64 ref_generation,
1243 u64 owner, u64 owner_offset,
1244 u64 empty_size, u64 hint_byte,
Chris Masonbe08c1b2007-05-03 09:06:49 -04001245 u64 search_end, struct btrfs_key *ins, int data);
Chris Masone089f052007-03-16 16:20:31 -04001246int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
Chris Mason5f39d392007-10-15 16:14:19 -04001247 struct extent_buffer *buf);
Chris Masone089f052007-03-16 16:20:31 -04001248int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Mason7bb86312007-12-11 09:25:06 -05001249 *root, u64 bytenr, u64 num_bytes,
1250 u64 root_objectid, u64 ref_generation,
1251 u64 owner_objectid, u64 owner_offset, int pin);
Chris Masonccd467d2007-06-28 15:57:36 -04001252int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
1253 struct btrfs_root *root,
Chris Masond1310b22008-01-24 16:13:08 -05001254 struct extent_io_tree *unpin);
Chris Masonb18c6682007-04-17 13:26:50 -04001255int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
1256 struct btrfs_root *root,
Chris Mason7bb86312007-12-11 09:25:06 -05001257 u64 bytenr, u64 num_bytes,
1258 u64 root_objectid, u64 ref_generation,
1259 u64 owner, u64 owner_offset);
Chris Mason9078a3e2007-04-26 16:46:15 -04001260int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1261 struct btrfs_root *root);
1262int btrfs_free_block_groups(struct btrfs_fs_info *info);
1263int btrfs_read_block_groups(struct btrfs_root *root);
Chris Mason0b86a832008-03-24 15:01:56 -04001264int btrfs_make_block_group(struct btrfs_trans_handle *trans,
1265 struct btrfs_root *root, u64 bytes_used,
1266 u64 type, u64 chunk_tree, u64 chunk_objectid,
1267 u64 size);
Chris Masondee26a92007-03-26 16:00:06 -04001268/* ctree.c */
Chris Mason0b86a832008-03-24 15:01:56 -04001269int btrfs_previous_item(struct btrfs_root *root,
1270 struct btrfs_path *path, u64 min_objectid,
1271 int type);
Chris Mason5f39d392007-10-15 16:14:19 -04001272int btrfs_cow_block(struct btrfs_trans_handle *trans,
1273 struct btrfs_root *root, struct extent_buffer *buf,
1274 struct extent_buffer *parent, int parent_slot,
1275 struct extent_buffer **cow_ret);
Chris Masonbe20aa92007-12-17 20:14:01 -05001276int btrfs_copy_root(struct btrfs_trans_handle *trans,
1277 struct btrfs_root *root,
1278 struct extent_buffer *buf,
1279 struct extent_buffer **cow_ret, u64 new_root_objectid);
Chris Mason6567e832007-04-16 09:22:45 -04001280int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1281 *root, struct btrfs_path *path, u32 data_size);
Chris Masonb18c6682007-04-17 13:26:50 -04001282int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1283 struct btrfs_root *root,
1284 struct btrfs_path *path,
Chris Mason179e29e2007-11-01 11:28:41 -04001285 u32 new_size, int from_end);
Chris Masone089f052007-03-16 16:20:31 -04001286int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1287 *root, struct btrfs_key *key, struct btrfs_path *p, int
1288 ins_len, int cow);
Chris Mason6702ed42007-08-07 16:15:09 -04001289int btrfs_realloc_node(struct btrfs_trans_handle *trans,
Chris Mason5f39d392007-10-15 16:14:19 -04001290 struct btrfs_root *root, struct extent_buffer *parent,
Chris Masona6b6e752007-10-15 16:22:39 -04001291 int start_slot, int cache_only, u64 *last_ret,
1292 struct btrfs_key *progress);
Chris Mason234b63a2007-03-13 10:46:10 -04001293void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
Chris Mason2c90e5d2007-04-02 10:50:19 -04001294struct btrfs_path *btrfs_alloc_path(void);
1295void btrfs_free_path(struct btrfs_path *p);
Chris Mason234b63a2007-03-13 10:46:10 -04001296void btrfs_init_path(struct btrfs_path *p);
Chris Mason85e21ba2008-01-29 15:11:36 -05001297int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1298 struct btrfs_path *path, int slot, int nr);
1299
1300static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
1301 struct btrfs_root *root,
1302 struct btrfs_path *path)
1303{
1304 return btrfs_del_items(trans, root, path, path->slots[0], 1);
1305}
1306
Chris Masone089f052007-03-16 16:20:31 -04001307int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1308 *root, struct btrfs_key *key, void *data, u32 data_size);
Chris Mason9c583092008-01-29 15:15:18 -05001309int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
1310 struct btrfs_root *root,
1311 struct btrfs_path *path,
1312 struct btrfs_key *cpu_key, u32 *data_size, int nr);
1313
1314static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
1315 struct btrfs_root *root,
1316 struct btrfs_path *path,
1317 struct btrfs_key *key,
1318 u32 data_size)
1319{
1320 return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
1321}
1322
Chris Mason234b63a2007-03-13 10:46:10 -04001323int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
Chris Mason7bb86312007-12-11 09:25:06 -05001324int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
Chris Mason5f39d392007-10-15 16:14:19 -04001325int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
Chris Masone089f052007-03-16 16:20:31 -04001326int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Mason9f3a7422007-08-07 15:52:19 -04001327 *root);
Chris Masondee26a92007-03-26 16:00:06 -04001328/* root-item.c */
Chris Masone089f052007-03-16 16:20:31 -04001329int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1330 struct btrfs_key *key);
1331int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1332 *root, struct btrfs_key *key, struct btrfs_root_item
1333 *item);
1334int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1335 *root, struct btrfs_key *key, struct btrfs_root_item
1336 *item);
1337int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1338 btrfs_root_item *item, struct btrfs_key *key);
Chris Mason5ce14bb2007-09-11 11:15:39 -04001339int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
1340 struct btrfs_root *latest_root);
Chris Masondee26a92007-03-26 16:00:06 -04001341/* dir-item.c */
Chris Masone089f052007-03-16 16:20:31 -04001342int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Masond6e4a422007-04-06 15:37:36 -04001343 *root, const char *name, int name_len, u64 dir,
1344 struct btrfs_key *location, u8 type);
Chris Mason7e381802007-04-19 15:36:27 -04001345struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
1346 struct btrfs_root *root,
1347 struct btrfs_path *path, u64 dir,
1348 const char *name, int name_len,
1349 int mod);
1350struct btrfs_dir_item *
1351btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
1352 struct btrfs_root *root,
1353 struct btrfs_path *path, u64 dir,
1354 u64 objectid, const char *name, int name_len,
1355 int mod);
1356struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
1357 struct btrfs_path *path,
Chris Mason7f5c1512007-03-23 15:56:19 -04001358 const char *name, int name_len);
Chris Mason7e381802007-04-19 15:36:27 -04001359int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
1360 struct btrfs_root *root,
1361 struct btrfs_path *path,
1362 struct btrfs_dir_item *di);
Josef Bacik5103e942007-11-16 11:45:54 -05001363int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
1364 struct btrfs_root *root, const char *name,
1365 u16 name_len, const void *data, u16 data_len,
1366 u64 dir);
1367struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
1368 struct btrfs_root *root,
1369 struct btrfs_path *path, u64 dir,
1370 const char *name, u16 name_len,
1371 int mod);
Chris Masondee26a92007-03-26 16:00:06 -04001372/* inode-map.c */
Chris Mason9f5fae22007-03-20 14:38:32 -04001373int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1374 struct btrfs_root *fs_root,
1375 u64 dirid, u64 *objectid);
Chris Mason5be6f7f2007-04-05 13:35:25 -04001376int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
1377
Chris Masondee26a92007-03-26 16:00:06 -04001378/* inode-item.c */
Chris Mason39544012007-12-12 14:38:19 -05001379int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
1380 struct btrfs_root *root,
1381 const char *name, int name_len,
1382 u64 inode_objectid, u64 ref_objectid);
1383int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
1384 struct btrfs_root *root,
1385 const char *name, int name_len,
1386 u64 inode_objectid, u64 ref_objectid);
Chris Mason5f39d392007-10-15 16:14:19 -04001387int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
1388 struct btrfs_root *root,
1389 struct btrfs_path *path, u64 objectid);
Chris Mason293ffd52007-03-20 15:57:25 -04001390int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Masond6e4a422007-04-06 15:37:36 -04001391 *root, struct btrfs_path *path,
1392 struct btrfs_key *location, int mod);
Chris Masondee26a92007-03-26 16:00:06 -04001393
1394/* file-item.c */
Chris Masonb18c6682007-04-17 13:26:50 -04001395int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
Chris Masondee26a92007-03-26 16:00:06 -04001396 struct btrfs_root *root,
Chris Masonb18c6682007-04-17 13:26:50 -04001397 u64 objectid, u64 pos, u64 offset,
Chris Masondb945352007-10-15 16:15:53 -04001398 u64 disk_num_bytes,
1399 u64 num_bytes);
Chris Masondee26a92007-03-26 16:00:06 -04001400int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
1401 struct btrfs_root *root,
1402 struct btrfs_path *path, u64 objectid,
Chris Masondb945352007-10-15 16:15:53 -04001403 u64 bytenr, int mod);
Chris Mason065631f2008-02-20 12:07:25 -05001404int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
1405 struct btrfs_root *root, struct inode *inode,
1406 struct bio *bio);
Chris Masonb18c6682007-04-17 13:26:50 -04001407struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
1408 struct btrfs_root *root,
1409 struct btrfs_path *path,
1410 u64 objectid, u64 offset,
1411 int cow);
Chris Mason1de037a2007-05-29 15:17:08 -04001412int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
1413 struct btrfs_root *root, struct btrfs_path *path,
1414 u64 isize);
Chris Mason39279cc2007-06-12 06:35:45 -04001415/* inode.c */
Chris Mason90692182008-02-08 13:49:28 -05001416static inline void dec_i_blocks(struct inode *inode, u64 dec)
1417{
1418 dec = dec >> 9;
1419 if (dec <= inode->i_blocks)
1420 inode->i_blocks -= dec;
1421 else
1422 inode->i_blocks = 0;
1423}
1424
Chris Masonedbd8d42007-12-21 16:27:24 -05001425unsigned long btrfs_force_ra(struct address_space *mapping,
1426 struct file_ra_state *ra, struct file *file,
1427 pgoff_t offset, pgoff_t last_index);
Chris Mason1832a6d2007-12-21 16:27:21 -05001428int btrfs_check_free_space(struct btrfs_root *root, u64 num_required,
1429 int for_del);
Chris Mason9ebefb182007-06-15 13:50:00 -04001430int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page);
1431int btrfs_readpage(struct file *file, struct page *page);
Chris Mason39279cc2007-06-12 06:35:45 -04001432void btrfs_delete_inode(struct inode *inode);
Chris Mason2da98f02008-01-16 11:44:43 -05001433void btrfs_put_inode(struct inode *inode);
Chris Mason39279cc2007-06-12 06:35:45 -04001434void btrfs_read_locked_inode(struct inode *inode);
1435int btrfs_write_inode(struct inode *inode, int wait);
1436void btrfs_dirty_inode(struct inode *inode);
1437struct inode *btrfs_alloc_inode(struct super_block *sb);
1438void btrfs_destroy_inode(struct inode *inode);
1439int btrfs_init_cachep(void);
1440void btrfs_destroy_cachep(void);
Christoph Hellwig34287aa2007-09-14 10:22:47 -04001441long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
Chris Mason39279cc2007-06-12 06:35:45 -04001442struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
1443 struct btrfs_root *root);
Chris Masondc17ff82008-01-08 15:46:30 -05001444struct inode *btrfs_ilookup(struct super_block *s, u64 objectid,
1445 u64 root_objectid);
Chris Mason39279cc2007-06-12 06:35:45 -04001446int btrfs_commit_write(struct file *file, struct page *page,
1447 unsigned from, unsigned to);
Chris Masona52d9a82007-08-27 16:49:44 -04001448struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
1449 size_t page_offset, u64 start, u64 end,
1450 int create);
1451int btrfs_update_inode(struct btrfs_trans_handle *trans,
1452 struct btrfs_root *root,
1453 struct inode *inode);
Chris Mason39279cc2007-06-12 06:35:45 -04001454/* file.c */
Chris Masona52d9a82007-08-27 16:49:44 -04001455int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end);
Chris Mason5f564062008-01-22 16:47:59 -05001456int btrfs_check_file(struct btrfs_root *root, struct inode *inode);
Chris Mason39279cc2007-06-12 06:35:45 -04001457extern struct file_operations btrfs_file_operations;
1458int btrfs_drop_extents(struct btrfs_trans_handle *trans,
1459 struct btrfs_root *root, struct inode *inode,
Chris Mason00f5c792007-11-30 10:09:33 -05001460 u64 start, u64 end, u64 inline_limit, u64 *hint_block);
Chris Mason6702ed42007-08-07 16:15:09 -04001461/* tree-defrag.c */
1462int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
1463 struct btrfs_root *root, int cache_only);
Josef Bacik58176a92007-08-29 15:47:34 -04001464
1465/* sysfs.c */
1466int btrfs_init_sysfs(void);
1467void btrfs_exit_sysfs(void);
1468int btrfs_sysfs_add_super(struct btrfs_fs_info *fs);
1469int btrfs_sysfs_add_root(struct btrfs_root *root);
1470void btrfs_sysfs_del_root(struct btrfs_root *root);
1471void btrfs_sysfs_del_super(struct btrfs_fs_info *root);
1472
Josef Bacik5103e942007-11-16 11:45:54 -05001473/* xattr.c */
1474ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
1475int btrfs_delete_xattrs(struct btrfs_trans_handle *trans,
1476 struct btrfs_root *root, struct inode *inode);
Chris Masonedbd8d42007-12-21 16:27:24 -05001477/* super.c */
1478u64 btrfs_parse_size(char *str);
Chris Masoneb60cea2007-02-02 09:18:22 -05001479#endif