79e8471b232508926edfe5061ed664a6aabc56d9
[reactos.git] / reactos / drivers / filesystems / npfs / volinfo.c
1 /*
2 * PROJECT: ReactOS Named Pipe FileSystem
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/filesystems/npfs/volinfo.c
5 * PURPOSE: Named Pipe FileSystem Volume Information
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include "npfs.h"
12
13 // File ID number for NPFS bugchecking support
14 #define NPFS_BUGCHECK_FILE_ID (NPFS_BUGCHECK_VOLINFO)
15
16 /* FUNCTIONS ******************************************************************/
17
18 NTSTATUS
19 NTAPI
20 NpQueryFsVolumeInfo(IN PVOID Buffer,
21 IN OUT PULONG Length)
22 {
23 PFILE_FS_VOLUME_INFORMATION InfoBuffer = Buffer;
24 NTSTATUS Status;
25 USHORT NameLength;
26
27 *Length -= sizeof(*InfoBuffer);
28
29 InfoBuffer->VolumeCreationTime.LowPart = 0;
30 InfoBuffer->VolumeCreationTime.HighPart = 0;
31 InfoBuffer->VolumeSerialNumber = 0;
32 InfoBuffer->SupportsObjects = 0;
33
34 NameLength = 18;
35 InfoBuffer->VolumeLabelLength = 18;
36
37 if (NameLength < 18)
38 {
39 NameLength = (USHORT)*Length;
40 Status = STATUS_BUFFER_OVERFLOW;
41 }
42 else
43 {
44 Status = STATUS_SUCCESS;
45 }
46
47 RtlCopyMemory(InfoBuffer->VolumeLabel, L"Named Pipe", NameLength);
48 *Length -= NameLength;
49
50 return Status;
51 }
52
53 NTSTATUS
54 NTAPI
55 NpQueryFsSizeInfo(IN PVOID Buffer,
56 IN OUT PULONG Length)
57 {
58 PFILE_FS_SIZE_INFORMATION InfoBuffer = Buffer;
59
60 *Length -= sizeof(*InfoBuffer);
61
62 InfoBuffer->TotalAllocationUnits.QuadPart = 0;
63 InfoBuffer->AvailableAllocationUnits.QuadPart = 0;
64 InfoBuffer->SectorsPerAllocationUnit = 1;
65 InfoBuffer->BytesPerSector = 1;
66
67 return STATUS_SUCCESS;
68 }
69
70 NTSTATUS
71 NTAPI
72 NpQueryFsDeviceInfo(IN PVOID Buffer,
73 IN OUT PULONG Length)
74 {
75 PFILE_FS_DEVICE_INFORMATION InfoBuffer = Buffer;
76 NTSTATUS Status;
77
78 if (*Length >= sizeof(*InfoBuffer))
79 {
80 InfoBuffer->DeviceType = 0;
81 InfoBuffer->Characteristics = 0;
82 InfoBuffer->DeviceType = FILE_DEVICE_NAMED_PIPE;
83 *Length -= sizeof(*InfoBuffer);
84 Status = STATUS_SUCCESS;
85 }
86 else
87 {
88 Status = STATUS_BUFFER_OVERFLOW;
89 }
90 return Status;
91 }
92
93 NTSTATUS
94 NTAPI
95 NpQueryFsAttributeInfo(IN PVOID Buffer,
96 IN OUT PULONG Length)
97 {
98 PFILE_FS_ATTRIBUTE_INFORMATION InfoBuffer = Buffer;
99 NTSTATUS Status;
100 USHORT NameLength;
101
102 NameLength = (USHORT)(*Length - 12);
103 if (NameLength < 8)
104 {
105 *Length = 0;
106 Status = STATUS_BUFFER_OVERFLOW;
107 }
108 else
109 {
110 *Length -= 20;
111 NameLength = 8;
112 Status = STATUS_SUCCESS;
113 }
114
115 InfoBuffer->MaximumComponentNameLength = 0xFFFFFFFF;
116 InfoBuffer->FileSystemNameLength = 8;
117 InfoBuffer->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES;
118 RtlCopyMemory(InfoBuffer->FileSystemName, L"NPFS", NameLength);
119
120 return Status;
121 }
122
123 NTSTATUS
124 NTAPI
125 NpQueryFsFullSizeInfo(IN PVOID Buffer,
126 IN OUT PULONG Length)
127 {
128 PFILE_FS_FULL_SIZE_INFORMATION InfoBuffer = Buffer;
129
130 *Length -= sizeof(*InfoBuffer);
131
132 RtlZeroMemory(InfoBuffer, sizeof(*InfoBuffer));
133
134 return STATUS_SUCCESS;
135 }
136
137 NTSTATUS
138 NTAPI
139 NpCommonQueryVolumeInformation(IN PDEVICE_OBJECT DeviceObject,
140 IN PIRP Irp)
141 {
142 PIO_STACK_LOCATION IoStack;
143 FS_INFORMATION_CLASS InfoClass;
144 ULONG Length;
145 PVOID Buffer;
146 NTSTATUS Status;
147 PAGED_CODE();
148
149 IoStack = IoGetCurrentIrpStackLocation(Irp);
150 Buffer = Irp->AssociatedIrp.SystemBuffer;
151 Length = IoStack->Parameters.QueryVolume.Length;
152 InfoClass = IoStack->Parameters.QueryVolume.FsInformationClass;
153
154 switch (InfoClass)
155 {
156 case FileFsVolumeInformation:
157 Status = NpQueryFsVolumeInfo(Buffer, &Length);
158 break;
159 case FileFsSizeInformation:
160 Status = NpQueryFsSizeInfo(Buffer, &Length);
161 break;
162 case FileFsDeviceInformation:
163 Status = NpQueryFsDeviceInfo(Buffer, &Length);
164 break;
165 case FileFsAttributeInformation:
166 Status = NpQueryFsAttributeInfo(Buffer, &Length);
167 break;
168 case FileFsFullSizeInformation:
169 Status = NpQueryFsFullSizeInfo(Buffer, &Length);
170 break;
171 default:
172 Status = STATUS_NOT_SUPPORTED;
173 break;
174 }
175
176 Irp->IoStatus.Information = IoStack->Parameters.QueryVolume.Length - Length;
177 return Status;
178 }
179
180 NTSTATUS
181 NTAPI
182 NpFsdQueryVolumeInformation(IN PDEVICE_OBJECT DeviceObject,
183 IN PIRP Irp)
184 {
185 NTSTATUS Status;
186 PAGED_CODE();
187
188 FsRtlEnterFileSystem();
189 ExAcquireResourceSharedLite(&NpVcb->Lock, TRUE);
190
191 Status = NpCommonQueryVolumeInformation(DeviceObject, Irp);
192
193 ExReleaseResourceLite(&NpVcb->Lock);
194 FsRtlExitFileSystem();
195
196 if (Status != STATUS_PENDING)
197 {
198 Irp->IoStatus.Status = Status;
199 IoCompleteRequest(Irp, IO_NAMED_PIPE_INCREMENT);
200 }
201
202 return Status;
203 }
204
205 /* EOF */