Skip to content

Commit e607c82

Browse files
Yongpeng YangJaegeuk Kim
authored andcommitted
f2fs_io: add flags parameter to fiemap subcommand
Add a flags parameter to the fiemap subcommand so that it can pass FIEMAP_FLAG_SYNC, FIEMAP_FLAG_XATTR, and FIEMAP_FLAG_CACHE. Before retrieving the fiemap, perform the corresponding actions based on these flags, such as syncing data or preloading extents. Signed-off-by: Yongpeng Yang <yangyongpeng@xiaomi.com> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent c7ac88f commit e607c82

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

man/f2fs_io.8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ mmap(MAP_POPULATE)
138138
mmap() + mlock()
139139
.RE
140140
.TP
141-
\fBfiemap\fR \fI[offset in 4kb] [count] [file_path]\fR
141+
\fBfiemap\fR \fI[offset in 4kb] [count] [file_path] {flags}\fR
142142
get block address in file
143143
.TP
144144
\fBgc_urgent\fR \fIdev [start|end|run] [time in sec]\fR

tools/f2fs_io/f2fs_io.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,19 +1357,24 @@ static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)
13571357
}
13581358

13591359
#define fiemap_desc "get block address in file"
1360-
#define fiemap_help \
1361-
"f2fs_io fiemap [offset in 4kb] [count in 4kb] [file_path]\n\n"\
1360+
#define fiemap_help \
1361+
"f2fs_io fiemap [offset in 4kb] [count in 4kb] [file_path] {flags}\n\n" \
1362+
"flags: bitmask with optional combinations of:\n" \
1363+
"0: no extra actions, by default\n" \
1364+
"1: sync file data before map\n" \
1365+
"2: map extended attribute tree\n" \
1366+
"4: request caching of the extents\n" \
13621367

13631368
#if defined(HAVE_LINUX_FIEMAP_H) && defined(HAVE_LINUX_FS_H)
13641369
static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
13651370
{
13661371
unsigned int i;
13671372
int fd, extents_mem_size;
13681373
u64 start, length;
1369-
u32 mapped_extents;
1374+
u32 mapped_extents, flags = 0;
13701375
struct fiemap *fm = xmalloc(sizeof(struct fiemap));
13711376

1372-
if (argc != 4) {
1377+
if (argc < 4 || argc > 5) {
13731378
fputs("Excess arguments\n\n", stderr);
13741379
fputs(cmd->cmd_help, stderr);
13751380
exit(1);
@@ -1378,8 +1383,11 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
13781383
memset(fm, 0, sizeof(struct fiemap));
13791384
start = (u64)atoi(argv[1]) * F2FS_DEFAULT_BLKSIZE;
13801385
length = (u64)atoi(argv[2]) * F2FS_DEFAULT_BLKSIZE;
1386+
if (argc == 5)
1387+
flags = (u32)atoi(argv[4]);
13811388
fm->fm_start = start;
13821389
fm->fm_length = length;
1390+
fm->fm_flags = flags;
13831391

13841392
fd = xopen(argv[3], O_RDONLY | O_LARGEFILE, 0);
13851393

@@ -1397,6 +1405,7 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
13971405
memset(fm, 0, sizeof(struct fiemap) + extents_mem_size);
13981406
fm->fm_start = start;
13991407
fm->fm_length = length;
1408+
fm->fm_flags = flags;
14001409
fm->fm_extent_count = mapped_extents;
14011410

14021411
if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)

0 commit comments

Comments
 (0)