2005-08-24 18:29:45 +00:00
|
|
|
/*
|
1999-12-11 21:14:49 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
2003-10-11 17:51:56 +00:00
|
|
|
* FILE: drivers/fs/vfat/rw.c
|
1999-12-11 21:14:49 +00:00
|
|
|
* PURPOSE: VFAT Filesystem
|
|
|
|
* PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include "vfat.h"
|
|
|
|
|
2004-08-01 21:57:18 +00:00
|
|
|
/*
|
|
|
|
* Uncomment to enable strict verification of cluster/offset pair
|
|
|
|
* caching. If this option is enabled you lose all the benefits of
|
|
|
|
* the caching and the read/write operations will actually be
|
|
|
|
* slower. It's meant only for debugging!!!
|
|
|
|
* - Filip Navara, 26/07/2004
|
|
|
|
*/
|
|
|
|
/* #define DEBUG_VERIFY_OFFSET_CACHING */
|
|
|
|
|
2001-01-01 04:42:12 +00:00
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2001-01-12 21:00:08 +00:00
|
|
|
NTSTATUS
|
2001-01-08 02:14:06 +00:00
|
|
|
NextCluster(PDEVICE_EXTENSION DeviceExt,
|
|
|
|
ULONG FirstCluster,
|
2001-01-16 09:55:02 +00:00
|
|
|
PULONG CurrentCluster,
|
|
|
|
BOOLEAN Extend)
|
|
|
|
/*
|
|
|
|
* Return the next cluster in a FAT chain, possibly extending the chain if
|
|
|
|
* necessary
|
|
|
|
*/
|
2001-01-08 02:14:06 +00:00
|
|
|
{
|
2003-05-11 09:51:26 +00:00
|
|
|
if (FirstCluster == 1)
|
2001-03-02 15:59:16 +00:00
|
|
|
{
|
2002-03-18 22:37:13 +00:00
|
|
|
(*CurrentCluster) += DeviceExt->FatInfo.SectorsPerCluster;
|
2002-01-08 00:49:02 +00:00
|
|
|
return(STATUS_SUCCESS);
|
2001-03-02 15:59:16 +00:00
|
|
|
}
|
2001-01-08 02:14:06 +00:00
|
|
|
else
|
|
|
|
{
|
2004-08-05 02:48:18 +00:00
|
|
|
if (Extend)
|
|
|
|
return GetNextClusterExtend(DeviceExt, (*CurrentCluster), CurrentCluster);
|
|
|
|
else
|
|
|
|
return GetNextCluster(DeviceExt, (*CurrentCluster), CurrentCluster);
|
2001-01-08 02:14:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-12 21:00:08 +00:00
|
|
|
NTSTATUS
|
2001-10-10 22:19:51 +00:00
|
|
|
OffsetToCluster(PDEVICE_EXTENSION DeviceExt,
|
|
|
|
ULONG FirstCluster,
|
2001-01-12 21:00:08 +00:00
|
|
|
ULONG FileOffset,
|
2001-01-16 09:55:02 +00:00
|
|
|
PULONG Cluster,
|
|
|
|
BOOLEAN Extend)
|
|
|
|
/*
|
|
|
|
* Return the cluster corresponding to an offset within a file,
|
|
|
|
* possibly extending the file if necessary
|
|
|
|
*/
|
2001-01-01 04:42:12 +00:00
|
|
|
{
|
|
|
|
ULONG CurrentCluster;
|
|
|
|
ULONG i;
|
2001-01-12 21:00:08 +00:00
|
|
|
NTSTATUS Status;
|
2003-07-24 19:00:42 +00:00
|
|
|
/*
|
2002-01-15 21:54:51 +00:00
|
|
|
DPRINT("OffsetToCluster(DeviceExt %x, Fcb %x, FirstCluster %x,"
|
2005-05-08 02:16:32 +00:00
|
|
|
" FileOffset %x, Cluster %x, Extend %d)\n", DeviceExt,
|
2002-01-15 21:54:51 +00:00
|
|
|
Fcb, FirstCluster, FileOffset, Cluster, Extend);
|
2003-07-24 19:00:42 +00:00
|
|
|
*/
|
2002-01-15 21:54:51 +00:00
|
|
|
if (FirstCluster == 0)
|
|
|
|
{
|
|
|
|
DbgPrint("OffsetToCluster is called with FirstCluster = 0!\n");
|
2008-08-24 15:48:05 +00:00
|
|
|
ASSERT(FALSE);
|
2002-01-15 21:54:51 +00:00
|
|
|
}
|
2001-01-01 04:42:12 +00:00
|
|
|
|
|
|
|
if (FirstCluster == 1)
|
2001-10-10 22:19:51 +00:00
|
|
|
{
|
2001-01-01 04:42:12 +00:00
|
|
|
/* root of FAT16 or FAT12 */
|
2002-03-18 22:37:13 +00:00
|
|
|
*Cluster = DeviceExt->FatInfo.rootStart + FileOffset
|
|
|
|
/ (DeviceExt->FatInfo.BytesPerCluster) * DeviceExt->FatInfo.SectorsPerCluster;
|
2001-01-12 21:00:08 +00:00
|
|
|
return(STATUS_SUCCESS);
|
2001-01-01 04:42:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-01-12 21:00:08 +00:00
|
|
|
CurrentCluster = FirstCluster;
|
2004-08-05 02:48:18 +00:00
|
|
|
if (Extend)
|
|
|
|
{
|
|
|
|
for (i = 0; i < FileOffset / DeviceExt->FatInfo.BytesPerCluster; i++)
|
|
|
|
{
|
|
|
|
Status = GetNextClusterExtend (DeviceExt, CurrentCluster, &CurrentCluster);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return(Status);
|
|
|
|
}
|
|
|
|
*Cluster = CurrentCluster;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < FileOffset / DeviceExt->FatInfo.BytesPerCluster; i++)
|
|
|
|
{
|
|
|
|
Status = GetNextCluster (DeviceExt, CurrentCluster, &CurrentCluster);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return(Status);
|
|
|
|
}
|
|
|
|
*Cluster = CurrentCluster;
|
|
|
|
}
|
|
|
|
return(STATUS_SUCCESS);
|
2005-05-08 02:16:32 +00:00
|
|
|
}
|
2001-01-01 04:42:12 +00:00
|
|
|
}
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2005-10-06 21:39:18 +00:00
|
|
|
static NTSTATUS
|
2005-05-08 02:16:32 +00:00
|
|
|
VfatReadFileData (PVFAT_IRP_CONTEXT IrpContext,
|
|
|
|
ULONG Length,
|
|
|
|
LARGE_INTEGER ReadOffset,
|
2004-05-15 23:00:02 +00:00
|
|
|
PULONG LengthRead)
|
2001-01-01 04:42:12 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Reads data from a file
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
ULONG CurrentCluster;
|
|
|
|
ULONG FirstCluster;
|
2001-10-10 22:19:51 +00:00
|
|
|
ULONG StartCluster;
|
|
|
|
ULONG ClusterCount;
|
2002-06-26 18:36:41 +00:00
|
|
|
LARGE_INTEGER StartOffset;
|
2002-05-05 20:20:15 +00:00
|
|
|
PDEVICE_EXTENSION DeviceExt;
|
|
|
|
BOOLEAN First = TRUE;
|
2001-01-01 04:42:12 +00:00
|
|
|
PVFATFCB Fcb;
|
2001-01-12 21:00:08 +00:00
|
|
|
NTSTATUS Status;
|
2002-01-27 01:11:24 +00:00
|
|
|
ULONG BytesDone;
|
2002-06-26 18:36:41 +00:00
|
|
|
ULONG BytesPerSector;
|
|
|
|
ULONG BytesPerCluster;
|
2004-08-01 21:57:18 +00:00
|
|
|
ULONG LastCluster;
|
|
|
|
ULONG LastOffset;
|
2001-01-01 04:42:12 +00:00
|
|
|
|
|
|
|
/* PRECONDITION */
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(IrpContext);
|
2002-05-05 20:20:15 +00:00
|
|
|
DeviceExt = IrpContext->DeviceExt;
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(DeviceExt);
|
|
|
|
ASSERT(DeviceExt->FatInfo.BytesPerCluster);
|
|
|
|
ASSERT(IrpContext->FileObject);
|
|
|
|
ASSERT(IrpContext->FileObject->FsContext2 != NULL);
|
2001-01-01 04:42:12 +00:00
|
|
|
|
2007-11-21 16:50:07 +00:00
|
|
|
DPRINT("VfatReadFileData(DeviceExt %p, FileObject %p, "
|
2002-05-05 20:20:15 +00:00
|
|
|
"Length %d, ReadOffset 0x%I64x)\n", DeviceExt,
|
2004-05-15 23:00:02 +00:00
|
|
|
IrpContext->FileObject, Length, ReadOffset.QuadPart);
|
2001-07-20 08:00:21 +00:00
|
|
|
|
|
|
|
*LengthRead = 0;
|
2001-01-01 04:42:12 +00:00
|
|
|
|
2003-02-13 22:24:19 +00:00
|
|
|
Fcb = IrpContext->FileObject->FsContext;
|
2002-06-26 18:36:41 +00:00
|
|
|
BytesPerSector = DeviceExt->FatInfo.BytesPerSector;
|
|
|
|
BytesPerCluster = DeviceExt->FatInfo.BytesPerCluster;
|
2001-10-10 22:19:51 +00:00
|
|
|
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(ReadOffset.QuadPart + Length <= ROUND_UP(Fcb->RFCB.FileSize.QuadPart, BytesPerSector));
|
|
|
|
ASSERT(ReadOffset.u.LowPart % BytesPerSector == 0);
|
|
|
|
ASSERT(Length % BytesPerSector == 0);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
2002-01-27 01:11:24 +00:00
|
|
|
/* Is this a read of the FAT? */
|
2001-10-10 22:19:51 +00:00
|
|
|
if (Fcb->Flags & FCB_IS_FAT)
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
2002-06-26 18:36:41 +00:00
|
|
|
ReadOffset.QuadPart += DeviceExt->FatInfo.FATStart * BytesPerSector;
|
2004-05-15 23:00:02 +00:00
|
|
|
Status = VfatReadDiskPartial(IrpContext, &ReadOffset, Length, 0, TRUE);
|
2001-10-10 22:19:51 +00:00
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
2001-08-08 19:04:13 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
*LengthRead = Length;
|
2001-08-08 19:04:13 +00:00
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
else
|
2002-01-27 01:11:24 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
DPRINT1("FAT reading failed, Status %x\n", Status);
|
2002-01-27 01:11:24 +00:00
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
return Status;
|
|
|
|
}
|
2002-06-26 18:36:41 +00:00
|
|
|
/* Is this a read of the Volume ? */
|
2002-05-05 20:20:15 +00:00
|
|
|
if (Fcb->Flags & FCB_IS_VOLUME)
|
|
|
|
{
|
2004-05-15 23:00:02 +00:00
|
|
|
Status = VfatReadDiskPartial(IrpContext, &ReadOffset, Length, 0, TRUE);
|
2002-05-05 20:20:15 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
2002-01-27 01:11:24 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
*LengthRead = Length;
|
2002-01-27 01:11:24 +00:00
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
else
|
2002-01-27 01:11:24 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
DPRINT1("Volume reading failed, Status %x\n", Status);
|
2002-01-27 01:11:24 +00:00
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
return Status;
|
2002-01-27 01:11:24 +00:00
|
|
|
}
|
2001-10-10 22:19:51 +00:00
|
|
|
|
|
|
|
/*
|
2002-05-05 20:20:15 +00:00
|
|
|
* Find the first cluster
|
2001-10-10 22:19:51 +00:00
|
|
|
*/
|
2002-05-05 20:20:15 +00:00
|
|
|
FirstCluster = CurrentCluster =
|
|
|
|
vfatDirEntryGetFirstCluster (DeviceExt, &Fcb->entry);
|
2002-01-27 01:11:24 +00:00
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
if (FirstCluster == 1)
|
|
|
|
{
|
|
|
|
// Directory of FAT12/16 needs a special handling
|
2002-06-26 18:36:41 +00:00
|
|
|
if (ReadOffset.u.LowPart + Length > DeviceExt->FatInfo.rootDirectorySectors * BytesPerSector)
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
2002-06-26 18:36:41 +00:00
|
|
|
Length = DeviceExt->FatInfo.rootDirectorySectors * BytesPerSector - ReadOffset.u.LowPart;
|
2001-01-01 04:42:12 +00:00
|
|
|
}
|
2002-06-26 18:36:41 +00:00
|
|
|
ReadOffset.u.LowPart += DeviceExt->FatInfo.rootStart * BytesPerSector;
|
2001-01-16 09:55:02 +00:00
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
// Fire up the read command
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2004-05-15 23:00:02 +00:00
|
|
|
Status = VfatReadDiskPartial (IrpContext, &ReadOffset, Length, 0, TRUE);
|
2002-05-05 20:20:15 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
2004-05-15 23:00:02 +00:00
|
|
|
*LengthRead = Length;
|
2002-05-05 20:20:15 +00:00
|
|
|
}
|
|
|
|
return Status;
|
2001-08-08 19:04:13 +00:00
|
|
|
}
|
2004-08-01 21:57:18 +00:00
|
|
|
|
|
|
|
ExAcquireFastMutex(&Fcb->LastMutex);
|
|
|
|
LastCluster = Fcb->LastCluster;
|
|
|
|
LastOffset = Fcb->LastOffset;
|
|
|
|
ExReleaseFastMutex(&Fcb->LastMutex);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2001-01-16 09:55:02 +00:00
|
|
|
/*
|
2002-05-05 20:20:15 +00:00
|
|
|
* Find the cluster to start the read from
|
2001-01-16 09:55:02 +00:00
|
|
|
*/
|
2004-08-01 21:57:18 +00:00
|
|
|
if (LastCluster > 0 && ReadOffset.u.LowPart >= LastOffset)
|
|
|
|
{
|
|
|
|
Status = OffsetToCluster(DeviceExt, LastCluster,
|
|
|
|
ROUND_DOWN(ReadOffset.u.LowPart, BytesPerCluster) -
|
|
|
|
LastOffset,
|
|
|
|
&CurrentCluster, FALSE);
|
|
|
|
#ifdef DEBUG_VERIFY_OFFSET_CACHING
|
|
|
|
/* DEBUG VERIFICATION */
|
|
|
|
{
|
|
|
|
ULONG CorrectCluster;
|
|
|
|
OffsetToCluster(DeviceExt, FirstCluster,
|
|
|
|
ROUND_DOWN(ReadOffset.u.LowPart, BytesPerCluster),
|
|
|
|
&CorrectCluster, FALSE);
|
|
|
|
if (CorrectCluster != CurrentCluster)
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheck(FAT_FILE_SYSTEM);
|
2004-08-01 21:57:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
2001-08-08 19:04:13 +00:00
|
|
|
{
|
2004-08-01 21:57:18 +00:00
|
|
|
Status = OffsetToCluster(DeviceExt, FirstCluster,
|
|
|
|
ROUND_DOWN(ReadOffset.u.LowPart, BytesPerCluster),
|
|
|
|
&CurrentCluster, FALSE);
|
2001-08-08 19:04:13 +00:00
|
|
|
}
|
2001-01-16 09:55:02 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2001-08-08 19:04:13 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
return(Status);
|
2001-08-08 19:04:13 +00:00
|
|
|
}
|
2001-01-16 09:55:02 +00:00
|
|
|
|
2004-08-01 21:57:18 +00:00
|
|
|
ExAcquireFastMutex(&Fcb->LastMutex);
|
|
|
|
Fcb->LastCluster = CurrentCluster;
|
|
|
|
Fcb->LastOffset = ROUND_DOWN (ReadOffset.u.LowPart, BytesPerCluster);
|
|
|
|
ExReleaseFastMutex(&Fcb->LastMutex);
|
2001-10-10 22:19:51 +00:00
|
|
|
|
2004-05-15 23:00:02 +00:00
|
|
|
KeInitializeEvent(&IrpContext->Event, NotificationEvent, FALSE);
|
|
|
|
IrpContext->RefCount = 1;
|
|
|
|
|
|
|
|
while (Length > 0 && CurrentCluster != 0xffffffff)
|
2001-08-08 19:04:13 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
StartCluster = CurrentCluster;
|
2003-01-04 02:07:18 +00:00
|
|
|
StartOffset.QuadPart = ClusterToSector(DeviceExt, StartCluster) * BytesPerSector;
|
2002-05-05 20:20:15 +00:00
|
|
|
BytesDone = 0;
|
|
|
|
ClusterCount = 0;
|
2001-10-10 22:19:51 +00:00
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
do
|
2001-10-10 22:19:51 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
ClusterCount++;
|
|
|
|
if (First)
|
|
|
|
{
|
2002-06-26 18:36:41 +00:00
|
|
|
BytesDone = min (Length, BytesPerCluster - (ReadOffset.u.LowPart % BytesPerCluster));
|
|
|
|
StartOffset.QuadPart += ReadOffset.u.LowPart % BytesPerCluster;
|
2002-05-05 20:20:15 +00:00
|
|
|
First = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-06-26 18:36:41 +00:00
|
|
|
if (Length - BytesDone > BytesPerCluster)
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
2002-06-26 18:36:41 +00:00
|
|
|
BytesDone += BytesPerCluster;
|
2002-05-05 20:20:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BytesDone = Length;
|
|
|
|
}
|
|
|
|
}
|
2003-05-11 09:51:26 +00:00
|
|
|
Status = NextCluster(DeviceExt, FirstCluster, &CurrentCluster, FALSE);
|
2001-10-10 22:19:51 +00:00
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
while (StartCluster + ClusterCount == CurrentCluster && NT_SUCCESS(Status) && Length > BytesDone);
|
|
|
|
DPRINT("start %08x, next %08x, count %d\n",
|
|
|
|
StartCluster, CurrentCluster, ClusterCount);
|
|
|
|
|
2004-08-01 21:57:18 +00:00
|
|
|
ExAcquireFastMutex(&Fcb->LastMutex);
|
|
|
|
Fcb->LastCluster = StartCluster + (ClusterCount - 1);
|
2004-08-31 20:02:24 +00:00
|
|
|
Fcb->LastOffset = ROUND_DOWN(ReadOffset.u.LowPart, BytesPerCluster) + (ClusterCount - 1) * BytesPerCluster;
|
2004-08-01 21:57:18 +00:00
|
|
|
ExReleaseFastMutex(&Fcb->LastMutex);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
2004-05-15 23:00:02 +00:00
|
|
|
// Fire up the read command
|
|
|
|
Status = VfatReadDiskPartial (IrpContext, &StartOffset, BytesDone, *LengthRead, FALSE);
|
|
|
|
if (!NT_SUCCESS(Status) && Status != STATUS_PENDING)
|
2003-07-24 19:00:42 +00:00
|
|
|
{
|
2004-05-15 23:00:02 +00:00
|
|
|
break;
|
2003-07-24 19:00:42 +00:00
|
|
|
}
|
2004-05-15 23:00:02 +00:00
|
|
|
*LengthRead += BytesDone;
|
|
|
|
Length -= BytesDone;
|
|
|
|
ReadOffset.u.LowPart += BytesDone;
|
2002-05-05 20:20:15 +00:00
|
|
|
}
|
2004-05-15 23:00:02 +00:00
|
|
|
if (0 != InterlockedDecrement((PLONG)&IrpContext->RefCount))
|
|
|
|
{
|
|
|
|
KeWaitForSingleObject(&IrpContext->Event, Executive, KernelMode, FALSE, NULL);
|
|
|
|
}
|
|
|
|
if (NT_SUCCESS(Status) || Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
if (Length > 0)
|
|
|
|
{
|
|
|
|
Status = STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = IrpContext->Irp->IoStatus.Status;
|
|
|
|
}
|
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
return Status;
|
|
|
|
}
|
2001-10-10 22:19:51 +00:00
|
|
|
|
2005-10-06 21:39:18 +00:00
|
|
|
static NTSTATUS
|
2004-05-15 23:00:02 +00:00
|
|
|
VfatWriteFileData(PVFAT_IRP_CONTEXT IrpContext,
|
|
|
|
ULONG Length,
|
|
|
|
LARGE_INTEGER WriteOffset)
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
|
|
|
PDEVICE_EXTENSION DeviceExt;
|
|
|
|
PVFATFCB Fcb;
|
|
|
|
ULONG Count;
|
|
|
|
ULONG FirstCluster;
|
|
|
|
ULONG CurrentCluster;
|
|
|
|
ULONG BytesDone;
|
|
|
|
ULONG StartCluster;
|
|
|
|
ULONG ClusterCount;
|
2003-10-11 17:51:56 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2002-05-05 20:20:15 +00:00
|
|
|
BOOLEAN First = TRUE;
|
2002-06-26 18:36:41 +00:00
|
|
|
ULONG BytesPerSector;
|
|
|
|
ULONG BytesPerCluster;
|
|
|
|
LARGE_INTEGER StartOffset;
|
2004-05-15 23:00:02 +00:00
|
|
|
ULONG BufferOffset;
|
2004-08-01 21:57:18 +00:00
|
|
|
ULONG LastCluster;
|
|
|
|
ULONG LastOffset;
|
2002-05-05 20:20:15 +00:00
|
|
|
|
|
|
|
/* PRECONDITION */
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(IrpContext);
|
2002-05-05 20:20:15 +00:00
|
|
|
DeviceExt = IrpContext->DeviceExt;
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(DeviceExt);
|
|
|
|
ASSERT(DeviceExt->FatInfo.BytesPerCluster);
|
|
|
|
ASSERT(IrpContext->FileObject);
|
|
|
|
ASSERT(IrpContext->FileObject->FsContext2 != NULL);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
2003-02-13 22:24:19 +00:00
|
|
|
Fcb = IrpContext->FileObject->FsContext;
|
2002-06-26 18:36:41 +00:00
|
|
|
BytesPerCluster = DeviceExt->FatInfo.BytesPerCluster;
|
|
|
|
BytesPerSector = DeviceExt->FatInfo.BytesPerSector;
|
2002-05-05 20:20:15 +00:00
|
|
|
|
2007-11-21 16:50:07 +00:00
|
|
|
DPRINT("VfatWriteFileData(DeviceExt %p, FileObject %p, "
|
2003-10-11 17:51:56 +00:00
|
|
|
"Length %d, WriteOffset 0x%I64x), '%wZ'\n", DeviceExt,
|
2004-05-15 23:00:02 +00:00
|
|
|
IrpContext->FileObject, Length, WriteOffset,
|
2003-10-11 17:51:56 +00:00
|
|
|
&Fcb->PathNameU);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(WriteOffset.QuadPart + Length <= Fcb->RFCB.AllocationSize.QuadPart);
|
|
|
|
ASSERT(WriteOffset.u.LowPart % BytesPerSector == 0);
|
2005-01-12 10:46:13 +00:00
|
|
|
ASSERT(Length % BytesPerSector == 0);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
|
|
|
// Is this a write of the volume ?
|
|
|
|
if (Fcb->Flags & FCB_IS_VOLUME)
|
|
|
|
{
|
2004-05-15 23:00:02 +00:00
|
|
|
Status = VfatWriteDiskPartial(IrpContext, &WriteOffset, Length, 0, TRUE);
|
2001-10-10 22:19:51 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
DPRINT1("Volume writing failed, Status %x\n", Status);
|
2001-10-10 22:19:51 +00:00
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
return Status;
|
|
|
|
}
|
2001-10-10 22:19:51 +00:00
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
// Is this a write to the FAT ?
|
|
|
|
if (Fcb->Flags & FCB_IS_FAT)
|
|
|
|
{
|
2002-06-26 18:36:41 +00:00
|
|
|
WriteOffset.u.LowPart += DeviceExt->FatInfo.FATStart * BytesPerSector;
|
2004-05-15 23:00:02 +00:00
|
|
|
IrpContext->RefCount = 1;
|
2002-05-05 20:20:15 +00:00
|
|
|
for (Count = 0; Count < DeviceExt->FatInfo.FATCount; Count++)
|
2001-10-10 22:19:51 +00:00
|
|
|
{
|
2004-05-15 23:00:02 +00:00
|
|
|
Status = VfatWriteDiskPartial(IrpContext, &WriteOffset, Length, 0, FALSE);
|
|
|
|
if (!NT_SUCCESS(Status) && Status != STATUS_PENDING)
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
|
|
|
DPRINT1("FAT writing failed, Status %x\n", Status);
|
2004-05-15 23:00:02 +00:00
|
|
|
break;
|
2002-05-05 20:20:15 +00:00
|
|
|
}
|
2002-06-26 18:36:41 +00:00
|
|
|
WriteOffset.u.LowPart += Fcb->RFCB.FileSize.u.LowPart;
|
2001-10-10 22:19:51 +00:00
|
|
|
}
|
2004-05-15 23:00:02 +00:00
|
|
|
if (0 != InterlockedDecrement((PLONG)&IrpContext->RefCount))
|
|
|
|
{
|
|
|
|
KeWaitForSingleObject(&IrpContext->Event, Executive, KernelMode, FALSE, NULL);
|
|
|
|
}
|
|
|
|
if (NT_SUCCESS(Status) || Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
Status = IrpContext->Irp->IoStatus.Status;
|
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
return Status;
|
|
|
|
}
|
2001-10-10 22:19:51 +00:00
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
/*
|
|
|
|
* Find the first cluster
|
|
|
|
*/
|
|
|
|
FirstCluster = CurrentCluster =
|
|
|
|
vfatDirEntryGetFirstCluster (DeviceExt, &Fcb->entry);
|
|
|
|
|
|
|
|
if (FirstCluster == 1)
|
|
|
|
{
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(WriteOffset.u.LowPart + Length <= DeviceExt->FatInfo.rootDirectorySectors * BytesPerSector);
|
2002-05-05 20:20:15 +00:00
|
|
|
// Directory of FAT12/16 needs a special handling
|
2002-06-26 18:36:41 +00:00
|
|
|
WriteOffset.u.LowPart += DeviceExt->FatInfo.rootStart * BytesPerSector;
|
2002-05-05 20:20:15 +00:00
|
|
|
// Fire up the write command
|
2004-05-15 23:00:02 +00:00
|
|
|
Status = VfatWriteDiskPartial (IrpContext, &WriteOffset, Length, 0, TRUE);
|
2001-10-10 22:19:51 +00:00
|
|
|
return Status;
|
2002-05-05 20:20:15 +00:00
|
|
|
}
|
2001-08-07 15:38:04 +00:00
|
|
|
|
2004-08-01 21:57:18 +00:00
|
|
|
ExAcquireFastMutex(&Fcb->LastMutex);
|
|
|
|
LastCluster = Fcb->LastCluster;
|
|
|
|
LastOffset = Fcb->LastOffset;
|
|
|
|
ExReleaseFastMutex(&Fcb->LastMutex);
|
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
/*
|
|
|
|
* Find the cluster to start the write from
|
|
|
|
*/
|
2004-08-01 21:57:18 +00:00
|
|
|
if (LastCluster > 0 && WriteOffset.u.LowPart >= LastOffset)
|
|
|
|
{
|
|
|
|
Status = OffsetToCluster(DeviceExt, LastCluster,
|
|
|
|
ROUND_DOWN(WriteOffset.u.LowPart, BytesPerCluster) -
|
|
|
|
LastOffset,
|
|
|
|
&CurrentCluster, FALSE);
|
|
|
|
#ifdef DEBUG_VERIFY_OFFSET_CACHING
|
|
|
|
/* DEBUG VERIFICATION */
|
|
|
|
{
|
|
|
|
ULONG CorrectCluster;
|
|
|
|
OffsetToCluster(DeviceExt, FirstCluster,
|
|
|
|
ROUND_DOWN(WriteOffset.u.LowPart, BytesPerCluster),
|
|
|
|
&CorrectCluster, FALSE);
|
|
|
|
if (CorrectCluster != CurrentCluster)
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheck(FAT_FILE_SYSTEM);
|
2004-08-01 21:57:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
2004-08-01 21:57:18 +00:00
|
|
|
Status = OffsetToCluster(DeviceExt, FirstCluster,
|
|
|
|
ROUND_DOWN(WriteOffset.u.LowPart, BytesPerCluster),
|
|
|
|
&CurrentCluster, FALSE);
|
2002-05-05 20:20:15 +00:00
|
|
|
}
|
2001-08-08 19:04:13 +00:00
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2001-10-10 22:19:51 +00:00
|
|
|
return(Status);
|
2002-05-05 20:20:15 +00:00
|
|
|
}
|
2000-12-29 23:17:12 +00:00
|
|
|
|
2004-08-01 21:57:18 +00:00
|
|
|
ExAcquireFastMutex(&Fcb->LastMutex);
|
|
|
|
Fcb->LastCluster = CurrentCluster;
|
|
|
|
Fcb->LastOffset = ROUND_DOWN (WriteOffset.u.LowPart, BytesPerCluster);
|
|
|
|
ExReleaseFastMutex(&Fcb->LastMutex);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
2004-05-15 23:00:02 +00:00
|
|
|
IrpContext->RefCount = 1;
|
|
|
|
BufferOffset = 0;
|
|
|
|
|
|
|
|
while (Length > 0 && CurrentCluster != 0xffffffff)
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
2001-10-10 22:19:51 +00:00
|
|
|
StartCluster = CurrentCluster;
|
2002-06-26 18:36:41 +00:00
|
|
|
StartOffset.QuadPart = ClusterToSector(DeviceExt, StartCluster) * BytesPerSector;
|
2002-05-05 20:20:15 +00:00
|
|
|
BytesDone = 0;
|
|
|
|
ClusterCount = 0;
|
|
|
|
|
2001-10-10 22:19:51 +00:00
|
|
|
do
|
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
ClusterCount++;
|
|
|
|
if (First)
|
|
|
|
{
|
2002-06-26 18:36:41 +00:00
|
|
|
BytesDone = min (Length, BytesPerCluster - (WriteOffset.u.LowPart % BytesPerCluster));
|
|
|
|
StartOffset.QuadPart += WriteOffset.u.LowPart % BytesPerCluster;
|
2002-05-05 20:20:15 +00:00
|
|
|
First = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-06-26 18:36:41 +00:00
|
|
|
if (Length - BytesDone > BytesPerCluster)
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
2002-06-26 18:36:41 +00:00
|
|
|
BytesDone += BytesPerCluster;
|
2002-05-05 20:20:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BytesDone = Length;
|
|
|
|
}
|
|
|
|
}
|
2003-05-11 09:51:26 +00:00
|
|
|
Status = NextCluster(DeviceExt, FirstCluster, &CurrentCluster, FALSE);
|
2001-10-10 22:19:51 +00:00
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
while (StartCluster + ClusterCount == CurrentCluster && NT_SUCCESS(Status) && Length > BytesDone);
|
|
|
|
DPRINT("start %08x, next %08x, count %d\n",
|
|
|
|
StartCluster, CurrentCluster, ClusterCount);
|
2001-10-10 22:19:51 +00:00
|
|
|
|
2004-08-01 21:57:18 +00:00
|
|
|
ExAcquireFastMutex(&Fcb->LastMutex);
|
|
|
|
Fcb->LastCluster = StartCluster + (ClusterCount - 1);
|
2004-08-31 20:02:24 +00:00
|
|
|
Fcb->LastOffset = ROUND_DOWN(WriteOffset.u.LowPart, BytesPerCluster) + (ClusterCount - 1) * BytesPerCluster;
|
2004-08-01 21:57:18 +00:00
|
|
|
ExReleaseFastMutex(&Fcb->LastMutex);
|
2001-10-10 22:19:51 +00:00
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
// Fire up the write command
|
2004-05-15 23:00:02 +00:00
|
|
|
Status = VfatWriteDiskPartial (IrpContext, &StartOffset, BytesDone, BufferOffset, FALSE);
|
|
|
|
if (!NT_SUCCESS(Status) && Status != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
BufferOffset += BytesDone;
|
|
|
|
Length -= BytesDone;
|
|
|
|
WriteOffset.u.LowPart += BytesDone;
|
|
|
|
}
|
|
|
|
if (0 != InterlockedDecrement((PLONG)&IrpContext->RefCount))
|
|
|
|
{
|
|
|
|
KeWaitForSingleObject(&IrpContext->Event, Executive, KernelMode, FALSE, NULL);
|
|
|
|
}
|
|
|
|
if (NT_SUCCESS(Status) || Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
if (Length > 0)
|
2003-07-24 19:00:42 +00:00
|
|
|
{
|
2004-05-15 23:00:02 +00:00
|
|
|
Status = STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = IrpContext->Irp->IoStatus.Status;
|
|
|
|
}
|
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
return Status;
|
1999-12-11 21:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
NTSTATUS
|
2002-01-27 01:11:24 +00:00
|
|
|
VfatRead(PVFAT_IRP_CONTEXT IrpContext)
|
2001-11-02 22:47:36 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PVFATFCB Fcb;
|
2003-10-12 01:13:23 +00:00
|
|
|
ULONG Length = 0;
|
2002-05-05 20:20:15 +00:00
|
|
|
ULONG ReturnedLength = 0;
|
|
|
|
PERESOURCE Resource = NULL;
|
|
|
|
LARGE_INTEGER ByteOffset;
|
|
|
|
PVOID Buffer;
|
2002-06-26 18:36:41 +00:00
|
|
|
ULONG BytesPerSector;
|
2002-05-05 20:20:15 +00:00
|
|
|
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(IrpContext);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
2007-11-21 16:50:07 +00:00
|
|
|
DPRINT("VfatRead(IrpContext %p)\n", IrpContext);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(IrpContext->DeviceObject);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
|
|
|
// This request is not allowed on the main device object
|
|
|
|
if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
|
|
|
|
{
|
|
|
|
DPRINT("VfatRead is called with the main device object.\n");
|
|
|
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
|
|
|
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(IrpContext->DeviceExt);
|
|
|
|
ASSERT(IrpContext->FileObject);
|
2003-02-13 22:24:19 +00:00
|
|
|
Fcb = IrpContext->FileObject->FsContext;
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(Fcb);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
2011-12-23 15:56:25 +00:00
|
|
|
if (Fcb->Flags & FCB_IS_PAGE_FILE)
|
|
|
|
{
|
|
|
|
PFATINFO FatInfo = &IrpContext->DeviceExt->FatInfo;
|
|
|
|
IrpContext->Stack->Parameters.Read.ByteOffset.QuadPart += FatInfo->dataStart * FatInfo->BytesPerSector;
|
|
|
|
IoSkipCurrentIrpStackLocation(IrpContext->Irp);
|
|
|
|
DPRINT("Read from page file, disk offset %I64x\n", IrpContext->Stack->Parameters.Read.ByteOffset.QuadPart);
|
|
|
|
Status = IoCallDriver(IrpContext->DeviceExt->StorageDevice, IrpContext->Irp);
|
|
|
|
VfatFreeIrpContext(IrpContext);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2003-10-11 17:51:56 +00:00
|
|
|
DPRINT("<%wZ>\n", &Fcb->PathNameU);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
|
|
|
ByteOffset = IrpContext->Stack->Parameters.Read.ByteOffset;
|
|
|
|
Length = IrpContext->Stack->Parameters.Read.Length;
|
2002-06-26 18:36:41 +00:00
|
|
|
BytesPerSector = IrpContext->DeviceExt->FatInfo.BytesPerSector;
|
2002-05-05 20:20:15 +00:00
|
|
|
|
|
|
|
/* fail if file is a directory and no paged read */
|
2004-12-05 16:31:51 +00:00
|
|
|
if (*Fcb->Attributes & FILE_ATTRIBUTE_DIRECTORY && !(IrpContext->Irp->Flags & IRP_PAGING_IO))
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-11 17:51:56 +00:00
|
|
|
DPRINT("'%wZ', Offset: %d, Length %d\n", &Fcb->PathNameU, ByteOffset.u.LowPart, Length);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
|
|
|
if (ByteOffset.u.HighPart && !(Fcb->Flags & FCB_IS_VOLUME))
|
|
|
|
{
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
|
|
|
if (ByteOffset.QuadPart >= Fcb->RFCB.FileSize.QuadPart)
|
|
|
|
{
|
|
|
|
IrpContext->Irp->IoStatus.Information = 0;
|
|
|
|
Status = STATUS_END_OF_FILE;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
|
|
|
if (IrpContext->Irp->Flags & (IRP_PAGING_IO | IRP_NOCACHE) || (Fcb->Flags & FCB_IS_VOLUME))
|
|
|
|
{
|
2002-06-26 18:36:41 +00:00
|
|
|
if (ByteOffset.u.LowPart % BytesPerSector != 0 || Length % BytesPerSector != 0)
|
2001-11-02 22:47:36 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
DPRINT("%d %d\n", ByteOffset.u.LowPart, Length);
|
2004-05-15 23:00:02 +00:00
|
|
|
// non cached read must be sector aligned
|
2002-05-05 20:20:15 +00:00
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto ByeBye;
|
2001-11-02 22:47:36 +00:00
|
|
|
}
|
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
if (Length == 0)
|
2001-11-02 22:47:36 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
IrpContext->Irp->IoStatus.Information = 0;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
goto ByeBye;
|
2001-11-02 22:47:36 +00:00
|
|
|
}
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
if (Fcb->Flags & FCB_IS_VOLUME)
|
|
|
|
{
|
|
|
|
Resource = &IrpContext->DeviceExt->DirResource;
|
|
|
|
}
|
|
|
|
else if (IrpContext->Irp->Flags & IRP_PAGING_IO)
|
|
|
|
{
|
|
|
|
Resource = &Fcb->PagingIoResource;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Resource = &Fcb->MainResource;
|
|
|
|
}
|
2003-07-24 19:00:42 +00:00
|
|
|
if (!ExAcquireResourceSharedLite(Resource,
|
2005-01-01 11:11:52 +00:00
|
|
|
IrpContext->Flags & IRPCONTEXT_CANWAIT ? TRUE : FALSE))
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
|
|
|
Resource = NULL;
|
|
|
|
Status = STATUS_PENDING;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
2003-01-25 15:55:08 +00:00
|
|
|
|
|
|
|
if (!(IrpContext->Irp->Flags & IRP_PAGING_IO) &&
|
|
|
|
FsRtlAreThereCurrentFileLocks(&Fcb->FileLock))
|
|
|
|
{
|
2005-05-08 02:16:32 +00:00
|
|
|
if (!FsRtlCheckLockForReadAccess(&Fcb->FileLock, IrpContext->Irp))
|
2003-01-25 15:55:08 +00:00
|
|
|
{
|
|
|
|
Status = STATUS_FILE_LOCK_CONFLICT;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-15 23:00:02 +00:00
|
|
|
Buffer = VfatGetUserBuffer(IrpContext->Irp);
|
|
|
|
if (!Buffer)
|
|
|
|
{
|
|
|
|
Status = STATUS_INVALID_USER_BUFFER;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
if (!(IrpContext->Irp->Flags & (IRP_NOCACHE|IRP_PAGING_IO)) &&
|
|
|
|
!(Fcb->Flags & (FCB_IS_PAGE_FILE|FCB_IS_VOLUME)))
|
|
|
|
{
|
|
|
|
// cached read
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
if (ByteOffset.u.LowPart + Length > Fcb->RFCB.FileSize.u.LowPart)
|
|
|
|
{
|
|
|
|
Length = Fcb->RFCB.FileSize.u.LowPart - ByteOffset.u.LowPart;
|
|
|
|
Status = /*STATUS_END_OF_FILE*/STATUS_SUCCESS;
|
|
|
|
}
|
2001-11-02 22:47:36 +00:00
|
|
|
|
2002-08-17 15:15:50 +00:00
|
|
|
if (IrpContext->FileObject->PrivateCacheMap == NULL)
|
|
|
|
{
|
2005-01-12 13:00:43 +00:00
|
|
|
CcInitializeCacheMap(IrpContext->FileObject,
|
|
|
|
(PCC_FILE_SIZES)(&Fcb->RFCB.AllocationSize),
|
|
|
|
FALSE,
|
|
|
|
&(VfatGlobalData->CacheMgrCallbacks),
|
|
|
|
Fcb);
|
2002-08-17 15:15:50 +00:00
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
if (!CcCopyRead(IrpContext->FileObject, &ByteOffset, Length,
|
2003-07-24 19:00:42 +00:00
|
|
|
(BOOLEAN)(IrpContext->Flags & IRPCONTEXT_CANWAIT), Buffer,
|
2002-05-05 20:20:15 +00:00
|
|
|
&IrpContext->Irp->IoStatus))
|
|
|
|
{
|
2008-11-10 09:57:42 +00:00
|
|
|
Status = STATUS_PENDING;
|
2002-05-05 20:20:15 +00:00
|
|
|
goto ByeBye;
|
|
|
|
}
|
|
|
|
if (!NT_SUCCESS(IrpContext->Irp->IoStatus.Status))
|
|
|
|
{
|
|
|
|
Status = IrpContext->Irp->IoStatus.Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2001-11-02 22:47:36 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
// non cached read
|
2002-06-26 18:36:41 +00:00
|
|
|
if (ByteOffset.QuadPart + Length > ROUND_UP(Fcb->RFCB.FileSize.QuadPart, BytesPerSector))
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
2005-01-12 10:46:13 +00:00
|
|
|
Length = (ULONG)(ROUND_UP(Fcb->RFCB.FileSize.QuadPart, BytesPerSector) - ByteOffset.QuadPart);
|
2002-05-05 20:20:15 +00:00
|
|
|
}
|
|
|
|
|
2004-05-15 23:00:02 +00:00
|
|
|
Status = VfatLockUserBuffer(IrpContext->Irp, Length, IoWriteAccess);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
|
2004-05-15 23:00:02 +00:00
|
|
|
Status = VfatReadFileData(IrpContext, Length, ByteOffset, &ReturnedLength);
|
2002-05-05 20:20:15 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
IrpContext->Irp->IoStatus.Information = ReturnedLength;
|
2001-11-02 22:47:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
ByeBye:
|
|
|
|
if (Resource)
|
|
|
|
{
|
|
|
|
ExReleaseResourceLite(Resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
Status = VfatLockUserBuffer(IrpContext->Irp, Length, IoWriteAccess);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Status = VfatQueueRequest(IrpContext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IrpContext->Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(IrpContext->Irp, IO_NO_INCREMENT);
|
|
|
|
VfatFreeIrpContext(IrpContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IrpContext->Irp->IoStatus.Status = Status;
|
|
|
|
if (IrpContext->FileObject->Flags & FO_SYNCHRONOUS_IO &&
|
|
|
|
!(IrpContext->Irp->Flags & IRP_PAGING_IO) &&
|
|
|
|
(NT_SUCCESS(Status) || Status==STATUS_END_OF_FILE))
|
|
|
|
{
|
|
|
|
IrpContext->FileObject->CurrentByteOffset.QuadPart =
|
|
|
|
ByteOffset.QuadPart + IrpContext->Irp->IoStatus.Information;
|
|
|
|
}
|
|
|
|
|
|
|
|
IoCompleteRequest(IrpContext->Irp,
|
2003-07-24 19:00:42 +00:00
|
|
|
(CCHAR)(NT_SUCCESS(Status) ? IO_DISK_INCREMENT : IO_NO_INCREMENT));
|
2002-05-05 20:20:15 +00:00
|
|
|
VfatFreeIrpContext(IrpContext);
|
|
|
|
}
|
|
|
|
DPRINT("%x\n", Status);
|
|
|
|
return Status;
|
2001-11-02 22:47:36 +00:00
|
|
|
}
|
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
|
2001-11-02 22:47:36 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
PVFATFCB Fcb;
|
|
|
|
PERESOURCE Resource = NULL;
|
|
|
|
LARGE_INTEGER ByteOffset;
|
2002-06-10 21:17:57 +00:00
|
|
|
LARGE_INTEGER OldFileSize;
|
2001-11-02 22:47:36 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2003-10-12 01:13:23 +00:00
|
|
|
ULONG Length = 0;
|
2001-11-02 22:47:36 +00:00
|
|
|
PVOID Buffer;
|
2002-06-26 18:36:41 +00:00
|
|
|
ULONG BytesPerSector;
|
2001-11-02 22:47:36 +00:00
|
|
|
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(IrpContext);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
2007-11-21 16:50:07 +00:00
|
|
|
DPRINT("VfatWrite(IrpContext %p)\n", IrpContext);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(IrpContext->DeviceObject);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
|
|
|
// This request is not allowed on the main device object
|
|
|
|
if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
|
|
|
|
{
|
|
|
|
DPRINT("VfatWrite is called with the main device object.\n");
|
|
|
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
|
|
|
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(IrpContext->DeviceExt);
|
|
|
|
ASSERT(IrpContext->FileObject);
|
2003-02-13 22:24:19 +00:00
|
|
|
Fcb = IrpContext->FileObject->FsContext;
|
2004-11-06 13:44:57 +00:00
|
|
|
ASSERT(Fcb);
|
2001-11-02 22:47:36 +00:00
|
|
|
|
2011-12-23 15:56:25 +00:00
|
|
|
if (Fcb->Flags & FCB_IS_PAGE_FILE)
|
|
|
|
{
|
|
|
|
PFATINFO FatInfo = &IrpContext->DeviceExt->FatInfo;
|
|
|
|
IrpContext->Stack->Parameters.Write.ByteOffset.QuadPart += FatInfo->dataStart * FatInfo->BytesPerSector;
|
|
|
|
IoSkipCurrentIrpStackLocation(IrpContext->Irp);
|
|
|
|
DPRINT("Write to page file, disk offset %I64x\n", IrpContext->Stack->Parameters.Write.ByteOffset.QuadPart);
|
|
|
|
Status = IoCallDriver(IrpContext->DeviceExt->StorageDevice, IrpContext->Irp);
|
|
|
|
VfatFreeIrpContext(IrpContext);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2003-10-11 17:51:56 +00:00
|
|
|
DPRINT("<%wZ>\n", &Fcb->PathNameU);
|
2002-05-05 20:20:15 +00:00
|
|
|
|
2003-05-11 09:51:26 +00:00
|
|
|
/* fail if file is a directory and no paged read */
|
2004-12-05 16:31:51 +00:00
|
|
|
if (*Fcb->Attributes & FILE_ATTRIBUTE_DIRECTORY && !(IrpContext->Irp->Flags & IRP_PAGING_IO))
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
|
|
|
|
|
|
|
ByteOffset = IrpContext->Stack->Parameters.Write.ByteOffset;
|
2004-09-28 10:52:55 +00:00
|
|
|
if (ByteOffset.u.LowPart == FILE_WRITE_TO_END_OF_FILE &&
|
2005-07-05 22:35:29 +00:00
|
|
|
ByteOffset.u.HighPart == -1)
|
2004-09-28 10:52:55 +00:00
|
|
|
{
|
|
|
|
ByteOffset.QuadPart = Fcb->RFCB.FileSize.QuadPart;
|
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
Length = IrpContext->Stack->Parameters.Write.Length;
|
2002-06-26 18:36:41 +00:00
|
|
|
BytesPerSector = IrpContext->DeviceExt->FatInfo.BytesPerSector;
|
2002-05-05 20:20:15 +00:00
|
|
|
|
|
|
|
if (ByteOffset.u.HighPart && !(Fcb->Flags & FCB_IS_VOLUME))
|
|
|
|
{
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Fcb->Flags & (FCB_IS_FAT | FCB_IS_VOLUME) ||
|
|
|
|
1 == vfatDirEntryGetFirstCluster (IrpContext->DeviceExt, &Fcb->entry))
|
2001-11-02 22:47:36 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
if (ByteOffset.QuadPart + Length > Fcb->RFCB.FileSize.QuadPart)
|
2001-11-02 22:47:36 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
// we can't extend the FAT, the volume or the root on FAT12/FAT16
|
|
|
|
Status = STATUS_END_OF_FILE;
|
|
|
|
goto ByeBye;
|
2001-11-02 22:47:36 +00:00
|
|
|
}
|
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
|
|
|
|
if (IrpContext->Irp->Flags & (IRP_PAGING_IO|IRP_NOCACHE) || (Fcb->Flags & FCB_IS_VOLUME))
|
2001-11-02 22:47:36 +00:00
|
|
|
{
|
2002-06-26 18:36:41 +00:00
|
|
|
if (ByteOffset.u.LowPart % BytesPerSector != 0 || Length % BytesPerSector != 0)
|
2001-11-02 22:47:36 +00:00
|
|
|
{
|
2004-05-15 23:00:02 +00:00
|
|
|
// non cached write must be sector aligned
|
2002-05-05 20:20:15 +00:00
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto ByeBye;
|
2001-11-02 22:47:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
if (Length == 0)
|
|
|
|
{
|
2004-05-15 23:00:02 +00:00
|
|
|
/* FIXME:
|
|
|
|
* Update last write time
|
|
|
|
*/
|
2002-05-05 20:20:15 +00:00
|
|
|
IrpContext->Irp->IoStatus.Information = 0;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
2001-11-02 22:47:36 +00:00
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
if (IrpContext->Irp->Flags & IRP_PAGING_IO)
|
|
|
|
{
|
|
|
|
if (ByteOffset.u.LowPart + Length > Fcb->RFCB.AllocationSize.u.LowPart)
|
|
|
|
{
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
2002-06-26 18:36:41 +00:00
|
|
|
if (ByteOffset.u.LowPart + Length > ROUND_UP(Fcb->RFCB.AllocationSize.u.LowPart, BytesPerSector))
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
2002-06-26 18:36:41 +00:00
|
|
|
Length = ROUND_UP(Fcb->RFCB.FileSize.u.LowPart, BytesPerSector) - ByteOffset.u.LowPart;
|
2002-05-05 20:20:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Fcb->Flags & FCB_IS_VOLUME)
|
|
|
|
{
|
|
|
|
Resource = &IrpContext->DeviceExt->DirResource;
|
|
|
|
}
|
|
|
|
else if (IrpContext->Irp->Flags & IRP_PAGING_IO)
|
2001-11-02 22:47:36 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
Resource = &Fcb->PagingIoResource;
|
2001-11-02 22:47:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
Resource = &Fcb->MainResource;
|
2001-11-02 22:47:36 +00:00
|
|
|
}
|
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
if (Fcb->Flags & FCB_IS_PAGE_FILE)
|
2001-11-02 22:47:36 +00:00
|
|
|
{
|
2003-07-24 19:00:42 +00:00
|
|
|
if (!ExAcquireResourceSharedLite(Resource,
|
|
|
|
(BOOLEAN)(IrpContext->Flags & IRPCONTEXT_CANWAIT)))
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
|
|
|
Resource = NULL;
|
|
|
|
Status = STATUS_PENDING;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
2001-11-02 22:47:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-07-24 19:00:42 +00:00
|
|
|
if (!ExAcquireResourceExclusiveLite(Resource,
|
|
|
|
(BOOLEAN)(IrpContext->Flags & IRPCONTEXT_CANWAIT)))
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
|
|
|
Resource = NULL;
|
|
|
|
Status = STATUS_PENDING;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-25 15:55:08 +00:00
|
|
|
if (!(IrpContext->Irp->Flags & IRP_PAGING_IO) &&
|
|
|
|
FsRtlAreThereCurrentFileLocks(&Fcb->FileLock))
|
|
|
|
{
|
2005-05-08 02:16:32 +00:00
|
|
|
if (!FsRtlCheckLockForWriteAccess(&Fcb->FileLock, IrpContext->Irp))
|
2003-01-25 15:55:08 +00:00
|
|
|
{
|
|
|
|
Status = STATUS_FILE_LOCK_CONFLICT;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
if (!(IrpContext->Flags & IRPCONTEXT_CANWAIT) && !(Fcb->Flags & FCB_IS_VOLUME))
|
|
|
|
{
|
|
|
|
if (ByteOffset.u.LowPart + Length > Fcb->RFCB.AllocationSize.u.LowPart)
|
|
|
|
{
|
|
|
|
Status = STATUS_PENDING;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
2001-11-02 22:47:36 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 21:17:57 +00:00
|
|
|
OldFileSize = Fcb->RFCB.FileSize;
|
|
|
|
|
2004-05-15 23:00:02 +00:00
|
|
|
Buffer = VfatGetUserBuffer(IrpContext->Irp);
|
|
|
|
if (!Buffer)
|
|
|
|
{
|
|
|
|
Status = STATUS_INVALID_USER_BUFFER;
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-08 02:16:32 +00:00
|
|
|
if (!(Fcb->Flags & (FCB_IS_FAT|FCB_IS_VOLUME)) &&
|
2002-08-17 16:51:07 +00:00
|
|
|
!(IrpContext->Irp->Flags & IRP_PAGING_IO) &&
|
|
|
|
ByteOffset.u.LowPart + Length > Fcb->RFCB.FileSize.u.LowPart)
|
2001-11-02 22:47:36 +00:00
|
|
|
{
|
2002-08-17 15:15:50 +00:00
|
|
|
LARGE_INTEGER AllocationSize;
|
|
|
|
AllocationSize.QuadPart = ByteOffset.u.LowPart + Length;
|
|
|
|
Status = VfatSetAllocationSizeInformation(IrpContext->FileObject, Fcb,
|
|
|
|
IrpContext->DeviceExt, &AllocationSize);
|
2002-05-05 20:20:15 +00:00
|
|
|
if (!NT_SUCCESS (Status))
|
2001-11-02 22:47:36 +00:00
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
goto ByeBye;
|
2001-11-02 22:47:36 +00:00
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(IrpContext->Irp->Flags & (IRP_NOCACHE|IRP_PAGING_IO)) &&
|
|
|
|
!(Fcb->Flags & (FCB_IS_PAGE_FILE|FCB_IS_VOLUME)))
|
|
|
|
{
|
|
|
|
// cached write
|
|
|
|
|
2002-08-17 15:15:50 +00:00
|
|
|
if (IrpContext->FileObject->PrivateCacheMap == NULL)
|
|
|
|
{
|
2005-01-12 13:00:43 +00:00
|
|
|
CcInitializeCacheMap(IrpContext->FileObject,
|
|
|
|
(PCC_FILE_SIZES)(&Fcb->RFCB.AllocationSize),
|
|
|
|
FALSE,
|
|
|
|
&VfatGlobalData->CacheMgrCallbacks,
|
|
|
|
Fcb);
|
2002-08-17 15:15:50 +00:00
|
|
|
}
|
* Used look aside lists to allocate memory for VFATFCB, VFATCCB and VFAT_IRP_CONTEXT.
* Removed IsLastEntry, IsVolEntry, IsDeletedEntry, vfat_wstrlen, vfatGrabFCB,
vfat_initstr, vfat_wcsncat, vfat_wcsncpy, vfat_movestr, wstrcmpi and replaced
this functions with existing equivalents or functions from ntoskrnl.
* Merged GetEntryName into vfatGetNextDirEntry for reducing some overhead.
* Implemented a file name cache to speed up the searching for existing fcb.
* Removed some calls to FsdDosDateTimeToFileTime.
* Moved the call to CcZeroData behind the initializing of the cache (in VfatWrite).
* Using existing fcbs in FindFile if there is no '*?' within the search name.
svn path=/trunk/; revision=3740
2002-11-11 21:49:18 +00:00
|
|
|
if (ByteOffset.QuadPart > OldFileSize.QuadPart)
|
|
|
|
{
|
2005-01-12 13:00:43 +00:00
|
|
|
CcZeroData(IrpContext->FileObject, &OldFileSize, &ByteOffset, TRUE);
|
* Used look aside lists to allocate memory for VFATFCB, VFATCCB and VFAT_IRP_CONTEXT.
* Removed IsLastEntry, IsVolEntry, IsDeletedEntry, vfat_wstrlen, vfatGrabFCB,
vfat_initstr, vfat_wcsncat, vfat_wcsncpy, vfat_movestr, wstrcmpi and replaced
this functions with existing equivalents or functions from ntoskrnl.
* Merged GetEntryName into vfatGetNextDirEntry for reducing some overhead.
* Implemented a file name cache to speed up the searching for existing fcb.
* Removed some calls to FsdDosDateTimeToFileTime.
* Moved the call to CcZeroData behind the initializing of the cache (in VfatWrite).
* Using existing fcbs in FindFile if there is no '*?' within the search name.
svn path=/trunk/; revision=3740
2002-11-11 21:49:18 +00:00
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
if (CcCopyWrite(IrpContext->FileObject, &ByteOffset, Length,
|
|
|
|
1 /*IrpContext->Flags & IRPCONTEXT_CANWAIT*/, Buffer))
|
|
|
|
{
|
|
|
|
IrpContext->Irp->IoStatus.Information = Length;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
2001-11-02 22:47:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-05-05 20:20:15 +00:00
|
|
|
// non cached write
|
|
|
|
|
* Used look aside lists to allocate memory for VFATFCB, VFATCCB and VFAT_IRP_CONTEXT.
* Removed IsLastEntry, IsVolEntry, IsDeletedEntry, vfat_wstrlen, vfatGrabFCB,
vfat_initstr, vfat_wcsncat, vfat_wcsncpy, vfat_movestr, wstrcmpi and replaced
this functions with existing equivalents or functions from ntoskrnl.
* Merged GetEntryName into vfatGetNextDirEntry for reducing some overhead.
* Implemented a file name cache to speed up the searching for existing fcb.
* Removed some calls to FsdDosDateTimeToFileTime.
* Moved the call to CcZeroData behind the initializing of the cache (in VfatWrite).
* Using existing fcbs in FindFile if there is no '*?' within the search name.
svn path=/trunk/; revision=3740
2002-11-11 21:49:18 +00:00
|
|
|
if (ByteOffset.QuadPart > OldFileSize.QuadPart)
|
|
|
|
{
|
|
|
|
CcZeroData(IrpContext->FileObject, &OldFileSize, &ByteOffset, TRUE);
|
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
|
2004-05-15 23:00:02 +00:00
|
|
|
Status = VfatLockUserBuffer(IrpContext->Irp, Length, IoReadAccess);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = VfatWriteFileData(IrpContext, Length, ByteOffset);
|
2002-05-05 20:20:15 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
IrpContext->Irp->IoStatus.Information = Length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(IrpContext->Irp->Flags & IRP_PAGING_IO) &&
|
|
|
|
!(Fcb->Flags & (FCB_IS_FAT|FCB_IS_VOLUME)))
|
|
|
|
{
|
2004-12-05 16:31:51 +00:00
|
|
|
if(!(*Fcb->Attributes & FILE_ATTRIBUTE_DIRECTORY))
|
2002-05-05 20:20:15 +00:00
|
|
|
{
|
2004-11-06 13:44:57 +00:00
|
|
|
LARGE_INTEGER SystemTime;
|
2002-05-05 20:20:15 +00:00
|
|
|
// set dates and times
|
|
|
|
KeQuerySystemTime (&SystemTime);
|
2004-12-05 16:31:51 +00:00
|
|
|
if (Fcb->Flags & FCB_IS_FATX_ENTRY)
|
|
|
|
{
|
|
|
|
FsdSystemTimeToDosDateTime (IrpContext->DeviceExt,
|
|
|
|
&SystemTime, &Fcb->entry.FatX.UpdateDate,
|
|
|
|
&Fcb->entry.FatX.UpdateTime);
|
|
|
|
Fcb->entry.FatX.AccessDate = Fcb->entry.FatX.UpdateDate;
|
|
|
|
Fcb->entry.FatX.AccessTime = Fcb->entry.FatX.UpdateTime;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FsdSystemTimeToDosDateTime (IrpContext->DeviceExt,
|
|
|
|
&SystemTime, &Fcb->entry.Fat.UpdateDate,
|
|
|
|
&Fcb->entry.Fat.UpdateTime);
|
|
|
|
Fcb->entry.Fat.AccessDate = Fcb->entry.Fat.UpdateDate;
|
|
|
|
}
|
2003-10-11 17:51:56 +00:00
|
|
|
/* set date and times to dirty */
|
|
|
|
Fcb->Flags |= FCB_IS_DIRTY;
|
2002-05-05 20:20:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ByeBye:
|
|
|
|
if (Resource)
|
|
|
|
{
|
|
|
|
ExReleaseResourceLite(Resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
Status = VfatLockUserBuffer(IrpContext->Irp, Length, IoReadAccess);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Status = VfatQueueRequest(IrpContext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IrpContext->Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(IrpContext->Irp, IO_NO_INCREMENT);
|
|
|
|
VfatFreeIrpContext(IrpContext);
|
|
|
|
}
|
2001-11-02 22:47:36 +00:00
|
|
|
}
|
2002-05-05 20:20:15 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
IrpContext->Irp->IoStatus.Status = Status;
|
|
|
|
if (IrpContext->FileObject->Flags & FO_SYNCHRONOUS_IO &&
|
|
|
|
!(IrpContext->Irp->Flags & IRP_PAGING_IO) && NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
IrpContext->FileObject->CurrentByteOffset.QuadPart =
|
|
|
|
ByteOffset.QuadPart + IrpContext->Irp->IoStatus.Information;
|
|
|
|
}
|
2001-11-02 22:47:36 +00:00
|
|
|
|
2002-05-05 20:20:15 +00:00
|
|
|
IoCompleteRequest(IrpContext->Irp,
|
2003-07-24 19:00:42 +00:00
|
|
|
(CCHAR)(NT_SUCCESS(Status) ? IO_DISK_INCREMENT : IO_NO_INCREMENT));
|
2002-05-05 20:20:15 +00:00
|
|
|
VfatFreeIrpContext(IrpContext);
|
|
|
|
}
|
|
|
|
DPRINT("%x\n", Status);
|
2001-11-02 22:47:36 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|