From ecdba5ddfc99815181db1e5d571ea8e2b806c0f9 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 11 Jan 2012 17:05:08 +0100 Subject: build-sys: add --enable-new-mount Now we have three versions of the mount(8) utility * old mount(8) --enable-mount [default] * old mount(8) linked with libmount This is this is necessary for systems without mtab file. --enable-libmount-mount - new mount(8) This is completely new pure-libmount based mount(8). --enable-new-mount Signed-off-by: Karel Zak --- configure.ac | 15 +- libmount/Makefile.am | 2 +- libmount/samples/.gitignore | 2 - libmount/samples/Makefile.am | 14 - libmount/samples/mount.c | 543 -------------------------------- libmount/samples/umount.c | 286 ----------------- sys-utils/.gitignore | 2 + sys-utils/Makefile.am | 29 ++ sys-utils/mount.c | 543 ++++++++++++++++++++++++++++++++ sys-utils/umount.c | 286 +++++++++++++++++ tools/config-gen.d/devel-new-mount.conf | 8 + 11 files changed, 882 insertions(+), 848 deletions(-) delete mode 100644 libmount/samples/.gitignore delete mode 100644 libmount/samples/Makefile.am delete mode 100644 libmount/samples/mount.c delete mode 100644 libmount/samples/umount.c create mode 100644 sys-utils/mount.c create mode 100644 sys-utils/umount.c create mode 100644 tools/config-gen.d/devel-new-mount.conf diff --git a/configure.ac b/configure.ac index e30c8df33..8af42e435 100644 --- a/configure.ac +++ b/configure.ac @@ -697,7 +697,7 @@ AM_CONDITIONAL(BUILD_LOSETUP, test "x$build_losetup" = xyes) AC_ARG_ENABLE([libmount-mount], - AS_HELP_STRING([--enable-libmount-mount], [link mount(8) with libmount (EXPERIMENTAL)]), + AS_HELP_STRING([--enable-libmount-mount], [link old mount(8) with libmount]), [], enable_libmount_mount=no ) UL_BUILD_INIT([libmount_mount]) @@ -709,6 +709,18 @@ fi AM_CONDITIONAL(BUILD_LIBMOUNT_MOUNT, test "x$build_libmount_mount" = xyes) +AC_ARG_ENABLE([new-mount], + AS_HELP_STRING([--enable-new-mount], [build new pure libmount based mount(8) (EXPERIMENTAL)]), + [], enable_new_mount=no +) +UL_BUILD_INIT([new_mount]) +UL_REQUIRES_BUILD([new_mount], [libmount]) +if test "x$build_new_mount" = xyes; then + AM_CONDITIONAL(BUILD_MOUNT, [false]) +fi +AM_CONDITIONAL(BUILD_NEW_MOUNT, test "x$build_new_mount" = xyes) + + AC_ARG_ENABLE([fsck], AS_HELP_STRING([--disable-fsck], [do not build fsck]), [], enable_fsck=check @@ -1180,7 +1192,6 @@ libmount/src/Makefile libmount/src/libmount.h libmount/docs/Makefile libmount/docs/version.xml -libmount/samples/Makefile libuuid/uuid.pc libuuid/Makefile libuuid/man/Makefile diff --git a/libmount/Makefile.am b/libmount/Makefile.am index dbe131789..5f7ca4ca5 100644 --- a/libmount/Makefile.am +++ b/libmount/Makefile.am @@ -1,6 +1,6 @@ include $(top_srcdir)/config/include-Makefile.am -SUBDIRS = src samples +SUBDIRS = src if ENABLE_GTK_DOC SUBDIRS += docs diff --git a/libmount/samples/.gitignore b/libmount/samples/.gitignore deleted file mode 100644 index 33dbb1785..000000000 --- a/libmount/samples/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -mount -umount diff --git a/libmount/samples/Makefile.am b/libmount/samples/Makefile.am deleted file mode 100644 index a8c001f7d..000000000 --- a/libmount/samples/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -include $(top_srcdir)/config/include-Makefile.am - -AM_CPPFLAGS += -I$(ul_libmount_incdir) -AM_LDFLAGS += $(ul_libmount_la) - -noinst_PROGRAMS = mount umount - -mount_SOURCES = mount.c \ - $(top_srcdir)/lib/env.c \ - $(top_srcdir)/lib/xgetpass.c \ - $(top_srcdir)/lib/strutils.c - -umount_SOURCES = umount.c $(top_srcdir)/lib/env.c - diff --git a/libmount/samples/mount.c b/libmount/samples/mount.c deleted file mode 100644 index cdd70b8f6..000000000 --- a/libmount/samples/mount.c +++ /dev/null @@ -1,543 +0,0 @@ -/* - * mount(8) -- mount a filesystem - * - * Copyright (C) 2011 Red Hat, Inc. All rights reserved. - * Written by Karel Zak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it would be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "nls.h" -#include "c.h" -#include "env.h" -#include "optutils.h" -#include "strutils.h" -#include "xgetpass.h" - -/*** TODO: DOCS: - * - * --guess-fstype is unsupported - */ - -/* exit status */ -#define EX_SUCCESS 0 -#define EX_USAGE 1 /* incorrect invocation or permission */ -#define EX_SYSERR 2 /* out of memory, cannot fork, ... */ -#define EX_SOFTWARE 4 /* internal mount bug or wrong version */ -#define EX_USER 8 /* user interrupt */ -#define EX_FILEIO 16 /* problems writing, locking, ... mtab/fstab */ -#define EX_FAIL 32 /* mount failure */ -#define EX_SOMEOK 64 /* some mount succeeded */ - -static int passfd = -1; - -static void __attribute__((__noreturn__)) exit_non_root(const char *option) -{ - const uid_t ruid = getuid(); - const uid_t euid = geteuid(); - - if (ruid == 0 && euid != 0) { - /* user is root, but setuid to non-root */ - if (option) - errx(EX_USAGE, _("only root can use \"--%s\" option " - "(effective UID is %u)"), - option, euid); - errx(EX_USAGE, _("only root can do that " - "(effective UID is %u)"), euid); - } - if (option) - errx(EX_USAGE, _("only root can use \"--%s\" option"), option); - errx(EX_USAGE, _("only root can do that")); -} - -static void __attribute__((__noreturn__)) print_version(void) -{ - const char *ver = NULL; - - mnt_get_library_version(&ver); - - printf(_("%s from %s (libmount %s)\n"), - program_invocation_short_name, PACKAGE_STRING, ver); - exit(EX_SUCCESS); -} - -static int table_parser_errcb(struct libmnt_table *tb __attribute__((__unused__)), - const char *filename, int line) -{ - if (filename) - warnx(_("%s: parse error: ignore entry at line %d."), - filename, line); - return 0; -} - -static char *encrypt_pass_get(struct libmnt_context *cxt) -{ - if (!cxt) - return 0; - -#ifdef MCL_FUTURE - if (mlockall(MCL_CURRENT | MCL_FUTURE)) { - warn(_("couldn't lock into memory")); - return NULL; - } -#endif - return xgetpass(passfd, _("Password: ")); -} - -static void encrypt_pass_release(struct libmnt_context *cxt, char *pwd) -{ - char *p = pwd; - - while (p && *p) - *p++ = '\0'; - - free(pwd); - munlockall(); -} - -static void print_all(struct libmnt_context *cxt, char *pattern, int show_label) -{ - struct libmnt_table *tb; - struct libmnt_iter *itr = NULL; - struct libmnt_fs *fs; - struct libmnt_cache *cache = NULL; - - if (mnt_context_get_mtab(cxt, &tb)) - err(EX_SYSERR, _("failed to read mtab")); - - itr = mnt_new_iter(MNT_ITER_FORWARD); - if (!itr) - err(EX_SYSERR, _("failed to initialize libmount iterator")); - if (show_label) - cache = mnt_new_cache(); - - while (mnt_table_next_fs(tb, itr, &fs) == 0) { - const char *type = mnt_fs_get_fstype(fs); - const char *src = mnt_fs_get_source(fs); - const char *optstr = mnt_fs_get_options(fs); - char *xsrc; - - if (type && pattern && !mnt_match_fstype(type, pattern)) - continue; - - xsrc = mnt_pretty_path(src, cache); - printf ("%s on %s", xsrc, mnt_fs_get_target(fs)); - if (type) - printf (" type %s", type); - if (optstr) - printf (" (%s)", optstr); - if (show_label && src) { - char *lb = mnt_cache_find_tag_value(cache, src, "LABEL"); - if (lb) - printf (" [%s]", lb); - } - fputc('\n', stdout); - free(xsrc); - } - - mnt_free_cache(cache); - mnt_free_iter(itr); -} - -/* - * mount -a [-F] - */ -static int mount_all(struct libmnt_context *cxt) -{ - struct libmnt_iter *itr; - struct libmnt_fs *fs; - int mntrc, ignored, rc = EX_SUCCESS; - - itr = mnt_new_iter(MNT_ITER_FORWARD); - if (!itr) { - warn(_("failed to initialize libmount iterator")); - return EX_SYSERR; - } - - while (mnt_context_next_mount(cxt, itr, &fs, &mntrc, &ignored) == 0) { - - const char *tgt = mnt_fs_get_target(fs); - - if (ignored) { - if (mnt_context_is_verbose(cxt)) - printf(ignored == 1 ? _("%-25s: ignored\n") : - _("%-25s: already mounted\n"), - tgt); - - } else if (mnt_context_is_fork(cxt)) { - printf("%-25s: mount successfully forked\n", tgt); - - } else { - if (!mnt_context_get_status(cxt)) { - if (mntrc > 0) { - errno = mntrc; - printf(_("%-25s: failed: %s\n"), tgt, - strerror(mntrc)); - rc |= EX_FAIL; - } else { - printf(_("%-25s: failed\n"), tgt); - rc |= EX_SYSERR; - } - } else { - if (mnt_context_is_verbose(cxt)) - printf("%-25s: successfully mounted\n", tgt); - - rc |= EX_SOMEOK; - } - } - } - - if (mnt_context_is_parent(cxt)) { - /* wait for mount --fork children */ - int nerrs = 0, nchildren = 0; - - rc = mnt_context_wait_for_children(cxt, &nchildren, &nerrs); - if (!rc && nchildren) - rc = nchildren == nerrs ? EX_FAIL : EX_SOMEOK; - } - - return rc; -} - -static void __attribute__((__noreturn__)) usage(FILE *out) -{ - fputs(USAGE_HEADER, out); - fprintf(out, _( - " %1$s [-lhV]\n" - " %1$s -a [options]\n" - " %1$s [options] | \n" - " %1$s [options] \n" - " %1$s []\n"), - program_invocation_short_name); - - fputs(USAGE_OPTIONS, out); - fprintf(out, _( - " -a, --all mount all filesystems mentioned in fstab\n" - " -c, --no-canonicalize don't canonicalize paths\n" - " -f, --fake dry run; skip the mount(2) syscall\n" - " -F, --fork fork off for each device (use with -a)\n")); - fprintf(out, _( - " -h, --help display this help text and exit\n" - " -i, --internal-only don't call the mount. helpers\n" - " -l, --show-labels lists all mounts with LABELs\n" - " -n, --no-mtab don't write to /etc/mtab\n")); - fprintf(out, _( - " -o, --options comma-separated list of mount options\n" - " -O, --test-opts limit the set of filesystems (use with -a)\n" - " -p, --pass-fd read the passphrase from file descriptor\n" - " -r, --read-only mount the filesystem read-only (same as -o ro)\n" - " -t, --types limit the set of filesystem types\n")); - fprintf(out, _( - " -v, --verbose say what is being done\n" - " -V, --version display version information and exit\n" - " -w, --read-write mount the filesystem read-write (default)\n")); - - fputs(USAGE_SEPARATOR, out); - fputs(USAGE_HELP, out); - fputs(USAGE_VERSION, out); - - fprintf(out, _( - "\nSource:\n" - " -L, --label