]> www.infradead.org Git - users/willy/xarray.git/commitdiff
cifs: Add support for creating SFU symlinks
authorPali Rohár <pali@kernel.org>
Sun, 15 Sep 2024 19:45:42 +0000 (21:45 +0200)
committerSteve French <stfrench@microsoft.com>
Tue, 17 Sep 2024 01:10:34 +0000 (20:10 -0500)
Linux cifs client can already detect SFU symlinks and reads it content
(target location). But currently is not able to create new symlink. So
implement this missing support.

When 'sfu' mount option is specified and 'mfsymlinks' is not specified then
create new symlinks in SFU-style. This will provide full SFU compatibility
of symlinks when mounting cifs share with 'sfu' option. 'mfsymlinks' option
override SFU for better Apple compatibility as explained in fs_context.c
file in smb3_update_mnt_flags() function.

Extend __cifs_sfu_make_node() function, which now can handle also S_IFLNK
type and refactor structures passed to sync_write() in this function, by
splitting SFU type and SFU data from original combined struct win_dev as
combined fixed-length struct cannot be used for variable-length symlinks.

Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/cifspdu.h
fs/smb/client/cifsproto.h
fs/smb/client/fs_context.c
fs/smb/client/link.c
fs/smb/client/smb2ops.c

index a2072ab9e586d0d3ba34afe5bcab985b38537202..c3b6263060b0acb90fd7a672160b06c7b881ec3e 100644 (file)
@@ -2573,12 +2573,6 @@ typedef struct {
 } __attribute__((packed)) FIND_FILE_STANDARD_INFO; /* level 0x1 FF resp data */
 
 
-struct win_dev {
-       unsigned char type[8]; /* IntxCHR or IntxBLK or LnxFIFO or LnxSOCK */
-       __le64 major;
-       __le64 minor;
-} __attribute__((packed));
-
 struct fea {
        unsigned char EA_flags;
        __u8 name_len;
index 7066ec71d03335dd509006a1101994ca1642cb28..c69e3f48a60c52c88a67e77ab6c83a049364554a 100644 (file)
@@ -676,6 +676,10 @@ 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,
+                        const char *symname);
 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);
