[Top] [All Lists]

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

To: Eric Sandeen <sandeen@xxxxxxxxxx>
Subject: [PATCH V2] mkfs: don't try to detect filesystems on regular files via blkid
From: Eric Sandeen <sandeen@xxxxxxxxxxx>
Date: Thu, 04 Feb 2010 11:48:47 -0600
Cc: xfs mailing list <xfs@xxxxxxxxxxx>, Jim Meyering <meyering@xxxxxxxxxx>
In-reply-to: <4B6AF6FC.6030101@xxxxxxxxxx>
References: <4B6AF6FC.6030101@xxxxxxxxxx>
User-agent: Thunderbird (X11/20090320)
from RH bug 

# 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@xxxxxxxxxx>
Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>

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);

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