xref: /reactos/drivers/serial/serial/info.c (revision c2c66aff)
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         Serial port driver
4  * FILE:            drivers/dd/serial/info.c
5  * PURPOSE:         Serial IRP_MJ_QUERY_INFORMATION operations
6  *
7  * PROGRAMMERS:     Herv� Poussineau (hpoussin@reactos.org)
8  */
9 
10 #include "serial.h"
11 
12 #include <debug.h>
13 
14 NTSTATUS NTAPI
SerialQueryInformation(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)15 SerialQueryInformation(
16 	IN PDEVICE_OBJECT DeviceObject,
17 	IN PIRP Irp)
18 {
19 	PIO_STACK_LOCATION Stack;
20 	PVOID SystemBuffer;
21 	ULONG BufferLength;
22 	ULONG_PTR Information = 0;
23 	NTSTATUS Status;
24 
25 	Stack = IoGetCurrentIrpStackLocation(Irp);
26 	SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
27 	BufferLength = Stack->Parameters.QueryFile.Length;
28 
29 	switch (Stack->Parameters.QueryFile.FileInformationClass)
30 	{
31 		case FileStandardInformation:
32 		{
33 			PFILE_STANDARD_INFORMATION StandardInfo = (PFILE_STANDARD_INFORMATION)SystemBuffer;
34 
35 			TRACE_(SERIAL, "IRP_MJ_QUERY_INFORMATION / FileStandardInformation\n");
36 			if (BufferLength < sizeof(FILE_STANDARD_INFORMATION))
37 				Status = STATUS_BUFFER_OVERFLOW;
38 			else if (!StandardInfo)
39 				Status = STATUS_INVALID_PARAMETER;
40 			else
41 			{
42 				StandardInfo->AllocationSize.QuadPart = 0;
43 				StandardInfo->EndOfFile.QuadPart = 0;
44 				StandardInfo->Directory = FALSE;
45 				StandardInfo->NumberOfLinks = 0;
46 				StandardInfo->DeletePending = FALSE; /* FIXME: should be TRUE sometimes */
47 				Information = sizeof(FILE_STANDARD_INFORMATION);
48 				Status = STATUS_SUCCESS;
49 			}
50 			break;
51 		}
52 		case FilePositionInformation:
53 		{
54 			PFILE_POSITION_INFORMATION PositionInfo = (PFILE_POSITION_INFORMATION)SystemBuffer;
55 
56 			ASSERT(PositionInfo);
57 
58 			TRACE_(SERIAL, "IRP_MJ_QUERY_INFORMATION / FilePositionInformation\n");
59 			if (BufferLength < sizeof(FILE_POSITION_INFORMATION))
60 				Status = STATUS_BUFFER_OVERFLOW;
61 			else if (!PositionInfo)
62 				Status = STATUS_INVALID_PARAMETER;
63 			else
64 			{
65 				PositionInfo->CurrentByteOffset.QuadPart = 0;
66 				Information = sizeof(FILE_POSITION_INFORMATION);
67 				Status = STATUS_SUCCESS;
68 			}
69 			break;
70 		}
71 		default:
72 		{
73 			TRACE_(SERIAL, "IRP_MJ_QUERY_INFORMATION: Unexpected file information class 0x%02x\n", Stack->Parameters.QueryFile.FileInformationClass);
74 			return ForwardIrpAndForget(DeviceObject, Irp);
75 		}
76 	}
77 
78 	Irp->IoStatus.Information = Information;
79 	Irp->IoStatus.Status = Status;
80 	IoCompleteRequest(Irp, IO_NO_INCREMENT);
81 	return Status;
82 }
83