aboutsummaryrefslogtreecommitdiff
path: root/fsck
diff options
context:
space:
mode:
Diffstat (limited to 'fsck')
-rw-r--r--fsck/dump.c12
-rw-r--r--fsck/fsck.c88
-rw-r--r--fsck/main.c198
-rw-r--r--fsck/mount.c50
-rw-r--r--fsck/resize.c30
5 files changed, 189 insertions, 189 deletions
diff --git a/fsck/dump.c b/fsck/dump.c
index 332ff7c..80b18d2 100644
--- a/fsck/dump.c
+++ b/fsck/dump.c
@@ -363,17 +363,17 @@ void dump_file(struct f2fs_sb_info *sbi, struct node_info *ni,
name[le32_to_cpu(inode->i_namelen)] = 0;
sprintf(path, "./lost_found/%s", name);
- config.dump_fd = open(path, O_TRUNC|O_CREAT|O_RDWR, 0666);
- ASSERT(config.dump_fd >= 0);
+ c.dump_fd = open(path, O_TRUNC|O_CREAT|O_RDWR, 0666);
+ ASSERT(c.dump_fd >= 0);
/* dump file's data */
dump_inode_blk(sbi, ni->ino, node_blk);
/* adjust file size */
- ret = ftruncate(config.dump_fd, le32_to_cpu(inode->i_size));
+ ret = ftruncate(c.dump_fd, le32_to_cpu(inode->i_size));
ASSERT(ret >= 0);
- close(config.dump_fd);
+ close(c.dump_fd);
}
}
@@ -420,7 +420,7 @@ static void dump_node_from_blkaddr(u32 blk_addr)
ret = dev_read_block(node_blk, blk_addr);
ASSERT(ret >= 0);
- if (config.dbg_lv > 0)
+ if (c.dbg_lv > 0)
print_node_info(node_blk);
else
print_inode_info(&node_blk->i, 1);
@@ -546,7 +546,7 @@ int dump_info_from_blkaddr(struct f2fs_sb_info *sbi, u32 blk_addr)
}
/* print inode */
- if (config.dbg_lv > 0)
+ if (c.dbg_lv > 0)
dump_node_from_blkaddr(ino_ni.blk_addr);
if (type == SEG_TYPE_CUR_DATA || type == SEG_TYPE_DATA) {
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 3c28f2a..9df9118 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -141,7 +141,7 @@ static int is_valid_ssa_node_blk(struct f2fs_sb_info *sbi, u32 nid,
if (type != SEG_TYPE_NODE && type != SEG_TYPE_CUR_NODE) {
/* can't fix current summary, then drop the block */
- if (!config.fix_on || type < 0) {
+ if (!c.fix_on || type < 0) {
ASSERT_MSG("Summary footer is not for node segment");
ret = -EINVAL;
goto out;
@@ -161,7 +161,7 @@ static int is_valid_ssa_node_blk(struct f2fs_sb_info *sbi, u32 nid,
sum_entry = &(sum_blk->entries[offset]);
if (le32_to_cpu(sum_entry->nid) != nid) {
- if (!config.fix_on || type < 0) {
+ if (!c.fix_on || type < 0) {
DBG(0, "nid [0x%x]\n", nid);
DBG(0, "target blk_addr [0x%x]\n", blk_addr);
DBG(0, "summary blk_addr [0x%x]\n",
@@ -182,7 +182,7 @@ static int is_valid_ssa_node_blk(struct f2fs_sb_info *sbi, u32 nid,
need_fix = 1;
}
}
- if (need_fix && !config.ro) {
+ if (need_fix && !c.ro) {
u64 ssa_blk;
int ret2;
@@ -255,7 +255,7 @@ static int is_valid_ssa_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr,
if (type != SEG_TYPE_DATA && type != SEG_TYPE_CUR_DATA) {
/* can't fix current summary, then drop the block */
- if (!config.fix_on || type < 0) {
+ if (!c.fix_on || type < 0) {
ASSERT_MSG("Summary footer is not for data segment");
ret = -EINVAL;
goto out;
@@ -277,7 +277,7 @@ static int is_valid_ssa_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr,
if (le32_to_cpu(sum_entry->nid) != parent_nid ||
sum_entry->version != version ||
le16_to_cpu(sum_entry->ofs_in_node) != idx_in_node) {
- if (!config.fix_on || type < 0) {
+ if (!c.fix_on || type < 0) {
DBG(0, "summary_entry.nid [0x%x]\n",
le32_to_cpu(sum_entry->nid));
DBG(0, "summary_entry.version [0x%x]\n",
@@ -305,7 +305,7 @@ static int is_valid_ssa_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr,
need_fix = 1;
}
}
- if (need_fix && !config.ro) {
+ if (need_fix && !c.ro) {
u64 ssa_blk;
int ret2;
@@ -633,7 +633,7 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
if (find_and_dec_hard_link_list(sbi, nid)) {
ASSERT_MSG("[0x%x] needs more i_links=0x%x",
nid, i_links);
- if (config.fix_on) {
+ if (c.fix_on) {
node_blk->i.i_links =
cpu_to_le32(i_links + 1);
need_fix = 1;
@@ -650,7 +650,7 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
if (fsck_chk_xattr_blk(sbi, nid,
le32_to_cpu(node_blk->i.i_xattr_nid), blk_cnt) &&
- config.fix_on) {
+ c.fix_on) {
node_blk->i.i_xattr_nid = 0;
need_fix = 1;
FIX_MSG("Remove xattr block: 0x%x, x_nid = 0x%x",
@@ -727,7 +727,7 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
file_is_encrypt(node_blk->i.i_advise));
if (!ret) {
*blk_cnt = *blk_cnt + 1;
- } else if (config.fix_on) {
+ } else if (c.fix_on) {
node_blk->i.i_addr[idx] = 0;
need_fix = 1;
FIX_MSG("[0x%x] i_addr[%d] = 0", nid, idx);
@@ -756,7 +756,7 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
if (!ret) {
*blk_cnt = *blk_cnt + 1;
} else if (ret == -EINVAL) {
- if (config.fix_on) {
+ if (c.fix_on) {
node_blk->i.i_nid[idx] = 0;
need_fix = 1;
FIX_MSG("[0x%x] i_nid[%d] = 0", nid, idx);
@@ -779,7 +779,7 @@ skip:
if (child.state & FSCK_UNMATCHED_EXTENT) {
ASSERT_MSG("ino: 0x%x has wrong ext: [pgofs:%u, blk:%u, len:%u]",
nid, child.ei.fofs, child.ei.blk, child.ei.len);
- if (config.fix_on)
+ if (c.fix_on)
need_fix = 1;
}
check:
@@ -787,7 +787,7 @@ check:
ASSERT_MSG("ino: 0x%x has i_blocks: %08"PRIx64", "
"but has %u blocks",
nid, i_blocks, *blk_cnt);
- if (config.fix_on) {
+ if (c.fix_on) {
node_blk->i.i_blocks = cpu_to_le64(*blk_cnt);
need_fix = 1;
FIX_MSG("[0x%x] i_blocks=0x%08"PRIx64" -> 0x%x",
@@ -811,7 +811,7 @@ skip_blkcnt_fix:
if (i_links != child.links) {
ASSERT_MSG("ino: 0x%x i_links: %u, real links: %u",
nid, i_links, child.links);
- if (config.fix_on) {
+ if (c.fix_on) {
node_blk->i.i_links = cpu_to_le32(child.links);
need_fix = 1;
FIX_MSG("Dir: 0x%x i_links= 0x%x -> 0x%x",
@@ -822,7 +822,7 @@ skip_blkcnt_fix:
!(node_blk->i.i_inline & F2FS_INLINE_DOTS)) {
ASSERT_MSG("ino: 0x%x dots: %u",
nid, child.dots);
- if (config.fix_on) {
+ if (c.fix_on) {
node_blk->i.i_inline |= F2FS_INLINE_DOTS;
need_fix = 1;
FIX_MSG("Dir: 0x%x set inline_dots", nid);
@@ -832,7 +832,7 @@ skip_blkcnt_fix:
if (ftype == F2FS_FT_SYMLINK && i_blocks && i_size == 0) {
DBG(1, "ino: 0x%x i_blocks: %lu with zero i_size",
nid, i_blocks);
- if (config.fix_on) {
+ if (c.fix_on) {
u64 i_size = i_blocks * F2FS_BLKSIZE;
node_blk->i.i_size = cpu_to_le64(i_size);
@@ -845,14 +845,14 @@ skip_blkcnt_fix:
if (ftype == F2FS_FT_ORPHAN && i_links) {
MSG(0, "ino: 0x%x is orphan inode, but has i_links: %u",
nid, i_links);
- if (config.fix_on) {
+ if (c.fix_on) {
node_blk->i.i_links = 0;
need_fix = 1;
FIX_MSG("ino: 0x%x orphan_inode, i_links= 0x%x -> 0",
nid, i_links);
}
}
- if (need_fix && !config.ro) {
+ if (need_fix && !c.ro) {
/* drop extent information to avoid potential wrong access */
node_blk->i.i_ext.len = 0;
ret = dev_write_block(node_blk, ni->blk_addr);
@@ -883,13 +883,13 @@ int fsck_chk_dnode_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode,
file_is_encrypt(inode->i_advise));
if (!ret) {
*blk_cnt = *blk_cnt + 1;
- } else if (config.fix_on) {
+ } else if (c.fix_on) {
node_blk->dn.addr[idx] = 0;
need_fix = 1;
FIX_MSG("[0x%x] dn.addr[%d] = 0", nid, idx);
}
}
- if (need_fix && !config.ro) {
+ if (need_fix && !c.ro) {
ret = dev_write_block(node_blk, ni->blk_addr);
ASSERT(ret >= 0);
}
@@ -912,7 +912,7 @@ int fsck_chk_idnode_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode,
if (!ret)
*blk_cnt = *blk_cnt + 1;
else if (ret == -EINVAL) {
- if (!config.fix_on)
+ if (!c.fix_on)
printf("should delete in.nid[i] = 0;\n");
else {
node_blk->in.nid[i] = 0;
@@ -924,7 +924,7 @@ skip:
}
}
- if (need_fix && !config.ro) {
+ if (need_fix && !c.ro) {
struct node_info ni;
nid_t nid = le32_to_cpu(node_blk->footer.nid);
@@ -952,7 +952,7 @@ int fsck_chk_didnode_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode,
if (!ret)
*blk_cnt = *blk_cnt + 1;
else if (ret == -EINVAL) {
- if (!config.fix_on)
+ if (!c.fix_on)
printf("should delete in.nid[i] = 0;\n");
else {
node_blk->in.nid[i] = 0;
@@ -964,7 +964,7 @@ skip:
}
}
- if (need_fix && !config.ro) {
+ if (need_fix && !c.ro) {
struct node_info ni;
nid_t nid = le32_to_cpu(node_blk->footer.nid);
@@ -1030,7 +1030,7 @@ static void print_dentry(__u32 depth, __u8 *name,
int bit_offset;
unsigned char new[F2FS_NAME_LEN + 1];
- if (config.dbg_lv != -1)
+ if (c.dbg_lv != -1)
return;
name_len = le16_to_cpu(dentry[idx].name_len);
@@ -1252,7 +1252,7 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, struct child_info *child,
if (!IS_VALID_NID(sbi, le32_to_cpu(dentry[i].ino))) {
ASSERT_MSG("Bad dentry 0x%x with invalid NID/ino 0x%x",
i, le32_to_cpu(dentry[i].ino));
- if (config.fix_on) {
+ if (c.fix_on) {
FIX_MSG("Clear bad dentry 0x%x with bad ino 0x%x",
i, le32_to_cpu(dentry[i].ino));
test_and_clear_bit_le(i, bitmap);
@@ -1266,7 +1266,7 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, struct child_info *child,
if ((ftype <= F2FS_FT_UNKNOWN || ftype > F2FS_FT_LAST_FILE_TYPE)) {
ASSERT_MSG("Bad dentry 0x%x with unexpected ftype 0x%x",
le32_to_cpu(dentry[i].ino), ftype);
- if (config.fix_on) {
+ if (c.fix_on) {
FIX_MSG("Clear bad dentry 0x%x with bad ftype 0x%x",
i, ftype);
test_and_clear_bit_le(i, bitmap);
@@ -1280,7 +1280,7 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, struct child_info *child,
if (name_len == 0) {
ASSERT_MSG("Bad dentry 0x%x with zero name_len", i);
- if (config.fix_on) {
+ if (c.fix_on) {
FIX_MSG("Clear bad dentry 0x%x", i);
test_and_clear_bit_le(i, bitmap);
fixed = 1;
@@ -1342,7 +1342,7 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, struct child_info *child,
NULL, le32_to_cpu(dentry[i].ino), name,
ftype, TYPE_INODE, &blk_cnt, NULL);
- if (ret && config.fix_on) {
+ if (ret && c.fix_on) {
int j;
for (j = 0; j < slots; j++)
@@ -1413,7 +1413,7 @@ int fsck_chk_dentry_blk(struct f2fs_sb_info *sbi, u32 blk_addr,
de_blk->dentry, de_blk->filename,
NR_DENTRY_IN_BLOCK, last_blk, encrypted);
- if (dentries < 0 && !config.ro) {
+ if (dentries < 0 && !c.ro) {
ret = dev_write_block(de_blk, blk_addr);
ASSERT(ret >= 0);
DBG(1, "[%3d] Dentry Block [0x%x] Fixed hash_codes\n\n",
@@ -1510,12 +1510,12 @@ void fsck_chk_orphan_node(struct f2fs_sb_info *sbi)
if (!ret)
new_blk->ino[new_entry_count++] =
orphan_blk->ino[j];
- else if (ret && config.fix_on)
+ else if (ret && c.fix_on)
FIX_MSG("[0x%x] remove from orphan list", ino);
else if (ret)
ASSERT_MSG("[0x%x] wrong orphan inode", ino);
}
- if (!config.ro && config.fix_on &&
+ if (!c.ro && c.fix_on &&
entry_count != new_entry_count) {
new_blk->entry_count = cpu_to_le32(new_entry_count);
ret = dev_write_block(new_blk, start_blk + i);
@@ -1838,7 +1838,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
node->nid, node->links);
node = node->next;
}
- config.bug_on = 1;
+ c.bug_on = 1;
}
printf("[FSCK] Unreachable nat entries ");
@@ -1847,7 +1847,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
} else {
printf(" [Fail] [0x%x]\n", nr_unref_nid);
ret = EXIT_ERR_CODE;
- config.bug_on = 1;
+ c.bug_on = 1;
}
printf("[FSCK] SIT valid block bitmap checking ");
@@ -1857,7 +1857,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
} else {
printf("[Fail]\n");
ret = EXIT_ERR_CODE;
- config.bug_on = 1;
+ c.bug_on = 1;
}
printf("[FSCK] Hard link checking for regular file ");
@@ -1866,7 +1866,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
} else {
printf(" [Fail] [0x%x]\n", fsck->chk.multi_hard_link_files);
ret = EXIT_ERR_CODE;
- config.bug_on = 1;
+ c.bug_on = 1;
}
printf("[FSCK] valid_block_count matching with CP ");
@@ -1875,7 +1875,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
} else {
printf(" [Fail] [0x%x]\n", (u32)fsck->chk.valid_blk_cnt);
ret = EXIT_ERR_CODE;
- config.bug_on = 1;
+ c.bug_on = 1;
}
printf("[FSCK] valid_node_count matcing with CP (de lookup) ");
@@ -1884,7 +1884,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
} else {
printf(" [Fail] [0x%x]\n", fsck->chk.valid_node_cnt);
ret = EXIT_ERR_CODE;
- config.bug_on = 1;
+ c.bug_on = 1;
}
printf("[FSCK] valid_node_count matcing with CP (nat lookup) ");
@@ -1893,7 +1893,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
} else {
printf(" [Fail] [0x%x]\n", fsck->chk.valid_nat_entry_cnt);
ret = EXIT_ERR_CODE;
- config.bug_on = 1;
+ c.bug_on = 1;
}
printf("[FSCK] valid_inode_count matched with CP ");
@@ -1902,7 +1902,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
} else {
printf(" [Fail] [0x%x]\n", fsck->chk.valid_inode_cnt);
ret = EXIT_ERR_CODE;
- config.bug_on = 1;
+ c.bug_on = 1;
}
printf("[FSCK] free segment_count matched with CP ");
@@ -1912,7 +1912,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
} else {
printf(" [Fail] [0x%x]\n", fsck->chk.sit_free_segs);
ret = EXIT_ERR_CODE;
- config.bug_on = 1;
+ c.bug_on = 1;
}
printf("[FSCK] next block offset is free ");
@@ -1921,7 +1921,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
} else {
printf(" [Fail]\n");
ret = EXIT_ERR_CODE;
- config.bug_on = 1;
+ c.bug_on = 1;
}
printf("[FSCK] fixing SIT types\n");
@@ -1929,7 +1929,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
force = 1;
printf("[FSCK] other corrupted bugs ");
- if (config.bug_on == 0) {
+ if (c.bug_on == 0) {
printf(" [Ok..]\n");
} else {
printf(" [Fail]\n");
@@ -1937,10 +1937,10 @@ int fsck_verify(struct f2fs_sb_info *sbi)
}
/* fix global metadata */
- if (force || (config.fix_on && !config.ro)) {
+ if (force || (c.fix_on && !c.ro)) {
struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
- if (force || config.bug_on) {
+ if (force || c.bug_on) {
fix_hard_links(sbi);
fix_nat_entries(sbi);
move_curseg_info(sbi, SM_I(sbi)->main_blkaddr);
diff --git a/fsck/main.c b/fsck/main.c
index 464c62b..f1b065f 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -85,11 +85,11 @@ void f2fs_parse_options(int argc, char *argv[])
if (!strcmp("fsck.f2fs", prog)) {
const char *option_string = "ad:fp:t";
- config.func = FSCK;
+ c.func = FSCK;
while ((option = getopt(argc, argv, option_string)) != EOF) {
switch (option) {
case 'a':
- config.auto_fix = 1;
+ c.auto_fix = 1;
MSG(0, "Info: Fix the reported corruption.\n");
break;
case 'p':
@@ -97,27 +97,27 @@ void f2fs_parse_options(int argc, char *argv[])
* 0: default level, the same as -a
* 1: check meta
*/
- config.preen_mode = atoi(optarg);
- if (config.preen_mode < 0)
- config.preen_mode = PREEN_MODE_0;
- else if (config.preen_mode >= PREEN_MODE_MAX)
- config.preen_mode = PREEN_MODE_MAX - 1;
- if (config.preen_mode == PREEN_MODE_0)
- config.auto_fix = 1;
+ c.preen_mode = atoi(optarg);
+ if (c.preen_mode < 0)
+ c.preen_mode = PREEN_MODE_0;
+ else if (c.preen_mode >= PREEN_MODE_MAX)
+ c.preen_mode = PREEN_MODE_MAX - 1;
+ if (c.preen_mode == PREEN_MODE_0)
+ c.auto_fix = 1;
MSG(0, "Info: Fix the reported corruption in "
- "preen mode %d\n", config.preen_mode);
+ "preen mode %d\n", c.preen_mode);
break;
case 'd':
- config.dbg_lv = atoi(optarg);
+ c.dbg_lv = atoi(optarg);
MSG(0, "Info: Debug level = %d\n",
- config.dbg_lv);
+ c.dbg_lv);
break;
case 'f':
- config.fix_on = 1;
+ c.fix_on = 1;
MSG(0, "Info: Force to fix corruption\n");
break;
case 't':
- config.dbg_lv = -1;
+ c.dbg_lv = -1;
break;
default:
MSG(0, "\tError: Unknown option %c\n", option);
@@ -138,15 +138,15 @@ void f2fs_parse_options(int argc, char *argv[])
.blk_addr = -1,
};
- config.func = DUMP;
+ c.func = DUMP;
while ((option = getopt(argc, argv, option_string)) != EOF) {
int ret = 0;
switch (option) {
case 'd':
- config.dbg_lv = atoi(optarg);
+ c.dbg_lv = atoi(optarg);
MSG(0, "Info: Debug level = %d\n",
- config.dbg_lv);
+ c.dbg_lv);
break;
case 'i':
if (strncmp(optarg, "0x", 2))
@@ -187,46 +187,46 @@ void f2fs_parse_options(int argc, char *argv[])
ASSERT(ret >= 0);
}
- config.private = &dump_opt;
+ c.private = &dump_opt;
} else if (!strcmp("defrag.f2fs", prog)) {
const char *option_string = "d:s:l:t:i";
- config.func = DEFRAG;
+ c.func = DEFRAG;
while ((option = getopt(argc, argv, option_string)) != EOF) {
int ret = 0;
switch (option) {
case 'd':
- config.dbg_lv = atoi(optarg);
+ c.dbg_lv = atoi(optarg);
MSG(0, "Info: Debug level = %d\n",
- config.dbg_lv);
+ c.dbg_lv);
break;
case 's':
if (strncmp(optarg, "0x", 2))
ret = sscanf(optarg, "%"PRIu64"",
- &config.defrag_start);
+ &c.defrag_start);
else
ret = sscanf(optarg, "%"PRIx64"",
- &config.defrag_start);
+ &c.defrag_start);
break;
case 'l':
if (strncmp(optarg, "0x", 2))
ret = sscanf(optarg, "%"PRIu64"",
- &config.defrag_len);
+ &c.defrag_len);
else
ret = sscanf(optarg, "%"PRIx64"",
- &config.defrag_len);
+ &c.defrag_len);
break;
case 't':
if (strncmp(optarg, "0x", 2))
ret = sscanf(optarg, "%"PRIu64"",
- &config.defrag_target);
+ &c.defrag_target);
else
ret = sscanf(optarg, "%"PRIx64"",
- &config.defrag_target);
+ &c.defrag_target);
break;
case 'i':
- config.defrag_shrink = 1;
+ c.defrag_shrink = 1;
break;
default:
MSG(0, "\tError: Unknown option %c\n", option);
@@ -238,23 +238,23 @@ void f2fs_parse_options(int argc, char *argv[])
} else if (!strcmp("resize.f2fs", prog)) {
const char *option_string = "d:t:";
- config.func = RESIZE;
+ c.func = RESIZE;
while ((option = getopt(argc, argv, option_string)) != EOF) {
int ret = 0;
switch (option) {
case 'd':
- config.dbg_lv = atoi(optarg);
+ c.dbg_lv = atoi(optarg);
MSG(0, "Info: Debug level = %d\n",
- config.dbg_lv);
+ c.dbg_lv);
break;
case 't':
if (strncmp(optarg, "0x", 2))
ret = sscanf(optarg, "%"PRIu64"",
- &config.target_sectors);
+ &c.target_sectors);
else
ret = sscanf(optarg, "%"PRIx64"",
- &config.target_sectors);
+ &c.target_sectors);
break;
default:
MSG(0, "\tError: Unknown option %c\n", option);
@@ -266,19 +266,19 @@ void f2fs_parse_options(int argc, char *argv[])
} else if (!strcmp("sload.f2fs", prog)) {
const char *option_string = "d:f:t:";
- config.func = SLOAD;
+ c.func = SLOAD;
while ((option = getopt(argc, argv, option_string)) != EOF) {
switch (option) {
case 'd':
- config.dbg_lv = atoi(optarg);
+ c.dbg_lv = atoi(optarg);
MSG(0, "Info: Debug level = %d\n",
- config.dbg_lv);
+ c.dbg_lv);
break;
case 'f':
- config.from_dir = (char *)optarg;
+ c.from_dir = (char *)optarg;
break;
case 't':
- config.mount_point = (char *)optarg;
+ c.mount_point = (char *)optarg;
break;
default:
MSG(0, "\tError: Unknown option %c\n", option);
@@ -290,18 +290,18 @@ void f2fs_parse_options(int argc, char *argv[])
if ((optind + 1) != argc) {
MSG(0, "\tError: Device not specified\n");
- if (config.func == FSCK)
+ if (c.func == FSCK)
fsck_usage();
- else if (config.func == DUMP)
+ else if (c.func == DUMP)
dump_usage();
- else if (config.func == DEFRAG)
+ else if (c.func == DEFRAG)
defrag_usage();
- else if (config.func == RESIZE)
+ else if (c.func == RESIZE)
resize_usage();
- else if (config.func == SLOAD)
+ else if (c.func == SLOAD)
sload_usage();
}
- config.device_name = argv[optind];
+ c.device_name = argv[optind];
}
static void do_fsck(struct f2fs_sb_info *sbi)
@@ -314,8 +314,8 @@ static void do_fsck(struct f2fs_sb_info *sbi)
print_cp_state(flag);
- if (!config.fix_on && !config.bug_on) {
- switch (config.preen_mode) {
+ if (!c.fix_on && !c.bug_on) {
+ switch (c.preen_mode) {
case PREEN_MODE_1:
if (fsck_chk_meta(sbi)) {
MSG(0, "[FSCK] F2FS metadata [Fail]");
@@ -327,8 +327,8 @@ static void do_fsck(struct f2fs_sb_info *sbi)
return;
}
- if (!config.ro)
- config.fix_on = 1;
+ if (!c.ro)
+ c.fix_on = 1;
break;
}
} else {
@@ -342,7 +342,7 @@ static void do_fsck(struct f2fs_sb_info *sbi)
* we set fix_on = 1 here, so that fsck can fix errors
* automatically
*/
- config.fix_on = 1;
+ c.fix_on = 1;
}
fsck_chk_orphan_node(sbi);
@@ -357,7 +357,7 @@ static void do_fsck(struct f2fs_sb_info *sbi)
static void do_dump(struct f2fs_sb_info *sbi)
{
- struct dump_option *opt = (struct dump_option *)config.private;
+ struct dump_option *opt = (struct dump_option *)c.private;
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
u32 flag = le32_to_cpu(ckpt->ckpt_flags);
@@ -386,48 +386,48 @@ static int do_defrag(struct f2fs_sb_info *sbi)
{
struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
- if (config.defrag_start > get_sb(block_count))
+ if (c.defrag_start > get_sb(block_count))
goto out_range;
- if (config.defrag_start < SM_I(sbi)->main_blkaddr)
- config.defrag_start = SM_I(sbi)->main_blkaddr;
+ if (c.defrag_start < SM_I(sbi)->main_blkaddr)
+ c.defrag_start = SM_I(sbi)->main_blkaddr;
- if (config.defrag_len == 0)
- config.defrag_len = sbi->blocks_per_seg;
+ if (c.defrag_len == 0)
+ c.defrag_len = sbi->blocks_per_seg;
- if (config.defrag_start + config.defrag_len > get_sb(block_count))
- config.defrag_len = get_sb(block_count) - config.defrag_start;
+ if (c.defrag_start + c.defrag_len > get_sb(block_count))
+ c.defrag_len = get_sb(block_count) - c.defrag_start;
- if (config.defrag_target == 0) {
- config.defrag_target = config.defrag_start - 1;
- if (!config.defrag_shrink)
- config.defrag_target += config.defrag_len + 1;
+ if (c.defrag_target == 0) {
+ c.defrag_target = c.defrag_start - 1;
+ if (!c.defrag_shrink)
+ c.defrag_target += c.defrag_len + 1;
}
- if (config.defrag_target < SM_I(sbi)->main_blkaddr ||
- config.defrag_target > get_sb(block_count))
+ if (c.defrag_target < SM_I(sbi)->main_blkaddr ||
+ c.defrag_target > get_sb(block_count))
goto out_range;
- if (config.defrag_target >= config.defrag_start &&
- config.defrag_target < config.defrag_start + config.defrag_len)
+ if (c.defrag_target >= c.defrag_start &&
+ c.defrag_target < c.defrag_start + c.defrag_len)
goto out_range;
- if (config.defrag_start > config.defrag_target)
+ if (c.defrag_start > c.defrag_target)
MSG(0, "Info: Move 0x%"PRIx64" <- [0x%"PRIx64"-0x%"PRIx64"]\n",
- config.defrag_target,
- config.defrag_start,
- config.defrag_start + config.defrag_len - 1);
+ c.defrag_target,
+ c.defrag_start,
+ c.defrag_start + c.defrag_len - 1);
else
MSG(0, "Info: Move [0x%"PRIx64"-0x%"PRIx64"] -> 0x%"PRIx64"\n",
- config.defrag_start,
- config.defrag_start + config.defrag_len - 1,
- config.defrag_target);
+ c.defrag_start,
+ c.defrag_start + c.defrag_len - 1,
+ c.defrag_target);
- return f2fs_defragment(sbi, config.defrag_start, config.defrag_len,
- config.defrag_target, config.defrag_shrink);
+ return f2fs_defragment(sbi, c.defrag_start, c.defrag_len,
+ c.defrag_target, c.defrag_shrink);
out_range:
ASSERT_MSG("Out-of-range [0x%"PRIx64" ~ 0x%"PRIx64"] to 0x%"PRIx64"",
- config.defrag_start,
- config.defrag_start + config.defrag_len - 1,
- config.defrag_target);
+ c.defrag_start,
+ c.defrag_start + c.defrag_len - 1,
+ c.defrag_target);
return -1;
}
@@ -435,16 +435,16 @@ static int do_resize(struct f2fs_sb_info *sbi)
{
struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
- if (!config.target_sectors)
- config.target_sectors = config.total_sectors;
+ if (!c.target_sectors)
+ c.target_sectors = c.total_sectors;
- if (config.target_sectors > config.total_sectors) {
+ if (c.target_sectors > c.total_sectors) {
ASSERT_MSG("Out-of-range Target=0x%"PRIx64" / 0x%"PRIx64"",
- config.target_sectors, config.total_sectors);
+ c.target_sectors, c.total_sectors);
return -1;
}
- if (config.target_sectors ==
+ if (c.target_sectors ==
(get_sb(block_count) << get_sb(log_sectors_per_block))) {
ASSERT_MSG("Nothing to resize; it's same");
return -1;
@@ -454,15 +454,15 @@ static int do_resize(struct f2fs_sb_info *sbi)
static int do_sload(struct f2fs_sb_info *sbi)
{
- if (!config.from_dir) {
+ if (!c.from_dir) {
MSG(0, "\tError: Need source directory\n");
sload_usage();
return -1;
}
- if (!config.mount_point)
- config.mount_point = "/";
+ if (!c.mount_point)
+ c.mount_point = "/";
- return f2fs_sload(sbi, config.from_dir, config.mount_point, NULL, NULL);
+ return f2fs_sload(sbi, c.from_dir, c.mount_point, NULL, NULL);
}
int main(int argc, char **argv)
@@ -470,24 +470,24 @@ int main(int argc, char **argv)
struct f2fs_sb_info *sbi;
int ret = 0;
- f2fs_init_configuration(&config);
+ f2fs_init_configuration();
f2fs_parse_options(argc, argv);
- if (f2fs_dev_is_umounted(&config) < 0) {
- if (!config.ro || config.func == DEFRAG) {
+ if (f2fs_dev_is_umounted() < 0) {
+ if (!c.ro || c.func == DEFRAG) {
MSG(0, "\tError: Not available on mounted device!\n");
return -1;
}
/* allow ro-mounted partition */
MSG(0, "Info: Check FS only due to RO\n");
- config.fix_on = 0;
- config.auto_fix = 0;
+ c.fix_on = 0;
+ c.auto_fix = 0;
}
/* Get device */
- if (f2fs_get_device_info(&config) < 0)
+ if (f2fs_get_device_info() < 0)
return -1;
fsck_again:
memset(&gfsck, 0, sizeof(gfsck));
@@ -503,7 +503,7 @@ fsck_again:
goto out_err;
}
- switch (config.func) {
+ switch (c.func) {
case FSCK:
do_fsck(sbi);
break;
@@ -526,25 +526,25 @@ fsck_again:
f2fs_do_umount(sbi);
- if (config.func == FSCK && config.bug_on) {
- if (!config.ro && config.fix_on == 0 && config.auto_fix == 0) {
+ if (c.func == FSCK && c.bug_on) {
+ if (!c.ro && c.fix_on == 0 && c.auto_fix == 0) {
char ans[255] = {0};
retry:
printf("Do you want to fix this partition? [Y/N] ");
ret = scanf("%s", ans);
ASSERT(ret >= 0);
if (!strcasecmp(ans, "y"))
- config.fix_on = 1;
+ c.fix_on = 1;
else if (!strcasecmp(ans, "n"))
- config.fix_on = 0;
+ c.fix_on = 0;
else
goto retry;
- if (config.fix_on)
+ if (c.fix_on)
goto fsck_again;
}
}
- f2fs_finalize_device(&config);
+ f2fs_finalize_device();
printf("\nDone.\n");
return 0;
diff --git a/fsck/mount.c b/fsck/mount.c
index 3be60bb..798825b 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -134,7 +134,7 @@ static void DISP_label(u_int16_t *name)
void print_raw_sb_info(struct f2fs_super_block *sb)
{
- if (!config.dbg_lv)
+ if (!c.dbg_lv)
return;
printf("\n");
@@ -186,7 +186,7 @@ void print_ckpt_info(struct f2fs_sb_info *sbi)
{
struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
- if (!config.dbg_lv)
+ if (!c.dbg_lv)
return;
printf("\n");
@@ -415,33 +415,33 @@ int validate_super_block(struct f2fs_sb_info *sbi, int block)
if (!sanity_check_raw_super(sbi->raw_super, offset)) {
/* get kernel version */
- if (config.kd >= 0) {
- dev_read_version(config.version, 0, VERSION_LEN);
- get_kernel_version(config.version);
+ if (c.kd >= 0) {
+ dev_read_version(c.version, 0, VERSION_LEN);
+ get_kernel_version(c.version);
} else {
- memset(config.version, 0, VERSION_LEN);
+ memset(c.version, 0, VERSION_LEN);
}
/* build sb version */
- memcpy(config.sb_version, sbi->raw_super->version, VERSION_LEN);
- get_kernel_version(config.sb_version);
- memcpy(config.init_version, sbi->raw_super->init_version, VERSION_LEN);
- get_kernel_version(config.init_version);
+ memcpy(c.sb_version, sbi->raw_super->version, VERSION_LEN);
+ get_kernel_version(c.sb_version);
+ memcpy(c.init_version, sbi->raw_super->init_version, VERSION_LEN);
+ get_kernel_version(c.init_version);
- MSG(0, "Info: MKFS version\n \"%s\"\n", config.init_version);
+ MSG(0, "Info: MKFS version\n \"%s\"\n", c.init_version);
MSG(0, "Info: FSCK version\n from \"%s\"\n to \"%s\"\n",
- config.sb_version, config.version);
- if (memcmp(config.sb_version, config.version, VERSION_LEN)) {
+ c.sb_version, c.version);
+ if (memcmp(c.sb_version, c.version, VERSION_LEN)) {
int ret;
memcpy(sbi->raw_super->version,
- config.version, VERSION_LEN);
+ c.version, VERSION_LEN);
ret = dev_write(sbi->raw_super, offset,
sizeof(struct f2fs_super_block));
ASSERT(ret >= 0);
- config.auto_fix = 0;
- config.fix_on = 1;
+ c.auto_fix = 0;
+ c.fix_on = 1;
}
print_sb_state(sbi->raw_super);
return 0;
@@ -666,7 +666,7 @@ static int f2fs_init_nid_bitmap(struct f2fs_sb_info *sbi)
nid_t nid;
int i;
- if (!(config.func == SLOAD))
+ if (!(c.func == SLOAD))
return 0;
nm_i->nid_bitmap = (char *)calloc(nid_bitmap_size, 1);
@@ -1867,7 +1867,7 @@ void build_nat_area_bitmap(struct f2fs_sb_info *sbi)
ASSERT_MSG("Invalid nat entry[0]: "
"blk_addr[0x%x]\n",
ni.blk_addr);
- config.fix_on = 1;
+ c.fix_on = 1;
fsck->chk.valid_nat_entry_cnt--;
}
@@ -1895,8 +1895,8 @@ static int check_sector_size(struct f2fs_super_block *sb)
zero_buff = calloc(F2FS_BLKSIZE, 1);
- log_sectorsize = log_base_2(config.sector_size);
- log_sectors_per_block = log_base_2(config.sectors_per_blk);
+ log_sectorsize = log_base_2(c.sector_size);
+ log_sectors_per_block = log_base_2(c.sectors_per_blk);
if (log_sectorsize != get_sb(log_sectorsize))
set_sb(log_sectorsize, log_sectorsize);
@@ -1954,16 +1954,16 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
print_ckpt_info(sbi);
- if (config.auto_fix || config.preen_mode) {
+ if (c.auto_fix || c.preen_mode) {
u32 flag = get_cp(ckpt_flags);
if (flag & CP_FSCK_FLAG)
- config.fix_on = 1;
- else if (!config.preen_mode)
+ c.fix_on = 1;
+ else if (!c.preen_mode)
return 1;
}
- config.bug_on = 0;
+ c.bug_on = 0;
sbi->total_valid_node_count = get_cp(valid_node_count);
sbi->total_valid_inode_count = get_cp(valid_inode_count);
@@ -1993,7 +1993,7 @@ void f2fs_do_umount(struct f2fs_sb_info *sbi)
unsigned int i;
/* free nm_info */
- if (config.func == SLOAD)
+ if (c.func == SLOAD)
free(nm_i->nid_bitmap);
free(nm_i->nat_bitmap);
free(sbi->nm_info);
diff --git a/fsck/resize.c b/fsck/resize.c
index b53a6fa..565555c 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -22,19 +22,19 @@ static int get_new_sb(struct f2fs_sb_info *sbi, struct f2fs_super_block *sb)
u_int32_t blks_per_seg = 1 << get_sb(log_blocks_per_seg);
u_int32_t segs_per_zone = get_sb(segs_per_sec) * get_sb(secs_per_zone);
- set_sb(block_count, config.target_sectors >>
+ set_sb(block_count, c.target_sectors >>
get_sb(log_sectors_per_block));
zone_size_bytes = segment_size_bytes * segs_per_zone;
zone_align_start_offset =
- (config.start_sector * config.sector_size +
+ (c.start_sector * c.sector_size +
2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
zone_size_bytes * zone_size_bytes -
- config.start_sector * config.sector_size;
+ c.start_sector * c.sector_size;
- set_sb(segment_count, (config.target_sectors * config.sector_size -
+ set_sb(segment_count, (c.target_sectors * c.sector_size -
zone_align_start_offset) / segment_size_bytes /
- config.segs_per_sec * config.segs_per_sec);
+ c.segs_per_sec * c.segs_per_sec);
blocks_for_sit = ALIGN(get_sb(segment_count), SIT_ENTRY_PER_BLOCK);
sit_segments = SEG_ALIGN(blocks_for_sit);
@@ -115,17 +115,17 @@ static int get_new_sb(struct f2fs_sb_info *sbi, struct f2fs_super_block *sb)
get_sb(segs_per_sec));
/* Let's determine the best reserved and overprovisioned space */
- config.new_overprovision = get_best_overprovision(sb);
- config.new_reserved_segments =
- (2 * (100 / config.new_overprovision + 1) + 6) *
+ c.new_overprovision = get_best_overprovision(sb);
+ c.new_reserved_segments =
+ (2 * (100 / c.new_overprovision + 1) + 6) *
get_sb(segs_per_sec);
- if ((get_sb(segment_count_main) - 2) < config.new_reserved_segments ||
+ if ((get_sb(segment_count_main) - 2) < c.new_reserved_segments ||
get_sb(segment_count_main) * blks_per_seg >
get_sb(block_count)) {
MSG(0, "\tError: Device size is not sufficient for F2FS volume, "
"more segment needed =%u",
- config.new_reserved_segments -
+ c.new_reserved_segments -
(get_sb(segment_count_main) - 2));
return -1;
}
@@ -406,10 +406,10 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
ASSERT(buf);
/* ovp / free segments */
- set_cp(rsvd_segment_count, config.new_reserved_segments);
+ set_cp(rsvd_segment_count, c.new_reserved_segments);
set_cp(overprov_segment_count, (get_newsb(segment_count_main) -
get_cp(rsvd_segment_count)) *
- config.new_overprovision / 100);
+ c.new_overprovision / 100);
set_cp(overprov_segment_count, get_cp(overprov_segment_count) +
get_cp(rsvd_segment_count));
@@ -419,7 +419,7 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
set_cp(free_segment_count, free_segment_count + new_segment_count);
set_cp(user_block_count, ((get_newsb(segment_count_main) -
- get_cp(overprov_segment_count)) * config.blks_per_seg));
+ get_cp(overprov_segment_count)) * c.blks_per_seg));
if (is_set_ckpt_flags(cp, CP_ORPHAN_PRESENT_FLAG))
orphan_blks = __start_sum_addr(sbi) - 1;
@@ -545,10 +545,10 @@ int f2fs_resize(struct f2fs_sb_info *sbi)
}
}
- config.dbg_lv = 1;
+ c.dbg_lv = 1;
print_raw_sb_info(sb);
print_raw_sb_info(new_sb);
- config.dbg_lv = 0;
+ c.dbg_lv = 0;
old_main_blkaddr = get_sb(main_blkaddr);
new_main_blkaddr = get_newsb(main_blkaddr);