diff options
author | Pino Toscano <toscano.pino@tiscali.it> | 2012-09-07 18:24:20 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2012-09-30 19:42:26 +0200 |
commit | b8b7940234ed7b06cb81f49210b165c47d44a1f1 (patch) | |
tree | 62b0ad0ed9fe5cde949f232f98ffcb091dbeea08 | |
parent | 0cf1f48d64813fa46d83442ade4c94958ad4300b (diff) |
tmpfs: add --size
Add the possibility to specify the size with the --size parameter;
this makes tmpfs more usable in fstab or Linuxish mount invocations,
since the size in such cases is a mount -o option, which gets translated
to a --foo translator argument.
The old way (specifying the size as the first argument) is left there;
although, if --size is passed then the first argument must be "tmpfs",
as it is what is passed by fstab/mount.
* tmpfs/tmpfs.c (OPT_SIZE): New macro.
(options): Add the "size" option.
(parse_opt): Use -1 to indicate when SIZE is not yet set.
<OPT_SIZE>: Handle case.
<ARGP_KEY_NO_ARGS>: Error out only when SIZE is not set.
<ARGP_KEY_ARGS>: Error out when SIZE is set and the argument is not "tmpfs".
-rw-r--r-- | tmpfs/tmpfs.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/tmpfs/tmpfs.c b/tmpfs/tmpfs.c index 2a98178a..83795289 100644 --- a/tmpfs/tmpfs.c +++ b/tmpfs/tmpfs.c @@ -100,9 +100,12 @@ diskfs_reload_global_state () int diskfs_synchronous = 0; +#define OPT_SIZE 600 /* --size */ + static const struct argp_option options[] = { {"mode", 'm', "MODE", 0, "Permissions (octal) for root directory"}, + {"size", OPT_SIZE, "MAX-BYTES", 0, "Maximum size"}, {NULL,} }; @@ -188,7 +191,7 @@ parse_opt (int key, char *arg, struct argp_state *state) if (values == 0) return ENOMEM; state->hook = values; - values->size = 0; + values->size = -1; values->mode = -1; break; case ARGP_KEY_FINI: @@ -214,9 +217,21 @@ parse_opt (int key, char *arg, struct argp_state *state) } break; + case OPT_SIZE: /* --size=MAX-BYTES */ + { + error_t err = parse_opt_size (arg, state, &values->size); + if (err) + return err; + } + break; + case ARGP_KEY_NO_ARGS: - argp_error (state, "must supply maximum size"); - return EINVAL; + if (values->size < 0) + { + argp_error (state, "must supply maximum size"); + return EINVAL; + } + break; case ARGP_KEY_ARGS: if (state->argv[state->next + 1] != 0) @@ -224,6 +239,14 @@ parse_opt (int key, char *arg, struct argp_state *state) argp_error (state, "too many arguments"); return EINVAL; } + else if (values->size >= 0) + { + if (strcmp (state->argv[state->next], "tmpfs") != 0) + { + argp_error (state, "size specified with --size and argument is not \"tmpfs\""); + return EINVAL; + } + } else { error_t err = parse_opt_size (state->argv[state->next], state, |