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