2017-09-08 08:02:43 +00:00
|
|
|
/* Copyright (c) Mark Harmstone 2016-17
|
|
|
|
*
|
2016-03-23 20:35:05 +00:00
|
|
|
* This file is part of WinBtrfs.
|
2017-09-08 08:02:43 +00:00
|
|
|
*
|
2016-03-23 20:35:05 +00:00
|
|
|
* WinBtrfs is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public Licence as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the Licence, or
|
|
|
|
* (at your option) any later version.
|
2017-09-08 08:02:43 +00:00
|
|
|
*
|
2016-03-23 20:35:05 +00:00
|
|
|
* WinBtrfs is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public Licence for more details.
|
2017-09-08 08:02:43 +00:00
|
|
|
*
|
2016-03-23 20:35:05 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public Licence
|
|
|
|
* along with WinBtrfs. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include "btrfs_drv.h"
|
|
|
|
|
|
|
|
FAST_IO_DISPATCH FastIoDispatch;
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
_Function_class_(FAST_IO_QUERY_BASIC_INFO)
|
2019-09-01 12:53:20 +00:00
|
|
|
static BOOLEAN __stdcall fast_query_basic_info(PFILE_OBJECT FileObject, BOOLEAN wait, PFILE_BASIC_INFORMATION fbi,
|
|
|
|
PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject) {
|
2016-07-27 19:24:26 +00:00
|
|
|
fcb* fcb;
|
|
|
|
ccb* ccb;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
FsRtlEnterFileSystem();
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
TRACE("(%p, %u, %p, %p, %p)\n", FileObject, wait, fbi, IoStatus, DeviceObject);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
if (!FileObject) {
|
|
|
|
FsRtlExitFileSystem();
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2017-09-08 08:02:43 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
fcb = FileObject->FsContext;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
if (!fcb) {
|
|
|
|
FsRtlExitFileSystem();
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2017-09-08 08:02:43 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
ccb = FileObject->FsContext2;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
if (!ccb) {
|
|
|
|
FsRtlExitFileSystem();
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2017-09-08 08:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(ccb->access & (FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES))) {
|
|
|
|
FsRtlExitFileSystem();
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2017-09-08 08:02:43 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (fcb->ads) {
|
2017-09-08 08:02:43 +00:00
|
|
|
if (!ccb->fileref || !ccb->fileref->parent || !ccb->fileref->parent->fcb) {
|
|
|
|
FsRtlExitFileSystem();
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2017-09-08 08:02:43 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
fcb = ccb->fileref->parent->fcb;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!ExAcquireResourceSharedLite(fcb->Header.Resource, wait)) {
|
|
|
|
FsRtlExitFileSystem();
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2016-07-27 19:24:26 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
if (fcb == fcb->Vcb->dummy_fcb) {
|
|
|
|
LARGE_INTEGER time;
|
|
|
|
|
|
|
|
KeQuerySystemTime(&time);
|
|
|
|
fbi->CreationTime = fbi->LastAccessTime = fbi->LastWriteTime = fbi->ChangeTime = time;
|
|
|
|
} else {
|
|
|
|
fbi->CreationTime.QuadPart = unix_time_to_win(&fcb->inode_item.otime);
|
|
|
|
fbi->LastAccessTime.QuadPart = unix_time_to_win(&fcb->inode_item.st_atime);
|
|
|
|
fbi->LastWriteTime.QuadPart = unix_time_to_win(&fcb->inode_item.st_mtime);
|
|
|
|
fbi->ChangeTime.QuadPart = unix_time_to_win(&fcb->inode_item.st_ctime);
|
|
|
|
}
|
|
|
|
|
|
|
|
fbi->FileAttributes = fcb->atts == 0 ? FILE_ATTRIBUTE_NORMAL : fcb->atts;
|
2016-07-27 19:24:26 +00:00
|
|
|
|
|
|
|
IoStatus->Status = STATUS_SUCCESS;
|
|
|
|
IoStatus->Information = sizeof(FILE_BASIC_INFORMATION);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
ExReleaseResourceLite(fcb->Header.Resource);
|
|
|
|
|
|
|
|
FsRtlExitFileSystem();
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
return true;
|
2016-03-23 20:35:05 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
_Function_class_(FAST_IO_QUERY_STANDARD_INFO)
|
2019-09-01 12:53:20 +00:00
|
|
|
static BOOLEAN __stdcall fast_query_standard_info(PFILE_OBJECT FileObject, BOOLEAN wait, PFILE_STANDARD_INFORMATION fsi,
|
|
|
|
PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject) {
|
2016-07-27 19:24:26 +00:00
|
|
|
fcb* fcb;
|
|
|
|
ccb* ccb;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool ads;
|
2016-07-27 19:24:26 +00:00
|
|
|
ULONG adssize;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
FsRtlEnterFileSystem();
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
TRACE("(%p, %u, %p, %p, %p)\n", FileObject, wait, fsi, IoStatus, DeviceObject);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
if (!FileObject) {
|
|
|
|
FsRtlExitFileSystem();
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2017-09-08 08:02:43 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
fcb = FileObject->FsContext;
|
|
|
|
ccb = FileObject->FsContext2;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
if (!fcb) {
|
|
|
|
FsRtlExitFileSystem();
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2017-09-08 08:02:43 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!ExAcquireResourceSharedLite(fcb->Header.Resource, wait)) {
|
|
|
|
FsRtlExitFileSystem();
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2016-07-27 19:24:26 +00:00
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
ads = fcb->ads;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (ads) {
|
|
|
|
struct _fcb* fcb2;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!ccb || !ccb->fileref || !ccb->fileref->parent || !ccb->fileref->parent->fcb) {
|
|
|
|
ExReleaseResourceLite(fcb->Header.Resource);
|
|
|
|
FsRtlExitFileSystem();
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2016-07-27 19:24:26 +00:00
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
adssize = fcb->adsdata.Length;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
fcb2 = ccb->fileref->parent->fcb;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
ExReleaseResourceLite(fcb->Header.Resource);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
fcb = fcb2;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!ExAcquireResourceSharedLite(fcb->Header.Resource, wait)) {
|
|
|
|
FsRtlExitFileSystem();
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2016-07-27 19:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fsi->AllocationSize.QuadPart = fsi->EndOfFile.QuadPart = adssize;
|
|
|
|
fsi->NumberOfLinks = fcb->inode_item.st_nlink;
|
2019-09-01 12:53:20 +00:00
|
|
|
fsi->Directory = false;
|
2016-07-27 19:24:26 +00:00
|
|
|
} else {
|
2017-09-08 08:02:43 +00:00
|
|
|
fsi->AllocationSize.QuadPart = fcb_alloc_size(fcb);
|
2016-07-27 19:24:26 +00:00
|
|
|
fsi->EndOfFile.QuadPart = S_ISDIR(fcb->inode_item.st_mode) ? 0 : fcb->inode_item.st_size;
|
|
|
|
fsi->NumberOfLinks = fcb->inode_item.st_nlink;
|
|
|
|
fsi->Directory = S_ISDIR(fcb->inode_item.st_mode);
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
fsi->DeletePending = ccb->fileref ? ccb->fileref->delete_on_close : false;
|
2016-07-27 19:24:26 +00:00
|
|
|
|
|
|
|
IoStatus->Status = STATUS_SUCCESS;
|
|
|
|
IoStatus->Information = sizeof(FILE_STANDARD_INFORMATION);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
ExReleaseResourceLite(fcb->Header.Resource);
|
|
|
|
|
|
|
|
FsRtlExitFileSystem();
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
return true;
|
2016-03-23 20:35:05 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
_Function_class_(FAST_IO_CHECK_IF_POSSIBLE)
|
2019-09-01 12:53:20 +00:00
|
|
|
static BOOLEAN __stdcall fast_io_check_if_possible(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait,
|
|
|
|
ULONG LockKey, BOOLEAN CheckForReadOperation, PIO_STATUS_BLOCK IoStatus,
|
|
|
|
PDEVICE_OBJECT DeviceObject) {
|
2016-03-23 20:35:05 +00:00
|
|
|
fcb* fcb = FileObject->FsContext;
|
|
|
|
LARGE_INTEGER len2;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
UNUSED(Wait);
|
|
|
|
UNUSED(IoStatus);
|
|
|
|
UNUSED(DeviceObject);
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
len2.QuadPart = Length;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
if (CheckForReadOperation) {
|
|
|
|
if (FsRtlFastCheckLockForRead(&fcb->lock, FileOffset, &len2, LockKey, FileObject, PsGetCurrentProcess()))
|
2019-09-01 12:53:20 +00:00
|
|
|
return true;
|
2016-03-23 20:35:05 +00:00
|
|
|
} else {
|
2017-09-08 08:02:43 +00:00
|
|
|
if (!fcb->Vcb->readonly && !is_subvol_readonly(fcb->subvol, NULL) && FsRtlFastCheckLockForWrite(&fcb->lock, FileOffset, &len2, LockKey, FileObject, PsGetCurrentProcess()))
|
2019-09-01 12:53:20 +00:00
|
|
|
return true;
|
2016-03-23 20:35:05 +00:00
|
|
|
}
|
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2016-03-23 20:35:05 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
_Function_class_(FAST_IO_QUERY_NETWORK_OPEN_INFO)
|
2019-09-01 12:53:20 +00:00
|
|
|
static BOOLEAN __stdcall fast_io_query_network_open_info(PFILE_OBJECT FileObject, BOOLEAN Wait, FILE_NETWORK_OPEN_INFORMATION* fnoi,
|
|
|
|
PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject) {
|
2017-09-08 08:02:43 +00:00
|
|
|
fcb* fcb;
|
|
|
|
ccb* ccb;
|
|
|
|
file_ref* fileref;
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
FsRtlEnterFileSystem();
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
TRACE("(%p, %u, %p, %p, %p)\n", FileObject, Wait, fnoi, IoStatus, DeviceObject);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
RtlZeroMemory(fnoi, sizeof(FILE_NETWORK_OPEN_INFORMATION));
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
fcb = FileObject->FsContext;
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
if (!fcb || fcb == fcb->Vcb->volume_fcb) {
|
|
|
|
FsRtlExitFileSystem();
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2017-09-08 08:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ccb = FileObject->FsContext2;
|
|
|
|
|
|
|
|
if (!ccb) {
|
|
|
|
FsRtlExitFileSystem();
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2017-09-08 08:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fileref = ccb->fileref;
|
|
|
|
|
|
|
|
if (fcb == fcb->Vcb->dummy_fcb) {
|
|
|
|
LARGE_INTEGER time;
|
|
|
|
|
|
|
|
KeQuerySystemTime(&time);
|
|
|
|
fnoi->CreationTime = fnoi->LastAccessTime = fnoi->LastWriteTime = fnoi->ChangeTime = time;
|
|
|
|
} else {
|
|
|
|
INODE_ITEM* ii;
|
|
|
|
|
|
|
|
if (fcb->ads) {
|
|
|
|
if (!fileref || !fileref->parent) {
|
|
|
|
ERR("no fileref for stream\n");
|
|
|
|
FsRtlExitFileSystem();
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2017-09-08 08:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ii = &fileref->parent->fcb->inode_item;
|
|
|
|
} else
|
|
|
|
ii = &fcb->inode_item;
|
|
|
|
|
|
|
|
fnoi->CreationTime.QuadPart = unix_time_to_win(&ii->otime);
|
|
|
|
fnoi->LastAccessTime.QuadPart = unix_time_to_win(&ii->st_atime);
|
|
|
|
fnoi->LastWriteTime.QuadPart = unix_time_to_win(&ii->st_mtime);
|
|
|
|
fnoi->ChangeTime.QuadPart = unix_time_to_win(&ii->st_ctime);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fcb->ads) {
|
|
|
|
fnoi->AllocationSize.QuadPart = fnoi->EndOfFile.QuadPart = fcb->adsdata.Length;
|
|
|
|
fnoi->FileAttributes = fileref->parent->fcb->atts == 0 ? FILE_ATTRIBUTE_NORMAL : fileref->parent->fcb->atts;
|
|
|
|
} else {
|
|
|
|
fnoi->AllocationSize.QuadPart = fcb_alloc_size(fcb);
|
|
|
|
fnoi->EndOfFile.QuadPart = S_ISDIR(fcb->inode_item.st_mode) ? 0 : fcb->inode_item.st_size;
|
|
|
|
fnoi->FileAttributes = fcb->atts == 0 ? FILE_ATTRIBUTE_NORMAL : fcb->atts;
|
|
|
|
}
|
|
|
|
|
|
|
|
FsRtlExitFileSystem();
|
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
return true;
|
2016-03-23 20:35:05 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
_Function_class_(FAST_IO_ACQUIRE_FOR_MOD_WRITE)
|
2019-09-01 12:53:20 +00:00
|
|
|
static NTSTATUS __stdcall fast_io_acquire_for_mod_write(PFILE_OBJECT FileObject, PLARGE_INTEGER EndingOffset,
|
|
|
|
struct _ERESOURCE **ResourceToRelease, PDEVICE_OBJECT DeviceObject) {
|
2016-09-04 15:27:46 +00:00
|
|
|
fcb* fcb;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
TRACE("(%p, %I64x, %p, %p)\n", FileObject, EndingOffset ? EndingOffset->QuadPart : 0, ResourceToRelease, DeviceObject);
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
UNUSED(EndingOffset);
|
|
|
|
UNUSED(DeviceObject);
|
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
fcb = FileObject->FsContext;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
if (!fcb)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2018-12-16 11:03:16 +00:00
|
|
|
// Make sure we don't get interrupted by the flush thread, which can cause a deadlock
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
if (!ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, false))
|
2016-09-04 15:27:46 +00:00
|
|
|
return STATUS_CANT_WAIT;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
if (!ExAcquireResourceExclusiveLite(fcb->Header.Resource, false)) {
|
|
|
|
ExReleaseResourceLite(&fcb->Vcb->tree_lock);
|
|
|
|
TRACE("returning STATUS_CANT_WAIT\n");
|
|
|
|
return STATUS_CANT_WAIT;
|
|
|
|
}
|
|
|
|
|
2018-12-16 11:03:16 +00:00
|
|
|
// Ideally this would be PagingIoResource, but that doesn't play well with copy-on-write,
|
|
|
|
// as we can't guarantee that we won't need to do any reallocations.
|
|
|
|
|
|
|
|
*ResourceToRelease = fcb->Header.Resource;
|
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
TRACE("returning STATUS_SUCCESS\n");
|
2018-12-16 11:03:16 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
return STATUS_SUCCESS;
|
2016-03-23 20:35:05 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
_Function_class_(FAST_IO_RELEASE_FOR_MOD_WRITE)
|
2019-09-01 12:53:20 +00:00
|
|
|
static NTSTATUS __stdcall fast_io_release_for_mod_write(PFILE_OBJECT FileObject, struct _ERESOURCE *ResourceToRelease,
|
|
|
|
PDEVICE_OBJECT DeviceObject) {
|
2018-12-16 11:03:16 +00:00
|
|
|
fcb* fcb;
|
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
TRACE("(%p, %p, %p)\n", FileObject, ResourceToRelease, DeviceObject);
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
UNUSED(DeviceObject);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2018-12-16 11:03:16 +00:00
|
|
|
fcb = FileObject->FsContext;
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
ExReleaseResourceLite(ResourceToRelease);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2018-12-16 11:03:16 +00:00
|
|
|
ExReleaseResourceLite(&fcb->Vcb->tree_lock);
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
return STATUS_SUCCESS;
|
2016-03-23 20:35:05 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
_Function_class_(FAST_IO_ACQUIRE_FOR_CCFLUSH)
|
2019-09-01 12:53:20 +00:00
|
|
|
static NTSTATUS __stdcall fast_io_acquire_for_ccflush(PFILE_OBJECT FileObject, PDEVICE_OBJECT DeviceObject) {
|
2017-09-08 08:02:43 +00:00
|
|
|
UNUSED(FileObject);
|
|
|
|
UNUSED(DeviceObject);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
IoSetTopLevelIrp((PIRP)FSRTL_CACHE_TOP_LEVEL_IRP);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2016-03-26 11:53:07 +00:00
|
|
|
return STATUS_SUCCESS;
|
2016-03-23 20:35:05 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
_Function_class_(FAST_IO_RELEASE_FOR_CCFLUSH)
|
2019-09-01 12:53:20 +00:00
|
|
|
static NTSTATUS __stdcall fast_io_release_for_ccflush(PFILE_OBJECT FileObject, PDEVICE_OBJECT DeviceObject) {
|
2017-09-08 08:02:43 +00:00
|
|
|
UNUSED(FileObject);
|
|
|
|
UNUSED(DeviceObject);
|
|
|
|
|
|
|
|
if (IoGetTopLevelIrp() == (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP)
|
|
|
|
IoSetTopLevelIrp(NULL);
|
|
|
|
|
2016-03-26 11:53:07 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
_Function_class_(FAST_IO_WRITE)
|
2019-09-01 12:53:20 +00:00
|
|
|
static BOOLEAN __stdcall fast_io_write(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, ULONG LockKey, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject) {
|
2019-11-12 18:32:46 +00:00
|
|
|
fcb* fcb = FileObject->FsContext;
|
|
|
|
bool ret;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
FsRtlEnterFileSystem();
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
if (!ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, Wait)) {
|
|
|
|
FsRtlExitFileSystem();
|
|
|
|
return false;
|
2019-09-01 12:53:20 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
if (!ExAcquireResourceExclusiveLite(fcb->Header.Resource, Wait)) {
|
|
|
|
ExReleaseResourceLite(&fcb->Vcb->tree_lock);
|
|
|
|
FsRtlExitFileSystem();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = FsRtlCopyWrite(FileObject, FileOffset, Length, Wait, LockKey, Buffer, IoStatus, DeviceObject);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
fcb->inode_item.st_size = fcb->Header.FileSize.QuadPart;
|
|
|
|
|
|
|
|
ExReleaseResourceLite(fcb->Header.Resource);
|
|
|
|
ExReleaseResourceLite(&fcb->Vcb->tree_lock);
|
|
|
|
|
|
|
|
FsRtlExitFileSystem();
|
|
|
|
|
|
|
|
return ret;
|
2019-09-01 12:53:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_Function_class_(FAST_IO_LOCK)
|
|
|
|
static BOOLEAN __stdcall fast_io_lock(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, PLARGE_INTEGER Length, PEPROCESS ProcessId,
|
|
|
|
ULONG Key, BOOLEAN FailImmediately, BOOLEAN ExclusiveLock, PIO_STATUS_BLOCK IoStatus,
|
|
|
|
PDEVICE_OBJECT DeviceObject) {
|
|
|
|
BOOLEAN ret;
|
|
|
|
fcb* fcb = FileObject->FsContext;
|
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
TRACE("(%p, %I64x, %I64x, %p, %lx, %u, %u, %p, %p)\n", FileObject, FileOffset ? FileOffset->QuadPart : 0, Length ? Length->QuadPart : 0,
|
2019-09-01 12:53:20 +00:00
|
|
|
ProcessId, Key, FailImmediately, ExclusiveLock, IoStatus, DeviceObject);
|
|
|
|
|
|
|
|
if (fcb->type != BTRFS_TYPE_FILE) {
|
|
|
|
WARN("can only lock files\n");
|
|
|
|
IoStatus->Status = STATUS_INVALID_PARAMETER;
|
|
|
|
IoStatus->Information = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
FsRtlEnterFileSystem();
|
|
|
|
ExAcquireResourceSharedLite(fcb->Header.Resource, true);
|
|
|
|
|
|
|
|
ret = FsRtlFastLock(&fcb->lock, FileObject, FileOffset, Length, ProcessId, Key, FailImmediately,
|
|
|
|
ExclusiveLock, IoStatus, NULL, false);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
|
|
|
|
|
|
|
|
ExReleaseResourceLite(fcb->Header.Resource);
|
|
|
|
FsRtlExitFileSystem();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
_Function_class_(FAST_IO_UNLOCK_SINGLE)
|
|
|
|
static BOOLEAN __stdcall fast_io_unlock_single(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, PLARGE_INTEGER Length, PEPROCESS ProcessId,
|
|
|
|
ULONG Key, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject) {
|
|
|
|
fcb* fcb = FileObject->FsContext;
|
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
TRACE("(%p, %I64x, %I64x, %p, %lx, %p, %p)\n", FileObject, FileOffset ? FileOffset->QuadPart : 0, Length ? Length->QuadPart : 0,
|
2019-09-01 12:53:20 +00:00
|
|
|
ProcessId, Key, IoStatus, DeviceObject);
|
|
|
|
|
|
|
|
IoStatus->Information = 0;
|
|
|
|
|
|
|
|
if (fcb->type != BTRFS_TYPE_FILE) {
|
|
|
|
WARN("can only lock files\n");
|
|
|
|
IoStatus->Status = STATUS_INVALID_PARAMETER;
|
|
|
|
return true;
|
2017-01-01 17:12:12 +00:00
|
|
|
}
|
2016-03-26 11:53:07 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
FsRtlEnterFileSystem();
|
|
|
|
|
|
|
|
IoStatus->Status = FsRtlFastUnlockSingle(&fcb->lock, FileObject, FileOffset, Length, ProcessId, Key, NULL, false);
|
|
|
|
|
|
|
|
fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
|
|
|
|
|
|
|
|
FsRtlExitFileSystem();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_Function_class_(FAST_IO_UNLOCK_ALL)
|
|
|
|
static BOOLEAN __stdcall fast_io_unlock_all(PFILE_OBJECT FileObject, PEPROCESS ProcessId, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject) {
|
|
|
|
fcb* fcb = FileObject->FsContext;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %p, %p)\n", FileObject, ProcessId, IoStatus, DeviceObject);
|
|
|
|
|
|
|
|
IoStatus->Information = 0;
|
|
|
|
|
|
|
|
if (fcb->type != BTRFS_TYPE_FILE) {
|
|
|
|
WARN("can only lock files\n");
|
|
|
|
IoStatus->Status = STATUS_INVALID_PARAMETER;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
FsRtlEnterFileSystem();
|
|
|
|
|
|
|
|
ExAcquireResourceSharedLite(fcb->Header.Resource, true);
|
|
|
|
|
|
|
|
IoStatus->Status = FsRtlFastUnlockAll(&fcb->lock, FileObject, ProcessId, NULL);
|
|
|
|
|
|
|
|
fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
|
|
|
|
|
|
|
|
ExReleaseResourceLite(fcb->Header.Resource);
|
|
|
|
|
|
|
|
FsRtlExitFileSystem();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_Function_class_(FAST_IO_UNLOCK_ALL_BY_KEY)
|
|
|
|
static BOOLEAN __stdcall fast_io_unlock_all_by_key(PFILE_OBJECT FileObject, PVOID ProcessId, ULONG Key,
|
|
|
|
PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject) {
|
|
|
|
fcb* fcb = FileObject->FsContext;
|
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
TRACE("(%p, %p, %lx, %p, %p)\n", FileObject, ProcessId, Key, IoStatus, DeviceObject);
|
2019-09-01 12:53:20 +00:00
|
|
|
|
|
|
|
IoStatus->Information = 0;
|
|
|
|
|
|
|
|
if (fcb->type != BTRFS_TYPE_FILE) {
|
|
|
|
WARN("can only lock files\n");
|
|
|
|
IoStatus->Status = STATUS_INVALID_PARAMETER;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
FsRtlEnterFileSystem();
|
|
|
|
|
|
|
|
ExAcquireResourceSharedLite(fcb->Header.Resource, true);
|
|
|
|
|
|
|
|
IoStatus->Status = FsRtlFastUnlockAllByKey(&fcb->lock, FileObject, ProcessId, Key, NULL);
|
|
|
|
|
|
|
|
fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
|
|
|
|
|
|
|
|
ExReleaseResourceLite(fcb->Header.Resource);
|
|
|
|
|
|
|
|
FsRtlExitFileSystem();
|
|
|
|
|
|
|
|
return true;
|
2016-03-26 11:53:07 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
void init_fast_io_dispatch(FAST_IO_DISPATCH** fiod) {
|
2016-03-23 20:35:05 +00:00
|
|
|
RtlZeroMemory(&FastIoDispatch, sizeof(FastIoDispatch));
|
|
|
|
|
|
|
|
FastIoDispatch.SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH);
|
|
|
|
|
|
|
|
FastIoDispatch.FastIoCheckIfPossible = fast_io_check_if_possible;
|
2019-09-01 12:53:20 +00:00
|
|
|
FastIoDispatch.FastIoRead = FsRtlCopyRead;
|
|
|
|
FastIoDispatch.FastIoWrite = fast_io_write;
|
2016-03-23 20:35:05 +00:00
|
|
|
FastIoDispatch.FastIoQueryBasicInfo = fast_query_basic_info;
|
|
|
|
FastIoDispatch.FastIoQueryStandardInfo = fast_query_standard_info;
|
2019-09-01 12:53:20 +00:00
|
|
|
FastIoDispatch.FastIoLock = fast_io_lock;
|
|
|
|
FastIoDispatch.FastIoUnlockSingle = fast_io_unlock_single;
|
|
|
|
FastIoDispatch.FastIoUnlockAll = fast_io_unlock_all;
|
|
|
|
FastIoDispatch.FastIoUnlockAllByKey = fast_io_unlock_all_by_key;
|
2016-03-23 20:35:05 +00:00
|
|
|
FastIoDispatch.FastIoQueryNetworkOpenInfo = fast_io_query_network_open_info;
|
|
|
|
FastIoDispatch.AcquireForModWrite = fast_io_acquire_for_mod_write;
|
2016-03-26 11:53:07 +00:00
|
|
|
FastIoDispatch.MdlRead = FsRtlMdlReadDev;
|
|
|
|
FastIoDispatch.MdlReadComplete = FsRtlMdlReadCompleteDev;
|
|
|
|
FastIoDispatch.PrepareMdlWrite = FsRtlPrepareMdlWriteDev;
|
|
|
|
FastIoDispatch.MdlWriteComplete = FsRtlMdlWriteCompleteDev;
|
2019-09-01 12:53:20 +00:00
|
|
|
FastIoDispatch.ReleaseForModWrite = fast_io_release_for_mod_write;
|
|
|
|
FastIoDispatch.AcquireForCcFlush = fast_io_acquire_for_ccflush;
|
|
|
|
FastIoDispatch.ReleaseForCcFlush = fast_io_release_for_ccflush;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
*fiod = &FastIoDispatch;
|
2016-03-26 11:53:07 +00:00
|
|
|
}
|