diff options
-rw-r--r-- | nfs/main.c | 64 |
1 files changed, 63 insertions, 1 deletions
@@ -28,6 +28,7 @@ #include <string.h> #include <maptime.h> #include <argp.h> +#include <argz.h> #define DEFAULT_SOFT_RETRIES 3 /* times */ #define DEFAULT_STAT_TIMEOUT 3 /* seconds */ @@ -147,6 +148,67 @@ static char *args_doc = "REMOTE_FS [HOST]"; static char *doc = "If HOST is not specified, an attempt is made to extract" " it from REMOTE_FS, using either the `HOST:FS' or `FS@HOST' notations."; +/* Called when the the filesystem receives a set-options request. ARGC and + ARGV are the arguments given, and STANDARD_ARGP is a pointer to a struct + argp containing the info necessary to parse `standard' netfs runtime + options. The user may chain this onto the end of his own argp structure + and call argp_parse, or ignore it completely (or indeed, just call + argp_parse on it -- which is the behavior of the default implementation of + this function. EINVAL is returned if an unknown option is encountered. */ +error_t +netfs_parse_runtime_options (int argc, char **argv, + const struct argp *standard_argp) +{ + const struct argp *argp_parents[] = { standard_argp, 0 }; + struct argp argp = + { common_options, parse_common_opt, 0, 0, argp_parents }; + + return + argp_parse (&argp, argc, argv, + ARGP_NO_ERRS | ARGP_NO_HELP | ARGP_PARSE_ARGV0, + 0); +} + +/* Called when the the filesystem receives a get-options request. ARGZ & + ARGZ_LEN will contain information on `standard' netfs options; the user + may extend them (probably by using argz_add), or ignore them, in which + case case ARGZ should be freed, as it is malloced. The default + implementation simply leaves ARGZ & ARGZ_LEN unmodified and returns sucess + (0). */ +error_t +netfs_unparse_runtime_options (char **argz, size_t *argz_len) +{ + char buf[80]; + error_t err = 0; + +#define FOPT(fmt, arg) \ + do { \ + if (! err) \ + { \ + snprintf (buf, sizeof buf, fmt, arg); \ + err = argz_add (argz, argz_len, buf); \ + } \ + } while (0) + + if (mounted_soft) + FOPT ("--soft=%d", soft_retries); + else + err = argz_add (argz, argz_len, "--hard"); + + FOPT ("--read-size=%d", read_size); + FOPT ("--write-size=%d", write_size); + + FOPT ("--stat-timeout=%d", stat_timeout); + FOPT ("--cache-timeout=%d", cache_timeout); + FOPT ("--init-transmit-timeout=%d", initial_transmit_timeout); + FOPT ("--max-transmit-timeout=%d", max_transmit_timeout); + + if (err) + free (argz); + + return err; +} + /* Extract the host and remote filesystem names from SPEC, which should use either HOST:FS or FS@HOST notation. Returns the malloced storage into which both REMOTE_FS and HOST point, or 0 if SPEC is invalid. */ @@ -235,7 +297,7 @@ int main (int argc, char **argv) { struct argp common_argp = { common_options, parse_common_opt }; - const struct argp *argp_parents[] = { &common_argp, 0 }; + const struct argp *argp_parents[] = { &common_argp, netfs_startup_argp, 0 }; struct argp argp = { startup_options, parse_startup_opt, args_doc, doc, argp_parents }; mach_port_t bootstrap; |