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
);
86 * bh passed here can be an inode block or a dir data block, depending
87 * on the inode inline data flag.
89 static int ocfs2_check_dir_entry(struct inode
* dir
,
90 struct ocfs2_dir_entry
* de
,
91 struct buffer_head
* bh
,
94 const char *error_msg
= NULL
;
95 const int rlen
= le16_to_cpu(de
->rec_len
);
97 if (rlen
< OCFS2_DIR_REC_LEN(1))
98 error_msg
= "rec_len is smaller than minimal";
99 else if (rlen
% 4 != 0)
100 error_msg
= "rec_len % 4 != 0";
101 else if (rlen
< OCFS2_DIR_REC_LEN(de
->name_len
))
102 error_msg
= "rec_len is too small for name_len";
103 else if (((char *) de
- bh
->b_data
) + rlen
> dir
->i_sb
->s_blocksize
)
104 error_msg
= "directory entry across blocks";
106 if (error_msg
!= NULL
)
107 mlog(ML_ERROR
, "bad entry in directory #%llu: %s - "
108 "offset=%lu, inode=%llu, rec_len=%d, name_len=%d\n",
109 (unsigned long long)OCFS2_I(dir
)->ip_blkno
, error_msg
,
110 offset
, (unsigned long long)le64_to_cpu(de
->inode
), rlen
,
112 return error_msg
== NULL
? 1 : 0;
115 static inline int ocfs2_match(int len
,
116 const char * const name
,
117 struct ocfs2_dir_entry
*de
)
119 if (len
!= de
->name_len
)
123 return !memcmp(name
, de
->name
, len
);
127 * Returns 0 if not found, -1 on failure, and 1 on success
129 static int inline ocfs2_search_dirblock(struct buffer_head
*bh
,
131 const char *name
, int namelen
,
132 unsigned long offset
,
135 struct ocfs2_dir_entry
**res_dir
)
137 struct ocfs2_dir_entry
*de
;
138 char *dlimit
, *de_buf
;
145 dlimit
= de_buf
+ bytes
;
147 while (de_buf
< dlimit
) {
148 /* this code is executed quadratically often */
149 /* do minimal checking `by hand' */
151 de
= (struct ocfs2_dir_entry
*) de_buf
;
153 if (de_buf
+ namelen
<= dlimit
&&
154 ocfs2_match(namelen
, name
, de
)) {
155 /* found a match - just to be sure, do a full check */
156 if (!ocfs2_check_dir_entry(dir
, de
, bh
, offset
)) {
165 /* prevent looping on a bad block */
166 de_len
= le16_to_cpu(de
->rec_len
);
181 static struct buffer_head
*ocfs2_find_entry_id(const char *name
,
184 struct ocfs2_dir_entry
**res_dir
)
187 struct buffer_head
*di_bh
= NULL
;
188 struct ocfs2_dinode
*di
;
189 struct ocfs2_inline_data
*data
;
191 ret
= ocfs2_read_inode_block(dir
, &di_bh
);
197 di
= (struct ocfs2_dinode
*)di_bh
->b_data
;
198 data
= &di
->id2
.i_data
;
200 found
= ocfs2_search_dirblock(di_bh
, dir
, name
, namelen
, 0,
201 data
->id_data
, i_size_read(dir
), res_dir
);
210 static int ocfs2_validate_dir_block(struct super_block
*sb
,
211 struct buffer_head
*bh
)
214 * Nothing yet. We don't validate dirents here, that's handled
215 * in-place when the code walks them.
222 * This function forces all errors to -EIO for consistency with its
223 * predecessor, ocfs2_bread(). We haven't audited what returning the
224 * real error codes would do to callers. We log the real codes with
225 * mlog_errno() before we squash them.
227 static int ocfs2_read_dir_block(struct inode
*inode
, u64 v_block
,
228 struct buffer_head
**bh
, int flags
)
231 struct buffer_head
*tmp
= *bh
;
234 if (((u64
)v_block
<< inode
->i_sb
->s_blocksize_bits
) >=
235 i_size_read(inode
)) {
236 BUG_ON(!(flags
& OCFS2_BH_READAHEAD
));
240 down_read(&OCFS2_I(inode
)->ip_alloc_sem
);
241 rc
= ocfs2_extent_map_get_blocks(inode
, v_block
, &p_blkno
, NULL
,
243 up_read(&OCFS2_I(inode
)->ip_alloc_sem
);
252 "Directory #%llu contains a hole at offset %llu\n",
253 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
254 (unsigned long long)v_block
<< inode
->i_sb
->s_blocksize_bits
);
258 rc
= ocfs2_read_blocks(inode
, p_blkno
, 1, &tmp
, flags
);
264 if (!(flags
& OCFS2_BH_READAHEAD
)) {
265 rc
= ocfs2_validate_dir_block(inode
->i_sb
, tmp
);
272 /* If ocfs2_read_blocks() got us a new bh, pass it up. */
277 return rc
? -EIO
: 0;
280 static struct buffer_head
*ocfs2_find_entry_el(const char *name
, int namelen
,
282 struct ocfs2_dir_entry
**res_dir
)
284 struct super_block
*sb
;
285 struct buffer_head
*bh_use
[NAMEI_RA_SIZE
];
286 struct buffer_head
*bh
, *ret
= NULL
;
287 unsigned long start
, block
, b
;
288 int ra_max
= 0; /* Number of bh's in the readahead
290 int ra_ptr
= 0; /* Current index into readahead
299 nblocks
= i_size_read(dir
) >> sb
->s_blocksize_bits
;
300 start
= OCFS2_I(dir
)->ip_dir_start_lookup
;
301 if (start
>= nblocks
)
308 * We deal with the read-ahead logic here.
310 if (ra_ptr
>= ra_max
) {
311 /* Refill the readahead buffer */
314 for (ra_max
= 0; ra_max
< NAMEI_RA_SIZE
; ra_max
++) {
316 * Terminate if we reach the end of the
317 * directory and must wrap, or if our
318 * search has finished at this block.
320 if (b
>= nblocks
|| (num
&& block
== start
)) {
321 bh_use
[ra_max
] = NULL
;
327 err
= ocfs2_read_dir_block(dir
, b
++, &bh
,
332 if ((bh
= bh_use
[ra_ptr
++]) == NULL
)
334 if (ocfs2_read_dir_block(dir
, block
, &bh
, 0)) {
335 /* read error, skip block & hope for the best.
336 * ocfs2_read_dir_block() has released the bh. */
337 ocfs2_error(dir
->i_sb
, "reading directory %llu, "
339 (unsigned long long)OCFS2_I(dir
)->ip_blkno
,
343 i
= ocfs2_search_dirblock(bh
, dir
, name
, namelen
,
344 block
<< sb
->s_blocksize_bits
,
345 bh
->b_data
, sb
->s_blocksize
,
348 OCFS2_I(dir
)->ip_dir_start_lookup
= block
;
350 goto cleanup_and_exit
;
354 goto cleanup_and_exit
;
357 if (++block
>= nblocks
)
359 } while (block
!= start
);
362 * If the directory has grown while we were searching, then
363 * search the last part of the directory before giving up.
366 nblocks
= i_size_read(dir
) >> sb
->s_blocksize_bits
;
367 if (block
< nblocks
) {
373 /* Clean up the read-ahead blocks */
374 for (; ra_ptr
< ra_max
; ra_ptr
++)
375 brelse(bh_use
[ra_ptr
]);
382 * Try to find an entry of the provided name within 'dir'.
384 * If nothing was found, NULL is returned. Otherwise, a buffer_head
385 * and pointer to the dir entry are passed back.
387 * Caller can NOT assume anything about the contents of the
388 * buffer_head - it is passed back only so that it can be passed into
389 * any one of the manipulation functions (add entry, delete entry,
390 * etc). As an example, bh in the extent directory case is a data
391 * block, in the inline-data case it actually points to an inode.
393 struct buffer_head
*ocfs2_find_entry(const char *name
, int namelen
,
395 struct ocfs2_dir_entry
**res_dir
)
399 if (OCFS2_I(dir
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
)
400 return ocfs2_find_entry_id(name
, namelen
, dir
, res_dir
);
402 return ocfs2_find_entry_el(name
, namelen
, dir
, res_dir
);
406 * Update inode number and type of a previously found directory entry.
408 int ocfs2_update_entry(struct inode
*dir
, handle_t
*handle
,
409 struct buffer_head
*de_bh
, struct ocfs2_dir_entry
*de
,
410 struct inode
*new_entry_inode
)
415 * The same code works fine for both inline-data and extent
416 * based directories, so no need to split this up.
419 ret
= ocfs2_journal_access(handle
, dir
, de_bh
,
420 OCFS2_JOURNAL_ACCESS_WRITE
);
426 de
->inode
= cpu_to_le64(OCFS2_I(new_entry_inode
)->ip_blkno
);
427 ocfs2_set_de_type(de
, new_entry_inode
->i_mode
);
429 ocfs2_journal_dirty(handle
, de_bh
);
435 static int __ocfs2_delete_entry(handle_t
*handle
, struct inode
*dir
,
436 struct ocfs2_dir_entry
*de_del
,
437 struct buffer_head
*bh
, char *first_de
,
440 struct ocfs2_dir_entry
*de
, *pde
;
441 int i
, status
= -ENOENT
;
443 mlog_entry("(0x%p, 0x%p, 0x%p, 0x%p)\n", handle
, dir
, de_del
, bh
);
447 de
= (struct ocfs2_dir_entry
*) first_de
;
449 if (!ocfs2_check_dir_entry(dir
, de
, bh
, i
)) {
455 status
= ocfs2_journal_access(handle
, dir
, bh
,
456 OCFS2_JOURNAL_ACCESS_WRITE
);
463 le16_add_cpu(&pde
->rec_len
,
464 le16_to_cpu(de
->rec_len
));
468 status
= ocfs2_journal_dirty(handle
, bh
);
471 i
+= le16_to_cpu(de
->rec_len
);
473 de
= (struct ocfs2_dir_entry
*)((char *)de
+ le16_to_cpu(de
->rec_len
));
480 static inline int ocfs2_delete_entry_id(handle_t
*handle
,
482 struct ocfs2_dir_entry
*de_del
,
483 struct buffer_head
*bh
)
486 struct buffer_head
*di_bh
= NULL
;
487 struct ocfs2_dinode
*di
;
488 struct ocfs2_inline_data
*data
;
490 ret
= ocfs2_read_inode_block(dir
, &di_bh
);
496 di
= (struct ocfs2_dinode
*)di_bh
->b_data
;
497 data
= &di
->id2
.i_data
;
499 ret
= __ocfs2_delete_entry(handle
, dir
, de_del
, bh
, data
->id_data
,
507 static inline int ocfs2_delete_entry_el(handle_t
*handle
,
509 struct ocfs2_dir_entry
*de_del
,
510 struct buffer_head
*bh
)
512 return __ocfs2_delete_entry(handle
, dir
, de_del
, bh
, bh
->b_data
,
517 * ocfs2_delete_entry deletes a directory entry by merging it with the
520 int ocfs2_delete_entry(handle_t
*handle
,
522 struct ocfs2_dir_entry
*de_del
,
523 struct buffer_head
*bh
)
525 if (OCFS2_I(dir
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
)
526 return ocfs2_delete_entry_id(handle
, dir
, de_del
, bh
);
528 return ocfs2_delete_entry_el(handle
, dir
, de_del
, bh
);
532 * Check whether 'de' has enough room to hold an entry of
533 * 'new_rec_len' bytes.
535 static inline int ocfs2_dirent_would_fit(struct ocfs2_dir_entry
*de
,
536 unsigned int new_rec_len
)
538 unsigned int de_really_used
;
540 /* Check whether this is an empty record with enough space */
541 if (le64_to_cpu(de
->inode
) == 0 &&
542 le16_to_cpu(de
->rec_len
) >= new_rec_len
)
546 * Record might have free space at the end which we can
549 de_really_used
= OCFS2_DIR_REC_LEN(de
->name_len
);
550 if (le16_to_cpu(de
->rec_len
) >= (de_really_used
+ new_rec_len
))
556 /* we don't always have a dentry for what we want to add, so people
557 * like orphan dir can call this instead.
559 * If you pass me insert_bh, I'll skip the search of the other dir
560 * blocks and put the record in there.
562 int __ocfs2_add_entry(handle_t
*handle
,
564 const char *name
, int namelen
,
565 struct inode
*inode
, u64 blkno
,
566 struct buffer_head
*parent_fe_bh
,
567 struct buffer_head
*insert_bh
)
569 unsigned long offset
;
570 unsigned short rec_len
;
571 struct ocfs2_dir_entry
*de
, *de1
;
572 struct ocfs2_dinode
*di
= (struct ocfs2_dinode
*)parent_fe_bh
->b_data
;
573 struct super_block
*sb
= dir
->i_sb
;
575 unsigned int size
= sb
->s_blocksize
;
576 char *data_start
= insert_bh
->b_data
;
583 if (OCFS2_I(dir
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
) {
584 data_start
= di
->id2
.i_data
.id_data
;
585 size
= i_size_read(dir
);
587 BUG_ON(insert_bh
!= parent_fe_bh
);
590 rec_len
= OCFS2_DIR_REC_LEN(namelen
);
592 de
= (struct ocfs2_dir_entry
*) data_start
;
594 BUG_ON((char *)de
>= (size
+ data_start
));
596 /* These checks should've already been passed by the
597 * prepare function, but I guess we can leave them
599 if (!ocfs2_check_dir_entry(dir
, de
, insert_bh
, offset
)) {
603 if (ocfs2_match(namelen
, name
, de
)) {
608 if (ocfs2_dirent_would_fit(de
, rec_len
)) {
609 dir
->i_mtime
= dir
->i_ctime
= CURRENT_TIME
;
610 retval
= ocfs2_mark_inode_dirty(handle
, dir
, parent_fe_bh
);
616 status
= ocfs2_journal_access(handle
, dir
, insert_bh
,
617 OCFS2_JOURNAL_ACCESS_WRITE
);
618 /* By now the buffer is marked for journaling */
619 offset
+= le16_to_cpu(de
->rec_len
);
620 if (le64_to_cpu(de
->inode
)) {
621 de1
= (struct ocfs2_dir_entry
*)((char *) de
+
622 OCFS2_DIR_REC_LEN(de
->name_len
));
624 cpu_to_le16(le16_to_cpu(de
->rec_len
) -
625 OCFS2_DIR_REC_LEN(de
->name_len
));
626 de
->rec_len
= cpu_to_le16(OCFS2_DIR_REC_LEN(de
->name_len
));
629 de
->file_type
= OCFS2_FT_UNKNOWN
;
631 de
->inode
= cpu_to_le64(blkno
);
632 ocfs2_set_de_type(de
, inode
->i_mode
);
635 de
->name_len
= namelen
;
636 memcpy(de
->name
, name
, namelen
);
639 status
= ocfs2_journal_dirty(handle
, insert_bh
);
643 offset
+= le16_to_cpu(de
->rec_len
);
644 de
= (struct ocfs2_dir_entry
*) ((char *) de
+ le16_to_cpu(de
->rec_len
));
647 /* when you think about it, the assert above should prevent us
648 * from ever getting here. */
656 static int ocfs2_dir_foreach_blk_id(struct inode
*inode
,
658 loff_t
*f_pos
, void *priv
,
659 filldir_t filldir
, int *filldir_err
)
661 int ret
, i
, filldir_ret
;
662 unsigned long offset
= *f_pos
;
663 struct buffer_head
*di_bh
= NULL
;
664 struct ocfs2_dinode
*di
;
665 struct ocfs2_inline_data
*data
;
666 struct ocfs2_dir_entry
*de
;
668 ret
= ocfs2_read_inode_block(inode
, &di_bh
);
670 mlog(ML_ERROR
, "Unable to read inode block for dir %llu\n",
671 (unsigned long long)OCFS2_I(inode
)->ip_blkno
);
675 di
= (struct ocfs2_dinode
*)di_bh
->b_data
;
676 data
= &di
->id2
.i_data
;
678 while (*f_pos
< i_size_read(inode
)) {
680 /* If the dir block has changed since the last call to
681 * readdir(2), then we might be pointing to an invalid
682 * dirent right now. Scan from the start of the block
684 if (*f_version
!= inode
->i_version
) {
685 for (i
= 0; i
< i_size_read(inode
) && i
< offset
; ) {
686 de
= (struct ocfs2_dir_entry
*)
688 /* It's too expensive to do a full
689 * dirent test each time round this
690 * loop, but we do have to test at
691 * least that it is non-zero. A
692 * failure will be detected in the
693 * dirent test below. */
694 if (le16_to_cpu(de
->rec_len
) <
695 OCFS2_DIR_REC_LEN(1))
697 i
+= le16_to_cpu(de
->rec_len
);
700 *f_version
= inode
->i_version
;
703 de
= (struct ocfs2_dir_entry
*) (data
->id_data
+ *f_pos
);
704 if (!ocfs2_check_dir_entry(inode
, de
, di_bh
, *f_pos
)) {
705 /* On error, skip the f_pos to the end. */
706 *f_pos
= i_size_read(inode
);
709 offset
+= le16_to_cpu(de
->rec_len
);
710 if (le64_to_cpu(de
->inode
)) {
711 /* We might block in the next section
712 * if the data destination is
713 * currently swapped out. So, use a
714 * version stamp to detect whether or
715 * not the directory has been modified
716 * during the copy operation.
718 u64 version
= *f_version
;
719 unsigned char d_type
= DT_UNKNOWN
;
721 if (de
->file_type
< OCFS2_FT_MAX
)
722 d_type
= ocfs2_filetype_table
[de
->file_type
];
724 filldir_ret
= filldir(priv
, de
->name
,
727 le64_to_cpu(de
->inode
),
731 *filldir_err
= filldir_ret
;
734 if (version
!= *f_version
)
737 *f_pos
+= le16_to_cpu(de
->rec_len
);
746 static int ocfs2_dir_foreach_blk_el(struct inode
*inode
,
748 loff_t
*f_pos
, void *priv
,
749 filldir_t filldir
, int *filldir_err
)
752 unsigned long offset
, blk
, last_ra_blk
= 0;
754 struct buffer_head
* bh
, * tmp
;
755 struct ocfs2_dir_entry
* de
;
756 struct super_block
* sb
= inode
->i_sb
;
757 unsigned int ra_sectors
= 16;
762 offset
= (*f_pos
) & (sb
->s_blocksize
- 1);
764 while (!error
&& !stored
&& *f_pos
< i_size_read(inode
)) {
765 blk
= (*f_pos
) >> sb
->s_blocksize_bits
;
766 if (ocfs2_read_dir_block(inode
, blk
, &bh
, 0)) {
767 /* Skip the corrupt dirblock and keep trying */
768 *f_pos
+= sb
->s_blocksize
- offset
;
772 /* The idea here is to begin with 8k read-ahead and to stay
773 * 4k ahead of our current position.
775 * TODO: Use the pagecache for this. We just need to
776 * make sure it's cluster-safe... */
778 || (((last_ra_blk
- blk
) << 9) <= (ra_sectors
/ 2))) {
779 for (i
= ra_sectors
>> (sb
->s_blocksize_bits
- 9);
782 if (!ocfs2_read_dir_block(inode
, ++blk
, &tmp
,
791 /* If the dir block has changed since the last call to
792 * readdir(2), then we might be pointing to an invalid
793 * dirent right now. Scan from the start of the block
795 if (*f_version
!= inode
->i_version
) {
796 for (i
= 0; i
< sb
->s_blocksize
&& i
< offset
; ) {
797 de
= (struct ocfs2_dir_entry
*) (bh
->b_data
+ i
);
798 /* It's too expensive to do a full
799 * dirent test each time round this
800 * loop, but we do have to test at
801 * least that it is non-zero. A
802 * failure will be detected in the
803 * dirent test below. */
804 if (le16_to_cpu(de
->rec_len
) <
805 OCFS2_DIR_REC_LEN(1))
807 i
+= le16_to_cpu(de
->rec_len
);
810 *f_pos
= ((*f_pos
) & ~(sb
->s_blocksize
- 1))
812 *f_version
= inode
->i_version
;
815 while (!error
&& *f_pos
< i_size_read(inode
)
816 && offset
< sb
->s_blocksize
) {
817 de
= (struct ocfs2_dir_entry
*) (bh
->b_data
+ offset
);
818 if (!ocfs2_check_dir_entry(inode
, de
, bh
, offset
)) {
819 /* On error, skip the f_pos to the
821 *f_pos
= ((*f_pos
) | (sb
->s_blocksize
- 1)) + 1;
825 offset
+= le16_to_cpu(de
->rec_len
);
826 if (le64_to_cpu(de
->inode
)) {
827 /* We might block in the next section
828 * if the data destination is
829 * currently swapped out. So, use a
830 * version stamp to detect whether or
831 * not the directory has been modified
832 * during the copy operation.
834 unsigned long version
= *f_version
;
835 unsigned char d_type
= DT_UNKNOWN
;
837 if (de
->file_type
< OCFS2_FT_MAX
)
838 d_type
= ocfs2_filetype_table
[de
->file_type
];
839 error
= filldir(priv
, de
->name
,
842 le64_to_cpu(de
->inode
),
846 *filldir_err
= error
;
849 if (version
!= *f_version
)
853 *f_pos
+= le16_to_cpu(de
->rec_len
);
865 static int ocfs2_dir_foreach_blk(struct inode
*inode
, u64
*f_version
,
866 loff_t
*f_pos
, void *priv
, filldir_t filldir
,
869 if (OCFS2_I(inode
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
)
870 return ocfs2_dir_foreach_blk_id(inode
, f_version
, f_pos
, priv
,
871 filldir
, filldir_err
);
873 return ocfs2_dir_foreach_blk_el(inode
, f_version
, f_pos
, priv
, filldir
,
878 * This is intended to be called from inside other kernel functions,
879 * so we fake some arguments.
881 int ocfs2_dir_foreach(struct inode
*inode
, loff_t
*f_pos
, void *priv
,
884 int ret
= 0, filldir_err
= 0;
885 u64 version
= inode
->i_version
;
887 while (*f_pos
< i_size_read(inode
)) {
888 ret
= ocfs2_dir_foreach_blk(inode
, &version
, f_pos
, priv
,
889 filldir
, &filldir_err
);
890 if (ret
|| filldir_err
)
904 int ocfs2_readdir(struct file
* filp
, void * dirent
, filldir_t filldir
)
907 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
910 mlog_entry("dirino=%llu\n",
911 (unsigned long long)OCFS2_I(inode
)->ip_blkno
);
913 error
= ocfs2_inode_lock_atime(inode
, filp
->f_vfsmnt
, &lock_level
);
914 if (lock_level
&& error
>= 0) {
915 /* We release EX lock which used to update atime
916 * and get PR lock again to reduce contention
917 * on commonly accessed directories. */
918 ocfs2_inode_unlock(inode
, 1);
920 error
= ocfs2_inode_lock(inode
, NULL
, 0);
923 if (error
!= -ENOENT
)
925 /* we haven't got any yet, so propagate the error. */
929 error
= ocfs2_dir_foreach_blk(inode
, &filp
->f_version
, &filp
->f_pos
,
930 dirent
, filldir
, NULL
);
932 ocfs2_inode_unlock(inode
, lock_level
);
941 * NOTE: this should always be called with parent dir i_mutex taken.
943 int ocfs2_find_files_on_disk(const char *name
,
947 struct buffer_head
**dirent_bh
,
948 struct ocfs2_dir_entry
**dirent
)
950 int status
= -ENOENT
;
952 mlog_entry("(name=%.*s, blkno=%p, inode=%p, dirent_bh=%p, dirent=%p)\n",
953 namelen
, name
, blkno
, inode
, dirent_bh
, dirent
);
955 *dirent_bh
= ocfs2_find_entry(name
, namelen
, inode
, dirent
);
956 if (!*dirent_bh
|| !*dirent
) {
961 *blkno
= le64_to_cpu((*dirent
)->inode
);
976 * Convenience function for callers which just want the block number
977 * mapped to a name and don't require the full dirent info, etc.
979 int ocfs2_lookup_ino_from_name(struct inode
*dir
, const char *name
,
980 int namelen
, u64
*blkno
)
983 struct buffer_head
*bh
= NULL
;
984 struct ocfs2_dir_entry
*dirent
= NULL
;
986 ret
= ocfs2_find_files_on_disk(name
, namelen
, blkno
, dir
, &bh
, &dirent
);
992 /* Check for a name within a directory.
994 * Return 0 if the name does not exist
995 * Return -EEXIST if the directory contains the name
997 * Callers should have i_mutex + a cluster lock on dir
999 int ocfs2_check_dir_for_entry(struct inode
*dir
,
1004 struct buffer_head
*dirent_bh
= NULL
;
1005 struct ocfs2_dir_entry
*dirent
= NULL
;
1007 mlog_entry("dir %llu, name '%.*s'\n",
1008 (unsigned long long)OCFS2_I(dir
)->ip_blkno
, namelen
, name
);
1011 dirent_bh
= ocfs2_find_entry(name
, namelen
, dir
, &dirent
);
1023 struct ocfs2_empty_dir_priv
{
1025 unsigned seen_dot_dot
;
1026 unsigned seen_other
;
1028 static int ocfs2_empty_dir_filldir(void *priv
, const char *name
, int name_len
,
1029 loff_t pos
, u64 ino
, unsigned type
)
1031 struct ocfs2_empty_dir_priv
*p
= priv
;
1034 * Check the positions of "." and ".." records to be sure
1035 * they're in the correct place.
1037 if (name_len
== 1 && !strncmp(".", name
, 1) && pos
== 0) {
1042 if (name_len
== 2 && !strncmp("..", name
, 2) &&
1043 pos
== OCFS2_DIR_REC_LEN(1)) {
1044 p
->seen_dot_dot
= 1;
1052 * routine to check that the specified directory is empty (for rmdir)
1054 * Returns 1 if dir is empty, zero otherwise.
1056 int ocfs2_empty_dir(struct inode
*inode
)
1060 struct ocfs2_empty_dir_priv priv
;
1062 memset(&priv
, 0, sizeof(priv
));
1064 ret
= ocfs2_dir_foreach(inode
, &start
, &priv
, ocfs2_empty_dir_filldir
);
1068 if (!priv
.seen_dot
|| !priv
.seen_dot_dot
) {
1069 mlog(ML_ERROR
, "bad directory (dir #%llu) - no `.' or `..'\n",
1070 (unsigned long long)OCFS2_I(inode
)->ip_blkno
);
1072 * XXX: Is it really safe to allow an unlink to continue?
1077 return !priv
.seen_other
;
1080 static void ocfs2_fill_initial_dirents(struct inode
*inode
,
1081 struct inode
*parent
,
1082 char *start
, unsigned int size
)
1084 struct ocfs2_dir_entry
*de
= (struct ocfs2_dir_entry
*)start
;
1086 de
->inode
= cpu_to_le64(OCFS2_I(inode
)->ip_blkno
);
1089 cpu_to_le16(OCFS2_DIR_REC_LEN(de
->name_len
));
1090 strcpy(de
->name
, ".");
1091 ocfs2_set_de_type(de
, S_IFDIR
);
1093 de
= (struct ocfs2_dir_entry
*) ((char *)de
+ le16_to_cpu(de
->rec_len
));
1094 de
->inode
= cpu_to_le64(OCFS2_I(parent
)->ip_blkno
);
1095 de
->rec_len
= cpu_to_le16(size
- OCFS2_DIR_REC_LEN(1));
1097 strcpy(de
->name
, "..");
1098 ocfs2_set_de_type(de
, S_IFDIR
);
1102 * This works together with code in ocfs2_mknod_locked() which sets
1103 * the inline-data flag and initializes the inline-data section.
1105 static int ocfs2_fill_new_dir_id(struct ocfs2_super
*osb
,
1107 struct inode
*parent
,
1108 struct inode
*inode
,
1109 struct buffer_head
*di_bh
)
1112 struct ocfs2_dinode
*di
= (struct ocfs2_dinode
*)di_bh
->b_data
;
1113 struct ocfs2_inline_data
*data
= &di
->id2
.i_data
;
1114 unsigned int size
= le16_to_cpu(data
->id_count
);
1116 ret
= ocfs2_journal_access(handle
, inode
, di_bh
,
1117 OCFS2_JOURNAL_ACCESS_WRITE
);
1123 ocfs2_fill_initial_dirents(inode
, parent
, data
->id_data
, size
);
1125 ocfs2_journal_dirty(handle
, di_bh
);
1131 i_size_write(inode
, size
);
1133 inode
->i_blocks
= ocfs2_inode_sector_count(inode
);
1135 ret
= ocfs2_mark_inode_dirty(handle
, inode
, di_bh
);
1143 static int ocfs2_fill_new_dir_el(struct ocfs2_super
*osb
,
1145 struct inode
*parent
,
1146 struct inode
*inode
,
1147 struct buffer_head
*fe_bh
,
1148 struct ocfs2_alloc_context
*data_ac
)
1151 struct buffer_head
*new_bh
= NULL
;
1155 status
= ocfs2_do_extend_dir(osb
->sb
, handle
, inode
, fe_bh
,
1156 data_ac
, NULL
, &new_bh
);
1162 ocfs2_set_new_buffer_uptodate(inode
, new_bh
);
1164 status
= ocfs2_journal_access(handle
, inode
, new_bh
,
1165 OCFS2_JOURNAL_ACCESS_CREATE
);
1170 memset(new_bh
->b_data
, 0, osb
->sb
->s_blocksize
);
1172 ocfs2_fill_initial_dirents(inode
, parent
, new_bh
->b_data
,
1173 osb
->sb
->s_blocksize
);
1175 status
= ocfs2_journal_dirty(handle
, new_bh
);
1181 i_size_write(inode
, inode
->i_sb
->s_blocksize
);
1183 inode
->i_blocks
= ocfs2_inode_sector_count(inode
);
1184 status
= ocfs2_mark_inode_dirty(handle
, inode
, fe_bh
);
1198 int ocfs2_fill_new_dir(struct ocfs2_super
*osb
,
1200 struct inode
*parent
,
1201 struct inode
*inode
,
1202 struct buffer_head
*fe_bh
,
1203 struct ocfs2_alloc_context
*data_ac
)
1205 BUG_ON(!ocfs2_supports_inline_data(osb
) && data_ac
== NULL
);
1207 if (OCFS2_I(inode
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
)
1208 return ocfs2_fill_new_dir_id(osb
, handle
, parent
, inode
, fe_bh
);
1210 return ocfs2_fill_new_dir_el(osb
, handle
, parent
, inode
, fe_bh
,
1214 static void ocfs2_expand_last_dirent(char *start
, unsigned int old_size
,
1215 unsigned int new_size
)
1217 struct ocfs2_dir_entry
*de
;
1218 struct ocfs2_dir_entry
*prev_de
;
1219 char *de_buf
, *limit
;
1220 unsigned int bytes
= new_size
- old_size
;
1222 limit
= start
+ old_size
;
1224 de
= (struct ocfs2_dir_entry
*)de_buf
;
1227 de_buf
+= le16_to_cpu(de
->rec_len
);
1228 de
= (struct ocfs2_dir_entry
*)de_buf
;
1229 } while (de_buf
< limit
);
1231 le16_add_cpu(&prev_de
->rec_len
, bytes
);
1235 * We allocate enough clusters to fulfill "blocks_wanted", but set
1236 * i_size to exactly one block. Ocfs2_extend_dir() will handle the
1237 * rest automatically for us.
1239 * *first_block_bh is a pointer to the 1st data block allocated to the
1242 static int ocfs2_expand_inline_dir(struct inode
*dir
, struct buffer_head
*di_bh
,
1243 unsigned int blocks_wanted
,
1244 struct buffer_head
**first_block_bh
)
1246 int ret
, credits
= OCFS2_INLINE_TO_EXTENTS_CREDITS
;
1247 u32 alloc
, bit_off
, len
;
1248 struct super_block
*sb
= dir
->i_sb
;
1249 u64 blkno
, bytes
= blocks_wanted
<< sb
->s_blocksize_bits
;
1250 struct ocfs2_super
*osb
= OCFS2_SB(dir
->i_sb
);
1251 struct ocfs2_inode_info
*oi
= OCFS2_I(dir
);
1252 struct ocfs2_alloc_context
*data_ac
;
1253 struct buffer_head
*dirdata_bh
= NULL
;
1254 struct ocfs2_dinode
*di
= (struct ocfs2_dinode
*)di_bh
->b_data
;
1256 struct ocfs2_extent_tree et
;
1258 ocfs2_init_dinode_extent_tree(&et
, dir
, di_bh
);
1260 alloc
= ocfs2_clusters_for_bytes(sb
, bytes
);
1263 * We should never need more than 2 clusters for this -
1264 * maximum dirent size is far less than one block. In fact,
1265 * the only time we'd need more than one cluster is if
1266 * blocksize == clustersize and the dirent won't fit in the
1267 * extra space that the expansion to a single block gives. As
1268 * of today, that only happens on 4k/4k file systems.
1272 ret
= ocfs2_reserve_clusters(osb
, alloc
, &data_ac
);
1278 down_write(&oi
->ip_alloc_sem
);
1281 * Prepare for worst case allocation scenario of two separate
1285 credits
+= OCFS2_SUBALLOC_ALLOC
;
1287 handle
= ocfs2_start_trans(osb
, credits
);
1288 if (IS_ERR(handle
)) {
1289 ret
= PTR_ERR(handle
);
1295 * Try to claim as many clusters as the bitmap can give though
1296 * if we only get one now, that's enough to continue. The rest
1297 * will be claimed after the conversion to extents.
1299 ret
= ocfs2_claim_clusters(osb
, handle
, data_ac
, 1, &bit_off
, &len
);
1306 * Operations are carefully ordered so that we set up the new
1307 * data block first. The conversion from inline data to
1310 blkno
= ocfs2_clusters_to_blocks(dir
->i_sb
, bit_off
);
1311 dirdata_bh
= sb_getblk(sb
, blkno
);
1318 ocfs2_set_new_buffer_uptodate(dir
, dirdata_bh
);
1320 ret
= ocfs2_journal_access(handle
, dir
, dirdata_bh
,
1321 OCFS2_JOURNAL_ACCESS_CREATE
);
1327 memcpy(dirdata_bh
->b_data
, di
->id2
.i_data
.id_data
, i_size_read(dir
));
1328 memset(dirdata_bh
->b_data
+ i_size_read(dir
), 0,
1329 sb
->s_blocksize
- i_size_read(dir
));
1330 ocfs2_expand_last_dirent(dirdata_bh
->b_data
, i_size_read(dir
),
1333 ret
= ocfs2_journal_dirty(handle
, dirdata_bh
);
1340 * Set extent, i_size, etc on the directory. After this, the
1341 * inode should contain the same exact dirents as before and
1342 * be fully accessible from system calls.
1344 * We let the later dirent insert modify c/mtime - to the user
1345 * the data hasn't changed.
1347 ret
= ocfs2_journal_access(handle
, dir
, di_bh
,
1348 OCFS2_JOURNAL_ACCESS_CREATE
);
1354 spin_lock(&oi
->ip_lock
);
1355 oi
->ip_dyn_features
&= ~OCFS2_INLINE_DATA_FL
;
1356 di
->i_dyn_features
= cpu_to_le16(oi
->ip_dyn_features
);
1357 spin_unlock(&oi
->ip_lock
);
1359 ocfs2_dinode_new_extent_list(dir
, di
);
1361 i_size_write(dir
, sb
->s_blocksize
);
1362 dir
->i_mtime
= dir
->i_ctime
= CURRENT_TIME
;
1364 di
->i_size
= cpu_to_le64(sb
->s_blocksize
);
1365 di
->i_ctime
= di
->i_mtime
= cpu_to_le64(dir
->i_ctime
.tv_sec
);
1366 di
->i_ctime_nsec
= di
->i_mtime_nsec
= cpu_to_le32(dir
->i_ctime
.tv_nsec
);
1369 * This should never fail as our extent list is empty and all
1370 * related blocks have been journaled already.
1372 ret
= ocfs2_insert_extent(osb
, handle
, dir
, &et
, 0, blkno
, len
,
1380 * Set i_blocks after the extent insert for the most up to
1381 * date ip_clusters value.
1383 dir
->i_blocks
= ocfs2_inode_sector_count(dir
);
1385 ret
= ocfs2_journal_dirty(handle
, di_bh
);
1392 * We asked for two clusters, but only got one in the 1st
1393 * pass. Claim the 2nd cluster as a separate extent.
1396 ret
= ocfs2_claim_clusters(osb
, handle
, data_ac
, 1, &bit_off
,
1402 blkno
= ocfs2_clusters_to_blocks(dir
->i_sb
, bit_off
);
1404 ret
= ocfs2_insert_extent(osb
, handle
, dir
, &et
, 1,
1405 blkno
, len
, 0, NULL
);
1412 *first_block_bh
= dirdata_bh
;
1416 ocfs2_commit_trans(osb
, handle
);
1419 up_write(&oi
->ip_alloc_sem
);
1423 ocfs2_free_alloc_context(data_ac
);
1430 /* returns a bh of the 1st new block in the allocation. */
1431 static int ocfs2_do_extend_dir(struct super_block
*sb
,
1434 struct buffer_head
*parent_fe_bh
,
1435 struct ocfs2_alloc_context
*data_ac
,
1436 struct ocfs2_alloc_context
*meta_ac
,
1437 struct buffer_head
**new_bh
)
1441 u64 p_blkno
, v_blkno
;
1443 spin_lock(&OCFS2_I(dir
)->ip_lock
);
1444 extend
= (i_size_read(dir
) == ocfs2_clusters_to_bytes(sb
, OCFS2_I(dir
)->ip_clusters
));
1445 spin_unlock(&OCFS2_I(dir
)->ip_lock
);
1448 u32 offset
= OCFS2_I(dir
)->ip_clusters
;
1450 status
= ocfs2_add_inode_data(OCFS2_SB(sb
), dir
, &offset
,
1451 1, 0, parent_fe_bh
, handle
,
1452 data_ac
, meta_ac
, NULL
);
1453 BUG_ON(status
== -EAGAIN
);
1460 v_blkno
= ocfs2_blocks_for_bytes(sb
, i_size_read(dir
));
1461 status
= ocfs2_extent_map_get_blocks(dir
, v_blkno
, &p_blkno
, NULL
, NULL
);
1467 *new_bh
= sb_getblk(sb
, p_blkno
);
1480 * Assumes you already have a cluster lock on the directory.
1482 * 'blocks_wanted' is only used if we have an inline directory which
1483 * is to be turned into an extent based one. The size of the dirent to
1484 * insert might be larger than the space gained by growing to just one
1485 * block, so we may have to grow the inode by two blocks in that case.
1487 static int ocfs2_extend_dir(struct ocfs2_super
*osb
,
1489 struct buffer_head
*parent_fe_bh
,
1490 unsigned int blocks_wanted
,
1491 struct buffer_head
**new_de_bh
)
1494 int credits
, num_free_extents
, drop_alloc_sem
= 0;
1496 struct ocfs2_dinode
*fe
= (struct ocfs2_dinode
*) parent_fe_bh
->b_data
;
1497 struct ocfs2_extent_list
*el
= &fe
->id2
.i_list
;
1498 struct ocfs2_alloc_context
*data_ac
= NULL
;
1499 struct ocfs2_alloc_context
*meta_ac
= NULL
;
1500 handle_t
*handle
= NULL
;
1501 struct buffer_head
*new_bh
= NULL
;
1502 struct ocfs2_dir_entry
* de
;
1503 struct super_block
*sb
= osb
->sb
;
1504 struct ocfs2_extent_tree et
;
1508 if (OCFS2_I(dir
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
) {
1509 status
= ocfs2_expand_inline_dir(dir
, parent_fe_bh
,
1510 blocks_wanted
, &new_bh
);
1516 if (blocks_wanted
== 1) {
1518 * If the new dirent will fit inside the space
1519 * created by pushing out to one block, then
1520 * we can complete the operation
1521 * here. Otherwise we have to expand i_size
1522 * and format the 2nd block below.
1524 BUG_ON(new_bh
== NULL
);
1529 * Get rid of 'new_bh' - we want to format the 2nd
1530 * data block and return that instead.
1535 dir_i_size
= i_size_read(dir
);
1536 credits
= OCFS2_SIMPLE_DIR_EXTEND_CREDITS
;
1540 dir_i_size
= i_size_read(dir
);
1541 mlog(0, "extending dir %llu (i_size = %lld)\n",
1542 (unsigned long long)OCFS2_I(dir
)->ip_blkno
, dir_i_size
);
1544 /* dir->i_size is always block aligned. */
1545 spin_lock(&OCFS2_I(dir
)->ip_lock
);
1546 if (dir_i_size
== ocfs2_clusters_to_bytes(sb
, OCFS2_I(dir
)->ip_clusters
)) {
1547 spin_unlock(&OCFS2_I(dir
)->ip_lock
);
1548 ocfs2_init_dinode_extent_tree(&et
, dir
, parent_fe_bh
);
1549 num_free_extents
= ocfs2_num_free_extents(osb
, dir
, &et
);
1550 if (num_free_extents
< 0) {
1551 status
= num_free_extents
;
1556 if (!num_free_extents
) {
1557 status
= ocfs2_reserve_new_metadata(osb
, el
, &meta_ac
);
1559 if (status
!= -ENOSPC
)
1565 status
= ocfs2_reserve_clusters(osb
, 1, &data_ac
);
1567 if (status
!= -ENOSPC
)
1572 credits
= ocfs2_calc_extend_credits(sb
, el
, 1);
1574 spin_unlock(&OCFS2_I(dir
)->ip_lock
);
1575 credits
= OCFS2_SIMPLE_DIR_EXTEND_CREDITS
;
1579 down_write(&OCFS2_I(dir
)->ip_alloc_sem
);
1582 handle
= ocfs2_start_trans(osb
, credits
);
1583 if (IS_ERR(handle
)) {
1584 status
= PTR_ERR(handle
);
1590 status
= ocfs2_do_extend_dir(osb
->sb
, handle
, dir
, parent_fe_bh
,
1591 data_ac
, meta_ac
, &new_bh
);
1597 ocfs2_set_new_buffer_uptodate(dir
, new_bh
);
1599 status
= ocfs2_journal_access(handle
, dir
, new_bh
,
1600 OCFS2_JOURNAL_ACCESS_CREATE
);
1605 memset(new_bh
->b_data
, 0, sb
->s_blocksize
);
1606 de
= (struct ocfs2_dir_entry
*) new_bh
->b_data
;
1608 de
->rec_len
= cpu_to_le16(sb
->s_blocksize
);
1609 status
= ocfs2_journal_dirty(handle
, new_bh
);
1615 dir_i_size
+= dir
->i_sb
->s_blocksize
;
1616 i_size_write(dir
, dir_i_size
);
1617 dir
->i_blocks
= ocfs2_inode_sector_count(dir
);
1618 status
= ocfs2_mark_inode_dirty(handle
, dir
, parent_fe_bh
);
1625 *new_de_bh
= new_bh
;
1629 up_write(&OCFS2_I(dir
)->ip_alloc_sem
);
1631 ocfs2_commit_trans(osb
, handle
);
1634 ocfs2_free_alloc_context(data_ac
);
1636 ocfs2_free_alloc_context(meta_ac
);
1644 static int ocfs2_find_dir_space_id(struct inode
*dir
, struct buffer_head
*di_bh
,
1645 const char *name
, int namelen
,
1646 struct buffer_head
**ret_de_bh
,
1647 unsigned int *blocks_wanted
)
1650 struct ocfs2_dinode
*di
= (struct ocfs2_dinode
*)di_bh
->b_data
;
1651 struct ocfs2_dir_entry
*de
, *last_de
= NULL
;
1652 char *de_buf
, *limit
;
1653 unsigned long offset
= 0;
1654 unsigned int rec_len
, new_rec_len
;
1656 de_buf
= di
->id2
.i_data
.id_data
;
1657 limit
= de_buf
+ i_size_read(dir
);
1658 rec_len
= OCFS2_DIR_REC_LEN(namelen
);
1660 while (de_buf
< limit
) {
1661 de
= (struct ocfs2_dir_entry
*)de_buf
;
1663 if (!ocfs2_check_dir_entry(dir
, de
, di_bh
, offset
)) {
1667 if (ocfs2_match(namelen
, name
, de
)) {
1671 if (ocfs2_dirent_would_fit(de
, rec_len
)) {
1672 /* Ok, we found a spot. Return this bh and let
1673 * the caller actually fill it in. */
1681 de_buf
+= le16_to_cpu(de
->rec_len
);
1682 offset
+= le16_to_cpu(de
->rec_len
);
1686 * We're going to require expansion of the directory - figure
1687 * out how many blocks we'll need so that a place for the
1688 * dirent can be found.
1691 new_rec_len
= le16_to_cpu(last_de
->rec_len
) + (dir
->i_sb
->s_blocksize
- i_size_read(dir
));
1692 if (new_rec_len
< (rec_len
+ OCFS2_DIR_REC_LEN(last_de
->name_len
)))
1700 static int ocfs2_find_dir_space_el(struct inode
*dir
, const char *name
,
1701 int namelen
, struct buffer_head
**ret_de_bh
)
1703 unsigned long offset
;
1704 struct buffer_head
*bh
= NULL
;
1705 unsigned short rec_len
;
1706 struct ocfs2_dir_entry
*de
;
1707 struct super_block
*sb
= dir
->i_sb
;
1710 status
= ocfs2_read_dir_block(dir
, 0, &bh
, 0);
1716 rec_len
= OCFS2_DIR_REC_LEN(namelen
);
1718 de
= (struct ocfs2_dir_entry
*) bh
->b_data
;
1720 if ((char *)de
>= sb
->s_blocksize
+ bh
->b_data
) {
1724 if (i_size_read(dir
) <= offset
) {
1726 * Caller will have to expand this
1732 status
= ocfs2_read_dir_block(dir
,
1733 offset
>> sb
->s_blocksize_bits
,
1739 /* move to next block */
1740 de
= (struct ocfs2_dir_entry
*) bh
->b_data
;
1742 if (!ocfs2_check_dir_entry(dir
, de
, bh
, offset
)) {
1746 if (ocfs2_match(namelen
, name
, de
)) {
1750 if (ocfs2_dirent_would_fit(de
, rec_len
)) {
1751 /* Ok, we found a spot. Return this bh and let
1752 * the caller actually fill it in. */
1758 offset
+= le16_to_cpu(de
->rec_len
);
1759 de
= (struct ocfs2_dir_entry
*)((char *) de
+ le16_to_cpu(de
->rec_len
));
1770 int ocfs2_prepare_dir_for_insert(struct ocfs2_super
*osb
,
1772 struct buffer_head
*parent_fe_bh
,
1775 struct buffer_head
**ret_de_bh
)
1778 unsigned int blocks_wanted
= 1;
1779 struct buffer_head
*bh
= NULL
;
1781 mlog(0, "getting ready to insert namelen %d into dir %llu\n",
1782 namelen
, (unsigned long long)OCFS2_I(dir
)->ip_blkno
);
1792 if (OCFS2_I(dir
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
) {
1793 ret
= ocfs2_find_dir_space_id(dir
, parent_fe_bh
, name
,
1794 namelen
, &bh
, &blocks_wanted
);
1796 ret
= ocfs2_find_dir_space_el(dir
, name
, namelen
, &bh
);
1798 if (ret
&& ret
!= -ENOSPC
) {
1803 if (ret
== -ENOSPC
) {
1805 * We have to expand the directory to add this name.
1809 ret
= ocfs2_extend_dir(osb
, dir
, parent_fe_bh
, blocks_wanted
,