inc,sys,tst: FSP_FSCTL_VOLUME_PARAMS: fine-grained timeouts

This commit is contained in:
Bill Zissimopoulos
2018-04-21 11:53:14 -07:00
parent 5d34a3bd8c
commit 9501b5771d
7 changed files with 129 additions and 45 deletions

View File

@ -31,7 +31,7 @@ FSP_API NTSTATUS FspFsctlCreateVolume(PWSTR DevicePath,
{
NTSTATUS Result;
PWSTR DeviceRoot;
SIZE_T DeviceRootSize, DevicePathSize;
SIZE_T DeviceRootSize, DevicePathSize, VolumeParamsSize;
WCHAR DevicePathBuf[MAX_PATH + sizeof *VolumeParams], *DevicePathPtr, *DevicePathEnd;
HANDLE VolumeHandle = INVALID_HANDLE_VALUE;
DWORD Bytes;
@ -55,8 +55,11 @@ FSP_API NTSTATUS FspFsctlCreateVolume(PWSTR DevicePath,
memcpy(DevicePathPtr, DevicePath, DevicePathSize);
DevicePathPtr = (PVOID)((PUINT8)DevicePathPtr + DevicePathSize);
memcpy(DevicePathPtr, PREFIXW, PREFIXW_SIZE);
VolumeParamsSize = 0 == VolumeParams->Version ?
sizeof(FSP_FSCTL_VOLUME_PARAMS_V0) :
VolumeParams->Version;
DevicePathPtr = (PVOID)((PUINT8)DevicePathPtr + PREFIXW_SIZE);
DevicePathEnd = (PVOID)((PUINT8)DevicePathPtr + sizeof *VolumeParams * sizeof(WCHAR));
DevicePathEnd = (PVOID)((PUINT8)DevicePathPtr + VolumeParamsSize * sizeof(WCHAR));
for (PUINT8 VolumeParamsPtr = (PVOID)VolumeParams;
DevicePathEnd > DevicePathPtr; DevicePathPtr++, VolumeParamsPtr++)
{

View File

@ -346,7 +346,7 @@ static NTSTATUS FspFsvolDeviceInit(PDEVICE_OBJECT DeviceObject)
FsvolDeviceExtension->InitDoneIoq = 1;
/* create our security meta cache */
SecurityTimeout.QuadPart = FspTimeoutFromMillis(FsvolDeviceExtension->VolumeParams.FileInfoTimeout);
SecurityTimeout.QuadPart = FspTimeoutFromMillis(FsvolDeviceExtension->VolumeParams.SecurityTimeout);
/* convert millis to nanos */
Result = FspMetaCacheCreate(
FspFsvolDeviceSecurityCacheCapacity, FspFsvolDeviceSecurityCacheItemSizeMax, &SecurityTimeout,
@ -356,7 +356,7 @@ static NTSTATUS FspFsvolDeviceInit(PDEVICE_OBJECT DeviceObject)
FsvolDeviceExtension->InitDoneSec = 1;
/* create our directory meta cache */
DirInfoTimeout.QuadPart = FspTimeoutFromMillis(FsvolDeviceExtension->VolumeParams.FileInfoTimeout);
DirInfoTimeout.QuadPart = FspTimeoutFromMillis(FsvolDeviceExtension->VolumeParams.DirInfoTimeout);
/* convert millis to nanos */
Result = FspMetaCacheCreate(
FspFsvolDeviceDirInfoCacheCapacity, FspFsvolDeviceDirInfoCacheItemSizeMax, &DirInfoTimeout,
@ -366,7 +366,7 @@ static NTSTATUS FspFsvolDeviceInit(PDEVICE_OBJECT DeviceObject)
FsvolDeviceExtension->InitDoneDir = 1;
/* create our stream info meta cache */
StreamInfoTimeout.QuadPart = FspTimeoutFromMillis(FsvolDeviceExtension->VolumeParams.FileInfoTimeout);
StreamInfoTimeout.QuadPart = FspTimeoutFromMillis(FsvolDeviceExtension->VolumeParams.StreamInfoTimeout);
/* convert millis to nanos */
Result = FspMetaCacheCreate(
FspFsvolDeviceStreamInfoCacheCapacity, FspFsvolDeviceStreamInfoCacheItemSizeMax, &StreamInfoTimeout,
@ -873,7 +873,7 @@ VOID FspFsvolDeviceSetVolumeInfo(PDEVICE_OBJECT DeviceObject, const FSP_FSCTL_VO
KeAcquireSpinLock(&FsvolDeviceExtension->InfoSpinLock, &Irql);
FsvolDeviceExtension->VolumeInfo = VolumeInfoNp;
FsvolDeviceExtension->InfoExpirationTime = FspExpirationTimeFromMillis(
FsvolDeviceExtension->VolumeParams.FileInfoTimeout);
FsvolDeviceExtension->VolumeParams.VolumeInfoTimeout);
KeReleaseSpinLock(&FsvolDeviceExtension->InfoSpinLock, Irql);
}

View File

@ -551,7 +551,7 @@ static NTSTATUS FspFsvolQueryDirectoryRetry(
FsvolDeviceExtension->VolumeParams.MaxComponentLength * sizeof(WCHAR);
QueryDirectoryLengthMin = FSP_FSCTL_ALIGN_UP(QueryDirectoryLengthMin, 8);
ASSERT(QueryDirectoryLengthMin < FspFsvolQueryDirectoryLengthMax);
if (0 != FsvolDeviceExtension->VolumeParams.FileInfoTimeout &&
if (0 != FsvolDeviceExtension->VolumeParams.DirInfoTimeout &&
0 == FileDesc->DirectoryMarker.Buffer)
{
if (PatternIsFileName)

View File

@ -101,18 +101,26 @@ static NTSTATUS FspVolumeCreateNoLock(
FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension;
/* check parameters */
if (PREFIXW_SIZE + sizeof(FSP_FSCTL_VOLUME_PARAMS) * sizeof(WCHAR) > FileObject->FileName.Length)
if (PREFIXW_SIZE + sizeof(FSP_FSCTL_VOLUME_PARAMS_V0) * sizeof(WCHAR) > FileObject->FileName.Length)
return STATUS_INVALID_PARAMETER;
/* copy the VolumeParams */
for (USHORT Index = 0, Length = sizeof(FSP_FSCTL_VOLUME_PARAMS); Length > Index; Index++)
{
if (PREFIXW_SIZE / sizeof(WCHAR) + Index >= FileObject->FileName.Length / sizeof(WCHAR))
break;
WCHAR Value = FileObject->FileName.Buffer[PREFIXW_SIZE / sizeof(WCHAR) + Index];
if (0xF000 != (Value & 0xFF00))
return STATUS_INVALID_PARAMETER;
((PUINT8)&VolumeParams)[Index] = Value & 0xFF;
}
/* check VolumeParams size */
if (0 != VolumeParams.Version &&
PREFIXW_SIZE + VolumeParams.Version * sizeof(WCHAR) != FileObject->FileName.Length)
return STATUS_INVALID_PARAMETER;
/* check the VolumeParams */
if (0 == VolumeParams.SectorSize)
VolumeParams.SectorSize = 512;
@ -133,6 +141,28 @@ static NTSTATUS FspVolumeCreateNoLock(
if (FspFsctlIrpCapacityMinimum > VolumeParams.IrpCapacity ||
VolumeParams.IrpCapacity > FspFsctlIrpCapacityMaximum)
VolumeParams.IrpCapacity = FspFsctlIrpCapacityDefault;
if (sizeof(FSP_FSCTL_VOLUME_PARAMS_V0) >= VolumeParams.Version)
{
VolumeParams.VolumeInfoTimeout = VolumeParams.FileInfoTimeout;
VolumeParams.DirInfoTimeout = VolumeParams.FileInfoTimeout;
VolumeParams.SecurityTimeout = VolumeParams.FileInfoTimeout;
VolumeParams.StreamInfoTimeout = VolumeParams.FileInfoTimeout;
}
else
{
if (!VolumeParams.VolumeInfoTimeoutValid)
VolumeParams.VolumeInfoTimeout = VolumeParams.FileInfoTimeout;
if (!VolumeParams.DirInfoTimeoutValid)
VolumeParams.DirInfoTimeout = VolumeParams.FileInfoTimeout;
if (!VolumeParams.SecurityTimeoutValid)
VolumeParams.SecurityTimeout = VolumeParams.FileInfoTimeout;
if (!VolumeParams.StreamInfoTimeoutValid)
VolumeParams.StreamInfoTimeout = VolumeParams.FileInfoTimeout;
}
VolumeParams.VolumeInfoTimeoutValid = 1;
VolumeParams.DirInfoTimeoutValid = 1;
VolumeParams.SecurityTimeoutValid = 1;
VolumeParams.StreamInfoTimeoutValid = 1;
if (FILE_DEVICE_NETWORK_FILE_SYSTEM == FsctlDeviceObject->DeviceType)
{
VolumeParams.Prefix[sizeof VolumeParams.Prefix / sizeof(WCHAR) - 1] = L'\0';