2 * ind_block.c --- indirect block I/O routines
4 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
5 * 2001, 2002, 2003, 2004, 2005 by Theodore Ts'o.
8 * This file may be redistributed under the terms of the GNU Public
22 errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf)
25 #ifdef EXT2FS_ENABLE_SWAPFS
28 int limit = fs->blocksize >> 2;
31 if ((fs->flags & EXT2_FLAG_IMAGE_FILE) &&
32 (fs->io != fs->image_io))
33 memset(buf, 0, fs->blocksize);
35 retval = io_channel_read_blk(fs->io, blk, 1, buf);
39 #ifdef EXT2FS_ENABLE_SWAPFS
40 if (fs->flags & (EXT2_FLAG_SWAP_BYTES | EXT2_FLAG_SWAP_BYTES_READ)) {
41 block_nr = (blk_t *) buf;
42 for (i = 0; i < limit; i++, block_nr++)
43 *block_nr = ext2fs_swab32(*block_nr);
49 errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf)
51 #ifdef EXT2FS_ENABLE_SWAPFS
54 int limit = fs->blocksize >> 2;
57 if (fs->flags & EXT2_FLAG_IMAGE_FILE)
60 #ifdef EXT2FS_ENABLE_SWAPFS
61 if (fs->flags & (EXT2_FLAG_SWAP_BYTES | EXT2_FLAG_SWAP_BYTES_WRITE)) {
62 block_nr = (blk_t *) buf;
63 for (i = 0; i < limit; i++, block_nr++)
64 *block_nr = ext2fs_swab32(*block_nr);
67 return io_channel_write_blk(fs->io, blk, 1, buf);