36 #define NAMEI_RA_CHUNKS 2
37 #define NAMEI_RA_BLOCKS 4
38 #define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS)
39 #define NAMEI_RA_INDEX(c,b) (((c) * NAMEI_RA_BLOCKS) + (b))
41 static struct buffer_head *ext3_append(handle_t *
handle,
45 struct buffer_head *bh;
47 *block = inode->
i_size >> inode->
i_sb->s_blocksize_bits;
49 if ((bh = ext3_dir_bread(handle, inode, *block, 1, err))) {
51 EXT3_I(inode)->i_disksize = inode->
i_size;
62 #define assert(test) J_ASSERT(test)
66 #define dxtrace(command) command
68 #define dxtrace(command)
124 struct buffer_head *
bh;
136 static inline unsigned dx_get_block (
struct dx_entry *
entry);
144 static unsigned dx_root_limit (
struct inode *dir,
unsigned infosize);
145 static unsigned dx_node_limit (
struct inode *dir);
151 static void dx_release (
struct dx_frame *frames);
157 static struct ext3_dir_entry_2 *dx_pack_dirents(
char *base,
unsigned blocksize);
163 static struct buffer_head * ext3_dx_find_entry(
struct inode *dir,
176 ext3_rec_len_from_disk(p->
rec_len));
209 static inline unsigned dx_get_limit (
struct dx_entry *entries)
214 static inline void dx_set_count (
struct dx_entry *entries,
unsigned value)
219 static inline void dx_set_limit (
struct dx_entry *entries,
unsigned value)
224 static inline unsigned dx_root_limit (
struct inode *dir,
unsigned infosize)
228 return entry_space /
sizeof(
struct dx_entry);
231 static inline unsigned dx_node_limit (
struct inode *dir)
234 return entry_space /
sizeof(
struct dx_entry);
241 static void dx_show_index (
char *
label,
struct dx_entry *entries)
243 int i,
n = dx_get_count (entries);
244 printk(
"%s index ", label);
245 for (i = 0; i <
n; i++)
247 printk(
"%x->%u ", i? dx_get_hash(entries + i): 0, dx_get_block(entries + i));
260 int size,
int show_names)
262 unsigned names = 0, space = 0;
263 char *
base = (
char *) de;
267 while ((
char *) de < base + size)
275 while (len--)
printk(
"%c", *name++);
278 (
unsigned) ((
char *) de - base));
283 de = ext3_next_entry(de);
286 return (
struct stats) { names, space, 1 };
292 unsigned blocksize = dir->
i_sb->s_blocksize;
293 unsigned count = dx_get_count (entries), names = 0, space = 0,
i;
295 struct buffer_head *bh;
297 printk(
"%i indexed blocks...\n", count);
298 for (i = 0; i <
count; i++, entries++)
300 u32 block = dx_get_block(entries),
hash = i? dx_get_hash(entries): 0;
303 printk(
"%s%3u:%03u hash %8x/%8x ",levels?
"":
" ", i, block,
hash, range);
306 dx_show_entries(hinfo, dir, ((
struct dx_node *) bh->b_data)->entries, levels - 1):
308 names +=
stats.names;
309 space +=
stats.space;
310 bcount +=
stats.bcount;
314 printk(
"%snames %u, fullness %u (%u%%)\n", levels?
"":
" ",
315 names, space/bcount,(space/bcount)*100/blocksize);
316 return (
struct stats) { names, space, bcount};
333 unsigned count, indirect;
336 struct buffer_head *bh;
341 if (!(bh = ext3_dir_bread(
NULL, dir, 0, 0, err))) {
345 root = (
struct dx_root *) bh->b_data;
350 "Unrecognised inode hash code %d",
351 root->
info.hash_version);
359 hinfo->
seed = EXT3_SB(dir->
i_sb)->s_hash_seed;
364 if (root->
info.unused_flags & 1) {
366 "Unimplemented inode hash flags: %#06x",
367 root->
info.unused_flags);
373 if ((indirect = root->
info.indirect_levels) > 1) {
375 "Unimplemented inode hash depth: %#06x",
376 root->
info.indirect_levels);
383 root->
info.info_length);
385 if (dx_get_limit(entries) != dx_root_limit(dir,
386 root->
info.info_length)) {
388 "dx entry: limit != root limit");
397 count = dx_get_count(entries);
398 if (!count || count > dx_get_limit(entries)) {
400 "dx entry: no count or count > limit");
407 q = entries + count - 1;
412 if (dx_get_hash(m) > hash)
420 unsigned n = count - 1;
425 if (dx_get_hash(++at) > hash)
435 dxtrace(
printk(
" %x->%u\n", at == entries? 0: dx_get_hash(at), dx_get_block(at)));
439 if (!indirect--)
return frame;
440 if (!(bh = ext3_dir_bread(
NULL, dir, dx_get_block(at), 0, err))) {
444 at = entries = ((
struct dx_node *) bh->b_data)->entries;
445 if (dx_get_limit(entries) != dx_node_limit (dir)) {
447 "dx entry: limit != node limit");
456 while (frame >= frame_in) {
463 "Corrupt dir inode %ld, running e2fsck is "
464 "recommended.", dir->
i_ino);
468 static void dx_release (
struct dx_frame *frames)
470 if (frames[0].bh ==
NULL)
473 if (((
struct dx_root *) frames[0].bh->b_data)->info.indirect_levels)
474 brelse(frames[1].bh);
475 brelse(frames[0].bh);
495 static int ext3_htree_next_block(
struct inode *dir,
__u32 hash,
501 struct buffer_head *bh;
502 int err, num_frames = 0;
529 bhash = dx_get_hash(p->
at);
532 if ((hash & 1) == 0) {
533 if ((bhash & ~1) != hash)
540 while (num_frames--) {
541 if (!(bh = ext3_dir_bread(
NULL, dir, dx_get_block(p->
at),
558 static int htree_dirblock_to_tree(
struct file *dir_file,
559 struct inode *dir,
int block,
563 struct buffer_head *bh;
565 int err = 0, count = 0;
567 dxtrace(
printk(
"In htree dirblock_to_tree: block %d\n", block));
569 if (!(bh = ext3_dir_bread(
NULL, dir, block, 0, &err)))
574 dir->
i_sb->s_blocksize -
576 for (; de <
top; de = ext3_next_entry(de)) {
579 +((
char *)de - bh->b_data))) {
582 (dir->
i_sb->s_blocksize - 1)) + 1;
587 if ((hinfo->
hash < start_hash) ||
588 ((hinfo->
hash == start_hash) &&
625 dxtrace(
printk(
"In htree_fill_tree, start hash: %x:%x\n", start_hash,
627 dir = dir_file->
f_path.dentry->d_inode;
632 EXT3_SB(dir->
i_sb)->s_hash_unsigned;
633 hinfo.
seed = EXT3_SB(dir->
i_sb)->s_hash_seed;
634 count = htree_dirblock_to_tree(dir_file, dir, 0, &hinfo,
635 start_hash, start_minor_hash);
639 hinfo.
hash = start_hash;
641 frame = dx_probe(
NULL, dir_file->
f_path.dentry->d_inode, &hinfo, frames, &err);
646 if (!start_hash && !start_minor_hash) {
652 if (start_hash < 2 || (start_hash ==2 && start_minor_hash==0)) {
654 de = ext3_next_entry(de);
661 block = dx_get_block(frame->
at);
662 ret = htree_dirblock_to_tree(dir_file, dir, block, &hinfo,
663 start_hash, start_minor_hash);
671 frame, frames, &hashval);
672 *next_hash = hashval;
683 (count && ((hashval & 1) == 0)))
687 dxtrace(
printk(
"Fill tree: returned %d entries, next hash: %x\n",
708 char *base = (
char *) de;
711 while ((
char *) de < base + blocksize)
717 map_tail->
offs = (
u16) ((
char *) de - base);
723 de = ext3_next_entry(de);
739 for (p = top, q = p - count; q >=
map; p--, q--)
749 if (q[1].hash >= q[0].hash)
757 static void dx_insert_block(
struct dx_frame *frame,
u32 hash,
u32 block)
760 struct dx_entry *old = frame->
at, *
new = old + 1;
761 int count = dx_get_count(entries);
763 assert(count < dx_get_limit(entries));
764 assert(old < entries + count);
765 memmove(
new + 1,
new, (
char *)(entries + count) - (
char *)(
new));
766 dx_set_hash(
new, hash);
767 dx_set_block(
new, block);
768 dx_set_count(entries, count + 1);
771 static void ext3_update_dx_flag(
struct inode *
inode)
784 static inline int ext3_match (
int len,
const char *
const name,
797 static inline int search_dirblock(
struct buffer_head * bh,
806 const char *name = child->
name;
810 dlimit = bh->b_data + dir->
i_sb->s_blocksize;
811 while ((
char *) de < dlimit) {
815 if ((
char *) de + namelen <= dlimit &&
816 ext3_match (namelen, name, de)) {
819 dir, de, bh, offset))
825 de_len = ext3_rec_len_from_disk(de->
rec_len);
846 static struct buffer_head *ext3_find_entry(
struct inode *dir,
852 struct buffer_head * bh, *
ret =
NULL;
854 const u8 *name = entry->
name;
865 namelen = entry->len;
868 if ((namelen <= 2) && (name[0] ==
'.') &&
869 (name[1] ==
'.' || name[1] == 0)) {
879 bh = ext3_dx_find_entry(dir, entry, res_dir, &err);
887 dxtrace(
printk(
"ext3_find_entry: dx failed, falling back\n"));
890 start = EXT3_I(dir)->i_dir_start_lookup;
891 if (start >= nblocks)
899 if (ra_ptr >= ra_max) {
909 if (b >= nblocks || (num && block == start)) {
910 bh_use[ra_max] =
NULL;
924 if ((bh = bh_use[ra_ptr++]) ==
NULL)
927 if (!buffer_uptodate(bh)) {
929 ext3_error(sb, __func__,
"reading directory #%lu "
930 "offset %lu", dir->
i_ino, block);
934 i = search_dirblock(bh, dir, entry,
937 EXT3_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);
956 if (block < nblocks) {
963 for (; ra_ptr < ra_max; ra_ptr++)
964 brelse (bh_use[ra_ptr]);
968 static struct buffer_head * ext3_dx_find_entry(
struct inode *dir,
975 struct buffer_head *bh;
979 if (!(frame = dx_probe(entry, dir, &hinfo, frames, err)))
982 block = dx_get_block(frame->
at);
983 if (!(bh = ext3_dir_bread (
NULL, dir, block, 0, err)))
986 retval = search_dirblock(bh, dir, entry,
1000 retval = ext3_htree_next_block(dir, hinfo.
hash, frame,
1004 "error reading index page in directory #%lu",
1009 }
while (retval == 1);
1014 dx_release (frames);
1020 struct inode *
inode;
1022 struct buffer_head * bh;
1027 bh = ext3_find_entry(dir, &dentry->
d_name, &de);
1032 if (!ext3_valid_inum(dir->
i_sb, ino)) {
1034 "bad inode number: %lu", ino);
1035 return ERR_PTR(-
EIO);
1038 if (inode == ERR_PTR(-
ESTALE)) {
1040 "deleted inode referenced: %lu",
1042 return ERR_PTR(-
EIO);
1054 struct buffer_head *bh;
1056 bh = ext3_find_entry(child->
d_inode, &dotdot, &de);
1062 if (!ext3_valid_inum(child->
d_inode->i_sb, ino)) {
1064 "bad inode number: %lu", ino);
1065 return ERR_PTR(-
EIO);
1072 static unsigned char ext3_type_by_mode[
S_IFMT >>
S_SHIFT] = {
1082 static inline void ext3_set_de_type(
struct super_block *sb,
1101 memcpy (to, de, rec_len);
1103 ext3_rec_len_to_disk(rec_len);
1115 static struct ext3_dir_entry_2 *dx_pack_dirents(
char *base,
unsigned blocksize)
1119 unsigned rec_len = 0;
1122 while ((
char *)de < base + blocksize) {
1123 next = ext3_next_entry(de);
1128 to->
rec_len = ext3_rec_len_to_disk(rec_len);
1143 struct buffer_head **bh,
struct dx_frame *frame,
1146 unsigned blocksize = dir->
i_sb->s_blocksize;
1147 unsigned count, continued;
1148 struct buffer_head *bh2;
1157 bh2 = ext3_append (handle, dir, &newblock, &err);
1164 BUFFER_TRACE(*bh,
"get_write_access");
1169 BUFFER_TRACE(frame->
bh,
"get_write_access");
1174 data2 = bh2->b_data;
1179 blocksize, hinfo, map);
1181 dx_sort_map (map, count);
1185 for (i = count-1; i >= 0; i--) {
1187 if (size + map[i].size/2 > blocksize/2)
1189 size += map[
i].
size;
1193 split = count - move;
1195 continued = hash2 == map[split - 1].
hash;
1197 dx_get_block(frame->
at), hash2, split, count-split));
1200 de2 = dx_move_dirents(data1,
data2, map + split, count - split);
1201 de = dx_pack_dirents(data1,blocksize);
1202 de->
rec_len = ext3_rec_len_to_disk(data1 + blocksize - (
char *) de);
1203 de2->rec_len = ext3_rec_len_to_disk(
data2 + blocksize - (
char *) de2);
1208 if (hinfo->
hash >= hash2)
1213 dx_insert_block (frame, hash2 + continued, newblock);
1246 static int add_dirent_to_buf(handle_t *handle,
struct dentry *dentry,
1248 struct buffer_head * bh)
1250 struct inode *dir = dentry->
d_parent->d_inode;
1251 const char *name = dentry->
d_name.name;
1252 int namelen = dentry->
d_name.len;
1253 unsigned long offset = 0;
1254 unsigned short reclen;
1255 int nlen, rlen,
err;
1261 top = bh->b_data + dir->
i_sb->s_blocksize - reclen;
1262 while ((
char *) de <=
top) {
1268 if (ext3_match (namelen, name, de)) {
1273 rlen = ext3_rec_len_from_disk(de->
rec_len);
1274 if ((de->
inode? rlen - nlen: rlen) >= reclen)
1279 if ((
char *) de >
top)
1282 BUFFER_TRACE(bh,
"get_write_access");
1292 rlen = ext3_rec_len_from_disk(de->
rec_len);
1295 de1->
rec_len = ext3_rec_len_to_disk(rlen - nlen);
1296 de->
rec_len = ext3_rec_len_to_disk(nlen);
1302 ext3_set_de_type(dir->
i_sb, de, inode->
i_mode);
1319 ext3_update_dx_flag(dir);
1322 BUFFER_TRACE(bh,
"call ext3_journal_dirty_metadata");
1334 static int make_indexed_dir(handle_t *handle,
struct dentry *dentry,
1335 struct inode *inode,
struct buffer_head *bh)
1337 struct inode *dir = dentry->
d_parent->d_inode;
1338 const char *name = dentry->
d_name.name;
1339 int namelen = dentry->
d_name.len;
1340 struct buffer_head *bh2;
1353 blocksize = dir->
i_sb->s_blocksize;
1361 root = (
struct dx_root *) bh->b_data;
1366 ext3_rec_len_from_disk(fde->
rec_len));
1367 if ((
char *) de >= (((
char *) root) + blocksize)) {
1369 "invalid rec_len for '..' in inode %lu",
1374 len = ((
char *) root) + blocksize - (
char *) de;
1376 bh2 = ext3_append (handle, dir, &block, &retval);
1382 data1 = bh2->b_data;
1387 while ((
char *)(de2 = ext3_next_entry(de)) < top)
1389 de->
rec_len = ext3_rec_len_to_disk(data1 + blocksize - (
char *) de);
1394 root->
info.info_length =
sizeof(root->
info);
1395 root->
info.hash_version = EXT3_SB(dir->
i_sb)->s_def_hash_version;
1397 dx_set_block (entries, 1);
1398 dx_set_count (entries, 1);
1399 dx_set_limit (entries, dx_root_limit(dir,
sizeof(root->
info)));
1405 hinfo.
seed = EXT3_SB(dir->
i_sb)->s_hash_seed;
1418 de = do_split(handle,dir, &bh, frame, &hinfo, &retval);
1426 return add_dirent_to_buf(handle, dentry, inode, de, bh);
1439 static int ext3_add_entry (handle_t *handle,
struct dentry *dentry,
1440 struct inode *inode)
1442 struct inode *dir = dentry->
d_parent->d_inode;
1443 struct buffer_head * bh;
1456 retval = ext3_dx_add_entry(handle, dentry, inode);
1464 for (block = 0; block < blocks; block++) {
1465 if (!(bh = ext3_dir_bread(handle, dir, block, 0, &retval)))
1468 retval = add_dirent_to_buf(handle, dentry, inode,
NULL, bh);
1472 if (blocks == 1 && !dx_fallback &&
1474 return make_indexed_dir(handle, dentry, inode, bh);
1477 bh = ext3_append(handle, dir, &block, &retval);
1482 de->
rec_len = ext3_rec_len_to_disk(blocksize);
1483 return add_dirent_to_buf(handle, dentry, inode, de, bh);
1489 static int ext3_dx_add_entry(handle_t *handle,
struct dentry *dentry,
1490 struct inode *inode)
1495 struct buffer_head * bh;
1496 struct inode *dir = dentry->
d_parent->d_inode;
1501 frame = dx_probe(&dentry->
d_name, dir, &hinfo, frames, &err);
1507 if (!(bh = ext3_dir_bread(handle, dir, dx_get_block(frame->
at), 0, &err)))
1510 BUFFER_TRACE(bh,
"get_write_access");
1515 err = add_dirent_to_buf(handle, dentry, inode,
NULL, bh);
1523 dx_get_count(entries), dx_get_limit(entries)));
1525 if (dx_get_count(entries) == dx_get_limit(entries)) {
1527 unsigned icount = dx_get_count(entries);
1528 int levels = frame - frames;
1531 struct buffer_head *bh2;
1533 if (levels && (dx_get_count(frames->entries) ==
1534 dx_get_limit(frames->entries))) {
1536 "Directory index full!");
1540 bh2 = ext3_append (handle, dir, &newblock, &err);
1543 node2 = (
struct dx_node *)(bh2->b_data);
1547 BUFFER_TRACE(frame->
bh,
"get_write_access");
1552 unsigned icount1 = icount/2, icount2 = icount - icount1;
1553 unsigned hash2 = dx_get_hash(entries + icount1);
1556 BUFFER_TRACE(frame->
bh,
"get_write_access");
1562 memcpy ((
char *) entries2, (
char *) (entries + icount1),
1563 icount2 *
sizeof(
struct dx_entry));
1564 dx_set_count (entries, icount1);
1565 dx_set_count (entries2, icount2);
1566 dx_set_limit (entries2, dx_node_limit(dir));
1569 if (at - entries >= icount1) {
1570 frame->
at = at = at - entries - icount1 + entries2;
1571 frame->
entries = entries = entries2;
1574 dx_insert_block (frames + 0, hash2, newblock);
1575 dxtrace(dx_show_index (
"node", frames[1].entries));
1576 dxtrace(dx_show_index (
"node",
1577 ((
struct dx_node *) bh2->b_data)->entries));
1584 memcpy((
char *) entries2, (
char *) entries,
1586 dx_set_limit(entries2, dx_node_limit(dir));
1589 dx_set_count(entries, 1);
1590 dx_set_block(entries + 0, newblock);
1591 ((
struct dx_root *) frames[0].bh->b_data)->info.indirect_levels = 1;
1595 frame->
at = at = at - entries + entries2;
1596 frame->
entries = entries = entries2;
1607 de = do_split(handle, dir, &bh, frame, &hinfo, &err);
1610 err = add_dirent_to_buf(handle, dentry, inode, de, bh);
1627 static int ext3_delete_entry (handle_t *handle,
1630 struct buffer_head * bh)
1638 while (i < bh->b_size) {
1644 BUFFER_TRACE(bh,
"get_write_access");
1650 pde->
rec_len = ext3_rec_len_to_disk(
1651 ext3_rec_len_from_disk(pde->
rec_len) +
1652 ext3_rec_len_from_disk(de->
rec_len));
1656 BUFFER_TRACE(bh,
"call ext3_journal_dirty_metadata");
1665 i += ext3_rec_len_from_disk(de->
rec_len);
1667 de = ext3_next_entry(de);
1672 static int ext3_add_nondir(handle_t *handle,
1673 struct dentry *dentry,
struct inode *inode)
1675 int err = ext3_add_entry(handle, dentry, inode);
1696 static int ext3_create (
struct inode * dir,
struct dentry * dentry,
umode_t mode,
1700 struct inode *
inode;
1710 return PTR_ERR(handle);
1716 err = PTR_ERR(inode);
1717 if (!IS_ERR(inode)) {
1721 err = ext3_add_nondir(handle, dentry, inode);
1729 static int ext3_mknod (
struct inode * dir,
struct dentry *dentry,
1733 struct inode *
inode;
1734 int err, retries = 0;
1736 if (!new_valid_dev(rdev))
1746 return PTR_ERR(handle);
1752 err = PTR_ERR(inode);
1753 if (!IS_ERR(inode)) {
1755 #ifdef CONFIG_EXT3_FS_XATTR
1758 err = ext3_add_nondir(handle, dentry, inode);
1766 static int ext3_mkdir(
struct inode * dir,
struct dentry * dentry,
umode_t mode)
1769 struct inode *
inode;
1770 struct buffer_head * dir_block =
NULL;
1772 int err, retries = 0;
1784 return PTR_ERR(handle);
1790 err = PTR_ERR(inode);
1796 inode->
i_size = EXT3_I(inode)->i_disksize = inode->
i_sb->s_blocksize;
1797 if (!(dir_block = ext3_dir_bread(handle, inode, 0, 1, &err)))
1798 goto out_clear_inode;
1800 BUFFER_TRACE(dir_block,
"get_write_access");
1803 goto out_clear_inode;
1811 de = ext3_next_entry(de);
1813 de->
rec_len = ext3_rec_len_to_disk(inode->
i_sb->s_blocksize -
1819 BUFFER_TRACE(dir_block,
"call ext3_journal_dirty_metadata");
1822 goto out_clear_inode;
1826 err = ext3_add_entry (handle, dentry, inode);
1837 ext3_update_dx_flag(dir);
1840 goto out_clear_inode;
1855 static int empty_dir (
struct inode * inode)
1858 struct buffer_head * bh;
1865 !(bh = ext3_dir_bread(
NULL, inode, 0, 0, &err))) {
1868 "error %d reading directory #%lu offset 0",
1872 "bad directory (dir #%lu) - no data block",
1877 de1 = ext3_next_entry(de);
1883 "bad directory (dir #%lu) - no `.' or `..'",
1888 offset = ext3_rec_len_from_disk(de->
rec_len) +
1889 ext3_rec_len_from_disk(de1->
rec_len);
1890 de = ext3_next_entry(de1);
1893 (
void *) de >= (
void *) (bh->b_data+sb->
s_blocksize)) {
1896 if (!(bh = ext3_dir_bread (
NULL, inode,
1900 "error %d reading directory"
1902 err, inode->
i_ino, offset);
1918 offset += ext3_rec_len_from_disk(de->
rec_len);
1919 de = ext3_next_entry(de);
1940 if (!list_empty(&EXT3_I(inode)->i_orphan))
1959 BUFFER_TRACE(EXT3_SB(sb)->s_sbh,
"get_write_access");
1985 list_add(&EXT3_I(inode)->i_orphan, &EXT3_SB(sb)->s_orphan);
1988 jbd_debug(4,
"orphan inode %lu will point to %d\n",
2005 unsigned long ino_next;
2015 sbi = EXT3_SB(inode->
i_sb);
2017 jbd_debug(4,
"remove inode %lu from orphan list\n", inode->
i_ino);
2033 jbd_debug(4,
"superblock will point to %lu\n", ino_next);
2034 BUFFER_TRACE(sbi->
s_sbh,
"get_write_access");
2042 struct inode *i_prev =
2045 jbd_debug(4,
"orphan inode %lu will point to %lu\n",
2046 i_prev->
i_ino, ino_next);
2069 static int ext3_rmdir (
struct inode * dir,
struct dentry *dentry)
2072 struct inode *
inode;
2073 struct buffer_head * bh;
2084 return PTR_ERR(handle);
2087 bh = ext3_find_entry(dir, &dentry->
d_name, &de);
2101 if (!empty_dir (inode))
2104 retval = ext3_delete_entry(handle, dir, de, bh);
2109 "empty directory has nlink!=2 (%d)",
2121 ext3_update_dx_flag(dir);
2130 static int ext3_unlink(
struct inode * dir,
struct dentry *dentry)
2133 struct inode *
inode;
2134 struct buffer_head * bh;
2138 trace_ext3_unlink_enter(dir, dentry);
2146 return PTR_ERR(handle);
2152 bh = ext3_find_entry(dir, &dentry->
d_name, &de);
2164 "Deleting nonexistent file (%lu), %d",
2168 retval = ext3_delete_entry(handle, dir, de, bh);
2172 ext3_update_dx_flag(dir);
2184 trace_ext3_unlink_exit(dentry, retval);
2188 static int ext3_symlink (
struct inode * dir,
2189 struct dentry *dentry,
const char * symname)
2192 struct inode *
inode;
2193 int l,
err, retries = 0;
2197 if (l > dir->
i_sb->s_blocksize)
2223 handle = ext3_journal_start(dir, credits);
2225 return PTR_ERR(handle);
2231 err = PTR_ERR(inode);
2253 goto err_drop_inode;
2256 goto err_drop_inode;
2261 handle = ext3_journal_start(dir,
2264 if (IS_ERR(handle)) {
2265 err = PTR_ERR(handle);
2266 goto err_drop_inode;
2273 goto err_drop_inode;
2280 EXT3_I(inode)->i_disksize = inode->
i_size;
2281 err = ext3_add_nondir(handle, dentry, inode);
2293 static int ext3_link (
struct dentry * old_dentry,
2294 struct inode * dir,
struct dentry *dentry)
2297 struct inode *inode = old_dentry->
d_inode;
2298 int err, retries = 0;
2309 return PTR_ERR(handle);
2318 err = ext3_add_entry(handle, dentry, inode);
2332 #define PARENT_INO(buffer) \
2333 (ext3_next_entry((struct ext3_dir_entry_2 *)(buffer))->inode)
2339 static int ext3_rename (
struct inode * old_dir,
struct dentry *old_dentry,
2340 struct inode * new_dir,
struct dentry *new_dentry)
2344 struct buffer_head * old_bh, * new_bh, * dir_bh;
2346 int retval, flush_file = 0;
2351 old_bh = new_bh = dir_bh =
NULL;
2357 handle = ext3_journal_start(old_dir, 2 *
2361 return PTR_ERR(handle);
2366 old_bh = ext3_find_entry(old_dir, &old_dentry->
d_name, &old_de);
2373 old_inode = old_dentry->
d_inode;
2378 new_inode = new_dentry->
d_inode;
2379 new_bh = ext3_find_entry(new_dir, &new_dentry->
d_name, &new_de);
2389 if (!empty_dir (new_inode))
2393 dir_bh = ext3_dir_bread(handle, old_inode, 0, 0, &retval);
2399 if (!new_inode && new_dir!=old_dir &&
2404 retval = ext3_add_entry (handle, new_dentry, old_inode);
2408 BUFFER_TRACE(new_bh,
"get write access");
2419 BUFFER_TRACE(new_bh,
"call ext3_journal_dirty_metadata");
2440 (retval = ext3_delete_entry(handle, old_dir,
2441 old_de, old_bh)) == -
ENOENT) {
2446 struct buffer_head *old_bh2;
2449 old_bh2 = ext3_find_entry(old_dir, &old_dentry->
d_name,
2452 retval = ext3_delete_entry(handle, old_dir,
2459 "Deleting old file (%lu), %d, error=%d",
2468 ext3_update_dx_flag(old_dir);
2470 BUFFER_TRACE(dir_bh,
"get_write_access");
2475 BUFFER_TRACE(dir_bh,
"call ext3_journal_dirty_metadata");
2487 ext3_update_dx_flag(new_dir);
2496 if (ext3_should_writeback_data(new_inode))
2506 if (retval == 0 && flush_file)
2515 .create = ext3_create,
2516 .lookup = ext3_lookup,
2518 .unlink = ext3_unlink,
2519 .symlink = ext3_symlink,
2520 .mkdir = ext3_mkdir,
2521 .rmdir = ext3_rmdir,
2522 .mknod = ext3_mknod,
2523 .rename = ext3_rename,
2525 #ifdef CONFIG_EXT3_FS_XATTR
2536 #ifdef CONFIG_EXT3_FS_XATTR