mkdosfs refuses to run on /dev/loop0p1

Bug #935480 reported by Phillip Susi
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
dosfstools (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

psusi@faldara:~$ sudo mkdosfs /dev/loop0p1
mkdosfs 3.0.9 (31 Jan 2010)
mkdosfs: Device partition expected, not making filesystem on entire device '/dev/loop0p1' (use -I to override)

Obviously this is wrong since loop0p1 IS a partition. Oddly, it does not complain on loop0p2.

Revision history for this message
Jan Claeys (janc) wrote :

This looks like the same bug we are seeing in GParted: https://bugzilla.gnome.org/show_bug.cgi?id=693955

This is caused by an incorrect test in mkdosfs whether a device is a "hard disk":

    if (fstat(dev, &statbuf) < 0)
        die("unable to stat %s");
    if (!S_ISBLK(statbuf.st_mode)) {
        statbuf.st_rdev = 0;
        check = 0;
    } else
        /*
         * Ignore any 'full' fixed disk devices, if -I is not given.
         * On a MO-disk one doesn't need partitions. The filesytem can go
         * directly to the whole disk. Under other OSes this is known as
         * the 'superfloppy' format. As I don't know how to find out if
         * this is a MO disk I introduce a -I (ignore) switch. -Joey
         */
        if (!ignore_full_disk && ((statbuf.st_rdev & 0xff3f) == 0x0300 || /* hda, hdb */
                                  (statbuf.st_rdev & 0xff0f) == 0x0800 || /* sd */
                                  (statbuf.st_rdev & 0xff3f) == 0x0d00 || /* xd */
                                  (statbuf.st_rdev & 0xff3f) == 0x1600) /* hdc, hdd */
        )
        die("Device partition expected, not making filesystem on entire device '%s' (use -I to override)");

It makes certain apparently incorrect assumptions about how raw device numbers for full disks vs. partitions look like.
(It also doesn't use major()/minor() on the raw device number, which looks not very portable or future-proof to me...)

Revision history for this message
Phillip Susi (psusi) wrote :

I guess I forgot to update this bug report. I found that a while back and sent off a patch to the upstream maintainer but have not heard back.

Revision history for this message
Jan Claeys (janc) wrote :

At least GParted will have the "-I" option workaround in the next version.

Did your patch remove the check or fix it? (Is there a future-proof way to fix it?)

Revision history for this message
Phillip Susi (psusi) wrote :

I didn't even think about the major/minor part, I just suggested adding another leading 0xf to the masks.

Personally I think the whole check for full disk is brain damaged and should be removed.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in dosfstools (Ubuntu):
status: New → Confirmed
Revision history for this message
Jan Claeys (janc) wrote :
Revision history for this message
Jan Claeys (janc) wrote :

I think the idea of such a safety check for interactive use isn't brain damaged, but in reality there is (or seems to be) no correct way to do this check, and even more so if you also consider other OS than linux, so I agree the only sensible thing to do is to remove it.

Revision history for this message
Phillip Susi (psusi) wrote :

Yea, that's pretty much what I came up with before the new year and I sent it off to the maintainer, but never got a reply.

I don't think this kind of safety check and prompt is unix like in character. It isn't the job of tools to second guess the admin and try to stop you from shooting yourself in the foot. This is why rm -rf / doesn't stop and warn you, even though doing this is monumentally stupid, and why none of the other mkfs tools try to do this.

Usually tools that try to do this sort of thing at least have the good sense to first check if stdin is connected to a tty, and skip the prompt if it isn't.

Revision history for this message
Jan Claeys (janc) wrote :

Actually, on modern unix systems "rm -rf /" will refuse to delete anything (unless you add a special option, like " --no-preserve-root" in GNU rm).

This follows POSIX.1-2008/SUSv4[1]:

| The rm utility shall remove the directory entry specified by each file argument.
|
| If [...] or if an operand resolves to the root directory, rm shall write a diagnostic
| message to standard error and do nothing more with such operands.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/rm.html

Revision history for this message
Phillip Susi (psusi) wrote :

GAH! What is the world coming to?

Revision history for this message
Jan Claeys (janc) wrote :
Revision history for this message
Pali (pali) wrote :

This issue should be already fixed.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.