btrfs-progs: convert: Introduce function to check if convert image is able to be...
[platform/upstream/btrfs-progs.git] / convert / source-fs.h
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public
4  * License v2 as published by the Free Software Foundation.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9  * General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the
13  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14  * Boston, MA 021110-1307, USA.
15  */
16
17 #ifndef __BTRFS_CONVERT_SOURCE_FS_H__
18 #define __BTRFS_CONVERT_SOURCE_FS_H__
19
20 #include "kerncompat.h"
21
22 #define CONV_IMAGE_SUBVOL_OBJECTID BTRFS_FIRST_FREE_OBJECTID
23
24 /*
25  * Reresents a simple contiguous range.
26  *
27  * For multiple or non-contiguous ranges, use extent_cache_tree from
28  * extent-cache.c
29  */
30 struct simple_range {
31         u64 start;
32         u64 len;
33 };
34
35 extern struct simple_range btrfs_reserved_ranges[3];
36
37 struct task_info;
38
39 struct task_ctx {
40         u64 max_copy_inodes;
41         u64 cur_copy_inodes;
42         struct task_info *info;
43 };
44
45 struct btrfs_convert_context;
46
47 #define SOURCE_FS_NAME_LEN      (16)
48
49 #define CONVERT_FLAG_DATACSUM           (1U << 0)
50 #define CONVERT_FLAG_INLINE_DATA        (1U << 1)
51 #define CONVERT_FLAG_XATTR              (1U << 2)
52 #define CONVERT_FLAG_COPY_LABEL         (1U << 3)
53 #define CONVERT_FLAG_SET_LABEL          (1U << 4)
54
55 struct btrfs_convert_operations {
56         const char name[SOURCE_FS_NAME_LEN];
57         int (*open_fs)(struct btrfs_convert_context *cctx, const char *devname);
58         int (*read_used_space)(struct btrfs_convert_context *cctx);
59         int (*copy_inodes)(struct btrfs_convert_context *cctx,
60                          struct btrfs_root *root, u32 covert_flags,
61                          struct task_ctx *p);
62         void (*close_fs)(struct btrfs_convert_context *cctx);
63         int (*check_state)(struct btrfs_convert_context *cctx);
64 };
65
66 struct btrfs_trans_handle;
67 struct btrfs_root;
68 struct btrfs_inode_item;
69
70 struct blk_iterate_data {
71         struct btrfs_trans_handle *trans;
72         struct btrfs_root *root;
73         struct btrfs_root *convert_root;
74         struct btrfs_inode_item *inode;
75         u64 convert_ino;
76         u64 objectid;
77         u64 first_block;
78         u64 disk_block;
79         u64 num_blocks;
80         u64 boundary;
81         int checksum;
82         int errcode;
83 };
84
85 void init_convert_context(struct btrfs_convert_context *cctx);
86 void clean_convert_context(struct btrfs_convert_context *cctx);
87 int block_iterate_proc(u64 disk_block, u64 file_block,
88                               struct blk_iterate_data *idata);
89 void init_blk_iterate_data(struct blk_iterate_data *data,
90                                   struct btrfs_trans_handle *trans,
91                                   struct btrfs_root *root,
92                                   struct btrfs_inode_item *inode,
93                                   u64 objectid, int checksum);
94 int convert_insert_dirent(struct btrfs_trans_handle *trans,
95                                  struct btrfs_root *root,
96                                  const char *name, size_t name_len,
97                                  u64 dir, u64 objectid,
98                                  u8 file_type, u64 index_cnt,
99                                  struct btrfs_inode_item *inode);
100 int read_disk_extent(struct btrfs_root *root, u64 bytenr,
101                             u32 num_bytes, char *buffer);
102 int record_file_blocks(struct blk_iterate_data *data,
103                               u64 file_block, u64 disk_block, u64 num_blocks);
104
105 /*
106  * Simple range functions
107  *
108  * Get range end (exclusive)
109  */
110 static inline u64 range_end(struct simple_range *range)
111 {
112         return (range->start + range->len);
113 }
114
115 #endif