Implemented IRP_MJ_QUERY_VOLUME_INFORMATION/FileFsDeviceInformation. Msvcrt needs to detect the device type.

svn path=/trunk/; revision=17292
This commit is contained in:
Hartmut Birr 2005-08-11 19:07:11 +00:00
parent 77b9c0a70d
commit 2acde8450d

View file

@ -26,90 +26,119 @@ static const NULL_EXTENSION nxZero = NullZeroStream;
NTSTATUS STDCALL NTSTATUS STDCALL
NullDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp) NullDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{ {
PIO_STACK_LOCATION piosStack = IoGetCurrentIrpStackLocation(Irp); PIO_STACK_LOCATION piosStack = IoGetCurrentIrpStackLocation(Irp);
NTSTATUS nErrCode; NTSTATUS nErrCode;
nErrCode = STATUS_SUCCESS; nErrCode = STATUS_SUCCESS;
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
switch(piosStack->MajorFunction) switch(piosStack->MajorFunction)
{ {
/* opening and closing handles to the device */ /* opening and closing handles to the device */
case IRP_MJ_CREATE: case IRP_MJ_CREATE:
case IRP_MJ_CLOSE: case IRP_MJ_CLOSE:
switch(NULL_DEVICE_TYPE(DeviceObject)) switch(NULL_DEVICE_TYPE(DeviceObject))
{ {
case NullBitBucket: case NullBitBucket:
case NullZeroStream: case NullZeroStream:
break; break;
default: default:
ASSERT(FALSE); ASSERT(FALSE);
} }
break; break;
/* write data */ /* write data */
case IRP_MJ_WRITE: case IRP_MJ_WRITE:
{ {
switch(NULL_DEVICE_TYPE(DeviceObject)) switch(NULL_DEVICE_TYPE(DeviceObject))
{ {
case NullBitBucket: case NullBitBucket:
Irp->IoStatus.Information = piosStack->Parameters.Write.Length; Irp->IoStatus.Information = piosStack->Parameters.Write.Length;
break; break;
case NullZeroStream: case NullZeroStream:
nErrCode = STATUS_INVALID_DEVICE_REQUEST; nErrCode = STATUS_INVALID_DEVICE_REQUEST;
break; break;
default: default:
ASSERT(FALSE); ASSERT(FALSE);
} }
break; break;
} }
/* read data */ /* read data */
case IRP_MJ_READ: case IRP_MJ_READ:
{ {
switch(NULL_DEVICE_TYPE(DeviceObject)) switch(NULL_DEVICE_TYPE(DeviceObject))
{ {
case NullBitBucket: case NullBitBucket:
nErrCode = STATUS_END_OF_FILE; nErrCode = STATUS_END_OF_FILE;
break; break;
case NullZeroStream: case NullZeroStream:
_SEH_TRY _SEH_TRY
{ {
RtlZeroMemory(Irp->AssociatedIrp.SystemBuffer, piosStack->Parameters.Read.Length); RtlZeroMemory(Irp->AssociatedIrp.SystemBuffer, piosStack->Parameters.Read.Length);
Irp->IoStatus.Information = piosStack->Parameters.Read.Length; Irp->IoStatus.Information = piosStack->Parameters.Read.Length;
} }
_SEH_HANDLE _SEH_HANDLE
{ {
nErrCode = _SEH_GetExceptionCode(); nErrCode = _SEH_GetExceptionCode();
} }
_SEH_END; _SEH_END;
break; break;
default: default:
ASSERT(FALSE); ASSERT(FALSE);
} }
break; break;
} }
default: case IRP_MJ_QUERY_VOLUME_INFORMATION:
Irp->IoStatus.Information = 0; switch(piosStack->Parameters.QueryVolume.FsInformationClass)
nErrCode = STATUS_NOT_IMPLEMENTED; {
case FileFsDeviceInformation:
{
ULONG BufferLength = piosStack->Parameters.QueryVolume.Length;
PFILE_FS_DEVICE_INFORMATION FsDeviceInfo = (PFILE_FS_DEVICE_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
} if (BufferLength >= sizeof(FILE_FS_DEVICE_INFORMATION))
{
FsDeviceInfo->DeviceType = FILE_DEVICE_NULL;
FsDeviceInfo->Characteristics = 0; /* FIXME: fix this !! */
Irp->IoStatus.Information = sizeof(FILE_FS_DEVICE_INFORMATION);
nErrCode = STATUS_SUCCESS;
}
else
{
Irp->IoStatus.Information = 0;
nErrCode = STATUS_BUFFER_OVERFLOW;
}
}
break;
Irp->IoStatus.Status = nErrCode; default:
IoCompleteRequest(Irp, IO_NO_INCREMENT); Irp->IoStatus.Information = 0;
nErrCode = STATUS_NOT_IMPLEMENTED;
}
break;
return (nErrCode); default:
Irp->IoStatus.Information = 0;
nErrCode = STATUS_NOT_IMPLEMENTED;
}
Irp->IoStatus.Status = nErrCode;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return (nErrCode);
} }
VOID STDCALL VOID STDCALL
@ -121,62 +150,56 @@ NullUnload(PDRIVER_OBJECT DriverObject)
NTSTATUS STDCALL NTSTATUS STDCALL
DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{ {
PDEVICE_OBJECT pdoNullDevice; PDEVICE_OBJECT pdoNullDevice;
PDEVICE_OBJECT pdoZeroDevice; PDEVICE_OBJECT pdoZeroDevice;
UNICODE_STRING wstrNullDeviceName = RTL_CONSTANT_STRING(L"\\Device\\Null"); UNICODE_STRING wstrNullDeviceName = RTL_CONSTANT_STRING(L"\\Device\\Null");
UNICODE_STRING wstrZeroDeviceName = RTL_CONSTANT_STRING(L"\\Device\\Zero"); UNICODE_STRING wstrZeroDeviceName = RTL_CONSTANT_STRING(L"\\Device\\Zero");
NTSTATUS nErrCode; NTSTATUS nErrCode;
/* register driver routines */ /* register driver routines */
DriverObject->MajorFunction[IRP_MJ_CLOSE] = NullDispatch; DriverObject->MajorFunction[IRP_MJ_CLOSE] = NullDispatch;
DriverObject->MajorFunction[IRP_MJ_CREATE] = NullDispatch; DriverObject->MajorFunction[IRP_MJ_CREATE] = NullDispatch;
DriverObject->MajorFunction[IRP_MJ_WRITE] = NullDispatch; DriverObject->MajorFunction[IRP_MJ_WRITE] = NullDispatch;
DriverObject->MajorFunction[IRP_MJ_READ] = NullDispatch; DriverObject->MajorFunction[IRP_MJ_READ] = NullDispatch;
DriverObject->DriverUnload = NullUnload; DriverObject->DriverUnload = NullUnload;
/* create null device */ /* create null device */
nErrCode = IoCreateDevice nErrCode = IoCreateDevice(DriverObject,
( sizeof(NULL_EXTENSION),
DriverObject, &wstrNullDeviceName,
sizeof(NULL_EXTENSION), FILE_DEVICE_NULL,
&wstrNullDeviceName, 0,
FILE_DEVICE_NULL, FALSE,
0, &pdoNullDevice);
FALSE,
&pdoNullDevice
);
/* failure */ /* failure */
if(!NT_SUCCESS(nErrCode)) if(!NT_SUCCESS(nErrCode))
{ {
return (nErrCode); return (nErrCode);
} }
pdoNullDevice->DeviceExtension = (PVOID)&nxNull; pdoNullDevice->DeviceExtension = (PVOID)&nxNull;
/* create zero device */ /* create zero device */
nErrCode = IoCreateDevice nErrCode = IoCreateDevice(DriverObject,
( sizeof(NULL_EXTENSION),
DriverObject, &wstrZeroDeviceName,
sizeof(NULL_EXTENSION), FILE_DEVICE_NULL,
&wstrZeroDeviceName, FILE_READ_ONLY_DEVICE, /* zero device is read-only */
FILE_DEVICE_NULL, FALSE,
FILE_READ_ONLY_DEVICE, /* zero device is read-only */ &pdoZeroDevice);
FALSE,
&pdoZeroDevice
);
/* failure */ /* failure */
if(!NT_SUCCESS(nErrCode)) if(!NT_SUCCESS(nErrCode))
{ {
IoDeleteDevice(pdoNullDevice); IoDeleteDevice(pdoNullDevice);
return (nErrCode); return (nErrCode);
} }
pdoZeroDevice->DeviceExtension = (PVOID)&nxZero; pdoZeroDevice->DeviceExtension = (PVOID)&nxZero;
pdoZeroDevice->Flags |= DO_BUFFERED_IO; pdoZeroDevice->Flags |= DO_BUFFERED_IO;
return (nErrCode); return (nErrCode);
} }
/* EOF */ /* EOF */