~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/jfs/namei.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/jfs/namei.c (Version linux-6.11.5) and /fs/jfs/namei.c (Version linux-5.8.18)


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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php