From 1caea1e53763df316b6c7b4cc9dc7b54c3f3300e Mon Sep 17 00:00:00 2001 From: Aurelien Aptel Date: Wed, 20 Apr 2016 16:34:01 +0200 Subject: [PATCH 2/2] fs/cifs: Add full_path_type arg to cifs_build_path_to_root() Only add the server prefix in the case of a DFS link when explicitely asked. This function is called from: - cifs_mount() - cifs_get_root() The later expects a full path from the root, even in the presence of a DFS link. e.g. in the case of a DFS link like //A/shareA/link -> //B/shareB/sub/dir/ When doing a "cd link", cifs_get_root() was getting "//B/shareB//sub/dir" Instead of "/sub/dir" Resulting in sh: cd: link: No such file or directory This commit - lets the caller of cifs_build_path_to_root() decide the behaviour via a new argument. - make cifs_get_root() always use a simple path. Thanks to Josef Cejka for finding the bug&fix. Reported-by: Fons Jongh Signed-off-by: Aurelien Aptel --- fs/cifs/cifsfs.c | 3 ++- fs/cifs/cifsproto.h | 3 ++- fs/cifs/connect.c | 2 +- fs/cifs/dir.c | 6 ++++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 8920156..d56a5ed 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -607,7 +607,8 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb) char sep; full_path = cifs_build_path_to_root(vol, cifs_sb, - cifs_sb_master_tcon(cifs_sb)); + cifs_sb_master_tcon(cifs_sb), CIFS_NO_PREFIX); + if (full_path == NULL) return ERR_PTR(-ENOMEM); diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index eed7ff50..f6a0902 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h @@ -63,7 +63,8 @@ extern void exit_cifs_idmap(void); extern char *build_path_from_dentry(struct dentry *); extern char *cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, - struct cifs_tcon *tcon); + struct cifs_tcon *tcon, + enum full_path_type); extern char *build_wildcard_path_from_dentry(struct dentry *direntry); extern char *cifs_compose_mount_options(const char *sb_mountdata, const char *fullpath, const struct dfs_info3_param *ref, diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 6f62ac8..b054218 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -3660,7 +3660,7 @@ remote_path_check: /* * cifs_build_path_to_root works only when we have a valid tcon */ - full_path = cifs_build_path_to_root(volume_info, cifs_sb, tcon); + full_path = cifs_build_path_to_root(volume_info, cifs_sb, tcon, CIFS_SERVER_PREFIX); if (full_path == NULL) { rc = -ENOMEM; goto mount_fail_check; diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index c3eb998..b5fe596 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c @@ -47,7 +47,7 @@ renew_parental_timestamps(struct dentry *direntry) char * cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, - struct cifs_tcon *tcon) + struct cifs_tcon *tcon, enum full_path_type prefix) { int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0; int dfsplen; @@ -59,7 +59,8 @@ cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, return full_path; } - if (tcon->Flags & SMB_SHARE_IS_IN_DFS) + + if (prefix == CIFS_WITH_DFS_UNC_PREFIX && (tcon->Flags & SMB_SHARE_IS_IN_DFS)) dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1); else dfsplen = 0; @@ -68,6 +69,7 @@ cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, if (full_path == NULL) return full_path; + if (dfsplen) strncpy(full_path, tcon->treeName, dfsplen); full_path[dfsplen] = CIFS_DIR_SEP(cifs_sb); -- 2.1.4