blob: adf94a4f22fa6d21e058dfe29e2a01c7c5e3b8a2 [file] [log] [blame]
Namjae Jeonf4415842021-03-16 10:50:04 +09001/* 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"
Namjae Jeon8b758852021-06-29 14:52:00 +090017#include "xattr.h"
Namjae Jeonf4415842021-03-16 10:50:04 +090018
Namjae Jeonee2033e2021-06-22 13:26:24 +090019/*
20 * Enumeration for stream type.
21 */
22enum {
23 DATA_STREAM = 1, /* type $DATA */
24 DIR_STREAM /* type $INDEX_ALLOCATION */
25};
26
Namjae Jeonf4415842021-03-16 10:50:04 +090027/* CreateOptions */
Namjae Jeonf4415842021-03-16 10:50:04 +090028#define CREATE_TREE_CONNECTION cpu_to_le32(0x00000080)
Namjae Jeonf4415842021-03-16 10:50:04 +090029#define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000)
Namjae Jeonf4415842021-03-16 10:50:04 +090030
Namjae Jeonf4415842021-03-16 10:50:04 +090031#define CREATE_OPTION_READONLY 0x10000000
32/* system. NB not sent over wire */
33#define CREATE_OPTION_SPECIAL 0x20000000
34
35struct ksmbd_work;
36struct ksmbd_file;
37struct ksmbd_conn;
38
39struct ksmbd_dir_info {
40 const char *name;
41 char *wptr;
42 char *rptr;
43 int name_len;
44 int out_buf_len;
45 int num_entry;
46 int data_count;
47 int last_entry_offset;
48 bool hide_dot_file;
49 int flags;
50};
51
52struct ksmbd_readdir_data {
53 struct dir_context ctx;
54 union {
55 void *private;
56 char *dirent;
57 };
58
59 unsigned int used;
60 unsigned int dirent_count;
61 unsigned int file_attr;
62};
63
64/* ksmbd kstat wrapper to get valid create time when reading dir entry */
65struct ksmbd_kstat {
66 struct kstat *kstat;
67 unsigned long long create_time;
68 __le32 file_attributes;
69};
70
Christian Braunerda1e7ad2021-08-23 17:13:47 +020071int ksmbd_vfs_lock_parent(struct user_namespace *user_ns, struct dentry *parent,
72 struct dentry *child);
Hyunchul Leeaf349832021-06-30 18:25:53 +090073int ksmbd_vfs_may_delete(struct user_namespace *user_ns, struct dentry *dentry);
74int ksmbd_vfs_query_maximal_access(struct user_namespace *user_ns,
75 struct dentry *dentry, __le32 *daccess);
Namjae Jeonf4415842021-03-16 10:50:04 +090076int ksmbd_vfs_create(struct ksmbd_work *work, const char *name, umode_t mode);
77int ksmbd_vfs_mkdir(struct ksmbd_work *work, const char *name, umode_t mode);
78int ksmbd_vfs_read(struct ksmbd_work *work, struct ksmbd_file *fp,
Namjae Jeon070fb212021-05-26 17:57:12 +090079 size_t count, loff_t *pos);
Namjae Jeonf4415842021-03-16 10:50:04 +090080int ksmbd_vfs_write(struct ksmbd_work *work, struct ksmbd_file *fp,
Namjae Jeon070fb212021-05-26 17:57:12 +090081 char *buf, size_t count, loff_t *pos, bool sync,
82 ssize_t *written);
Namjae Jeon64b39f42021-03-30 14:25:35 +090083int ksmbd_vfs_fsync(struct ksmbd_work *work, u64 fid, u64 p_id);
Namjae Jeonf4415842021-03-16 10:50:04 +090084int ksmbd_vfs_remove_file(struct ksmbd_work *work, char *name);
85int ksmbd_vfs_link(struct ksmbd_work *work,
Namjae Jeon070fb212021-05-26 17:57:12 +090086 const char *oldname, const char *newname);
Namjae Jeonf4415842021-03-16 10:50:04 +090087int ksmbd_vfs_getattr(struct path *path, struct kstat *stat);
Namjae Jeonf4415842021-03-16 10:50:04 +090088int ksmbd_vfs_fp_rename(struct ksmbd_work *work, struct ksmbd_file *fp,
Namjae Jeon070fb212021-05-26 17:57:12 +090089 char *newname);
Hyunchul Lee265fd192021-09-25 00:06:16 +090090int ksmbd_vfs_truncate(struct ksmbd_work *work,
Namjae Jeon070fb212021-05-26 17:57:12 +090091 struct ksmbd_file *fp, loff_t size);
Namjae Jeonf4415842021-03-16 10:50:04 +090092struct srv_copychunk;
93int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,
Namjae Jeon070fb212021-05-26 17:57:12 +090094 struct ksmbd_file *src_fp,
95 struct ksmbd_file *dst_fp,
96 struct srv_copychunk *chunks,
97 unsigned int chunk_count,
98 unsigned int *chunk_count_written,
99 unsigned int *chunk_size_written,
100 loff_t *total_size_written);
Namjae Jeonf4415842021-03-16 10:50:04 +0900101ssize_t ksmbd_vfs_listxattr(struct dentry *dentry, char **list);
Hyunchul Leeaf349832021-06-30 18:25:53 +0900102ssize_t ksmbd_vfs_getxattr(struct user_namespace *user_ns,
103 struct dentry *dentry,
104 char *xattr_name,
Namjae Jeon070fb212021-05-26 17:57:12 +0900105 char **xattr_buf);
Hyunchul Leeaf349832021-06-30 18:25:53 +0900106ssize_t ksmbd_vfs_casexattr_len(struct user_namespace *user_ns,
107 struct dentry *dentry, char *attr_name,
Namjae Jeon070fb212021-05-26 17:57:12 +0900108 int attr_name_len);
Hyunchul Leeaf349832021-06-30 18:25:53 +0900109int ksmbd_vfs_setxattr(struct user_namespace *user_ns,
110 struct dentry *dentry, const char *attr_name,
Namjae Jeon070fb212021-05-26 17:57:12 +0900111 const void *attr_value, size_t attr_size, int flags);
Namjae Jeon64b39f42021-03-30 14:25:35 +0900112int ksmbd_vfs_xattr_stream_name(char *stream_name, char **xattr_stream_name,
Namjae Jeon070fb212021-05-26 17:57:12 +0900113 size_t *xattr_stream_name_size, int s_type);
Hyunchul Leeaf349832021-06-30 18:25:53 +0900114int ksmbd_vfs_remove_xattr(struct user_namespace *user_ns,
115 struct dentry *dentry, char *attr_name);
Hyunchul Lee265fd192021-09-25 00:06:16 +0900116int ksmbd_vfs_kern_path(struct ksmbd_work *work,
117 char *name, unsigned int flags, struct path *path,
Namjae Jeon070fb212021-05-26 17:57:12 +0900118 bool caseless);
Hyunchul Lee265fd192021-09-25 00:06:16 +0900119struct dentry *ksmbd_vfs_kern_path_create(struct ksmbd_work *work,
120 const char *name,
121 unsigned int flags,
122 struct path *path);
Namjae Jeonf4415842021-03-16 10:50:04 +0900123int ksmbd_vfs_empty_dir(struct ksmbd_file *fp);
124void ksmbd_vfs_set_fadvise(struct file *filp, __le32 option);
Namjae Jeon64b39f42021-03-30 14:25:35 +0900125int ksmbd_vfs_zero_data(struct ksmbd_work *work, struct ksmbd_file *fp,
Namjae Jeon070fb212021-05-26 17:57:12 +0900126 loff_t off, loff_t len);
Namjae Jeonf4415842021-03-16 10:50:04 +0900127struct file_allocated_range_buffer;
128int ksmbd_vfs_fqar_lseek(struct ksmbd_file *fp, loff_t start, loff_t length,
Namjae Jeon070fb212021-05-26 17:57:12 +0900129 struct file_allocated_range_buffer *ranges,
Namjae Jeonf7db8fd2021-10-08 07:31:03 +0900130 unsigned int in_count, unsigned int *out_count);
Hyunchul Leeaf349832021-06-30 18:25:53 +0900131int ksmbd_vfs_unlink(struct user_namespace *user_ns,
132 struct dentry *dir, struct dentry *dentry);
Namjae Jeonf4415842021-03-16 10:50:04 +0900133void *ksmbd_vfs_init_kstat(char **p, struct ksmbd_kstat *ksmbd_kstat);
Hyunchul Leeaf349832021-06-30 18:25:53 +0900134int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work,
135 struct user_namespace *user_ns,
136 struct dentry *dentry,
Namjae Jeon070fb212021-05-26 17:57:12 +0900137 struct ksmbd_kstat *ksmbd_kstat);
Hyunchul Lee45a64e82021-07-10 09:34:20 +0900138void ksmbd_vfs_posix_lock_wait(struct file_lock *flock);
Namjae Jeonf4415842021-03-16 10:50:04 +0900139int ksmbd_vfs_posix_lock_wait_timeout(struct file_lock *flock, long timeout);
140void ksmbd_vfs_posix_lock_unblock(struct file_lock *flock);
Hyunchul Leeaf349832021-06-30 18:25:53 +0900141int ksmbd_vfs_remove_acl_xattrs(struct user_namespace *user_ns,
142 struct dentry *dentry);
143int ksmbd_vfs_remove_sd_xattrs(struct user_namespace *user_ns,
144 struct dentry *dentry);
145int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn,
146 struct user_namespace *user_ns,
147 struct dentry *dentry,
Namjae Jeon070fb212021-05-26 17:57:12 +0900148 struct smb_ntsd *pntsd, int len);
Hyunchul Leeaf349832021-06-30 18:25:53 +0900149int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn,
150 struct user_namespace *user_ns,
151 struct dentry *dentry,
Namjae Jeon070fb212021-05-26 17:57:12 +0900152 struct smb_ntsd **pntsd);
Hyunchul Leeaf349832021-06-30 18:25:53 +0900153int ksmbd_vfs_set_dos_attrib_xattr(struct user_namespace *user_ns,
154 struct dentry *dentry,
Namjae Jeon070fb212021-05-26 17:57:12 +0900155 struct xattr_dos_attrib *da);
Hyunchul Leeaf349832021-06-30 18:25:53 +0900156int ksmbd_vfs_get_dos_attrib_xattr(struct user_namespace *user_ns,
157 struct dentry *dentry,
Namjae Jeon070fb212021-05-26 17:57:12 +0900158 struct xattr_dos_attrib *da);
Hyunchul Leeaf349832021-06-30 18:25:53 +0900159int ksmbd_vfs_set_init_posix_acl(struct user_namespace *user_ns,
160 struct inode *inode);
161int ksmbd_vfs_inherit_posix_acl(struct user_namespace *user_ns,
162 struct inode *inode,
Namjae Jeon070fb212021-05-26 17:57:12 +0900163 struct inode *parent_inode);
Namjae Jeonf4415842021-03-16 10:50:04 +0900164#endif /* __KSMBD_VFS_H__ */