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