Skip to content

Commit 66e7b09

Browse files
Ronnie SahlbergSteve French
authored andcommitted
cifs: move cifs_parse_devname to fs_context.c
Also rename the function from cifs_ to smb3_ Signed-off-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 15c7d09 commit 66e7b09

File tree

3 files changed

+59
-57
lines changed

3 files changed

+59
-57
lines changed

fs/cifs/cifsproto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ extern void cifs_mid_q_entry_release(struct mid_q_entry *midEntry);
8989
extern void cifs_wake_up_task(struct mid_q_entry *mid);
9090
extern int cifs_handle_standard(struct TCP_Server_Info *server,
9191
struct mid_q_entry *mid);
92+
extern int smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx);
9293
extern bool cifs_match_ipaddr(struct sockaddr *srcaddr, struct sockaddr *rhs);
9394
extern int cifs_discard_remaining_data(struct TCP_Server_Info *server);
9495
extern int cifs_call_async(struct TCP_Server_Info *server,

fs/cifs/connect.c

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,61 +1258,6 @@ static int get_option_gid(substring_t args[], kgid_t *result)
12581258
return 0;
12591259
}
12601260

1261-
/*
1262-
* Parse a devname into substrings and populate the vol->UNC and vol->prepath
1263-
* fields with the result. Returns 0 on success and an error otherwise.
1264-
*/
1265-
static int
1266-
cifs_parse_devname(const char *devname, struct smb3_fs_context *ctx)
1267-
{
1268-
char *pos;
1269-
const char *delims = "/\\";
1270-
size_t len;
1271-
1272-
if (unlikely(!devname || !*devname)) {
1273-
cifs_dbg(VFS, "Device name not specified\n");
1274-
return -EINVAL;
1275-
}
1276-
1277-
/* make sure we have a valid UNC double delimiter prefix */
1278-
len = strspn(devname, delims);
1279-
if (len != 2)
1280-
return -EINVAL;
1281-
1282-
/* find delimiter between host and sharename */
1283-
pos = strpbrk(devname + 2, delims);
1284-
if (!pos)
1285-
return -EINVAL;
1286-
1287-
/* skip past delimiter */
1288-
++pos;
1289-
1290-
/* now go until next delimiter or end of string */
1291-
len = strcspn(pos, delims);
1292-
1293-
/* move "pos" up to delimiter or NULL */
1294-
pos += len;
1295-
ctx->UNC = kstrndup(devname, pos - devname, GFP_KERNEL);
1296-
if (!ctx->UNC)
1297-
return -ENOMEM;
1298-
1299-
convert_delimiter(ctx->UNC, '\\');
1300-
1301-
/* skip any delimiter */
1302-
if (*pos == '/' || *pos == '\\')
1303-
pos++;
1304-
1305-
/* If pos is NULL then no prepath */
1306-
if (!*pos)
1307-
return 0;
1308-
1309-
ctx->prepath = kstrdup(pos, GFP_KERNEL);
1310-
if (!ctx->prepath)
1311-
return -ENOMEM;
1312-
1313-
return 0;
1314-
}
1315-
13161261
static int
13171262
cifs_parse_mount_options(const char *mountdata, const char *devname,
13181263
struct smb3_fs_context *ctx, bool is_smb3)
@@ -1416,7 +1361,7 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
14161361
ctx->backupuid_specified = false; /* no backup intent for a user */
14171362
ctx->backupgid_specified = false; /* no backup intent for a group */
14181363

1419-
switch (cifs_parse_devname(devname, ctx)) {
1364+
switch (smb3_parse_devname(devname, ctx)) {
14201365
case 0:
14211366
break;
14221367
case -ENOMEM:
@@ -4548,7 +4493,7 @@ static int check_dfs_prepath(struct cifs_sb_info *cifs_sb, struct smb3_fs_contex
45484493
struct smb3_fs_context v = {NULL};
45494494
/* if @path contains a tree name, skip it in the prefix path */
45504495
if (added_treename) {
4551-
rc = cifs_parse_devname(path, &v);
4496+
rc = smb3_parse_devname(path, &v);
45524497
if (rc)
45534498
break;
45544499
rc = -EREMOTE;

fs/cifs/fs_context.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,59 @@ smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx
260260

261261
return rc;
262262
}
263+
264+
/*
265+
* Parse a devname into substrings and populate the ctx->UNC and ctx->prepath
266+
* fields with the result. Returns 0 on success and an error otherwise
267+
* (e.g. ENOMEM or EINVAL)
268+
*/
269+
int
270+
smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
271+
{
272+
char *pos;
273+
const char *delims = "/\\";
274+
size_t len;
275+
276+
if (unlikely(!devname || !*devname)) {
277+
cifs_dbg(VFS, "Device name not specified\n");
278+
return -EINVAL;
279+
}
280+
281+
/* make sure we have a valid UNC double delimiter prefix */
282+
len = strspn(devname, delims);
283+
if (len != 2)
284+
return -EINVAL;
285+
286+
/* find delimiter between host and sharename */
287+
pos = strpbrk(devname + 2, delims);
288+
if (!pos)
289+
return -EINVAL;
290+
291+
/* skip past delimiter */
292+
++pos;
293+
294+
/* now go until next delimiter or end of string */
295+
len = strcspn(pos, delims);
296+
297+
/* move "pos" up to delimiter or NULL */
298+
pos += len;
299+
ctx->UNC = kstrndup(devname, pos - devname, GFP_KERNEL);
300+
if (!ctx->UNC)
301+
return -ENOMEM;
302+
303+
convert_delimiter(ctx->UNC, '\\');
304+
305+
/* skip any delimiter */
306+
if (*pos == '/' || *pos == '\\')
307+
pos++;
308+
309+
/* If pos is NULL then no prepath */
310+
if (!*pos)
311+
return 0;
312+
313+
ctx->prepath = kstrdup(pos, GFP_KERNEL);
314+
if (!ctx->prepath)
315+
return -ENOMEM;
316+
317+
return 0;
318+
}

0 commit comments

Comments
 (0)