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