Skip to content

Commit bf2d787

Browse files
HeisSpiterJoachimHenze
authored andcommitted
[0.4.9] cherry-pick [FASTFAT] Properly handle IRPs that can wait and these that cannot.
CORE-14634 (cherry picked from commit b436306)
1 parent 07a13ca commit bf2d787

File tree

3 files changed

+31
-35
lines changed

3 files changed

+31
-35
lines changed

drivers/filesystems/fastfat/cleanup.c

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,8 @@ VfatCleanupFile(
5050
}
5151
else
5252
{
53-
if(!ExAcquireResourceExclusiveLite(&pFcb->MainResource,
54-
BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
55-
{
56-
return STATUS_PENDING;
57-
}
58-
if(!ExAcquireResourceExclusiveLite(&pFcb->PagingIoResource,
59-
BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
60-
{
61-
ExReleaseResourceLite(&pFcb->MainResource);
62-
return STATUS_PENDING;
63-
}
53+
ExAcquireResourceExclusiveLite(&pFcb->MainResource, TRUE);
54+
ExAcquireResourceExclusiveLite(&pFcb->PagingIoResource, TRUE);
6455

6556
pCcb = FileObject->FsContext2;
6657
if (BooleanFlagOn(pCcb->Flags, CCB_DELETE_ON_CLOSE))
@@ -173,21 +164,10 @@ VfatCleanup(
173164
return STATUS_SUCCESS;
174165
}
175166

176-
if (!ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource,
177-
BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
178-
{
179-
return VfatMarkIrpContextForQueue(IrpContext);
180-
}
181-
167+
ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, TRUE);
182168
Status = VfatCleanupFile(IrpContext);
183-
184169
ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
185170

186-
if (Status == STATUS_PENDING)
187-
{
188-
return VfatMarkIrpContextForQueue(IrpContext);
189-
}
190-
191171
IrpContext->Irp->IoStatus.Information = 0;
192172
return Status;
193173
}

drivers/filesystems/fastfat/create.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,11 +1059,6 @@ VfatCreate(
10591059
return STATUS_SUCCESS;
10601060
}
10611061

1062-
if (!BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT))
1063-
{
1064-
return VfatMarkIrpContextForQueue(IrpContext);
1065-
}
1066-
10671062
IrpContext->Irp->IoStatus.Information = 0;
10681063
ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, TRUE);
10691064
Status = VfatCreateFile(IrpContext->DeviceObject, IrpContext->Irp);

drivers/filesystems/fastfat/misc.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,18 +287,39 @@ VfatAllocateIrpContext(
287287
IrpContext->MinorFunction = IrpContext->Stack->MinorFunction;
288288
IrpContext->FileObject = IrpContext->Stack->FileObject;
289289
IrpContext->Flags = IRPCONTEXT_COMPLETE;
290-
if (MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL ||
291-
MajorFunction == IRP_MJ_DEVICE_CONTROL ||
292-
MajorFunction == IRP_MJ_SHUTDOWN)
290+
291+
/* Easy cases that can wait */
292+
if (MajorFunction == IRP_MJ_CLEANUP ||
293+
MajorFunction == IRP_MJ_CREATE ||
294+
MajorFunction == IRP_MJ_SHUTDOWN ||
295+
MajorFunction == IRP_MJ_CLOSE /* likely to be fixed */)
293296
{
294-
IrpContext->Flags |= IRPCONTEXT_CANWAIT;
297+
SetFlag(IrpContext->Flags, IRPCONTEXT_CANWAIT);
295298
}
296-
else if (MajorFunction != IRP_MJ_CLEANUP &&
297-
MajorFunction != IRP_MJ_CLOSE &&
299+
/* Cases that can wait if synchronous IRP */
300+
else if ((MajorFunction == IRP_MJ_DEVICE_CONTROL ||
301+
MajorFunction == IRP_MJ_QUERY_INFORMATION ||
302+
MajorFunction == IRP_MJ_SET_INFORMATION ||
303+
MajorFunction == IRP_MJ_FLUSH_BUFFERS ||
304+
MajorFunction == IRP_MJ_LOCK_CONTROL ||
305+
MajorFunction == IRP_MJ_QUERY_VOLUME_INFORMATION ||
306+
MajorFunction == IRP_MJ_SET_VOLUME_INFORMATION ||
307+
MajorFunction == IRP_MJ_DIRECTORY_CONTROL ||
308+
MajorFunction == IRP_MJ_WRITE ||
309+
MajorFunction == IRP_MJ_READ) &&
298310
IoIsOperationSynchronous(Irp))
299311
{
300-
IrpContext->Flags |= IRPCONTEXT_CANWAIT;
312+
SetFlag(IrpContext->Flags, IRPCONTEXT_CANWAIT);
313+
}
314+
/* Cases that can wait if synchronous or if no FO */
315+
else if ((MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL ||
316+
MajorFunction == IRP_MJ_PNP) &&
317+
(IoGetCurrentIrpStackLocation(Irp)->FileObject == NULL ||
318+
IoIsOperationSynchronous(Irp)))
319+
{
320+
SetFlag(IrpContext->Flags, IRPCONTEXT_CANWAIT);
301321
}
322+
302323
KeInitializeEvent(&IrpContext->Event, NotificationEvent, FALSE);
303324
IrpContext->RefCount = 0;
304325
IrpContext->PriorityBoost = IO_NO_INCREMENT;

0 commit comments

Comments
 (0)