Whamcloud - gitweb
libext2fs: find/alloc a range of empty blocks
[tools/e2fsprogs.git] / lib / ext2fs / dosio.c
index b1d7971..d0cf269 100644 (file)
@@ -2,23 +2,26 @@
  * dosio.c -- Disk I/O module for the ext2fs/DOS library.
  *
  * Copyright (c) 1997 by Theodore Ts'o.
- * 
+ *
  * Copyright (c) 1997 Mark Habersack
- * This file may be distributed under the terms of the GNU Public License.
  *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
+ * %End-Header%
  */
 
+#include "config.h"
 #include <stdio.h>
 #include <bios.h>
 #include <string.h>
-#include <stdlib.h>
 #include <ctype.h>
 #include <io.h>
 #ifdef HAVE_ERRNO_H
 #include <errno.h>
 #endif
 
-#include <linux/types.h>
+#include <ext2fs/ext2_types.h>
 #include "utils.h"
 #include "dosio.h"
 #include "et/com_err.h"
@@ -59,15 +62,16 @@ static errcode_t dos_write_blk(io_channel channel, unsigned long block,
 static errcode_t dos_flush(io_channel channel);
 
 static struct struct_io_manager struct_dos_manager = {
-        EXT2_ET_MAGIC_IO_MANAGER,
-        "DOS I/O Manager",
-        dos_open,
-        dos_close,
-        dos_set_blksize,
-        dos_read_blk,
-        dos_write_blk,
-        dos_flush
+       .magic          = EXT2_ET_MAGIC_IO_MANAGER,
+       .name           = "DOS I/O Manager",
+       .open           = dos_open,
+       .close          = dos_close,
+       .set_blksize    = dos_set_blksize,
+       .read_blk       = dos_read_blk,
+       .write_blk      = dos_write_blk,
+       .flush          = dos_flush
 };
+
 io_manager dos_io_manager = &struct_dos_manager;
 
 /*
@@ -180,7 +184,7 @@ static errcode_t dos_open(const char *dev, int flags, io_channel *channel)
   PARTITION      *part;
   PTABLE_ENTRY   *pent;
   PARTITION        **newparts;
-  
+
   if(!dev)
   {
     _dio_error = ERR_BADDEV;
@@ -279,8 +283,8 @@ static errcode_t dos_open(const char *dev, int flags, io_channel *channel)
   if(!HW_OK())
   {
     _dio_error = ERR_HARDWARE;
-    if (part)
-           free(part);
+    free(part->dev);
+    free(part);
     return EFAULT;
   }
 
@@ -299,8 +303,8 @@ static errcode_t dos_open(const char *dev, int flags, io_channel *channel)
   if(!HW_OK())
   {
     _dio_error = ERR_HARDWARE;
-    if (part)
-           free(part);
+    free(part->dev);
+    free(part);
     return EFAULT;
   }
 
@@ -311,8 +315,8 @@ static errcode_t dos_open(const char *dev, int flags, io_channel *channel)
   {
     _dio_error = part->pno == 0xFE ? ERR_EMPTYPART :
                  part->pno == 0xFD ? ERR_LINUXSWAP : ERR_NOTEXT2FS;
-    if (part)
-           free(part);
+    free(part->dev);
+    free(part);
     return ENODEV;
   }
 
@@ -353,10 +357,8 @@ static errcode_t dos_open(const char *dev, int flags, io_channel *channel)
 
 static errcode_t dos_close(io_channel channel)
 {
-       if (channel->name)
-               free(channel->name);
-       if (channel)
-               free(channel);
+       free(channel->name);
+       free(channel);
 
        return 0;
 }