Skip to contentSkip to conversation

(Resend) [PATCH v2] f2fs: fix to use per-inode maxbytes in f2fs_fiemap

f2fs-dev Chengguang Xu 2 participants 2 messages Mar 9, 2021 – Mar 11, 2021 F2FS file system

lore
Share & tools
lore
#0 lore raw

F2FS inode may have different max size,
so change to use per-inode maxbytes.

---
Hi Jaegeuk, Chao

Please take this instead of previous v2 patch which has sent by mistake.

v1->v2:
- Calculate max bytes in inode lock.

 fs/f2fs/data.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
fs/f2fs/data.c +10 -0
index 7c95818639a6..b734ca023149 100644
@@ -1837,6 +1837,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 	int ret = 0;
 	bool compr_cluster = false;
 	unsigned int cluster_size = F2FS_I(inode)->i_cluster_size;
+	loff_t maxbytes;
 
 	if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) {
 		ret = f2fs_precache_extents(inode);
@@ -1850,6 +1851,15 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 
 	inode_lock(inode);
 
+	maxbytes = max_file_blocks(inode) << F2FS_BLKSIZE_BITS;
+	if (start > maxbytes) {
+		ret = -EFBIG;
+		goto out;
+	}
+
+	if (len > maxbytes || (maxbytes - len) < start)
+		len = maxbytes - start;
+
 	if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) {
 		ret = f2fs_xattr_fiemap(inode, fieinfo);
 		goto out;
Signature · 9 lines
2.27.0




_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel