Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) International Business Machines Corp., 2000-2004 |
| 3 | * Portions Copyright (C) Christoph Hellwig, 2001-2002 |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 7 | * the Free Software Foundation; either version 2 of the License, or |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * (at your option) any later version. |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 13 | * the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 16 | * along with this program; if not, write to the Free Software |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
| 20 | #include <linux/fs.h> |
Nick Piggin | 2bc334d | 2011-01-07 17:49:25 +1100 | [diff] [blame] | 21 | #include <linux/namei.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/ctype.h> |
| 23 | #include <linux/quotaops.h> |
Christoph Hellwig | d425de7 | 2007-10-21 16:42:09 -0700 | [diff] [blame] | 24 | #include <linux/exportfs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include "jfs_incore.h" |
| 26 | #include "jfs_superblock.h" |
| 27 | #include "jfs_inode.h" |
| 28 | #include "jfs_dinode.h" |
| 29 | #include "jfs_dmap.h" |
| 30 | #include "jfs_unicode.h" |
| 31 | #include "jfs_metapage.h" |
| 32 | #include "jfs_xattr.h" |
| 33 | #include "jfs_acl.h" |
| 34 | #include "jfs_debug.h" |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | /* |
| 37 | * forward references |
| 38 | */ |
Al Viro | ad28b4e | 2009-02-20 06:00:49 +0000 | [diff] [blame] | 39 | const struct dentry_operations jfs_ci_dentry_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | static s64 commitZeroLink(tid_t, struct inode *); |
| 42 | |
| 43 | /* |
Dave Kleikamp | 4f4b401 | 2005-09-01 09:02:43 -0500 | [diff] [blame] | 44 | * NAME: free_ea_wmap(inode) |
| 45 | * |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 46 | * FUNCTION: free uncommitted extended attributes from working map |
Dave Kleikamp | 4f4b401 | 2005-09-01 09:02:43 -0500 | [diff] [blame] | 47 | * |
| 48 | */ |
| 49 | static inline void free_ea_wmap(struct inode *inode) |
| 50 | { |
| 51 | dxd_t *ea = &JFS_IP(inode)->ea; |
| 52 | |
| 53 | if (ea->flag & DXD_EXTENT) { |
| 54 | /* free EA pages from cache */ |
| 55 | invalidate_dxd_metapages(inode, *ea); |
| 56 | dbFree(inode, addressDXD(ea), lengthDXD(ea)); |
| 57 | } |
| 58 | ea->flag = 0; |
| 59 | } |
| 60 | |
| 61 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * NAME: jfs_create(dip, dentry, mode) |
| 63 | * |
| 64 | * FUNCTION: create a regular file in the parent directory <dip> |
| 65 | * with name = <from dentry> and mode = <mode> |
| 66 | * |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 67 | * PARAMETER: dip - parent directory vnode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | * dentry - dentry of new file |
| 69 | * mode - create mode (rwxrwxrwx). |
| 70 | * nd- nd struct |
| 71 | * |
| 72 | * RETURN: Errors from subroutines |
| 73 | * |
| 74 | */ |
| 75 | static int jfs_create(struct inode *dip, struct dentry *dentry, int mode, |
| 76 | struct nameidata *nd) |
| 77 | { |
| 78 | int rc = 0; |
| 79 | tid_t tid; /* transaction id */ |
| 80 | struct inode *ip = NULL; /* child directory inode */ |
| 81 | ino_t ino; |
| 82 | struct component_name dname; /* child directory name */ |
| 83 | struct btstack btstack; |
| 84 | struct inode *iplist[2]; |
| 85 | struct tblock *tblk; |
| 86 | |
| 87 | jfs_info("jfs_create: dip:0x%p name:%s", dip, dentry->d_name.name); |
| 88 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 89 | dquot_initialize(dip); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* |
| 92 | * search parent directory for entry/freespace |
| 93 | * (dtSearch() returns parent directory page pinned) |
| 94 | */ |
| 95 | if ((rc = get_UCSname(&dname, dentry))) |
| 96 | goto out1; |
| 97 | |
| 98 | /* |
| 99 | * Either iAlloc() or txBegin() may block. Deadlock can occur if we |
| 100 | * block there while holding dtree page, so we allocate the inode & |
| 101 | * begin the transaction before we search the directory. |
| 102 | */ |
| 103 | ip = ialloc(dip, mode); |
Akinobu Mita | 087387f | 2006-09-14 09:22:38 -0500 | [diff] [blame] | 104 | if (IS_ERR(ip)) { |
| 105 | rc = PTR_ERR(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | goto out2; |
| 107 | } |
| 108 | |
| 109 | tid = txBegin(dip->i_sb, 0); |
| 110 | |
Dave Kleikamp | 82d5b9a | 2007-01-09 14:14:48 -0600 | [diff] [blame] | 111 | mutex_lock_nested(&JFS_IP(dip)->commit_mutex, COMMIT_MUTEX_PARENT); |
| 112 | mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Dave Kleikamp | 4f4b401 | 2005-09-01 09:02:43 -0500 | [diff] [blame] | 114 | rc = jfs_init_acl(tid, ip, dip); |
| 115 | if (rc) |
| 116 | goto out3; |
| 117 | |
Dave Kleikamp | 1d15b10f | 2005-09-01 09:05:39 -0500 | [diff] [blame] | 118 | rc = jfs_init_security(tid, ip, dip); |
| 119 | if (rc) { |
| 120 | txAbort(tid, 0); |
| 121 | goto out3; |
| 122 | } |
| 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) { |
| 125 | jfs_err("jfs_create: dtSearch returned %d", rc); |
Dave Kleikamp | 4f4b401 | 2005-09-01 09:02:43 -0500 | [diff] [blame] | 126 | txAbort(tid, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | goto out3; |
| 128 | } |
| 129 | |
| 130 | tblk = tid_to_tblock(tid); |
| 131 | tblk->xflag |= COMMIT_CREATE; |
| 132 | tblk->ino = ip->i_ino; |
| 133 | tblk->u.ixpxd = JFS_IP(ip)->ixpxd; |
| 134 | |
| 135 | iplist[0] = dip; |
| 136 | iplist[1] = ip; |
| 137 | |
| 138 | /* |
| 139 | * initialize the child XAD tree root in-line in inode |
| 140 | */ |
| 141 | xtInitRoot(tid, ip); |
| 142 | |
| 143 | /* |
| 144 | * create entry in parent directory for child directory |
| 145 | * (dtInsert() releases parent directory page) |
| 146 | */ |
| 147 | ino = ip->i_ino; |
| 148 | if ((rc = dtInsert(tid, dip, &dname, &ino, &btstack))) { |
| 149 | if (rc == -EIO) { |
| 150 | jfs_err("jfs_create: dtInsert returned -EIO"); |
| 151 | txAbort(tid, 1); /* Marks Filesystem dirty */ |
| 152 | } else |
| 153 | txAbort(tid, 0); /* Filesystem full */ |
| 154 | goto out3; |
| 155 | } |
| 156 | |
| 157 | ip->i_op = &jfs_file_inode_operations; |
| 158 | ip->i_fop = &jfs_file_operations; |
| 159 | ip->i_mapping->a_ops = &jfs_aops; |
| 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | mark_inode_dirty(ip); |
| 162 | |
| 163 | dip->i_ctime = dip->i_mtime = CURRENT_TIME; |
| 164 | |
| 165 | mark_inode_dirty(dip); |
| 166 | |
| 167 | rc = txCommit(tid, 2, &iplist[0], 0); |
| 168 | |
| 169 | out3: |
| 170 | txEnd(tid); |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 171 | mutex_unlock(&JFS_IP(ip)->commit_mutex); |
Evgeniy Dushistov | 48ce8b0 | 2006-06-05 08:21:03 -0500 | [diff] [blame] | 172 | mutex_unlock(&JFS_IP(dip)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | if (rc) { |
Dave Kleikamp | 4f4b401 | 2005-09-01 09:02:43 -0500 | [diff] [blame] | 174 | free_ea_wmap(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | ip->i_nlink = 0; |
Dave Kleikamp | 1f3403f | 2008-12-30 22:08:37 -0600 | [diff] [blame] | 176 | unlock_new_inode(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | iput(ip); |
Dave Kleikamp | 1f3403f | 2008-12-30 22:08:37 -0600 | [diff] [blame] | 178 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | d_instantiate(dentry, ip); |
Dave Kleikamp | 1f3403f | 2008-12-30 22:08:37 -0600 | [diff] [blame] | 180 | unlock_new_inode(ip); |
| 181 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
| 183 | out2: |
| 184 | free_UCSname(&dname); |
| 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | out1: |
| 187 | |
| 188 | jfs_info("jfs_create: rc:%d", rc); |
| 189 | return rc; |
| 190 | } |
| 191 | |
| 192 | |
| 193 | /* |
| 194 | * NAME: jfs_mkdir(dip, dentry, mode) |
| 195 | * |
| 196 | * FUNCTION: create a child directory in the parent directory <dip> |
| 197 | * with name = <from dentry> and mode = <mode> |
| 198 | * |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 199 | * PARAMETER: dip - parent directory vnode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | * dentry - dentry of child directory |
| 201 | * mode - create mode (rwxrwxrwx). |
| 202 | * |
| 203 | * RETURN: Errors from subroutines |
| 204 | * |
| 205 | * note: |
| 206 | * EACCESS: user needs search+write permission on the parent directory |
| 207 | */ |
| 208 | static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode) |
| 209 | { |
| 210 | int rc = 0; |
| 211 | tid_t tid; /* transaction id */ |
| 212 | struct inode *ip = NULL; /* child directory inode */ |
| 213 | ino_t ino; |
| 214 | struct component_name dname; /* child directory name */ |
| 215 | struct btstack btstack; |
| 216 | struct inode *iplist[2]; |
| 217 | struct tblock *tblk; |
| 218 | |
| 219 | jfs_info("jfs_mkdir: dip:0x%p name:%s", dip, dentry->d_name.name); |
| 220 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 221 | dquot_initialize(dip); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | /* link count overflow on parent directory ? */ |
| 224 | if (dip->i_nlink == JFS_LINK_MAX) { |
| 225 | rc = -EMLINK; |
| 226 | goto out1; |
| 227 | } |
| 228 | |
| 229 | /* |
| 230 | * search parent directory for entry/freespace |
| 231 | * (dtSearch() returns parent directory page pinned) |
| 232 | */ |
| 233 | if ((rc = get_UCSname(&dname, dentry))) |
| 234 | goto out1; |
| 235 | |
| 236 | /* |
| 237 | * Either iAlloc() or txBegin() may block. Deadlock can occur if we |
| 238 | * block there while holding dtree page, so we allocate the inode & |
| 239 | * begin the transaction before we search the directory. |
| 240 | */ |
| 241 | ip = ialloc(dip, S_IFDIR | mode); |
Akinobu Mita | 087387f | 2006-09-14 09:22:38 -0500 | [diff] [blame] | 242 | if (IS_ERR(ip)) { |
| 243 | rc = PTR_ERR(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | goto out2; |
| 245 | } |
| 246 | |
| 247 | tid = txBegin(dip->i_sb, 0); |
| 248 | |
Dave Kleikamp | 82d5b9a | 2007-01-09 14:14:48 -0600 | [diff] [blame] | 249 | mutex_lock_nested(&JFS_IP(dip)->commit_mutex, COMMIT_MUTEX_PARENT); |
| 250 | mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Dave Kleikamp | 4f4b401 | 2005-09-01 09:02:43 -0500 | [diff] [blame] | 252 | rc = jfs_init_acl(tid, ip, dip); |
| 253 | if (rc) |
| 254 | goto out3; |
| 255 | |
Dave Kleikamp | 1d15b10f | 2005-09-01 09:05:39 -0500 | [diff] [blame] | 256 | rc = jfs_init_security(tid, ip, dip); |
| 257 | if (rc) { |
| 258 | txAbort(tid, 0); |
| 259 | goto out3; |
| 260 | } |
| 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) { |
| 263 | jfs_err("jfs_mkdir: dtSearch returned %d", rc); |
Dave Kleikamp | 4f4b401 | 2005-09-01 09:02:43 -0500 | [diff] [blame] | 264 | txAbort(tid, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | goto out3; |
| 266 | } |
| 267 | |
| 268 | tblk = tid_to_tblock(tid); |
| 269 | tblk->xflag |= COMMIT_CREATE; |
| 270 | tblk->ino = ip->i_ino; |
| 271 | tblk->u.ixpxd = JFS_IP(ip)->ixpxd; |
| 272 | |
| 273 | iplist[0] = dip; |
| 274 | iplist[1] = ip; |
| 275 | |
| 276 | /* |
| 277 | * initialize the child directory in-line in inode |
| 278 | */ |
| 279 | dtInitRoot(tid, ip, dip->i_ino); |
| 280 | |
| 281 | /* |
| 282 | * create entry in parent directory for child directory |
| 283 | * (dtInsert() releases parent directory page) |
| 284 | */ |
| 285 | ino = ip->i_ino; |
| 286 | if ((rc = dtInsert(tid, dip, &dname, &ino, &btstack))) { |
| 287 | if (rc == -EIO) { |
| 288 | jfs_err("jfs_mkdir: dtInsert returned -EIO"); |
| 289 | txAbort(tid, 1); /* Marks Filesystem dirty */ |
| 290 | } else |
| 291 | txAbort(tid, 0); /* Filesystem full */ |
| 292 | goto out3; |
| 293 | } |
| 294 | |
| 295 | ip->i_nlink = 2; /* for '.' */ |
| 296 | ip->i_op = &jfs_dir_inode_operations; |
| 297 | ip->i_fop = &jfs_dir_operations; |
| 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | mark_inode_dirty(ip); |
| 300 | |
| 301 | /* update parent directory inode */ |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 302 | inc_nlink(dip); /* for '..' from child directory */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | dip->i_ctime = dip->i_mtime = CURRENT_TIME; |
| 304 | mark_inode_dirty(dip); |
| 305 | |
| 306 | rc = txCommit(tid, 2, &iplist[0], 0); |
| 307 | |
| 308 | out3: |
| 309 | txEnd(tid); |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 310 | mutex_unlock(&JFS_IP(ip)->commit_mutex); |
Evgeniy Dushistov | 48ce8b0 | 2006-06-05 08:21:03 -0500 | [diff] [blame] | 311 | mutex_unlock(&JFS_IP(dip)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | if (rc) { |
Dave Kleikamp | 4f4b401 | 2005-09-01 09:02:43 -0500 | [diff] [blame] | 313 | free_ea_wmap(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | ip->i_nlink = 0; |
Dave Kleikamp | 1f3403f | 2008-12-30 22:08:37 -0600 | [diff] [blame] | 315 | unlock_new_inode(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | iput(ip); |
Dave Kleikamp | 1f3403f | 2008-12-30 22:08:37 -0600 | [diff] [blame] | 317 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | d_instantiate(dentry, ip); |
Dave Kleikamp | 1f3403f | 2008-12-30 22:08:37 -0600 | [diff] [blame] | 319 | unlock_new_inode(ip); |
| 320 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
| 322 | out2: |
| 323 | free_UCSname(&dname); |
| 324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | out1: |
| 327 | |
| 328 | jfs_info("jfs_mkdir: rc:%d", rc); |
| 329 | return rc; |
| 330 | } |
| 331 | |
| 332 | /* |
| 333 | * NAME: jfs_rmdir(dip, dentry) |
| 334 | * |
| 335 | * FUNCTION: remove a link to child directory |
| 336 | * |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 337 | * PARAMETER: dip - parent inode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | * dentry - child directory dentry |
| 339 | * |
| 340 | * RETURN: -EINVAL - if name is . or .. |
Dave Kleikamp | f720e3b | 2007-06-06 15:28:35 -0500 | [diff] [blame] | 341 | * -EINVAL - if . or .. exist but are invalid. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | * errors from subroutines |
| 343 | * |
| 344 | * note: |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 345 | * if other threads have the directory open when the last link |
| 346 | * is removed, the "." and ".." entries, if present, are removed before |
| 347 | * rmdir() returns and no new entries may be created in the directory, |
| 348 | * but the directory is not removed until the last reference to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | * the directory is released (cf.unlink() of regular file). |
| 350 | */ |
| 351 | static int jfs_rmdir(struct inode *dip, struct dentry *dentry) |
| 352 | { |
| 353 | int rc; |
| 354 | tid_t tid; /* transaction id */ |
| 355 | struct inode *ip = dentry->d_inode; |
| 356 | ino_t ino; |
| 357 | struct component_name dname; |
| 358 | struct inode *iplist[2]; |
| 359 | struct tblock *tblk; |
| 360 | |
| 361 | jfs_info("jfs_rmdir: dip:0x%p name:%s", dip, dentry->d_name.name); |
| 362 | |
| 363 | /* Init inode for quota operations. */ |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 364 | dquot_initialize(dip); |
| 365 | dquot_initialize(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | /* directory must be empty to be removed */ |
| 368 | if (!dtEmpty(ip)) { |
| 369 | rc = -ENOTEMPTY; |
| 370 | goto out; |
| 371 | } |
| 372 | |
| 373 | if ((rc = get_UCSname(&dname, dentry))) { |
| 374 | goto out; |
| 375 | } |
| 376 | |
| 377 | tid = txBegin(dip->i_sb, 0); |
| 378 | |
Dave Kleikamp | 82d5b9a | 2007-01-09 14:14:48 -0600 | [diff] [blame] | 379 | mutex_lock_nested(&JFS_IP(dip)->commit_mutex, COMMIT_MUTEX_PARENT); |
| 380 | mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
| 382 | iplist[0] = dip; |
| 383 | iplist[1] = ip; |
| 384 | |
| 385 | tblk = tid_to_tblock(tid); |
| 386 | tblk->xflag |= COMMIT_DELETE; |
| 387 | tblk->u.ip = ip; |
| 388 | |
| 389 | /* |
| 390 | * delete the entry of target directory from parent directory |
| 391 | */ |
| 392 | ino = ip->i_ino; |
| 393 | if ((rc = dtDelete(tid, dip, &dname, &ino, JFS_REMOVE))) { |
| 394 | jfs_err("jfs_rmdir: dtDelete returned %d", rc); |
| 395 | if (rc == -EIO) |
| 396 | txAbort(tid, 1); |
| 397 | txEnd(tid); |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 398 | mutex_unlock(&JFS_IP(ip)->commit_mutex); |
Evgeniy Dushistov | 48ce8b0 | 2006-06-05 08:21:03 -0500 | [diff] [blame] | 399 | mutex_unlock(&JFS_IP(dip)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | goto out2; |
| 402 | } |
| 403 | |
| 404 | /* update parent directory's link count corresponding |
| 405 | * to ".." entry of the target directory deleted |
| 406 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | dip->i_ctime = dip->i_mtime = CURRENT_TIME; |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 408 | inode_dec_link_count(dip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
| 410 | /* |
| 411 | * OS/2 could have created EA and/or ACL |
| 412 | */ |
| 413 | /* free EA from both persistent and working map */ |
| 414 | if (JFS_IP(ip)->ea.flag & DXD_EXTENT) { |
| 415 | /* free EA pages */ |
| 416 | txEA(tid, ip, &JFS_IP(ip)->ea, NULL); |
| 417 | } |
| 418 | JFS_IP(ip)->ea.flag = 0; |
| 419 | |
| 420 | /* free ACL from both persistent and working map */ |
| 421 | if (JFS_IP(ip)->acl.flag & DXD_EXTENT) { |
| 422 | /* free ACL pages */ |
| 423 | txEA(tid, ip, &JFS_IP(ip)->acl, NULL); |
| 424 | } |
| 425 | JFS_IP(ip)->acl.flag = 0; |
| 426 | |
| 427 | /* mark the target directory as deleted */ |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 428 | clear_nlink(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | mark_inode_dirty(ip); |
| 430 | |
| 431 | rc = txCommit(tid, 2, &iplist[0], 0); |
| 432 | |
| 433 | txEnd(tid); |
| 434 | |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 435 | mutex_unlock(&JFS_IP(ip)->commit_mutex); |
Evgeniy Dushistov | 48ce8b0 | 2006-06-05 08:21:03 -0500 | [diff] [blame] | 436 | mutex_unlock(&JFS_IP(dip)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
| 438 | /* |
| 439 | * Truncating the directory index table is not guaranteed. It |
| 440 | * may need to be done iteratively |
| 441 | */ |
| 442 | if (test_cflag(COMMIT_Stale, dip)) { |
| 443 | if (dip->i_size > 1) |
| 444 | jfs_truncate_nolock(dip, 0); |
| 445 | |
| 446 | clear_cflag(COMMIT_Stale, dip); |
| 447 | } |
| 448 | |
| 449 | out2: |
| 450 | free_UCSname(&dname); |
| 451 | |
| 452 | out: |
| 453 | jfs_info("jfs_rmdir: rc:%d", rc); |
| 454 | return rc; |
| 455 | } |
| 456 | |
| 457 | /* |
| 458 | * NAME: jfs_unlink(dip, dentry) |
| 459 | * |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 460 | * FUNCTION: remove a link to object <vp> named by <name> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | * from parent directory <dvp> |
| 462 | * |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 463 | * PARAMETER: dip - inode of parent directory |
| 464 | * dentry - dentry of object to be removed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | * |
| 466 | * RETURN: errors from subroutines |
| 467 | * |
| 468 | * note: |
| 469 | * temporary file: if one or more processes have the file open |
| 470 | * when the last link is removed, the link will be removed before |
| 471 | * unlink() returns, but the removal of the file contents will be |
| 472 | * postponed until all references to the files are closed. |
| 473 | * |
| 474 | * JFS does NOT support unlink() on directories. |
| 475 | * |
| 476 | */ |
| 477 | static int jfs_unlink(struct inode *dip, struct dentry *dentry) |
| 478 | { |
| 479 | int rc; |
| 480 | tid_t tid; /* transaction id */ |
| 481 | struct inode *ip = dentry->d_inode; |
| 482 | ino_t ino; |
| 483 | struct component_name dname; /* object name */ |
| 484 | struct inode *iplist[2]; |
| 485 | struct tblock *tblk; |
| 486 | s64 new_size = 0; |
| 487 | int commit_flag; |
| 488 | |
| 489 | jfs_info("jfs_unlink: dip:0x%p name:%s", dip, dentry->d_name.name); |
| 490 | |
| 491 | /* Init inode for quota operations. */ |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 492 | dquot_initialize(dip); |
| 493 | dquot_initialize(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | if ((rc = get_UCSname(&dname, dentry))) |
| 496 | goto out; |
| 497 | |
Dave Kleikamp | 82d5b9a | 2007-01-09 14:14:48 -0600 | [diff] [blame] | 498 | IWRITE_LOCK(ip, RDWRLOCK_NORMAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
| 500 | tid = txBegin(dip->i_sb, 0); |
| 501 | |
Dave Kleikamp | 82d5b9a | 2007-01-09 14:14:48 -0600 | [diff] [blame] | 502 | mutex_lock_nested(&JFS_IP(dip)->commit_mutex, COMMIT_MUTEX_PARENT); |
| 503 | mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
| 505 | iplist[0] = dip; |
| 506 | iplist[1] = ip; |
| 507 | |
| 508 | /* |
| 509 | * delete the entry of target file from parent directory |
| 510 | */ |
| 511 | ino = ip->i_ino; |
| 512 | if ((rc = dtDelete(tid, dip, &dname, &ino, JFS_REMOVE))) { |
| 513 | jfs_err("jfs_unlink: dtDelete returned %d", rc); |
| 514 | if (rc == -EIO) |
| 515 | txAbort(tid, 1); /* Marks FS Dirty */ |
| 516 | txEnd(tid); |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 517 | mutex_unlock(&JFS_IP(ip)->commit_mutex); |
Evgeniy Dushistov | 48ce8b0 | 2006-06-05 08:21:03 -0500 | [diff] [blame] | 518 | mutex_unlock(&JFS_IP(dip)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | IWRITE_UNLOCK(ip); |
| 520 | goto out1; |
| 521 | } |
| 522 | |
| 523 | ASSERT(ip->i_nlink); |
| 524 | |
| 525 | ip->i_ctime = dip->i_ctime = dip->i_mtime = CURRENT_TIME; |
| 526 | mark_inode_dirty(dip); |
| 527 | |
| 528 | /* update target's inode */ |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 529 | inode_dec_link_count(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
| 531 | /* |
Dave Kleikamp | f720e3b | 2007-06-06 15:28:35 -0500 | [diff] [blame] | 532 | * commit zero link count object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | */ |
| 534 | if (ip->i_nlink == 0) { |
| 535 | assert(!test_cflag(COMMIT_Nolink, ip)); |
| 536 | /* free block resources */ |
| 537 | if ((new_size = commitZeroLink(tid, ip)) < 0) { |
| 538 | txAbort(tid, 1); /* Marks FS Dirty */ |
| 539 | txEnd(tid); |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 540 | mutex_unlock(&JFS_IP(ip)->commit_mutex); |
Evgeniy Dushistov | 48ce8b0 | 2006-06-05 08:21:03 -0500 | [diff] [blame] | 541 | mutex_unlock(&JFS_IP(dip)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | IWRITE_UNLOCK(ip); |
| 543 | rc = new_size; |
| 544 | goto out1; |
| 545 | } |
| 546 | tblk = tid_to_tblock(tid); |
| 547 | tblk->xflag |= COMMIT_DELETE; |
| 548 | tblk->u.ip = ip; |
| 549 | } |
| 550 | |
| 551 | /* |
| 552 | * Incomplete truncate of file data can |
| 553 | * result in timing problems unless we synchronously commit the |
| 554 | * transaction. |
| 555 | */ |
| 556 | if (new_size) |
| 557 | commit_flag = COMMIT_SYNC; |
| 558 | else |
| 559 | commit_flag = 0; |
| 560 | |
| 561 | /* |
| 562 | * If xtTruncate was incomplete, commit synchronously to avoid |
| 563 | * timing complications |
| 564 | */ |
| 565 | rc = txCommit(tid, 2, &iplist[0], commit_flag); |
| 566 | |
| 567 | txEnd(tid); |
| 568 | |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 569 | mutex_unlock(&JFS_IP(ip)->commit_mutex); |
Evgeniy Dushistov | 48ce8b0 | 2006-06-05 08:21:03 -0500 | [diff] [blame] | 570 | mutex_unlock(&JFS_IP(dip)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
| 572 | while (new_size && (rc == 0)) { |
| 573 | tid = txBegin(dip->i_sb, 0); |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 574 | mutex_lock(&JFS_IP(ip)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | new_size = xtTruncate_pmap(tid, ip, new_size); |
| 576 | if (new_size < 0) { |
| 577 | txAbort(tid, 1); /* Marks FS Dirty */ |
| 578 | rc = new_size; |
| 579 | } else |
| 580 | rc = txCommit(tid, 2, &iplist[0], COMMIT_SYNC); |
| 581 | txEnd(tid); |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 582 | mutex_unlock(&JFS_IP(ip)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | if (ip->i_nlink == 0) |
| 586 | set_cflag(COMMIT_Nolink, ip); |
| 587 | |
| 588 | IWRITE_UNLOCK(ip); |
| 589 | |
| 590 | /* |
| 591 | * Truncating the directory index table is not guaranteed. It |
| 592 | * may need to be done iteratively |
| 593 | */ |
| 594 | if (test_cflag(COMMIT_Stale, dip)) { |
| 595 | if (dip->i_size > 1) |
| 596 | jfs_truncate_nolock(dip, 0); |
| 597 | |
| 598 | clear_cflag(COMMIT_Stale, dip); |
| 599 | } |
| 600 | |
| 601 | out1: |
| 602 | free_UCSname(&dname); |
| 603 | out: |
| 604 | jfs_info("jfs_unlink: rc:%d", rc); |
| 605 | return rc; |
| 606 | } |
| 607 | |
| 608 | /* |
| 609 | * NAME: commitZeroLink() |
| 610 | * |
Dave Kleikamp | f720e3b | 2007-06-06 15:28:35 -0500 | [diff] [blame] | 611 | * FUNCTION: for non-directory, called by jfs_remove(), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | * truncate a regular file, directory or symbolic |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 613 | * link to zero length. return 0 if type is not |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | * one of these. |
| 615 | * |
| 616 | * if the file is currently associated with a VM segment |
| 617 | * only permanent disk and inode map resources are freed, |
| 618 | * and neither the inode nor indirect blocks are modified |
| 619 | * so that the resources can be later freed in the work |
| 620 | * map by ctrunc1. |
| 621 | * if there is no VM segment on entry, the resources are |
| 622 | * freed in both work and permanent map. |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 623 | * (? for temporary file - memory object is cached even |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | * after no reference: |
| 625 | * reference count > 0 - ) |
| 626 | * |
| 627 | * PARAMETERS: cd - pointer to commit data structure. |
| 628 | * current inode is the one to truncate. |
| 629 | * |
| 630 | * RETURN: Errors from subroutines |
| 631 | */ |
| 632 | static s64 commitZeroLink(tid_t tid, struct inode *ip) |
| 633 | { |
| 634 | int filetype; |
| 635 | struct tblock *tblk; |
| 636 | |
| 637 | jfs_info("commitZeroLink: tid = %d, ip = 0x%p", tid, ip); |
| 638 | |
| 639 | filetype = ip->i_mode & S_IFMT; |
| 640 | switch (filetype) { |
| 641 | case S_IFREG: |
| 642 | break; |
| 643 | case S_IFLNK: |
| 644 | /* fast symbolic link */ |
| 645 | if (ip->i_size < IDATASIZE) { |
| 646 | ip->i_size = 0; |
| 647 | return 0; |
| 648 | } |
| 649 | break; |
| 650 | default: |
| 651 | assert(filetype != S_IFDIR); |
| 652 | return 0; |
| 653 | } |
| 654 | |
| 655 | set_cflag(COMMIT_Freewmap, ip); |
| 656 | |
| 657 | /* mark transaction of block map update type */ |
| 658 | tblk = tid_to_tblock(tid); |
| 659 | tblk->xflag |= COMMIT_PMAP; |
| 660 | |
| 661 | /* |
| 662 | * free EA |
| 663 | */ |
| 664 | if (JFS_IP(ip)->ea.flag & DXD_EXTENT) |
| 665 | /* acquire maplock on EA to be freed from block map */ |
| 666 | txEA(tid, ip, &JFS_IP(ip)->ea, NULL); |
| 667 | |
| 668 | /* |
| 669 | * free ACL |
| 670 | */ |
| 671 | if (JFS_IP(ip)->acl.flag & DXD_EXTENT) |
| 672 | /* acquire maplock on EA to be freed from block map */ |
| 673 | txEA(tid, ip, &JFS_IP(ip)->acl, NULL); |
| 674 | |
| 675 | /* |
| 676 | * free xtree/data (truncate to zero length): |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 677 | * free xtree/data pages from cache if COMMIT_PWMAP, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | * free xtree/data blocks from persistent block map, and |
| 679 | * free xtree/data blocks from working block map if COMMIT_PWMAP; |
| 680 | */ |
| 681 | if (ip->i_size) |
| 682 | return xtTruncate_pmap(tid, ip, 0); |
| 683 | |
| 684 | return 0; |
| 685 | } |
| 686 | |
| 687 | |
| 688 | /* |
Dave Kleikamp | 1868f4a | 2005-05-04 15:29:35 -0500 | [diff] [blame] | 689 | * NAME: jfs_free_zero_link() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | * |
Dave Kleikamp | f720e3b | 2007-06-06 15:28:35 -0500 | [diff] [blame] | 691 | * FUNCTION: for non-directory, called by iClose(), |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 692 | * free resources of a file from cache and WORKING map |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | * for a file previously committed with zero link count |
| 694 | * while associated with a pager object, |
| 695 | * |
| 696 | * PARAMETER: ip - pointer to inode of file. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | */ |
Dave Kleikamp | 1868f4a | 2005-05-04 15:29:35 -0500 | [diff] [blame] | 698 | void jfs_free_zero_link(struct inode *ip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | int type; |
| 701 | |
Dave Kleikamp | 1868f4a | 2005-05-04 15:29:35 -0500 | [diff] [blame] | 702 | jfs_info("jfs_free_zero_link: ip = 0x%p", ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
| 704 | /* return if not reg or symbolic link or if size is |
| 705 | * already ok. |
| 706 | */ |
| 707 | type = ip->i_mode & S_IFMT; |
| 708 | |
| 709 | switch (type) { |
| 710 | case S_IFREG: |
| 711 | break; |
| 712 | case S_IFLNK: |
| 713 | /* if its contained in inode nothing to do */ |
| 714 | if (ip->i_size < IDATASIZE) |
Dave Kleikamp | 1868f4a | 2005-05-04 15:29:35 -0500 | [diff] [blame] | 715 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | break; |
| 717 | default: |
Dave Kleikamp | 1868f4a | 2005-05-04 15:29:35 -0500 | [diff] [blame] | 718 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | /* |
| 722 | * free EA |
| 723 | */ |
| 724 | if (JFS_IP(ip)->ea.flag & DXD_EXTENT) { |
| 725 | s64 xaddr = addressDXD(&JFS_IP(ip)->ea); |
| 726 | int xlen = lengthDXD(&JFS_IP(ip)->ea); |
| 727 | struct maplock maplock; /* maplock for COMMIT_WMAP */ |
| 728 | struct pxd_lock *pxdlock; /* maplock for COMMIT_WMAP */ |
| 729 | |
| 730 | /* free EA pages from cache */ |
| 731 | invalidate_dxd_metapages(ip, JFS_IP(ip)->ea); |
| 732 | |
| 733 | /* free EA extent from working block map */ |
| 734 | maplock.index = 1; |
| 735 | pxdlock = (struct pxd_lock *) & maplock; |
| 736 | pxdlock->flag = mlckFREEPXD; |
| 737 | PXDaddress(&pxdlock->pxd, xaddr); |
| 738 | PXDlength(&pxdlock->pxd, xlen); |
| 739 | txFreeMap(ip, pxdlock, NULL, COMMIT_WMAP); |
| 740 | } |
| 741 | |
| 742 | /* |
| 743 | * free ACL |
| 744 | */ |
| 745 | if (JFS_IP(ip)->acl.flag & DXD_EXTENT) { |
| 746 | s64 xaddr = addressDXD(&JFS_IP(ip)->acl); |
| 747 | int xlen = lengthDXD(&JFS_IP(ip)->acl); |
| 748 | struct maplock maplock; /* maplock for COMMIT_WMAP */ |
| 749 | struct pxd_lock *pxdlock; /* maplock for COMMIT_WMAP */ |
| 750 | |
| 751 | invalidate_dxd_metapages(ip, JFS_IP(ip)->acl); |
| 752 | |
| 753 | /* free ACL extent from working block map */ |
| 754 | maplock.index = 1; |
| 755 | pxdlock = (struct pxd_lock *) & maplock; |
| 756 | pxdlock->flag = mlckFREEPXD; |
| 757 | PXDaddress(&pxdlock->pxd, xaddr); |
| 758 | PXDlength(&pxdlock->pxd, xlen); |
| 759 | txFreeMap(ip, pxdlock, NULL, COMMIT_WMAP); |
| 760 | } |
| 761 | |
| 762 | /* |
| 763 | * free xtree/data (truncate to zero length): |
| 764 | * free xtree/data pages from cache, and |
| 765 | * free xtree/data blocks from working block map; |
| 766 | */ |
| 767 | if (ip->i_size) |
Dave Kleikamp | 1868f4a | 2005-05-04 15:29:35 -0500 | [diff] [blame] | 768 | xtTruncate(0, ip, 0, COMMIT_WMAP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | /* |
| 772 | * NAME: jfs_link(vp, dvp, name, crp) |
| 773 | * |
| 774 | * FUNCTION: create a link to <vp> by the name = <name> |
| 775 | * in the parent directory <dvp> |
| 776 | * |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 777 | * PARAMETER: vp - target object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | * dvp - parent directory of new link |
| 779 | * name - name of new link to target object |
| 780 | * crp - credential |
| 781 | * |
| 782 | * RETURN: Errors from subroutines |
| 783 | * |
| 784 | * note: |
| 785 | * JFS does NOT support link() on directories (to prevent circular |
| 786 | * path in the directory hierarchy); |
| 787 | * EPERM: the target object is a directory, and either the caller |
| 788 | * does not have appropriate privileges or the implementation prohibits |
| 789 | * using link() on directories [XPG4.2]. |
| 790 | * |
| 791 | * JFS does NOT support links between file systems: |
| 792 | * EXDEV: target object and new link are on different file systems and |
| 793 | * implementation does not support links between file systems [XPG4.2]. |
| 794 | */ |
| 795 | static int jfs_link(struct dentry *old_dentry, |
| 796 | struct inode *dir, struct dentry *dentry) |
| 797 | { |
| 798 | int rc; |
| 799 | tid_t tid; |
| 800 | struct inode *ip = old_dentry->d_inode; |
| 801 | ino_t ino; |
| 802 | struct component_name dname; |
| 803 | struct btstack btstack; |
| 804 | struct inode *iplist[2]; |
| 805 | |
| 806 | jfs_info("jfs_link: %s %s", old_dentry->d_name.name, |
| 807 | dentry->d_name.name); |
| 808 | |
| 809 | if (ip->i_nlink == JFS_LINK_MAX) |
| 810 | return -EMLINK; |
| 811 | |
| 812 | if (ip->i_nlink == 0) |
| 813 | return -ENOENT; |
| 814 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 815 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | tid = txBegin(ip->i_sb, 0); |
| 818 | |
Dave Kleikamp | 82d5b9a | 2007-01-09 14:14:48 -0600 | [diff] [blame] | 819 | mutex_lock_nested(&JFS_IP(dir)->commit_mutex, COMMIT_MUTEX_PARENT); |
| 820 | mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | |
| 822 | /* |
| 823 | * scan parent directory for entry/freespace |
| 824 | */ |
| 825 | if ((rc = get_UCSname(&dname, dentry))) |
| 826 | goto out; |
| 827 | |
| 828 | if ((rc = dtSearch(dir, &dname, &ino, &btstack, JFS_CREATE))) |
| 829 | goto free_dname; |
| 830 | |
| 831 | /* |
| 832 | * create entry for new link in parent directory |
| 833 | */ |
| 834 | ino = ip->i_ino; |
| 835 | if ((rc = dtInsert(tid, dir, &dname, &ino, &btstack))) |
| 836 | goto free_dname; |
| 837 | |
| 838 | /* update object inode */ |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 839 | inc_nlink(ip); /* for new link */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | ip->i_ctime = CURRENT_TIME; |
Dave Kleikamp | 988a649 | 2005-10-31 16:53:04 -0600 | [diff] [blame] | 841 | dir->i_ctime = dir->i_mtime = CURRENT_TIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | mark_inode_dirty(dir); |
Al Viro | 7de9c6ee | 2010-10-23 11:11:40 -0400 | [diff] [blame] | 843 | ihold(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
| 845 | iplist[0] = ip; |
| 846 | iplist[1] = dir; |
| 847 | rc = txCommit(tid, 2, &iplist[0], 0); |
| 848 | |
| 849 | if (rc) { |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 850 | ip->i_nlink--; /* never instantiated */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | iput(ip); |
| 852 | } else |
| 853 | d_instantiate(dentry, ip); |
| 854 | |
| 855 | free_dname: |
| 856 | free_UCSname(&dname); |
| 857 | |
| 858 | out: |
| 859 | txEnd(tid); |
| 860 | |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 861 | mutex_unlock(&JFS_IP(ip)->commit_mutex); |
Evgeniy Dushistov | 48ce8b0 | 2006-06-05 08:21:03 -0500 | [diff] [blame] | 862 | mutex_unlock(&JFS_IP(dir)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
| 864 | jfs_info("jfs_link: rc:%d", rc); |
| 865 | return rc; |
| 866 | } |
| 867 | |
| 868 | /* |
| 869 | * NAME: jfs_symlink(dip, dentry, name) |
| 870 | * |
| 871 | * FUNCTION: creates a symbolic link to <symlink> by name <name> |
Dave Kleikamp | f720e3b | 2007-06-06 15:28:35 -0500 | [diff] [blame] | 872 | * in directory <dip> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | * |
Dave Kleikamp | f720e3b | 2007-06-06 15:28:35 -0500 | [diff] [blame] | 874 | * PARAMETER: dip - parent directory vnode |
| 875 | * dentry - dentry of symbolic link |
| 876 | * name - the path name of the existing object |
| 877 | * that will be the source of the link |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | * |
| 879 | * RETURN: errors from subroutines |
| 880 | * |
| 881 | * note: |
| 882 | * ENAMETOOLONG: pathname resolution of a symbolic link produced |
| 883 | * an intermediate result whose length exceeds PATH_MAX [XPG4.2] |
| 884 | */ |
| 885 | |
| 886 | static int jfs_symlink(struct inode *dip, struct dentry *dentry, |
| 887 | const char *name) |
| 888 | { |
| 889 | int rc; |
| 890 | tid_t tid; |
| 891 | ino_t ino = 0; |
| 892 | struct component_name dname; |
| 893 | int ssize; /* source pathname size */ |
| 894 | struct btstack btstack; |
| 895 | struct inode *ip = dentry->d_inode; |
| 896 | unchar *i_fastsymlink; |
| 897 | s64 xlen = 0; |
| 898 | int bmask = 0, xsize; |
| 899 | s64 extent = 0, xaddr; |
| 900 | struct metapage *mp; |
| 901 | struct super_block *sb; |
| 902 | struct tblock *tblk; |
| 903 | |
| 904 | struct inode *iplist[2]; |
| 905 | |
| 906 | jfs_info("jfs_symlink: dip:0x%p name:%s", dip, name); |
| 907 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 908 | dquot_initialize(dip); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 909 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | ssize = strlen(name) + 1; |
| 911 | |
| 912 | /* |
| 913 | * search parent directory for entry/freespace |
| 914 | * (dtSearch() returns parent directory page pinned) |
| 915 | */ |
| 916 | |
| 917 | if ((rc = get_UCSname(&dname, dentry))) |
| 918 | goto out1; |
| 919 | |
| 920 | /* |
| 921 | * allocate on-disk/in-memory inode for symbolic link: |
| 922 | * (iAlloc() returns new, locked inode) |
| 923 | */ |
| 924 | ip = ialloc(dip, S_IFLNK | 0777); |
Akinobu Mita | 087387f | 2006-09-14 09:22:38 -0500 | [diff] [blame] | 925 | if (IS_ERR(ip)) { |
| 926 | rc = PTR_ERR(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | goto out2; |
| 928 | } |
| 929 | |
| 930 | tid = txBegin(dip->i_sb, 0); |
| 931 | |
Dave Kleikamp | 82d5b9a | 2007-01-09 14:14:48 -0600 | [diff] [blame] | 932 | mutex_lock_nested(&JFS_IP(dip)->commit_mutex, COMMIT_MUTEX_PARENT); |
| 933 | mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | |
Dave Kleikamp | 1d15b10f | 2005-09-01 09:05:39 -0500 | [diff] [blame] | 935 | rc = jfs_init_security(tid, ip, dip); |
| 936 | if (rc) |
| 937 | goto out3; |
| 938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | tblk = tid_to_tblock(tid); |
| 940 | tblk->xflag |= COMMIT_CREATE; |
| 941 | tblk->ino = ip->i_ino; |
| 942 | tblk->u.ixpxd = JFS_IP(ip)->ixpxd; |
| 943 | |
| 944 | /* fix symlink access permission |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 945 | * (dir_create() ANDs in the u.u_cmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | * but symlinks really need to be 777 access) |
| 947 | */ |
| 948 | ip->i_mode |= 0777; |
| 949 | |
| 950 | /* |
| 951 | * write symbolic link target path name |
| 952 | */ |
| 953 | xtInitRoot(tid, ip); |
| 954 | |
| 955 | /* |
| 956 | * write source path name inline in on-disk inode (fast symbolic link) |
| 957 | */ |
| 958 | |
| 959 | if (ssize <= IDATASIZE) { |
Dmitry Monakhov | c7f2e1f | 2010-04-16 08:05:50 -0500 | [diff] [blame] | 960 | ip->i_op = &jfs_fast_symlink_inode_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
| 962 | i_fastsymlink = JFS_IP(ip)->i_inline; |
| 963 | memcpy(i_fastsymlink, name, ssize); |
| 964 | ip->i_size = ssize - 1; |
| 965 | |
| 966 | /* |
| 967 | * if symlink is > 128 bytes, we don't have the space to |
| 968 | * store inline extended attributes |
| 969 | */ |
| 970 | if (ssize > sizeof (JFS_IP(ip)->i_inline)) |
| 971 | JFS_IP(ip)->mode2 &= ~INLINEEA; |
| 972 | |
| 973 | jfs_info("jfs_symlink: fast symlink added ssize:%d name:%s ", |
| 974 | ssize, name); |
| 975 | } |
| 976 | /* |
| 977 | * write source path name in a single extent |
| 978 | */ |
| 979 | else { |
| 980 | jfs_info("jfs_symlink: allocate extent ip:0x%p", ip); |
| 981 | |
Dmitry Monakhov | c7f2e1f | 2010-04-16 08:05:50 -0500 | [diff] [blame] | 982 | ip->i_op = &jfs_symlink_inode_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | ip->i_mapping->a_ops = &jfs_aops; |
| 984 | |
| 985 | /* |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 986 | * even though the data of symlink object (source |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | * path name) is treated as non-journaled user data, |
| 988 | * it is read/written thru buffer cache for performance. |
| 989 | */ |
| 990 | sb = ip->i_sb; |
| 991 | bmask = JFS_SBI(sb)->bsize - 1; |
| 992 | xsize = (ssize + bmask) & ~bmask; |
| 993 | xaddr = 0; |
| 994 | xlen = xsize >> JFS_SBI(sb)->l2bsize; |
| 995 | if ((rc = xtInsert(tid, ip, 0, 0, xlen, &xaddr, 0))) { |
| 996 | txAbort(tid, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | goto out3; |
| 998 | } |
| 999 | extent = xaddr; |
| 1000 | ip->i_size = ssize - 1; |
| 1001 | while (ssize) { |
| 1002 | /* This is kind of silly since PATH_MAX == 4K */ |
| 1003 | int copy_size = min(ssize, PSIZE); |
| 1004 | |
| 1005 | mp = get_metapage(ip, xaddr, PSIZE, 1); |
| 1006 | |
| 1007 | if (mp == NULL) { |
| 1008 | xtTruncate(tid, ip, 0, COMMIT_PWMAP); |
| 1009 | rc = -EIO; |
| 1010 | txAbort(tid, 0); |
| 1011 | goto out3; |
| 1012 | } |
| 1013 | memcpy(mp->data, name, copy_size); |
| 1014 | flush_metapage(mp); |
| 1015 | ssize -= copy_size; |
| 1016 | name += copy_size; |
| 1017 | xaddr += JFS_SBI(sb)->nbperpage; |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | /* |
| 1022 | * create entry for symbolic link in parent directory |
| 1023 | */ |
| 1024 | rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE); |
| 1025 | if (rc == 0) { |
| 1026 | ino = ip->i_ino; |
| 1027 | rc = dtInsert(tid, dip, &dname, &ino, &btstack); |
| 1028 | } |
| 1029 | if (rc) { |
| 1030 | if (xlen) |
| 1031 | xtTruncate(tid, ip, 0, COMMIT_PWMAP); |
| 1032 | txAbort(tid, 0); |
| 1033 | /* discard new inode */ |
| 1034 | goto out3; |
| 1035 | } |
| 1036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | mark_inode_dirty(ip); |
| 1038 | |
Dave Kleikamp | 988a649 | 2005-10-31 16:53:04 -0600 | [diff] [blame] | 1039 | dip->i_ctime = dip->i_mtime = CURRENT_TIME; |
| 1040 | mark_inode_dirty(dip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | /* |
| 1042 | * commit update of parent directory and link object |
| 1043 | */ |
| 1044 | |
| 1045 | iplist[0] = dip; |
| 1046 | iplist[1] = ip; |
| 1047 | rc = txCommit(tid, 2, &iplist[0], 0); |
| 1048 | |
| 1049 | out3: |
| 1050 | txEnd(tid); |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 1051 | mutex_unlock(&JFS_IP(ip)->commit_mutex); |
Evgeniy Dushistov | 48ce8b0 | 2006-06-05 08:21:03 -0500 | [diff] [blame] | 1052 | mutex_unlock(&JFS_IP(dip)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | if (rc) { |
Dave Kleikamp | 4f4b401 | 2005-09-01 09:02:43 -0500 | [diff] [blame] | 1054 | free_ea_wmap(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | ip->i_nlink = 0; |
Dave Kleikamp | 1f3403f | 2008-12-30 22:08:37 -0600 | [diff] [blame] | 1056 | unlock_new_inode(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | iput(ip); |
Dave Kleikamp | 1f3403f | 2008-12-30 22:08:37 -0600 | [diff] [blame] | 1058 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | d_instantiate(dentry, ip); |
Dave Kleikamp | 1f3403f | 2008-12-30 22:08:37 -0600 | [diff] [blame] | 1060 | unlock_new_inode(ip); |
| 1061 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | |
| 1063 | out2: |
| 1064 | free_UCSname(&dname); |
| 1065 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | out1: |
| 1067 | jfs_info("jfs_symlink: rc:%d", rc); |
| 1068 | return rc; |
| 1069 | } |
| 1070 | |
| 1071 | |
| 1072 | /* |
Dave Kleikamp | f720e3b | 2007-06-06 15:28:35 -0500 | [diff] [blame] | 1073 | * NAME: jfs_rename |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | * |
Dave Kleikamp | f720e3b | 2007-06-06 15:28:35 -0500 | [diff] [blame] | 1075 | * FUNCTION: rename a file or directory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | */ |
| 1077 | static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 1078 | struct inode *new_dir, struct dentry *new_dentry) |
| 1079 | { |
| 1080 | struct btstack btstack; |
| 1081 | ino_t ino; |
| 1082 | struct component_name new_dname; |
| 1083 | struct inode *new_ip; |
| 1084 | struct component_name old_dname; |
| 1085 | struct inode *old_ip; |
| 1086 | int rc; |
| 1087 | tid_t tid; |
| 1088 | struct tlock *tlck; |
| 1089 | struct dt_lock *dtlck; |
| 1090 | struct lv *lv; |
| 1091 | int ipcount; |
| 1092 | struct inode *iplist[4]; |
| 1093 | struct tblock *tblk; |
| 1094 | s64 new_size = 0; |
| 1095 | int commit_flag; |
| 1096 | |
| 1097 | |
| 1098 | jfs_info("jfs_rename: %s %s", old_dentry->d_name.name, |
| 1099 | new_dentry->d_name.name); |
| 1100 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 1101 | dquot_initialize(old_dir); |
| 1102 | dquot_initialize(new_dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 1103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | old_ip = old_dentry->d_inode; |
| 1105 | new_ip = new_dentry->d_inode; |
| 1106 | |
| 1107 | if ((rc = get_UCSname(&old_dname, old_dentry))) |
| 1108 | goto out1; |
| 1109 | |
| 1110 | if ((rc = get_UCSname(&new_dname, new_dentry))) |
| 1111 | goto out2; |
| 1112 | |
| 1113 | /* |
| 1114 | * Make sure source inode number is what we think it is |
| 1115 | */ |
| 1116 | rc = dtSearch(old_dir, &old_dname, &ino, &btstack, JFS_LOOKUP); |
| 1117 | if (rc || (ino != old_ip->i_ino)) { |
| 1118 | rc = -ENOENT; |
| 1119 | goto out3; |
| 1120 | } |
| 1121 | |
| 1122 | /* |
| 1123 | * Make sure dest inode number (if any) is what we think it is |
| 1124 | */ |
| 1125 | rc = dtSearch(new_dir, &new_dname, &ino, &btstack, JFS_LOOKUP); |
Joe Perches | 09aaa74 | 2007-11-13 22:16:08 -0600 | [diff] [blame] | 1126 | if (!rc) { |
Dave Kleikamp | da8a41d | 2007-11-13 22:25:41 -0600 | [diff] [blame] | 1127 | if ((!new_ip) || (ino != new_ip->i_ino)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | rc = -ESTALE; |
| 1129 | goto out3; |
| 1130 | } |
| 1131 | } else if (rc != -ENOENT) |
| 1132 | goto out3; |
| 1133 | else if (new_ip) { |
| 1134 | /* no entry exists, but one was expected */ |
| 1135 | rc = -ESTALE; |
| 1136 | goto out3; |
| 1137 | } |
| 1138 | |
| 1139 | if (S_ISDIR(old_ip->i_mode)) { |
| 1140 | if (new_ip) { |
| 1141 | if (!dtEmpty(new_ip)) { |
| 1142 | rc = -ENOTEMPTY; |
| 1143 | goto out3; |
| 1144 | } |
| 1145 | } else if ((new_dir != old_dir) && |
| 1146 | (new_dir->i_nlink == JFS_LINK_MAX)) { |
| 1147 | rc = -EMLINK; |
| 1148 | goto out3; |
| 1149 | } |
| 1150 | } else if (new_ip) { |
Dave Kleikamp | 82d5b9a | 2007-01-09 14:14:48 -0600 | [diff] [blame] | 1151 | IWRITE_LOCK(new_ip, RDWRLOCK_NORMAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | /* Init inode for quota operations. */ |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 1153 | dquot_initialize(new_ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | /* |
| 1157 | * The real work starts here |
| 1158 | */ |
| 1159 | tid = txBegin(new_dir->i_sb, 0); |
| 1160 | |
Dave Kleikamp | 82d5b9a | 2007-01-09 14:14:48 -0600 | [diff] [blame] | 1161 | /* |
| 1162 | * How do we know the locking is safe from deadlocks? |
| 1163 | * The vfs does the hard part for us. Any time we are taking nested |
| 1164 | * commit_mutexes, the vfs already has i_mutex held on the parent. |
| 1165 | * Here, the vfs has already taken i_mutex on both old_dir and new_dir. |
| 1166 | */ |
| 1167 | mutex_lock_nested(&JFS_IP(new_dir)->commit_mutex, COMMIT_MUTEX_PARENT); |
| 1168 | mutex_lock_nested(&JFS_IP(old_ip)->commit_mutex, COMMIT_MUTEX_CHILD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | if (old_dir != new_dir) |
Dave Kleikamp | 82d5b9a | 2007-01-09 14:14:48 -0600 | [diff] [blame] | 1170 | mutex_lock_nested(&JFS_IP(old_dir)->commit_mutex, |
| 1171 | COMMIT_MUTEX_SECOND_PARENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | |
| 1173 | if (new_ip) { |
Dave Kleikamp | 82d5b9a | 2007-01-09 14:14:48 -0600 | [diff] [blame] | 1174 | mutex_lock_nested(&JFS_IP(new_ip)->commit_mutex, |
| 1175 | COMMIT_MUTEX_VICTIM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | /* |
| 1177 | * Change existing directory entry to new inode number |
| 1178 | */ |
| 1179 | ino = new_ip->i_ino; |
| 1180 | rc = dtModify(tid, new_dir, &new_dname, &ino, |
| 1181 | old_ip->i_ino, JFS_RENAME); |
| 1182 | if (rc) |
| 1183 | goto out4; |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 1184 | drop_nlink(new_ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | if (S_ISDIR(new_ip->i_mode)) { |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 1186 | drop_nlink(new_ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | if (new_ip->i_nlink) { |
Evgeniy Dushistov | 48ce8b0 | 2006-06-05 08:21:03 -0500 | [diff] [blame] | 1188 | mutex_unlock(&JFS_IP(new_ip)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | if (old_dir != new_dir) |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 1190 | mutex_unlock(&JFS_IP(old_dir)->commit_mutex); |
Evgeniy Dushistov | 48ce8b0 | 2006-06-05 08:21:03 -0500 | [diff] [blame] | 1191 | mutex_unlock(&JFS_IP(old_ip)->commit_mutex); |
| 1192 | mutex_unlock(&JFS_IP(new_dir)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | if (!S_ISDIR(old_ip->i_mode) && new_ip) |
| 1194 | IWRITE_UNLOCK(new_ip); |
| 1195 | jfs_error(new_ip->i_sb, |
| 1196 | "jfs_rename: new_ip->i_nlink != 0"); |
| 1197 | return -EIO; |
| 1198 | } |
| 1199 | tblk = tid_to_tblock(tid); |
| 1200 | tblk->xflag |= COMMIT_DELETE; |
| 1201 | tblk->u.ip = new_ip; |
| 1202 | } else if (new_ip->i_nlink == 0) { |
| 1203 | assert(!test_cflag(COMMIT_Nolink, new_ip)); |
| 1204 | /* free block resources */ |
| 1205 | if ((new_size = commitZeroLink(tid, new_ip)) < 0) { |
| 1206 | txAbort(tid, 1); /* Marks FS Dirty */ |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 1207 | rc = new_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | goto out4; |
| 1209 | } |
| 1210 | tblk = tid_to_tblock(tid); |
| 1211 | tblk->xflag |= COMMIT_DELETE; |
| 1212 | tblk->u.ip = new_ip; |
| 1213 | } else { |
| 1214 | new_ip->i_ctime = CURRENT_TIME; |
| 1215 | mark_inode_dirty(new_ip); |
| 1216 | } |
| 1217 | } else { |
| 1218 | /* |
| 1219 | * Add new directory entry |
| 1220 | */ |
| 1221 | rc = dtSearch(new_dir, &new_dname, &ino, &btstack, |
| 1222 | JFS_CREATE); |
| 1223 | if (rc) { |
| 1224 | jfs_err("jfs_rename didn't expect dtSearch to fail " |
| 1225 | "w/rc = %d", rc); |
| 1226 | goto out4; |
| 1227 | } |
| 1228 | |
| 1229 | ino = old_ip->i_ino; |
| 1230 | rc = dtInsert(tid, new_dir, &new_dname, &ino, &btstack); |
| 1231 | if (rc) { |
| 1232 | if (rc == -EIO) |
| 1233 | jfs_err("jfs_rename: dtInsert returned -EIO"); |
| 1234 | goto out4; |
| 1235 | } |
| 1236 | if (S_ISDIR(old_ip->i_mode)) |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 1237 | inc_nlink(new_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | } |
| 1239 | /* |
| 1240 | * Remove old directory entry |
| 1241 | */ |
| 1242 | |
| 1243 | ino = old_ip->i_ino; |
| 1244 | rc = dtDelete(tid, old_dir, &old_dname, &ino, JFS_REMOVE); |
| 1245 | if (rc) { |
| 1246 | jfs_err("jfs_rename did not expect dtDelete to return rc = %d", |
| 1247 | rc); |
| 1248 | txAbort(tid, 1); /* Marks Filesystem dirty */ |
| 1249 | goto out4; |
| 1250 | } |
| 1251 | if (S_ISDIR(old_ip->i_mode)) { |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 1252 | drop_nlink(old_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | if (old_dir != new_dir) { |
| 1254 | /* |
| 1255 | * Change inode number of parent for moved directory |
| 1256 | */ |
| 1257 | |
| 1258 | JFS_IP(old_ip)->i_dtroot.header.idotdot = |
| 1259 | cpu_to_le32(new_dir->i_ino); |
| 1260 | |
| 1261 | /* Linelock header of dtree */ |
| 1262 | tlck = txLock(tid, old_ip, |
| 1263 | (struct metapage *) &JFS_IP(old_ip)->bxflag, |
| 1264 | tlckDTREE | tlckBTROOT | tlckRELINK); |
| 1265 | dtlck = (struct dt_lock *) & tlck->lock; |
| 1266 | ASSERT(dtlck->index == 0); |
| 1267 | lv = & dtlck->lv[0]; |
| 1268 | lv->offset = 0; |
| 1269 | lv->length = 1; |
| 1270 | dtlck->index++; |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | /* |
| 1275 | * Update ctime on changed/moved inodes & mark dirty |
| 1276 | */ |
| 1277 | old_ip->i_ctime = CURRENT_TIME; |
| 1278 | mark_inode_dirty(old_ip); |
| 1279 | |
| 1280 | new_dir->i_ctime = new_dir->i_mtime = current_fs_time(new_dir->i_sb); |
| 1281 | mark_inode_dirty(new_dir); |
| 1282 | |
| 1283 | /* Build list of inodes modified by this transaction */ |
| 1284 | ipcount = 0; |
| 1285 | iplist[ipcount++] = old_ip; |
| 1286 | if (new_ip) |
| 1287 | iplist[ipcount++] = new_ip; |
| 1288 | iplist[ipcount++] = old_dir; |
| 1289 | |
| 1290 | if (old_dir != new_dir) { |
| 1291 | iplist[ipcount++] = new_dir; |
| 1292 | old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME; |
| 1293 | mark_inode_dirty(old_dir); |
| 1294 | } |
| 1295 | |
| 1296 | /* |
| 1297 | * Incomplete truncate of file data can |
| 1298 | * result in timing problems unless we synchronously commit the |
| 1299 | * transaction. |
| 1300 | */ |
| 1301 | if (new_size) |
| 1302 | commit_flag = COMMIT_SYNC; |
| 1303 | else |
| 1304 | commit_flag = 0; |
| 1305 | |
| 1306 | rc = txCommit(tid, ipcount, iplist, commit_flag); |
| 1307 | |
| 1308 | out4: |
| 1309 | txEnd(tid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | if (new_ip) |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 1311 | mutex_unlock(&JFS_IP(new_ip)->commit_mutex); |
Evgeniy Dushistov | 48ce8b0 | 2006-06-05 08:21:03 -0500 | [diff] [blame] | 1312 | if (old_dir != new_dir) |
| 1313 | mutex_unlock(&JFS_IP(old_dir)->commit_mutex); |
| 1314 | mutex_unlock(&JFS_IP(old_ip)->commit_mutex); |
| 1315 | mutex_unlock(&JFS_IP(new_dir)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | |
| 1317 | while (new_size && (rc == 0)) { |
| 1318 | tid = txBegin(new_ip->i_sb, 0); |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 1319 | mutex_lock(&JFS_IP(new_ip)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | new_size = xtTruncate_pmap(tid, new_ip, new_size); |
| 1321 | if (new_size < 0) { |
| 1322 | txAbort(tid, 1); |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 1323 | rc = new_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | } else |
| 1325 | rc = txCommit(tid, 1, &new_ip, COMMIT_SYNC); |
| 1326 | txEnd(tid); |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 1327 | mutex_unlock(&JFS_IP(new_ip)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | } |
| 1329 | if (new_ip && (new_ip->i_nlink == 0)) |
| 1330 | set_cflag(COMMIT_Nolink, new_ip); |
| 1331 | out3: |
| 1332 | free_UCSname(&new_dname); |
| 1333 | out2: |
| 1334 | free_UCSname(&old_dname); |
| 1335 | out1: |
| 1336 | if (new_ip && !S_ISDIR(new_ip->i_mode)) |
| 1337 | IWRITE_UNLOCK(new_ip); |
| 1338 | /* |
| 1339 | * Truncating the directory index table is not guaranteed. It |
| 1340 | * may need to be done iteratively |
| 1341 | */ |
| 1342 | if (test_cflag(COMMIT_Stale, old_dir)) { |
| 1343 | if (old_dir->i_size > 1) |
| 1344 | jfs_truncate_nolock(old_dir, 0); |
| 1345 | |
| 1346 | clear_cflag(COMMIT_Stale, old_dir); |
| 1347 | } |
| 1348 | |
| 1349 | jfs_info("jfs_rename: returning %d", rc); |
| 1350 | return rc; |
| 1351 | } |
| 1352 | |
| 1353 | |
| 1354 | /* |
Dave Kleikamp | f720e3b | 2007-06-06 15:28:35 -0500 | [diff] [blame] | 1355 | * NAME: jfs_mknod |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | * |
Dave Kleikamp | f720e3b | 2007-06-06 15:28:35 -0500 | [diff] [blame] | 1357 | * FUNCTION: Create a special file (device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | */ |
| 1359 | static int jfs_mknod(struct inode *dir, struct dentry *dentry, |
| 1360 | int mode, dev_t rdev) |
| 1361 | { |
| 1362 | struct jfs_inode_info *jfs_ip; |
| 1363 | struct btstack btstack; |
| 1364 | struct component_name dname; |
| 1365 | ino_t ino; |
| 1366 | struct inode *ip; |
| 1367 | struct inode *iplist[2]; |
| 1368 | int rc; |
| 1369 | tid_t tid; |
| 1370 | struct tblock *tblk; |
| 1371 | |
| 1372 | if (!new_valid_dev(rdev)) |
| 1373 | return -EINVAL; |
| 1374 | |
| 1375 | jfs_info("jfs_mknod: %s", dentry->d_name.name); |
| 1376 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 1377 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 1378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | if ((rc = get_UCSname(&dname, dentry))) |
| 1380 | goto out; |
| 1381 | |
| 1382 | ip = ialloc(dir, mode); |
Akinobu Mita | 087387f | 2006-09-14 09:22:38 -0500 | [diff] [blame] | 1383 | if (IS_ERR(ip)) { |
| 1384 | rc = PTR_ERR(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | goto out1; |
| 1386 | } |
| 1387 | jfs_ip = JFS_IP(ip); |
| 1388 | |
| 1389 | tid = txBegin(dir->i_sb, 0); |
| 1390 | |
Dave Kleikamp | 82d5b9a | 2007-01-09 14:14:48 -0600 | [diff] [blame] | 1391 | mutex_lock_nested(&JFS_IP(dir)->commit_mutex, COMMIT_MUTEX_PARENT); |
| 1392 | mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | |
Dave Kleikamp | 4f4b401 | 2005-09-01 09:02:43 -0500 | [diff] [blame] | 1394 | rc = jfs_init_acl(tid, ip, dir); |
| 1395 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | goto out3; |
| 1397 | |
Dave Kleikamp | 1d15b10f | 2005-09-01 09:05:39 -0500 | [diff] [blame] | 1398 | rc = jfs_init_security(tid, ip, dir); |
| 1399 | if (rc) { |
| 1400 | txAbort(tid, 0); |
| 1401 | goto out3; |
| 1402 | } |
| 1403 | |
Dave Kleikamp | 4f4b401 | 2005-09-01 09:02:43 -0500 | [diff] [blame] | 1404 | if ((rc = dtSearch(dir, &dname, &ino, &btstack, JFS_CREATE))) { |
| 1405 | txAbort(tid, 0); |
| 1406 | goto out3; |
| 1407 | } |
| 1408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | tblk = tid_to_tblock(tid); |
| 1410 | tblk->xflag |= COMMIT_CREATE; |
| 1411 | tblk->ino = ip->i_ino; |
| 1412 | tblk->u.ixpxd = JFS_IP(ip)->ixpxd; |
| 1413 | |
| 1414 | ino = ip->i_ino; |
Dave Kleikamp | 4f4b401 | 2005-09-01 09:02:43 -0500 | [diff] [blame] | 1415 | if ((rc = dtInsert(tid, dir, &dname, &ino, &btstack))) { |
| 1416 | txAbort(tid, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | goto out3; |
Dave Kleikamp | 4f4b401 | 2005-09-01 09:02:43 -0500 | [diff] [blame] | 1418 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | |
| 1420 | ip->i_op = &jfs_file_inode_operations; |
| 1421 | jfs_ip->dev = new_encode_dev(rdev); |
| 1422 | init_special_inode(ip, ip->i_mode, rdev); |
| 1423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | mark_inode_dirty(ip); |
| 1425 | |
| 1426 | dir->i_ctime = dir->i_mtime = CURRENT_TIME; |
| 1427 | |
| 1428 | mark_inode_dirty(dir); |
| 1429 | |
| 1430 | iplist[0] = dir; |
| 1431 | iplist[1] = ip; |
| 1432 | rc = txCommit(tid, 2, iplist, 0); |
| 1433 | |
| 1434 | out3: |
| 1435 | txEnd(tid); |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 1436 | mutex_unlock(&JFS_IP(ip)->commit_mutex); |
| 1437 | mutex_unlock(&JFS_IP(dir)->commit_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | if (rc) { |
Dave Kleikamp | 4f4b401 | 2005-09-01 09:02:43 -0500 | [diff] [blame] | 1439 | free_ea_wmap(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | ip->i_nlink = 0; |
Dave Kleikamp | 1f3403f | 2008-12-30 22:08:37 -0600 | [diff] [blame] | 1441 | unlock_new_inode(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | iput(ip); |
Dave Kleikamp | 1f3403f | 2008-12-30 22:08:37 -0600 | [diff] [blame] | 1443 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | d_instantiate(dentry, ip); |
Dave Kleikamp | 1f3403f | 2008-12-30 22:08:37 -0600 | [diff] [blame] | 1445 | unlock_new_inode(ip); |
| 1446 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | |
| 1448 | out1: |
| 1449 | free_UCSname(&dname); |
| 1450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | out: |
| 1452 | jfs_info("jfs_mknod: returning %d", rc); |
| 1453 | return rc; |
| 1454 | } |
| 1455 | |
| 1456 | static struct dentry *jfs_lookup(struct inode *dip, struct dentry *dentry, struct nameidata *nd) |
| 1457 | { |
| 1458 | struct btstack btstack; |
| 1459 | ino_t inum; |
| 1460 | struct inode *ip; |
| 1461 | struct component_name key; |
| 1462 | const char *name = dentry->d_name.name; |
| 1463 | int len = dentry->d_name.len; |
| 1464 | int rc; |
| 1465 | |
| 1466 | jfs_info("jfs_lookup: name = %s", name); |
| 1467 | |
Dave Kleikamp | 686762c | 2005-08-17 13:53:13 -0500 | [diff] [blame] | 1468 | if (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2) |
| 1469 | dentry->d_op = &jfs_ci_dentry_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | |
| 1471 | if ((name[0] == '.') && (len == 1)) |
| 1472 | inum = dip->i_ino; |
| 1473 | else if (strcmp(name, "..") == 0) |
| 1474 | inum = PARENT(dip); |
| 1475 | else { |
| 1476 | if ((rc = get_UCSname(&key, dentry))) |
| 1477 | return ERR_PTR(rc); |
| 1478 | rc = dtSearch(dip, &key, &inum, &btstack, JFS_LOOKUP); |
| 1479 | free_UCSname(&key); |
| 1480 | if (rc == -ENOENT) { |
| 1481 | d_add(dentry, NULL); |
Marcin Slusarz | 88f85a5 | 2008-05-12 16:42:43 -0500 | [diff] [blame] | 1482 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | } else if (rc) { |
| 1484 | jfs_err("jfs_lookup: dtSearch returned %d", rc); |
| 1485 | return ERR_PTR(rc); |
| 1486 | } |
| 1487 | } |
| 1488 | |
David Howells | eab1df7 | 2008-02-07 00:15:43 -0800 | [diff] [blame] | 1489 | ip = jfs_iget(dip->i_sb, inum); |
| 1490 | if (IS_ERR(ip)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | jfs_err("jfs_lookup: iget failed on inum %d", (uint) inum); |
David Howells | eab1df7 | 2008-02-07 00:15:43 -0800 | [diff] [blame] | 1492 | return ERR_CAST(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | dentry = d_splice_alias(ip, dentry); |
| 1496 | |
| 1497 | if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2)) |
| 1498 | dentry->d_op = &jfs_ci_dentry_operations; |
| 1499 | |
| 1500 | return dentry; |
| 1501 | } |
| 1502 | |
Christoph Hellwig | d425de7 | 2007-10-21 16:42:09 -0700 | [diff] [blame] | 1503 | static struct inode *jfs_nfs_get_inode(struct super_block *sb, |
| 1504 | u64 ino, u32 generation) |
Christoph Hellwig | 5ca2960 | 2007-07-17 04:04:29 -0700 | [diff] [blame] | 1505 | { |
Christoph Hellwig | 5ca2960 | 2007-07-17 04:04:29 -0700 | [diff] [blame] | 1506 | struct inode *inode; |
Christoph Hellwig | 5ca2960 | 2007-07-17 04:04:29 -0700 | [diff] [blame] | 1507 | |
| 1508 | if (ino == 0) |
| 1509 | return ERR_PTR(-ESTALE); |
David Howells | eab1df7 | 2008-02-07 00:15:43 -0800 | [diff] [blame] | 1510 | inode = jfs_iget(sb, ino); |
| 1511 | if (IS_ERR(inode)) |
| 1512 | return ERR_CAST(inode); |
Christoph Hellwig | 5ca2960 | 2007-07-17 04:04:29 -0700 | [diff] [blame] | 1513 | |
David Howells | eab1df7 | 2008-02-07 00:15:43 -0800 | [diff] [blame] | 1514 | if (generation && inode->i_generation != generation) { |
Christoph Hellwig | d425de7 | 2007-10-21 16:42:09 -0700 | [diff] [blame] | 1515 | iput(inode); |
| 1516 | return ERR_PTR(-ESTALE); |
Christoph Hellwig | 5ca2960 | 2007-07-17 04:04:29 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
Christoph Hellwig | d425de7 | 2007-10-21 16:42:09 -0700 | [diff] [blame] | 1519 | return inode; |
| 1520 | } |
Christoph Hellwig | 5ca2960 | 2007-07-17 04:04:29 -0700 | [diff] [blame] | 1521 | |
Christoph Hellwig | d425de7 | 2007-10-21 16:42:09 -0700 | [diff] [blame] | 1522 | struct dentry *jfs_fh_to_dentry(struct super_block *sb, struct fid *fid, |
| 1523 | int fh_len, int fh_type) |
| 1524 | { |
| 1525 | return generic_fh_to_dentry(sb, fid, fh_len, fh_type, |
| 1526 | jfs_nfs_get_inode); |
| 1527 | } |
| 1528 | |
| 1529 | struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid, |
| 1530 | int fh_len, int fh_type) |
| 1531 | { |
| 1532 | return generic_fh_to_parent(sb, fid, fh_len, fh_type, |
| 1533 | jfs_nfs_get_inode); |
Christoph Hellwig | 5ca2960 | 2007-07-17 04:04:29 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | struct dentry *jfs_get_parent(struct dentry *dentry) |
| 1537 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | unsigned long parent_ino; |
| 1539 | |
| 1540 | parent_ino = |
| 1541 | le32_to_cpu(JFS_IP(dentry->d_inode)->i_dtroot.header.idotdot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | |
Christoph Hellwig | 4400372 | 2008-08-11 15:49:04 +0200 | [diff] [blame] | 1543 | return d_obtain_alias(jfs_iget(dentry->d_inode->i_sb, parent_ino)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 1546 | const struct inode_operations jfs_dir_inode_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | .create = jfs_create, |
| 1548 | .lookup = jfs_lookup, |
| 1549 | .link = jfs_link, |
| 1550 | .unlink = jfs_unlink, |
| 1551 | .symlink = jfs_symlink, |
| 1552 | .mkdir = jfs_mkdir, |
| 1553 | .rmdir = jfs_rmdir, |
| 1554 | .mknod = jfs_mknod, |
| 1555 | .rename = jfs_rename, |
| 1556 | .setxattr = jfs_setxattr, |
| 1557 | .getxattr = jfs_getxattr, |
| 1558 | .listxattr = jfs_listxattr, |
| 1559 | .removexattr = jfs_removexattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | .setattr = jfs_setattr, |
Christoph Hellwig | 759bfee | 2010-03-03 09:05:02 -0500 | [diff] [blame] | 1561 | #ifdef CONFIG_JFS_POSIX_ACL |
Linus Torvalds | 18f4c64 | 2009-08-28 12:29:03 -0700 | [diff] [blame] | 1562 | .check_acl = jfs_check_acl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | #endif |
| 1564 | }; |
| 1565 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 1566 | const struct file_operations jfs_dir_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | .read = generic_read_dir, |
| 1568 | .readdir = jfs_readdir, |
| 1569 | .fsync = jfs_fsync, |
Andi Kleen | baab81f | 2008-01-27 16:58:51 -0600 | [diff] [blame] | 1570 | .unlocked_ioctl = jfs_ioctl, |
Andi Kleen | ef1fc2f | 2008-01-27 17:02:02 -0600 | [diff] [blame] | 1571 | #ifdef CONFIG_COMPAT |
| 1572 | .compat_ioctl = jfs_compat_ioctl, |
| 1573 | #endif |
Christoph Hellwig | 3222a3e | 2008-09-03 21:53:01 +0200 | [diff] [blame] | 1574 | .llseek = generic_file_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | }; |
| 1576 | |
Nick Piggin | b1e6a01 | 2011-01-07 17:49:28 +1100 | [diff] [blame^] | 1577 | static int jfs_ci_hash(const struct dentry *dir, const struct inode *inode, |
| 1578 | struct qstr *this) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | { |
| 1580 | unsigned long hash; |
| 1581 | int i; |
| 1582 | |
| 1583 | hash = init_name_hash(); |
| 1584 | for (i=0; i < this->len; i++) |
| 1585 | hash = partial_name_hash(tolower(this->name[i]), hash); |
| 1586 | this->hash = end_name_hash(hash); |
| 1587 | |
| 1588 | return 0; |
| 1589 | } |
| 1590 | |
Nick Piggin | 621e155 | 2011-01-07 17:49:27 +1100 | [diff] [blame] | 1591 | static int jfs_ci_compare(const struct dentry *parent, |
| 1592 | const struct inode *pinode, |
| 1593 | const struct dentry *dentry, const struct inode *inode, |
| 1594 | unsigned int len, const char *str, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | { |
| 1596 | int i, result = 1; |
| 1597 | |
Nick Piggin | 621e155 | 2011-01-07 17:49:27 +1100 | [diff] [blame] | 1598 | if (len != name->len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | goto out; |
Nick Piggin | 621e155 | 2011-01-07 17:49:27 +1100 | [diff] [blame] | 1600 | for (i=0; i < len; i++) { |
| 1601 | if (tolower(str[i]) != tolower(name->name[i])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | goto out; |
| 1603 | } |
| 1604 | result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | out: |
| 1606 | return result; |
| 1607 | } |
| 1608 | |
Nick Piggin | 2bc334d | 2011-01-07 17:49:25 +1100 | [diff] [blame] | 1609 | static int jfs_ci_revalidate(struct dentry *dentry, struct nameidata *nd) |
| 1610 | { |
| 1611 | /* |
| 1612 | * This is not negative dentry. Always valid. |
| 1613 | * |
| 1614 | * Note, rename() to existing directory entry will have ->d_inode, |
| 1615 | * and will use existing name which isn't specified name by user. |
| 1616 | * |
| 1617 | * We may be able to drop this positive dentry here. But dropping |
| 1618 | * positive dentry isn't good idea. So it's unsupported like |
| 1619 | * rename("filename", "FILENAME") for now. |
| 1620 | */ |
| 1621 | if (dentry->d_inode) |
| 1622 | return 1; |
| 1623 | |
| 1624 | /* |
| 1625 | * This may be nfsd (or something), anyway, we can't see the |
| 1626 | * intent of this. So, since this can be for creation, drop it. |
| 1627 | */ |
| 1628 | if (!nd) |
| 1629 | return 0; |
| 1630 | |
| 1631 | /* |
| 1632 | * Drop the negative dentry, in order to make sure to use the |
| 1633 | * case sensitive name which is specified by user if this is |
| 1634 | * for creation. |
| 1635 | */ |
| 1636 | if (!(nd->flags & (LOOKUP_CONTINUE | LOOKUP_PARENT))) { |
| 1637 | if (nd->flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET)) |
| 1638 | return 0; |
| 1639 | } |
| 1640 | return 1; |
| 1641 | } |
| 1642 | |
Al Viro | ad28b4e | 2009-02-20 06:00:49 +0000 | [diff] [blame] | 1643 | const struct dentry_operations jfs_ci_dentry_operations = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | { |
| 1645 | .d_hash = jfs_ci_hash, |
| 1646 | .d_compare = jfs_ci_compare, |
Nick Piggin | 2bc334d | 2011-01-07 17:49:25 +1100 | [diff] [blame] | 1647 | .d_revalidate = jfs_ci_revalidate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | }; |