1 /** 2 * fsck.h 3 * 4 * Copyright (c) 2013 Samsung Electronics Co., Ltd. 5 * http://www.samsung.com/ 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 */ 11 #ifndef _FSCK_H_ 12 #define _FSCK_H_ 13 14 #include "f2fs.h" 15 16 /* fsck.c */ 17 struct orphan_info { 18 u32 nr_inodes; 19 u32 *ino_list; 20 }; 21 22 struct f2fs_fsck { 23 struct f2fs_sb_info sbi; 24 25 struct orphan_info orphani; 26 struct chk_result { 27 u64 valid_blk_cnt; 28 u32 valid_nat_entry_cnt; 29 u32 valid_node_cnt; 30 u32 valid_inode_cnt; 31 u32 multi_hard_link_files; 32 u64 sit_valid_blocks; 33 u32 sit_free_segs; 34 } chk; 35 36 struct hard_link_node *hard_link_list_head; 37 38 char *main_seg_usage; 39 char *main_area_bitmap; 40 char *nat_area_bitmap; 41 char *sit_area_bitmap; 42 43 u64 main_area_bitmap_sz; 44 u32 nat_area_bitmap_sz; 45 u32 sit_area_bitmap_sz; 46 47 u64 nr_main_blks; 48 u32 nr_nat_entries; 49 50 u32 dentry_depth; 51 }; 52 53 #define BLOCK_SZ 4096 54 struct block { 55 unsigned char buf[BLOCK_SZ]; 56 }; 57 58 enum NODE_TYPE { 59 TYPE_INODE = 37, 60 TYPE_DIRECT_NODE = 43, 61 TYPE_INDIRECT_NODE = 53, 62 TYPE_DOUBLE_INDIRECT_NODE = 67 63 }; 64 65 struct hard_link_node { 66 u32 nid; 67 u32 links; 68 struct hard_link_node *next; 69 }; 70 71 enum seg_type { 72 SEG_TYPE_DATA, 73 SEG_TYPE_CUR_DATA, 74 SEG_TYPE_NODE, 75 SEG_TYPE_CUR_NODE, 76 SEG_TYPE_MAX, 77 }; 78 79 extern int fsck_chk_xattr_blk(struct f2fs_sb_info *sbi, u32 ino, u32 x_nid, u32 *blk_cnt); 80 extern int fsck_chk_orphan_node(struct f2fs_sb_info *sbi); 81 82 extern int fsck_chk_node_blk(struct f2fs_sb_info *sbi, 83 struct f2fs_inode *inode, 84 u32 nid, 85 enum FILE_TYPE ftype, 86 enum NODE_TYPE ntype, 87 u32 *blk_cnt); 88 89 extern int fsck_chk_inode_blk(struct f2fs_sb_info *sbi, 90 u32 nid, 91 enum FILE_TYPE ftype, 92 struct f2fs_node *node_blk, 93 u32 *blk_cnt, 94 struct node_info *ni); 95 96 extern int fsck_chk_dnode_blk(struct f2fs_sb_info *sbi, 97 struct f2fs_inode *inode, 98 u32 nid, 99 enum FILE_TYPE ftype, 100 struct f2fs_node *node_blk, 101 u32 *blk_cnt, 102 struct node_info *ni); 103 104 extern int fsck_chk_idnode_blk(struct f2fs_sb_info *sbi, 105 struct f2fs_inode *inode, 106 enum FILE_TYPE ftype, 107 struct f2fs_node *node_blk, 108 u32 *blk_cnt); 109 110 extern int fsck_chk_didnode_blk(struct f2fs_sb_info *sbi, 111 struct f2fs_inode *inode, 112 enum FILE_TYPE ftype, 113 struct f2fs_node *node_blk, 114 u32 *blk_cnt); 115 116 extern int fsck_chk_data_blk(struct f2fs_sb_info *sbi, 117 u32 blk_addr, 118 u32 *child_cnt, 119 u32 *child_files, 120 int last_blk, 121 enum FILE_TYPE ftype, 122 u32 parent_nid, 123 u16 idx_in_node, 124 u8 ver); 125 126 extern int fsck_chk_dentry_blk(struct f2fs_sb_info *sbi, 127 u32 blk_addr, 128 u32 *child_cnt, 129 u32 *child_files, 130 int last_blk); 131 132 extern void print_node_info(struct f2fs_node *node_block); 133 extern void print_inode_info(struct f2fs_inode *inode); 134 extern struct seg_entry *get_seg_entry(struct f2fs_sb_info *sbi, unsigned int segno); 135 extern int get_sum_block(struct f2fs_sb_info *sbi, unsigned int segno, struct f2fs_summary_block *sum_blk); 136 extern int get_sum_entry(struct f2fs_sb_info *sbi, u32 blk_addr, struct f2fs_summary *sum_entry); 137 extern int get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 138 extern void build_nat_area_bitmap(struct f2fs_sb_info *sbi); 139 extern int build_sit_area_bitmap(struct f2fs_sb_info *sbi); 140 extern int fsck_init(struct f2fs_sb_info *sbi); 141 extern int fsck_verify(struct f2fs_sb_info *sbi); 142 extern void fsck_free(struct f2fs_sb_info *sbi); 143 extern int f2fs_do_mount(struct f2fs_sb_info *sbi); 144 extern void f2fs_do_umount(struct f2fs_sb_info *sbi); 145 146 /* dump.c */ 147 struct dump_option { 148 nid_t nid; 149 int start_sit; 150 int end_sit; 151 int start_ssa; 152 int end_ssa; 153 int32_t blk_addr; 154 }; 155 156 extern void sit_dump(struct f2fs_sb_info *sbi, int start_sit, int end_sit); 157 extern void ssa_dump(struct f2fs_sb_info *sbi, int start_ssa, int end_ssa); 158 extern int dump_node(struct f2fs_sb_info *sbi, nid_t nid); 159 extern int dump_inode_from_blkaddr(struct f2fs_sb_info *sbi, u32 blk_addr); 160 161 #endif /* _FSCK_H_ */ 162