From: Eric Sandeen Date: Fri, 18 Dec 2015 01:15:25 +0000 (+1100) Subject: mkfs: get sector size from host fs d_miniosz when mkfs'ing file X-Git-Tag: v4.5.0-rc1~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98dd72d3b239050138cf9eb9373c83743878a7d2;p=thirdparty%2Fxfsprogs-dev.git mkfs: get sector size from host fs d_miniosz when mkfs'ing file Now that we allow logical-sector-sized DIOs even if our xfs filesystem is set to physical-sector-sized "sectors," we can allow the creation of filesystem images with block and sector sizes down to the host device's logical sector size, rather than the filesystem's sector size. So in platform_findsizes(), change our query of the filesystem to an XFS_IOC_DIOINFO query, and use the returned d_miniosz for sector size in the S_IFREG case. This allows the creation of i.e. a 2k block sized image on an xfs filesystem w/ 4k sector size created on a 4k/512 block device, which would otherwise fail today. Signed-off-by: Eric Sandeen Reviewed-by: Dave Chinner Signed-off-by: Dave Chinner --- diff --git a/libxfs/linux.c b/libxfs/linux.c index 885016a01..f6ea1b2ce 100644 --- a/libxfs/linux.c +++ b/libxfs/linux.c @@ -142,18 +142,20 @@ platform_findsizes(char *path, int fd, long long *sz, int *bsz) progname, path, strerror(errno)); exit(1); } + if ((st.st_mode & S_IFMT) == S_IFREG) { - struct xfs_fsop_geom_v1 geom = { 0 }; + struct dioattr da; *sz = (long long)(st.st_size >> 9); - if (ioctl(fd, XFS_IOC_FSGEOMETRY_V1, &geom) < 0) { + + if (ioctl(fd, XFS_IOC_DIOINFO, &da) < 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; + *bsz = da.d_miniosz; if (*bsz > max_block_alignment) max_block_alignment = *bsz;