1/* vi: set sw=4 ts=4: */ 2/* 3 * ind_block.c --- indirect block I/O routines 4 * 5 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 6 * 2001, 2002, 2003, 2004, 2005 by Theodore Ts'o. 7 * 8 * %Begin-Header% 9 * This file may be redistributed under the terms of the GNU Public 10 * License. 11 * %End-Header% 12 */ 13 14#include <stdio.h> 15#include <string.h> 16#if HAVE_UNISTD_H 17#include <unistd.h> 18#endif 19 20#include "ext2_fs.h" 21#include "ext2fs.h" 22 23errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf) 24{ 25 errcode_t retval; 26#if BB_BIG_ENDIAN 27 blk_t *block_nr; 28 int i; 29 int limit = fs->blocksize >> 2; 30#endif 31 32 if ((fs->flags & EXT2_FLAG_IMAGE_FILE) && 33 (fs->io != fs->image_io)) 34 memset(buf, 0, fs->blocksize); 35 else { 36 retval = io_channel_read_blk(fs->io, blk, 1, buf); 37 if (retval) 38 return retval; 39 } 40#if BB_BIG_ENDIAN 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); 45 } 46#endif 47 return 0; 48} 49 50errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf) 51{ 52#if BB_BIG_ENDIAN 53 blk_t *block_nr; 54 int i; 55 int limit = fs->blocksize >> 2; 56#endif 57 58 if (fs->flags & EXT2_FLAG_IMAGE_FILE) 59 return 0; 60 61#if BB_BIG_ENDIAN 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); 66 } 67#endif 68 return io_channel_write_blk(fs->io, blk, 1, buf); 69} 70 71 72