cifsd: clean-up codes using chechpatch.pl --strict
[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
f4415848
NJ
104/* CreateOptions */
105/* Flag is set, it must not be a file , valid for directory only */
106#define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
107#define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
108#define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
109
110/* Should not buffer on server*/
111#define FILE_NO_INTERMEDIATE_BUFFERING_LE cpu_to_le32(0x00000008)
112/* MBZ */
113#define FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010)
114/* MBZ */
115#define FILE_SYNCHRONOUS_IO_NONALERT_LE cpu_to_le32(0x00000020)
116
117/* Flaf must not be set for directory */
118#define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
119
120/* Should be zero */
121#define CREATE_TREE_CONNECTION cpu_to_le32(0x00000080)
122#define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
123#define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
124#define FILE_OPEN_REMOTE_INSTANCE cpu_to_le32(0x00000400)
125
126/**
127 * Doc says this is obsolete "open for recovery" flag should be zero
128 * in any case.
129 */
130#define CREATE_OPEN_FOR_RECOVERY cpu_to_le32(0x00000400)
131#define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
132#define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
133#define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
134#define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
135#define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
136
137/* Should be zero*/
138#define FILE_OPEN_REQUIRING_OPLOCK cpu_to_le32(0x00010000)
139#define FILE_DISALLOW_EXCLUSIVE cpu_to_le32(0x00020000)
140#define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000)
141#define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
142#define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
143
144/* Should be zero */
145#define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE cpu_to_le32(0x00800000)
146#define CREATE_OPTIONS_MASK cpu_to_le32(0x00FFFFFF)
147#define CREATE_OPTION_READONLY 0x10000000
148/* system. NB not sent over wire */
149#define CREATE_OPTION_SPECIAL 0x20000000
150
151struct ksmbd_work;
152struct ksmbd_file;
153struct ksmbd_conn;
154
155struct ksmbd_dir_info {
156 const char *name;
157 char *wptr;
158 char *rptr;
159 int name_len;
160 int out_buf_len;
161 int num_entry;
162 int data_count;
163 int last_entry_offset;
164 bool hide_dot_file;
165 int flags;
166};
167
168struct ksmbd_readdir_data {
169 struct dir_context ctx;
170 union {
171 void *private;
172 char *dirent;
173 };
174
175 unsigned int used;
176 unsigned int dirent_count;
177 unsigned int file_attr;
178};
179
180/* ksmbd kstat wrapper to get valid create time when reading dir entry */
181struct ksmbd_kstat {
182 struct kstat *kstat;
183 unsigned long long create_time;
184 __le32 file_attributes;
185};
186
187struct ksmbd_fs_sector_size {
188 unsigned short logical_sector_size;
189 unsigned int physical_sector_size;
190 unsigned int optimal_io_size;
191};
192
193int ksmbd_vfs_inode_permission(struct dentry *dentry, int acc_mode,
194 bool delete);
195int ksmbd_vfs_query_maximal_access(struct dentry *dentry, __le32 *daccess);
196int ksmbd_vfs_create(struct ksmbd_work *work, const char *name, umode_t mode);
197int ksmbd_vfs_mkdir(struct ksmbd_work *work, const char *name, umode_t mode);
198int ksmbd_vfs_read(struct ksmbd_work *work, struct ksmbd_file *fp,
64b39f4a 199 size_t count, loff_t *pos);
f4415848 200int ksmbd_vfs_write(struct ksmbd_work *work, struct ksmbd_file *fp,
64b39f4a
NJ
201 char *buf, size_t count, loff_t *pos, bool sync,
202 ssize_t *written);
203int ksmbd_vfs_fsync(struct ksmbd_work *work, u64 fid, u64 p_id);
f4415848
NJ
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);
f4415848
NJ
213
214int ksmbd_vfs_truncate(struct ksmbd_work *work, const char *name,
64b39f4a 215 struct ksmbd_file *fp, loff_t size);
f4415848
NJ
216
217struct srv_copychunk;
218int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,
64b39f4a
NJ
219 struct ksmbd_file *src_fp, struct ksmbd_file *dst_fp,
220 struct srv_copychunk *chunks, unsigned int chunk_count,
221 unsigned int *chunk_count_written,
222 unsigned int *chunk_size_written, loff_t *total_size_written);
f4415848
NJ
223
224ssize_t ksmbd_vfs_listxattr(struct dentry *dentry, char **list);
64b39f4a
NJ
225ssize_t ksmbd_vfs_getxattr(struct dentry *dentry, char *xattr_name,
226 char **xattr_buf);
227ssize_t ksmbd_vfs_casexattr_len(struct dentry *dentry, char *attr_name,
228 int attr_name_len);
229int ksmbd_vfs_setxattr(struct dentry *dentry, const char *attr_name,
230 const void *attr_value, size_t attr_size, int flags);
231int ksmbd_vfs_xattr_stream_name(char *stream_name, char **xattr_stream_name,
232 size_t *xattr_stream_name_size, int s_type);
f4415848
NJ
233int ksmbd_vfs_truncate_xattr(struct dentry *dentry, int wo_streams);
234int ksmbd_vfs_remove_xattr(struct dentry *dentry, char *attr_name);
235void ksmbd_vfs_xattr_free(char *xattr);
f4415848
NJ
236int ksmbd_vfs_kern_path(char *name, unsigned int flags, struct path *path,
237 bool caseless);
238int ksmbd_vfs_empty_dir(struct ksmbd_file *fp);
239void ksmbd_vfs_set_fadvise(struct file *filp, __le32 option);
240int ksmbd_vfs_lock(struct file *filp, int cmd, struct file_lock *flock);
241int ksmbd_vfs_readdir(struct file *file, struct ksmbd_readdir_data *rdata);
64b39f4a
NJ
242int ksmbd_vfs_alloc_size(struct ksmbd_work *work, struct ksmbd_file *fp,
243 loff_t len);
244int ksmbd_vfs_zero_data(struct ksmbd_work *work, struct ksmbd_file *fp,
245 loff_t off, loff_t len);
f4415848
NJ
246struct file_allocated_range_buffer;
247int ksmbd_vfs_fqar_lseek(struct ksmbd_file *fp, loff_t start, loff_t length,
64b39f4a
NJ
248 struct file_allocated_range_buffer *ranges,
249 int in_count, int *out_count);
f4415848
NJ
250int ksmbd_vfs_unlink(struct dentry *dir, struct dentry *dentry);
251unsigned short ksmbd_vfs_logical_sector_size(struct inode *inode);
252void ksmbd_vfs_smb2_sector_size(struct inode *inode,
64b39f4a 253 struct ksmbd_fs_sector_size *fs_ss);
f4415848 254void *ksmbd_vfs_init_kstat(char **p, struct ksmbd_kstat *ksmbd_kstat);
64b39f4a
NJ
255int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work, struct dentry *dentry,
256 struct ksmbd_kstat *ksmbd_kstat);
f4415848
NJ
257int ksmbd_vfs_posix_lock_wait(struct file_lock *flock);
258int ksmbd_vfs_posix_lock_wait_timeout(struct file_lock *flock, long timeout);
259void ksmbd_vfs_posix_lock_unblock(struct file_lock *flock);
f4415848
NJ
260int ksmbd_vfs_remove_acl_xattrs(struct dentry *dentry);
261int ksmbd_vfs_remove_sd_xattrs(struct dentry *dentry);
262int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn, struct dentry *dentry,
263 struct smb_ntsd *pntsd, int len);
264int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn, struct dentry *dentry,
265 struct smb_ntsd **pntsd);
266int ksmbd_vfs_set_dos_attrib_xattr(struct dentry *dentry,
267 struct xattr_dos_attrib *da);
268int ksmbd_vfs_get_dos_attrib_xattr(struct dentry *dentry,
269 struct xattr_dos_attrib *da);
270struct posix_acl *ksmbd_vfs_posix_acl_alloc(int count, gfp_t flags);
271struct posix_acl *ksmbd_vfs_get_acl(struct inode *inode, int type);
272int ksmbd_vfs_set_posix_acl(struct inode *inode, int type,
273 struct posix_acl *acl);
274int ksmbd_vfs_set_init_posix_acl(struct inode *inode);
275int ksmbd_vfs_inherit_posix_acl(struct inode *inode,
276 struct inode *parent_inode);
277#endif /* __KSMBD_VFS_H__ */