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