xref: /freebsd/sys/contrib/openzfs/include/os/linux/zfs/sys/zpl.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2011, Lawrence Livermore National Security, LLC.
24  */
25 
26 #ifndef	_SYS_ZPL_H
27 #define	_SYS_ZPL_H
28 
29 #include <sys/mntent.h>
30 #include <sys/vfs.h>
31 #include <linux/aio.h>
32 #include <linux/dcache_compat.h>
33 #include <linux/exportfs.h>
34 #include <linux/falloc.h>
35 #include <linux/parser.h>
36 #include <linux/vfs_compat.h>
37 #include <linux/writeback.h>
38 #include <linux/xattr_compat.h>
39 
40 /* zpl_inode.c */
41 extern void zpl_vap_init(vattr_t *vap, struct inode *dir,
42     umode_t mode, cred_t *cr, zidmap_t *mnt_ns);
43 
44 extern const struct inode_operations zpl_inode_operations;
45 extern const struct inode_operations zpl_dir_inode_operations;
46 extern const struct inode_operations zpl_symlink_inode_operations;
47 extern const struct inode_operations zpl_special_inode_operations;
48 
49 /* zpl_file.c */
50 extern const struct address_space_operations zpl_address_space_operations;
51 extern const struct file_operations zpl_file_operations;
52 extern const struct file_operations zpl_dir_file_operations;
53 
54 /* zpl_super.c */
55 extern void zpl_prune_sb(uint64_t nr_to_scan, void *arg);
56 
57 extern const struct super_operations zpl_super_operations;
58 extern const struct export_operations zpl_export_operations;
59 extern struct file_system_type zpl_fs_type;
60 
61 /* zpl_xattr.c */
62 extern ssize_t zpl_xattr_list(struct dentry *dentry, char *buf, size_t size);
63 extern int zpl_xattr_security_init(struct inode *ip, struct inode *dip,
64     const struct qstr *qstr);
65 
66 #if defined(CONFIG_FS_POSIX_ACL)
67 
68 #if defined(HAVE_SET_ACL_IDMAP_DENTRY)
69 extern int zpl_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
70     struct posix_acl *acl, int type);
71 #elif defined(HAVE_SET_ACL_USERNS)
72 extern int zpl_set_acl(struct user_namespace *userns, struct inode *ip,
73     struct posix_acl *acl, int type);
74 #elif defined(HAVE_SET_ACL_USERNS_DENTRY_ARG2)
75 extern int zpl_set_acl(struct user_namespace *userns, struct dentry *dentry,
76     struct posix_acl *acl, int type);
77 #else
78 extern int zpl_set_acl(struct inode *ip, struct posix_acl *acl, int type);
79 #endif /* HAVE_SET_ACL_USERNS */
80 
81 #if defined(HAVE_GET_ACL_RCU) || defined(HAVE_GET_INODE_ACL)
82 extern struct posix_acl *zpl_get_acl(struct inode *ip, int type, bool rcu);
83 #elif defined(HAVE_GET_ACL)
84 extern struct posix_acl *zpl_get_acl(struct inode *ip, int type);
85 #endif
86 extern int zpl_init_acl(struct inode *ip, struct inode *dir);
87 extern int zpl_chmod_acl(struct inode *ip);
88 #else
89 static inline int
zpl_init_acl(struct inode * ip,struct inode * dir)90 zpl_init_acl(struct inode *ip, struct inode *dir)
91 {
92 	return (0);
93 }
94 
95 static inline int
zpl_chmod_acl(struct inode * ip)96 zpl_chmod_acl(struct inode *ip)
97 {
98 	return (0);
99 }
100 #endif /* CONFIG_FS_POSIX_ACL */
101 
102 extern xattr_handler_t *zpl_xattr_handlers[];
103 
104 /* zpl_ctldir.c */
105 extern const struct file_operations zpl_fops_root;
106 extern const struct inode_operations zpl_ops_root;
107 
108 extern const struct file_operations zpl_fops_snapdir;
109 extern const struct inode_operations zpl_ops_snapdir;
110 
111 extern const struct file_operations zpl_fops_shares;
112 extern const struct inode_operations zpl_ops_shares;
113 
114 /* zpl_file_range.c */
115 
116 /* handlers for file_operations of the same name */
117 extern ssize_t zpl_copy_file_range(struct file *src_file, loff_t src_off,
118     struct file *dst_file, loff_t dst_off, size_t len, unsigned int flags);
119 extern loff_t zpl_remap_file_range(struct file *src_file, loff_t src_off,
120     struct file *dst_file, loff_t dst_off, loff_t len, unsigned int flags);
121 extern int zpl_clone_file_range(struct file *src_file, loff_t src_off,
122     struct file *dst_file, loff_t dst_off, uint64_t len);
123 extern int zpl_dedupe_file_range(struct file *src_file, loff_t src_off,
124     struct file *dst_file, loff_t dst_off, uint64_t len);
125 
126 /* compat for FICLONE/FICLONERANGE/FIDEDUPERANGE ioctls */
127 typedef struct {
128 	int64_t		fcr_src_fd;
129 	uint64_t	fcr_src_offset;
130 	uint64_t	fcr_src_length;
131 	uint64_t	fcr_dest_offset;
132 } zfs_ioc_compat_file_clone_range_t;
133 
134 typedef struct {
135 	int64_t		fdri_dest_fd;
136 	uint64_t	fdri_dest_offset;
137 	uint64_t	fdri_bytes_deduped;
138 	int32_t		fdri_status;
139 	uint32_t	fdri_reserved;
140 } zfs_ioc_compat_dedupe_range_info_t;
141 
142 typedef struct {
143 	uint64_t	fdr_src_offset;
144 	uint64_t	fdr_src_length;
145 	uint16_t	fdr_dest_count;
146 	uint16_t	fdr_reserved1;
147 	uint32_t	fdr_reserved2;
148 	zfs_ioc_compat_dedupe_range_info_t	fdr_info[];
149 } zfs_ioc_compat_dedupe_range_t;
150 
151 #define	ZFS_IOC_COMPAT_FICLONE		_IOW(0x94, 9, int)
152 #define	ZFS_IOC_COMPAT_FICLONERANGE \
153     _IOW(0x94, 13, zfs_ioc_compat_file_clone_range_t)
154 #define	ZFS_IOC_COMPAT_FIDEDUPERANGE \
155     _IOWR(0x94, 54, zfs_ioc_compat_dedupe_range_t)
156 
157 extern long zpl_ioctl_ficlone(struct file *filp, void *arg);
158 extern long zpl_ioctl_ficlonerange(struct file *filp, void *arg);
159 extern long zpl_ioctl_fideduperange(struct file *filp, void *arg);
160 
161 
162 #if defined(HAVE_INODE_TIMESTAMP_TRUNCATE)
163 #define	zpl_inode_timestamp_truncate(ts, ip)	timestamp_truncate(ts, ip)
164 #else
165 #define	zpl_inode_timestamp_truncate(ts, ip)	\
166 	timespec64_trunc(ts, (ip)->i_sb->s_time_gran)
167 #endif
168 
169 #if defined(HAVE_INODE_OWNER_OR_CAPABLE)
170 #define	zpl_inode_owner_or_capable(ns, ip)	inode_owner_or_capable(ip)
171 #elif defined(HAVE_INODE_OWNER_OR_CAPABLE_USERNS)
172 #define	zpl_inode_owner_or_capable(ns, ip)	inode_owner_or_capable(ns, ip)
173 #elif defined(HAVE_INODE_OWNER_OR_CAPABLE_IDMAP)
174 #define	zpl_inode_owner_or_capable(idmap, ip) inode_owner_or_capable(idmap, ip)
175 #else
176 #error "Unsupported kernel"
177 #endif
178 
179 #if defined(HAVE_SETATTR_PREPARE_USERNS) || defined(HAVE_SETATTR_PREPARE_IDMAP)
180 #define	zpl_setattr_prepare(ns, dentry, ia)	setattr_prepare(ns, dentry, ia)
181 #else
182 /*
183  * Use kernel-provided version, or our own from
184  * linux/vfs_compat.h
185  */
186 #define	zpl_setattr_prepare(ns, dentry, ia)	setattr_prepare(dentry, ia)
187 #endif
188 
189 #ifdef HAVE_INODE_GET_CTIME
190 #define	zpl_inode_get_ctime(ip)	inode_get_ctime(ip)
191 #else
192 #define	zpl_inode_get_ctime(ip)	(ip->i_ctime)
193 #endif
194 #ifdef HAVE_INODE_SET_CTIME_TO_TS
195 #define	zpl_inode_set_ctime_to_ts(ip, ts)	inode_set_ctime_to_ts(ip, ts)
196 #else
197 #define	zpl_inode_set_ctime_to_ts(ip, ts)	(ip->i_ctime = ts)
198 #endif
199 #ifdef HAVE_INODE_GET_ATIME
200 #define	zpl_inode_get_atime(ip)	inode_get_atime(ip)
201 #else
202 #define	zpl_inode_get_atime(ip)	(ip->i_atime)
203 #endif
204 #ifdef HAVE_INODE_SET_ATIME_TO_TS
205 #define	zpl_inode_set_atime_to_ts(ip, ts)	inode_set_atime_to_ts(ip, ts)
206 #else
207 #define	zpl_inode_set_atime_to_ts(ip, ts)	(ip->i_atime = ts)
208 #endif
209 #ifdef HAVE_INODE_GET_MTIME
210 #define	zpl_inode_get_mtime(ip)	inode_get_mtime(ip)
211 #else
212 #define	zpl_inode_get_mtime(ip)	(ip->i_mtime)
213 #endif
214 #ifdef HAVE_INODE_SET_MTIME_TO_TS
215 #define	zpl_inode_set_mtime_to_ts(ip, ts)	inode_set_mtime_to_ts(ip, ts)
216 #else
217 #define	zpl_inode_set_mtime_to_ts(ip, ts)	(ip->i_mtime = ts)
218 #endif
219 
220 #endif	/* _SYS_ZPL_H */
221