2 * linux/fs/ext4/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
19 * Hash Tree Directory indexing (c)
20 * Daniel Phillips, 2001
21 * Hash Tree Directory indexing porting
22 * Christopher Li, 2002
23 * Hash Tree Directory indexing cleanup
28 #include <linux/pagemap.h>
29 #include <linux/jbd2.h>
30 #include <linux/time.h>
31 #include <linux/fcntl.h>
32 #include <linux/stat.h>
33 #include <linux/string.h>
34 #include <linux/quotaops.h>
35 #include <linux/buffer_head.h>
36 #include <linux/bio.h>
38 #include "ext4_jbd2.h"
45 * define how far ahead to read directories while searching them.
47 #define NAMEI_RA_CHUNKS 2
48 #define NAMEI_RA_BLOCKS 4
49 #define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS)
50 #define NAMEI_RA_INDEX(c,b) (((c) * NAMEI_RA_BLOCKS) + (b))
52 static struct buffer_head *ext4_append(handle_t *handle,
54 ext4_lblk_t *block, int *err)
56 struct buffer_head *bh;
58 *block = inode->i_size >> inode->i_sb->s_blocksize_bits;
60 bh = ext4_bread(handle, inode, *block, 1, err);
62 inode->i_size += inode->i_sb->s_blocksize;
63 EXT4_I(inode)->i_disksize = inode->i_size;
64 *err = ext4_journal_get_write_access(handle, bh);
74 #define assert(test) J_ASSERT(test)
78 #define swap(x, y) do { typeof(x) z = x; x = y; y = z; } while (0)
82 #define dxtrace(command) command
84 #define dxtrace(command)
108 * dx_root_info is laid out so that if it should somehow get overlaid by a
109 * dirent the two low bits of the hash version will be zero. Therefore, the
110 * hash version mod 4 should never be 0. Sincerely, the paranoia department.
115 struct fake_dirent dot;
117 struct fake_dirent dotdot;
121 __le32 reserved_zero;
123 u8 info_length; /* 8 */
128 struct dx_entry entries[0];
133 struct fake_dirent fake;
134 struct dx_entry entries[0];
140 struct buffer_head *bh;
141 struct dx_entry *entries;
152 static inline ext4_lblk_t dx_get_block(struct dx_entry *entry);
153 static void dx_set_block(struct dx_entry *entry, ext4_lblk_t value);
154 static inline unsigned dx_get_hash (struct dx_entry *entry);
155 static void dx_set_hash (struct dx_entry *entry, unsigned value);
156 static unsigned dx_get_count (struct dx_entry *entries);
157 static unsigned dx_get_limit (struct dx_entry *entries);
158 static void dx_set_count (struct dx_entry *entries, unsigned value);
159 static void dx_set_limit (struct dx_entry *entries, unsigned value);
160 static unsigned dx_root_limit (struct inode *dir, unsigned infosize);
161 static unsigned dx_node_limit (struct inode *dir);
162 static struct dx_frame *dx_probe(struct dentry *dentry,
164 struct dx_hash_info *hinfo,
165 struct dx_frame *frame,
167 static void dx_release (struct dx_frame *frames);
168 static int dx_make_map (struct ext4_dir_entry_2 *de, int size,
169 struct dx_hash_info *hinfo, struct dx_map_entry map[]);
170 static void dx_sort_map(struct dx_map_entry *map, unsigned count);
171 static struct ext4_dir_entry_2 *dx_move_dirents (char *from, char *to,
172 struct dx_map_entry *offsets, int count);
173 static struct ext4_dir_entry_2* dx_pack_dirents (char *base, int size);
174 static void dx_insert_block(struct dx_frame *frame,
175 u32 hash, ext4_lblk_t block);
176 static int ext4_htree_next_block(struct inode *dir, __u32 hash,
177 struct dx_frame *frame,
178 struct dx_frame *frames,
180 static struct buffer_head * ext4_dx_find_entry(struct dentry *dentry,
181 struct ext4_dir_entry_2 **res_dir, int *err);
182 static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
183 struct inode *inode);
186 * p is at least 6 bytes before the end of page
188 static inline struct ext4_dir_entry_2 *
189 ext4_next_entry(struct ext4_dir_entry_2 *p)
191 return (struct ext4_dir_entry_2 *)((char *)p +
192 ext4_rec_len_from_disk(p->rec_len));
196 * Future: use high four bits of block for coalesce-on-delete flags
197 * Mask them off for now.
200 static inline ext4_lblk_t dx_get_block(struct dx_entry *entry)
202 return le32_to_cpu(entry->block) & 0x00ffffff;
205 static inline void dx_set_block(struct dx_entry *entry, ext4_lblk_t value)
207 entry->block = cpu_to_le32(value);
210 static inline unsigned dx_get_hash (struct dx_entry *entry)
212 return le32_to_cpu(entry->hash);
215 static inline void dx_set_hash (struct dx_entry *entry, unsigned value)
217 entry->hash = cpu_to_le32(value);
220 static inline unsigned dx_get_count (struct dx_entry *entries)
222 return le16_to_cpu(((struct dx_countlimit *) entries)->count);
225 static inline unsigned dx_get_limit (struct dx_entry *entries)
227 return le16_to_cpu(((struct dx_countlimit *) entries)->limit);
230 static inline void dx_set_count (struct dx_entry *entries, unsigned value)
232 ((struct dx_countlimit *) entries)->count = cpu_to_le16(value);
235 static inline void dx_set_limit (struct dx_entry *entries, unsigned value)
237 ((struct dx_countlimit *) entries)->limit = cpu_to_le16(value);
240 static inline unsigned dx_root_limit (struct inode *dir, unsigned infosize)
242 unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(1) -
243 EXT4_DIR_REC_LEN(2) - infosize;
244 return entry_space / sizeof(struct dx_entry);
247 static inline unsigned dx_node_limit (struct inode *dir)
249 unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(0);
250 return entry_space / sizeof(struct dx_entry);
257 static void dx_show_index (char * label, struct dx_entry *entries)
259 int i, n = dx_get_count (entries);
260 printk("%s index ", label);
261 for (i = 0; i < n; i++) {
262 printk("%x->%lu ", i? dx_get_hash(entries + i) :
263 0, (unsigned long)dx_get_block(entries + i));
275 static struct stats dx_show_leaf(struct dx_hash_info *hinfo, struct ext4_dir_entry_2 *de,
276 int size, int show_names)
278 unsigned names = 0, space = 0;
279 char *base = (char *) de;
280 struct dx_hash_info h = *hinfo;
283 while ((char *) de < base + size)
289 int len = de->name_len;
290 char *name = de->name;
291 while (len--) printk("%c", *name++);
292 ext4fs_dirhash(de->name, de->name_len, &h);
293 printk(":%x.%u ", h.hash,
294 ((char *) de - base));
296 space += EXT4_DIR_REC_LEN(de->name_len);
299 de = ext4_next_entry(de);
301 printk("(%i)\n", names);
302 return (struct stats) { names, space, 1 };
305 struct stats dx_show_entries(struct dx_hash_info *hinfo, struct inode *dir,
306 struct dx_entry *entries, int levels)
308 unsigned blocksize = dir->i_sb->s_blocksize;
309 unsigned count = dx_get_count (entries), names = 0, space = 0, i;
311 struct buffer_head *bh;
313 printk("%i indexed blocks...\n", count);
314 for (i = 0; i < count; i++, entries++)
316 ext4_lblk_t block = dx_get_block(entries);
317 ext4_lblk_t hash = i ? dx_get_hash(entries): 0;
318 u32 range = i < count - 1? (dx_get_hash(entries + 1) - hash): ~hash;
320 printk("%s%3u:%03u hash %8x/%8x ",levels?"":" ", i, block, hash, range);
321 if (!(bh = ext4_bread (NULL,dir, block, 0,&err))) continue;
323 dx_show_entries(hinfo, dir, ((struct dx_node *) bh->b_data)->entries, levels - 1):
324 dx_show_leaf(hinfo, (struct ext4_dir_entry_2 *) bh->b_data, blocksize, 0);
325 names += stats.names;
326 space += stats.space;
327 bcount += stats.bcount;
331 printk("%snames %u, fullness %u (%u%%)\n", levels?"":" ",
332 names, space/bcount,(space/bcount)*100/blocksize);
333 return (struct stats) { names, space, bcount};
335 #endif /* DX_DEBUG */
338 * Probe for a directory leaf block to search.
340 * dx_probe can return ERR_BAD_DX_DIR, which means there was a format
341 * error in the directory index, and the caller should fall back to
342 * searching the directory normally. The callers of dx_probe **MUST**
343 * check for this error code, and make sure it never gets reflected
346 static struct dx_frame *
347 dx_probe(struct dentry *dentry, struct inode *dir,
348 struct dx_hash_info *hinfo, struct dx_frame *frame_in, int *err)
350 unsigned count, indirect;
351 struct dx_entry *at, *entries, *p, *q, *m;
352 struct dx_root *root;
353 struct buffer_head *bh;
354 struct dx_frame *frame = frame_in;
359 dir = dentry->d_parent->d_inode;
360 if (!(bh = ext4_bread (NULL,dir, 0, 0, err)))
362 root = (struct dx_root *) bh->b_data;
363 if (root->info.hash_version != DX_HASH_TEA &&
364 root->info.hash_version != DX_HASH_HALF_MD4 &&
365 root->info.hash_version != DX_HASH_LEGACY) {
366 ext4_warning(dir->i_sb, __func__,
367 "Unrecognised inode hash code %d",
368 root->info.hash_version);
370 *err = ERR_BAD_DX_DIR;
373 hinfo->hash_version = root->info.hash_version;
374 if (hinfo->hash_version <= DX_HASH_TEA)
375 hinfo->hash_version += EXT4_SB(dir->i_sb)->s_hash_unsigned;
376 hinfo->seed = EXT4_SB(dir->i_sb)->s_hash_seed;
378 ext4fs_dirhash(dentry->d_name.name, dentry->d_name.len, hinfo);
381 if (root->info.unused_flags & 1) {
382 ext4_warning(dir->i_sb, __func__,
383 "Unimplemented inode hash flags: %#06x",
384 root->info.unused_flags);
386 *err = ERR_BAD_DX_DIR;
390 if ((indirect = root->info.indirect_levels) > 1) {
391 ext4_warning(dir->i_sb, __func__,
392 "Unimplemented inode hash depth: %#06x",
393 root->info.indirect_levels);
395 *err = ERR_BAD_DX_DIR;
399 entries = (struct dx_entry *) (((char *)&root->info) +
400 root->info.info_length);
402 if (dx_get_limit(entries) != dx_root_limit(dir,
403 root->info.info_length)) {
404 ext4_warning(dir->i_sb, __func__,
405 "dx entry: limit != root limit");
407 *err = ERR_BAD_DX_DIR;
411 dxtrace (printk("Look up %x", hash));
414 count = dx_get_count(entries);
415 if (!count || count > dx_get_limit(entries)) {
416 ext4_warning(dir->i_sb, __func__,
417 "dx entry: no count or count > limit");
419 *err = ERR_BAD_DX_DIR;
424 q = entries + count - 1;
428 dxtrace(printk("."));
429 if (dx_get_hash(m) > hash)
435 if (0) // linear search cross check
437 unsigned n = count - 1;
441 dxtrace(printk(","));
442 if (dx_get_hash(++at) > hash)
448 assert (at == p - 1);
452 dxtrace(printk(" %x->%u\n", at == entries? 0: dx_get_hash(at), dx_get_block(at)));
454 frame->entries = entries;
456 if (!indirect--) return frame;
457 if (!(bh = ext4_bread (NULL,dir, dx_get_block(at), 0, err)))
459 at = entries = ((struct dx_node *) bh->b_data)->entries;
460 if (dx_get_limit(entries) != dx_node_limit (dir)) {
461 ext4_warning(dir->i_sb, __func__,
462 "dx entry: limit != node limit");
464 *err = ERR_BAD_DX_DIR;
471 while (frame >= frame_in) {
476 if (*err == ERR_BAD_DX_DIR)
477 ext4_warning(dir->i_sb, __func__,
478 "Corrupt dir inode %ld, running e2fsck is "
479 "recommended.", dir->i_ino);
483 static void dx_release (struct dx_frame *frames)
485 if (frames[0].bh == NULL)
488 if (((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels)
489 brelse(frames[1].bh);
490 brelse(frames[0].bh);
494 * This function increments the frame pointer to search the next leaf
495 * block, and reads in the necessary intervening nodes if the search
496 * should be necessary. Whether or not the search is necessary is
497 * controlled by the hash parameter. If the hash value is even, then
498 * the search is only continued if the next block starts with that
499 * hash value. This is used if we are searching for a specific file.
501 * If the hash value is HASH_NB_ALWAYS, then always go to the next block.
503 * This function returns 1 if the caller should continue to search,
504 * or 0 if it should not. If there is an error reading one of the
505 * index blocks, it will a negative error code.
507 * If start_hash is non-null, it will be filled in with the starting
508 * hash of the next page.
510 static int ext4_htree_next_block(struct inode *dir, __u32 hash,
511 struct dx_frame *frame,
512 struct dx_frame *frames,
516 struct buffer_head *bh;
517 int err, num_frames = 0;
522 * Find the next leaf page by incrementing the frame pointer.
523 * If we run out of entries in the interior node, loop around and
524 * increment pointer in the parent node. When we break out of
525 * this loop, num_frames indicates the number of interior
526 * nodes need to be read.
529 if (++(p->at) < p->entries + dx_get_count(p->entries))
538 * If the hash is 1, then continue only if the next page has a
539 * continuation hash of any value. This is used for readdir
540 * handling. Otherwise, check to see if the hash matches the
541 * desired contiuation hash. If it doesn't, return since
542 * there's no point to read in the successive index pages.
544 bhash = dx_get_hash(p->at);
547 if ((hash & 1) == 0) {
548 if ((bhash & ~1) != hash)
552 * If the hash is HASH_NB_ALWAYS, we always go to the next
553 * block so no check is necessary
555 while (num_frames--) {
556 if (!(bh = ext4_bread(NULL, dir, dx_get_block(p->at),
558 return err; /* Failure */
562 p->at = p->entries = ((struct dx_node *) bh->b_data)->entries;
569 * This function fills a red-black tree with information from a
570 * directory block. It returns the number directory entries loaded
571 * into the tree. If there is an error it is returned in err.
573 static int htree_dirblock_to_tree(struct file *dir_file,
574 struct inode *dir, ext4_lblk_t block,
575 struct dx_hash_info *hinfo,
576 __u32 start_hash, __u32 start_minor_hash)
578 struct buffer_head *bh;
579 struct ext4_dir_entry_2 *de, *top;
582 dxtrace(printk(KERN_INFO "In htree dirblock_to_tree: block %lu\n",
583 (unsigned long)block));
584 if (!(bh = ext4_bread (NULL, dir, block, 0, &err)))
587 de = (struct ext4_dir_entry_2 *) bh->b_data;
588 top = (struct ext4_dir_entry_2 *) ((char *) de +
589 dir->i_sb->s_blocksize -
590 EXT4_DIR_REC_LEN(0));
591 for (; de < top; de = ext4_next_entry(de)) {
592 if (!ext4_check_dir_entry("htree_dirblock_to_tree", dir, de, bh,
593 (block<<EXT4_BLOCK_SIZE_BITS(dir->i_sb))
594 +((char *)de - bh->b_data))) {
595 /* On error, skip the f_pos to the next block. */
596 dir_file->f_pos = (dir_file->f_pos |
597 (dir->i_sb->s_blocksize - 1)) + 1;
601 ext4fs_dirhash(de->name, de->name_len, hinfo);
602 if ((hinfo->hash < start_hash) ||
603 ((hinfo->hash == start_hash) &&
604 (hinfo->minor_hash < start_minor_hash)))
608 if ((err = ext4_htree_store_dirent(dir_file,
609 hinfo->hash, hinfo->minor_hash, de)) != 0) {
621 * This function fills a red-black tree with information from a
622 * directory. We start scanning the directory in hash order, starting
623 * at start_hash and start_minor_hash.
625 * This function returns the number of entries inserted into the tree,
626 * or a negative error code.
628 int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
629 __u32 start_minor_hash, __u32 *next_hash)
631 struct dx_hash_info hinfo;
632 struct ext4_dir_entry_2 *de;
633 struct dx_frame frames[2], *frame;
640 dxtrace(printk("In htree_fill_tree, start hash: %x:%x\n", start_hash,
642 dir = dir_file->f_path.dentry->d_inode;
643 if (!(EXT4_I(dir)->i_flags & EXT4_INDEX_FL)) {
644 hinfo.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
645 if (hinfo.hash_version <= DX_HASH_TEA)
646 hinfo.hash_version +=
647 EXT4_SB(dir->i_sb)->s_hash_unsigned;
648 hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
649 count = htree_dirblock_to_tree(dir_file, dir, 0, &hinfo,
650 start_hash, start_minor_hash);
654 hinfo.hash = start_hash;
655 hinfo.minor_hash = 0;
656 frame = dx_probe(NULL, dir_file->f_path.dentry->d_inode, &hinfo, frames, &err);
660 /* Add '.' and '..' from the htree header */
661 if (!start_hash && !start_minor_hash) {
662 de = (struct ext4_dir_entry_2 *) frames[0].bh->b_data;
663 if ((err = ext4_htree_store_dirent(dir_file, 0, 0, de)) != 0)
667 if (start_hash < 2 || (start_hash ==2 && start_minor_hash==0)) {
668 de = (struct ext4_dir_entry_2 *) frames[0].bh->b_data;
669 de = ext4_next_entry(de);
670 if ((err = ext4_htree_store_dirent(dir_file, 2, 0, de)) != 0)
676 block = dx_get_block(frame->at);
677 ret = htree_dirblock_to_tree(dir_file, dir, block, &hinfo,
678 start_hash, start_minor_hash);
685 ret = ext4_htree_next_block(dir, HASH_NB_ALWAYS,
686 frame, frames, &hashval);
687 *next_hash = hashval;
693 * Stop if: (a) there are no more entries, or
694 * (b) we have inserted at least one entry and the
695 * next hash value is not a continuation
698 (count && ((hashval & 1) == 0)))
702 dxtrace(printk("Fill tree: returned %d entries, next hash: %x\n",
712 * Directory block splitting, compacting
716 * Create map of hash values, offsets, and sizes, stored at end of block.
717 * Returns number of entries mapped.
719 static int dx_make_map (struct ext4_dir_entry_2 *de, int size,
720 struct dx_hash_info *hinfo, struct dx_map_entry *map_tail)
723 char *base = (char *) de;
724 struct dx_hash_info h = *hinfo;
726 while ((char *) de < base + size)
728 if (de->name_len && de->inode) {
729 ext4fs_dirhash(de->name, de->name_len, &h);
731 map_tail->hash = h.hash;
732 map_tail->offs = (u16) ((char *) de - base);
733 map_tail->size = le16_to_cpu(de->rec_len);
737 /* XXX: do we need to check rec_len == 0 case? -Chris */
738 de = ext4_next_entry(de);
743 /* Sort map by hash value */
744 static void dx_sort_map (struct dx_map_entry *map, unsigned count)
746 struct dx_map_entry *p, *q, *top = map + count - 1;
748 /* Combsort until bubble sort doesn't suck */
751 if (count - 9 < 2) /* 9, 10 -> 11 */
753 for (p = top, q = p - count; q >= map; p--, q--)
754 if (p->hash < q->hash)
757 /* Garden variety bubble sort */
762 if (q[1].hash >= q[0].hash)
770 static void dx_insert_block(struct dx_frame *frame, u32 hash, ext4_lblk_t block)
772 struct dx_entry *entries = frame->entries;
773 struct dx_entry *old = frame->at, *new = old + 1;
774 int count = dx_get_count(entries);
776 assert(count < dx_get_limit(entries));
777 assert(old < entries + count);
778 memmove(new + 1, new, (char *)(entries + count) - (char *)(new));
779 dx_set_hash(new, hash);
780 dx_set_block(new, block);
781 dx_set_count(entries, count + 1);
784 static void ext4_update_dx_flag(struct inode *inode)
786 if (!EXT4_HAS_COMPAT_FEATURE(inode->i_sb,
787 EXT4_FEATURE_COMPAT_DIR_INDEX))
788 EXT4_I(inode)->i_flags &= ~EXT4_INDEX_FL;
792 * NOTE! unlike strncmp, ext4_match returns 1 for success, 0 for failure.
794 * `len <= EXT4_NAME_LEN' is guaranteed by caller.
795 * `de != NULL' is guaranteed by caller.
797 static inline int ext4_match (int len, const char * const name,
798 struct ext4_dir_entry_2 * de)
800 if (len != de->name_len)
804 return !memcmp(name, de->name, len);
808 * Returns 0 if not found, -1 on failure, and 1 on success
810 static inline int search_dirblock(struct buffer_head * bh,
812 struct dentry *dentry,
813 unsigned long offset,
814 struct ext4_dir_entry_2 ** res_dir)
816 struct ext4_dir_entry_2 * de;
819 const char *name = dentry->d_name.name;
820 int namelen = dentry->d_name.len;
822 de = (struct ext4_dir_entry_2 *) bh->b_data;
823 dlimit = bh->b_data + dir->i_sb->s_blocksize;
824 while ((char *) de < dlimit) {
825 /* this code is executed quadratically often */
826 /* do minimal checking `by hand' */
828 if ((char *) de + namelen <= dlimit &&
829 ext4_match (namelen, name, de)) {
830 /* found a match - just to be sure, do a full check */
831 if (!ext4_check_dir_entry("ext4_find_entry",
832 dir, de, bh, offset))
837 /* prevent looping on a bad block */
838 de_len = ext4_rec_len_from_disk(de->rec_len);
842 de = (struct ext4_dir_entry_2 *) ((char *) de + de_len);
851 * finds an entry in the specified directory with the wanted name. It
852 * returns the cache buffer in which the entry was found, and the entry
853 * itself (as a parameter - res_dir). It does NOT read the inode of the
854 * entry - you'll have to do that yourself if you want to.
856 * The returned buffer_head has ->b_count elevated. The caller is expected
857 * to brelse() it when appropriate.
859 static struct buffer_head * ext4_find_entry (struct dentry *dentry,
860 struct ext4_dir_entry_2 ** res_dir)
862 struct super_block * sb;
863 struct buffer_head * bh_use[NAMEI_RA_SIZE];
864 struct buffer_head * bh, *ret = NULL;
865 ext4_lblk_t start, block, b;
866 int ra_max = 0; /* Number of bh's in the readahead
868 int ra_ptr = 0; /* Current index into readahead
873 struct inode *dir = dentry->d_parent->d_inode;
878 namelen = dentry->d_name.len;
879 if (namelen > EXT4_NAME_LEN)
882 bh = ext4_dx_find_entry(dentry, res_dir, &err);
884 * On success, or if the error was file not found,
885 * return. Otherwise, fall back to doing a search the
888 if (bh || (err != ERR_BAD_DX_DIR))
890 dxtrace(printk("ext4_find_entry: dx failed, falling back\n"));
892 nblocks = dir->i_size >> EXT4_BLOCK_SIZE_BITS(sb);
893 start = EXT4_I(dir)->i_dir_start_lookup;
894 if (start >= nblocks)
900 * We deal with the read-ahead logic here.
902 if (ra_ptr >= ra_max) {
903 /* Refill the readahead buffer */
906 for (ra_max = 0; ra_max < NAMEI_RA_SIZE; ra_max++) {
908 * Terminate if we reach the end of the
909 * directory and must wrap, or if our
910 * search has finished at this block.
912 if (b >= nblocks || (num && block == start)) {
913 bh_use[ra_max] = NULL;
917 bh = ext4_getblk(NULL, dir, b++, 0, &err);
920 ll_rw_block(READ_META, 1, &bh);
923 if ((bh = bh_use[ra_ptr++]) == NULL)
926 if (!buffer_uptodate(bh)) {
927 /* read error, skip block & hope for the best */
928 ext4_error(sb, __func__, "reading directory #%lu "
929 "offset %lu", dir->i_ino,
930 (unsigned long)block);
934 i = search_dirblock(bh, dir, dentry,
935 block << EXT4_BLOCK_SIZE_BITS(sb), res_dir);
937 EXT4_I(dir)->i_dir_start_lookup = block;
939 goto cleanup_and_exit;
943 goto cleanup_and_exit;
946 if (++block >= nblocks)
948 } while (block != start);
951 * If the directory has grown while we were searching, then
952 * search the last part of the directory before giving up.
955 nblocks = dir->i_size >> EXT4_BLOCK_SIZE_BITS(sb);
956 if (block < nblocks) {
962 /* Clean up the read-ahead blocks */
963 for (; ra_ptr < ra_max; ra_ptr++)
964 brelse (bh_use[ra_ptr]);
968 static struct buffer_head * ext4_dx_find_entry(struct dentry *dentry,
969 struct ext4_dir_entry_2 **res_dir, int *err)
971 struct super_block * sb;
972 struct dx_hash_info hinfo;
974 struct dx_frame frames[2], *frame;
975 struct ext4_dir_entry_2 *de, *top;
976 struct buffer_head *bh;
979 int namelen = dentry->d_name.len;
980 const u8 *name = dentry->d_name.name;
981 struct inode *dir = dentry->d_parent->d_inode;
984 /* NFS may look up ".." - look at dx_root directory block */
985 if (namelen > 2 || name[0] != '.'||(name[1] != '.' && name[1] != '\0')){
986 if (!(frame = dx_probe(dentry, NULL, &hinfo, frames, err)))
990 frame->bh = NULL; /* for dx_release() */
991 frame->at = (struct dx_entry *)frames; /* hack for zero entry*/
992 dx_set_block(frame->at, 0); /* dx_root block is 0 */
996 block = dx_get_block(frame->at);
997 if (!(bh = ext4_bread (NULL,dir, block, 0, err)))
999 de = (struct ext4_dir_entry_2 *) bh->b_data;
1000 top = (struct ext4_dir_entry_2 *) ((char *) de + sb->s_blocksize -
1001 EXT4_DIR_REC_LEN(0));
1002 for (; de < top; de = ext4_next_entry(de)) {
1003 int off = (block << EXT4_BLOCK_SIZE_BITS(sb))
1004 + ((char *) de - bh->b_data);
1006 if (!ext4_check_dir_entry(__func__, dir, de, bh, off)) {
1008 *err = ERR_BAD_DX_DIR;
1012 if (ext4_match(namelen, name, de)) {
1019 /* Check to see if we should continue to search */
1020 retval = ext4_htree_next_block(dir, hash, frame,
1023 ext4_warning(sb, __func__,
1024 "error reading index page in directory #%lu",
1029 } while (retval == 1);
1033 dxtrace(printk("%s not found\n", name));
1034 dx_release (frames);
1038 static struct dentry *ext4_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
1040 struct inode * inode;
1041 struct ext4_dir_entry_2 * de;
1042 struct buffer_head * bh;
1044 if (dentry->d_name.len > EXT4_NAME_LEN)
1045 return ERR_PTR(-ENAMETOOLONG);
1047 bh = ext4_find_entry(dentry, &de);
1050 unsigned long ino = le32_to_cpu(de->inode);
1052 if (!ext4_valid_inum(dir->i_sb, ino)) {
1053 ext4_error(dir->i_sb, "ext4_lookup",
1054 "bad inode number: %lu", ino);
1055 return ERR_PTR(-EIO);
1057 inode = ext4_iget(dir->i_sb, ino);
1058 if (unlikely(IS_ERR(inode))) {
1059 if (PTR_ERR(inode) == -ESTALE) {
1060 ext4_error(dir->i_sb, __func__,
1061 "deleted inode referenced: %u",
1063 return ERR_PTR(-EIO);
1065 return ERR_CAST(inode);
1069 return d_splice_alias(inode, dentry);
1073 struct dentry *ext4_get_parent(struct dentry *child)
1076 struct dentry *parent;
1077 struct inode *inode;
1078 struct dentry dotdot;
1079 struct ext4_dir_entry_2 * de;
1080 struct buffer_head *bh;
1082 dotdot.d_name.name = "..";
1083 dotdot.d_name.len = 2;
1084 dotdot.d_parent = child; /* confusing, isn't it! */
1086 bh = ext4_find_entry(&dotdot, &de);
1089 return ERR_PTR(-ENOENT);
1090 ino = le32_to_cpu(de->inode);
1093 if (!ext4_valid_inum(child->d_inode->i_sb, ino)) {
1094 ext4_error(child->d_inode->i_sb, "ext4_get_parent",
1095 "bad inode number: %lu", ino);
1096 return ERR_PTR(-EIO);
1099 inode = ext4_iget(child->d_inode->i_sb, ino);
1101 return ERR_CAST(inode);
1103 parent = d_alloc_anon(inode);
1106 parent = ERR_PTR(-ENOMEM);
1112 static unsigned char ext4_type_by_mode[S_IFMT >> S_SHIFT] = {
1113 [S_IFREG >> S_SHIFT] = EXT4_FT_REG_FILE,
1114 [S_IFDIR >> S_SHIFT] = EXT4_FT_DIR,
1115 [S_IFCHR >> S_SHIFT] = EXT4_FT_CHRDEV,
1116 [S_IFBLK >> S_SHIFT] = EXT4_FT_BLKDEV,
1117 [S_IFIFO >> S_SHIFT] = EXT4_FT_FIFO,
1118 [S_IFSOCK >> S_SHIFT] = EXT4_FT_SOCK,
1119 [S_IFLNK >> S_SHIFT] = EXT4_FT_SYMLINK,
1122 static inline void ext4_set_de_type(struct super_block *sb,
1123 struct ext4_dir_entry_2 *de,
1125 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FILETYPE))
1126 de->file_type = ext4_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1130 * Move count entries from end of map between two memory locations.
1131 * Returns pointer to last entry moved.
1133 static struct ext4_dir_entry_2 *
1134 dx_move_dirents(char *from, char *to, struct dx_map_entry *map, int count)
1136 unsigned rec_len = 0;
1139 struct ext4_dir_entry_2 *de = (struct ext4_dir_entry_2 *) (from + map->offs);
1140 rec_len = EXT4_DIR_REC_LEN(de->name_len);
1141 memcpy (to, de, rec_len);
1142 ((struct ext4_dir_entry_2 *) to)->rec_len =
1143 ext4_rec_len_to_disk(rec_len);
1148 return (struct ext4_dir_entry_2 *) (to - rec_len);
1152 * Compact each dir entry in the range to the minimal rec_len.
1153 * Returns pointer to last entry in range.
1155 static struct ext4_dir_entry_2* dx_pack_dirents(char *base, int size)
1157 struct ext4_dir_entry_2 *next, *to, *prev, *de = (struct ext4_dir_entry_2 *) base;
1158 unsigned rec_len = 0;
1161 while ((char*)de < base + size) {
1162 next = ext4_next_entry(de);
1163 if (de->inode && de->name_len) {
1164 rec_len = EXT4_DIR_REC_LEN(de->name_len);
1166 memmove(to, de, rec_len);
1167 to->rec_len = ext4_rec_len_to_disk(rec_len);
1169 to = (struct ext4_dir_entry_2 *) (((char *) to) + rec_len);
1177 * Split a full leaf block to make room for a new dir entry.
1178 * Allocate a new block, and move entries so that they are approx. equally full.
1179 * Returns pointer to de in block into which the new entry will be inserted.
1181 static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
1182 struct buffer_head **bh,struct dx_frame *frame,
1183 struct dx_hash_info *hinfo, int *error)
1185 unsigned blocksize = dir->i_sb->s_blocksize;
1186 unsigned count, continued;
1187 struct buffer_head *bh2;
1188 ext4_lblk_t newblock;
1190 struct dx_map_entry *map;
1191 char *data1 = (*bh)->b_data, *data2;
1192 unsigned split, move, size, i;
1193 struct ext4_dir_entry_2 *de = NULL, *de2;
1196 bh2 = ext4_append (handle, dir, &newblock, &err);
1203 BUFFER_TRACE(*bh, "get_write_access");
1204 err = ext4_journal_get_write_access(handle, *bh);
1208 BUFFER_TRACE(frame->bh, "get_write_access");
1209 err = ext4_journal_get_write_access(handle, frame->bh);
1213 data2 = bh2->b_data;
1215 /* create map in the end of data2 block */
1216 map = (struct dx_map_entry *) (data2 + blocksize);
1217 count = dx_make_map ((struct ext4_dir_entry_2 *) data1,
1218 blocksize, hinfo, map);
1220 dx_sort_map (map, count);
1221 /* Split the existing block in the middle, size-wise */
1224 for (i = count-1; i >= 0; i--) {
1225 /* is more than half of this entry in 2nd half of the block? */
1226 if (size + map[i].size/2 > blocksize/2)
1228 size += map[i].size;
1231 /* map index at which we will split */
1232 split = count - move;
1233 hash2 = map[split].hash;
1234 continued = hash2 == map[split - 1].hash;
1235 dxtrace(printk(KERN_INFO "Split block %lu at %x, %i/%i\n",
1236 (unsigned long)dx_get_block(frame->at),
1237 hash2, split, count-split));
1239 /* Fancy dance to stay within two buffers */
1240 de2 = dx_move_dirents(data1, data2, map + split, count - split);
1241 de = dx_pack_dirents(data1,blocksize);
1242 de->rec_len = ext4_rec_len_to_disk(data1 + blocksize - (char *) de);
1243 de2->rec_len = ext4_rec_len_to_disk(data2 + blocksize - (char *) de2);
1244 dxtrace(dx_show_leaf (hinfo, (struct ext4_dir_entry_2 *) data1, blocksize, 1));
1245 dxtrace(dx_show_leaf (hinfo, (struct ext4_dir_entry_2 *) data2, blocksize, 1));
1247 /* Which block gets the new entry? */
1248 if (hinfo->hash >= hash2)
1253 dx_insert_block (frame, hash2 + continued, newblock);
1254 err = ext4_journal_dirty_metadata (handle, bh2);
1257 err = ext4_journal_dirty_metadata (handle, frame->bh);
1261 dxtrace(dx_show_index ("frame", frame->entries));
1268 ext4_std_error(dir->i_sb, err);
1275 * Add a new entry into a directory (leaf) block. If de is non-NULL,
1276 * it points to a directory entry which is guaranteed to be large
1277 * enough for new directory entry. If de is NULL, then
1278 * add_dirent_to_buf will attempt search the directory block for
1279 * space. It will return -ENOSPC if no space is available, and -EIO
1280 * and -EEXIST if directory entry already exists.
1282 * NOTE! bh is NOT released in the case where ENOSPC is returned. In
1283 * all other cases bh is released.
1285 static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1286 struct inode *inode, struct ext4_dir_entry_2 *de,
1287 struct buffer_head * bh)
1289 struct inode *dir = dentry->d_parent->d_inode;
1290 const char *name = dentry->d_name.name;
1291 int namelen = dentry->d_name.len;
1292 unsigned long offset = 0;
1293 unsigned short reclen;
1294 int nlen, rlen, err;
1297 reclen = EXT4_DIR_REC_LEN(namelen);
1299 de = (struct ext4_dir_entry_2 *)bh->b_data;
1300 top = bh->b_data + dir->i_sb->s_blocksize - reclen;
1301 while ((char *) de <= top) {
1302 if (!ext4_check_dir_entry("ext4_add_entry", dir, de,
1307 if (ext4_match (namelen, name, de)) {
1311 nlen = EXT4_DIR_REC_LEN(de->name_len);
1312 rlen = ext4_rec_len_from_disk(de->rec_len);
1313 if ((de->inode? rlen - nlen: rlen) >= reclen)
1315 de = (struct ext4_dir_entry_2 *)((char *)de + rlen);
1318 if ((char *) de > top)
1321 BUFFER_TRACE(bh, "get_write_access");
1322 err = ext4_journal_get_write_access(handle, bh);
1324 ext4_std_error(dir->i_sb, err);
1329 /* By now the buffer is marked for journaling */
1330 nlen = EXT4_DIR_REC_LEN(de->name_len);
1331 rlen = ext4_rec_len_from_disk(de->rec_len);
1333 struct ext4_dir_entry_2 *de1 = (struct ext4_dir_entry_2 *)((char *)de + nlen);
1334 de1->rec_len = ext4_rec_len_to_disk(rlen - nlen);
1335 de->rec_len = ext4_rec_len_to_disk(nlen);
1338 de->file_type = EXT4_FT_UNKNOWN;
1340 de->inode = cpu_to_le32(inode->i_ino);
1341 ext4_set_de_type(dir->i_sb, de, inode->i_mode);
1344 de->name_len = namelen;
1345 memcpy (de->name, name, namelen);
1347 * XXX shouldn't update any times until successful
1348 * completion of syscall, but too many callers depend
1351 * XXX similarly, too many callers depend on
1352 * ext4_new_inode() setting the times, but error
1353 * recovery deletes the inode, so the worst that can
1354 * happen is that the times are slightly out of date
1355 * and/or different from the directory change time.
1357 dir->i_mtime = dir->i_ctime = ext4_current_time(dir);
1358 ext4_update_dx_flag(dir);
1360 ext4_mark_inode_dirty(handle, dir);
1361 BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
1362 err = ext4_journal_dirty_metadata(handle, bh);
1364 ext4_std_error(dir->i_sb, err);
1370 * This converts a one block unindexed directory to a 3 block indexed
1371 * directory, and adds the dentry to the indexed directory.
1373 static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1374 struct inode *inode, struct buffer_head *bh)
1376 struct inode *dir = dentry->d_parent->d_inode;
1377 const char *name = dentry->d_name.name;
1378 int namelen = dentry->d_name.len;
1379 struct buffer_head *bh2;
1380 struct dx_root *root;
1381 struct dx_frame frames[2], *frame;
1382 struct dx_entry *entries;
1383 struct ext4_dir_entry_2 *de, *de2;
1388 struct dx_hash_info hinfo;
1390 struct fake_dirent *fde;
1392 blocksize = dir->i_sb->s_blocksize;
1393 dxtrace(printk(KERN_DEBUG "Creating index: inode %lu\n", dir->i_ino));
1394 retval = ext4_journal_get_write_access(handle, bh);
1396 ext4_std_error(dir->i_sb, retval);
1400 root = (struct dx_root *) bh->b_data;
1402 /* The 0th block becomes the root, move the dirents out */
1403 fde = &root->dotdot;
1404 de = (struct ext4_dir_entry_2 *)((char *)fde +
1405 ext4_rec_len_from_disk(fde->rec_len));
1406 if ((char *) de >= (((char *) root) + blocksize)) {
1407 ext4_error(dir->i_sb, __func__,
1408 "invalid rec_len for '..' in inode %lu",
1413 len = ((char *) root) + blocksize - (char *) de;
1415 /* Allocate new block for the 0th block's dirents */
1416 bh2 = ext4_append (handle, dir, &block, &retval);
1421 EXT4_I(dir)->i_flags |= EXT4_INDEX_FL;
1422 data1 = bh2->b_data;
1424 memcpy (data1, de, len);
1425 de = (struct ext4_dir_entry_2 *) data1;
1427 while ((char *)(de2 = ext4_next_entry(de)) < top)
1429 de->rec_len = ext4_rec_len_to_disk(data1 + blocksize - (char *) de);
1430 /* Initialize the root; the dot dirents already exist */
1431 de = (struct ext4_dir_entry_2 *) (&root->dotdot);
1432 de->rec_len = ext4_rec_len_to_disk(blocksize - EXT4_DIR_REC_LEN(2));
1433 memset (&root->info, 0, sizeof(root->info));
1434 root->info.info_length = sizeof(root->info);
1435 root->info.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
1436 entries = root->entries;
1437 dx_set_block (entries, 1);
1438 dx_set_count (entries, 1);
1439 dx_set_limit (entries, dx_root_limit(dir, sizeof(root->info)));
1441 /* Initialize as for dx_probe */
1442 hinfo.hash_version = root->info.hash_version;
1443 if (hinfo.hash_version <= DX_HASH_TEA)
1444 hinfo.hash_version += EXT4_SB(dir->i_sb)->s_hash_unsigned;
1445 hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
1446 ext4fs_dirhash(name, namelen, &hinfo);
1448 frame->entries = entries;
1449 frame->at = entries;
1452 de = do_split(handle,dir, &bh, frame, &hinfo, &retval);
1453 dx_release (frames);
1457 return add_dirent_to_buf(handle, dentry, inode, de, bh);
1463 * adds a file entry to the specified directory, using the same
1464 * semantics as ext4_find_entry(). It returns NULL if it failed.
1466 * NOTE!! The inode part of 'de' is left at 0 - which means you
1467 * may not sleep between calling this and putting something into
1468 * the entry, as someone else might have used it while you slept.
1470 static int ext4_add_entry (handle_t *handle, struct dentry *dentry,
1471 struct inode *inode)
1473 struct inode *dir = dentry->d_parent->d_inode;
1474 unsigned long offset;
1475 struct buffer_head * bh;
1476 struct ext4_dir_entry_2 *de;
1477 struct super_block * sb;
1481 ext4_lblk_t block, blocks;
1484 blocksize = sb->s_blocksize;
1485 if (!dentry->d_name.len)
1488 retval = ext4_dx_add_entry(handle, dentry, inode);
1489 if (!retval || (retval != ERR_BAD_DX_DIR))
1491 EXT4_I(dir)->i_flags &= ~EXT4_INDEX_FL;
1493 ext4_mark_inode_dirty(handle, dir);
1495 blocks = dir->i_size >> sb->s_blocksize_bits;
1496 for (block = 0, offset = 0; block < blocks; block++) {
1497 bh = ext4_bread(handle, dir, block, 0, &retval);
1500 retval = add_dirent_to_buf(handle, dentry, inode, NULL, bh);
1501 if (retval != -ENOSPC)
1504 if (blocks == 1 && !dx_fallback &&
1505 EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_DIR_INDEX))
1506 return make_indexed_dir(handle, dentry, inode, bh);
1509 bh = ext4_append(handle, dir, &block, &retval);
1512 de = (struct ext4_dir_entry_2 *) bh->b_data;
1514 de->rec_len = ext4_rec_len_to_disk(blocksize);
1515 return add_dirent_to_buf(handle, dentry, inode, de, bh);
1519 * Returns 0 for success, or a negative error value
1521 static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
1522 struct inode *inode)
1524 struct dx_frame frames[2], *frame;
1525 struct dx_entry *entries, *at;
1526 struct dx_hash_info hinfo;
1527 struct buffer_head * bh;
1528 struct inode *dir = dentry->d_parent->d_inode;
1529 struct super_block * sb = dir->i_sb;
1530 struct ext4_dir_entry_2 *de;
1533 frame = dx_probe(dentry, NULL, &hinfo, frames, &err);
1536 entries = frame->entries;
1539 if (!(bh = ext4_bread(handle,dir, dx_get_block(frame->at), 0, &err)))
1542 BUFFER_TRACE(bh, "get_write_access");
1543 err = ext4_journal_get_write_access(handle, bh);
1547 err = add_dirent_to_buf(handle, dentry, inode, NULL, bh);
1548 if (err != -ENOSPC) {
1553 /* Block full, should compress but for now just split */
1554 dxtrace(printk("using %u of %u node entries\n",
1555 dx_get_count(entries), dx_get_limit(entries)));
1556 /* Need to split index? */
1557 if (dx_get_count(entries) == dx_get_limit(entries)) {
1558 ext4_lblk_t newblock;
1559 unsigned icount = dx_get_count(entries);
1560 int levels = frame - frames;
1561 struct dx_entry *entries2;
1562 struct dx_node *node2;
1563 struct buffer_head *bh2;
1565 if (levels && (dx_get_count(frames->entries) ==
1566 dx_get_limit(frames->entries))) {
1567 ext4_warning(sb, __func__,
1568 "Directory index full!");
1572 bh2 = ext4_append (handle, dir, &newblock, &err);
1575 node2 = (struct dx_node *)(bh2->b_data);
1576 entries2 = node2->entries;
1577 node2->fake.rec_len = ext4_rec_len_to_disk(sb->s_blocksize);
1578 node2->fake.inode = 0;
1579 BUFFER_TRACE(frame->bh, "get_write_access");
1580 err = ext4_journal_get_write_access(handle, frame->bh);
1584 unsigned icount1 = icount/2, icount2 = icount - icount1;
1585 unsigned hash2 = dx_get_hash(entries + icount1);
1586 dxtrace(printk("Split index %i/%i\n", icount1, icount2));
1588 BUFFER_TRACE(frame->bh, "get_write_access"); /* index root */
1589 err = ext4_journal_get_write_access(handle,
1594 memcpy ((char *) entries2, (char *) (entries + icount1),
1595 icount2 * sizeof(struct dx_entry));
1596 dx_set_count (entries, icount1);
1597 dx_set_count (entries2, icount2);
1598 dx_set_limit (entries2, dx_node_limit(dir));
1600 /* Which index block gets the new entry? */
1601 if (at - entries >= icount1) {
1602 frame->at = at = at - entries - icount1 + entries2;
1603 frame->entries = entries = entries2;
1604 swap(frame->bh, bh2);
1606 dx_insert_block (frames + 0, hash2, newblock);
1607 dxtrace(dx_show_index ("node", frames[1].entries));
1608 dxtrace(dx_show_index ("node",
1609 ((struct dx_node *) bh2->b_data)->entries));
1610 err = ext4_journal_dirty_metadata(handle, bh2);
1615 dxtrace(printk("Creating second level index...\n"));
1616 memcpy((char *) entries2, (char *) entries,
1617 icount * sizeof(struct dx_entry));
1618 dx_set_limit(entries2, dx_node_limit(dir));
1621 dx_set_count(entries, 1);
1622 dx_set_block(entries + 0, newblock);
1623 ((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels = 1;
1625 /* Add new access path frame */
1627 frame->at = at = at - entries + entries2;
1628 frame->entries = entries = entries2;
1630 err = ext4_journal_get_write_access(handle,
1635 ext4_journal_dirty_metadata(handle, frames[0].bh);
1637 de = do_split(handle, dir, &bh, frame, &hinfo, &err);
1640 err = add_dirent_to_buf(handle, dentry, inode, de, bh);
1645 ext4_std_error(dir->i_sb, err);
1654 * ext4_delete_entry deletes a directory entry by merging it with the
1657 static int ext4_delete_entry (handle_t *handle,
1659 struct ext4_dir_entry_2 * de_del,
1660 struct buffer_head * bh)
1662 struct ext4_dir_entry_2 * de, * pde;
1667 de = (struct ext4_dir_entry_2 *) bh->b_data;
1668 while (i < bh->b_size) {
1669 if (!ext4_check_dir_entry("ext4_delete_entry", dir, de, bh, i))
1672 BUFFER_TRACE(bh, "get_write_access");
1673 ext4_journal_get_write_access(handle, bh);
1675 pde->rec_len = ext4_rec_len_to_disk(
1676 ext4_rec_len_from_disk(pde->rec_len) +
1677 ext4_rec_len_from_disk(de->rec_len));
1681 BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
1682 ext4_journal_dirty_metadata(handle, bh);
1685 i += ext4_rec_len_from_disk(de->rec_len);
1687 de = ext4_next_entry(de);
1693 * DIR_NLINK feature is set if 1) nlinks > EXT4_LINK_MAX or 2) nlinks == 2,
1694 * since this indicates that nlinks count was previously 1.
1696 static void ext4_inc_count(handle_t *handle, struct inode *inode)
1699 if (is_dx(inode) && inode->i_nlink > 1) {
1700 /* limit is 16-bit i_links_count */
1701 if (inode->i_nlink >= EXT4_LINK_MAX || inode->i_nlink == 2) {
1703 EXT4_SET_RO_COMPAT_FEATURE(inode->i_sb,
1704 EXT4_FEATURE_RO_COMPAT_DIR_NLINK);
1710 * If a directory had nlink == 1, then we should let it be 1. This indicates
1711 * directory has >EXT4_LINK_MAX subdirs.
1713 static void ext4_dec_count(handle_t *handle, struct inode *inode)
1716 if (S_ISDIR(inode->i_mode) && inode->i_nlink == 0)
1721 static int ext4_add_nondir(handle_t *handle,
1722 struct dentry *dentry, struct inode *inode)
1724 int err = ext4_add_entry(handle, dentry, inode);
1726 ext4_mark_inode_dirty(handle, inode);
1727 d_instantiate(dentry, inode);
1736 * By the time this is called, we already have created
1737 * the directory cache entry for the new file, but it
1738 * is so far negative - it has no inode.
1740 * If the create succeeds, we fill in the inode information
1741 * with d_instantiate().
1743 static int ext4_create (struct inode * dir, struct dentry * dentry, int mode,
1744 struct nameidata *nd)
1747 struct inode * inode;
1748 int err, retries = 0;
1751 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
1752 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
1753 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
1755 return PTR_ERR(handle);
1757 if (IS_DIRSYNC(dir))
1760 inode = ext4_new_inode (handle, dir, mode);
1761 err = PTR_ERR(inode);
1762 if (!IS_ERR(inode)) {
1763 inode->i_op = &ext4_file_inode_operations;
1764 inode->i_fop = &ext4_file_operations;
1765 ext4_set_aops(inode);
1766 err = ext4_add_nondir(handle, dentry, inode);
1768 ext4_journal_stop(handle);
1769 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
1774 static int ext4_mknod (struct inode * dir, struct dentry *dentry,
1775 int mode, dev_t rdev)
1778 struct inode *inode;
1779 int err, retries = 0;
1781 if (!new_valid_dev(rdev))
1785 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
1786 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
1787 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
1789 return PTR_ERR(handle);
1791 if (IS_DIRSYNC(dir))
1794 inode = ext4_new_inode (handle, dir, mode);
1795 err = PTR_ERR(inode);
1796 if (!IS_ERR(inode)) {
1797 init_special_inode(inode, inode->i_mode, rdev);
1798 #ifdef CONFIG_EXT4DEV_FS_XATTR
1799 inode->i_op = &ext4_special_inode_operations;
1801 err = ext4_add_nondir(handle, dentry, inode);
1803 ext4_journal_stop(handle);
1804 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
1809 static int ext4_mkdir(struct inode * dir, struct dentry * dentry, int mode)
1812 struct inode * inode;
1813 struct buffer_head * dir_block;
1814 struct ext4_dir_entry_2 * de;
1815 int err, retries = 0;
1817 if (EXT4_DIR_LINK_MAX(dir))
1821 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
1822 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
1823 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
1825 return PTR_ERR(handle);
1827 if (IS_DIRSYNC(dir))
1830 inode = ext4_new_inode (handle, dir, S_IFDIR | mode);
1831 err = PTR_ERR(inode);
1835 inode->i_op = &ext4_dir_inode_operations;
1836 inode->i_fop = &ext4_dir_operations;
1837 inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
1838 dir_block = ext4_bread (handle, inode, 0, 1, &err);
1840 goto out_clear_inode;
1841 BUFFER_TRACE(dir_block, "get_write_access");
1842 ext4_journal_get_write_access(handle, dir_block);
1843 de = (struct ext4_dir_entry_2 *) dir_block->b_data;
1844 de->inode = cpu_to_le32(inode->i_ino);
1846 de->rec_len = ext4_rec_len_to_disk(EXT4_DIR_REC_LEN(de->name_len));
1847 strcpy (de->name, ".");
1848 ext4_set_de_type(dir->i_sb, de, S_IFDIR);
1849 de = ext4_next_entry(de);
1850 de->inode = cpu_to_le32(dir->i_ino);
1851 de->rec_len = ext4_rec_len_to_disk(inode->i_sb->s_blocksize -
1852 EXT4_DIR_REC_LEN(1));
1854 strcpy (de->name, "..");
1855 ext4_set_de_type(dir->i_sb, de, S_IFDIR);
1857 BUFFER_TRACE(dir_block, "call ext4_journal_dirty_metadata");
1858 ext4_journal_dirty_metadata(handle, dir_block);
1860 ext4_mark_inode_dirty(handle, inode);
1861 err = ext4_add_entry (handle, dentry, inode);
1865 ext4_mark_inode_dirty(handle, inode);
1869 ext4_inc_count(handle, dir);
1870 ext4_update_dx_flag(dir);
1871 ext4_mark_inode_dirty(handle, dir);
1872 d_instantiate(dentry, inode);
1874 ext4_journal_stop(handle);
1875 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
1881 * routine to check that the specified directory is empty (for rmdir)
1883 static int empty_dir (struct inode * inode)
1885 unsigned long offset;
1886 struct buffer_head * bh;
1887 struct ext4_dir_entry_2 * de, * de1;
1888 struct super_block * sb;
1892 if (inode->i_size < EXT4_DIR_REC_LEN(1) + EXT4_DIR_REC_LEN(2) ||
1893 !(bh = ext4_bread (NULL, inode, 0, 0, &err))) {
1895 ext4_error(inode->i_sb, __func__,
1896 "error %d reading directory #%lu offset 0",
1899 ext4_warning(inode->i_sb, __func__,
1900 "bad directory (dir #%lu) - no data block",
1904 de = (struct ext4_dir_entry_2 *) bh->b_data;
1905 de1 = ext4_next_entry(de);
1906 if (le32_to_cpu(de->inode) != inode->i_ino ||
1907 !le32_to_cpu(de1->inode) ||
1908 strcmp (".", de->name) ||
1909 strcmp ("..", de1->name)) {
1910 ext4_warning (inode->i_sb, "empty_dir",
1911 "bad directory (dir #%lu) - no `.' or `..'",
1916 offset = ext4_rec_len_from_disk(de->rec_len) +
1917 ext4_rec_len_from_disk(de1->rec_len);
1918 de = ext4_next_entry(de1);
1919 while (offset < inode->i_size ) {
1921 (void *) de >= (void *) (bh->b_data+sb->s_blocksize)) {
1924 bh = ext4_bread (NULL, inode,
1925 offset >> EXT4_BLOCK_SIZE_BITS(sb), 0, &err);
1928 ext4_error(sb, __func__,
1929 "error %d reading directory"
1931 err, inode->i_ino, offset);
1932 offset += sb->s_blocksize;
1935 de = (struct ext4_dir_entry_2 *) bh->b_data;
1937 if (!ext4_check_dir_entry("empty_dir", inode, de, bh, offset)) {
1938 de = (struct ext4_dir_entry_2 *)(bh->b_data +
1940 offset = (offset | (sb->s_blocksize - 1)) + 1;
1943 if (le32_to_cpu(de->inode)) {
1947 offset += ext4_rec_len_from_disk(de->rec_len);
1948 de = ext4_next_entry(de);
1954 /* ext4_orphan_add() links an unlinked or truncated inode into a list of
1955 * such inodes, starting at the superblock, in case we crash before the
1956 * file is closed/deleted, or in case the inode truncate spans multiple
1957 * transactions and the last transaction is not recovered after a crash.
1959 * At filesystem recovery time, we walk this list deleting unlinked
1960 * inodes and truncating linked inodes in ext4_orphan_cleanup().
1962 int ext4_orphan_add(handle_t *handle, struct inode *inode)
1964 struct super_block *sb = inode->i_sb;
1965 struct ext4_iloc iloc;
1969 if (!list_empty(&EXT4_I(inode)->i_orphan))
1972 /* Orphan handling is only valid for files with data blocks
1973 * being truncated, or files being unlinked. */
1975 /* @@@ FIXME: Observation from aviro:
1976 * I think I can trigger J_ASSERT in ext4_orphan_add(). We block
1977 * here (on lock_super()), so race with ext4_link() which might bump
1978 * ->i_nlink. For, say it, character device. Not a regular file,
1979 * not a directory, not a symlink and ->i_nlink > 0.
1981 J_ASSERT ((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1982 S_ISLNK(inode->i_mode)) || inode->i_nlink == 0);
1984 BUFFER_TRACE(EXT4_SB(sb)->s_sbh, "get_write_access");
1985 err = ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh);
1989 err = ext4_reserve_inode_write(handle, inode, &iloc);
1993 /* Insert this inode at the head of the on-disk orphan list... */
1994 NEXT_ORPHAN(inode) = le32_to_cpu(EXT4_SB(sb)->s_es->s_last_orphan);
1995 EXT4_SB(sb)->s_es->s_last_orphan = cpu_to_le32(inode->i_ino);
1996 err = ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh);
1997 rc = ext4_mark_iloc_dirty(handle, inode, &iloc);
2001 /* Only add to the head of the in-memory list if all the
2002 * previous operations succeeded. If the orphan_add is going to
2003 * fail (possibly taking the journal offline), we can't risk
2004 * leaving the inode on the orphan list: stray orphan-list
2005 * entries can cause panics at unmount time.
2007 * This is safe: on error we're going to ignore the orphan list
2008 * anyway on the next recovery. */
2010 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
2012 jbd_debug(4, "superblock will point to %lu\n", inode->i_ino);
2013 jbd_debug(4, "orphan inode %lu will point to %d\n",
2014 inode->i_ino, NEXT_ORPHAN(inode));
2017 ext4_std_error(inode->i_sb, err);
2022 * ext4_orphan_del() removes an unlinked or truncated inode from the list
2023 * of such inodes stored on disk, because it is finally being cleaned up.
2025 int ext4_orphan_del(handle_t *handle, struct inode *inode)
2027 struct list_head *prev;
2028 struct ext4_inode_info *ei = EXT4_I(inode);
2029 struct ext4_sb_info *sbi;
2030 unsigned long ino_next;
2031 struct ext4_iloc iloc;
2034 lock_super(inode->i_sb);
2035 if (list_empty(&ei->i_orphan)) {
2036 unlock_super(inode->i_sb);
2040 ino_next = NEXT_ORPHAN(inode);
2041 prev = ei->i_orphan.prev;
2042 sbi = EXT4_SB(inode->i_sb);
2044 jbd_debug(4, "remove inode %lu from orphan list\n", inode->i_ino);
2046 list_del_init(&ei->i_orphan);
2048 /* If we're on an error path, we may not have a valid
2049 * transaction handle with which to update the orphan list on
2050 * disk, but we still need to remove the inode from the linked
2051 * list in memory. */
2055 err = ext4_reserve_inode_write(handle, inode, &iloc);
2059 if (prev == &sbi->s_orphan) {
2060 jbd_debug(4, "superblock will point to %lu\n", ino_next);
2061 BUFFER_TRACE(sbi->s_sbh, "get_write_access");
2062 err = ext4_journal_get_write_access(handle, sbi->s_sbh);
2065 sbi->s_es->s_last_orphan = cpu_to_le32(ino_next);
2066 err = ext4_journal_dirty_metadata(handle, sbi->s_sbh);
2068 struct ext4_iloc iloc2;
2069 struct inode *i_prev =
2070 &list_entry(prev, struct ext4_inode_info, i_orphan)->vfs_inode;
2072 jbd_debug(4, "orphan inode %lu will point to %lu\n",
2073 i_prev->i_ino, ino_next);
2074 err = ext4_reserve_inode_write(handle, i_prev, &iloc2);
2077 NEXT_ORPHAN(i_prev) = ino_next;
2078 err = ext4_mark_iloc_dirty(handle, i_prev, &iloc2);
2082 NEXT_ORPHAN(inode) = 0;
2083 err = ext4_mark_iloc_dirty(handle, inode, &iloc);
2086 ext4_std_error(inode->i_sb, err);
2088 unlock_super(inode->i_sb);
2096 static int ext4_rmdir (struct inode * dir, struct dentry *dentry)
2099 struct inode * inode;
2100 struct buffer_head * bh;
2101 struct ext4_dir_entry_2 * de;
2104 /* Initialize quotas before so that eventual writes go in
2105 * separate transaction */
2106 DQUOT_INIT(dentry->d_inode);
2107 handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb));
2109 return PTR_ERR(handle);
2112 bh = ext4_find_entry (dentry, &de);
2116 if (IS_DIRSYNC(dir))
2119 inode = dentry->d_inode;
2122 if (le32_to_cpu(de->inode) != inode->i_ino)
2125 retval = -ENOTEMPTY;
2126 if (!empty_dir (inode))
2129 retval = ext4_delete_entry(handle, dir, de, bh);
2132 if (!EXT4_DIR_LINK_EMPTY(inode))
2133 ext4_warning (inode->i_sb, "ext4_rmdir",
2134 "empty directory has too many links (%d)",
2138 /* There's no need to set i_disksize: the fact that i_nlink is
2139 * zero will ensure that the right thing happens during any
2142 ext4_orphan_add(handle, inode);
2143 inode->i_ctime = dir->i_ctime = dir->i_mtime = ext4_current_time(inode);
2144 ext4_mark_inode_dirty(handle, inode);
2145 ext4_dec_count(handle, dir);
2146 ext4_update_dx_flag(dir);
2147 ext4_mark_inode_dirty(handle, dir);
2150 ext4_journal_stop(handle);
2155 static int ext4_unlink(struct inode * dir, struct dentry *dentry)
2158 struct inode * inode;
2159 struct buffer_head * bh;
2160 struct ext4_dir_entry_2 * de;
2163 /* Initialize quotas before so that eventual writes go
2164 * in separate transaction */
2165 DQUOT_INIT(dentry->d_inode);
2166 handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb));
2168 return PTR_ERR(handle);
2170 if (IS_DIRSYNC(dir))
2174 bh = ext4_find_entry (dentry, &de);
2178 inode = dentry->d_inode;
2181 if (le32_to_cpu(de->inode) != inode->i_ino)
2184 if (!inode->i_nlink) {
2185 ext4_warning (inode->i_sb, "ext4_unlink",
2186 "Deleting nonexistent file (%lu), %d",
2187 inode->i_ino, inode->i_nlink);
2190 retval = ext4_delete_entry(handle, dir, de, bh);
2193 dir->i_ctime = dir->i_mtime = ext4_current_time(dir);
2194 ext4_update_dx_flag(dir);
2195 ext4_mark_inode_dirty(handle, dir);
2197 if (!inode->i_nlink)
2198 ext4_orphan_add(handle, inode);
2199 inode->i_ctime = ext4_current_time(inode);
2200 ext4_mark_inode_dirty(handle, inode);
2204 ext4_journal_stop(handle);
2209 static int ext4_symlink (struct inode * dir,
2210 struct dentry *dentry, const char * symname)
2213 struct inode * inode;
2214 int l, err, retries = 0;
2216 l = strlen(symname)+1;
2217 if (l > dir->i_sb->s_blocksize)
2218 return -ENAMETOOLONG;
2221 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
2222 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 5 +
2223 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
2225 return PTR_ERR(handle);
2227 if (IS_DIRSYNC(dir))
2230 inode = ext4_new_inode (handle, dir, S_IFLNK|S_IRWXUGO);
2231 err = PTR_ERR(inode);
2235 if (l > sizeof (EXT4_I(inode)->i_data)) {
2236 inode->i_op = &ext4_symlink_inode_operations;
2237 ext4_set_aops(inode);
2239 * page_symlink() calls into ext4_prepare/commit_write.
2240 * We have a transaction open. All is sweetness. It also sets
2241 * i_size in generic_commit_write().
2243 err = __page_symlink(inode, symname, l, 1);
2246 ext4_mark_inode_dirty(handle, inode);
2251 /* clear the extent format for fast symlink */
2252 EXT4_I(inode)->i_flags &= ~EXT4_EXTENTS_FL;
2253 inode->i_op = &ext4_fast_symlink_inode_operations;
2254 memcpy((char*)&EXT4_I(inode)->i_data,symname,l);
2255 inode->i_size = l-1;
2257 EXT4_I(inode)->i_disksize = inode->i_size;
2258 err = ext4_add_nondir(handle, dentry, inode);
2260 ext4_journal_stop(handle);
2261 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
2266 static int ext4_link (struct dentry * old_dentry,
2267 struct inode * dir, struct dentry *dentry)
2270 struct inode *inode = old_dentry->d_inode;
2271 int err, retries = 0;
2273 if (EXT4_DIR_LINK_MAX(inode))
2277 * Return -ENOENT if we've raced with unlink and i_nlink is 0. Doing
2278 * otherwise has the potential to corrupt the orphan inode list.
2280 if (inode->i_nlink == 0)
2284 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
2285 EXT4_INDEX_EXTRA_TRANS_BLOCKS);
2287 return PTR_ERR(handle);
2289 if (IS_DIRSYNC(dir))
2292 inode->i_ctime = ext4_current_time(inode);
2293 ext4_inc_count(handle, inode);
2294 atomic_inc(&inode->i_count);
2296 err = ext4_add_nondir(handle, dentry, inode);
2297 ext4_journal_stop(handle);
2298 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
2303 #define PARENT_INO(buffer) \
2304 (ext4_next_entry((struct ext4_dir_entry_2 *)(buffer))->inode)
2307 * Anybody can rename anything with this: the permission checks are left to the
2308 * higher-level routines.
2310 static int ext4_rename (struct inode * old_dir, struct dentry *old_dentry,
2311 struct inode * new_dir,struct dentry *new_dentry)
2314 struct inode * old_inode, * new_inode;
2315 struct buffer_head * old_bh, * new_bh, * dir_bh;
2316 struct ext4_dir_entry_2 * old_de, * new_de;
2319 old_bh = new_bh = dir_bh = NULL;
2321 /* Initialize quotas before so that eventual writes go
2322 * in separate transaction */
2323 if (new_dentry->d_inode)
2324 DQUOT_INIT(new_dentry->d_inode);
2325 handle = ext4_journal_start(old_dir, 2 *
2326 EXT4_DATA_TRANS_BLOCKS(old_dir->i_sb) +
2327 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 2);
2329 return PTR_ERR(handle);
2331 if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
2334 old_bh = ext4_find_entry (old_dentry, &old_de);
2336 * Check for inode number is _not_ due to possible IO errors.
2337 * We might rmdir the source, keep it as pwd of some process
2338 * and merrily kill the link to whatever was created under the
2339 * same name. Goodbye sticky bit ;-<
2341 old_inode = old_dentry->d_inode;
2343 if (!old_bh || le32_to_cpu(old_de->inode) != old_inode->i_ino)
2346 new_inode = new_dentry->d_inode;
2347 new_bh = ext4_find_entry (new_dentry, &new_de);
2354 if (S_ISDIR(old_inode->i_mode)) {
2356 retval = -ENOTEMPTY;
2357 if (!empty_dir (new_inode))
2361 dir_bh = ext4_bread (handle, old_inode, 0, 0, &retval);
2364 if (le32_to_cpu(PARENT_INO(dir_bh->b_data)) != old_dir->i_ino)
2367 if (!new_inode && new_dir!=old_dir &&
2368 new_dir->i_nlink >= EXT4_LINK_MAX)
2372 retval = ext4_add_entry (handle, new_dentry, old_inode);
2376 BUFFER_TRACE(new_bh, "get write access");
2377 ext4_journal_get_write_access(handle, new_bh);
2378 new_de->inode = cpu_to_le32(old_inode->i_ino);
2379 if (EXT4_HAS_INCOMPAT_FEATURE(new_dir->i_sb,
2380 EXT4_FEATURE_INCOMPAT_FILETYPE))
2381 new_de->file_type = old_de->file_type;
2382 new_dir->i_version++;
2383 new_dir->i_ctime = new_dir->i_mtime =
2384 ext4_current_time(new_dir);
2385 ext4_mark_inode_dirty(handle, new_dir);
2386 BUFFER_TRACE(new_bh, "call ext4_journal_dirty_metadata");
2387 ext4_journal_dirty_metadata(handle, new_bh);
2393 * Like most other Unix systems, set the ctime for inodes on a
2396 old_inode->i_ctime = ext4_current_time(old_inode);
2397 ext4_mark_inode_dirty(handle, old_inode);
2402 if (le32_to_cpu(old_de->inode) != old_inode->i_ino ||
2403 old_de->name_len != old_dentry->d_name.len ||
2404 strncmp(old_de->name, old_dentry->d_name.name, old_de->name_len) ||
2405 (retval = ext4_delete_entry(handle, old_dir,
2406 old_de, old_bh)) == -ENOENT) {
2407 /* old_de could have moved from under us during htree split, so
2408 * make sure that we are deleting the right entry. We might
2409 * also be pointing to a stale entry in the unused part of
2410 * old_bh so just checking inum and the name isn't enough. */
2411 struct buffer_head *old_bh2;
2412 struct ext4_dir_entry_2 *old_de2;
2414 old_bh2 = ext4_find_entry(old_dentry, &old_de2);
2416 retval = ext4_delete_entry(handle, old_dir,
2422 ext4_warning(old_dir->i_sb, "ext4_rename",
2423 "Deleting old file (%lu), %d, error=%d",
2424 old_dir->i_ino, old_dir->i_nlink, retval);
2428 ext4_dec_count(handle, new_inode);
2429 new_inode->i_ctime = ext4_current_time(new_inode);
2431 old_dir->i_ctime = old_dir->i_mtime = ext4_current_time(old_dir);
2432 ext4_update_dx_flag(old_dir);
2434 BUFFER_TRACE(dir_bh, "get_write_access");
2435 ext4_journal_get_write_access(handle, dir_bh);
2436 PARENT_INO(dir_bh->b_data) = cpu_to_le32(new_dir->i_ino);
2437 BUFFER_TRACE(dir_bh, "call ext4_journal_dirty_metadata");
2438 ext4_journal_dirty_metadata(handle, dir_bh);
2439 ext4_dec_count(handle, old_dir);
2441 /* checked empty_dir above, can't have another parent,
2442 * ext4_dec_count() won't work for many-linked dirs */
2443 new_inode->i_nlink = 0;
2445 ext4_inc_count(handle, new_dir);
2446 ext4_update_dx_flag(new_dir);
2447 ext4_mark_inode_dirty(handle, new_dir);
2450 ext4_mark_inode_dirty(handle, old_dir);
2452 ext4_mark_inode_dirty(handle, new_inode);
2453 if (!new_inode->i_nlink)
2454 ext4_orphan_add(handle, new_inode);
2462 ext4_journal_stop(handle);
2467 * directories can handle most operations...
2469 const struct inode_operations ext4_dir_inode_operations = {
2470 .create = ext4_create,
2471 .lookup = ext4_lookup,
2473 .unlink = ext4_unlink,
2474 .symlink = ext4_symlink,
2475 .mkdir = ext4_mkdir,
2476 .rmdir = ext4_rmdir,
2477 .mknod = ext4_mknod,
2478 .rename = ext4_rename,
2479 .setattr = ext4_setattr,
2480 #ifdef CONFIG_EXT4DEV_FS_XATTR
2481 .setxattr = generic_setxattr,
2482 .getxattr = generic_getxattr,
2483 .listxattr = ext4_listxattr,
2484 .removexattr = generic_removexattr,
2486 .permission = ext4_permission,
2489 const struct inode_operations ext4_special_inode_operations = {
2490 .setattr = ext4_setattr,
2491 #ifdef CONFIG_EXT4DEV_FS_XATTR
2492 .setxattr = generic_setxattr,
2493 .getxattr = generic_getxattr,
2494 .listxattr = ext4_listxattr,
2495 .removexattr = generic_removexattr,
2497 .permission = ext4_permission,