public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] mkswap: use is_mounted() instead of check_mount()
@ 2012-05-13 11:44 Petr Uzel
  2012-05-13 11:44 ` [PATCH 2/3] mkswap: allow creating swap on /dev/hd[ab] Petr Uzel
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Petr Uzel @ 2012-05-13 11:44 UTC (permalink / raw)
  To: util-linux


Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
 disk-utils/Makefile.am |    1 +
 disk-utils/mkswap.c    |   26 ++------------------------
 2 files changed, 3 insertions(+), 24 deletions(-)

diff --git a/disk-utils/Makefile.am b/disk-utils/Makefile.am
index 09dfa99..ecff70e 100644
--- a/disk-utils/Makefile.am
+++ b/disk-utils/Makefile.am
@@ -47,6 +47,7 @@ swaplabel_CFLAGS = $(AM_CFLAGS) $(uuid_cflags)
 
 mkswap_SOURCES = \
 	mkswap.c \
+	$(top_srcdir)/lib/ismounted.c \
 	$(top_srcdir)/lib/strutils.c \
 	$(top_srcdir)/lib/wholedisk.c \
 	$(utils_common)
diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
index 51a0c89..c7dedd7 100644
--- a/disk-utils/mkswap.c
+++ b/disk-utils/mkswap.c
@@ -58,6 +58,7 @@
 #include "xalloc.h"
 #include "c.h"
 #include "closestream.h"
+#include "ismounted.h"
 
 #ifdef HAVE_LIBUUID
 # include <uuid.h>
@@ -348,29 +349,6 @@ get_size(const char *file)
 	return size;
 }
 
-/*
- * Check to make certain that our new filesystem won't be created on
- * an already mounted partition.  Code adapted from mke2fs, Copyright
- * (C) 1994 Theodore Ts'o.  Also licensed under GPL.
- * (C) 2006 Karel Zak -- port to mkswap
- */
-static int
-check_mount(void)
-{
-	FILE *f;
-	struct mntent *mnt;
-
-	if ((f = setmntent (_PATH_MOUNTED, "r")) == NULL)
-		return 0;
-	while ((mnt = getmntent (f)) != NULL)
-		if (strcmp (device_name, mnt->mnt_fsname) == 0)
-			break;
-	endmntent (f);
-	if (!mnt)
-		return 0;
-	return 1;
-}
-
 #ifdef HAVE_LIBBLKID
 static blkid_probe
 new_prober(int fd)
@@ -625,7 +603,7 @@ main(int argc, char **argv) {
 		errx(EXIT_FAILURE, _("error: "
 			"will not try to make swapdevice on '%s'"),
 			device_name);
-	else if (check_mount())
+	else if (is_mounted(device_name))
 		errx(EXIT_FAILURE, _("error: "
 			"%s is mounted; will not make swapspace."),
 			device_name);
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] mkswap: allow creating swap on /dev/hd[ab]
  2012-05-13 11:44 [PATCH 1/3] mkswap: use is_mounted() instead of check_mount() Petr Uzel
@ 2012-05-13 11:44 ` Petr Uzel
  2012-05-13 13:38   ` Russell Coker
  2012-05-15  9:23   ` Karel Zak
  2012-05-13 11:44 ` [PATCH 3/3] mkswap: improve diagnostics message if the device is mounted Petr Uzel
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 8+ messages in thread
From: Petr Uzel @ 2012-05-13 11:44 UTC (permalink / raw)
  To: util-linux; +Cc: Russell Coker

Currently, mkswap does not allow swap to be created on /dev/hda and
/dev/hdb. There is no reason why /dev/hda and /dev/hdb should be treated
differently.

Addresses: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=491021
Cc: Russell Coker <russell@coker.com.au>
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
 disk-utils/mkswap.c |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)

diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
index c7dedd7..dec34e1 100644
--- a/disk-utils/mkswap.c
+++ b/disk-utils/mkswap.c
@@ -596,13 +596,8 @@ main(int argc, char **argv) {
 		exit(EXIT_FAILURE);
 	}
 
-	/* Want a block device. Probably not /dev/hda or /dev/hdb. */
 	if (!S_ISBLK(statbuf.st_mode))
 		check=0;
-	else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
-		errx(EXIT_FAILURE, _("error: "
-			"will not try to make swapdevice on '%s'"),
-			device_name);
 	else if (is_mounted(device_name))
 		errx(EXIT_FAILURE, _("error: "
 			"%s is mounted; will not make swapspace."),
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] mkswap: improve diagnostics message if the device is mounted
  2012-05-13 11:44 [PATCH 1/3] mkswap: use is_mounted() instead of check_mount() Petr Uzel
  2012-05-13 11:44 ` [PATCH 2/3] mkswap: allow creating swap on /dev/hd[ab] Petr Uzel
