diff mbox series

SMB3] Add support for WSL reparse tags

Message ID CAH2r5mvWqz2bMX9ut0bT4ZQH8WQNAc8Cjg3bM1TKeXgzupOZMQ@mail.gmail.com (mailing list archive)
State New, archived
Headers show
Series SMB3] Add support for WSL reparse tags | expand

Commit Message

Steve French Oct. 22, 2020, 5 a.m. UTC
The IO_REPARSE_TAG_LX_ tags originally were used by WSL but they
are preferred by the Linux client in some cases since, unlike
the NFS reparse tag (or EAs), they don't require an extra query
to determine which type of special file they represent.

Add support for readdir to recognize special file types of
FIFO, SOCKET, CHAR, BLOCK and SYMLINK.  This can be tested
by creating these special files in WSL Linux and then
sharing that location on the Windows server and mounting
to the Windows server to access them.

Prior to this patch all of the special files would show up
as being of type 'file' but with this patch they can be seen
with the correct file type as can be seen below:

  brwxr-xr-x 1 root root 0, 0 Oct 21 17:10 block
  crwxr-xr-x 1 root root 0, 0 Oct 21 17:46 char
  drwxr-xr-x 2 root root    0 Oct 21 18:27 dir
  prwxr-xr-x 1 root root    0 Oct 21 16:21 fifo
  -rwxr-xr-x 1 root root    0 Oct 21 15:48 file
  lrwxr-xr-x 1 root root    0 Oct 21 15:52 symlink-to-file

TODO: go through all documented reparse tags to see if we can
reasonably map some of them to directories vs. files vs. symlinks

Comments

Aurélien Aptel Oct. 22, 2020, 10:35 a.m. UTC | #1
Steve French <smfrench@gmail.com> writes:
> Prior to this patch all of the special files would show up
> as being of type 'file' but with this patch they can be seen
> with the correct file type as can be seen below:

TODO: Still cannot read the symlink target and the device major/minor numbers.

Reviewed-by: Aurelien Aptel <aaptel@suse.com>

Cheers,
ronnie sahlberg Oct. 23, 2020, 3:14 a.m. UTC | #2
Reviewed-by me

Very good.

On Thu, Oct 22, 2020 at 3:02 PM Steve French via samba-technical
<samba-technical@lists.samba.org> wrote:
>
> The IO_REPARSE_TAG_LX_ tags originally were used by WSL but they
> are preferred by the Linux client in some cases since, unlike
> the NFS reparse tag (or EAs), they don't require an extra query
> to determine which type of special file they represent.
>
> Add support for readdir to recognize special file types of
> FIFO, SOCKET, CHAR, BLOCK and SYMLINK.  This can be tested
> by creating these special files in WSL Linux and then
> sharing that location on the Windows server and mounting
> to the Windows server to access them.
>
> Prior to this patch all of the special files would show up
> as being of type 'file' but with this patch they can be seen
> with the correct file type as can be seen below:
>
>   brwxr-xr-x 1 root root 0, 0 Oct 21 17:10 block
>   crwxr-xr-x 1 root root 0, 0 Oct 21 17:46 char
>   drwxr-xr-x 2 root root    0 Oct 21 18:27 dir
>   prwxr-xr-x 1 root root    0 Oct 21 16:21 fifo
>   -rwxr-xr-x 1 root root    0 Oct 21 15:48 file
>   lrwxr-xr-x 1 root root    0 Oct 21 15:52 symlink-to-file
>
> TODO: go through all documented reparse tags to see if we can
> reasonably map some of them to directories vs. files vs. symlinks
>
> --
> Thanks,
>
> Steve
diff mbox series

Patch

From d9dc8174f13f7b437d9670a84ca8d41fc2110063 Mon Sep 17 00:00:00 2001
From: Steve French <stfrench@microsoft.com>
Date: Wed, 21 Oct 2020 23:54:19 -0500
Subject: [PATCH] SMB3: add support for recognizing WSL reparse tags

The IO_REPARSE_TAG_LX_ tags originally were used by WSL but they
are preferred by the Linux client in some cases since, unlike
the NFS reparse tag (or EAs), they don't require an extra query
to determine which type of special file they represent.

Add support for readdir to recognize special file types of
FIFO, SOCKET, CHAR, BLOCK and SYMLINK.  This can be tested
by creating these special files in WSL Linux and then
sharing that location on the Windows server and mounting
to the Windows server to access them.

Prior to this patch all of the special files would show up
as being of type 'file' but with this patch they can be seen
with the correct file type as can be seen below:

  brwxr-xr-x 1 root root 0, 0 Oct 21 17:10 block
  crwxr-xr-x 1 root root 0, 0 Oct 21 17:46 char
  drwxr-xr-x 2 root root    0 Oct 21 18:27 dir
  prwxr-xr-x 1 root root    0 Oct 21 16:21 fifo
  -rwxr-xr-x 1 root root    0 Oct 21 15:48 file
  lrwxr-xr-x 1 root root    0 Oct 21 15:52 symlink-to-file

TODO: go through all documented reparse tags to see if we can
reasonably map some of them to directories vs. files vs. symlinks

Signed-off-by: Steve French <stfrench@microsoft.com>
---
 fs/cifs/readdir.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index 5abf1ea21abe..799be3a5d25e 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -168,10 +168,33 @@  cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb)
 	fattr->cf_uid = cifs_sb->mnt_uid;
 	fattr->cf_gid = cifs_sb->mnt_gid;
 
+	/*
+	 * The IO_REPARSE_TAG_LX_ tags originally were used by WSL but they
+	 * are preferred by the Linux client in some cases since, unlike
+	 * the NFS reparse tag (or EAs), they don't require an extra query
+	 * to determine which type of special file they represent.
+	 * TODO: go through all documented  reparse tags to see if we can
+	 * reasonably map some of them to directories vs. files vs. symlinks
+	 */
 	if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
 		fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode;
 		fattr->cf_dtype = DT_DIR;
-	} else {
+	} else if (fattr->cf_cifstag == IO_REPARSE_TAG_LX_SYMLINK) {
+		fattr->cf_mode |= S_IFLNK | cifs_sb->mnt_file_mode;
+		fattr->cf_dtype = DT_LNK;
+	} else if (fattr->cf_cifstag == IO_REPARSE_TAG_LX_FIFO) {
+		fattr->cf_mode |= S_IFIFO | cifs_sb->mnt_file_mode;
+		fattr->cf_dtype = DT_FIFO;
+	} else if (fattr->cf_cifstag == IO_REPARSE_TAG_AF_UNIX) {
+		fattr->cf_mode |= S_IFSOCK | cifs_sb->mnt_file_mode;
+		fattr->cf_dtype = DT_SOCK;
+	} else if (fattr->cf_cifstag == IO_REPARSE_TAG_LX_CHR) {
+		fattr->cf_mode |= S_IFCHR | cifs_sb->mnt_file_mode;
+		fattr->cf_dtype = DT_CHR;
+	} else if (fattr->cf_cifstag == IO_REPARSE_TAG_LX_BLK) {
+		fattr->cf_mode |= S_IFBLK | cifs_sb->mnt_file_mode;
+		fattr->cf_dtype = DT_BLK;
+	} else { /* TODO: should we mark some other reparse points (like DFSR) as directories? */
 		fattr->cf_mode = S_IFREG | cifs_sb->mnt_file_mode;
 		fattr->cf_dtype = DT_REG;
 	}
-- 
2.25.1