Skip to contentSkip to conversation

fs/cifs/dir.c: use correct path separators

PATCH In review Aurelien Aptel 2 participants 3 messages Sep 7, 2016 – Sep 17, 2016 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/cifs/dir.c: use correct path separators

When a prefix path needs to be added, current code hardcodes the initial path separator to backslash. Use CIFS_DIR_SEP instead and properly convert path separator in the prefix path.

CIFS_MOUNT_USE_PREFIX_PATH is rarely needed (Windows shares with very specific ACL or buggy mount call AFAIK) which explains why the backsplash wasn't a big issue.

---
 fs/cifs/dir.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
fs/cifs/dir.c +6 -4
index 4716c54..c85a8bb 100644
@@ -160,13 +160,15 @@ cifs_bp_rename_retry:
 
 	if (pplen) {
 		int i;
+		char oldsep = dirsep == '/' ? '\\' : '/';
 
 		cifs_dbg(FYI, "using cifs_sb prepath <%s>\n", cifs_sb->prepath);
+
+		full_path[dfsplen] = dirsep;
 		memcpy(full_path+dfsplen+1, cifs_sb->prepath, pplen-1);
-		full_path[dfsplen] = '\\';
-		for (i = 0; i < pplen-1; i++)
-			if (full_path[dfsplen+1+i] == '/')
-				full_path[dfsplen+1+i] = CIFS_DIR_SEP(cifs_sb);
+		for (i = 1; i < pplen; i++)
+			if (full_path[dfsplen+i] == oldsep)
+				full_path[dfsplen+i] = dirsep;
 	}
 
 	if (dfsplen) {
Signature · 1 line
2.1.4

A message that is not in the archive (sent off-list or not yet received): 1473255952-27579-1-git-send-email-aaptel-IBi9RG/[email protected]

#2 lore raw

Thanks Aurelien. Comments below.

Quoted 35 lines · Aurelien Aptel

When a prefix path needs to be added, current code hardcodes the initial
path separator to backslash. Use CIFS_DIR_SEP instead and properly convert path separator in the prefix path.

CIFS_MOUNT_USE_PREFIX_PATH is rarely needed (Windows shares with very specific ACL or buggy mount call AFAIK) which explains why the backsplash wasn't a big issue.

---
 fs/cifs/dir.c | 10 ++++++----

 1 file changed, 6 insertions(+), 4 deletions(-)
fs/cifs/dir.c +0 -0
index 4716c54..c85a8bb 100644
@@ -160,13 +160,15 @@ cifs_bp_rename_retry:


  if (pplen) {
  int i;

fs/cifs/dir.c +1 -0
+		char oldsep = dirsep == '/' ? '\\' : '/';


  cifs_dbg(FYI, "using cifs_sb prepath <%s>\n", cifs_sb->prepath);

fs/cifs/dir.c +2 -0
+
+		full_path[dfsplen] = dirsep;

  memcpy(full_path+dfsplen+1, cifs_sb->prepath, pplen- 1);

fs/cifs/dir.c +0 -4
-		full_path[dfsplen] = '\\';
-		for (i = 0; i < pplen-1; i++)
-			if (full_path[dfsplen+1+i] == '/')
-				full_path[dfsplen+1+i] =

CIFS_DIR_SEP(cifs_sb);

fs/cifs/dir.c cifs_bp_rename_retry: · line 171

Quoted 3 lines
fs/cifs/dir.c +3 -0
+		for (i = 1; i < pplen; i++)
+			if (full_path[dfsplen+i] == oldsep)
+				full_path[dfsplen+i] = dirsep;

We have an inline helper convert_delimiter() which already does this. The block for dfsplen also seems to repeat the code.

Can we use the  helper for the complete patch instead when the full_path variable is available?
I think the code here for copying the treename and the prefixpath name can also be cleaned to make it easier to read ie. move the treeName copy before we copy over the prefix path.

Sachin Prabhu

Quoted 3 lines

  }

  if (dfsplen) {

A message that is not in the archive (sent off-list or not yet received): 1473705389.29354.20.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#4 lore raw
Quoted 2 lines · Sachin Prabhu

We have an inline helper convert_delimiter() which already does this. The block for dfsplen also seems to repeat the code.

Correct except for a small detail: the inline helper does the conversion until the end of the string. Here we need to stop in the middle.

Quoted 2 lines

Can we use the  helper for the complete patch instead when the full_path variable is available?

We do not want to mess with unix path that might contain a valid backslash inside a path component.

Quoted 3 lines

I think the code here for copying the treename and the prefixpath name can also be cleaned to make it easier to read ie. move the treeName copy before we copy over the prefix path.

Agreed. Thanks for the feedback, Sachin.
I'll send an updated patch for review.

Signature · 4 lines
Aurélien Aptel / SUSE Labs Samba Team
GPG: 1839 CB5F 9F5B FB9B AA97  8C99 03C8 A49B 521B D5D3
SUSE Linux GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)