>From 5f0ae10564d3f9fe6b0fefd8766d118c3c1b880b Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov <unlimitedscol...@gmail.com> Date: Sun, 5 Jul 2009 22:39:09 +0300 Subject: [PATCH] Add the ``--mount'' command line option.
* Makefile (OBJS): Add mount.o * options.h (OPT_MOUNT, OPT_LONG_MOUNT): Define. * options.c (argp_common_options): Add option ``-mount''. (argp_parse_common_options): Handle the new option. * netfs.c (netfs_append_args): Add the ``--mount'' option to the result. * mount.h: New file. * mount.c: Likewise. --- Makefile | 4 +++- mount.c | 29 +++++++++++++++++++++++++++++ mount.h | 32 ++++++++++++++++++++++++++++++++ netfs.c | 28 +++++++++++++++++++++++++++- options.c | 19 +++++++++++++++++++ options.h | 7 ++++++- 6 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 mount.c create mode 100644 mount.h diff --git a/Makefile b/Makefile index 7ef2100..a6d579b 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ # Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. # # Written by Jeroen Dekkers <jer...@dekkers.cx>. +# +# Adapted for unionmount by Sergiu Ivanov <unlimitedscol...@gmail.com>. # # 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 @@ -27,7 +29,7 @@ CFLAGS += -Wall -g -O2 -D_FILE_OFFSET_BITS=64 -std=gnu99 \ LDFLAGS += -lnetfs -lfshelp -liohelp -lthreads \ -lports -lihash -lshouldbeinlibc -lhurdbugaddr OBJS = main.o node.o lnode.o ulfs.o ncache.o netfs.o \ - lib.o options.o pattern.o stow.o update.o + lib.o options.o pattern.o stow.o update.o mount.o MIGCOMSFLAGS = -prefix stow_ fs_notify-MIGSFLAGS = -imacros ./stow-mutations.h diff --git a/mount.c b/mount.c new file mode 100644 index 0000000..7bc1fb8 --- /dev/null +++ b/mount.c @@ -0,0 +1,29 @@ +/* Hurd unionmount + The core of unionmount functionality. + + Copyright (C) 2009 Free Software Foundation, Inc. + + Written by Sergiu Ivanov <unlimitedscol...@gmail.com>. + + 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 will 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#define _GNU_SOURCE + +#include "mount.h" + +/* The command line for starting the mountee. */ +char * mountee_argz; +size_t mountee_argz_len; diff --git a/mount.h b/mount.h new file mode 100644 index 0000000..a7dd933 --- /dev/null +++ b/mount.h @@ -0,0 +1,32 @@ +/* Hurd unionmount + General information and properties for unionmount/unionfs. + + Copyright (C) 2009 Free Software Foundation, Inc. + + Written by Sergiu Ivanov <unlimitedscol...@gmail.com>. + + 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 will 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#ifndef INCLUDED_MOUNT_H +#define INCLUDED_MOUNT_H + +#include <unistd.h> + +/* The command line for starting the mountee. */ +extern char * mountee_argz; +extern size_t mountee_argz_len; + +#endif /* not INCLUDED_MOUNT_H */ diff --git a/netfs.c b/netfs.c index 89d1bf6..5549365 100644 --- a/netfs.c +++ b/netfs.c @@ -1,7 +1,11 @@ /* Hurd unionfs - Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2003, 2005, 2009 + Free Software Foundation, Inc. + Written by Moritz Schulte <mor...@duesseldorf.ccc.de>. + Adapted for unionmount by Sergiu Ivanov <unlimitedscol...@gmail.com>. + 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 @@ -36,6 +40,7 @@ #include "lib.h" #include "ncache.h" #include "options.h" +#include "mount.h" /* Return an argz string describing the current options. Fill *ARGZ with a pointer to newly malloced storage holding the list and *LEN @@ -45,6 +50,27 @@ netfs_append_args (char **argz, size_t *argz_len) { error_t err = 0; + /* Add the --mount option to the result. */ + if (mountee_argz) + { + /* The string describing the value of the ``--mount'' option. */ + char * opt = NULL; + + /* The mountee command line converted to a 0-terminated string + form. */ + char * mountee_cl = malloc (mountee_argz_len); + if (!mountee_cl) + return ENOMEM; + + memcpy (mountee_cl, mountee_argz, mountee_argz_len); + argz_stringify (mountee_cl, mountee_argz_len, ' '); + + if (asprintf (&opt, "%s=\"%s\"", OPT_LONG (OPT_LONG_MOUNT), mountee_cl) == -1) + return ENOMEM; + + err = argz_add (argz, argz_len, opt); + } + ulfs_iterate { if (! err) diff --git a/options.c b/options.c index 2d3a11f..e2e5dcd 100644 --- a/options.c +++ b/options.c @@ -1,7 +1,10 @@ /* Hurd unionfs Copyright (C) 2001, 2002, 2005, 2009 Free Software Foundation, Inc. + Written by Moritz Schulte <mor...@duesseldorf.ccc.de>. + Adapted for unionmount by Sergiu Ivanov <unlimitedscol...@gmail.com>. + 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 @@ -23,6 +26,7 @@ #include <argp.h> #include <error.h> +#include <argz.h> #include "options.h" #include "ulfs.h" @@ -33,6 +37,7 @@ #include "pattern.h" #include "stow.h" #include "update.h" +#include "mount.h" /* This variable is set to a non-zero value after parsing of the startup options. Whenever the argument parser is later called to @@ -51,6 +56,9 @@ static const struct argp_option argp_common_options[] = "send debugging messages to stderr" }, { OPT_LONG_CACHE_SIZE, OPT_CACHE_SIZE, "SIZE", 0, "specify the maximum number of nodes in the cache" }, + { OPT_LONG_MOUNT, OPT_MOUNT, "MOUNTEE", 0, + "use MOUNTEE as translator command line, start the translator," + "and add its filesystem"}, { 0, 0, 0, 0, "Runtime options:", 1 }, { OPT_LONG_STOW, OPT_STOW, "STOWDIR", 0, "stow given directory", 1}, @@ -124,6 +132,17 @@ argp_parse_common_options (int key, char *arg, struct argp_state *state) ulfs_match = 0; break; + case OPT_MOUNT: + if (mountee_argz) + error (EXIT_FAILURE, err, "You can specify only one %s option.", + OPT_LONG (OPT_LONG_MOUNT)); + + /* TODO: Improve the mountee command line parsing mechanism. */ + err = argz_create_sep (arg, ' ', &mountee_argz, &mountee_argz_len); + if (err) + error (EXIT_FAILURE, err, "argz_create_sep"); + break; + case OPT_UNDERLYING: /* --underlying */ case ARGP_KEY_ARG: diff --git a/options.h b/options.h index eb74ce6..95a6ddb 100644 --- a/options.h +++ b/options.h @@ -1,7 +1,10 @@ /* Hurd unionfs - Copyright (C) 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2009 Free Software Foundation, Inc. + Written by Moritz Schulte <mor...@duesseldorf.ccc.de>. + Adapted for unionmount by Sergiu Ivanov <unlimitedscol...@gmail.com>. + 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 @@ -29,6 +32,7 @@ #define OPT_PATTERN 'm' #define OPT_PRIORITY 'p' #define OPT_STOW 's' +#define OPT_MOUNT 't' /* The long options. */ #define OPT_LONG_UNDERLYING "underlying" @@ -40,6 +44,7 @@ #define OPT_LONG_PATTERN "match" #define OPT_LONG_PRIORITY "priority" #define OPT_LONG_STOW "stow" +#define OPT_LONG_MOUNT "mount" #define OPT_LONG(o) "--" o -- 1.6.3.3