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