2 * dirblock.c --- directory block routines.
4 * Copyright (C) 1995, 1996 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
19 #if EXT2_FLAT_INCLUDES
22 #include <linux/ext2_fs.h>
27 errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
32 struct ext2_dir_entry *dirent;
34 retval = io_channel_read_blk(fs->io, block, 1, buf);
37 if ((fs->flags & (EXT2_FLAG_SWAP_BYTES|
38 EXT2_FLAG_SWAP_BYTES_READ)) == 0)
41 end = (char *) buf + fs->blocksize;
43 dirent = (struct ext2_dir_entry *) p;
44 dirent->inode = ext2fs_swab32(dirent->inode);
45 dirent->rec_len = ext2fs_swab16(dirent->rec_len);
46 dirent->name_len = ext2fs_swab16(dirent->name_len);
47 p += (dirent->rec_len < 8) ? 8 : dirent->rec_len;
52 errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
56 char *p, *end, *write_buf;
58 struct ext2_dir_entry *dirent;
60 if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
61 (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)) {
62 retval = ext2fs_get_mem(fs->blocksize, (void **) &buf);
66 memcpy(buf, inbuf, fs->blocksize);
68 end = buf + fs->blocksize;
70 dirent = (struct ext2_dir_entry *) p;
71 p += (dirent->rec_len < 8) ? 8 : dirent->rec_len;
72 dirent->inode = ext2fs_swab32(dirent->inode);
73 dirent->rec_len = ext2fs_swab16(dirent->rec_len);
74 dirent->name_len = ext2fs_swab16(dirent->name_len);
77 write_buf = (char *) inbuf;
78 retval = io_channel_write_blk(fs->io, block, 1, write_buf);
80 ext2fs_free_mem((void **) &buf);