]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mkswap: use is_mounted() instead of check_mount()
authorPetr Uzel <petr.uzel@suse.cz>
Sun, 13 May 2012 11:44:30 +0000 (13:44 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 15 May 2012 09:19:52 +0000 (11:19 +0200)
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
disk-utils/Makefile.am
disk-utils/mkswap.c

index 09dfa994d13c41d061419cb1df2fe9b3a351cad5..ecff70e13587da9ad80cb5e016b8a55cc6ad9d03 100644 (file)
@@ -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)
index 51a0c890bd0791aaeed5248abb2362f017de25d0..c7dedd7c235ad4b18ae26e49b0874587560d043c 100644 (file)
@@ -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);