xfs
[Top] [All Lists]

[PATCH 1/2, RFC] xfsprogs: check fs sector size in platform_findsizes()

To: Eric Sandeen <sandeen@xxxxxxxxxx>, xfs-oss <xfs@xxxxxxxxxxx>
Subject: [PATCH 1/2, RFC] xfsprogs: check fs sector size in platform_findsizes()
From: Eric Sandeen <sandeen@xxxxxxxxxxx>
Date: Tue, 27 May 2014 19:14:25 -0500
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <53852A05.5040006@xxxxxxxxxx>
References: <53852A05.5040006@xxxxxxxxxx>
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
Try the xfs geometry ioctl if the mkfs target resides
in a file; this gives us the equivalent of a device
sector size.

This does, however, emit a warning if the target file
exists on a non-XFS filesystem, and that might not be super.

Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
---

diff --git a/libxfs/linux.c b/libxfs/linux.c
index 2e07d54..d66a90f 100644
--- a/libxfs/linux.c
+++ b/libxfs/linux.c
@@ -141,10 +141,19 @@ platform_findsizes(char *path, int fd, long long *sz, int 
*bsz)
                exit(1);
        }
        if ((st.st_mode & S_IFMT) == S_IFREG) {
+               struct xfs_fsop_geom_v1 geom = { 0 };
+
                *sz = (long long)(st.st_size >> 9);
-               *bsz = BBSIZE;
-               if (BBSIZE > max_block_alignment)
-                       max_block_alignment = BBSIZE;
+               if (ioctl(fd, XFS_IOC_FSGEOMETRY_V1, &geom) < 0) {
+                       fprintf(stderr, _("Cannot get host filesystem 
geometry.\n"
+       "mkfs may fail if there is a sector size mismatch between\n"
+       "the image and the host filesystem.\n"));
+                       *bsz = BBSIZE;
+               } else
+                       *bsz = geom.sectsize;
+
+               if (*bsz > max_block_alignment)
+                       max_block_alignment = *bsz;
                return;
        }
 


<Prev in Thread] Current Thread [Next in Thread>