Debian Bug report logs - #115084
mkswap: should check whether the specified device contains a mounted filesystem

version graph

Package: util-linux; Maintainer for util-linux is LaMont Jones <lamont@debian.org>; Source for util-linux is src:util-linux.

Reported by: Matt Zimmerman <mdz@debian.org>

Date: Wed, 10 Oct 2001 00:03:01 UTC

Severity: wishlist

Tags: patch, upstream, wontfix

Found in version 2.11h-1

Reply or subscribe to this bug.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Adrian Bunk <bunk@fs.tum.de>:
Bug#115084; Package util-linux. Full text and rfc822 format available.

Acknowledgement sent to Matt Zimmerman <mdz@debian.org>:
New Bug report received and forwarded. Copy sent to Adrian Bunk <bunk@fs.tum.de>. Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: Matt Zimmerman <mdz@debian.org>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: mkswap: should check whether the specified device contains a mounted filesystem
Date: Tue, 9 Oct 2001 19:53:10 -0400
Package: util-linux
Version: 2.11h-1
Severity: wishlist

Someone on a mailing list reported being bitten this way, and since
mkswap already does some other safety checks (e.g., the partition table
check), it doesn't seem unreasonable to expect it to perform this one as
well.  I'll try to put a patch together if I have the time.

-- System Information
Debian Release: unstable
Architecture: i386
Kernel: Linux mizar 2.4.9 #1 Tue Sep 18 01:23:10 EDT 2001 i686
Locale: LANG=en_US, LC_CTYPE=

Versions of packages util-linux depends on:
ii  libc6                     2.2.4-3        GNU C Library: Shared libraries an
ii  libncurses5               5.2.20010318-3 Shared libraries for terminal hand
ii  slang1                    1.4.4-4        The S-Lang programming library - r

-- 
 - mdz



Information forwarded to debian-bugs-dist@lists.debian.org, Adrian Bunk <bunk@fs.tum.de>:
Bug#115084; Package util-linux. Full text and rfc822 format available.

Acknowledgement sent to Matt Zimmerman <mdz@debian.org>:
Extra info received and forwarded to list. Copy sent to Adrian Bunk <bunk@fs.tum.de>. Full text and rfc822 format available.

Message #10 received at 115084@bugs.debian.org (full text, mbox):

From: Matt Zimmerman <mdz@debian.org>
To: 115084@bugs.debian.org
Subject: Patch
Date: Tue, 9 Oct 2001 20:21:33 -0400
[Message part 1 (text/plain, inline)]
tags 115084 patch
thanks

Here is a patch to add this functionality.  It assumes that <paths.h>
and <mntent.h> are available, but I think they always are on Linux.

-- 
 - mdz
[mkswap-mounted.diff (text/plain, attachment)]

Tags added: patch Request was from Matt Zimmerman <mdz@debian.org> to control@bugs.debian.org. Full text and rfc822 format available.

Noted your statement that Bug has been forwarded to util-linux@math.uio.no. Request was from Adrian Bunk <bunk@fs.tum.de> to control@bugs.debian.org. Full text and rfc822 format available.

Acknowledgement sent to Adrian Bunk <bunk@fs.tum.de>:
Extra info received and filed, but not forwarded. Full text and rfc822 format available.

Message #17 received at 115084-quiet@bugs.debian.org (full text, mbox):

From: Adrian Bunk <bunk@fs.tum.de>
To: util-linux@math.uio.no
Cc: 115084-quiet@bugs.debian.org
Subject: [patch] mkswap should check whether the specified device contains a mounted filesystem
Date: Sat, 20 Oct 2001 03:25:23 +0200 (CEST)
Hi Andries,

Matt Zimmerman <mdz@debian.org> sent the patch below with the following
comment:

<--  snip  -->

Someone on a mailing list reported being bitten this way, and since
mkswap already does some other safety checks (e.g., the partition table
check), it doesn't seem unreasonable to expect it to perform this one as
well.

<--  snip  -->


--- util-linux-2.11l.orig/disk-utils/mkswap.c
+++ util-linux-2.11l/disk-utils/mkswap.c
@@ -39,6 +39,8 @@
 #include <sys/ioctl.h>		/* for _IO */
 #include <sys/utsname.h>
 #include <sys/stat.h>
+#include <mntent.h>
+#include <paths.h>
 #include "nls.h"

 /* Try to get PAGE_SIZE from libc or kernel includes */
@@ -589,6 +591,20 @@
 		}
 	}
 #endif
+	if (!force) {
+	  FILE *mtab;
+	  struct mntent *ent;
+
+	  if ((mtab = setmntent(_PATH_MOUNTED, "r")) != NULL) {
+	    while ((ent = getmntent(mtab)) != NULL)
+	      if (strcmp(device_name, ent->mnt_fsname) == 0) {
+		fprintf(stderr, _("\
+%s: Device '%s' appears to contain a mounted filesystem\n\
+No swap created.  Use the -f option to force swap creation.\n"), program_name, device_name);
+		exit(1);
+	      }
+	  }
+	}

 	if (version == 0 || check)
 		check_blocks();


cu
Adrian

--

Get my GPG key: finger bunk@debian.org | gpg --import

Fingerprint: B29C E71E FE19 6755 5C8A  84D4 99FC EA98 4F12 B400






