[EXT2LIB]
[reactos.git] / reactos / lib / fslib / ext2lib / Mke2fs.c
index 6c64bc6..6477408 100644 (file)
@@ -8,6 +8,8 @@
 /* INCLUDES **************************************************************/
 
 #include "Mke2fs.h"
+
+#include <fmifs/fmifs.h>
 #include <debug.h>
 
 /* GLOBALS ***************************************************************/
@@ -16,6 +18,9 @@ int     inode_ratio = 4096;
 
 BOOLEAN bLocked = FALSE;
 
+/* This is needed for the ext2fs driver to mount the volume */
+#define ZAP_BOOTBLOCK
+
 /* FUNCTIONS *************************************************************/
 
 int int_log2(int arg)
@@ -117,7 +122,7 @@ void set_fs_defaults(const char *fs_type,
 bool zero_blocks(PEXT2_FILESYS fs, ULONG blk, ULONG num,
                  ULONG *ret_blk, ULONG *ret_count)
 {
-    ULONG       j, count, next_update, next_update_incr;
+    ULONG       j, count;
     static unsigned char        *buf;
     bool        retval;
 
@@ -150,11 +155,6 @@ bool zero_blocks(PEXT2_FILESYS fs, ULONG blk, ULONG num,
     }
 
     /* OK, do the write loop */
-    next_update = 0;
-    next_update_incr = num / 100;
-    if (next_update_incr < 1)
-        next_update_incr = 1;
-
     for (j=0; j < num; j += STRIDE_LENGTH, blk += STRIDE_LENGTH)
     {
         if (num-j > STRIDE_LENGTH)
@@ -197,8 +197,6 @@ bool zap_sector(PEXT2_FILESYS Ext2Sys, int sect, int nsect)
                 sect, sect + nsect - 1);
         return false;
     }
-
-    memset(buf, 0, (ULONG)nsect * SECTOR_SIZE);
     
 #define BSD_DISKMAGIC   (0x82564557UL)  /* The disk magic number */
 #define BSD_MAGICDISK   (0x57455682UL)  /* The disk magic number reversed */
@@ -217,6 +215,8 @@ bool zap_sector(PEXT2_FILESYS Ext2Sys, int sect, int nsect)
                 goto clean_up;
     }
 
+    memset(buf, 0, (ULONG)nsect * SECTOR_SIZE);
+
     // Write buf to disk
     Ext2WriteDisk( Ext2Sys,
                    (LONGLONG)(sect * SECTOR_SIZE),
@@ -820,7 +820,10 @@ Ext2Format(IN PUNICODE_STRING DriveRoot,
     ULONG ret_blk;
 
 
-    Callback(PROGRESS, 0, (PVOID)&Percent);
+    if (Callback != NULL)
+    {
+        Callback(PROGRESS, 0, (PVOID)&Percent);
+    }
 
 
     RtlZeroMemory(&Ext2Sb, sizeof(EXT2_SUPER_BLOCK));
@@ -925,6 +928,7 @@ Ext2Format(IN PUNICODE_STRING DriveRoot,
     blocks = Ext2Sb.s_blocks_count;
 
 #ifdef ZAP_BOOTBLOCK
+    DPRINT1("Mke2fs: zeroing volume boot record\n");
     zap_sector(&FileSys, 0, 2);
 #endif
 
@@ -997,7 +1001,10 @@ clean_up:
 
     Ext2CloseDevice(&FileSys);
 
-    Callback(DONE, 0, (PVOID)&bRet);
+    if (Callback != NULL)
+    {
+        Callback(DONE, 0, (PVOID)&bRet);
+    }
 
     return Status;
 }