Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 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" |
Namjae Jeon | 8b75885 | 2021-06-29 14:52:00 +0900 | [diff] [blame] | 17 | #include "xattr.h" |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 18 | |
Namjae Jeon | ee2033e | 2021-06-22 13:26:24 +0900 | [diff] [blame] | 19 | /* |
| 20 | * Enumeration for stream type. |
| 21 | */ |
| 22 | enum { |
| 23 | DATA_STREAM = 1, /* type $DATA */ |
| 24 | DIR_STREAM /* type $INDEX_ALLOCATION */ |
| 25 | }; |
| 26 | |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 27 | /* CreateOptions */ |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 28 | #define CREATE_TREE_CONNECTION cpu_to_le32(0x00000080) |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 29 | #define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000) |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 30 | |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 31 | #define CREATE_OPTION_READONLY 0x10000000 |
| 32 | /* system. NB not sent over wire */ |
| 33 | #define CREATE_OPTION_SPECIAL 0x20000000 |
| 34 | |
| 35 | struct ksmbd_work; |
| 36 | struct ksmbd_file; |
| 37 | struct ksmbd_conn; |
| 38 | |
| 39 | struct 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; |
Namjae Jeon | 04e2609 | 2022-01-30 18:31:01 +0900 | [diff] [blame] | 50 | int last_entry_off_align; |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | struct ksmbd_readdir_data { |
| 54 | struct dir_context ctx; |
| 55 | union { |
| 56 | void *private; |
| 57 | char *dirent; |
| 58 | }; |
| 59 | |
| 60 | unsigned int used; |
| 61 | unsigned int dirent_count; |
| 62 | unsigned int file_attr; |
| 63 | }; |
| 64 | |
| 65 | /* ksmbd kstat wrapper to get valid create time when reading dir entry */ |
| 66 | struct ksmbd_kstat { |
| 67 | struct kstat *kstat; |
| 68 | unsigned long long create_time; |
| 69 | __le32 file_attributes; |
| 70 | }; |
| 71 | |
Christian Brauner | da1e7ad | 2021-08-23 17:13:47 +0200 | [diff] [blame] | 72 | int ksmbd_vfs_lock_parent(struct user_namespace *user_ns, struct dentry *parent, |
| 73 | struct dentry *child); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 74 | int ksmbd_vfs_may_delete(struct user_namespace *user_ns, struct dentry *dentry); |
| 75 | int ksmbd_vfs_query_maximal_access(struct user_namespace *user_ns, |
| 76 | struct dentry *dentry, __le32 *daccess); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 77 | int ksmbd_vfs_create(struct ksmbd_work *work, const char *name, umode_t mode); |
| 78 | int ksmbd_vfs_mkdir(struct ksmbd_work *work, const char *name, umode_t mode); |
| 79 | int ksmbd_vfs_read(struct ksmbd_work *work, struct ksmbd_file *fp, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 80 | size_t count, loff_t *pos); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 81 | int ksmbd_vfs_write(struct ksmbd_work *work, struct ksmbd_file *fp, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 82 | char *buf, size_t count, loff_t *pos, bool sync, |
| 83 | ssize_t *written); |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 84 | int ksmbd_vfs_fsync(struct ksmbd_work *work, u64 fid, u64 p_id); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 85 | int ksmbd_vfs_remove_file(struct ksmbd_work *work, char *name); |
| 86 | int ksmbd_vfs_link(struct ksmbd_work *work, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 87 | const char *oldname, const char *newname); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 88 | int ksmbd_vfs_getattr(struct path *path, struct kstat *stat); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 89 | int ksmbd_vfs_fp_rename(struct ksmbd_work *work, struct ksmbd_file *fp, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 90 | char *newname); |
Hyunchul Lee | 265fd19 | 2021-09-25 00:06:16 +0900 | [diff] [blame] | 91 | int ksmbd_vfs_truncate(struct ksmbd_work *work, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 92 | struct ksmbd_file *fp, loff_t size); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 93 | struct srv_copychunk; |
| 94 | int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 95 | struct ksmbd_file *src_fp, |
| 96 | struct ksmbd_file *dst_fp, |
| 97 | struct srv_copychunk *chunks, |
| 98 | unsigned int chunk_count, |
| 99 | unsigned int *chunk_count_written, |
| 100 | unsigned int *chunk_size_written, |
| 101 | loff_t *total_size_written); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 102 | ssize_t ksmbd_vfs_listxattr(struct dentry *dentry, char **list); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 103 | ssize_t ksmbd_vfs_getxattr(struct user_namespace *user_ns, |
| 104 | struct dentry *dentry, |
| 105 | char *xattr_name, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 106 | char **xattr_buf); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 107 | ssize_t ksmbd_vfs_casexattr_len(struct user_namespace *user_ns, |
| 108 | struct dentry *dentry, char *attr_name, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 109 | int attr_name_len); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 110 | int ksmbd_vfs_setxattr(struct user_namespace *user_ns, |
| 111 | struct dentry *dentry, const char *attr_name, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 112 | const void *attr_value, size_t attr_size, int flags); |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 113 | int ksmbd_vfs_xattr_stream_name(char *stream_name, char **xattr_stream_name, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 114 | size_t *xattr_stream_name_size, int s_type); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 115 | int ksmbd_vfs_remove_xattr(struct user_namespace *user_ns, |
| 116 | struct dentry *dentry, char *attr_name); |
Hyunchul Lee | 265fd19 | 2021-09-25 00:06:16 +0900 | [diff] [blame] | 117 | int ksmbd_vfs_kern_path(struct ksmbd_work *work, |
| 118 | char *name, unsigned int flags, struct path *path, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 119 | bool caseless); |
Hyunchul Lee | 265fd19 | 2021-09-25 00:06:16 +0900 | [diff] [blame] | 120 | struct dentry *ksmbd_vfs_kern_path_create(struct ksmbd_work *work, |
| 121 | const char *name, |
| 122 | unsigned int flags, |
| 123 | struct path *path); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 124 | int ksmbd_vfs_empty_dir(struct ksmbd_file *fp); |
| 125 | void ksmbd_vfs_set_fadvise(struct file *filp, __le32 option); |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 126 | int ksmbd_vfs_zero_data(struct ksmbd_work *work, struct ksmbd_file *fp, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 127 | loff_t off, loff_t len); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 128 | struct file_allocated_range_buffer; |
| 129 | int ksmbd_vfs_fqar_lseek(struct ksmbd_file *fp, loff_t start, loff_t length, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 130 | struct file_allocated_range_buffer *ranges, |
Namjae Jeon | f7db8fd | 2021-10-08 07:31:03 +0900 | [diff] [blame] | 131 | unsigned int in_count, unsigned int *out_count); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 132 | int ksmbd_vfs_unlink(struct user_namespace *user_ns, |
| 133 | struct dentry *dir, struct dentry *dentry); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 134 | void *ksmbd_vfs_init_kstat(char **p, struct ksmbd_kstat *ksmbd_kstat); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 135 | int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work, |
| 136 | struct user_namespace *user_ns, |
| 137 | struct dentry *dentry, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 138 | struct ksmbd_kstat *ksmbd_kstat); |
Hyunchul Lee | 45a64e8 | 2021-07-10 09:34:20 +0900 | [diff] [blame] | 139 | void ksmbd_vfs_posix_lock_wait(struct file_lock *flock); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 140 | int ksmbd_vfs_posix_lock_wait_timeout(struct file_lock *flock, long timeout); |
| 141 | void ksmbd_vfs_posix_lock_unblock(struct file_lock *flock); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 142 | int ksmbd_vfs_remove_acl_xattrs(struct user_namespace *user_ns, |
| 143 | struct dentry *dentry); |
| 144 | int ksmbd_vfs_remove_sd_xattrs(struct user_namespace *user_ns, |
| 145 | struct dentry *dentry); |
| 146 | int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn, |
| 147 | struct user_namespace *user_ns, |
| 148 | struct dentry *dentry, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 149 | struct smb_ntsd *pntsd, int len); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 150 | int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn, |
| 151 | struct user_namespace *user_ns, |
| 152 | struct dentry *dentry, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 153 | struct smb_ntsd **pntsd); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 154 | int ksmbd_vfs_set_dos_attrib_xattr(struct user_namespace *user_ns, |
| 155 | struct dentry *dentry, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 156 | struct xattr_dos_attrib *da); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 157 | int ksmbd_vfs_get_dos_attrib_xattr(struct user_namespace *user_ns, |
| 158 | struct dentry *dentry, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 159 | struct xattr_dos_attrib *da); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 160 | int ksmbd_vfs_set_init_posix_acl(struct user_namespace *user_ns, |
| 161 | struct inode *inode); |
| 162 | int ksmbd_vfs_inherit_posix_acl(struct user_namespace *user_ns, |
| 163 | struct inode *inode, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 164 | struct inode *parent_inode); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 165 | #endif /* __KSMBD_VFS_H__ */ |