diff --git a/reactos/drivers/fs/vfat/create.c b/reactos/drivers/fs/vfat/create.c index 2204b4b9273..1f95922f578 100644 --- a/reactos/drivers/fs/vfat/create.c +++ b/reactos/drivers/fs/vfat/create.c @@ -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 @@ VfatOpenFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, { 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 @@ VfatOpenFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, 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; + } } diff --git a/reactos/drivers/fs/vfat/fsctl.c b/reactos/drivers/fs/vfat/fsctl.c index 5bd8bc9dcda..890595b35f9 100644 --- a/reactos/drivers/fs/vfat/fsctl.c +++ b/reactos/drivers/fs/vfat/fsctl.c @@ -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 #include -//#define NDEBUG +#define NDEBUG #include #include "vfat.h" @@ -74,6 +74,7 @@ VfatHasFileSystem(PDEVICE_OBJECT DeviceToMount, 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 @@ VfatMountDevice(PDEVICE_EXTENSION DeviceExt, { NTSTATUS Status; BOOLEAN RecognizedFS; + ULONG Size; DPRINT("Mounting VFAT device...\n"); @@ -284,6 +286,22 @@ VfatMountDevice(PDEVICE_EXTENSION DeviceExt, } 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 @@ VfatVerify (PVFAT_IRP_CONTEXT IrpContext) { 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; } diff --git a/reactos/drivers/fs/vfat/vfat.h b/reactos/drivers/fs/vfat/vfat.h index 63a19ef5365..0eb9b0d53a4 100644 --- a/reactos/drivers/fs/vfat/vfat.h +++ b/reactos/drivers/fs/vfat/vfat.h @@ -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 @@ -129,6 +129,7 @@ typedef struct ULONG NumberOfClusters; ULONG FatType; ULONG Sectors; + BOOL FixedMedia; } FATINFO, *PFATINFO; struct _VFATFCB; @@ -162,6 +163,9 @@ typedef struct struct _VFATFCB * VolumeFcb; LIST_ENTRY VolumeListEntry; + + ULONG MediaChangeCount; + } DEVICE_EXTENSION, *PDEVICE_EXTENSION, VCB, *PVCB; typedef struct