From: Eric Sandeen Date: Sun, 17 Jan 2010 16:31:58 +0000 (-0600) Subject: mkfs: get size of device properly X-Git-Tag: v3.1.1~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d943b1140e566223bfd424ca4e24b3c1f3781037;p=thirdparty%2Fxfsprogs-dev.git mkfs: get size of device properly Test device node size properly in check_overwrite, st_size is only valid for regular files. Signed-off-by: Eric Sandeen Reviewed-by: Christoph Hellwig --- diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 0743976a9..689425dfa 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -297,18 +297,23 @@ check_overwrite( const char *type; blkid_probe pr = NULL; int ret; - struct stat statbuf; + int fd; + long long size; + int bsz; if (!device || !*device) return 0; ret = -1; /* will reset on success of all setup calls */ - if (stat(device, &statbuf) < 0) + fd = open(device, O_RDONLY); + if (fd < 0) goto out; + platform_findsizes(device, fd, &size, &bsz); + close(fd); /* nothing to overwrite on a 0-length device */ - if (statbuf.st_size == 0) { + if (size == 0) { ret = 0; goto out; }