ksmbd: move fs/cifsd to fs/ksmbd
[linux-2.6-microblaze.git] / fs / ksmbd / vfs.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *   Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
4  *   Copyright (C) 2018 Samsung Electronics Co., Ltd.
5  */
6
7 #ifndef __KSMBD_VFS_H__
8 #define __KSMBD_VFS_H__
9
10 #include <linux/file.h>
11 #include <linux/fs.h>
12 #include <linux/namei.h>
13 #include <uapi/linux/xattr.h>
14 #include <linux/posix_acl.h>
15
16 #include "smbacl.h"
17
18 /* STREAM XATTR PREFIX */
19 #define STREAM_PREFIX                   "DosStream."
20 #define STREAM_PREFIX_LEN               (sizeof(STREAM_PREFIX) - 1)
21 #define XATTR_NAME_STREAM               (XATTR_USER_PREFIX STREAM_PREFIX)
22 #define XATTR_NAME_STREAM_LEN           (sizeof(XATTR_NAME_STREAM) - 1)
23
24 enum {
25         XATTR_DOSINFO_ATTRIB            = 0x00000001,
26         XATTR_DOSINFO_EA_SIZE           = 0x00000002,
27         XATTR_DOSINFO_SIZE              = 0x00000004,
28         XATTR_DOSINFO_ALLOC_SIZE        = 0x00000008,
29         XATTR_DOSINFO_CREATE_TIME       = 0x00000010,
30         XATTR_DOSINFO_CHANGE_TIME       = 0x00000020,
31         XATTR_DOSINFO_ITIME             = 0x00000040
32 };
33
34 struct xattr_dos_attrib {
35         __u16   version;
36         __u32   flags;
37         __u32   attr;
38         __u32   ea_size;
39         __u64   size;
40         __u64   alloc_size;
41         __u64   create_time;
42         __u64   change_time;
43         __u64   itime;
44 };
45
46 /* DOS ATTRIBUITE XATTR PREFIX */
47 #define DOS_ATTRIBUTE_PREFIX            "DOSATTRIB"
48 #define DOS_ATTRIBUTE_PREFIX_LEN        (sizeof(DOS_ATTRIBUTE_PREFIX) - 1)
49 #define XATTR_NAME_DOS_ATTRIBUTE        \
50                 (XATTR_USER_PREFIX DOS_ATTRIBUTE_PREFIX)
51 #define XATTR_NAME_DOS_ATTRIBUTE_LEN    \
52                 (sizeof(XATTR_USER_PREFIX DOS_ATTRIBUTE_PREFIX) - 1)
53
54 #define XATTR_SD_HASH_TYPE_SHA256       0x1
55 #define XATTR_SD_HASH_SIZE              64
56
57 #define SMB_ACL_READ                    4
58 #define SMB_ACL_WRITE                   2
59 #define SMB_ACL_EXECUTE                 1
60
61 enum {
62         SMB_ACL_TAG_INVALID = 0,
63         SMB_ACL_USER,
64         SMB_ACL_USER_OBJ,
65         SMB_ACL_GROUP,
66         SMB_ACL_GROUP_OBJ,
67         SMB_ACL_OTHER,
68         SMB_ACL_MASK
69 };
70
71 struct xattr_acl_entry {
72         int type;
73         uid_t uid;
74         gid_t gid;
75         mode_t perm;
76 };
77
78 struct xattr_smb_acl {
79         int count;
80         int next;
81         struct xattr_acl_entry entries[0];
82 };
83
84 struct xattr_ntacl {
85         __u16   version;
86         void    *sd_buf;
87         __u32   sd_size;
88         __u16   hash_type;
89         __u8    desc[10];
90         __u16   desc_len;
91         __u64   current_time;
92         __u8    hash[XATTR_SD_HASH_SIZE];
93         __u8    posix_acl_hash[XATTR_SD_HASH_SIZE];
94 };
95
96 /* SECURITY DESCRIPTOR XATTR PREFIX */
97 #define SD_PREFIX                       "NTACL"
98 #define SD_PREFIX_LEN   (sizeof(SD_PREFIX) - 1)
99 #define XATTR_NAME_SD   \
100                 (XATTR_SECURITY_PREFIX SD_PREFIX)
101 #define XATTR_NAME_SD_LEN       \
102                 (sizeof(XATTR_SECURITY_PREFIX SD_PREFIX) - 1)
103
104 /*
105  * Enumeration for stream type.
106  */
107 enum {
108         DATA_STREAM     = 1,    /* type $DATA */
109         DIR_STREAM              /* type $INDEX_ALLOCATION */
110 };
111
112 /* CreateOptions */
113 /* Flag is set, it must not be a file , valid for directory only */
114 #define FILE_DIRECTORY_FILE_LE                  cpu_to_le32(0x00000001)
115 #define FILE_WRITE_THROUGH_LE                   cpu_to_le32(0x00000002)
116 #define FILE_SEQUENTIAL_ONLY_LE                 cpu_to_le32(0x00000004)
117
118 /* Should not buffer on server*/
119 #define FILE_NO_INTERMEDIATE_BUFFERING_LE       cpu_to_le32(0x00000008)
120 /* MBZ */
121 #define FILE_SYNCHRONOUS_IO_ALERT_LE            cpu_to_le32(0x00000010)
122 /* MBZ */
123 #define FILE_SYNCHRONOUS_IO_NONALERT_LE         cpu_to_le32(0x00000020)
124
125 /* Flaf must not be set for directory */
126 #define FILE_NON_DIRECTORY_FILE_LE              cpu_to_le32(0x00000040)
127
128 /* Should be zero */
129 #define CREATE_TREE_CONNECTION                  cpu_to_le32(0x00000080)
130 #define FILE_COMPLETE_IF_OPLOCKED_LE            cpu_to_le32(0x00000100)
131 #define FILE_NO_EA_KNOWLEDGE_LE                 cpu_to_le32(0x00000200)
132 #define FILE_OPEN_REMOTE_INSTANCE               cpu_to_le32(0x00000400)
133
134 /**
135  * Doc says this is obsolete "open for recovery" flag should be zero
136  * in any case.
137  */
138 #define CREATE_OPEN_FOR_RECOVERY                cpu_to_le32(0x00000400)
139 #define FILE_RANDOM_ACCESS_LE                   cpu_to_le32(0x00000800)
140 #define FILE_DELETE_ON_CLOSE_LE                 cpu_to_le32(0x00001000)
141 #define FILE_OPEN_BY_FILE_ID_LE                 cpu_to_le32(0x00002000)
142 #define FILE_OPEN_FOR_BACKUP_INTENT_LE          cpu_to_le32(0x00004000)
143 #define FILE_NO_COMPRESSION_LE                  cpu_to_le32(0x00008000)
144
145 /* Should be zero*/
146 #define FILE_OPEN_REQUIRING_OPLOCK              cpu_to_le32(0x00010000)
147 #define FILE_DISALLOW_EXCLUSIVE                 cpu_to_le32(0x00020000)
148 #define FILE_RESERVE_OPFILTER_LE                cpu_to_le32(0x00100000)
149 #define FILE_OPEN_REPARSE_POINT_LE              cpu_to_le32(0x00200000)
150 #define FILE_OPEN_NO_RECALL_LE                  cpu_to_le32(0x00400000)
151
152 /* Should be zero */
153 #define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE       cpu_to_le32(0x00800000)
154 #define CREATE_OPTIONS_MASK                     cpu_to_le32(0x00FFFFFF)
155 #define CREATE_OPTION_READONLY                  0x10000000
156 /* system. NB not sent over wire */
157 #define CREATE_OPTION_SPECIAL                   0x20000000
158
159 struct ksmbd_work;
160 struct ksmbd_file;
161 struct ksmbd_conn;
162
163 struct ksmbd_dir_info {
164         const char      *name;
165         char            *wptr;
166         char            *rptr;
167         int             name_len;
168         int             out_buf_len;
169         int             num_entry;
170         int             data_count;
171         int             last_entry_offset;
172         bool            hide_dot_file;
173         int             flags;
174 };
175
176 struct ksmbd_readdir_data {
177         struct dir_context      ctx;
178         union {
179                 void            *private;
180                 char            *dirent;
181         };
182
183         unsigned int            used;
184         unsigned int            dirent_count;
185         unsigned int            file_attr;
186 };
187
188 /* ksmbd kstat wrapper to get valid create time when reading dir entry */
189 struct ksmbd_kstat {
190         struct kstat            *kstat;
191         unsigned long long      create_time;
192         __le32                  file_attributes;
193 };
194
195 int ksmbd_vfs_inode_permission(struct dentry *dentry, int acc_mode,
196                                bool delete);
197 int ksmbd_vfs_query_maximal_access(struct dentry *dentry, __le32 *daccess);
198 int ksmbd_vfs_create(struct ksmbd_work *work, const char *name, umode_t mode);
199 int ksmbd_vfs_mkdir(struct ksmbd_work *work, const char *name, umode_t mode);
200 int ksmbd_vfs_read(struct ksmbd_work *work, struct ksmbd_file *fp,
201                    size_t count, loff_t *pos);
202 int ksmbd_vfs_write(struct ksmbd_work *work, struct ksmbd_file *fp,
203                     char *buf, size_t count, loff_t *pos, bool sync,
204                     ssize_t *written);
205 int ksmbd_vfs_fsync(struct ksmbd_work *work, u64 fid, u64 p_id);
206 int ksmbd_vfs_remove_file(struct ksmbd_work *work, char *name);
207 int ksmbd_vfs_link(struct ksmbd_work *work,
208                    const char *oldname, const char *newname);
209 int ksmbd_vfs_getattr(struct path *path, struct kstat *stat);
210 int ksmbd_vfs_fp_rename(struct ksmbd_work *work, struct ksmbd_file *fp,
211                         char *newname);
212 int ksmbd_vfs_truncate(struct ksmbd_work *work, const char *name,
213                        struct ksmbd_file *fp, loff_t size);
214 struct srv_copychunk;
215 int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,
216                                struct ksmbd_file *src_fp,
217                                struct ksmbd_file *dst_fp,
218                                struct srv_copychunk *chunks,
219                                unsigned int chunk_count,
220                                unsigned int *chunk_count_written,
221                                unsigned int *chunk_size_written,
222                                loff_t  *total_size_written);
223 ssize_t ksmbd_vfs_listxattr(struct dentry *dentry, char **list);
224 ssize_t ksmbd_vfs_getxattr(struct dentry *dentry, char *xattr_name,
225                            char **xattr_buf);
226 ssize_t ksmbd_vfs_casexattr_len(struct dentry *dentry, char *attr_name,
227                                 int attr_name_len);
228 int ksmbd_vfs_setxattr(struct dentry *dentry, const char *attr_name,
229                        const void *attr_value, size_t attr_size, int flags);
230 int ksmbd_vfs_xattr_stream_name(char *stream_name, char **xattr_stream_name,
231                                 size_t *xattr_stream_name_size, int s_type);
232 int ksmbd_vfs_remove_xattr(struct dentry *dentry, char *attr_name);
233 int ksmbd_vfs_kern_path(char *name, unsigned int flags, struct path *path,
234                         bool caseless);
235 int ksmbd_vfs_empty_dir(struct ksmbd_file *fp);
236 void ksmbd_vfs_set_fadvise(struct file *filp, __le32 option);
237 int ksmbd_vfs_zero_data(struct ksmbd_work *work, struct ksmbd_file *fp,
238                         loff_t off, loff_t len);
239 struct file_allocated_range_buffer;
240 int ksmbd_vfs_fqar_lseek(struct ksmbd_file *fp, loff_t start, loff_t length,
241                          struct file_allocated_range_buffer *ranges,
242                          int in_count, int *out_count);
243 int ksmbd_vfs_unlink(struct dentry *dir, struct dentry *dentry);
244 void *ksmbd_vfs_init_kstat(char **p, struct ksmbd_kstat *ksmbd_kstat);
245 int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work, struct dentry *dentry,
246                                 struct ksmbd_kstat *ksmbd_kstat);
247 int ksmbd_vfs_posix_lock_wait(struct file_lock *flock);
248 int ksmbd_vfs_posix_lock_wait_timeout(struct file_lock *flock, long timeout);
249 void ksmbd_vfs_posix_lock_unblock(struct file_lock *flock);
250 int ksmbd_vfs_remove_acl_xattrs(struct dentry *dentry);
251 int ksmbd_vfs_remove_sd_xattrs(struct dentry *dentry);
252 int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn, struct dentry *dentry,
253                            struct smb_ntsd *pntsd, int len);
254 int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn, struct dentry *dentry,
255                            struct smb_ntsd **pntsd);
256 int ksmbd_vfs_set_dos_attrib_xattr(struct dentry *dentry,
257                                    struct xattr_dos_attrib *da);
258 int ksmbd_vfs_get_dos_attrib_xattr(struct dentry *dentry,
259                                    struct xattr_dos_attrib *da);
260 int ksmbd_vfs_set_init_posix_acl(struct inode *inode);
261 int ksmbd_vfs_inherit_posix_acl(struct inode *inode,
262                                 struct inode *parent_inode);
263 #endif /* __KSMBD_VFS_H__ */