]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfsprogs: try to handle mkfs of a file on 4k sector device
authorEric Sandeen <sandeen@sandeen.net>
Thu, 19 Jun 2014 02:10:23 +0000 (12:10 +1000)
committerDave Chinner <david@fromorbit.com>
Thu, 19 Jun 2014 02:10:23 +0000 (12:10 +1000)
Try the xfs geometry ioctl if the mkfs target resides
in a file; this gives us the equivalent of a device
sector size.

If this fails, and there's a sector size mismatch
between the host FS and the filesystem, then mkfs might
fail - but that's no worse than it's been before.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
libxfs/linux.c

index 2e07d544d9ba8682e3670f796f224dabf2db2080..8d1a117688d9e2abbc7ddb31198909adbe26cad0 100644 (file)
@@ -141,10 +141,20 @@ 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) {
+                       /*
+                        * fall back to BBSIZE; mkfs might fail if there's a
+                        * size mismatch between the image & the host fs...
+                        */
+                       *bsz = BBSIZE;
+               } else
+                       *bsz = geom.sectsize;
+
+               if (*bsz > max_block_alignment)
+                       max_block_alignment = *bsz;
                return;
        }