Skip to content

Commit

Permalink
Fixed an issue where the fatx and xiso drivers were accidentally clos…
Browse files Browse the repository at this point in the history
…ing the device handles
  • Loading branch information
ergo720 committed Aug 13, 2024
1 parent fb247c6 commit d792860
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
21 changes: 12 additions & 9 deletions nboxkrnl/io/cdrom/xiso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,15 +434,18 @@ static NTSTATUS XBOXAPI XisoIrpClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
PXISO_FILE_INFO FileInfo = (PXISO_FILE_INFO)FileObject->FsContext2;

if (--FileInfo->RefCounter == 0) {
SubmitIoRequestToHost(
DEV_TYPE(DEV_CDROM) | IoRequestType::Close,
0,
0,
0,
FileInfo->HostHandle
);
XisoRemoveFile(VolumeExtension, FileInfo);
if (!(FileInfo->Flags & XISO_VOLUME_FILE)) {
if (FileInfo->Flags & XISO_VOLUME_FILE) {
XisoRemoveFile(VolumeExtension, FileInfo);
}
else {
SubmitIoRequestToHost(
DEV_TYPE(DEV_CDROM) | IoRequestType::Close,
0,
0,
0,
FileInfo->HostHandle
);
XisoRemoveFile(VolumeExtension, FileInfo);
ExFreePool(FileInfo);
}
FileObject->FsContext2 = nullptr;
Expand Down
23 changes: 13 additions & 10 deletions nboxkrnl/io/hdd/fatx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,15 +608,18 @@ static NTSTATUS XBOXAPI FatxIrpClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
// NOTE: it's not viable to check for FileInfo->ShareAccess.OpenCount here, because it's possible to use a file handle with no access rights granted, which would
// mean that OpenCount is zero and yet the handle is still in use
if (--FileInfo->RefCounter == 0) {
SubmitIoRequestToHost(
DEV_TYPE(VolumeExtension->CacheExtension.DeviceType) | IoRequestType::Close,
0,
0,
0,
FileInfo->HostHandle
);
FatxRemoveFile(VolumeExtension, FileInfo);
if (!(FileInfo->Flags & FATX_VOLUME_FILE)) {
if (FileInfo->Flags & FATX_VOLUME_FILE) {
FatxRemoveFile(VolumeExtension, FileInfo);
}
else {
SubmitIoRequestToHost(
DEV_TYPE(VolumeExtension->CacheExtension.DeviceType) | IoRequestType::Close,
0,
0,
0,
FileInfo->HostHandle
);
FatxRemoveFile(VolumeExtension, FileInfo);
ExFreePool(FileInfo);
}
FileObject->FsContext2 = nullptr;
Expand Down Expand Up @@ -796,7 +799,7 @@ static NTSTATUS XBOXAPI FatxIrpWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
}
else if (NT_SUCCESS(Status)) {
if ((FileObject->CurrentByteOffset.LowPart + InfoBlock.Info) > FileInfo->FileSize) {
FileInfo->FileSize = FileObject->CurrentByteOffset.QuadPart + InfoBlock.Info;
FileInfo->FileSize = FileObject->CurrentByteOffset.LowPart + InfoBlock.Info;
}
if (FileObject->Flags & FO_SYNCHRONOUS_IO) {
FileObject->CurrentByteOffset.QuadPart += InfoBlock.Info;
Expand Down

0 comments on commit d792860

Please sign in to comment.