~ [ 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.0.21)


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

~ [ 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