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 enum {
17 FSCK_SUCCESS = 0,
18 FSCK_ERROR_CORRECTED = 1 << 0,
19 FSCK_SYSTEM_SHOULD_REBOOT = 1 << 1,
20 FSCK_ERRORS_LEFT_UNCORRECTED = 1 << 2,
21 FSCK_OPERATIONAL_ERROR = 1 << 3,
22 FSCK_USAGE_OR_SYNTAX_ERROR = 1 << 4,
23 FSCK_USER_CANCELLED = 1 << 5,
24 FSCK_SHARED_LIB_ERROR = 1 << 7,
25 };
26
27 struct quota_ctx;
28
29 #define FSCK_UNMATCHED_EXTENT 0x00000001
30 #define FSCK_INLINE_INODE 0x00000002
31
32 enum {
33 PREEN_MODE_0,
34 PREEN_MODE_1,
35 PREEN_MODE_2,
36 PREEN_MODE_MAX
37 };
38
39 enum {
40 NOERROR,
41 EWRONG_OPT,
42 ENEED_ARG,
43 EUNKNOWN_OPT,
44 EUNKNOWN_ARG,
45 };
46
47 enum SB_ADDR {
48 SB0_ADDR = 0,
49 SB1_ADDR,
50 SB_MAX_ADDR,
51 };
52
53 #define SB_MASK(i) (1 << i)
54 #define SB_MASK_ALL (SB_MASK(SB0_ADDR) | SB_MASK(SB1_ADDR))
55
56 /* fsck.c */
57 struct orphan_info {
58 u32 nr_inodes;
59 u32 *ino_list;
60 };
61
62 struct extent_info {
63 u32 fofs; /* start offset in a file */
64 u32 blk; /* start block address of the extent */
65 u32 len; /* length of the extent */
66 };
67
68 struct child_info {
69 u32 state;
70 u32 links;
71 u32 files;
72 u32 pgofs;
73 u8 dots;
74 u8 dir_level;
75 u32 p_ino; /*parent ino*/
76 u32 pp_ino; /*parent parent ino*/
77 struct extent_info ei;
78 u32 last_blk;
79 u32 i_namelen; /* dentry namelen */
80 };
81
82 struct f2fs_fsck {
83 struct f2fs_sb_info sbi;
84
85 struct orphan_info orphani;
86 struct chk_result {
87 u64 valid_blk_cnt;
88 u32 valid_nat_entry_cnt;
89 u32 valid_node_cnt;
90 u32 valid_inode_cnt;
91 u32 multi_hard_link_files;
92 u64 sit_valid_blocks;
93 u32 sit_free_segs;
94 u32 wp_fixed;
95 u32 wp_inconsistent_zones;
96 } chk;
97
98 struct hard_link_node *hard_link_list_head;
99
100 char *main_seg_usage;
101 char *main_area_bitmap;
102 char *nat_area_bitmap;
103 char *sit_area_bitmap;
104
105 u64 main_area_bitmap_sz;
106 u32 nat_area_bitmap_sz;
107 u32 sit_area_bitmap_sz;
108
109 u64 nr_main_blks;
110 u32 nr_nat_entries;
111
112 u32 dentry_depth;
113 struct f2fs_nat_entry *entries;
114 u32 nat_valid_inode_cnt;
115
116 struct quota_ctx *qctx;
117 };
118
119 #define BLOCK_SZ 4096
120 struct block {
121 unsigned char buf[BLOCK_SZ];
122 };
123
124 enum NODE_TYPE {
125 TYPE_INODE = 37,
126 TYPE_DIRECT_NODE = 43,
127 TYPE_INDIRECT_NODE = 53,
128 TYPE_DOUBLE_INDIRECT_NODE = 67,
129 TYPE_XATTR = 77
130 };
131
132 struct hard_link_node {
133 u32 nid;
134 u32 links;
135 u32 actual_links;
136 struct hard_link_node *next;
137 };
138
139 enum seg_type {
140 SEG_TYPE_DATA,
141 SEG_TYPE_CUR_DATA,
142 SEG_TYPE_NODE,
143 SEG_TYPE_CUR_NODE,
144 SEG_TYPE_MAX,
145 };
146
147 struct selabel_handle;
148
need_fsync_data_record(struct f2fs_sb_info * sbi)149 static inline bool need_fsync_data_record(struct f2fs_sb_info *sbi)
150 {
151 return !is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) ||
152 c.zoned_model == F2FS_ZONED_HM;
153 }
154
155 extern int fsck_chk_orphan_node(struct f2fs_sb_info *);
156 extern int fsck_chk_quota_node(struct f2fs_sb_info *);
157 extern int fsck_chk_quota_files(struct f2fs_sb_info *);
158 extern int fsck_sanity_check_nid(struct f2fs_sb_info *, u32,
159 struct f2fs_node *, enum FILE_TYPE, enum NODE_TYPE,
160 struct node_info *);
161 extern int fsck_chk_node_blk(struct f2fs_sb_info *, struct f2fs_inode *, u32,
162 enum FILE_TYPE, enum NODE_TYPE, u32 *,
163 struct child_info *);
164 extern void fsck_chk_inode_blk(struct f2fs_sb_info *, u32, enum FILE_TYPE,
165 struct f2fs_node *, u32 *, struct node_info *, struct child_info *);
166 extern int fsck_chk_dnode_blk(struct f2fs_sb_info *, struct f2fs_inode *,
167 u32, enum FILE_TYPE, struct f2fs_node *, u32 *,
168 struct child_info *, struct node_info *);
169 extern int fsck_chk_idnode_blk(struct f2fs_sb_info *, struct f2fs_inode *,
170 enum FILE_TYPE, struct f2fs_node *, u32 *, struct child_info *);
171 extern int fsck_chk_didnode_blk(struct f2fs_sb_info *, struct f2fs_inode *,
172 enum FILE_TYPE, struct f2fs_node *, u32 *, struct child_info *);
173 extern int fsck_chk_data_blk(struct f2fs_sb_info *, int,
174 u32, struct child_info *, int, enum FILE_TYPE, u32, u16, u8, int);
175 extern int fsck_chk_dentry_blk(struct f2fs_sb_info *, int,
176 u32, struct child_info *, int, int);
177 int fsck_chk_inline_dentries(struct f2fs_sb_info *, struct f2fs_node *,
178 struct child_info *);
179 void fsck_chk_checkpoint(struct f2fs_sb_info *sbi);
180 int fsck_chk_meta(struct f2fs_sb_info *sbi);
181 void fsck_chk_and_fix_write_pointers(struct f2fs_sb_info *);
182 int fsck_chk_curseg_info(struct f2fs_sb_info *);
183 void pretty_print_filename(const u8 *raw_name, u32 len,
184 char out[F2FS_PRINT_NAMELEN], int enc_name);
185
186 extern void update_free_segments(struct f2fs_sb_info *);
187 void print_cp_state(u32);
188 extern void print_node_info(struct f2fs_sb_info *, struct f2fs_node *, int);
189 extern void print_inode_info(struct f2fs_sb_info *, struct f2fs_node *, int);
190 extern struct seg_entry *get_seg_entry(struct f2fs_sb_info *, unsigned int);
191 extern struct f2fs_summary_block *get_sum_block(struct f2fs_sb_info *,
192 unsigned int, int *);
193 extern int get_sum_entry(struct f2fs_sb_info *, u32, struct f2fs_summary *);
194 extern void update_sum_entry(struct f2fs_sb_info *, block_t,
195 struct f2fs_summary *);
196 extern void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
197 extern void nullify_nat_entry(struct f2fs_sb_info *, u32);
198 extern void rewrite_sit_area_bitmap(struct f2fs_sb_info *);
199 extern void build_nat_area_bitmap(struct f2fs_sb_info *);
200 extern void build_sit_area_bitmap(struct f2fs_sb_info *);
201 extern int f2fs_set_main_bitmap(struct f2fs_sb_info *, u32, int);
202 extern int f2fs_set_sit_bitmap(struct f2fs_sb_info *, u32);
203 extern void fsck_init(struct f2fs_sb_info *);
204 extern int fsck_verify(struct f2fs_sb_info *);
205 extern void fsck_free(struct f2fs_sb_info *);
206 extern int f2fs_ra_meta_pages(struct f2fs_sb_info *, block_t, int, int);
207 extern int f2fs_do_mount(struct f2fs_sb_info *);
208 extern void f2fs_do_umount(struct f2fs_sb_info *);
209 extern int f2fs_sparse_initialize_meta(struct f2fs_sb_info *);
210
211 extern void flush_journal_entries(struct f2fs_sb_info *);
212 extern void update_curseg_info(struct f2fs_sb_info *, int);
213 extern void zero_journal_entries(struct f2fs_sb_info *);
214 extern void flush_sit_entries(struct f2fs_sb_info *);
215 extern void move_curseg_info(struct f2fs_sb_info *, u64, int);
216 extern void write_curseg_info(struct f2fs_sb_info *);
217 extern int find_next_free_block(struct f2fs_sb_info *, u64 *, int, int, bool);
218 extern void duplicate_checkpoint(struct f2fs_sb_info *);
219 extern void write_checkpoint(struct f2fs_sb_info *);
220 extern void write_checkpoints(struct f2fs_sb_info *);
221 extern void update_superblock(struct f2fs_super_block *, int);
222 extern void update_data_blkaddr(struct f2fs_sb_info *, nid_t, u16, block_t);
223 extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t);
224
225 extern void print_raw_sb_info(struct f2fs_super_block *);
226 extern pgoff_t current_nat_addr(struct f2fs_sb_info *, nid_t, int *);
227
228 extern u32 get_free_segments(struct f2fs_sb_info *);
229 extern void get_current_sit_page(struct f2fs_sb_info *,
230 unsigned int, struct f2fs_sit_block *);
231 extern void rewrite_current_sit_page(struct f2fs_sb_info *, unsigned int,
232 struct f2fs_sit_block *);
233
234 extern u32 update_nat_bits_flags(struct f2fs_super_block *,
235 struct f2fs_checkpoint *, u32);
236 extern void write_nat_bits(struct f2fs_sb_info *, struct f2fs_super_block *,
237 struct f2fs_checkpoint *, int);
238 extern unsigned int get_usable_seg_count(struct f2fs_sb_info *);
239 extern bool is_usable_seg(struct f2fs_sb_info *, unsigned int);
240
241 /* dump.c */
242 struct dump_option {
243 nid_t nid;
244 nid_t start_nat;
245 nid_t end_nat;
246 int start_sit;
247 int end_sit;
248 int start_ssa;
249 int end_ssa;
250 int32_t blk_addr;
251 };
252
253 extern void nat_dump(struct f2fs_sb_info *, nid_t, nid_t);
254 extern void sit_dump(struct f2fs_sb_info *, unsigned int, unsigned int);
255 extern void ssa_dump(struct f2fs_sb_info *, int, int);
256 extern void dump_node(struct f2fs_sb_info *, nid_t, int);
257 extern int dump_info_from_blkaddr(struct f2fs_sb_info *, u32);
258 extern unsigned int start_bidx_of_node(unsigned int, struct f2fs_node *);
259
260
261 /* defrag.c */
262 int f2fs_defragment(struct f2fs_sb_info *, u64, u64, u64, int);
263
264 /* resize.c */
265 int f2fs_resize(struct f2fs_sb_info *);
266
267 /* sload.c */
268 int f2fs_sload(struct f2fs_sb_info *);
269
270 /* segment.c */
271 int reserve_new_block(struct f2fs_sb_info *, block_t *,
272 struct f2fs_summary *, int, bool);
273 int new_data_block(struct f2fs_sb_info *, void *,
274 struct dnode_of_data *, int);
275 int f2fs_build_file(struct f2fs_sb_info *, struct dentry *);
276 void f2fs_alloc_nid(struct f2fs_sb_info *, nid_t *);
277 void set_data_blkaddr(struct dnode_of_data *);
278 block_t new_node_block(struct f2fs_sb_info *,
279 struct dnode_of_data *, unsigned int);
280
281 /* segment.c */
282 struct quota_file;
283 u64 f2fs_quota_size(struct quota_file *);
284 u64 f2fs_read(struct f2fs_sb_info *, nid_t, u8 *, u64, pgoff_t);
285 u64 f2fs_write(struct f2fs_sb_info *, nid_t, u8 *, u64, pgoff_t);
286 void f2fs_filesize_update(struct f2fs_sb_info *, nid_t, u64);
287
288 int get_dnode_of_data(struct f2fs_sb_info *, struct dnode_of_data *,
289 pgoff_t, int);
290 void make_dentry_ptr(struct f2fs_dentry_ptr *, struct f2fs_node *, void *, int);
291 int f2fs_create(struct f2fs_sb_info *, struct dentry *);
292 int f2fs_mkdir(struct f2fs_sb_info *, struct dentry *);
293 int f2fs_symlink(struct f2fs_sb_info *, struct dentry *);
294 int inode_set_selinux(struct f2fs_sb_info *, u32, const char *);
295 int f2fs_find_path(struct f2fs_sb_info *, char *, nid_t *);
296 nid_t f2fs_lookup(struct f2fs_sb_info *, struct f2fs_node *, u8 *, int);
297 int f2fs_add_link(struct f2fs_sb_info *, struct f2fs_node *,
298 const unsigned char *, int, nid_t, int, block_t, int);
299
300 /* xattr.c */
301 void *read_all_xattrs(struct f2fs_sb_info *, struct f2fs_node *);
302
303 #endif /* _FSCK_H_ */
304