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 <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#ifdef WORDS_BIGENDIAN
26	blk_t		*block_nr;
27	int		i;
28	int		limit = fs->blocksize >> 2;
29#endif
30
31	if ((fs->flags & EXT2_FLAG_IMAGE_FILE) &&
32	    (fs->io != fs->image_io))
33		memset(buf, 0, fs->blocksize);
34	else {
35		retval = io_channel_read_blk(fs->io, blk, 1, buf);
36		if (retval)
37			return retval;
38	}
39#ifdef WORDS_BIGENDIAN
40	block_nr = (blk_t *) buf;
41	for (i = 0; i < limit; i++, block_nr++)
42		*block_nr = ext2fs_swab32(*block_nr);
43#endif
44	return 0;
45}
46
47errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf)
48{
49#ifdef WORDS_BIGENDIAN
50	blk_t		*block_nr;
51	int		i;
52	int		limit = fs->blocksize >> 2;
53#endif
54
55	if (fs->flags & EXT2_FLAG_IMAGE_FILE)
56		return 0;
57
58#ifdef WORDS_BIGENDIAN
59	block_nr = (blk_t *) buf;
60	for (i = 0; i < limit; i++, block_nr++)
61		*block_nr = ext2fs_swab32(*block_nr);
62#endif
63	return io_channel_write_blk(fs->io, blk, 1, buf);
64}
65
66
67