CIFS: Implement follow_link for SMB2
Subsystems (2)
PATCH v2 1/2 CIFS: Implement follow_link for SMB2
that allows to access files through symlink created on a server.
Acked-by Jeff Layton <[email protected]>
Signed-off-by Pavel Shilovsky <[email protected]>
Signed-off-by Steve French <[email protected]>
--- fs/cifs/cifsglob.h | 3 +++ fs/cifs/inode.c | 4 ++++ fs/cifs/link.c | 24 +++++---------------- fs/cifs/readdir.c | 3 +++ fs/cifs/smb2file.c | 2 +- fs/cifs/smb2inode.c | 9 ++++---- fs/cifs/smb2misc.c | 4 ++++ fs/cifs/smb2ops.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++--- fs/cifs/smb2pdu.c | 6 +++++- fs/cifs/smb2pdu.h | 14 ++++++++++++ fs/cifs/smb2proto.h | 3 ++- 11 files changed, 103 insertions(+), 29 deletions(-)
fs/cifs/cifsglob.h +3 -0
@@ -308,6 +308,9 @@ struct smb_version_operations {int (*create_hardlink)(const unsigned int ,struct cifs_tcon *,const char *,const char *,struct cifs_sb_info *); +/* query symlink target */ +int (*query_symlink)(const unsigned int ,struct cifs_tcon *, +const char *,char **,struct cifs_sb_info *);/* open a file for non-posix mounts */ int (*open)(const unsigned int ,struct cifs_open_parms *,__u32 *,FILE_ALL_INFO *);
fs/cifs/inode.c +4 -0
@@ -549,6 +549,10 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,* when Unix extensions are disabled - fake it. */ fattr->cf_nlink =2 ; + }else if (fattr->cf_cifsattrs &ATTR_REPARSE ) { + fattr->cf_mode =S_IFLNK ; + fattr->cf_dtype =DT_LNK ; + fattr->cf_nlink =le32_to_cpu (info->NumberOfLinks); }else { fattr->cf_mode =S_IFREG | cifs_sb->mnt_file_mode; fattr->cf_dtype =DT_REG ;
fs/cifs/link.c +5 -19
@@ -509,6 +509,7 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)struct cifs_sb_info *cifs_sb =CIFS_SB (inode->i_sb);struct tcon_link *tlink =NULL ;struct cifs_tcon *tcon; +struct TCP_Server_Info *server; xid =get_xid ();
@@ -519,25 +520,7 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd) goto out; } tcon =tlink_tcon (tlink); - -/* -* For now, we just handle symlinks with unix extensions enabled. -* Eventually we should handle NTFS reparse points, and MacOS -* symlink support. For instance... -* -* rc = CIFSSMBQueryReparseLinkInfo(...) -* -* For now, just return -EACCES when the server doesn't support posix -* extensions. Note that we still allow querying symlinks when posix -* extensions are manually disabled. We could disable these as well -* but there doesn't seem to be any harm in allowing the client to -* read them. -*/ -if (!(cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MF_SYMLINKS ) && - !cap_unix (tcon->ses)) { - rc = -EACCES ; - goto out; - } + server = tcon->ses->server; full_path =build_path_from_dentry (direntry);if (!full_path)
@@ -559,6 +542,9 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)if ((rc !=0 ) &&cap_unix (tcon->ses)) rc =CIFSSMBUnixQuerySymLink (xid, tcon, full_path, &target_path, cifs_sb->local_nls); +else if (rc !=0 && server->ops->query_symlink) + rc = server->ops->query_symlink (xid, tcon, full_path, + &target_path, cifs_sb);kfree (full_path); out:
fs/cifs/readdir.c +3 -0
@@ -172,6 +172,9 @@ cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb)if (cifs_dfs_is_possible (cifs_sb) && (fattr->cf_cifsattrs &ATTR_REPARSE )) fattr->cf_flags |=CIFS_FATTR_NEED_REVAL ; + }else if (fattr->cf_cifsattrs &ATTR_REPARSE ) { + fattr->cf_mode =S_IFLNK ; + fattr->cf_dtype =DT_LNK ; }else { fattr->cf_mode =S_IFREG | cifs_sb->mnt_file_mode; fattr->cf_dtype =DT_REG ;
fs/cifs/smb2file.c +1 -1
@@ -86,7 +86,7 @@ smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,if (oparms->tcon->ses->server->capabilities &SMB2_GLOBAL_CAP_LEASING )memcpy (smb2_oplock +1 , fid->lease_key,SMB2_LEASE_KEY_SIZE ); - rc =SMB2_open (xid, oparms, smb2_path, smb2_oplock, smb2_data); + rc =SMB2_open (xid, oparms, smb2_path, smb2_oplock, smb2_data,NULL );if (rc) goto out;
fs/cifs/smb2inode.c +5 -4
@@ -60,7 +60,7 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; - rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ); + rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ,NULL );if (rc) {kfree (utf16_path);return rc;
@@ -136,7 +136,8 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,return -ENOMEM ; rc =smb2_open_op_close (xid, tcon, cifs_sb, full_path, -FILE_READ_ATTRIBUTES ,FILE_OPEN ,0 , smb2_data, +FILE_READ_ATTRIBUTES ,FILE_OPEN , +OPEN_REPARSE_POINT , smb2_data,SMB2_OP_QUERY_INFO );if (rc) goto out;
@@ -191,8 +192,8 @@ smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name, struct cifs_sb_info *cifs_sb) {return smb2_open_op_close (xid, tcon, cifs_sb, name,DELETE ,FILE_OPEN , -CREATE_DELETE_ON_CLOSE ,NULL , -SMB2_OP_DELETE ); +CREATE_DELETE_ON_CLOSE |OPEN_REPARSE_POINT , +NULL ,SMB2_OP_DELETE ); } static int
fs/cifs/smb2misc.c +4 -0
@@ -171,6 +171,10 @@ smb2_check_message(char *buf, unsigned int length)if (4 + len != clc_len) {cifs_dbg (FYI ,"Calculated size %u length %u mismatch mid %llu\n" , clc_len,4 + len, mid); +/* create failed on symlink */ +if (command ==SMB2_CREATE_HE && + hdr->Status ==STATUS_STOPPED_ON_SYMLINK ) +return 0 ;/* Windows 7 server returns 24 bytes more */ if (clc_len +20 == len && command ==SMB2_OPLOCK_BREAK_HE )return 0 ;
fs/cifs/smb2ops.c +57 -3
102 lines not on this page · raw message
fs/cifs/smb2pdu.c +5 -1
@@ -977,7 +977,8 @@ add_durable_context(struct kvec *iov, unsigned int *num_iovec,int SMB2_open (const unsigned int xid,struct cifs_open_parms *oparms,__le16 *path, -__u8 *oplock,struct smb2_file_all_info *buf) +__u8 *oplock,struct smb2_file_all_info *buf, +struct smb2_err_rsp **err_buf) {struct smb2_create_req *req;struct smb2_create_rsp *rsp;
@@ -1082,6 +1083,9 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,if (rc !=0 ) {cifs_stats_fail_inc (tcon,SMB2_CREATE_HE ); +if (err_buf) + *err_buf =kmemdup (rsp,get_rfc1002_length (rsp) +4 , +GFP_KERNEL ); goto creat_exit; }
fs/cifs/smb2pdu.h +14 -0
@@ -150,6 +150,20 @@ struct smb2_err_rsp {__u8 ErrorData[1 ];/* variable length */ } __packed; +struct smb2_symlink_err_rsp { +__le32 SymLinkLength; +__le32 SymLinkErrorTag; +__le32 ReparseTag; +__le16 ReparseDataLength; +__le16 UnparsedPathLength; +__le16 SubstituteNameOffset; +__le16 SubstituteNameLength; +__le16 PrintNameOffset; +__le16 PrintNameLength; +__le32 Flags; +__u8 PathBuffer[0 ]; +} __packed; +#define SMB2_CLIENT_GUID_SIZE 16extern __u8 cifs_client_guid[SMB2_CLIENT_GUID_SIZE ];
fs/cifs/smb2proto.h +2 -1
@@ -106,7 +106,8 @@ extern int SMB2_tcon(const unsigned int xid, struct cifs_ses *ses,extern int SMB2_tdis (const unsigned int xid,struct cifs_tcon *tcon);extern int SMB2_open (const unsigned int xid,struct cifs_open_parms *oparms,__le16 *path,__u8 *oplock, -struct smb2_file_all_info *buf); +struct smb2_file_all_info *buf, +struct smb2_err_rsp **err_buf); extern int SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, u64 volatile_fid, u32 opcode, bool is_fsctl, char *in_data, u32 indatalen,
Signature · 1 line
1.7.10.4
A message that is not in the archive (sent off-list or not yet received): 1376493922-7150-1-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org
PATCH v2 2/2 CIFS: Implement follow_link for nounix CIFS mounts
by using a query reparse ioctl request.
Acked-by Jeff Layton <[email protected]>
Signed-off-by Pavel Shilovsky <[email protected]>
Signed-off-by Steve French <[email protected]>
--- fs/cifs/cifspdu.h | 11 +++--- fs/cifs/cifsproto.h | 10 ++--- fs/cifs/cifssmb.c | 110 ++++++++++++++++++++++++--------------------------- fs/cifs/smb1ops.c | 32 +++++++++++++++ 4 files changed, 92 insertions(+), 71 deletions(-)
fs/cifs/cifspdu.h +6 -5
@@ -1495,11 +1495,12 @@ struct reparse_data {__u32 ReparseTag;__u16 ReparseDataLength;__u16 Reserved; -__u16 AltNameOffset; -__u16 AltNameLen; -__u16 TargetNameOffset; -__u16 TargetNameLen; -char LinkNamesBuf[1 ]; +__u16 SubstituteNameOffset; +__u16 SubstituteNameLength; +__u16 PrintNameOffset; +__u16 PrintNameLength; +__u32 Flags; +char PathBuffer[0 ]; } __attribute__((packed));struct cifs_quota_data {
fs/cifs/cifsproto.h +3 -7
@@ -357,13 +357,9 @@ extern int CIFSSMBUnixQuerySymLink(const unsigned int xid,struct cifs_tcon *tcon, const unsigned char *searchName, char **syminfo, const struct nls_table *nls_codepage); -#ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL -extern int CIFSSMBQueryReparseLinkInfo (const unsigned int xid, -struct cifs_tcon *tcon, -const unsigned char *searchName, -char *symlinkinfo,const int buflen,__u16 fid, -const struct nls_table *nls_codepage); -#endif /* temporarily unused until cifs_symlink fixed */ +extern int CIFSSMBQuerySymLink (const unsigned int xid,struct cifs_tcon *tcon, +__u16 fid,char **symlinkinfo, +const struct nls_table *nls_codepage); extern int CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon, const char *fileName, const int disposition, const int access_flags, const int omode,
fs/cifs/cifssmb.c +51 -59
142 lines not on this page · raw message
fs/cifs/smb1ops.c +32 -0
@@ -881,6 +881,37 @@ cifs_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, (__u8)type, wait, 0); } +static int +cifs_query_symlink (const unsigned int xid,struct cifs_tcon *tcon, +const char *full_path,char **target_path, +struct cifs_sb_info *cifs_sb) +{ +int rc; +int oplock =0 ; +__u16 netfid; + +cifs_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); + + rc =CIFSSMBOpen (xid, tcon, full_path,FILE_OPEN , +FILE_READ_ATTRIBUTES ,OPEN_REPARSE_POINT , &netfid, + &oplock,NULL , cifs_sb->local_nls, + cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR ); +if (rc) +return rc; + + rc =CIFSSMBQuerySymLink (xid, tcon, netfid, target_path, + cifs_sb->local_nls); +if (rc) { +CIFSSMBClose (xid, tcon, netfid); +return rc; + } + +convert_delimiter (*target_path,'/' ); +CIFSSMBClose (xid, tcon, netfid); +cifs_dbg (FYI ,"%s: target path: %s\n" , __func__, *target_path); +return rc; +} +struct smb_version_operations smb1_operations = { .send_cancel = send_nt_cancel, .compare_fids = cifs_compare_fids,
@@ -927,6 +958,7 @@ struct smb_version_operations smb1_operations = { .rename_pending_delete = cifs_rename_pending_delete, .rename = CIFSSMBRename, .create_hardlink = CIFSCreateHardLink, + .query_symlink = cifs_query_symlink, .open = cifs_open_file, .set_fid = cifs_set_fid, .close = cifs_close_file,
Signature · 1 line
1.7.10.4