Skip to content

Commit 77569f7

Browse files
Zhiguo NiuJaegeuk Kim
authored andcommitted
f2fs: fix to adjust appropriate length for fiemap
If user give a file size as "length" parameter for fiemap operations, but if this size is non-block size aligned, it will show 2 segments fiemap results even this whole file is contiguous on disk, such as the following results: ./f2fs_io fiemap 0 19034 ylog/analyzer.py Fiemap: offset = 0 len = 19034 logical addr. physical addr. length flags 0 0000000000000000 0000000020baa000 0000000000004000 00001000 1 0000000000004000 0000000020bae000 0000000000001000 00001001 after this patch: ./f2fs_io fiemap 0 19034 ylog/analyzer.py Fiemap: offset = 0 len = 19034 logical addr. physical addr. length flags 0 0000000000000000 00000000315f3000 0000000000005000 00001001 Signed-off-by: Zhiguo Niu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 7461f37 commit 77569f7

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

fs/f2fs/data.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,12 +1938,12 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
19381938
goto out;
19391939
}
19401940

1941-
if (F2FS_BYTES_TO_BLK(len) == 0)
1942-
len = F2FS_BLKSIZE;
1943-
19441941
start_blk = F2FS_BYTES_TO_BLK(start);
19451942
last_blk = F2FS_BYTES_TO_BLK(start + len - 1);
19461943

1944+
if (len & F2FS_BLKSIZE_MASK)
1945+
len = round_up(len, F2FS_BLKSIZE);
1946+
19471947
next:
19481948
memset(&map, 0, sizeof(map));
19491949
map.m_lblk = start_blk;

include/linux/f2fs_fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define NEW_ADDR ((block_t)-1) /* used as block_t addresses */
2525
#define COMPRESS_ADDR ((block_t)-2) /* used as compressed data flag */
2626

27+
#define F2FS_BLKSIZE_MASK (F2FS_BLKSIZE - 1)
2728
#define F2FS_BYTES_TO_BLK(bytes) ((unsigned long long)(bytes) >> F2FS_BLKSIZE_BITS)
2829
#define F2FS_BLK_TO_BYTES(blk) ((unsigned long long)(blk) << F2FS_BLKSIZE_BITS)
2930
#define F2FS_BLK_END_BYTES(blk) (F2FS_BLK_TO_BYTES(blk + 1) - 1)

0 commit comments

Comments
 (0)