[PATCH V2] mkfs: don't try to detect filesystems on regular files via blkid

Eric Sandeen sandeen at sandeen.net
Thu Feb 4 11:48:47 CST 2010


from RH bug 
https://bugzilla.redhat.com/show_bug.cgi?id=561870

# dd if=/dev/zero of=k bs=1MB count=2 seek=20; mkfs.xfs k 
# mkfs.xfs: probe of k failed, cannot detect existing filesystem.
# mkfs.xfs: Use the -f option to force overwrite.

blkid fails to do a probe of a regular file.

I wish blkid would cope with this, but for now it might
be better to just turn it off.

I kept the size==0 check just in case we stumble on a 0-sized
device, blkid doesn't like that either...

Reported-by: Jim Meyering <meyering at redhat.com>
Signed-off-by: Eric Sandeen <sandeen at redhat.com>
---

V2: use fstat after the open

diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 9baf116..219c81e 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -300,6 +300,7 @@ check_overwrite(
 	int		fd;
 	long long	size;
 	int		bsz;
+	struct stat	statbuf;
 
 	if (!device || !*device)
 		return 0;
@@ -309,6 +310,14 @@ check_overwrite(
 	fd = open(device, O_RDONLY);
 	if (fd < 0)
 		goto out;
+
+	/* blkid can't get info from a regular file */
+	if (!fstat(fd, &statbuf) && S_ISREG(statbuf.st_mode)) {
+		close(fd);
+		ret = 0;
+		goto out;
+	}
+
 	platform_findsizes(device, fd, &size, &bsz);
 	close(fd);
 





More information about the xfs mailing list