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