1 /* SPDX-License-Identifier: LGPL-2.1+ */
7 #include <linux/types.h> /* __le64, __l32 ... */
11 #ifndef BTRFS_SUPER_MAGIC
12 # define BTRFS_SUPER_MAGIC 0x9123683E
20 struct btrfs_ioctl_space_info
{
21 unsigned long long flags
;
22 unsigned long long total_bytes
;
23 unsigned long long used_bytes
;
26 struct btrfs_ioctl_space_args
{
27 unsigned long long space_slots
;
28 unsigned long long total_spaces
;
29 struct btrfs_ioctl_space_info spaces
[];
32 #define BTRFS_IOCTL_MAGIC 0x94
33 #define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, unsigned long long)
34 #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
35 struct btrfs_ioctl_space_args)
37 #define BTRFS_FSID_SIZE 16
38 struct btrfs_ioctl_fs_info_args
{
39 unsigned long long max_id
;
40 unsigned long long num_devices
;
41 char fsid
[BTRFS_FSID_SIZE
];
42 unsigned long long reserved
[124];
45 #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
46 struct btrfs_ioctl_fs_info_args)
49 #define BTRFS_SUBVOL_NAME_MAX 4039
50 #define BTRFS_PATH_NAME_MAX 4087
52 struct btrfs_ioctl_vol_args
{
54 char name
[BTRFS_PATH_NAME_MAX
+ 1];
57 #define BTRFS_IOCTL_MAGIC 0x94
58 #define BTRFS_IOC_SUBVOL_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 24, \
59 struct btrfs_ioctl_vol_args_v2)
60 #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
61 struct btrfs_ioctl_vol_args_v2)
62 #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
63 struct btrfs_ioctl_vol_args)
64 #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
65 struct btrfs_ioctl_vol_args)
67 #define BTRFS_QGROUP_INHERIT_SET_LIMITS (1ULL << 0)
69 struct btrfs_ioctl_vol_args_v2
{
71 unsigned long long transid
;
72 unsigned long long flags
;
75 unsigned long long size
;
76 /*struct btrfs_qgroup_inherit *qgroup_inherit; */
79 unsigned long long unused
[4];
81 char name
[BTRFS_SUBVOL_NAME_MAX
+ 1];
85 * root backrefs tie subvols and snapshots to the directory entries that
88 #define BTRFS_ROOT_BACKREF_KEY 144
91 * root items point to tree roots. There are typically in the root
92 * tree used by the super block to find all the other trees
94 #define BTRFS_ROOT_ITEM_KEY 132
97 * root refs make a fast index for listing all of the snapshots and
98 * subvolumes referenced by a given root. They point directly to the
99 * directory item in the root that references the subvol
101 #define BTRFS_ROOT_REF_KEY 156
103 #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
104 #define BTRFS_DIR_ITEM_KEY 84
107 * * this is used for both forward and backward root refs
109 struct btrfs_root_ref
{
113 } __attribute__ ((__packed__
));
115 struct btrfs_disk_key
{
119 } __attribute__ ((__packed__
));
121 struct btrfs_dir_item
{
122 struct btrfs_disk_key location
;
127 } __attribute__ ((__packed__
));
129 #define BTRFS_IOCTL_MAGIC 0x94
130 #define BTRFS_VOL_NAME_MAX 255
131 #define BTRFS_PATH_NAME_MAX 4087
133 struct btrfs_ioctl_search_key
{
134 /* which root are we searching. 0 is the tree of tree roots */
137 /* keys returned will be >= min and <= max */
141 /* keys returned will be >= min and <= max */
145 /* max and min transids to search for */
149 /* keys returned will be >= min and <= max */
154 * how many items did userland ask for, and how many are we
159 /* align to 64 bits */
162 /* some extra for later */
169 struct btrfs_ioctl_search_header
{
175 } __attribute__((may_alias
));
177 #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
179 * the buf is an array of search headers where
180 * each header is followed by the actual item
181 * the type field is expanded to 32 bits for alignment
183 struct btrfs_ioctl_search_args
{
184 struct btrfs_ioctl_search_key key
;
185 char buf
[BTRFS_SEARCH_ARGS_BUFSIZE
];
188 #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \
189 struct btrfs_ioctl_search_args)
190 #define BTRFS_UUID_SIZE 16
192 struct btrfs_timespec
{
195 } __attribute__ ((__packed__
));
197 struct btrfs_inode_item
{
198 /* nfs style generation number */
200 /* transid that last touched this inode */
212 /* modification sequence number for NFS */
216 * a little future expansion, for more than this we can
217 * just grow the inode item and version it
220 struct btrfs_timespec atime
;
221 struct btrfs_timespec ctime
;
222 struct btrfs_timespec mtime
;
223 struct btrfs_timespec otime
;
224 } __attribute__ ((__packed__
));
226 struct btrfs_root_item_v0
{
227 struct btrfs_inode_item inode
;
233 __le64 last_snapshot
;
236 struct btrfs_disk_key drop_progress
;
239 } __attribute__ ((__packed__
));
241 struct btrfs_root_item
{
242 struct btrfs_inode_item inode
;
248 __le64 last_snapshot
;
251 struct btrfs_disk_key drop_progress
;
256 * The following fields appear after subvol_uuids+subvol_times
261 * This generation number is used to test if the new fields are valid
262 * and up to date while reading the root item. Every time the root item
263 * is written out, the "generation" field is copied into this field. If
264 * anyone ever mounted the fs with an older kernel, we will have
265 * mismatching generation values here and thus must invalidate the
266 * new fields. See btrfs_update_root and btrfs_find_last_root for
268 * the offset of generation_v2 is also used as the start for the memset
269 * when invalidating the fields.
271 __le64 generation_v2
;
272 u8 uuid
[BTRFS_UUID_SIZE
];
273 u8 parent_uuid
[BTRFS_UUID_SIZE
];
274 u8 received_uuid
[BTRFS_UUID_SIZE
];
275 __le64 ctransid
; /* updated when an inode changes */
276 __le64 otransid
; /* trans when created */
277 __le64 stransid
; /* trans when sent. non-zero for received subvol */
278 __le64 rtransid
; /* trans when received. non-zero for received subvol */
279 struct btrfs_timespec ctime
;
280 struct btrfs_timespec otime
;
281 struct btrfs_timespec stime
;
282 struct btrfs_timespec rtime
;
283 __le64 reserved
[8]; /* for future */
284 } __attribute__ ((__packed__
));
286 #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
287 struct btrfs_ioctl_ino_lookup_args)
289 #define BTRFS_INO_LOOKUP_PATH_MAX 4080
290 struct btrfs_ioctl_ino_lookup_args
{
293 char name
[BTRFS_INO_LOOKUP_PATH_MAX
];
297 * All files have objectids in this range.
299 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
300 #define BTRFS_LAST_FREE_OBJECTID -256ULL
301 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
304 * The followings are macro for correctly getting member of
305 * structures in both low and big endian platforms as per
309 #define __force __attribute__((force))
314 #if __BYTE_ORDER == __BIG_ENDIAN
315 #define cpu_to_le64(x) ((__force __le64)(u64)(bswap_64(x)))
316 #define le64_to_cpu(x) ((__force u64)(__le64)(bswap_64(x)))
317 #define cpu_to_le32(x) ((__force __le32)(u32)(bswap_32(x)))
318 #define le32_to_cpu(x) ((__force u32)(__le32)(bswap_32(x)))
319 #define cpu_to_le16(x) ((__force __le16)(u16)(bswap_16(x)))
320 #define le16_to_cpu(x) ((__force u16)(__le16)(bswap_16(x)))
322 #define cpu_to_le64(x) ((__force __le64)(u64)(x))
323 #define le64_to_cpu(x) ((__force u64)(__le64)(x))
324 #define cpu_to_le32(x) ((__force __le32)(u32)(x))
325 #define le32_to_cpu(x) ((__force u32)(__le32)(x))
326 #define cpu_to_le16(x) ((__force __le16)(u16)(x))
327 #define le16_to_cpu(x) ((__force u16)(__le16)(x))
330 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
331 static inline u##bits btrfs_##name(type *s) \
333 return le##bits##_to_cpu(s->member); \
335 static inline void btrfs_set_##name(type *s, u##bits val) \
337 s->member = cpu_to_le##bits(val); \
340 /* defined as btrfs_stack_root_ref_dirid */
341 BTRFS_SETGET_STACK_FUNCS(stack_root_ref_dirid
, struct btrfs_root_ref
, dirid
, 64);
342 /* defined as btrfs_stack_root_ref_sequence */
343 BTRFS_SETGET_STACK_FUNCS(stack_root_ref_sequence
, struct btrfs_root_ref
, sequence
, 64);
344 /* defined as btrfs_stack_root_ref_name_len */
345 BTRFS_SETGET_STACK_FUNCS(stack_root_ref_name_len
, struct btrfs_root_ref
, name_len
, 16);
360 struct my_btrfs_tree
{
361 struct mytree_node
*nodes
;
365 extern int btrfs_clonepaths(struct lxc_storage
*orig
, struct lxc_storage
*new,
366 const char *oldname
, const char *cname
,
367 const char *oldpath
, const char *lxcpath
, int snap
,
368 uint64_t newsize
, struct lxc_conf
*conf
);
369 extern int btrfs_create(struct lxc_storage
*bdev
, const char *dest
,
370 const char *n
, struct bdev_specs
*specs
);
371 extern int btrfs_destroy(struct lxc_storage
*orig
);
372 extern bool btrfs_detect(const char *path
);
373 extern int btrfs_mount(struct lxc_storage
*bdev
);
374 extern int btrfs_umount(struct lxc_storage
*bdev
);
376 extern char *get_btrfs_subvol_path(int fd
, u64 dir_id
, u64 objid
, char *name
,
378 extern int btrfs_list_get_path_rootid(int fd
, u64
*treeid
);
379 extern bool is_btrfs_fs(const char *path
);
380 extern int is_btrfs_subvol(const char *path
);
381 extern bool btrfs_try_remove_subvol(const char *path
);
382 extern int btrfs_same_fs(const char *orig
, const char *new);
383 extern int btrfs_snapshot(const char *orig
, const char *new);
384 extern int btrfs_snapshot_wrapper(void *data
);
385 extern bool btrfs_create_clone(struct lxc_conf
*conf
, struct lxc_storage
*orig
,
386 struct lxc_storage
*new, uint64_t newsize
);
387 extern bool btrfs_create_snapshot(struct lxc_conf
*conf
,
388 struct lxc_storage
*orig
,
389 struct lxc_storage
*new, uint64_t newsize
);
391 #endif /* __LXC_BTRFS_H */