Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * namei.c - NILFS pathname lookup operations. |
| 3 | * |
| 4 | * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | * |
| 20 | * Modified for NILFS by Amagai Yoshiji <amagai@osrg.net>, |
| 21 | * Ryusuke Konishi <ryusuke@osrg.net> |
| 22 | */ |
| 23 | /* |
| 24 | * linux/fs/ext2/namei.c |
| 25 | * |
| 26 | * Copyright (C) 1992, 1993, 1994, 1995 |
| 27 | * Remy Card (card@masi.ibp.fr) |
| 28 | * Laboratoire MASI - Institut Blaise Pascal |
| 29 | * Universite Pierre et Marie Curie (Paris VI) |
| 30 | * |
| 31 | * from |
| 32 | * |
| 33 | * linux/fs/minix/namei.c |
| 34 | * |
| 35 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 36 | * |
| 37 | * Big-endian to little-endian byte-swapping/bitmaps by |
| 38 | * David S. Miller (davem@caip.rutgers.edu), 1995 |
| 39 | */ |
| 40 | |
| 41 | #include <linux/pagemap.h> |
| 42 | #include "nilfs.h" |
| 43 | |
| 44 | |
| 45 | static inline int nilfs_add_nondir(struct dentry *dentry, struct inode *inode) |
| 46 | { |
| 47 | int err = nilfs_add_link(dentry, inode); |
| 48 | if (!err) { |
| 49 | d_instantiate(dentry, inode); |
| 50 | return 0; |
| 51 | } |
| 52 | inode_dec_link_count(inode); |
| 53 | iput(inode); |
| 54 | return err; |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * Methods themselves. |
| 59 | */ |
| 60 | |
| 61 | static struct dentry * |
| 62 | nilfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) |
| 63 | { |
| 64 | struct inode *inode; |
| 65 | ino_t ino; |
| 66 | |
| 67 | if (dentry->d_name.len > NILFS_NAME_LEN) |
| 68 | return ERR_PTR(-ENAMETOOLONG); |
| 69 | |
| 70 | ino = nilfs_inode_by_name(dir, dentry); |
| 71 | inode = NULL; |
| 72 | if (ino) { |
| 73 | inode = nilfs_iget(dir->i_sb, ino); |
| 74 | if (IS_ERR(inode)) |
| 75 | return ERR_CAST(inode); |
| 76 | } |
| 77 | return d_splice_alias(inode, dentry); |
| 78 | } |
| 79 | |
| 80 | struct dentry *nilfs_get_parent(struct dentry *child) |
| 81 | { |
| 82 | unsigned long ino; |
| 83 | struct inode *inode; |
| 84 | struct dentry dotdot; |
| 85 | |
| 86 | dotdot.d_name.name = ".."; |
| 87 | dotdot.d_name.len = 2; |
| 88 | |
| 89 | ino = nilfs_inode_by_name(child->d_inode, &dotdot); |
| 90 | if (!ino) |
| 91 | return ERR_PTR(-ENOENT); |
| 92 | |
| 93 | inode = nilfs_iget(child->d_inode->i_sb, ino); |
| 94 | if (IS_ERR(inode)) |
| 95 | return ERR_CAST(inode); |
| 96 | return d_obtain_alias(inode); |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * By the time this is called, we already have created |
| 101 | * the directory cache entry for the new file, but it |
| 102 | * is so far negative - it has no inode. |
| 103 | * |
| 104 | * If the create succeeds, we fill in the inode information |
| 105 | * with d_instantiate(). |
| 106 | */ |
| 107 | static int nilfs_create(struct inode *dir, struct dentry *dentry, int mode, |
| 108 | struct nameidata *nd) |
| 109 | { |
| 110 | struct inode *inode; |
| 111 | struct nilfs_transaction_info ti; |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 112 | int err; |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 113 | |
| 114 | err = nilfs_transaction_begin(dir->i_sb, &ti, 1); |
| 115 | if (err) |
| 116 | return err; |
| 117 | inode = nilfs_new_inode(dir, mode); |
| 118 | err = PTR_ERR(inode); |
| 119 | if (!IS_ERR(inode)) { |
| 120 | inode->i_op = &nilfs_file_inode_operations; |
| 121 | inode->i_fop = &nilfs_file_operations; |
| 122 | inode->i_mapping->a_ops = &nilfs_aops; |
Jiro SEKIBA | abdb318 | 2009-11-27 19:41:14 +0900 | [diff] [blame] | 123 | nilfs_mark_inode_dirty(inode); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 124 | err = nilfs_add_nondir(dentry, inode); |
| 125 | } |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 126 | if (!err) |
| 127 | err = nilfs_transaction_commit(dir->i_sb); |
| 128 | else |
| 129 | nilfs_transaction_abort(dir->i_sb); |
| 130 | |
| 131 | return err; |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static int |
| 135 | nilfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) |
| 136 | { |
| 137 | struct inode *inode; |
| 138 | struct nilfs_transaction_info ti; |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 139 | int err; |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 140 | |
| 141 | if (!new_valid_dev(rdev)) |
| 142 | return -EINVAL; |
| 143 | |
| 144 | err = nilfs_transaction_begin(dir->i_sb, &ti, 1); |
| 145 | if (err) |
| 146 | return err; |
| 147 | inode = nilfs_new_inode(dir, mode); |
| 148 | err = PTR_ERR(inode); |
| 149 | if (!IS_ERR(inode)) { |
| 150 | init_special_inode(inode, inode->i_mode, rdev); |
Jiro SEKIBA | abdb318 | 2009-11-27 19:41:14 +0900 | [diff] [blame] | 151 | nilfs_mark_inode_dirty(inode); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 152 | err = nilfs_add_nondir(dentry, inode); |
| 153 | } |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 154 | if (!err) |
| 155 | err = nilfs_transaction_commit(dir->i_sb); |
| 156 | else |
| 157 | nilfs_transaction_abort(dir->i_sb); |
| 158 | |
| 159 | return err; |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | static int nilfs_symlink(struct inode *dir, struct dentry *dentry, |
| 163 | const char *symname) |
| 164 | { |
| 165 | struct nilfs_transaction_info ti; |
| 166 | struct super_block *sb = dir->i_sb; |
| 167 | unsigned l = strlen(symname)+1; |
| 168 | struct inode *inode; |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 169 | int err; |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 170 | |
| 171 | if (l > sb->s_blocksize) |
| 172 | return -ENAMETOOLONG; |
| 173 | |
| 174 | err = nilfs_transaction_begin(dir->i_sb, &ti, 1); |
| 175 | if (err) |
| 176 | return err; |
| 177 | |
| 178 | inode = nilfs_new_inode(dir, S_IFLNK | S_IRWXUGO); |
| 179 | err = PTR_ERR(inode); |
| 180 | if (IS_ERR(inode)) |
| 181 | goto out; |
| 182 | |
| 183 | /* slow symlink */ |
| 184 | inode->i_op = &nilfs_symlink_inode_operations; |
| 185 | inode->i_mapping->a_ops = &nilfs_aops; |
| 186 | err = page_symlink(inode, symname, l); |
| 187 | if (err) |
| 188 | goto out_fail; |
| 189 | |
| 190 | /* mark_inode_dirty(inode); */ |
Jiro SEKIBA | 9ca941d | 2009-11-27 19:41:06 +0900 | [diff] [blame] | 191 | /* page_symlink() do this */ |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 192 | |
| 193 | err = nilfs_add_nondir(dentry, inode); |
| 194 | out: |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 195 | if (!err) |
| 196 | err = nilfs_transaction_commit(dir->i_sb); |
| 197 | else |
| 198 | nilfs_transaction_abort(dir->i_sb); |
| 199 | |
| 200 | return err; |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 201 | |
| 202 | out_fail: |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 203 | drop_nlink(inode); |
Jiro SEKIBA | abdb318 | 2009-11-27 19:41:14 +0900 | [diff] [blame] | 204 | nilfs_mark_inode_dirty(inode); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 205 | iput(inode); |
| 206 | goto out; |
| 207 | } |
| 208 | |
| 209 | static int nilfs_link(struct dentry *old_dentry, struct inode *dir, |
| 210 | struct dentry *dentry) |
| 211 | { |
| 212 | struct inode *inode = old_dentry->d_inode; |
| 213 | struct nilfs_transaction_info ti; |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 214 | int err; |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 215 | |
| 216 | if (inode->i_nlink >= NILFS_LINK_MAX) |
| 217 | return -EMLINK; |
| 218 | |
| 219 | err = nilfs_transaction_begin(dir->i_sb, &ti, 1); |
| 220 | if (err) |
| 221 | return err; |
| 222 | |
| 223 | inode->i_ctime = CURRENT_TIME; |
| 224 | inode_inc_link_count(inode); |
| 225 | atomic_inc(&inode->i_count); |
| 226 | |
| 227 | err = nilfs_add_nondir(dentry, inode); |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 228 | if (!err) |
| 229 | err = nilfs_transaction_commit(dir->i_sb); |
| 230 | else |
| 231 | nilfs_transaction_abort(dir->i_sb); |
| 232 | |
| 233 | return err; |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | static int nilfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) |
| 237 | { |
| 238 | struct inode *inode; |
| 239 | struct nilfs_transaction_info ti; |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 240 | int err; |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 241 | |
| 242 | if (dir->i_nlink >= NILFS_LINK_MAX) |
| 243 | return -EMLINK; |
| 244 | |
| 245 | err = nilfs_transaction_begin(dir->i_sb, &ti, 1); |
| 246 | if (err) |
| 247 | return err; |
| 248 | |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 249 | inc_nlink(dir); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 250 | |
| 251 | inode = nilfs_new_inode(dir, S_IFDIR | mode); |
| 252 | err = PTR_ERR(inode); |
| 253 | if (IS_ERR(inode)) |
| 254 | goto out_dir; |
| 255 | |
| 256 | inode->i_op = &nilfs_dir_inode_operations; |
| 257 | inode->i_fop = &nilfs_dir_operations; |
| 258 | inode->i_mapping->a_ops = &nilfs_aops; |
| 259 | |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 260 | inc_nlink(inode); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 261 | |
| 262 | err = nilfs_make_empty(inode, dir); |
| 263 | if (err) |
| 264 | goto out_fail; |
| 265 | |
| 266 | err = nilfs_add_link(dentry, inode); |
| 267 | if (err) |
| 268 | goto out_fail; |
| 269 | |
Jiro SEKIBA | abdb318 | 2009-11-27 19:41:14 +0900 | [diff] [blame] | 270 | nilfs_mark_inode_dirty(inode); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 271 | d_instantiate(dentry, inode); |
| 272 | out: |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 273 | if (!err) |
| 274 | err = nilfs_transaction_commit(dir->i_sb); |
| 275 | else |
| 276 | nilfs_transaction_abort(dir->i_sb); |
| 277 | |
| 278 | return err; |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 279 | |
| 280 | out_fail: |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 281 | drop_nlink(inode); |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 282 | drop_nlink(inode); |
Jiro SEKIBA | abdb318 | 2009-11-27 19:41:14 +0900 | [diff] [blame] | 283 | nilfs_mark_inode_dirty(inode); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 284 | iput(inode); |
| 285 | out_dir: |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 286 | drop_nlink(dir); |
Jiro SEKIBA | abdb318 | 2009-11-27 19:41:14 +0900 | [diff] [blame] | 287 | nilfs_mark_inode_dirty(dir); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 288 | goto out; |
| 289 | } |
| 290 | |
Jiro SEKIBA | 4cd76c3 | 2009-11-27 19:41:10 +0900 | [diff] [blame] | 291 | static int nilfs_do_unlink(struct inode *dir, struct dentry *dentry) |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 292 | { |
| 293 | struct inode *inode; |
| 294 | struct nilfs_dir_entry *de; |
| 295 | struct page *page; |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 296 | int err; |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 297 | |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 298 | err = -ENOENT; |
| 299 | de = nilfs_find_entry(dir, dentry, &page); |
| 300 | if (!de) |
| 301 | goto out; |
| 302 | |
| 303 | inode = dentry->d_inode; |
| 304 | err = -EIO; |
| 305 | if (le64_to_cpu(de->inode) != inode->i_ino) |
| 306 | goto out; |
| 307 | |
| 308 | if (!inode->i_nlink) { |
| 309 | nilfs_warning(inode->i_sb, __func__, |
| 310 | "deleting nonexistent file (%lu), %d\n", |
| 311 | inode->i_ino, inode->i_nlink); |
| 312 | inode->i_nlink = 1; |
| 313 | } |
| 314 | err = nilfs_delete_entry(de, page); |
| 315 | if (err) |
| 316 | goto out; |
| 317 | |
| 318 | inode->i_ctime = dir->i_ctime; |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 319 | drop_nlink(inode); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 320 | err = 0; |
| 321 | out: |
Jiro SEKIBA | 4cd76c3 | 2009-11-27 19:41:10 +0900 | [diff] [blame] | 322 | return err; |
| 323 | } |
| 324 | |
| 325 | static int nilfs_unlink(struct inode *dir, struct dentry *dentry) |
| 326 | { |
| 327 | struct nilfs_transaction_info ti; |
| 328 | int err; |
| 329 | |
| 330 | err = nilfs_transaction_begin(dir->i_sb, &ti, 0); |
| 331 | if (err) |
| 332 | return err; |
| 333 | |
| 334 | err = nilfs_do_unlink(dir, dentry); |
| 335 | |
| 336 | if (!err) { |
Jiro SEKIBA | abdb318 | 2009-11-27 19:41:14 +0900 | [diff] [blame] | 337 | nilfs_mark_inode_dirty(dir); |
| 338 | nilfs_mark_inode_dirty(dentry->d_inode); |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 339 | err = nilfs_transaction_commit(dir->i_sb); |
Jiro SEKIBA | 4cd76c3 | 2009-11-27 19:41:10 +0900 | [diff] [blame] | 340 | } else |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 341 | nilfs_transaction_abort(dir->i_sb); |
| 342 | |
| 343 | return err; |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | static int nilfs_rmdir(struct inode *dir, struct dentry *dentry) |
| 347 | { |
| 348 | struct inode *inode = dentry->d_inode; |
| 349 | struct nilfs_transaction_info ti; |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 350 | int err; |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 351 | |
| 352 | err = nilfs_transaction_begin(dir->i_sb, &ti, 0); |
| 353 | if (err) |
| 354 | return err; |
| 355 | |
| 356 | err = -ENOTEMPTY; |
| 357 | if (nilfs_empty_dir(inode)) { |
Jiro SEKIBA | 4cd76c3 | 2009-11-27 19:41:10 +0900 | [diff] [blame] | 358 | err = nilfs_do_unlink(dir, dentry); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 359 | if (!err) { |
| 360 | inode->i_size = 0; |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 361 | drop_nlink(inode); |
Jiro SEKIBA | abdb318 | 2009-11-27 19:41:14 +0900 | [diff] [blame] | 362 | nilfs_mark_inode_dirty(inode); |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 363 | drop_nlink(dir); |
Jiro SEKIBA | abdb318 | 2009-11-27 19:41:14 +0900 | [diff] [blame] | 364 | nilfs_mark_inode_dirty(dir); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 365 | } |
| 366 | } |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 367 | if (!err) |
| 368 | err = nilfs_transaction_commit(dir->i_sb); |
| 369 | else |
| 370 | nilfs_transaction_abort(dir->i_sb); |
| 371 | |
| 372 | return err; |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 376 | struct inode *new_dir, struct dentry *new_dentry) |
| 377 | { |
| 378 | struct inode *old_inode = old_dentry->d_inode; |
| 379 | struct inode *new_inode = new_dentry->d_inode; |
| 380 | struct page *dir_page = NULL; |
| 381 | struct nilfs_dir_entry *dir_de = NULL; |
| 382 | struct page *old_page; |
| 383 | struct nilfs_dir_entry *old_de; |
| 384 | struct nilfs_transaction_info ti; |
| 385 | int err; |
| 386 | |
| 387 | err = nilfs_transaction_begin(old_dir->i_sb, &ti, 1); |
| 388 | if (unlikely(err)) |
| 389 | return err; |
| 390 | |
| 391 | err = -ENOENT; |
| 392 | old_de = nilfs_find_entry(old_dir, old_dentry, &old_page); |
| 393 | if (!old_de) |
| 394 | goto out; |
| 395 | |
| 396 | if (S_ISDIR(old_inode->i_mode)) { |
| 397 | err = -EIO; |
| 398 | dir_de = nilfs_dotdot(old_inode, &dir_page); |
| 399 | if (!dir_de) |
| 400 | goto out_old; |
| 401 | } |
| 402 | |
| 403 | if (new_inode) { |
| 404 | struct page *new_page; |
| 405 | struct nilfs_dir_entry *new_de; |
| 406 | |
| 407 | err = -ENOTEMPTY; |
| 408 | if (dir_de && !nilfs_empty_dir(new_inode)) |
| 409 | goto out_dir; |
| 410 | |
| 411 | err = -ENOENT; |
| 412 | new_de = nilfs_find_entry(new_dir, new_dentry, &new_page); |
| 413 | if (!new_de) |
| 414 | goto out_dir; |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 415 | inc_nlink(old_inode); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 416 | nilfs_set_link(new_dir, new_de, new_page, old_inode); |
Jiro SEKIBA | abdb318 | 2009-11-27 19:41:14 +0900 | [diff] [blame] | 417 | nilfs_mark_inode_dirty(new_dir); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 418 | new_inode->i_ctime = CURRENT_TIME; |
| 419 | if (dir_de) |
| 420 | drop_nlink(new_inode); |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 421 | drop_nlink(new_inode); |
Jiro SEKIBA | abdb318 | 2009-11-27 19:41:14 +0900 | [diff] [blame] | 422 | nilfs_mark_inode_dirty(new_inode); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 423 | } else { |
| 424 | if (dir_de) { |
| 425 | err = -EMLINK; |
| 426 | if (new_dir->i_nlink >= NILFS_LINK_MAX) |
| 427 | goto out_dir; |
| 428 | } |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 429 | inc_nlink(old_inode); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 430 | err = nilfs_add_link(new_dentry, old_inode); |
| 431 | if (err) { |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 432 | drop_nlink(old_inode); |
Jiro SEKIBA | abdb318 | 2009-11-27 19:41:14 +0900 | [diff] [blame] | 433 | nilfs_mark_inode_dirty(old_inode); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 434 | goto out_dir; |
| 435 | } |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 436 | if (dir_de) { |
| 437 | inc_nlink(new_dir); |
Jiro SEKIBA | abdb318 | 2009-11-27 19:41:14 +0900 | [diff] [blame] | 438 | nilfs_mark_inode_dirty(new_dir); |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 439 | } |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /* |
| 443 | * Like most other Unix systems, set the ctime for inodes on a |
| 444 | * rename. |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 445 | */ |
| 446 | old_inode->i_ctime = CURRENT_TIME; |
| 447 | |
| 448 | nilfs_delete_entry(old_de, old_page); |
Jiro SEKIBA | 43f8bc2 | 2009-11-27 19:41:07 +0900 | [diff] [blame] | 449 | drop_nlink(old_inode); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 450 | |
| 451 | if (dir_de) { |
| 452 | nilfs_set_link(old_inode, dir_de, dir_page, new_dir); |
Jiro SEKIBA | 565de40 | 2009-11-27 19:41:08 +0900 | [diff] [blame] | 453 | drop_nlink(old_dir); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 454 | } |
Jiro SEKIBA | abdb318 | 2009-11-27 19:41:14 +0900 | [diff] [blame] | 455 | nilfs_mark_inode_dirty(old_dir); |
| 456 | nilfs_mark_inode_dirty(old_inode); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 457 | |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 458 | err = nilfs_transaction_commit(old_dir->i_sb); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 459 | return err; |
| 460 | |
| 461 | out_dir: |
| 462 | if (dir_de) { |
| 463 | kunmap(dir_page); |
| 464 | page_cache_release(dir_page); |
| 465 | } |
| 466 | out_old: |
| 467 | kunmap(old_page); |
| 468 | page_cache_release(old_page); |
| 469 | out: |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 470 | nilfs_transaction_abort(old_dir->i_sb); |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 471 | return err; |
| 472 | } |
| 473 | |
Alexey Dobriyan | 6e1d5dc | 2009-09-21 17:01:11 -0700 | [diff] [blame] | 474 | const struct inode_operations nilfs_dir_inode_operations = { |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 475 | .create = nilfs_create, |
| 476 | .lookup = nilfs_lookup, |
| 477 | .link = nilfs_link, |
| 478 | .unlink = nilfs_unlink, |
| 479 | .symlink = nilfs_symlink, |
| 480 | .mkdir = nilfs_mkdir, |
| 481 | .rmdir = nilfs_rmdir, |
| 482 | .mknod = nilfs_mknod, |
| 483 | .rename = nilfs_rename, |
| 484 | .setattr = nilfs_setattr, |
| 485 | .permission = nilfs_permission, |
| 486 | }; |
| 487 | |
Alexey Dobriyan | 6e1d5dc | 2009-09-21 17:01:11 -0700 | [diff] [blame] | 488 | const struct inode_operations nilfs_special_inode_operations = { |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 489 | .setattr = nilfs_setattr, |
| 490 | .permission = nilfs_permission, |
| 491 | }; |
| 492 | |
Alexey Dobriyan | 6e1d5dc | 2009-09-21 17:01:11 -0700 | [diff] [blame] | 493 | const struct inode_operations nilfs_symlink_inode_operations = { |
Ryusuke Konishi | d250065 | 2009-04-06 19:01:34 -0700 | [diff] [blame] | 494 | .readlink = generic_readlink, |
| 495 | .follow_link = page_follow_link_light, |
| 496 | .put_link = page_put_link, |
| 497 | }; |