Acknowledgement sent to Andries.Brouwer@cwi.nl:
Extra info received and filed, but not forwarded. Full text and rfc822 format available.

Message #20 received at 115084-quiet@bugs.debian.org (full text, mbox):

From: Andries.Brouwer@cwi.nl
To: bunk@fs.tum.de, util-linux@math.uio.no
Cc: 115084-quiet@bugs.debian.org
Subject: Re: [util-linux] [patch] mkswap should check whether the specified device contains a mounted filesystem
Date: Sat, 20 Oct 2001 06:52:32 GMT
> Someone on a mailing list reported being bitten this way

Yes, that is Unix. If you say "rm file" then it is gone.

> since mkswap already does some other safety checks
> (e.g., the partition table check)

That is deep knowledge (where the partition table lives,
which versions of swap space leave it, which versions destroy it).

"mkswap /dev/foo" on the other hand does not require any
specialist knowledge.

"Handholding" is a bad habit.

Not applied.
Andries



Information forwarded to debian-bugs-dist@lists.debian.org:
Bug#115084; Package util-linux. Full text and rfc822 format available.

Acknowledgement sent to Adrian Bunk <bunk@fs.tum.de>:
Extra info received and forwarded to list. Full text and rfc822 format available.

Message #25 received at 115084@bugs.debian.org (full text, mbox):

From: Adrian Bunk <bunk@fs.tum.de>
To: Matt Zimmerman <mdz@debian.org>
Cc: control@bugs.debian.org, <115084@bugs.debian.org>
Subject: Re: [util-linux] [patch] mkswap should check whether the specified device contains a mounted filesystem (fwd)
Date: Fri, 26 Oct 2001 14:10:10 +0200 (CEST)
tags 115084 + wontfix
thanks

Hi Matt,

below is the opinion of upstream regarding your patch. I'm sorry but I
won't include patches upstream rejects in the Debian package.

cu
Adrian


---------- Forwarded message ----------
Date: Sat, 20 Oct 2001 06:52:32 GMT
From: Andries.Brouwer@cwi.nl
To: bunk@fs.tum.de, util-linux@math.uio.no
Cc: 115084-quiet@bugs.debian.org
Subject: Re: [util-linux] [patch] mkswap should check whether the specified
    device contains a mounted filesystem

> Someone on a mailing list reported being bitten this way

Yes, that is Unix. If you say "rm file" then it is gone.

> since mkswap already does some other safety checks
> (e.g., the partition table check)

That is deep knowledge (where the partition table lives,
which versions of swap space leave it, which versions destroy it).

"mkswap /dev/foo" on the other hand does not require any
specialist knowledge.

"Handholding" is a bad habit.

Not applied.
Andries




Tags added: wontfix Request was from Adrian Bunk <bunk@fs.tum.de> to control@bugs.debian.org. Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Adrian Bunk <bunk@fs.tum.de>:
Bug#115084; Package util-linux. Full text and rfc822 format available.

Acknowledgement sent to Matt Zimmerman <mdz@debian.org>:
Extra info received and forwarded to list. Copy sent to Adrian Bunk <bunk@fs.tum.de>. Full text and rfc822 format available.

Message #32 received at 115084@bugs.debian.org (full text, mbox):

From: Matt Zimmerman <mdz@debian.org>
To: Andries.Brouwer@cwi.nl
Cc: 115084@bugs.debian.org
Subject: Re: [util-linux] [patch] mkswap should check whether the specified device contains a mounted filesystem (fwd)
Date: Fri, 26 Oct 2001 17:36:23 -0400
> ---------- Forwarded message ----------
> Date: Sat, 20 Oct 2001 06:52:32 GMT
> From: Andries.Brouwer@cwi.nl
> To: bunk@fs.tum.de, util-linux@math.uio.no
> Cc: 115084-quiet@bugs.debian.org
> Subject: Re: [util-linux] [patch] mkswap should check whether the specified
>     device contains a mounted filesystem
> 
> > Someone on a mailing list reported being bitten this way
> 
> Yes, that is Unix. If you say "rm file" then it is gone.

Yes, but if you say "rm <directory>", it won't unlink a directory and
leave its contents dangling.  Doing so would put the filesystem in an
inconsistent state, and such behavior would only be desirable in the
most extreme circumstances.  This situation is more analogous to
unlinking a non-empty directory than removing a file.

> "Handholding" is a bad habit.

In general, I agree.  However, scribbling all over a device which
contains a mounted filesystem is never desirable.  mkfs (both
util-linux(mkfs.minix) and e2fsprogs(mke2fs)) refuse to do this at all,
without even an option to override it.  Same goes for BSD newfs.

In nearly all cases, the user really does want to "rm file", and will
get what they want.  But, if a mounted filesystem is mkswap'ed, the
admin won't even be able to swap to the device because it is mounted,
and a crash could be caused by the now-corrupted filesystem.  Of what
possible utility could this be?

I consider this sanity checking, not handholding.

-- 
 - mdz



Removed annotation that Bug had been forwarded to util-linux@math.uio.no. Request was from Thomas Hood <jdthood@yahoo.co.uk> to control@bugs.debian.org. Full text and rfc822 format available.

Tags added: upstream Request was from Thomas Hood <jdthood@yahoo.co.uk> to control@bugs.debian.org. Full text and rfc822 format available.

Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Sat Apr 19 18:15:00 2014; Machine Name: buxtehude.debian.org

Debian Bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.