libbtrfsutil: always build libbtrfsutil.so.$MAJOR
[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 #include <linux/kdev_t.h>
22 #include <sys/types.h>
23 #include <pthread.h>
24 #include <sys/types.h>
25
26 #define CONV_IMAGE_SUBVOL_OBJECTID BTRFS_FIRST_FREE_OBJECTID
27
28 /*
29  * Reresents a simple contiguous range.
30  *
31  * For multiple or non-contiguous ranges, use extent_cache_tree from
32  * extent-cache.c
33  */
34 struct simple_range {
35         u64 start;
36         u64 len;
37 };
38
39 extern const struct simple_range btrfs_reserved_ranges[3];
40
41 struct task_info;
42
43 struct task_ctx {
44         pthread_mutex_t mutex;
45         u64 max_copy_inodes;
46         u64 cur_copy_inodes;
47         struct task_info *info;
48 };
49
50 struct btrfs_convert_context;
51
52 #define SOURCE_FS_NAME_LEN      (16)
53
54 #define CONVERT_FLAG_DATACSUM           (1U << 0)
55 #define CONVERT_FLAG_INLINE_DATA        (1U << 1)
56 #define CONVERT_FLAG_XATTR              (1U << 2)
57 #define CONVERT_FLAG_COPY_LABEL         (1U << 3)
58 #define CONVERT_FLAG_SET_LABEL          (1U << 4)
59
60 /* 23.2.5 acl_tag_t values */
61
62 #define ACL_UNDEFINED_TAG       (0x00)
63 #define ACL_USER_OBJ            (0x01)
64 #define ACL_USER                (0x02)
65 #define ACL_GROUP_OBJ           (0x04)
66 #define ACL_GROUP               (0x08)
67 #define ACL_MASK                (0x10)
68 #define ACL_OTHER               (0x20)
69
70 /* 23.2.7 ACL qualifier constants */
71
72 #define ACL_UNDEFINED_ID        ((id_t)-1)
73
74 #define ACL_EA_VERSION          0x0002
75
76 typedef struct {
77         __le16          e_tag;
78         __le16          e_perm;
79         __le32          e_id;
80 } acl_ea_entry;
81
82 typedef struct {
83         __le32          a_version;
84         acl_ea_entry    a_entries[0];
85 } acl_ea_header;
86
87 typedef struct {
88         __le16          e_tag;
89         __le16          e_perm;
90         __le32          e_id;
91 } ext2_acl_entry;
92
93 typedef struct {
94         __le16          e_tag;
95         __le16          e_perm;
96 } ext2_acl_entry_short;
97
98 typedef struct {
99         __le32          a_version;
100 } ext2_acl_header;
101
102 static inline size_t acl_ea_size(int count)
103 {
104         return sizeof(acl_ea_header) + count * sizeof(acl_ea_entry);
105 }
106
107 int ext2_acl_count(size_t size);
108
109 #ifndef MKDEV
110 #define MINORBITS       20
111 #define MKDEV(ma, mi)   (((ma) << MINORBITS) | (mi))
112 #endif
113
114 dev_t decode_dev(u32 dev);
115
116 struct btrfs_convert_operations {
117         const char name[SOURCE_FS_NAME_LEN];
118         int (*open_fs)(struct btrfs_convert_context *cctx, const char *devname);
119         int (*read_used_space)(struct btrfs_convert_context *cctx);
120         int (*copy_inodes)(struct btrfs_convert_context *cctx,
121                          struct btrfs_root *root, u32 covert_flags,
122                          struct task_ctx *p);
123         void (*close_fs)(struct btrfs_convert_context *cctx);
124         int (*check_state)(struct btrfs_convert_context *cctx);
125 };
126
127 struct btrfs_trans_handle;
128 struct btrfs_root;
129 struct btrfs_inode_item;
130
131 struct blk_iterate_data {
132         struct btrfs_trans_handle *trans;
133         struct btrfs_root *root;
134         struct btrfs_root *convert_root;
135         struct btrfs_inode_item *inode;
136         u64 convert_ino;
137         u64 objectid;
138         u64 first_block;
139         u64 disk_block;
140         u64 num_blocks;
141         u64 boundary;
142         int checksum;
143         int errcode;
144 };
145
146 void init_convert_context(struct btrfs_convert_context *cctx);
147 void clean_convert_context(struct btrfs_convert_context *cctx);
148 int block_iterate_proc(u64 disk_block, u64 file_block,
149                               struct blk_iterate_data *idata);
150 void init_blk_iterate_data(struct blk_iterate_data *data,
151                                   struct btrfs_trans_handle *trans,
152                                   struct btrfs_root *root,
153                                   struct btrfs_inode_item *inode,
154                                   u64 objectid, int checksum);
155 int convert_insert_dirent(struct btrfs_trans_handle *trans,
156                                  struct btrfs_root *root,
157                                  const char *name, size_t name_len,
158                                  u64 dir, u64 objectid,
159                                  u8 file_type, u64 index_cnt,
160                                  struct btrfs_inode_item *inode);
161 int read_disk_extent(struct btrfs_root *root, u64 bytenr,
162                             u32 num_bytes, char *buffer);
163 int record_file_blocks(struct blk_iterate_data *data,
164                               u64 file_block, u64 disk_block, u64 num_blocks);
165
166 /*
167  * Simple range functions
168  *
169  * Get range end (exclusive)
170  */
171 static inline u64 range_end(const struct simple_range *range)
172 {
173         return (range->start + range->len);
174 }
175
176 #endif