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 | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 17 | |
| 18 | #include "f2fs.h" |
Jaegeuk Kim | 953a3e2 | 2013-03-21 15:21:57 +0900 | [diff] [blame] | 19 | #include "node.h" |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 20 | #include "xattr.h" |
| 21 | #include "acl.h" |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 22 | #include <trace/events/f2fs.h> |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 23 | |
| 24 | static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode) |
| 25 | { |
Jaegeuk Kim | a014e03 | 2014-06-20 21:44:02 -0700 | [diff] [blame] | 26 | struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 27 | nid_t ino; |
| 28 | struct inode *inode; |
| 29 | bool nid_free = false; |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 30 | int err; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 31 | |
Jaegeuk Kim | a014e03 | 2014-06-20 21:44:02 -0700 | [diff] [blame] | 32 | inode = new_inode(dir->i_sb); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 33 | if (!inode) |
| 34 | return ERR_PTR(-ENOMEM); |
| 35 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 36 | f2fs_lock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 37 | if (!alloc_nid(sbi, &ino)) { |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 38 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 39 | err = -ENOSPC; |
| 40 | goto fail; |
| 41 | } |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 42 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 43 | |
Chao Yu | 70ff5df | 2014-05-08 17:09:30 +0800 | [diff] [blame] | 44 | inode_init_owner(inode, dir, mode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 45 | |
| 46 | inode->i_ino = ino; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 47 | inode->i_blocks = 0; |
| 48 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; |
| 49 | inode->i_generation = sbi->s_next_generation++; |
| 50 | |
| 51 | err = insert_inode_locked(inode); |
| 52 | if (err) { |
| 53 | err = -EINVAL; |
| 54 | nid_free = true; |
| 55 | goto out; |
| 56 | } |
Jaegeuk Kim | d70b4f5 | 2013-04-25 13:24:33 +0900 | [diff] [blame] | 57 | trace_f2fs_new_inode(inode, 0); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 58 | mark_inode_dirty(inode); |
| 59 | return inode; |
| 60 | |
| 61 | out: |
| 62 | clear_nlink(inode); |
| 63 | unlock_new_inode(inode); |
| 64 | fail: |
Jaegeuk Kim | d70b4f5 | 2013-04-25 13:24:33 +0900 | [diff] [blame] | 65 | trace_f2fs_new_inode(inode, err); |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 66 | make_bad_inode(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 67 | iput(inode); |
| 68 | if (nid_free) |
| 69 | alloc_nid_failed(sbi, ino); |
| 70 | return ERR_PTR(err); |
| 71 | } |
| 72 | |
| 73 | static int is_multimedia_file(const unsigned char *s, const char *sub) |
| 74 | { |
Leon Romanovsky | 9836b8b | 2012-12-27 19:55:46 +0200 | [diff] [blame] | 75 | size_t slen = strlen(s); |
| 76 | size_t sublen = strlen(sub); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 77 | |
| 78 | if (sublen > slen) |
Namjae Jeon | e66509f0 | 2013-04-20 01:27:21 +0900 | [diff] [blame] | 79 | return 0; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 80 | |
Gu Zheng | 749ebfd | 2013-08-22 18:11:25 +0800 | [diff] [blame] | 81 | return !strncasecmp(s + slen - sublen, sub, sublen); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 82 | } |
| 83 | |
Jaegeuk Kim | 0a8165d | 2012-11-29 13:28:09 +0900 | [diff] [blame] | 84 | /* |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 85 | * Set multimedia files as cold files for hot/cold data separation |
| 86 | */ |
Jaegeuk Kim | 953a3e2 | 2013-03-21 15:21:57 +0900 | [diff] [blame] | 87 | 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] | 88 | const unsigned char *name) |
| 89 | { |
| 90 | int i; |
| 91 | __u8 (*extlist)[8] = sbi->raw_super->extension_list; |
| 92 | |
| 93 | int count = le32_to_cpu(sbi->raw_super->extension_count); |
| 94 | for (i = 0; i < count; i++) { |
Namjae Jeon | e66509f0 | 2013-04-20 01:27:21 +0900 | [diff] [blame] | 95 | if (is_multimedia_file(name, extlist[i])) { |
Jaegeuk Kim | 354a339 | 2013-06-14 08:52:35 +0900 | [diff] [blame] | 96 | file_set_cold(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 97 | break; |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
| 103 | bool excl) |
| 104 | { |
Jaegeuk Kim | a014e03 | 2014-06-20 21:44:02 -0700 | [diff] [blame] | 105 | struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 106 | struct inode *inode; |
| 107 | nid_t ino = 0; |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 108 | int err; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 109 | |
Jaegeuk Kim | 1efef83 | 2012-12-19 16:25:21 +0900 | [diff] [blame] | 110 | f2fs_balance_fs(sbi); |
| 111 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 112 | inode = f2fs_new_inode(dir, mode); |
| 113 | if (IS_ERR(inode)) |
| 114 | return PTR_ERR(inode); |
| 115 | |
| 116 | if (!test_opt(sbi, DISABLE_EXT_IDENTIFY)) |
Jaegeuk Kim | 953a3e2 | 2013-03-21 15:21:57 +0900 | [diff] [blame] | 117 | set_cold_files(sbi, inode, dentry->d_name.name); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 118 | |
| 119 | inode->i_op = &f2fs_file_inode_operations; |
| 120 | inode->i_fop = &f2fs_file_operations; |
| 121 | inode->i_mapping->a_ops = &f2fs_dblock_aops; |
| 122 | ino = inode->i_ino; |
| 123 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 124 | f2fs_lock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 125 | err = f2fs_add_link(dentry, inode); |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 126 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 127 | if (err) |
| 128 | goto out; |
| 129 | |
| 130 | alloc_nid_done(sbi, ino); |
| 131 | |
Jaegeuk Kim | 0a364af | 2013-05-16 08:57:43 +0900 | [diff] [blame] | 132 | d_instantiate(dentry, inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 133 | unlock_new_inode(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 134 | return 0; |
| 135 | out: |
| 136 | clear_nlink(inode); |
| 137 | unlock_new_inode(inode); |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 138 | make_bad_inode(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 139 | iput(inode); |
| 140 | alloc_nid_failed(sbi, ino); |
| 141 | return err; |
| 142 | } |
| 143 | |
| 144 | static int f2fs_link(struct dentry *old_dentry, struct inode *dir, |
| 145 | struct dentry *dentry) |
| 146 | { |
| 147 | struct inode *inode = old_dentry->d_inode; |
Jaegeuk Kim | a014e03 | 2014-06-20 21:44:02 -0700 | [diff] [blame] | 148 | struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 149 | int err; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 150 | |
Jaegeuk Kim | 1efef83 | 2012-12-19 16:25:21 +0900 | [diff] [blame] | 151 | f2fs_balance_fs(sbi); |
| 152 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 153 | inode->i_ctime = CURRENT_TIME; |
Jaegeuk Kim | 6f6fd83 | 2013-05-22 12:06:26 +0900 | [diff] [blame] | 154 | ihold(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 155 | |
| 156 | set_inode_flag(F2FS_I(inode), FI_INC_LINK); |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 157 | f2fs_lock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 158 | err = f2fs_add_link(dentry, inode); |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 159 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 160 | if (err) |
| 161 | goto out; |
| 162 | |
| 163 | d_instantiate(dentry, inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 164 | return 0; |
| 165 | out: |
| 166 | clear_inode_flag(F2FS_I(inode), FI_INC_LINK); |
| 167 | iput(inode); |
| 168 | return err; |
| 169 | } |
| 170 | |
| 171 | struct dentry *f2fs_get_parent(struct dentry *child) |
| 172 | { |
| 173 | struct qstr dotdot = QSTR_INIT("..", 2); |
| 174 | unsigned long ino = f2fs_inode_by_name(child->d_inode, &dotdot); |
| 175 | if (!ino) |
| 176 | return ERR_PTR(-ENOENT); |
| 177 | return d_obtain_alias(f2fs_iget(child->d_inode->i_sb, ino)); |
| 178 | } |
| 179 | |
| 180 | static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry, |
| 181 | unsigned int flags) |
| 182 | { |
| 183 | struct inode *inode = NULL; |
| 184 | struct f2fs_dir_entry *de; |
| 185 | struct page *page; |
| 186 | |
Jaegeuk Kim | 5a20d33 | 2013-03-03 13:58:05 +0900 | [diff] [blame] | 187 | if (dentry->d_name.len > F2FS_NAME_LEN) |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 188 | return ERR_PTR(-ENAMETOOLONG); |
| 189 | |
| 190 | de = f2fs_find_entry(dir, &dentry->d_name, &page); |
| 191 | if (de) { |
| 192 | nid_t ino = le32_to_cpu(de->ino); |
| 193 | kunmap(page); |
| 194 | f2fs_put_page(page, 0); |
| 195 | |
| 196 | inode = f2fs_iget(dir->i_sb, ino); |
| 197 | if (IS_ERR(inode)) |
| 198 | return ERR_CAST(inode); |
Chao Yu | 48b230a | 2014-04-07 11:18:34 +0800 | [diff] [blame] | 199 | |
| 200 | stat_inc_inline_inode(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | return d_splice_alias(inode, dentry); |
| 204 | } |
| 205 | |
| 206 | static int f2fs_unlink(struct inode *dir, struct dentry *dentry) |
| 207 | { |
Jaegeuk Kim | a014e03 | 2014-06-20 21:44:02 -0700 | [diff] [blame] | 208 | struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 209 | struct inode *inode = dentry->d_inode; |
| 210 | struct f2fs_dir_entry *de; |
| 211 | struct page *page; |
| 212 | int err = -ENOENT; |
| 213 | |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 214 | trace_f2fs_unlink_enter(dir, dentry); |
Jaegeuk Kim | 1efef83 | 2012-12-19 16:25:21 +0900 | [diff] [blame] | 215 | f2fs_balance_fs(sbi); |
| 216 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 217 | de = f2fs_find_entry(dir, &dentry->d_name, &page); |
| 218 | if (!de) |
| 219 | goto fail; |
| 220 | |
Jaegeuk Kim | ccaaca2 | 2013-10-08 10:19:28 +0900 | [diff] [blame] | 221 | f2fs_lock_op(sbi); |
Jaegeuk Kim | cbd56e7 | 2013-07-30 11:36:53 +0900 | [diff] [blame] | 222 | err = acquire_orphan_inode(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 223 | if (err) { |
Jaegeuk Kim | ccaaca2 | 2013-10-08 10:19:28 +0900 | [diff] [blame] | 224 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 225 | kunmap(page); |
| 226 | f2fs_put_page(page, 0); |
| 227 | goto fail; |
| 228 | } |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 229 | f2fs_delete_entry(de, page, inode); |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 230 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 231 | |
| 232 | /* In order to evict this inode, we set it dirty */ |
| 233 | mark_inode_dirty(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 234 | fail: |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 235 | trace_f2fs_unlink_exit(inode, err); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 236 | return err; |
| 237 | } |
| 238 | |
| 239 | static int f2fs_symlink(struct inode *dir, struct dentry *dentry, |
| 240 | const char *symname) |
| 241 | { |
Jaegeuk Kim | a014e03 | 2014-06-20 21:44:02 -0700 | [diff] [blame] | 242 | struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 243 | struct inode *inode; |
Leon Romanovsky | 9836b8b | 2012-12-27 19:55:46 +0200 | [diff] [blame] | 244 | size_t symlen = strlen(symname) + 1; |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 245 | int err; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 246 | |
Jaegeuk Kim | 1efef83 | 2012-12-19 16:25:21 +0900 | [diff] [blame] | 247 | f2fs_balance_fs(sbi); |
| 248 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 249 | inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO); |
| 250 | if (IS_ERR(inode)) |
| 251 | return PTR_ERR(inode); |
| 252 | |
| 253 | inode->i_op = &f2fs_symlink_inode_operations; |
| 254 | inode->i_mapping->a_ops = &f2fs_dblock_aops; |
| 255 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 256 | f2fs_lock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 257 | err = f2fs_add_link(dentry, inode); |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 258 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 259 | if (err) |
| 260 | goto out; |
| 261 | |
| 262 | err = page_symlink(inode, symname, symlen); |
| 263 | alloc_nid_done(sbi, inode->i_ino); |
| 264 | |
| 265 | d_instantiate(dentry, inode); |
| 266 | unlock_new_inode(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 267 | return err; |
| 268 | out: |
| 269 | clear_nlink(inode); |
| 270 | unlock_new_inode(inode); |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 271 | make_bad_inode(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 272 | iput(inode); |
| 273 | alloc_nid_failed(sbi, inode->i_ino); |
| 274 | return err; |
| 275 | } |
| 276 | |
| 277 | static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
| 278 | { |
| 279 | struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); |
| 280 | struct inode *inode; |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 281 | int err; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 282 | |
Jaegeuk Kim | 1efef83 | 2012-12-19 16:25:21 +0900 | [diff] [blame] | 283 | f2fs_balance_fs(sbi); |
| 284 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 285 | inode = f2fs_new_inode(dir, S_IFDIR | mode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 286 | if (IS_ERR(inode)) |
Namjae Jeon | 61412b6 | 2012-12-01 10:56:25 +0900 | [diff] [blame] | 287 | return PTR_ERR(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 288 | |
| 289 | inode->i_op = &f2fs_dir_inode_operations; |
| 290 | inode->i_fop = &f2fs_dir_operations; |
| 291 | inode->i_mapping->a_ops = &f2fs_dblock_aops; |
Namjae Jeon | a0d4253 | 2012-12-08 14:54:18 +0900 | [diff] [blame] | 292 | mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_ZERO); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 293 | |
| 294 | set_inode_flag(F2FS_I(inode), FI_INC_LINK); |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 295 | f2fs_lock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 296 | err = f2fs_add_link(dentry, inode); |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 297 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 298 | if (err) |
| 299 | goto out_fail; |
| 300 | |
| 301 | alloc_nid_done(sbi, inode->i_ino); |
| 302 | |
| 303 | d_instantiate(dentry, inode); |
| 304 | unlock_new_inode(inode); |
| 305 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 306 | return 0; |
| 307 | |
| 308 | out_fail: |
| 309 | clear_inode_flag(F2FS_I(inode), FI_INC_LINK); |
| 310 | clear_nlink(inode); |
| 311 | unlock_new_inode(inode); |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 312 | make_bad_inode(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 313 | iput(inode); |
| 314 | alloc_nid_failed(sbi, inode->i_ino); |
| 315 | return err; |
| 316 | } |
| 317 | |
| 318 | static int f2fs_rmdir(struct inode *dir, struct dentry *dentry) |
| 319 | { |
| 320 | struct inode *inode = dentry->d_inode; |
| 321 | if (f2fs_empty_dir(inode)) |
| 322 | return f2fs_unlink(dir, dentry); |
| 323 | return -ENOTEMPTY; |
| 324 | } |
| 325 | |
| 326 | static int f2fs_mknod(struct inode *dir, struct dentry *dentry, |
| 327 | umode_t mode, dev_t rdev) |
| 328 | { |
Jaegeuk Kim | a014e03 | 2014-06-20 21:44:02 -0700 | [diff] [blame] | 329 | struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 330 | struct inode *inode; |
| 331 | int err = 0; |
| 332 | |
| 333 | if (!new_valid_dev(rdev)) |
| 334 | return -EINVAL; |
| 335 | |
Jaegeuk Kim | 1efef83 | 2012-12-19 16:25:21 +0900 | [diff] [blame] | 336 | f2fs_balance_fs(sbi); |
| 337 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 338 | inode = f2fs_new_inode(dir, mode); |
| 339 | if (IS_ERR(inode)) |
| 340 | return PTR_ERR(inode); |
| 341 | |
| 342 | init_special_inode(inode, inode->i_mode, rdev); |
| 343 | inode->i_op = &f2fs_special_inode_operations; |
| 344 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 345 | f2fs_lock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 346 | err = f2fs_add_link(dentry, 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 | if (err) |
| 349 | goto out; |
| 350 | |
| 351 | alloc_nid_done(sbi, inode->i_ino); |
| 352 | d_instantiate(dentry, inode); |
| 353 | unlock_new_inode(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 354 | return 0; |
| 355 | out: |
| 356 | clear_nlink(inode); |
| 357 | unlock_new_inode(inode); |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 358 | make_bad_inode(inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 359 | iput(inode); |
| 360 | alloc_nid_failed(sbi, inode->i_ino); |
| 361 | return err; |
| 362 | } |
| 363 | |
| 364 | static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 365 | struct inode *new_dir, struct dentry *new_dentry) |
| 366 | { |
Jaegeuk Kim | a014e03 | 2014-06-20 21:44:02 -0700 | [diff] [blame] | 367 | struct f2fs_sb_info *sbi = F2FS_SB(old_dir->i_sb); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 368 | struct inode *old_inode = old_dentry->d_inode; |
| 369 | struct inode *new_inode = new_dentry->d_inode; |
| 370 | struct page *old_dir_page; |
Jaegeuk Kim | cbd56e7 | 2013-07-30 11:36:53 +0900 | [diff] [blame] | 371 | struct page *old_page, *new_page; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 372 | struct f2fs_dir_entry *old_dir_entry = NULL; |
| 373 | struct f2fs_dir_entry *old_entry; |
| 374 | struct f2fs_dir_entry *new_entry; |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 375 | int err = -ENOENT; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 376 | |
Jaegeuk Kim | 1efef83 | 2012-12-19 16:25:21 +0900 | [diff] [blame] | 377 | f2fs_balance_fs(sbi); |
| 378 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 379 | old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page); |
| 380 | if (!old_entry) |
| 381 | goto out; |
| 382 | |
| 383 | if (S_ISDIR(old_inode->i_mode)) { |
| 384 | err = -EIO; |
| 385 | old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page); |
| 386 | if (!old_dir_entry) |
| 387 | goto out_old; |
| 388 | } |
| 389 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 390 | if (new_inode) { |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 391 | |
| 392 | err = -ENOTEMPTY; |
| 393 | if (old_dir_entry && !f2fs_empty_dir(new_inode)) |
| 394 | goto out_dir; |
| 395 | |
| 396 | err = -ENOENT; |
| 397 | new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, |
| 398 | &new_page); |
| 399 | if (!new_entry) |
| 400 | goto out_dir; |
| 401 | |
Chao Yu | 1256010 | 2014-06-24 14:16:24 +0800 | [diff] [blame] | 402 | f2fs_lock_op(sbi); |
| 403 | |
Jaegeuk Kim | cbd56e7 | 2013-07-30 11:36:53 +0900 | [diff] [blame] | 404 | err = acquire_orphan_inode(sbi); |
| 405 | if (err) |
| 406 | goto put_out_dir; |
| 407 | |
Jaegeuk Kim | 1cd14ca | 2013-07-18 18:02:31 +0900 | [diff] [blame] | 408 | if (update_dent_inode(old_inode, &new_dentry->d_name)) { |
Jaegeuk Kim | cbd56e7 | 2013-07-30 11:36:53 +0900 | [diff] [blame] | 409 | release_orphan_inode(sbi); |
| 410 | goto put_out_dir; |
Jaegeuk Kim | 1cd14ca | 2013-07-18 18:02:31 +0900 | [diff] [blame] | 411 | } |
| 412 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 413 | f2fs_set_link(new_dir, new_entry, new_page, old_inode); |
| 414 | |
| 415 | new_inode->i_ctime = CURRENT_TIME; |
Jaegeuk Kim | d928bfb | 2014-03-20 19:10:08 +0900 | [diff] [blame] | 416 | down_write(&F2FS_I(new_inode)->i_sem); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 417 | if (old_dir_entry) |
| 418 | drop_nlink(new_inode); |
| 419 | drop_nlink(new_inode); |
Jaegeuk Kim | d928bfb | 2014-03-20 19:10:08 +0900 | [diff] [blame] | 420 | up_write(&F2FS_I(new_inode)->i_sem); |
| 421 | |
Jaegeuk Kim | a18ff06 | 2014-01-21 13:32:12 +0900 | [diff] [blame] | 422 | mark_inode_dirty(new_inode); |
Jaegeuk Kim | cbd56e7 | 2013-07-30 11:36:53 +0900 | [diff] [blame] | 423 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 424 | if (!new_inode->i_nlink) |
| 425 | add_orphan_inode(sbi, new_inode->i_ino); |
Jaegeuk Kim | cbd56e7 | 2013-07-30 11:36:53 +0900 | [diff] [blame] | 426 | else |
| 427 | release_orphan_inode(sbi); |
| 428 | |
Jaegeuk Kim | 8cb8268 | 2013-08-26 21:25:31 +0900 | [diff] [blame] | 429 | update_inode_page(old_inode); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 430 | update_inode_page(new_inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 431 | } else { |
Chao Yu | 1256010 | 2014-06-24 14:16:24 +0800 | [diff] [blame] | 432 | f2fs_lock_op(sbi); |
| 433 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 434 | err = f2fs_add_link(new_dentry, old_inode); |
Chao Yu | 1256010 | 2014-06-24 14:16:24 +0800 | [diff] [blame] | 435 | if (err) { |
| 436 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 437 | goto out_dir; |
Chao Yu | 1256010 | 2014-06-24 14:16:24 +0800 | [diff] [blame] | 438 | } |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 439 | |
| 440 | if (old_dir_entry) { |
| 441 | inc_nlink(new_dir); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 442 | update_inode_page(new_dir); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
Jaegeuk Kim | b2c0829 | 2014-06-30 18:09:55 +0900 | [diff] [blame] | 446 | down_write(&F2FS_I(old_inode)->i_sem); |
| 447 | file_lost_pino(old_inode); |
| 448 | up_write(&F2FS_I(old_inode)->i_sem); |
| 449 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 450 | old_inode->i_ctime = CURRENT_TIME; |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 451 | mark_inode_dirty(old_inode); |
| 452 | |
| 453 | f2fs_delete_entry(old_entry, old_page, NULL); |
| 454 | |
| 455 | if (old_dir_entry) { |
| 456 | if (old_dir != new_dir) { |
| 457 | f2fs_set_link(old_inode, old_dir_entry, |
| 458 | old_dir_page, new_dir); |
Jaegeuk Kim | a18ff06 | 2014-01-21 13:32:12 +0900 | [diff] [blame] | 459 | update_inode_page(old_inode); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 460 | } else { |
| 461 | kunmap(old_dir_page); |
| 462 | f2fs_put_page(old_dir_page, 0); |
| 463 | } |
| 464 | drop_nlink(old_dir); |
Jaegeuk Kim | a18ff06 | 2014-01-21 13:32:12 +0900 | [diff] [blame] | 465 | mark_inode_dirty(old_dir); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 466 | update_inode_page(old_dir); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 467 | } |
| 468 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 469 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 470 | return 0; |
| 471 | |
Jaegeuk Kim | cbd56e7 | 2013-07-30 11:36:53 +0900 | [diff] [blame] | 472 | put_out_dir: |
Chao Yu | 1256010 | 2014-06-24 14:16:24 +0800 | [diff] [blame] | 473 | f2fs_unlock_op(sbi); |
Chao Yu | dd4d961 | 2014-06-24 14:13:13 +0800 | [diff] [blame] | 474 | kunmap(new_page); |
| 475 | f2fs_put_page(new_page, 0); |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 476 | out_dir: |
| 477 | if (old_dir_entry) { |
| 478 | kunmap(old_dir_page); |
| 479 | f2fs_put_page(old_dir_page, 0); |
| 480 | } |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 481 | out_old: |
| 482 | kunmap(old_page); |
| 483 | f2fs_put_page(old_page, 0); |
| 484 | out: |
| 485 | return err; |
| 486 | } |
| 487 | |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 488 | static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 489 | struct inode *new_dir, struct dentry *new_dentry) |
| 490 | { |
| 491 | struct super_block *sb = old_dir->i_sb; |
| 492 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 493 | struct inode *old_inode = old_dentry->d_inode; |
| 494 | struct inode *new_inode = new_dentry->d_inode; |
| 495 | struct page *old_dir_page, *new_dir_page; |
| 496 | struct page *old_page, *new_page; |
| 497 | struct f2fs_dir_entry *old_dir_entry = NULL, *new_dir_entry = NULL; |
| 498 | struct f2fs_dir_entry *old_entry, *new_entry; |
| 499 | int old_nlink = 0, new_nlink = 0; |
| 500 | int err = -ENOENT; |
| 501 | |
| 502 | f2fs_balance_fs(sbi); |
| 503 | |
| 504 | old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page); |
| 505 | if (!old_entry) |
| 506 | goto out; |
| 507 | |
| 508 | new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, &new_page); |
| 509 | if (!new_entry) |
| 510 | goto out_old; |
| 511 | |
| 512 | /* prepare for updating ".." directory entry info later */ |
| 513 | if (old_dir != new_dir) { |
| 514 | if (S_ISDIR(old_inode->i_mode)) { |
| 515 | err = -EIO; |
| 516 | old_dir_entry = f2fs_parent_dir(old_inode, |
| 517 | &old_dir_page); |
| 518 | if (!old_dir_entry) |
| 519 | goto out_new; |
| 520 | } |
| 521 | |
| 522 | if (S_ISDIR(new_inode->i_mode)) { |
| 523 | err = -EIO; |
| 524 | new_dir_entry = f2fs_parent_dir(new_inode, |
| 525 | &new_dir_page); |
| 526 | if (!new_dir_entry) |
| 527 | goto out_old_dir; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | /* |
| 532 | * If cross rename between file and directory those are not |
| 533 | * in the same directory, we will inc nlink of file's parent |
| 534 | * later, so we should check upper boundary of its nlink. |
| 535 | */ |
| 536 | if ((!old_dir_entry || !new_dir_entry) && |
| 537 | old_dir_entry != new_dir_entry) { |
| 538 | old_nlink = old_dir_entry ? -1 : 1; |
| 539 | new_nlink = -old_nlink; |
| 540 | err = -EMLINK; |
| 541 | if ((old_nlink > 0 && old_inode->i_nlink >= F2FS_LINK_MAX) || |
| 542 | (new_nlink > 0 && new_inode->i_nlink >= F2FS_LINK_MAX)) |
| 543 | goto out_new_dir; |
| 544 | } |
| 545 | |
| 546 | f2fs_lock_op(sbi); |
| 547 | |
| 548 | err = update_dent_inode(old_inode, &new_dentry->d_name); |
| 549 | if (err) |
| 550 | goto out_unlock; |
| 551 | |
| 552 | err = update_dent_inode(new_inode, &old_dentry->d_name); |
| 553 | if (err) |
| 554 | goto out_undo; |
| 555 | |
| 556 | /* update ".." directory entry info of old dentry */ |
| 557 | if (old_dir_entry) |
| 558 | f2fs_set_link(old_inode, old_dir_entry, old_dir_page, new_dir); |
| 559 | |
| 560 | /* update ".." directory entry info of new dentry */ |
| 561 | if (new_dir_entry) |
| 562 | f2fs_set_link(new_inode, new_dir_entry, new_dir_page, old_dir); |
| 563 | |
| 564 | /* update directory entry info of old dir inode */ |
| 565 | f2fs_set_link(old_dir, old_entry, old_page, new_inode); |
| 566 | |
| 567 | down_write(&F2FS_I(old_inode)->i_sem); |
| 568 | file_lost_pino(old_inode); |
| 569 | up_write(&F2FS_I(old_inode)->i_sem); |
| 570 | |
| 571 | update_inode_page(old_inode); |
| 572 | |
| 573 | old_dir->i_ctime = CURRENT_TIME; |
| 574 | if (old_nlink) { |
| 575 | down_write(&F2FS_I(old_dir)->i_sem); |
| 576 | if (old_nlink < 0) |
| 577 | drop_nlink(old_dir); |
| 578 | else |
| 579 | inc_nlink(old_dir); |
| 580 | up_write(&F2FS_I(old_dir)->i_sem); |
| 581 | } |
| 582 | mark_inode_dirty(old_dir); |
| 583 | update_inode_page(old_dir); |
| 584 | |
| 585 | /* update directory entry info of new dir inode */ |
| 586 | f2fs_set_link(new_dir, new_entry, new_page, old_inode); |
| 587 | |
| 588 | down_write(&F2FS_I(new_inode)->i_sem); |
| 589 | file_lost_pino(new_inode); |
| 590 | up_write(&F2FS_I(new_inode)->i_sem); |
| 591 | |
| 592 | update_inode_page(new_inode); |
| 593 | |
| 594 | new_dir->i_ctime = CURRENT_TIME; |
| 595 | if (new_nlink) { |
| 596 | down_write(&F2FS_I(new_dir)->i_sem); |
| 597 | if (new_nlink < 0) |
| 598 | drop_nlink(new_dir); |
| 599 | else |
| 600 | inc_nlink(new_dir); |
| 601 | up_write(&F2FS_I(new_dir)->i_sem); |
| 602 | } |
| 603 | mark_inode_dirty(new_dir); |
| 604 | update_inode_page(new_dir); |
| 605 | |
| 606 | f2fs_unlock_op(sbi); |
| 607 | return 0; |
| 608 | out_undo: |
| 609 | /* Still we may fail to recover name info of f2fs_inode here */ |
| 610 | update_dent_inode(old_inode, &old_dentry->d_name); |
| 611 | out_unlock: |
| 612 | f2fs_unlock_op(sbi); |
| 613 | out_new_dir: |
| 614 | if (new_dir_entry) { |
| 615 | kunmap(new_dir_page); |
| 616 | f2fs_put_page(new_dir_page, 0); |
| 617 | } |
| 618 | out_old_dir: |
| 619 | if (old_dir_entry) { |
| 620 | kunmap(old_dir_page); |
| 621 | f2fs_put_page(old_dir_page, 0); |
| 622 | } |
| 623 | out_new: |
| 624 | kunmap(new_page); |
| 625 | f2fs_put_page(new_page, 0); |
| 626 | out_old: |
| 627 | kunmap(old_page); |
| 628 | f2fs_put_page(old_page, 0); |
| 629 | out: |
| 630 | return err; |
| 631 | } |
| 632 | |
| 633 | static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry, |
| 634 | struct inode *new_dir, struct dentry *new_dentry, |
| 635 | unsigned int flags) |
| 636 | { |
| 637 | if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE)) |
| 638 | return -EINVAL; |
| 639 | |
| 640 | if (flags & RENAME_EXCHANGE) { |
| 641 | return f2fs_cross_rename(old_dir, old_dentry, |
| 642 | new_dir, new_dentry); |
| 643 | } |
| 644 | /* |
| 645 | * VFS has already handled the new dentry existence case, |
| 646 | * here, we just deal with "RENAME_NOREPLACE" as regular rename. |
| 647 | */ |
| 648 | return f2fs_rename(old_dir, old_dentry, new_dir, new_dentry); |
| 649 | } |
| 650 | |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 651 | static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) |
| 652 | { |
Jaegeuk Kim | a014e03 | 2014-06-20 21:44:02 -0700 | [diff] [blame] | 653 | struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 654 | struct inode *inode; |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 655 | int err; |
| 656 | |
| 657 | inode = f2fs_new_inode(dir, mode); |
| 658 | if (IS_ERR(inode)) |
| 659 | return PTR_ERR(inode); |
| 660 | |
| 661 | inode->i_op = &f2fs_file_inode_operations; |
| 662 | inode->i_fop = &f2fs_file_operations; |
| 663 | inode->i_mapping->a_ops = &f2fs_dblock_aops; |
| 664 | |
| 665 | f2fs_lock_op(sbi); |
| 666 | err = acquire_orphan_inode(sbi); |
| 667 | if (err) |
| 668 | goto out; |
Jaegeuk Kim | b97a9b5 | 2014-06-20 21:37:02 -0700 | [diff] [blame] | 669 | |
| 670 | err = f2fs_do_tmpfile(inode, dir); |
| 671 | if (err) |
| 672 | goto release_out; |
| 673 | |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 674 | /* |
| 675 | * add this non-linked tmpfile to orphan list, in this way we could |
| 676 | * remove all unused data of tmpfile after abnormal power-off. |
| 677 | */ |
| 678 | add_orphan_inode(sbi, inode->i_ino); |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 679 | f2fs_unlock_op(sbi); |
| 680 | |
| 681 | alloc_nid_done(sbi, inode->i_ino); |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 682 | d_tmpfile(dentry, inode); |
| 683 | unlock_new_inode(inode); |
| 684 | return 0; |
Jaegeuk Kim | b97a9b5 | 2014-06-20 21:37:02 -0700 | [diff] [blame] | 685 | |
| 686 | release_out: |
| 687 | release_orphan_inode(sbi); |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 688 | out: |
| 689 | f2fs_unlock_op(sbi); |
| 690 | clear_nlink(inode); |
| 691 | unlock_new_inode(inode); |
| 692 | make_bad_inode(inode); |
| 693 | iput(inode); |
| 694 | alloc_nid_failed(sbi, inode->i_ino); |
| 695 | return err; |
| 696 | } |
| 697 | |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 698 | const struct inode_operations f2fs_dir_inode_operations = { |
| 699 | .create = f2fs_create, |
| 700 | .lookup = f2fs_lookup, |
| 701 | .link = f2fs_link, |
| 702 | .unlink = f2fs_unlink, |
| 703 | .symlink = f2fs_symlink, |
| 704 | .mkdir = f2fs_mkdir, |
| 705 | .rmdir = f2fs_rmdir, |
| 706 | .mknod = f2fs_mknod, |
| 707 | .rename = f2fs_rename, |
Chao Yu | 32f9bc2 | 2014-07-12 19:13:54 +0800 | [diff] [blame] | 708 | .rename2 = f2fs_rename2, |
Chao Yu | 50732df | 2014-06-19 16:23:19 +0800 | [diff] [blame] | 709 | .tmpfile = f2fs_tmpfile, |
Jaegeuk Kim | 2d4d9fb5 | 2013-06-07 16:33:07 +0900 | [diff] [blame] | 710 | .getattr = f2fs_getattr, |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 711 | .setattr = f2fs_setattr, |
| 712 | .get_acl = f2fs_get_acl, |
Christoph Hellwig | a6dda0e | 2013-12-20 05:16:45 -0800 | [diff] [blame] | 713 | .set_acl = f2fs_set_acl, |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 714 | #ifdef CONFIG_F2FS_FS_XATTR |
| 715 | .setxattr = generic_setxattr, |
| 716 | .getxattr = generic_getxattr, |
| 717 | .listxattr = f2fs_listxattr, |
| 718 | .removexattr = generic_removexattr, |
| 719 | #endif |
| 720 | }; |
| 721 | |
| 722 | const struct inode_operations f2fs_symlink_inode_operations = { |
| 723 | .readlink = generic_readlink, |
| 724 | .follow_link = page_follow_link_light, |
| 725 | .put_link = page_put_link, |
Jaegeuk Kim | 2d4d9fb5 | 2013-06-07 16:33:07 +0900 | [diff] [blame] | 726 | .getattr = f2fs_getattr, |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 727 | .setattr = f2fs_setattr, |
| 728 | #ifdef CONFIG_F2FS_FS_XATTR |
| 729 | .setxattr = generic_setxattr, |
| 730 | .getxattr = generic_getxattr, |
| 731 | .listxattr = f2fs_listxattr, |
| 732 | .removexattr = generic_removexattr, |
| 733 | #endif |
| 734 | }; |
| 735 | |
| 736 | const struct inode_operations f2fs_special_inode_operations = { |
Jaegeuk Kim | 2d4d9fb5 | 2013-06-07 16:33:07 +0900 | [diff] [blame] | 737 | .getattr = f2fs_getattr, |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 738 | .setattr = f2fs_setattr, |
| 739 | .get_acl = f2fs_get_acl, |
Christoph Hellwig | a6dda0e | 2013-12-20 05:16:45 -0800 | [diff] [blame] | 740 | .set_acl = f2fs_set_acl, |
Jaegeuk Kim | 57397d8 | 2012-11-02 17:11:10 +0900 | [diff] [blame] | 741 | #ifdef CONFIG_F2FS_FS_XATTR |
| 742 | .setxattr = generic_setxattr, |
| 743 | .getxattr = generic_getxattr, |
| 744 | .listxattr = f2fs_listxattr, |
| 745 | .removexattr = generic_removexattr, |
| 746 | #endif |
| 747 | }; |