btrfs-progs: check: Move fs_root_objectid function to check/common.h
[btrfs-progs-unstable/devel.git] / check / common.h
blob77a0ab54166f97b067465fb9141cac072956f0ca
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_COMMON_H__
22 #define __BTRFS_CHECK_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 extern u64 bytes_used;
42 extern u64 total_csum_bytes;
43 extern u64 total_btree_bytes;
44 extern u64 total_fs_tree_bytes;
45 extern u64 total_extent_tree_bytes;
46 extern u64 btree_space_waste;
47 extern u64 data_bytes_allocated;
48 extern u64 data_bytes_referenced;
49 extern struct list_head duplicate_extents;
50 extern struct list_head delete_items;
51 extern int no_holes;
52 extern int init_extent_tree;
53 extern int check_data_csum;
54 extern struct btrfs_fs_info *global_info;
55 extern struct task_ctx ctx;
56 extern struct cache_tree *roots_info_cache;
58 static inline u8 imode_to_type(u32 imode)
60 #define S_SHIFT 12
61 static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = {
62 [S_IFREG >> S_SHIFT] = BTRFS_FT_REG_FILE,
63 [S_IFDIR >> S_SHIFT] = BTRFS_FT_DIR,
64 [S_IFCHR >> S_SHIFT] = BTRFS_FT_CHRDEV,
65 [S_IFBLK >> S_SHIFT] = BTRFS_FT_BLKDEV,
66 [S_IFIFO >> S_SHIFT] = BTRFS_FT_FIFO,
67 [S_IFSOCK >> S_SHIFT] = BTRFS_FT_SOCK,
68 [S_IFLNK >> S_SHIFT] = BTRFS_FT_SYMLINK,
71 return btrfs_type_by_mode[(imode & S_IFMT) >> S_SHIFT];
72 #undef S_SHIFT
75 static inline int fs_root_objectid(u64 objectid)
77 if (objectid == BTRFS_TREE_RELOC_OBJECTID ||
78 objectid == BTRFS_DATA_RELOC_TREE_OBJECTID)
79 return 1;
80 return is_fstree(objectid);
83 #endif