Skip to content

Commit

Permalink
cifs: move cifs_parse_devname to fs_context.c
Browse files Browse the repository at this point in the history
Also rename the function from cifs_ to smb3_

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
  • Loading branch information
Ronnie Sahlberg authored and Steve French committed Dec 14, 2020
1 parent 15c7d09 commit 66e7b09
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 57 deletions.
1 change: 1 addition & 0 deletions fs/cifs/cifsproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ extern void cifs_mid_q_entry_release(struct mid_q_entry *midEntry);
extern void cifs_wake_up_task(struct mid_q_entry *mid);
extern int cifs_handle_standard(struct TCP_Server_Info *server,
struct mid_q_entry *mid);
extern int smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx);
extern bool cifs_match_ipaddr(struct sockaddr *srcaddr, struct sockaddr *rhs);
extern int cifs_discard_remaining_data(struct TCP_Server_Info *server);
extern int cifs_call_async(struct TCP_Server_Info *server,
Expand Down
59 changes: 2 additions & 57 deletions fs/cifs/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,61 +1258,6 @@ static int get_option_gid(substring_t args[], kgid_t *result)
return 0;
}

/*
* Parse a devname into substrings and populate the vol->UNC and vol->prepath
* fields with the result. Returns 0 on success and an error otherwise.
*/
static int
cifs_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;
}

static int
cifs_parse_mount_options(const char *mountdata, const char *devname,
struct smb3_fs_context *ctx, bool is_smb3)
Expand Down Expand Up @@ -1416,7 +1361,7 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
ctx->backupuid_specified = false; /* no backup intent for a user */
ctx->backupgid_specified = false; /* no backup intent for a group */

switch (cifs_parse_devname(devname, ctx)) {
switch (smb3_parse_devname(devname, ctx)) {
case 0:
break;
case -ENOMEM:
Expand Down Expand Up @@ -4548,7 +4493,7 @@ static int check_dfs_prepath(struct cifs_sb_info *cifs_sb, struct smb3_fs_contex
struct smb3_fs_context v = {NULL};
/* if @path contains a tree name, skip it in the prefix path */
if (added_treename) {
rc = cifs_parse_devname(path, &v);
rc = smb3_parse_devname(path, &v);
if (rc)
break;
rc = -EREMOTE;
Expand Down
56 changes: 56 additions & 0 deletions fs/cifs/fs_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 66e7b09

Please sign in to comment.