]> Git Repo - J-linux.git/blob - fs/smb/client/reparse.h
Merge tag 'vfs-6.13-rc7.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
[J-linux.git] / fs / smb / client / reparse.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2024 Paulo Alcantara <[email protected]>
4  */
5
6 #ifndef _CIFS_REPARSE_H
7 #define _CIFS_REPARSE_H
8
9 #include <linux/fs.h>
10 #include <linux/stat.h>
11 #include <linux/uidgid.h>
12 #include "fs_context.h"
13 #include "cifsglob.h"
14
15 #define REPARSE_SYM_PATH_MAX 4060
16
17 /*
18  * Used only by cifs.ko to ignore reparse points from files when client or
19  * server doesn't support FSCTL_GET_REPARSE_POINT.
20  */
21 #define IO_REPARSE_TAG_INTERNAL ((__u32)~0U)
22
23 static inline dev_t reparse_mkdev(void *ptr)
24 {
25         u64 v = le64_to_cpu(*(__le64 *)ptr);
26
27         return MKDEV(v & 0xffffffff, v >> 32);
28 }
29
30 static inline kuid_t wsl_make_kuid(struct cifs_sb_info *cifs_sb,
31                                    void *ptr)
32 {
33         u32 uid = le32_to_cpu(*(__le32 *)ptr);
34
35         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
36                 return cifs_sb->ctx->linux_uid;
37         return make_kuid(current_user_ns(), uid);
38 }
39
40 static inline kgid_t wsl_make_kgid(struct cifs_sb_info *cifs_sb,
41                                    void *ptr)
42 {
43         u32 gid = le32_to_cpu(*(__le32 *)ptr);
44
45         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
46                 return cifs_sb->ctx->linux_gid;
47         return make_kgid(current_user_ns(), gid);
48 }
49
50 static inline u64 reparse_mode_nfs_type(mode_t mode)
51 {
52         switch (mode & S_IFMT) {
53         case S_IFBLK: return NFS_SPECFILE_BLK;
54         case S_IFCHR: return NFS_SPECFILE_CHR;
55         case S_IFIFO: return NFS_SPECFILE_FIFO;
56         case S_IFSOCK: return NFS_SPECFILE_SOCK;
57         }
58         return 0;
59 }
60
61 static inline u32 reparse_mode_wsl_tag(mode_t mode)
62 {
63         switch (mode & S_IFMT) {
64         case S_IFBLK: return IO_REPARSE_TAG_LX_BLK;
65         case S_IFCHR: return IO_REPARSE_TAG_LX_CHR;
66         case S_IFIFO: return IO_REPARSE_TAG_LX_FIFO;
67         case S_IFSOCK: return IO_REPARSE_TAG_AF_UNIX;
68         }
69         return 0;
70 }
71
72 /*
73  * Match a reparse point inode if reparse tag and ctime haven't changed.
74  *
75  * Windows Server updates ctime of reparse points when their data have changed.
76  * The server doesn't allow changing reparse tags from existing reparse points,
77  * though it's worth checking.
78  */
79 static inline bool reparse_inode_match(struct inode *inode,
80                                        struct cifs_fattr *fattr)
81 {
82         struct cifsInodeInfo *cinode = CIFS_I(inode);
83         struct timespec64 ctime = inode_get_ctime(inode);
84
85         /*
86          * Do not match reparse tags when client or server doesn't support
87          * FSCTL_GET_REPARSE_POINT.  @fattr->cf_cifstag should contain correct
88          * reparse tag from query dir response but the client won't be able to
89          * read the reparse point data anyway.  This spares us a revalidation.
90          */
91         if (cinode->reparse_tag != IO_REPARSE_TAG_INTERNAL &&
92             cinode->reparse_tag != fattr->cf_cifstag)
93                 return false;
94         return (cinode->cifsAttrs & ATTR_REPARSE) &&
95                 timespec64_equal(&ctime, &fattr->cf_ctime);
96 }
97
98 static inline bool cifs_open_data_reparse(struct cifs_open_info_data *data)
99 {
100         struct smb2_file_all_info *fi = &data->fi;
101         u32 attrs = le32_to_cpu(fi->Attributes);
102         bool ret;
103
104         ret = data->reparse_point || (attrs & ATTR_REPARSE);
105         if (ret)
106                 attrs |= ATTR_REPARSE;
107         fi->Attributes = cpu_to_le32(attrs);
108         return ret;
109 }
110
111 bool cifs_reparse_point_to_fattr(struct cifs_sb_info *cifs_sb,
112                                  struct cifs_fattr *fattr,
113                                  struct cifs_open_info_data *data);
114 int smb2_create_reparse_symlink(const unsigned int xid, struct inode *inode,
115                                 struct dentry *dentry, struct cifs_tcon *tcon,
116                                 const char *full_path, const char *symname);
117 int smb2_mknod_reparse(unsigned int xid, struct inode *inode,
118                        struct dentry *dentry, struct cifs_tcon *tcon,
119                        const char *full_path, umode_t mode, dev_t dev);
120 int smb2_parse_reparse_point(struct cifs_sb_info *cifs_sb,
121                              const char *full_path,
122                              struct kvec *rsp_iov,
123                              struct cifs_open_info_data *data);
124
125 #endif /* _CIFS_REPARSE_H */
This page took 0.033544 seconds and 4 git commands to generate.