Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/ufs/namei.c |
| 3 | * |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 4 | * Migration to usage of "page cache" on May 2006 by |
| 5 | * Evgeniy Dushistov <dushistov@mail.ru> based on ext2 code base. |
| 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Copyright (C) 1998 |
| 8 | * Daniel Pirkl <daniel.pirkl@email.cz> |
| 9 | * Charles University, Faculty of Mathematics and Physics |
| 10 | * |
| 11 | * from |
| 12 | * |
| 13 | * linux/fs/ext2/namei.c |
| 14 | * |
| 15 | * Copyright (C) 1992, 1993, 1994, 1995 |
| 16 | * Remy Card (card@masi.ibp.fr) |
| 17 | * Laboratoire MASI - Institut Blaise Pascal |
| 18 | * Universite Pierre et Marie Curie (Paris VI) |
| 19 | * |
| 20 | * from |
| 21 | * |
| 22 | * linux/fs/minix/namei.c |
| 23 | * |
| 24 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 25 | * |
| 26 | * Big-endian to little-endian byte-swapping/bitmaps by |
| 27 | * David S. Miller (davem@caip.rutgers.edu), 1995 |
| 28 | */ |
| 29 | |
| 30 | #include <linux/time.h> |
| 31 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/smp_lock.h> |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 33 | #include <linux/quotaops.h> |
Mike Frysinger | e542059 | 2008-02-08 04:21:31 -0800 | [diff] [blame] | 34 | |
| 35 | #include "ufs_fs.h" |
Christoph Hellwig | bcd6d4e | 2007-10-16 23:26:51 -0700 | [diff] [blame] | 36 | #include "ufs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include "util.h" |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | static inline int ufs_add_nondir(struct dentry *dentry, struct inode *inode) |
| 40 | { |
| 41 | int err = ufs_add_link(dentry, inode); |
| 42 | if (!err) { |
| 43 | d_instantiate(dentry, inode); |
| 44 | return 0; |
| 45 | } |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 46 | inode_dec_link_count(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | iput(inode); |
| 48 | return err; |
| 49 | } |
| 50 | |
| 51 | static struct dentry *ufs_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd) |
| 52 | { |
| 53 | struct inode * inode = NULL; |
| 54 | ino_t ino; |
| 55 | |
| 56 | if (dentry->d_name.len > UFS_MAXNAMLEN) |
| 57 | return ERR_PTR(-ENAMETOOLONG); |
| 58 | |
| 59 | lock_kernel(); |
Alexey Dobriyan | 0804970 | 2009-12-15 16:46:50 -0800 | [diff] [blame] | 60 | ino = ufs_inode_by_name(dir, &dentry->d_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | if (ino) { |
David Howells | b55c460 | 2008-02-07 00:15:48 -0800 | [diff] [blame] | 62 | inode = ufs_iget(dir->i_sb, ino); |
| 63 | if (IS_ERR(inode)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | unlock_kernel(); |
David Howells | b55c460 | 2008-02-07 00:15:48 -0800 | [diff] [blame] | 65 | return ERR_CAST(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | unlock_kernel(); |
| 69 | d_add(dentry, inode); |
| 70 | return NULL; |
| 71 | } |
| 72 | |
| 73 | /* |
| 74 | * By the time this is called, we already have created |
| 75 | * the directory cache entry for the new file, but it |
| 76 | * is so far negative - it has no inode. |
| 77 | * |
| 78 | * If the create succeeds, we fill in the inode information |
| 79 | * with d_instantiate(). |
| 80 | */ |
| 81 | static int ufs_create (struct inode * dir, struct dentry * dentry, int mode, |
| 82 | struct nameidata *nd) |
| 83 | { |
Evgeniy Dushistov | abf5d15 | 2006-06-25 05:47:24 -0700 | [diff] [blame] | 84 | struct inode *inode; |
| 85 | int err; |
| 86 | |
| 87 | UFSD("BEGIN\n"); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 88 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 89 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 90 | |
Evgeniy Dushistov | abf5d15 | 2006-06-25 05:47:24 -0700 | [diff] [blame] | 91 | inode = ufs_new_inode(dir, mode); |
| 92 | err = PTR_ERR(inode); |
| 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | if (!IS_ERR(inode)) { |
| 95 | inode->i_op = &ufs_file_inode_operations; |
| 96 | inode->i_fop = &ufs_file_operations; |
| 97 | inode->i_mapping->a_ops = &ufs_aops; |
| 98 | mark_inode_dirty(inode); |
| 99 | lock_kernel(); |
| 100 | err = ufs_add_nondir(dentry, inode); |
| 101 | unlock_kernel(); |
| 102 | } |
Evgeniy Dushistov | abf5d15 | 2006-06-25 05:47:24 -0700 | [diff] [blame] | 103 | UFSD("END: err=%d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | return err; |
| 105 | } |
| 106 | |
| 107 | static int ufs_mknod (struct inode * dir, struct dentry *dentry, int mode, dev_t rdev) |
| 108 | { |
| 109 | struct inode *inode; |
| 110 | int err; |
| 111 | |
| 112 | if (!old_valid_dev(rdev)) |
| 113 | return -EINVAL; |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 114 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 115 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | inode = ufs_new_inode(dir, mode); |
| 118 | err = PTR_ERR(inode); |
| 119 | if (!IS_ERR(inode)) { |
| 120 | init_special_inode(inode, mode, rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | ufs_set_inode_dev(inode->i_sb, UFS_I(inode), rdev); |
| 122 | mark_inode_dirty(inode); |
| 123 | lock_kernel(); |
| 124 | err = ufs_add_nondir(dentry, inode); |
| 125 | unlock_kernel(); |
| 126 | } |
| 127 | return err; |
| 128 | } |
| 129 | |
| 130 | static int ufs_symlink (struct inode * dir, struct dentry * dentry, |
| 131 | const char * symname) |
| 132 | { |
| 133 | struct super_block * sb = dir->i_sb; |
| 134 | int err = -ENAMETOOLONG; |
| 135 | unsigned l = strlen(symname)+1; |
| 136 | struct inode * inode; |
| 137 | |
| 138 | if (l > sb->s_blocksize) |
Josh Triplett | 344fe78 | 2006-07-30 03:03:59 -0700 | [diff] [blame] | 139 | goto out_notlocked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 141 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | lock_kernel(); |
| 144 | inode = ufs_new_inode(dir, S_IFLNK | S_IRWXUGO); |
| 145 | err = PTR_ERR(inode); |
| 146 | if (IS_ERR(inode)) |
| 147 | goto out; |
| 148 | |
| 149 | if (l > UFS_SB(sb)->s_uspi->s_maxsymlinklen) { |
| 150 | /* slow symlink */ |
| 151 | inode->i_op = &page_symlink_inode_operations; |
| 152 | inode->i_mapping->a_ops = &ufs_aops; |
| 153 | err = page_symlink(inode, symname, l); |
| 154 | if (err) |
| 155 | goto out_fail; |
| 156 | } else { |
| 157 | /* fast symlink */ |
| 158 | inode->i_op = &ufs_fast_symlink_inode_operations; |
Duane Griffin | 723be1f | 2009-01-08 22:43:51 +0000 | [diff] [blame] | 159 | memcpy(UFS_I(inode)->i_u1.i_symlink, symname, l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | inode->i_size = l-1; |
| 161 | } |
| 162 | mark_inode_dirty(inode); |
| 163 | |
| 164 | err = ufs_add_nondir(dentry, inode); |
| 165 | out: |
| 166 | unlock_kernel(); |
Josh Triplett | 344fe78 | 2006-07-30 03:03:59 -0700 | [diff] [blame] | 167 | out_notlocked: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | return err; |
| 169 | |
| 170 | out_fail: |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 171 | inode_dec_link_count(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | iput(inode); |
| 173 | goto out; |
| 174 | } |
| 175 | |
| 176 | static int ufs_link (struct dentry * old_dentry, struct inode * dir, |
| 177 | struct dentry *dentry) |
| 178 | { |
| 179 | struct inode *inode = old_dentry->d_inode; |
| 180 | int error; |
| 181 | |
| 182 | lock_kernel(); |
| 183 | if (inode->i_nlink >= UFS_LINK_MAX) { |
| 184 | unlock_kernel(); |
| 185 | return -EMLINK; |
| 186 | } |
| 187 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 188 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | inode->i_ctime = CURRENT_TIME_SEC; |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 191 | inode_inc_link_count(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | atomic_inc(&inode->i_count); |
| 193 | |
| 194 | error = ufs_add_nondir(dentry, inode); |
| 195 | unlock_kernel(); |
| 196 | return error; |
| 197 | } |
| 198 | |
| 199 | static int ufs_mkdir(struct inode * dir, struct dentry * dentry, int mode) |
| 200 | { |
| 201 | struct inode * inode; |
| 202 | int err = -EMLINK; |
| 203 | |
| 204 | if (dir->i_nlink >= UFS_LINK_MAX) |
| 205 | goto out; |
| 206 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 207 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | lock_kernel(); |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 210 | inode_inc_link_count(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
| 212 | inode = ufs_new_inode(dir, S_IFDIR|mode); |
| 213 | err = PTR_ERR(inode); |
| 214 | if (IS_ERR(inode)) |
| 215 | goto out_dir; |
| 216 | |
| 217 | inode->i_op = &ufs_dir_inode_operations; |
| 218 | inode->i_fop = &ufs_dir_operations; |
Evgeniy Dushistov | 826843a | 2006-06-25 05:47:21 -0700 | [diff] [blame] | 219 | inode->i_mapping->a_ops = &ufs_aops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 221 | inode_inc_link_count(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
| 223 | err = ufs_make_empty(inode, dir); |
| 224 | if (err) |
| 225 | goto out_fail; |
| 226 | |
| 227 | err = ufs_add_link(dentry, inode); |
| 228 | if (err) |
| 229 | goto out_fail; |
| 230 | unlock_kernel(); |
| 231 | |
| 232 | d_instantiate(dentry, inode); |
| 233 | out: |
| 234 | return err; |
| 235 | |
| 236 | out_fail: |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 237 | inode_dec_link_count(inode); |
| 238 | inode_dec_link_count(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | iput (inode); |
| 240 | out_dir: |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 241 | inode_dec_link_count(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | unlock_kernel(); |
| 243 | goto out; |
| 244 | } |
| 245 | |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 246 | static int ufs_unlink(struct inode *dir, struct dentry *dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
| 248 | struct inode * inode = dentry->d_inode; |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 249 | struct ufs_dir_entry *de; |
| 250 | struct page *page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | int err = -ENOENT; |
| 252 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 253 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 254 | |
Alexey Dobriyan | 0804970 | 2009-12-15 16:46:50 -0800 | [diff] [blame] | 255 | de = ufs_find_entry(dir, &dentry->d_name, &page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | if (!de) |
| 257 | goto out; |
| 258 | |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 259 | err = ufs_delete_entry(dir, de, page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | if (err) |
| 261 | goto out; |
| 262 | |
| 263 | inode->i_ctime = dir->i_ctime; |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 264 | inode_dec_link_count(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | err = 0; |
| 266 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | return err; |
| 268 | } |
| 269 | |
| 270 | static int ufs_rmdir (struct inode * dir, struct dentry *dentry) |
| 271 | { |
| 272 | struct inode * inode = dentry->d_inode; |
| 273 | int err= -ENOTEMPTY; |
| 274 | |
| 275 | lock_kernel(); |
| 276 | if (ufs_empty_dir (inode)) { |
| 277 | err = ufs_unlink(dir, dentry); |
| 278 | if (!err) { |
| 279 | inode->i_size = 0; |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 280 | inode_dec_link_count(inode); |
| 281 | inode_dec_link_count(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | unlock_kernel(); |
| 285 | return err; |
| 286 | } |
| 287 | |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 288 | static int ufs_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 289 | struct inode *new_dir, struct dentry *new_dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
| 291 | struct inode *old_inode = old_dentry->d_inode; |
| 292 | struct inode *new_inode = new_dentry->d_inode; |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 293 | struct page *dir_page = NULL; |
| 294 | struct ufs_dir_entry * dir_de = NULL; |
| 295 | struct page *old_page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | struct ufs_dir_entry *old_de; |
| 297 | int err = -ENOENT; |
| 298 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 299 | dquot_initialize(old_dir); |
| 300 | dquot_initialize(new_dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 301 | |
Alexey Dobriyan | 0804970 | 2009-12-15 16:46:50 -0800 | [diff] [blame] | 302 | old_de = ufs_find_entry(old_dir, &old_dentry->d_name, &old_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | if (!old_de) |
| 304 | goto out; |
| 305 | |
| 306 | if (S_ISDIR(old_inode->i_mode)) { |
| 307 | err = -EIO; |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 308 | dir_de = ufs_dotdot(old_inode, &dir_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | if (!dir_de) |
| 310 | goto out_old; |
| 311 | } |
| 312 | |
| 313 | if (new_inode) { |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 314 | struct page *new_page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | struct ufs_dir_entry *new_de; |
| 316 | |
| 317 | err = -ENOTEMPTY; |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 318 | if (dir_de && !ufs_empty_dir(new_inode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | goto out_dir; |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | err = -ENOENT; |
Alexey Dobriyan | 0804970 | 2009-12-15 16:46:50 -0800 | [diff] [blame] | 322 | new_de = ufs_find_entry(new_dir, &new_dentry->d_name, &new_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | if (!new_de) |
| 324 | goto out_dir; |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 325 | inode_inc_link_count(old_inode); |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 326 | ufs_set_link(new_dir, new_de, new_page, old_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | new_inode->i_ctime = CURRENT_TIME_SEC; |
| 328 | if (dir_de) |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 329 | drop_nlink(new_inode); |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 330 | inode_dec_link_count(new_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } else { |
| 332 | if (dir_de) { |
| 333 | err = -EMLINK; |
| 334 | if (new_dir->i_nlink >= UFS_LINK_MAX) |
| 335 | goto out_dir; |
| 336 | } |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 337 | inode_inc_link_count(old_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | err = ufs_add_link(new_dentry, old_inode); |
| 339 | if (err) { |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 340 | inode_dec_link_count(old_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | goto out_dir; |
| 342 | } |
| 343 | if (dir_de) |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 344 | inode_inc_link_count(new_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 347 | /* |
| 348 | * Like most other Unix systems, set the ctime for inodes on a |
| 349 | * rename. |
| 350 | * inode_dec_link_count() will mark the inode dirty. |
| 351 | */ |
| 352 | old_inode->i_ctime = CURRENT_TIME_SEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 354 | ufs_delete_entry(old_dir, old_de, old_page); |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 355 | inode_dec_link_count(old_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | if (dir_de) { |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 358 | ufs_set_link(old_inode, dir_de, dir_page, new_dir); |
Alexey Dobriyan | 3257545 | 2006-03-23 03:00:53 -0800 | [diff] [blame] | 359 | inode_dec_link_count(old_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | return 0; |
| 362 | |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | out_dir: |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 365 | if (dir_de) { |
| 366 | kunmap(dir_page); |
| 367 | page_cache_release(dir_page); |
| 368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | out_old: |
Evgeniy Dushistov | b71034e | 2006-06-25 05:47:22 -0700 | [diff] [blame] | 370 | kunmap(old_page); |
| 371 | page_cache_release(old_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | return err; |
| 374 | } |
| 375 | |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 376 | const struct inode_operations ufs_dir_inode_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | .create = ufs_create, |
| 378 | .lookup = ufs_lookup, |
| 379 | .link = ufs_link, |
| 380 | .unlink = ufs_unlink, |
| 381 | .symlink = ufs_symlink, |
| 382 | .mkdir = ufs_mkdir, |
| 383 | .rmdir = ufs_rmdir, |
| 384 | .mknod = ufs_mknod, |
| 385 | .rename = ufs_rename, |
| 386 | }; |