Jaegeuk Kim | 0a8165d | 2012-11-29 13:28:09 +0900 | [diff] [blame] | 1 | /* |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 2 | * fs/f2fs/namei.c |
| 3 | * |
| 4 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. |
| 5 | * http://www.samsung.com/ |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | #include <linux/fs.h> |
| 12 | #include <linux/f2fs_fs.h> |
| 13 | #include <linux/pagemap.h> |
| 14 | #include <linux/sched.h> |
| 15 | #include <linux/ctype.h> |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 16 | #include <linux/dcache.h> |
Jaegeuk Kim | feb7cbb | 2015-04-15 13:49:55 -0700 | [diff] [blame] | 17 | #include <linux/namei.h> |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 18 | |
| 19 | #include "f2fs.h" |
Jaegeuk Kim | 953a3e2 | 2013-03-21 15:21:57 +0900 | [diff] [blame] | 20 | #include "node.h" |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 21 | #include "xattr.h" |
| 22 | #include "acl.h" |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 23 | #include <trace/events/f2fs.h> |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 24 | |
| 25 | static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode) |
| 26 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 27 | struct f2fs_sb_info *sbi = F2FS_I_SB(dir); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 28 | nid_t ino; |
| 29 | struct inode *inode; |
| 30 | bool nid_free = false; |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 31 | int err; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 32 | |
Jaegeuk Kim | a014e03 | 2014-06-20 21:44:02 -0700 | [diff] [blame] | 33 | inode = new_inode(dir->i_sb); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 34 | if (!inode) |
| 35 | return ERR_PTR(-ENOMEM); |
| 36 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 37 | f2fs_lock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 38 | if (!alloc_nid(sbi, &ino)) { |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 39 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 40 | err = -ENOSPC; |
| 41 | goto fail; |
| 42 | } |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 43 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 44 | |
Chao Yu | 70ff5df | 2014-05-08 17:09:30 +0800 | [diff] [blame] | 45 | inode_init_owner(inode, dir, mode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 46 | |
| 47 | inode->i_ino = ino; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 48 | inode->i_blocks = 0; |
| 49 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; |
| 50 | inode->i_generation = sbi->s_next_generation++; |
| 51 | |
| 52 | err = insert_inode_locked(inode); |
| 53 | if (err) { |
| 54 | err = -EINVAL; |
| 55 | nid_free = true; |
Jaegeuk Kim | a21c20f | 2015-08-16 12:38:15 -0700 | [diff] [blame] | 56 | goto fail; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 57 | } |
Chao Yu | 622f28a | 2014-09-24 18:19:10 +0800 | [diff] [blame] | 58 | |
Jaegeuk Kim | fcc85a4 | 2015-04-21 20:39:58 -0700 | [diff] [blame] | 59 | /* If the directory encrypted, then we should encrypt the inode. */ |
| 60 | if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode)) |
| 61 | f2fs_set_encrypted_inode(inode); |
| 62 | |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 63 | set_inode_flag(inode, FI_NEW_INODE); |
| 64 | |
| 65 | if (test_opt(sbi, INLINE_XATTR)) |
| 66 | set_inode_flag(inode, FI_INLINE_XATTR); |
Chao Yu | fba48a8 | 2015-12-23 17:51:35 +0800 | [diff] [blame] | 67 | if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode)) |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 68 | set_inode_flag(inode, FI_INLINE_DATA); |
Jaegeuk Kim | 01b960e | 2015-04-23 10:27:21 -0700 | [diff] [blame] | 69 | if (f2fs_may_inline_dentry(inode)) |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 70 | set_inode_flag(inode, FI_INLINE_DENTRY); |
Chao Yu | 622f28a | 2014-09-24 18:19:10 +0800 | [diff] [blame] | 71 | |
Jaegeuk Kim | 3e72f72 | 2015-06-19 17:53:26 -0700 | [diff] [blame] | 72 | f2fs_init_extent_tree(inode, NULL); |
| 73 | |
Chao Yu | d5e8f6c | 2015-07-15 17:28:53 +0800 | [diff] [blame] | 74 | stat_inc_inline_xattr(inode); |
Jaegeuk Kim | 2fb2c95 | 2015-04-30 18:58:22 -0700 | [diff] [blame] | 75 | stat_inc_inline_inode(inode); |
| 76 | stat_inc_inline_dir(inode); |
| 77 | |
Jaegeuk Kim | d70b4f5 | 2013-04-25 13:24:33 +0900 | [diff] [blame] | 78 | trace_f2fs_new_inode(inode, 0); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 79 | return inode; |
| 80 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 81 | fail: |
Jaegeuk Kim | d70b4f5 | 2013-04-25 13:24:33 +0900 | [diff] [blame] | 82 | trace_f2fs_new_inode(inode, err); |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 83 | make_bad_inode(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 84 | if (nid_free) |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 85 | set_inode_flag(inode, FI_FREE_NID); |
Jaegeuk Kim | c9b63bd | 2015-06-23 10:36:08 -0700 | [diff] [blame] | 86 | iput(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 87 | return ERR_PTR(err); |
| 88 | } |
| 89 | |
| 90 | static int is_multimedia_file(const unsigned char *s, const char *sub) |
| 91 | { |
Leon Romanovsky | 9836b8b | 2012-12-27 19:55:46 +0200 | [diff] [blame] | 92 | size_t slen = strlen(s); |
| 93 | size_t sublen = strlen(sub); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 94 | |
Chao Yu | 741a7be | 2015-07-06 20:30:40 +0800 | [diff] [blame] | 95 | /* |
| 96 | * filename format of multimedia file should be defined as: |
| 97 | * "filename + '.' + extension". |
| 98 | */ |
| 99 | if (slen < sublen + 2) |
| 100 | return 0; |
| 101 | |
| 102 | if (s[slen - sublen - 1] != '.') |
Namjae Jeon | e66509f0 | 2013-04-20 01:27:21 +0900 | [diff] [blame] | 103 | return 0; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 104 | |
Gu Zheng | 749ebfd | 2013-08-22 18:11:25 +0800 | [diff] [blame] | 105 | return !strncasecmp(s + slen - sublen, sub, sublen); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 106 | } |
| 107 | |
Jaegeuk Kim | 0a8165d | 2012-11-29 13:28:09 +0900 | [diff] [blame] | 108 | /* |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 109 | * Set multimedia files as cold files for hot/cold data separation |
| 110 | */ |
Jaegeuk Kim | 953a3e2 | 2013-03-21 15:21:57 +0900 | [diff] [blame] | 111 | static inline void set_cold_files(struct f2fs_sb_info *sbi, struct inode *inode, |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 112 | const unsigned char *name) |
| 113 | { |
| 114 | int i; |
| 115 | __u8 (*extlist)[8] = sbi->raw_super->extension_list; |
| 116 | |
| 117 | int count = le32_to_cpu(sbi->raw_super->extension_count); |
| 118 | for (i = 0; i < count; i++) { |
Namjae Jeon | e66509f0 | 2013-04-20 01:27:21 +0900 | [diff] [blame] | 119 | if (is_multimedia_file(name, extlist[i])) { |
Jaegeuk Kim | 354a339 | 2013-06-14 08:52:35 +0900 | [diff] [blame] | 120 | file_set_cold(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 121 | break; |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
| 127 | bool excl) |
| 128 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 129 | struct f2fs_sb_info *sbi = F2FS_I_SB(dir); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 130 | struct inode *inode; |
| 131 | nid_t ino = 0; |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 132 | int err; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 133 | |
| 134 | inode = f2fs_new_inode(dir, mode); |
| 135 | if (IS_ERR(inode)) |
| 136 | return PTR_ERR(inode); |
| 137 | |
| 138 | if (!test_opt(sbi, DISABLE_EXT_IDENTIFY)) |
Jaegeuk Kim | 953a3e2 | 2013-03-21 15:21:57 +0900 | [diff] [blame] | 139 | set_cold_files(sbi, inode, dentry->d_name.name); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 140 | |
| 141 | inode->i_op = &f2fs_file_inode_operations; |
| 142 | inode->i_fop = &f2fs_file_operations; |
| 143 | inode->i_mapping->a_ops = &f2fs_dblock_aops; |
| 144 | ino = inode->i_ino; |
| 145 | |
Jaegeuk Kim | 2c4db1a | 2016-01-07 14:15:04 -0800 | [diff] [blame] | 146 | f2fs_balance_fs(sbi, true); |
Jaegeuk Kim | 00623e6 | 2015-12-22 11:56:08 -0800 | [diff] [blame] | 147 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 148 | f2fs_lock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 149 | err = f2fs_add_link(dentry, inode); |
| 150 | if (err) |
| 151 | goto out; |
Jaegeuk Kim | 44c1615 | 2014-09-25 11:55:53 -0700 | [diff] [blame] | 152 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 153 | |
| 154 | alloc_nid_done(sbi, ino); |
| 155 | |
Jaegeuk Kim | 0a364af | 2013-05-16 08:57:43 +0900 | [diff] [blame] | 156 | d_instantiate(dentry, inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 157 | unlock_new_inode(inode); |
Jaegeuk Kim | b7e1d80 | 2014-11-09 22:15:31 -0800 | [diff] [blame] | 158 | |
| 159 | if (IS_DIRSYNC(dir)) |
| 160 | f2fs_sync_fs(sbi->sb, 1); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 161 | return 0; |
| 162 | out: |
Jaegeuk Kim | 44c1615 | 2014-09-25 11:55:53 -0700 | [diff] [blame] | 163 | handle_failed_inode(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 164 | return err; |
| 165 | } |
| 166 | |
| 167 | static int f2fs_link(struct dentry *old_dentry, struct inode *dir, |
| 168 | struct dentry *dentry) |
| 169 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 170 | struct inode *inode = d_inode(old_dentry); |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 171 | struct f2fs_sb_info *sbi = F2FS_I_SB(dir); |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 172 | int err; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 173 | |
Jaegeuk Kim | fcc85a4 | 2015-04-21 20:39:58 -0700 | [diff] [blame] | 174 | if (f2fs_encrypted_inode(dir) && |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 175 | !fscrypt_has_permitted_context(dir, inode)) |
Jaegeuk Kim | fcc85a4 | 2015-04-21 20:39:58 -0700 | [diff] [blame] | 176 | return -EPERM; |
| 177 | |
Jaegeuk Kim | 2c4db1a | 2016-01-07 14:15:04 -0800 | [diff] [blame] | 178 | f2fs_balance_fs(sbi, true); |
Jaegeuk Kim | 1efef83 | 2012-12-19 16:25:21 +0900 | [diff] [blame] | 179 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 180 | inode->i_ctime = CURRENT_TIME; |
Jaegeuk Kim | 6f6fd83 | 2013-05-22 12:06:26 +0900 | [diff] [blame] | 181 | ihold(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 182 | |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 183 | set_inode_flag(inode, FI_INC_LINK); |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 184 | f2fs_lock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 185 | err = f2fs_add_link(dentry, inode); |
| 186 | if (err) |
| 187 | goto out; |
Jaegeuk Kim | 44c1615 | 2014-09-25 11:55:53 -0700 | [diff] [blame] | 188 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 189 | |
| 190 | d_instantiate(dentry, inode); |
Jaegeuk Kim | b7e1d80 | 2014-11-09 22:15:31 -0800 | [diff] [blame] | 191 | |
| 192 | if (IS_DIRSYNC(dir)) |
| 193 | f2fs_sync_fs(sbi->sb, 1); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 194 | return 0; |
| 195 | out: |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 196 | clear_inode_flag(inode, FI_INC_LINK); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 197 | iput(inode); |
Jaegeuk Kim | 44c1615 | 2014-09-25 11:55:53 -0700 | [diff] [blame] | 198 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 199 | return err; |
| 200 | } |
| 201 | |
| 202 | struct dentry *f2fs_get_parent(struct dentry *child) |
| 203 | { |
| 204 | struct qstr dotdot = QSTR_INIT("..", 2); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 205 | unsigned long ino = f2fs_inode_by_name(d_inode(child), &dotdot); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 206 | if (!ino) |
| 207 | return ERR_PTR(-ENOENT); |
Al Viro | fc64005 | 2016-04-10 01:33:30 -0400 | [diff] [blame] | 208 | return d_obtain_alias(f2fs_iget(child->d_sb, ino)); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 209 | } |
| 210 | |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 211 | static int __recover_dot_dentries(struct inode *dir, nid_t pino) |
| 212 | { |
| 213 | struct f2fs_sb_info *sbi = F2FS_I_SB(dir); |
| 214 | struct qstr dot = QSTR_INIT(".", 1); |
| 215 | struct qstr dotdot = QSTR_INIT("..", 2); |
| 216 | struct f2fs_dir_entry *de; |
| 217 | struct page *page; |
| 218 | int err = 0; |
| 219 | |
Chao Yu | 4e0d836 | 2015-12-30 17:40:31 +0800 | [diff] [blame] | 220 | if (f2fs_readonly(sbi->sb)) { |
| 221 | f2fs_msg(sbi->sb, KERN_INFO, |
| 222 | "skip recovering inline_dots inode (ino:%lu, pino:%u) " |
| 223 | "in readonly mountpoint", dir->i_ino, pino); |
| 224 | return 0; |
| 225 | } |
| 226 | |
Jaegeuk Kim | 2c4db1a | 2016-01-07 14:15:04 -0800 | [diff] [blame] | 227 | f2fs_balance_fs(sbi, true); |
Chao Yu | d538417 | 2015-12-24 18:03:29 +0800 | [diff] [blame] | 228 | |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 229 | f2fs_lock_op(sbi); |
| 230 | |
| 231 | de = f2fs_find_entry(dir, &dot, &page); |
| 232 | if (de) { |
| 233 | f2fs_dentry_kunmap(dir, page); |
| 234 | f2fs_put_page(page, 0); |
| 235 | } else { |
| 236 | err = __f2fs_add_link(dir, &dot, NULL, dir->i_ino, S_IFDIR); |
| 237 | if (err) |
| 238 | goto out; |
| 239 | } |
| 240 | |
| 241 | de = f2fs_find_entry(dir, &dotdot, &page); |
| 242 | if (de) { |
| 243 | f2fs_dentry_kunmap(dir, page); |
| 244 | f2fs_put_page(page, 0); |
| 245 | } else { |
| 246 | err = __f2fs_add_link(dir, &dotdot, NULL, pino, S_IFDIR); |
| 247 | } |
| 248 | out: |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame^] | 249 | if (!err) |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 250 | clear_inode_flag(dir, FI_INLINE_DOTS); |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 251 | |
| 252 | f2fs_unlock_op(sbi); |
| 253 | return err; |
| 254 | } |
| 255 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 256 | static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry, |
| 257 | unsigned int flags) |
| 258 | { |
| 259 | struct inode *inode = NULL; |
| 260 | struct f2fs_dir_entry *de; |
| 261 | struct page *page; |
Jaegeuk Kim | 06957e8 | 2015-04-22 11:40:27 -0700 | [diff] [blame] | 262 | nid_t ino; |
Jaegeuk Kim | fcc85a4 | 2015-04-21 20:39:58 -0700 | [diff] [blame] | 263 | int err = 0; |
Liu Xue | 8c2b143 | 2016-02-26 06:39:23 +0000 | [diff] [blame] | 264 | unsigned int root_ino = F2FS_ROOT_INO(F2FS_I_SB(dir)); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 265 | |
Jaegeuk Kim | 8074bb5 | 2016-02-23 09:21:37 -0800 | [diff] [blame] | 266 | if (f2fs_encrypted_inode(dir)) { |
| 267 | int res = fscrypt_get_encryption_info(dir); |
| 268 | |
| 269 | /* |
| 270 | * DCACHE_ENCRYPTED_WITH_KEY is set if the dentry is |
| 271 | * created while the directory was encrypted and we |
| 272 | * don't have access to the key. |
| 273 | */ |
| 274 | if (fscrypt_has_encryption_key(dir)) |
| 275 | fscrypt_set_encrypted_dentry(dentry); |
| 276 | fscrypt_set_d_op(dentry); |
| 277 | if (res && res != -ENOKEY) |
| 278 | return ERR_PTR(res); |
| 279 | } |
| 280 | |
Jaegeuk Kim | 5a20d33 | 2013-03-03 13:58:05 +0900 | [diff] [blame] | 281 | if (dentry->d_name.len > F2FS_NAME_LEN) |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 282 | return ERR_PTR(-ENAMETOOLONG); |
| 283 | |
| 284 | de = f2fs_find_entry(dir, &dentry->d_name, &page); |
Jaegeuk Kim | 06957e8 | 2015-04-22 11:40:27 -0700 | [diff] [blame] | 285 | if (!de) |
| 286 | return d_splice_alias(inode, dentry); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 287 | |
Jaegeuk Kim | 06957e8 | 2015-04-22 11:40:27 -0700 | [diff] [blame] | 288 | ino = le32_to_cpu(de->ino); |
| 289 | f2fs_dentry_kunmap(dir, page); |
| 290 | f2fs_put_page(page, 0); |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 291 | |
Jaegeuk Kim | 06957e8 | 2015-04-22 11:40:27 -0700 | [diff] [blame] | 292 | inode = f2fs_iget(dir->i_sb, ino); |
| 293 | if (IS_ERR(inode)) |
| 294 | return ERR_CAST(inode); |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 295 | |
Liu Xue | 8c2b143 | 2016-02-26 06:39:23 +0000 | [diff] [blame] | 296 | if ((dir->i_ino == root_ino) && f2fs_has_inline_dots(dir)) { |
| 297 | err = __recover_dot_dentries(dir, root_ino); |
| 298 | if (err) |
| 299 | goto err_out; |
| 300 | } |
| 301 | |
Jaegeuk Kim | fcc85a4 | 2015-04-21 20:39:58 -0700 | [diff] [blame] | 302 | if (f2fs_has_inline_dots(inode)) { |
Jaegeuk Kim | 06957e8 | 2015-04-22 11:40:27 -0700 | [diff] [blame] | 303 | err = __recover_dot_dentries(inode, dir->i_ino); |
Jaegeuk Kim | fcc85a4 | 2015-04-21 20:39:58 -0700 | [diff] [blame] | 304 | if (err) |
| 305 | goto err_out; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 306 | } |
Jaegeuk Kim | 8074bb5 | 2016-02-23 09:21:37 -0800 | [diff] [blame] | 307 | if (!IS_ERR(inode) && f2fs_encrypted_inode(dir) && |
| 308 | (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) && |
| 309 | !fscrypt_has_permitted_context(dir, inode)) { |
| 310 | bool nokey = f2fs_encrypted_inode(inode) && |
| 311 | !fscrypt_has_encryption_key(inode); |
Chao Yu | d726732 | 2016-03-10 22:24:23 +0800 | [diff] [blame] | 312 | err = nokey ? -ENOKEY : -EPERM; |
| 313 | goto err_out; |
Jaegeuk Kim | 8074bb5 | 2016-02-23 09:21:37 -0800 | [diff] [blame] | 314 | } |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 315 | return d_splice_alias(inode, dentry); |
Jaegeuk Kim | fcc85a4 | 2015-04-21 20:39:58 -0700 | [diff] [blame] | 316 | |
| 317 | err_out: |
Chao Yu | d726732 | 2016-03-10 22:24:23 +0800 | [diff] [blame] | 318 | iput(inode); |
Jaegeuk Kim | fcc85a4 | 2015-04-21 20:39:58 -0700 | [diff] [blame] | 319 | return ERR_PTR(err); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | static int f2fs_unlink(struct inode *dir, struct dentry *dentry) |
| 323 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 324 | struct f2fs_sb_info *sbi = F2FS_I_SB(dir); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 325 | struct inode *inode = d_inode(dentry); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 326 | struct f2fs_dir_entry *de; |
| 327 | struct page *page; |
| 328 | int err = -ENOENT; |
| 329 | |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 330 | trace_f2fs_unlink_enter(dir, dentry); |
Jaegeuk Kim | 1efef83 | 2012-12-19 16:25:21 +0900 | [diff] [blame] | 331 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 332 | de = f2fs_find_entry(dir, &dentry->d_name, &page); |
| 333 | if (!de) |
| 334 | goto fail; |
| 335 | |
Jaegeuk Kim | 2c4db1a | 2016-01-07 14:15:04 -0800 | [diff] [blame] | 336 | f2fs_balance_fs(sbi, true); |
Jaegeuk Kim | 00623e6 | 2015-12-22 11:56:08 -0800 | [diff] [blame] | 337 | |
Jaegeuk Kim | ccaaca2 | 2013-10-08 10:19:28 +0900 | [diff] [blame] | 338 | f2fs_lock_op(sbi); |
Jaegeuk Kim | cbd56e7 | 2013-07-30 11:36:53 +0900 | [diff] [blame] | 339 | err = acquire_orphan_inode(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 340 | if (err) { |
Jaegeuk Kim | ccaaca2 | 2013-10-08 10:19:28 +0900 | [diff] [blame] | 341 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 9486ba4 | 2014-11-21 16:36:28 -0800 | [diff] [blame] | 342 | f2fs_dentry_kunmap(dir, page); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 343 | f2fs_put_page(page, 0); |
| 344 | goto fail; |
| 345 | } |
Chao Yu | dbeacf0 | 2014-09-24 18:17:04 +0800 | [diff] [blame] | 346 | f2fs_delete_entry(de, page, dir, inode); |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 347 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 348 | |
Jaegeuk Kim | b7e1d80 | 2014-11-09 22:15:31 -0800 | [diff] [blame] | 349 | if (IS_DIRSYNC(dir)) |
| 350 | f2fs_sync_fs(sbi->sb, 1); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 351 | fail: |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 352 | trace_f2fs_unlink_exit(inode, err); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 353 | return err; |
| 354 | } |
| 355 | |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 356 | static const char *f2fs_get_link(struct dentry *dentry, |
Al Viro | fceef39 | 2015-12-29 15:58:39 -0500 | [diff] [blame] | 357 | struct inode *inode, |
| 358 | struct delayed_call *done) |
Jaegeuk Kim | feb7cbb | 2015-04-15 13:49:55 -0700 | [diff] [blame] | 359 | { |
Al Viro | fceef39 | 2015-12-29 15:58:39 -0500 | [diff] [blame] | 360 | const char *link = page_get_link(dentry, inode, done); |
Al Viro | 680baac | 2015-05-02 13:32:22 -0400 | [diff] [blame] | 361 | if (!IS_ERR(link) && !*link) { |
| 362 | /* this is broken symlink case */ |
Al Viro | fceef39 | 2015-12-29 15:58:39 -0500 | [diff] [blame] | 363 | do_delayed_call(done); |
| 364 | clear_delayed_call(done); |
Al Viro | 680baac | 2015-05-02 13:32:22 -0400 | [diff] [blame] | 365 | link = ERR_PTR(-ENOENT); |
Jaegeuk Kim | feb7cbb | 2015-04-15 13:49:55 -0700 | [diff] [blame] | 366 | } |
Al Viro | 680baac | 2015-05-02 13:32:22 -0400 | [diff] [blame] | 367 | return link; |
Jaegeuk Kim | feb7cbb | 2015-04-15 13:49:55 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 370 | static int f2fs_symlink(struct inode *dir, struct dentry *dentry, |
| 371 | const char *symname) |
| 372 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 373 | struct f2fs_sb_info *sbi = F2FS_I_SB(dir); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 374 | struct inode *inode; |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 375 | size_t len = strlen(symname); |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 376 | struct fscrypt_str disk_link = FSTR_INIT((char *)symname, len + 1); |
| 377 | struct fscrypt_symlink_data *sd = NULL; |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 378 | int err; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 379 | |
Chao Yu | 922ec35 | 2016-02-15 17:54:26 +0800 | [diff] [blame] | 380 | if (f2fs_encrypted_inode(dir)) { |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 381 | err = fscrypt_get_encryption_info(dir); |
Chao Yu | 922ec35 | 2016-02-15 17:54:26 +0800 | [diff] [blame] | 382 | if (err) |
| 383 | return err; |
| 384 | |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 385 | if (!fscrypt_has_encryption_key(dir)) |
Chao Yu | 922ec35 | 2016-02-15 17:54:26 +0800 | [diff] [blame] | 386 | return -EPERM; |
| 387 | |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 388 | disk_link.len = (fscrypt_fname_encrypted_size(dir, len) + |
| 389 | sizeof(struct fscrypt_symlink_data)); |
Chao Yu | 922ec35 | 2016-02-15 17:54:26 +0800 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | if (disk_link.len > dir->i_sb->s_blocksize) |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 393 | return -ENAMETOOLONG; |
| 394 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 395 | inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO); |
| 396 | if (IS_ERR(inode)) |
| 397 | return PTR_ERR(inode); |
| 398 | |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 399 | if (f2fs_encrypted_inode(inode)) |
| 400 | inode->i_op = &f2fs_encrypted_symlink_inode_operations; |
| 401 | else |
| 402 | inode->i_op = &f2fs_symlink_inode_operations; |
Al Viro | 21fc61c | 2015-11-17 01:07:57 -0500 | [diff] [blame] | 403 | inode_nohighmem(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 404 | inode->i_mapping->a_ops = &f2fs_dblock_aops; |
| 405 | |
Jaegeuk Kim | 2c4db1a | 2016-01-07 14:15:04 -0800 | [diff] [blame] | 406 | f2fs_balance_fs(sbi, true); |
Jaegeuk Kim | 00623e6 | 2015-12-22 11:56:08 -0800 | [diff] [blame] | 407 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 408 | f2fs_lock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 409 | err = f2fs_add_link(dentry, inode); |
| 410 | if (err) |
| 411 | goto out; |
Jaegeuk Kim | 44c1615 | 2014-09-25 11:55:53 -0700 | [diff] [blame] | 412 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 413 | alloc_nid_done(sbi, inode->i_ino); |
| 414 | |
Chao Yu | 922ec35 | 2016-02-15 17:54:26 +0800 | [diff] [blame] | 415 | if (f2fs_encrypted_inode(inode)) { |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 416 | struct qstr istr = QSTR_INIT(symname, len); |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 417 | struct fscrypt_str ostr; |
Chao Yu | 922ec35 | 2016-02-15 17:54:26 +0800 | [diff] [blame] | 418 | |
| 419 | sd = kzalloc(disk_link.len, GFP_NOFS); |
| 420 | if (!sd) { |
| 421 | err = -ENOMEM; |
| 422 | goto err_out; |
| 423 | } |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 424 | |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 425 | err = fscrypt_get_encryption_info(inode); |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 426 | if (err) |
| 427 | goto err_out; |
| 428 | |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 429 | if (!fscrypt_has_encryption_key(inode)) { |
Chao Yu | 922ec35 | 2016-02-15 17:54:26 +0800 | [diff] [blame] | 430 | err = -EPERM; |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 431 | goto err_out; |
Chao Yu | 922ec35 | 2016-02-15 17:54:26 +0800 | [diff] [blame] | 432 | } |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 433 | |
Chao Yu | 922ec35 | 2016-02-15 17:54:26 +0800 | [diff] [blame] | 434 | ostr.name = sd->encrypted_path; |
| 435 | ostr.len = disk_link.len; |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 436 | err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr); |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 437 | if (err < 0) |
| 438 | goto err_out; |
| 439 | |
Chao Yu | 922ec35 | 2016-02-15 17:54:26 +0800 | [diff] [blame] | 440 | sd->len = cpu_to_le16(ostr.len); |
| 441 | disk_link.name = (char *)sd; |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Chao Yu | 922ec35 | 2016-02-15 17:54:26 +0800 | [diff] [blame] | 444 | err = page_symlink(inode, disk_link.name, disk_link.len); |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 445 | |
| 446 | err_out: |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 447 | d_instantiate(dentry, inode); |
| 448 | unlock_new_inode(inode); |
Jaegeuk Kim | b7e1d80 | 2014-11-09 22:15:31 -0800 | [diff] [blame] | 449 | |
Jaegeuk Kim | d0cae97 | 2015-04-15 13:37:53 -0700 | [diff] [blame] | 450 | /* |
| 451 | * Let's flush symlink data in order to avoid broken symlink as much as |
| 452 | * possible. Nevertheless, fsyncing is the best way, but there is no |
| 453 | * way to get a file descriptor in order to flush that. |
| 454 | * |
| 455 | * Note that, it needs to do dir->fsync to make this recoverable. |
| 456 | * If the symlink path is stored into inline_data, there is no |
| 457 | * performance regression. |
| 458 | */ |
Chao Yu | a6be014 | 2015-10-22 18:23:08 +0800 | [diff] [blame] | 459 | if (!err) { |
Chao Yu | 922ec35 | 2016-02-15 17:54:26 +0800 | [diff] [blame] | 460 | filemap_write_and_wait_range(inode->i_mapping, 0, |
| 461 | disk_link.len - 1); |
Jaegeuk Kim | d0cae97 | 2015-04-15 13:37:53 -0700 | [diff] [blame] | 462 | |
Chao Yu | a6be014 | 2015-10-22 18:23:08 +0800 | [diff] [blame] | 463 | if (IS_DIRSYNC(dir)) |
| 464 | f2fs_sync_fs(sbi->sb, 1); |
| 465 | } else { |
| 466 | f2fs_unlink(dir, dentry); |
| 467 | } |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 468 | |
| 469 | kfree(sd); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 470 | return err; |
| 471 | out: |
Jaegeuk Kim | 44c1615 | 2014-09-25 11:55:53 -0700 | [diff] [blame] | 472 | handle_failed_inode(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 473 | return err; |
| 474 | } |
| 475 | |
| 476 | static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
| 477 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 478 | struct f2fs_sb_info *sbi = F2FS_I_SB(dir); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 479 | struct inode *inode; |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 480 | int err; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 481 | |
| 482 | inode = f2fs_new_inode(dir, S_IFDIR | mode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 483 | if (IS_ERR(inode)) |
Namjae Jeon | 61412b6 | 2012-12-01 10:56:25 +0900 | [diff] [blame] | 484 | return PTR_ERR(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 485 | |
| 486 | inode->i_op = &f2fs_dir_inode_operations; |
| 487 | inode->i_fop = &f2fs_dir_operations; |
| 488 | inode->i_mapping->a_ops = &f2fs_dblock_aops; |
Chao Yu | 560d467 | 2015-02-07 17:36:15 +0800 | [diff] [blame] | 489 | mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_HIGH_ZERO); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 490 | |
Jaegeuk Kim | 2c4db1a | 2016-01-07 14:15:04 -0800 | [diff] [blame] | 491 | f2fs_balance_fs(sbi, true); |
Jaegeuk Kim | 00623e6 | 2015-12-22 11:56:08 -0800 | [diff] [blame] | 492 | |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 493 | set_inode_flag(inode, FI_INC_LINK); |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 494 | f2fs_lock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 495 | err = f2fs_add_link(dentry, inode); |
| 496 | if (err) |
| 497 | goto out_fail; |
Jaegeuk Kim | 44c1615 | 2014-09-25 11:55:53 -0700 | [diff] [blame] | 498 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 499 | |
| 500 | alloc_nid_done(sbi, inode->i_ino); |
| 501 | |
| 502 | d_instantiate(dentry, inode); |
| 503 | unlock_new_inode(inode); |
| 504 | |
Jaegeuk Kim | b7e1d80 | 2014-11-09 22:15:31 -0800 | [diff] [blame] | 505 | if (IS_DIRSYNC(dir)) |
| 506 | f2fs_sync_fs(sbi->sb, 1); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 507 | return 0; |
| 508 | |
| 509 | out_fail: |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 510 | clear_inode_flag(inode, FI_INC_LINK); |
Jaegeuk Kim | 44c1615 | 2014-09-25 11:55:53 -0700 | [diff] [blame] | 511 | handle_failed_inode(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 512 | return err; |
| 513 | } |
| 514 | |
| 515 | static int f2fs_rmdir(struct inode *dir, struct dentry *dentry) |
| 516 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 517 | struct inode *inode = d_inode(dentry); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 518 | if (f2fs_empty_dir(inode)) |
| 519 | return f2fs_unlink(dir, dentry); |
| 520 | return -ENOTEMPTY; |
| 521 | } |
| 522 | |
| 523 | static int f2fs_mknod(struct inode *dir, struct dentry *dentry, |
| 524 | umode_t mode, dev_t rdev) |
| 525 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 526 | struct f2fs_sb_info *sbi = F2FS_I_SB(dir); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 527 | struct inode *inode; |
| 528 | int err = 0; |
| 529 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 530 | inode = f2fs_new_inode(dir, mode); |
| 531 | if (IS_ERR(inode)) |
| 532 | return PTR_ERR(inode); |
| 533 | |
| 534 | init_special_inode(inode, inode->i_mode, rdev); |
| 535 | inode->i_op = &f2fs_special_inode_operations; |
| 536 | |
Jaegeuk Kim | 2c4db1a | 2016-01-07 14:15:04 -0800 | [diff] [blame] | 537 | f2fs_balance_fs(sbi, true); |
Jaegeuk Kim | 00623e6 | 2015-12-22 11:56:08 -0800 | [diff] [blame] | 538 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 539 | f2fs_lock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 540 | err = f2fs_add_link(dentry, inode); |
| 541 | if (err) |
| 542 | goto out; |
Jaegeuk Kim | 44c1615 | 2014-09-25 11:55:53 -0700 | [diff] [blame] | 543 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 544 | |
| 545 | alloc_nid_done(sbi, inode->i_ino); |
Jaegeuk Kim | b7e1d80 | 2014-11-09 22:15:31 -0800 | [diff] [blame] | 546 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 547 | d_instantiate(dentry, inode); |
| 548 | unlock_new_inode(inode); |
Jaegeuk Kim | b7e1d80 | 2014-11-09 22:15:31 -0800 | [diff] [blame] | 549 | |
| 550 | if (IS_DIRSYNC(dir)) |
| 551 | f2fs_sync_fs(sbi->sb, 1); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 552 | return 0; |
| 553 | out: |
Jaegeuk Kim | 44c1615 | 2014-09-25 11:55:53 -0700 | [diff] [blame] | 554 | handle_failed_inode(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 555 | return err; |
| 556 | } |
| 557 | |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 558 | static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry, |
| 559 | umode_t mode, struct inode **whiteout) |
| 560 | { |
| 561 | struct f2fs_sb_info *sbi = F2FS_I_SB(dir); |
| 562 | struct inode *inode; |
| 563 | int err; |
| 564 | |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 565 | inode = f2fs_new_inode(dir, mode); |
| 566 | if (IS_ERR(inode)) |
| 567 | return PTR_ERR(inode); |
| 568 | |
| 569 | if (whiteout) { |
| 570 | init_special_inode(inode, inode->i_mode, WHITEOUT_DEV); |
| 571 | inode->i_op = &f2fs_special_inode_operations; |
| 572 | } else { |
| 573 | inode->i_op = &f2fs_file_inode_operations; |
| 574 | inode->i_fop = &f2fs_file_operations; |
| 575 | inode->i_mapping->a_ops = &f2fs_dblock_aops; |
| 576 | } |
| 577 | |
Jaegeuk Kim | 2c4db1a | 2016-01-07 14:15:04 -0800 | [diff] [blame] | 578 | f2fs_balance_fs(sbi, true); |
Jaegeuk Kim | 00623e6 | 2015-12-22 11:56:08 -0800 | [diff] [blame] | 579 | |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 580 | f2fs_lock_op(sbi); |
| 581 | err = acquire_orphan_inode(sbi); |
| 582 | if (err) |
| 583 | goto out; |
| 584 | |
| 585 | err = f2fs_do_tmpfile(inode, dir); |
| 586 | if (err) |
| 587 | goto release_out; |
| 588 | |
| 589 | /* |
| 590 | * add this non-linked tmpfile to orphan list, in this way we could |
| 591 | * remove all unused data of tmpfile after abnormal power-off. |
| 592 | */ |
| 593 | add_orphan_inode(sbi, inode->i_ino); |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 594 | alloc_nid_done(sbi, inode->i_ino); |
| 595 | |
| 596 | if (whiteout) { |
Jaegeuk Kim | a196124 | 2016-05-20 09:43:20 -0700 | [diff] [blame] | 597 | f2fs_i_links_write(inode, false); |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 598 | *whiteout = inode; |
| 599 | } else { |
| 600 | d_tmpfile(dentry, inode); |
| 601 | } |
Jaegeuk Kim | a196124 | 2016-05-20 09:43:20 -0700 | [diff] [blame] | 602 | /* link_count was changed by d_tmpfile as well. */ |
| 603 | f2fs_unlock_op(sbi); |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 604 | unlock_new_inode(inode); |
| 605 | return 0; |
| 606 | |
| 607 | release_out: |
| 608 | release_orphan_inode(sbi); |
| 609 | out: |
| 610 | handle_failed_inode(inode); |
| 611 | return err; |
| 612 | } |
| 613 | |
| 614 | static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) |
| 615 | { |
Jaegeuk Kim | 304eecc | 2015-05-19 16:11:40 -0700 | [diff] [blame] | 616 | if (f2fs_encrypted_inode(dir)) { |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 617 | int err = fscrypt_get_encryption_info(dir); |
Jaegeuk Kim | 304eecc | 2015-05-19 16:11:40 -0700 | [diff] [blame] | 618 | if (err) |
| 619 | return err; |
| 620 | } |
| 621 | |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 622 | return __f2fs_tmpfile(dir, dentry, mode, NULL); |
| 623 | } |
| 624 | |
| 625 | static int f2fs_create_whiteout(struct inode *dir, struct inode **whiteout) |
| 626 | { |
| 627 | return __f2fs_tmpfile(dir, NULL, S_IFCHR | WHITEOUT_MODE, whiteout); |
| 628 | } |
| 629 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 630 | static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 631 | struct inode *new_dir, struct dentry *new_dentry, |
| 632 | unsigned int flags) |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 633 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 634 | struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 635 | struct inode *old_inode = d_inode(old_dentry); |
| 636 | struct inode *new_inode = d_inode(new_dentry); |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 637 | struct inode *whiteout = NULL; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 638 | struct page *old_dir_page; |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 639 | struct page *old_page, *new_page = NULL; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 640 | struct f2fs_dir_entry *old_dir_entry = NULL; |
| 641 | struct f2fs_dir_entry *old_entry; |
| 642 | struct f2fs_dir_entry *new_entry; |
Chao Yu | 993a049 | 2016-02-17 16:47:05 +0800 | [diff] [blame] | 643 | bool is_old_inline = f2fs_has_inline_dentry(old_dir); |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 644 | int err = -ENOENT; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 645 | |
Jaegeuk Kim | fcc85a4 | 2015-04-21 20:39:58 -0700 | [diff] [blame] | 646 | if ((old_dir != new_dir) && f2fs_encrypted_inode(new_dir) && |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 647 | !fscrypt_has_permitted_context(new_dir, old_inode)) { |
Jaegeuk Kim | fcc85a4 | 2015-04-21 20:39:58 -0700 | [diff] [blame] | 648 | err = -EPERM; |
| 649 | goto out; |
| 650 | } |
| 651 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 652 | old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page); |
| 653 | if (!old_entry) |
| 654 | goto out; |
| 655 | |
| 656 | if (S_ISDIR(old_inode->i_mode)) { |
| 657 | err = -EIO; |
| 658 | old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page); |
| 659 | if (!old_dir_entry) |
| 660 | goto out_old; |
| 661 | } |
| 662 | |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 663 | if (flags & RENAME_WHITEOUT) { |
| 664 | err = f2fs_create_whiteout(old_dir, &whiteout); |
| 665 | if (err) |
| 666 | goto out_dir; |
| 667 | } |
| 668 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 669 | if (new_inode) { |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 670 | |
| 671 | err = -ENOTEMPTY; |
| 672 | if (old_dir_entry && !f2fs_empty_dir(new_inode)) |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 673 | goto out_whiteout; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 674 | |
| 675 | err = -ENOENT; |
| 676 | new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, |
| 677 | &new_page); |
| 678 | if (!new_entry) |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 679 | goto out_whiteout; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 680 | |
Jaegeuk Kim | 2c4db1a | 2016-01-07 14:15:04 -0800 | [diff] [blame] | 681 | f2fs_balance_fs(sbi, true); |
Jaegeuk Kim | 00623e6 | 2015-12-22 11:56:08 -0800 | [diff] [blame] | 682 | |
Chao Yu | 1256010 | 2014-06-24 14:16:24 +0800 | [diff] [blame] | 683 | f2fs_lock_op(sbi); |
| 684 | |
Jaegeuk Kim | cbd56e7 | 2013-07-30 11:36:53 +0900 | [diff] [blame] | 685 | err = acquire_orphan_inode(sbi); |
| 686 | if (err) |
| 687 | goto put_out_dir; |
| 688 | |
Chao Yu | 9def1e9 | 2016-02-17 16:45:44 +0800 | [diff] [blame] | 689 | err = update_dent_inode(old_inode, new_inode, |
| 690 | &new_dentry->d_name); |
| 691 | if (err) { |
Jaegeuk Kim | cbd56e7 | 2013-07-30 11:36:53 +0900 | [diff] [blame] | 692 | release_orphan_inode(sbi); |
| 693 | goto put_out_dir; |
Jaegeuk Kim | 1cd14ca | 2013-07-18 18:02:31 +0900 | [diff] [blame] | 694 | } |
| 695 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 696 | f2fs_set_link(new_dir, new_entry, new_page, old_inode); |
| 697 | |
| 698 | new_inode->i_ctime = CURRENT_TIME; |
Jaegeuk Kim | d928bfb | 2014-03-20 19:10:08 +0900 | [diff] [blame] | 699 | down_write(&F2FS_I(new_inode)->i_sem); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 700 | if (old_dir_entry) |
Jaegeuk Kim | a196124 | 2016-05-20 09:43:20 -0700 | [diff] [blame] | 701 | f2fs_i_links_write(new_inode, false); |
| 702 | f2fs_i_links_write(new_inode, false); |
Jaegeuk Kim | d928bfb | 2014-03-20 19:10:08 +0900 | [diff] [blame] | 703 | up_write(&F2FS_I(new_inode)->i_sem); |
| 704 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 705 | if (!new_inode->i_nlink) |
| 706 | add_orphan_inode(sbi, new_inode->i_ino); |
Jaegeuk Kim | cbd56e7 | 2013-07-30 11:36:53 +0900 | [diff] [blame] | 707 | else |
| 708 | release_orphan_inode(sbi); |
| 709 | |
Jaegeuk Kim | 8cb8268 | 2013-08-26 21:25:31 +0900 | [diff] [blame] | 710 | update_inode_page(old_inode); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 711 | update_inode_page(new_inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 712 | } else { |
Jaegeuk Kim | 2c4db1a | 2016-01-07 14:15:04 -0800 | [diff] [blame] | 713 | f2fs_balance_fs(sbi, true); |
Jaegeuk Kim | 00623e6 | 2015-12-22 11:56:08 -0800 | [diff] [blame] | 714 | |
Chao Yu | 1256010 | 2014-06-24 14:16:24 +0800 | [diff] [blame] | 715 | f2fs_lock_op(sbi); |
| 716 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 717 | err = f2fs_add_link(new_dentry, old_inode); |
Chao Yu | 1256010 | 2014-06-24 14:16:24 +0800 | [diff] [blame] | 718 | if (err) { |
| 719 | f2fs_unlock_op(sbi); |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 720 | goto out_whiteout; |
Chao Yu | 1256010 | 2014-06-24 14:16:24 +0800 | [diff] [blame] | 721 | } |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 722 | |
| 723 | if (old_dir_entry) { |
Jaegeuk Kim | a196124 | 2016-05-20 09:43:20 -0700 | [diff] [blame] | 724 | f2fs_i_links_write(new_dir, true); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 725 | update_inode_page(new_dir); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 726 | } |
Chao Yu | 993a049 | 2016-02-17 16:47:05 +0800 | [diff] [blame] | 727 | |
| 728 | /* |
| 729 | * old entry and new entry can locate in the same inline |
| 730 | * dentry in inode, when attaching new entry in inline dentry, |
| 731 | * it could force inline dentry conversion, after that, |
| 732 | * old_entry and old_page will point to wrong address, in |
| 733 | * order to avoid this, let's do the check and update here. |
| 734 | */ |
| 735 | if (is_old_inline && !f2fs_has_inline_dentry(old_dir)) { |
| 736 | f2fs_put_page(old_page, 0); |
| 737 | old_page = NULL; |
| 738 | |
| 739 | old_entry = f2fs_find_entry(old_dir, |
| 740 | &old_dentry->d_name, &old_page); |
| 741 | if (!old_entry) { |
| 742 | err = -EIO; |
| 743 | f2fs_unlock_op(sbi); |
| 744 | goto out_whiteout; |
| 745 | } |
| 746 | } |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 747 | } |
| 748 | |
Jaegeuk Kim | b2c0829 | 2014-06-30 18:09:55 +0900 | [diff] [blame] | 749 | down_write(&F2FS_I(old_inode)->i_sem); |
| 750 | file_lost_pino(old_inode); |
Jaegeuk Kim | e7d5545 | 2015-04-29 17:02:18 -0700 | [diff] [blame] | 751 | if (new_inode && file_enc_name(new_inode)) |
| 752 | file_set_enc_name(old_inode); |
Jaegeuk Kim | b2c0829 | 2014-06-30 18:09:55 +0900 | [diff] [blame] | 753 | up_write(&F2FS_I(old_inode)->i_sem); |
| 754 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 755 | old_inode->i_ctime = CURRENT_TIME; |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame^] | 756 | mark_inode_dirty_sync(old_inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 757 | |
Chao Yu | dbeacf0 | 2014-09-24 18:17:04 +0800 | [diff] [blame] | 758 | f2fs_delete_entry(old_entry, old_page, old_dir, NULL); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 759 | |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 760 | if (whiteout) { |
| 761 | whiteout->i_state |= I_LINKABLE; |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 762 | set_inode_flag(whiteout, FI_INC_LINK); |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 763 | err = f2fs_add_link(old_dentry, whiteout); |
| 764 | if (err) |
| 765 | goto put_out_dir; |
| 766 | whiteout->i_state &= ~I_LINKABLE; |
| 767 | iput(whiteout); |
| 768 | } |
| 769 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 770 | if (old_dir_entry) { |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 771 | if (old_dir != new_dir && !whiteout) { |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 772 | f2fs_set_link(old_inode, old_dir_entry, |
| 773 | old_dir_page, new_dir); |
Jaegeuk Kim | a18ff06 | 2014-01-21 13:32:12 +0900 | [diff] [blame] | 774 | update_inode_page(old_inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 775 | } else { |
Jaegeuk Kim | 9486ba4 | 2014-11-21 16:36:28 -0800 | [diff] [blame] | 776 | f2fs_dentry_kunmap(old_inode, old_dir_page); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 777 | f2fs_put_page(old_dir_page, 0); |
| 778 | } |
Jaegeuk Kim | a196124 | 2016-05-20 09:43:20 -0700 | [diff] [blame] | 779 | f2fs_i_links_write(old_dir, false); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 780 | update_inode_page(old_dir); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 781 | } |
| 782 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 783 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | b7e1d80 | 2014-11-09 22:15:31 -0800 | [diff] [blame] | 784 | |
| 785 | if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir)) |
| 786 | f2fs_sync_fs(sbi->sb, 1); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 787 | return 0; |
| 788 | |
Jaegeuk Kim | cbd56e7 | 2013-07-30 11:36:53 +0900 | [diff] [blame] | 789 | put_out_dir: |
Chao Yu | 1256010 | 2014-06-24 14:16:24 +0800 | [diff] [blame] | 790 | f2fs_unlock_op(sbi); |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 791 | if (new_page) { |
| 792 | f2fs_dentry_kunmap(new_dir, new_page); |
| 793 | f2fs_put_page(new_page, 0); |
| 794 | } |
| 795 | out_whiteout: |
| 796 | if (whiteout) |
| 797 | iput(whiteout); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 798 | out_dir: |
| 799 | if (old_dir_entry) { |
Jaegeuk Kim | 9486ba4 | 2014-11-21 16:36:28 -0800 | [diff] [blame] | 800 | f2fs_dentry_kunmap(old_inode, old_dir_page); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 801 | f2fs_put_page(old_dir_page, 0); |
| 802 | } |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 803 | out_old: |
Jaegeuk Kim | 9486ba4 | 2014-11-21 16:36:28 -0800 | [diff] [blame] | 804 | f2fs_dentry_kunmap(old_dir, old_page); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 805 | f2fs_put_page(old_page, 0); |
| 806 | out: |
| 807 | return err; |
| 808 | } |
| 809 | |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 810 | static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 811 | struct inode *new_dir, struct dentry *new_dentry) |
| 812 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 813 | struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 814 | struct inode *old_inode = d_inode(old_dentry); |
| 815 | struct inode *new_inode = d_inode(new_dentry); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 816 | struct page *old_dir_page, *new_dir_page; |
| 817 | struct page *old_page, *new_page; |
| 818 | struct f2fs_dir_entry *old_dir_entry = NULL, *new_dir_entry = NULL; |
| 819 | struct f2fs_dir_entry *old_entry, *new_entry; |
| 820 | int old_nlink = 0, new_nlink = 0; |
| 821 | int err = -ENOENT; |
| 822 | |
Chao Yu | d3baf7c | 2015-05-25 18:07:02 +0800 | [diff] [blame] | 823 | if ((f2fs_encrypted_inode(old_dir) || f2fs_encrypted_inode(new_dir)) && |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 824 | (old_dir != new_dir) && |
| 825 | (!fscrypt_has_permitted_context(new_dir, old_inode) || |
| 826 | !fscrypt_has_permitted_context(old_dir, new_inode))) |
Chao Yu | d3baf7c | 2015-05-25 18:07:02 +0800 | [diff] [blame] | 827 | return -EPERM; |
| 828 | |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 829 | old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page); |
| 830 | if (!old_entry) |
| 831 | goto out; |
| 832 | |
| 833 | new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, &new_page); |
| 834 | if (!new_entry) |
| 835 | goto out_old; |
| 836 | |
| 837 | /* prepare for updating ".." directory entry info later */ |
| 838 | if (old_dir != new_dir) { |
| 839 | if (S_ISDIR(old_inode->i_mode)) { |
| 840 | err = -EIO; |
| 841 | old_dir_entry = f2fs_parent_dir(old_inode, |
| 842 | &old_dir_page); |
| 843 | if (!old_dir_entry) |
| 844 | goto out_new; |
| 845 | } |
| 846 | |
| 847 | if (S_ISDIR(new_inode->i_mode)) { |
| 848 | err = -EIO; |
| 849 | new_dir_entry = f2fs_parent_dir(new_inode, |
| 850 | &new_dir_page); |
| 851 | if (!new_dir_entry) |
| 852 | goto out_old_dir; |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | /* |
| 857 | * If cross rename between file and directory those are not |
| 858 | * in the same directory, we will inc nlink of file's parent |
| 859 | * later, so we should check upper boundary of its nlink. |
| 860 | */ |
| 861 | if ((!old_dir_entry || !new_dir_entry) && |
| 862 | old_dir_entry != new_dir_entry) { |
| 863 | old_nlink = old_dir_entry ? -1 : 1; |
| 864 | new_nlink = -old_nlink; |
| 865 | err = -EMLINK; |
| 866 | if ((old_nlink > 0 && old_inode->i_nlink >= F2FS_LINK_MAX) || |
| 867 | (new_nlink > 0 && new_inode->i_nlink >= F2FS_LINK_MAX)) |
| 868 | goto out_new_dir; |
| 869 | } |
| 870 | |
Jaegeuk Kim | 2c4db1a | 2016-01-07 14:15:04 -0800 | [diff] [blame] | 871 | f2fs_balance_fs(sbi, true); |
Jaegeuk Kim | 00623e6 | 2015-12-22 11:56:08 -0800 | [diff] [blame] | 872 | |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 873 | f2fs_lock_op(sbi); |
| 874 | |
Jaegeuk Kim | e7d5545 | 2015-04-29 17:02:18 -0700 | [diff] [blame] | 875 | err = update_dent_inode(old_inode, new_inode, &new_dentry->d_name); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 876 | if (err) |
| 877 | goto out_unlock; |
Jaegeuk Kim | e7d5545 | 2015-04-29 17:02:18 -0700 | [diff] [blame] | 878 | if (file_enc_name(new_inode)) |
| 879 | file_set_enc_name(old_inode); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 880 | |
Jaegeuk Kim | e7d5545 | 2015-04-29 17:02:18 -0700 | [diff] [blame] | 881 | err = update_dent_inode(new_inode, old_inode, &old_dentry->d_name); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 882 | if (err) |
| 883 | goto out_undo; |
Jaegeuk Kim | e7d5545 | 2015-04-29 17:02:18 -0700 | [diff] [blame] | 884 | if (file_enc_name(old_inode)) |
| 885 | file_set_enc_name(new_inode); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 886 | |
| 887 | /* update ".." directory entry info of old dentry */ |
| 888 | if (old_dir_entry) |
| 889 | f2fs_set_link(old_inode, old_dir_entry, old_dir_page, new_dir); |
| 890 | |
| 891 | /* update ".." directory entry info of new dentry */ |
| 892 | if (new_dir_entry) |
| 893 | f2fs_set_link(new_inode, new_dir_entry, new_dir_page, old_dir); |
| 894 | |
| 895 | /* update directory entry info of old dir inode */ |
| 896 | f2fs_set_link(old_dir, old_entry, old_page, new_inode); |
| 897 | |
| 898 | down_write(&F2FS_I(old_inode)->i_sem); |
| 899 | file_lost_pino(old_inode); |
| 900 | up_write(&F2FS_I(old_inode)->i_sem); |
| 901 | |
| 902 | update_inode_page(old_inode); |
| 903 | |
| 904 | old_dir->i_ctime = CURRENT_TIME; |
| 905 | if (old_nlink) { |
| 906 | down_write(&F2FS_I(old_dir)->i_sem); |
Jaegeuk Kim | a196124 | 2016-05-20 09:43:20 -0700 | [diff] [blame] | 907 | f2fs_i_links_write(old_dir, old_nlink > 0); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 908 | up_write(&F2FS_I(old_dir)->i_sem); |
| 909 | } |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame^] | 910 | mark_inode_dirty_sync(old_dir); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 911 | update_inode_page(old_dir); |
| 912 | |
| 913 | /* update directory entry info of new dir inode */ |
| 914 | f2fs_set_link(new_dir, new_entry, new_page, old_inode); |
| 915 | |
| 916 | down_write(&F2FS_I(new_inode)->i_sem); |
| 917 | file_lost_pino(new_inode); |
| 918 | up_write(&F2FS_I(new_inode)->i_sem); |
| 919 | |
| 920 | update_inode_page(new_inode); |
| 921 | |
| 922 | new_dir->i_ctime = CURRENT_TIME; |
| 923 | if (new_nlink) { |
| 924 | down_write(&F2FS_I(new_dir)->i_sem); |
Jaegeuk Kim | a196124 | 2016-05-20 09:43:20 -0700 | [diff] [blame] | 925 | f2fs_i_links_write(new_dir, new_nlink > 0); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 926 | up_write(&F2FS_I(new_dir)->i_sem); |
| 927 | } |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame^] | 928 | mark_inode_dirty_sync(new_dir); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 929 | update_inode_page(new_dir); |
| 930 | |
| 931 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | b7e1d80 | 2014-11-09 22:15:31 -0800 | [diff] [blame] | 932 | |
| 933 | if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir)) |
| 934 | f2fs_sync_fs(sbi->sb, 1); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 935 | return 0; |
| 936 | out_undo: |
Jaegeuk Kim | e7d5545 | 2015-04-29 17:02:18 -0700 | [diff] [blame] | 937 | /* |
| 938 | * Still we may fail to recover name info of f2fs_inode here |
| 939 | * Drop it, once its name is set as encrypted |
| 940 | */ |
| 941 | update_dent_inode(old_inode, old_inode, &old_dentry->d_name); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 942 | out_unlock: |
| 943 | f2fs_unlock_op(sbi); |
| 944 | out_new_dir: |
| 945 | if (new_dir_entry) { |
Jaegeuk Kim | 9486ba4 | 2014-11-21 16:36:28 -0800 | [diff] [blame] | 946 | f2fs_dentry_kunmap(new_inode, new_dir_page); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 947 | f2fs_put_page(new_dir_page, 0); |
| 948 | } |
| 949 | out_old_dir: |
| 950 | if (old_dir_entry) { |
Jaegeuk Kim | 9486ba4 | 2014-11-21 16:36:28 -0800 | [diff] [blame] | 951 | f2fs_dentry_kunmap(old_inode, old_dir_page); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 952 | f2fs_put_page(old_dir_page, 0); |
| 953 | } |
| 954 | out_new: |
Jaegeuk Kim | 9486ba4 | 2014-11-21 16:36:28 -0800 | [diff] [blame] | 955 | f2fs_dentry_kunmap(new_dir, new_page); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 956 | f2fs_put_page(new_page, 0); |
| 957 | out_old: |
Jaegeuk Kim | 9486ba4 | 2014-11-21 16:36:28 -0800 | [diff] [blame] | 958 | f2fs_dentry_kunmap(old_dir, old_page); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 959 | f2fs_put_page(old_page, 0); |
| 960 | out: |
| 961 | return err; |
| 962 | } |
| 963 | |
| 964 | static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry, |
| 965 | struct inode *new_dir, struct dentry *new_dentry, |
| 966 | unsigned int flags) |
| 967 | { |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 968 | if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT)) |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 969 | return -EINVAL; |
| 970 | |
| 971 | if (flags & RENAME_EXCHANGE) { |
| 972 | return f2fs_cross_rename(old_dir, old_dentry, |
| 973 | new_dir, new_dentry); |
| 974 | } |
| 975 | /* |
| 976 | * VFS has already handled the new dentry existence case, |
| 977 | * here, we just deal with "RENAME_NOREPLACE" as regular rename. |
| 978 | */ |
Chao Yu | 7e01e7ad | 2015-05-19 17:37:26 +0800 | [diff] [blame] | 979 | return f2fs_rename(old_dir, old_dentry, new_dir, new_dentry, flags); |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 980 | } |
| 981 | |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 982 | static const char *f2fs_encrypted_get_link(struct dentry *dentry, |
Al Viro | fceef39 | 2015-12-29 15:58:39 -0500 | [diff] [blame] | 983 | struct inode *inode, |
| 984 | struct delayed_call *done) |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 985 | { |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 986 | struct page *cpage = NULL; |
| 987 | char *caddr, *paddr = NULL; |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 988 | struct fscrypt_str cstr = FSTR_INIT(NULL, 0); |
| 989 | struct fscrypt_str pstr = FSTR_INIT(NULL, 0); |
| 990 | struct fscrypt_symlink_data *sd; |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 991 | loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1); |
| 992 | u32 max_size = inode->i_sb->s_blocksize; |
| 993 | int res; |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 994 | |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 995 | if (!dentry) |
| 996 | return ERR_PTR(-ECHILD); |
| 997 | |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 998 | res = fscrypt_get_encryption_info(inode); |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 999 | if (res) |
| 1000 | return ERR_PTR(res); |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 1001 | |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1002 | cpage = read_mapping_page(inode->i_mapping, 0, NULL); |
| 1003 | if (IS_ERR(cpage)) |
Linus Torvalds | cfcc0ad | 2015-06-24 20:38:29 -0700 | [diff] [blame] | 1004 | return ERR_CAST(cpage); |
Al Viro | 21fc61c | 2015-11-17 01:07:57 -0500 | [diff] [blame] | 1005 | caddr = page_address(cpage); |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1006 | caddr[size] = 0; |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 1007 | |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1008 | /* Symlink is encrypted */ |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 1009 | sd = (struct fscrypt_symlink_data *)caddr; |
Chao Yu | 922ec35 | 2016-02-15 17:54:26 +0800 | [diff] [blame] | 1010 | cstr.name = sd->encrypted_path; |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1011 | cstr.len = le16_to_cpu(sd->len); |
Jaegeuk Kim | 8dc0d6a | 2015-12-24 16:13:09 -0800 | [diff] [blame] | 1012 | |
| 1013 | /* this is broken symlink case */ |
| 1014 | if (unlikely(cstr.len == 0)) { |
| 1015 | res = -ENOENT; |
| 1016 | goto errout; |
| 1017 | } |
Jaegeuk Kim | b97a9b5 | 2014-06-20 21:37:02 -0700 | [diff] [blame] | 1018 | |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 1019 | if ((cstr.len + sizeof(struct fscrypt_symlink_data) - 1) > max_size) { |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1020 | /* Symlink data on the disk is corrupted */ |
| 1021 | res = -EIO; |
| 1022 | goto errout; |
| 1023 | } |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 1024 | res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr); |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1025 | if (res) |
| 1026 | goto errout; |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 1027 | |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 1028 | res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr); |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1029 | if (res < 0) |
| 1030 | goto errout; |
Chao Yu | 3c0d84d | 2015-02-16 16:20:27 +0800 | [diff] [blame] | 1031 | |
Jaegeuk Kim | c90e09f | 2016-03-30 13:13:16 -0700 | [diff] [blame] | 1032 | /* this is broken symlink case */ |
| 1033 | if (unlikely(pstr.name[0] == 0)) { |
| 1034 | res = -ENOENT; |
| 1035 | goto errout; |
| 1036 | } |
| 1037 | |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1038 | paddr = pstr.name; |
Jaegeuk Kim | b97a9b5 | 2014-06-20 21:37:02 -0700 | [diff] [blame] | 1039 | |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1040 | /* Null-terminate the name */ |
| 1041 | paddr[res] = '\0'; |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1042 | |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1043 | put_page(cpage); |
Al Viro | fceef39 | 2015-12-29 15:58:39 -0500 | [diff] [blame] | 1044 | set_delayed_call(done, kfree_link, paddr); |
| 1045 | return paddr; |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1046 | errout: |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 1047 | fscrypt_fname_free_buffer(&pstr); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1048 | put_page(cpage); |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1049 | return ERR_PTR(res); |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 1050 | } |
| 1051 | |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1052 | const struct inode_operations f2fs_encrypted_symlink_inode_operations = { |
| 1053 | .readlink = generic_readlink, |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 1054 | .get_link = f2fs_encrypted_get_link, |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1055 | .getattr = f2fs_getattr, |
| 1056 | .setattr = f2fs_setattr, |
Chao Yu | 3a9e643 | 2015-12-31 18:20:10 +0800 | [diff] [blame] | 1057 | #ifdef CONFIG_F2FS_FS_XATTR |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1058 | .setxattr = generic_setxattr, |
| 1059 | .getxattr = generic_getxattr, |
| 1060 | .listxattr = f2fs_listxattr, |
| 1061 | .removexattr = generic_removexattr, |
Chao Yu | 3a9e643 | 2015-12-31 18:20:10 +0800 | [diff] [blame] | 1062 | #endif |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1063 | }; |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 1064 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 1065 | const struct inode_operations f2fs_dir_inode_operations = { |
| 1066 | .create = f2fs_create, |
| 1067 | .lookup = f2fs_lookup, |
| 1068 | .link = f2fs_link, |
| 1069 | .unlink = f2fs_unlink, |
| 1070 | .symlink = f2fs_symlink, |
| 1071 | .mkdir = f2fs_mkdir, |
| 1072 | .rmdir = f2fs_rmdir, |
| 1073 | .mknod = f2fs_mknod, |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 1074 | .rename2 = f2fs_rename2, |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 1075 | .tmpfile = f2fs_tmpfile, |
Jaegeuk Kim | 2d4d9fb5 | 2013-06-07 16:33:07 +0900 | [diff] [blame] | 1076 | .getattr = f2fs_getattr, |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 1077 | .setattr = f2fs_setattr, |
| 1078 | .get_acl = f2fs_get_acl, |
Christoph Hellwig | a6dda0e | 2013-12-20 05:16:45 -0800 | [diff] [blame] | 1079 | .set_acl = f2fs_set_acl, |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 1080 | #ifdef CONFIG_F2FS_FS_XATTR |
| 1081 | .setxattr = generic_setxattr, |
| 1082 | .getxattr = generic_getxattr, |
| 1083 | .listxattr = f2fs_listxattr, |
| 1084 | .removexattr = generic_removexattr, |
| 1085 | #endif |
| 1086 | }; |
| 1087 | |
| 1088 | const struct inode_operations f2fs_symlink_inode_operations = { |
| 1089 | .readlink = generic_readlink, |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 1090 | .get_link = f2fs_get_link, |
Jaegeuk Kim | 2d4d9fb5 | 2013-06-07 16:33:07 +0900 | [diff] [blame] | 1091 | .getattr = f2fs_getattr, |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 1092 | .setattr = f2fs_setattr, |
| 1093 | #ifdef CONFIG_F2FS_FS_XATTR |
| 1094 | .setxattr = generic_setxattr, |
| 1095 | .getxattr = generic_getxattr, |
| 1096 | .listxattr = f2fs_listxattr, |
| 1097 | .removexattr = generic_removexattr, |
| 1098 | #endif |
| 1099 | }; |
| 1100 | |
| 1101 | const struct inode_operations f2fs_special_inode_operations = { |
Jaegeuk Kim | 2d4d9fb5 | 2013-06-07 16:33:07 +0900 | [diff] [blame] | 1102 | .getattr = f2fs_getattr, |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 1103 | .setattr = f2fs_setattr, |
| 1104 | .get_acl = f2fs_get_acl, |
Christoph Hellwig | a6dda0e | 2013-12-20 05:16:45 -0800 | [diff] [blame] | 1105 | .set_acl = f2fs_set_acl, |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 1106 | #ifdef CONFIG_F2FS_FS_XATTR |
| 1107 | .setxattr = generic_setxattr, |
| 1108 | .getxattr = generic_getxattr, |
| 1109 | .listxattr = f2fs_listxattr, |
| 1110 | .removexattr = generic_removexattr, |
| 1111 | #endif |
| 1112 | }; |