xref: /linux/fs/smb/server/vfs.h (revision 00b04f4495c354cad82f96d41947aa70f71e2cc4)
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 #include <linux/unicode.h>
16 
17 #include "smbacl.h"
18 #include "xattr.h"
19 
20 /*
21  * Enumeration for stream type.
22  */
23 enum {
24 	DATA_STREAM	= 1,	/* type $DATA */
25 	DIR_STREAM		/* type $INDEX_ALLOCATION */
26 };
27 
28 /* CreateOptions */
29 #define CREATE_TREE_CONNECTION			cpu_to_le32(0x00000080)
30 #define FILE_RESERVE_OPFILTER_LE		cpu_to_le32(0x00100000)
31 
32 #define CREATE_OPTION_READONLY			0x10000000
33 /* system. NB not sent over wire */
34 #define CREATE_OPTION_SPECIAL			0x20000000
35 
36 struct ksmbd_work;
37 struct ksmbd_file;
38 struct ksmbd_conn;
39 
40 struct ksmbd_dir_info {
41 	const char	*name;
42 	char		*wptr;
43 	char		*rptr;
44 	int		name_len;
45 	int		out_buf_len;
46 	int		num_scan;
47 	int		num_entry;
48 	int		data_count;
49 	int		last_entry_offset;
50 	bool		hide_dot_file;
51 	int		flags;
52 	int		last_entry_off_align;
53 };
54 
55 struct ksmbd_readdir_data {
56 	struct dir_context	ctx;
57 	union {
58 		void		*private;
59 		char		*dirent;
60 	};
61 
62 	unsigned int		used;
63 	unsigned int		dirent_count;
64 	unsigned int		file_attr;
65 	struct unicode_map	*um;
66 };
67 
68 /* ksmbd kstat wrapper to get valid create time when reading dir entry */
69 struct ksmbd_kstat {
70 	struct kstat		*kstat;
71 	unsigned long long	create_time;
72 	__le32			file_attributes;
73 	bool			has_ads_stream; /* AAPL READDIR_ATTR V2 xattr-presence flag */
74 };
75 
76 int ksmbd_vfs_lock_parent(struct dentry *parent, struct dentry *child);
77 void ksmbd_vfs_query_maximal_access(const struct mnt_idmap *idmap,
78 				   struct dentry *dentry, __le32 *daccess);
79 int ksmbd_vfs_create(struct ksmbd_work *work, const char *name, umode_t mode);
80 int ksmbd_vfs_mkdir(struct ksmbd_work *work, const char *name, umode_t mode);
81 int ksmbd_vfs_read(struct ksmbd_work *work, struct ksmbd_file *fp, size_t count,
82 		   loff_t *pos, char *rbuf);
83 int ksmbd_vfs_write(struct ksmbd_work *work, struct ksmbd_file *fp,
84 		    char *buf, size_t count, loff_t *pos, bool sync,
85 		    ssize_t *written);
86 int ksmbd_vfs_fsync(struct ksmbd_work *work, u64 fid, u64 p_id);
87 int ksmbd_vfs_remove_file(struct ksmbd_work *work, const struct path *path);
88 int ksmbd_vfs_link(struct ksmbd_work *work,
89 		   const char *oldname, const char *newname);
90 int ksmbd_vfs_getattr(const struct path *path, struct kstat *stat);
91 int ksmbd_vfs_rename(struct ksmbd_work *work, struct ksmbd_file *old_fp,
92 			 char *newname, int flags);
93 int ksmbd_vfs_check_rename_share(struct ksmbd_work *work,
94 				 const struct path *old_path);
95 int ksmbd_vfs_truncate(struct ksmbd_work *work,
96 		       struct ksmbd_file *fp, loff_t size);
97 struct srv_copychunk;
98 int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,
99 			       struct ksmbd_file *src_fp,
100 			       struct ksmbd_file *dst_fp,
101 			       struct srv_copychunk *chunks,
102 			       unsigned int chunk_count,
103 			       unsigned int *chunk_count_written,
104 			       unsigned int *chunk_size_written,
105 			       loff_t  *total_size_written);
106 ssize_t ksmbd_vfs_listxattr(struct dentry *dentry, char **list);
107 ssize_t ksmbd_vfs_getxattr(const struct mnt_idmap *idmap,
108 			   struct dentry *dentry,
109 			   char *xattr_name,
110 			   char **xattr_buf);
111 ssize_t ksmbd_vfs_casexattr_len(const struct mnt_idmap *idmap,
112 				struct dentry *dentry, char *attr_name,
113 				int attr_name_len);
114 int ksmbd_vfs_setxattr(const struct mnt_idmap *idmap,
115 		       const struct path *path, const char *attr_name,
116 		       void *attr_value, size_t attr_size, int flags,
117 		       bool get_write);
118 int ksmbd_vfs_xattr_stream_name(char *stream_name, char **xattr_stream_name,
119 				size_t *xattr_stream_name_size, int s_type);
120 int ksmbd_vfs_remove_xattr(const struct mnt_idmap *idmap,
121 			   const struct path *path, char *attr_name,
122 			   bool get_write);
123 int ksmbd_vfs_kern_path(struct ksmbd_work *work, char *name,
124 			unsigned int flags,
125 			struct path *path, bool caseless);
126 int ksmbd_vfs_kern_path_start_removing(struct ksmbd_work *work, char *name,
127 				       unsigned int flags,
128 				       struct path *path, bool caseless);
129 void ksmbd_vfs_kern_path_end_removing(const struct path *path);
130 struct dentry *ksmbd_vfs_kern_path_create(struct ksmbd_work *work,
131 					  const char *name,
132 					  unsigned int flags,
133 					  struct path *path);
134 int ksmbd_vfs_empty_dir(struct ksmbd_file *fp);
135 void ksmbd_vfs_set_fadvise(struct file *filp, __le32 option);
136 int ksmbd_vfs_zero_data(struct ksmbd_work *work, struct ksmbd_file *fp,
137 			loff_t off, loff_t len);
138 int ksmbd_vfs_zero_holes(struct ksmbd_file *fp);
139 int ksmbd_vfs_trim_data(struct ksmbd_work *work, struct ksmbd_file *fp,
140 			loff_t off, loff_t len);
141 struct file_allocated_range_buffer;
142 int ksmbd_vfs_query_allocated_ranges(struct ksmbd_file *fp, loff_t start,
143 				     loff_t length,
144 				     struct file_allocated_range_buffer *ranges,
145 				     unsigned int in_count,
146 				     unsigned int *out_count);
147 int ksmbd_vfs_unlink(struct file *filp);
148 void *ksmbd_vfs_init_kstat(char **p, struct ksmbd_kstat *ksmbd_kstat);
149 int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work,
150 				const struct mnt_idmap *idmap,
151 				struct dentry *dentry,
152 				struct ksmbd_kstat *ksmbd_kstat);
153 void ksmbd_vfs_posix_lock_wait(struct file_lock *flock);
154 void ksmbd_vfs_posix_lock_unblock(struct file_lock *flock);
155 int ksmbd_vfs_remove_acl_xattrs(const struct mnt_idmap *idmap,
156 				const struct path *path);
157 int ksmbd_vfs_remove_sd_xattrs(const struct mnt_idmap *idmap, const struct path *path);
158 int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn,
159 			   const struct mnt_idmap *idmap,
160 			   const struct path *path,
161 			   struct smb_ntsd *pntsd, int len,
162 			   bool get_write);
163 int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn,
164 			   const struct mnt_idmap *idmap,
165 			   struct dentry *dentry,
166 			   struct smb_ntsd **pntsd);
167 int ksmbd_vfs_set_dos_attrib_xattr(const struct mnt_idmap *idmap,
168 				   const struct path *path,
169 				   struct xattr_dos_attrib *da,
170 				   bool get_write);
171 int ksmbd_vfs_get_dos_attrib_xattr(const struct mnt_idmap *idmap,
172 				   struct dentry *dentry,
173 				   struct xattr_dos_attrib *da);
174 int ksmbd_vfs_set_init_posix_acl(const struct mnt_idmap *idmap,
175 				 const struct path *path);
176 int ksmbd_vfs_inherit_posix_acl(const struct mnt_idmap *idmap,
177 				const struct path *path,
178 				struct inode *parent_inode);
179 void ksmbd_vfs_update_compressed_fattr(struct dentry *dentry, __le32 *fattr);
180 int ksmbd_vfs_get_compression(struct ksmbd_file *fp, u16 *fmt);
181 int ksmbd_vfs_set_compression(struct ksmbd_work *work, struct ksmbd_file *fp, u16 fmt);
182 int ksmbd_vfs_set_compression_create(struct ksmbd_work *work,
183 				     struct ksmbd_file *fp, u16 fmt);
184 #endif /* __KSMBD_VFS_H__ */
185