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