* [PATCH 1/5] f2fs: avoid AOSP build failure
@ 2016-10-14 0:02 Jaegeuk Kim
2016-10-14 0:02 ` [PATCH 2/5] f2fs-tools: clean up and avoid build warning Jaegeuk Kim
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Jaegeuk Kim @ 2016-10-14 0:02 UTC (permalink / raw)
To: linux-f2fs-devel; +Cc: Jaegeuk Kim
SCSI-related operations are not permitted to AOSP biuld.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fsck/main.c | 2 ++
lib/libf2fs.c | 10 ++++++++++
2 files changed, 12 insertions(+)
diff --git a/fsck/main.c b/fsck/main.c
index f1b065f..75f8c1e 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -510,6 +510,7 @@ fsck_again:
case DUMP:
do_dump(sbi);
break;
+#ifndef WITH_ANDROID
case DEFRAG:
ret = do_defrag(sbi);
if (ret)
@@ -522,6 +523,7 @@ fsck_again:
case SLOAD:
do_sload(sbi);
break;
+#endif
}
f2fs_do_umount(sbi);
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 6140452..d3311ca 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -19,14 +19,18 @@
#include <sys/stat.h>
#include <sys/mount.h>
#include <sys/ioctl.h>
+#ifndef WITH_ANDROID
#include <scsi/sg.h>
+#endif
#include <linux/hdreg.h>
#include <linux/limits.h>
#include <f2fs_fs.h>
+#ifndef WITH_ANDROID
/* SCSI command for standard inquiry*/
#define MODELINQUIRY 0x12,0x00,0x00,0x00,0x4A,0x00
+#endif
/*
* UTF conversion codes are Copied from exfat tools.
@@ -652,9 +656,11 @@ int f2fs_get_device_info(void)
#endif
struct stat stat_buf;
struct hd_geometry geom;
+#ifndef WITH_ANDROID
sg_io_hdr_t io_hdr;
unsigned char reply_buffer[96];
unsigned char model_inq[6] = {MODELINQUIRY};
+#endif
u_int64_t wanted_total_sectors = c.total_sectors;
fd = open(c.device_name, O_RDWR);
@@ -704,6 +710,7 @@ int f2fs_get_device_info(void)
else
c.start_sector = geom.start;
+#ifndef WITH_ANDROID
/* Send INQUIRY command */
memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
io_hdr.interface_id = 'S';
@@ -722,6 +729,7 @@ int f2fs_get_device_info(void)
printf("%c", reply_buffer[i++]);
printf("\n");
}
+#endif
} else {
MSG(0, "\tError: Volume type is not supported!!!\n");
return -1;
@@ -737,6 +745,7 @@ int f2fs_get_device_info(void)
return -1;
}
+#ifndef WITH_ANDROID
if (c.smr_mode) {
if (zbc_scsi_report_zones()) {
MSG(0, "\tError: Not proper SMR drive\n");
@@ -749,6 +758,7 @@ int f2fs_get_device_info(void)
c.segs_per_sec = c.zone_sectors /
c.sectors_per_blk / DEFAULT_BLOCKS_PER_SEGMENT;
}
+#endif
c.segs_per_zone = c.segs_per_sec * c.secs_per_zone;
MSG(0, "Info: Segments per section = %d\n", c.segs_per_sec);
--
2.8.3
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/5] f2fs-tools: clean up and avoid build warning
2016-10-14 0:02 [PATCH 1/5] f2fs: avoid AOSP build failure Jaegeuk Kim
@ 2016-10-14 0:02 ` Jaegeuk Kim
2016-10-14 0:02 ` [PATCH 3/5] libf2fs: avoid garbage printout Jaegeuk Kim
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Jaegeuk Kim @ 2016-10-14 0:02 UTC (permalink / raw)
To: linux-f2fs-devel; +Cc: Jaegeuk Kim
This patch is to clean up and avoid warnings when compiling aosp.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fsck/dump.c | 67 ++++++++++++++++++++++++++++++++++++------------------------
fsck/fsck.c | 11 ++++++----
fsck/fsck.h | 4 ++--
fsck/main.c | 2 +-
fsck/sload.c | 10 ++++-----
5 files changed, 55 insertions(+), 39 deletions(-)
diff --git a/fsck/dump.c b/fsck/dump.c
index 80b18d2..c048429 100644
--- a/fsck/dump.c
+++ b/fsck/dump.c
@@ -23,7 +23,7 @@ const char *seg_type_name[SEG_TYPE_MAX + 1] = {
"SEG_TYPE_NONE",
};
-void nat_dump(struct f2fs_sb_info *sbi, int start_nat, int end_nat)
+void nat_dump(struct f2fs_sb_info *sbi)
{
struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
struct f2fs_nm_info *nm_i = NM_I(sbi);
@@ -77,14 +77,16 @@ void nat_dump(struct f2fs_sb_info *sbi, int start_nat, int end_nat)
ASSERT(ret >= 0);
if (ni.blk_addr != 0x0) {
memset(buf, 0, BUF_SZ);
- snprintf(buf, BUF_SZ, "nid:%5u\tino:%5u\toffset:%5u"
- "\tblkaddr:%10u\tpack:%d\n",ni.nid, ni.ino,
- node_block->footer.flag >> OFFSET_BIT_SHIFT,
- ni.blk_addr, pack);
+ snprintf(buf, BUF_SZ,
+ "nid:%5u\tino:%5u\toffset:%5u"
+ "\tblkaddr:%10u\tpack:%d\n",
+ ni.nid, ni.ino,
+ node_block->footer.flag >>
+ OFFSET_BIT_SHIFT,
+ ni.blk_addr, pack);
ret = write(fd, buf, strlen(buf));
ASSERT(ret >= 0);
}
-
} else {
node_info_from_raw_nat(&ni,
&nat_block->entries[i]);
@@ -94,10 +96,13 @@ void nat_dump(struct f2fs_sb_info *sbi, int start_nat, int end_nat)
ret = dev_read_block(node_block, ni.blk_addr);
ASSERT(ret >= 0);
memset(buf, 0, BUF_SZ);
- snprintf(buf, BUF_SZ, "nid:%5u\tino:%5u\toffset:%5u"
- "\tblkaddr:%10u\tpack:%d\n",ni.nid,
- ni.ino,node_block->footer.flag >>
- OFFSET_BIT_SHIFT,ni.blk_addr, pack);
+ snprintf(buf, BUF_SZ,
+ "nid:%5u\tino:%5u\toffset:%5u"
+ "\tblkaddr:%10u\tpack:%d\n",
+ ni.nid, ni.ino,
+ node_block->footer.flag >>
+ OFFSET_BIT_SHIFT,
+ ni.blk_addr, pack);
ret = write(fd, buf, strlen(buf));
ASSERT(ret >= 0);
}
@@ -110,7 +115,8 @@ void nat_dump(struct f2fs_sb_info *sbi, int start_nat, int end_nat)
close(fd);
}
-void sit_dump(struct f2fs_sb_info *sbi, int start_sit, int end_sit)
+void sit_dump(struct f2fs_sb_info *sbi, unsigned int start_sit,
+ unsigned int end_sit)
{
struct seg_entry *se;
struct sit_info *sit_i = SIT_I(sbi);
@@ -133,37 +139,44 @@ void sit_dump(struct f2fs_sb_info *sbi, int start_sit, int end_sit)
for (segno = start_sit; segno < end_sit; segno++) {
se = get_seg_entry(sbi, segno);
offset = SIT_BLOCK_OFFSET(sit_i, segno);
- i = f2fs_test_bit(offset, sit_i->sit_bitmap)?2:1;
memset(buf, 0, BUF_SZ);
- snprintf(buf, BUF_SZ, "\nsegno:%8u\tvblocks:%3u\tseg_type:%d\tsit_pack:%d\n\n",
- segno, se->valid_blocks, se->type, i);
+ snprintf(buf, BUF_SZ,
+ "\nsegno:%8u\tvblocks:%3u\tseg_type:%d\tsit_pack:%d\n\n",
+ segno, se->valid_blocks, se->type,
+ f2fs_test_bit(offset, sit_i->sit_bitmap) ? 2 : 1);
ret = write(fd, buf, strlen(buf));
ASSERT(ret >= 0);
if (se->valid_blocks == 0x0) {
free_segs++;
- } else {
- ASSERT(se->valid_blocks <= 512);
- valid_blocks += se->valid_blocks;
+ continue;
+ }
- for (i = 0; i < 64; i++) {
- memset(buf, 0, BUF_SZ);
- snprintf(buf, BUF_SZ, " %02x", *(se->cur_valid_map + i));
+ ASSERT(se->valid_blocks <= 512);
+ valid_blocks += se->valid_blocks;
+
+ for (i = 0; i < 64; i++) {
+ memset(buf, 0, BUF_SZ);
+ snprintf(buf, BUF_SZ, " %02x",
+ *(se->cur_valid_map + i));
+ ret = write(fd, buf, strlen(buf));
+ ASSERT(ret >= 0);
+
+ if ((i + 1) % 16 == 0) {
+ snprintf(buf, BUF_SZ, "\n");
ret = write(fd, buf, strlen(buf));
ASSERT(ret >= 0);
- if((i+1) % 16 == 0) {
- snprintf(buf, BUF_SZ, "\n");
- ret = write(fd, buf, strlen(buf));
- ASSERT(ret >= 0);
- }
}
}
}
memset(buf, 0, BUF_SZ);
- snprintf(buf, BUF_SZ, "valid_blocks:[0x%" PRIx64 "]\tvalid_segs:%d\t free_segs:%d\n",
- valid_blocks, SM_I(sbi)->main_segments - free_segs, free_segs);
+ snprintf(buf, BUF_SZ,
+ "valid_blocks:[0x%" PRIx64 "]\tvalid_segs:%d\t free_segs:%d\n",
+ valid_blocks,
+ SM_I(sbi)->main_segments - free_segs,
+ free_segs);
ret = write(fd, buf, strlen(buf));
ASSERT(ret >= 0);
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 9df9118..4b6628e 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -602,18 +602,21 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
u32 *blk_cnt, struct node_info *ni)
{
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
- struct child_info child = {0, 2, 0, 0, 0, 0};
+ struct child_info child;
enum NODE_TYPE ntype;
u32 i_links = le32_to_cpu(node_blk->i.i_links);
u64 i_size = le64_to_cpu(node_blk->i.i_size);
u64 i_blocks = le64_to_cpu(node_blk->i.i_blocks);
- child.p_ino = nid;
- child.pp_ino = le32_to_cpu(node_blk->i.i_pino);
- child.dir_level = node_blk->i.i_dir_level;
unsigned int idx = 0;
int need_fix = 0;
int ret;
+ memset(&child, 0, sizeof(child));
+ child.links = 2;
+ child.p_ino = nid;
+ child.pp_ino = le32_to_cpu(node_blk->i.i_pino);
+ child.dir_level = node_blk->i.i_dir_level;
+
if (f2fs_test_main_bitmap(sbi, ni->blk_addr) == 0)
fsck->chk.valid_inode_cnt++;
diff --git a/fsck/fsck.h b/fsck/fsck.h
index 50dc440..a86a30f 100644
--- a/fsck/fsck.h
+++ b/fsck/fsck.h
@@ -176,8 +176,8 @@ struct dump_option {
int32_t blk_addr;
};
-extern void nat_dump(struct f2fs_sb_info *, int, int);
-extern void sit_dump(struct f2fs_sb_info *, int, int);
+extern void nat_dump(struct f2fs_sb_info *);
+extern void sit_dump(struct f2fs_sb_info *, unsigned int, unsigned int);
extern void ssa_dump(struct f2fs_sb_info *, int, int);
extern void dump_node(struct f2fs_sb_info *, nid_t);
extern int dump_info_from_blkaddr(struct f2fs_sb_info *, u32);
diff --git a/fsck/main.c b/fsck/main.c
index 75f8c1e..8acc970 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -368,7 +368,7 @@ static void do_dump(struct f2fs_sb_info *sbi)
if (opt->end_ssa == -1)
opt->end_ssa = SM_I(sbi)->main_segments;
if (opt->start_nat != -1)
- nat_dump(sbi, opt->start_nat, opt->end_nat);
+ nat_dump(sbi);
if (opt->start_sit != -1)
sit_dump(sbi, opt->start_sit, opt->end_sit);
if (opt->start_ssa != -1)
diff --git a/fsck/sload.c b/fsck/sload.c
index 424e642..ea072d1 100644
--- a/fsck/sload.c
+++ b/fsck/sload.c
@@ -30,12 +30,12 @@ static void handle_selabel(struct dentry *de, int dir, char *target_out)
unsigned int uid = 0;
unsigned int gid = 0;
- fs_config(de[i].path, dir, target_out, &uid,
+ fs_config(de->path, dir, target_out, &uid,
&gid, &mode, &capabilities);
- de.mode = mode;
- de.uid = uid;
- de.gid = gid;
- de.capabilities = capabilities;
+ de->mode = mode;
+ de->uid = uid;
+ de->gid = gid;
+ de->capabilities = capabilities;
}
#else
#define handle_selabel(...)
--
2.8.3
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/5] libf2fs: avoid garbage printout
2016-10-14 0:02 [PATCH 1/5] f2fs: avoid AOSP build failure Jaegeuk Kim
2016-10-14 0:02 ` [PATCH 2/5] f2fs-tools: clean up and avoid build warning Jaegeuk Kim
@ 2016-10-14 0:02 ` Jaegeuk Kim
2016-10-14 0:02 ` [PATCH 4/5] fsck.f2fs: check condition to avoid wrong memory allocation Jaegeuk Kim
2016-10-14 0:02 ` [PATCH 5/5] fsck.f2fs: support restore lost files into ./lost_found/ Jaegeuk Kim
3 siblings, 0 replies; 5+ messages in thread
From: Jaegeuk Kim @ 2016-10-14 0:02 UTC (permalink / raw)
To: linux-f2fs-devel; +Cc: Jaegeuk Kim
This patch avoids to print garbage data.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
lib/libf2fs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index d3311ca..63cf6d4 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -658,7 +658,7 @@ int f2fs_get_device_info(void)
struct hd_geometry geom;
#ifndef WITH_ANDROID
sg_io_hdr_t io_hdr;
- unsigned char reply_buffer[96];
+ unsigned char reply_buffer[96] = {0};
unsigned char model_inq[6] = {MODELINQUIRY};
#endif
u_int64_t wanted_total_sectors = c.total_sectors;
@@ -725,7 +725,7 @@ int f2fs_get_device_info(void)
int i = 16;
MSG(0, "Info: Disk Model: ");
- while (reply_buffer[i] != '`')
+ while (reply_buffer[i] != '`' && i < 80)
printf("%c", reply_buffer[i++]);
printf("\n");
}
--
2.8.3
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/5] fsck.f2fs: check condition to avoid wrong memory allocation
2016-10-14 0:02 [PATCH 1/5] f2fs: avoid AOSP build failure Jaegeuk Kim
2016-10-14 0:02 ` [PATCH 2/5] f2fs-tools: clean up and avoid build warning Jaegeuk Kim
2016-10-14 0:02 ` [PATCH 3/5] libf2fs: avoid garbage printout Jaegeuk Kim
@ 2016-10-14 0:02 ` Jaegeuk Kim
2016-10-14 0:02 ` [PATCH 5/5] fsck.f2fs: support restore lost files into ./lost_found/ Jaegeuk Kim
3 siblings, 0 replies; 5+ messages in thread
From: Jaegeuk Kim @ 2016-10-14 0:02 UTC (permalink / raw)
To: linux-f2fs-devel; +Cc: Jaegeuk Kim
This patch should fix the below bug.
Info: checkpoint state = 4 : compacted_summary sudden-power-off
[FIX] (is_valid_ssa_data_blk: 301) --> Set data summary 0x1039 -> [0x3] [0x0] [0x0]
[ASSERT] (fsck_chk_data_blk:1459) --> SIT bitmap is 0x0. blk_addr[0x20b6d8]
[ASSERT] (__chk_dentries:1255) --> Bad dentry 0x2 with invalid NID/ino 0x1644b164
[FIX] (__chk_dentries:1258) --> Clear bad dentry 0x2 with bad ino 0x1644b164
[ASSERT] (__chk_dentries:1269) --> Bad dentry 0x0 with unexpected ftype 0x2c
[FIX] (__chk_dentries:1272) --> Clear bad dentry 0x4 with bad ftype 0x2c
[ASSERT] (__chk_dentries:1255) --> Bad dentry 0x5 with invalid NID/ino 0x49000000
[FIX] (__chk_dentries:1258) --> Clear bad dentry 0x5 with bad ino 0x49000000
[ASSERT] (__chk_dentries:1255) --> Bad dentry 0x7 with invalid NID/ino 0x67706a2e
[FIX] (__chk_dentries:1258) --> Clear bad dentry 0x7 with bad ino 0x67706a2e
[ASSERT] (__chk_dentries:1255) --> Bad dentry 0x8 with invalid NID/ino 0x4a437044
[FIX] (__chk_dentries:1258) --> Clear bad dentry 0x8 with bad ino 0x4a437044
[ASSERT] (__chk_dentries:1269) --> Bad dentry 0x0 with unexpected ftype 0x0
[FIX] (__chk_dentries:1272) --> Clear bad dentry 0xf with bad ftype 0x0
[ASSERT] (__chk_dentries:1255) --> Bad dentry 0x20 with invalid NID/ino 0x4a150009
[FIX] (__chk_dentries:1258) --> Clear bad dentry 0x20 with bad ino 0x4a150009
[ASSERT] (__chk_dentries:1255) --> Bad dentry 0x21 with invalid NID/ino 0x1800094a
[FIX] (__chk_dentries:1258) --> Clear bad dentry 0x21 with bad ino 0x1800094a
*** buffer overflow detected ***: fsck.f2fs terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7338f)[0x7fa56b17b38f]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7fa56b212c9c]
/lib/x86_64-linux-gnu/libc.so.6(+0x109b60)[0x7fa56b211b60]
fsck.f2fs[0x4032f6]
fsck.f2fs[0x4063f7]
fsck.f2fs[0x406d09]
fsck.f2fs[0x4046b8]
fsck.f2fs[0x405378]
fsck.f2fs[0x405d86]
fsck.f2fs[0x402071]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7fa56b129ec5]
Reported-by: Mirh <mirh@protonmail.ch>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fsck/fsck.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 4b6628e..636477d 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -1281,8 +1281,8 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, struct child_info *child,
name_len = le16_to_cpu(dentry[i].name_len);
- if (name_len == 0) {
- ASSERT_MSG("Bad dentry 0x%x with zero name_len", i);
+ if (name_len == 0 || name_len > F2FS_NAME_LEN) {
+ ASSERT_MSG("Bad dentry 0x%x with invalid name_len", i);
if (c.fix_on) {
FIX_MSG("Clear bad dentry 0x%x", i);
test_and_clear_bit_le(i, bitmap);
--
2.8.3
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 5/5] fsck.f2fs: support restore lost files into ./lost_found/
2016-10-14 0:02 [PATCH 1/5] f2fs: avoid AOSP build failure Jaegeuk Kim
` (2 preceding siblings ...)
2016-10-14 0:02 ` [PATCH 4/5] fsck.f2fs: check condition to avoid wrong memory allocation Jaegeuk Kim
@ 2016-10-14 0:02 ` Jaegeuk Kim
3 siblings, 0 replies; 5+ messages in thread
From: Jaegeuk Kim @ 2016-10-14 0:02 UTC (permalink / raw)
To: linux-f2fs-devel; +Cc: Jaegeuk Kim
This patch adds to support restoring lost files into ./lost_found/.
For example,
# fsck.f2fs /dev/sdXX
...
NID[0x87d7] is unreachable
NID[0x87d8] is unreachable
NID[0x87d9] is unreachable
[FSCK] Unreachable nat entries [Fail] [0x4988]
[FSCK] SIT valid block bitmap checking [Fail]
[FSCK] Hard link checking for regular file [Ok..] [0x0]
[FSCK] valid_block_count matching with CP [Fail] [0x2]
[FSCK] valid_node_count matcing with CP (de lookup) [Fail] [0x1]
[FSCK] valid_node_count matcing with CP (nat lookup) [Ok..] [0x4989]
[FSCK] valid_inode_count matched with CP [Fail] [0x1]
[FSCK] free segment_count matched with CP [Ok..] [0x1f7]
[FSCK] next block offset is free [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs [Fail]
Do you want to restore lost files into ./lost_found/? [Y/N] y
Then, you can restore unreachable files from ./lost_found/ in its best effort.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fsck/dump.c | 41 +++++++++++++++++++++++------------------
fsck/fsck.c | 15 +++++++++++++++
fsck/fsck.h | 4 ++--
fsck/main.c | 2 +-
fsck/mount.c | 11 ++++++-----
5 files changed, 47 insertions(+), 26 deletions(-)
diff --git a/fsck/dump.c b/fsck/dump.c
index c048429..befffd7 100644
--- a/fsck/dump.c
+++ b/fsck/dump.c
@@ -239,7 +239,7 @@ void ssa_dump(struct f2fs_sb_info *sbi, int start_ssa, int end_ssa)
close(fd);
}
-static void dump_data_blk(__u64 offset, u32 blkaddr)
+static void dump_data_blk(struct f2fs_sb_info *sbi, __u64 offset, u32 blkaddr)
{
char buf[F2FS_BLKSIZE];
@@ -247,7 +247,7 @@ static void dump_data_blk(__u64 offset, u32 blkaddr)
return;
/* get data */
- if (blkaddr == NEW_ADDR) {
+ if (blkaddr == NEW_ADDR || !IS_VALID_BLK_ADDR(sbi, blkaddr)) {
memset(buf, 0, F2FS_BLKSIZE);
} else {
int ret;
@@ -294,7 +294,7 @@ static void dump_node_blk(struct f2fs_sb_info *sbi, int ntype,
for (i = 0; i < idx; i++, (*ofs)++) {
switch (ntype) {
case TYPE_DIRECT_NODE:
- dump_data_blk(*ofs * F2FS_BLKSIZE,
+ dump_data_blk(sbi, *ofs * F2FS_BLKSIZE,
le32_to_cpu(node_blk->dn.addr[i]));
break;
case TYPE_INDIRECT_NODE:
@@ -328,7 +328,7 @@ static void dump_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
/* check data blocks in inode */
for (i = 0; i < ADDRS_PER_INODE(&node_blk->i); i++, ofs++)
- dump_data_blk(ofs * F2FS_BLKSIZE,
+ dump_data_blk(sbi, ofs * F2FS_BLKSIZE,
le32_to_cpu(node_blk->i.i_addr[i]));
/* check node blocks in inode */
@@ -347,33 +347,36 @@ static void dump_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
}
}
-void dump_file(struct f2fs_sb_info *sbi, struct node_info *ni,
- struct f2fs_node *node_blk)
+static void dump_file(struct f2fs_sb_info *sbi, struct node_info *ni,
+ struct f2fs_node *node_blk, int force)
{
struct f2fs_inode *inode = &node_blk->i;
u32 imode = le32_to_cpu(inode->i_mode);
+ u32 namelen = le32_to_cpu(inode->i_namelen);
char name[255] = {0};
char path[1024] = {0};
char ans[255] = {0};
int ret;
- if (!S_ISREG(imode)) {
- MSG(0, "Not a regular file\n\n");
+ if (!S_ISREG(imode) || namelen == 0 || namelen > F2FS_NAME_LEN) {
+ MSG(force, "Not a regular file or wrong name info\n\n");
return;
}
+ if (force)
+ goto dump;
printf("Do you want to dump this file into ./lost_found/? [Y/N] ");
ret = scanf("%s", ans);
ASSERT(ret >= 0);
if (!strcasecmp(ans, "y")) {
+dump:
ret = system("mkdir -p ./lost_found");
ASSERT(ret >= 0);
/* make a file */
- strncpy(name, (const char *)inode->i_name,
- le32_to_cpu(inode->i_namelen));
- name[le32_to_cpu(inode->i_namelen)] = 0;
+ strncpy(name, (const char *)inode->i_name, namelen);
+ name[namelen] = 0;
sprintf(path, "./lost_found/%s", name);
c.dump_fd = open(path, O_TRUNC|O_CREAT|O_RDWR, 0666);
@@ -390,7 +393,7 @@ void dump_file(struct f2fs_sb_info *sbi, struct node_info *ni,
}
}
-void dump_node(struct f2fs_sb_info *sbi, nid_t nid)
+void dump_node(struct f2fs_sb_info *sbi, nid_t nid, int force)
{
struct node_info ni;
struct f2fs_node *node_blk;
@@ -406,17 +409,19 @@ void dump_node(struct f2fs_sb_info *sbi, nid_t nid)
DBG(1, "nat_entry.ino [0x%x]\n", ni.ino);
if (ni.blk_addr == 0x0)
- MSG(0, "Invalid nat entry\n\n");
+ MSG(force, "Invalid nat entry\n\n");
DBG(1, "node_blk.footer.ino [0x%x]\n", le32_to_cpu(node_blk->footer.ino));
DBG(1, "node_blk.footer.nid [0x%x]\n", le32_to_cpu(node_blk->footer.nid));
if (le32_to_cpu(node_blk->footer.ino) == ni.ino &&
- le32_to_cpu(node_blk->footer.nid) == ni.nid) {
- print_node_info(node_blk);
- dump_file(sbi, &ni, node_blk);
+ le32_to_cpu(node_blk->footer.nid) == ni.nid &&
+ ni.ino == ni.nid) {
+ print_node_info(node_blk, force);
+ dump_file(sbi, &ni, node_blk, force);
} else {
- MSG(0, "Invalid node block\n\n");
+ print_node_info(node_blk, force);
+ MSG(force, "Invalid (i)node block\n\n");
}
free(node_blk);
@@ -434,7 +439,7 @@ static void dump_node_from_blkaddr(u32 blk_addr)
ASSERT(ret >= 0);
if (c.dbg_lv > 0)
- print_node_info(node_blk);
+ print_node_info(node_blk, 0);
else
print_inode_info(&node_blk->i, 1);
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 636477d..7dd311f 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -1939,6 +1939,21 @@ int fsck_verify(struct f2fs_sb_info *sbi)
ret = EXIT_ERR_CODE;
}
+#ifndef WITH_ANDROID
+ if (nr_unref_nid && !c.ro) {
+ char ans[255] = {0};
+
+ printf("\nDo you want to restore lost files into ./lost_found/? [Y/N] ");
+ ret = scanf("%s", ans);
+ ASSERT(ret >= 0);
+ if (!strcasecmp(ans, "y")) {
+ for (i = 0; i < fsck->nr_nat_entries; i++) {
+ if (f2fs_test_bit(i, fsck->nat_area_bitmap))
+ dump_node(sbi, i, 1);
+ }
+ }
+ }
+#endif
/* fix global metadata */
if (force || (c.fix_on && !c.ro)) {
struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
diff --git a/fsck/fsck.h b/fsck/fsck.h
index a86a30f..438d29b 100644
--- a/fsck/fsck.h
+++ b/fsck/fsck.h
@@ -133,7 +133,7 @@ int fsck_chk_meta(struct f2fs_sb_info *sbi);
extern void update_free_segments(struct f2fs_sb_info *);
void print_cp_state(u32);
-extern void print_node_info(struct f2fs_node *);
+extern void print_node_info(struct f2fs_node *, int);
extern void print_inode_info(struct f2fs_inode *, int);
extern struct seg_entry *get_seg_entry(struct f2fs_sb_info *, unsigned int);
extern struct f2fs_summary_block *get_sum_block(struct f2fs_sb_info *,
@@ -179,7 +179,7 @@ struct dump_option {
extern void nat_dump(struct f2fs_sb_info *);
extern void sit_dump(struct f2fs_sb_info *, unsigned int, unsigned int);
extern void ssa_dump(struct f2fs_sb_info *, int, int);
-extern void dump_node(struct f2fs_sb_info *, nid_t);
+extern void dump_node(struct f2fs_sb_info *, nid_t, int);
extern int dump_info_from_blkaddr(struct f2fs_sb_info *, u32);
/* defrag.c */
diff --git a/fsck/main.c b/fsck/main.c
index 8acc970..7e8fdf3 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -376,7 +376,7 @@ static void do_dump(struct f2fs_sb_info *sbi)
if (opt->blk_addr != -1)
dump_info_from_blkaddr(sbi, opt->blk_addr);
if (opt->nid)
- dump_node(sbi, opt->nid);
+ dump_node(sbi, opt->nid, 0);
print_cp_state(flag);
diff --git a/fsck/mount.c b/fsck/mount.c
index 1550f45..f343718 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -105,21 +105,22 @@ void print_inode_info(struct f2fs_inode *inode, int name)
printf("\n");
}
-void print_node_info(struct f2fs_node *node_block)
+void print_node_info(struct f2fs_node *node_block, int verbose)
{
nid_t ino = le32_to_cpu(node_block->footer.ino);
nid_t nid = le32_to_cpu(node_block->footer.nid);
/* Is this inode? */
if (ino == nid) {
- DBG(0, "Node ID [0x%x:%u] is inode\n", nid, nid);
- print_inode_info(&node_block->i, 0);
+ DBG(verbose, "Node ID [0x%x:%u] is inode\n", nid, nid);
+ print_inode_info(&node_block->i, verbose);
} else {
int i;
u32 *dump_blk = (u32 *)node_block;
- DBG(0, "Node ID [0x%x:%u] is direct node or indirect node.\n",
+ DBG(verbose,
+ "Node ID [0x%x:%u] is direct node or indirect node.\n",
nid, nid);
for (i = 0; i <= 10; i++)
- MSG(0, "[%d]\t\t\t[0x%8x : %d]\n",
+ MSG(verbose, "[%d]\t\t\t[0x%8x : %d]\n",
i, dump_blk[i], dump_blk[i]);
}
}
--
2.8.3
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-10-14 0:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-14 0:02 [PATCH 1/5] f2fs: avoid AOSP build failure Jaegeuk Kim
2016-10-14 0:02 ` [PATCH 2/5] f2fs-tools: clean up and avoid build warning Jaegeuk Kim
2016-10-14 0:02 ` [PATCH 3/5] libf2fs: avoid garbage printout Jaegeuk Kim
2016-10-14 0:02 ` [PATCH 4/5] fsck.f2fs: check condition to avoid wrong memory allocation Jaegeuk Kim
2016-10-14 0:02 ` [PATCH 5/5] fsck.f2fs: support restore lost files into ./lost_found/ Jaegeuk Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).