diff mbox series

[f2fs-dev,1/1] f2fs-tools: prefer physical over logical block size

Message ID 20241121150623.156534-1-nl6720@gmail.com (mailing list archive)
State New
Headers show
Series [f2fs-dev,1/1] f2fs-tools: prefer physical over logical block size | expand

Commit Message

nl6720 Nov. 21, 2024, 3:06 p.m. UTC
Some drives operate in "512e" configuration with their logical block
size set to 512 bytes for legacy compatibility reasons while providing
a more optimal 4096 byte value as the physical block size.

Since the physical block size is the smallest unit a physical storage
device can write atomically, prefer it over the logical block size.

Closes: https://github.com/jaegeuk/f2fs-tools/issues/29

Signed-off-by: nl6720 <nl6720@gmail.com>
---
 lib/libf2fs.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index ecd22d4e6a5cab515b86e4d1f606b3aaa2672072..7903861f952f38334f88fc3b72422b7665c00b54 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -933,10 +933,15 @@  void get_kernel_uname_version(__u8 *version)
 #define BLKSSZGET	_IO(0x12,104)
 #endif
 
+#if defined(__linux__) && defined(_IO) && !defined(BLKPBSZGET)
+#define BLKPBSZGET	_IO(0x12,123)
+#endif
+
 #if defined(__APPLE__)
 #include <sys/disk.h>
 #define BLKGETSIZE	DKIOCGETBLOCKCOUNT
 #define BLKSSZGET	DKIOCGETBLOCKCOUNT
+#define BLKPBSZGET	DKIOCGETBLOCKCOUNT
 #endif /* APPLE_DARWIN */
 
 #ifndef _WIN32
@@ -1050,8 +1055,8 @@  int get_device_info(int i)
 	} else if (S_ISREG(stat_buf->st_mode)) {
 		dev->total_sectors = stat_buf->st_size / dev->sector_size;
 	} else if (S_ISBLK(stat_buf->st_mode)) {
-#ifdef BLKSSZGET
-		if (ioctl(fd, BLKSSZGET, &sector_size) < 0)
+#if defined(BLKPBSZGET) && defined(BLKSSZGET)
+		if ((ioctl(fd, BLKPBSZGET, &sector_size) < 0) && (ioctl(fd, BLKSSZGET, &sector_size) < 0))
 			MSG(0, "\tError: Using the default sector size\n");
 		else if (dev->sector_size < sector_size)
 			dev->sector_size = sector_size;