Home | History | Annotate | Download | only in ext2fs
      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 Public
      9  * License.
     10  * %End-Header%
     11  */
     12 
     13 #include <stdio.h>
     14 #include <string.h>
     15 #if HAVE_UNISTD_H
     16 #include <unistd.h>
     17 #endif
     18 
     19 #include "ext2_fs.h"
     20 #include "ext2fs.h"
     21 
     22 errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf)
     23 {
     24 	errcode_t	retval;
     25 	blk_t		*block_nr;
     26 	int		i;
     27 	int		limit = fs->blocksize >> 2;
     28 
     29 	if ((fs->flags & EXT2_FLAG_IMAGE_FILE) &&
     30 	    (fs->io != fs->image_io))
     31 		memset(buf, 0, fs->blocksize);
     32 	else {
     33 		retval = io_channel_read_blk(fs->io, blk, 1, buf);
     34 		if (retval)
     35 			return retval;
     36 	}
     37 #ifdef EXT2FS_ENABLE_SWAPFS
     38 	if (fs->flags & (EXT2_FLAG_SWAP_BYTES | EXT2_FLAG_SWAP_BYTES_READ)) {
     39 		block_nr = (blk_t *) buf;
     40 		for (i = 0; i < limit; i++, block_nr++)
     41 			*block_nr = ext2fs_swab32(*block_nr);
     42 	}
     43 #endif
     44 	return 0;
     45 }
     46 
     47 errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf)
     48 {
     49 	blk_t		*block_nr;
     50 	int		i;
     51 	int		limit = fs->blocksize >> 2;
     52 
     53 	if (fs->flags & EXT2_FLAG_IMAGE_FILE)
     54 		return 0;
     55 
     56 #ifdef EXT2FS_ENABLE_SWAPFS
     57 	if (fs->flags & (EXT2_FLAG_SWAP_BYTES | EXT2_FLAG_SWAP_BYTES_WRITE)) {
     58 		block_nr = (blk_t *) buf;
     59 		for (i = 0; i < limit; i++, block_nr++)
     60 			*block_nr = ext2fs_swab32(*block_nr);
     61 	}
     62 #endif
     63 	return io_channel_write_blk(fs->io, blk, 1, buf);
     64 }
     65 
     66 
     67