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 char p_name[F2FS_NAME_LEN + 1]; /* parent name */
77 u32 pp_ino; /* parent parent ino*/
78 struct extent_info ei;
79 u32 last_blk;
80 u32 i_namelen; /* dentry namelen */
81 };
82
83 struct f2fs_dentry {
84 char name[F2FS_NAME_LEN + 1];
85 int depth;
86 struct f2fs_dentry *next;
87 };
88
89 struct f2fs_fsck {
90 struct f2fs_sb_info sbi;
91
92 struct orphan_info orphani;
93 struct chk_result {
94 u64 checked_node_cnt;
95 u64 valid_blk_cnt;
96 u32 valid_nat_entry_cnt;
97 u32 valid_node_cnt;
98 u32 valid_inode_cnt;
99 u32 multi_hard_link_files;
100 u64 sit_valid_blocks;
101 u32 sit_free_segs;
102 u32 wp_fixed;
103 u32 wp_inconsistent_zones;
104 } chk;
105
106 struct hard_link_node *hard_link_list_head;
107
108 char *main_seg_usage;
109 char *main_area_bitmap;
110 char *nat_area_bitmap;
111 char *sit_area_bitmap;
112
113 u64 main_area_bitmap_sz;
114 u32 nat_area_bitmap_sz;
115 u32 sit_area_bitmap_sz;
116
117 u64 nr_main_blks;
118 u32 nr_nat_entries;
119
120 u32 dentry_depth;
121 struct f2fs_dentry *dentry;
122 struct f2fs_dentry *dentry_end;
123 struct f2fs_nat_entry *entries;
124 u32 nat_valid_inode_cnt;
125
126 struct quota_ctx *qctx;
127 };
128
129 #define BLOCK_SZ 4096
130 struct block {
131 unsigned char buf[BLOCK_SZ];
132 };
133
134 enum NODE_TYPE {
135 TYPE_INODE = 37,
136 TYPE_DIRECT_NODE = 43,
137 TYPE_INDIRECT_NODE = 53,
138 TYPE_DOUBLE_INDIRECT_NODE = 67,
139 TYPE_XATTR = 77
140 };
141
142 struct hard_link_node {
143 u32 nid;
144 u32 links;
145 u32 actual_links;
146 struct hard_link_node *next;
147 };
148
149 enum seg_type {
150 SEG_TYPE_DATA,
151 SEG_TYPE_CUR_DATA,
152 SEG_TYPE_NODE,
153 SEG_TYPE_CUR_NODE,
154 SEG_TYPE_MAX,
155 };
156
157 struct selabel_handle;
158
need_fsync_data_record(struct f2fs_sb_info * sbi)159 static inline bool need_fsync_data_record(struct f2fs_sb_info *sbi)
160 {
161 return !is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) ||
162 c.zoned_model == F2FS_ZONED_HM;
163 }
164
165 extern int fsck_chk_orphan_node(struct f2fs_sb_info *);
166 extern int fsck_chk_quota_node(struct f2fs_sb_info *);
167 extern int fsck_chk_quota_files(struct f2fs_sb_info *);
168 extern int fsck_sanity_check_nid(struct f2fs_sb_info *, u32,
169 struct f2fs_node *, enum FILE_TYPE, enum NODE_TYPE,
170 struct node_info *);
171 extern int fsck_chk_node_blk(struct f2fs_sb_info *, struct f2fs_inode *, u32,
172 enum FILE_TYPE, enum NODE_TYPE, u32 *,
173 struct f2fs_compr_blk_cnt *, struct child_info *);
174 extern void fsck_chk_inode_blk(struct f2fs_sb_info *, u32, enum FILE_TYPE,
175 struct f2fs_node *, u32 *, struct f2fs_compr_blk_cnt *,
176 struct node_info *, struct child_info *);
177 extern int fsck_chk_dnode_blk(struct f2fs_sb_info *, struct f2fs_inode *,
178 u32, enum FILE_TYPE, struct f2fs_node *, u32 *,
179 struct f2fs_compr_blk_cnt *, struct child_info *,
180 struct node_info *);
181 extern int fsck_chk_idnode_blk(struct f2fs_sb_info *, struct f2fs_inode *,
182 enum FILE_TYPE, struct f2fs_node *, u32 *,
183 struct f2fs_compr_blk_cnt *, struct child_info *);
184 extern int fsck_chk_didnode_blk(struct f2fs_sb_info *, struct f2fs_inode *,
185 enum FILE_TYPE, struct f2fs_node *, u32 *,
186 struct f2fs_compr_blk_cnt *, struct child_info *);
187 extern int fsck_chk_data_blk(struct f2fs_sb_info *, int,
188 u32, struct child_info *, int, enum FILE_TYPE, u32, u16, u8, int);
189 extern int fsck_chk_dentry_blk(struct f2fs_sb_info *, int,
190 u32, struct child_info *, int, int);
191 int fsck_chk_inline_dentries(struct f2fs_sb_info *, struct f2fs_node *,
192 struct child_info *);
193 void fsck_chk_checkpoint(struct f2fs_sb_info *sbi);
194 int fsck_chk_meta(struct f2fs_sb_info *sbi);
195 void fsck_chk_and_fix_write_pointers(struct f2fs_sb_info *);
196 int fsck_chk_curseg_info(struct f2fs_sb_info *);
197 void pretty_print_filename(const u8 *raw_name, u32 len,
198 char out[F2FS_PRINT_NAMELEN], int enc_name);
199
200 extern void update_free_segments(struct f2fs_sb_info *);
201 void print_cp_state(u32);
202 extern void print_node_info(struct f2fs_sb_info *, struct f2fs_node *, int);
203 extern void print_inode_info(struct f2fs_sb_info *, struct f2fs_node *, int);
204 extern struct seg_entry *get_seg_entry(struct f2fs_sb_info *, unsigned int);
205 extern struct f2fs_summary_block *get_sum_block(struct f2fs_sb_info *,
206 unsigned int, int *);
207 extern int get_sum_entry(struct f2fs_sb_info *, u32, struct f2fs_summary *);
208 extern void update_sum_entry(struct f2fs_sb_info *, block_t,
209 struct f2fs_summary *);
210 extern void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
211 extern void nullify_nat_entry(struct f2fs_sb_info *, u32);
212 extern void rewrite_sit_area_bitmap(struct f2fs_sb_info *);
213 extern void build_nat_area_bitmap(struct f2fs_sb_info *);
214 extern void build_sit_area_bitmap(struct f2fs_sb_info *);
215 extern int f2fs_set_main_bitmap(struct f2fs_sb_info *, u32, int);
216 extern int f2fs_set_sit_bitmap(struct f2fs_sb_info *, u32);
217 extern void fsck_init(struct f2fs_sb_info *);
218 extern int fsck_verify(struct f2fs_sb_info *);
219 extern void fsck_free(struct f2fs_sb_info *);
220 extern int f2fs_ra_meta_pages(struct f2fs_sb_info *, block_t, int, int);
221 extern int f2fs_do_mount(struct f2fs_sb_info *);
222 extern void f2fs_do_umount(struct f2fs_sb_info *);
223 extern int f2fs_sparse_initialize_meta(struct f2fs_sb_info *);
224
225 extern void flush_journal_entries(struct f2fs_sb_info *);
226 extern void update_curseg_info(struct f2fs_sb_info *, int);
227 extern void zero_journal_entries(struct f2fs_sb_info *);
228 extern void flush_sit_entries(struct f2fs_sb_info *);
229 extern void move_curseg_info(struct f2fs_sb_info *, u64, int);
230 extern void write_curseg_info(struct f2fs_sb_info *);
231 extern int find_next_free_block(struct f2fs_sb_info *, u64 *, int, int, bool);
232 extern void duplicate_checkpoint(struct f2fs_sb_info *);
233 extern void write_checkpoint(struct f2fs_sb_info *);
234 extern void write_checkpoints(struct f2fs_sb_info *);
235 extern void update_superblock(struct f2fs_super_block *, int);
236 extern void update_data_blkaddr(struct f2fs_sb_info *, nid_t, u16, block_t);
237 extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t);
238
239 extern void print_raw_sb_info(struct f2fs_super_block *);
240 extern bool is_checkpoint_stop(struct f2fs_super_block *, bool);
241 extern bool is_inconsistent_error(struct f2fs_super_block *);
242 extern pgoff_t current_nat_addr(struct f2fs_sb_info *, nid_t, int *);
243
244 extern u32 get_free_segments(struct f2fs_sb_info *);
245 extern void get_current_sit_page(struct f2fs_sb_info *,
246 unsigned int, struct f2fs_sit_block *);
247 extern void rewrite_current_sit_page(struct f2fs_sb_info *, unsigned int,
248 struct f2fs_sit_block *);
249
250 extern u32 update_nat_bits_flags(struct f2fs_super_block *,
251 struct f2fs_checkpoint *, u32);
252 extern void write_nat_bits(struct f2fs_sb_info *, struct f2fs_super_block *,
253 struct f2fs_checkpoint *, int);
254 extern unsigned int get_usable_seg_count(struct f2fs_sb_info *);
255 extern bool is_usable_seg(struct f2fs_sb_info *, unsigned int);
256
257 /* dump.c */
258 struct dump_option {
259 nid_t nid;
260 nid_t start_nat;
261 nid_t end_nat;
262 int start_sit;
263 int end_sit;
264 int start_ssa;
265 int end_ssa;
266 int32_t blk_addr;
267 nid_t scan_nid;
268 };
269
270 extern void nat_dump(struct f2fs_sb_info *, nid_t, nid_t);
271 extern void sit_dump(struct f2fs_sb_info *, unsigned int, unsigned int);
272 extern void ssa_dump(struct f2fs_sb_info *, int, int);
273 extern int dump_node(struct f2fs_sb_info *, nid_t, int);
274 extern int dump_info_from_blkaddr(struct f2fs_sb_info *, u32);
275 extern unsigned int start_bidx_of_node(unsigned int, struct f2fs_node *);
276 extern void dump_node_scan_disk(struct f2fs_sb_info *sbi, nid_t nid);
277
278
279 /* defrag.c */
280 int f2fs_defragment(struct f2fs_sb_info *, u64, u64, u64, int);
281
282 /* resize.c */
283 int f2fs_resize(struct f2fs_sb_info *);
284
285 /* sload.c */
286 int f2fs_sload(struct f2fs_sb_info *);
287
288 /* segment.c */
289 int reserve_new_block(struct f2fs_sb_info *, block_t *,
290 struct f2fs_summary *, int, bool);
291 int new_data_block(struct f2fs_sb_info *, void *,
292 struct dnode_of_data *, int);
293 int f2fs_build_file(struct f2fs_sb_info *, struct dentry *);
294 void f2fs_alloc_nid(struct f2fs_sb_info *, nid_t *);
295 void set_data_blkaddr(struct dnode_of_data *);
296 block_t new_node_block(struct f2fs_sb_info *,
297 struct dnode_of_data *, unsigned int);
298 int f2fs_rebuild_qf_inode(struct f2fs_sb_info *sbi, int qtype);
299
300 /* segment.c */
301 struct quota_file;
302 u64 f2fs_quota_size(struct quota_file *);
303 u64 f2fs_read(struct f2fs_sb_info *, nid_t, u8 *, u64, pgoff_t);
304 enum wr_addr_type {
305 WR_NORMAL = 1,
306 WR_COMPRESS_DATA = 2,
307 WR_NULL_ADDR = NULL_ADDR, /* 0 */
308 WR_NEW_ADDR = NEW_ADDR, /* -1U */
309 WR_COMPRESS_ADDR = COMPRESS_ADDR, /* -2U */
310 };
311 u64 f2fs_write(struct f2fs_sb_info *, nid_t, u8 *, u64, pgoff_t);
312 u64 f2fs_write_compress_data(struct f2fs_sb_info *, nid_t, u8 *, u64, pgoff_t);
313 u64 f2fs_write_addrtag(struct f2fs_sb_info *, nid_t, pgoff_t, unsigned int);
314 void f2fs_filesize_update(struct f2fs_sb_info *, nid_t, u64);
315
316 int get_dnode_of_data(struct f2fs_sb_info *, struct dnode_of_data *,
317 pgoff_t, int);
318 void make_dentry_ptr(struct f2fs_dentry_ptr *, struct f2fs_node *, void *, int);
319 int f2fs_create(struct f2fs_sb_info *, struct dentry *);
320 int f2fs_mkdir(struct f2fs_sb_info *, struct dentry *);
321 int f2fs_symlink(struct f2fs_sb_info *, struct dentry *);
322 int inode_set_selinux(struct f2fs_sb_info *, u32, const char *);
323 int f2fs_find_path(struct f2fs_sb_info *, char *, nid_t *);
324 nid_t f2fs_lookup(struct f2fs_sb_info *, struct f2fs_node *, u8 *, int);
325 int f2fs_add_link(struct f2fs_sb_info *, struct f2fs_node *,
326 const unsigned char *, int, nid_t, int, block_t, int);
327 struct hardlink_cache_entry *f2fs_search_hardlink(struct f2fs_sb_info *sbi,
328 struct dentry *de);
329
330 /* xattr.c */
331 void *read_all_xattrs(struct f2fs_sb_info *, struct f2fs_node *, bool);
332 void write_all_xattrs(struct f2fs_sb_info *sbi,
333 struct f2fs_node *inode, __u32 hsize, void *txattr_addr);
334
335 #endif /* _FSCK_H_ */
336