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