2 * linux/fs/ext2/namei.c
4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
11 * linux/fs/minix/namei.c
13 * Copyright (C) 1991, 1992 Linus Torvalds
15 * Big-endian to little-endian byte-swapping/bitmaps by
16 * David S. Miller (davem@caip.rutgers.edu), 1995
17 * Directory entry file type support and forward compatibility hooks
18 * for B-tree directories by Theodore Ts'o (tytso@mit.edu), 1998
21 #include <linux/module.h>
23 #include <linux/locks.h>
24 #include <linux/quotaops.h>
29 * define how far ahead to read directories while searching them.
31 #define NAMEI_RA_CHUNKS 2
32 #define NAMEI_RA_BLOCKS 4
33 #define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS)
34 #define NAMEI_RA_INDEX(c,b) (((c) * NAMEI_RA_BLOCKS) + (b))
37 * NOTE! unlike strncmp, ext2_match returns 1 for success, 0 for failure.
39 * `len <= EXT2_NAME_LEN' is guaranteed by caller.
40 * `de != NULL' is guaranteed by caller.
42 static inline int ext2_match (int len
, const char * const name
,
43 struct ext2_dir_entry_2
* de
)
45 if (len
!= de
->name_len
)
49 return !memcmp(name
, de
->name
, len
);
55 * finds an entry in the specified directory with the wanted name. It
56 * returns the cache buffer in which the entry was found, and the entry
57 * itself (as a parameter - res_dir). It does NOT read the inode of the
58 * entry - you'll have to do that yourself if you want to.
60 static struct buffer_head
* ext2_find_entry (struct inode
* dir
,
61 const char * const name
, int namelen
,
62 struct ext2_dir_entry_2
** res_dir
)
64 struct super_block
* sb
;
65 struct buffer_head
* bh_use
[NAMEI_RA_SIZE
];
66 struct buffer_head
* bh_read
[NAMEI_RA_SIZE
];
68 int block
, toread
, i
, err
;
73 if (namelen
> EXT2_NAME_LEN
)
76 memset (bh_use
, 0, sizeof (bh_use
));
78 for (block
= 0; block
< NAMEI_RA_SIZE
; ++block
) {
79 struct buffer_head
* bh
;
81 if ((block
<< EXT2_BLOCK_SIZE_BITS (sb
)) >= dir
->i_size
)
83 bh
= ext2_getblk (dir
, block
, 0, &err
);
85 if (bh
&& !buffer_uptodate(bh
))
86 bh_read
[toread
++] = bh
;
89 for (block
= 0, offset
= 0; offset
< dir
->i_size
; block
++) {
90 struct buffer_head
* bh
;
91 struct ext2_dir_entry_2
* de
;
94 if ((block
% NAMEI_RA_BLOCKS
) == 0 && toread
) {
95 ll_rw_block (READ
, toread
, bh_read
);
98 bh
= bh_use
[block
% NAMEI_RA_SIZE
];
101 ext2_error (sb
, "ext2_find_entry",
102 "directory #%lu contains a hole at offset %lu",
105 offset
+= sb
->s_blocksize
;
109 if (!buffer_uptodate(bh
)) {
111 * read error: all bets are off
116 de
= (struct ext2_dir_entry_2
*) bh
->b_data
;
117 dlimit
= bh
->b_data
+ sb
->s_blocksize
;
118 while ((char *) de
< dlimit
) {
119 /* this code is executed quadratically often */
120 /* do minimal checking `by hand' */
123 if ((char *) de
+ namelen
<= dlimit
&&
124 ext2_match (namelen
, name
, de
)) {
126 just to be sure, do a full check */
127 if (!ext2_check_dir_entry("ext2_find_entry",
128 dir
, de
, bh
, offset
))
130 for (i
= 0; i
< NAMEI_RA_SIZE
; ++i
) {
137 /* prevent looping on a bad block */
138 de_len
= le16_to_cpu(de
->rec_len
);
142 de
= (struct ext2_dir_entry_2
*)
143 ((char *) de
+ de_len
);
147 if (((block
+ NAMEI_RA_SIZE
) << EXT2_BLOCK_SIZE_BITS (sb
)) >=
151 bh
= ext2_getblk (dir
, block
+ NAMEI_RA_SIZE
, 0, &err
);
152 bh_use
[block
% NAMEI_RA_SIZE
] = bh
;
153 if (bh
&& !buffer_uptodate(bh
))
154 bh_read
[toread
++] = bh
;
158 for (i
= 0; i
< NAMEI_RA_SIZE
; ++i
)
163 struct dentry
*ext2_lookup(struct inode
* dir
, struct dentry
*dentry
)
165 struct inode
* inode
;
166 struct ext2_dir_entry_2
* de
;
167 struct buffer_head
* bh
;
169 if (dentry
->d_name
.len
> EXT2_NAME_LEN
)
170 return ERR_PTR(-ENAMETOOLONG
);
172 bh
= ext2_find_entry (dir
, dentry
->d_name
.name
, dentry
->d_name
.len
, &de
);
175 unsigned long ino
= le32_to_cpu(de
->inode
);
177 inode
= iget(dir
->i_sb
, ino
);
180 return ERR_PTR(-EACCES
);
182 d_add(dentry
, inode
);
189 * adds a file entry to the specified directory, using the same
190 * semantics as ext2_find_entry(). It returns NULL if it failed.
192 * NOTE!! The inode part of 'de' is left at 0 - which means you
193 * may not sleep between calling this and putting something into
194 * the entry, as someone else might have used it while you slept.
196 static struct buffer_head
* ext2_add_entry (struct inode
* dir
,
197 const char * name
, int namelen
,
198 struct ext2_dir_entry_2
** res_dir
,
201 unsigned long offset
;
202 unsigned short rec_len
;
203 struct buffer_head
* bh
;
204 struct ext2_dir_entry_2
* de
, * de1
;
205 struct super_block
* sb
;
209 if (!dir
|| !dir
->i_nlink
)
216 * Is this a busy deleted directory? Can't create new files if so
218 if (dir
->i_size
== 0)
223 bh
= ext2_bread (dir
, 0, 0, err
);
226 rec_len
= EXT2_DIR_REC_LEN(namelen
);
228 de
= (struct ext2_dir_entry_2
*) bh
->b_data
;
231 if ((char *)de
>= sb
->s_blocksize
+ bh
->b_data
) {
234 bh
= ext2_bread (dir
, offset
>> EXT2_BLOCK_SIZE_BITS(sb
), 1, err
);
237 if (dir
->i_size
<= offset
) {
238 if (dir
->i_size
== 0) {
243 ext2_debug ("creating next block\n");
245 de
= (struct ext2_dir_entry_2
*) bh
->b_data
;
247 de
->rec_len
= le16_to_cpu(sb
->s_blocksize
);
248 dir
->i_size
= offset
+ sb
->s_blocksize
;
249 dir
->u
.ext2_i
.i_flags
&= ~EXT2_BTREE_FL
;
250 mark_inode_dirty(dir
);
253 ext2_debug ("skipping to next block\n");
255 de
= (struct ext2_dir_entry_2
*) bh
->b_data
;
258 if (!ext2_check_dir_entry ("ext2_add_entry", dir
, de
, bh
,
264 if (ext2_match (namelen
, name
, de
)) {
269 if ((le32_to_cpu(de
->inode
) == 0 && le16_to_cpu(de
->rec_len
) >= rec_len
) ||
270 (le16_to_cpu(de
->rec_len
) >= EXT2_DIR_REC_LEN(de
->name_len
) + rec_len
)) {
271 offset
+= le16_to_cpu(de
->rec_len
);
272 if (le32_to_cpu(de
->inode
)) {
273 de1
= (struct ext2_dir_entry_2
*) ((char *) de
+
274 EXT2_DIR_REC_LEN(de
->name_len
));
275 de1
->rec_len
= cpu_to_le16(le16_to_cpu(de
->rec_len
) -
276 EXT2_DIR_REC_LEN(de
->name_len
));
277 de
->rec_len
= cpu_to_le16(EXT2_DIR_REC_LEN(de
->name_len
));
281 de
->name_len
= namelen
;
283 memcpy (de
->name
, name
, namelen
);
285 * XXX shouldn't update any times until successful
286 * completion of syscall, but too many callers depend
289 * XXX similarly, too many callers depend on
290 * ext2_new_inode() setting the times, but error
291 * recovery deletes the inode, so the worst that can
292 * happen is that the times are slightly out of date
293 * and/or different from the directory change time.
295 dir
->i_mtime
= dir
->i_ctime
= CURRENT_TIME
;
296 dir
->u
.ext2_i
.i_flags
&= ~EXT2_BTREE_FL
;
297 mark_inode_dirty(dir
);
298 dir
->i_version
= ++event
;
299 mark_buffer_dirty(bh
, 1);
304 offset
+= le16_to_cpu(de
->rec_len
);
305 de
= (struct ext2_dir_entry_2
*) ((char *) de
+ le16_to_cpu(de
->rec_len
));
312 * ext2_delete_entry deletes a directory entry by merging it with the
315 static int ext2_delete_entry (struct ext2_dir_entry_2
* dir
,
316 struct buffer_head
* bh
)
318 struct ext2_dir_entry_2
* de
, * pde
;
323 de
= (struct ext2_dir_entry_2
*) bh
->b_data
;
324 while (i
< bh
->b_size
) {
325 if (!ext2_check_dir_entry ("ext2_delete_entry", NULL
,
331 cpu_to_le16(le16_to_cpu(pde
->rec_len
) +
332 le16_to_cpu(dir
->rec_len
));
337 i
+= le16_to_cpu(de
->rec_len
);
339 de
= (struct ext2_dir_entry_2
*) ((char *) de
+ le16_to_cpu(de
->rec_len
));
344 static inline void ext2_set_de_type(struct super_block
*sb
,
345 struct ext2_dir_entry_2
*de
,
347 if (!EXT2_HAS_INCOMPAT_FEATURE(sb
, EXT2_FEATURE_INCOMPAT_FILETYPE
))
350 de
->file_type
= EXT2_FT_CHRDEV
;
351 else if (S_ISBLK(mode
))
352 de
->file_type
= EXT2_FT_BLKDEV
;
353 else if (S_ISFIFO(mode
))
354 de
->file_type
= EXT2_FT_FIFO
;
355 else if (S_ISLNK(mode
))
356 de
->file_type
= EXT2_FT_SYMLINK
;
357 else if (S_ISREG(mode
))
358 de
->file_type
= EXT2_FT_REG_FILE
;
359 else if (S_ISDIR(mode
))
360 de
->file_type
= EXT2_FT_DIR
;
364 * By the time this is called, we already have created
365 * the directory cache entry for the new file, but it
366 * is so far negative - it has no inode.
368 * If the create succeeds, we fill in the inode information
369 * with d_instantiate().
371 int ext2_create (struct inode
* dir
, struct dentry
* dentry
, int mode
)
373 struct inode
* inode
;
374 struct buffer_head
* bh
;
375 struct ext2_dir_entry_2
* de
;
379 * N.B. Several error exits in ext2_new_inode don't set err.
381 inode
= ext2_new_inode (dir
, mode
, &err
);
385 inode
->i_op
= &ext2_file_inode_operations
;
386 inode
->i_mode
= mode
;
387 mark_inode_dirty(inode
);
388 bh
= ext2_add_entry (dir
, dentry
->d_name
.name
, dentry
->d_name
.len
, &de
, &err
);
391 mark_inode_dirty(inode
);
395 de
->inode
= cpu_to_le32(inode
->i_ino
);
396 ext2_set_de_type(dir
->i_sb
, de
, S_IFREG
);
397 dir
->i_version
= ++event
;
398 mark_buffer_dirty(bh
, 1);
400 ll_rw_block (WRITE
, 1, &bh
);
404 d_instantiate(dentry
, inode
);
408 int ext2_mknod (struct inode
* dir
, struct dentry
*dentry
, int mode
, int rdev
)
410 struct inode
* inode
;
411 struct buffer_head
* bh
;
412 struct ext2_dir_entry_2
* de
;
415 inode
= ext2_new_inode (dir
, mode
, &err
);
419 inode
->i_uid
= current
->fsuid
;
420 init_special_inode(inode
, mode
, rdev
);
421 bh
= ext2_add_entry (dir
, dentry
->d_name
.name
, dentry
->d_name
.len
, &de
, &err
);
424 de
->inode
= cpu_to_le32(inode
->i_ino
);
425 dir
->i_version
= ++event
;
426 ext2_set_de_type(dir
->i_sb
, de
, inode
->i_mode
);
427 mark_inode_dirty(inode
);
428 mark_buffer_dirty(bh
, 1);
430 ll_rw_block (WRITE
, 1, &bh
);
433 d_instantiate(dentry
, inode
);
441 mark_inode_dirty(inode
);
446 int ext2_mkdir(struct inode
* dir
, struct dentry
* dentry
, int mode
)
448 struct inode
* inode
;
449 struct buffer_head
* bh
, * dir_block
;
450 struct ext2_dir_entry_2
* de
;
454 if (dir
->i_nlink
>= EXT2_LINK_MAX
)
458 inode
= ext2_new_inode (dir
, S_IFDIR
, &err
);
462 inode
->i_op
= &ext2_dir_inode_operations
;
463 inode
->i_size
= inode
->i_sb
->s_blocksize
;
465 dir_block
= ext2_bread (inode
, 0, 1, &err
);
467 inode
->i_nlink
--; /* is this nlink == 0? */
468 mark_inode_dirty(inode
);
472 de
= (struct ext2_dir_entry_2
*) dir_block
->b_data
;
473 de
->inode
= cpu_to_le32(inode
->i_ino
);
475 de
->rec_len
= cpu_to_le16(EXT2_DIR_REC_LEN(de
->name_len
));
476 strcpy (de
->name
, ".");
477 ext2_set_de_type(dir
->i_sb
, de
, S_IFDIR
);
478 de
= (struct ext2_dir_entry_2
*) ((char *) de
+ le16_to_cpu(de
->rec_len
));
479 de
->inode
= cpu_to_le32(dir
->i_ino
);
480 de
->rec_len
= cpu_to_le16(inode
->i_sb
->s_blocksize
- EXT2_DIR_REC_LEN(1));
482 strcpy (de
->name
, "..");
483 ext2_set_de_type(dir
->i_sb
, de
, S_IFDIR
);
485 mark_buffer_dirty(dir_block
, 1);
487 inode
->i_mode
= S_IFDIR
| mode
;
488 if (dir
->i_mode
& S_ISGID
)
489 inode
->i_mode
|= S_ISGID
;
490 mark_inode_dirty(inode
);
491 bh
= ext2_add_entry (dir
, dentry
->d_name
.name
, dentry
->d_name
.len
, &de
, &err
);
494 de
->inode
= cpu_to_le32(inode
->i_ino
);
495 ext2_set_de_type(dir
->i_sb
, de
, S_IFDIR
);
496 dir
->i_version
= ++event
;
497 mark_buffer_dirty(bh
, 1);
499 ll_rw_block (WRITE
, 1, &bh
);
503 dir
->u
.ext2_i
.i_flags
&= ~EXT2_BTREE_FL
;
504 mark_inode_dirty(dir
);
505 d_instantiate(dentry
, inode
);
513 mark_inode_dirty(inode
);
519 * routine to check that the specified directory is empty (for rmdir)
521 static int empty_dir (struct inode
* inode
)
523 unsigned long offset
;
524 struct buffer_head
* bh
;
525 struct ext2_dir_entry_2
* de
, * de1
;
526 struct super_block
* sb
;
530 if (inode
->i_size
< EXT2_DIR_REC_LEN(1) + EXT2_DIR_REC_LEN(2) ||
531 !(bh
= ext2_bread (inode
, 0, 0, &err
))) {
532 ext2_warning (inode
->i_sb
, "empty_dir",
533 "bad directory (dir #%lu) - no data block",
537 de
= (struct ext2_dir_entry_2
*) bh
->b_data
;
538 de1
= (struct ext2_dir_entry_2
*) ((char *) de
+ le16_to_cpu(de
->rec_len
));
539 if (le32_to_cpu(de
->inode
) != inode
->i_ino
|| !le32_to_cpu(de1
->inode
) ||
540 strcmp (".", de
->name
) || strcmp ("..", de1
->name
)) {
541 ext2_warning (inode
->i_sb
, "empty_dir",
542 "bad directory (dir #%lu) - no `.' or `..'",
547 offset
= le16_to_cpu(de
->rec_len
) + le16_to_cpu(de1
->rec_len
);
548 de
= (struct ext2_dir_entry_2
*) ((char *) de1
+ le16_to_cpu(de1
->rec_len
));
549 while (offset
< inode
->i_size
) {
550 if (!bh
|| (void *) de
>= (void *) (bh
->b_data
+ sb
->s_blocksize
)) {
552 bh
= ext2_bread (inode
, offset
>> EXT2_BLOCK_SIZE_BITS(sb
), 0, &err
);
555 ext2_error (sb
, "empty_dir",
556 "directory #%lu contains a hole at offset %lu",
557 inode
->i_ino
, offset
);
559 offset
+= sb
->s_blocksize
;
562 de
= (struct ext2_dir_entry_2
*) bh
->b_data
;
564 if (!ext2_check_dir_entry ("empty_dir", inode
, de
, bh
,
569 if (le32_to_cpu(de
->inode
)) {
573 offset
+= le16_to_cpu(de
->rec_len
);
574 de
= (struct ext2_dir_entry_2
*) ((char *) de
+ le16_to_cpu(de
->rec_len
));
580 int ext2_rmdir (struct inode
* dir
, struct dentry
*dentry
)
583 struct inode
* inode
;
584 struct buffer_head
* bh
;
585 struct ext2_dir_entry_2
* de
;
588 bh
= ext2_find_entry (dir
, dentry
->d_name
.name
, dentry
->d_name
.len
, &de
);
592 inode
= dentry
->d_inode
;
596 if (le32_to_cpu(de
->inode
) != inode
->i_ino
)
600 if (!empty_dir (inode
))
603 retval
= ext2_delete_entry (de
, bh
);
604 dir
->i_version
= ++event
;
607 mark_buffer_dirty(bh
, 1);
609 ll_rw_block (WRITE
, 1, &bh
);
612 if (inode
->i_nlink
!= 2)
613 ext2_warning (inode
->i_sb
, "ext2_rmdir",
614 "empty directory has nlink!=2 (%d)",
616 inode
->i_version
= ++event
;
619 mark_inode_dirty(inode
);
621 inode
->i_ctime
= dir
->i_ctime
= dir
->i_mtime
= CURRENT_TIME
;
622 dir
->u
.ext2_i
.i_flags
&= ~EXT2_BTREE_FL
;
623 mark_inode_dirty(dir
);
631 int ext2_unlink(struct inode
* dir
, struct dentry
*dentry
)
634 struct inode
* inode
;
635 struct buffer_head
* bh
;
636 struct ext2_dir_entry_2
* de
;
639 bh
= ext2_find_entry (dir
, dentry
->d_name
.name
, dentry
->d_name
.len
, &de
);
643 inode
= dentry
->d_inode
;
647 if (le32_to_cpu(de
->inode
) != inode
->i_ino
)
650 if (!inode
->i_nlink
) {
651 ext2_warning (inode
->i_sb
, "ext2_unlink",
652 "Deleting nonexistent file (%lu), %d",
653 inode
->i_ino
, inode
->i_nlink
);
656 retval
= ext2_delete_entry (de
, bh
);
659 dir
->i_version
= ++event
;
660 mark_buffer_dirty(bh
, 1);
662 ll_rw_block (WRITE
, 1, &bh
);
665 dir
->i_ctime
= dir
->i_mtime
= CURRENT_TIME
;
666 dir
->u
.ext2_i
.i_flags
&= ~EXT2_BTREE_FL
;
667 mark_inode_dirty(dir
);
669 mark_inode_dirty(inode
);
670 inode
->i_ctime
= dir
->i_ctime
;
672 d_delete(dentry
); /* This also frees the inode */
679 int ext2_symlink (struct inode
* dir
, struct dentry
*dentry
, const char * symname
)
681 struct ext2_dir_entry_2
* de
;
682 struct inode
* inode
;
683 struct buffer_head
* bh
= NULL
, * name_block
= NULL
;
685 int i
, l
, err
= -EIO
;
688 if (!(inode
= ext2_new_inode (dir
, S_IFLNK
, &err
))) {
691 inode
->i_mode
= S_IFLNK
| S_IRWXUGO
;
692 inode
->i_op
= &ext2_symlink_inode_operations
;
693 for (l
= 0; l
< inode
->i_sb
->s_blocksize
- 1 &&
696 if (l
>= sizeof (inode
->u
.ext2_i
.i_data
)) {
698 ext2_debug ("l=%d, normal symlink\n", l
);
700 name_block
= ext2_bread (inode
, 0, 1, &err
);
703 mark_inode_dirty(inode
);
707 link
= name_block
->b_data
;
709 link
= (char *) inode
->u
.ext2_i
.i_data
;
711 ext2_debug ("l=%d, fast symlink\n", l
);
715 while (i
< inode
->i_sb
->s_blocksize
- 1 && (c
= *(symname
++)))
719 mark_buffer_dirty(name_block
, 1);
723 mark_inode_dirty(inode
);
725 bh
= ext2_add_entry (dir
, dentry
->d_name
.name
, dentry
->d_name
.len
, &de
, &err
);
728 de
->inode
= cpu_to_le32(inode
->i_ino
);
729 ext2_set_de_type(dir
->i_sb
, de
, S_IFLNK
);
730 dir
->i_version
= ++event
;
731 mark_buffer_dirty(bh
, 1);
733 ll_rw_block (WRITE
, 1, &bh
);
737 d_instantiate(dentry
, inode
);
744 mark_inode_dirty(inode
);
749 int ext2_link (struct dentry
* old_dentry
,
750 struct inode
* dir
, struct dentry
*dentry
)
752 struct inode
*inode
= old_dentry
->d_inode
;
753 struct ext2_dir_entry_2
* de
;
754 struct buffer_head
* bh
;
757 if (S_ISDIR(inode
->i_mode
))
760 if (inode
->i_nlink
>= EXT2_LINK_MAX
)
763 bh
= ext2_add_entry (dir
, dentry
->d_name
.name
, dentry
->d_name
.len
, &de
, &err
);
767 de
->inode
= cpu_to_le32(inode
->i_ino
);
768 ext2_set_de_type(dir
->i_sb
, de
, inode
->i_mode
);
769 dir
->i_version
= ++event
;
770 mark_buffer_dirty(bh
, 1);
772 ll_rw_block (WRITE
, 1, &bh
);
777 inode
->i_ctime
= CURRENT_TIME
;
778 mark_inode_dirty(inode
);
780 d_instantiate(dentry
, inode
);
784 #define PARENT_INO(buffer) \
785 ((struct ext2_dir_entry_2 *) ((char *) buffer + \
786 le16_to_cpu(((struct ext2_dir_entry_2 *) buffer)->rec_len)))->inode
789 * Anybody can rename anything with this: the permission checks are left to the
790 * higher-level routines.
792 int ext2_rename (struct inode
* old_dir
, struct dentry
*old_dentry
,
793 struct inode
* new_dir
,struct dentry
*new_dentry
)
795 struct inode
* old_inode
, * new_inode
;
796 struct buffer_head
* old_bh
, * new_bh
, * dir_bh
;
797 struct ext2_dir_entry_2
* old_de
, * new_de
;
800 old_bh
= new_bh
= dir_bh
= NULL
;
802 old_bh
= ext2_find_entry (old_dir
, old_dentry
->d_name
.name
, old_dentry
->d_name
.len
, &old_de
);
804 * Check for inode number is _not_ due to possible IO errors.
805 * We might rmdir the source, keep it as pwd of some process
806 * and merrily kill the link to whatever was created under the
807 * same name. Goodbye sticky bit ;-<
809 old_inode
= old_dentry
->d_inode
;
811 if (!old_bh
|| le32_to_cpu(old_de
->inode
) != old_inode
->i_ino
)
814 new_inode
= new_dentry
->d_inode
;
815 new_bh
= ext2_find_entry (new_dir
, new_dentry
->d_name
.name
,
816 new_dentry
->d_name
.len
, &new_de
);
822 DQUOT_INIT(new_inode
);
825 if (S_ISDIR(old_inode
->i_mode
)) {
828 if (!empty_dir (new_inode
))
832 dir_bh
= ext2_bread (old_inode
, 0, 0, &retval
);
835 if (le32_to_cpu(PARENT_INO(dir_bh
->b_data
)) != old_dir
->i_ino
)
838 if (!new_inode
&& new_dir
!=old_dir
&&
839 new_dir
->i_nlink
>= EXT2_LINK_MAX
)
843 new_bh
= ext2_add_entry (new_dir
, new_dentry
->d_name
.name
,
844 new_dentry
->d_name
.len
, &new_de
,
849 new_dir
->i_version
= ++event
;
854 new_de
->inode
= le32_to_cpu(old_inode
->i_ino
);
855 if (EXT2_HAS_INCOMPAT_FEATURE(new_dir
->i_sb
,
856 EXT2_FEATURE_INCOMPAT_FILETYPE
))
857 new_de
->file_type
= old_de
->file_type
;
859 ext2_delete_entry (old_de
, old_bh
);
861 old_dir
->i_version
= ++event
;
863 new_inode
->i_nlink
--;
864 new_inode
->i_ctime
= CURRENT_TIME
;
865 mark_inode_dirty(new_inode
);
867 old_dir
->i_ctime
= old_dir
->i_mtime
= CURRENT_TIME
;
868 old_dir
->u
.ext2_i
.i_flags
&= ~EXT2_BTREE_FL
;
869 mark_inode_dirty(old_dir
);
871 PARENT_INO(dir_bh
->b_data
) = le32_to_cpu(new_dir
->i_ino
);
872 mark_buffer_dirty(dir_bh
, 1);
874 mark_inode_dirty(old_dir
);
876 new_inode
->i_nlink
--;
877 mark_inode_dirty(new_inode
);
880 new_dir
->u
.ext2_i
.i_flags
&= ~EXT2_BTREE_FL
;
881 mark_inode_dirty(new_dir
);
884 mark_buffer_dirty(old_bh
, 1);
885 if (IS_SYNC(old_dir
)) {
886 ll_rw_block (WRITE
, 1, &old_bh
);
887 wait_on_buffer (old_bh
);
889 mark_buffer_dirty(new_bh
, 1);
890 if (IS_SYNC(new_dir
)) {
891 ll_rw_block (WRITE
, 1, &new_bh
);
892 wait_on_buffer (new_bh
);