[2/3] xfs_io: get foreign blocksize & sector size in openfile
diff mbox

Message ID e8e53975-5482-3846-f528-08fc5db97517@sandeen.net
State New
Headers show

Commit Message

Eric Sandeen Aug. 22, 2017, 9:16 p.m. UTC
Use statvfs to fill in geometry block size and sector
size in openfile() for "foreign" (non-xfs) files.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/io/open.c b/io/open.c
index f2ea7c3..b0dcabc 100644
--- a/io/open.c
+++ b/io/open.c
@@ -16,6 +16,7 @@ 
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <sys/statvfs.h>
 #include "command.h"
 #include "input.h"
 #include "init.h"
@@ -94,13 +95,25 @@  openfile(
                }
        }
 
-       if (!geom || !platform_test_xfs_fd(fd))
+       if (!geom)
                return fd;
 
-       if (xfsctl(path, fd, XFS_IOC_FSGEOMETRY, geom) < 0) {
-               perror("XFS_IOC_FSGEOMETRY");
-               close(fd);
-               return -1;
+       if (platform_test_xfs_fd(fd)) {
+               if (xfsctl(path, fd, XFS_IOC_FSGEOMETRY, geom) < 0) {
+                       perror("XFS_IOC_FSGEOMETRY");
+                       close(fd);
+                       return -1;
+               }
+       } else {        /* Fill in block & sector size for cvtnum */
+               struct statvfs  statbuf;
+
+               if (fstatvfs(fd, &statbuf) < 0) {
+                       perror("fstatvfs");
+                       close(fd);
+                       return -1;
+               }
+               geom->blocksize = statbuf.f_bsize;
+               geom->sectsize = 512;
        }
 
        if (!(flags & IO_READONLY) && (flags & IO_REALTIME)) {