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
20 #include <linux/ext2_fs.h>
24 errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
29 struct ext2_dir_entry *dirent;
31 retval = io_channel_read_blk(fs->io, block, 1, buf);
34 if ((fs->flags & (EXT2_FLAG_SWAP_BYTES|
35 EXT2_FLAG_SWAP_BYTES_READ)) == 0)
38 end = (char *) buf + fs->blocksize;
40 dirent = (struct ext2_dir_entry *) p;
41 dirent->inode = ext2fs_swab32(dirent->inode);
42 dirent->rec_len = ext2fs_swab16(dirent->rec_len);
43 dirent->name_len = ext2fs_swab16(dirent->name_len);
44 p += (dirent->rec_len < 8) ? 8 : dirent->rec_len;
49 errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
53 char *p, *end, *write_buf;
55 struct ext2_dir_entry *dirent;
57 if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
58 (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)) {
59 write_buf = buf = malloc(fs->blocksize);
61 return EXT2_NO_MEMORY;
62 memcpy(buf, inbuf, fs->blocksize);
64 end = buf + fs->blocksize;
66 dirent = (struct ext2_dir_entry *) p;
67 p += (dirent->rec_len < 8) ? 8 : dirent->rec_len;
68 dirent->inode = ext2fs_swab32(dirent->inode);
69 dirent->rec_len = ext2fs_swab16(dirent->rec_len);
70 dirent->name_len = ext2fs_swab16(dirent->name_len);
74 retval = io_channel_write_blk(fs->io, block, 1, write_buf);