summaryrefslogtreecommitdiff
path: root/e2fsprogs/ext2fs/ind_block.c
diff options
context:
space:
mode:
authorMike Frysinger2005-05-09 22:10:42 +0000
committerMike Frysinger2005-05-09 22:10:42 +0000
commit1fd98e039d146dcff02a5350f509cabca65fd29c (patch)
tree1564707d41a6271bb44cf3fa5b88b9cc70fedd35 /e2fsprogs/ext2fs/ind_block.c
parentb32011943a0764872ca1ea17f13b53176ace8e69 (diff)
downloadbusybox-1fd98e039d146dcff02a5350f509cabca65fd29c.zip
busybox-1fd98e039d146dcff02a5350f509cabca65fd29c.tar.gz
import ext2fs lib to prep for new e2fsprogs
Diffstat (limited to 'e2fsprogs/ext2fs/ind_block.c')
-rw-r--r--e2fsprogs/ext2fs/ind_block.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/e2fsprogs/ext2fs/ind_block.c b/e2fsprogs/ext2fs/ind_block.c
new file mode 100644
index 0000000..3519048
--- /dev/null
+++ b/e2fsprogs/ext2fs/ind_block.c
@@ -0,0 +1,66 @@
+/*
+ * ind_block.c --- indirect block I/O routines
+ *
+ * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+ * 2001, 2002, 2003, 2004, 2005 by Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ * %End-Header%
+ */
+
+#include <stdio.h>
+#include <string.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "ext2_fs.h"
+#include "ext2fs.h"
+
+errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf)
+{
+ errcode_t retval;
+ blk_t *block_nr;
+ int i;
+ int limit = fs->blocksize >> 2;
+
+ if ((fs->flags & EXT2_FLAG_IMAGE_FILE) &&
+ (fs->io != fs->image_io))
+ memset(buf, 0, fs->blocksize);
+ else {
+ retval = io_channel_read_blk(fs->io, blk, 1, buf);
+ if (retval)
+ return retval;
+ }
+#ifdef EXT2FS_ENABLE_SWAPFS
+ if (fs->flags & (EXT2_FLAG_SWAP_BYTES | EXT2_FLAG_SWAP_BYTES_READ)) {
+ block_nr = (blk_t *) buf;
+ for (i = 0; i < limit; i++, block_nr++)
+ *block_nr = ext2fs_swab32(*block_nr);
+ }
+#endif
+ return 0;
+}
+
+errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf)
+{
+ blk_t *block_nr;
+ int i;
+ int limit = fs->blocksize >> 2;
+
+ if (fs->flags & EXT2_FLAG_IMAGE_FILE)
+ return 0;
+
+#ifdef EXT2FS_ENABLE_SWAPFS
+ if (fs->flags & (EXT2_FLAG_SWAP_BYTES | EXT2_FLAG_SWAP_BYTES_WRITE)) {
+ block_nr = (blk_t *) buf;
+ for (i = 0; i < limit; i++, block_nr++)
+ *block_nr = ext2fs_swab32(*block_nr);
+ }
+#endif
+ return io_channel_write_blk(fs->io, blk, 1, buf);
+}
+
+