]> git.proxmox.com Git - mirror_zfs.git/blob - include/sys/zpl.h
Add CODE_OF_CONDUCT.md
[mirror_zfs.git] / include / sys / zpl.h
1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2011, Lawrence Livermore National Security, LLC.
23 */
24
25 #ifndef _SYS_ZPL_H
26 #define _SYS_ZPL_H
27
28 #include <sys/mntent.h>
29 #include <sys/vfs.h>
30 #include <linux/aio.h>
31 #include <linux/dcache_compat.h>
32 #include <linux/exportfs.h>
33 #include <linux/falloc.h>
34 #include <linux/parser.h>
35 #include <linux/task_io_accounting_ops.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 zpl_umode_t mode, cred_t *cr);
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 extern dentry_operations_t zpl_dentry_operations;
49
50 /* zpl_file.c */
51 extern ssize_t zpl_read_common(struct inode *ip, const char *buf,
52 size_t len, loff_t *ppos, uio_seg_t segment, int flags,
53 cred_t *cr);
54 extern ssize_t zpl_write_common(struct inode *ip, const char *buf,
55 size_t len, loff_t *ppos, uio_seg_t segment, int flags,
56 cred_t *cr);
57 #if defined(HAVE_FILE_FALLOCATE) || defined(HAVE_INODE_FALLOCATE)
58 extern long zpl_fallocate_common(struct inode *ip, int mode,
59 loff_t offset, loff_t len);
60 #endif /* defined(HAVE_FILE_FALLOCATE) || defined(HAVE_INODE_FALLOCATE) */
61
62 extern const struct address_space_operations zpl_address_space_operations;
63 extern const struct file_operations zpl_file_operations;
64 extern const struct file_operations zpl_dir_file_operations;
65
66 /* zpl_super.c */
67 extern void zpl_prune_sb(int64_t nr_to_scan, void *arg);
68
69 extern const struct super_operations zpl_super_operations;
70 extern const struct export_operations zpl_export_operations;
71 extern struct file_system_type zpl_fs_type;
72
73 /* zpl_xattr.c */
74 extern ssize_t zpl_xattr_list(struct dentry *dentry, char *buf, size_t size);
75 extern int zpl_xattr_security_init(struct inode *ip, struct inode *dip,
76 const struct qstr *qstr);
77 #if defined(CONFIG_FS_POSIX_ACL)
78 extern int zpl_set_acl(struct inode *ip, struct posix_acl *acl, int type);
79 extern struct posix_acl *zpl_get_acl(struct inode *ip, int type);
80 #if !defined(HAVE_GET_ACL)
81 #if defined(HAVE_CHECK_ACL_WITH_FLAGS)
82 extern int zpl_check_acl(struct inode *inode, int mask, unsigned int flags);
83 #elif defined(HAVE_CHECK_ACL)
84 extern int zpl_check_acl(struct inode *inode, int mask);
85 #elif defined(HAVE_PERMISSION_WITH_NAMEIDATA)
86 extern int zpl_permission(struct inode *ip, int mask, struct nameidata *nd);
87 #elif defined(HAVE_PERMISSION)
88 extern int zpl_permission(struct inode *ip, int mask);
89 #endif /* HAVE_CHECK_ACL | HAVE_PERMISSION */
90 #endif /* HAVE_GET_ACL */
91
92 extern int zpl_init_acl(struct inode *ip, struct inode *dir);
93 extern int zpl_chmod_acl(struct inode *ip);
94 #else
95 static inline int
96 zpl_init_acl(struct inode *ip, struct inode *dir)
97 {
98 return (0);
99 }
100
101 static inline int
102 zpl_chmod_acl(struct inode *ip)
103 {
104 return (0);
105 }
106 #endif /* CONFIG_FS_POSIX_ACL */
107
108 extern xattr_handler_t *zpl_xattr_handlers[];
109
110 /* zpl_ctldir.c */
111 extern const struct file_operations zpl_fops_root;
112 extern const struct inode_operations zpl_ops_root;
113
114 extern const struct file_operations zpl_fops_snapdir;
115 extern const struct inode_operations zpl_ops_snapdir;
116 #ifdef HAVE_AUTOMOUNT
117 extern const struct dentry_operations zpl_dops_snapdirs;
118 #else
119 extern const struct inode_operations zpl_ops_snapdirs;
120 #endif /* HAVE_AUTOMOUNT */
121
122 extern const struct file_operations zpl_fops_shares;
123 extern const struct inode_operations zpl_ops_shares;
124
125 #if defined(HAVE_VFS_ITERATE) || defined(HAVE_VFS_ITERATE_SHARED)
126
127 #define ZPL_DIR_CONTEXT_INIT(_dirent, _actor, _pos) { \
128 .actor = _actor, \
129 .pos = _pos, \
130 }
131
132 typedef struct dir_context zpl_dir_context_t;
133
134 #define zpl_dir_emit dir_emit
135 #define zpl_dir_emit_dot dir_emit_dot
136 #define zpl_dir_emit_dotdot dir_emit_dotdot
137 #define zpl_dir_emit_dots dir_emit_dots
138
139 #else
140
141 typedef struct zpl_dir_context {
142 void *dirent;
143 const filldir_t actor;
144 loff_t pos;
145 } zpl_dir_context_t;
146
147 #define ZPL_DIR_CONTEXT_INIT(_dirent, _actor, _pos) { \
148 .dirent = _dirent, \
149 .actor = _actor, \
150 .pos = _pos, \
151 }
152
153 static inline bool
154 zpl_dir_emit(zpl_dir_context_t *ctx, const char *name, int namelen,
155 uint64_t ino, unsigned type)
156 {
157 return (!ctx->actor(ctx->dirent, name, namelen, ctx->pos, ino, type));
158 }
159
160 static inline bool
161 zpl_dir_emit_dot(struct file *file, zpl_dir_context_t *ctx)
162 {
163 return (ctx->actor(ctx->dirent, ".", 1, ctx->pos,
164 file_inode(file)->i_ino, DT_DIR) == 0);
165 }
166
167 static inline bool
168 zpl_dir_emit_dotdot(struct file *file, zpl_dir_context_t *ctx)
169 {
170 return (ctx->actor(ctx->dirent, "..", 2, ctx->pos,
171 parent_ino(file_dentry(file)), DT_DIR) == 0);
172 }
173
174 static inline bool
175 zpl_dir_emit_dots(struct file *file, zpl_dir_context_t *ctx)
176 {
177 if (ctx->pos == 0) {
178 if (!zpl_dir_emit_dot(file, ctx))
179 return (false);
180 ctx->pos = 1;
181 }
182 if (ctx->pos == 1) {
183 if (!zpl_dir_emit_dotdot(file, ctx))
184 return (false);
185 ctx->pos = 2;
186 }
187 return (true);
188 }
189 #endif /* HAVE_VFS_ITERATE */
190
191 /*
192 * Linux 4.18, inode times converted from timespec to timespec64.
193 */
194 #if defined(HAVE_INODE_TIMESPEC64_TIMES)
195 #define zpl_inode_timespec_trunc(ts, gran) timespec64_trunc(ts, gran)
196 #else
197 #define zpl_inode_timespec_trunc(ts, gran) timespec_trunc(ts, gran)
198 #endif
199
200 #endif /* _SYS_ZPL_H */