btrfs-progs: print-tree: Enhance warning on tree block level mismatch and error handling
[platform/upstream/btrfs-progs.git] / mkfs / common.h
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public
4  * License v2 as published by the Free Software Foundation.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9  * General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the
13  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14  * Boston, MA 021110-1307, USA.
15  */
16
17 /*
18  * Defines and function declarations for users of the mkfs API, no internal
19  * defintions.
20  */
21
22 #ifndef __BTRFS_MKFS_COMMON_H__
23 #define __BTRFS_MKFS_COMMON_H__
24
25 #include "kerncompat.h"
26 #include "common-defs.h"
27
28 #define BTRFS_MKFS_SYSTEM_GROUP_SIZE SZ_4M
29 #define BTRFS_MKFS_SMALL_VOLUME_SIZE SZ_1G
30
31 /*
32  * Tree root blocks created during mkfs
33  */
34 enum btrfs_mkfs_block {
35         MKFS_SUPER_BLOCK = 0,
36         MKFS_ROOT_TREE,
37         MKFS_EXTENT_TREE,
38         MKFS_CHUNK_TREE,
39         MKFS_DEV_TREE,
40         MKFS_FS_TREE,
41         MKFS_CSUM_TREE,
42         MKFS_BLOCK_COUNT
43 };
44
45 struct btrfs_mkfs_config {
46         /* Label of the new filesystem */
47         const char *label;
48         /* Blck sizes */
49         u32 nodesize;
50         u32 sectorsize;
51         u32 stripesize;
52         /* Bitfield of incompat features, BTRFS_FEATURE_INCOMPAT_* */
53         u64 features;
54         /* Size of the filesystem in bytes */
55         u64 num_bytes;
56
57         /* Output fields, set during creation */
58
59         /* Logical addresses of superblock [0] and other tree roots */
60         u64 blocks[MKFS_BLOCK_COUNT + 1];
61         char fs_uuid[BTRFS_UUID_UNPARSED_SIZE];
62         char chunk_uuid[BTRFS_UUID_UNPARSED_SIZE];
63
64         /* Superblock offset after make_btrfs */
65         u64 super_bytenr;
66 };
67
68 int make_btrfs(int fd, struct btrfs_mkfs_config *cfg);
69 u64 btrfs_min_dev_size(u32 nodesize, int mixed, u64 meta_profile,
70                        u64 data_profile);
71 int test_minimum_size(const char *file, u64 min_dev_size);
72 int is_vol_small(const char *file);
73 int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
74         u64 dev_cnt, int mixed, int ssd);
75 int test_status_for_mkfs(const char *file, bool force_overwrite);
76 int test_dev_for_mkfs(const char *file, int force_overwrite);
77
78 #endif