ReactOS  0.4.14-dev-114-gc8cbd56
fileinfo.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Named Pipe FileSystem
3  * LICENSE: BSD - See COPYING.ARM in the top level directory
4  * FILE: drivers/filesystems/npfs/fileinfo.c
5  * PURPOSE: Pipes 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_FILEINFO)
15 
16 /* FUNCTIONS ******************************************************************/
17 
19 NTAPI
22 {
23  PAGED_CODE();
24  return STATUS_SUCCESS;
25 }
26 
28 NTAPI
30  IN PNP_CCB Ccb,
32  IN ULONG NamedPipeEnd,
34 {
36  PNP_DATA_QUEUE ReadQueue, WriteQueue;
37  PAGED_CODE();
38 
39  if (Buffer->ReadMode == FILE_PIPE_MESSAGE_MODE && Fcb->NamedPipeType == FILE_PIPE_BYTE_STREAM_TYPE)
40  {
42  }
43 
44  if (NamedPipeEnd != FILE_PIPE_CLIENT_END)
45  {
46  if (NamedPipeEnd != FILE_PIPE_SERVER_END)
47  {
48  NpBugCheck(NamedPipeEnd, 0, 0);
49  }
50  ReadQueue = &Ccb->DataQueue[FILE_PIPE_INBOUND];
51  WriteQueue = &Ccb->DataQueue[FILE_PIPE_OUTBOUND];
52  }
53  else
54  {
55  ReadQueue = &Ccb->DataQueue[FILE_PIPE_OUTBOUND];
56  WriteQueue = &Ccb->DataQueue[FILE_PIPE_INBOUND];
57  }
58 
59  if (Buffer->CompletionMode != FILE_PIPE_COMPLETE_OPERATION ||
60  Ccb->CompletionMode[NamedPipeEnd] == FILE_PIPE_COMPLETE_OPERATION ||
61  (ReadQueue->QueueState != ReadEntries &&
62  WriteQueue->QueueState != WriteEntries))
63  {
64  Ccb->ReadMode[NamedPipeEnd] = Buffer->ReadMode & 0xFF;
65  Ccb->CompletionMode[NamedPipeEnd] = Buffer->CompletionMode & 0xFF;
66 
69  }
70  else
71  {
73  }
74 
75  return Status;
76 }
77 
79 NTAPI
81  IN PIRP Irp,
83 {
84  NODE_TYPE_CODE NodeTypeCode;
85  PIO_STACK_LOCATION IoStack;
86  ULONG InfoClass;
87  PVOID Buffer;
88  PNP_FCB Fcb;
89  PNP_CCB Ccb;
90  ULONG NamedPipeEnd;
91  PAGED_CODE();
92 
94 
95  NodeTypeCode = NpDecodeFileObject(IoStack->FileObject,
96  (PVOID*)&Fcb,
97  &Ccb,
98  &NamedPipeEnd);
99  if (!NodeTypeCode) return STATUS_PIPE_DISCONNECTED;
100  if (NodeTypeCode != NPFS_NTC_CCB) return STATUS_INVALID_PARAMETER;
101 
102  InfoClass = IoStack->Parameters.QueryFile.FileInformationClass;
103  Buffer = Irp->AssociatedIrp.SystemBuffer;
104 
105  if (InfoClass == FileBasicInformation) return NpSetBasicInfo(Ccb, Buffer);
106 
107  if (InfoClass != FilePipeInformation) return STATUS_INVALID_PARAMETER;
108 
109  return NpSetPipeInfo(Fcb, Ccb, Buffer, NamedPipeEnd, List);
110 }
111 
112 NTSTATUS
113 NTAPI
115  IN PIRP Irp)
116 {
118  LIST_ENTRY DeferredList;
119  PAGED_CODE();
120 
121  InitializeListHead(&DeferredList);
122 
125 
126  Status = NpCommonSetInformation(DeviceObject, Irp, &DeferredList);
127 
128  NpReleaseVcb();
129  NpCompleteDeferredIrps(&DeferredList);
131 
132  if (Status != STATUS_PENDING)
133  {
134  Irp->IoStatus.Status = Status;
136  }
137 
138  return Status;
139 }
140 
141 NTSTATUS
142 NTAPI
144  IN PVOID Buffer,
146 {
147  PFILE_BASIC_INFORMATION InfoBuffer = Buffer;
148 
149  *Length -= sizeof(*InfoBuffer);
150 
151  RtlZeroMemory(InfoBuffer, sizeof(*InfoBuffer));
153 
154  return STATUS_SUCCESS;
155 }
156 
157 NTSTATUS
158 NTAPI
160  IN PVOID Buffer,
162  IN ULONG NamedPipeEnd)
163 {
164  PNP_DATA_QUEUE DataQueue;
165  PFILE_STANDARD_INFORMATION InfoBuffer = Buffer;
166 
167  *Length -= sizeof(*InfoBuffer);
168 
169  RtlZeroMemory(InfoBuffer, sizeof(*InfoBuffer));
170 
171  if (NamedPipeEnd == FILE_PIPE_SERVER_END)
172  {
173  DataQueue = &Ccb->DataQueue[FILE_PIPE_INBOUND];
174  }
175  else
176  {
177  DataQueue = &Ccb->DataQueue[FILE_PIPE_OUTBOUND];
178  }
179 
180  InfoBuffer->AllocationSize.LowPart = Ccb->DataQueue[FILE_PIPE_INBOUND].Quota +
181  Ccb->DataQueue[FILE_PIPE_OUTBOUND].Quota;
182  InfoBuffer->AllocationSize.HighPart = 0;
183 
184  if (DataQueue->QueueState == WriteEntries)
185  {
186  InfoBuffer->EndOfFile.HighPart = 0;
187  InfoBuffer->EndOfFile.LowPart = DataQueue->BytesInQueue -
188  DataQueue->ByteOffset;
189  }
190 
191  InfoBuffer->Directory = FALSE;
192  InfoBuffer->NumberOfLinks = 1;
193  InfoBuffer->DeletePending = TRUE;
194 
195  return STATUS_SUCCESS;
196 }
197 
198 NTSTATUS
199 NTAPI
201  IN PVOID Buffer,
203 {
204  PFILE_EA_INFORMATION InfoBuffer = Buffer;
205 
206  *Length -= sizeof(*InfoBuffer);
207 
208  RtlZeroMemory(InfoBuffer, sizeof(*InfoBuffer));
209 
210  return STATUS_SUCCESS;
211 }
212 
213 NTSTATUS
214 NTAPI
216  IN PVOID Buffer,
218 {
219  PFILE_NAME_INFORMATION InfoBuffer = Buffer;
220  USHORT NameLength;
222  PWCHAR Name;
223 
224  *Length -= sizeof(*InfoBuffer);
225 
226  if (Ccb->NodeType == NPFS_NTC_ROOT_DCB_CCB)
227  {
228  NameLength = NpVcb->RootDcb->FullName.Length;
229  Name = NpVcb->RootDcb->FullName.Buffer;
230  }
231  else
232  {
233  NameLength = Ccb->Fcb->FullName.Length;
234  Name = Ccb->Fcb->FullName.Buffer;
235  }
236 
237  if (*Length < NameLength)
238  {
240  NameLength = (USHORT)*Length;
241  }
242  else
243  {
245  }
246 
247  RtlCopyMemory(InfoBuffer->FileName, Name, NameLength);
248  InfoBuffer->FileNameLength = NameLength;
249 
250  *Length -= NameLength;
251  return Status;
252 }
253 
254 NTSTATUS
255 NTAPI
257  IN PVOID Buffer,
259 {
260  PFILE_INTERNAL_INFORMATION InfoBuffer = Buffer;
261 
262  *Length -= sizeof(*InfoBuffer);
263 
264  RtlZeroMemory(InfoBuffer, sizeof(*InfoBuffer));
265 
266  return STATUS_SUCCESS;
267 }
268 
269 NTSTATUS
270 NTAPI
272  IN PVOID Buffer,
274  IN ULONG NamedPipeEnd)
275 {
276  PNP_DATA_QUEUE DataQueue;
277  PFILE_POSITION_INFORMATION InfoBuffer = Buffer;
278 
279  *Length -= sizeof(*InfoBuffer);
280 
281  RtlZeroMemory(InfoBuffer, sizeof(*InfoBuffer));
282 
283  if (NamedPipeEnd == FILE_PIPE_SERVER_END)
284  {
285  DataQueue = &Ccb->DataQueue[FILE_PIPE_INBOUND];
286  }
287  else
288  {
289  DataQueue = &Ccb->DataQueue[FILE_PIPE_OUTBOUND];
290  }
291 
292  if (DataQueue->QueueState == WriteEntries)
293  {
294  InfoBuffer->CurrentByteOffset.QuadPart = DataQueue->BytesInQueue -
295  DataQueue->ByteOffset;
296  }
297 
298  return STATUS_SUCCESS;
299 }
300 
301 NTSTATUS
302 NTAPI
304  IN PNP_CCB Ccb,
305  IN PVOID Buffer,
307  IN ULONG NamedPipeEnd)
308 {
310  PNP_DATA_QUEUE InQueue, OutQueue;
311 
312  *Length -= sizeof(*InfoBuffer);
313 
314  RtlZeroMemory(InfoBuffer, sizeof(*InfoBuffer));
315 
316  InQueue = &Ccb->DataQueue[FILE_PIPE_INBOUND];
317  OutQueue = &Ccb->DataQueue[FILE_PIPE_OUTBOUND];
318 
319  InfoBuffer->NamedPipeType = Fcb->NamedPipeType;
320  InfoBuffer->NamedPipeConfiguration = Fcb->NamedPipeConfiguration;
321  InfoBuffer->MaximumInstances = Fcb->MaximumInstances;
322  InfoBuffer->CurrentInstances = Fcb->CurrentInstances;
323  InfoBuffer->InboundQuota = InQueue->Quota;
324  InfoBuffer->OutboundQuota = OutQueue->Quota;
325  InfoBuffer->NamedPipeState = Ccb->NamedPipeState;
326  InfoBuffer->NamedPipeEnd = NamedPipeEnd;
327 
328  if (NamedPipeEnd == FILE_PIPE_SERVER_END)
329  {
330  if (InQueue->QueueState == WriteEntries)
331  {
332  InfoBuffer->ReadDataAvailable = InQueue->BytesInQueue - InQueue->ByteOffset;
333  }
334  InfoBuffer->WriteQuotaAvailable = OutQueue->Quota - OutQueue->QuotaUsed;
335  }
336  else
337  {
338  if (OutQueue->QueueState == WriteEntries)
339  {
340  InfoBuffer->ReadDataAvailable = OutQueue->BytesInQueue - OutQueue->ByteOffset;
341  }
342  InfoBuffer->WriteQuotaAvailable = OutQueue->Quota - InQueue->QuotaUsed;
343  }
344 
345  return STATUS_SUCCESS;
346 }
347 
348 NTSTATUS
349 NTAPI
351  IN PNP_CCB Ccb,
352  IN PVOID Buffer,
354  IN ULONG NamedPipeEnd)
355 {
356  PFILE_PIPE_INFORMATION InfoBuffer = Buffer;
357 
358  *Length -= sizeof(*InfoBuffer);
359 
360  RtlZeroMemory(InfoBuffer, sizeof(*InfoBuffer));
361 
362  InfoBuffer->ReadMode = Ccb->ReadMode[NamedPipeEnd];
363  InfoBuffer->CompletionMode = Ccb->CompletionMode[NamedPipeEnd];
364 
365  return STATUS_SUCCESS;
366 }
367 
368 NTSTATUS
369 NTAPI
371  IN PIRP Irp)
372 {
373  PIO_STACK_LOCATION IoStack;
374  NODE_TYPE_CODE NodeTypeCode;
375  ULONG NamedPipeEnd;
376  PNP_FCB Fcb;
377  PNP_CCB Ccb;
378  FILE_INFORMATION_CLASS InfoClass;
379  ULONG Length;
380  PVOID Buffer;
381  PFILE_ALL_INFORMATION AllInfo;
383  PAGED_CODE();
384 
386  NodeTypeCode = NpDecodeFileObject(IoStack->FileObject,
387  (PVOID*)&Fcb,
388  &Ccb,
389  &NamedPipeEnd);
390  if (!NodeTypeCode) return STATUS_PIPE_DISCONNECTED;
391 
392  Buffer = Irp->AssociatedIrp.SystemBuffer;
393  Length = IoStack->Parameters.QueryFile.Length;
394  InfoClass = IoStack->Parameters.QueryFile.FileInformationClass;
395 
396  if (NodeTypeCode != NPFS_NTC_CCB)
397  {
398  if (NodeTypeCode != NPFS_NTC_ROOT_DCB || InfoClass != FileNameInformation)
399  {
401  }
402  }
403 
404  switch (InfoClass)
405  {
406  case FileNameInformation:
408  break;
409 
411  Status = NpQueryPositionInfo(Ccb, Buffer, &Length, NamedPipeEnd);
412  break;
413 
414  case FilePipeInformation:
415  Status = NpQueryPipeInfo(Fcb, Ccb, Buffer, &Length, NamedPipeEnd);
416  break;
417 
419  Status = NpQueryPipeLocalInfo(Fcb, Ccb, Buffer, &Length, NamedPipeEnd);
420  break;
421 
424  break;
425 
427  Status = NpQueryStandardInfo(Ccb, Buffer, &Length, NamedPipeEnd);
428  break;
429 
432  break;
433 
434  case FileAllInformation:
435 
436  Length -= 12;
437  AllInfo = (PFILE_ALL_INFORMATION)Buffer;
439  NpQueryStandardInfo(Ccb, &AllInfo->StandardInformation, &Length, NamedPipeEnd);
441  NpQueryEaInfo(Ccb, &AllInfo->EaInformation, &Length);
442  NpQueryPositionInfo(Ccb, &AllInfo->PositionInformation, &Length, NamedPipeEnd);
444  Length += 96;
445  break;
446 
447  case FileEaInformation:
449  break;
450 
451  default:
453  break;
454  }
455 
456  Irp->IoStatus.Information = IoStack->Parameters.Read.Length - Length;
457  return Status;
458 }
459 
460 NTSTATUS
461 NTAPI
463  IN PIRP Irp)
464 {
466  PAGED_CODE();
467 
470 
472 
473  NpReleaseVcb();
475 
476  if (Status != STATUS_PENDING)
477  {
478  Irp->IoStatus.Status = Status;
480  }
481 
482  return Status;
483 }
484 
485 /* EOF */
#define FILE_PIPE_BYTE_STREAM_TYPE
Definition: iotypes.h:75
#define IN
Definition: typedefs.h:38
NTSTATUS NTAPI NpSetPipeInfo(IN PNP_FCB Fcb, IN PNP_CCB Ccb, IN PFILE_PIPE_INFORMATION Buffer, IN ULONG NamedPipeEnd, IN PLIST_ENTRY List)
Definition: fileinfo.c:29
NTSTATUS NTAPI NpQueryInternalInfo(IN PNP_CCB Ccb, IN PVOID Buffer, IN OUT PULONG Length)
Definition: fileinfo.c:256
struct _FCB::@697::@700 Fcb
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
FORCEINLINE VOID NpAcquireSharedVcb(VOID)
Definition: npfs.h:328
FILE_POSITION_INFORMATION PositionInformation
Definition: winternl.h:801
#define FsRtlEnterFileSystem
#define STATUS_PIPE_DISCONNECTED
Definition: ntstatus.h:398
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_PIPE_CLIENT_END
Definition: iotypes.h:84
#define NPFS_NTC_CCB
Definition: npfs.h:115
ULONG Quota
Definition: npfs.h:144
uint16_t * PWCHAR
Definition: typedefs.h:54
VOID NTAPI NpCheckForNotify(IN PNP_DCB Dcb, IN BOOLEAN SecondList, IN PLIST_ENTRY List)
Definition: create.c:20
struct _FCB * ParentDcb
Definition: fatstruc.h:835
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI NpQueryNameInfo(IN PNP_CCB Ccb, IN PVOID Buffer, IN OUT PULONG Length)
Definition: fileinfo.c:215
Definition: npfs.h:228
Definition: npfs.h:258
NTSTATUS NTAPI NpCommonSetInformation(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PLIST_ENTRY List)
Definition: fileinfo.c:80
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
struct NameRec_ * Name
Definition: cdprocs.h:464
NTSTATUS NTAPI NpQueryStandardInfo(IN PNP_CCB Ccb, IN PVOID Buffer, IN OUT PULONG Length, IN ULONG NamedPipeEnd)
Definition: fileinfo.c:159
ULONG QuotaUsed
Definition: npfs.h:142
#define IoCompleteRequest
Definition: irp.c:1240
LARGE_INTEGER CurrentByteOffset
Definition: nt_native.h:955
Definition: bufpool.h:45
NTSTATUS NTAPI NpQueryPipeLocalInfo(IN PNP_FCB Fcb, IN PNP_CCB Ccb, IN PVOID Buffer, IN OUT PULONG Length, IN ULONG NamedPipeEnd)
Definition: fileinfo.c:303
ULONG QueueState
Definition: npfs.h:139
enum _FILE_INFORMATION_CLASS FILE_INFORMATION_CLASS
Definition: directory.c:44
NTSTATUS NTAPI NpFsdQueryInformation(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fileinfo.c:462
#define NpBugCheck(p1, p2, p3)
Definition: npfs.h:106
NTSTATUS NTAPI NpQueryEaInfo(IN PNP_CCB Ccb, IN PVOID Buffer, IN OUT PULONG Length)
Definition: fileinfo.c:200
ULONG BytesInQueue
Definition: npfs.h:140
LIST_ENTRY List
Definition: psmgr.c:57
#define NPFS_NTC_ROOT_DCB_CCB
Definition: npfs.h:117
#define STATUS_PENDING
Definition: ntstatus.h:82
struct _FILE_ALL_INFORMATION * PFILE_ALL_INFORMATION
NTSTATUS NTAPI NpQueryBasicInfo(IN PNP_CCB Ccb, IN PVOID Buffer, IN OUT PULONG Length)
Definition: fileinfo.c:143
NTSTATUS NTAPI NpQueryPipeInfo(IN PNP_FCB Fcb, IN PNP_CCB Ccb, IN PVOID Buffer, IN OUT PULONG Length, IN ULONG NamedPipeEnd)
Definition: fileinfo.c:350
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
LARGE_INTEGER AllocationSize
Definition: propsheet.cpp:54
ULONG ByteOffset
Definition: npfs.h:143
#define FILE_PIPE_SERVER_END
Definition: iotypes.h:85
PNP_VCB NpVcb
Definition: strucsup.c:19
#define IO_NAMED_PIPE_INCREMENT
Definition: iotypes.h:572
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
FILE_EA_INFORMATION EaInformation
Definition: winternl.h:799
#define FILE_PIPE_COMPLETE_OPERATION
Definition: iotypes.h:80
FILE_NAME_INFORMATION NameInformation
Definition: winternl.h:804
ULONG LowPart
Definition: typedefs.h:104
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
Definition: typedefs.h:117
#define NPFS_NTC_ROOT_DCB
Definition: npfs.h:113
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
unsigned short USHORT
Definition: pedump.c:61
FORCEINLINE VOID NpReleaseVcb(VOID)
Definition: npfs.h:344
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define FILE_PIPE_OUTBOUND
Definition: iotypes.h:82
#define FILE_PIPE_MESSAGE_MODE
Definition: iotypes.h:78
NTSTATUS NTAPI NpFsdSetInformation(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fileinfo.c:114
unsigned int * PULONG
Definition: retypes.h:1
NTSTATUS NTAPI NpQueryPositionInfo(IN PNP_CCB Ccb, IN PVOID Buffer, IN OUT PULONG Length, IN ULONG NamedPipeEnd)
Definition: fileinfo.c:271
NTSTATUS NTAPI NpCommonQueryInformation(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fileinfo.c:370
#define FileStandardInformation
Definition: propsheet.cpp:61
PNP_DCB RootDcb
Definition: npfs.h:281
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
FILE_BASIC_INFORMATION BasicInformation
Definition: winternl.h:796
NODE_TYPE_CODE NTAPI NpDecodeFileObject(IN PFILE_OBJECT FileObject, OUT PVOID *PrimaryContext OPTIONAL, OUT PNP_CCB *Ccb, OUT PULONG NamedPipeEnd OPTIONAL)
Definition: fileobsup.c:20
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define FILE_PIPE_INBOUND
Definition: iotypes.h:81
FORCEINLINE VOID NpAcquireExclusiveVcb(VOID)
Definition: npfs.h:336
FILE_INTERNAL_INFORMATION InternalInformation
Definition: winternl.h:798
USHORT NODE_TYPE_CODE
Definition: nodetype.h:22
#define STATUS_PIPE_BUSY
Definition: ntstatus.h:396
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
NTSTATUS NTAPI NpSetBasicInfo(IN PNP_CCB Ccb, IN PFILE_BASIC_INFORMATION Buffer)
Definition: fileinfo.c:20
_In_ PFCB Fcb
Definition: cdprocs.h:151
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
FORCEINLINE VOID NpCompleteDeferredIrps(IN PLIST_ENTRY DeferredList)
Definition: npfs.h:356
LONGLONG QuadPart
Definition: typedefs.h:112
FILE_STANDARD_INFORMATION StandardInformation
Definition: winternl.h:797