index 20dc31a07a56c881490b7c6273679e82dbc9af16..28c4e576d460aa2b91eccfab9fb9386a21f187ff 100644 (file)
@@ -1899,14 +1899,17 @@ void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb)
        if (ctx->mfsymlinks) {
                if (ctx->sfu_emul) {
                        /*
-                        * Our SFU ("Services for Unix" emulation does not allow
-                        * creating symlinks but does allow reading existing SFU
-                        * symlinks (it does allow both creating and reading SFU
-                        * style mknod and FIFOs though). When "mfsymlinks" and
+                        * Our SFU ("Services for Unix") emulation allows now
+                        * creating new and reading existing SFU symlinks.
+                        * Older Linux kernel versions were not able to neither
+                        * read existing nor create new SFU symlinks. But
+                        * creating and reading SFU style mknod and FIFOs was
+                        * supported for long time. When "mfsymlinks" and
                         * "sfu" are both enabled at the same time, it allows
                         * reading both types of symlinks, but will only create
                         * them with mfsymlinks format. This allows better
-                        * Apple compatibility (probably better for Samba too)
+                        * Apple compatibility, compatibility with older Linux
+                        * kernel clients (probably better for Samba too)
                         * while still recognizing old Windows style symlinks.
                         */
                        cifs_dbg(VFS, "mount options mfsymlinks and sfu both enabled\n");
index 80099bbb333b0847364161782cd361fe39b9dc91..47ddeb7fa1116b3eb50b5f8732b77aa35d8737d8 100644 (file)
@@ -606,6 +606,9 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode,
        /* BB what if DFS and this volume is on different share? BB */
        if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) {
                rc = create_mf_symlink(xid, pTcon, cifs_sb, full_path, symname);
+       } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
+               rc = __cifs_sfu_make_node(xid, inode, direntry, pTcon,
+                                         full_path, S_IFLNK, 0, symname);
 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
        } else if (pTcon->unix_ext) {
                rc = CIFSUnixCreateSymLink(xid, pTcon, full_path, symname,
index a5174bf41e51491478578232a0d6c73b172f3794..11452317b09028dc575b0913e3776a8327609b6f 100644 (file)
@@ -5055,9 +5055,10 @@ static int smb2_next_header(struct TCP_Server_Info *server, char *buf,
        return 0;
 }
 
-static int __cifs_sfu_make_node(unsigned int xid, struct inode *inode,
+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)
+                               const char *full_path, umode_t mode, dev_t dev,
+                               const char *symname)
 {
        struct TCP_Server_Info *server = tcon->ses->server;
        struct cifs_open_parms oparms;
@@ -5065,30 +5066,64 @@ static int __cifs_sfu_make_node(unsigned int xid, struct inode *inode,
        struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
        struct cifs_fid fid;
        unsigned int bytes_written;
-       struct win_dev pdev = {};
-       struct kvec iov[2];
+       u8 type[8];
+       int type_len = 0;
+       struct {
+               __le64 major;
+               __le64 minor;
+       } __packed pdev = {};
+       __le16 *symname_utf16 = NULL;
+       u8 *data = NULL;
+       int data_len = 0;
+       struct kvec iov[3];
        __u32 oplock = server->oplocks ? REQ_OPLOCK : 0;
        int rc;
 
        switch (mode & S_IFMT) {
        case S_IFCHR:
-               memcpy(pdev.type, "IntxCHR\0", 8);
+               type_len = 8;
+               memcpy(type, "IntxCHR\0", type_len);
                pdev.major = cpu_to_le64(MAJOR(dev));
                pdev.minor = cpu_to_le64(MINOR(dev));
+               data = (u8 *)&pdev;
+               data_len = sizeof(pdev);
                break;
        case S_IFBLK:
-               memcpy(pdev.type, "IntxBLK\0", 8);
+               type_len = 8;
+               memcpy(type, "IntxBLK\0", type_len);
                pdev.major = cpu_to_le64(MAJOR(dev));
                pdev.minor = cpu_to_le64(MINOR(dev));
+               data = (u8 *)&pdev;
+               data_len = sizeof(pdev);
+               break;
+       case S_IFLNK:
+               type_len = 8;
+               memcpy(type, "IntxLNK\1", type_len);
+               symname_utf16 = cifs_strndup_to_utf16(symname, strlen(symname),
+                                                     &data_len, cifs_sb->local_nls,
+                                                     NO_MAP_UNI_RSVD);
+               if (!symname_utf16) {
+                       rc = -ENOMEM;
+                       goto out;
+               }
+               data_len -= 2; /* symlink is without trailing wide-nul */
+               data = (u8 *)symname_utf16;
                break;
        case S_IFSOCK:
-               strscpy(pdev.type, "LnxSOCK");
+               type_len = 8;
+               strscpy(type, "LnxSOCK");
+               data = (u8 *)&pdev;
+               data_len = sizeof(pdev);
                break;
        case S_IFIFO:
-               strscpy(pdev.type, "LnxFIFO");
+               type_len = 8;
+               strscpy(type, "LnxFIFO");
+               data = (u8 *)&pdev;
+               data_len = sizeof(pdev);
                break;
        default:
-               return -EPERM;
+               rc = -EPERM;
+               goto out;
        }
 
        oparms = CIFS_OPARMS(cifs_sb, tcon, full_path, GENERIC_WRITE,
@@ -5098,17 +5133,26 @@ static int __cifs_sfu_make_node(unsigned int xid, struct inode *inode,
 
        rc = server->ops->open(xid, &oparms, &oplock, NULL);
        if (rc)
-               return rc;
+               goto out;
 
-       io_parms.pid = current->tgid;
-       io_parms.tcon = tcon;
-       io_parms.length = sizeof(pdev);
-       iov[1].iov_base = &pdev;
-       iov[1].iov_len = sizeof(pdev);
+       if (type_len + data_len > 0) {
+               io_parms.pid = current->tgid;
+               io_parms.tcon = tcon;
+               io_parms.length = type_len + data_len;
+               iov[1].iov_base = type;
+               iov[1].iov_len = type_len;
+               iov[2].iov_base = data;
+               iov[2].iov_len = data_len;
+
+               rc = server->ops->sync_write(xid, &fid, &io_parms,
+                                            &bytes_written,
+                                            iov, ARRAY_SIZE(iov)-1);
+       }
 
-       rc = server->ops->sync_write(xid, &fid, &io_parms,
-                                    &bytes_written, iov, 1);
        server->ops->close(xid, tcon, &fid);
+
+out:
+       kfree(symname_utf16);
        return rc;
 }
 
@@ -5120,7 +5164,7 @@ int cifs_sfu_make_node(unsigned int xid, struct inode *inode,
        int rc;
 
        rc = __cifs_sfu_make_node(xid, inode, dentry, tcon,
-                                 full_path, mode, dev);
+                                 full_path, mode, dev, NULL);
        if (rc)
                return rc;