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 */ |
| 28 | /* Flag is set, it must not be a file , valid for directory only */ |
| 29 | #define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001) |
| 30 | #define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002) |
| 31 | #define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004) |
| 32 | |
| 33 | /* Should not buffer on server*/ |
| 34 | #define FILE_NO_INTERMEDIATE_BUFFERING_LE cpu_to_le32(0x00000008) |
| 35 | /* MBZ */ |
| 36 | #define FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010) |
| 37 | /* MBZ */ |
| 38 | #define FILE_SYNCHRONOUS_IO_NONALERT_LE cpu_to_le32(0x00000020) |
| 39 | |
| 40 | /* Flaf must not be set for directory */ |
| 41 | #define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040) |
| 42 | |
| 43 | /* Should be zero */ |
| 44 | #define CREATE_TREE_CONNECTION cpu_to_le32(0x00000080) |
| 45 | #define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100) |
| 46 | #define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200) |
| 47 | #define FILE_OPEN_REMOTE_INSTANCE cpu_to_le32(0x00000400) |
| 48 | |
| 49 | /** |
| 50 | * Doc says this is obsolete "open for recovery" flag should be zero |
| 51 | * in any case. |
| 52 | */ |
| 53 | #define CREATE_OPEN_FOR_RECOVERY cpu_to_le32(0x00000400) |
| 54 | #define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800) |
| 55 | #define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000) |
| 56 | #define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000) |
| 57 | #define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000) |
| 58 | #define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000) |
| 59 | |
| 60 | /* Should be zero*/ |
| 61 | #define FILE_OPEN_REQUIRING_OPLOCK cpu_to_le32(0x00010000) |
| 62 | #define FILE_DISALLOW_EXCLUSIVE cpu_to_le32(0x00020000) |
| 63 | #define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000) |
| 64 | #define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000) |
| 65 | #define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000) |
| 66 | |
| 67 | /* Should be zero */ |
| 68 | #define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE cpu_to_le32(0x00800000) |
| 69 | #define CREATE_OPTIONS_MASK cpu_to_le32(0x00FFFFFF) |
| 70 | #define CREATE_OPTION_READONLY 0x10000000 |
| 71 | /* system. NB not sent over wire */ |
| 72 | #define CREATE_OPTION_SPECIAL 0x20000000 |
| 73 | |
| 74 | struct ksmbd_work; |
| 75 | struct ksmbd_file; |
| 76 | struct ksmbd_conn; |
| 77 | |
| 78 | struct ksmbd_dir_info { |
| 79 | const char *name; |
| 80 | char *wptr; |
| 81 | char *rptr; |
| 82 | int name_len; |
| 83 | int out_buf_len; |
| 84 | int num_entry; |
| 85 | int data_count; |
| 86 | int last_entry_offset; |
| 87 | bool hide_dot_file; |
| 88 | int flags; |
| 89 | }; |
| 90 | |
| 91 | struct ksmbd_readdir_data { |
| 92 | struct dir_context ctx; |
| 93 | union { |
| 94 | void *private; |
| 95 | char *dirent; |
| 96 | }; |
| 97 | |
| 98 | unsigned int used; |
| 99 | unsigned int dirent_count; |
| 100 | unsigned int file_attr; |
| 101 | }; |
| 102 | |
| 103 | /* ksmbd kstat wrapper to get valid create time when reading dir entry */ |
| 104 | struct ksmbd_kstat { |
| 105 | struct kstat *kstat; |
| 106 | unsigned long long create_time; |
| 107 | __le32 file_attributes; |
| 108 | }; |
| 109 | |
Namjae Jeon | 12202c0 | 2021-06-29 09:23:56 +0900 | [diff] [blame] | 110 | int ksmbd_vfs_lock_parent(struct dentry *parent, struct dentry *child); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 111 | int ksmbd_vfs_may_delete(struct user_namespace *user_ns, struct dentry *dentry); |
| 112 | int ksmbd_vfs_query_maximal_access(struct user_namespace *user_ns, |
| 113 | struct dentry *dentry, __le32 *daccess); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 114 | int ksmbd_vfs_create(struct ksmbd_work *work, const char *name, umode_t mode); |
| 115 | int ksmbd_vfs_mkdir(struct ksmbd_work *work, const char *name, umode_t mode); |
| 116 | int ksmbd_vfs_read(struct ksmbd_work *work, struct ksmbd_file *fp, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 117 | size_t count, loff_t *pos); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 118 | int ksmbd_vfs_write(struct ksmbd_work *work, struct ksmbd_file *fp, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 119 | char *buf, size_t count, loff_t *pos, bool sync, |
| 120 | ssize_t *written); |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 121 | 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] | 122 | int ksmbd_vfs_remove_file(struct ksmbd_work *work, char *name); |
| 123 | int ksmbd_vfs_link(struct ksmbd_work *work, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 124 | const char *oldname, const char *newname); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 125 | int ksmbd_vfs_getattr(struct path *path, struct kstat *stat); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 126 | 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] | 127 | char *newname); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 128 | int ksmbd_vfs_truncate(struct ksmbd_work *work, const char *name, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 129 | struct ksmbd_file *fp, loff_t size); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 130 | struct srv_copychunk; |
| 131 | int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 132 | struct ksmbd_file *src_fp, |
| 133 | struct ksmbd_file *dst_fp, |
| 134 | struct srv_copychunk *chunks, |
| 135 | unsigned int chunk_count, |
| 136 | unsigned int *chunk_count_written, |
| 137 | unsigned int *chunk_size_written, |
| 138 | loff_t *total_size_written); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 139 | ssize_t ksmbd_vfs_listxattr(struct dentry *dentry, char **list); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 140 | ssize_t ksmbd_vfs_getxattr(struct user_namespace *user_ns, |
| 141 | struct dentry *dentry, |
| 142 | char *xattr_name, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 143 | char **xattr_buf); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 144 | ssize_t ksmbd_vfs_casexattr_len(struct user_namespace *user_ns, |
| 145 | struct dentry *dentry, char *attr_name, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 146 | int attr_name_len); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 147 | int ksmbd_vfs_setxattr(struct user_namespace *user_ns, |
| 148 | struct dentry *dentry, const char *attr_name, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 149 | const void *attr_value, size_t attr_size, int flags); |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 150 | 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] | 151 | size_t *xattr_stream_name_size, int s_type); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 152 | int ksmbd_vfs_remove_xattr(struct user_namespace *user_ns, |
| 153 | struct dentry *dentry, char *attr_name); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 154 | int ksmbd_vfs_kern_path(char *name, unsigned int flags, struct path *path, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 155 | bool caseless); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 156 | int ksmbd_vfs_empty_dir(struct ksmbd_file *fp); |
| 157 | void ksmbd_vfs_set_fadvise(struct file *filp, __le32 option); |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 158 | 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] | 159 | loff_t off, loff_t len); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 160 | struct file_allocated_range_buffer; |
| 161 | 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] | 162 | struct file_allocated_range_buffer *ranges, |
| 163 | int in_count, int *out_count); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 164 | int ksmbd_vfs_unlink(struct user_namespace *user_ns, |
| 165 | struct dentry *dir, struct dentry *dentry); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 166 | void *ksmbd_vfs_init_kstat(char **p, struct ksmbd_kstat *ksmbd_kstat); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 167 | int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work, |
| 168 | struct user_namespace *user_ns, |
| 169 | struct dentry *dentry, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 170 | struct ksmbd_kstat *ksmbd_kstat); |
Hyunchul Lee | 45a64e8 | 2021-07-10 09:34:20 +0900 | [diff] [blame^] | 171 | void ksmbd_vfs_posix_lock_wait(struct file_lock *flock); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 172 | int ksmbd_vfs_posix_lock_wait_timeout(struct file_lock *flock, long timeout); |
| 173 | void ksmbd_vfs_posix_lock_unblock(struct file_lock *flock); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 174 | int ksmbd_vfs_remove_acl_xattrs(struct user_namespace *user_ns, |
| 175 | struct dentry *dentry); |
| 176 | int ksmbd_vfs_remove_sd_xattrs(struct user_namespace *user_ns, |
| 177 | struct dentry *dentry); |
| 178 | int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn, |
| 179 | struct user_namespace *user_ns, |
| 180 | struct dentry *dentry, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 181 | struct smb_ntsd *pntsd, int len); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 182 | int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn, |
| 183 | struct user_namespace *user_ns, |
| 184 | struct dentry *dentry, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 185 | struct smb_ntsd **pntsd); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 186 | int ksmbd_vfs_set_dos_attrib_xattr(struct user_namespace *user_ns, |
| 187 | struct dentry *dentry, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 188 | struct xattr_dos_attrib *da); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 189 | int ksmbd_vfs_get_dos_attrib_xattr(struct user_namespace *user_ns, |
| 190 | struct dentry *dentry, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 191 | struct xattr_dos_attrib *da); |
Hyunchul Lee | af34983 | 2021-06-30 18:25:53 +0900 | [diff] [blame] | 192 | int ksmbd_vfs_set_init_posix_acl(struct user_namespace *user_ns, |
| 193 | struct inode *inode); |
| 194 | int ksmbd_vfs_inherit_posix_acl(struct user_namespace *user_ns, |
| 195 | struct inode *inode, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 196 | struct inode *parent_inode); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 197 | #endif /* __KSMBD_VFS_H__ */ |