Whamcloud - gitweb
ChangeLog, openfs.c:
[tools/e2fsprogs.git] / lib / ext2fs / test_io.c
index 65c4d10..10cf3a5 100644 (file)
 #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...
@@ -84,23 +88,23 @@ static errcode_t test_open(const char *name, int flags, io_channel *channel)
 
        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;
@@ -126,9 +130,9 @@ static errcode_t test_open(const char *name, int flags, io_channel *channel)
 
 cleanup:
        if (io)
-               free(io);
+               ext2fs_free_mem((void **) &io);
        if (data)
-               free(data);
+               ext2fs_free_mem((void **) &data);
        return retval;
 }
 
@@ -148,10 +152,10 @@ static errcode_t test_close(io_channel channel)
                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;
 }
 
@@ -221,13 +225,18 @@ static errcode_t test_write_blk(io_channel channel, unsigned long block,
 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;
 }