"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame^] | 1 | /* vi: set sw=4 ts=4: */ |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 2 | /* |
| 3 | * ind_block.c --- indirect block I/O routines |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
| 6 | * 2001, 2002, 2003, 2004, 2005 by Theodore Ts'o. |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 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 | |
| 23 | errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf) |
| 24 | { |
| 25 | errcode_t retval; |
Rob Landley | 7c94bed | 2006-05-03 21:58:45 +0000 | [diff] [blame] | 26 | #if BB_BIG_ENDIAN |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 27 | blk_t *block_nr; |
| 28 | int i; |
| 29 | int limit = fs->blocksize >> 2; |
Mike Frysinger | 0301ffa | 2005-06-11 00:11:37 +0000 | [diff] [blame] | 30 | #endif |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 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 | } |
Rob Landley | 7c94bed | 2006-05-03 21:58:45 +0000 | [diff] [blame] | 40 | #if BB_BIG_ENDIAN |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 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 | |
| 50 | errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf) |
| 51 | { |
Rob Landley | 7c94bed | 2006-05-03 21:58:45 +0000 | [diff] [blame] | 52 | #if BB_BIG_ENDIAN |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 53 | blk_t *block_nr; |
| 54 | int i; |
| 55 | int limit = fs->blocksize >> 2; |
Mike Frysinger | 0301ffa | 2005-06-11 00:11:37 +0000 | [diff] [blame] | 56 | #endif |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 57 | |
| 58 | if (fs->flags & EXT2_FLAG_IMAGE_FILE) |
| 59 | return 0; |
| 60 | |
Rob Landley | 7c94bed | 2006-05-03 21:58:45 +0000 | [diff] [blame] | 61 | #if BB_BIG_ENDIAN |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 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 | |