diff options
author | Karel Zak | 2016-01-26 14:39:13 +0100 |
---|---|---|
committer | Karel Zak | 2016-01-26 14:39:13 +0100 |
commit | 5a9713293d5f0e20230646fc403ec4a5bf8c1a1f (patch) | |
tree | 3b3c7318dcbe66734c05d683fcaf070abdd7ca52 /libmount/src/btrfs.c | |
parent | more: remove unnecessary compatibility layer (diff) | |
download | kernel-qcow2-util-linux-5a9713293d5f0e20230646fc403ec4a5bf8c1a1f.tar.gz kernel-qcow2-util-linux-5a9713293d5f0e20230646fc403ec4a5bf8c1a1f.tar.xz kernel-qcow2-util-linux-5a9713293d5f0e20230646fc403ec4a5bf8c1a1f.zip |
libmount: consolidate btrfs stuff, make it more portable
- add --with-btrfs (enabled by default)
- check for linux/btrfs.h
- add "btrfs" to libmount features list (see mount -V)
- #ifdef HAVE_BTRFS_SUPPORT for all btrfs stuff in libmount
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/btrfs.c')
-rw-r--r-- | libmount/src/btrfs.c | 90 |
1 files changed, 81 insertions, 9 deletions
diff --git a/libmount/src/btrfs.c b/libmount/src/btrfs.c index 3c61a2a03..1db604a87 100644 --- a/libmount/src/btrfs.c +++ b/libmount/src/btrfs.c @@ -1,4 +1,5 @@ /* + * Copyright (C) 1999 Andrea Arcangeli <andrea@suse.de> * Copyright (C) 2016 David Sterba <dsterba@suse.cz> * Copyright (C) 2016 Stanislav Brabec <sbrabec@suse.cz> * @@ -6,17 +7,89 @@ * GNU Lesser General Public License. */ +#include <dirent.h> +#include <sys/ioctl.h> +#include <libio.h> +#include <stdint.h> +#include <linux/btrfs.h> + +#include "mountP.h" +#include "bitops.h" + + +/* linux/btrfs.h lacks large parts of stuff needed for getting default + * sub-volume. Suppose that if BTRFS_DIR_ITEM_KEY is not defined, all + * declarations are still missing. + */ +#ifndef BTRFS_DIR_ITEM_KEY + +/* + * dir items are the name -> inode pointers in a directory. There is one + * for every name in a directory. + */ +#define BTRFS_DIR_ITEM_KEY 84 + +/* holds pointers to all of the tree roots */ +#define BTRFS_ROOT_TREE_OBJECTID 1ULL + +/* directory objectid inside the root tree */ +#define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL + /* - * SECTION: btrfs - * @title: btrfs - * @short_description: special function for btrfs + * the key defines the order in the tree, and so it also defines (optimal) + * block layout. objectid corresonds to the inode number. The flags + * tells us things about the object, and is a kind of stream selector. + * so for a given inode, keys with flags of 1 might refer to the inode + * data, flags of 2 may point to file data in the btree and flags == 3 + * may point to extents. * - * btrfs contains function needed for manipulation with btrfs. + * offset is the starting byte offset for this key in the stream. + * + * btrfs_disk_key is in disk byte order. struct btrfs_key is always + * in cpu native order. Otherwise they are identical and their sizes + * should be the same (ie both packed) */ -#include <dirent.h> -#include <sys/ioctl.h> -#include <linux/magic.h> -#include "btrfs.h" +struct btrfs_disk_key { + uint64_t objectid; /* little endian */ + uint8_t type; + uint64_t offset; /* little endian */ +} __attribute__ ((__packed__)); + +struct btrfs_dir_item { + struct btrfs_disk_key location; + uint64_t transid; /* little endian */ + uint16_t data_len; /* little endian */ + uint16_t name_len; /* little endian */ + uint8_t type; +} __attribute__ ((__packed__)); + +#define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \ +static inline uint##bits##_t btrfs_##name(const type *s) \ +{ \ + return le##bits##_to_cpu(s->member); \ +} \ +static inline void btrfs_set_##name(type *s, uint##bits##_t val) \ +{ \ + s->member = cpu_to_le##bits(val); \ +} + +/* struct btrfs_disk_key */ +BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, + objectid, 64); + +BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item, name_len, 16); + +/* + Red Black Trees +*/ +struct rb_node { + unsigned long __rb_parent_color; + struct rb_node *rb_right; + struct rb_node *rb_left; +} __attribute__((aligned(sizeof(long)))); + /* The alignment might seem pointless, but allegedly CRIS needs it */ + +#endif /* BTRFS_DIR_ITEM_KEY */ /* * btrfs_get_default_subvol_id: @@ -97,6 +170,5 @@ uint64_t btrfs_get_default_subvol_id(const char *path) out: closedir(dirstream); - return found; } |