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 dxtrace(command) command
80 #define dxtrace(command)
104 * dx_root_info is laid out so that if it should somehow get overlaid by a
105 * dirent the two low bits of the hash version will be zero. Therefore, the
106 * hash version mod 4 should never be 0. Sincerely, the paranoia department.
111 struct fake_dirent dot;
113 struct fake_dirent dotdot;
117 __le32 reserved_zero;
119 u8 info_length; /* 8 */
124 struct dx_entry entries[0];
129 struct fake_dirent fake;
130 struct dx_entry entries[0];
136 struct buffer_head *bh;
137 struct dx_entry *entries;
148 static inline ext4_lblk_t dx_get_block(struct dx_entry *entry);
149 static void dx_set_block(struct dx_entry *entry, ext4_lblk_t value);
150 static inline unsigned dx_get_hash(struct dx_entry *entry);
151 static void dx_set_hash(struct dx_entry *entry, unsigned value);
152 static unsigned dx_get_count(struct dx_entry *entries);
153 static unsigned dx_get_limit(struct dx_entry *entries);
154 static void dx_set_count(struct dx_entry *entries, unsigned value);
155 static void dx_set_limit(struct dx_entry *entries, unsigned value);
156 static unsigned dx_root_limit(struct inode *dir, unsigned infosize);
157 static unsigned dx_node_limit(struct inode *dir);
158 static struct dx_frame *dx_probe(const struct qstr *d_name,
160 struct dx_hash_info *hinfo,
161 struct dx_frame *frame,
163 static void dx_release(struct dx_frame *frames);
164 static int dx_make_map(struct ext4_dir_entry_2 *de, int size,
165 struct dx_hash_info *hinfo, struct dx_map_entry map[]);
166 static void dx_sort_map(struct dx_map_entry *map, unsigned count);
167 static struct ext4_dir_entry_2 *dx_move_dirents(char *from, char *to,
168 struct dx_map_entry *offsets, int count);
169 static struct ext4_dir_entry_2* dx_pack_dirents(char *base, int size);
170 static void dx_insert_block(struct dx_frame *frame,
171 u32 hash, ext4_lblk_t block);
172 static int ext4_htree_next_block(struct inode *dir, __u32 hash,
173 struct dx_frame *frame,
174 struct dx_frame *frames,
176 static struct buffer_head * ext4_dx_find_entry(struct inode *dir,
177 const struct qstr *d_name,
178 struct ext4_dir_entry_2 **res_dir,
180 static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
181 struct inode *inode);
184 * p is at least 6 bytes before the end of page
186 static inline struct ext4_dir_entry_2 *
187 ext4_next_entry(struct ext4_dir_entry_2 *p)
189 return (struct ext4_dir_entry_2 *)((char *)p +
190 ext4_rec_len_from_disk(p->rec_len));
194 * Future: use high four bits of block for coalesce-on-delete flags
195 * Mask them off for now.
198 static inline ext4_lblk_t dx_get_block(struct dx_entry *entry)
200 return le32_to_cpu(entry->block) & 0x00ffffff;
203 static inline void dx_set_block(struct dx_entry *entry, ext4_lblk_t value)
205 entry->block = cpu_to_le32(value);
208 static inline unsigned dx_get_hash(struct dx_entry *entry)
210 return le32_to_cpu(entry->hash);
213 static inline void dx_set_hash(struct dx_entry *entry, unsigned value)
215 entry->hash = cpu_to_le32(value);
218 static inline unsigned dx_get_count(struct dx_entry *entries)
220 return le16_to_cpu(((struct dx_countlimit *) entries)->count);
223 static inline unsigned dx_get_limit(struct dx_entry *entries)
225 return le16_to_cpu(((struct dx_countlimit *) entries)->limit);
228 static inline void dx_set_count(struct dx_entry *entries, unsigned value)
230 ((struct dx_countlimit *) entries)->count = cpu_to_le16(value);
233 static inline void dx_set_limit(struct dx_entry *entries, unsigned value)
235 ((struct dx_countlimit *) entries)->limit = cpu_to_le16(value);
238 static inline unsigned dx_root_limit(struct inode *dir, unsigned infosize)
240 unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(1) -
241 EXT4_DIR_REC_LEN(2) - infosize;
242 return entry_space / sizeof(struct dx_entry);
245 static inline unsigned dx_node_limit(struct inode *dir)
247 unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(0);
248 return entry_space / sizeof(struct dx_entry);
255 static void dx_show_index(char * label, struct dx_entry *entries)
257 int i, n = dx_get_count (entries);
258 printk(KERN_DEBUG "%s index ", label);
259 for (i = 0; i < n; i++) {
260 printk("%x->%lu ", i ? dx_get_hash(entries + i) :
261 0, (unsigned long)dx_get_block(entries + i));
273 static struct stats dx_show_leaf(struct dx_hash_info *hinfo, struct ext4_dir_entry_2 *de,
274 int size, int show_names)
276 unsigned names = 0, space = 0;
277 char *base = (char *) de;
278 struct dx_hash_info h = *hinfo;
281 while ((char *) de < base + size)
287 int len = de->name_len;
288 char *name = de->name;
289 while (len--) printk("%c", *name++);
290 ext4fs_dirhash(de->name, de->name_len, &h);
291 printk(":%x.%u ", h.hash,
292 ((char *) de - base));
294 space += EXT4_DIR_REC_LEN(de->name_len);
297 de = ext4_next_entry(de);
299 printk("(%i)\n", names);
300 return (struct stats) { names, space, 1 };
303 struct stats dx_show_entries(struct dx_hash_info *hinfo, struct inode *dir,
304 struct dx_entry *entries, int levels)
306 unsigned blocksize = dir->i_sb->s_blocksize;
307 unsigned count = dx_get_count(entries), names = 0, space = 0, i;
309 struct buffer_head *bh;
311 printk("%i indexed blocks...\n", count);
312 for (i = 0; i < count; i++, entries++)
314 ext4_lblk_t block = dx_get_block(entries);
315 ext4_lblk_t hash = i ? dx_get_hash(entries): 0;
316 u32 range = i < count - 1? (dx_get_hash(entries + 1) - hash): ~hash;
318 printk("%s%3u:%03u hash %8x/%8x ",levels?"":" ", i, block, hash, range);
319 if (!(bh = ext4_bread (NULL,dir, block, 0,&err))) continue;
321 dx_show_entries(hinfo, dir, ((struct dx_node *) bh->b_data)->entries, levels - 1):
322 dx_show_leaf(hinfo, (struct ext4_dir_entry_2 *) bh->b_data, blocksize, 0);
323 names += stats.names;
324 space += stats.space;
325 bcount += stats.bcount;
329 printk(KERN_DEBUG "%snames %u, fullness %u (%u%%)\n",
330 levels ? "" : " ", names, space/bcount,
331 (space/bcount)*100/blocksize);
332 return (struct stats) { names, space, bcount};
334 #endif /* DX_DEBUG */
337 * Probe for a directory leaf block to search.
339 * dx_probe can return ERR_BAD_DX_DIR, which means there was a format
340 * error in the directory index, and the caller should fall back to
341 * searching the directory normally. The callers of dx_probe **MUST**
342 * check for this error code, and make sure it never gets reflected
345 static struct dx_frame *
346 dx_probe(const struct qstr *d_name, struct inode *dir,
347 struct dx_hash_info *hinfo, struct dx_frame *frame_in, int *err)
349 unsigned count, indirect;
350 struct dx_entry *at, *entries, *p, *q, *m;
351 struct dx_root *root;
352 struct buffer_head *bh;
353 struct dx_frame *frame = frame_in;
357 if (!(bh = ext4_bread (NULL,dir, 0, 0, err)))
359 root = (struct dx_root *) bh->b_data;
360 if (root->info.hash_version != DX_HASH_TEA &&
361 root->info.hash_version != DX_HASH_HALF_MD4 &&
362 root->info.hash_version != DX_HASH_LEGACY) {
363 ext4_warning(dir->i_sb, __func__,
364 "Unrecognised inode hash code %d",
365 root->info.hash_version);
367 *err = ERR_BAD_DX_DIR;
370 hinfo->hash_version = root->info.hash_version;
371 hinfo->seed = EXT4_SB(dir->i_sb)->s_hash_seed;
373 ext4fs_dirhash(d_name->name, d_name->len, hinfo);
376 if (root->info.unused_flags & 1) {
377 ext4_warning(dir->i_sb, __func__,
378 "Unimplemented inode hash flags: %#06x",
379 root->info.unused_flags);
381 *err = ERR_BAD_DX_DIR;
385 if ((indirect = root->info.indirect_levels) > 1) {
386 ext4_warning(dir->i_sb, __func__,
387 "Unimplemented inode hash depth: %#06x",
388 root->info.indirect_levels);
390 *err = ERR_BAD_DX_DIR;
394 entries = (struct dx_entry *) (((char *)&root->info) +
395 root->info.info_length);
397 if (dx_get_limit(entries) != dx_root_limit(dir,
398 root->info.info_length)) {
399 ext4_warning(dir->i_sb, __func__,
400 "dx entry: limit != root limit");
402 *err = ERR_BAD_DX_DIR;
406 dxtrace(printk("Look up %x", hash));
409 count = dx_get_count(entries);
410 if (!count || count > dx_get_limit(entries)) {
411 ext4_warning(dir->i_sb, __func__,
412 "dx entry: no count or count > limit");
414 *err = ERR_BAD_DX_DIR;
419 q = entries + count - 1;
423 dxtrace(printk("."));
424 if (dx_get_hash(m) > hash)
430 if (0) // linear search cross check
432 unsigned n = count - 1;
436 dxtrace(printk(","));
437 if (dx_get_hash(++at) > hash)
443 assert (at == p - 1);
447 dxtrace(printk(" %x->%u\n", at == entries? 0: dx_get_hash(at), dx_get_block(at)));
449 frame->entries = entries;
451 if (!indirect--) return frame;
452 if (!(bh = ext4_bread (NULL,dir, dx_get_block(at), 0, err)))
454 at = entries = ((struct dx_node *) bh->b_data)->entries;
455 if (dx_get_limit(entries) != dx_node_limit (dir)) {
456 ext4_warning(dir->i_sb, __func__,
457 "dx entry: limit != node limit");
459 *err = ERR_BAD_DX_DIR;
466 while (frame >= frame_in) {
471 if (*err == ERR_BAD_DX_DIR)
472 ext4_warning(dir->i_sb, __func__,
473 "Corrupt dir inode %ld, running e2fsck is "
474 "recommended.", dir->i_ino);
478 static void dx_release (struct dx_frame *frames)
480 if (frames[0].bh == NULL)
483 if (((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels)
484 brelse(frames[1].bh);
485 brelse(frames[0].bh);
489 * This function increments the frame pointer to search the next leaf
490 * block, and reads in the necessary intervening nodes if the search
491 * should be necessary. Whether or not the search is necessary is
492 * controlled by the hash parameter. If the hash value is even, then
493 * the search is only continued if the next block starts with that
494 * hash value. This is used if we are searching for a specific file.
496 * If the hash value is HASH_NB_ALWAYS, then always go to the next block.
498 * This function returns 1 if the caller should continue to search,
499 * or 0 if it should not. If there is an error reading one of the
500 * index blocks, it will a negative error code.
502 * If start_hash is non-null, it will be filled in with the starting
503 * hash of the next page.
505 static int ext4_htree_next_block(struct inode *dir, __u32 hash,
506 struct dx_frame *frame,
507 struct dx_frame *frames,
511 struct buffer_head *bh;
512 int err, num_frames = 0;
517 * Find the next leaf page by incrementing the frame pointer.
518 * If we run out of entries in the interior node, loop around and
519 * increment pointer in the parent node. When we break out of
520 * this loop, num_frames indicates the number of interior
521 * nodes need to be read.
524 if (++(p->at) < p->entries + dx_get_count(p->entries))
533 * If the hash is 1, then continue only if the next page has a
534 * continuation hash of any value. This is used for readdir
535 * handling. Otherwise, check to see if the hash matches the
536 * desired contiuation hash. If it doesn't, return since
537 * there's no point to read in the successive index pages.
539 bhash = dx_get_hash(p->at);
542 if ((hash & 1) == 0) {
543 if ((bhash & ~1) != hash)
547 * If the hash is HASH_NB_ALWAYS, we always go to the next
548 * block so no check is necessary
550 while (num_frames--) {
551 if (!(bh = ext4_bread(NULL, dir, dx_get_block(p->at),
553 return err; /* Failure */
557 p->at = p->entries = ((struct dx_node *) bh->b_data)->entries;
564 * This function fills a red-black tree with information from a
565 * directory block. It returns the number directory entries loaded
566 * into the tree. If there is an error it is returned in err.
568 static int htree_dirblock_to_tree(struct file *dir_file,
569 struct inode *dir, ext4_lblk_t block,
570 struct dx_hash_info *hinfo,
571 __u32 start_hash, __u32 start_minor_hash)
573 struct buffer_head *bh;
574 struct ext4_dir_entry_2 *de, *top;
577 dxtrace(printk(KERN_INFO "In htree dirblock_to_tree: block %lu\n",
578 (unsigned long)block));
579 if (!(bh = ext4_bread (NULL, dir, block, 0, &err)))
582 de = (struct ext4_dir_entry_2 *) bh->b_data;
583 top = (struct ext4_dir_entry_2 *) ((char *) de +
584 dir->i_sb->s_blocksize -
585 EXT4_DIR_REC_LEN(0));
586 for (; de < top; de = ext4_next_entry(de)) {
587 if (!ext4_check_dir_entry("htree_dirblock_to_tree", dir, de, bh,
588 (block<<EXT4_BLOCK_SIZE_BITS(dir->i_sb))
589 +((char *)de - bh->b_data))) {
590 /* On error, skip the f_pos to the next block. */
591 dir_file->f_pos = (dir_file->f_pos |
592 (dir->i_sb->s_blocksize - 1)) + 1;
596 ext4fs_dirhash(de->name, de->name_len, hinfo);
597 if ((hinfo->hash < start_hash) ||
598 ((hinfo->hash == start_hash) &&
599 (hinfo->minor_hash < start_minor_hash)))
603 if ((err = ext4_htree_store_dirent(dir_file,
604 hinfo->hash, hinfo->minor_hash, de)) != 0) {
616 * This function fills a red-black tree with information from a
617 * directory. We start scanning the directory in hash order, starting
618 * at start_hash and start_minor_hash.
620 * This function returns the number of entries inserted into the tree,
621 * or a negative error code.
623 int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
624 __u32 start_minor_hash, __u32 *next_hash)
626 struct dx_hash_info hinfo;
627 struct ext4_dir_entry_2 *de;
628 struct dx_frame frames[2], *frame;
635 dxtrace(printk(KERN_DEBUG "In htree_fill_tree, start hash: %x:%x\n",
636 start_hash, start_minor_hash));
637 dir = dir_file->f_path.dentry->d_inode;
638 if (!(EXT4_I(dir)->i_flags & EXT4_INDEX_FL)) {
639 hinfo.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
640 hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
641 count = htree_dirblock_to_tree(dir_file, dir, 0, &hinfo,
642 start_hash, start_minor_hash);
646 hinfo.hash = start_hash;
647 hinfo.minor_hash = 0;
648 frame = dx_probe(NULL, dir, &hinfo, frames, &err);
652 /* Add '.' and '..' from the htree header */
653 if (!start_hash && !start_minor_hash) {
654 de = (struct ext4_dir_entry_2 *) frames[0].bh->b_data;
655 if ((err = ext4_htree_store_dirent(dir_file, 0, 0, de)) != 0)
659 if (start_hash < 2 || (start_hash ==2 && start_minor_hash==0)) {
660 de = (struct ext4_dir_entry_2 *) frames[0].bh->b_data;
661 de = ext4_next_entry(de);
662 if ((err = ext4_htree_store_dirent(dir_file, 2, 0, de)) != 0)
668 block = dx_get_block(frame->at);
669 ret = htree_dirblock_to_tree(dir_file, dir, block, &hinfo,
670 start_hash, start_minor_hash);
677 ret = ext4_htree_next_block(dir, HASH_NB_ALWAYS,
678 frame, frames, &hashval);
679 *next_hash = hashval;
685 * Stop if: (a) there are no more entries, or
686 * (b) we have inserted at least one entry and the
687 * next hash value is not a continuation
690 (count && ((hashval & 1) == 0)))
694 dxtrace(printk(KERN_DEBUG "Fill tree: returned %d entries, "
695 "next hash: %x\n", count, *next_hash));
704 * Directory block splitting, compacting
708 * Create map of hash values, offsets, and sizes, stored at end of block.
709 * Returns number of entries mapped.
711 static int dx_make_map (struct ext4_dir_entry_2 *de, int size,
712 struct dx_hash_info *hinfo, struct dx_map_entry *map_tail)
715 char *base = (char *) de;
716 struct dx_hash_info h = *hinfo;
718 while ((char *) de < base + size)
720 if (de->name_len && de->inode) {
721 ext4fs_dirhash(de->name, de->name_len, &h);
723 map_tail->hash = h.hash;
724 map_tail->offs = (u16) ((char *) de - base);
725 map_tail->size = le16_to_cpu(de->rec_len);
729 /* XXX: do we need to check rec_len == 0 case? -Chris */
730 de = ext4_next_entry(de);
735 /* Sort map by hash value */
736 static void dx_sort_map (struct dx_map_entry *map, unsigned count)
738 struct dx_map_entry *p, *q, *top = map + count - 1;
740 /* Combsort until bubble sort doesn't suck */
743 if (count - 9 < 2) /* 9, 10 -> 11 */
745 for (p = top, q = p - count; q >= map; p--, q--)
746 if (p->hash < q->hash)
749 /* Garden variety bubble sort */
754 if (q[1].hash >= q[0].hash)
762 static void dx_insert_block(struct dx_frame *frame, u32 hash, ext4_lblk_t block)
764 struct dx_entry *entries = frame->entries;
765 struct dx_entry *old = frame->at, *new = old + 1;
766 int count = dx_get_count(entries);
768 assert(count < dx_get_limit(entries));
769 assert(old < entries + count);
770 memmove(new + 1, new, (char *)(entries + count) - (char *)(new));
771 dx_set_hash(new, hash);
772 dx_set_block(new, block);
773 dx_set_count(entries, count + 1);
776 static void ext4_update_dx_flag(struct inode *inode)
778 if (!EXT4_HAS_COMPAT_FEATURE(inode->i_sb,
779 EXT4_FEATURE_COMPAT_DIR_INDEX))
780 EXT4_I(inode)->i_flags &= ~EXT4_INDEX_FL;
784 * NOTE! unlike strncmp, ext4_match returns 1 for success, 0 for failure.
786 * `len <= EXT4_NAME_LEN' is guaranteed by caller.
787 * `de != NULL' is guaranteed by caller.
789 static inline int ext4_match (int len, const char * const name,
790 struct ext4_dir_entry_2 * de)
792 if (len != de->name_len)
796 return !memcmp(name, de->name, len);
800 * Returns 0 if not found, -1 on failure, and 1 on success
802 static inline int search_dirblock(struct buffer_head *bh,
804 const struct qstr *d_name,
805 unsigned long offset,
806 struct ext4_dir_entry_2 ** res_dir)
808 struct ext4_dir_entry_2 * de;
811 const char *name = d_name->name;
812 int namelen = d_name->len;
814 de = (struct ext4_dir_entry_2 *) bh->b_data;
815 dlimit = bh->b_data + dir->i_sb->s_blocksize;
816 while ((char *) de < dlimit) {
817 /* this code is executed quadratically often */
818 /* do minimal checking `by hand' */
820 if ((char *) de + namelen <= dlimit &&
821 ext4_match (namelen, name, de)) {
822 /* found a match - just to be sure, do a full check */
823 if (!ext4_check_dir_entry("ext4_find_entry",
824 dir, de, bh, offset))
829 /* prevent looping on a bad block */
830 de_len = ext4_rec_len_from_disk(de->rec_len);
834 de = (struct ext4_dir_entry_2 *) ((char *) de + de_len);
843 * finds an entry in the specified directory with the wanted name. It
844 * returns the cache buffer in which the entry was found, and the entry
845 * itself (as a parameter - res_dir). It does NOT read the inode of the
846 * entry - you'll have to do that yourself if you want to.
848 * The returned buffer_head has ->b_count elevated. The caller is expected
849 * to brelse() it when appropriate.
851 static struct buffer_head * ext4_find_entry (struct inode *dir,
852 const struct qstr *d_name,
853 struct ext4_dir_entry_2 ** res_dir)
855 struct super_block *sb;
856 struct buffer_head *bh_use[NAMEI_RA_SIZE];
857 struct buffer_head *bh, *ret = NULL;
858 ext4_lblk_t start, block, b;
859 int ra_max = 0; /* Number of bh's in the readahead
861 int ra_ptr = 0; /* Current index into readahead
870 namelen = d_name->len;
871 if (namelen > EXT4_NAME_LEN)
874 bh = ext4_dx_find_entry(dir, d_name, res_dir, &err);
876 * On success, or if the error was file not found,
877 * return. Otherwise, fall back to doing a search the
880 if (bh || (err != ERR_BAD_DX_DIR))
882 dxtrace(printk(KERN_DEBUG "ext4_find_entry: dx failed, "
885 nblocks = dir->i_size >> EXT4_BLOCK_SIZE_BITS(sb);
886 start = EXT4_I(dir)->i_dir_start_lookup;
887 if (start >= nblocks)
893 * We deal with the read-ahead logic here.
895 if (ra_ptr >= ra_max) {
896 /* Refill the readahead buffer */
899 for (ra_max = 0; ra_max < NAMEI_RA_SIZE; ra_max++) {
901 * Terminate if we reach the end of the
902 * directory and must wrap, or if our
903 * search has finished at this block.
905 if (b >= nblocks || (num && block == start)) {
906 bh_use[ra_max] = NULL;
910 bh = ext4_getblk(NULL, dir, b++, 0, &err);
913 ll_rw_block(READ_META, 1, &bh);
916 if ((bh = bh_use[ra_ptr++]) == NULL)
919 if (!buffer_uptodate(bh)) {
920 /* read error, skip block & hope for the best */
921 ext4_error(sb, __func__, "reading directory #%lu "
922 "offset %lu", dir->i_ino,
923 (unsigned long)block);
927 i = search_dirblock(bh, dir, d_name,
928 block << EXT4_BLOCK_SIZE_BITS(sb), res_dir);
930 EXT4_I(dir)->i_dir_start_lookup = block;
932 goto cleanup_and_exit;
936 goto cleanup_and_exit;
939 if (++block >= nblocks)
941 } while (block != start);
944 * If the directory has grown while we were searching, then
945 * search the last part of the directory before giving up.
948 nblocks = dir->i_size >> EXT4_BLOCK_SIZE_BITS(sb);
949 if (block < nblocks) {
955 /* Clean up the read-ahead blocks */
956 for (; ra_ptr < ra_max; ra_ptr++)
957 brelse(bh_use[ra_ptr]);
961 static struct buffer_head * ext4_dx_find_entry(struct inode *dir, const struct qstr *d_name,
962 struct ext4_dir_entry_2 **res_dir, int *err)
964 struct super_block * sb;
965 struct dx_hash_info hinfo;
967 struct dx_frame frames[2], *frame;
968 struct ext4_dir_entry_2 *de, *top;
969 struct buffer_head *bh;
972 int namelen = d_name->len;
973 const u8 *name = d_name->name;
976 /* NFS may look up ".." - look at dx_root directory block */
977 if (namelen > 2 || name[0] != '.'||(name[1] != '.' && name[1] != '\0')){
978 if (!(frame = dx_probe(d_name, dir, &hinfo, frames, err)))
982 frame->bh = NULL; /* for dx_release() */
983 frame->at = (struct dx_entry *)frames; /* hack for zero entry*/
984 dx_set_block(frame->at, 0); /* dx_root block is 0 */
988 block = dx_get_block(frame->at);
989 if (!(bh = ext4_bread (NULL,dir, block, 0, err)))
991 de = (struct ext4_dir_entry_2 *) bh->b_data;
992 top = (struct ext4_dir_entry_2 *) ((char *) de + sb->s_blocksize -
993 EXT4_DIR_REC_LEN(0));
994 for (; de < top; de = ext4_next_entry(de)) {
995 int off = (block << EXT4_BLOCK_SIZE_BITS(sb))
996 + ((char *) de - bh->b_data);
998 if (!ext4_check_dir_entry(__func__, dir, de, bh, off)) {
1000 *err = ERR_BAD_DX_DIR;
1004 if (ext4_match(namelen, name, de)) {
1011 /* Check to see if we should continue to search */
1012 retval = ext4_htree_next_block(dir, hash, frame,
1015 ext4_warning(sb, __func__,
1016 "error reading index page in directory #%lu",
1021 } while (retval == 1);
1025 dxtrace(printk(KERN_DEBUG "%s not found\n", name));
1026 dx_release (frames);
1030 static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
1032 struct inode *inode;
1033 struct ext4_dir_entry_2 *de;
1034 struct buffer_head *bh;
1036 if (dentry->d_name.len > EXT4_NAME_LEN)
1037 return ERR_PTR(-ENAMETOOLONG);
1039 bh = ext4_find_entry(dir, &dentry->d_name, &de);
1042 unsigned long ino = le32_to_cpu(de->inode);
1044 if (!ext4_valid_inum(dir->i_sb, ino)) {
1045 ext4_error(dir->i_sb, "ext4_lookup",
1046 "bad inode number: %lu", ino);
1047 return ERR_PTR(-EIO);
1049 inode = ext4_iget(dir->i_sb, ino);
1051 return ERR_CAST(inode);
1053 return d_splice_alias(inode, dentry);
1057 struct dentry *ext4_get_parent(struct dentry *child)
1060 struct inode *inode;
1061 static const struct qstr dotdot = {
1065 struct ext4_dir_entry_2 * de;
1066 struct buffer_head *bh;
1068 bh = ext4_find_entry(child->d_inode, &dotdot, &de);
1071 return ERR_PTR(-ENOENT);
1072 ino = le32_to_cpu(de->inode);
1075 if (!ext4_valid_inum(child->d_inode->i_sb, ino)) {
1076 ext4_error(child->d_inode->i_sb, "ext4_get_parent",
1077 "bad inode number: %lu", ino);
1078 return ERR_PTR(-EIO);
1081 return d_obtain_alias(ext4_iget(child->d_inode->i_sb, ino));
1085 static unsigned char ext4_type_by_mode[S_IFMT >> S_SHIFT] = {
1086 [S_IFREG >> S_SHIFT] = EXT4_FT_REG_FILE,
1087 [S_IFDIR >> S_SHIFT] = EXT4_FT_DIR,
1088 [S_IFCHR >> S_SHIFT] = EXT4_FT_CHRDEV,
1089 [S_IFBLK >> S_SHIFT] = EXT4_FT_BLKDEV,
1090 [S_IFIFO >> S_SHIFT] = EXT4_FT_FIFO,
1091 [S_IFSOCK >> S_SHIFT] = EXT4_FT_SOCK,
1092 [S_IFLNK >> S_SHIFT] = EXT4_FT_SYMLINK,
1095 static inline void ext4_set_de_type(struct super_block *sb,
1096 struct ext4_dir_entry_2 *de,
1098 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FILETYPE))
1099 de->file_type = ext4_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1103 * Move count entries from end of map between two memory locations.
1104 * Returns pointer to last entry moved.
1106 static struct ext4_dir_entry_2 *
1107 dx_move_dirents(char *from, char *to, struct dx_map_entry *map, int count)
1109 unsigned rec_len = 0;
1112 struct ext4_dir_entry_2 *de = (struct ext4_dir_entry_2 *) (from + map->offs);
1113 rec_len = EXT4_DIR_REC_LEN(de->name_len);
1114 memcpy (to, de, rec_len);
1115 ((struct ext4_dir_entry_2 *) to)->rec_len =
1116 ext4_rec_len_to_disk(rec_len);
1121 return (struct ext4_dir_entry_2 *) (to - rec_len);
1125 * Compact each dir entry in the range to the minimal rec_len.
1126 * Returns pointer to last entry in range.
1128 static struct ext4_dir_entry_2* dx_pack_dirents(char *base, int size)
1130 struct ext4_dir_entry_2 *next, *to, *prev, *de = (struct ext4_dir_entry_2 *) base;
1131 unsigned rec_len = 0;
1134 while ((char*)de < base + size) {
1135 next = ext4_next_entry(de);
1136 if (de->inode && de->name_len) {
1137 rec_len = EXT4_DIR_REC_LEN(de->name_len);
1139 memmove(to, de, rec_len);
1140 to->rec_len = ext4_rec_len_to_disk(rec_len);
1142 to = (struct ext4_dir_entry_2 *) (((char *) to) + rec_len);
1150 * Split a full leaf block to make room for a new dir entry.
1151 * Allocate a new block, and move entries so that they are approx. equally full.
1152 * Returns pointer to de in block into which the new entry will be inserted.
1154 static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
1155 struct buffer_head **bh,struct dx_frame *frame,
1156 struct dx_hash_info *hinfo, int *error)
1158 unsigned blocksize = dir->i_sb->s_blocksize;
1159 unsigned count, continued;
1160 struct buffer_head *bh2;
1161 ext4_lblk_t newblock;
1163 struct dx_map_entry *map;
1164 char *data1 = (*bh)->b_data, *data2;
1165 unsigned split, move, size, i;
1166 struct ext4_dir_entry_2 *de = NULL, *de2;
1169 bh2 = ext4_append (handle, dir, &newblock, &err);
1176 BUFFER_TRACE(*bh, "get_write_access");
1177 err = ext4_journal_get_write_access(handle, *bh);
1181 BUFFER_TRACE(frame->bh, "get_write_access");
1182 err = ext4_journal_get_write_access(handle, frame->bh);
1186 data2 = bh2->b_data;
1188 /* create map in the end of data2 block */
1189 map = (struct dx_map_entry *) (data2 + blocksize);
1190 count = dx_make_map((struct ext4_dir_entry_2 *) data1,
1191 blocksize, hinfo, map);
1193 dx_sort_map(map, count);
1194 /* Split the existing block in the middle, size-wise */
1197 for (i = count-1; i >= 0; i--) {
1198 /* is more than half of this entry in 2nd half of the block? */
1199 if (size + map[i].size/2 > blocksize/2)
1201 size += map[i].size;
1204 /* map index at which we will split */
1205 split = count - move;
1206 hash2 = map[split].hash;
1207 continued = hash2 == map[split - 1].hash;
1208 dxtrace(printk(KERN_INFO "Split block %lu at %x, %i/%i\n",
1209 (unsigned long)dx_get_block(frame->at),
1210 hash2, split, count-split));
1212 /* Fancy dance to stay within two buffers */
1213 de2 = dx_move_dirents(data1, data2, map + split, count - split);
1214 de = dx_pack_dirents(data1, blocksize);
1215 de->rec_len = ext4_rec_len_to_disk(data1 + blocksize - (char *) de);
1216 de2->rec_len = ext4_rec_len_to_disk(data2 + blocksize - (char *) de2);
1217 dxtrace(dx_show_leaf (hinfo, (struct ext4_dir_entry_2 *) data1, blocksize, 1));
1218 dxtrace(dx_show_leaf (hinfo, (struct ext4_dir_entry_2 *) data2, blocksize, 1));
1220 /* Which block gets the new entry? */
1221 if (hinfo->hash >= hash2)
1226 dx_insert_block(frame, hash2 + continued, newblock);
1227 err = ext4_journal_dirty_metadata(handle, bh2);
1230 err = ext4_journal_dirty_metadata(handle, frame->bh);
1234 dxtrace(dx_show_index("frame", frame->entries));
1241 ext4_std_error(dir->i_sb, err);
1248 * Add a new entry into a directory (leaf) block. If de is non-NULL,
1249 * it points to a directory entry which is guaranteed to be large
1250 * enough for new directory entry. If de is NULL, then
1251 * add_dirent_to_buf will attempt search the directory block for
1252 * space. It will return -ENOSPC if no space is available, and -EIO
1253 * and -EEXIST if directory entry already exists.
1255 * NOTE! bh is NOT released in the case where ENOSPC is returned. In
1256 * all other cases bh is released.
1258 static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1259 struct inode *inode, struct ext4_dir_entry_2 *de,
1260 struct buffer_head *bh)
1262 struct inode *dir = dentry->d_parent->d_inode;
1263 const char *name = dentry->d_name.name;
1264 int namelen = dentry->d_name.len;
1265 unsigned long offset = 0;
1266 unsigned short reclen;
1267 int nlen, rlen, err;
1270 reclen = EXT4_DIR_REC_LEN(namelen);
1272 de = (struct ext4_dir_entry_2 *)bh->b_data;
1273 top = bh->b_data + dir->i_sb->s_blocksize - reclen;
1274 while ((char *) de <= top) {
1275 if (!ext4_check_dir_entry("ext4_add_entry", dir, de,
1280 if (ext4_match(namelen, name, de)) {
1284 nlen = EXT4_DIR_REC_LEN(de->name_len);
1285 rlen = ext4_rec_len_from_disk(de->rec_len);
1286 if ((de->inode? rlen - nlen: rlen) >= reclen)
1288 de = (struct ext4_dir_entry_2 *)((char *)de + rlen);
1291 if ((char *) de > top)
1294 BUFFER_TRACE(bh, "get_write_access");
1295 err = ext4_journal_get_write_access(handle, bh);
1297 ext4_std_error(dir->i_sb, err);
1302 /* By now the buffer is marked for journaling */
1303 nlen = EXT4_DIR_REC_LEN(de->name_len);
1304 rlen = ext4_rec_len_from_disk(de->rec_len);
1306 struct ext4_dir_entry_2 *de1 = (struct ext4_dir_entry_2 *)((char *)de + nlen);
1307 de1->rec_len = ext4_rec_len_to_disk(rlen - nlen);
1308 de->rec_len = ext4_rec_len_to_disk(nlen);
1311 de->file_type = EXT4_FT_UNKNOWN;
1313 de->inode = cpu_to_le32(inode->i_ino);
1314 ext4_set_de_type(dir->i_sb, de, inode->i_mode);
1317 de->name_len = namelen;
1318 memcpy(de->name, name, namelen);
1320 * XXX shouldn't update any times until successful
1321 * completion of syscall, but too many callers depend
1324 * XXX similarly, too many callers depend on
1325 * ext4_new_inode() setting the times, but error
1326 * recovery deletes the inode, so the worst that can
1327 * happen is that the times are slightly out of date
1328 * and/or different from the directory change time.
1330 dir->i_mtime = dir->i_ctime = ext4_current_time(dir);
1331 ext4_update_dx_flag(dir);
1333 ext4_mark_inode_dirty(handle, dir);
1334 BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
1335 err = ext4_journal_dirty_metadata(handle, bh);
1337 ext4_std_error(dir->i_sb, err);
1343 * This converts a one block unindexed directory to a 3 block indexed
1344 * directory, and adds the dentry to the indexed directory.
1346 static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1347 struct inode *inode, struct buffer_head *bh)
1349 struct inode *dir = dentry->d_parent->d_inode;
1350 const char *name = dentry->d_name.name;
1351 int namelen = dentry->d_name.len;
1352 struct buffer_head *bh2;
1353 struct dx_root *root;
1354 struct dx_frame frames[2], *frame;
1355 struct dx_entry *entries;
1356 struct ext4_dir_entry_2 *de, *de2;
1361 struct dx_hash_info hinfo;
1363 struct fake_dirent *fde;
1365 blocksize = dir->i_sb->s_blocksize;
1366 dxtrace(printk(KERN_DEBUG "Creating index\n"));
1367 retval = ext4_journal_get_write_access(handle, bh);
1369 ext4_std_error(dir->i_sb, retval);
1373 root = (struct dx_root *) bh->b_data;
1375 bh2 = ext4_append(handle, dir, &block, &retval);
1380 EXT4_I(dir)->i_flags |= EXT4_INDEX_FL;
1381 data1 = bh2->b_data;
1383 /* The 0th block becomes the root, move the dirents out */
1384 fde = &root->dotdot;
1385 de = (struct ext4_dir_entry_2 *)((char *)fde +
1386 ext4_rec_len_from_disk(fde->rec_len));
1387 len = ((char *) root) + blocksize - (char *) de;
1388 memcpy (data1, de, len);
1389 de = (struct ext4_dir_entry_2 *) data1;
1391 while ((char *)(de2 = ext4_next_entry(de)) < top)
1393 de->rec_len = ext4_rec_len_to_disk(data1 + blocksize - (char *) de);
1394 /* Initialize the root; the dot dirents already exist */
1395 de = (struct ext4_dir_entry_2 *) (&root->dotdot);
1396 de->rec_len = ext4_rec_len_to_disk(blocksize - EXT4_DIR_REC_LEN(2));
1397 memset (&root->info, 0, sizeof(root->info));
1398 root->info.info_length = sizeof(root->info);
1399 root->info.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
1400 entries = root->entries;
1401 dx_set_block(entries, 1);
1402 dx_set_count(entries, 1);
1403 dx_set_limit(entries, dx_root_limit(dir, sizeof(root->info)));
1405 /* Initialize as for dx_probe */
1406 hinfo.hash_version = root->info.hash_version;
1407 hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
1408 ext4fs_dirhash(name, namelen, &hinfo);
1410 frame->entries = entries;
1411 frame->at = entries;
1414 de = do_split(handle,dir, &bh, frame, &hinfo, &retval);
1415 dx_release (frames);
1419 return add_dirent_to_buf(handle, dentry, inode, de, bh);
1425 * adds a file entry to the specified directory, using the same
1426 * semantics as ext4_find_entry(). It returns NULL if it failed.
1428 * NOTE!! The inode part of 'de' is left at 0 - which means you
1429 * may not sleep between calling this and putting something into
1430 * the entry, as someone else might have used it while you slept.
1432 static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
1433 struct inode *inode)
1435 struct inode *dir = dentry->d_parent->d_inode;
1436 unsigned long offset;
1437 struct buffer_head *bh;
1438 struct ext4_dir_entry_2 *de;
1439 struct super_block *sb;
1443 ext4_lblk_t block, blocks;
1446 blocksize = sb->s_blocksize;
1447 if (!dentry->d_name.len)
1450 retval = ext4_dx_add_entry(handle, dentry, inode);
1451 if (!retval || (retval != ERR_BAD_DX_DIR))
1453 EXT4_I(dir)->i_flags &= ~EXT4_INDEX_FL;
1455 ext4_mark_inode_dirty(handle, dir);
1457 blocks = dir->i_size >> sb->s_blocksize_bits;
1458 for (block = 0, offset = 0; block < blocks; block++) {
1459 bh = ext4_bread(handle, dir, block, 0, &retval);
1462 retval = add_dirent_to_buf(handle, dentry, inode, NULL, bh);
1463 if (retval != -ENOSPC)
1466 if (blocks == 1 && !dx_fallback &&
1467 EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_DIR_INDEX))
1468 return make_indexed_dir(handle, dentry, inode, bh);
1471 bh = ext4_append(handle, dir, &block, &retval);
1474 de = (struct ext4_dir_entry_2 *) bh->b_data;
1476 de->rec_len = ext4_rec_len_to_disk(blocksize);
1477 return add_dirent_to_buf(handle, dentry, inode, de, bh);
1481 * Returns 0 for success, or a negative error value
1483 static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
1484 struct inode *inode)
1486 struct dx_frame frames[2], *frame;
1487 struct dx_entry *entries, *at;
1488 struct dx_hash_info hinfo;
1489 struct buffer_head *bh;
1490 struct inode *dir = dentry->d_parent->d_inode;
1491 struct super_block *sb = dir->i_sb;
1492 struct ext4_dir_entry_2 *de;
1495 frame = dx_probe(&dentry->d_name, dir, &hinfo, frames, &err);
1498 entries = frame->entries;
1501 if (!(bh = ext4_bread(handle,dir, dx_get_block(frame->at), 0, &err)))
1504 BUFFER_TRACE(bh, "get_write_access");
1505 err = ext4_journal_get_write_access(handle, bh);
1509 err = add_dirent_to_buf(handle, dentry, inode, NULL, bh);
1510 if (err != -ENOSPC) {
1515 /* Block full, should compress but for now just split */
1516 dxtrace(printk(KERN_DEBUG "using %u of %u node entries\n",
1517 dx_get_count(entries), dx_get_limit(entries)));
1518 /* Need to split index? */
1519 if (dx_get_count(entries) == dx_get_limit(entries)) {
1520 ext4_lblk_t newblock;
1521 unsigned icount = dx_get_count(entries);
1522 int levels = frame - frames;
1523 struct dx_entry *entries2;
1524 struct dx_node *node2;
1525 struct buffer_head *bh2;
1527 if (levels && (dx_get_count(frames->entries) ==
1528 dx_get_limit(frames->entries))) {
1529 ext4_warning(sb, __func__,
1530 "Directory index full!");
1534 bh2 = ext4_append (handle, dir, &newblock, &err);
1537 node2 = (struct dx_node *)(bh2->b_data);
1538 entries2 = node2->entries;
1539 node2->fake.rec_len = ext4_rec_len_to_disk(sb->s_blocksize);
1540 node2->fake.inode = 0;
1541 BUFFER_TRACE(frame->bh, "get_write_access");
1542 err = ext4_journal_get_write_access(handle, frame->bh);
1546 unsigned icount1 = icount/2, icount2 = icount - icount1;
1547 unsigned hash2 = dx_get_hash(entries + icount1);
1548 dxtrace(printk(KERN_DEBUG "Split index %i/%i\n",
1551 BUFFER_TRACE(frame->bh, "get_write_access"); /* index root */
1552 err = ext4_journal_get_write_access(handle,
1557 memcpy((char *) entries2, (char *) (entries + icount1),
1558 icount2 * sizeof(struct dx_entry));
1559 dx_set_count(entries, icount1);
1560 dx_set_count(entries2, icount2);
1561 dx_set_limit(entries2, dx_node_limit(dir));
1563 /* Which index block gets the new entry? */
1564 if (at - entries >= icount1) {
1565 frame->at = at = at - entries - icount1 + entries2;
1566 frame->entries = entries = entries2;
1567 swap(frame->bh, bh2);
1569 dx_insert_block(frames + 0, hash2, newblock);
1570 dxtrace(dx_show_index("node", frames[1].entries));
1571 dxtrace(dx_show_index("node",
1572 ((struct dx_node *) bh2->b_data)->entries));
1573 err = ext4_journal_dirty_metadata(handle, bh2);
1578 dxtrace(printk(KERN_DEBUG
1579 "Creating second level index...\n"));
1580 memcpy((char *) entries2, (char *) entries,
1581 icount * sizeof(struct dx_entry));
1582 dx_set_limit(entries2, dx_node_limit(dir));
1585 dx_set_count(entries, 1);
1586 dx_set_block(entries + 0, newblock);
1587 ((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels = 1;
1589 /* Add new access path frame */
1591 frame->at = at = at - entries + entries2;
1592 frame->entries = entries = entries2;
1594 err = ext4_journal_get_write_access(handle,
1599 ext4_journal_dirty_metadata(handle, frames[0].bh);
1601 de = do_split(handle, dir, &bh, frame, &hinfo, &err);
1604 err = add_dirent_to_buf(handle, dentry, inode, de, bh);
1609 ext4_std_error(dir->i_sb, err);
1618 * ext4_delete_entry deletes a directory entry by merging it with the
1621 static int ext4_delete_entry(handle_t *handle,
1623 struct ext4_dir_entry_2 *de_del,
1624 struct buffer_head *bh)
1626 struct ext4_dir_entry_2 *de, *pde;
1631 de = (struct ext4_dir_entry_2 *) bh->b_data;
1632 while (i < bh->b_size) {
1633 if (!ext4_check_dir_entry("ext4_delete_entry", dir, de, bh, i))
1636 BUFFER_TRACE(bh, "get_write_access");
1637 ext4_journal_get_write_access(handle, bh);
1639 pde->rec_len = ext4_rec_len_to_disk(
1640 ext4_rec_len_from_disk(pde->rec_len) +
1641 ext4_rec_len_from_disk(de->rec_len));
1645 BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
1646 ext4_journal_dirty_metadata(handle, bh);
1649 i += ext4_rec_len_from_disk(de->rec_len);
1651 de = ext4_next_entry(de);
1657 * DIR_NLINK feature is set if 1) nlinks > EXT4_LINK_MAX or 2) nlinks == 2,
1658 * since this indicates that nlinks count was previously 1.
1660 static void ext4_inc_count(handle_t *handle, struct inode *inode)
1663 if (is_dx(inode) && inode->i_nlink > 1) {
1664 /* limit is 16-bit i_links_count */
1665 if (inode->i_nlink >= EXT4_LINK_MAX || inode->i_nlink == 2) {
1667 EXT4_SET_RO_COMPAT_FEATURE(inode->i_sb,
1668 EXT4_FEATURE_RO_COMPAT_DIR_NLINK);
1674 * If a directory had nlink == 1, then we should let it be 1. This indicates
1675 * directory has >EXT4_LINK_MAX subdirs.
1677 static void ext4_dec_count(handle_t *handle, struct inode *inode)
1680 if (S_ISDIR(inode->i_mode) && inode->i_nlink == 0)
1685 static int ext4_add_nondir(handle_t *handle,
1686 struct dentry *dentry, struct inode *inode)
1688 int err = ext4_add_entry(handle, dentry, inode);
1690 ext4_mark_inode_dirty(handle, inode);
1691 d_instantiate(dentry, inode);
1692 unlock_new_inode(inode);
1696 unlock_new_inode(inode);
1702 * By the time this is called, we already have created
1703 * the directory cache entry for the new file, but it
1704 * is so far negative - it has no inode.
1706 * If the create succeeds, we fill in the inode information
1707 * with d_instantiate().
1709 static int ext4_create(struct inode *dir, struct dentry *dentry, int mode,
1710 struct nameidata *nd)
1713 struct inode *inode;
1714 int err, retries = 0;
1717 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
1718 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
1719 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
1721 return PTR_ERR(handle);
1723 if (IS_DIRSYNC(dir))
1726 inode = ext4_new_inode (handle, dir, mode);
1727 err = PTR_ERR(inode);
1728 if (!IS_ERR(inode)) {
1729 inode->i_op = &ext4_file_inode_operations;
1730 inode->i_fop = &ext4_file_operations;
1731 ext4_set_aops(inode);
1732 err = ext4_add_nondir(handle, dentry, inode);
1734 ext4_journal_stop(handle);
1735 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
1740 static int ext4_mknod(struct inode *dir, struct dentry *dentry,
1741 int mode, dev_t rdev)
1744 struct inode *inode;
1745 int err, retries = 0;
1747 if (!new_valid_dev(rdev))
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 init_special_inode(inode, inode->i_mode, rdev);
1764 #ifdef CONFIG_EXT4_FS_XATTR
1765 inode->i_op = &ext4_special_inode_operations;
1767 err = ext4_add_nondir(handle, dentry, inode);
1769 ext4_journal_stop(handle);
1770 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
1775 static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1778 struct inode *inode;
1779 struct buffer_head *dir_block;
1780 struct ext4_dir_entry_2 *de;
1781 int err, retries = 0;
1783 if (EXT4_DIR_LINK_MAX(dir))
1787 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
1788 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
1789 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
1791 return PTR_ERR(handle);
1793 if (IS_DIRSYNC(dir))
1796 inode = ext4_new_inode(handle, dir, S_IFDIR | mode);
1797 err = PTR_ERR(inode);
1801 inode->i_op = &ext4_dir_inode_operations;
1802 inode->i_fop = &ext4_dir_operations;
1803 inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
1804 dir_block = ext4_bread(handle, inode, 0, 1, &err);
1806 goto out_clear_inode;
1807 BUFFER_TRACE(dir_block, "get_write_access");
1808 ext4_journal_get_write_access(handle, dir_block);
1809 de = (struct ext4_dir_entry_2 *) dir_block->b_data;
1810 de->inode = cpu_to_le32(inode->i_ino);
1812 de->rec_len = ext4_rec_len_to_disk(EXT4_DIR_REC_LEN(de->name_len));
1813 strcpy(de->name, ".");
1814 ext4_set_de_type(dir->i_sb, de, S_IFDIR);
1815 de = ext4_next_entry(de);
1816 de->inode = cpu_to_le32(dir->i_ino);
1817 de->rec_len = ext4_rec_len_to_disk(inode->i_sb->s_blocksize -
1818 EXT4_DIR_REC_LEN(1));
1820 strcpy(de->name, "..");
1821 ext4_set_de_type(dir->i_sb, de, S_IFDIR);
1823 BUFFER_TRACE(dir_block, "call ext4_journal_dirty_metadata");
1824 ext4_journal_dirty_metadata(handle, dir_block);
1826 ext4_mark_inode_dirty(handle, inode);
1827 err = ext4_add_entry(handle, dentry, inode);
1831 unlock_new_inode(inode);
1832 ext4_mark_inode_dirty(handle, inode);
1836 ext4_inc_count(handle, dir);
1837 ext4_update_dx_flag(dir);
1838 ext4_mark_inode_dirty(handle, dir);
1839 d_instantiate(dentry, inode);
1840 unlock_new_inode(inode);
1842 ext4_journal_stop(handle);
1843 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
1849 * routine to check that the specified directory is empty (for rmdir)
1851 static int empty_dir(struct inode *inode)
1853 unsigned long offset;
1854 struct buffer_head *bh;
1855 struct ext4_dir_entry_2 *de, *de1;
1856 struct super_block *sb;
1860 if (inode->i_size < EXT4_DIR_REC_LEN(1) + EXT4_DIR_REC_LEN(2) ||
1861 !(bh = ext4_bread(NULL, inode, 0, 0, &err))) {
1863 ext4_error(inode->i_sb, __func__,
1864 "error %d reading directory #%lu offset 0",
1867 ext4_warning(inode->i_sb, __func__,
1868 "bad directory (dir #%lu) - no data block",
1872 de = (struct ext4_dir_entry_2 *) bh->b_data;
1873 de1 = ext4_next_entry(de);
1874 if (le32_to_cpu(de->inode) != inode->i_ino ||
1875 !le32_to_cpu(de1->inode) ||
1876 strcmp(".", de->name) ||
1877 strcmp("..", de1->name)) {
1878 ext4_warning(inode->i_sb, "empty_dir",
1879 "bad directory (dir #%lu) - no `.' or `..'",
1884 offset = ext4_rec_len_from_disk(de->rec_len) +
1885 ext4_rec_len_from_disk(de1->rec_len);
1886 de = ext4_next_entry(de1);
1887 while (offset < inode->i_size) {
1889 (void *) de >= (void *) (bh->b_data+sb->s_blocksize)) {
1892 bh = ext4_bread(NULL, inode,
1893 offset >> EXT4_BLOCK_SIZE_BITS(sb), 0, &err);
1896 ext4_error(sb, __func__,
1897 "error %d reading directory"
1899 err, inode->i_ino, offset);
1900 offset += sb->s_blocksize;
1903 de = (struct ext4_dir_entry_2 *) bh->b_data;
1905 if (!ext4_check_dir_entry("empty_dir", inode, de, bh, offset)) {
1906 de = (struct ext4_dir_entry_2 *)(bh->b_data +
1908 offset = (offset | (sb->s_blocksize - 1)) + 1;
1911 if (le32_to_cpu(de->inode)) {
1915 offset += ext4_rec_len_from_disk(de->rec_len);
1916 de = ext4_next_entry(de);
1922 /* ext4_orphan_add() links an unlinked or truncated inode into a list of
1923 * such inodes, starting at the superblock, in case we crash before the
1924 * file is closed/deleted, or in case the inode truncate spans multiple
1925 * transactions and the last transaction is not recovered after a crash.
1927 * At filesystem recovery time, we walk this list deleting unlinked
1928 * inodes and truncating linked inodes in ext4_orphan_cleanup().
1930 int ext4_orphan_add(handle_t *handle, struct inode *inode)
1932 struct super_block *sb = inode->i_sb;
1933 struct ext4_iloc iloc;
1937 if (!list_empty(&EXT4_I(inode)->i_orphan))
1940 /* Orphan handling is only valid for files with data blocks
1941 * being truncated, or files being unlinked. */
1943 /* @@@ FIXME: Observation from aviro:
1944 * I think I can trigger J_ASSERT in ext4_orphan_add(). We block
1945 * here (on lock_super()), so race with ext4_link() which might bump
1946 * ->i_nlink. For, say it, character device. Not a regular file,
1947 * not a directory, not a symlink and ->i_nlink > 0.
1949 J_ASSERT((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1950 S_ISLNK(inode->i_mode)) || inode->i_nlink == 0);
1952 BUFFER_TRACE(EXT4_SB(sb)->s_sbh, "get_write_access");
1953 err = ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh);
1957 err = ext4_reserve_inode_write(handle, inode, &iloc);
1961 /* Insert this inode at the head of the on-disk orphan list... */
1962 NEXT_ORPHAN(inode) = le32_to_cpu(EXT4_SB(sb)->s_es->s_last_orphan);
1963 EXT4_SB(sb)->s_es->s_last_orphan = cpu_to_le32(inode->i_ino);
1964 err = ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh);
1965 rc = ext4_mark_iloc_dirty(handle, inode, &iloc);
1969 /* Only add to the head of the in-memory list if all the
1970 * previous operations succeeded. If the orphan_add is going to
1971 * fail (possibly taking the journal offline), we can't risk
1972 * leaving the inode on the orphan list: stray orphan-list
1973 * entries can cause panics at unmount time.
1975 * This is safe: on error we're going to ignore the orphan list
1976 * anyway on the next recovery. */
1978 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
1980 jbd_debug(4, "superblock will point to %lu\n", inode->i_ino);
1981 jbd_debug(4, "orphan inode %lu will point to %d\n",
1982 inode->i_ino, NEXT_ORPHAN(inode));
1985 ext4_std_error(inode->i_sb, err);
1990 * ext4_orphan_del() removes an unlinked or truncated inode from the list
1991 * of such inodes stored on disk, because it is finally being cleaned up.
1993 int ext4_orphan_del(handle_t *handle, struct inode *inode)
1995 struct list_head *prev;
1996 struct ext4_inode_info *ei = EXT4_I(inode);
1997 struct ext4_sb_info *sbi;
1998 unsigned long ino_next;
1999 struct ext4_iloc iloc;
2002 lock_super(inode->i_sb);
2003 if (list_empty(&ei->i_orphan)) {
2004 unlock_super(inode->i_sb);
2008 ino_next = NEXT_ORPHAN(inode);
2009 prev = ei->i_orphan.prev;
2010 sbi = EXT4_SB(inode->i_sb);
2012 jbd_debug(4, "remove inode %lu from orphan list\n", inode->i_ino);
2014 list_del_init(&ei->i_orphan);
2016 /* If we're on an error path, we may not have a valid
2017 * transaction handle with which to update the orphan list on
2018 * disk, but we still need to remove the inode from the linked
2019 * list in memory. */
2023 err = ext4_reserve_inode_write(handle, inode, &iloc);
2027 if (prev == &sbi->s_orphan) {
2028 jbd_debug(4, "superblock will point to %lu\n", ino_next);
2029 BUFFER_TRACE(sbi->s_sbh, "get_write_access");
2030 err = ext4_journal_get_write_access(handle, sbi->s_sbh);
2033 sbi->s_es->s_last_orphan = cpu_to_le32(ino_next);
2034 err = ext4_journal_dirty_metadata(handle, sbi->s_sbh);
2036 struct ext4_iloc iloc2;
2037 struct inode *i_prev =
2038 &list_entry(prev, struct ext4_inode_info, i_orphan)->vfs_inode;
2040 jbd_debug(4, "orphan inode %lu will point to %lu\n",
2041 i_prev->i_ino, ino_next);
2042 err = ext4_reserve_inode_write(handle, i_prev, &iloc2);
2045 NEXT_ORPHAN(i_prev) = ino_next;
2046 err = ext4_mark_iloc_dirty(handle, i_prev, &iloc2);
2050 NEXT_ORPHAN(inode) = 0;
2051 err = ext4_mark_iloc_dirty(handle, inode, &iloc);
2054 ext4_std_error(inode->i_sb, err);
2056 unlock_super(inode->i_sb);
2064 static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
2067 struct inode *inode;
2068 struct buffer_head *bh;
2069 struct ext4_dir_entry_2 *de;
2072 /* Initialize quotas before so that eventual writes go in
2073 * separate transaction */
2074 DQUOT_INIT(dentry->d_inode);
2075 handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb));
2077 return PTR_ERR(handle);
2080 bh = ext4_find_entry(dir, &dentry->d_name, &de);
2084 if (IS_DIRSYNC(dir))
2087 inode = dentry->d_inode;
2090 if (le32_to_cpu(de->inode) != inode->i_ino)
2093 retval = -ENOTEMPTY;
2094 if (!empty_dir(inode))
2097 retval = ext4_delete_entry(handle, dir, de, bh);
2100 if (!EXT4_DIR_LINK_EMPTY(inode))
2101 ext4_warning(inode->i_sb, "ext4_rmdir",
2102 "empty directory has too many links (%d)",
2106 /* There's no need to set i_disksize: the fact that i_nlink is
2107 * zero will ensure that the right thing happens during any
2110 ext4_orphan_add(handle, inode);
2111 inode->i_ctime = dir->i_ctime = dir->i_mtime = ext4_current_time(inode);
2112 ext4_mark_inode_dirty(handle, inode);
2113 ext4_dec_count(handle, dir);
2114 ext4_update_dx_flag(dir);
2115 ext4_mark_inode_dirty(handle, dir);
2118 ext4_journal_stop(handle);
2123 static int ext4_unlink(struct inode *dir, struct dentry *dentry)
2126 struct inode *inode;
2127 struct buffer_head *bh;
2128 struct ext4_dir_entry_2 *de;
2131 /* Initialize quotas before so that eventual writes go
2132 * in separate transaction */
2133 DQUOT_INIT(dentry->d_inode);
2134 handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb));
2136 return PTR_ERR(handle);
2138 if (IS_DIRSYNC(dir))
2142 bh = ext4_find_entry(dir, &dentry->d_name, &de);
2146 inode = dentry->d_inode;
2149 if (le32_to_cpu(de->inode) != inode->i_ino)
2152 if (!inode->i_nlink) {
2153 ext4_warning(inode->i_sb, "ext4_unlink",
2154 "Deleting nonexistent file (%lu), %d",
2155 inode->i_ino, inode->i_nlink);
2158 retval = ext4_delete_entry(handle, dir, de, bh);
2161 dir->i_ctime = dir->i_mtime = ext4_current_time(dir);
2162 ext4_update_dx_flag(dir);
2163 ext4_mark_inode_dirty(handle, dir);
2165 if (!inode->i_nlink)
2166 ext4_orphan_add(handle, inode);
2167 inode->i_ctime = ext4_current_time(inode);
2168 ext4_mark_inode_dirty(handle, inode);
2172 ext4_journal_stop(handle);
2177 static int ext4_symlink(struct inode *dir,
2178 struct dentry *dentry, const char *symname)
2181 struct inode *inode;
2182 int l, err, retries = 0;
2184 l = strlen(symname)+1;
2185 if (l > dir->i_sb->s_blocksize)
2186 return -ENAMETOOLONG;
2189 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
2190 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 5 +
2191 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
2193 return PTR_ERR(handle);
2195 if (IS_DIRSYNC(dir))
2198 inode = ext4_new_inode(handle, dir, S_IFLNK|S_IRWXUGO);
2199 err = PTR_ERR(inode);
2203 if (l > sizeof(EXT4_I(inode)->i_data)) {
2204 inode->i_op = &ext4_symlink_inode_operations;
2205 ext4_set_aops(inode);
2207 * page_symlink() calls into ext4_prepare/commit_write.
2208 * We have a transaction open. All is sweetness. It also sets
2209 * i_size in generic_commit_write().
2211 err = __page_symlink(inode, symname, l, 1);
2214 unlock_new_inode(inode);
2215 ext4_mark_inode_dirty(handle, inode);
2220 /* clear the extent format for fast symlink */
2221 EXT4_I(inode)->i_flags &= ~EXT4_EXTENTS_FL;
2222 inode->i_op = &ext4_fast_symlink_inode_operations;
2223 memcpy((char *)&EXT4_I(inode)->i_data, symname, l);
2224 inode->i_size = l-1;
2226 EXT4_I(inode)->i_disksize = inode->i_size;
2227 err = ext4_add_nondir(handle, dentry, inode);
2229 ext4_journal_stop(handle);
2230 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
2235 static int ext4_link(struct dentry *old_dentry,
2236 struct inode *dir, struct dentry *dentry)
2239 struct inode *inode = old_dentry->d_inode;
2240 int err, retries = 0;
2242 if (EXT4_DIR_LINK_MAX(inode))
2246 * Return -ENOENT if we've raced with unlink and i_nlink is 0. Doing
2247 * otherwise has the potential to corrupt the orphan inode list.
2249 if (inode->i_nlink == 0)
2253 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
2254 EXT4_INDEX_EXTRA_TRANS_BLOCKS);
2256 return PTR_ERR(handle);
2258 if (IS_DIRSYNC(dir))
2261 inode->i_ctime = ext4_current_time(inode);
2262 ext4_inc_count(handle, inode);
2263 atomic_inc(&inode->i_count);
2265 err = ext4_add_entry(handle, dentry, inode);
2267 ext4_mark_inode_dirty(handle, inode);
2268 d_instantiate(dentry, inode);
2273 ext4_journal_stop(handle);
2274 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
2279 #define PARENT_INO(buffer) \
2280 (ext4_next_entry((struct ext4_dir_entry_2 *)(buffer))->inode)
2283 * Anybody can rename anything with this: the permission checks are left to the
2284 * higher-level routines.
2286 static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
2287 struct inode *new_dir, struct dentry *new_dentry)
2290 struct inode *old_inode, *new_inode;
2291 struct buffer_head *old_bh, *new_bh, *dir_bh;
2292 struct ext4_dir_entry_2 *old_de, *new_de;
2295 old_bh = new_bh = dir_bh = NULL;
2297 /* Initialize quotas before so that eventual writes go
2298 * in separate transaction */
2299 if (new_dentry->d_inode)
2300 DQUOT_INIT(new_dentry->d_inode);
2301 handle = ext4_journal_start(old_dir, 2 *
2302 EXT4_DATA_TRANS_BLOCKS(old_dir->i_sb) +
2303 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 2);
2305 return PTR_ERR(handle);
2307 if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
2310 old_bh = ext4_find_entry(old_dir, &old_dentry->d_name, &old_de);
2312 * Check for inode number is _not_ due to possible IO errors.
2313 * We might rmdir the source, keep it as pwd of some process
2314 * and merrily kill the link to whatever was created under the
2315 * same name. Goodbye sticky bit ;-<
2317 old_inode = old_dentry->d_inode;
2319 if (!old_bh || le32_to_cpu(old_de->inode) != old_inode->i_ino)
2322 new_inode = new_dentry->d_inode;
2323 new_bh = ext4_find_entry(new_dir, &new_dentry->d_name, &new_de);
2330 if (S_ISDIR(old_inode->i_mode)) {
2332 retval = -ENOTEMPTY;
2333 if (!empty_dir(new_inode))
2337 dir_bh = ext4_bread(handle, old_inode, 0, 0, &retval);
2340 if (le32_to_cpu(PARENT_INO(dir_bh->b_data)) != old_dir->i_ino)
2343 if (!new_inode && new_dir != old_dir &&
2344 new_dir->i_nlink >= EXT4_LINK_MAX)
2348 retval = ext4_add_entry(handle, new_dentry, old_inode);
2352 BUFFER_TRACE(new_bh, "get write access");
2353 ext4_journal_get_write_access(handle, new_bh);
2354 new_de->inode = cpu_to_le32(old_inode->i_ino);
2355 if (EXT4_HAS_INCOMPAT_FEATURE(new_dir->i_sb,
2356 EXT4_FEATURE_INCOMPAT_FILETYPE))
2357 new_de->file_type = old_de->file_type;
2358 new_dir->i_version++;
2359 new_dir->i_ctime = new_dir->i_mtime =
2360 ext4_current_time(new_dir);
2361 ext4_mark_inode_dirty(handle, new_dir);
2362 BUFFER_TRACE(new_bh, "call ext4_journal_dirty_metadata");
2363 ext4_journal_dirty_metadata(handle, new_bh);
2369 * Like most other Unix systems, set the ctime for inodes on a
2372 old_inode->i_ctime = ext4_current_time(old_inode);
2373 ext4_mark_inode_dirty(handle, old_inode);
2378 if (le32_to_cpu(old_de->inode) != old_inode->i_ino ||
2379 old_de->name_len != old_dentry->d_name.len ||
2380 strncmp(old_de->name, old_dentry->d_name.name, old_de->name_len) ||
2381 (retval = ext4_delete_entry(handle, old_dir,
2382 old_de, old_bh)) == -ENOENT) {
2383 /* old_de could have moved from under us during htree split, so
2384 * make sure that we are deleting the right entry. We might
2385 * also be pointing to a stale entry in the unused part of
2386 * old_bh so just checking inum and the name isn't enough. */
2387 struct buffer_head *old_bh2;
2388 struct ext4_dir_entry_2 *old_de2;
2390 old_bh2 = ext4_find_entry(old_dir, &old_dentry->d_name, &old_de2);
2392 retval = ext4_delete_entry(handle, old_dir,
2398 ext4_warning(old_dir->i_sb, "ext4_rename",
2399 "Deleting old file (%lu), %d, error=%d",
2400 old_dir->i_ino, old_dir->i_nlink, retval);
2404 ext4_dec_count(handle, new_inode);
2405 new_inode->i_ctime = ext4_current_time(new_inode);
2407 old_dir->i_ctime = old_dir->i_mtime = ext4_current_time(old_dir);
2408 ext4_update_dx_flag(old_dir);
2410 BUFFER_TRACE(dir_bh, "get_write_access");
2411 ext4_journal_get_write_access(handle, dir_bh);
2412 PARENT_INO(dir_bh->b_data) = cpu_to_le32(new_dir->i_ino);
2413 BUFFER_TRACE(dir_bh, "call ext4_journal_dirty_metadata");
2414 ext4_journal_dirty_metadata(handle, dir_bh);
2415 ext4_dec_count(handle, old_dir);
2417 /* checked empty_dir above, can't have another parent,
2418 * ext4_dec_count() won't work for many-linked dirs */
2419 new_inode->i_nlink = 0;
2421 ext4_inc_count(handle, new_dir);
2422 ext4_update_dx_flag(new_dir);
2423 ext4_mark_inode_dirty(handle, new_dir);
2426 ext4_mark_inode_dirty(handle, old_dir);
2428 ext4_mark_inode_dirty(handle, new_inode);
2429 if (!new_inode->i_nlink)
2430 ext4_orphan_add(handle, new_inode);
2438 ext4_journal_stop(handle);
2443 * directories can handle most operations...
2445 const struct inode_operations ext4_dir_inode_operations = {
2446 .create = ext4_create,
2447 .lookup = ext4_lookup,
2449 .unlink = ext4_unlink,
2450 .symlink = ext4_symlink,
2451 .mkdir = ext4_mkdir,
2452 .rmdir = ext4_rmdir,
2453 .mknod = ext4_mknod,
2454 .rename = ext4_rename,
2455 .setattr = ext4_setattr,
2456 #ifdef CONFIG_EXT4_FS_XATTR
2457 .setxattr = generic_setxattr,
2458 .getxattr = generic_getxattr,
2459 .listxattr = ext4_listxattr,
2460 .removexattr = generic_removexattr,
2462 .permission = ext4_permission,
2465 const struct inode_operations ext4_special_inode_operations = {
2466 .setattr = ext4_setattr,
2467 #ifdef CONFIG_EXT4_FS_XATTR
2468 .setxattr = generic_setxattr,
2469 .getxattr = generic_getxattr,
2470 .listxattr = ext4_listxattr,
2471 .removexattr = generic_removexattr,
2473 .permission = ext4_permission,