Skip to contentSkip to conversation

mkfs.f2fs: fix the discarding size for block device

PATCH New Jaegeuk Kim 1 participant 1 message Oct 18, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs.f2fs: fix the discarding size for block device

This patch fixes wrong discarding size.

---
 mkfs/f2fs_format.c       | 2 +-
 mkfs/f2fs_format_utils.c | 7 +++----
 mkfs/f2fs_format_utils.h | 2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)
mkfs/f2fs_format.c +1 -1
index 659c73c..1453b6b 100644
@@ -948,7 +948,7 @@ int f2fs_format_device(void)
 	}
 
 	if (c.trim) {
-		err = f2fs_trim_device(c.fd);
+		err = f2fs_trim_device(c.fd, c.total_sectors * c.sector_size);
 		if (err < 0) {
 			MSG(0, "\tError: Failed to trim whole device!!!\n");
 			goto exit;
mkfs/f2fs_format_utils.c +3 -4
index eb8e3c0..ba93308 100644
@@ -34,7 +34,7 @@
 #define BLKSECDISCARD	_IO(0x12,125)
 #endif
 
-int f2fs_trim_device(int fd)
+int f2fs_trim_device(int fd, u_int64_t bytes)
 {
 	unsigned long long range[2];
 	struct stat stat_buf;
@@ -45,7 +45,7 @@ int f2fs_trim_device(int fd)
 	}
 
 	range[0] = 0;
-	range[1] = stat_buf.st_size;
+	range[1] = bytes;
 
 #if defined(WITH_BLKDISCARD) && defined(BLKDISCARD)
 	MSG(0, "Info: Discarding device\n");
@@ -70,8 +70,7 @@ int f2fs_trim_device(int fd)
 		if (ioctl(fd, BLKDISCARD, &range) < 0) {
 			MSG(0, "Info: This device doesn't support BLKDISCARD\n");
 		} else {
-			MSG(0, "Info: Discarded %lu MB\n",
-						stat_buf.st_size >> 20);
+			MSG(0, "Info: Discarded %llu MB\n", range[1] >> 20);
 		}
 	} else
 		return -1;
mkfs/f2fs_format_utils.h +1 -1
index bc91aa3..ed28c58 100644
@@ -12,5 +12,5 @@
 
 extern struct f2fs_configuration c;
 
-int f2fs_trim_device(int);
+int f2fs_trim_device(int, u_int64_t);
 int f2fs_format_device(void);
Signature · 6 lines
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