Commit in reactos/drivers/fs/vfat on MAIN
vfat.h+5-11.63 -> 1.64
create.c+36-451.67 -> 1.68
fsctl.c+51-121.31 -> 1.32
+92-58
3 modified files
- Improved removable media support.

reactos/drivers/fs/vfat
vfat.h 1.63 -> 1.64
diff -u -r1.63 -r1.64
--- vfat.h	15 May 2004 23:00:02 -0000	1.63
+++ vfat.h	23 Jun 2004 20:23:59 -0000	1.64
@@ -1,4 +1,4 @@
-/* $Id: vfat.h,v 1.63 2004/05/15 23:00:02 hbirr Exp $ */
+/* $Id: vfat.h,v 1.64 2004/06/23 20:23:59 hbirr Exp $ */
 
 #include <ddk/ntifs.h>
 
@@ -129,6 +129,7 @@
   ULONG NumberOfClusters;
   ULONG FatType;
   ULONG Sectors;
+  BOOL FixedMedia;
 } FATINFO, *PFATINFO;
 
 struct _VFATFCB;
@@ -162,6 +163,9 @@
   struct _VFATFCB * VolumeFcb;
 
   LIST_ENTRY VolumeListEntry;
+
+  ULONG MediaChangeCount;
+
 } DEVICE_EXTENSION, *PDEVICE_EXTENSION, VCB, *PVCB;
 
 typedef struct

