btrfs-progs: tests: mkfs/008 mkfs with force
[platform/upstream/btrfs-progs.git] / ctree.h
diff --git a/ctree.h b/ctree.h
index c457a8d..ef422ea 100644 (file)
--- a/ctree.h
+++ b/ctree.h
@@ -19,6 +19,8 @@
 #ifndef __BTRFS_CTREE_H__
 #define __BTRFS_CTREE_H__
 
+#include <stdbool.h>
+
 #if BTRFS_FLAT_INCLUDES
 #include "list.h"
 #include "kerncompat.h"
@@ -138,6 +140,8 @@ struct btrfs_free_space_ctl;
  */
 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
 
+#define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2ULL
+
 /*
  * the max metadata block size.  This limit is somewhat artificial,
  * but the memmove costs go through the roof for larger blocks.
@@ -352,11 +356,11 @@ struct btrfs_header {
        u8 level;
 } __attribute__ ((__packed__));
 
-#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
+#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->fs_info->nodesize - \
                                sizeof(struct btrfs_header)) / \
                                sizeof(struct btrfs_key_ptr))
 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
-#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->nodesize))
+#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->fs_info->nodesize))
 #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
                                        sizeof(struct btrfs_item) - \
                                        sizeof(struct btrfs_file_extent_item))
@@ -482,14 +486,7 @@ struct btrfs_super_block {
 #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL  (1ULL << 1)
 #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS    (1ULL << 2)
 #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO    (1ULL << 3)
-
-/*
- * some patches floated around with a second compression method
- * lets save that incompat here for when they do get in
- * Note we don't actually support it, we're just reserving the
- * number
- */
-#define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZOv2   (1ULL << 4)
+#define BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD   (1ULL << 4)
 
 /*
  * older kernels tried to do bigger metadata blocks, but the
@@ -514,6 +511,7 @@ struct btrfs_super_block {
        (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF |         \
         BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL |        \
         BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO |          \
+        BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD |         \
         BTRFS_FEATURE_INCOMPAT_BIG_METADATA |          \
         BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF |         \
         BTRFS_FEATURE_INCOMPAT_RAID56 |                \
@@ -675,8 +673,9 @@ typedef enum {
        BTRFS_COMPRESS_NONE  = 0,
        BTRFS_COMPRESS_ZLIB  = 1,
        BTRFS_COMPRESS_LZO   = 2,
-       BTRFS_COMPRESS_TYPES = 2,
-       BTRFS_COMPRESS_LAST  = 3,
+       BTRFS_COMPRESS_ZSTD  = 3,
+       BTRFS_COMPRESS_TYPES = 3,
+       BTRFS_COMPRESS_LAST  = 4,
 } btrfs_compression_type;
 
 /* we don't understand any encryption methods right now */
