2 * dirblock.c --- directory block routines.
4 * Copyright (C) 1995 Theodore Ts'o. This file may be redistributed
5 * under the terms of the GNU Public License.
16 #include <linux/ext2_fs.h>
20 errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
25 struct ext2_dir_entry *dirent;
27 retval = io_channel_read_blk(fs->io, block, 1, buf);
30 if ((fs->flags & EXT2_SWAP_BYTES) == 0)
33 end = (char *) buf + fs->blocksize;
35 dirent = (struct ext2_dir_entry *) p;
36 dirent->inode = ext2fs_swab32(dirent->inode);
37 dirent->rec_len = ext2fs_swab16(dirent->rec_len);
38 dirent->name_len = ext2fs_swab16(dirent->name_len);
39 p += (dirent->rec_len < 8) ? 8 : dirent->rec_len;
44 errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
48 char *p, *end, *write_buf;
50 struct ext2_dir_entry *dirent;
52 if (fs->flags & EXT2_SWAP_BYTES) {
53 write_buf = buf = malloc(fs->blocksize);
56 memcpy(buf, inbuf, fs->blocksize);
58 end = buf + fs->blocksize;
60 dirent = (struct ext2_dir_entry *) p;
61 p += (dirent->rec_len < 8) ? 8 : dirent->rec_len;
62 dirent->inode = ext2fs_swab32(dirent->inode);
63 dirent->rec_len = ext2fs_swab16(dirent->rec_len);
64 dirent->name_len = ext2fs_swab16(dirent->name_len);
68 retval = io_channel_write_blk(fs->io, block, 1, write_buf);