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 37 _When_(TypeOfOpen == UnopenedFileObject, _At_(Fcb, _In_opt_)) 38 _When_(TypeOfOpen != UnopenedFileObject, _At_(Fcb, _In_)) 39 VOID 40 CdSetFileObject ( 41 _In_ PIRP_CONTEXT IrpContext, 42 _Inout_ PFILE_OBJECT FileObject, 43 _In_ TYPE_OF_OPEN TypeOfOpen, 44 PFCB Fcb, 45 _In_opt_ PCCB Ccb 46 ) 47 48 /*++ 49 50 Routine Description: 51 52 This routine will initialize the FileObject context fields based on the 53 input type and data structures. 54 55 Arguments: 56 57 FileObject - Supplies the file object pointer being initialized. 58 59 TypeOfOpen - Sets the type of open. 60 61 Fcb - Fcb for this file object. Ignored for UnopenedFileObject. 62 63 Ccb - Ccb for the handle corresponding to this file object. Will not 64 be present for stream file objects. 65 66 Return Value: 67 68 None. 69 70 --*/ 71 72 { 73 PAGED_CODE(); 74 75 UNREFERENCED_PARAMETER( IrpContext ); 76 77 // 78 // We only have values 0 to 7 available so make sure we didn't 79 // inadvertantly add a new type. 80 // 81 82 NT_ASSERTMSG( "FileObject types exceed available bits\n", BeyondValidType <= 8 ); 83 84 // 85 // Setting a file object to type UnopenedFileObject means just 86 // clearing all of the context fields. All the other input 87 // 88 89 if (TypeOfOpen == UnopenedFileObject) { 90 91 FileObject->FsContext = 92 FileObject->FsContext2 = NULL; 93 94 return; 95 } 96 97 // 98 // Check that the 3 low-order bits of the Ccb are clear. 99 // 100 101 NT_ASSERTMSG( "Ccb is not quad-aligned\n", !FlagOn( ((ULONG_PTR) Ccb), TYPE_OF_OPEN_MASK )); 102 103 // 104 // We will or the type of open into the low order bits of FsContext2 105 // along with the Ccb value. 106 // The Fcb is stored into the FsContext field. 107 // 108 109 FileObject->FsContext = Fcb; 110 FileObject->FsContext2 = Ccb; 111 112 #ifdef _MSC_VER 113 #pragma warning( suppress: 4213 ) 114 #endif 115 SetFlag( (*(PULONG_PTR)&FileObject->FsContext2), TypeOfOpen ); /* ReactOS Change: GCC "invalid lvalue in assignment" */ 116 117 // 118 // Set the Vpb field in the file object. 119 // 120 121 FileObject->Vpb = Fcb->Vcb->Vpb; 122 123 return; 124 } 125 126 127 _When_(return == UnopenedFileObject, _At_(*Fcb, _Post_null_)) 128 _When_(return != UnopenedFileObject, _At_(Fcb, _Outptr_)) 129 _When_(return == UnopenedFileObject, _At_(*Ccb, _Post_null_)) 130 _When_(return != UnopenedFileObject, _At_(Ccb, _Outptr_)) 131 TYPE_OF_OPEN 132 CdDecodeFileObject ( 133 _In_ PIRP_CONTEXT IrpContext, 134 _In_ PFILE_OBJECT FileObject, 135 PFCB *Fcb, 136 PCCB *Ccb 137 ) 138 139 /*++ 140 141 Routine Description: 142 143 This routine takes a file object and extracts the Fcb and Ccb (possibly NULL) 144 and returns the type of open. 145 146 Arguments: 147 148 FileObject - Supplies the file object pointer being initialized. 149 150 Fcb - Address to store the Fcb contained in the file object. 151 152 Ccb - Address to store the Ccb contained in the file object. 153 154 Return Value: 155 156 TYPE_OF_OPEN - Indicates the type of file object. 157 158 --*/ 159 160 { 161 TYPE_OF_OPEN TypeOfOpen; 162 163 PAGED_CODE(); 164 165 UNREFERENCED_PARAMETER( IrpContext ); 166 167 // 168 // If this is an unopened file object then return NULL for the 169 // Fcb/Ccb. Don't trust any other values in the file object. 170 // 171 172 TypeOfOpen = (TYPE_OF_OPEN) FlagOn( (ULONG_PTR) FileObject->FsContext2, 173 TYPE_OF_OPEN_MASK ); 174 175 if (TypeOfOpen == UnopenedFileObject) { 176 177 *Fcb = NULL; 178 *Ccb = NULL; 179 180 } else { 181 182 // 183 // The Fcb is pointed to by the FsContext field. The Ccb is in 184 // FsContext2 (after clearing the low three bits). The low three 185 // bits are the file object type. 186 // 187 188 *Fcb = FileObject->FsContext; 189 *Ccb = FileObject->FsContext2; 190 191 #ifdef _MSC_VER 192 #pragma warning( suppress: 4213 ) 193 #endif 194 ClearFlag( (*(PULONG_PTR)Ccb), TYPE_OF_OPEN_MASK ); /* ReactOS Change: GCC "invalid lvalue in assignment" */ 195 } 196 197 // 198 // Now return the type of open. 199 // 200 201 return TypeOfOpen; 202 } 203 204 205 TYPE_OF_OPEN 206 CdFastDecodeFileObject ( 207 _In_ PFILE_OBJECT FileObject, 208 _Out_ PFCB *Fcb 209 ) 210 211 /*++ 212 213 Routine Description: 214 215 This procedure takes a pointer to a file object, that has already been 216 opened by Cdfs and does a quick decode operation. It will only return 217 a non null value if the file object is a user file open 218 219 Arguments: 220 221 FileObject - Supplies the file object pointer being interrogated 222 223 Fcb - Address to store Fcb if this is a user file object. NULL 224 otherwise. 225 226 Return Value: 227 228 TYPE_OF_OPEN - type of open of this file object. 229 230 --*/ 231 232 { 233 PAGED_CODE(); 234 235 ASSERT_FILE_OBJECT( FileObject ); 236 237 // 238 // The Fcb is in the FsContext field. The type of open is in the low 239 // bits of the Ccb. 240 // 241 242 *Fcb = FileObject->FsContext; 243 244 return (TYPE_OF_OPEN) 245 FlagOn( (ULONG_PTR) FileObject->FsContext2, TYPE_OF_OPEN_MASK ); 246 } 247 248 249 250