reactos/drivers/fs/vfat
create.c 1.67 -> 1.68
diff -u -r1.67 -r1.68
--- create.c	31 Mar 2004 03:30:36 -0000	1.67
+++ create.c	23 Jun 2004 20:23:59 -0000	1.68
@@ -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: create.c,v 1.67 2004/03/31 03:30:36 jimtabor Exp $
+/* $Id: create.c,v 1.68 2004/06/23 20:23:59 hbirr Exp $
  *
  * PROJECT:          ReactOS kernel
  * FILE:             drivers/fs/vfat/create.c
@@ -338,11 +338,11 @@
 {
   PVFATFCB ParentFcb;
   PVFATFCB Fcb;
-  DISK_GEOMETRY DiskGeometry;
   NTSTATUS Status;
   UNICODE_STRING NameU;
   WCHAR Name[MAX_PATH];
   ULONG Size;
+  ULONG MediaChangeCount;
 
 //  PDEVICE_OBJECT DeviceObject = DeviceExt->StorageDevice->Vpb->DeviceObject;
   
@@ -370,50 +370,41 @@
 
   DPRINT ("PathName to open: '%wZ'\n", FileNameU);
 
-   Size = sizeof(DISK_GEOMETRY);
-   Status = VfatBlockDeviceIoControl(DeviceExt->StorageDevice,
-				     IOCTL_DISK_GET_DRIVE_GEOMETRY,
-				     NULL,
-				     0,
-				     &DiskGeometry,
-				     &Size,
-				     FALSE);
-
-  if (DiskGeometry.MediaType != FixedMedia )
-     {
-
-  	Status = VfatBlockDeviceIoControl (DeviceExt->StorageDevice,
-					IOCTL_DISK_CHECK_VERIFY,
-					NULL,
-					0,
-					NULL,
-					0,
-					TRUE);
-
-      if (Status == STATUS_VERIFY_REQUIRED)
-    	    {
-      PDEVICE_OBJECT DeviceToVerify;
-
-      DPRINT ("Media change detected!\n");
-      DPRINT ("Device %p\n", DeviceObject);
-
-      DeviceToVerify = IoGetDeviceToVerify (PsGetCurrentThread ());
-      IoSetDeviceToVerify (PsGetCurrentThread (),
-			   NULL);
-
-      Status = IoVerifyVolume (DeviceToVerify,
-			       FALSE);
-      if (!NT_SUCCESS(Status))
-	{
-	  DPRINT ("Status %lx\n", Status);
-	  return Status;
-	}
-    }
-  else if (!NT_SUCCESS(Status))
+  if (!DeviceExt->FatInfo.FixedMedia)
     {
-      DPRINT ("Status %lx\n", Status);
-      return Status;
-    }
+      Size = sizeof(ULONG);
+      Status = VfatBlockDeviceIoControl (DeviceExt->StorageDevice,
+					 IOCTL_DISK_CHECK_VERIFY,
+					 NULL,
+					 0,
+					 &MediaChangeCount,
+					 &Size,
+					 FALSE);
+
+      if (Status == STATUS_VERIFY_REQUIRED || MediaChangeCount != DeviceExt->MediaChangeCount)
+        {
+          PDEVICE_OBJECT DeviceToVerify;
+
+          DPRINT ("Media change detected!\n");
+          DPRINT ("Device %p\n", DeviceExt->StorageDevice);
+
+          DeviceToVerify = IoGetDeviceToVerify (PsGetCurrentThread ());
+          IoSetDeviceToVerify (PsGetCurrentThread (),
+			       NULL);
+
+          Status = IoVerifyVolume (DeviceToVerify,
+			          FALSE);
+          if (!NT_SUCCESS(Status))
+	    {
+	      DPRINT ("Status %lx\n", Status);
+	      return Status;
+	    }
+        }
+      else if (!NT_SUCCESS(Status))
+        {
+          DPRINT ("Status %lx\n", Status);
+          return Status;
+        }
     }
 
 

reactos/drivers/fs/vfat
fsctl.c 1.31 -> 1.32
diff -u -r1.31 -r1.32
--- fsctl.c	20 Jun 2004 09:52:58 -0000	1.31
+++ fsctl.c	23 Jun 2004 20:23:59 -0000	1.32
@@ -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.31 2004/06/20 09:52:58 navaraf Exp $
+/* $Id: fsctl.c,v 1.32 2004/06/23 20:23:59 hbirr Exp $
  *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
@@ -31,7 +31,7 @@
 #include <rosrtl/string.h>
 #include <wchar.h>
 
-//#define NDEBUG
+#define NDEBUG
 #include <debug.h>
 
 #include "vfat.h"
@@ -74,6 +74,7 @@
       DPRINT("VfatBlockDeviceIoControl faild (%x)\n", Status);
       return Status;
    }
+   FatInfo.FixedMedia = DiskGeometry.MediaType == FixedMedia ? TRUE : FALSE;
    if (DiskGeometry.MediaType == FixedMedia || DiskGeometry.MediaType == RemovableMedia)
    {
       // We have found a hard disk
@@ -274,6 +275,7 @@
 {
    NTSTATUS Status;
    BOOLEAN RecognizedFS;
+   ULONG Size;
 
    DPRINT("Mounting VFAT device...\n");
 
@@ -284,6 +286,22 @@
    }
    DPRINT("MountVfatdev %d, PAGE_SIZE = %d\n", DeviceExt->FatInfo.BytesPerCluster, PAGE_SIZE);
 
+   if (!DeviceExt->FatInfo.FixedMedia)
+     {
+       Size = sizeof(ULONG);
+       Status = VfatBlockDeviceIoControl (DeviceToMount,
+					  IOCTL_DISK_CHECK_VERIFY,
+					  NULL,
+					  0,
+					  &DeviceExt->MediaChangeCount,
+					  &Size,
+					  FALSE);
+       if (!NT_SUCCESS(Status))
+         {
+	   return Status;
+	 }
+     }
+
    return(STATUS_SUCCESS);
 }
 
@@ -478,29 +496,50 @@
 {
   PDEVICE_OBJECT DeviceToVerify;
   NTSTATUS Status = STATUS_SUCCESS;
-
+  FATINFO FatInfo;
+  BOOLEAN RecognizedFS;
+  ULONG Size;
+  PDEVICE_EXTENSION DeviceExt = IrpContext->DeviceExt;
 
   DPRINT("VfatVerify(IrpContext %x)\n", IrpContext);
 
   DeviceToVerify = IrpContext->Stack->Parameters.VerifyVolume.DeviceObject;
+  Size = sizeof(ULONG);
   Status = VfatBlockDeviceIoControl(DeviceToVerify,
 				    IOCTL_DISK_CHECK_VERIFY,
 				    NULL,
 				    0,
-				    NULL,
-				    NULL,
+				    &DeviceExt->MediaChangeCount,
+				    &Size,
 				    FALSE);
-  if (!NT_SUCCESS(Status))
+  if (!NT_SUCCESS(Status) && Status != STATUS_VERIFY_REQUIRED)
     {
       DPRINT("VfatBlockDeviceIoControl() failed (Status %lx)\n", Status);
-
-      /* FIXME: Compare volume label */
-
-      DPRINT("  returning STATUS_WRONG_VOLUME\n");
-
       Status = STATUS_WRONG_VOLUME;
     }
-  DeviceToVerify->Flags &= ~DO_VERIFY_VOLUME;
+  else
+    {
+      Status = VfatHasFileSystem(DeviceToVerify, &RecognizedFS, &FatInfo);
+      if (!NT_SUCCESS(Status) || RecognizedFS == FALSE)
+        {
+          Status = STATUS_WRONG_VOLUME;
+        }
+      else if (sizeof(FATINFO) == RtlCompareMemory(&FatInfo, &DeviceExt->FatInfo, sizeof(FATINFO)))
+        {
+          /*
+           * FIXME:
+           *   Preformated floppy disks have very often a serial number of 0000:0000. 
+           *   We should calculate a crc sum over the sectors from the root directory as secondary volume number. 
+	   *   Each write to the root directory must update this crc sum.
+           */
+  
+          DeviceToVerify->Flags &= ~DO_VERIFY_VOLUME;
+        }
+      else
+      	{
+      	  Status = STATUS_WRONG_VOLUME;
+        }
+     }
     
   return Status;
 }
CVSspam 0.2.8