btrfs-progs: enclose uuid tree compat code with ifdefs
[platform/upstream/btrfs-progs.git] / send-utils.h
1 /*
2  * Copyright (C) 2012 Alexander Block.  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 #ifndef SEND_UTILS_H_
19 #define SEND_UTILS_H_
20
21 #if BTRFS_FLAT_INCLUDES
22 #include "ctree.h"
23 #include "rbtree.h"
24 #else
25 #include <btrfs/ctree.h>
26 #include <btrfs/rbtree.h>
27 #endif /* BTRFS_FLAT_INCLUDES */
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 /*
34  * Compatibility code for kernels < 3.12; the UUID tree is not available there
35  * and we have to do the slow search. This should be deprecated someday.
36  */
37 #define BTRFS_COMPAT_SEND_NO_UUID_TREE 1
38
39 enum subvol_search_type {
40         subvol_search_by_root_id,
41         subvol_search_by_uuid,
42         subvol_search_by_received_uuid,
43         subvol_search_by_path,
44 };
45
46 struct subvol_info {
47 #ifdef BTRFS_COMPAT_SEND_NO_UUID_TREE
48         struct rb_node rb_root_id_node;
49         struct rb_node rb_local_node;
50         struct rb_node rb_received_node;
51         struct rb_node rb_path_node;
52 #endif
53
54         u64 root_id;
55         u8 uuid[BTRFS_UUID_SIZE];
56         u8 parent_uuid[BTRFS_UUID_SIZE];
57         u8 received_uuid[BTRFS_UUID_SIZE];
58         u64 ctransid;
59         u64 otransid;
60         u64 stransid;
61         u64 rtransid;
62
63         char *path;
64 };
65
66 struct subvol_uuid_search {
67         int mnt_fd;
68 #ifdef BTRFS_COMPAT_SEND_NO_UUID_TREE
69         int uuid_tree_existed;
70
71         struct rb_root root_id_subvols;
72         struct rb_root local_subvols;
73         struct rb_root received_subvols;
74         struct rb_root path_subvols;
75 #endif
76 };
77
78 int subvol_uuid_search_init(int mnt_fd, struct subvol_uuid_search *s);
79 void subvol_uuid_search_finit(struct subvol_uuid_search *s);
80 struct subvol_info *subvol_uuid_search(struct subvol_uuid_search *s,
81                                        u64 root_id, const u8 *uuid, u64 transid,
82                                        const char *path,
83                                        enum subvol_search_type type);
84 void subvol_uuid_search_add(struct subvol_uuid_search *s,
85                             struct subvol_info *si);
86
87 int btrfs_subvolid_resolve(int fd, char *path, size_t path_len, u64 subvol_id);
88
89 char *path_cat(const char *p1, const char *p2);
90 char *path_cat3(const char *p1, const char *p2, const char *p3);
91
92 #ifdef __cplusplus
93 }
94 #endif
95
96 #endif /* SEND_UTILS_H_ */