1 /*
2  * PROJECT:     ReactOS Named Pipe FileSystem
3  * LICENSE:     BSD - See COPYING.ARM in the top level directory
4  * FILE:        drivers/filesystems/npfs/fileobsup.c
5  * PURPOSE:     Pipes File Object Support
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_FILEOBSUP)
15 
16 /* FUNCTIONS ******************************************************************/
17 
18 NODE_TYPE_CODE
19 NTAPI
20 NpDecodeFileObject(IN PFILE_OBJECT FileObject,
21                    OUT PVOID* PrimaryContext OPTIONAL,
22                    OUT PNP_CCB* Ccb,
23                    OUT PULONG NamedPipeEnd OPTIONAL)
24 {
25     ULONG_PTR Context;
26     PNP_CCB Node;
27     PAGED_CODE();
28 
29     Context = (ULONG_PTR)FileObject->FsContext;
30     if ((Context) && (Context != 1))
31     {
32         if (NamedPipeEnd) *NamedPipeEnd = Context & 1;
33 
34         Node = (PVOID)(Context & ~1);
35 
36         switch (Node->NodeType)
37         {
38             case NPFS_NTC_VCB:
39                 return NPFS_NTC_VCB;
40 
41             case NPFS_NTC_ROOT_DCB:
42                 *Ccb = FileObject->FsContext2;
43                 if (PrimaryContext) *PrimaryContext = Node;
44                 return NPFS_NTC_ROOT_DCB;
45 
46             case NPFS_NTC_CCB:
47                 *Ccb = Node;
48                 if (PrimaryContext) *PrimaryContext = Node->Fcb;
49                 return NPFS_NTC_CCB;
50 
51             default:
52                 NpBugCheck(Node->NodeType, 0, 0);
53                 break;
54             }
55     }
56 
57     return 0;
58 }
59 
60 VOID
61 NTAPI
62 NpSetFileObject(IN PFILE_OBJECT FileObject,
63                 IN PVOID PrimaryContext,
64                 IN PVOID Ccb,
65                 IN ULONG NamedPipeEnd)
66 {
67     BOOLEAN FileIsPipe;
68     PAGED_CODE();
69 
70     if (!FileObject) return;
71 
72     if ((PrimaryContext) && (((PNP_CCB)PrimaryContext)->NodeType == NPFS_NTC_CCB))
73     {
74         FileIsPipe = TRUE;
75         if (NamedPipeEnd == FILE_PIPE_SERVER_END)
76         {
77             PrimaryContext = (PVOID) ((ULONG_PTR) PrimaryContext | 1);
78         }
79     }
80     else
81     {
82         FileIsPipe = FALSE;
83     }
84 
85     FileObject->FsContext = PrimaryContext;
86     FileObject->FsContext2 = Ccb;
87     FileObject->PrivateCacheMap = (PVOID)1;
88     if (FileIsPipe) FileObject->Flags |= FO_NAMED_PIPE;
89 }
90 
91 /* EOF */
92