[CDFS_NEW] Fix headers inclusion so that it can work on a *nix platform
[reactos.git] / drivers / filesystems / cdfs_new / filobsup.c
1 /*++
2
3 Copyright (c) 1989-2000 Microsoft Corporation
4
5 Module Name:
6
7 FilObSup.c
8
9 Abstract:
10
11 This module implements the Cdfs File object support routines.
12
13
14 --*/
15
16 #include "cdprocs.h"
17
18 //
19 // The Bug check file id for this module
20 //
21
22 #define BugCheckFileId (CDFS_BUG_CHECK_FILOBSUP)
23
24 //
25 // Local constants.
26 //
27
28 #define TYPE_OF_OPEN_MASK (0x00000007)
29
30 #ifdef ALLOC_PRAGMA
31 #pragma alloc_text(PAGE, CdDecodeFileObject)
32 #pragma alloc_text(PAGE, CdFastDecodeFileObject)
33 #pragma alloc_text(PAGE, CdSetFileObject)
34 #endif
35
36 \f
37 VOID
38 CdSetFileObject (
39 IN PIRP_CONTEXT IrpContext,
40 IN PFILE_OBJECT FileObject,
41 IN TYPE_OF_OPEN TypeOfOpen,
42 IN PFCB Fcb OPTIONAL,
43 IN PCCB Ccb OPTIONAL
44 )
45
46 /*++
47
48 Routine Description:
49
50 This routine will initialize the FileObject context fields based on the
51 input type and data structures.
52
53 Arguments:
54
55 FileObject - Supplies the file object pointer being initialized.
56
57 TypeOfOpen - Sets the type of open.
58
59 Fcb - Fcb for this file object. Ignored for UnopenedFileObject.
60
61 Ccb - Ccb for the handle corresponding to this file object. Will not
62 be present for stream file objects.
63
64 Return Value:
65
66 None.
67
68 --*/
69
70 {
71 PAGED_CODE();
72
73 //
74 // We only have values 0 to 7 available so make sure we didn't
75 // inadvertantly add a new type.
76 //
77
78 ASSERTMSG( "FileObject types exceed available bits\n", BeyondValidType <= 8 );
79
80 //
81 // Setting a file object to type UnopenedFileObject means just
82 // clearing all of the context fields. All the other input
83 //
84
85 if (TypeOfOpen == UnopenedFileObject) {
86
87 FileObject->FsContext =
88 FileObject->FsContext2 = NULL;
89
90 return;
91 }
92
93 //
94 // Check that the 3 low-order bits of the Ccb are clear.
95 //
96
97 ASSERTMSG( "Ccb is not quad-aligned\n", !FlagOn( ((ULONG_PTR) Ccb), TYPE_OF_OPEN_MASK ));
98
99 //
100 // We will or the type of open into the low order bits of FsContext2
101 // along with the Ccb value.
102 // The Fcb is stored into the FsContext field.
103 //
104
105 FileObject->FsContext = Fcb;
106 FileObject->FsContext2 = Ccb;
107
108 SetFlag( (*(PULONG_PTR)&FileObject->FsContext2), TypeOfOpen ); /* ReactOS Change: GCC "invalid lvalue in assignment" */
109
110 //
111 // Set the Vpb field in the file object.
112 //
113
114 FileObject->Vpb = Fcb->Vcb->Vpb;
115
116 return;
117 }
118
119
120 \f
121 TYPE_OF_OPEN
122 CdDecodeFileObject (
123 IN PIRP_CONTEXT IrpContext,
124 IN PFILE_OBJECT FileObject,
125 OUT PFCB *Fcb,
126 OUT PCCB *Ccb
127 )
128
129 /*++
130
131 Routine Description:
132
133 This routine takes a file object and extracts the Fcb and Ccb (possibly NULL)
134 and returns the type of open.
135
136 Arguments:
137
138 FileObject - Supplies the file object pointer being initialized.
139
140 Fcb - Address to store the Fcb contained in the file object.
141
142 Ccb - Address to store the Ccb contained in the file object.
143
144 Return Value:
145
146 TYPE_OF_OPEN - Indicates the type of file object.
147
148 --*/
149
150 {
151 TYPE_OF_OPEN TypeOfOpen;
152
153 PAGED_CODE();
154
155 //
156 // If this is an unopened file object then return NULL for the
157 // Fcb/Ccb. Don't trust any other values in the file object.
158 //
159
160 TypeOfOpen = (TYPE_OF_OPEN) FlagOn( (ULONG_PTR) FileObject->FsContext2,
161 TYPE_OF_OPEN_MASK );
162
163 if (TypeOfOpen == UnopenedFileObject) {
164
165 *Fcb = NULL;
166 *Ccb = NULL;
167
168 } else {
169
170 //
171 // The Fcb is pointed to by the FsContext field. The Ccb is in
172 // FsContext2 (after clearing the low three bits). The low three
173 // bits are the file object type.
174 //
175
176 *Fcb = FileObject->FsContext;
177 *Ccb = FileObject->FsContext2;
178
179 ClearFlag( (*(PULONG_PTR)Ccb), TYPE_OF_OPEN_MASK ); /* ReactOS Change: GCC "invalid lvalue in assignment" */
180 }
181
182 //
183 // Now return the type of open.
184 //
185
186 return TypeOfOpen;
187 }
188
189 \f
190 TYPE_OF_OPEN
191 CdFastDecodeFileObject (
192 IN PFILE_OBJECT FileObject,
193 OUT PFCB *Fcb
194 )
195
196 /*++
197
198 Routine Description:
199
200 This procedure takes a pointer to a file object, that has already been
201 opened by Cdfs and does a quick decode operation. It will only return
202 a non null value if the file object is a user file open
203
204 Arguments:
205
206 FileObject - Supplies the file object pointer being interrogated
207
208 Fcb - Address to store Fcb if this is a user file object. NULL
209 otherwise.
210
211 Return Value:
212
213 TYPE_OF_OPEN - type of open of this file object.
214
215 --*/
216
217 {
218 PAGED_CODE();
219
220 ASSERT_FILE_OBJECT( FileObject );
221
222 //
223 // The Fcb is in the FsContext field. The type of open is in the low
224 // bits of the Ccb.
225 //
226
227 *Fcb = FileObject->FsContext;
228
229 return (TYPE_OF_OPEN)
230 FlagOn( (ULONG_PTR) FileObject->FsContext2, TYPE_OF_OPEN_MASK );
231 }
232
233
234