Skip to content

Commit

Permalink
open_file: check oplocks
Browse files Browse the repository at this point in the history
  • Loading branch information
maharmstone committed Sep 4, 2017
1 parent 4a07808 commit 0319dbf
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -3161,6 +3161,36 @@ static NTSTATUS open_file(PDEVICE_OBJECT DeviceObject, _Requires_lock_held_(_Cur
} else
IoSetShareAccess(granted_access, IrpSp->Parameters.Create.ShareAccess, FileObject, &fileref->fcb->share_access);

if (fileref->open_count > 0) {
Status = FsRtlCheckOplock(fcb_oplock(fileref->fcb), Irp, NULL, NULL, NULL);

if (!NT_SUCCESS(Status)) {
ERR("FsRtlCheckOplock returned %08x\n", Status);

IoRemoveShareAccess(FileObject, &fileref->fcb->share_access);

ExAcquireResourceExclusiveLite(&Vcb->fcb_lock, TRUE);
free_fileref(Vcb, fileref);
ExReleaseResourceLite(&Vcb->fcb_lock);

goto exit;
}
}

Status = FsRtlCheckOplockEx(fcb_oplock(fileref->fcb), Irp, OPLOCK_FLAG_OPLOCK_KEY_CHECK_ONLY, NULL, NULL, NULL);

if (!NT_SUCCESS(Status)) {
ERR("FsRtlCheckOplockEx returned %08x\n", Status);

IoRemoveShareAccess(FileObject, &fileref->fcb->share_access);

ExAcquireResourceExclusiveLite(&Vcb->fcb_lock, TRUE);
free_fileref(Vcb, fileref);
ExReleaseResourceLite(&Vcb->fcb_lock);

goto exit;
}

if (granted_access & FILE_WRITE_DATA || options & FILE_DELETE_ON_CLOSE) {
if (!MmFlushImageSection(&fileref->fcb->nonpaged->segment_object, MmFlushForWrite)) {
Status = (options & FILE_DELETE_ON_CLOSE) ? STATUS_CANNOT_DELETE : STATUS_SHARING_VIOLATION;
Expand Down

0 comments on commit 0319dbf

Please sign in to comment.