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 https://opensource.org/licenses/CDDL-1.0. 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 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 extern const struct address_space_operations zpl_address_space_operations; 50 extern const struct file_operations zpl_file_operations; 51 extern const struct file_operations zpl_dir_file_operations; 52 53 /* zpl_super.c */ 54 extern void zpl_prune_sb(int64_t nr_to_scan, void *arg); 55 56 extern const struct super_operations zpl_super_operations; 57 extern const struct export_operations zpl_export_operations; 58 extern struct file_system_type zpl_fs_type; 59 60 /* zpl_xattr.c */ 61 extern ssize_t zpl_xattr_list(struct dentry *dentry, char *buf, size_t size); 62 extern int zpl_xattr_security_init(struct inode *ip, struct inode *dip, 63 const struct qstr *qstr); 64 #if defined(CONFIG_FS_POSIX_ACL) 65 #if defined(HAVE_SET_ACL) 66 #if defined(HAVE_SET_ACL_USERNS) 67 extern int zpl_set_acl(struct user_namespace *userns, struct inode *ip, 68 struct posix_acl *acl, int type); 69 #else 70 extern int zpl_set_acl(struct inode *ip, struct posix_acl *acl, int type); 71 #endif /* HAVE_SET_ACL_USERNS */ 72 #endif /* HAVE_SET_ACL */ 73 #if defined(HAVE_GET_ACL_RCU) 74 extern struct posix_acl *zpl_get_acl(struct inode *ip, int type, bool rcu); 75 #elif defined(HAVE_GET_ACL) 76 extern struct posix_acl *zpl_get_acl(struct inode *ip, int type); 77 #endif 78 extern int zpl_init_acl(struct inode *ip, struct inode *dir); 79 extern int zpl_chmod_acl(struct inode *ip); 80 #else 81 static inline int 82 zpl_init_acl(struct inode *ip, struct inode *dir) 83 { 84 return (0); 85 } 86 87 static inline int 88 zpl_chmod_acl(struct inode *ip) 89 { 90 return (0); 91 } 92 #endif /* CONFIG_FS_POSIX_ACL */ 93 94 extern xattr_handler_t *zpl_xattr_handlers[]; 95 96 /* zpl_ctldir.c */ 97 extern const struct file_operations zpl_fops_root; 98 extern const struct inode_operations zpl_ops_root; 99 100 extern const struct file_operations zpl_fops_snapdir; 101 extern const struct inode_operations zpl_ops_snapdir; 102 103 extern const struct file_operations zpl_fops_shares; 104 extern const struct inode_operations zpl_ops_shares; 105 106 #if defined(HAVE_VFS_ITERATE) || defined(HAVE_VFS_ITERATE_SHARED) 107 108 #define ZPL_DIR_CONTEXT_INIT(_dirent, _actor, _pos) { \ 109 .actor = _actor, \ 110 .pos = _pos, \ 111 } 112 113 typedef struct dir_context zpl_dir_context_t; 114 115 #define zpl_dir_emit dir_emit 116 #define zpl_dir_emit_dot dir_emit_dot 117 #define zpl_dir_emit_dotdot dir_emit_dotdot 118 #define zpl_dir_emit_dots dir_emit_dots 119 120 #else 121 122 typedef struct zpl_dir_context { 123 void *dirent; 124 const filldir_t actor; 125 loff_t pos; 126 } zpl_dir_context_t; 127 128 #define ZPL_DIR_CONTEXT_INIT(_dirent, _actor, _pos) { \ 129 .dirent = _dirent, \ 130 .actor = _actor, \ 131 .pos = _pos, \ 132 } 133 134 static inline bool 135 zpl_dir_emit(zpl_dir_context_t *ctx, const char *name, int namelen, 136 uint64_t ino, unsigned type) 137 { 138 return (!ctx->actor(ctx->dirent, name, namelen, ctx->pos, ino, type)); 139 } 140 141 static inline bool 142 zpl_dir_emit_dot(struct file *file, zpl_dir_context_t *ctx) 143 { 144 return (ctx->actor(ctx->dirent, ".", 1, ctx->pos, 145 file_inode(file)->i_ino, DT_DIR) == 0); 146 } 147 148 static inline bool 149 zpl_dir_emit_dotdot(struct file *file, zpl_dir_context_t *ctx) 150 { 151 return (ctx->actor(ctx->dirent, "..", 2, ctx->pos, 152 parent_ino(file_dentry(file)), DT_DIR) == 0); 153 } 154 155 static inline bool 156 zpl_dir_emit_dots(struct file *file, zpl_dir_context_t *ctx) 157 { 158 if (ctx->pos == 0) { 159 if (!zpl_dir_emit_dot(file, ctx)) 160 return (false); 161 ctx->pos = 1; 162 } 163 if (ctx->pos == 1) { 164 if (!zpl_dir_emit_dotdot(file, ctx)) 165 return (false); 166 ctx->pos = 2; 167 } 168 return (true); 169 } 170 #endif /* HAVE_VFS_ITERATE */ 171 172 #if defined(HAVE_INODE_TIMESTAMP_TRUNCATE) 173 #define zpl_inode_timestamp_truncate(ts, ip) timestamp_truncate(ts, ip) 174 #elif defined(HAVE_INODE_TIMESPEC64_TIMES) 175 #define zpl_inode_timestamp_truncate(ts, ip) \ 176 timespec64_trunc(ts, (ip)->i_sb->s_time_gran) 177 #else 178 #define zpl_inode_timestamp_truncate(ts, ip) \ 179 timespec_trunc(ts, (ip)->i_sb->s_time_gran) 180 #endif 181 182 #if defined(HAVE_INODE_OWNER_OR_CAPABLE) 183 #define zpl_inode_owner_or_capable(ns, ip) inode_owner_or_capable(ip) 184 #elif defined(HAVE_INODE_OWNER_OR_CAPABLE_IDMAPPED) 185 #define zpl_inode_owner_or_capable(ns, ip) inode_owner_or_capable(ns, ip) 186 #else 187 #error "Unsupported kernel" 188 #endif 189 190 #ifdef HAVE_SETATTR_PREPARE_USERNS 191 #define zpl_setattr_prepare(ns, dentry, ia) setattr_prepare(ns, dentry, ia) 192 #else 193 /* 194 * Use kernel-provided version, or our own from 195 * linux/vfs_compat.h 196 */ 197 #define zpl_setattr_prepare(ns, dentry, ia) setattr_prepare(dentry, ia) 198 #endif 199 200 #endif /* _SYS_ZPL_H */ 201