1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
4 * Copyright (C) 2018 Samsung Electronics Co., Ltd.
7 #ifndef __KSMBD_VFS_H__
8 #define __KSMBD_VFS_H__
10 #include <linux/file.h>
12 #include <linux/namei.h>
13 #include <uapi/linux/xattr.h>
14 #include <linux/posix_acl.h>
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)
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
34 struct xattr_dos_attrib {
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)
54 #define XATTR_SD_HASH_TYPE_SHA256 0x1
55 #define XATTR_SD_HASH_SIZE 64
57 #define SMB_ACL_READ 4
58 #define SMB_ACL_WRITE 2
59 #define SMB_ACL_EXECUTE 1
62 SMB_ACL_TAG_INVALID = 0,
71 struct xattr_acl_entry {
78 struct xattr_smb_acl {
81 struct xattr_acl_entry entries[0];
92 __u8 hash[XATTR_SD_HASH_SIZE];
93 __u8 posix_acl_hash[XATTR_SD_HASH_SIZE];
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)
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)
110 /* Should not buffer on server*/
111 #define FILE_NO_INTERMEDIATE_BUFFERING_LE cpu_to_le32(0x00000008)
113 #define FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010)
115 #define FILE_SYNCHRONOUS_IO_NONALERT_LE cpu_to_le32(0x00000020)
117 /* Flaf must not be set for directory */
118 #define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
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)
127 * Doc says this is obsolete "open for recovery" flag should be zero
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)
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)
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
155 struct ksmbd_dir_info {
163 int last_entry_offset;
168 struct ksmbd_readdir_data {
169 struct dir_context ctx;
176 unsigned int dirent_count;
177 unsigned int file_attr;
180 /* ksmbd kstat wrapper to get valid create time when reading dir entry */
183 unsigned long long create_time;
184 __le32 file_attributes;
187 struct ksmbd_fs_sector_size {
188 unsigned short logical_sector_size;
189 unsigned int physical_sector_size;
190 unsigned int optimal_io_size;
193 int ksmbd_vfs_inode_permission(struct dentry *dentry, int acc_mode,
195 int ksmbd_vfs_query_maximal_access(struct dentry *dentry, __le32 *daccess);
196 int ksmbd_vfs_create(struct ksmbd_work *work, const char *name, umode_t mode);
197 int ksmbd_vfs_mkdir(struct ksmbd_work *work, const char *name, umode_t mode);
198 int ksmbd_vfs_read(struct ksmbd_work *work, struct ksmbd_file *fp,
199 size_t count, loff_t *pos);
200 int ksmbd_vfs_write(struct ksmbd_work *work, struct ksmbd_file *fp,
201 char *buf, size_t count, loff_t *pos, bool sync,
203 int ksmbd_vfs_fsync(struct ksmbd_work *work, u64 fid, u64 p_id);
204 int ksmbd_vfs_remove_file(struct ksmbd_work *work, char *name);
205 int ksmbd_vfs_link(struct ksmbd_work *work,
206 const char *oldname, const char *newname);
207 int ksmbd_vfs_getattr(struct path *path, struct kstat *stat);
209 int ksmbd_vfs_fp_rename(struct ksmbd_work *work, struct ksmbd_file *fp,
212 int ksmbd_vfs_truncate(struct ksmbd_work *work, const char *name,
213 struct ksmbd_file *fp, loff_t size);
215 struct srv_copychunk;
216 int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,
217 struct ksmbd_file *src_fp, struct ksmbd_file *dst_fp,
218 struct srv_copychunk *chunks, unsigned int chunk_count,
219 unsigned int *chunk_count_written,
220 unsigned int *chunk_size_written, loff_t *total_size_written);
221 int ksmbd_vfs_copy_file_range(struct file *file_in, loff_t pos_in,
222 struct file *file_out, loff_t pos_out, size_t len);
223 ssize_t ksmbd_vfs_listxattr(struct dentry *dentry, char **list);
224 ssize_t ksmbd_vfs_getxattr(struct dentry *dentry, char *xattr_name,
226 ssize_t ksmbd_vfs_casexattr_len(struct dentry *dentry, char *attr_name,
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,
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_lock(struct file *filp, int cmd, struct file_lock *flock);
238 int ksmbd_vfs_readdir(struct file *file, struct ksmbd_readdir_data *rdata);
239 int ksmbd_vfs_alloc_size(struct ksmbd_work *work, struct ksmbd_file *fp,
241 int ksmbd_vfs_zero_data(struct ksmbd_work *work, struct ksmbd_file *fp,
242 loff_t off, loff_t len);
243 struct file_allocated_range_buffer;
244 int ksmbd_vfs_fqar_lseek(struct ksmbd_file *fp, loff_t start, loff_t length,
245 struct file_allocated_range_buffer *ranges,
246 int in_count, int *out_count);
247 int ksmbd_vfs_unlink(struct dentry *dir, struct dentry *dentry);
248 unsigned short ksmbd_vfs_logical_sector_size(struct inode *inode);
249 void ksmbd_vfs_smb2_sector_size(struct inode *inode,
250 struct ksmbd_fs_sector_size *fs_ss);
251 void *ksmbd_vfs_init_kstat(char **p, struct ksmbd_kstat *ksmbd_kstat);
252 int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work, struct dentry *dentry,
253 struct ksmbd_kstat *ksmbd_kstat);
254 int ksmbd_vfs_posix_lock_wait(struct file_lock *flock);
255 int ksmbd_vfs_posix_lock_wait_timeout(struct file_lock *flock, long timeout);
256 void ksmbd_vfs_posix_lock_unblock(struct file_lock *flock);
257 int ksmbd_vfs_remove_acl_xattrs(struct dentry *dentry);
258 int ksmbd_vfs_remove_sd_xattrs(struct dentry *dentry);
259 int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn, struct dentry *dentry,
260 struct smb_ntsd *pntsd, int len);
261 int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn, struct dentry *dentry,
262 struct smb_ntsd **pntsd);
263 int ksmbd_vfs_set_dos_attrib_xattr(struct dentry *dentry,
264 struct xattr_dos_attrib *da);
265 int ksmbd_vfs_get_dos_attrib_xattr(struct dentry *dentry,
266 struct xattr_dos_attrib *da);
267 struct posix_acl *ksmbd_vfs_posix_acl_alloc(int count, gfp_t flags);
268 struct posix_acl *ksmbd_vfs_get_acl(struct inode *inode, int type);
269 int ksmbd_vfs_set_posix_acl(struct inode *inode, int type,
270 struct posix_acl *acl);
271 int ksmbd_vfs_set_init_posix_acl(struct inode *inode);
272 int ksmbd_vfs_inherit_posix_acl(struct inode *inode,
273 struct inode *parent_inode);
274 #endif /* __KSMBD_VFS_H__ */