#if HAVE_UNISTD_H
#include <unistd.h>
#endif
-#include <stdlib.h>
#include <fcntl.h>
#include <time.h>
+#if HAVE_SYS_STAT_H
#include <sys/stat.h>
+#endif
+#if HAVE_SYS_TYPES_H
#include <sys/types.h>
-#if HAVE_ERRNO_H
-#include <errno.h>
#endif
-#include "et/com_err.h"
-#include "ext2fs/ext2_err.h"
-#include "io.h"
+#if EXT2_FLAT_INCLUDES
+#include "ext2_fs.h"
+#else
+#include <linux/ext2_fs.h>
+#endif
+
+#include "ext2fs.h"
/*
* For checking structure magic numbers...
if (name == 0)
return EXT2_ET_BAD_DEVICE_NAME;
- io = (io_channel) malloc(sizeof(struct struct_io_channel));
- if (!io)
- return ENOMEM;
+ retval = ext2fs_get_mem(sizeof(struct struct_io_channel),
+ (void **) &io);
+ if (retval)
+ return retval;
memset(io, 0, sizeof(struct struct_io_channel));
io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
- data = (struct test_private_data *)
- malloc(sizeof(struct test_private_data));
- if (!data) {
- retval = ENOMEM;
+ retval = ext2fs_get_mem(sizeof(struct test_private_data),
+ (void **) &data);
+ if (retval) {
+ retval = EXT2_ET_NO_MEMORY;
goto cleanup;
}
io->manager = test_io_manager;
- io->name = malloc(strlen(name)+1);
- if (!io->name) {
- retval = ENOMEM;
+ retval = ext2fs_get_mem(strlen(name)+1, (void **) &io->name);
+ if (retval)
goto cleanup;
- }
+
strcpy(io->name, name);
io->private_data = data;
io->block_size = 1024;
cleanup:
if (io)
- free(io);
+ ext2fs_free_mem((void **) &io);
if (data)
- free(data);
+ ext2fs_free_mem((void **) &data);
return retval;
}
retval = io_channel_close(data->real);
if (channel->private_data)
- free(channel->private_data);
+ ext2fs_free_mem((void **) &channel->private_data);
if (channel->name)
- free(channel->name);
- free(channel);
+ ext2fs_free_mem((void **) &channel->name);
+ ext2fs_free_mem((void **) &channel);
return retval;
}
static errcode_t test_flush(io_channel channel)
{
struct test_private_data *data;
+ errcode_t retval = 0;
EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
data = (struct test_private_data *) channel->private_data;
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
if (data->real)
- return io_channel_flush(data->real);
- return 0;
+ retval = io_channel_flush(data->real);
+
+ printf("Test_io: flush() returned %s\n",
+ retval ? error_message(retval) : "OK");
+
+ return retval;
}