btrfs-progs: check: enhance return values of walk_down_tree_v2
[btrfs-progs-unstable/devel.git] / send-utils.h
blobe8f86912b246b7df942b23025691f95e0f2a8bc0
1 /*
2 * Copyright (C) 2012 Alexander Block. All rights reserved.
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.
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.
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.
19 #ifndef __BTRFS_SEND_UTILS_H__
20 #define __BTRFS_SEND_UTILS_H__
22 #if BTRFS_FLAT_INCLUDES
23 #include "kerncompat.h"
24 #include "ctree.h"
25 #include "rbtree.h"
26 #else
27 #include <btrfs/kerncompat.h>
28 #include <btrfs/ctree.h>
29 #include <btrfs/rbtree.h>
30 #endif /* BTRFS_FLAT_INCLUDES */
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
37 * Compatibility code for kernels < 3.12; the UUID tree is not available there
38 * and we have to do the slow search. This should be deprecated someday.
40 #define BTRFS_COMPAT_SEND_NO_UUID_TREE 1
42 enum subvol_search_type {
43 subvol_search_by_root_id,
44 subvol_search_by_uuid,
45 subvol_search_by_received_uuid,
46 subvol_search_by_path,
49 struct subvol_info {
50 #ifdef BTRFS_COMPAT_SEND_NO_UUID_TREE
51 struct rb_node rb_root_id_node;
52 struct rb_node rb_local_node;
53 struct rb_node rb_received_node;
54 struct rb_node rb_path_node;
55 #endif
57 u64 root_id;
58 u8 uuid[BTRFS_UUID_SIZE];
59 u8 parent_uuid[BTRFS_UUID_SIZE];
60 u8 received_uuid[BTRFS_UUID_SIZE];
61 u64 ctransid;
62 u64 otransid;
63 u64 stransid;
64 u64 rtransid;
66 char *path;
69 struct subvol_uuid_search {
70 int mnt_fd;
71 #ifdef BTRFS_COMPAT_SEND_NO_UUID_TREE
72 int uuid_tree_existed;
74 struct rb_root root_id_subvols;
75 struct rb_root local_subvols;
76 struct rb_root received_subvols;
77 struct rb_root path_subvols;
78 #endif
81 int subvol_uuid_search_init(int mnt_fd, struct subvol_uuid_search *s);
82 void subvol_uuid_search_finit(struct subvol_uuid_search *s);
84 * Search for a subvolume by given type (received uuid, root id, path), returns
85 * pointer to newly allocated struct subvol_info or NULL in case it's not found
86 * or there was another error. This ambiguity of error value is fixed by
87 * subvol_uuid_search2 that returns a negative errno in case of an error, of a
88 * valid pointer otherwise.
90 * This function will be deprecated in the future, please consider using v2 in
91 * new code unless you need to keep backward compatibility with older
92 * btrfs-progs.
94 struct subvol_info *subvol_uuid_search(struct subvol_uuid_search *s,
95 u64 root_id, const u8 *uuid, u64 transid,
96 const char *path,
97 enum subvol_search_type type);
98 struct subvol_info *subvol_uuid_search2(struct subvol_uuid_search *s,
99 u64 root_id, const u8 *uuid, u64 transid,
100 const char *path,
101 enum subvol_search_type type);
102 void subvol_uuid_search_add(struct subvol_uuid_search *s,
103 struct subvol_info *si);
105 int btrfs_subvolid_resolve(int fd, char *path, size_t path_len, u64 subvol_id);
108 * DEPRECATED: the functions path_cat and path_cat3 are unsafe and should not
109 * be used, use the _out variants and always check the return code.
111 __attribute__((deprecated))
112 char *path_cat(const char *p1, const char *p2);
113 __attribute__((deprecated))
114 char *path_cat3(const char *p1, const char *p2, const char *p3);
116 int path_cat_out(char *out, const char *p1, const char *p2);
117 int path_cat3_out(char *out, const char *p1, const char *p2, const char *p3);
119 #ifdef __cplusplus
121 #endif
123 #endif