@@ -1126,8 +1125,8 @@ struct btrfs_fs_info {
 
        struct btrfs_fs_devices *fs_devices;
        struct list_head space_info;
-       int system_allocs;
 
+       unsigned int system_allocs:1;
        unsigned int readonly:1;
        unsigned int on_restoring:1;
        unsigned int is_chunk_recover:1;
@@ -1139,6 +1138,8 @@ struct btrfs_fs_info {
        unsigned int avoid_sys_chunk_alloc:1;
        unsigned int finalize_on_close:1;
 
+       int transaction_aborted;
+
        int (*free_extent_hook)(struct btrfs_trans_handle *trans,
                                struct btrfs_root *root,
                                u64 bytenr, u64 num_bytes, u64 parent,
@@ -1147,6 +1148,10 @@ struct btrfs_fs_info {
        struct cache_tree *fsck_extent_cache;
        struct cache_tree *corrupt_blocks;
 
+       /* Cached block sizes */
+       u32 nodesize;
+       u32 sectorsize;
+       u32 stripesize;
 };
 
 /*
@@ -1162,15 +1167,6 @@ struct btrfs_root {
        u64 objectid;
        u64 last_trans;
 
-       /* data allocations are done in sectorsize units */
-       u32 sectorsize;
-
-       /* node allocations are done in nodesize units */
-       u32 nodesize;
-
-       /* leaf allocations are done in nodesize units */
-       u32 stripesize;
-
        int ref_cows;
        int track_dirty;
 
@@ -2076,6 +2072,38 @@ BTRFS_SETGET_STACK_FUNCS(root_stransid, struct btrfs_root_item,
 BTRFS_SETGET_STACK_FUNCS(root_rtransid, struct btrfs_root_item,
                         rtransid, 64);
 
+static inline struct btrfs_timespec* btrfs_root_ctime(
+               struct btrfs_root_item *root_item)
+{
+       unsigned long ptr = (unsigned long)root_item;
+       ptr += offsetof(struct btrfs_root_item, ctime);
+       return (struct btrfs_timespec *)ptr;
+}
+
+static inline struct btrfs_timespec* btrfs_root_otime(
+               struct btrfs_root_item *root_item)
+{
+       unsigned long ptr = (unsigned long)root_item;
+       ptr += offsetof(struct btrfs_root_item, otime);
+       return (struct btrfs_timespec *)ptr;
+}
+
+static inline struct btrfs_timespec* btrfs_root_stime(
+               struct btrfs_root_item *root_item)
+{
+       unsigned long ptr = (unsigned long)root_item;
+       ptr += offsetof(struct btrfs_root_item, stime);
+       return (struct btrfs_timespec *)ptr;
+}
+
+static inline struct btrfs_timespec* btrfs_root_rtime(
+               struct btrfs_root_item *root_item)
+{
+       unsigned long ptr = (unsigned long)root_item;
+       ptr += offsetof(struct btrfs_root_item, rtime);
+       return (struct btrfs_timespec *)ptr;
+}
+
 /* struct btrfs_root_backup */
 BTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup,
                   tree_root, 64);
@@ -2503,11 +2531,11 @@ struct btrfs_block_group_cache *
 btrfs_add_block_group(struct btrfs_fs_info *fs_info, u64 bytes_used, u64 type,
                      u64 chunk_objectid, u64 chunk_offset, u64 size);
 int btrfs_make_block_group(struct btrfs_trans_handle *trans,
-                          struct btrfs_root *root, u64 bytes_used,
+                          struct btrfs_fs_info *fs_info, u64 bytes_used,
                           u64 type, u64 chunk_objectid, u64 chunk_offset,
                           u64 size);
 int btrfs_make_block_groups(struct btrfs_trans_handle *trans,
-                           struct btrfs_root *root);
+                           struct btrfs_fs_info *fs_info);
 int btrfs_update_block_group(struct btrfs_trans_handle *trans,
                             struct btrfs_root *root, u64 bytenr, u64 num,
                             int alloc, int mark_free);
@@ -2538,7 +2566,7 @@ btrfs_check_leaf(struct btrfs_root *root, struct btrfs_disk_key *parent_key,
                 struct extent_buffer *buf);
 void reada_for_search(struct btrfs_root *root, struct btrfs_path *path,
                             int level, int slot, u64 objectid);
-struct extent_buffer *read_node_slot(struct btrfs_root *root,
+struct extent_buffer *read_node_slot(struct btrfs_fs_info *fs_info,
                                   struct extent_buffer *parent, int slot);
 int btrfs_previous_item(struct btrfs_root *root,
                        struct btrfs_path *path, u64 min_objectid,
@@ -2712,7 +2740,7 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
                             u64 num_bytes);
 int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
                                struct btrfs_root *root, u64 objectid,
-                               u64 offset, char *buffer, size_t size);
+                               u64 offset, const char *buffer, size_t size);
 int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
                          struct btrfs_root *root, u64 alloc_end,
                          u64 bytenr, char *data, size_t len);
@@ -2742,7 +2770,7 @@ int btrfs_change_inode_flags(struct btrfs_trans_handle *trans,
                             struct btrfs_root *root, u64 ino, u64 flags);
 int btrfs_add_link(struct btrfs_trans_handle *trans, struct btrfs_root *root,
                   u64 ino, u64 parent_ino, char *name, int namelen,
-                  u8 type, u64 *index, int add_backref);
+                  u8 type, u64 *index, int add_backref, int ignore_existed);
 int btrfs_unlink(struct btrfs_trans_handle *trans, struct btrfs_root *root,
                 u64 ino, u64 parent_ino, u64 index, const char *name,
                 int namelen, int add_orphan);
@@ -2751,6 +2779,8 @@ int btrfs_add_orphan_item(struct btrfs_trans_handle *trans,
                          u64 ino);
 int btrfs_mkdir(struct btrfs_trans_handle *trans, struct btrfs_root *root,
                char *name, int namelen, u64 parent_ino, u64 *ino, int mode);
+struct btrfs_root *btrfs_mksubvol(struct btrfs_root *root, const char *base,
+                                 u64 root_objectid, bool convert);
 
 /* file.c */
 int btrfs_get_extent(struct btrfs_trans_handle *trans,