1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
6 * Creates, reads, walks and deletes directory-nodes
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
10 * Portions of this code from linux/fs/ext3/dir.c
12 * Copyright (C) 1992, 1993, 1994, 1995
13 * Remy Card (card@masi.ibp.fr)
14 * Laboratoire MASI - Institut Blaise pascal
15 * Universite Pierre et Marie Curie (Paris VI)
19 * linux/fs/minix/dir.c
21 * Copyright (C) 1991, 1992 Linux Torvalds
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public
25 * License as published by the Free Software Foundation; either
26 * version 2 of the License, or (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 * General Public License for more details.
33 * You should have received a copy of the GNU General Public
34 * License along with this program; if not, write to the
35 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
36 * Boston, MA 021110-1307, USA.
40 #include <linux/types.h>
41 #include <linux/slab.h>
42 #include <linux/highmem.h>
44 #define MLOG_MASK_PREFIX ML_NAMEI
45 #include <cluster/masklog.h>
52 #include "extent_map.h"
61 #include "buffer_head_io.h"
63 #define NAMEI_RA_CHUNKS 2
64 #define NAMEI_RA_BLOCKS 4
65 #define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS)
66 #define NAMEI_RA_INDEX(c,b) (((c) * NAMEI_RA_BLOCKS) + (b))
68 static unsigned char ocfs2_filetype_table
[] = {
69 DT_UNKNOWN
, DT_REG
, DT_DIR
, DT_CHR
, DT_BLK
, DT_FIFO
, DT_SOCK
, DT_LNK
72 static int ocfs2_extend_dir(struct ocfs2_super
*osb
,
74 struct buffer_head
*parent_fe_bh
,
75 unsigned int blocks_wanted
,
76 struct buffer_head
**new_de_bh
);
77 static int ocfs2_do_extend_dir(struct super_block
*sb
,
80 struct buffer_head
*parent_fe_bh
,
81 struct ocfs2_alloc_context
*data_ac
,
82 struct ocfs2_alloc_context
*meta_ac
,
83 struct buffer_head
**new_bh
);
85 static struct buffer_head
*ocfs2_bread(struct inode
*inode
,
86 int block
, int *err
, int reada
)
88 struct buffer_head
*bh
= NULL
;
94 readflags
|= OCFS2_BH_READAHEAD
;
96 if (((u64
)block
<< inode
->i_sb
->s_blocksize_bits
) >=
102 down_read(&OCFS2_I(inode
)->ip_alloc_sem
);
103 tmperr
= ocfs2_extent_map_get_blocks(inode
, block
, &p_blkno
, NULL
,
105 up_read(&OCFS2_I(inode
)->ip_alloc_sem
);
111 tmperr
= ocfs2_read_blocks(inode
, p_blkno
, 1, &bh
, readflags
);
129 * bh passed here can be an inode block or a dir data block, depending
130 * on the inode inline data flag.
132 static int ocfs2_check_dir_entry(struct inode
* dir
,
133 struct ocfs2_dir_entry
* de
,
134 struct buffer_head
* bh
,
135 unsigned long offset
)
137 const char *error_msg
= NULL
;
138 const int rlen
= le16_to_cpu(de
->rec_len
);
140 if (rlen
< OCFS2_DIR_REC_LEN(1))
141 error_msg
= "rec_len is smaller than minimal";
142 else if (rlen
% 4 != 0)
143 error_msg
= "rec_len % 4 != 0";
144 else if (rlen
< OCFS2_DIR_REC_LEN(de
->name_len
))
145 error_msg
= "rec_len is too small for name_len";
146 else if (((char *) de
- bh
->b_data
) + rlen
> dir
->i_sb
->s_blocksize
)
147 error_msg
= "directory entry across blocks";
149 if (error_msg
!= NULL
)
150 mlog(ML_ERROR
, "bad entry in directory #%llu: %s - "
151 "offset=%lu, inode=%llu, rec_len=%d, name_len=%d\n",
152 (unsigned long long)OCFS2_I(dir
)->ip_blkno
, error_msg
,
153 offset
, (unsigned long long)le64_to_cpu(de
->inode
), rlen
,
155 return error_msg
== NULL
? 1 : 0;
158 static inline int ocfs2_match(int len
,
159 const char * const name
,
160 struct ocfs2_dir_entry
*de
)
162 if (len
!= de
->name_len
)
166 return !memcmp(name
, de
->name
, len
);
170 * Returns 0 if not found, -1 on failure, and 1 on success
172 static int inline ocfs2_search_dirblock(struct buffer_head
*bh
,
174 const char *name
, int namelen
,
175 unsigned long offset
,
178 struct ocfs2_dir_entry
**res_dir
)
180 struct ocfs2_dir_entry
*de
;
181 char *dlimit
, *de_buf
;
188 dlimit
= de_buf
+ bytes
;
190 while (de_buf
< dlimit
) {
191 /* this code is executed quadratically often */
192 /* do minimal checking `by hand' */
194 de
= (struct ocfs2_dir_entry
*) de_buf
;
196 if (de_buf
+ namelen
<= dlimit
&&
197 ocfs2_match(namelen
, name
, de
)) {
198 /* found a match - just to be sure, do a full check */
199 if (!ocfs2_check_dir_entry(dir
, de
, bh
, offset
)) {
208 /* prevent looping on a bad block */
209 de_len
= le16_to_cpu(de
->rec_len
);
224 static struct buffer_head
*ocfs2_find_entry_id(const char *name
,
227 struct ocfs2_dir_entry
**res_dir
)
230 struct buffer_head
*di_bh
= NULL
;
231 struct ocfs2_dinode
*di
;
232 struct ocfs2_inline_data
*data
;
234 ret
= ocfs2_read_block(dir
, OCFS2_I(dir
)->ip_blkno
, &di_bh
);
240 di
= (struct ocfs2_dinode
*)di_bh
->b_data
;
241 data
= &di
->id2
.i_data
;
243 found
= ocfs2_search_dirblock(di_bh
, dir
, name
, namelen
, 0,
244 data
->id_data
, i_size_read(dir
), res_dir
);
253 static struct buffer_head
*ocfs2_find_entry_el(const char *name
, int namelen
,
255 struct ocfs2_dir_entry
**res_dir
)
257 struct super_block
*sb
;
258 struct buffer_head
*bh_use
[NAMEI_RA_SIZE
];
259 struct buffer_head
*bh
, *ret
= NULL
;
260 unsigned long start
, block
, b
;
261 int ra_max
= 0; /* Number of bh's in the readahead
263 int ra_ptr
= 0; /* Current index into readahead
272 nblocks
= i_size_read(dir
) >> sb
->s_blocksize_bits
;
273 start
= OCFS2_I(dir
)->ip_dir_start_lookup
;
274 if (start
>= nblocks
)
281 * We deal with the read-ahead logic here.
283 if (ra_ptr
>= ra_max
) {
284 /* Refill the readahead buffer */
287 for (ra_max
= 0; ra_max
< NAMEI_RA_SIZE
; ra_max
++) {
289 * Terminate if we reach the end of the
290 * directory and must wrap, or if our
291 * search has finished at this block.
293 if (b
>= nblocks
|| (num
&& block
== start
)) {
294 bh_use
[ra_max
] = NULL
;
299 bh
= ocfs2_bread(dir
, b
++, &err
, 1);
303 if ((bh
= bh_use
[ra_ptr
++]) == NULL
)
305 if (ocfs2_read_block(dir
, block
, &bh
)) {
306 /* read error, skip block & hope for the best.
307 * ocfs2_read_block() has released the bh. */
308 ocfs2_error(dir
->i_sb
, "reading directory %llu, "
310 (unsigned long long)OCFS2_I(dir
)->ip_blkno
,
314 i
= ocfs2_search_dirblock(bh
, dir
, name
, namelen
,
315 block
<< sb
->s_blocksize_bits
,
316 bh
->b_data
, sb
->s_blocksize
,
319 OCFS2_I(dir
)->ip_dir_start_lookup
= block
;
321 goto cleanup_and_exit
;
325 goto cleanup_and_exit
;
328 if (++block
>= nblocks
)
330 } while (block
!= start
);
333 * If the directory has grown while we were searching, then
334 * search the last part of the directory before giving up.
337 nblocks
= i_size_read(dir
) >> sb
->s_blocksize_bits
;
338 if (block
< nblocks
) {
344 /* Clean up the read-ahead blocks */
345 for (; ra_ptr
< ra_max
; ra_ptr
++)
346 brelse(bh_use
[ra_ptr
]);
353 * Try to find an entry of the provided name within 'dir'.
355 * If nothing was found, NULL is returned. Otherwise, a buffer_head
356 * and pointer to the dir entry are passed back.
358 * Caller can NOT assume anything about the contents of the
359 * buffer_head - it is passed back only so that it can be passed into
360 * any one of the manipulation functions (add entry, delete entry,
361 * etc). As an example, bh in the extent directory case is a data
362 * block, in the inline-data case it actually points to an inode.
364 struct buffer_head
*ocfs2_find_entry(const char *name
, int namelen
,
366 struct ocfs2_dir_entry
**res_dir
)
370 if (OCFS2_I(dir
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
)
371 return ocfs2_find_entry_id(name
, namelen
, dir
, res_dir
);
373 return ocfs2_find_entry_el(name
, namelen
, dir
, res_dir
);
377 * Update inode number and type of a previously found directory entry.
379 int ocfs2_update_entry(struct inode
*dir
, handle_t
*handle
,
380 struct buffer_head
*de_bh
, struct ocfs2_dir_entry
*de
,
381 struct inode
*new_entry_inode
)
386 * The same code works fine for both inline-data and extent
387 * based directories, so no need to split this up.
390 ret
= ocfs2_journal_access(handle
, dir
, de_bh
,
391 OCFS2_JOURNAL_ACCESS_WRITE
);
397 de
->inode
= cpu_to_le64(OCFS2_I(new_entry_inode
)->ip_blkno
);
398 ocfs2_set_de_type(de
, new_entry_inode
->i_mode
);
400 ocfs2_journal_dirty(handle
, de_bh
);
406 static int __ocfs2_delete_entry(handle_t
*handle
, struct inode
*dir
,
407 struct ocfs2_dir_entry
*de_del
,
408 struct buffer_head
*bh
, char *first_de
,
411 struct ocfs2_dir_entry
*de
, *pde
;
412 int i
, status
= -ENOENT
;
414 mlog_entry("(0x%p, 0x%p, 0x%p, 0x%p)\n", handle
, dir
, de_del
, bh
);
418 de
= (struct ocfs2_dir_entry
*) first_de
;
420 if (!ocfs2_check_dir_entry(dir
, de
, bh
, i
)) {
426 status
= ocfs2_journal_access(handle
, dir
, bh
,
427 OCFS2_JOURNAL_ACCESS_WRITE
);
434 le16_add_cpu(&pde
->rec_len
,
435 le16_to_cpu(de
->rec_len
));
439 status
= ocfs2_journal_dirty(handle
, bh
);
442 i
+= le16_to_cpu(de
->rec_len
);
444 de
= (struct ocfs2_dir_entry
*)((char *)de
+ le16_to_cpu(de
->rec_len
));
451 static inline int ocfs2_delete_entry_id(handle_t
*handle
,
453 struct ocfs2_dir_entry
*de_del
,
454 struct buffer_head
*bh
)
457 struct buffer_head
*di_bh
= NULL
;
458 struct ocfs2_dinode
*di
;
459 struct ocfs2_inline_data
*data
;
461 ret
= ocfs2_read_block(dir
, OCFS2_I(dir
)->ip_blkno
, &di_bh
);
467 di
= (struct ocfs2_dinode
*)di_bh
->b_data
;
468 data
= &di
->id2
.i_data
;
470 ret
= __ocfs2_delete_entry(handle
, dir
, de_del
, bh
, data
->id_data
,
478 static inline int ocfs2_delete_entry_el(handle_t
*handle
,
480 struct ocfs2_dir_entry
*de_del
,
481 struct buffer_head
*bh
)
483 return __ocfs2_delete_entry(handle
, dir
, de_del
, bh
, bh
->b_data
,
488 * ocfs2_delete_entry deletes a directory entry by merging it with the
491 int ocfs2_delete_entry(handle_t
*handle
,
493 struct ocfs2_dir_entry
*de_del
,
494 struct buffer_head
*bh
)
496 if (OCFS2_I(dir
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
)
497 return ocfs2_delete_entry_id(handle
, dir
, de_del
, bh
);
499 return ocfs2_delete_entry_el(handle
, dir
, de_del
, bh
);
503 * Check whether 'de' has enough room to hold an entry of
504 * 'new_rec_len' bytes.
506 static inline int ocfs2_dirent_would_fit(struct ocfs2_dir_entry
*de
,
507 unsigned int new_rec_len
)
509 unsigned int de_really_used
;
511 /* Check whether this is an empty record with enough space */
512 if (le64_to_cpu(de
->inode
) == 0 &&
513 le16_to_cpu(de
->rec_len
) >= new_rec_len
)
517 * Record might have free space at the end which we can
520 de_really_used
= OCFS2_DIR_REC_LEN(de
->name_len
);
521 if (le16_to_cpu(de
->rec_len
) >= (de_really_used
+ new_rec_len
))
527 /* we don't always have a dentry for what we want to add, so people
528 * like orphan dir can call this instead.
530 * If you pass me insert_bh, I'll skip the search of the other dir
531 * blocks and put the record in there.
533 int __ocfs2_add_entry(handle_t
*handle
,
535 const char *name
, int namelen
,
536 struct inode
*inode
, u64 blkno
,
537 struct buffer_head
*parent_fe_bh
,
538 struct buffer_head
*insert_bh
)
540 unsigned long offset
;
541 unsigned short rec_len
;
542 struct ocfs2_dir_entry
*de
, *de1
;
543 struct ocfs2_dinode
*di
= (struct ocfs2_dinode
*)parent_fe_bh
->b_data
;
544 struct super_block
*sb
= dir
->i_sb
;
546 unsigned int size
= sb
->s_blocksize
;
547 char *data_start
= insert_bh
->b_data
;
554 if (OCFS2_I(dir
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
) {
555 data_start
= di
->id2
.i_data
.id_data
;
556 size
= i_size_read(dir
);
558 BUG_ON(insert_bh
!= parent_fe_bh
);
561 rec_len
= OCFS2_DIR_REC_LEN(namelen
);
563 de
= (struct ocfs2_dir_entry
*) data_start
;
565 BUG_ON((char *)de
>= (size
+ data_start
));
567 /* These checks should've already been passed by the
568 * prepare function, but I guess we can leave them
570 if (!ocfs2_check_dir_entry(dir
, de
, insert_bh
, offset
)) {
574 if (ocfs2_match(namelen
, name
, de
)) {
579 if (ocfs2_dirent_would_fit(de
, rec_len
)) {
580 dir
->i_mtime
= dir
->i_ctime
= CURRENT_TIME
;
581 retval
= ocfs2_mark_inode_dirty(handle
, dir
, parent_fe_bh
);
587 status
= ocfs2_journal_access(handle
, dir
, insert_bh
,
588 OCFS2_JOURNAL_ACCESS_WRITE
);
589 /* By now the buffer is marked for journaling */
590 offset
+= le16_to_cpu(de
->rec_len
);
591 if (le64_to_cpu(de
->inode
)) {
592 de1
= (struct ocfs2_dir_entry
*)((char *) de
+
593 OCFS2_DIR_REC_LEN(de
->name_len
));
595 cpu_to_le16(le16_to_cpu(de
->rec_len
) -
596 OCFS2_DIR_REC_LEN(de
->name_len
));
597 de
->rec_len
= cpu_to_le16(OCFS2_DIR_REC_LEN(de
->name_len
));
600 de
->file_type
= OCFS2_FT_UNKNOWN
;
602 de
->inode
= cpu_to_le64(blkno
);
603 ocfs2_set_de_type(de
, inode
->i_mode
);
606 de
->name_len
= namelen
;
607 memcpy(de
->name
, name
, namelen
);
610 status
= ocfs2_journal_dirty(handle
, insert_bh
);
614 offset
+= le16_to_cpu(de
->rec_len
);
615 de
= (struct ocfs2_dir_entry
*) ((char *) de
+ le16_to_cpu(de
->rec_len
));
618 /* when you think about it, the assert above should prevent us
619 * from ever getting here. */
627 static int ocfs2_dir_foreach_blk_id(struct inode
*inode
,
629 loff_t
*f_pos
, void *priv
,
630 filldir_t filldir
, int *filldir_err
)
632 int ret
, i
, filldir_ret
;
633 unsigned long offset
= *f_pos
;
634 struct buffer_head
*di_bh
= NULL
;
635 struct ocfs2_dinode
*di
;
636 struct ocfs2_inline_data
*data
;
637 struct ocfs2_dir_entry
*de
;
639 ret
= ocfs2_read_block(inode
, OCFS2_I(inode
)->ip_blkno
, &di_bh
);
641 mlog(ML_ERROR
, "Unable to read inode block for dir %llu\n",
642 (unsigned long long)OCFS2_I(inode
)->ip_blkno
);
646 di
= (struct ocfs2_dinode
*)di_bh
->b_data
;
647 data
= &di
->id2
.i_data
;
649 while (*f_pos
< i_size_read(inode
)) {
651 /* If the dir block has changed since the last call to
652 * readdir(2), then we might be pointing to an invalid
653 * dirent right now. Scan from the start of the block
655 if (*f_version
!= inode
->i_version
) {
656 for (i
= 0; i
< i_size_read(inode
) && i
< offset
; ) {
657 de
= (struct ocfs2_dir_entry
*)
659 /* It's too expensive to do a full
660 * dirent test each time round this
661 * loop, but we do have to test at
662 * least that it is non-zero. A
663 * failure will be detected in the
664 * dirent test below. */
665 if (le16_to_cpu(de
->rec_len
) <
666 OCFS2_DIR_REC_LEN(1))
668 i
+= le16_to_cpu(de
->rec_len
);
671 *f_version
= inode
->i_version
;
674 de
= (struct ocfs2_dir_entry
*) (data
->id_data
+ *f_pos
);
675 if (!ocfs2_check_dir_entry(inode
, de
, di_bh
, *f_pos
)) {
676 /* On error, skip the f_pos to the end. */
677 *f_pos
= i_size_read(inode
);
680 offset
+= le16_to_cpu(de
->rec_len
);
681 if (le64_to_cpu(de
->inode
)) {
682 /* We might block in the next section
683 * if the data destination is
684 * currently swapped out. So, use a
685 * version stamp to detect whether or
686 * not the directory has been modified
687 * during the copy operation.
689 u64 version
= *f_version
;
690 unsigned char d_type
= DT_UNKNOWN
;
692 if (de
->file_type
< OCFS2_FT_MAX
)
693 d_type
= ocfs2_filetype_table
[de
->file_type
];
695 filldir_ret
= filldir(priv
, de
->name
,
698 le64_to_cpu(de
->inode
),
702 *filldir_err
= filldir_ret
;
705 if (version
!= *f_version
)
708 *f_pos
+= le16_to_cpu(de
->rec_len
);
717 static int ocfs2_dir_foreach_blk_el(struct inode
*inode
,
719 loff_t
*f_pos
, void *priv
,
720 filldir_t filldir
, int *filldir_err
)
723 unsigned long offset
, blk
, last_ra_blk
= 0;
725 struct buffer_head
* bh
, * tmp
;
726 struct ocfs2_dir_entry
* de
;
728 struct super_block
* sb
= inode
->i_sb
;
729 unsigned int ra_sectors
= 16;
734 offset
= (*f_pos
) & (sb
->s_blocksize
- 1);
736 while (!error
&& !stored
&& *f_pos
< i_size_read(inode
)) {
737 blk
= (*f_pos
) >> sb
->s_blocksize_bits
;
738 bh
= ocfs2_bread(inode
, blk
, &err
, 0);
741 "directory #%llu contains a hole at offset %lld\n",
742 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
744 *f_pos
+= sb
->s_blocksize
- offset
;
748 /* The idea here is to begin with 8k read-ahead and to stay
749 * 4k ahead of our current position.
751 * TODO: Use the pagecache for this. We just need to
752 * make sure it's cluster-safe... */
754 || (((last_ra_blk
- blk
) << 9) <= (ra_sectors
/ 2))) {
755 for (i
= ra_sectors
>> (sb
->s_blocksize_bits
- 9);
757 tmp
= ocfs2_bread(inode
, ++blk
, &err
, 1);
765 /* If the dir block has changed since the last call to
766 * readdir(2), then we might be pointing to an invalid
767 * dirent right now. Scan from the start of the block
769 if (*f_version
!= inode
->i_version
) {
770 for (i
= 0; i
< sb
->s_blocksize
&& i
< offset
; ) {
771 de
= (struct ocfs2_dir_entry
*) (bh
->b_data
+ i
);
772 /* It's too expensive to do a full
773 * dirent test each time round this
774 * loop, but we do have to test at
775 * least that it is non-zero. A
776 * failure will be detected in the
777 * dirent test below. */
778 if (le16_to_cpu(de
->rec_len
) <
779 OCFS2_DIR_REC_LEN(1))
781 i
+= le16_to_cpu(de
->rec_len
);
784 *f_pos
= ((*f_pos
) & ~(sb
->s_blocksize
- 1))
786 *f_version
= inode
->i_version
;
789 while (!error
&& *f_pos
< i_size_read(inode
)
790 && offset
< sb
->s_blocksize
) {
791 de
= (struct ocfs2_dir_entry
*) (bh
->b_data
+ offset
);
792 if (!ocfs2_check_dir_entry(inode
, de
, bh
, offset
)) {
793 /* On error, skip the f_pos to the
795 *f_pos
= ((*f_pos
) | (sb
->s_blocksize
- 1)) + 1;
799 offset
+= le16_to_cpu(de
->rec_len
);
800 if (le64_to_cpu(de
->inode
)) {
801 /* We might block in the next section
802 * if the data destination is
803 * currently swapped out. So, use a
804 * version stamp to detect whether or
805 * not the directory has been modified
806 * during the copy operation.
808 unsigned long version
= *f_version
;
809 unsigned char d_type
= DT_UNKNOWN
;
811 if (de
->file_type
< OCFS2_FT_MAX
)
812 d_type
= ocfs2_filetype_table
[de
->file_type
];
813 error
= filldir(priv
, de
->name
,
816 le64_to_cpu(de
->inode
),
820 *filldir_err
= error
;
823 if (version
!= *f_version
)
827 *f_pos
+= le16_to_cpu(de
->rec_len
);
838 static int ocfs2_dir_foreach_blk(struct inode
*inode
, u64
*f_version
,
839 loff_t
*f_pos
, void *priv
, filldir_t filldir
,
842 if (OCFS2_I(inode
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
)
843 return ocfs2_dir_foreach_blk_id(inode
, f_version
, f_pos
, priv
,
844 filldir
, filldir_err
);
846 return ocfs2_dir_foreach_blk_el(inode
, f_version
, f_pos
, priv
, filldir
,
851 * This is intended to be called from inside other kernel functions,
852 * so we fake some arguments.
854 int ocfs2_dir_foreach(struct inode
*inode
, loff_t
*f_pos
, void *priv
,
857 int ret
= 0, filldir_err
= 0;
858 u64 version
= inode
->i_version
;
860 while (*f_pos
< i_size_read(inode
)) {
861 ret
= ocfs2_dir_foreach_blk(inode
, &version
, f_pos
, priv
,
862 filldir
, &filldir_err
);
863 if (ret
|| filldir_err
)
877 int ocfs2_readdir(struct file
* filp
, void * dirent
, filldir_t filldir
)
880 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
883 mlog_entry("dirino=%llu\n",
884 (unsigned long long)OCFS2_I(inode
)->ip_blkno
);
886 error
= ocfs2_inode_lock_atime(inode
, filp
->f_vfsmnt
, &lock_level
);
887 if (lock_level
&& error
>= 0) {
888 /* We release EX lock which used to update atime
889 * and get PR lock again to reduce contention
890 * on commonly accessed directories. */
891 ocfs2_inode_unlock(inode
, 1);
893 error
= ocfs2_inode_lock(inode
, NULL
, 0);
896 if (error
!= -ENOENT
)
898 /* we haven't got any yet, so propagate the error. */
902 error
= ocfs2_dir_foreach_blk(inode
, &filp
->f_version
, &filp
->f_pos
,
903 dirent
, filldir
, NULL
);
905 ocfs2_inode_unlock(inode
, lock_level
);
914 * NOTE: this should always be called with parent dir i_mutex taken.
916 int ocfs2_find_files_on_disk(const char *name
,
920 struct buffer_head
**dirent_bh
,
921 struct ocfs2_dir_entry
**dirent
)
923 int status
= -ENOENT
;
925 mlog_entry("(name=%.*s, blkno=%p, inode=%p, dirent_bh=%p, dirent=%p)\n",
926 namelen
, name
, blkno
, inode
, dirent_bh
, dirent
);
928 *dirent_bh
= ocfs2_find_entry(name
, namelen
, inode
, dirent
);
929 if (!*dirent_bh
|| !*dirent
) {
934 *blkno
= le64_to_cpu((*dirent
)->inode
);
949 * Convenience function for callers which just want the block number
950 * mapped to a name and don't require the full dirent info, etc.
952 int ocfs2_lookup_ino_from_name(struct inode
*dir
, const char *name
,
953 int namelen
, u64
*blkno
)
956 struct buffer_head
*bh
= NULL
;
957 struct ocfs2_dir_entry
*dirent
= NULL
;
959 ret
= ocfs2_find_files_on_disk(name
, namelen
, blkno
, dir
, &bh
, &dirent
);
965 /* Check for a name within a directory.
967 * Return 0 if the name does not exist
968 * Return -EEXIST if the directory contains the name
970 * Callers should have i_mutex + a cluster lock on dir
972 int ocfs2_check_dir_for_entry(struct inode
*dir
,
977 struct buffer_head
*dirent_bh
= NULL
;
978 struct ocfs2_dir_entry
*dirent
= NULL
;
980 mlog_entry("dir %llu, name '%.*s'\n",
981 (unsigned long long)OCFS2_I(dir
)->ip_blkno
, namelen
, name
);
984 dirent_bh
= ocfs2_find_entry(name
, namelen
, dir
, &dirent
);
996 struct ocfs2_empty_dir_priv
{
998 unsigned seen_dot_dot
;
1001 static int ocfs2_empty_dir_filldir(void *priv
, const char *name
, int name_len
,
1002 loff_t pos
, u64 ino
, unsigned type
)
1004 struct ocfs2_empty_dir_priv
*p
= priv
;
1007 * Check the positions of "." and ".." records to be sure
1008 * they're in the correct place.
1010 if (name_len
== 1 && !strncmp(".", name
, 1) && pos
== 0) {
1015 if (name_len
== 2 && !strncmp("..", name
, 2) &&
1016 pos
== OCFS2_DIR_REC_LEN(1)) {
1017 p
->seen_dot_dot
= 1;
1025 * routine to check that the specified directory is empty (for rmdir)
1027 * Returns 1 if dir is empty, zero otherwise.
1029 int ocfs2_empty_dir(struct inode
*inode
)
1033 struct ocfs2_empty_dir_priv priv
;
1035 memset(&priv
, 0, sizeof(priv
));
1037 ret
= ocfs2_dir_foreach(inode
, &start
, &priv
, ocfs2_empty_dir_filldir
);
1041 if (!priv
.seen_dot
|| !priv
.seen_dot_dot
) {
1042 mlog(ML_ERROR
, "bad directory (dir #%llu) - no `.' or `..'\n",
1043 (unsigned long long)OCFS2_I(inode
)->ip_blkno
);
1045 * XXX: Is it really safe to allow an unlink to continue?
1050 return !priv
.seen_other
;
1053 static void ocfs2_fill_initial_dirents(struct inode
*inode
,
1054 struct inode
*parent
,
1055 char *start
, unsigned int size
)
1057 struct ocfs2_dir_entry
*de
= (struct ocfs2_dir_entry
*)start
;
1059 de
->inode
= cpu_to_le64(OCFS2_I(inode
)->ip_blkno
);
1062 cpu_to_le16(OCFS2_DIR_REC_LEN(de
->name_len
));
1063 strcpy(de
->name
, ".");
1064 ocfs2_set_de_type(de
, S_IFDIR
);
1066 de
= (struct ocfs2_dir_entry
*) ((char *)de
+ le16_to_cpu(de
->rec_len
));
1067 de
->inode
= cpu_to_le64(OCFS2_I(parent
)->ip_blkno
);
1068 de
->rec_len
= cpu_to_le16(size
- OCFS2_DIR_REC_LEN(1));
1070 strcpy(de
->name
, "..");
1071 ocfs2_set_de_type(de
, S_IFDIR
);
1075 * This works together with code in ocfs2_mknod_locked() which sets
1076 * the inline-data flag and initializes the inline-data section.
1078 static int ocfs2_fill_new_dir_id(struct ocfs2_super
*osb
,
1080 struct inode
*parent
,
1081 struct inode
*inode
,
1082 struct buffer_head
*di_bh
)
1085 struct ocfs2_dinode
*di
= (struct ocfs2_dinode
*)di_bh
->b_data
;
1086 struct ocfs2_inline_data
*data
= &di
->id2
.i_data
;
1087 unsigned int size
= le16_to_cpu(data
->id_count
);
1089 ret
= ocfs2_journal_access(handle
, inode
, di_bh
,
1090 OCFS2_JOURNAL_ACCESS_WRITE
);
1096 ocfs2_fill_initial_dirents(inode
, parent
, data
->id_data
, size
);
1098 ocfs2_journal_dirty(handle
, di_bh
);
1104 i_size_write(inode
, size
);
1106 inode
->i_blocks
= ocfs2_inode_sector_count(inode
);
1108 ret
= ocfs2_mark_inode_dirty(handle
, inode
, di_bh
);
1116 static int ocfs2_fill_new_dir_el(struct ocfs2_super
*osb
,
1118 struct inode
*parent
,
1119 struct inode
*inode
,
1120 struct buffer_head
*fe_bh
,
1121 struct ocfs2_alloc_context
*data_ac
)
1124 struct buffer_head
*new_bh
= NULL
;
1128 status
= ocfs2_do_extend_dir(osb
->sb
, handle
, inode
, fe_bh
,
1129 data_ac
, NULL
, &new_bh
);
1135 ocfs2_set_new_buffer_uptodate(inode
, new_bh
);
1137 status
= ocfs2_journal_access(handle
, inode
, new_bh
,
1138 OCFS2_JOURNAL_ACCESS_CREATE
);
1143 memset(new_bh
->b_data
, 0, osb
->sb
->s_blocksize
);
1145 ocfs2_fill_initial_dirents(inode
, parent
, new_bh
->b_data
,
1146 osb
->sb
->s_blocksize
);
1148 status
= ocfs2_journal_dirty(handle
, new_bh
);
1154 i_size_write(inode
, inode
->i_sb
->s_blocksize
);
1156 inode
->i_blocks
= ocfs2_inode_sector_count(inode
);
1157 status
= ocfs2_mark_inode_dirty(handle
, inode
, fe_bh
);
1171 int ocfs2_fill_new_dir(struct ocfs2_super
*osb
,
1173 struct inode
*parent
,
1174 struct inode
*inode
,
1175 struct buffer_head
*fe_bh
,
1176 struct ocfs2_alloc_context
*data_ac
)
1178 BUG_ON(!ocfs2_supports_inline_data(osb
) && data_ac
== NULL
);
1180 if (OCFS2_I(inode
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
)
1181 return ocfs2_fill_new_dir_id(osb
, handle
, parent
, inode
, fe_bh
);
1183 return ocfs2_fill_new_dir_el(osb
, handle
, parent
, inode
, fe_bh
,
1187 static void ocfs2_expand_last_dirent(char *start
, unsigned int old_size
,
1188 unsigned int new_size
)
1190 struct ocfs2_dir_entry
*de
;
1191 struct ocfs2_dir_entry
*prev_de
;
1192 char *de_buf
, *limit
;
1193 unsigned int bytes
= new_size
- old_size
;
1195 limit
= start
+ old_size
;
1197 de
= (struct ocfs2_dir_entry
*)de_buf
;
1200 de_buf
+= le16_to_cpu(de
->rec_len
);
1201 de
= (struct ocfs2_dir_entry
*)de_buf
;
1202 } while (de_buf
< limit
);
1204 le16_add_cpu(&prev_de
->rec_len
, bytes
);
1208 * We allocate enough clusters to fulfill "blocks_wanted", but set
1209 * i_size to exactly one block. Ocfs2_extend_dir() will handle the
1210 * rest automatically for us.
1212 * *first_block_bh is a pointer to the 1st data block allocated to the
1215 static int ocfs2_expand_inline_dir(struct inode
*dir
, struct buffer_head
*di_bh
,
1216 unsigned int blocks_wanted
,
1217 struct buffer_head
**first_block_bh
)
1219 int ret
, credits
= OCFS2_INLINE_TO_EXTENTS_CREDITS
;
1220 u32 alloc
, bit_off
, len
;
1221 struct super_block
*sb
= dir
->i_sb
;
1222 u64 blkno
, bytes
= blocks_wanted
<< sb
->s_blocksize_bits
;
1223 struct ocfs2_super
*osb
= OCFS2_SB(dir
->i_sb
);
1224 struct ocfs2_inode_info
*oi
= OCFS2_I(dir
);
1225 struct ocfs2_alloc_context
*data_ac
;
1226 struct buffer_head
*dirdata_bh
= NULL
;
1227 struct ocfs2_dinode
*di
= (struct ocfs2_dinode
*)di_bh
->b_data
;
1229 struct ocfs2_extent_tree et
;
1231 ocfs2_init_dinode_extent_tree(&et
, dir
, di_bh
);
1233 alloc
= ocfs2_clusters_for_bytes(sb
, bytes
);
1236 * We should never need more than 2 clusters for this -
1237 * maximum dirent size is far less than one block. In fact,
1238 * the only time we'd need more than one cluster is if
1239 * blocksize == clustersize and the dirent won't fit in the
1240 * extra space that the expansion to a single block gives. As
1241 * of today, that only happens on 4k/4k file systems.
1245 ret
= ocfs2_reserve_clusters(osb
, alloc
, &data_ac
);
1251 down_write(&oi
->ip_alloc_sem
);
1254 * Prepare for worst case allocation scenario of two separate
1258 credits
+= OCFS2_SUBALLOC_ALLOC
;
1260 handle
= ocfs2_start_trans(osb
, credits
);
1261 if (IS_ERR(handle
)) {
1262 ret
= PTR_ERR(handle
);
1268 * Try to claim as many clusters as the bitmap can give though
1269 * if we only get one now, that's enough to continue. The rest
1270 * will be claimed after the conversion to extents.
1272 ret
= ocfs2_claim_clusters(osb
, handle
, data_ac
, 1, &bit_off
, &len
);
1279 * Operations are carefully ordered so that we set up the new
1280 * data block first. The conversion from inline data to
1283 blkno
= ocfs2_clusters_to_blocks(dir
->i_sb
, bit_off
);
1284 dirdata_bh
= sb_getblk(sb
, blkno
);
1291 ocfs2_set_new_buffer_uptodate(dir
, dirdata_bh
);
1293 ret
= ocfs2_journal_access(handle
, dir
, dirdata_bh
,
1294 OCFS2_JOURNAL_ACCESS_CREATE
);
1300 memcpy(dirdata_bh
->b_data
, di
->id2
.i_data
.id_data
, i_size_read(dir
));
1301 memset(dirdata_bh
->b_data
+ i_size_read(dir
), 0,
1302 sb
->s_blocksize
- i_size_read(dir
));
1303 ocfs2_expand_last_dirent(dirdata_bh
->b_data
, i_size_read(dir
),
1306 ret
= ocfs2_journal_dirty(handle
, dirdata_bh
);
1313 * Set extent, i_size, etc on the directory. After this, the
1314 * inode should contain the same exact dirents as before and
1315 * be fully accessible from system calls.
1317 * We let the later dirent insert modify c/mtime - to the user
1318 * the data hasn't changed.
1320 ret
= ocfs2_journal_access(handle
, dir
, di_bh
,
1321 OCFS2_JOURNAL_ACCESS_CREATE
);
1327 spin_lock(&oi
->ip_lock
);
1328 oi
->ip_dyn_features
&= ~OCFS2_INLINE_DATA_FL
;
1329 di
->i_dyn_features
= cpu_to_le16(oi
->ip_dyn_features
);
1330 spin_unlock(&oi
->ip_lock
);
1332 ocfs2_dinode_new_extent_list(dir
, di
);
1334 i_size_write(dir
, sb
->s_blocksize
);
1335 dir
->i_mtime
= dir
->i_ctime
= CURRENT_TIME
;
1337 di
->i_size
= cpu_to_le64(sb
->s_blocksize
);
1338 di
->i_ctime
= di
->i_mtime
= cpu_to_le64(dir
->i_ctime
.tv_sec
);
1339 di
->i_ctime_nsec
= di
->i_mtime_nsec
= cpu_to_le32(dir
->i_ctime
.tv_nsec
);
1342 * This should never fail as our extent list is empty and all
1343 * related blocks have been journaled already.
1345 ret
= ocfs2_insert_extent(osb
, handle
, dir
, &et
, 0, blkno
, len
,
1353 * Set i_blocks after the extent insert for the most up to
1354 * date ip_clusters value.
1356 dir
->i_blocks
= ocfs2_inode_sector_count(dir
);
1358 ret
= ocfs2_journal_dirty(handle
, di_bh
);
1365 * We asked for two clusters, but only got one in the 1st
1366 * pass. Claim the 2nd cluster as a separate extent.
1369 ret
= ocfs2_claim_clusters(osb
, handle
, data_ac
, 1, &bit_off
,
1375 blkno
= ocfs2_clusters_to_blocks(dir
->i_sb
, bit_off
);
1377 ret
= ocfs2_insert_extent(osb
, handle
, dir
, &et
, 1,
1378 blkno
, len
, 0, NULL
);
1385 *first_block_bh
= dirdata_bh
;
1389 ocfs2_commit_trans(osb
, handle
);
1392 up_write(&oi
->ip_alloc_sem
);
1396 ocfs2_free_alloc_context(data_ac
);
1403 /* returns a bh of the 1st new block in the allocation. */
1404 static int ocfs2_do_extend_dir(struct super_block
*sb
,
1407 struct buffer_head
*parent_fe_bh
,
1408 struct ocfs2_alloc_context
*data_ac
,
1409 struct ocfs2_alloc_context
*meta_ac
,
1410 struct buffer_head
**new_bh
)
1414 u64 p_blkno
, v_blkno
;
1416 spin_lock(&OCFS2_I(dir
)->ip_lock
);
1417 extend
= (i_size_read(dir
) == ocfs2_clusters_to_bytes(sb
, OCFS2_I(dir
)->ip_clusters
));
1418 spin_unlock(&OCFS2_I(dir
)->ip_lock
);
1421 u32 offset
= OCFS2_I(dir
)->ip_clusters
;
1423 status
= ocfs2_add_inode_data(OCFS2_SB(sb
), dir
, &offset
,
1424 1, 0, parent_fe_bh
, handle
,
1425 data_ac
, meta_ac
, NULL
);
1426 BUG_ON(status
== -EAGAIN
);
1433 v_blkno
= ocfs2_blocks_for_bytes(sb
, i_size_read(dir
));
1434 status
= ocfs2_extent_map_get_blocks(dir
, v_blkno
, &p_blkno
, NULL
, NULL
);
1440 *new_bh
= sb_getblk(sb
, p_blkno
);
1453 * Assumes you already have a cluster lock on the directory.
1455 * 'blocks_wanted' is only used if we have an inline directory which
1456 * is to be turned into an extent based one. The size of the dirent to
1457 * insert might be larger than the space gained by growing to just one
1458 * block, so we may have to grow the inode by two blocks in that case.
1460 static int ocfs2_extend_dir(struct ocfs2_super
*osb
,
1462 struct buffer_head
*parent_fe_bh
,
1463 unsigned int blocks_wanted
,
1464 struct buffer_head
**new_de_bh
)
1467 int credits
, num_free_extents
, drop_alloc_sem
= 0;
1469 struct ocfs2_dinode
*fe
= (struct ocfs2_dinode
*) parent_fe_bh
->b_data
;
1470 struct ocfs2_extent_list
*el
= &fe
->id2
.i_list
;
1471 struct ocfs2_alloc_context
*data_ac
= NULL
;
1472 struct ocfs2_alloc_context
*meta_ac
= NULL
;
1473 handle_t
*handle
= NULL
;
1474 struct buffer_head
*new_bh
= NULL
;
1475 struct ocfs2_dir_entry
* de
;
1476 struct super_block
*sb
= osb
->sb
;
1477 struct ocfs2_extent_tree et
;
1481 if (OCFS2_I(dir
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
) {
1482 status
= ocfs2_expand_inline_dir(dir
, parent_fe_bh
,
1483 blocks_wanted
, &new_bh
);
1489 if (blocks_wanted
== 1) {
1491 * If the new dirent will fit inside the space
1492 * created by pushing out to one block, then
1493 * we can complete the operation
1494 * here. Otherwise we have to expand i_size
1495 * and format the 2nd block below.
1497 BUG_ON(new_bh
== NULL
);
1502 * Get rid of 'new_bh' - we want to format the 2nd
1503 * data block and return that instead.
1508 dir_i_size
= i_size_read(dir
);
1509 credits
= OCFS2_SIMPLE_DIR_EXTEND_CREDITS
;
1513 dir_i_size
= i_size_read(dir
);
1514 mlog(0, "extending dir %llu (i_size = %lld)\n",
1515 (unsigned long long)OCFS2_I(dir
)->ip_blkno
, dir_i_size
);
1517 /* dir->i_size is always block aligned. */
1518 spin_lock(&OCFS2_I(dir
)->ip_lock
);
1519 if (dir_i_size
== ocfs2_clusters_to_bytes(sb
, OCFS2_I(dir
)->ip_clusters
)) {
1520 spin_unlock(&OCFS2_I(dir
)->ip_lock
);
1521 ocfs2_init_dinode_extent_tree(&et
, dir
, parent_fe_bh
);
1522 num_free_extents
= ocfs2_num_free_extents(osb
, dir
, &et
);
1523 if (num_free_extents
< 0) {
1524 status
= num_free_extents
;
1529 if (!num_free_extents
) {
1530 status
= ocfs2_reserve_new_metadata(osb
, el
, &meta_ac
);
1532 if (status
!= -ENOSPC
)
1538 status
= ocfs2_reserve_clusters(osb
, 1, &data_ac
);
1540 if (status
!= -ENOSPC
)
1545 credits
= ocfs2_calc_extend_credits(sb
, el
, 1);
1547 spin_unlock(&OCFS2_I(dir
)->ip_lock
);
1548 credits
= OCFS2_SIMPLE_DIR_EXTEND_CREDITS
;
1552 down_write(&OCFS2_I(dir
)->ip_alloc_sem
);
1555 handle
= ocfs2_start_trans(osb
, credits
);
1556 if (IS_ERR(handle
)) {
1557 status
= PTR_ERR(handle
);
1563 status
= ocfs2_do_extend_dir(osb
->sb
, handle
, dir
, parent_fe_bh
,
1564 data_ac
, meta_ac
, &new_bh
);
1570 ocfs2_set_new_buffer_uptodate(dir
, new_bh
);
1572 status
= ocfs2_journal_access(handle
, dir
, new_bh
,
1573 OCFS2_JOURNAL_ACCESS_CREATE
);
1578 memset(new_bh
->b_data
, 0, sb
->s_blocksize
);
1579 de
= (struct ocfs2_dir_entry
*) new_bh
->b_data
;
1581 de
->rec_len
= cpu_to_le16(sb
->s_blocksize
);
1582 status
= ocfs2_journal_dirty(handle
, new_bh
);
1588 dir_i_size
+= dir
->i_sb
->s_blocksize
;
1589 i_size_write(dir
, dir_i_size
);
1590 dir
->i_blocks
= ocfs2_inode_sector_count(dir
);
1591 status
= ocfs2_mark_inode_dirty(handle
, dir
, parent_fe_bh
);
1598 *new_de_bh
= new_bh
;
1602 up_write(&OCFS2_I(dir
)->ip_alloc_sem
);
1604 ocfs2_commit_trans(osb
, handle
);
1607 ocfs2_free_alloc_context(data_ac
);
1609 ocfs2_free_alloc_context(meta_ac
);
1617 static int ocfs2_find_dir_space_id(struct inode
*dir
, struct buffer_head
*di_bh
,
1618 const char *name
, int namelen
,
1619 struct buffer_head
**ret_de_bh
,
1620 unsigned int *blocks_wanted
)
1623 struct ocfs2_dinode
*di
= (struct ocfs2_dinode
*)di_bh
->b_data
;
1624 struct ocfs2_dir_entry
*de
, *last_de
= NULL
;
1625 char *de_buf
, *limit
;
1626 unsigned long offset
= 0;
1627 unsigned int rec_len
, new_rec_len
;
1629 de_buf
= di
->id2
.i_data
.id_data
;
1630 limit
= de_buf
+ i_size_read(dir
);
1631 rec_len
= OCFS2_DIR_REC_LEN(namelen
);
1633 while (de_buf
< limit
) {
1634 de
= (struct ocfs2_dir_entry
*)de_buf
;
1636 if (!ocfs2_check_dir_entry(dir
, de
, di_bh
, offset
)) {
1640 if (ocfs2_match(namelen
, name
, de
)) {
1644 if (ocfs2_dirent_would_fit(de
, rec_len
)) {
1645 /* Ok, we found a spot. Return this bh and let
1646 * the caller actually fill it in. */
1654 de_buf
+= le16_to_cpu(de
->rec_len
);
1655 offset
+= le16_to_cpu(de
->rec_len
);
1659 * We're going to require expansion of the directory - figure
1660 * out how many blocks we'll need so that a place for the
1661 * dirent can be found.
1664 new_rec_len
= le16_to_cpu(last_de
->rec_len
) + (dir
->i_sb
->s_blocksize
- i_size_read(dir
));
1665 if (new_rec_len
< (rec_len
+ OCFS2_DIR_REC_LEN(last_de
->name_len
)))
1673 static int ocfs2_find_dir_space_el(struct inode
*dir
, const char *name
,
1674 int namelen
, struct buffer_head
**ret_de_bh
)
1676 unsigned long offset
;
1677 struct buffer_head
*bh
= NULL
;
1678 unsigned short rec_len
;
1679 struct ocfs2_dir_entry
*de
;
1680 struct super_block
*sb
= dir
->i_sb
;
1683 bh
= ocfs2_bread(dir
, 0, &status
, 0);
1689 rec_len
= OCFS2_DIR_REC_LEN(namelen
);
1691 de
= (struct ocfs2_dir_entry
*) bh
->b_data
;
1693 if ((char *)de
>= sb
->s_blocksize
+ bh
->b_data
) {
1697 if (i_size_read(dir
) <= offset
) {
1699 * Caller will have to expand this
1705 bh
= ocfs2_bread(dir
,
1706 offset
>> sb
->s_blocksize_bits
,
1713 /* move to next block */
1714 de
= (struct ocfs2_dir_entry
*) bh
->b_data
;
1716 if (!ocfs2_check_dir_entry(dir
, de
, bh
, offset
)) {
1720 if (ocfs2_match(namelen
, name
, de
)) {
1724 if (ocfs2_dirent_would_fit(de
, rec_len
)) {
1725 /* Ok, we found a spot. Return this bh and let
1726 * the caller actually fill it in. */
1732 offset
+= le16_to_cpu(de
->rec_len
);
1733 de
= (struct ocfs2_dir_entry
*)((char *) de
+ le16_to_cpu(de
->rec_len
));
1744 int ocfs2_prepare_dir_for_insert(struct ocfs2_super
*osb
,
1746 struct buffer_head
*parent_fe_bh
,
1749 struct buffer_head
**ret_de_bh
)
1752 unsigned int blocks_wanted
= 1;
1753 struct buffer_head
*bh
= NULL
;
1755 mlog(0, "getting ready to insert namelen %d into dir %llu\n",
1756 namelen
, (unsigned long long)OCFS2_I(dir
)->ip_blkno
);
1766 if (OCFS2_I(dir
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
) {
1767 ret
= ocfs2_find_dir_space_id(dir
, parent_fe_bh
, name
,
1768 namelen
, &bh
, &blocks_wanted
);
1770 ret
= ocfs2_find_dir_space_el(dir
, name
, namelen
, &bh
);
1772 if (ret
&& ret
!= -ENOSPC
) {
1777 if (ret
== -ENOSPC
) {
1779 * We have to expand the directory to add this name.
1783 ret
= ocfs2_extend_dir(osb
, dir
, parent_fe_bh
, blocks_wanted
,