162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *   Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
462306a36Sopenharmony_ci *   Copyright (C) 2018 Samsung Electronics Co., Ltd.
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#ifndef __KSMBD_VFS_H__
862306a36Sopenharmony_ci#define __KSMBD_VFS_H__
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/file.h>
1162306a36Sopenharmony_ci#include <linux/fs.h>
1262306a36Sopenharmony_ci#include <linux/namei.h>
1362306a36Sopenharmony_ci#include <uapi/linux/xattr.h>
1462306a36Sopenharmony_ci#include <linux/posix_acl.h>
1562306a36Sopenharmony_ci#include <linux/unicode.h>
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#include "smbacl.h"
1862306a36Sopenharmony_ci#include "xattr.h"
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/*
2162306a36Sopenharmony_ci * Enumeration for stream type.
2262306a36Sopenharmony_ci */
2362306a36Sopenharmony_cienum {
2462306a36Sopenharmony_ci	DATA_STREAM	= 1,	/* type $DATA */
2562306a36Sopenharmony_ci	DIR_STREAM		/* type $INDEX_ALLOCATION */
2662306a36Sopenharmony_ci};
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/* CreateOptions */
2962306a36Sopenharmony_ci#define CREATE_TREE_CONNECTION			cpu_to_le32(0x00000080)
3062306a36Sopenharmony_ci#define FILE_RESERVE_OPFILTER_LE		cpu_to_le32(0x00100000)
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define CREATE_OPTION_READONLY			0x10000000
3362306a36Sopenharmony_ci/* system. NB not sent over wire */
3462306a36Sopenharmony_ci#define CREATE_OPTION_SPECIAL			0x20000000
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_cistruct ksmbd_work;
3762306a36Sopenharmony_cistruct ksmbd_file;
3862306a36Sopenharmony_cistruct ksmbd_conn;
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_cistruct ksmbd_dir_info {
4162306a36Sopenharmony_ci	const char	*name;
4262306a36Sopenharmony_ci	char		*wptr;
4362306a36Sopenharmony_ci	char		*rptr;
4462306a36Sopenharmony_ci	int		name_len;
4562306a36Sopenharmony_ci	int		out_buf_len;
4662306a36Sopenharmony_ci	int		num_entry;
4762306a36Sopenharmony_ci	int		data_count;
4862306a36Sopenharmony_ci	int		last_entry_offset;
4962306a36Sopenharmony_ci	bool		hide_dot_file;
5062306a36Sopenharmony_ci	int		flags;
5162306a36Sopenharmony_ci	int		last_entry_off_align;
5262306a36Sopenharmony_ci};
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistruct ksmbd_readdir_data {
5562306a36Sopenharmony_ci	struct dir_context	ctx;
5662306a36Sopenharmony_ci	union {
5762306a36Sopenharmony_ci		void		*private;
5862306a36Sopenharmony_ci		char		*dirent;
5962306a36Sopenharmony_ci	};
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci	unsigned int		used;
6262306a36Sopenharmony_ci	unsigned int		dirent_count;
6362306a36Sopenharmony_ci	unsigned int		file_attr;
6462306a36Sopenharmony_ci	struct unicode_map	*um;
6562306a36Sopenharmony_ci};
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci/* ksmbd kstat wrapper to get valid create time when reading dir entry */
6862306a36Sopenharmony_cistruct ksmbd_kstat {
6962306a36Sopenharmony_ci	struct kstat		*kstat;
7062306a36Sopenharmony_ci	unsigned long long	create_time;
7162306a36Sopenharmony_ci	__le32			file_attributes;
7262306a36Sopenharmony_ci};
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ciint ksmbd_vfs_lock_parent(struct dentry *parent, struct dentry *child);
7562306a36Sopenharmony_civoid ksmbd_vfs_query_maximal_access(struct mnt_idmap *idmap,
7662306a36Sopenharmony_ci				   struct dentry *dentry, __le32 *daccess);
7762306a36Sopenharmony_ciint ksmbd_vfs_create(struct ksmbd_work *work, const char *name, umode_t mode);
7862306a36Sopenharmony_ciint ksmbd_vfs_mkdir(struct ksmbd_work *work, const char *name, umode_t mode);
7962306a36Sopenharmony_ciint ksmbd_vfs_read(struct ksmbd_work *work, struct ksmbd_file *fp, size_t count,
8062306a36Sopenharmony_ci		   loff_t *pos, char *rbuf);
8162306a36Sopenharmony_ciint ksmbd_vfs_write(struct ksmbd_work *work, struct ksmbd_file *fp,
8262306a36Sopenharmony_ci		    char *buf, size_t count, loff_t *pos, bool sync,
8362306a36Sopenharmony_ci		    ssize_t *written);
8462306a36Sopenharmony_ciint ksmbd_vfs_fsync(struct ksmbd_work *work, u64 fid, u64 p_id);
8562306a36Sopenharmony_ciint ksmbd_vfs_remove_file(struct ksmbd_work *work, const struct path *path);
8662306a36Sopenharmony_ciint ksmbd_vfs_link(struct ksmbd_work *work,
8762306a36Sopenharmony_ci		   const char *oldname, const char *newname);
8862306a36Sopenharmony_ciint ksmbd_vfs_getattr(const struct path *path, struct kstat *stat);
8962306a36Sopenharmony_ciint ksmbd_vfs_rename(struct ksmbd_work *work, const struct path *old_path,
9062306a36Sopenharmony_ci		     char *newname, int flags);
9162306a36Sopenharmony_ciint ksmbd_vfs_truncate(struct ksmbd_work *work,
9262306a36Sopenharmony_ci		       struct ksmbd_file *fp, loff_t size);
9362306a36Sopenharmony_cistruct srv_copychunk;
9462306a36Sopenharmony_ciint ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,
9562306a36Sopenharmony_ci			       struct ksmbd_file *src_fp,
9662306a36Sopenharmony_ci			       struct ksmbd_file *dst_fp,
9762306a36Sopenharmony_ci			       struct srv_copychunk *chunks,
9862306a36Sopenharmony_ci			       unsigned int chunk_count,
9962306a36Sopenharmony_ci			       unsigned int *chunk_count_written,
10062306a36Sopenharmony_ci			       unsigned int *chunk_size_written,
10162306a36Sopenharmony_ci			       loff_t  *total_size_written);
10262306a36Sopenharmony_cissize_t ksmbd_vfs_listxattr(struct dentry *dentry, char **list);
10362306a36Sopenharmony_cissize_t ksmbd_vfs_getxattr(struct mnt_idmap *idmap,
10462306a36Sopenharmony_ci			   struct dentry *dentry,
10562306a36Sopenharmony_ci			   char *xattr_name,
10662306a36Sopenharmony_ci			   char **xattr_buf);
10762306a36Sopenharmony_cissize_t ksmbd_vfs_casexattr_len(struct mnt_idmap *idmap,
10862306a36Sopenharmony_ci				struct dentry *dentry, char *attr_name,
10962306a36Sopenharmony_ci				int attr_name_len);
11062306a36Sopenharmony_ciint ksmbd_vfs_setxattr(struct mnt_idmap *idmap,
11162306a36Sopenharmony_ci		       const struct path *path, const char *attr_name,
11262306a36Sopenharmony_ci		       void *attr_value, size_t attr_size, int flags,
11362306a36Sopenharmony_ci		       bool get_write);
11462306a36Sopenharmony_ciint ksmbd_vfs_xattr_stream_name(char *stream_name, char **xattr_stream_name,
11562306a36Sopenharmony_ci				size_t *xattr_stream_name_size, int s_type);
11662306a36Sopenharmony_ciint ksmbd_vfs_remove_xattr(struct mnt_idmap *idmap,
11762306a36Sopenharmony_ci			   const struct path *path, char *attr_name);
11862306a36Sopenharmony_ciint ksmbd_vfs_kern_path_locked(struct ksmbd_work *work, char *name,
11962306a36Sopenharmony_ci			       unsigned int flags, struct path *parent_path,
12062306a36Sopenharmony_ci			       struct path *path, bool caseless);
12162306a36Sopenharmony_civoid ksmbd_vfs_kern_path_unlock(struct path *parent_path, struct path *path);
12262306a36Sopenharmony_cistruct dentry *ksmbd_vfs_kern_path_create(struct ksmbd_work *work,
12362306a36Sopenharmony_ci					  const char *name,
12462306a36Sopenharmony_ci					  unsigned int flags,
12562306a36Sopenharmony_ci					  struct path *path);
12662306a36Sopenharmony_ciint ksmbd_vfs_empty_dir(struct ksmbd_file *fp);
12762306a36Sopenharmony_civoid ksmbd_vfs_set_fadvise(struct file *filp, __le32 option);
12862306a36Sopenharmony_ciint ksmbd_vfs_zero_data(struct ksmbd_work *work, struct ksmbd_file *fp,
12962306a36Sopenharmony_ci			loff_t off, loff_t len);
13062306a36Sopenharmony_cistruct file_allocated_range_buffer;
13162306a36Sopenharmony_ciint ksmbd_vfs_fqar_lseek(struct ksmbd_file *fp, loff_t start, loff_t length,
13262306a36Sopenharmony_ci			 struct file_allocated_range_buffer *ranges,
13362306a36Sopenharmony_ci			 unsigned int in_count, unsigned int *out_count);
13462306a36Sopenharmony_ciint ksmbd_vfs_unlink(struct file *filp);
13562306a36Sopenharmony_civoid *ksmbd_vfs_init_kstat(char **p, struct ksmbd_kstat *ksmbd_kstat);
13662306a36Sopenharmony_ciint ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work,
13762306a36Sopenharmony_ci				struct mnt_idmap *idmap,
13862306a36Sopenharmony_ci				struct dentry *dentry,
13962306a36Sopenharmony_ci				struct ksmbd_kstat *ksmbd_kstat);
14062306a36Sopenharmony_civoid ksmbd_vfs_posix_lock_wait(struct file_lock *flock);
14162306a36Sopenharmony_ciint ksmbd_vfs_posix_lock_wait_timeout(struct file_lock *flock, long timeout);
14262306a36Sopenharmony_civoid ksmbd_vfs_posix_lock_unblock(struct file_lock *flock);
14362306a36Sopenharmony_ciint ksmbd_vfs_remove_acl_xattrs(struct mnt_idmap *idmap,
14462306a36Sopenharmony_ci				const struct path *path);
14562306a36Sopenharmony_ciint ksmbd_vfs_remove_sd_xattrs(struct mnt_idmap *idmap, const struct path *path);
14662306a36Sopenharmony_ciint ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn,
14762306a36Sopenharmony_ci			   struct mnt_idmap *idmap,
14862306a36Sopenharmony_ci			   const struct path *path,
14962306a36Sopenharmony_ci			   struct smb_ntsd *pntsd, int len,
15062306a36Sopenharmony_ci			   bool get_write);
15162306a36Sopenharmony_ciint ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn,
15262306a36Sopenharmony_ci			   struct mnt_idmap *idmap,
15362306a36Sopenharmony_ci			   struct dentry *dentry,
15462306a36Sopenharmony_ci			   struct smb_ntsd **pntsd);
15562306a36Sopenharmony_ciint ksmbd_vfs_set_dos_attrib_xattr(struct mnt_idmap *idmap,
15662306a36Sopenharmony_ci				   const struct path *path,
15762306a36Sopenharmony_ci				   struct xattr_dos_attrib *da,
15862306a36Sopenharmony_ci				   bool get_write);
15962306a36Sopenharmony_ciint ksmbd_vfs_get_dos_attrib_xattr(struct mnt_idmap *idmap,
16062306a36Sopenharmony_ci				   struct dentry *dentry,
16162306a36Sopenharmony_ci				   struct xattr_dos_attrib *da);
16262306a36Sopenharmony_ciint ksmbd_vfs_set_init_posix_acl(struct mnt_idmap *idmap,
16362306a36Sopenharmony_ci				 struct path *path);
16462306a36Sopenharmony_ciint ksmbd_vfs_inherit_posix_acl(struct mnt_idmap *idmap,
16562306a36Sopenharmony_ci				struct path *path,
16662306a36Sopenharmony_ci				struct inode *parent_inode);
16762306a36Sopenharmony_ci#endif /* __KSMBD_VFS_H__ */
168