Btrfs progs v4.17.1
[btrfs-progs-unstable/devel.git] / check / mode-common.h
blob6b05f8baf4749f32d655346a1515677126a453a0
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.
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.
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.
18 * Defines and function declarations for code shared by both lowmem and
19 * original mode
21 #ifndef __BTRFS_CHECK_MODE_COMMON_H__
22 #define __BTRFS_CHECK_MODE_COMMON_H__
24 #include <sys/stat.h>
25 #include "ctree.h"
28 * Use for tree walk to walk through trees whose leaves/nodes can be shared
29 * between different trees. (Namely subvolume/fs trees)
31 struct node_refs {
32 u64 bytenr[BTRFS_MAX_LEVEL];
33 u64 refs[BTRFS_MAX_LEVEL];
34 int need_check[BTRFS_MAX_LEVEL];
35 /* field for checking all trees */
36 int checked[BTRFS_MAX_LEVEL];
37 /* the corresponding extent should be marked as full backref or not */
38 int full_backref[BTRFS_MAX_LEVEL];
41 enum task_position {
42 TASK_ROOT_ITEMS,
43 TASK_EXTENTS,
44 TASK_FREE_SPACE,
45 TASK_FS_ROOTS,
46 TASK_CSUMS,
47 TASK_ROOT_REFS,
48 TASK_QGROUPS,
49 TASK_NOTHING, /* has to be the last element */
52 struct task_ctx {
53 int progress_enabled;
54 enum task_position tp;
55 time_t start_time;
56 u64 item_count;
58 struct task_info *info;
61 extern u64 bytes_used;
62 extern u64 total_csum_bytes;
63 extern u64 total_btree_bytes;
64 extern u64 total_fs_tree_bytes;
65 extern u64 total_extent_tree_bytes;
66 extern u64 btree_space_waste;
67 extern u64 data_bytes_allocated;
68 extern u64 data_bytes_referenced;
69 extern struct list_head duplicate_extents;
70 extern struct list_head delete_items;
71 extern int no_holes;
72 extern int init_extent_tree;
73 extern int check_data_csum;
74 extern struct btrfs_fs_info *global_info;
75 extern struct task_ctx ctx;
76 extern struct cache_tree *roots_info_cache;
78 static inline u8 imode_to_type(u32 imode)
80 #define S_SHIFT 12
81 static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = {
82 [S_IFREG >> S_SHIFT] = BTRFS_FT_REG_FILE,
83 [S_IFDIR >> S_SHIFT] = BTRFS_FT_DIR,
84 [S_IFCHR >> S_SHIFT] = BTRFS_FT_CHRDEV,
85 [S_IFBLK >> S_SHIFT] = BTRFS_FT_BLKDEV,
86 [S_IFIFO >> S_SHIFT] = BTRFS_FT_FIFO,
87 [S_IFSOCK >> S_SHIFT] = BTRFS_FT_SOCK,
88 [S_IFLNK >> S_SHIFT] = BTRFS_FT_SYMLINK,
91 return btrfs_type_by_mode[(imode & S_IFMT) >> S_SHIFT];
92 #undef S_SHIFT
95 static inline int fs_root_objectid(u64 objectid)
97 if (objectid == BTRFS_TREE_RELOC_OBJECTID ||
98 objectid == BTRFS_DATA_RELOC_TREE_OBJECTID)
99 return 1;
100 return is_fstree(objectid);
103 int check_prealloc_extent_written(struct btrfs_fs_info *fs_info,
104 u64 disk_bytenr, u64 num_bytes);
105 int count_csum_range(struct btrfs_fs_info *fs_info, u64 start,
106 u64 len, u64 *found);
107 int insert_inode_item(struct btrfs_trans_handle *trans,
108 struct btrfs_root *root, u64 ino, u64 size,
109 u64 nbytes, u64 nlink, u32 mode);
110 int link_inode_to_lostfound(struct btrfs_trans_handle *trans,
111 struct btrfs_root *root,
112 struct btrfs_path *path,
113 u64 ino, char *namebuf, u32 name_len,
114 u8 filetype, u64 *ref_count);
115 void check_dev_size_alignment(u64 devid, u64 total_bytes, u32 sectorsize);
116 void reada_walk_down(struct btrfs_root *root, struct extent_buffer *node,
117 int slot);
118 int check_child_node(struct extent_buffer *parent, int slot,
119 struct extent_buffer *child);
120 void reset_cached_block_groups(struct btrfs_fs_info *fs_info);
121 int pin_metadata_blocks(struct btrfs_fs_info *fs_info);
122 int exclude_metadata_blocks(struct btrfs_fs_info *fs_info);
123 void cleanup_excluded_extents(struct btrfs_fs_info *fs_info);
125 #endif