diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2009-09-29 10:36:19 -0400 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2009-09-29 10:36:19 -0400 |
commit | 88c4f664f869d7450b84f0262fd87fbda4f1f61b (patch) | |
tree | 7630ff360b1012b7fb7b84f7c341f8b44cc430a7 /utils | |
parent | 5f06c2b5e18990a2d62987ea06bdf5afb8306a2d (diff) | |
download | nfs-utils-88c4f664f869d7450b84f0262fd87fbda4f1f61b.tar.gz nfs-utils-88c4f664f869d7450b84f0262fd87fbda4f1f61b.tar.xz nfs-utils-88c4f664f869d7450b84f0262fd87fbda4f1f61b.zip |
mount.nfs: Add API to duplicate a mount option list
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'utils')
-rw-r--r-- | utils/mount/parse_opt.c | 65 | ||||
-rw-r--r-- | utils/mount/parse_opt.h | 1 |
2 files changed, 66 insertions, 0 deletions
diff --git a/utils/mount/parse_opt.c b/utils/mount/parse_opt.c index 1dfee8a..f0918f7 100644 --- a/utils/mount/parse_opt.c +++ b/utils/mount/parse_opt.c @@ -101,6 +101,37 @@ fail: return NULL; } +static struct mount_option *option_dup(const struct mount_option *option) +{ + struct mount_option *new; + + new = malloc(sizeof(*new)); + if (!new) + return NULL; + + new->next = NULL; + new->prev = NULL; + + new->keyword = strdup(option->keyword); + if (!new->keyword) + goto fail; + + new->value = NULL; + if (option->value) { + new->value = strdup(option->value); + if (!new->value) { + free(new->keyword); + goto fail; + } + } + + return new; + +fail: + free(new); + return NULL; +} + static void option_destroy(struct mount_option *option) { free(option->keyword); @@ -229,6 +260,40 @@ fail: } /** + * po_dup - duplicate an existing list of options + * @options: pointer to mount options + * + */ +struct mount_options *po_dup(struct mount_options *source) +{ + struct mount_options *target; + struct mount_option *current; + + if (!source) + return NULL; + + target = options_create(); + if (options_empty(source) || target == NULL) + return target; + + current = source->head; + while (target->count < source->count) { + struct mount_option *option; + + option = option_dup(current); + if (!option) { + po_destroy(target); + return NULL; + } + + options_tail_insert(target, option); + current = current->next; + } + + return target; +} + +/** * po_replace - replace mount options in one mount_options object with another * @target: pointer to previously instantiated object to replace * @source: pointer to object containing source mount options diff --git a/utils/mount/parse_opt.h b/utils/mount/parse_opt.h index f9243c3..2c0b5f4 100644 --- a/utils/mount/parse_opt.h +++ b/utils/mount/parse_opt.h @@ -38,6 +38,7 @@ typedef enum { struct mount_options; struct mount_options * po_split(char *); +struct mount_options * po_dup(struct mount_options *); void po_replace(struct mount_options *, struct mount_options *); po_return_t po_join(struct mount_options *, char **); |