xfs
[Top] [All Lists]

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

To: xfs mailing list <xfs@xxxxxxxxxxx>
Subject: [PATCH] mkfs: don't try to detect filesystems on regular files via blkid
From: Eric Sandeen <sandeen@xxxxxxxxxx>
Date: Thu, 04 Feb 2010 10:34:04 -0600
Cc: Jim Meyering <meyering@xxxxxxxxxx>
User-agent: Thunderbird 2.0.0.21 (X11/20090320)
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.

Reported-by: Jim Meyering <meyering@xxxxxxxxxx>
Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
---

diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 9baf116..de87647 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -300,10 +300,15 @@ check_overwrite(
        int             fd;
        long long       size;
        int             bsz;
+       struct stat     statbuf;
 
        if (!device || !*device)
                return 0;
 
+       /* blkid can't get info from a regular file */
+       if (!stat(device, &statbuf) && S_ISREG(statbuf.st_mode))
+               return 0;
+
        ret = -1; /* will reset on success of all setup calls */
 
        fd = open(device, O_RDONLY);

<Prev in Thread] Current Thread [Next in Thread>