Commit in reactos/drivers/fs/vfat on MAIN
fsctl.c+94-391.29 -> 1.30
vfat.h+5-51.61 -> 1.62
+99-44
2 modified files
- Fixed checking for a FAT file system on a removable media.  
- Check more exactly for a FAT file system.

reactos/drivers/fs/vfat
fsctl.c 1.29 -> 1.30
diff -u -r1.29 -r1.30
--- fsctl.c	31 Mar 2004 03:30:36 -0000	1.29
+++ fsctl.c	2 May 2004 20:16:45 -0000	1.30
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: fsctl.c,v 1.29 2004/03/31 03:30:36 jimtabor Exp $
+/* $Id: fsctl.c,v 1.30 2004/05/02 20:16:45 hbirr Exp $
  *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
@@ -55,6 +55,9 @@
    ULONG Sectors;
    LARGE_INTEGER Offset;
    struct _BootSector* Boot;
+   BOOL PartitionInfoIsValid = FALSE;
+
+   DPRINT("VfatHasFileSystem\n");
 
    *RecognizedFS = FALSE;
 
@@ -66,15 +69,12 @@
 				     &DiskGeometry,
 				     &Size,
 				     FALSE);
-  DPRINT("VfatHasFileSystem start\n");
-  
-
    if (!NT_SUCCESS(Status))
    {
       DPRINT("VfatBlockDeviceIoControl faild (%x)\n", Status);
       return Status;
    }
-   if (DiskGeometry.MediaType == FixedMedia || RemovableMedia)
+   if (DiskGeometry.MediaType == FixedMedia || DiskGeometry.MediaType == RemovableMedia)
    {
       // We have found a hard disk
       Size = sizeof(PARTITION_INFORMATION);
@@ -90,7 +90,8 @@
          DPRINT("VfatBlockDeviceIoControl faild (%x)\n", Status);
          return Status;
       }
-/*#ifndef NDEBUG*/
+      PartitionInfoIsValid = TRUE;
+#if defined(DBG) && !defined(NDEBUG)
       DbgPrint("Partition Information:\n");
       DbgPrint("StartingOffset      %u\n", PartitionInfo.StartingOffset.QuadPart  / 512);
       DbgPrint("PartitionLength     %u\n", PartitionInfo.PartitionLength.QuadPart / 512);
@@ -100,18 +101,29 @@
       DbgPrint("BootIndicator       %u\n", PartitionInfo.BootIndicator);
       DbgPrint("RecognizedPartition %u\n", PartitionInfo.RecognizedPartition);
       DbgPrint("RewritePartition    %u\n", PartitionInfo.RewritePartition);
-/*#endif*/
-      if (PartitionInfo.PartitionType == PARTITION_FAT_12       ||
-          PartitionInfo.PartitionType == PARTITION_FAT_16       ||
-          PartitionInfo.PartitionType == PARTITION_HUGE         ||
-          PartitionInfo.PartitionType == PARTITION_FAT32        ||
-          PartitionInfo.PartitionType == PARTITION_FAT32_XINT13 ||
-          PartitionInfo.PartitionType == PARTITION_XINT13)
+#endif
+      if (PartitionInfo.PartitionType)
       {
+         if (PartitionInfo.PartitionType == PARTITION_FAT_12       ||
+             PartitionInfo.PartitionType == PARTITION_FAT_16       ||
+             PartitionInfo.PartitionType == PARTITION_HUGE         ||
+             PartitionInfo.PartitionType == PARTITION_FAT32        ||
+             PartitionInfo.PartitionType == PARTITION_FAT32_XINT13 ||
+             PartitionInfo.PartitionType == PARTITION_XINT13)
+         {
+            *RecognizedFS = TRUE;
+         }
+      }
+      else if (DiskGeometry.MediaType == RemovableMedia &&
+               PartitionInfo.PartitionNumber > 0 &&
+               PartitionInfo.StartingOffset.QuadPart == 0LL &&
+               PartitionInfo.PartitionLength.QuadPart > 0LL)
+      {
+         /* This is possible a removable media formated as super floppy */
          *RecognizedFS = TRUE;
       }
    }
-   else if (DiskGeometry.MediaType > Unknown && DiskGeometry.MediaType <= RemovableMedia )
+   if (DiskGeometry.MediaType > Unknown && DiskGeometry.MediaType < RemovableMedia )
    {
       *RecognizedFS = TRUE;
    }
@@ -123,8 +135,6 @@
    Boot = ExAllocatePool(NonPagedPool, DiskGeometry.BytesPerSector);
    if (Boot == NULL)
    {
-  DPRINT("VfatHasFileSystem 1\n");
-
       *RecognizedFS=FALSE;
       return STATUS_INSUFFICIENT_RESOURCES;
    }
