Commit in reactos/drivers/fs/fs_rec on MAIN
fs_rec.h+19-11.3 -> 1.4
fat.c+136-501.8 -> 1.9
+155-51
2 modified files
- Check more exactly for a FAT file system.

reactos/drivers/fs/fs_rec
fs_rec.h 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- fs_rec.h	16 Jan 2003 11:58:15 -0000	1.3
+++ fs_rec.h	2 May 2004 20:12:38 -0000	1.4
@@ -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: fs_rec.h,v 1.3 2003/01/16 11:58:15 ekohl Exp $
+/* $Id: fs_rec.h,v 1.4 2004/05/02 20:12:38 hbirr Exp $
  *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
@@ -40,6 +40,24 @@
   ULONG FsType;
 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
 
+struct _BootSector
+{
+  unsigned char  magic0, res0, magic1;
+  unsigned char  OEMName[8];
+  unsigned short BytesPerSector;
+  unsigned char  SectorsPerCluster;
+  unsigned short ReservedSectors;
+  unsigned char  FATCount;
+  unsigned short RootEntries, Sectors;
+  unsigned char  Media;
+  unsigned short FATSectors, SectorsPerTrack, Heads;
+  unsigned long  HiddenSectors, SectorsHuge;
+  unsigned char  Drive, Res1, Sig;
+  unsigned long  VolumeID;
+  unsigned char  VolumeLabel[11], SysType[8];
+  unsigned char  Res2[448];
+  unsigned short Signatur1;
+} __attribute__((packed));
 
 /* blockdev.c */
 

reactos/drivers/fs/fs_rec
fat.c 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- fat.c	17 Nov 2003 02:12:49 -0000	1.8
+++ fat.c	2 May 2004 20:12:38 -0000	1.9
@@ -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: fat.c,v 1.8 2003/11/17 02:12:49 hyperion Exp $
+/* $Id: fat.c,v 1.9 2004/05/02 20:12:38 hbirr Exp $
  *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
@@ -41,57 +41,143 @@
 static NTSTATUS
 FsRecIsFatVolume(IN PDEVICE_OBJECT DeviceObject)
 {
-  DISK_GEOMETRY DiskGeometry;
-  PUCHAR Buffer;
-  ULONG Size;
-  NTSTATUS Status;
-
-  Size = sizeof(DISK_GEOMETRY);
-  Status = FsRecDeviceIoControl(DeviceObject,
-				IOCTL_DISK_GET_DRIVE_GEOMETRY,
-				NULL,
-				0,
-				&DiskGeometry,
-				&Size);
-  DPRINT("FsRecDeviceIoControl() Status %lx\n", Status);
-  if (!NT_SUCCESS(Status))
-    {
-      return(Status);
-    }
-
-  DPRINT("BytesPerSector: %lu\n", DiskGeometry.BytesPerSector);
-  Buffer = ExAllocatePool(NonPagedPool,
-			  DiskGeometry.BytesPerSector);
-  if (Buffer == NULL)
-    {
-      return(STATUS_INSUFFICIENT_RESOURCES);
-    }
-
-  Status = FsRecReadSectors(DeviceObject,
-			    0, /* Partition boot sector */
-			    1,
-			    DiskGeometry.BytesPerSector,
-			    Buffer);
-  if (!NT_SUCCESS(Status))
-    {
-      ExFreePool(Buffer);
-      return(Status);
-    }
-
-  if ((strncmp(&Buffer[0x36], "FAT12", 5) == 0) ||
-      (strncmp(&Buffer[0x36], "FAT16", 5) == 0) ||
-      (strncmp(&Buffer[0x52], "FAT32", 5) == 0))
-    {
-      Status = STATUS_SUCCESS;
-    }
-  else
-    {
-      Status = STATUS_UNRECOGNIZED_VOLUME;
-    }
+   NTSTATUS Status;
+   PARTITION_INFORMATION PartitionInfo;
+   DISK_GEOMETRY DiskGeometry;
+   ULONG Size;
+   struct _BootSector* Boot;
+   BOOL RecognizedFS = FALSE;
+   Size = sizeof(DISK_GEOMETRY);
+
+   Status = FsRecDeviceIoControl(DeviceObject,
+				 IOCTL_DISK_GET_DRIVE_GEOMETRY,
+				 NULL,
+				 0,
+				 &DiskGeometry,
+				 &Size);
+   if (!NT_SUCCESS(Status))
+   {
+      DPRINT("FsRecDeviceIoControl faild (%x)\n", Status);
+      return Status;
+   }
+   if (DiskGeometry.MediaType == FixedMedia || DiskGeometry.MediaType == RemovableMedia)
+   {
+      // We have found a hard disk
+      Size = sizeof(PARTITION_INFORMATION);
+      Status = FsRecDeviceIoControl(DeviceObject,
+				    IOCTL_DISK_GET_PARTITION_INFO,
+				    NULL,
+				    0,
+				    &PartitionInfo,
+				    &Size);
+      if (!NT_SUCCESS(Status))
+      {
+         DPRINT("FsRecDeviceIoControl faild (%x)\n", Status);
+         return Status;
+      }
+      
+      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;
+      }
+   }
+   if (DiskGeometry.MediaType > Unknown && DiskGeometry.MediaType < RemovableMedia )
+   {
+      RecognizedFS = TRUE;
+   }
+   if (RecognizedFS == FALSE)
+   {
+      return STATUS_UNRECOGNIZED_VOLUME;
+   }
+
+   Boot = ExAllocatePool(NonPagedPool, DiskGeometry.BytesPerSector);
+   if (Boot == NULL)
+   {
+      return STATUS_INSUFFICIENT_RESOURCES;
+   }
+
+   Status = FsRecReadSectors(DeviceObject, 
+                             0, 
+                             1,
+                             DiskGeometry.BytesPerSector, 
+                             (PUCHAR) Boot);
+   if (!NT_SUCCESS(Status))
+   {
+      return Status;
+   }
+   
+   if (Boot->Signatur1 != 0xaa55)
+   {
+      RecognizedFS=FALSE;
+   }
+   if (RecognizedFS &&
+       Boot->BytesPerSector != 512 &&
+       Boot->BytesPerSector != 1024 &&
+       Boot->BytesPerSector != 2048 && 
+       Boot->BytesPerSector == 4096)
+   {
+      RecognizedFS=FALSE;
+   }
+
+   if (RecognizedFS &&
+       Boot->FATCount != 1 && 
+       Boot->FATCount != 2)
+   {
+      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)
+   {
+      RecognizedFS=FALSE;
+   }
+
+   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)
+   {
+      RecognizedFS=FALSE;
+   }
+
+   if (RecognizedFS &&
+       Boot->BytesPerSector * Boot->SectorsPerCluster > 32 * 1024)
+   {
+      RecognizedFS=FALSE;
+   }
 
-  ExFreePool(Buffer);
 
-  return(Status);
+   ExFreePool(Boot);
+   return RecognizedFS ? STATUS_SUCCESS : STATUS_UNRECOGNIZED_VOLUME;
 }
 
 
CVSspam 0.2.8