1 /* vi: set sw=4 ts=4: */
3 * ind_block.c --- indirect block I/O routines
5 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
6 * 2001, 2002, 2003, 2004, 2005 by Theodore Ts'o.
9 * This file may be redistributed under the terms of the GNU Public
23 errcode_t
ext2fs_read_ind_block(ext2_filsys fs
, blk_t blk
, void *buf
)
29 int limit
= fs
->blocksize
>> 2;
32 if ((fs
->flags
& EXT2_FLAG_IMAGE_FILE
) &&
33 (fs
->io
!= fs
->image_io
))
34 memset(buf
, 0, fs
->blocksize
);
36 retval
= io_channel_read_blk(fs
->io
, blk
, 1, buf
);
41 if (fs
->flags
& (EXT2_FLAG_SWAP_BYTES
| EXT2_FLAG_SWAP_BYTES_READ
)) {
42 block_nr
= (blk_t
*) buf
;
43 for (i
= 0; i
< limit
; i
++, block_nr
++)
44 *block_nr
= ext2fs_swab32(*block_nr
);
50 errcode_t
ext2fs_write_ind_block(ext2_filsys fs
, blk_t blk
, void *buf
)
55 int limit
= fs
->blocksize
>> 2;
58 if (fs
->flags
& EXT2_FLAG_IMAGE_FILE
)
62 if (fs
->flags
& (EXT2_FLAG_SWAP_BYTES
| EXT2_FLAG_SWAP_BYTES_WRITE
)) {
63 block_nr
= (blk_t
*) buf
;
64 for (i
= 0; i
< limit
; i
++, block_nr
++)
65 *block_nr
= ext2fs_swab32(*block_nr
);
68 return io_channel_write_blk(fs
->io
, blk
, 1, buf
);