@@ -134,9 +144,66 @@
    Status = VfatReadDisk(DeviceToMount, &Offset, DiskGeometry.BytesPerSector, (PUCHAR) Boot, FALSE);
    if (NT_SUCCESS(Status))
    {
-      DPRINT("VfatHasFileSystem 2\n");
+      if (Boot->Signatur1 != 0xaa55)
+      {
+         DPRINT1("Signature %04x\n", Boot->Signatur1);
+         *RecognizedFS=FALSE;
+      }
+      if (*RecognizedFS &&
+	  Boot->BytesPerSector != 512 &&
+	  Boot->BytesPerSector != 1024 &&
+          Boot->BytesPerSector != 2048 && 
+	  Boot->BytesPerSector == 4096)
+      {
+         DPRINT1("BytesPerSector %d\n", Boot->BytesPerSector);
+         *RecognizedFS=FALSE;
+      }
+
+      if (*RecognizedFS &&
+          Boot->FATCount != 1 && 
+	  Boot->FATCount != 2)
+      {
+         DPRINT1("FATCount %d\n", Boot->FATCount);
+         *RecognizedFS=FALSE;
+      }
+
+      if (*RecognizedFS &&
+          Boot->Media != 0xf0 && 
+	  Boot->Media != 0xf8 &&
+	  Boot->Media != 0xf9 &&
+	  Boot->Media != 0xfa && 
+	  Boot->Media != 0xfb &&
+	  Boot->Media != 0xfc &&
+	  Boot->Media != 0xfd &&
+	  Boot->Media != 0xfe && 
+	  Boot->Media != 0xff)
+      {
+         DPRINT1("Media             %02x\n", Boot->Media);
+         *RecognizedFS=FALSE;
+      }
 
-      if (Boot->BytesPerSector != 0)
+      if (*RecognizedFS &&
+	  Boot->SectorsPerCluster != 1 &&
+	  Boot->SectorsPerCluster != 2 &&
+          Boot->SectorsPerCluster != 4 && 
+	  Boot->SectorsPerCluster != 8 &&
+          Boot->SectorsPerCluster != 16 &&
+	  Boot->SectorsPerCluster != 32 && 
+          Boot->SectorsPerCluster != 64 &&
+	  Boot->SectorsPerCluster != 128)
+      {
+         DPRINT1("SectorsPerCluster %02x\n", Boot->SectorsPerCluster);
+         *RecognizedFS=FALSE;
+      }
+
+      if (*RecognizedFS &&
+          Boot->BytesPerSector * Boot->SectorsPerCluster > 32 * 1024)
+      {
+         DPRINT1("ClusterSize %dx\n", Boot->BytesPerSector * Boot->SectorsPerCluster);
+         *RecognizedFS=FALSE;
+      }
+
+      if (*RecognizedFS)
       {
          FatInfo.VolumeID = Boot->VolumeID;
          FatInfo.FATStart = Boot->ReservedSectors;
@@ -169,21 +236,22 @@
             DPRINT("FAT16\n");
             FatInfo.FatType = FAT16;
          }
-         if (pFatInfo)
+	 if (PartitionInfoIsValid &&
+	     FatInfo.Sectors > PartitionInfo.PartitionLength.QuadPart / FatInfo.BytesPerSector)
+	 {
+	    CHECKPOINT1;
+	    *RecognizedFS = FALSE;
+	 }
+	    
+         if (pFatInfo && *RecognizedFS)
          {
             *pFatInfo = FatInfo;
          }
       }
-      else
-      {
-        DPRINT("VfatHasFileSystem 3\n");
-
-      	Status = STATUS_INSUFFICIENT_RESOURCES;
-      }
    }
-     DPRINT("VfatHasFileSystem end\n");
 
    ExFreePool(Boot);
+   DPRINT("VfatHasFileSystem done\n");
    return Status;
 }
 
@@ -206,19 +274,6 @@
    }
    DPRINT("MountVfatdev %d, PAGE_SIZE = %d\n", DeviceExt->FatInfo.BytesPerCluster, PAGE_SIZE);
 
-   if (DeviceExt->FatInfo.BytesPerCluster >= PAGE_SIZE &&
-      (DeviceExt->FatInfo.BytesPerCluster % PAGE_SIZE) != 0)
-   {
-      DbgPrint("(%s:%d) Invalid cluster size\n", __FILE__, __LINE__);
-      KEBUGCHECK(0);
-   }
-   else if (DeviceExt->FatInfo.BytesPerCluster < PAGE_SIZE &&
-      (PAGE_SIZE % DeviceExt->FatInfo.BytesPerCluster) != 0)
-   {
-      DbgPrint("(%s:%d) Invalid cluster size2\n", __FILE__, __LINE__);
-      KEBUGCHECK(0);
-   }
-
    return(STATUS_SUCCESS);
 }
 

reactos/drivers/fs/vfat
vfat.h 1.61 -> 1.62
diff -u -r1.61 -r1.62
--- vfat.h	12 Nov 2003 15:26:44 -0000	1.61
+++ vfat.h	2 May 2004 20:16:46 -0000	1.62
@@ -1,4 +1,4 @@
-/* $Id: vfat.h,v 1.61 2003/11/12 15:26:44 ekohl Exp $ */
+/* $Id: vfat.h,v 1.62 2004/05/02 20:16:46 hbirr Exp $ */
 
 #include <ddk/ntifs.h>
 
@@ -20,8 +20,8 @@
   unsigned char  Drive, Res1, Sig;
   unsigned long  VolumeID;
   unsigned char  VolumeLabel[11], SysType[8];
-  unsigned char  Res2[446];
-  unsigned long  Signatur1;
+  unsigned char  Res2[448];
+  unsigned short Signatur1;
 } __attribute__((packed));
 
 struct _BootSector32
@@ -48,8 +48,8 @@
   unsigned char  ExtBootSignature;			// 66
   unsigned long  VolumeID;				// 67
   unsigned char  VolumeLabel[11], SysType[8];		// 71
-  unsigned char  Res2[418];				// 90
-  unsigned long  Signature1;				// 508
+  unsigned char  Res2[420];				// 90
+  unsigned short Signature1;				// 510
 } __attribute__((packed));
 
 struct _FsInfoSector
CVSspam 0.2.8