cifsd: add file operations
[linux-block.git] / fs / cifsd / vfs.h
CommitLineData
f4415848
NJ
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
24enum {
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
34struct 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
61enum {
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
71struct xattr_acl_entry {
72 int type;
73 uid_t uid;
74 gid_t gid;
75 mode_t perm;
76};
77
78struct xattr_smb_acl {
79 int count;
80 int next;
81 struct xattr_acl_entry entries[0];
82};
83
84struct 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/* CreateOptions */
106/* Flag is set, it must not be a file , valid for directory only */
107#define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
108#define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
109#define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
110
111/* Should not buffer on server*/
112#define FILE_NO_INTERMEDIATE_BUFFERING_LE cpu_to_le32(0x00000008)
113/* MBZ */
114#define FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010)
115/* MBZ */
116#define FILE_SYNCHRONOUS_IO_NONALERT_LE cpu_to_le32(0x00000020)
117
118/* Flaf must not be set for directory */
119#define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
120
121/* Should be zero */
122#define CREATE_TREE_CONNECTION cpu_to_le32(0x00000080)
123#define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
124#define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
125#define FILE_OPEN_REMOTE_INSTANCE cpu_to_le32(0x00000400)
126
127/**
128 * Doc says this is obsolete "open for recovery" flag should be zero
129 * in any case.
130 */
131#define CREATE_OPEN_FOR_RECOVERY cpu_to_le32(0x00000400)
132#define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
133#define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
134#define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
135#define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
136#define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
137
138/* Should be zero*/
139#define FILE_OPEN_REQUIRING_OPLOCK cpu_to_le32(0x00010000)
140#define FILE_DISALLOW_EXCLUSIVE cpu_to_le32(0x00020000)
141#define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000)
142#define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
143#define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
144
145/* Should be zero */
146#define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE cpu_to_le32(0x00800000)
147#define CREATE_OPTIONS_MASK cpu_to_le32(0x00FFFFFF)
148#define CREATE_OPTION_READONLY 0x10000000
149/* system. NB not sent over wire */
150#define CREATE_OPTION_SPECIAL 0x20000000
151
152struct ksmbd_work;
153struct ksmbd_file;
154struct ksmbd_conn;
155
156struct ksmbd_dir_info {
157 const char *name;
158 char *wptr;
159 char *rptr;
160 int name_len;
161 int out_buf_len;
162 int num_entry;
163 int data_count;
164 int last_entry_offset;
165 bool hide_dot_file;
166 int flags;
167};
168
169struct ksmbd_readdir_data {
170 struct dir_context ctx;
171 union {
172 void *private;
173 char *dirent;
174 };
175
176 unsigned int used;
177 unsigned int dirent_count;
178 unsigned int file_attr;
179};
180
181/* ksmbd kstat wrapper to get valid create time when reading dir entry */
182struct ksmbd_kstat {
183 struct kstat *kstat;
184 unsigned long long create_time;
185 __le32 file_attributes;
186};
187
188struct ksmbd_fs_sector_size {
189 unsigned short logical_sector_size;
190 unsigned int physical_sector_size;
191 unsigned int optimal_io_size;
192};
193
194int ksmbd_vfs_inode_permission(struct dentry *dentry, int acc_mode,
195 bool delete);
196int ksmbd_vfs_query_maximal_access(struct dentry *dentry, __le32 *daccess);
197int ksmbd_vfs_create(struct ksmbd_work *work, const char *name, umode_t mode);
198int ksmbd_vfs_mkdir(struct ksmbd_work *work, const char *name, umode_t mode);
199int ksmbd_vfs_read(struct ksmbd_work *work, struct ksmbd_file *fp,
200 size_t count, loff_t *pos);
201int ksmbd_vfs_write(struct ksmbd_work *work, struct ksmbd_file *fp,
202 char *buf, size_t count, loff_t *pos, bool sync, ssize_t *written);
203int ksmbd_vfs_fsync(struct ksmbd_work *work, uint64_t fid, uint64_t p_id);
204int ksmbd_vfs_remove_file(struct ksmbd_work *work, char *name);
205int ksmbd_vfs_link(struct ksmbd_work *work,
206 const char *oldname, const char *newname);
207int ksmbd_vfs_getattr(struct path *path, struct kstat *stat);
208int ksmbd_vfs_symlink(const char *name, const char *symname);
209int ksmbd_vfs_readlink(struct path *path, char *buf, int lenp);
210
211int ksmbd_vfs_fp_rename(struct ksmbd_work *work, struct ksmbd_file *fp,
212 char *newname);
213int ksmbd_vfs_rename_slowpath(struct ksmbd_work *work,
214 char *oldname, char *newname);
215
216int ksmbd_vfs_truncate(struct ksmbd_work *work, const char *name,
217 struct ksmbd_file *fp, loff_t size);
218
219struct srv_copychunk;
220int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,
221 struct ksmbd_file *src_fp,
222 struct ksmbd_file *dst_fp,
223 struct srv_copychunk *chunks,
224 unsigned int chunk_count,
225 unsigned int *chunk_count_written,
226 unsigned int *chunk_size_written,
227 loff_t *total_size_written);
228
229struct ksmbd_file *ksmbd_vfs_dentry_open(struct ksmbd_work *work,
230 const struct path *path,
231 int flags,
232 __le32 option,
233 int fexist);
234
235ssize_t ksmbd_vfs_listxattr(struct dentry *dentry, char **list);
236ssize_t ksmbd_vfs_getxattr(struct dentry *dentry,
237 char *xattr_name,
238 char **xattr_buf);
239
240ssize_t ksmbd_vfs_casexattr_len(struct dentry *dentry,
241 char *attr_name,
242 int attr_name_len);
243
244int ksmbd_vfs_setxattr(struct dentry *dentry,
245 const char *attr_name,
246 const void *attr_value,
247 size_t attr_size,
248 int flags);
249
250int ksmbd_vfs_fsetxattr(const char *filename,
251 const char *attr_name,
252 const void *attr_value,
253 size_t attr_size,
254 int flags);
255
256int ksmbd_vfs_xattr_stream_name(char *stream_name,
257 char **xattr_stream_name,
258 size_t *xattr_stream_name_size,
259 int s_type);
260
261int ksmbd_vfs_truncate_xattr(struct dentry *dentry, int wo_streams);
262int ksmbd_vfs_remove_xattr(struct dentry *dentry, char *attr_name);
263void ksmbd_vfs_xattr_free(char *xattr);
264
265int ksmbd_vfs_kern_path(char *name, unsigned int flags, struct path *path,
266 bool caseless);
267int ksmbd_vfs_empty_dir(struct ksmbd_file *fp);
268void ksmbd_vfs_set_fadvise(struct file *filp, __le32 option);
269int ksmbd_vfs_lock(struct file *filp, int cmd, struct file_lock *flock);
270int ksmbd_vfs_readdir(struct file *file, struct ksmbd_readdir_data *rdata);
271int ksmbd_vfs_alloc_size(struct ksmbd_work *work,
272 struct ksmbd_file *fp,
273 loff_t len);
274int ksmbd_vfs_zero_data(struct ksmbd_work *work,
275 struct ksmbd_file *fp,
276 loff_t off,
277 loff_t len);
278
279struct file_allocated_range_buffer;
280int ksmbd_vfs_fqar_lseek(struct ksmbd_file *fp, loff_t start, loff_t length,
281 struct file_allocated_range_buffer *ranges,
282 int in_count, int *out_count);
283int ksmbd_vfs_unlink(struct dentry *dir, struct dentry *dentry);
284unsigned short ksmbd_vfs_logical_sector_size(struct inode *inode);
285void ksmbd_vfs_smb2_sector_size(struct inode *inode,
286 struct ksmbd_fs_sector_size *fs_ss);
287void *ksmbd_vfs_init_kstat(char **p, struct ksmbd_kstat *ksmbd_kstat);
288
289int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work,
290 struct dentry *dentry,
291 struct ksmbd_kstat *ksmbd_kstat);
292
293int ksmbd_vfs_posix_lock_wait(struct file_lock *flock);
294int ksmbd_vfs_posix_lock_wait_timeout(struct file_lock *flock, long timeout);
295void ksmbd_vfs_posix_lock_unblock(struct file_lock *flock);
296
297int ksmbd_vfs_remove_acl_xattrs(struct dentry *dentry);
298int ksmbd_vfs_remove_sd_xattrs(struct dentry *dentry);
299int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn, struct dentry *dentry,
300 struct smb_ntsd *pntsd, int len);
301int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn, struct dentry *dentry,
302 struct smb_ntsd **pntsd);
303int ksmbd_vfs_set_dos_attrib_xattr(struct dentry *dentry,
304 struct xattr_dos_attrib *da);
305int ksmbd_vfs_get_dos_attrib_xattr(struct dentry *dentry,
306 struct xattr_dos_attrib *da);
307struct posix_acl *ksmbd_vfs_posix_acl_alloc(int count, gfp_t flags);
308struct posix_acl *ksmbd_vfs_get_acl(struct inode *inode, int type);
309int ksmbd_vfs_set_posix_acl(struct inode *inode, int type,
310 struct posix_acl *acl);
311int ksmbd_vfs_set_init_posix_acl(struct inode *inode);
312int ksmbd_vfs_inherit_posix_acl(struct inode *inode,
313 struct inode *parent_inode);
314#endif /* __KSMBD_VFS_H__ */