Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2011 Novell Inc. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published by |
| 7 | * the Free Software Foundation. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/fs.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/xattr.h> |
| 13 | #include "overlayfs.h" |
| 14 | |
Al Viro | 0f7ff2d | 2015-12-06 12:31:07 -0500 | [diff] [blame] | 15 | static int ovl_copy_up_truncate(struct dentry *dentry) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 16 | { |
| 17 | int err; |
| 18 | struct dentry *parent; |
| 19 | struct kstat stat; |
| 20 | struct path lowerpath; |
| 21 | |
| 22 | parent = dget_parent(dentry); |
| 23 | err = ovl_copy_up(parent); |
| 24 | if (err) |
| 25 | goto out_dput_parent; |
| 26 | |
| 27 | ovl_path_lower(dentry, &lowerpath); |
| 28 | err = vfs_getattr(&lowerpath, &stat); |
| 29 | if (err) |
| 30 | goto out_dput_parent; |
| 31 | |
Al Viro | 0f7ff2d | 2015-12-06 12:31:07 -0500 | [diff] [blame] | 32 | stat.size = 0; |
| 33 | err = ovl_copy_up_one(parent, dentry, &lowerpath, &stat); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 34 | |
| 35 | out_dput_parent: |
| 36 | dput(parent); |
| 37 | return err; |
| 38 | } |
| 39 | |
| 40 | int ovl_setattr(struct dentry *dentry, struct iattr *attr) |
| 41 | { |
| 42 | int err; |
| 43 | struct dentry *upperdentry; |
| 44 | |
Miklos Szeredi | cf9a678 | 2015-12-11 16:30:49 +0100 | [diff] [blame] | 45 | /* |
| 46 | * Check for permissions before trying to copy-up. This is redundant |
| 47 | * since it will be rechecked later by ->setattr() on upper dentry. But |
| 48 | * without this, copy-up can be triggered by just about anybody. |
| 49 | * |
| 50 | * We don't initialize inode->size, which just means that |
| 51 | * inode_newsize_ok() will always check against MAX_LFS_FILESIZE and not |
| 52 | * check for a swapfile (which this won't be anyway). |
| 53 | */ |
| 54 | err = inode_change_ok(dentry->d_inode, attr); |
| 55 | if (err) |
| 56 | return err; |
| 57 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 58 | err = ovl_want_write(dentry); |
| 59 | if (err) |
| 60 | goto out; |
| 61 | |
Miklos Szeredi | 03bea60 | 2016-06-29 16:03:55 +0200 | [diff] [blame] | 62 | if (attr->ia_valid & ATTR_SIZE) { |
| 63 | struct inode *realinode = d_inode(ovl_dentry_real(dentry)); |
| 64 | |
| 65 | err = -ETXTBSY; |
| 66 | if (atomic_read(&realinode->i_writecount) < 0) |
| 67 | goto out_drop_write; |
| 68 | } |
| 69 | |
Miklos Szeredi | acff81e | 2015-12-04 19:18:48 +0100 | [diff] [blame] | 70 | err = ovl_copy_up(dentry); |
| 71 | if (!err) { |
Miklos Szeredi | 03bea60 | 2016-06-29 16:03:55 +0200 | [diff] [blame] | 72 | struct inode *winode = NULL; |
| 73 | |
Miklos Szeredi | acff81e | 2015-12-04 19:18:48 +0100 | [diff] [blame] | 74 | upperdentry = ovl_dentry_upper(dentry); |
| 75 | |
Miklos Szeredi | 03bea60 | 2016-06-29 16:03:55 +0200 | [diff] [blame] | 76 | if (attr->ia_valid & ATTR_SIZE) { |
| 77 | winode = d_inode(upperdentry); |
| 78 | err = get_write_access(winode); |
| 79 | if (err) |
| 80 | goto out_drop_write; |
| 81 | } |
| 82 | |
Miklos Szeredi | b99c2d9 | 2016-07-04 16:49:48 +0200 | [diff] [blame] | 83 | if (attr->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID)) |
| 84 | attr->ia_valid &= ~ATTR_MODE; |
| 85 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 86 | inode_lock(upperdentry->d_inode); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 87 | err = notify_change(upperdentry, attr, NULL); |
Konstantin Khlebnikov | b81de06 | 2016-01-31 16:21:29 +0300 | [diff] [blame] | 88 | if (!err) |
| 89 | ovl_copyattr(upperdentry->d_inode, dentry->d_inode); |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 90 | inode_unlock(upperdentry->d_inode); |
Miklos Szeredi | 03bea60 | 2016-06-29 16:03:55 +0200 | [diff] [blame] | 91 | |
| 92 | if (winode) |
| 93 | put_write_access(winode); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 94 | } |
Miklos Szeredi | 03bea60 | 2016-06-29 16:03:55 +0200 | [diff] [blame] | 95 | out_drop_write: |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 96 | ovl_drop_write(dentry); |
| 97 | out: |
| 98 | return err; |
| 99 | } |
| 100 | |
| 101 | static int ovl_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 102 | struct kstat *stat) |
| 103 | { |
| 104 | struct path realpath; |
| 105 | |
| 106 | ovl_path_real(dentry, &realpath); |
| 107 | return vfs_getattr(&realpath, stat); |
| 108 | } |
| 109 | |
| 110 | int ovl_permission(struct inode *inode, int mask) |
| 111 | { |
Andreas Gruenbacher | 58ed4e7 | 2016-05-26 02:01:47 +0200 | [diff] [blame] | 112 | struct ovl_entry *oe = inode->i_private; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 113 | bool is_upper; |
Andreas Gruenbacher | 58ed4e7 | 2016-05-26 02:01:47 +0200 | [diff] [blame] | 114 | struct dentry *realdentry = ovl_entry_real(oe, &is_upper); |
| 115 | struct inode *realinode; |
Vivek Goyal | c0ca3d7 | 2016-07-01 16:34:27 -0400 | [diff] [blame^] | 116 | const struct cred *old_cred; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 117 | int err; |
| 118 | |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 119 | if (ovl_is_default_permissions(inode)) { |
| 120 | struct kstat stat; |
| 121 | struct path realpath = { .dentry = realdentry }; |
| 122 | |
| 123 | if (mask & MAY_NOT_BLOCK) |
| 124 | return -ECHILD; |
| 125 | |
| 126 | realpath.mnt = ovl_entry_mnt_real(oe, inode, is_upper); |
| 127 | |
| 128 | err = vfs_getattr(&realpath, &stat); |
| 129 | if (err) |
Andreas Gruenbacher | 58ed4e7 | 2016-05-26 02:01:47 +0200 | [diff] [blame] | 130 | return err; |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 131 | |
| 132 | if ((stat.mode ^ inode->i_mode) & S_IFMT) |
Andreas Gruenbacher | 58ed4e7 | 2016-05-26 02:01:47 +0200 | [diff] [blame] | 133 | return -ESTALE; |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 134 | |
| 135 | inode->i_mode = stat.mode; |
| 136 | inode->i_uid = stat.uid; |
| 137 | inode->i_gid = stat.gid; |
| 138 | |
Andreas Gruenbacher | 58ed4e7 | 2016-05-26 02:01:47 +0200 | [diff] [blame] | 139 | return generic_permission(inode, mask); |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 140 | } |
| 141 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 142 | /* Careful in RCU walk mode */ |
Andreas Gruenbacher | 58ed4e7 | 2016-05-26 02:01:47 +0200 | [diff] [blame] | 143 | realinode = d_inode_rcu(realdentry); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 144 | if (!realinode) { |
| 145 | WARN_ON(!(mask & MAY_NOT_BLOCK)); |
Andreas Gruenbacher | 58ed4e7 | 2016-05-26 02:01:47 +0200 | [diff] [blame] | 146 | return -ENOENT; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | if (mask & MAY_WRITE) { |
| 150 | umode_t mode = realinode->i_mode; |
| 151 | |
| 152 | /* |
| 153 | * Writes will always be redirected to upper layer, so |
| 154 | * ignore lower layer being read-only. |
| 155 | * |
| 156 | * If the overlay itself is read-only then proceed |
| 157 | * with the permission check, don't return EROFS. |
| 158 | * This will only happen if this is the lower layer of |
| 159 | * another overlayfs. |
| 160 | * |
| 161 | * If upper fs becomes read-only after the overlay was |
| 162 | * constructed return EROFS to prevent modification of |
| 163 | * upper layer. |
| 164 | */ |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 165 | if (is_upper && !IS_RDONLY(inode) && IS_RDONLY(realinode) && |
| 166 | (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))) |
Andreas Gruenbacher | 58ed4e7 | 2016-05-26 02:01:47 +0200 | [diff] [blame] | 167 | return -EROFS; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 168 | } |
| 169 | |
Vivek Goyal | c0ca3d7 | 2016-07-01 16:34:27 -0400 | [diff] [blame^] | 170 | /* |
| 171 | * Check overlay inode with the creds of task and underlying inode |
| 172 | * with creds of mounter |
| 173 | */ |
| 174 | err = generic_permission(inode, mask); |
| 175 | if (err) |
| 176 | return err; |
| 177 | |
| 178 | old_cred = ovl_override_creds(inode->i_sb); |
| 179 | err = __inode_permission(realinode, mask); |
| 180 | revert_creds(old_cred); |
| 181 | |
| 182 | return err; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 185 | static const char *ovl_get_link(struct dentry *dentry, |
Al Viro | fceef39 | 2015-12-29 15:58:39 -0500 | [diff] [blame] | 186 | struct inode *inode, |
| 187 | struct delayed_call *done) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 188 | { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 189 | struct dentry *realdentry; |
| 190 | struct inode *realinode; |
| 191 | |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 192 | if (!dentry) |
| 193 | return ERR_PTR(-ECHILD); |
| 194 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 195 | realdentry = ovl_dentry_real(dentry); |
| 196 | realinode = realdentry->d_inode; |
| 197 | |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 198 | if (WARN_ON(!realinode->i_op->get_link)) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 199 | return ERR_PTR(-EPERM); |
| 200 | |
Al Viro | fceef39 | 2015-12-29 15:58:39 -0500 | [diff] [blame] | 201 | return realinode->i_op->get_link(realdentry, realinode, done); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | static int ovl_readlink(struct dentry *dentry, char __user *buf, int bufsiz) |
| 205 | { |
| 206 | struct path realpath; |
| 207 | struct inode *realinode; |
| 208 | |
| 209 | ovl_path_real(dentry, &realpath); |
| 210 | realinode = realpath.dentry->d_inode; |
| 211 | |
| 212 | if (!realinode->i_op->readlink) |
| 213 | return -EINVAL; |
| 214 | |
| 215 | touch_atime(&realpath); |
| 216 | |
| 217 | return realinode->i_op->readlink(realpath.dentry, buf, bufsiz); |
| 218 | } |
| 219 | |
| 220 | |
| 221 | static bool ovl_is_private_xattr(const char *name) |
| 222 | { |
hujianyang | cead89b | 2014-11-24 18:25:21 +0800 | [diff] [blame] | 223 | return strncmp(name, OVL_XATTR_PRE_NAME, OVL_XATTR_PRE_LEN) == 0; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Al Viro | 3767e25 | 2016-05-27 11:06:05 -0400 | [diff] [blame] | 226 | int ovl_setxattr(struct dentry *dentry, struct inode *inode, |
| 227 | const char *name, const void *value, |
| 228 | size_t size, int flags) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 229 | { |
| 230 | int err; |
| 231 | struct dentry *upperdentry; |
| 232 | |
| 233 | err = ovl_want_write(dentry); |
| 234 | if (err) |
| 235 | goto out; |
| 236 | |
| 237 | err = -EPERM; |
| 238 | if (ovl_is_private_xattr(name)) |
| 239 | goto out_drop_write; |
| 240 | |
| 241 | err = ovl_copy_up(dentry); |
| 242 | if (err) |
| 243 | goto out_drop_write; |
| 244 | |
| 245 | upperdentry = ovl_dentry_upper(dentry); |
| 246 | err = vfs_setxattr(upperdentry, name, value, size, flags); |
| 247 | |
| 248 | out_drop_write: |
| 249 | ovl_drop_write(dentry); |
| 250 | out: |
| 251 | return err; |
| 252 | } |
| 253 | |
Al Viro | ce23e64 | 2016-04-11 00:48:00 -0400 | [diff] [blame] | 254 | ssize_t ovl_getxattr(struct dentry *dentry, struct inode *inode, |
| 255 | const char *name, void *value, size_t size) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 256 | { |
Miklos Szeredi | b581755 | 2016-06-06 16:21:37 +0200 | [diff] [blame] | 257 | struct dentry *realdentry = ovl_dentry_real(dentry); |
Miklos Szeredi | 5214846 | 2014-11-20 16:40:00 +0100 | [diff] [blame] | 258 | |
Miklos Szeredi | b581755 | 2016-06-06 16:21:37 +0200 | [diff] [blame] | 259 | if (ovl_is_private_xattr(name)) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 260 | return -ENODATA; |
| 261 | |
Miklos Szeredi | b581755 | 2016-06-06 16:21:37 +0200 | [diff] [blame] | 262 | return vfs_getxattr(realdentry, name, value, size); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size) |
| 266 | { |
Miklos Szeredi | b581755 | 2016-06-06 16:21:37 +0200 | [diff] [blame] | 267 | struct dentry *realdentry = ovl_dentry_real(dentry); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 268 | ssize_t res; |
| 269 | int off; |
| 270 | |
Miklos Szeredi | b581755 | 2016-06-06 16:21:37 +0200 | [diff] [blame] | 271 | res = vfs_listxattr(realdentry, list, size); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 272 | if (res <= 0 || size == 0) |
| 273 | return res; |
| 274 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 275 | /* filter out private xattrs */ |
| 276 | for (off = 0; off < res;) { |
| 277 | char *s = list + off; |
| 278 | size_t slen = strlen(s) + 1; |
| 279 | |
| 280 | BUG_ON(off + slen > res); |
| 281 | |
| 282 | if (ovl_is_private_xattr(s)) { |
| 283 | res -= slen; |
| 284 | memmove(s, s + slen, res - off); |
| 285 | } else { |
| 286 | off += slen; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | return res; |
| 291 | } |
| 292 | |
| 293 | int ovl_removexattr(struct dentry *dentry, const char *name) |
| 294 | { |
| 295 | int err; |
| 296 | struct path realpath; |
Miklos Szeredi | 5214846 | 2014-11-20 16:40:00 +0100 | [diff] [blame] | 297 | enum ovl_path_type type = ovl_path_real(dentry, &realpath); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 298 | |
| 299 | err = ovl_want_write(dentry); |
| 300 | if (err) |
| 301 | goto out; |
| 302 | |
Miklos Szeredi | 5214846 | 2014-11-20 16:40:00 +0100 | [diff] [blame] | 303 | err = -ENODATA; |
Miklos Szeredi | b581755 | 2016-06-06 16:21:37 +0200 | [diff] [blame] | 304 | if (ovl_is_private_xattr(name)) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 305 | goto out_drop_write; |
| 306 | |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 307 | if (!OVL_TYPE_UPPER(type)) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 308 | err = vfs_getxattr(realpath.dentry, name, NULL, 0); |
| 309 | if (err < 0) |
| 310 | goto out_drop_write; |
| 311 | |
| 312 | err = ovl_copy_up(dentry); |
| 313 | if (err) |
| 314 | goto out_drop_write; |
| 315 | |
| 316 | ovl_path_upper(dentry, &realpath); |
| 317 | } |
| 318 | |
| 319 | err = vfs_removexattr(realpath.dentry, name); |
| 320 | out_drop_write: |
| 321 | ovl_drop_write(dentry); |
| 322 | out: |
| 323 | return err; |
| 324 | } |
| 325 | |
Vivek Goyal | 39a25b2 | 2016-07-01 16:34:26 -0400 | [diff] [blame] | 326 | struct posix_acl *ovl_get_acl(struct inode *inode, int type) |
| 327 | { |
| 328 | struct inode *realinode = ovl_inode_real(inode); |
| 329 | |
Vivek Goyal | 39a25b2 | 2016-07-01 16:34:26 -0400 | [diff] [blame] | 330 | if (!IS_POSIXACL(realinode)) |
| 331 | return NULL; |
| 332 | |
| 333 | if (!realinode->i_op->get_acl) |
| 334 | return NULL; |
| 335 | |
| 336 | return realinode->i_op->get_acl(realinode, type); |
| 337 | } |
| 338 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 339 | static bool ovl_open_need_copy_up(int flags, enum ovl_path_type type, |
| 340 | struct dentry *realdentry) |
| 341 | { |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 342 | if (OVL_TYPE_UPPER(type)) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 343 | return false; |
| 344 | |
| 345 | if (special_file(realdentry->d_inode->i_mode)) |
| 346 | return false; |
| 347 | |
| 348 | if (!(OPEN_FMODE(flags) & FMODE_WRITE) && !(flags & O_TRUNC)) |
| 349 | return false; |
| 350 | |
| 351 | return true; |
| 352 | } |
| 353 | |
Miklos Szeredi | 2d90267 | 2016-06-30 08:53:27 +0200 | [diff] [blame] | 354 | int ovl_open_maybe_copy_up(struct dentry *dentry, unsigned int file_flags) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 355 | { |
Miklos Szeredi | 2d90267 | 2016-06-30 08:53:27 +0200 | [diff] [blame] | 356 | int err = 0; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 357 | struct path realpath; |
| 358 | enum ovl_path_type type; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 359 | |
| 360 | type = ovl_path_real(dentry, &realpath); |
David Howells | 4bacc9c | 2015-06-18 14:32:31 +0100 | [diff] [blame] | 361 | if (ovl_open_need_copy_up(file_flags, type, realpath.dentry)) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 362 | err = ovl_want_write(dentry); |
Miklos Szeredi | 2d90267 | 2016-06-30 08:53:27 +0200 | [diff] [blame] | 363 | if (!err) { |
| 364 | if (file_flags & O_TRUNC) |
| 365 | err = ovl_copy_up_truncate(dentry); |
| 366 | else |
| 367 | err = ovl_copy_up(dentry); |
| 368 | ovl_drop_write(dentry); |
| 369 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 370 | } |
| 371 | |
Miklos Szeredi | 2d90267 | 2016-06-30 08:53:27 +0200 | [diff] [blame] | 372 | return err; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | static const struct inode_operations ovl_file_inode_operations = { |
| 376 | .setattr = ovl_setattr, |
| 377 | .permission = ovl_permission, |
| 378 | .getattr = ovl_getattr, |
| 379 | .setxattr = ovl_setxattr, |
| 380 | .getxattr = ovl_getxattr, |
| 381 | .listxattr = ovl_listxattr, |
| 382 | .removexattr = ovl_removexattr, |
Vivek Goyal | 39a25b2 | 2016-07-01 16:34:26 -0400 | [diff] [blame] | 383 | .get_acl = ovl_get_acl, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 384 | }; |
| 385 | |
| 386 | static const struct inode_operations ovl_symlink_inode_operations = { |
| 387 | .setattr = ovl_setattr, |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 388 | .get_link = ovl_get_link, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 389 | .readlink = ovl_readlink, |
| 390 | .getattr = ovl_getattr, |
| 391 | .setxattr = ovl_setxattr, |
| 392 | .getxattr = ovl_getxattr, |
| 393 | .listxattr = ovl_listxattr, |
| 394 | .removexattr = ovl_removexattr, |
| 395 | }; |
| 396 | |
| 397 | struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, |
| 398 | struct ovl_entry *oe) |
| 399 | { |
| 400 | struct inode *inode; |
| 401 | |
| 402 | inode = new_inode(sb); |
| 403 | if (!inode) |
| 404 | return NULL; |
| 405 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 406 | inode->i_ino = get_next_ino(); |
| 407 | inode->i_mode = mode; |
| 408 | inode->i_flags |= S_NOATIME | S_NOCMTIME; |
Andreas Gruenbacher | 58ed4e7 | 2016-05-26 02:01:47 +0200 | [diff] [blame] | 409 | inode->i_private = oe; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 410 | |
Vivek Goyal | 07a2daa | 2016-07-01 16:34:25 -0400 | [diff] [blame] | 411 | mode &= S_IFMT; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 412 | switch (mode) { |
| 413 | case S_IFDIR: |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 414 | inode->i_op = &ovl_dir_inode_operations; |
| 415 | inode->i_fop = &ovl_dir_operations; |
| 416 | break; |
| 417 | |
| 418 | case S_IFLNK: |
| 419 | inode->i_op = &ovl_symlink_inode_operations; |
| 420 | break; |
| 421 | |
| 422 | case S_IFREG: |
| 423 | case S_IFSOCK: |
| 424 | case S_IFBLK: |
| 425 | case S_IFCHR: |
| 426 | case S_IFIFO: |
| 427 | inode->i_op = &ovl_file_inode_operations; |
| 428 | break; |
| 429 | |
| 430 | default: |
| 431 | WARN(1, "illegal file type: %i\n", mode); |
| 432 | iput(inode); |
| 433 | inode = NULL; |
| 434 | } |
| 435 | |
| 436 | return inode; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 437 | } |