blob: 54c754dd9a148a0bbd7a56dfa713b92e0efc0041 [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 Mason234b63a2007-03-13 10:46:10 -040019#ifndef __BTRFS__
20#define __BTRFS__
Chris Masoneb60cea2007-02-02 09:18:22 -050021
Chris Masone20d96d2007-03-22 12:13:20 -040022#include <linux/fs.h>
Chris Mason08607c12007-06-08 15:33:54 -040023#include <linux/workqueue.h>
Josef Bacik58176a92007-08-29 15:47:34 -040024#include <linux/completion.h>
Chris Mason479965d2007-10-15 16:14:27 -040025#include <asm/kmap_types.h>
Chris Mason8ef97622007-03-26 10:15:30 -040026#include "bit-radix.h"
Chris Mason5f39d392007-10-15 16:14:19 -040027#include "extent_map.h"
Chris Masone20d96d2007-03-22 12:13:20 -040028
Chris Masone089f052007-03-16 16:20:31 -040029struct btrfs_trans_handle;
Chris Mason79154b12007-03-22 15:59:16 -040030struct btrfs_transaction;
Chris Mason35b7e472007-05-02 15:53:43 -040031extern struct kmem_cache *btrfs_trans_handle_cachep;
32extern struct kmem_cache *btrfs_transaction_cachep;
33extern struct kmem_cache *btrfs_bit_radix_cachep;
Chris Mason2c90e5d2007-04-02 10:50:19 -040034extern struct kmem_cache *btrfs_path_cachep;
Chris Masone089f052007-03-16 16:20:31 -040035
Chris Mason5f39d392007-10-15 16:14:19 -040036#define BTRFS_MAGIC "_B2RfS_M"
Chris Masoneb60cea2007-02-02 09:18:22 -050037
Chris Mason6407bf62007-03-27 06:33:00 -040038#define BTRFS_ROOT_TREE_OBJECTID 1ULL
Chris Mason0cf6c622007-06-09 09:22:25 -040039#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
40#define BTRFS_FS_TREE_OBJECTID 3ULL
41#define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL
42#define BTRFS_FIRST_FREE_OBJECTID 5ULL
Chris Mason3768f362007-03-13 16:47:54 -040043
Chris Masonfec577f2007-02-26 10:40:21 -050044/*
Chris Masone20d96d2007-03-22 12:13:20 -040045 * we can actually store much bigger names, but lets not confuse the rest
46 * of linux
47 */
48#define BTRFS_NAME_LEN 255
49
Chris Masonf254e522007-03-29 15:15:27 -040050/* 32 bytes in various csum fields */
51#define BTRFS_CSUM_SIZE 32
Chris Mason509659c2007-05-10 12:36:17 -040052/* four bytes for CRC32 */
53#define BTRFS_CRC32_SIZE 4
Chris Masone06afa82007-05-23 15:44:28 -040054#define BTRFS_EMPTY_DIR_SIZE 6
Chris Masonf254e522007-03-29 15:15:27 -040055
Chris Masonfabb5682007-06-07 22:13:21 -040056#define BTRFS_FT_UNKNOWN 0
57#define BTRFS_FT_REG_FILE 1
58#define BTRFS_FT_DIR 2
59#define BTRFS_FT_CHRDEV 3
60#define BTRFS_FT_BLKDEV 4
61#define BTRFS_FT_FIFO 5
62#define BTRFS_FT_SOCK 6
63#define BTRFS_FT_SYMLINK 7
64#define BTRFS_FT_MAX 8
65
Chris Masone20d96d2007-03-22 12:13:20 -040066/*
Chris Masonfec577f2007-02-26 10:40:21 -050067 * the key defines the order in the tree, and so it also defines (optimal)
68 * block layout. objectid corresonds to the inode number. The flags
69 * tells us things about the object, and is a kind of stream selector.
70 * so for a given inode, keys with flags of 1 might refer to the inode
71 * data, flags of 2 may point to file data in the btree and flags == 3
72 * may point to extents.
73 *
74 * offset is the starting byte offset for this key in the stream.
Chris Masone2fa7222007-03-12 16:22:34 -040075 *
76 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
77 * in cpu native order. Otherwise they are identical and their sizes
78 * should be the same (ie both packed)
Chris Masonfec577f2007-02-26 10:40:21 -050079 */
Chris Masone2fa7222007-03-12 16:22:34 -040080struct btrfs_disk_key {
81 __le64 objectid;
Chris Mason5f39d392007-10-15 16:14:19 -040082 u8 type;
Chris Mason70b2bef2007-04-17 15:39:32 -040083 __le64 offset;
Chris Masone2fa7222007-03-12 16:22:34 -040084} __attribute__ ((__packed__));
85
86struct btrfs_key {
Chris Masoneb60cea2007-02-02 09:18:22 -050087 u64 objectid;
Chris Mason5f39d392007-10-15 16:14:19 -040088 u8 type;
Chris Mason70b2bef2007-04-17 15:39:32 -040089 u64 offset;
Chris Masoneb60cea2007-02-02 09:18:22 -050090} __attribute__ ((__packed__));
91
Chris Mason5f39d392007-10-15 16:14:19 -040092#define BTRFS_FSID_SIZE 16
Chris Masonfec577f2007-02-26 10:40:21 -050093/*
94 * every tree block (leaf or node) starts with this header.
95 */
Chris Masonbb492bb2007-03-12 12:29:44 -040096struct btrfs_header {
Chris Masonf254e522007-03-29 15:15:27 -040097 u8 csum[BTRFS_CSUM_SIZE];
Chris Mason5f39d392007-10-15 16:14:19 -040098 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
Chris Masondb945352007-10-15 16:15:53 -040099 __le64 bytenr; /* which block this node is supposed to live in */
Chris Mason7f5c1512007-03-23 15:56:19 -0400100 __le64 generation;
Chris Mason4d775672007-04-20 20:23:12 -0400101 __le64 owner;
Chris Mason5f39d392007-10-15 16:14:19 -0400102 __le32 nritems;
Chris Masonbb492bb2007-03-12 12:29:44 -0400103 __le16 flags;
Chris Mason9a6f11e2007-03-27 09:06:38 -0400104 u8 level;
Chris Masoneb60cea2007-02-02 09:18:22 -0500105} __attribute__ ((__packed__));
106
Chris Mason234b63a2007-03-13 10:46:10 -0400107#define BTRFS_MAX_LEVEL 8
Chris Mason5f39d392007-10-15 16:14:19 -0400108#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
Chris Mason123abc82007-03-14 14:14:43 -0400109 sizeof(struct btrfs_header)) / \
110 (sizeof(struct btrfs_disk_key) + sizeof(u64)))
111#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
Chris Mason5f39d392007-10-15 16:14:19 -0400112#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
Chris Mason236454d2007-04-19 13:37:44 -0400113#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
114 sizeof(struct btrfs_item) - \
115 sizeof(struct btrfs_file_extent_item))
Chris Masoneb60cea2007-02-02 09:18:22 -0500116
Chris Masonfec577f2007-02-26 10:40:21 -0500117/*
Chris Masonfec577f2007-02-26 10:40:21 -0500118 * the super block basically lists the main trees of the FS
119 * it currently lacks any block count etc etc
120 */
Chris Mason234b63a2007-03-13 10:46:10 -0400121struct btrfs_super_block {
Chris Masonf254e522007-03-29 15:15:27 -0400122 u8 csum[BTRFS_CSUM_SIZE];
Chris Mason87cbda52007-03-28 19:44:27 -0400123 /* the first 3 fields must match struct btrfs_header */
Chris Mason3768f362007-03-13 16:47:54 -0400124 u8 fsid[16]; /* FS specific uuid */
Chris Masondb945352007-10-15 16:15:53 -0400125 __le64 bytenr; /* this block number */
Chris Mason3768f362007-03-13 16:47:54 -0400126 __le64 magic;
Chris Mason3768f362007-03-13 16:47:54 -0400127 __le64 generation;
128 __le64 root;
Chris Masondb945352007-10-15 16:15:53 -0400129 __le64 total_bytes;
130 __le64 bytes_used;
Chris Mason2e635a22007-03-21 11:12:56 -0400131 __le64 root_dir_objectid;
Chris Mason5f39d392007-10-15 16:14:19 -0400132 __le32 sectorsize;
133 __le32 nodesize;
134 __le32 leafsize;
Chris Masondb945352007-10-15 16:15:53 -0400135 u8 root_level;
Chris Masoncfaa7292007-02-21 17:04:57 -0500136} __attribute__ ((__packed__));
137
Chris Masonfec577f2007-02-26 10:40:21 -0500138/*
Chris Mason62e27492007-03-15 12:56:47 -0400139 * A leaf is full of items. offset and size tell us where to find
Chris Masonfec577f2007-02-26 10:40:21 -0500140 * the item in the leaf (relative to the start of the data area)
141 */
Chris Mason0783fcf2007-03-12 20:12:07 -0400142struct btrfs_item {
Chris Masone2fa7222007-03-12 16:22:34 -0400143 struct btrfs_disk_key key;
Chris Mason123abc82007-03-14 14:14:43 -0400144 __le32 offset;
Chris Mason5f39d392007-10-15 16:14:19 -0400145 __le32 size;
Chris Masoneb60cea2007-02-02 09:18:22 -0500146} __attribute__ ((__packed__));
147
Chris Masonfec577f2007-02-26 10:40:21 -0500148/*
149 * leaves have an item area and a data area:
150 * [item0, item1....itemN] [free space] [dataN...data1, data0]
151 *
152 * The data is separate from the items to get the keys closer together
153 * during searches.
154 */
Chris Mason234b63a2007-03-13 10:46:10 -0400155struct btrfs_leaf {
Chris Masonbb492bb2007-03-12 12:29:44 -0400156 struct btrfs_header header;
Chris Mason123abc82007-03-14 14:14:43 -0400157 struct btrfs_item items[];
Chris Masoneb60cea2007-02-02 09:18:22 -0500158} __attribute__ ((__packed__));
159
Chris Masonfec577f2007-02-26 10:40:21 -0500160/*
161 * all non-leaf blocks are nodes, they hold only keys and pointers to
162 * other blocks
163 */
Chris Mason123abc82007-03-14 14:14:43 -0400164struct btrfs_key_ptr {
165 struct btrfs_disk_key key;
166 __le64 blockptr;
167} __attribute__ ((__packed__));
168
Chris Mason234b63a2007-03-13 10:46:10 -0400169struct btrfs_node {
Chris Masonbb492bb2007-03-12 12:29:44 -0400170 struct btrfs_header header;
Chris Mason123abc82007-03-14 14:14:43 -0400171 struct btrfs_key_ptr ptrs[];
Chris Masoneb60cea2007-02-02 09:18:22 -0500172} __attribute__ ((__packed__));
173
Chris Masonfec577f2007-02-26 10:40:21 -0500174/*
Chris Mason234b63a2007-03-13 10:46:10 -0400175 * btrfs_paths remember the path taken from the root down to the leaf.
176 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
Chris Masonfec577f2007-02-26 10:40:21 -0500177 * to any other levels that are present.
178 *
179 * The slots array records the index of the item or block pointer
180 * used while walking the tree.
181 */
Chris Mason234b63a2007-03-13 10:46:10 -0400182struct btrfs_path {
Chris Mason5f39d392007-10-15 16:14:19 -0400183 struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
Chris Mason234b63a2007-03-13 10:46:10 -0400184 int slots[BTRFS_MAX_LEVEL];
Chris Mason3c69fae2007-08-07 15:52:22 -0400185 int reada;
Chris Mason6702ed42007-08-07 16:15:09 -0400186 int lowest_level;
Chris Masoneb60cea2007-02-02 09:18:22 -0500187};
Chris Mason5de08d72007-02-24 06:24:44 -0500188
Chris Mason62e27492007-03-15 12:56:47 -0400189/*
190 * items in the extent btree are used to record the objectid of the
191 * owner of the block and the number of references
192 */
193struct btrfs_extent_item {
194 __le32 refs;
Chris Mason4d775672007-04-20 20:23:12 -0400195 __le64 owner;
Chris Mason62e27492007-03-15 12:56:47 -0400196} __attribute__ ((__packed__));
197
Chris Mason1e1d2702007-03-15 19:03:33 -0400198struct btrfs_inode_timespec {
Chris Masonf254e522007-03-29 15:15:27 -0400199 __le64 sec;
Chris Mason1e1d2702007-03-15 19:03:33 -0400200 __le32 nsec;
201} __attribute__ ((__packed__));
202
203/*
204 * there is no padding here on purpose. If you want to extent the inode,
205 * make a new item type
206 */
207struct btrfs_inode_item {
208 __le64 generation;
209 __le64 size;
210 __le64 nblocks;
Chris Mason31f3c992007-04-30 15:25:45 -0400211 __le64 block_group;
Chris Mason1e1d2702007-03-15 19:03:33 -0400212 __le32 nlink;
213 __le32 uid;
214 __le32 gid;
215 __le32 mode;
216 __le32 rdev;
217 __le16 flags;
218 __le16 compat_flags;
219 struct btrfs_inode_timespec atime;
220 struct btrfs_inode_timespec ctime;
221 struct btrfs_inode_timespec mtime;
222 struct btrfs_inode_timespec otime;
223} __attribute__ ((__packed__));
224
Chris Mason62e27492007-03-15 12:56:47 -0400225struct btrfs_dir_item {
Chris Masond6e4a422007-04-06 15:37:36 -0400226 struct btrfs_disk_key location;
Chris Mason62e27492007-03-15 12:56:47 -0400227 __le16 flags;
Chris Masona8a2ee02007-03-16 08:46:49 -0400228 __le16 name_len;
Chris Mason62e27492007-03-15 12:56:47 -0400229 u8 type;
230} __attribute__ ((__packed__));
231
232struct btrfs_root_item {
Chris Masond6e4a422007-04-06 15:37:36 -0400233 struct btrfs_inode_item inode;
234 __le64 root_dirid;
Chris Masondb945352007-10-15 16:15:53 -0400235 __le64 bytenr;
236 __le64 byte_limit;
237 __le64 bytes_used;
Chris Mason5eda7b52007-06-22 14:16:25 -0400238 __le32 flags;
Chris Mason62e27492007-03-15 12:56:47 -0400239 __le32 refs;
Chris Mason5eda7b52007-06-22 14:16:25 -0400240 struct btrfs_disk_key drop_progress;
241 u8 drop_level;
Chris Masondb945352007-10-15 16:15:53 -0400242 u8 level;
Chris Mason9f5fae22007-03-20 14:38:32 -0400243} __attribute__ ((__packed__));
244
Chris Mason236454d2007-04-19 13:37:44 -0400245#define BTRFS_FILE_EXTENT_REG 0
246#define BTRFS_FILE_EXTENT_INLINE 1
247
Chris Mason9f5fae22007-03-20 14:38:32 -0400248struct btrfs_file_extent_item {
Chris Mason71951f32007-03-27 09:16:29 -0400249 __le64 generation;
Chris Mason236454d2007-04-19 13:37:44 -0400250 u8 type;
Chris Mason9f5fae22007-03-20 14:38:32 -0400251 /*
252 * disk space consumed by the extent, checksum blocks are included
253 * in these numbers
254 */
Chris Masondb945352007-10-15 16:15:53 -0400255 __le64 disk_bytenr;
256 __le64 disk_num_bytes;
Chris Mason9f5fae22007-03-20 14:38:32 -0400257 /*
Chris Masondee26a92007-03-26 16:00:06 -0400258 * the logical offset in file blocks (no csums)
Chris Mason9f5fae22007-03-20 14:38:32 -0400259 * this extent record is for. This allows a file extent to point
260 * into the middle of an existing extent on disk, sharing it
261 * between two snapshots (useful if some bytes in the middle of the
262 * extent have changed
263 */
264 __le64 offset;
265 /*
266 * the logical number of file blocks (no csums included)
267 */
Chris Masondb945352007-10-15 16:15:53 -0400268 __le64 num_bytes;
Chris Mason9f5fae22007-03-20 14:38:32 -0400269} __attribute__ ((__packed__));
270
Chris Masonf254e522007-03-29 15:15:27 -0400271struct btrfs_csum_item {
Chris Mason509659c2007-05-10 12:36:17 -0400272 u8 csum;
Chris Masonf254e522007-03-29 15:15:27 -0400273} __attribute__ ((__packed__));
274
Chris Mason9078a3e2007-04-26 16:46:15 -0400275/* tag for the radix tree of block groups in ram */
Chris Mason9078a3e2007-04-26 16:46:15 -0400276#define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
Chris Mason1e2677e2007-05-29 16:52:18 -0400277
278
279#define BTRFS_BLOCK_GROUP_DATA 1
Chris Mason9078a3e2007-04-26 16:46:15 -0400280struct btrfs_block_group_item {
281 __le64 used;
Chris Mason1e2677e2007-05-29 16:52:18 -0400282 u8 flags;
Chris Mason9078a3e2007-04-26 16:46:15 -0400283} __attribute__ ((__packed__));
284
285struct btrfs_block_group_cache {
286 struct btrfs_key key;
287 struct btrfs_block_group_item item;
Chris Masonbe744172007-05-06 10:15:01 -0400288 int data;
Chris Masone37c9e62007-05-09 20:13:14 -0400289 int cached;
Chris Mason9078a3e2007-04-26 16:46:15 -0400290};
291
Chris Mason9f5fae22007-03-20 14:38:32 -0400292struct btrfs_fs_info {
Chris Mason5f39d392007-10-15 16:14:19 -0400293 u8 fsid[BTRFS_FSID_SIZE];
Chris Mason9f5fae22007-03-20 14:38:32 -0400294 struct btrfs_root *extent_root;
295 struct btrfs_root *tree_root;
Chris Mason0f7d52f2007-04-09 10:42:37 -0400296 struct radix_tree_root fs_roots_radix;
Chris Mason1a5bc162007-10-15 16:15:26 -0400297
Chris Masonf510cfe2007-10-15 16:14:48 -0400298 struct extent_map_tree free_space_cache;
Chris Mason96b51792007-10-15 16:15:19 -0400299 struct extent_map_tree block_group_cache;
Chris Mason1a5bc162007-10-15 16:15:26 -0400300 struct extent_map_tree pinned_extents;
301 struct extent_map_tree pending_del;
302 struct extent_map_tree extent_ins;
303
Chris Mason293ffd52007-03-20 15:57:25 -0400304 u64 generation;
Josef Bacik15ee9bc2007-08-10 16:22:09 -0400305 u64 last_trans_committed;
Chris Mason79154b12007-03-22 15:59:16 -0400306 struct btrfs_transaction *running_transaction;
Chris Mason4b52dff2007-06-26 10:06:50 -0400307 struct btrfs_super_block super_copy;
Chris Mason5f39d392007-10-15 16:14:19 -0400308 struct extent_buffer *sb_buffer;
Chris Masone20d96d2007-03-22 12:13:20 -0400309 struct super_block *sb;
Chris Masond98237b2007-03-28 13:57:48 -0400310 struct inode *btree_inode;
Chris Mason79154b12007-03-22 15:59:16 -0400311 struct mutex trans_mutex;
Chris Masond561c022007-03-23 19:47:49 -0400312 struct mutex fs_mutex;
Chris Mason8fd17792007-04-19 21:01:03 -0400313 struct list_head trans_list;
Chris Masonfacda1e2007-06-08 18:11:48 -0400314 struct list_head dead_roots;
Chris Mason08607c12007-06-08 15:33:54 -0400315 struct delayed_work trans_work;
Josef Bacik58176a92007-08-29 15:47:34 -0400316 struct kobject super_kobj;
317 struct completion kobj_unregister;
Chris Masone66f7092007-04-20 13:16:02 -0400318 int do_barriers;
Chris Masonfacda1e2007-06-08 18:11:48 -0400319 int closing;
Chris Mason62e27492007-03-15 12:56:47 -0400320};
321
322/*
323 * in ram representation of the tree. extent_root is used for all allocations
Chris Masonf2458e12007-04-25 15:52:25 -0400324 * and for the extent tree extent_root root.
Chris Mason62e27492007-03-15 12:56:47 -0400325 */
326struct btrfs_root {
Chris Mason5f39d392007-10-15 16:14:19 -0400327 struct extent_buffer *node;
328 struct extent_buffer *commit_root;
Chris Mason62e27492007-03-15 12:56:47 -0400329 struct btrfs_root_item root_item;
330 struct btrfs_key root_key;
Chris Mason9f5fae22007-03-20 14:38:32 -0400331 struct btrfs_fs_info *fs_info;
Chris Mason0f7d52f2007-04-09 10:42:37 -0400332 struct inode *inode;
Josef Bacik58176a92007-08-29 15:47:34 -0400333 struct kobject root_kobj;
334 struct completion kobj_unregister;
Chris Mason011410b2007-09-10 19:58:36 -0400335 struct rw_semaphore snap_sem;
Chris Mason0f7d52f2007-04-09 10:42:37 -0400336 u64 objectid;
337 u64 last_trans;
Chris Mason5f39d392007-10-15 16:14:19 -0400338
339 /* data allocations are done in sectorsize units */
340 u32 sectorsize;
341
342 /* node allocations are done in nodesize units */
343 u32 nodesize;
344
345 /* leaf allocations are done in leafsize units */
346 u32 leafsize;
347
Chris Mason9f5fae22007-03-20 14:38:32 -0400348 u32 type;
Chris Mason1b05da22007-04-10 12:13:09 -0400349 u64 highest_inode;
350 u64 last_inode_alloc;
Chris Mason9f3a7422007-08-07 15:52:19 -0400351 int ref_cows;
Chris Mason6702ed42007-08-07 16:15:09 -0400352 struct btrfs_key defrag_progress;
353 int defrag_running;
354 int defrag_level;
Josef Bacik58176a92007-08-29 15:47:34 -0400355 char *name;
Chris Mason62e27492007-03-15 12:56:47 -0400356};
357
Chris Mason1e1d2702007-03-15 19:03:33 -0400358/*
359 * inode items have the data typically returned from stat and store other
360 * info about object characteristics. There is one for every file and dir in
361 * the FS
362 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400363#define BTRFS_INODE_ITEM_KEY 1
364
365/* reserve 2-15 close to the inode for later flexibility */
Chris Mason1e1d2702007-03-15 19:03:33 -0400366
367/*
368 * dir items are the name -> inode pointers in a directory. There is one
369 * for every name in a directory.
370 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400371#define BTRFS_DIR_ITEM_KEY 16
372#define BTRFS_DIR_INDEX_KEY 17
Chris Mason1e1d2702007-03-15 19:03:33 -0400373/*
Chris Mason9078a3e2007-04-26 16:46:15 -0400374 * extent data is for file data
Chris Mason1e1d2702007-03-15 19:03:33 -0400375 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400376#define BTRFS_EXTENT_DATA_KEY 18
Chris Mason1e1d2702007-03-15 19:03:33 -0400377/*
Chris Masonf254e522007-03-29 15:15:27 -0400378 * csum items have the checksums for data in the extents
379 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400380#define BTRFS_CSUM_ITEM_KEY 19
381
382/* reserve 20-31 for other file stuff */
Chris Masonf254e522007-03-29 15:15:27 -0400383
384/*
Chris Mason1e1d2702007-03-15 19:03:33 -0400385 * root items point to tree roots. There are typically in the root
386 * tree used by the super block to find all the other trees
387 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400388#define BTRFS_ROOT_ITEM_KEY 32
Chris Mason1e1d2702007-03-15 19:03:33 -0400389/*
390 * extent items are in the extent map tree. These record which blocks
391 * are used, and how many references there are to each block
392 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400393#define BTRFS_EXTENT_ITEM_KEY 33
394
395/*
396 * block groups give us hints into the extent allocation trees. Which
397 * blocks are free etc etc
398 */
399#define BTRFS_BLOCK_GROUP_ITEM_KEY 34
Chris Mason9f5fae22007-03-20 14:38:32 -0400400
401/*
Chris Mason1e1d2702007-03-15 19:03:33 -0400402 * string items are for debugging. They just store a short string of
403 * data in the FS
404 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400405#define BTRFS_STRING_ITEM_KEY 253
406
Chris Mason5f39d392007-10-15 16:14:19 -0400407/* some macros to generate set/get funcs for the struct fields. This
408 * assumes there is a lefoo_to_cpu for every type, so lets make a simple
409 * one for u8:
410 */
411#define le8_to_cpu(v) (v)
412#define cpu_to_le8(v) (v)
413#define __le8 u8
Chris Mason9078a3e2007-04-26 16:46:15 -0400414
Chris Mason5f39d392007-10-15 16:14:19 -0400415#define read_eb_member(eb, ptr, type, member, result) ( \
416 read_extent_buffer(eb, (char *)(result), \
417 ((unsigned long)(ptr)) + \
418 offsetof(type, member), \
419 sizeof(((type *)0)->member)))
420
421#define write_eb_member(eb, ptr, type, member, result) ( \
422 write_extent_buffer(eb, (char *)(result), \
423 ((unsigned long)(ptr)) + \
424 offsetof(type, member), \
425 sizeof(((type *)0)->member)))
426
427#define BTRFS_SETGET_FUNCS(name, type, member, bits) \
428static inline u##bits btrfs_##name(struct extent_buffer *eb, \
429 type *s) \
430{ \
Chris Mason479965d2007-10-15 16:14:27 -0400431 int err; \
432 char *map_token; \
433 char *kaddr; \
Chris Masondb945352007-10-15 16:15:53 -0400434 int unmap_on_exit = (eb->map_token == NULL); \
Chris Mason479965d2007-10-15 16:14:27 -0400435 unsigned long map_start; \
436 unsigned long map_len; \
437 unsigned long offset = (unsigned long)s + \
438 offsetof(type, member); \
Chris Mason14048ed2007-10-15 16:16:28 -0400439 if (eb->map_token && offset >= eb->map_start && \
440 offset + sizeof(((type *)0)->member) <= eb->map_start + \
441 eb->map_len) { \
442 kaddr = eb->kaddr; \
443 map_start = eb->map_start; \
444 err = 0; \
445 } else { \
446 err = map_extent_buffer(eb, offset, \
Chris Mason479965d2007-10-15 16:14:27 -0400447 sizeof(((type *)0)->member), \
448 &map_token, &kaddr, \
Chris Masondb945352007-10-15 16:15:53 -0400449 &map_start, &map_len, KM_USER1); \
Chris Mason14048ed2007-10-15 16:16:28 -0400450 } \
Chris Mason479965d2007-10-15 16:14:27 -0400451 if (!err) { \
452 __le##bits *tmp = (__le##bits *)(kaddr + offset - \
453 map_start); \
454 u##bits res = le##bits##_to_cpu(*tmp); \
Chris Masondb945352007-10-15 16:15:53 -0400455 if (unmap_on_exit) \
456 unmap_extent_buffer(eb, map_token, KM_USER1); \
Chris Mason479965d2007-10-15 16:14:27 -0400457 return res; \
458 } else { \
459 __le##bits res; \
460 read_eb_member(eb, s, type, member, &res); \
461 return le##bits##_to_cpu(res); \
462 } \
Chris Mason5f39d392007-10-15 16:14:19 -0400463} \
464static inline void btrfs_set_##name(struct extent_buffer *eb, \
465 type *s, u##bits val) \
466{ \
Chris Mason479965d2007-10-15 16:14:27 -0400467 int err; \
468 char *map_token; \
469 char *kaddr; \
470 unsigned long map_start; \
471 unsigned long map_len; \
Chris Masondb945352007-10-15 16:15:53 -0400472 int unmap_on_exit = (eb->map_token == NULL); \
Chris Mason479965d2007-10-15 16:14:27 -0400473 unsigned long offset = (unsigned long)s + \
474 offsetof(type, member); \
Chris Mason14048ed2007-10-15 16:16:28 -0400475 if (eb->map_token && offset >= eb->map_start && \
476 offset + sizeof(((type *)0)->member) <= eb->map_start + \
477 eb->map_len) { \
478 kaddr = eb->kaddr; \
479 map_start = eb->map_start; \
480 err = 0; \
481 } else { \
482 err = map_extent_buffer(eb, offset, \
Chris Mason479965d2007-10-15 16:14:27 -0400483 sizeof(((type *)0)->member), \
484 &map_token, &kaddr, \
Chris Masondb945352007-10-15 16:15:53 -0400485 &map_start, &map_len, KM_USER1); \
Chris Mason14048ed2007-10-15 16:16:28 -0400486 } \
Chris Mason479965d2007-10-15 16:14:27 -0400487 if (!err) { \
488 __le##bits *tmp = (__le##bits *)(kaddr + offset - \
489 map_start); \
490 *tmp = cpu_to_le##bits(val); \
Chris Masondb945352007-10-15 16:15:53 -0400491 if (unmap_on_exit) \
492 unmap_extent_buffer(eb, map_token, KM_USER1); \
Chris Mason479965d2007-10-15 16:14:27 -0400493 } else { \
494 val = cpu_to_le##bits(val); \
495 write_eb_member(eb, s, type, member, &val); \
496 } \
Chris Mason9078a3e2007-04-26 16:46:15 -0400497}
498
Chris Mason5f39d392007-10-15 16:14:19 -0400499#define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
500static inline u##bits btrfs_##name(struct extent_buffer *eb) \
501{ \
Chris Mason6d36dcd2007-10-15 16:14:37 -0400502 int err; \
503 char *map_token; \
504 char *kaddr; \
505 unsigned long map_start; \
506 unsigned long map_len; \
507 unsigned long offset = offsetof(type, member); \
Chris Masondb945352007-10-15 16:15:53 -0400508 int unmap_on_exit = (eb->map_token == NULL); \
Chris Mason14048ed2007-10-15 16:16:28 -0400509 if (eb->map_token && offset >= eb->map_start && \
510 offset + sizeof(((type *)0)->member) <= eb->map_start + \
511 eb->map_len) { \
512 kaddr = eb->kaddr; \
513 map_start = eb->map_start; \
514 err = 0; \
515 } else { \
516 err = map_extent_buffer(eb, offset, \
Chris Mason6d36dcd2007-10-15 16:14:37 -0400517 sizeof(((type *)0)->member), \
518 &map_token, &kaddr, \
Chris Masondb945352007-10-15 16:15:53 -0400519 &map_start, &map_len, KM_USER1); \
Chris Mason14048ed2007-10-15 16:16:28 -0400520 } \
Chris Mason6d36dcd2007-10-15 16:14:37 -0400521 if (!err) { \
522 __le##bits *tmp = (__le##bits *)(kaddr + offset - \
523 map_start); \
524 u##bits res = le##bits##_to_cpu(*tmp); \
Chris Masondb945352007-10-15 16:15:53 -0400525 if (unmap_on_exit) \
526 unmap_extent_buffer(eb, map_token, KM_USER1); \
Chris Mason6d36dcd2007-10-15 16:14:37 -0400527 return res; \
528 } else { \
529 __le##bits res; \
530 read_eb_member(eb, NULL, type, member, &res); \
531 return le##bits##_to_cpu(res); \
532 } \
Chris Mason5f39d392007-10-15 16:14:19 -0400533} \
534static inline void btrfs_set_##name(struct extent_buffer *eb, \
535 u##bits val) \
536{ \
Chris Mason6d36dcd2007-10-15 16:14:37 -0400537 int err; \
538 char *map_token; \
539 char *kaddr; \
540 unsigned long map_start; \
541 unsigned long map_len; \
542 unsigned long offset = offsetof(type, member); \
Chris Masondb945352007-10-15 16:15:53 -0400543 int unmap_on_exit = (eb->map_token == NULL); \
Chris Mason14048ed2007-10-15 16:16:28 -0400544 if (eb->map_token && offset >= eb->map_start && \
545 offset + sizeof(((type *)0)->member) <= eb->map_start + \
546 eb->map_len) { \
547 kaddr = eb->kaddr; \
548 map_start = eb->map_start; \
549 err = 0; \
550 } else { \
551 err = map_extent_buffer(eb, offset, \
Chris Mason6d36dcd2007-10-15 16:14:37 -0400552 sizeof(((type *)0)->member), \
553 &map_token, &kaddr, \
Chris Masondb945352007-10-15 16:15:53 -0400554 &map_start, &map_len, KM_USER1); \
Chris Mason14048ed2007-10-15 16:16:28 -0400555 } \
Chris Mason6d36dcd2007-10-15 16:14:37 -0400556 if (!err) { \
557 __le##bits *tmp = (__le##bits *)(kaddr + offset - \
558 map_start); \
559 *tmp = cpu_to_le##bits(val); \
Chris Masondb945352007-10-15 16:15:53 -0400560 if (unmap_on_exit) \
561 unmap_extent_buffer(eb, map_token, KM_USER1); \
Chris Mason6d36dcd2007-10-15 16:14:37 -0400562 } else { \
563 val = cpu_to_le##bits(val); \
564 write_eb_member(eb, NULL, type, member, &val); \
565 } \
Chris Mason9078a3e2007-04-26 16:46:15 -0400566}
Chris Mason1e1d2702007-03-15 19:03:33 -0400567
Chris Mason5f39d392007-10-15 16:14:19 -0400568#define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
569static inline u##bits btrfs_##name(type *s) \
570{ \
571 return le##bits##_to_cpu(s->member); \
572} \
573static inline void btrfs_set_##name(type *s, u##bits val) \
574{ \
575 s->member = cpu_to_le##bits(val); \
Chris Mason1e1d2702007-03-15 19:03:33 -0400576}
577
Chris Mason5f39d392007-10-15 16:14:19 -0400578/* struct btrfs_block_group_item */
579BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
580 used, 64);
581BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
582 used, 64);
583
584/* struct btrfs_inode_item */
585BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
586BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
587BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64);
588BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
589BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
590BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
591BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
592BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
593BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 32);
594BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16);
595BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item,
596 compat_flags, 16);
597
598static inline struct btrfs_inode_timespec *
599btrfs_inode_atime(struct btrfs_inode_item *inode_item)
Chris Mason1e1d2702007-03-15 19:03:33 -0400600{
Chris Mason5f39d392007-10-15 16:14:19 -0400601 unsigned long ptr = (unsigned long)inode_item;
602 ptr += offsetof(struct btrfs_inode_item, atime);
603 return (struct btrfs_inode_timespec *)ptr;
Chris Mason1e1d2702007-03-15 19:03:33 -0400604}
605
Chris Mason5f39d392007-10-15 16:14:19 -0400606static inline struct btrfs_inode_timespec *
607btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
Chris Mason1e1d2702007-03-15 19:03:33 -0400608{
Chris Mason5f39d392007-10-15 16:14:19 -0400609 unsigned long ptr = (unsigned long)inode_item;
610 ptr += offsetof(struct btrfs_inode_item, mtime);
611 return (struct btrfs_inode_timespec *)ptr;
Chris Mason1e1d2702007-03-15 19:03:33 -0400612}
613
Chris Mason5f39d392007-10-15 16:14:19 -0400614static inline struct btrfs_inode_timespec *
615btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
Chris Mason1e1d2702007-03-15 19:03:33 -0400616{
Chris Mason5f39d392007-10-15 16:14:19 -0400617 unsigned long ptr = (unsigned long)inode_item;
618 ptr += offsetof(struct btrfs_inode_item, ctime);
619 return (struct btrfs_inode_timespec *)ptr;
Chris Mason1e1d2702007-03-15 19:03:33 -0400620}
621
Chris Mason5f39d392007-10-15 16:14:19 -0400622static inline struct btrfs_inode_timespec *
623btrfs_inode_otime(struct btrfs_inode_item *inode_item)
Chris Mason1e1d2702007-03-15 19:03:33 -0400624{
Chris Mason5f39d392007-10-15 16:14:19 -0400625 unsigned long ptr = (unsigned long)inode_item;
626 ptr += offsetof(struct btrfs_inode_item, otime);
627 return (struct btrfs_inode_timespec *)ptr;
Chris Mason1e1d2702007-03-15 19:03:33 -0400628}
629
Chris Mason5f39d392007-10-15 16:14:19 -0400630BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_inode_timespec, sec, 64);
631BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_inode_timespec, nsec, 32);
632
633/* struct btrfs_extent_item */
634BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
635BTRFS_SETGET_FUNCS(extent_owner, struct btrfs_extent_item, owner, 32);
636
637BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
638 refs, 32);
639BTRFS_SETGET_STACK_FUNCS(stack_extent_owner, struct btrfs_extent_item,
640 owner, 32);
641
642/* struct btrfs_node */
643BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
644
645static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400646{
Chris Mason5f39d392007-10-15 16:14:19 -0400647 unsigned long ptr;
648 ptr = offsetof(struct btrfs_node, ptrs) +
649 sizeof(struct btrfs_key_ptr) * nr;
650 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
Chris Mason1e1d2702007-03-15 19:03:33 -0400651}
652
Chris Mason5f39d392007-10-15 16:14:19 -0400653static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
654 int nr, u64 val)
Chris Mason31f3c992007-04-30 15:25:45 -0400655{
Chris Mason5f39d392007-10-15 16:14:19 -0400656 unsigned long ptr;
657 ptr = offsetof(struct btrfs_node, ptrs) +
658 sizeof(struct btrfs_key_ptr) * nr;
659 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
Chris Mason31f3c992007-04-30 15:25:45 -0400660}
661
Chris Mason5f39d392007-10-15 16:14:19 -0400662static unsigned long btrfs_node_key_ptr_offset(int nr)
Chris Mason31f3c992007-04-30 15:25:45 -0400663{
Chris Mason5f39d392007-10-15 16:14:19 -0400664 return offsetof(struct btrfs_node, ptrs) +
665 sizeof(struct btrfs_key_ptr) * nr;
Chris Mason31f3c992007-04-30 15:25:45 -0400666}
667
Chris Mason5f39d392007-10-15 16:14:19 -0400668static void btrfs_node_key(struct extent_buffer *eb,
669 struct btrfs_disk_key *disk_key, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400670{
Chris Mason5f39d392007-10-15 16:14:19 -0400671 unsigned long ptr;
672 ptr = btrfs_node_key_ptr_offset(nr);
673 read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
674 struct btrfs_key_ptr, key, disk_key);
675}
676static inline void btrfs_set_node_key(struct extent_buffer *eb,
677 struct btrfs_disk_key *disk_key, int nr)
678{
679 unsigned long ptr;
680 ptr = btrfs_node_key_ptr_offset(nr);
681 write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
682 struct btrfs_key_ptr, key, disk_key);
Chris Mason1e1d2702007-03-15 19:03:33 -0400683}
684
Chris Mason5f39d392007-10-15 16:14:19 -0400685/* struct btrfs_item */
686BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
687BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
688
689static inline unsigned long btrfs_item_nr_offset(int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400690{
Chris Mason5f39d392007-10-15 16:14:19 -0400691 return offsetof(struct btrfs_leaf, items) +
692 sizeof(struct btrfs_item) * nr;
Chris Mason1e1d2702007-03-15 19:03:33 -0400693}
694
Chris Mason5f39d392007-10-15 16:14:19 -0400695static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
696 int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400697{
Chris Mason5f39d392007-10-15 16:14:19 -0400698 return (struct btrfs_item *)btrfs_item_nr_offset(nr);
Chris Mason1e1d2702007-03-15 19:03:33 -0400699}
700
Chris Mason5f39d392007-10-15 16:14:19 -0400701static inline u32 btrfs_item_end(struct extent_buffer *eb,
702 struct btrfs_item *item)
Chris Mason1e1d2702007-03-15 19:03:33 -0400703{
Chris Mason5f39d392007-10-15 16:14:19 -0400704 return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
Chris Mason1e1d2702007-03-15 19:03:33 -0400705}
706
Chris Mason5f39d392007-10-15 16:14:19 -0400707static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400708{
Chris Mason5f39d392007-10-15 16:14:19 -0400709 return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
Chris Mason1e1d2702007-03-15 19:03:33 -0400710}
711
Chris Mason5f39d392007-10-15 16:14:19 -0400712static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400713{
Chris Mason5f39d392007-10-15 16:14:19 -0400714 return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
Chris Mason1e1d2702007-03-15 19:03:33 -0400715}
716
Chris Mason5f39d392007-10-15 16:14:19 -0400717static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400718{
Chris Mason5f39d392007-10-15 16:14:19 -0400719 return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
Chris Mason1e1d2702007-03-15 19:03:33 -0400720}
721
Chris Mason5f39d392007-10-15 16:14:19 -0400722static inline void btrfs_item_key(struct extent_buffer *eb,
723 struct btrfs_disk_key *disk_key, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400724{
Chris Mason5f39d392007-10-15 16:14:19 -0400725 struct btrfs_item *item = btrfs_item_nr(eb, nr);
726 read_eb_member(eb, item, struct btrfs_item, key, disk_key);
Chris Mason1e1d2702007-03-15 19:03:33 -0400727}
728
Chris Mason5f39d392007-10-15 16:14:19 -0400729static inline void btrfs_set_item_key(struct extent_buffer *eb,
730 struct btrfs_disk_key *disk_key, int nr)
Chris Mason1e1d2702007-03-15 19:03:33 -0400731{
Chris Mason5f39d392007-10-15 16:14:19 -0400732 struct btrfs_item *item = btrfs_item_nr(eb, nr);
733 write_eb_member(eb, item, struct btrfs_item, key, disk_key);
Chris Mason1e1d2702007-03-15 19:03:33 -0400734}
735
Chris Mason5f39d392007-10-15 16:14:19 -0400736/* struct btrfs_dir_item */
737BTRFS_SETGET_FUNCS(dir_flags, struct btrfs_dir_item, flags, 16);
738BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
739BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
740
741static inline void btrfs_dir_item_key(struct extent_buffer *eb,
742 struct btrfs_dir_item *item,
743 struct btrfs_disk_key *key)
Chris Mason1e1d2702007-03-15 19:03:33 -0400744{
Chris Mason5f39d392007-10-15 16:14:19 -0400745 read_eb_member(eb, item, struct btrfs_dir_item, location, key);
Chris Mason1e1d2702007-03-15 19:03:33 -0400746}
747
Chris Mason5f39d392007-10-15 16:14:19 -0400748static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
749 struct btrfs_dir_item *item,
750 struct btrfs_disk_key *key)
Chris Mason1e1d2702007-03-15 19:03:33 -0400751{
Chris Mason5f39d392007-10-15 16:14:19 -0400752 write_eb_member(eb, item, struct btrfs_dir_item, location, key);
Chris Mason1e1d2702007-03-15 19:03:33 -0400753}
754
Chris Mason5f39d392007-10-15 16:14:19 -0400755/* struct btrfs_disk_key */
756BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
757 objectid, 64);
758BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
759BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
Chris Mason1d4f6402007-03-15 15:18:43 -0400760
Chris Masone2fa7222007-03-12 16:22:34 -0400761static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
762 struct btrfs_disk_key *disk)
763{
764 cpu->offset = le64_to_cpu(disk->offset);
Chris Mason5f39d392007-10-15 16:14:19 -0400765 cpu->type = disk->type;
Chris Masone2fa7222007-03-12 16:22:34 -0400766 cpu->objectid = le64_to_cpu(disk->objectid);
767}
768
769static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
770 struct btrfs_key *cpu)
771{
772 disk->offset = cpu_to_le64(cpu->offset);
Chris Mason5f39d392007-10-15 16:14:19 -0400773 disk->type = cpu->type;
Chris Masone2fa7222007-03-12 16:22:34 -0400774 disk->objectid = cpu_to_le64(cpu->objectid);
775}
776
Chris Mason5f39d392007-10-15 16:14:19 -0400777static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
778 struct btrfs_key *key, int nr)
Chris Masone2fa7222007-03-12 16:22:34 -0400779{
Chris Mason5f39d392007-10-15 16:14:19 -0400780 struct btrfs_disk_key disk_key;
781 btrfs_node_key(eb, &disk_key, nr);
782 btrfs_disk_key_to_cpu(key, &disk_key);
Chris Masone2fa7222007-03-12 16:22:34 -0400783}
784
Chris Mason5f39d392007-10-15 16:14:19 -0400785static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
786 struct btrfs_key *key, int nr)
Chris Masone2fa7222007-03-12 16:22:34 -0400787{
Chris Mason5f39d392007-10-15 16:14:19 -0400788 struct btrfs_disk_key disk_key;
789 btrfs_item_key(eb, &disk_key, nr);
790 btrfs_disk_key_to_cpu(key, &disk_key);
Chris Masone2fa7222007-03-12 16:22:34 -0400791}
792
Chris Mason5f39d392007-10-15 16:14:19 -0400793static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
794 struct btrfs_dir_item *item,
795 struct btrfs_key *key)
Chris Masone2fa7222007-03-12 16:22:34 -0400796{
Chris Mason5f39d392007-10-15 16:14:19 -0400797 struct btrfs_disk_key disk_key;
798 btrfs_dir_item_key(eb, item, &disk_key);
799 btrfs_disk_key_to_cpu(key, &disk_key);
Chris Masone2fa7222007-03-12 16:22:34 -0400800}
801
Chris Mason5f39d392007-10-15 16:14:19 -0400802
803static inline u8 btrfs_key_type(struct btrfs_key *key)
Chris Masone2fa7222007-03-12 16:22:34 -0400804{
Chris Mason5f39d392007-10-15 16:14:19 -0400805 return key->type;
Chris Masone2fa7222007-03-12 16:22:34 -0400806}
807
Chris Mason5f39d392007-10-15 16:14:19 -0400808static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
Chris Masone2fa7222007-03-12 16:22:34 -0400809{
Chris Mason5f39d392007-10-15 16:14:19 -0400810 key->type = val;
Chris Masone2fa7222007-03-12 16:22:34 -0400811}
812
Chris Mason5f39d392007-10-15 16:14:19 -0400813/* struct btrfs_header */
Chris Masondb945352007-10-15 16:15:53 -0400814BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400815BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
816 generation, 64);
817BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
818BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
819BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 16);
820BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
821
822static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
Chris Masone2fa7222007-03-12 16:22:34 -0400823{
Chris Mason5f39d392007-10-15 16:14:19 -0400824 unsigned long ptr = offsetof(struct btrfs_header, fsid);
825 return (u8 *)ptr;
Chris Masone2fa7222007-03-12 16:22:34 -0400826}
827
Chris Mason5f39d392007-10-15 16:14:19 -0400828static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
Chris Masona429e512007-04-18 16:15:28 -0400829{
Chris Mason5f39d392007-10-15 16:14:19 -0400830 unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
831 return (u8 *)ptr;
Chris Masona429e512007-04-18 16:15:28 -0400832}
833
Chris Mason5f39d392007-10-15 16:14:19 -0400834static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
Chris Masona429e512007-04-18 16:15:28 -0400835{
Chris Mason5f39d392007-10-15 16:14:19 -0400836 unsigned long ptr = offsetof(struct btrfs_header, csum);
837 return (u8 *)ptr;
Chris Masona429e512007-04-18 16:15:28 -0400838}
839
Chris Mason5f39d392007-10-15 16:14:19 -0400840static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
Chris Masona429e512007-04-18 16:15:28 -0400841{
Chris Mason5f39d392007-10-15 16:14:19 -0400842 return NULL;
Chris Masona429e512007-04-18 16:15:28 -0400843}
844
Chris Mason5f39d392007-10-15 16:14:19 -0400845static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
Chris Masona429e512007-04-18 16:15:28 -0400846{
Chris Mason5f39d392007-10-15 16:14:19 -0400847 return NULL;
Chris Masona429e512007-04-18 16:15:28 -0400848}
849
Chris Mason5f39d392007-10-15 16:14:19 -0400850static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
Chris Mason7518a232007-03-12 12:01:18 -0400851{
Chris Mason5f39d392007-10-15 16:14:19 -0400852 return NULL;
Chris Mason7518a232007-03-12 12:01:18 -0400853}
854
Chris Mason5f39d392007-10-15 16:14:19 -0400855static inline int btrfs_is_leaf(struct extent_buffer *eb)
Chris Mason7518a232007-03-12 12:01:18 -0400856{
Chris Mason5f39d392007-10-15 16:14:19 -0400857 return (btrfs_header_level(eb) == 0);
Chris Mason7518a232007-03-12 12:01:18 -0400858}
859
Chris Mason5f39d392007-10-15 16:14:19 -0400860/* struct btrfs_root_item */
861BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
Chris Masondb945352007-10-15 16:15:53 -0400862BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
863BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
Chris Mason5f39d392007-10-15 16:14:19 -0400864
Chris Masondb945352007-10-15 16:15:53 -0400865BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
866BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
Chris Mason5f39d392007-10-15 16:14:19 -0400867BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
868BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
869BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
Chris Masondb945352007-10-15 16:15:53 -0400870BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
871BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400872
873/* struct btrfs_super_block */
Chris Masondb945352007-10-15 16:15:53 -0400874BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400875BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
876 generation, 64);
877BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
Chris Masondb945352007-10-15 16:15:53 -0400878BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
879 root_level, 8);
880BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
881 total_bytes, 64);
882BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
883 bytes_used, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400884BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
885 sectorsize, 32);
886BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
887 nodesize, 32);
888BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
889 leafsize, 32);
890BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
891 root_dir_objectid, 64);
892
893static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
Chris Mason7f5c1512007-03-23 15:56:19 -0400894{
Chris Mason5f39d392007-10-15 16:14:19 -0400895 return offsetof(struct btrfs_leaf, items);
Chris Mason7f5c1512007-03-23 15:56:19 -0400896}
897
Chris Mason5f39d392007-10-15 16:14:19 -0400898/* struct btrfs_file_extent_item */
899BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
Chris Mason7f5c1512007-03-23 15:56:19 -0400900
Chris Mason5f39d392007-10-15 16:14:19 -0400901static inline unsigned long btrfs_file_extent_inline_start(struct
Chris Mason236454d2007-04-19 13:37:44 -0400902 btrfs_file_extent_item *e)
903{
Chris Mason5f39d392007-10-15 16:14:19 -0400904 unsigned long offset = (unsigned long)e;
Chris Masondb945352007-10-15 16:15:53 -0400905 offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
Chris Mason5f39d392007-10-15 16:14:19 -0400906 return offset;
Chris Mason236454d2007-04-19 13:37:44 -0400907}
908
909static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
910{
Chris Masondb945352007-10-15 16:15:53 -0400911 return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
Chris Mason236454d2007-04-19 13:37:44 -0400912}
913
Chris Mason5f39d392007-10-15 16:14:19 -0400914static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
915 struct btrfs_item *e)
Chris Mason236454d2007-04-19 13:37:44 -0400916{
Chris Mason5f39d392007-10-15 16:14:19 -0400917 unsigned long offset;
Chris Masondb945352007-10-15 16:15:53 -0400918 offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
Chris Mason5f39d392007-10-15 16:14:19 -0400919 return btrfs_item_size(eb, e) - offset;
Chris Mason236454d2007-04-19 13:37:44 -0400920}
921
Chris Masondb945352007-10-15 16:15:53 -0400922BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
923 disk_bytenr, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400924BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
925 generation, 64);
Chris Masondb945352007-10-15 16:15:53 -0400926BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
927 disk_num_bytes, 64);
Chris Mason5f39d392007-10-15 16:14:19 -0400928BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
929 offset, 64);
Chris Masondb945352007-10-15 16:15:53 -0400930BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
931 num_bytes, 64);
Chris Mason9f5fae22007-03-20 14:38:32 -0400932
Chris Masone20d96d2007-03-22 12:13:20 -0400933static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
934{
935 return sb->s_fs_info;
936}
937
Josef Bacik58176a92007-08-29 15:47:34 -0400938static inline int btrfs_set_root_name(struct btrfs_root *root,
939 const char *name, int len)
940{
941 /* if we already have a name just free it */
942 if (root->name)
943 kfree(root->name);
944
945 root->name = kmalloc(len+1, GFP_KERNEL);
946 if (!root->name)
947 return -ENOMEM;
948
949 memcpy(root->name, name, len);
950 root->name[len] ='\0';
951
952 return 0;
953}
954
Chris Masondb945352007-10-15 16:15:53 -0400955static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
956 if (level == 0)
957 return root->leafsize;
958 return root->nodesize;
959}
960
Chris Mason4beb1b82007-03-14 10:31:29 -0400961/* helper function to cast into the data area of the leaf. */
962#define btrfs_item_ptr(leaf, slot, type) \
Chris Mason123abc82007-03-14 14:14:43 -0400963 ((type *)(btrfs_leaf_data(leaf) + \
Chris Mason5f39d392007-10-15 16:14:19 -0400964 btrfs_item_offset_nr(leaf, slot)))
965
966#define btrfs_item_ptr_offset(leaf, slot) \
967 ((unsigned long)(btrfs_leaf_data(leaf) + \
968 btrfs_item_offset_nr(leaf, slot)))
Chris Mason4beb1b82007-03-14 10:31:29 -0400969
Chris Mason95e05282007-08-29 09:11:44 -0400970/* mount option defines and helpers */
971#define BTRFS_MOUNT_SUBVOL 0x000001
972#define btrfs_clear_opt(o, opt) o &= ~BTRFS_MOUNT_##opt
973#define btrfs_set_opt(o, opt) o |= BTRFS_MOUNT_##opt
974#define btrfs_test_opt(sb, opt) (BTRFS_SB(sb)->s_mount_opt & \
975 BTRFS_MOUNT_##opt)
Chris Masonb18c6682007-04-17 13:26:50 -0400976/* extent-tree.c */
Chris Masone9d0b132007-08-10 14:06:19 -0400977int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
978 struct btrfs_root *root);
Chris Mason1a5bc162007-10-15 16:15:26 -0400979int btrfs_copy_pinned(struct btrfs_root *root, struct extent_map_tree *copy);
Chris Mason5276aed2007-06-11 21:33:38 -0400980struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
981 btrfs_fs_info *info,
Chris Masondb945352007-10-15 16:15:53 -0400982 u64 bytenr);
Chris Mason31f3c992007-04-30 15:25:45 -0400983struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
984 struct btrfs_block_group_cache
Chris Masonbe744172007-05-06 10:15:01 -0400985 *hint, u64 search_start,
Chris Masonde428b62007-05-18 13:28:27 -0400986 int data, int owner);
Chris Masonc5739bb2007-04-10 09:27:04 -0400987int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
988 struct btrfs_root *root);
Chris Mason5f39d392007-10-15 16:14:19 -0400989struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
Chris Masondb945352007-10-15 16:15:53 -0400990 struct btrfs_root *root, u32 size,
991 u64 hint, u64 empty_size);
Chris Mason4d775672007-04-20 20:23:12 -0400992int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
993 struct btrfs_root *root, u64 owner,
Chris Masondb945352007-10-15 16:15:53 -0400994 u64 num_bytes, u64 empty_size, u64 search_start,
Chris Masonbe08c1b2007-05-03 09:06:49 -0400995 u64 search_end, struct btrfs_key *ins, int data);
Chris Masone089f052007-03-16 16:20:31 -0400996int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
Chris Mason5f39d392007-10-15 16:14:19 -0400997 struct extent_buffer *buf);
Chris Masone089f052007-03-16 16:20:31 -0400998int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Masondb945352007-10-15 16:15:53 -0400999 *root, u64 bytenr, u64 num_bytes, int pin);
Chris Masonccd467d2007-06-28 15:57:36 -04001000int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
1001 struct btrfs_root *root,
Chris Mason1a5bc162007-10-15 16:15:26 -04001002 struct extent_map_tree *unpin);
Chris Masonb18c6682007-04-17 13:26:50 -04001003int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
1004 struct btrfs_root *root,
Chris Masondb945352007-10-15 16:15:53 -04001005 u64 bytenr, u64 num_bytes);
Chris Mason9078a3e2007-04-26 16:46:15 -04001006int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1007 struct btrfs_root *root);
1008int btrfs_free_block_groups(struct btrfs_fs_info *info);
1009int btrfs_read_block_groups(struct btrfs_root *root);
Chris Masondee26a92007-03-26 16:00:06 -04001010/* ctree.c */
Chris Mason5f39d392007-10-15 16:14:19 -04001011int btrfs_cow_block(struct btrfs_trans_handle *trans,
1012 struct btrfs_root *root, struct extent_buffer *buf,
1013 struct extent_buffer *parent, int parent_slot,
1014 struct extent_buffer **cow_ret);
Chris Mason6567e832007-04-16 09:22:45 -04001015int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1016 *root, struct btrfs_path *path, u32 data_size);
Chris Masonb18c6682007-04-17 13:26:50 -04001017int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1018 struct btrfs_root *root,
1019 struct btrfs_path *path,
1020 u32 new_size);
Chris Masone089f052007-03-16 16:20:31 -04001021int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1022 *root, struct btrfs_key *key, struct btrfs_path *p, int
1023 ins_len, int cow);
Chris Mason6702ed42007-08-07 16:15:09 -04001024int btrfs_realloc_node(struct btrfs_trans_handle *trans,
Chris Mason5f39d392007-10-15 16:14:19 -04001025 struct btrfs_root *root, struct extent_buffer *parent,
Chris Masone9d0b132007-08-10 14:06:19 -04001026 int cache_only, u64 *last_ret);
Chris Mason234b63a2007-03-13 10:46:10 -04001027void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
Chris Mason2c90e5d2007-04-02 10:50:19 -04001028struct btrfs_path *btrfs_alloc_path(void);
1029void btrfs_free_path(struct btrfs_path *p);
Chris Mason234b63a2007-03-13 10:46:10 -04001030void btrfs_init_path(struct btrfs_path *p);
Chris Masone089f052007-03-16 16:20:31 -04001031int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1032 struct btrfs_path *path);
1033int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1034 *root, struct btrfs_key *key, void *data, u32 data_size);
1035int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
1036 *root, struct btrfs_path *path, struct btrfs_key
1037 *cpu_key, u32 data_size);
Chris Mason234b63a2007-03-13 10:46:10 -04001038int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
Chris Mason5f39d392007-10-15 16:14:19 -04001039int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
Chris Masone089f052007-03-16 16:20:31 -04001040int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Mason9f3a7422007-08-07 15:52:19 -04001041 *root);
Chris Masondee26a92007-03-26 16:00:06 -04001042/* root-item.c */
Chris Masone089f052007-03-16 16:20:31 -04001043int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1044 struct btrfs_key *key);
1045int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1046 *root, struct btrfs_key *key, struct btrfs_root_item
1047 *item);
1048int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1049 *root, struct btrfs_key *key, struct btrfs_root_item
1050 *item);
1051int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1052 btrfs_root_item *item, struct btrfs_key *key);
Chris Mason5ce14bb2007-09-11 11:15:39 -04001053int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
1054 struct btrfs_root *latest_root);
Chris Masondee26a92007-03-26 16:00:06 -04001055/* dir-item.c */
Chris Masone089f052007-03-16 16:20:31 -04001056int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Masond6e4a422007-04-06 15:37:36 -04001057 *root, const char *name, int name_len, u64 dir,
1058 struct btrfs_key *location, u8 type);
Chris Mason7e381802007-04-19 15:36:27 -04001059struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
1060 struct btrfs_root *root,
1061 struct btrfs_path *path, u64 dir,
1062 const char *name, int name_len,
1063 int mod);
1064struct btrfs_dir_item *
1065btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
1066 struct btrfs_root *root,
1067 struct btrfs_path *path, u64 dir,
1068 u64 objectid, const char *name, int name_len,
1069 int mod);
1070struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
1071 struct btrfs_path *path,
Chris Mason7f5c1512007-03-23 15:56:19 -04001072 const char *name, int name_len);
Chris Mason7e381802007-04-19 15:36:27 -04001073int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
1074 struct btrfs_root *root,
1075 struct btrfs_path *path,
1076 struct btrfs_dir_item *di);
Chris Masondee26a92007-03-26 16:00:06 -04001077/* inode-map.c */
Chris Mason9f5fae22007-03-20 14:38:32 -04001078int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1079 struct btrfs_root *fs_root,
1080 u64 dirid, u64 *objectid);
Chris Mason5be6f7f2007-04-05 13:35:25 -04001081int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
1082
Chris Masondee26a92007-03-26 16:00:06 -04001083/* inode-item.c */
Chris Mason5f39d392007-10-15 16:14:19 -04001084int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
1085 struct btrfs_root *root,
1086 struct btrfs_path *path, u64 objectid);
Chris Mason293ffd52007-03-20 15:57:25 -04001087int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Masond6e4a422007-04-06 15:37:36 -04001088 *root, struct btrfs_path *path,
1089 struct btrfs_key *location, int mod);
Chris Masondee26a92007-03-26 16:00:06 -04001090
1091/* file-item.c */
Chris Masonb18c6682007-04-17 13:26:50 -04001092int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
Chris Masondee26a92007-03-26 16:00:06 -04001093 struct btrfs_root *root,
Chris Masonb18c6682007-04-17 13:26:50 -04001094 u64 objectid, u64 pos, u64 offset,
Chris Masondb945352007-10-15 16:15:53 -04001095 u64 disk_num_bytes,
1096 u64 num_bytes);
Chris Masondee26a92007-03-26 16:00:06 -04001097int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
1098 struct btrfs_root *root,
1099 struct btrfs_path *path, u64 objectid,
Chris Masondb945352007-10-15 16:15:53 -04001100 u64 bytenr, int mod);
Chris Masonf254e522007-03-29 15:15:27 -04001101int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
1102 struct btrfs_root *root,
1103 u64 objectid, u64 offset,
1104 char *data, size_t len);
Chris Masonb18c6682007-04-17 13:26:50 -04001105struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
1106 struct btrfs_root *root,
1107 struct btrfs_path *path,
1108 u64 objectid, u64 offset,
1109 int cow);
Chris Mason1de037a2007-05-29 15:17:08 -04001110int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
1111 struct btrfs_root *root, struct btrfs_path *path,
1112 u64 isize);
Chris Mason39279cc2007-06-12 06:35:45 -04001113/* inode.c */
Chris Mason9ebefb182007-06-15 13:50:00 -04001114int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page);
1115int btrfs_readpage(struct file *file, struct page *page);
Chris Mason39279cc2007-06-12 06:35:45 -04001116void btrfs_delete_inode(struct inode *inode);
1117void btrfs_read_locked_inode(struct inode *inode);
1118int btrfs_write_inode(struct inode *inode, int wait);
1119void btrfs_dirty_inode(struct inode *inode);
1120struct inode *btrfs_alloc_inode(struct super_block *sb);
1121void btrfs_destroy_inode(struct inode *inode);
1122int btrfs_init_cachep(void);
1123void btrfs_destroy_cachep(void);
Christoph Hellwig34287aa2007-09-14 10:22:47 -04001124long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
Chris Mason39279cc2007-06-12 06:35:45 -04001125struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
1126 struct btrfs_root *root);
1127int btrfs_commit_write(struct file *file, struct page *page,
1128 unsigned from, unsigned to);
Chris Masona52d9a82007-08-27 16:49:44 -04001129struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
1130 size_t page_offset, u64 start, u64 end,
1131 int create);
1132int btrfs_update_inode(struct btrfs_trans_handle *trans,
1133 struct btrfs_root *root,
1134 struct inode *inode);
Chris Mason39279cc2007-06-12 06:35:45 -04001135/* file.c */
Chris Masona52d9a82007-08-27 16:49:44 -04001136int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end);
Chris Mason39279cc2007-06-12 06:35:45 -04001137extern struct file_operations btrfs_file_operations;
1138int btrfs_drop_extents(struct btrfs_trans_handle *trans,
1139 struct btrfs_root *root, struct inode *inode,
1140 u64 start, u64 end, u64 *hint_block);
Chris Mason6702ed42007-08-07 16:15:09 -04001141/* tree-defrag.c */
1142int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
1143 struct btrfs_root *root, int cache_only);
Josef Bacik58176a92007-08-29 15:47:34 -04001144
1145/* sysfs.c */
1146int btrfs_init_sysfs(void);
1147void btrfs_exit_sysfs(void);
1148int btrfs_sysfs_add_super(struct btrfs_fs_info *fs);
1149int btrfs_sysfs_add_root(struct btrfs_root *root);
1150void btrfs_sysfs_del_root(struct btrfs_root *root);
1151void btrfs_sysfs_del_super(struct btrfs_fs_info *root);
1152
Chris Masoneb60cea2007-02-02 09:18:22 -05001153#endif