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 #define FSCK_UNMATCHED_EXTENT 0x00000001 17 18 enum { 19 PREEN_MODE_0, 20 PREEN_MODE_1, 21 PREEN_MODE_MAX 22 }; 23 24 enum { 25 NOERROR, 26 EWRONG_OPT, 27 ENEED_ARG, 28 EUNKNOWN_OPT, 29 EUNKNOWN_ARG, 30 }; 31 32 /* fsck.c */ 33 struct orphan_info { 34 u32 nr_inodes; 35 u32 *ino_list; 36 }; 37 38 struct extent_info { 39 u32 fofs; /* start offset in a file */ 40 u32 blk; /* start block address of the extent */ 41 u32 len; /* length of the extent */ 42 }; 43 44 struct child_info { 45 u32 state; 46 u32 links; 47 u32 files; 48 u32 pgofs; 49 u8 dots; 50 u8 dir_level; 51 u32 p_ino; /*parent ino*/ 52 u32 pp_ino; /*parent parent ino*/ 53 struct extent_info ei; 54 u32 last_blk; 55 }; 56 57 struct f2fs_fsck { 58 struct f2fs_sb_info sbi; 59 60 struct orphan_info orphani; 61 struct chk_result { 62 u64 valid_blk_cnt; 63 u32 valid_nat_entry_cnt; 64 u32 valid_node_cnt; 65 u32 valid_inode_cnt; 66 u32 multi_hard_link_files; 67 u64 sit_valid_blocks; 68 u32 sit_free_segs; 69 } chk; 70 71 struct hard_link_node *hard_link_list_head; 72 73 char *main_seg_usage; 74 char *main_area_bitmap; 75 char *nat_area_bitmap; 76 char *sit_area_bitmap; 77 78 u64 main_area_bitmap_sz; 79 u32 nat_area_bitmap_sz; 80 u32 sit_area_bitmap_sz; 81 82 u64 nr_main_blks; 83 u32 nr_nat_entries; 84 85 u32 dentry_depth; 86 struct f2fs_nat_entry *entries; 87 u32 nat_valid_inode_cnt; 88 }; 89 90 #define BLOCK_SZ 4096 91 struct block { 92 unsigned char buf[BLOCK_SZ]; 93 }; 94 95 enum NODE_TYPE { 96 TYPE_INODE = 37, 97 TYPE_DIRECT_NODE = 43, 98 TYPE_INDIRECT_NODE = 53, 99 TYPE_DOUBLE_INDIRECT_NODE = 67, 100 TYPE_XATTR = 77 101 }; 102 103 struct hard_link_node { 104 u32 nid; 105 u32 links; 106 u32 actual_links; 107 struct hard_link_node *next; 108 }; 109 110 enum seg_type { 111 SEG_TYPE_DATA, 112 SEG_TYPE_CUR_DATA, 113 SEG_TYPE_NODE, 114 SEG_TYPE_CUR_NODE, 115 SEG_TYPE_MAX, 116 }; 117 118 struct selabel_handle; 119 120 extern int fsck_chk_orphan_node(struct f2fs_sb_info *); 121 extern int fsck_chk_node_blk(struct f2fs_sb_info *, struct f2fs_inode *, u32, 122 enum FILE_TYPE, enum NODE_TYPE, u32 *, 123 struct child_info *); 124 extern void fsck_chk_inode_blk(struct f2fs_sb_info *, u32, enum FILE_TYPE, 125 struct f2fs_node *, u32 *, struct node_info *); 126 extern int fsck_chk_dnode_blk(struct f2fs_sb_info *, struct f2fs_inode *, 127 u32, enum FILE_TYPE, struct f2fs_node *, u32 *, 128 struct child_info *, struct node_info *); 129 extern int fsck_chk_idnode_blk(struct f2fs_sb_info *, struct f2fs_inode *, 130 enum FILE_TYPE, struct f2fs_node *, u32 *, struct child_info *); 131 extern int fsck_chk_didnode_blk(struct f2fs_sb_info *, struct f2fs_inode *, 132 enum FILE_TYPE, struct f2fs_node *, u32 *, struct child_info *); 133 extern int fsck_chk_data_blk(struct f2fs_sb_info *sbi, u32, struct child_info *, 134 int, enum FILE_TYPE, u32, u16, u8, int); 135 extern int fsck_chk_dentry_blk(struct f2fs_sb_info *, u32, struct child_info *, 136 int, int); 137 int fsck_chk_inline_dentries(struct f2fs_sb_info *, struct f2fs_node *, 138 struct child_info *); 139 int fsck_chk_meta(struct f2fs_sb_info *sbi); 140 int convert_encrypted_name(unsigned char *, int, unsigned char *, int); 141 142 extern void update_free_segments(struct f2fs_sb_info *); 143 void print_cp_state(u32); 144 extern void print_node_info(struct f2fs_node *, int); 145 extern void print_inode_info(struct f2fs_inode *, int); 146 extern struct seg_entry *get_seg_entry(struct f2fs_sb_info *, unsigned int); 147 extern struct f2fs_summary_block *get_sum_block(struct f2fs_sb_info *, 148 unsigned int, int *); 149 extern int get_sum_entry(struct f2fs_sb_info *, u32, struct f2fs_summary *); 150 extern void update_sum_entry(struct f2fs_sb_info *, block_t, 151 struct f2fs_summary *); 152 extern void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 153 extern void nullify_nat_entry(struct f2fs_sb_info *, u32); 154 extern void rewrite_sit_area_bitmap(struct f2fs_sb_info *); 155 extern void build_nat_area_bitmap(struct f2fs_sb_info *); 156 extern void build_sit_area_bitmap(struct f2fs_sb_info *); 157 extern void fsck_init(struct f2fs_sb_info *); 158 extern int fsck_verify(struct f2fs_sb_info *); 159 extern void fsck_free(struct f2fs_sb_info *); 160 extern int f2fs_do_mount(struct f2fs_sb_info *); 161 extern void f2fs_do_umount(struct f2fs_sb_info *); 162 163 extern void flush_journal_entries(struct f2fs_sb_info *); 164 extern void zero_journal_entries(struct f2fs_sb_info *); 165 extern void flush_sit_entries(struct f2fs_sb_info *); 166 extern void move_curseg_info(struct f2fs_sb_info *, u64); 167 extern void write_curseg_info(struct f2fs_sb_info *); 168 extern int find_next_free_block(struct f2fs_sb_info *, u64 *, int, int); 169 extern void write_checkpoint(struct f2fs_sb_info *); 170 extern void update_data_blkaddr(struct f2fs_sb_info *, nid_t, u16, block_t); 171 extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t); 172 173 extern void print_raw_sb_info(struct f2fs_super_block *); 174 175 extern u32 get_free_segments(struct f2fs_sb_info *); 176 extern struct f2fs_sit_block *get_current_sit_page(struct f2fs_sb_info *, 177 unsigned int); 178 extern void rewrite_current_sit_page(struct f2fs_sb_info *, unsigned int, 179 struct f2fs_sit_block *); 180 181 extern u32 update_nat_bits_flags(struct f2fs_super_block *, 182 struct f2fs_checkpoint *, u32); 183 extern void write_nat_bits(struct f2fs_sb_info *, struct f2fs_super_block *, 184 struct f2fs_checkpoint *, int); 185 186 /* dump.c */ 187 struct dump_option { 188 nid_t nid; 189 int start_nat; 190 int end_nat; 191 int start_sit; 192 int end_sit; 193 int start_ssa; 194 int end_ssa; 195 int32_t blk_addr; 196 }; 197 198 extern void nat_dump(struct f2fs_sb_info *); 199 extern void sit_dump(struct f2fs_sb_info *, unsigned int, unsigned int); 200 extern void ssa_dump(struct f2fs_sb_info *, int, int); 201 extern void dump_node(struct f2fs_sb_info *, nid_t, int); 202 extern int dump_info_from_blkaddr(struct f2fs_sb_info *, u32); 203 204 /* defrag.c */ 205 int f2fs_defragment(struct f2fs_sb_info *, u64, u64, u64, int); 206 207 /* resize.c */ 208 int f2fs_resize(struct f2fs_sb_info *); 209 210 /* sload.c */ 211 int f2fs_sload(struct f2fs_sb_info *, const char *, const char *, 212 const char *, struct selabel_handle *); 213 void reserve_new_block(struct f2fs_sb_info *, block_t *, 214 struct f2fs_summary *, int); 215 void new_data_block(struct f2fs_sb_info *, void *, 216 struct dnode_of_data *, int); 217 int f2fs_build_file(struct f2fs_sb_info *, struct dentry *); 218 void f2fs_alloc_nid(struct f2fs_sb_info *, nid_t *, int); 219 void set_data_blkaddr(struct dnode_of_data *); 220 block_t new_node_block(struct f2fs_sb_info *, 221 struct dnode_of_data *, unsigned int); 222 void get_dnode_of_data(struct f2fs_sb_info *, struct dnode_of_data *, 223 pgoff_t, int); 224 int f2fs_create(struct f2fs_sb_info *, struct dentry *); 225 int f2fs_mkdir(struct f2fs_sb_info *, struct dentry *); 226 int f2fs_symlink(struct f2fs_sb_info *, struct dentry *); 227 int inode_set_selinux(struct f2fs_sb_info *, u32, const char *); 228 int f2fs_find_path(struct f2fs_sb_info *, char *, nid_t *); 229 230 #endif /* _FSCK_H_ */ 231