3eb982e891ebbeafaa6d1bf38d019ad94d9c58a9
[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 "extent-cache.h"
22 #include "list.h"
23
24 struct btrfs_buffer {
25         struct cache_extent cache_node;
26         u64 bytenr;
27         u64 dev_bytenr;
28         u32 size;
29         int count;
30         int fd;
31         struct list_head dirty;
32         struct list_head cache;
33         union {
34                 struct btrfs_node node;
35                 struct btrfs_leaf leaf;
36         };
37 };
38
39 struct btrfs_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
40                                      u32 blocksize);
41 struct btrfs_buffer *find_tree_block(struct btrfs_root *root, u64 bytenr,
42                                      u32 blocksize);
43 int write_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
44                      struct btrfs_buffer *buf);
45 int dirty_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
46                      struct btrfs_buffer *buf);
47 int clean_tree_block(struct btrfs_trans_handle *trans,
48                      struct btrfs_root *root, struct btrfs_buffer *buf);
49 int btrfs_commit_transaction(struct btrfs_trans_handle *trans, struct btrfs_root
50                              *root, struct btrfs_super_block *s);
51 struct btrfs_root *open_ctree(char *filename, struct btrfs_super_block *s);
52 struct btrfs_root *open_ctree_fd(int fp, struct btrfs_super_block *super);
53 int close_ctree(struct btrfs_root *root, struct btrfs_super_block *s);
54 void btrfs_block_release(struct btrfs_root *root, struct btrfs_buffer *buf);
55 int write_ctree_super(struct btrfs_trans_handle *trans, struct btrfs_root *root,
56                       struct btrfs_super_block *s);
57 int btrfs_map_bh_to_logical(struct btrfs_root *root, struct btrfs_buffer *bh,
58                              u64 logical);
59 int btrfs_csum_super(struct btrfs_root *root, struct btrfs_super_block *super);
60 int btrfs_csum_node(struct btrfs_root *root, struct btrfs_node *node);
61 #define BTRFS_SUPER_INFO_OFFSET (16 * 1024)
62
63 #endif