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