All of lore.kernel.org
 help / color / mirror / Atom feed
From: nl6720 via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: nl6720 <devnull@nl6720.me>
Subject: [f2fs-dev] [PATCH] f2fs-tools: prefer physical over logical block size
Date: Fri, 25 Apr 2025 04:36:23 +0300	[thread overview]
Message-ID: <20250425013623.918150-1-devnull@nl6720.me> (raw)

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 <devnull@nl6720.me>
---
 lib/libf2fs.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index d2579d76a5c7eaf141dc8aad11c176eeadabad83..040ea4bc87288fa075cb4bf51df08b9db28a65b3 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;
-- 
2.49.0



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

             reply	other threads:[~2025-04-25  1:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-25  1:36 nl6720 via Linux-f2fs-devel [this message]
2025-04-27  8:45 ` [f2fs-dev] [PATCH] f2fs-tools: prefer physical over logical block size Chao Yu via Linux-f2fs-devel
2025-04-27  9:30   ` nl6720 via Linux-f2fs-devel
2025-04-28  7:33     ` Chao Yu via Linux-f2fs-devel
2025-04-29 16:53       ` nl6720 via Linux-f2fs-devel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250425013623.918150-1-devnull@nl6720.me \
    --to=linux-f2fs-devel@lists.sourceforge.net \
    --cc=devnull@nl6720.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.