If mkfs is making a FS in a file, then the new FS should take host FS blocksize as sectorsize. This patch is ensuring it by using statfs() instead of stat() and platform_findsizes(). Signed-off-by: Jan Ťulák <jtulak@xxxxxxxxxx> --- libxfs/init.c | 7 +++++-- mkfs/xfs_mkfs.c | 54 +++++++++++++++++++++++++++++------------------------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/libxfs/init.c b/libxfs/init.c index ed97043..02d152c 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -17,6 +17,7 @@ */ #include <sys/stat.h> +#include <sys/vfs.h> #include "init.h" #include "libxfs_priv.h" @@ -247,6 +248,7 @@ libxfs_init(libxfs_init_t *a) int rval = 0; int flags; struct stat st; + struct statfs stfs; dpath[0] = logpath[0] = rtpath[0] = '\0'; dname = a->dname; @@ -280,8 +282,9 @@ libxfs_init(libxfs_init_t *a) a->setblksize); a->dfd = libxfs_device_to_fd(a->ddev); stat(dname, &st); - a->dsize = st.st_size; - a->dbsize = st.st_blksize; + statfs(dname, &stfs); + a->dsize = st.st_size/BBSIZE; + a->dbsize = stfs.f_bsize; } else { if (!check_open(dname, flags, &rawfile, &blockfile)) goto done; diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index ce64230..2e455db 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -18,6 +18,7 @@ #include <xfs/libxfs.h> #include <ctype.h> +#include <sys/vfs.h> #ifdef ENABLE_BLKID #include <blkid/blkid.h> #else @@ -865,31 +866,23 @@ static void get_topology( struct fs_topology *ft, int force_overwrite) { - if (!xi->disfile) { - char *dfile = xi->volname ? xi->volname : xi->dname; - struct stat statbuf; + char *dfile = xi->volname ? xi->volname : xi->dname; + struct stat statbuf; + struct statfs statfsbuf; - /* - * If our target is a regular file, and xi->disfile isn't - * set (i.e. no "-d file" invocation), use platform_findsizes - * to try to obtain the underlying filesystem's requirements - * for direct IO; we'll set our sector size to that if possible. - */ - if (!stat(dfile, &statbuf) && S_ISREG(statbuf.st_mode)) { - int fd; - long long dummy; - - fd = open(dfile, O_RDONLY); - if (fd >= 0) { - platform_findsizes(dfile, fd, &dummy, - &ft->lsectorsize); - close(fd); - } - } else { - blkid_get_topology(dfile, &ft->dsunit, &ft->dswidth, - &ft->lsectorsize, &ft->psectorsize, - force_overwrite); - } + /* + * If our target is a regular file, use statfs + * to try to obtain the underlying filesystem's blocksize. + */ + if (xi->disfile || + (!stat(dfile, &statbuf) && S_ISREG(statbuf.st_mode))) { + + statfs(dfile, &statfsbuf); + ft->lsectorsize = statfsbuf.f_bsize; + } else { + blkid_get_topology(dfile, &ft->dsunit, &ft->dswidth, + &ft->lsectorsize, &ft->psectorsize, + force_overwrite); } if (xi->rtname && !xi->risfile) { @@ -930,9 +923,20 @@ static void get_topology( { char *dfile = xi->volname ? xi->volname : xi->dname; + struct stat statbuf; + struct statfs statfsbuf; int bsz = BBSIZE; - if (!xi->disfile) { + /* + * If our target is a regular file, use statfs + * to try to obtain the underlying filesystem's blocksize. + */ + if (xi->disfile || + (!stat(dfile, &statbuf) && S_ISREG(statbuf.st_mode))) { + + statfs(dfile, &statfsbuf); + bsz = statfsbuf.f_bsize; + } else { int fd; long long dummy; -- 2.1.0 _______________________________________________ xfs mailing list xfs@xxxxxxxxxxx http://oss.sgi.com/mailman/listinfo/xfs