[NPFS]
[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 TRACE("Entered\n");
27
28 *Length -= sizeof(*InfoBuffer);
29
30 InfoBuffer->VolumeCreationTime.LowPart = 0;
31 InfoBuffer->VolumeCreationTime.HighPart = 0;
32 InfoBuffer->VolumeSerialNumber = 0;
33 InfoBuffer->SupportsObjects = 0;
34
35 NameLength = 18;
36 InfoBuffer->VolumeLabelLength = 18;
37
38 if (NameLength < 18)
39 {
40 NameLength = (USHORT)*Length;
41 Status = STATUS_BUFFER_OVERFLOW;
42 }
43 else
44 {
45 Status = STATUS_SUCCESS;
46 }
47
48 RtlCopyMemory(InfoBuffer->VolumeLabel, L"Named Pipe", NameLength);
49 *Length -= NameLength;
50
51 TRACE("Leaving, Status = %lx\n", Status);
52 return Status;
53 }
54
55 NTSTATUS
56 NTAPI
57 NpQueryFsSizeInfo(IN PVOID Buffer,
58 IN OUT PULONG Length)
59 {
60 PFILE_FS_SIZE_INFORMATION InfoBuffer = Buffer;
61 TRACE("Entered\n");
62
63 *Length -= sizeof(*InfoBuffer);
64
65 InfoBuffer->TotalAllocationUnits.QuadPart = 0;
66 InfoBuffer->AvailableAllocationUnits.QuadPart = 0;
67 InfoBuffer->SectorsPerAllocationUnit = 1;
68 InfoBuffer->BytesPerSector = 1;
69
70 TRACE("Leaving, Status = STATUS_SUCCESS\n");
71 return STATUS_SUCCESS;
72 }
73
74 NTSTATUS
75 NTAPI
76 NpQueryFsDeviceInfo(IN PVOID Buffer,
77 IN OUT PULONG Length)
78 {
79 PFILE_FS_DEVICE_INFORMATION InfoBuffer = Buffer;
80 NTSTATUS Status;
81 TRACE("Entered\n");
82
83 if (*Length >= sizeof(*InfoBuffer))
84 {
85 InfoBuffer->DeviceType = 0;
86 InfoBuffer->Characteristics = 0;
87 InfoBuffer->DeviceType = FILE_DEVICE_NAMED_PIPE;
88 *Length -= sizeof(*InfoBuffer);
89 Status = STATUS_SUCCESS;
90 }
91 else
92 {
93 Status = STATUS_BUFFER_OVERFLOW;
94 }
95 TRACE("Leaving, Status = %lx\n", Status);
96 return Status;
97 }
98
99 NTSTATUS
100 NTAPI
101 NpQueryFsAttributeInfo(IN PVOID Buffer,
102 IN OUT PULONG Length)
103 {
104 PFILE_FS_ATTRIBUTE_INFORMATION InfoBuffer = Buffer;
105 NTSTATUS Status;
106 USHORT NameLength;
107 TRACE("Entered\n");
108
109 NameLength = (USHORT)(*Length - 12);
110 if (NameLength < 8)
111 {
112 *Length = 0;
113 Status = STATUS_BUFFER_OVERFLOW;
114 }
115 else
116 {
117 *Length -= 20;
118 NameLength = 8;
119 Status = STATUS_SUCCESS;
120 }
121
122 InfoBuffer->MaximumComponentNameLength = 0xFFFFFFFF;
123 InfoBuffer->FileSystemNameLength = 8;
124 InfoBuffer->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES;
125 RtlCopyMemory(InfoBuffer->FileSystemName, L"NPFS", NameLength);
126
127 TRACE("Leaving, Status = %lx\n", Status);
128 return Status;
129 }
130
131 NTSTATUS
132 NTAPI
133 NpQueryFsFullSizeInfo(IN PVOID Buffer,
134 IN OUT PULONG Length)
135 {
136 PFILE_FS_FULL_SIZE_INFORMATION InfoBuffer = Buffer;
137 TRACE("Entered\n");
138
139 *Length -= sizeof(*InfoBuffer);
140
141 RtlZeroMemory(InfoBuffer, sizeof(*InfoBuffer));
142
143 TRACE("Leaving, Status = STATUS_SUCCESS\n");
144 return STATUS_SUCCESS;
145 }
146
147 NTSTATUS
148 NTAPI
149 NpCommonQueryVolumeInformation(IN PDEVICE_OBJECT DeviceObject,
150 IN PIRP Irp)
151 {
152 PIO_STACK_LOCATION IoStack;
153 FS_INFORMATION_CLASS InfoClass;
154 ULONG Length;
155 PVOID Buffer;
156 NTSTATUS Status;
157 PAGED_CODE();
158 TRACE("Entered\n");
159
160 IoStack = IoGetCurrentIrpStackLocation(Irp);
161 Buffer = Irp->AssociatedIrp.SystemBuffer;
162 Length = IoStack->Parameters.QueryVolume.Length;
163 InfoClass = IoStack->Parameters.QueryVolume.FsInformationClass;
164
165 switch (InfoClass)
166 {
167 case FileFsVolumeInformation:
168 Status = NpQueryFsVolumeInfo(Buffer, &Length);
169 break;
170 case FileFsSizeInformation:
171 Status = NpQueryFsSizeInfo(Buffer, &Length);
172 break;
173 case FileFsDeviceInformation:
174 Status = NpQueryFsDeviceInfo(Buffer, &Length);
175 break;
176 case FileFsAttributeInformation:
177 Status = NpQueryFsAttributeInfo(Buffer, &Length);
178 break;
179 case FileFsFullSizeInformation:
180 Status = NpQueryFsFullSizeInfo(Buffer, &Length);
181 break;
182 default:
183 Status = STATUS_NOT_SUPPORTED;
184 break;
185 }
186
187 Irp->IoStatus.Information = IoStack->Parameters.QueryVolume.Length - Length;
188 TRACE("Leaving, Status = %lx\n", Status);
189 return Status;
190 }
191
192 NTSTATUS
193 NTAPI
194 NpFsdQueryVolumeInformation(IN PDEVICE_OBJECT DeviceObject,
195 IN PIRP Irp)
196 {
197 NTSTATUS Status;
198 PAGED_CODE();
199 TRACE("Entered\n");
200
201 FsRtlEnterFileSystem();
202 ExAcquireResourceSharedLite(&NpVcb->Lock, TRUE);
203
204 Status = NpCommonQueryVolumeInformation(DeviceObject, Irp);
205
206 ExReleaseResourceLite(&NpVcb->Lock);
207 FsRtlExitFileSystem();
208
209 if (Status != STATUS_PENDING)
210 {
211 Irp->IoStatus.Status = Status;
212 IoCompleteRequest(Irp, IO_NAMED_PIPE_INCREMENT);
213 }
214
215 TRACE("Leaving, Status = %lx\n", Status);
216 return Status;
217 }
218
219 /* EOF */