6c0ba722c200b9509bd8b2bfad1694d2944081f5
[platform/upstream/btrfs-progs.git] / disk-io.h
1 /*
2  * Copyright (C) 2007 Oracle.  All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public
6  * License v2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public
14  * License along with this program; if not, write to the
15  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16  * Boston, MA 021110-1307, USA.
17  */
18
19 #ifndef __DISKIO__
20 #define __DISKIO__
21 #include "list.h"
22
23 struct btrfs_buffer {
24         u64 blocknr;
25         u64 dev_blocknr;
26         u32 size;
27         int count;
28         int fd;
29         struct list_head dirty;
30         struct list_head cache;
31         union {
32                 struct btrfs_node node;
33                 struct btrfs_leaf leaf;
34         };
35 };
36
37 struct btrfs_buffer *read_tree_block(struct btrfs_root *root, u64 blocknr);
38 struct btrfs_buffer *find_tree_block(struct btrfs_root *root, u64 blocknr);
39 int write_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
40                      struct btrfs_buffer *buf);
41 int dirty_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
42                      struct btrfs_buffer *buf);
43 int clean_tree_block(struct btrfs_trans_handle *trans,
44                      struct btrfs_root *root, struct btrfs_buffer *buf);
45 int btrfs_commit_transaction(struct btrfs_trans_handle *trans, struct btrfs_root
46                              *root, struct btrfs_super_block *s);
47 struct btrfs_root *open_ctree(char *filename, struct btrfs_super_block *s);
48 struct btrfs_root *open_ctree_fd(int fp, struct btrfs_super_block *super);
49 int close_ctree(struct btrfs_root *root, struct btrfs_super_block *s);
50 void btrfs_block_release(struct btrfs_root *root, struct btrfs_buffer *buf);
51 int write_ctree_super(struct btrfs_trans_handle *trans, struct btrfs_root *root,
52                       struct btrfs_super_block *s);
53 int btrfs_map_bh_to_logical(struct btrfs_root *root, struct btrfs_buffer *bh,
54                              u64 logical);
55 int btrfs_csum_super(struct btrfs_root *root, struct btrfs_super_block *super);
56 int btrfs_csum_node(struct btrfs_root *root, struct btrfs_node *node);
57 #define BTRFS_SUPER_INFO_OFFSET (16 * 1024)
58
59 #endif