1 /* 2 * ind_block.c --- indirect block I/O routines 3 * 4 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 5 * 2001, 2002, 2003, 2004, 2005 by Theodore Ts'o. 6 * 7 * %Begin-Header% 8 * This file may be redistributed under the terms of the GNU Library 9 * General Public License, version 2. 10 * %End-Header% 11 */ 12 13 #include "config.h" 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 23 errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf) 24 { 25 errcode_t retval; 26 #ifdef WORDS_BIGENDIAN 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 #ifdef WORDS_BIGENDIAN 41 block_nr = (blk_t *) buf; 42 for (i = 0; i < limit; i++, block_nr++) 43 *block_nr = ext2fs_swab32(*block_nr); 44 #endif 45 return 0; 46 } 47 48 errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf) 49 { 50 #ifdef WORDS_BIGENDIAN 51 blk_t *block_nr; 52 int i; 53 int limit = fs->blocksize >> 2; 54 #endif 55 56 if (fs->flags & EXT2_FLAG_IMAGE_FILE) 57 return 0; 58 59 #ifdef WORDS_BIGENDIAN 60 block_nr = (blk_t *) buf; 61 for (i = 0; i < limit; i++, block_nr++) 62 *block_nr = ext2fs_swab32(*block_nr); 63 #endif 64 return io_channel_write_blk(fs->io, blk, 1, buf); 65 } 66 67