blob: 5830b4333d83d4ef1d64293cd0652f4e23dcf420 [file] [log] [blame]
Chris Mason234b63a2007-03-13 10:46:10 -04001#ifndef __BTRFS__
2#define __BTRFS__
Chris Masoneb60cea2007-02-02 09:18:22 -05003
Chris Masone20d96d2007-03-22 12:13:20 -04004#include <linux/fs.h>
Chris Masond6025572007-03-30 14:27:56 -04005#include <linux/buffer_head.h>
Chris Masond6e4a422007-04-06 15:37:36 -04006#include <linux/kobject.h>
Chris Mason8ef97622007-03-26 10:15:30 -04007#include "bit-radix.h"
Chris Masone20d96d2007-03-22 12:13:20 -04008
Chris Masone089f052007-03-16 16:20:31 -04009struct btrfs_trans_handle;
Chris Mason79154b12007-03-22 15:59:16 -040010struct btrfs_transaction;
Chris Mason35b7e472007-05-02 15:53:43 -040011extern struct kmem_cache *btrfs_trans_handle_cachep;
12extern struct kmem_cache *btrfs_transaction_cachep;
13extern struct kmem_cache *btrfs_bit_radix_cachep;
Chris Mason2c90e5d2007-04-02 10:50:19 -040014extern struct kmem_cache *btrfs_path_cachep;
Chris Masone089f052007-03-16 16:20:31 -040015
Chris Mason3768f362007-03-13 16:47:54 -040016#define BTRFS_MAGIC "_BtRfS_M"
Chris Masoneb60cea2007-02-02 09:18:22 -050017
Chris Mason6407bf62007-03-27 06:33:00 -040018#define BTRFS_ROOT_TREE_OBJECTID 1ULL
Chris Mason0bd93ba2007-04-11 13:57:44 -040019#define BTRFS_DEV_TREE_OBJECTID 2ULL
20#define BTRFS_EXTENT_TREE_OBJECTID 3ULL
21#define BTRFS_FS_TREE_OBJECTID 4ULL
22#define BTRFS_ROOT_TREE_DIR_OBJECTID 5ULL
23#define BTRFS_FIRST_FREE_OBJECTID 6ULL
Chris Mason3768f362007-03-13 16:47:54 -040024
Chris Masonfec577f2007-02-26 10:40:21 -050025/*
Chris Masone20d96d2007-03-22 12:13:20 -040026 * we can actually store much bigger names, but lets not confuse the rest
27 * of linux
28 */
29#define BTRFS_NAME_LEN 255
30
Chris Masonf254e522007-03-29 15:15:27 -040031/* 32 bytes in various csum fields */
32#define BTRFS_CSUM_SIZE 32
Chris Mason509659c2007-05-10 12:36:17 -040033/* four bytes for CRC32 */
34#define BTRFS_CRC32_SIZE 4
Chris Masonf254e522007-03-29 15:15:27 -040035
Chris Masone20d96d2007-03-22 12:13:20 -040036/*
Chris Masonfec577f2007-02-26 10:40:21 -050037 * the key defines the order in the tree, and so it also defines (optimal)
38 * block layout. objectid corresonds to the inode number. The flags
39 * tells us things about the object, and is a kind of stream selector.
40 * so for a given inode, keys with flags of 1 might refer to the inode
41 * data, flags of 2 may point to file data in the btree and flags == 3
42 * may point to extents.
43 *
44 * offset is the starting byte offset for this key in the stream.
Chris Masone2fa7222007-03-12 16:22:34 -040045 *
46 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
47 * in cpu native order. Otherwise they are identical and their sizes
48 * should be the same (ie both packed)
Chris Masonfec577f2007-02-26 10:40:21 -050049 */
Chris Masone2fa7222007-03-12 16:22:34 -040050struct btrfs_disk_key {
51 __le64 objectid;
Chris Masonf254e522007-03-29 15:15:27 -040052 __le32 flags;
Chris Mason70b2bef2007-04-17 15:39:32 -040053 __le64 offset;
Chris Masone2fa7222007-03-12 16:22:34 -040054} __attribute__ ((__packed__));
55
56struct btrfs_key {
Chris Masoneb60cea2007-02-02 09:18:22 -050057 u64 objectid;
Chris Masonf254e522007-03-29 15:15:27 -040058 u32 flags;
Chris Mason70b2bef2007-04-17 15:39:32 -040059 u64 offset;
Chris Masoneb60cea2007-02-02 09:18:22 -050060} __attribute__ ((__packed__));
61
Chris Masonfec577f2007-02-26 10:40:21 -050062/*
63 * every tree block (leaf or node) starts with this header.
64 */
Chris Masonbb492bb2007-03-12 12:29:44 -040065struct btrfs_header {
Chris Masonf254e522007-03-29 15:15:27 -040066 u8 csum[BTRFS_CSUM_SIZE];
Chris Mason3768f362007-03-13 16:47:54 -040067 u8 fsid[16]; /* FS specific uuid */
Chris Masonbb492bb2007-03-12 12:29:44 -040068 __le64 blocknr; /* which block this node is supposed to live in */
Chris Mason7f5c1512007-03-23 15:56:19 -040069 __le64 generation;
Chris Mason4d775672007-04-20 20:23:12 -040070 __le64 owner;
Chris Masonbb492bb2007-03-12 12:29:44 -040071 __le16 nritems;
72 __le16 flags;
Chris Mason9a6f11e2007-03-27 09:06:38 -040073 u8 level;
Chris Masoneb60cea2007-02-02 09:18:22 -050074} __attribute__ ((__packed__));
75
Chris Mason234b63a2007-03-13 10:46:10 -040076#define BTRFS_MAX_LEVEL 8
Chris Mason123abc82007-03-14 14:14:43 -040077#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \
78 sizeof(struct btrfs_header)) / \
79 (sizeof(struct btrfs_disk_key) + sizeof(u64)))
80#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
81#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
Chris Mason236454d2007-04-19 13:37:44 -040082#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
83 sizeof(struct btrfs_item) - \
84 sizeof(struct btrfs_file_extent_item))
Chris Masoneb60cea2007-02-02 09:18:22 -050085
Chris Masone20d96d2007-03-22 12:13:20 -040086struct buffer_head;
Chris Masonfec577f2007-02-26 10:40:21 -050087/*
Chris Masonfec577f2007-02-26 10:40:21 -050088 * the super block basically lists the main trees of the FS
89 * it currently lacks any block count etc etc
90 */
Chris Mason234b63a2007-03-13 10:46:10 -040091struct btrfs_super_block {
Chris Masonf254e522007-03-29 15:15:27 -040092 u8 csum[BTRFS_CSUM_SIZE];
Chris Mason87cbda52007-03-28 19:44:27 -040093 /* the first 3 fields must match struct btrfs_header */
Chris Mason3768f362007-03-13 16:47:54 -040094 u8 fsid[16]; /* FS specific uuid */
95 __le64 blocknr; /* this block number */
Chris Mason3768f362007-03-13 16:47:54 -040096 __le64 magic;
Chris Mason123abc82007-03-14 14:14:43 -040097 __le32 blocksize;
Chris Mason3768f362007-03-13 16:47:54 -040098 __le64 generation;
99 __le64 root;
100 __le64 total_blocks;
101 __le64 blocks_used;
Chris Mason2e635a22007-03-21 11:12:56 -0400102 __le64 root_dir_objectid;
Chris Masonb4100d62007-04-12 12:14:00 -0400103 __le64 last_device_id;
Chris Mason0bd93ba2007-04-11 13:57:44 -0400104 /* fields below here vary with the underlying disk */
105 __le64 device_block_start;
106 __le64 device_num_blocks;
107 __le64 device_root;
Chris Masonb4100d62007-04-12 12:14:00 -0400108 __le64 device_id;
Chris Masoncfaa7292007-02-21 17:04:57 -0500109} __attribute__ ((__packed__));
110
Chris Masonfec577f2007-02-26 10:40:21 -0500111/*
Chris Mason62e27492007-03-15 12:56:47 -0400112 * A leaf is full of items. offset and size tell us where to find
Chris Masonfec577f2007-02-26 10:40:21 -0500113 * the item in the leaf (relative to the start of the data area)
114 */
Chris Mason0783fcf2007-03-12 20:12:07 -0400115struct btrfs_item {
Chris Masone2fa7222007-03-12 16:22:34 -0400116 struct btrfs_disk_key key;
Chris Mason123abc82007-03-14 14:14:43 -0400117 __le32 offset;
Chris Mason0783fcf2007-03-12 20:12:07 -0400118 __le16 size;
Chris Masoneb60cea2007-02-02 09:18:22 -0500119} __attribute__ ((__packed__));
120
Chris Masonfec577f2007-02-26 10:40:21 -0500121/*
122 * leaves have an item area and a data area:
123 * [item0, item1....itemN] [free space] [dataN...data1, data0]
124 *
125 * The data is separate from the items to get the keys closer together
126 * during searches.
127 */
Chris Mason234b63a2007-03-13 10:46:10 -0400128struct btrfs_leaf {
Chris Masonbb492bb2007-03-12 12:29:44 -0400129 struct btrfs_header header;
Chris Mason123abc82007-03-14 14:14:43 -0400130 struct btrfs_item items[];
Chris Masoneb60cea2007-02-02 09:18:22 -0500131} __attribute__ ((__packed__));
132
Chris Masonfec577f2007-02-26 10:40:21 -0500133/*
134 * all non-leaf blocks are nodes, they hold only keys and pointers to
135 * other blocks
136 */
Chris Mason123abc82007-03-14 14:14:43 -0400137struct btrfs_key_ptr {
138 struct btrfs_disk_key key;
139 __le64 blockptr;
140} __attribute__ ((__packed__));
141
Chris Mason234b63a2007-03-13 10:46:10 -0400142struct btrfs_node {
Chris Masonbb492bb2007-03-12 12:29:44 -0400143 struct btrfs_header header;
Chris Mason123abc82007-03-14 14:14:43 -0400144 struct btrfs_key_ptr ptrs[];
Chris Masoneb60cea2007-02-02 09:18:22 -0500145} __attribute__ ((__packed__));
146
Chris Masonfec577f2007-02-26 10:40:21 -0500147/*
Chris Mason234b63a2007-03-13 10:46:10 -0400148 * btrfs_paths remember the path taken from the root down to the leaf.
149 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
Chris Masonfec577f2007-02-26 10:40:21 -0500150 * to any other levels that are present.
151 *
152 * The slots array records the index of the item or block pointer
153 * used while walking the tree.
154 */
Chris Mason234b63a2007-03-13 10:46:10 -0400155struct btrfs_path {
Chris Masone20d96d2007-03-22 12:13:20 -0400156 struct buffer_head *nodes[BTRFS_MAX_LEVEL];
Chris Mason234b63a2007-03-13 10:46:10 -0400157 int slots[BTRFS_MAX_LEVEL];
Chris Masoneb60cea2007-02-02 09:18:22 -0500158};
Chris Mason5de08d72007-02-24 06:24:44 -0500159
Chris Mason62e27492007-03-15 12:56:47 -0400160/*
161 * items in the extent btree are used to record the objectid of the
162 * owner of the block and the number of references
163 */
164struct btrfs_extent_item {
165 __le32 refs;
Chris Mason4d775672007-04-20 20:23:12 -0400166 __le64 owner;
Chris Mason62e27492007-03-15 12:56:47 -0400167} __attribute__ ((__packed__));
168
Chris Mason1e1d2702007-03-15 19:03:33 -0400169struct btrfs_inode_timespec {
Chris Masonf254e522007-03-29 15:15:27 -0400170 __le64 sec;
Chris Mason1e1d2702007-03-15 19:03:33 -0400171 __le32 nsec;
172} __attribute__ ((__packed__));
173
174/*
175 * there is no padding here on purpose. If you want to extent the inode,
176 * make a new item type
177 */
178struct btrfs_inode_item {
179 __le64 generation;
180 __le64 size;
181 __le64 nblocks;
Chris Mason31f3c992007-04-30 15:25:45 -0400182 __le64 block_group;
Chris Mason1e1d2702007-03-15 19:03:33 -0400183 __le32 nlink;
184 __le32 uid;
185 __le32 gid;
186 __le32 mode;
187 __le32 rdev;
188 __le16 flags;
189 __le16 compat_flags;
190 struct btrfs_inode_timespec atime;
191 struct btrfs_inode_timespec ctime;
192 struct btrfs_inode_timespec mtime;
193 struct btrfs_inode_timespec otime;
194} __attribute__ ((__packed__));
195
Chris Mason62e27492007-03-15 12:56:47 -0400196struct btrfs_dir_item {
Chris Masond6e4a422007-04-06 15:37:36 -0400197 struct btrfs_disk_key location;
Chris Mason62e27492007-03-15 12:56:47 -0400198 __le16 flags;
Chris Masona8a2ee02007-03-16 08:46:49 -0400199 __le16 name_len;
Chris Mason62e27492007-03-15 12:56:47 -0400200 u8 type;
201} __attribute__ ((__packed__));
202
203struct btrfs_root_item {
Chris Masond6e4a422007-04-06 15:37:36 -0400204 struct btrfs_inode_item inode;
205 __le64 root_dirid;
Chris Mason62e27492007-03-15 12:56:47 -0400206 __le64 blocknr;
207 __le32 flags;
208 __le64 block_limit;
209 __le64 blocks_used;
210 __le32 refs;
Chris Mason9f5fae22007-03-20 14:38:32 -0400211} __attribute__ ((__packed__));
212
Chris Mason236454d2007-04-19 13:37:44 -0400213#define BTRFS_FILE_EXTENT_REG 0
214#define BTRFS_FILE_EXTENT_INLINE 1
215
Chris Mason9f5fae22007-03-20 14:38:32 -0400216struct btrfs_file_extent_item {
Chris Mason71951f32007-03-27 09:16:29 -0400217 __le64 generation;
Chris Mason236454d2007-04-19 13:37:44 -0400218 u8 type;
Chris Mason9f5fae22007-03-20 14:38:32 -0400219 /*
220 * disk space consumed by the extent, checksum blocks are included
221 * in these numbers
222 */
223 __le64 disk_blocknr;
224 __le64 disk_num_blocks;
225 /*
Chris Masondee26a92007-03-26 16:00:06 -0400226 * the logical offset in file blocks (no csums)
Chris Mason9f5fae22007-03-20 14:38:32 -0400227 * this extent record is for. This allows a file extent to point
228 * into the middle of an existing extent on disk, sharing it
229 * between two snapshots (useful if some bytes in the middle of the
230 * extent have changed
231 */
232 __le64 offset;
233 /*
234 * the logical number of file blocks (no csums included)
235 */
236 __le64 num_blocks;
237} __attribute__ ((__packed__));
238
Chris Masonf254e522007-03-29 15:15:27 -0400239struct btrfs_csum_item {
Chris Mason509659c2007-05-10 12:36:17 -0400240 u8 csum;
Chris Masonf254e522007-03-29 15:15:27 -0400241} __attribute__ ((__packed__));
242
Chris Mason0bd93ba2007-04-11 13:57:44 -0400243struct btrfs_device_item {
244 __le16 pathlen;
Chris Masonb4100d62007-04-12 12:14:00 -0400245 __le64 device_id;
Chris Mason0bd93ba2007-04-11 13:57:44 -0400246} __attribute__ ((__packed__));
247
Chris Mason9078a3e2007-04-26 16:46:15 -0400248/* tag for the radix tree of block groups in ram */
249#define BTRFS_BLOCK_GROUP_DIRTY 0
Chris Mason31f3c992007-04-30 15:25:45 -0400250#define BTRFS_BLOCK_GROUP_AVAIL 1
Chris Mason9078a3e2007-04-26 16:46:15 -0400251#define BTRFS_BLOCK_GROUP_HINTS 8
252#define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
253struct btrfs_block_group_item {
254 __le64 used;
255} __attribute__ ((__packed__));
256
257struct btrfs_block_group_cache {
258 struct btrfs_key key;
259 struct btrfs_block_group_item item;
Chris Mason3e1ad542007-05-07 20:03:49 -0400260 struct radix_tree_root *radix;
Chris Masoncd1bc462007-04-27 10:08:34 -0400261 u64 first_free;
262 u64 last_alloc;
Chris Masonbe744172007-05-06 10:15:01 -0400263 u64 pinned;
Chris Masone37c9e62007-05-09 20:13:14 -0400264 u64 last_prealloc;
Chris Masonbe744172007-05-06 10:15:01 -0400265 int data;
Chris Masone37c9e62007-05-09 20:13:14 -0400266 int cached;
Chris Mason9078a3e2007-04-26 16:46:15 -0400267};
268
Chris Mason87cbda52007-03-28 19:44:27 -0400269struct crypto_hash;
Chris Mason9f5fae22007-03-20 14:38:32 -0400270struct btrfs_fs_info {
Chris Mason9f5fae22007-03-20 14:38:32 -0400271 struct btrfs_root *extent_root;
272 struct btrfs_root *tree_root;
Chris Mason0bd93ba2007-04-11 13:57:44 -0400273 struct btrfs_root *dev_root;
Chris Mason0f7d52f2007-04-09 10:42:37 -0400274 struct radix_tree_root fs_roots_radix;
Chris Mason8ef97622007-03-26 10:15:30 -0400275 struct radix_tree_root pending_del_radix;
Chris Mason9f5fae22007-03-20 14:38:32 -0400276 struct radix_tree_root pinned_radix;
Chris Mason7eccb902007-04-11 15:53:25 -0400277 struct radix_tree_root dev_radix;
Chris Mason9078a3e2007-04-26 16:46:15 -0400278 struct radix_tree_root block_group_radix;
Chris Masonbe744172007-05-06 10:15:01 -0400279 struct radix_tree_root block_group_data_radix;
Chris Masone37c9e62007-05-09 20:13:14 -0400280 struct radix_tree_root extent_map_radix;
Chris Masonf2458e12007-04-25 15:52:25 -0400281
282 u64 extent_tree_insert[BTRFS_MAX_LEVEL * 3];
283 int extent_tree_insert_nr;
284 u64 extent_tree_prealloc[BTRFS_MAX_LEVEL * 3];
285 int extent_tree_prealloc_nr;
286
Chris Mason293ffd52007-03-20 15:57:25 -0400287 u64 generation;
Chris Mason79154b12007-03-22 15:59:16 -0400288 struct btrfs_transaction *running_transaction;
Chris Mason1261ec42007-03-20 20:35:03 -0400289 struct btrfs_super_block *disk_super;
Chris Masone20d96d2007-03-22 12:13:20 -0400290 struct buffer_head *sb_buffer;
291 struct super_block *sb;
Chris Masond98237b2007-03-28 13:57:48 -0400292 struct inode *btree_inode;
Chris Mason79154b12007-03-22 15:59:16 -0400293 struct mutex trans_mutex;
Chris Masond561c022007-03-23 19:47:49 -0400294 struct mutex fs_mutex;
Chris Mason8fd17792007-04-19 21:01:03 -0400295 struct list_head trans_list;
Chris Mason87cbda52007-03-28 19:44:27 -0400296 struct crypto_hash *hash_tfm;
297 spinlock_t hash_lock;
Chris Masone66f7092007-04-20 13:16:02 -0400298 int do_barriers;
Chris Masond6e4a422007-04-06 15:37:36 -0400299 struct kobject kobj;
Chris Mason62e27492007-03-15 12:56:47 -0400300};
301
302/*
303 * in ram representation of the tree. extent_root is used for all allocations
Chris Masonf2458e12007-04-25 15:52:25 -0400304 * and for the extent tree extent_root root.
Chris Mason62e27492007-03-15 12:56:47 -0400305 */
306struct btrfs_root {
Chris Masone20d96d2007-03-22 12:13:20 -0400307 struct buffer_head *node;
308 struct buffer_head *commit_root;
Chris Mason62e27492007-03-15 12:56:47 -0400309 struct btrfs_root_item root_item;
310 struct btrfs_key root_key;
Chris Mason9f5fae22007-03-20 14:38:32 -0400311 struct btrfs_fs_info *fs_info;
Chris Mason0f7d52f2007-04-09 10:42:37 -0400312 struct inode *inode;
313 u64 objectid;
314 u64 last_trans;
Chris Mason62e27492007-03-15 12:56:47 -0400315 u32 blocksize;
Chris Mason9f5fae22007-03-20 14:38:32 -0400316 int ref_cows;
317 u32 type;
Chris Mason1b05da22007-04-10 12:13:09 -0400318 u64 highest_inode;
319 u64 last_inode_alloc;
Chris Mason62e27492007-03-15 12:56:47 -0400320};
321
Chris Mason62e27492007-03-15 12:56:47 -0400322/* the lower bits in the key flags defines the item type */
323#define BTRFS_KEY_TYPE_MAX 256
Chris Masona429e512007-04-18 16:15:28 -0400324#define BTRFS_KEY_TYPE_SHIFT 24
325#define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
326 BTRFS_KEY_TYPE_SHIFT)
Chris Mason1e1d2702007-03-15 19:03:33 -0400327
328/*
329 * inode items have the data typically returned from stat and store other
330 * info about object characteristics. There is one for every file and dir in
331 * the FS
332 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400333#define BTRFS_INODE_ITEM_KEY 1
334
335/* reserve 2-15 close to the inode for later flexibility */
Chris Mason1e1d2702007-03-15 19:03:33 -0400336
337/*
338 * dir items are the name -> inode pointers in a directory. There is one
339 * for every name in a directory.
340 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400341#define BTRFS_DIR_ITEM_KEY 16
342#define BTRFS_DIR_INDEX_KEY 17
Chris Mason1e1d2702007-03-15 19:03:33 -0400343/*
Chris Mason9078a3e2007-04-26 16:46:15 -0400344 * extent data is for file data
Chris Mason1e1d2702007-03-15 19:03:33 -0400345 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400346#define BTRFS_EXTENT_DATA_KEY 18
Chris Mason1e1d2702007-03-15 19:03:33 -0400347/*
Chris Masonf254e522007-03-29 15:15:27 -0400348 * csum items have the checksums for data in the extents
349 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400350#define BTRFS_CSUM_ITEM_KEY 19
351
352/* reserve 20-31 for other file stuff */
Chris Masonf254e522007-03-29 15:15:27 -0400353
354/*
Chris Mason1e1d2702007-03-15 19:03:33 -0400355 * root items point to tree roots. There are typically in the root
356 * tree used by the super block to find all the other trees
357 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400358#define BTRFS_ROOT_ITEM_KEY 32
Chris Mason1e1d2702007-03-15 19:03:33 -0400359/*
360 * extent items are in the extent map tree. These record which blocks
361 * are used, and how many references there are to each block
362 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400363#define BTRFS_EXTENT_ITEM_KEY 33
364
365/*
366 * block groups give us hints into the extent allocation trees. Which
367 * blocks are free etc etc
368 */
369#define BTRFS_BLOCK_GROUP_ITEM_KEY 34
Chris Mason9f5fae22007-03-20 14:38:32 -0400370
371/*
Chris Mason0bd93ba2007-04-11 13:57:44 -0400372 * dev items list the devices that make up the FS
373 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400374#define BTRFS_DEV_ITEM_KEY 35
Chris Mason0bd93ba2007-04-11 13:57:44 -0400375
376/*
Chris Mason1e1d2702007-03-15 19:03:33 -0400377 * string items are for debugging. They just store a short string of
378 * data in the FS
379 */
Chris Mason9078a3e2007-04-26 16:46:15 -0400380#define BTRFS_STRING_ITEM_KEY 253
381
382
383static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi)
384{
385 return le64_to_cpu(bi->used);
386}
387
388static inline void btrfs_set_block_group_used(struct
389 btrfs_block_group_item *bi,
390 u64 val)
391{
392 bi->used = cpu_to_le64(val);
393}
Chris Mason1e1d2702007-03-15 19:03:33 -0400394
395static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
396{
397 return le64_to_cpu(i->generation);
398}
399
400static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
401 u64 val)
402{
403 i->generation = cpu_to_le64(val);
404}
405
406static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
407{
408 return le64_to_cpu(i->size);
409}
410
411static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
412{
413 i->size = cpu_to_le64(val);
414}
415
416static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
417{
418 return le64_to_cpu(i->nblocks);
419}
420
421static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
422{
423 i->nblocks = cpu_to_le64(val);
424}
425
Chris Mason31f3c992007-04-30 15:25:45 -0400426static inline u64 btrfs_inode_block_group(struct btrfs_inode_item *i)
427{
428 return le64_to_cpu(i->block_group);
429}
430
431static inline void btrfs_set_inode_block_group(struct btrfs_inode_item *i,
432 u64 val)
433{
434 i->block_group = cpu_to_le64(val);
435}
436
Chris Mason1e1d2702007-03-15 19:03:33 -0400437static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
438{
439 return le32_to_cpu(i->nlink);
440}
441
442static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
443{
444 i->nlink = cpu_to_le32(val);
445}
446
447static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
448{
449 return le32_to_cpu(i->uid);
450}
451
452static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
453{
454 i->uid = cpu_to_le32(val);
455}
456
457static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
458{
459 return le32_to_cpu(i->gid);
460}
461
462static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
463{
464 i->gid = cpu_to_le32(val);
465}
466
467static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
468{
469 return le32_to_cpu(i->mode);
470}
471
472static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
473{
474 i->mode = cpu_to_le32(val);
475}
476
477static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
478{
479 return le32_to_cpu(i->rdev);
480}
481
482static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
483{
484 i->rdev = cpu_to_le32(val);
485}
486
487static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
488{
489 return le16_to_cpu(i->flags);
490}
491
492static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
493{
494 i->flags = cpu_to_le16(val);
495}
496
497static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
498{
499 return le16_to_cpu(i->compat_flags);
500}
501
502static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
503 u16 val)
504{
505 i->compat_flags = cpu_to_le16(val);
506}
507
Chris Masonf254e522007-03-29 15:15:27 -0400508static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
Chris Masone20d96d2007-03-22 12:13:20 -0400509{
Chris Masonf254e522007-03-29 15:15:27 -0400510 return le64_to_cpu(ts->sec);
Chris Masone20d96d2007-03-22 12:13:20 -0400511}
512
513static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
Chris Masonf254e522007-03-29 15:15:27 -0400514 u64 val)
Chris Masone20d96d2007-03-22 12:13:20 -0400515{
Chris Masonf254e522007-03-29 15:15:27 -0400516 ts->sec = cpu_to_le64(val);
Chris Masone20d96d2007-03-22 12:13:20 -0400517}
518
519static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
520{
521 return le32_to_cpu(ts->nsec);
522}
523
524static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
525 u32 val)
526{
527 ts->nsec = cpu_to_le32(val);
528}
529
Chris Mason234b63a2007-03-13 10:46:10 -0400530static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
Chris Masoncf27e1e2007-03-13 09:49:06 -0400531{
532 return le32_to_cpu(ei->refs);
533}
534
Chris Mason234b63a2007-03-13 10:46:10 -0400535static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
Chris Masoncf27e1e2007-03-13 09:49:06 -0400536{
537 ei->refs = cpu_to_le32(val);
538}
539
Chris Mason4d775672007-04-20 20:23:12 -0400540static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
541{
542 return le64_to_cpu(ei->owner);
543}
544
545static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
546{
547 ei->owner = cpu_to_le64(val);
548}
549
Chris Mason234b63a2007-03-13 10:46:10 -0400550static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
Chris Mason1d4f8a02007-03-13 09:28:32 -0400551{
Chris Mason123abc82007-03-14 14:14:43 -0400552 return le64_to_cpu(n->ptrs[nr].blockptr);
Chris Mason1d4f8a02007-03-13 09:28:32 -0400553}
554
Chris Mason4d775672007-04-20 20:23:12 -0400555
Chris Mason234b63a2007-03-13 10:46:10 -0400556static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
557 u64 val)
Chris Mason1d4f8a02007-03-13 09:28:32 -0400558{
Chris Mason123abc82007-03-14 14:14:43 -0400559 n->ptrs[nr].blockptr = cpu_to_le64(val);
Chris Mason1d4f8a02007-03-13 09:28:32 -0400560}
561
Chris Mason123abc82007-03-14 14:14:43 -0400562static inline u32 btrfs_item_offset(struct btrfs_item *item)
Chris Mason0783fcf2007-03-12 20:12:07 -0400563{
Chris Mason123abc82007-03-14 14:14:43 -0400564 return le32_to_cpu(item->offset);
Chris Mason0783fcf2007-03-12 20:12:07 -0400565}
566
Chris Mason123abc82007-03-14 14:14:43 -0400567static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
Chris Mason0783fcf2007-03-12 20:12:07 -0400568{
Chris Mason123abc82007-03-14 14:14:43 -0400569 item->offset = cpu_to_le32(val);
Chris Mason0783fcf2007-03-12 20:12:07 -0400570}
571
Chris Mason123abc82007-03-14 14:14:43 -0400572static inline u32 btrfs_item_end(struct btrfs_item *item)
Chris Mason0783fcf2007-03-12 20:12:07 -0400573{
Chris Mason123abc82007-03-14 14:14:43 -0400574 return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
Chris Mason0783fcf2007-03-12 20:12:07 -0400575}
576
577static inline u16 btrfs_item_size(struct btrfs_item *item)
578{
579 return le16_to_cpu(item->size);
580}
581
582static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
583{
584 item->size = cpu_to_le16(val);
585}
586
Chris Mason1d4f6402007-03-15 15:18:43 -0400587static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
588{
589 return le16_to_cpu(d->flags);
590}
591
592static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
593{
594 d->flags = cpu_to_le16(val);
595}
596
597static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
598{
599 return d->type;
600}
601
602static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
603{
604 d->type = val;
605}
606
Chris Masona8a2ee02007-03-16 08:46:49 -0400607static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
Chris Mason1d4f6402007-03-15 15:18:43 -0400608{
Chris Masona8a2ee02007-03-16 08:46:49 -0400609 return le16_to_cpu(d->name_len);
610}
611
612static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
613{
614 d->name_len = cpu_to_le16(val);
Chris Mason1d4f6402007-03-15 15:18:43 -0400615}
616
Chris Masone2fa7222007-03-12 16:22:34 -0400617static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
618 struct btrfs_disk_key *disk)
619{
620 cpu->offset = le64_to_cpu(disk->offset);
621 cpu->flags = le32_to_cpu(disk->flags);
622 cpu->objectid = le64_to_cpu(disk->objectid);
623}
624
625static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
626 struct btrfs_key *cpu)
627{
628 disk->offset = cpu_to_le64(cpu->offset);
629 disk->flags = cpu_to_le32(cpu->flags);
630 disk->objectid = cpu_to_le64(cpu->objectid);
631}
632
Chris Mason62e27492007-03-15 12:56:47 -0400633static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
Chris Masone2fa7222007-03-12 16:22:34 -0400634{
635 return le64_to_cpu(disk->objectid);
636}
637
Chris Mason62e27492007-03-15 12:56:47 -0400638static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
639 u64 val)
Chris Masone2fa7222007-03-12 16:22:34 -0400640{
641 disk->objectid = cpu_to_le64(val);
642}
643
Chris Mason62e27492007-03-15 12:56:47 -0400644static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
Chris Masone2fa7222007-03-12 16:22:34 -0400645{
646 return le64_to_cpu(disk->offset);
647}
648
Chris Mason62e27492007-03-15 12:56:47 -0400649static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
650 u64 val)
Chris Masone2fa7222007-03-12 16:22:34 -0400651{
652 disk->offset = cpu_to_le64(val);
653}
654
Chris Mason62e27492007-03-15 12:56:47 -0400655static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
Chris Masone2fa7222007-03-12 16:22:34 -0400656{
657 return le32_to_cpu(disk->flags);
658}
659
Chris Mason62e27492007-03-15 12:56:47 -0400660static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
661 u32 val)
Chris Masone2fa7222007-03-12 16:22:34 -0400662{
663 disk->flags = cpu_to_le32(val);
664}
665
Chris Masona429e512007-04-18 16:15:28 -0400666static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
667{
668 return le32_to_cpu(key->flags) >> BTRFS_KEY_TYPE_SHIFT;
669}
670
671static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key,
672 u32 val)
673{
674 u32 flags = btrfs_disk_key_flags(key);
675 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
676 val = val << BTRFS_KEY_TYPE_SHIFT;
677 flags = (flags & ~BTRFS_KEY_TYPE_MASK) | val;
678 btrfs_set_disk_key_flags(key, flags);
679}
680
681static inline u32 btrfs_key_type(struct btrfs_key *key)
682{
683 return key->flags >> BTRFS_KEY_TYPE_SHIFT;
684}
685
686static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
687{
688 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
689 val = val << BTRFS_KEY_TYPE_SHIFT;
690 key->flags = (key->flags & ~(BTRFS_KEY_TYPE_MASK)) | val;
691}
692
Chris Masonbb492bb2007-03-12 12:29:44 -0400693static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
Chris Mason7518a232007-03-12 12:01:18 -0400694{
Chris Masonbb492bb2007-03-12 12:29:44 -0400695 return le64_to_cpu(h->blocknr);
Chris Mason7518a232007-03-12 12:01:18 -0400696}
697
Chris Masonbb492bb2007-03-12 12:29:44 -0400698static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
Chris Mason7518a232007-03-12 12:01:18 -0400699{
Chris Masonbb492bb2007-03-12 12:29:44 -0400700 h->blocknr = cpu_to_le64(blocknr);
Chris Mason7518a232007-03-12 12:01:18 -0400701}
702
Chris Mason7f5c1512007-03-23 15:56:19 -0400703static inline u64 btrfs_header_generation(struct btrfs_header *h)
704{
705 return le64_to_cpu(h->generation);
706}
707
708static inline void btrfs_set_header_generation(struct btrfs_header *h,
709 u64 val)
710{
711 h->generation = cpu_to_le64(val);
712}
713
Chris Mason4d775672007-04-20 20:23:12 -0400714static inline u64 btrfs_header_owner(struct btrfs_header *h)
715{
716 return le64_to_cpu(h->owner);
717}
718
719static inline void btrfs_set_header_owner(struct btrfs_header *h,
720 u64 val)
721{
722 h->owner = cpu_to_le64(val);
723}
724
Chris Masonbb492bb2007-03-12 12:29:44 -0400725static inline u16 btrfs_header_nritems(struct btrfs_header *h)
Chris Mason7518a232007-03-12 12:01:18 -0400726{
Chris Masonbb492bb2007-03-12 12:29:44 -0400727 return le16_to_cpu(h->nritems);
Chris Mason7518a232007-03-12 12:01:18 -0400728}
729
Chris Masonbb492bb2007-03-12 12:29:44 -0400730static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
Chris Mason7518a232007-03-12 12:01:18 -0400731{
Chris Masonbb492bb2007-03-12 12:29:44 -0400732 h->nritems = cpu_to_le16(val);
Chris Mason7518a232007-03-12 12:01:18 -0400733}
734
Chris Masonbb492bb2007-03-12 12:29:44 -0400735static inline u16 btrfs_header_flags(struct btrfs_header *h)
Chris Mason7518a232007-03-12 12:01:18 -0400736{
Chris Masonbb492bb2007-03-12 12:29:44 -0400737 return le16_to_cpu(h->flags);
Chris Mason7518a232007-03-12 12:01:18 -0400738}
739
Chris Masonbb492bb2007-03-12 12:29:44 -0400740static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
Chris Mason7518a232007-03-12 12:01:18 -0400741{
Chris Masonbb492bb2007-03-12 12:29:44 -0400742 h->flags = cpu_to_le16(val);
Chris Mason7518a232007-03-12 12:01:18 -0400743}
744
Chris Masonbb492bb2007-03-12 12:29:44 -0400745static inline int btrfs_header_level(struct btrfs_header *h)
Chris Mason7518a232007-03-12 12:01:18 -0400746{
Chris Mason9a6f11e2007-03-27 09:06:38 -0400747 return h->level;
Chris Mason7518a232007-03-12 12:01:18 -0400748}
749
Chris Masonbb492bb2007-03-12 12:29:44 -0400750static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
Chris Mason7518a232007-03-12 12:01:18 -0400751{
Chris Mason234b63a2007-03-13 10:46:10 -0400752 BUG_ON(level > BTRFS_MAX_LEVEL);
Chris Mason9a6f11e2007-03-27 09:06:38 -0400753 h->level = level;
Chris Mason7518a232007-03-12 12:01:18 -0400754}
755
Chris Mason234b63a2007-03-13 10:46:10 -0400756static inline int btrfs_is_leaf(struct btrfs_node *n)
Chris Mason7518a232007-03-12 12:01:18 -0400757{
758 return (btrfs_header_level(&n->header) == 0);
759}
760
Chris Mason3768f362007-03-13 16:47:54 -0400761static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
762{
763 return le64_to_cpu(item->blocknr);
764}
765
766static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
767{
768 item->blocknr = cpu_to_le64(val);
769}
770
Chris Masond6e4a422007-04-06 15:37:36 -0400771static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
772{
773 return le64_to_cpu(item->root_dirid);
774}
775
776static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
777{
778 item->root_dirid = cpu_to_le64(val);
779}
780
Chris Mason3768f362007-03-13 16:47:54 -0400781static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
782{
783 return le32_to_cpu(item->refs);
784}
785
786static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
787{
788 item->refs = cpu_to_le32(val);
789}
790
791static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
792{
793 return le64_to_cpu(s->blocknr);
794}
795
796static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
797{
798 s->blocknr = cpu_to_le64(val);
799}
800
Chris Mason0f7d52f2007-04-09 10:42:37 -0400801static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
802{
803 return le64_to_cpu(s->generation);
804}
805
806static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
807 u64 val)
808{
809 s->generation = cpu_to_le64(val);
810}
811
Chris Mason3768f362007-03-13 16:47:54 -0400812static inline u64 btrfs_super_root(struct btrfs_super_block *s)
813{
814 return le64_to_cpu(s->root);
815}
816
817static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
818{
819 s->root = cpu_to_le64(val);
820}
821
822static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
823{
824 return le64_to_cpu(s->total_blocks);
825}
826
827static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
828 u64 val)
829{
830 s->total_blocks = cpu_to_le64(val);
831}
832
833static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
834{
835 return le64_to_cpu(s->blocks_used);
836}
837
838static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
839 u64 val)
840{
841 s->blocks_used = cpu_to_le64(val);
842}
843
Chris Mason123abc82007-03-14 14:14:43 -0400844static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
Chris Mason3768f362007-03-13 16:47:54 -0400845{
Chris Mason123abc82007-03-14 14:14:43 -0400846 return le32_to_cpu(s->blocksize);
Chris Mason3768f362007-03-13 16:47:54 -0400847}
848
849static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
Chris Mason123abc82007-03-14 14:14:43 -0400850 u32 val)
Chris Mason3768f362007-03-13 16:47:54 -0400851{
Chris Mason123abc82007-03-14 14:14:43 -0400852 s->blocksize = cpu_to_le32(val);
853}
854
Chris Mason2e635a22007-03-21 11:12:56 -0400855static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
856{
857 return le64_to_cpu(s->root_dir_objectid);
858}
859
860static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
861 val)
862{
863 s->root_dir_objectid = cpu_to_le64(val);
864}
865
Chris Masonb4100d62007-04-12 12:14:00 -0400866static inline u64 btrfs_super_last_device_id(struct btrfs_super_block *s)
867{
868 return le64_to_cpu(s->last_device_id);
869}
870
871static inline void btrfs_set_super_last_device_id(struct btrfs_super_block *s,
872 u64 val)
873{
874 s->last_device_id = cpu_to_le64(val);
875}
876
877static inline u64 btrfs_super_device_id(struct btrfs_super_block *s)
878{
879 return le64_to_cpu(s->device_id);
880}
881
882static inline void btrfs_set_super_device_id(struct btrfs_super_block *s,
883 u64 val)
884{
885 s->device_id = cpu_to_le64(val);
886}
887
Chris Mason0bd93ba2007-04-11 13:57:44 -0400888static inline u64 btrfs_super_device_block_start(struct btrfs_super_block *s)
889{
890 return le64_to_cpu(s->device_block_start);
891}
892
893static inline void btrfs_set_super_device_block_start(struct btrfs_super_block
894 *s, u64 val)
895{
896 s->device_block_start = cpu_to_le64(val);
897}
898
899static inline u64 btrfs_super_device_num_blocks(struct btrfs_super_block *s)
900{
901 return le64_to_cpu(s->device_num_blocks);
902}
903
904static inline void btrfs_set_super_device_num_blocks(struct btrfs_super_block
905 *s, u64 val)
906{
907 s->device_num_blocks = cpu_to_le64(val);
908}
909
910static inline u64 btrfs_super_device_root(struct btrfs_super_block *s)
911{
912 return le64_to_cpu(s->device_root);
913}
914
915static inline void btrfs_set_super_device_root(struct btrfs_super_block
916 *s, u64 val)
917{
918 s->device_root = cpu_to_le64(val);
919}
920
921
Chris Mason123abc82007-03-14 14:14:43 -0400922static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
923{
924 return (u8 *)l->items;
Chris Mason3768f362007-03-13 16:47:54 -0400925}
Chris Mason9f5fae22007-03-20 14:38:32 -0400926
Chris Mason236454d2007-04-19 13:37:44 -0400927static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e)
928{
929 return e->type;
930}
931static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
932 u8 val)
933{
934 e->type = val;
935}
936
937static inline char *btrfs_file_extent_inline_start(struct
938 btrfs_file_extent_item *e)
939{
940 return (char *)(&e->disk_blocknr);
941}
942
943static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
944{
945 return (unsigned long)(&((struct
946 btrfs_file_extent_item *)NULL)->disk_blocknr) + datasize;
947}
948
949static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
950{
951 struct btrfs_file_extent_item *fe = NULL;
952 return btrfs_item_size(e) - (unsigned long)(&fe->disk_blocknr);
953}
954
Chris Mason9f5fae22007-03-20 14:38:32 -0400955static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
956 *e)
957{
958 return le64_to_cpu(e->disk_blocknr);
959}
960
961static inline void btrfs_set_file_extent_disk_blocknr(struct
962 btrfs_file_extent_item
963 *e, u64 val)
964{
965 e->disk_blocknr = cpu_to_le64(val);
966}
967
Chris Mason71951f32007-03-27 09:16:29 -0400968static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
969{
970 return le64_to_cpu(e->generation);
971}
972
973static inline void btrfs_set_file_extent_generation(struct
974 btrfs_file_extent_item *e,
975 u64 val)
976{
977 e->generation = cpu_to_le64(val);
978}
979
Chris Mason9f5fae22007-03-20 14:38:32 -0400980static inline u64 btrfs_file_extent_disk_num_blocks(struct
981 btrfs_file_extent_item *e)
982{
983 return le64_to_cpu(e->disk_num_blocks);
984}
985
986static inline void btrfs_set_file_extent_disk_num_blocks(struct
987 btrfs_file_extent_item
988 *e, u64 val)
989{
990 e->disk_num_blocks = cpu_to_le64(val);
991}
992
993static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
994{
995 return le64_to_cpu(e->offset);
996}
997
998static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
999 *e, u64 val)
1000{
1001 e->offset = cpu_to_le64(val);
1002}
1003
1004static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
1005 *e)
1006{
1007 return le64_to_cpu(e->num_blocks);
1008}
1009
1010static inline void btrfs_set_file_extent_num_blocks(struct
1011 btrfs_file_extent_item *e,
1012 u64 val)
1013{
1014 e->num_blocks = cpu_to_le64(val);
1015}
1016
Chris Mason0bd93ba2007-04-11 13:57:44 -04001017static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d)
1018{
1019 return le16_to_cpu(d->pathlen);
1020}
1021
1022static inline void btrfs_set_device_pathlen(struct btrfs_device_item *d,
1023 u16 val)
1024{
1025 d->pathlen = cpu_to_le16(val);
1026}
1027
Chris Masonb4100d62007-04-12 12:14:00 -04001028static inline u64 btrfs_device_id(struct btrfs_device_item *d)
1029{
1030 return le64_to_cpu(d->device_id);
1031}
1032
1033static inline void btrfs_set_device_id(struct btrfs_device_item *d,
1034 u64 val)
1035{
1036 d->device_id = cpu_to_le64(val);
1037}
1038
Chris Masone20d96d2007-03-22 12:13:20 -04001039static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
1040{
1041 return sb->s_fs_info;
1042}
1043
Chris Masond6025572007-03-30 14:27:56 -04001044static inline void btrfs_check_bounds(void *vptr, size_t len,
1045 void *vcontainer, size_t container_len)
1046{
1047 char *ptr = vptr;
1048 char *container = vcontainer;
1049 WARN_ON(ptr < container);
1050 WARN_ON(ptr + len > container + container_len);
1051}
1052
1053static inline void btrfs_memcpy(struct btrfs_root *root,
1054 void *dst_block,
1055 void *dst, const void *src, size_t nr)
1056{
1057 btrfs_check_bounds(dst, nr, dst_block, root->fs_info->sb->s_blocksize);
1058 memcpy(dst, src, nr);
1059}
1060
1061static inline void btrfs_memmove(struct btrfs_root *root,
1062 void *dst_block,
1063 void *dst, void *src, size_t nr)
1064{
1065 btrfs_check_bounds(dst, nr, dst_block, root->fs_info->sb->s_blocksize);
1066 memmove(dst, src, nr);
1067}
1068
1069static inline void btrfs_mark_buffer_dirty(struct buffer_head *bh)
1070{
1071 WARN_ON(!atomic_read(&bh->b_count));
1072 mark_buffer_dirty(bh);
1073}
1074
Chris Mason4beb1b82007-03-14 10:31:29 -04001075/* helper function to cast into the data area of the leaf. */
1076#define btrfs_item_ptr(leaf, slot, type) \
Chris Mason123abc82007-03-14 14:14:43 -04001077 ((type *)(btrfs_leaf_data(leaf) + \
1078 btrfs_item_offset((leaf)->items + (slot))))
Chris Mason4beb1b82007-03-14 10:31:29 -04001079
Chris Masonb18c6682007-04-17 13:26:50 -04001080/* extent-tree.c */
Chris Mason31f3c992007-04-30 15:25:45 -04001081struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
1082 struct btrfs_block_group_cache
Chris Masonbe744172007-05-06 10:15:01 -04001083 *hint, u64 search_start,
Chris Masonde428b62007-05-18 13:28:27 -04001084 int data, int owner);
Chris Masonc5739bb2007-04-10 09:27:04 -04001085int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
1086 struct btrfs_root *root);
Chris Masone20d96d2007-03-22 12:13:20 -04001087struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
Chris Mason31f3c992007-04-30 15:25:45 -04001088 struct btrfs_root *root, u64 hint);
Chris Mason4d775672007-04-20 20:23:12 -04001089int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1090 struct btrfs_root *root, u64 owner,
Chris Masonc62a1922007-04-24 12:07:39 -04001091 u64 num_blocks, u64 search_start,
Chris Masonbe08c1b2007-05-03 09:06:49 -04001092 u64 search_end, struct btrfs_key *ins, int data);
Chris Masone089f052007-03-16 16:20:31 -04001093int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
Chris Masone20d96d2007-03-22 12:13:20 -04001094 struct buffer_head *buf);
Chris Masone089f052007-03-16 16:20:31 -04001095int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1096 *root, u64 blocknr, u64 num_blocks, int pin);
Chris Masondee26a92007-03-26 16:00:06 -04001097int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
1098 btrfs_root *root);
Chris Masonb18c6682007-04-17 13:26:50 -04001099int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
1100 struct btrfs_root *root,
1101 u64 blocknr, u64 num_blocks);
Chris Mason9078a3e2007-04-26 16:46:15 -04001102int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1103 struct btrfs_root *root);
1104int btrfs_free_block_groups(struct btrfs_fs_info *info);
1105int btrfs_read_block_groups(struct btrfs_root *root);
Chris Masondee26a92007-03-26 16:00:06 -04001106/* ctree.c */
Chris Mason6567e832007-04-16 09:22:45 -04001107int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1108 *root, struct btrfs_path *path, u32 data_size);
Chris Masonb18c6682007-04-17 13:26:50 -04001109int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1110 struct btrfs_root *root,
1111 struct btrfs_path *path,
1112 u32 new_size);
Chris Masone089f052007-03-16 16:20:31 -04001113int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1114 *root, struct btrfs_key *key, struct btrfs_path *p, int
1115 ins_len, int cow);
Chris Mason234b63a2007-03-13 10:46:10 -04001116void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
Chris Mason2c90e5d2007-04-02 10:50:19 -04001117struct btrfs_path *btrfs_alloc_path(void);
1118void btrfs_free_path(struct btrfs_path *p);
Chris Mason234b63a2007-03-13 10:46:10 -04001119void btrfs_init_path(struct btrfs_path *p);
Chris Masone089f052007-03-16 16:20:31 -04001120int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1121 struct btrfs_path *path);
1122int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1123 *root, struct btrfs_key *key, void *data, u32 data_size);
1124int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
1125 *root, struct btrfs_path *path, struct btrfs_key
1126 *cpu_key, u32 data_size);
Chris Mason234b63a2007-03-13 10:46:10 -04001127int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
Chris Mason123abc82007-03-14 14:14:43 -04001128int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
Chris Masone089f052007-03-16 16:20:31 -04001129int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Masone20d96d2007-03-22 12:13:20 -04001130 *root, struct buffer_head *snap);
Chris Masondee26a92007-03-26 16:00:06 -04001131/* root-item.c */
Chris Masone089f052007-03-16 16:20:31 -04001132int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1133 struct btrfs_key *key);
1134int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1135 *root, struct btrfs_key *key, struct btrfs_root_item
1136 *item);
1137int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1138 *root, struct btrfs_key *key, struct btrfs_root_item
1139 *item);
1140int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1141 btrfs_root_item *item, struct btrfs_key *key);
Chris Masondee26a92007-03-26 16:00:06 -04001142/* dir-item.c */
Chris Masone089f052007-03-16 16:20:31 -04001143int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Masond6e4a422007-04-06 15:37:36 -04001144 *root, const char *name, int name_len, u64 dir,
1145 struct btrfs_key *location, u8 type);
Chris Mason7e381802007-04-19 15:36:27 -04001146struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
1147 struct btrfs_root *root,
1148 struct btrfs_path *path, u64 dir,
1149 const char *name, int name_len,
1150 int mod);
1151struct btrfs_dir_item *
1152btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
1153 struct btrfs_root *root,
1154 struct btrfs_path *path, u64 dir,
1155 u64 objectid, const char *name, int name_len,
1156 int mod);
1157struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
1158 struct btrfs_path *path,
Chris Mason7f5c1512007-03-23 15:56:19 -04001159 const char *name, int name_len);
Chris Mason7e381802007-04-19 15:36:27 -04001160int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
1161 struct btrfs_root *root,
1162 struct btrfs_path *path,
1163 struct btrfs_dir_item *di);
Chris Masondee26a92007-03-26 16:00:06 -04001164/* inode-map.c */
Chris Mason9f5fae22007-03-20 14:38:32 -04001165int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1166 struct btrfs_root *fs_root,
1167 u64 dirid, u64 *objectid);
Chris Mason5be6f7f2007-04-05 13:35:25 -04001168int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
1169
Chris Masondee26a92007-03-26 16:00:06 -04001170/* inode-item.c */
Chris Mason293ffd52007-03-20 15:57:25 -04001171int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1172 *root, u64 objectid, struct btrfs_inode_item
1173 *inode_item);
1174int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Masond6e4a422007-04-06 15:37:36 -04001175 *root, struct btrfs_path *path,
1176 struct btrfs_key *location, int mod);
Chris Masondee26a92007-03-26 16:00:06 -04001177
1178/* file-item.c */
Chris Masonb18c6682007-04-17 13:26:50 -04001179int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
Chris Masondee26a92007-03-26 16:00:06 -04001180 struct btrfs_root *root,
Chris Masonb18c6682007-04-17 13:26:50 -04001181 u64 objectid, u64 pos, u64 offset,
1182 u64 num_blocks);
Chris Masondee26a92007-03-26 16:00:06 -04001183int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
1184 struct btrfs_root *root,
1185 struct btrfs_path *path, u64 objectid,
Chris Mason9773a782007-03-27 11:26:26 -04001186 u64 blocknr, int mod);
Chris Masonf254e522007-03-29 15:15:27 -04001187int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
1188 struct btrfs_root *root,
1189 u64 objectid, u64 offset,
1190 char *data, size_t len);
1191int btrfs_csum_verify_file_block(struct btrfs_root *root,
1192 u64 objectid, u64 offset,
1193 char *data, size_t len);
Chris Masonb18c6682007-04-17 13:26:50 -04001194struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
1195 struct btrfs_root *root,
1196 struct btrfs_path *path,
1197 u64 objectid, u64 offset,
1198 int cow);
Chris Masond6e4a422007-04-06 15:37:36 -04001199/* super.c */
1200extern struct subsystem btrfs_subsys;
1201
Chris Masoneb60cea2007-02-02 09:18:22 -05001202#endif