2 * Copyright (C) International Business Machines Corp., 2000-2004
3 * Portions Copyright (C) Christoph Hellwig, 2001-2002
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.
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.
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
21 #include <linux/ctype.h>
22 #include <linux/quotaops.h>
23 #include "jfs_incore.h"
24 #include "jfs_superblock.h"
25 #include "jfs_inode.h"
26 #include "jfs_dinode.h"
28 #include "jfs_unicode.h"
29 #include "jfs_metapage.h"
30 #include "jfs_xattr.h"
32 #include "jfs_debug.h"
34 extern struct inode_operations jfs_file_inode_operations
;
35 extern struct inode_operations jfs_symlink_inode_operations
;
36 extern struct file_operations jfs_file_operations
;
37 extern struct address_space_operations jfs_aops
;
39 extern int jfs_fsync(struct file
*, struct dentry
*, int);
40 extern void jfs_truncate_nolock(struct inode
*, loff_t
);
41 extern int jfs_init_acl(struct inode
*, struct inode
*);
46 struct inode_operations jfs_dir_inode_operations
;
47 struct file_operations jfs_dir_operations
;
48 struct dentry_operations jfs_ci_dentry_operations
;
50 static s64
commitZeroLink(tid_t
, struct inode
*);
53 * NAME: jfs_create(dip, dentry, mode)
55 * FUNCTION: create a regular file in the parent directory <dip>
56 * with name = <from dentry> and mode = <mode>
58 * PARAMETER: dip - parent directory vnode
59 * dentry - dentry of new file
60 * mode - create mode (rwxrwxrwx).
63 * RETURN: Errors from subroutines
66 static int jfs_create(struct inode
*dip
, struct dentry
*dentry
, int mode
,
70 tid_t tid
; /* transaction id */
71 struct inode
*ip
= NULL
; /* child directory inode */
73 struct component_name dname
; /* child directory name */
74 struct btstack btstack
;
75 struct inode
*iplist
[2];
78 jfs_info("jfs_create: dip:0x%p name:%s", dip
, dentry
->d_name
.name
);
81 * search parent directory for entry/freespace
82 * (dtSearch() returns parent directory page pinned)
84 if ((rc
= get_UCSname(&dname
, dentry
)))
88 * Either iAlloc() or txBegin() may block. Deadlock can occur if we
89 * block there while holding dtree page, so we allocate the inode &
90 * begin the transaction before we search the directory.
92 ip
= ialloc(dip
, mode
);
98 tid
= txBegin(dip
->i_sb
, 0);
100 down(&JFS_IP(dip
)->commit_sem
);
101 down(&JFS_IP(ip
)->commit_sem
);
103 if ((rc
= dtSearch(dip
, &dname
, &ino
, &btstack
, JFS_CREATE
))) {
104 jfs_err("jfs_create: dtSearch returned %d", rc
);
108 tblk
= tid_to_tblock(tid
);
109 tblk
->xflag
|= COMMIT_CREATE
;
110 tblk
->ino
= ip
->i_ino
;
111 tblk
->u
.ixpxd
= JFS_IP(ip
)->ixpxd
;
117 * initialize the child XAD tree root in-line in inode
122 * create entry in parent directory for child directory
123 * (dtInsert() releases parent directory page)
126 if ((rc
= dtInsert(tid
, dip
, &dname
, &ino
, &btstack
))) {
128 jfs_err("jfs_create: dtInsert returned -EIO");
129 txAbort(tid
, 1); /* Marks Filesystem dirty */
131 txAbort(tid
, 0); /* Filesystem full */
135 ip
->i_op
= &jfs_file_inode_operations
;
136 ip
->i_fop
= &jfs_file_operations
;
137 ip
->i_mapping
->a_ops
= &jfs_aops
;
139 insert_inode_hash(ip
);
140 mark_inode_dirty(ip
);
142 dip
->i_ctime
= dip
->i_mtime
= CURRENT_TIME
;
144 mark_inode_dirty(dip
);
146 rc
= txCommit(tid
, 2, &iplist
[0], 0);
150 up(&JFS_IP(dip
)->commit_sem
);
151 up(&JFS_IP(ip
)->commit_sem
);
156 d_instantiate(dentry
, ip
);
159 free_UCSname(&dname
);
161 #ifdef CONFIG_JFS_POSIX_ACL
163 jfs_init_acl(ip
, dip
);
168 jfs_info("jfs_create: rc:%d", rc
);
174 * NAME: jfs_mkdir(dip, dentry, mode)
176 * FUNCTION: create a child directory in the parent directory <dip>
177 * with name = <from dentry> and mode = <mode>
179 * PARAMETER: dip - parent directory vnode
180 * dentry - dentry of child directory
181 * mode - create mode (rwxrwxrwx).
183 * RETURN: Errors from subroutines
186 * EACCESS: user needs search+write permission on the parent directory
188 static int jfs_mkdir(struct inode
*dip
, struct dentry
*dentry
, int mode
)
191 tid_t tid
; /* transaction id */
192 struct inode
*ip
= NULL
; /* child directory inode */
194 struct component_name dname
; /* child directory name */
195 struct btstack btstack
;
196 struct inode
*iplist
[2];
199 jfs_info("jfs_mkdir: dip:0x%p name:%s", dip
, dentry
->d_name
.name
);
201 /* link count overflow on parent directory ? */
202 if (dip
->i_nlink
== JFS_LINK_MAX
) {
208 * search parent directory for entry/freespace
209 * (dtSearch() returns parent directory page pinned)
211 if ((rc
= get_UCSname(&dname
, dentry
)))
215 * Either iAlloc() or txBegin() may block. Deadlock can occur if we
216 * block there while holding dtree page, so we allocate the inode &
217 * begin the transaction before we search the directory.
219 ip
= ialloc(dip
, S_IFDIR
| mode
);
225 tid
= txBegin(dip
->i_sb
, 0);
227 down(&JFS_IP(dip
)->commit_sem
);
228 down(&JFS_IP(ip
)->commit_sem
);
230 if ((rc
= dtSearch(dip
, &dname
, &ino
, &btstack
, JFS_CREATE
))) {
231 jfs_err("jfs_mkdir: dtSearch returned %d", rc
);
235 tblk
= tid_to_tblock(tid
);
236 tblk
->xflag
|= COMMIT_CREATE
;
237 tblk
->ino
= ip
->i_ino
;
238 tblk
->u
.ixpxd
= JFS_IP(ip
)->ixpxd
;
244 * initialize the child directory in-line in inode
246 dtInitRoot(tid
, ip
, dip
->i_ino
);
249 * create entry in parent directory for child directory
250 * (dtInsert() releases parent directory page)
253 if ((rc
= dtInsert(tid
, dip
, &dname
, &ino
, &btstack
))) {
255 jfs_err("jfs_mkdir: dtInsert returned -EIO");
256 txAbort(tid
, 1); /* Marks Filesystem dirty */
258 txAbort(tid
, 0); /* Filesystem full */
262 ip
->i_nlink
= 2; /* for '.' */
263 ip
->i_op
= &jfs_dir_inode_operations
;
264 ip
->i_fop
= &jfs_dir_operations
;
266 insert_inode_hash(ip
);
267 mark_inode_dirty(ip
);
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
);
274 rc
= txCommit(tid
, 2, &iplist
[0], 0);
278 up(&JFS_IP(dip
)->commit_sem
);
279 up(&JFS_IP(ip
)->commit_sem
);
284 d_instantiate(dentry
, ip
);
287 free_UCSname(&dname
);
289 #ifdef CONFIG_JFS_POSIX_ACL
291 jfs_init_acl(ip
, dip
);
296 jfs_info("jfs_mkdir: rc:%d", rc
);
301 * NAME: jfs_rmdir(dip, dentry)
303 * FUNCTION: remove a link to child directory
305 * PARAMETER: dip - parent inode
306 * dentry - child directory dentry
308 * RETURN: -EINVAL - if name is . or ..
309 * -EINVAL - if . or .. exist but are invalid.
310 * errors from subroutines
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).
319 static int jfs_rmdir(struct inode
*dip
, struct dentry
*dentry
)
322 tid_t tid
; /* transaction id */
323 struct inode
*ip
= dentry
->d_inode
;
325 struct component_name dname
;
326 struct inode
*iplist
[2];
329 jfs_info("jfs_rmdir: dip:0x%p name:%s", dip
, dentry
->d_name
.name
);
331 /* Init inode for quota operations. */
334 /* directory must be empty to be removed */
340 if ((rc
= get_UCSname(&dname
, dentry
))) {
344 tid
= txBegin(dip
->i_sb
, 0);
346 down(&JFS_IP(dip
)->commit_sem
);
347 down(&JFS_IP(ip
)->commit_sem
);
352 tblk
= tid_to_tblock(tid
);
353 tblk
->xflag
|= COMMIT_DELETE
;
357 * delete the entry of target directory from parent directory
360 if ((rc
= dtDelete(tid
, dip
, &dname
, &ino
, JFS_REMOVE
))) {
361 jfs_err("jfs_rmdir: dtDelete returned %d", rc
);
365 up(&JFS_IP(dip
)->commit_sem
);
366 up(&JFS_IP(ip
)->commit_sem
);
371 /* update parent directory's link count corresponding
372 * to ".." entry of the target directory deleted
375 dip
->i_ctime
= dip
->i_mtime
= CURRENT_TIME
;
376 mark_inode_dirty(dip
);
379 * OS/2 could have created EA and/or ACL
381 /* free EA from both persistent and working map */
382 if (JFS_IP(ip
)->ea
.flag
& DXD_EXTENT
) {
384 txEA(tid
, ip
, &JFS_IP(ip
)->ea
, NULL
);
386 JFS_IP(ip
)->ea
.flag
= 0;
388 /* free ACL from both persistent and working map */
389 if (JFS_IP(ip
)->acl
.flag
& DXD_EXTENT
) {
391 txEA(tid
, ip
, &JFS_IP(ip
)->acl
, NULL
);
393 JFS_IP(ip
)->acl
.flag
= 0;
395 /* mark the target directory as deleted */
397 mark_inode_dirty(ip
);
399 rc
= txCommit(tid
, 2, &iplist
[0], 0);
403 up(&JFS_IP(dip
)->commit_sem
);
404 up(&JFS_IP(ip
)->commit_sem
);
407 * Truncating the directory index table is not guaranteed. It
408 * may need to be done iteratively
410 if (test_cflag(COMMIT_Stale
, dip
)) {
412 jfs_truncate_nolock(dip
, 0);
414 clear_cflag(COMMIT_Stale
, dip
);
418 free_UCSname(&dname
);
421 jfs_info("jfs_rmdir: rc:%d", rc
);
426 * NAME: jfs_unlink(dip, dentry)
428 * FUNCTION: remove a link to object <vp> named by <name>
429 * from parent directory <dvp>
431 * PARAMETER: dip - inode of parent directory
432 * dentry - dentry of object to be removed
434 * RETURN: errors from subroutines
437 * temporary file: if one or more processes have the file open
438 * when the last link is removed, the link will be removed before
439 * unlink() returns, but the removal of the file contents will be
440 * postponed until all references to the files are closed.
442 * JFS does NOT support unlink() on directories.
445 static int jfs_unlink(struct inode
*dip
, struct dentry
*dentry
)
448 tid_t tid
; /* transaction id */
449 struct inode
*ip
= dentry
->d_inode
;
451 struct component_name dname
; /* object name */
452 struct inode
*iplist
[2];
457 jfs_info("jfs_unlink: dip:0x%p name:%s", dip
, dentry
->d_name
.name
);
459 /* Init inode for quota operations. */
462 if ((rc
= get_UCSname(&dname
, dentry
)))
467 tid
= txBegin(dip
->i_sb
, 0);
469 down(&JFS_IP(dip
)->commit_sem
);
470 down(&JFS_IP(ip
)->commit_sem
);
476 * delete the entry of target file from parent directory
479 if ((rc
= dtDelete(tid
, dip
, &dname
, &ino
, JFS_REMOVE
))) {
480 jfs_err("jfs_unlink: dtDelete returned %d", rc
);
482 txAbort(tid
, 1); /* Marks FS Dirty */
484 up(&JFS_IP(dip
)->commit_sem
);
485 up(&JFS_IP(ip
)->commit_sem
);
492 ip
->i_ctime
= dip
->i_ctime
= dip
->i_mtime
= CURRENT_TIME
;
493 mark_inode_dirty(dip
);
495 /* update target's inode */
497 mark_inode_dirty(ip
);
500 * commit zero link count object
502 if (ip
->i_nlink
== 0) {
503 assert(!test_cflag(COMMIT_Nolink
, ip
));
504 /* free block resources */
505 if ((new_size
= commitZeroLink(tid
, ip
)) < 0) {
506 txAbort(tid
, 1); /* Marks FS Dirty */
508 up(&JFS_IP(dip
)->commit_sem
);
509 up(&JFS_IP(ip
)->commit_sem
);
514 tblk
= tid_to_tblock(tid
);
515 tblk
->xflag
|= COMMIT_DELETE
;
520 * Incomplete truncate of file data can
521 * result in timing problems unless we synchronously commit the
525 commit_flag
= COMMIT_SYNC
;
530 * If xtTruncate was incomplete, commit synchronously to avoid
531 * timing complications
533 rc
= txCommit(tid
, 2, &iplist
[0], commit_flag
);
537 up(&JFS_IP(dip
)->commit_sem
);
538 up(&JFS_IP(ip
)->commit_sem
);
541 while (new_size
&& (rc
== 0)) {
542 tid
= txBegin(dip
->i_sb
, 0);
543 down(&JFS_IP(ip
)->commit_sem
);
544 new_size
= xtTruncate_pmap(tid
, ip
, new_size
);
546 txAbort(tid
, 1); /* Marks FS Dirty */
549 rc
= txCommit(tid
, 2, &iplist
[0], COMMIT_SYNC
);
551 up(&JFS_IP(ip
)->commit_sem
);
554 if (ip
->i_nlink
== 0)
555 set_cflag(COMMIT_Nolink
, ip
);
560 * Truncating the directory index table is not guaranteed. It
561 * may need to be done iteratively
563 if (test_cflag(COMMIT_Stale
, dip
)) {
565 jfs_truncate_nolock(dip
, 0);
567 clear_cflag(COMMIT_Stale
, dip
);
571 free_UCSname(&dname
);
573 jfs_info("jfs_unlink: rc:%d", rc
);
578 * NAME: commitZeroLink()
580 * FUNCTION: for non-directory, called by jfs_remove(),
581 * truncate a regular file, directory or symbolic
582 * link to zero length. return 0 if type is not
585 * if the file is currently associated with a VM segment
586 * only permanent disk and inode map resources are freed,
587 * and neither the inode nor indirect blocks are modified
588 * so that the resources can be later freed in the work
590 * if there is no VM segment on entry, the resources are
591 * freed in both work and permanent map.
592 * (? for temporary file - memory object is cached even
593 * after no reference:
594 * reference count > 0 - )
596 * PARAMETERS: cd - pointer to commit data structure.
597 * current inode is the one to truncate.
599 * RETURN: Errors from subroutines
601 static s64
commitZeroLink(tid_t tid
, struct inode
*ip
)
606 jfs_info("commitZeroLink: tid = %d, ip = 0x%p", tid
, ip
);
608 filetype
= ip
->i_mode
& S_IFMT
;
613 /* fast symbolic link */
614 if (ip
->i_size
< IDATASIZE
) {
620 assert(filetype
!= S_IFDIR
);
624 set_cflag(COMMIT_Freewmap
, ip
);
626 /* mark transaction of block map update type */
627 tblk
= tid_to_tblock(tid
);
628 tblk
->xflag
|= COMMIT_PMAP
;
633 if (JFS_IP(ip
)->ea
.flag
& DXD_EXTENT
)
634 /* acquire maplock on EA to be freed from block map */
635 txEA(tid
, ip
, &JFS_IP(ip
)->ea
, NULL
);
640 if (JFS_IP(ip
)->acl
.flag
& DXD_EXTENT
)
641 /* acquire maplock on EA to be freed from block map */
642 txEA(tid
, ip
, &JFS_IP(ip
)->acl
, NULL
);
645 * free xtree/data (truncate to zero length):
646 * free xtree/data pages from cache if COMMIT_PWMAP,
647 * free xtree/data blocks from persistent block map, and
648 * free xtree/data blocks from working block map if COMMIT_PWMAP;
651 return xtTruncate_pmap(tid
, ip
, 0);
658 * NAME: freeZeroLink()
660 * FUNCTION: for non-directory, called by iClose(),
661 * free resources of a file from cache and WORKING map
662 * for a file previously committed with zero link count
663 * while associated with a pager object,
665 * PARAMETER: ip - pointer to inode of file.
669 int freeZeroLink(struct inode
*ip
)
674 jfs_info("freeZeroLink: ip = 0x%p", ip
);
676 /* return if not reg or symbolic link or if size is
679 type
= ip
->i_mode
& S_IFMT
;
685 /* if its contained in inode nothing to do */
686 if (ip
->i_size
< IDATASIZE
)
696 if (JFS_IP(ip
)->ea
.flag
& DXD_EXTENT
) {
697 s64 xaddr
= addressDXD(&JFS_IP(ip
)->ea
);
698 int xlen
= lengthDXD(&JFS_IP(ip
)->ea
);
699 struct maplock maplock
; /* maplock for COMMIT_WMAP */
700 struct pxd_lock
*pxdlock
; /* maplock for COMMIT_WMAP */
702 /* free EA pages from cache */
703 invalidate_dxd_metapages(ip
, JFS_IP(ip
)->ea
);
705 /* free EA extent from working block map */
707 pxdlock
= (struct pxd_lock
*) & maplock
;
708 pxdlock
->flag
= mlckFREEPXD
;
709 PXDaddress(&pxdlock
->pxd
, xaddr
);
710 PXDlength(&pxdlock
->pxd
, xlen
);
711 txFreeMap(ip
, pxdlock
, NULL
, COMMIT_WMAP
);
717 if (JFS_IP(ip
)->acl
.flag
& DXD_EXTENT
) {
718 s64 xaddr
= addressDXD(&JFS_IP(ip
)->acl
);
719 int xlen
= lengthDXD(&JFS_IP(ip
)->acl
);
720 struct maplock maplock
; /* maplock for COMMIT_WMAP */
721 struct pxd_lock
*pxdlock
; /* maplock for COMMIT_WMAP */
723 invalidate_dxd_metapages(ip
, JFS_IP(ip
)->acl
);
725 /* free ACL extent from working block map */
727 pxdlock
= (struct pxd_lock
*) & maplock
;
728 pxdlock
->flag
= mlckFREEPXD
;
729 PXDaddress(&pxdlock
->pxd
, xaddr
);
730 PXDlength(&pxdlock
->pxd
, xlen
);
731 txFreeMap(ip
, pxdlock
, NULL
, COMMIT_WMAP
);
735 * free xtree/data (truncate to zero length):
736 * free xtree/data pages from cache, and
737 * free xtree/data blocks from working block map;
740 rc
= xtTruncate(0, ip
, 0, COMMIT_WMAP
);
746 * NAME: jfs_link(vp, dvp, name, crp)
748 * FUNCTION: create a link to <vp> by the name = <name>
749 * in the parent directory <dvp>
751 * PARAMETER: vp - target object
752 * dvp - parent directory of new link
753 * name - name of new link to target object
756 * RETURN: Errors from subroutines
759 * JFS does NOT support link() on directories (to prevent circular
760 * path in the directory hierarchy);
761 * EPERM: the target object is a directory, and either the caller
762 * does not have appropriate privileges or the implementation prohibits
763 * using link() on directories [XPG4.2].
765 * JFS does NOT support links between file systems:
766 * EXDEV: target object and new link are on different file systems and
767 * implementation does not support links between file systems [XPG4.2].
769 static int jfs_link(struct dentry
*old_dentry
,
770 struct inode
*dir
, struct dentry
*dentry
)
774 struct inode
*ip
= old_dentry
->d_inode
;
776 struct component_name dname
;
777 struct btstack btstack
;
778 struct inode
*iplist
[2];
780 jfs_info("jfs_link: %s %s", old_dentry
->d_name
.name
,
781 dentry
->d_name
.name
);
783 if (ip
->i_nlink
== JFS_LINK_MAX
)
786 if (ip
->i_nlink
== 0)
789 tid
= txBegin(ip
->i_sb
, 0);
791 down(&JFS_IP(dir
)->commit_sem
);
792 down(&JFS_IP(ip
)->commit_sem
);
795 * scan parent directory for entry/freespace
797 if ((rc
= get_UCSname(&dname
, dentry
)))
800 if ((rc
= dtSearch(dir
, &dname
, &ino
, &btstack
, JFS_CREATE
)))
804 * create entry for new link in parent directory
807 if ((rc
= dtInsert(tid
, dir
, &dname
, &ino
, &btstack
)))
810 /* update object inode */
811 ip
->i_nlink
++; /* for new link */
812 ip
->i_ctime
= CURRENT_TIME
;
813 mark_inode_dirty(dir
);
814 atomic_inc(&ip
->i_count
);
818 rc
= txCommit(tid
, 2, &iplist
[0], 0);
824 d_instantiate(dentry
, ip
);
827 free_UCSname(&dname
);
832 up(&JFS_IP(dir
)->commit_sem
);
833 up(&JFS_IP(ip
)->commit_sem
);
835 jfs_info("jfs_link: rc:%d", rc
);
840 * NAME: jfs_symlink(dip, dentry, name)
842 * FUNCTION: creates a symbolic link to <symlink> by name <name>
845 * PARAMETER: dip - parent directory vnode
846 * dentry - dentry of symbolic link
847 * name - the path name of the existing object
848 * that will be the source of the link
850 * RETURN: errors from subroutines
853 * ENAMETOOLONG: pathname resolution of a symbolic link produced
854 * an intermediate result whose length exceeds PATH_MAX [XPG4.2]
857 static int jfs_symlink(struct inode
*dip
, struct dentry
*dentry
,
863 struct component_name dname
;
864 int ssize
; /* source pathname size */
865 struct btstack btstack
;
866 struct inode
*ip
= dentry
->d_inode
;
867 unchar
*i_fastsymlink
;
869 int bmask
= 0, xsize
;
870 s64 extent
= 0, xaddr
;
872 struct super_block
*sb
;
875 struct inode
*iplist
[2];
877 jfs_info("jfs_symlink: dip:0x%p name:%s", dip
, name
);
879 ssize
= strlen(name
) + 1;
882 * search parent directory for entry/freespace
883 * (dtSearch() returns parent directory page pinned)
886 if ((rc
= get_UCSname(&dname
, dentry
)))
890 * allocate on-disk/in-memory inode for symbolic link:
891 * (iAlloc() returns new, locked inode)
893 ip
= ialloc(dip
, S_IFLNK
| 0777);
899 tid
= txBegin(dip
->i_sb
, 0);
901 down(&JFS_IP(dip
)->commit_sem
);
902 down(&JFS_IP(ip
)->commit_sem
);
904 tblk
= tid_to_tblock(tid
);
905 tblk
->xflag
|= COMMIT_CREATE
;
906 tblk
->ino
= ip
->i_ino
;
907 tblk
->u
.ixpxd
= JFS_IP(ip
)->ixpxd
;
909 /* fix symlink access permission
910 * (dir_create() ANDs in the u.u_cmask,
911 * but symlinks really need to be 777 access)
916 * write symbolic link target path name
921 * write source path name inline in on-disk inode (fast symbolic link)
924 if (ssize
<= IDATASIZE
) {
925 ip
->i_op
= &jfs_symlink_inode_operations
;
927 i_fastsymlink
= JFS_IP(ip
)->i_inline
;
928 memcpy(i_fastsymlink
, name
, ssize
);
929 ip
->i_size
= ssize
- 1;
932 * if symlink is > 128 bytes, we don't have the space to
933 * store inline extended attributes
935 if (ssize
> sizeof (JFS_IP(ip
)->i_inline
))
936 JFS_IP(ip
)->mode2
&= ~INLINEEA
;
938 jfs_info("jfs_symlink: fast symlink added ssize:%d name:%s ",
942 * write source path name in a single extent
945 jfs_info("jfs_symlink: allocate extent ip:0x%p", ip
);
947 ip
->i_op
= &page_symlink_inode_operations
;
948 ip
->i_mapping
->a_ops
= &jfs_aops
;
951 * even though the data of symlink object (source
952 * path name) is treated as non-journaled user data,
953 * it is read/written thru buffer cache for performance.
956 bmask
= JFS_SBI(sb
)->bsize
- 1;
957 xsize
= (ssize
+ bmask
) & ~bmask
;
959 xlen
= xsize
>> JFS_SBI(sb
)->l2bsize
;
960 if ((rc
= xtInsert(tid
, ip
, 0, 0, xlen
, &xaddr
, 0))) {
966 ip
->i_size
= ssize
- 1;
968 /* This is kind of silly since PATH_MAX == 4K */
969 int copy_size
= min(ssize
, PSIZE
);
971 mp
= get_metapage(ip
, xaddr
, PSIZE
, 1);
974 xtTruncate(tid
, ip
, 0, COMMIT_PWMAP
);
979 memcpy(mp
->data
, name
, copy_size
);
983 xaddr
+= JFS_SBI(sb
)->nbperpage
;
988 * create entry for symbolic link in parent directory
990 rc
= dtSearch(dip
, &dname
, &ino
, &btstack
, JFS_CREATE
);
993 rc
= dtInsert(tid
, dip
, &dname
, &ino
, &btstack
);
997 xtTruncate(tid
, ip
, 0, COMMIT_PWMAP
);
999 /* discard new inode */
1003 insert_inode_hash(ip
);
1004 mark_inode_dirty(ip
);
1007 * commit update of parent directory and link object
1012 rc
= txCommit(tid
, 2, &iplist
[0], 0);
1016 up(&JFS_IP(dip
)->commit_sem
);
1017 up(&JFS_IP(ip
)->commit_sem
);
1022 d_instantiate(dentry
, ip
);
1025 free_UCSname(&dname
);
1027 #ifdef CONFIG_JFS_POSIX_ACL
1029 jfs_init_acl(ip
, dip
);
1033 jfs_info("jfs_symlink: rc:%d", rc
);
1041 * FUNCTION: rename a file or directory
1043 static int jfs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
1044 struct inode
*new_dir
, struct dentry
*new_dentry
)
1046 struct btstack btstack
;
1048 struct component_name new_dname
;
1049 struct inode
*new_ip
;
1050 struct component_name old_dname
;
1051 struct inode
*old_ip
;
1055 struct dt_lock
*dtlck
;
1058 struct inode
*iplist
[4];
1059 struct tblock
*tblk
;
1064 jfs_info("jfs_rename: %s %s", old_dentry
->d_name
.name
,
1065 new_dentry
->d_name
.name
);
1067 old_ip
= old_dentry
->d_inode
;
1068 new_ip
= new_dentry
->d_inode
;
1070 if ((rc
= get_UCSname(&old_dname
, old_dentry
)))
1073 if ((rc
= get_UCSname(&new_dname
, new_dentry
)))
1077 * Make sure source inode number is what we think it is
1079 rc
= dtSearch(old_dir
, &old_dname
, &ino
, &btstack
, JFS_LOOKUP
);
1080 if (rc
|| (ino
!= old_ip
->i_ino
)) {
1086 * Make sure dest inode number (if any) is what we think it is
1088 rc
= dtSearch(new_dir
, &new_dname
, &ino
, &btstack
, JFS_LOOKUP
);
1090 if ((new_ip
== 0) || (ino
!= new_ip
->i_ino
)) {
1094 } else if (rc
!= -ENOENT
)
1097 /* no entry exists, but one was expected */
1102 if (S_ISDIR(old_ip
->i_mode
)) {
1104 if (!dtEmpty(new_ip
)) {
1108 } else if ((new_dir
!= old_dir
) &&
1109 (new_dir
->i_nlink
== JFS_LINK_MAX
)) {
1113 } else if (new_ip
) {
1114 IWRITE_LOCK(new_ip
);
1115 /* Init inode for quota operations. */
1120 * The real work starts here
1122 tid
= txBegin(new_dir
->i_sb
, 0);
1124 down(&JFS_IP(new_dir
)->commit_sem
);
1125 down(&JFS_IP(old_ip
)->commit_sem
);
1126 if (old_dir
!= new_dir
)
1127 down(&JFS_IP(old_dir
)->commit_sem
);
1130 down(&JFS_IP(new_ip
)->commit_sem
);
1132 * Change existing directory entry to new inode number
1134 ino
= new_ip
->i_ino
;
1135 rc
= dtModify(tid
, new_dir
, &new_dname
, &ino
,
1136 old_ip
->i_ino
, JFS_RENAME
);
1140 if (S_ISDIR(new_ip
->i_mode
)) {
1142 if (new_ip
->i_nlink
) {
1143 up(&JFS_IP(new_dir
)->commit_sem
);
1144 up(&JFS_IP(old_ip
)->commit_sem
);
1145 if (old_dir
!= new_dir
)
1146 up(&JFS_IP(old_dir
)->commit_sem
);
1147 if (!S_ISDIR(old_ip
->i_mode
) && new_ip
)
1148 IWRITE_UNLOCK(new_ip
);
1149 jfs_error(new_ip
->i_sb
,
1150 "jfs_rename: new_ip->i_nlink != 0");
1153 tblk
= tid_to_tblock(tid
);
1154 tblk
->xflag
|= COMMIT_DELETE
;
1155 tblk
->u
.ip
= new_ip
;
1156 } else if (new_ip
->i_nlink
== 0) {
1157 assert(!test_cflag(COMMIT_Nolink
, new_ip
));
1158 /* free block resources */
1159 if ((new_size
= commitZeroLink(tid
, new_ip
)) < 0) {
1160 txAbort(tid
, 1); /* Marks FS Dirty */
1164 tblk
= tid_to_tblock(tid
);
1165 tblk
->xflag
|= COMMIT_DELETE
;
1166 tblk
->u
.ip
= new_ip
;
1168 new_ip
->i_ctime
= CURRENT_TIME
;
1169 mark_inode_dirty(new_ip
);
1173 * Add new directory entry
1175 rc
= dtSearch(new_dir
, &new_dname
, &ino
, &btstack
,
1178 jfs_err("jfs_rename didn't expect dtSearch to fail "
1183 ino
= old_ip
->i_ino
;
1184 rc
= dtInsert(tid
, new_dir
, &new_dname
, &ino
, &btstack
);
1187 jfs_err("jfs_rename: dtInsert returned -EIO");
1190 if (S_ISDIR(old_ip
->i_mode
))
1194 * Remove old directory entry
1197 ino
= old_ip
->i_ino
;
1198 rc
= dtDelete(tid
, old_dir
, &old_dname
, &ino
, JFS_REMOVE
);
1200 jfs_err("jfs_rename did not expect dtDelete to return rc = %d",
1202 txAbort(tid
, 1); /* Marks Filesystem dirty */
1205 if (S_ISDIR(old_ip
->i_mode
)) {
1207 if (old_dir
!= new_dir
) {
1209 * Change inode number of parent for moved directory
1212 JFS_IP(old_ip
)->i_dtroot
.header
.idotdot
=
1213 cpu_to_le32(new_dir
->i_ino
);
1215 /* Linelock header of dtree */
1216 tlck
= txLock(tid
, old_ip
,
1217 (struct metapage
*) &JFS_IP(old_ip
)->bxflag
,
1218 tlckDTREE
| tlckBTROOT
| tlckRELINK
);
1219 dtlck
= (struct dt_lock
*) & tlck
->lock
;
1220 ASSERT(dtlck
->index
== 0);
1221 lv
= & dtlck
->lv
[0];
1229 * Update ctime on changed/moved inodes & mark dirty
1231 old_ip
->i_ctime
= CURRENT_TIME
;
1232 mark_inode_dirty(old_ip
);
1234 new_dir
->i_ctime
= new_dir
->i_mtime
= current_fs_time(new_dir
->i_sb
);
1235 mark_inode_dirty(new_dir
);
1237 /* Build list of inodes modified by this transaction */
1239 iplist
[ipcount
++] = old_ip
;
1241 iplist
[ipcount
++] = new_ip
;
1242 iplist
[ipcount
++] = old_dir
;
1244 if (old_dir
!= new_dir
) {
1245 iplist
[ipcount
++] = new_dir
;
1246 old_dir
->i_ctime
= old_dir
->i_mtime
= CURRENT_TIME
;
1247 mark_inode_dirty(old_dir
);
1251 * Incomplete truncate of file data can
1252 * result in timing problems unless we synchronously commit the
1256 commit_flag
= COMMIT_SYNC
;
1260 rc
= txCommit(tid
, ipcount
, iplist
, commit_flag
);
1265 up(&JFS_IP(new_dir
)->commit_sem
);
1266 up(&JFS_IP(old_ip
)->commit_sem
);
1267 if (old_dir
!= new_dir
)
1268 up(&JFS_IP(old_dir
)->commit_sem
);
1270 up(&JFS_IP(new_ip
)->commit_sem
);
1272 while (new_size
&& (rc
== 0)) {
1273 tid
= txBegin(new_ip
->i_sb
, 0);
1274 down(&JFS_IP(new_ip
)->commit_sem
);
1275 new_size
= xtTruncate_pmap(tid
, new_ip
, new_size
);
1280 rc
= txCommit(tid
, 1, &new_ip
, COMMIT_SYNC
);
1282 up(&JFS_IP(new_ip
)->commit_sem
);
1284 if (new_ip
&& (new_ip
->i_nlink
== 0))
1285 set_cflag(COMMIT_Nolink
, new_ip
);
1287 free_UCSname(&new_dname
);
1289 free_UCSname(&old_dname
);
1291 if (new_ip
&& !S_ISDIR(new_ip
->i_mode
))
1292 IWRITE_UNLOCK(new_ip
);
1294 * Truncating the directory index table is not guaranteed. It
1295 * may need to be done iteratively
1297 if (test_cflag(COMMIT_Stale
, old_dir
)) {
1298 if (old_dir
->i_size
> 1)
1299 jfs_truncate_nolock(old_dir
, 0);
1301 clear_cflag(COMMIT_Stale
, old_dir
);
1304 jfs_info("jfs_rename: returning %d", rc
);
1312 * FUNCTION: Create a special file (device)
1314 static int jfs_mknod(struct inode
*dir
, struct dentry
*dentry
,
1315 int mode
, dev_t rdev
)
1317 struct jfs_inode_info
*jfs_ip
;
1318 struct btstack btstack
;
1319 struct component_name dname
;
1322 struct inode
*iplist
[2];
1325 struct tblock
*tblk
;
1327 if (!new_valid_dev(rdev
))
1330 jfs_info("jfs_mknod: %s", dentry
->d_name
.name
);
1332 if ((rc
= get_UCSname(&dname
, dentry
)))
1335 ip
= ialloc(dir
, mode
);
1340 jfs_ip
= JFS_IP(ip
);
1342 tid
= txBegin(dir
->i_sb
, 0);
1344 down(&JFS_IP(dir
)->commit_sem
);
1345 down(&JFS_IP(ip
)->commit_sem
);
1347 if ((rc
= dtSearch(dir
, &dname
, &ino
, &btstack
, JFS_CREATE
)))
1350 tblk
= tid_to_tblock(tid
);
1351 tblk
->xflag
|= COMMIT_CREATE
;
1352 tblk
->ino
= ip
->i_ino
;
1353 tblk
->u
.ixpxd
= JFS_IP(ip
)->ixpxd
;
1356 if ((rc
= dtInsert(tid
, dir
, &dname
, &ino
, &btstack
)))
1359 ip
->i_op
= &jfs_file_inode_operations
;
1360 jfs_ip
->dev
= new_encode_dev(rdev
);
1361 init_special_inode(ip
, ip
->i_mode
, rdev
);
1363 insert_inode_hash(ip
);
1364 mark_inode_dirty(ip
);
1366 dir
->i_ctime
= dir
->i_mtime
= CURRENT_TIME
;
1368 mark_inode_dirty(dir
);
1372 rc
= txCommit(tid
, 2, iplist
, 0);
1376 up(&JFS_IP(ip
)->commit_sem
);
1377 up(&JFS_IP(dir
)->commit_sem
);
1382 d_instantiate(dentry
, ip
);
1385 free_UCSname(&dname
);
1387 #ifdef CONFIG_JFS_POSIX_ACL
1389 jfs_init_acl(ip
, dir
);
1393 jfs_info("jfs_mknod: returning %d", rc
);
1397 static struct dentry
*jfs_lookup(struct inode
*dip
, struct dentry
*dentry
, struct nameidata
*nd
)
1399 struct btstack btstack
;
1402 struct component_name key
;
1403 const char *name
= dentry
->d_name
.name
;
1404 int len
= dentry
->d_name
.len
;
1407 jfs_info("jfs_lookup: name = %s", name
);
1410 if ((name
[0] == '.') && (len
== 1))
1412 else if (strcmp(name
, "..") == 0)
1415 if ((rc
= get_UCSname(&key
, dentry
)))
1417 rc
= dtSearch(dip
, &key
, &inum
, &btstack
, JFS_LOOKUP
);
1419 if (rc
== -ENOENT
) {
1420 d_add(dentry
, NULL
);
1423 jfs_err("jfs_lookup: dtSearch returned %d", rc
);
1428 ip
= iget(dip
->i_sb
, inum
);
1429 if (ip
== NULL
|| is_bad_inode(ip
)) {
1430 jfs_err("jfs_lookup: iget failed on inum %d", (uint
) inum
);
1433 return ERR_PTR(-EACCES
);
1436 if (JFS_SBI(dip
->i_sb
)->mntflag
& JFS_OS2
)
1437 dentry
->d_op
= &jfs_ci_dentry_operations
;
1439 dentry
= d_splice_alias(ip
, dentry
);
1441 if (dentry
&& (JFS_SBI(dip
->i_sb
)->mntflag
& JFS_OS2
))
1442 dentry
->d_op
= &jfs_ci_dentry_operations
;
1447 struct dentry
*jfs_get_parent(struct dentry
*dentry
)
1449 struct super_block
*sb
= dentry
->d_inode
->i_sb
;
1450 struct dentry
*parent
= ERR_PTR(-ENOENT
);
1451 struct inode
*inode
;
1452 unsigned long parent_ino
;
1455 le32_to_cpu(JFS_IP(dentry
->d_inode
)->i_dtroot
.header
.idotdot
);
1456 inode
= iget(sb
, parent_ino
);
1458 if (is_bad_inode(inode
)) {
1460 parent
= ERR_PTR(-EACCES
);
1462 parent
= d_alloc_anon(inode
);
1464 parent
= ERR_PTR(-ENOMEM
);
1473 struct inode_operations jfs_dir_inode_operations
= {
1474 .create
= jfs_create
,
1475 .lookup
= jfs_lookup
,
1477 .unlink
= jfs_unlink
,
1478 .symlink
= jfs_symlink
,
1482 .rename
= jfs_rename
,
1483 .setxattr
= jfs_setxattr
,
1484 .getxattr
= jfs_getxattr
,
1485 .listxattr
= jfs_listxattr
,
1486 .removexattr
= jfs_removexattr
,
1487 #ifdef CONFIG_JFS_POSIX_ACL
1488 .setattr
= jfs_setattr
,
1489 .permission
= jfs_permission
,
1493 struct file_operations jfs_dir_operations
= {
1494 .read
= generic_read_dir
,
1495 .readdir
= jfs_readdir
,
1499 static int jfs_ci_hash(struct dentry
*dir
, struct qstr
*this)
1504 hash
= init_name_hash();
1505 for (i
=0; i
< this->len
; i
++)
1506 hash
= partial_name_hash(tolower(this->name
[i
]), hash
);
1507 this->hash
= end_name_hash(hash
);
1512 static int jfs_ci_compare(struct dentry
*dir
, struct qstr
*a
, struct qstr
*b
)
1516 if (a
->len
!= b
->len
)
1518 for (i
=0; i
< a
->len
; i
++) {
1519 if (tolower(a
->name
[i
]) != tolower(b
->name
[i
]))
1525 * We want creates to preserve case. A negative dentry, a, that
1526 * has a different case than b may cause a new entry to be created
1527 * with the wrong case. Since we can't tell if a comes from a negative
1528 * dentry, we blindly replace it with b. This should be harmless if
1529 * a is not a negative dentry.
1531 memcpy((unsigned char *)a
->name
, b
->name
, a
->len
);
1536 struct dentry_operations jfs_ci_dentry_operations
=
1538 .d_hash
= jfs_ci_hash
,
1539 .d_compare
= jfs_ci_compare
,