diff options
author | Ronnie Sahlberg <lsahlber@redhat.com> | 2020-11-05 13:58:14 +1000 |
---|---|---|
committer | Steve French <stfrench@microsoft.com> | 2020-12-13 19:12:07 -0600 |
commit | 66e7b09c731175064de5a3682c692ec166e02499 (patch) | |
tree | 04b448cf6e822cb5dfb8e3998b1da10605753a01 /fs/cifs/fs_context.c | |
parent | cifs: move the enum for cifs parameters into fs_context.h (diff) | |
download | linux-dev-66e7b09c731175064de5a3682c692ec166e02499.tar.xz linux-dev-66e7b09c731175064de5a3682c692ec166e02499.zip |
cifs: move cifs_parse_devname to fs_context.c
Also rename the function from cifs_ to smb3_
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Diffstat (limited to 'fs/cifs/fs_context.c')
-rw-r--r-- | fs/cifs/fs_context.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/fs/cifs/fs_context.c b/fs/cifs/fs_context.c index af6ff0192d5e..84354cd4c960 100644 --- a/fs/cifs/fs_context.c +++ b/fs/cifs/fs_context.c @@ -260,3 +260,59 @@ smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx return rc; } + +/* + * Parse a devname into substrings and populate the ctx->UNC and ctx->prepath + * fields with the result. Returns 0 on success and an error otherwise + * (e.g. ENOMEM or EINVAL) + */ +int +smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx) +{ + char *pos; + const char *delims = "/\\"; + size_t len; + + if (unlikely(!devname || !*devname)) { + cifs_dbg(VFS, "Device name not specified\n"); + return -EINVAL; + } + + /* make sure we have a valid UNC double delimiter prefix */ + len = strspn(devname, delims); + if (len != 2) + return -EINVAL; + + /* find delimiter between host and sharename */ + pos = strpbrk(devname + 2, delims); + if (!pos) + return -EINVAL; + + /* skip past delimiter */ + ++pos; + + /* now go until next delimiter or end of string */ + len = strcspn(pos, delims); + + /* move "pos" up to delimiter or NULL */ + pos += len; + ctx->UNC = kstrndup(devname, pos - devname, GFP_KERNEL); + if (!ctx->UNC) + return -ENOMEM; + + convert_delimiter(ctx->UNC, '\\'); + + /* skip any delimiter */ + if (*pos == '/' || *pos == '\\') + pos++; + + /* If pos is NULL then no prepath */ + if (!*pos) + return 0; + + ctx->prepath = kstrdup(pos, GFP_KERNEL); + if (!ctx->prepath) + return -ENOMEM; + + return 0; +} |