@ 2012-05-13 11:44 ` Petr Uzel
  2012-05-15  9:23   ` Karel Zak
  2012-05-15  9:21 ` [PATCH 1/3] mkswap: use is_mounted() instead of check_mount() Karel Zak
  2012-05-15  9:22 ` Karel Zak
  3 siblings, 1 reply; 8+ messages in thread
From: Petr Uzel @ 2012-05-13 11:44 UTC (permalink / raw)
  To: util-linux

Currently, attempt to create swap on mounted partition results
with "/dev/sdXy: Device or resource busy" message being printed.
Change this to explicitly telling the user that the device is mounted.

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
 disk-utils/mkswap.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
index dec34e1..43129a7 100644
--- a/disk-utils/mkswap.c
+++ b/disk-utils/mkswap.c
@@ -582,6 +582,11 @@ main(int argc, char **argv) {
 			PAGES * pagesize / 1024);
 	}
 
+	if (is_mounted(device_name))
+		errx(EXIT_FAILURE, _("error: "
+			"%s is mounted; will not make swapspace."),
+			device_name);
+
 	if (stat(device_name, &statbuf) < 0) {
 		perror(device_name);
 		exit(EXIT_FAILURE);
@@ -598,10 +603,6 @@ main(int argc, char **argv) {
 
 	if (!S_ISBLK(statbuf.st_mode))
 		check=0;
-	else if (is_mounted(device_name))
-		errx(EXIT_FAILURE, _("error: "
-			"%s is mounted; will not make swapspace."),
-			device_name);
 	else if (blkdev_is_misaligned(DEV))
 		warnx(_("warning: %s is misaligned"), device_name);
 
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] mkswap: allow creating swap on /dev/hd[ab]
  2012-05-13 11:44 ` [PATCH 2/3] mkswap: allow creating swap on /dev/hd[ab] Petr Uzel
@ 2012-05-13 13:38   ` Russell Coker
  2012-05-15  9:23   ` Karel Zak
  1 sibling, 0 replies; 8+ messages in thread
From: Russell Coker @ 2012-05-13 13:38 UTC (permalink / raw)
  To: Petr Uzel; +Cc: util-linux, 491021

The patch looks good.  Although as /dev/hda seems to be unused it probably 
won't affect anyone.  It would be nice to get this Debian bug closed before it 
turns 4.

On Sun, 13 May 2012, Petr Uzel <petr.uzel@suse.cz> wrote:
> Currently, mkswap does not allow swap to be created on /dev/hda and
> /dev/hdb. There is no reason why /dev/hda and /dev/hdb should be treated
> differently.
> 
> Addresses: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=491021
> Cc: Russell Coker <russell@coker.com.au>
> Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
> ---
>  disk-utils/mkswap.c |    5 -----
>  1 files changed, 0 insertions(+), 5 deletions(-)
> 
> diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
> index c7dedd7..dec34e1 100644
> --- a/disk-utils/mkswap.c
> +++ b/disk-utils/mkswap.c
> @@ -596,13 +596,8 @@ main(int argc, char **argv) {
>  		exit(EXIT_FAILURE);
>  	}
> 
> -	/* Want a block device. Probably not /dev/hda or /dev/hdb. */
>  	if (!S_ISBLK(statbuf.st_mode))
>  		check=0;
> -	else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
> -		errx(EXIT_FAILURE, _("error: "
> -			"will not try to make swapdevice on '%s'"),
> -			device_name);
>  	else if (is_mounted(device_name))
>  		errx(EXIT_FAILURE, _("error: "
>  			"%s is mounted; will not make swapspace."),


-- 
My Main Blog         http://etbe.coker.com.au/
My Documents Blog    http://doc.coker.com.au/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] mkswap: use is_mounted() instead of check_mount()
  2012-05-13 11:44 [PATCH 1/3] mkswap: use is_mounted() instead of check_mount() Petr Uzel
  2012-05-13 11:44 ` [PATCH 2/3] mkswap: allow creating swap on /dev/hd[ab] Petr Uzel
  2012-05-13 11:44 ` [PATCH 3/3] mkswap: improve diagnostics message if the device is mounted Petr Uzel
@ 2012-05-15  9:21 ` Karel Zak
  2012-05-15  9:22 ` Karel Zak
  3 siblings, 0 replies; 8+ messages in thread
From: Karel Zak @ 2012-05-15  9:21 UTC (permalink / raw)
  To: Petr Uzel; +Cc: util-linux

On Sun, May 13, 2012 at 01:44:30PM +0200, Petr Uzel wrote:
>  disk-utils/Makefile.am |    1 +
>  disk-utils/mkswap.c    |   26 ++------------------------
>  2 files changed, 3 insertions(+), 24 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] mkswap: use is_mounted() instead of check_mount()
  2012-05-13 11:44 [PATCH 1/3] mkswap: use is_mounted() instead of check_mount() Petr Uzel
                   ` (2 preceding siblings ...)
  2012-05-15  9:21 ` [PATCH 1/3] mkswap: use is_mounted() instead of check_mount() Karel Zak
@ 2012-05-15  9:22 ` Karel Zak
  3 siblings, 0 replies; 8+ messages in thread
From: Karel Zak @ 2012-05-15  9:22 UTC (permalink / raw)
  To: Petr Uzel; +Cc: util-linux

On Sun, May 13, 2012 at 01:44:30PM +0200, Petr Uzel wrote:
>  disk-utils/Makefile.am |    1 +
>  disk-utils/mkswap.c    |   26 ++------------------------
>  2 files changed, 3 insertions(+), 24 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] mkswap: allow creating swap on /dev/hd[ab]
  2012-05-13 11:44 ` [PATCH 2/3] mkswap: allow creating swap on /dev/hd[ab] Petr Uzel
  2012-05-13 13:38   ` Russell Coker
