Skip to content

Commit c4933c2

Browse files
Yongpeng YangJaegeuk Kim
authored andcommitted
f2fs_io: add flags parameter to fiemap subcommand
Add a flags parameter to the fiemap subcommand, allowing the specification of whether to retrieve file mappings after writing to the file. Signed-off-by: Yongpeng Yang <yangyongpeng@xiaomi.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 11839a7 commit c4933c2

2 files changed

Lines changed: 12 additions & 6 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] [flags] [file_path]\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: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,19 +1357,22 @@ 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] [flags] [file_path]\n\n" \
1362+
"flags can be the following values:\n" \
1363+
"0: No extra actions\n" \
1364+
"1: Sync file data before map\n" \
13621365

13631366
#if defined(HAVE_LINUX_FIEMAP_H) && defined(HAVE_LINUX_FS_H)
13641367
static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
13651368
{
13661369
unsigned int i;
13671370
int fd, extents_mem_size;
13681371
u64 start, length;
1369-
u32 mapped_extents;
1372+
u32 mapped_extents, flags;
13701373
struct fiemap *fm = xmalloc(sizeof(struct fiemap));
13711374

1372-
if (argc != 4) {
1375+
if (argc != 5) {
13731376
fputs("Excess arguments\n\n", stderr);
13741377
fputs(cmd->cmd_help, stderr);
13751378
exit(1);
@@ -1378,10 +1381,12 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
13781381
memset(fm, 0, sizeof(struct fiemap));
13791382
start = (u64)atoi(argv[1]) * F2FS_DEFAULT_BLKSIZE;
13801383
length = (u64)atoi(argv[2]) * F2FS_DEFAULT_BLKSIZE;
1384+
flags = (u32)atoi(argv[3]);
13811385
fm->fm_start = start;
13821386
fm->fm_length = length;
1387+
fm->fm_flags = flags;
13831388

1384-
fd = xopen(argv[3], O_RDONLY | O_LARGEFILE, 0);
1389+
fd = xopen(argv[4], O_RDONLY | O_LARGEFILE, 0);
13851390

13861391
printf("Fiemap: offset = %"PRIu64" len = %"PRIu64"\n",
13871392
start / F2FS_DEFAULT_BLKSIZE,
@@ -1397,6 +1402,7 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
13971402
memset(fm, 0, sizeof(struct fiemap) + extents_mem_size);
13981403
fm->fm_start = start;
13991404
fm->fm_length = length;
1405+
fm->fm_flags = flags;
14001406
fm->fm_extent_count = mapped_extents;
14011407

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

0 commit comments

Comments
 (0)