smb: client: implement ->query_reparse_point() for SMB1
Subsystems (2)
PATCH 1/3 smb: client: implement ->query_reparse_point() for SMB1
Reparse points are not limited to symlinks, so implement ->query_reparse_point() in order to handle different file types.
--- fs/smb/client/cifspdu.h | 2 +- fs/smb/client/cifsproto.h | 9 ++ fs/smb/client/cifssmb.c | 189 +++++++++++++++----------------------- fs/smb/client/smb1ops.c | 49 ++-------- fs/smb/client/smb2ops.c | 35 ++++--- 5 files changed, 111 insertions(+), 173 deletions(-)
fs/smb/client/cifspdu.h +1 -1
@@ -1356,7 +1356,7 @@ typedef struct smb_com_transaction_ioctl_rsp {__le32 DataDisplacement;__u8 SetupCount;/* 1 */ __le16 ReturnedDataLen; -__u16 ByteCount; +__le16 ByteCount; } __attribute__((packed)) TRANSACT_IOCTL_RSP;#define CIFS_ACL_OWNER 1
fs/smb/client/cifsproto.h +9 -0
@@ -458,6 +458,12 @@ extern int CIFSSMBUnixQuerySymLink(const unsigned int xid,struct cifs_tcon *tcon, const unsigned char *searchName, char **syminfo, const struct nls_table *nls_codepage, int remap); +extern int cifs_query_reparse_point (const unsigned int xid, +struct cifs_tcon *tcon, +struct cifs_sb_info *cifs_sb, +const char *full_path, +u32 *tag,struct kvec *rsp, +int *rsp_buftype);extern int CIFSSMBQuerySymLink (const unsigned int xid,struct cifs_tcon *tcon,__u16 fid,char **symlinkinfo,const struct nls_table *nls_codepage);
@@ -659,6 +665,9 @@ void cifs_put_tcp_super(struct super_block *sb);int cifs_update_super_prepath (struct cifs_sb_info *cifs_sb,char *prefix);char *extract_hostname (const char *unc);char *extract_sharename (const char *unc); +int parse_reparse_point (struct reparse_data_buffer *buf, +u32 plen,struct cifs_sb_info *cifs_sb, +bool unicode,char **target_path);#ifdef CONFIG_CIFS_DFS_UPCALL static inline int get_dfs_path(const unsigned int xid, struct cifs_ses *ses,
fs/smb/client/cifssmb.c +75 -114
211 lines not on this page · raw message
fs/smb/client/smb1ops.c +10 -39
71 lines not on this page · raw message
fs/smb/client/smb2ops.c +16 -19
@@ -2894,27 +2894,26 @@ parse_reparse_posix(struct reparse_posix_data *symlink_buf,return 0 ; } -static int -parse_reparse_symlink (struct reparse_symlink_data_buffer *symlink_buf, -u32 plen,char **target_path, -struct cifs_sb_info *cifs_sb) +static int parse_reparse_symlink (struct reparse_symlink_data_buffer *sym, +u32 plen,bool unicode,char **target_path, +struct cifs_sb_info *cifs_sb) {unsigned int sub_len;unsigned int sub_offset;/* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */ - sub_offset =le16_to_cpu (symlink_buf->SubstituteNameOffset); - sub_len =le16_to_cpu (symlink_buf->SubstituteNameLength); + sub_offset =le16_to_cpu (sym->SubstituteNameOffset); + sub_len =le16_to_cpu (sym->SubstituteNameLength);if (sub_offset +20 > plen || sub_offset + sub_len +20 > plen) {cifs_dbg (VFS ,"srv returned malformed symlink buffer\n" );return -EIO ; } - *target_path =cifs_strndup_from_utf16 ( - symlink_buf->PathBuffer + sub_offset, - sub_len, true, cifs_sb->local_nls); + *target_path =cifs_strndup_from_utf16 (sym->PathBuffer + sub_offset, + sub_len, unicode, + cifs_sb->local_nls);if (!(*target_path))return -ENOMEM ;
@@ -2924,19 +2923,17 @@ parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,return 0 ; } -static int -parse_reparse_point (struct reparse_data_buffer *buf, -u32 plen,char **target_path, -struct cifs_sb_info *cifs_sb) +int parse_reparse_point (struct reparse_data_buffer *buf, +u32 plen,struct cifs_sb_info *cifs_sb, +bool unicode,char **target_path) { -if (plen <sizeof (struct reparse_data_buffer )) { +if (plen <sizeof (*buf)) {cifs_dbg (VFS ,"reparse buffer is too small. Must be at least 8 bytes but was %d\n" , plen);return -EIO ; } -if (plen <le16_to_cpu (buf->ReparseDataLength) + -sizeof (struct reparse_data_buffer )) { +if (plen <le16_to_cpu (buf->ReparseDataLength) +sizeof (*buf)) {cifs_dbg (VFS ,"srv returned invalid reparse buf length: %d\n" , plen);return -EIO ;
@@ -2951,7 +2948,7 @@ parse_reparse_point(struct reparse_data_buffer *buf,case IO_REPARSE_TAG_SYMLINK :return parse_reparse_symlink ( (struct reparse_symlink_data_buffer *)buf, - plen, target_path, cifs_sb); + plen, unicode, target_path, cifs_sb);default :cifs_dbg (VFS ,"srv returned unknown symlink buffer tag:0x%08x\n" ,le32_to_cpu (buf->ReparseTag));
@@ -2970,11 +2967,11 @@ static int smb2_query_symlink(const unsigned int xid,struct smb2_ioctl_rsp *io = rsp_iov->iov_base;u32 plen =le32_to_cpu (io->OutputCount); -cifs_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); +cifs_tcon_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); buf = (struct reparse_data_buffer *)((u8 *)io +le32_to_cpu (io->OutputOffset)); -return parse_reparse_point (buf, plen, target_path, cifs_sb); +return parse_reparse_point (buf, plen, cifs_sb, true, target_path); } static int smb2_query_reparse_point(const unsigned int xid,
Signature · 1 line
2.42.1
PATCH 2/3 smb: client: introduce ->parse_reparse_point()
Parse reparse point into cifs_open_info_data structure and feed it through cifs_open_info_to_fattr().
--- fs/smb/client/cifsglob.h | 6 ++++-- fs/smb/client/inode.c | 23 +++++++++++++--------- fs/smb/client/smb1ops.c | 41 ++++++++++++++++++++++------------------ fs/smb/client/smb2ops.c | 22 +++++++++------------ 4 files changed, 50 insertions(+), 42 deletions(-)
fs/smb/client/cifsglob.h +4 -2
@@ -395,8 +395,7 @@ struct smb_version_operations {struct cifs_tcon *tcon, struct cifs_sb_info *cifs_sb, const char *full_path, - char **target_path, - struct kvec *rsp_iov); + char **target_path);/* open a file for non-posix mounts */ int (*open)(const unsigned int xid,struct cifs_open_parms *oparms,__u32 *oplock,void *buf);
@@ -551,6 +550,9 @@ struct smb_version_operations {bool (*is_status_io_timeout)(char *buf);/* Check for STATUS_NETWORK_NAME_DELETED */ bool (*is_network_name_deleted)(char *buf,struct TCP_Server_Info *srv); +int (*parse_reparse_point)(struct cifs_sb_info *cifs_sb, +struct kvec *rsp_iov, +struct cifs_open_info_data *data); };struct smb_version_values {
fs/smb/client/inode.c +14 -9
@@ -459,8 +459,7 @@ static int cifs_get_unix_fattr(const unsigned char *full_path,return -EOPNOTSUPP ; rc = server->ops->query_symlink (xid, tcon, cifs_sb, full_path, - &fattr->cf_symlink_target, -NULL ); + &fattr->cf_symlink_target);cifs_dbg (FYI ,"%s: query_symlink: %d\n" , __func__, rc); }return rc;
@@ -1035,22 +1034,28 @@ static int reparse_info_to_fattr(struct cifs_open_info_data *data,if (!rc) iov = &rsp_iov; } + + rc = -EOPNOTSUPP ;switch ((data->reparse_tag = tag)) {case 0 :/* SMB1 symlink */ - iov =NULL ; - fallthrough; -case IO_REPARSE_TAG_NFS : -case IO_REPARSE_TAG_SYMLINK : -if (!data->symlink_target && server->ops->query_symlink) { +if (server->ops->query_symlink) { rc = server->ops->query_symlink (xid, tcon, cifs_sb, full_path, - &data->symlink_target, - iov); + &data->symlink_target); }break ;case IO_REPARSE_TAG_MOUNT_POINT :cifs_create_junction_fattr (fattr, sb); + rc =0 ; goto out; +default : +if (data->symlink_target) { + rc =0 ; + }else if (server->ops->parse_reparse_point) { + rc = server->ops->parse_reparse_point (cifs_sb, + iov, data); + } +break ; }cifs_open_info_to_fattr (fattr, data, sb);
fs/smb/client/smb1ops.c +23 -18
61 lines not on this page · raw message
fs/smb/client/smb2ops.c +9 -13
@@ -2956,22 +2956,18 @@ int parse_reparse_point(struct reparse_data_buffer *buf, } } -static int smb2_query_symlink (const unsigned int xid, -struct cifs_tcon *tcon, -struct cifs_sb_info *cifs_sb, -const char *full_path, -char **target_path, -struct kvec *rsp_iov) +static int smb2_parse_reparse_point (struct cifs_sb_info *cifs_sb, +struct kvec *rsp_iov, +struct cifs_open_info_data *data) {struct reparse_data_buffer *buf;struct smb2_ioctl_rsp *io = rsp_iov->iov_base;u32 plen =le32_to_cpu (io->OutputCount); -cifs_tcon_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); - buf = (struct reparse_data_buffer *)((u8 *)io +le32_to_cpu (io->OutputOffset)); -return parse_reparse_point (buf, plen, cifs_sb, true, target_path); +return parse_reparse_point (buf, plen, cifs_sb, + true, &data->symlink_target); } static int smb2_query_reparse_point(const unsigned int xid,
@@ -5206,7 +5202,7 @@ struct smb_version_operations smb20_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, - .query_symlink = smb2_query_symlink, + .parse_reparse_point = smb2_parse_reparse_point, .query_mf_symlink = smb3_query_mf_symlink, .create_mf_symlink = smb3_create_mf_symlink, .open = smb2_open_file,
@@ -5308,7 +5304,7 @@ struct smb_version_operations smb21_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, - .query_symlink = smb2_query_symlink, + .parse_reparse_point = smb2_parse_reparse_point, .query_mf_symlink = smb3_query_mf_symlink, .create_mf_symlink = smb3_create_mf_symlink, .open = smb2_open_file,
@@ -5413,7 +5409,7 @@ struct smb_version_operations smb30_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, - .query_symlink = smb2_query_symlink, + .parse_reparse_point = smb2_parse_reparse_point, .query_mf_symlink = smb3_query_mf_symlink, .create_mf_symlink = smb3_create_mf_symlink, .open = smb2_open_file,
@@ -5527,7 +5523,7 @@ struct smb_version_operations smb311_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, - .query_symlink = smb2_query_symlink, + .parse_reparse_point = smb2_parse_reparse_point, .query_mf_symlink = smb3_query_mf_symlink, .create_mf_symlink = smb3_create_mf_symlink, .open = smb2_open_file,
Signature · 1 line
2.42.1
PATCH 3/3 smb: client: set correct file type from NFS reparse points
In reply to Paulo AlcantaraHandle all file types in NFS reparse points as specified in MS-FSCC 2.1.2.6 Network File System (NFS) Reparse Data Buffer.
The client is now able to set all file types based on the parsed NFS reparse point, which used to support only symlinks. This works for SMB1+.
Before patch:
$ mount.cifs //srv/share /mnt -o ... $ ls -l /mnt ls: cannot access 'block': Operation not supported ls: cannot access 'char': Operation not supported ls: cannot access 'fifo': Operation not supported ls: cannot access 'sock': Operation not supported total 1 l????????? ? ? ? ? ? block l????????? ? ? ? ? ? char -rwxr-xr-x 1 root root 5 Nov 18 23:22 f0 l????????? ? ? ? ? ? fifo l--------- 1 root root 0 Nov 18 23:23 link -> f0 l????????? ? ? ? ? ? sock
After patch:
$ mount.cifs //srv/share /mnt -o ... $ ls -l /mnt total 1 brwxr-xr-x 1 root root 123, 123 Nov 18 00:34 block crwxr-xr-x 1 root root 1234, 1234 Nov 18 00:33 char -rwxr-xr-x 1 root root 5 Nov 18 23:22 f0 prwxr-xr-x 1 root root 0 Nov 18 23:23 fifo lrwxr-xr-x 1 root root 0 Nov 18 23:23 link -> f0 srwxr-xr-x 1 root root 0 Nov 19 2023 sock
--- fs/smb/client/cifsglob.h | 8 +++- fs/smb/client/cifspdu.h | 2 +- fs/smb/client/cifsproto.h | 4 +- fs/smb/client/inode.c | 51 ++++++++++++++++++-- fs/smb/client/readdir.c | 6 ++- fs/smb/client/smb1ops.c | 3 +- fs/smb/client/smb2inode.c | 2 +- fs/smb/client/smb2ops.c | 99 ++++++++++++++++++++------------------- 8 files changed, 115 insertions(+), 60 deletions(-)
fs/smb/client/cifsglob.h +7 -1
@@ -191,7 +191,13 @@ struct cifs_open_info_data {bool reparse_point;bool symlink; }; -__u32 reparse_tag; +struct { +__u32 tag; +union { +struct reparse_data_buffer *buf; +struct reparse_posix_data *posix; + }; + } reparse;char *symlink_target;union {struct smb2_file_all_info fi;
fs/smb/client/cifspdu.h +1 -1
@@ -1509,7 +1509,7 @@ struct reparse_posix_data {__le16 ReparseDataLength;__u16 Reserved;__le64 InodeType;/* LNK, FIFO, CHR etc. */ -char PathBuffer[]; +__u8 DataBuffer[]; } __attribute__((packed));struct cifs_quota_data {
fs/smb/client/cifsproto.h +2 -2
@@ -210,7 +210,7 @@ int cifs_get_inode_info(struct inode **inode, const char *full_path, const struct cifs_fid *fid);bool cifs_reparse_point_to_fattr (struct cifs_sb_info *cifs_sb,struct cifs_fattr *fattr, -u32 tag); +struct cifs_open_info_data *data);extern int smb311_posix_get_inode_info (struct inode **pinode,const char *search_path,struct super_block *sb,unsigned int xid); extern int cifs_get_inode_info_unix(struct inode **pinode,
@@ -667,7 +667,7 @@ char *extract_hostname(const char *unc);char *extract_sharename (const char *unc);int parse_reparse_point (struct reparse_data_buffer *buf,u32 plen,struct cifs_sb_info *cifs_sb, -bool unicode,char **target_path); +bool unicode,struct cifs_open_info_data *data);#ifdef CONFIG_CIFS_DFS_UPCALL static inline int get_dfs_path(const unsigned int xid, struct cifs_ses *ses,
fs/smb/client/inode.c +46 -5
84 lines not on this page · raw message
fs/smb/client/readdir.c +5 -1
@@ -153,6 +153,10 @@ static bool reparse_file_needs_reval(const struct cifs_fattr *fattr)static void cifs_fill_common_info (struct cifs_fattr *fattr,struct cifs_sb_info *cifs_sb) { +struct cifs_open_info_data data = { + .reparse = { .tag = fattr->cf_cifstag, }, + }; + fattr->cf_uid = cifs_sb->ctx->linux_uid; fattr->cf_gid = cifs_sb->ctx->linux_gid;
@@ -165,7 +169,7 @@ cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb)* reasonably map some of them to directories vs. files vs. symlinks */ if ((fattr->cf_cifsattrs &ATTR_REPARSE ) && -cifs_reparse_point_to_fattr (cifs_sb, fattr, fattr->cf_cifstag)) +cifs_reparse_point_to_fattr (cifs_sb, fattr, &data)) goto out_reparse;if (fattr->cf_cifsattrs &ATTR_DIRECTORY ) {
fs/smb/client/smb1ops.c +1 -2
@@ -1004,8 +1004,7 @@ static int cifs_parse_reparse_point(struct cifs_sb_info *cifs_sb, buf = (struct reparse_data_buffer *)((__u8 *)&io->hdr.Protocol +le32_to_cpu (io->DataOffset)); -return parse_reparse_point (buf, plen, cifs_sb, unicode, - &data->symlink_target); +return parse_reparse_point (buf, plen, cifs_sb, unicode, data); } static bool
fs/smb/client/smb2inode.c +1 -1
@@ -555,7 +555,7 @@ static int parse_create_response(struct cifs_open_info_data *data,break ; } data->reparse_point = reparse_point; - data->reparse_tag = tag; + data->reparse.tag = tag;return rc; }
fs/smb/client/smb2ops.c +52 -47
152 lines not on this page · raw message
Signature · 1 line
2.42.1
PATCH v2 1/3 smb: client: implement ->query_reparse_point() for SMB1
In reply to Paulo AlcantaraReparse points are not limited to symlinks, so implement ->query_reparse_point() in order to handle different file types.
--- fs/smb/client/cifspdu.h | 2 +- fs/smb/client/cifsproto.h | 9 ++ fs/smb/client/cifssmb.c | 189 +++++++++++++++----------------------- fs/smb/client/smb1ops.c | 49 ++-------- fs/smb/client/smb2ops.c | 35 ++++--- 5 files changed, 111 insertions(+), 173 deletions(-)
fs/smb/client/cifspdu.h +1 -1
@@ -1356,7 +1356,7 @@ typedef struct smb_com_transaction_ioctl_rsp {__le32 DataDisplacement;__u8 SetupCount;/* 1 */ __le16 ReturnedDataLen; -__u16 ByteCount; +__le16 ByteCount; } __attribute__((packed)) TRANSACT_IOCTL_RSP;#define CIFS_ACL_OWNER 1
fs/smb/client/cifsproto.h +9 -0
@@ -458,6 +458,12 @@ extern int CIFSSMBUnixQuerySymLink(const unsigned int xid,struct cifs_tcon *tcon, const unsigned char *searchName, char **syminfo, const struct nls_table *nls_codepage, int remap); +extern int cifs_query_reparse_point (const unsigned int xid, +struct cifs_tcon *tcon, +struct cifs_sb_info *cifs_sb, +const char *full_path, +u32 *tag,struct kvec *rsp, +int *rsp_buftype);extern int CIFSSMBQuerySymLink (const unsigned int xid,struct cifs_tcon *tcon,__u16 fid,char **symlinkinfo,const struct nls_table *nls_codepage);
@@ -659,6 +665,9 @@ void cifs_put_tcp_super(struct super_block *sb);int cifs_update_super_prepath (struct cifs_sb_info *cifs_sb,char *prefix);char *extract_hostname (const char *unc);char *extract_sharename (const char *unc); +int parse_reparse_point (struct reparse_data_buffer *buf, +u32 plen,struct cifs_sb_info *cifs_sb, +bool unicode,char **target_path);#ifdef CONFIG_CIFS_DFS_UPCALL static inline int get_dfs_path(const unsigned int xid, struct cifs_ses *ses,
fs/smb/client/cifssmb.c +75 -114
211 lines not on this page · raw message
fs/smb/client/smb1ops.c +10 -39
71 lines not on this page · raw message
fs/smb/client/smb2ops.c +16 -19
@@ -2894,27 +2894,26 @@ parse_reparse_posix(struct reparse_posix_data *symlink_buf,return 0 ; } -static int -parse_reparse_symlink (struct reparse_symlink_data_buffer *symlink_buf, -u32 plen,char **target_path, -struct cifs_sb_info *cifs_sb) +static int parse_reparse_symlink (struct reparse_symlink_data_buffer *sym, +u32 plen,bool unicode,char **target_path, +struct cifs_sb_info *cifs_sb) {unsigned int sub_len;unsigned int sub_offset;/* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */ - sub_offset =le16_to_cpu (symlink_buf->SubstituteNameOffset); - sub_len =le16_to_cpu (symlink_buf->SubstituteNameLength); + sub_offset =le16_to_cpu (sym->SubstituteNameOffset); + sub_len =le16_to_cpu (sym->SubstituteNameLength);if (sub_offset +20 > plen || sub_offset + sub_len +20 > plen) {cifs_dbg (VFS ,"srv returned malformed symlink buffer\n" );return -EIO ; } - *target_path =cifs_strndup_from_utf16 ( - symlink_buf->PathBuffer + sub_offset, - sub_len, true, cifs_sb->local_nls); + *target_path =cifs_strndup_from_utf16 (sym->PathBuffer + sub_offset, + sub_len, unicode, + cifs_sb->local_nls);if (!(*target_path))return -ENOMEM ;
@@ -2924,19 +2923,17 @@ parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,return 0 ; } -static int -parse_reparse_point (struct reparse_data_buffer *buf, -u32 plen,char **target_path, -struct cifs_sb_info *cifs_sb) +int parse_reparse_point (struct reparse_data_buffer *buf, +u32 plen,struct cifs_sb_info *cifs_sb, +bool unicode,char **target_path) { -if (plen <sizeof (struct reparse_data_buffer )) { +if (plen <sizeof (*buf)) {cifs_dbg (VFS ,"reparse buffer is too small. Must be at least 8 bytes but was %d\n" , plen);return -EIO ; } -if (plen <le16_to_cpu (buf->ReparseDataLength) + -sizeof (struct reparse_data_buffer )) { +if (plen <le16_to_cpu (buf->ReparseDataLength) +sizeof (*buf)) {cifs_dbg (VFS ,"srv returned invalid reparse buf length: %d\n" , plen);return -EIO ;
@@ -2951,7 +2948,7 @@ parse_reparse_point(struct reparse_data_buffer *buf,case IO_REPARSE_TAG_SYMLINK :return parse_reparse_symlink ( (struct reparse_symlink_data_buffer *)buf, - plen, target_path, cifs_sb); + plen, unicode, target_path, cifs_sb);default :cifs_dbg (VFS ,"srv returned unknown symlink buffer tag:0x%08x\n" ,le32_to_cpu (buf->ReparseTag));
@@ -2970,11 +2967,11 @@ static int smb2_query_symlink(const unsigned int xid,struct smb2_ioctl_rsp *io = rsp_iov->iov_base;u32 plen =le32_to_cpu (io->OutputCount); -cifs_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); +cifs_tcon_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); buf = (struct reparse_data_buffer *)((u8 *)io +le32_to_cpu (io->OutputOffset)); -return parse_reparse_point (buf, plen, target_path, cifs_sb); +return parse_reparse_point (buf, plen, cifs_sb, true, target_path); } static int smb2_query_reparse_point(const unsigned int xid,
Signature · 1 line
2.42.1
PATCH v2 2/3 smb: client: introduce ->parse_reparse_point()
Parse reparse point into cifs_open_info_data structure and feed it through cifs_open_info_to_fattr().
---
v1 -> v2: add missing WSL reparse point check in parse_reparse_point() to avoid returning -EOPNOTSUPP on them. Reported by Steve.
fs/smb/client/cifsglob.h | 6 ++++-- fs/smb/client/inode.c | 23 +++++++++++++--------- fs/smb/client/smb1ops.c | 41 ++++++++++++++++++++++------------------ fs/smb/client/smb2ops.c | 28 ++++++++++++++------------- 4 files changed, 56 insertions(+), 42 deletions(-)
fs/smb/client/cifsglob.h +4 -2
@@ -395,8 +395,7 @@ struct smb_version_operations {struct cifs_tcon *tcon, struct cifs_sb_info *cifs_sb, const char *full_path, - char **target_path, - struct kvec *rsp_iov); + char **target_path);/* open a file for non-posix mounts */ int (*open)(const unsigned int xid,struct cifs_open_parms *oparms,__u32 *oplock,void *buf);
@@ -551,6 +550,9 @@ struct smb_version_operations {bool (*is_status_io_timeout)(char *buf);/* Check for STATUS_NETWORK_NAME_DELETED */ bool (*is_network_name_deleted)(char *buf,struct TCP_Server_Info *srv); +int (*parse_reparse_point)(struct cifs_sb_info *cifs_sb, +struct kvec *rsp_iov, +struct cifs_open_info_data *data); };struct smb_version_values {
fs/smb/client/inode.c +14 -9
@@ -459,8 +459,7 @@ static int cifs_get_unix_fattr(const unsigned char *full_path,return -EOPNOTSUPP ; rc = server->ops->query_symlink (xid, tcon, cifs_sb, full_path, - &fattr->cf_symlink_target, -NULL ); + &fattr->cf_symlink_target);cifs_dbg (FYI ,"%s: query_symlink: %d\n" , __func__, rc); }return rc;
@@ -1035,22 +1034,28 @@ static int reparse_info_to_fattr(struct cifs_open_info_data *data,if (!rc) iov = &rsp_iov; } + + rc = -EOPNOTSUPP ;switch ((data->reparse_tag = tag)) {case 0 :/* SMB1 symlink */ - iov =NULL ; - fallthrough; -case IO_REPARSE_TAG_NFS : -case IO_REPARSE_TAG_SYMLINK : -if (!data->symlink_target && server->ops->query_symlink) { +if (server->ops->query_symlink) { rc = server->ops->query_symlink (xid, tcon, cifs_sb, full_path, - &data->symlink_target, - iov); + &data->symlink_target); }break ;case IO_REPARSE_TAG_MOUNT_POINT :cifs_create_junction_fattr (fattr, sb); + rc =0 ; goto out; +default : +if (data->symlink_target) { + rc =0 ; + }else if (server->ops->parse_reparse_point) { + rc = server->ops->parse_reparse_point (cifs_sb, + iov, data); + } +break ; }cifs_open_info_to_fattr (fattr, data, sb);
fs/smb/client/smb1ops.c +23 -18
61 lines not on this page · raw message
fs/smb/client/smb2ops.c +15 -13
@@ -2949,6 +2949,12 @@ int parse_reparse_point(struct reparse_data_buffer *buf,return parse_reparse_symlink ( (struct reparse_symlink_data_buffer *)buf, plen, unicode, target_path, cifs_sb); +case IO_REPARSE_TAG_LX_SYMLINK : +case IO_REPARSE_TAG_AF_UNIX : +case IO_REPARSE_TAG_LX_FIFO : +case IO_REPARSE_TAG_LX_CHR : +case IO_REPARSE_TAG_LX_BLK : +return 0 ;default :cifs_dbg (VFS ,"srv returned unknown symlink buffer tag:0x%08x\n" ,le32_to_cpu (buf->ReparseTag));
@@ -2956,22 +2962,18 @@ int parse_reparse_point(struct reparse_data_buffer *buf, } } -static int smb2_query_symlink (const unsigned int xid, -struct cifs_tcon *tcon, -struct cifs_sb_info *cifs_sb, -const char *full_path, -char **target_path, -struct kvec *rsp_iov) +static int smb2_parse_reparse_point (struct cifs_sb_info *cifs_sb, +struct kvec *rsp_iov, +struct cifs_open_info_data *data) {struct reparse_data_buffer *buf;struct smb2_ioctl_rsp *io = rsp_iov->iov_base;u32 plen =le32_to_cpu (io->OutputCount); -cifs_tcon_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); - buf = (struct reparse_data_buffer *)((u8 *)io +le32_to_cpu (io->OutputOffset)); -return parse_reparse_point (buf, plen, cifs_sb, true, target_path); +return parse_reparse_point (buf, plen, cifs_sb, + true, &data->symlink_target); } static int smb2_query_reparse_point(const unsigned int xid,
@@ -5206,7 +5208,7 @@ struct smb_version_operations smb20_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, - .query_symlink = smb2_query_symlink, + .parse_reparse_point = smb2_parse_reparse_point, .query_mf_symlink = smb3_query_mf_symlink, .create_mf_symlink = smb3_create_mf_symlink, .open = smb2_open_file,
@@ -5308,7 +5310,7 @@ struct smb_version_operations smb21_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, - .query_symlink = smb2_query_symlink, + .parse_reparse_point = smb2_parse_reparse_point, .query_mf_symlink = smb3_query_mf_symlink, .create_mf_symlink = smb3_create_mf_symlink, .open = smb2_open_file,
@@ -5413,7 +5415,7 @@ struct smb_version_operations smb30_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, - .query_symlink = smb2_query_symlink, + .parse_reparse_point = smb2_parse_reparse_point, .query_mf_symlink = smb3_query_mf_symlink, .create_mf_symlink = smb3_create_mf_symlink, .open = smb2_open_file,
@@ -5527,7 +5529,7 @@ struct smb_version_operations smb311_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, - .query_symlink = smb2_query_symlink, + .parse_reparse_point = smb2_parse_reparse_point, .query_mf_symlink = smb3_query_mf_symlink, .create_mf_symlink = smb3_create_mf_symlink, .open = smb2_open_file,
Signature · 1 line
2.42.1
PATCH v2 3/3 smb: client: set correct file type from NFS reparse points
In reply to Paulo AlcantaraHandle all file types in NFS reparse points as specified in MS-FSCC 2.1.2.6 Network File System (NFS) Reparse Data Buffer.
The client is now able to set all file types based on the parsed NFS reparse point, which used to support only symlinks. This works for SMB1+.
Before patch:
$ mount.cifs //srv/share /mnt -o ... $ ls -l /mnt ls: cannot access 'block': Operation not supported ls: cannot access 'char': Operation not supported ls: cannot access 'fifo': Operation not supported ls: cannot access 'sock': Operation not supported total 1 l????????? ? ? ? ? ? block l????????? ? ? ? ? ? char -rwxr-xr-x 1 root root 5 Nov 18 23:22 f0 l????????? ? ? ? ? ? fifo l--------- 1 root root 0 Nov 18 23:23 link -> f0 l????????? ? ? ? ? ? sock
After patch:
$ mount.cifs //srv/share /mnt -o ... $ ls -l /mnt total 1 brwxr-xr-x 1 root root 123, 123 Nov 18 00:34 block crwxr-xr-x 1 root root 1234, 1234 Nov 18 00:33 char -rwxr-xr-x 1 root root 5 Nov 18 23:22 f0 prwxr-xr-x 1 root root 0 Nov 18 23:23 fifo lrwxr-xr-x 1 root root 0 Nov 18 23:23 link -> f0 srwxr-xr-x 1 root root 0 Nov 19 2023 sock
--- fs/smb/client/cifsglob.h | 8 +++- fs/smb/client/cifspdu.h | 2 +- fs/smb/client/cifsproto.h | 4 +- fs/smb/client/inode.c | 51 ++++++++++++++++++-- fs/smb/client/readdir.c | 6 ++- fs/smb/client/smb1ops.c | 3 +- fs/smb/client/smb2inode.c | 2 +- fs/smb/client/smb2ops.c | 99 ++++++++++++++++++++------------------- 8 files changed, 115 insertions(+), 60 deletions(-)
fs/smb/client/cifsglob.h +7 -1
@@ -191,7 +191,13 @@ struct cifs_open_info_data {bool reparse_point;bool symlink; }; -__u32 reparse_tag; +struct { +__u32 tag; +union { +struct reparse_data_buffer *buf; +struct reparse_posix_data *posix; + }; + } reparse;char *symlink_target;union {struct smb2_file_all_info fi;
fs/smb/client/cifspdu.h +1 -1
@@ -1509,7 +1509,7 @@ struct reparse_posix_data {__le16 ReparseDataLength;__u16 Reserved;__le64 InodeType;/* LNK, FIFO, CHR etc. */ -char PathBuffer[]; +__u8 DataBuffer[]; } __attribute__((packed));struct cifs_quota_data {
fs/smb/client/cifsproto.h +2 -2
@@ -210,7 +210,7 @@ int cifs_get_inode_info(struct inode **inode, const char *full_path, const struct cifs_fid *fid);bool cifs_reparse_point_to_fattr (struct cifs_sb_info *cifs_sb,struct cifs_fattr *fattr, -u32 tag); +struct cifs_open_info_data *data);extern int smb311_posix_get_inode_info (struct inode **pinode,const char *search_path,struct super_block *sb,unsigned int xid); extern int cifs_get_inode_info_unix(struct inode **pinode,
@@ -667,7 +667,7 @@ char *extract_hostname(const char *unc);char *extract_sharename (const char *unc);int parse_reparse_point (struct reparse_data_buffer *buf,u32 plen,struct cifs_sb_info *cifs_sb, -bool unicode,char **target_path); +bool unicode,struct cifs_open_info_data *data);#ifdef CONFIG_CIFS_DFS_UPCALL static inline int get_dfs_path(const unsigned int xid, struct cifs_ses *ses,
fs/smb/client/inode.c +46 -5
84 lines not on this page · raw message
fs/smb/client/readdir.c +5 -1
@@ -153,6 +153,10 @@ static bool reparse_file_needs_reval(const struct cifs_fattr *fattr)static void cifs_fill_common_info (struct cifs_fattr *fattr,struct cifs_sb_info *cifs_sb) { +struct cifs_open_info_data data = { + .reparse = { .tag = fattr->cf_cifstag, }, + }; + fattr->cf_uid = cifs_sb->ctx->linux_uid; fattr->cf_gid = cifs_sb->ctx->linux_gid;
@@ -165,7 +169,7 @@ cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb)* reasonably map some of them to directories vs. files vs. symlinks */ if ((fattr->cf_cifsattrs &ATTR_REPARSE ) && -cifs_reparse_point_to_fattr (cifs_sb, fattr, fattr->cf_cifstag)) +cifs_reparse_point_to_fattr (cifs_sb, fattr, &data)) goto out_reparse;if (fattr->cf_cifsattrs &ATTR_DIRECTORY ) {
fs/smb/client/smb1ops.c +1 -2
@@ -1004,8 +1004,7 @@ static int cifs_parse_reparse_point(struct cifs_sb_info *cifs_sb, buf = (struct reparse_data_buffer *)((__u8 *)&io->hdr.Protocol +le32_to_cpu (io->DataOffset)); -return parse_reparse_point (buf, plen, cifs_sb, unicode, - &data->symlink_target); +return parse_reparse_point (buf, plen, cifs_sb, unicode, data); } static bool
fs/smb/client/smb2inode.c +1 -1
@@ -555,7 +555,7 @@ static int parse_create_response(struct cifs_open_info_data *data,break ; } data->reparse_point = reparse_point; - data->reparse_tag = tag; + data->reparse.tag = tag;return rc; }
fs/smb/client/smb2ops.c +52 -47
157 lines not on this page · raw message
Signature · 1 line
2.42.1
Re: [PATCH v2 3/3] smb: client: set correct file type from NFS reparse points
Hi Paulo,
Quoted 6 lines · Paulo Alcantara
Handle all file types in NFS reparse points as specified in MS-FSCC 2.1.2.6 Network File System (NFS) Reparse Data Buffer.
The client is now able to set all file types based on the parsed NFS reparse point, which used to support only symlinks. This works for SMB1+.
any plans to also implement this for SMB3 UNIX Extensions?
Cheers!
-slow
Re: [PATCH v2 3/3] smb: client: set correct file type from NFS reparse points
Hi Ralph,
Quoted 8 lines · Ralph Boehme
Quoted 6 lines · Paulo Alcantara
Handle all file types in NFS reparse points as specified in MS-FSCC 2.1.2.6 Network File System (NFS) Reparse Data Buffer.
The client is now able to set all file types based on the parsed NFS reparse point, which used to support only symlinks. This works for SMB1+.
any plans to also implement this for SMB3 UNIX Extensions?
Absolutely. Just wanted to make sure that these worked only in the code paths where we actually handle reparse points.
I also plan sending patches to support creating special files via NFS reparse points and make it default when not using SFU via mount option.
Re: [PATCH v2 3/3] smb: client: set correct file type from NFS reparse points
Quoted 11 lines · Paulo Alcantara
Hi Ralph,
Quoted 7 lines · Ralph Boehme
Quoted 6 lines · Paulo Alcantara
Handle all file types in NFS reparse points as specified in MS-FSCC 2.1.2.6 Network File System (NFS) Reparse Data Buffer.
The client is now able to set all file types based on the parsed NFS reparse point, which used to support only symlinks. This works for SMB1+.
Quoted 7 lines
Quoted 1 line
any plans to also implement this for SMB3 UNIX Extensions?
Absolutely. Just wanted to make sure that these worked only in the code paths where we actually handle reparse points.
I also plan sending patches to support creating special files via NFS reparse points and make it default when not using SFU via mount option.
awesome! :)
-slow
PATCH 1/7 smb: client: implement ->query_reparse_point() for SMB1
In reply to Paulo AlcantaraReparse points are not limited to symlinks, so implement ->query_reparse_point() in order to handle different file types.
--- fs/smb/client/cifspdu.h | 2 +- fs/smb/client/cifsproto.h | 9 ++ fs/smb/client/cifssmb.c | 189 +++++++++++++++----------------------- fs/smb/client/smb1ops.c | 49 ++-------- fs/smb/client/smb2ops.c | 35 ++++--- 5 files changed, 111 insertions(+), 173 deletions(-)
fs/smb/client/cifspdu.h +1 -1
@@ -1356,7 +1356,7 @@ typedef struct smb_com_transaction_ioctl_rsp {__le32 DataDisplacement;__u8 SetupCount;/* 1 */ __le16 ReturnedDataLen; -__u16 ByteCount; +__le16 ByteCount; } __attribute__((packed)) TRANSACT_IOCTL_RSP;#define CIFS_ACL_OWNER 1
fs/smb/client/cifsproto.h +9 -0
@@ -458,6 +458,12 @@ extern int CIFSSMBUnixQuerySymLink(const unsigned int xid,struct cifs_tcon *tcon, const unsigned char *searchName, char **syminfo, const struct nls_table *nls_codepage, int remap); +extern int cifs_query_reparse_point (const unsigned int xid, +struct cifs_tcon *tcon, +struct cifs_sb_info *cifs_sb, +const char *full_path, +u32 *tag,struct kvec *rsp, +int *rsp_buftype);extern int CIFSSMBQuerySymLink (const unsigned int xid,struct cifs_tcon *tcon,__u16 fid,char **symlinkinfo,const struct nls_table *nls_codepage);
@@ -659,6 +665,9 @@ void cifs_put_tcp_super(struct super_block *sb);int cifs_update_super_prepath (struct cifs_sb_info *cifs_sb,char *prefix);char *extract_hostname (const char *unc);char *extract_sharename (const char *unc); +int parse_reparse_point (struct reparse_data_buffer *buf, +u32 plen,struct cifs_sb_info *cifs_sb, +bool unicode,char **target_path);#ifdef CONFIG_CIFS_DFS_UPCALL static inline int get_dfs_path(const unsigned int xid, struct cifs_ses *ses,
fs/smb/client/cifssmb.c +75 -114
211 lines not on this page · raw message
fs/smb/client/smb1ops.c +10 -39
71 lines not on this page · raw message
fs/smb/client/smb2ops.c +16 -19
@@ -2894,27 +2894,26 @@ parse_reparse_posix(struct reparse_posix_data *symlink_buf,return 0 ; } -static int -parse_reparse_symlink (struct reparse_symlink_data_buffer *symlink_buf, -u32 plen,char **target_path, -struct cifs_sb_info *cifs_sb) +static int parse_reparse_symlink (struct reparse_symlink_data_buffer *sym, +u32 plen,bool unicode,char **target_path, +struct cifs_sb_info *cifs_sb) {unsigned int sub_len;unsigned int sub_offset;/* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */ - sub_offset =le16_to_cpu (symlink_buf->SubstituteNameOffset); - sub_len =le16_to_cpu (symlink_buf->SubstituteNameLength); + sub_offset =le16_to_cpu (sym->SubstituteNameOffset); + sub_len =le16_to_cpu (sym->SubstituteNameLength);if (sub_offset +20 > plen || sub_offset + sub_len +20 > plen) {cifs_dbg (VFS ,"srv returned malformed symlink buffer\n" );return -EIO ; } - *target_path =cifs_strndup_from_utf16 ( - symlink_buf->PathBuffer + sub_offset, - sub_len, true, cifs_sb->local_nls); + *target_path =cifs_strndup_from_utf16 (sym->PathBuffer + sub_offset, + sub_len, unicode, + cifs_sb->local_nls);if (!(*target_path))return -ENOMEM ;
@@ -2924,19 +2923,17 @@ parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,return 0 ; } -static int -parse_reparse_point (struct reparse_data_buffer *buf, -u32 plen,char **target_path, -struct cifs_sb_info *cifs_sb) +int parse_reparse_point (struct reparse_data_buffer *buf, +u32 plen,struct cifs_sb_info *cifs_sb, +bool unicode,char **target_path) { -if (plen <sizeof (struct reparse_data_buffer )) { +if (plen <sizeof (*buf)) {cifs_dbg (VFS ,"reparse buffer is too small. Must be at least 8 bytes but was %d\n" , plen);return -EIO ; } -if (plen <le16_to_cpu (buf->ReparseDataLength) + -sizeof (struct reparse_data_buffer )) { +if (plen <le16_to_cpu (buf->ReparseDataLength) +sizeof (*buf)) {cifs_dbg (VFS ,"srv returned invalid reparse buf length: %d\n" , plen);return -EIO ;
@@ -2951,7 +2948,7 @@ parse_reparse_point(struct reparse_data_buffer *buf,case IO_REPARSE_TAG_SYMLINK :return parse_reparse_symlink ( (struct reparse_symlink_data_buffer *)buf, - plen, target_path, cifs_sb); + plen, unicode, target_path, cifs_sb);default :cifs_dbg (VFS ,"srv returned unknown symlink buffer tag:0x%08x\n" ,le32_to_cpu (buf->ReparseTag));
@@ -2970,11 +2967,11 @@ static int smb2_query_symlink(const unsigned int xid,struct smb2_ioctl_rsp *io = rsp_iov->iov_base;u32 plen =le32_to_cpu (io->OutputCount); -cifs_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); +cifs_tcon_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); buf = (struct reparse_data_buffer *)((u8 *)io +le32_to_cpu (io->OutputOffset)); -return parse_reparse_point (buf, plen, target_path, cifs_sb); +return parse_reparse_point (buf, plen, cifs_sb, true, target_path); } static int smb2_query_reparse_point(const unsigned int xid,
Signature · 1 line
2.42.1
PATCH 2/7 smb: client: introduce ->parse_reparse_point()
Parse reparse point into cifs_open_info_data structure and feed it through cifs_open_info_to_fattr().
--- fs/smb/client/cifsglob.h | 6 ++++-- fs/smb/client/inode.c | 23 +++++++++++++--------- fs/smb/client/smb1ops.c | 41 ++++++++++++++++++++++------------------ fs/smb/client/smb2ops.c | 28 ++++++++++++++------------- 4 files changed, 56 insertions(+), 42 deletions(-)
fs/smb/client/cifsglob.h +4 -2
@@ -395,8 +395,7 @@ struct smb_version_operations {struct cifs_tcon *tcon, struct cifs_sb_info *cifs_sb, const char *full_path, - char **target_path, - struct kvec *rsp_iov); + char **target_path);/* open a file for non-posix mounts */ int (*open)(const unsigned int xid,struct cifs_open_parms *oparms,__u32 *oplock,void *buf);
@@ -551,6 +550,9 @@ struct smb_version_operations {bool (*is_status_io_timeout)(char *buf);/* Check for STATUS_NETWORK_NAME_DELETED */ bool (*is_network_name_deleted)(char *buf,struct TCP_Server_Info *srv); +int (*parse_reparse_point)(struct cifs_sb_info *cifs_sb, +struct kvec *rsp_iov, +struct cifs_open_info_data *data); };struct smb_version_values {
fs/smb/client/inode.c +14 -9
@@ -459,8 +459,7 @@ static int cifs_get_unix_fattr(const unsigned char *full_path,return -EOPNOTSUPP ; rc = server->ops->query_symlink (xid, tcon, cifs_sb, full_path, - &fattr->cf_symlink_target, -NULL ); + &fattr->cf_symlink_target);cifs_dbg (FYI ,"%s: query_symlink: %d\n" , __func__, rc); }return rc;
@@ -1035,22 +1034,28 @@ static int reparse_info_to_fattr(struct cifs_open_info_data *data,if (!rc) iov = &rsp_iov; } + + rc = -EOPNOTSUPP ;switch ((data->reparse_tag = tag)) {case 0 :/* SMB1 symlink */ - iov =NULL ; - fallthrough; -case IO_REPARSE_TAG_NFS : -case IO_REPARSE_TAG_SYMLINK : -if (!data->symlink_target && server->ops->query_symlink) { +if (server->ops->query_symlink) { rc = server->ops->query_symlink (xid, tcon, cifs_sb, full_path, - &data->symlink_target, - iov); + &data->symlink_target); }break ;case IO_REPARSE_TAG_MOUNT_POINT :cifs_create_junction_fattr (fattr, sb); + rc =0 ; goto out; +default : +if (data->symlink_target) { + rc =0 ; + }else if (server->ops->parse_reparse_point) { + rc = server->ops->parse_reparse_point (cifs_sb, + iov, data); + } +break ; }cifs_open_info_to_fattr (fattr, data, sb);
fs/smb/client/smb1ops.c +23 -18
61 lines not on this page · raw message
fs/smb/client/smb2ops.c +15 -13
@@ -2949,6 +2949,12 @@ int parse_reparse_point(struct reparse_data_buffer *buf,return parse_reparse_symlink ( (struct reparse_symlink_data_buffer *)buf, plen, unicode, target_path, cifs_sb); +case IO_REPARSE_TAG_LX_SYMLINK : +case IO_REPARSE_TAG_AF_UNIX : +case IO_REPARSE_TAG_LX_FIFO : +case IO_REPARSE_TAG_LX_CHR : +case IO_REPARSE_TAG_LX_BLK : +return 0 ;default :cifs_dbg (VFS ,"srv returned unknown symlink buffer tag:0x%08x\n" ,le32_to_cpu (buf->ReparseTag));
@@ -2956,22 +2962,18 @@ int parse_reparse_point(struct reparse_data_buffer *buf, } } -static int smb2_query_symlink (const unsigned int xid, -struct cifs_tcon *tcon, -struct cifs_sb_info *cifs_sb, -const char *full_path, -char **target_path, -struct kvec *rsp_iov) +static int smb2_parse_reparse_point (struct cifs_sb_info *cifs_sb, +struct kvec *rsp_iov, +struct cifs_open_info_data *data) {struct reparse_data_buffer *buf;struct smb2_ioctl_rsp *io = rsp_iov->iov_base;u32 plen =le32_to_cpu (io->OutputCount); -cifs_tcon_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); - buf = (struct reparse_data_buffer *)((u8 *)io +le32_to_cpu (io->OutputOffset)); -return parse_reparse_point (buf, plen, cifs_sb, true, target_path); +return parse_reparse_point (buf, plen, cifs_sb, + true, &data->symlink_target); } static int smb2_query_reparse_point(const unsigned int xid,
@@ -5206,7 +5208,7 @@ struct smb_version_operations smb20_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, - .query_symlink = smb2_query_symlink, + .parse_reparse_point = smb2_parse_reparse_point, .query_mf_symlink = smb3_query_mf_symlink, .create_mf_symlink = smb3_create_mf_symlink, .open = smb2_open_file,
@@ -5308,7 +5310,7 @@ struct smb_version_operations smb21_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, - .query_symlink = smb2_query_symlink, + .parse_reparse_point = smb2_parse_reparse_point, .query_mf_symlink = smb3_query_mf_symlink, .create_mf_symlink = smb3_create_mf_symlink, .open = smb2_open_file,
@@ -5413,7 +5415,7 @@ struct smb_version_operations smb30_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, - .query_symlink = smb2_query_symlink, + .parse_reparse_point = smb2_parse_reparse_point, .query_mf_symlink = smb3_query_mf_symlink, .create_mf_symlink = smb3_create_mf_symlink, .open = smb2_open_file,
@@ -5527,7 +5529,7 @@ struct smb_version_operations smb311_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, - .query_symlink = smb2_query_symlink, + .parse_reparse_point = smb2_parse_reparse_point, .query_mf_symlink = smb3_query_mf_symlink, .create_mf_symlink = smb3_create_mf_symlink, .open = smb2_open_file,
Signature · 1 line
2.42.1
PATCH 3/7 smb: client: set correct file type from NFS reparse points
In reply to Paulo AlcantaraHandle all file types in NFS reparse points as specified in MS-FSCC 2.1.2.6 Network File System (NFS) Reparse Data Buffer.
The client is now able to set all file types based on the parsed NFS reparse point, which used to support only symlinks. This works for SMB1+.
Before patch:
$ mount.cifs //srv/share /mnt -o ... $ ls -l /mnt ls: cannot access 'block': Operation not supported ls: cannot access 'char': Operation not supported ls: cannot access 'fifo': Operation not supported ls: cannot access 'sock': Operation not supported total 1 l????????? ? ? ? ? ? block l????????? ? ? ? ? ? char -rwxr-xr-x 1 root root 5 Nov 18 23:22 f0 l????????? ? ? ? ? ? fifo l--------- 1 root root 0 Nov 18 23:23 link -> f0 l????????? ? ? ? ? ? sock
After patch:
$ mount.cifs //srv/share /mnt -o ... $ ls -l /mnt total 1 brwxr-xr-x 1 root root 123, 123 Nov 18 00:34 block crwxr-xr-x 1 root root 1234, 1234 Nov 18 00:33 char -rwxr-xr-x 1 root root 5 Nov 18 23:22 f0 prwxr-xr-x 1 root root 0 Nov 18 23:23 fifo lrwxr-xr-x 1 root root 0 Nov 18 23:23 link -> f0 srwxr-xr-x 1 root root 0 Nov 19 2023 sock
--- fs/smb/client/cifsglob.h | 8 +++- fs/smb/client/cifspdu.h | 2 +- fs/smb/client/cifsproto.h | 4 +- fs/smb/client/inode.c | 51 ++++++++++++++++++-- fs/smb/client/readdir.c | 6 ++- fs/smb/client/smb1ops.c | 3 +- fs/smb/client/smb2inode.c | 2 +- fs/smb/client/smb2ops.c | 99 ++++++++++++++++++++------------------- 8 files changed, 115 insertions(+), 60 deletions(-)
fs/smb/client/cifsglob.h +7 -1
@@ -191,7 +191,13 @@ struct cifs_open_info_data {bool reparse_point;bool symlink; }; -__u32 reparse_tag; +struct { +__u32 tag; +union { +struct reparse_data_buffer *buf; +struct reparse_posix_data *posix; + }; + } reparse;char *symlink_target;union {struct smb2_file_all_info fi;
fs/smb/client/cifspdu.h +1 -1
@@ -1509,7 +1509,7 @@ struct reparse_posix_data {__le16 ReparseDataLength;__u16 Reserved;__le64 InodeType;/* LNK, FIFO, CHR etc. */ -char PathBuffer[]; +__u8 DataBuffer[]; } __attribute__((packed));struct cifs_quota_data {
fs/smb/client/cifsproto.h +2 -2
@@ -210,7 +210,7 @@ int cifs_get_inode_info(struct inode **inode, const char *full_path, const struct cifs_fid *fid);bool cifs_reparse_point_to_fattr (struct cifs_sb_info *cifs_sb,struct cifs_fattr *fattr, -u32 tag); +struct cifs_open_info_data *data);extern int smb311_posix_get_inode_info (struct inode **pinode,const char *search_path,struct super_block *sb,unsigned int xid); extern int cifs_get_inode_info_unix(struct inode **pinode,
@@ -667,7 +667,7 @@ char *extract_hostname(const char *unc);char *extract_sharename (const char *unc);int parse_reparse_point (struct reparse_data_buffer *buf,u32 plen,struct cifs_sb_info *cifs_sb, -bool unicode,char **target_path); +bool unicode,struct cifs_open_info_data *data);#ifdef CONFIG_CIFS_DFS_UPCALL static inline int get_dfs_path(const unsigned int xid, struct cifs_ses *ses,
fs/smb/client/inode.c +46 -5
84 lines not on this page · raw message
fs/smb/client/readdir.c +5 -1
@@ -153,6 +153,10 @@ static bool reparse_file_needs_reval(const struct cifs_fattr *fattr)static void cifs_fill_common_info (struct cifs_fattr *fattr,struct cifs_sb_info *cifs_sb) { +struct cifs_open_info_data data = { + .reparse = { .tag = fattr->cf_cifstag, }, + }; + fattr->cf_uid = cifs_sb->ctx->linux_uid; fattr->cf_gid = cifs_sb->ctx->linux_gid;
@@ -165,7 +169,7 @@ cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb)* reasonably map some of them to directories vs. files vs. symlinks */ if ((fattr->cf_cifsattrs &ATTR_REPARSE ) && -cifs_reparse_point_to_fattr (cifs_sb, fattr, fattr->cf_cifstag)) +cifs_reparse_point_to_fattr (cifs_sb, fattr, &data)) goto out_reparse;if (fattr->cf_cifsattrs &ATTR_DIRECTORY ) {
fs/smb/client/smb1ops.c +1 -2
@@ -1004,8 +1004,7 @@ static int cifs_parse_reparse_point(struct cifs_sb_info *cifs_sb, buf = (struct reparse_data_buffer *)((__u8 *)&io->hdr.Protocol +le32_to_cpu (io->DataOffset)); -return parse_reparse_point (buf, plen, cifs_sb, unicode, - &data->symlink_target); +return parse_reparse_point (buf, plen, cifs_sb, unicode, data); } static bool
fs/smb/client/smb2inode.c +1 -1
@@ -555,7 +555,7 @@ static int parse_create_response(struct cifs_open_info_data *data,break ; } data->reparse_point = reparse_point; - data->reparse_tag = tag; + data->reparse.tag = tag;return rc; }
fs/smb/client/smb2ops.c +52 -47
157 lines not on this page · raw message
Signature · 1 line
2.42.1
PATCH 4/7 smb: client: introduce cifs_sfu_make_node()
In reply to Paulo AlcantaraRemove duplicate code and add new helper for creating special files in SFU (Services for UNIX) format that can be shared by SMB1+ code.
--- fs/smb/client/cifsproto.h | 3 ++ fs/smb/client/smb1ops.c | 80 ++++------------------------------- fs/smb/client/smb2ops.c | 89 ++++++++++++++++++--------------------- 3 files changed, 52 insertions(+), 120 deletions(-)
fs/smb/client/cifsproto.h +3 -0
@@ -668,6 +668,9 @@ char *extract_sharename(const char *unc);int parse_reparse_point (struct reparse_data_buffer *buf,u32 plen,struct cifs_sb_info *cifs_sb,bool unicode,struct cifs_open_info_data *data); +int cifs_sfu_make_node (unsigned int xid,struct inode *inode, +struct dentry *dentry,struct cifs_tcon *tcon, +const char *full_path,umode_t mode,dev_t dev);#ifdef CONFIG_CIFS_DFS_UPCALL static inline int get_dfs_path(const unsigned int xid, struct cifs_ses *ses,
fs/smb/client/smb1ops.c +8 -72
97 lines not on this page · raw message
fs/smb/client/smb2ops.c +41 -48
135 lines not on this page · raw message
Signature · 1 line
2.42.1
PATCH 5/7 smb: client: allow creating special files via reparse points
In reply to Paulo AlcantaraAdd support for creating special files (e.g. char/block devices, sockets, fifos) via NFS reparse points on SMB2+, which are fully supported by most SMB servers and documented in MS-FSCC.
--- fs/smb/client/inode.c | 3 +- fs/smb/client/smb2inode.c | 32 +++++++ fs/smb/client/smb2ops.c | 185 ++++++++++++++++++++++++++++++++++++-- fs/smb/client/smb2proto.h | 10 +++ 4 files changed, 220 insertions(+), 10 deletions(-)
fs/smb/client/inode.c +2 -1
@@ -1090,7 +1090,8 @@ static int reparse_info_to_fattr(struct cifs_open_info_data *data, rc =0 ; goto out;default : -if (data->symlink_target) { +/* Check for cached reparse point data */ +if (data->symlink_target || data->reparse.buf) { rc =0 ; }else if (server->ops->parse_reparse_point) { rc = server->ops->parse_reparse_point(cifs_sb,
fs/smb/client/smb2inode.c +32 -0
@@ -529,6 +529,38 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,return rc; } +struct inode *smb2_get_reparse_inode (struct cifs_open_info_data *data, +struct super_block *sb, +const unsigned int xid, +struct cifs_tcon *tcon, +const char *full_path) +{ +struct cifs_sb_info *cifs_sb =CIFS_SB (sb); +struct cifsFileInfo *cfile; +struct inode *new =NULL ; +int rc; + +if (tcon->posix_extensions) { + rc =smb311_posix_get_inode_info (&new, full_path, sb, xid); + }else { +/* +* Since we know it is a reparse point already, query info it +* directly and provide cached file metadata to +* cifs_get_inode_info() in order to avoid extra roundtrips. +*/ +cifs_get_readable_path (tcon, full_path, &cfile); + rc =smb2_compound_op (xid, tcon, cifs_sb, full_path, +FILE_READ_ATTRIBUTES ,FILE_OPEN , +OPEN_REPARSE_POINT ,ACL_NO_MODE , data, +SMB2_OP_QUERY_INFO , cfile,NULL ,NULL , +NULL ,NULL ); +if (rc) +return ERR_PTR (rc); + rc =cifs_get_inode_info (&new, full_path, data, sb, xid,NULL ); + } +return rc ?ERR_PTR (rc) : new; +} +static int parse_create_response (struct cifs_open_info_data *data,struct cifs_sb_info *cifs_sb,const struct kvec *iov)
fs/smb/client/smb2ops.c +176 -9
208 lines not on this page · raw message
fs/smb/client/smb2proto.h +10 -0
@@ -56,6 +56,11 @@ extern int smb3_handle_read_data(struct TCP_Server_Info *server,extern int smb2_query_reparse_tag (const unsigned int xid,struct cifs_tcon *tcon,struct cifs_sb_info *cifs_sb,const char *path,__u32 *reparse_tag); +struct inode *smb2_get_reparse_inode (struct cifs_open_info_data *data, +struct super_block *sb, +const unsigned int xid, +struct cifs_tcon *tcon, +const char *full_path); int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, struct cifs_sb_info *cifs_sb,
@@ -287,4 +292,9 @@ int smb311_posix_query_path_info(const unsigned int xid,int posix_info_parse (const void *beg,const void *end,struct smb2_posix_info_parsed *out);int posix_info_sid_size (const void *beg,const void *end); +int smb2_create_reparse_point (const unsigned int xid, +struct cifs_tcon *tcon, +struct cifs_sb_info *cifs_sb, +const char *full_path, +void *rbuf,u16 rsize);#endif /* _SMB2PROTO_H */
Signature · 1 line
2.42.1
Re: [PATCH 5/7] smb: client: allow creating special files via reparse points
Quoted 18 lines · Paulo Alcantara
fs/smb/client/smb2ops.c +18
-0+static int create_nfs_reparse (const unsigned int xid, +struct cifs_tcon *tcon, +struct cifs_sb_info *cifs_sb, +const char *full_path,mode_t mode, +struct reparse_posix_data *buf) +{ +u64 type; +u16 len, dlen; + + len =sizeof (*buf); + +switch ((type =mode_nfs_type (mode))) { +case NFS_SPECFILE_BLK : +case NFS_SPECFILE_CHR : + dlen =sizeof (__le64); +break ; +case NFS_SPECFILE_FIFO : +case NFS_SPECFILE_SOCK :
fs/smb/client/smb2ops.c int cifs_sfu_make_node(unsigned int xid, struct inode *inode, · line 5265
Quoted 10 lines
fs/smb/client/smb2ops.c +10
-0+ dlen =0 ; +break ; +default : +return -EOPNOTSUPP ; + } + + buf->ReparseTag =cpu_to_le32 (IO_REPARSE_TAG_NFS ); + buf->InodeType =cpu_to_le64 (type); + buf->ReparseDataLength =cpu_to_le16 (len + dlen - +sizeof (struct reparse_data_buffer ));
Err, forgot having @buf->Reserved set to 0 here, sorry. MS-FSCC doesnt't say we _must_ to, however it's better not sending garbage over the wire.
Let me know if you'd need v2 for the above.
PATCH 6/7 smb: client: allow creating symlinks via reparse points
In reply to Paulo AlcantaraAdd support for creating symlinks via IO_REPARSE_TAG_SYMLINK reparse points in SMB2+.
These are fully supported by most SMB servers and documented in MS-FSCC. Also have the advantage of requiring fewer roundtrips as their symlink targets can be parsed directly from CREATE responses on STATUS_STOPPED_ON_SYMLINK errors.
--- fs/smb/client/cifsglob.h | 6 ++++ fs/smb/client/link.c | 15 ++++++--- fs/smb/client/smb2ops.c | 70 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 5 deletions(-)
fs/smb/client/cifsglob.h +6 -0
@@ -559,6 +559,12 @@ struct smb_version_operations {int (*parse_reparse_point)(struct cifs_sb_info *cifs_sb,struct kvec *rsp_iov,struct cifs_open_info_data *data); +int (*create_reparse_symlink)(const unsigned int xid, +struct inode *inode, +struct dentry *dentry, +struct cifs_tcon *tcon, +const char *full_path, +const char *symname); };struct smb_version_values {
fs/smb/client/link.c +10 -5
@@ -569,6 +569,7 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode,int rc = -EOPNOTSUPP ;unsigned int xid;struct cifs_sb_info *cifs_sb =CIFS_SB (inode->i_sb); +struct TCP_Server_Info *server;struct tcon_link *tlink;struct cifs_tcon *pTcon;const char *full_path;
@@ -590,6 +591,7 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode, goto symlink_exit; } pTcon =tlink_tcon (tlink); + server =cifs_pick_channel (pTcon->ses); full_path =build_path_from_dentry (direntry, page);if (IS_ERR (full_path)) {
@@ -601,17 +603,20 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode,cifs_dbg (FYI ,"symname is %s\n" , symname);/* BB what if DFS and this volume is on different share? BB */ -if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MF_SYMLINKS ) +if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MF_SYMLINKS ) { rc =create_mf_symlink (xid, pTcon, cifs_sb, full_path, symname); #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY - else if (pTcon->unix_ext) + }else if (pTcon->unix_ext) { rc =CIFSUnixCreateSymLink (xid, pTcon, full_path, symname, cifs_sb->local_nls,cifs_remap (cifs_sb));#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ -/* else -rc = CIFSCreateReparseSymLink(xid, pTcon, fromName, toName, -cifs_sb_target->local_nls); */ + }else if (server->ops->create_reparse_symlink) { + rc = server->ops->create_reparse_symlink (xid, inode, direntry, + pTcon, full_path, + symname); + goto symlink_exit; + }if (rc ==0 ) {if (pTcon->posix_extensions)
fs/smb/client/smb2ops.c +70 -0
100 lines not on this page · raw message
Signature · 1 line
2.42.1
PATCH 7/7 smb: client: handle reparse points over SMB3 POSIX
In reply to Paulo AlcantaraAdd support for creating and listing special files via reparse points when using SMB3 POSIX extensions.
--- fs/smb/client/cifsproto.h | 8 +++-- fs/smb/client/dir.c | 7 ++-- fs/smb/client/file.c | 10 +++--- fs/smb/client/inode.c | 71 ++++++++++++++++++++++++++------------- fs/smb/client/link.c | 10 +++--- fs/smb/client/smb2inode.c | 21 ++++++++---- 6 files changed, 84 insertions(+), 43 deletions(-)
fs/smb/client/cifsproto.h +6 -2
@@ -211,8 +211,12 @@ int cifs_get_inode_info(struct inode **inode, const char *full_path,bool cifs_reparse_point_to_fattr (struct cifs_sb_info *cifs_sb,struct cifs_fattr *fattr,struct cifs_open_info_data *data); -extern int smb311_posix_get_inode_info (struct inode **pinode,const char *search_path, -struct super_block *sb,unsigned int xid); + +extern int smb311_posix_get_inode_info (struct inode **inode, +const char *full_path, +struct cifs_open_info_data *data, +struct super_block *sb, +const unsigned int xid);extern int cifs_get_inode_info_unix (struct inode **pinode,const unsigned char *search_path,struct super_block *sb,unsigned int xid);
fs/smb/client/dir.c +4 -3
@@ -680,9 +680,10 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, full_path, d_inode(direntry)); again: -if (pTcon->posix_extensions) - rc =smb311_posix_get_inode_info (&newInode, full_path, parent_dir_inode->i_sb, xid); -else if (pTcon->unix_ext) { +if (pTcon->posix_extensions) { + rc =smb311_posix_get_inode_info (&newInode, full_path,NULL , + parent_dir_inode->i_sb, xid); + }else if (pTcon->unix_ext) { rc =cifs_get_inode_info_unix (&newInode, full_path, parent_dir_inode->i_sb, xid); }else {
fs/smb/client/file.c +6 -4
@@ -1020,14 +1020,16 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)if (!is_interrupt_error (rc))mapping_set_error (inode->i_mapping, rc); -if (tcon->posix_extensions) - rc =smb311_posix_get_inode_info (&inode, full_path, inode->i_sb, xid); -else if (tcon->unix_ext) +if (tcon->posix_extensions) { + rc =smb311_posix_get_inode_info (&inode, full_path, +NULL , inode->i_sb, xid); + }else if (tcon->unix_ext) { rc =cifs_get_inode_info_unix (&inode, full_path, inode->i_sb, xid); -else + }else { rc =cifs_get_inode_info (&inode, full_path,NULL , inode->i_sb, xid,NULL ); + } }/* * Else we are writing out data to server already and could deadlock if
fs/smb/client/inode.c +47 -24
154 lines not on this page · raw message
fs/smb/client/link.c +6 -4
@@ -619,14 +619,16 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode, }if (rc ==0 ) { -if (pTcon->posix_extensions) - rc =smb311_posix_get_inode_info (&newinode, full_path, inode->i_sb, xid); -else if (pTcon->unix_ext) +if (pTcon->posix_extensions) { + rc =smb311_posix_get_inode_info (&newinode, full_path, +NULL , inode->i_sb, xid); + }else if (pTcon->unix_ext) { rc =cifs_get_inode_info_unix (&newinode, full_path, inode->i_sb, xid); -else + }else { rc =cifs_get_inode_info (&newinode, full_path,NULL , inode->i_sb, xid,NULL ); + }if (rc !=0 ) { cifs_dbg(FYI, "Create symlink ok, getinodeinfo fail rc = %d\n",
fs/smb/client/smb2inode.c +15 -6
@@ -540,14 +540,23 @@ struct inode *smb2_get_reparse_inode(struct cifs_open_info_data *data,struct inode *new =NULL ;int rc; +/* +* Since we know it is a reparse point already, query info it +* directly and provide cached file metadata to *get_inode_info() calls +* in order to avoid extra roundtrips. +*/ if (tcon->posix_extensions) { - rc =smb311_posix_get_inode_info (&new, full_path, sb, xid); +cifs_get_readable_path (tcon, full_path, &cfile); + rc =smb2_compound_op (xid, tcon, cifs_sb, full_path, +FILE_READ_ATTRIBUTES ,FILE_OPEN , +OPEN_REPARSE_POINT ,ACL_NO_MODE , data, +SMB2_OP_POSIX_QUERY_INFO , cfile,NULL , +NULL ,NULL ,NULL ); +if (rc) +return ERR_PTR (rc); + rc =smb311_posix_get_inode_info (&new, full_path, + data, sb, xid); }else { -/* -* Since we know it is a reparse point already, query info it -* directly and provide cached file metadata to -* cifs_get_inode_info() in order to avoid extra roundtrips. -*/ cifs_get_readable_path (tcon, full_path, &cfile); rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES, FILE_OPEN,
Signature · 1 line
2.42.1