blob: 9baa37f586a7b8741d625883c6f09708f6c2455e [file] [log] [blame]
Theodore Ts'odc8ce342005-01-06 00:04:24 -05001/*
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
22errcode_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)
Theodore Ts'ob1ae1192005-04-09 01:21:21 -040035 return retval;
Theodore Ts'odc8ce342005-01-06 00:04:24 -050036 }
Theodore Ts'o126a2912007-08-11 01:56:48 -040037#ifdef WORDS_BIGENDIAN
38 block_nr = (blk_t *) buf;
39 for (i = 0; i < limit; i++, block_nr++)
40 *block_nr = ext2fs_swab32(*block_nr);
Theodore Ts'odc8ce342005-01-06 00:04:24 -050041#endif
42 return 0;
43}
44
45errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf)
46{
47 blk_t *block_nr;
48 int i;
49 int limit = fs->blocksize >> 2;
50
51 if (fs->flags & EXT2_FLAG_IMAGE_FILE)
52 return 0;
53
Theodore Ts'o126a2912007-08-11 01:56:48 -040054#ifdef WORDS_BIGENDIAN
55 block_nr = (blk_t *) buf;
56 for (i = 0; i < limit; i++, block_nr++)
57 *block_nr = ext2fs_swab32(*block_nr);
Theodore Ts'odc8ce342005-01-06 00:04:24 -050058#endif
59 return io_channel_write_blk(fs->io, blk, 1, buf);
60}
61
62