@ 2012-05-15  9:23   ` Karel Zak
  1 sibling, 0 replies; 8+ messages in thread
From: Karel Zak @ 2012-05-15  9:23 UTC (permalink / raw)
  To: Petr Uzel; +Cc: util-linux, Russell Coker

On Sun, May 13, 2012 at 01:44:31PM +0200, Petr Uzel wrote:
>  disk-utils/mkswap.c |    5 -----
>  1 files changed, 0 insertions(+), 5 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] mkswap: improve diagnostics message if the device is mounted
  2012-05-13 11:44 ` [PATCH 3/3] mkswap: improve diagnostics message if the device is mounted Petr Uzel
@ 2012-05-15  9:23   ` Karel Zak
  0 siblings, 0 replies; 8+ messages in thread
From: Karel Zak @ 2012-05-15  9:23 UTC (permalink / raw)
  To: Petr Uzel; +Cc: util-linux

On Sun, May 13, 2012 at 01:44:32PM +0200, Petr Uzel wrote:
>  disk-utils/mkswap.c |    9 +++++----
>  1 files changed, 5 insertions(+), 4 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-05-15  9:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-13 11:44 [PATCH 1/3] mkswap: use is_mounted() instead of check_mount() Petr Uzel
2012-05-13 11:44 ` [PATCH 2/3] mkswap: allow creating swap on /dev/hd[ab] Petr Uzel
2012-05-13 13:38   ` Russell Coker
2012-05-15  9:23   ` Karel Zak
2012-05-13 11:44 ` [PATCH 3/3] mkswap: improve diagnostics message if the device is mounted Petr Uzel
2012-05-15  9:23   ` Karel Zak
2012-05-15  9:21 ` [PATCH 1/3] mkswap: use is_mounted() instead of check_mount() Karel Zak
2012-05-15  9:22 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox