Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendir.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS FAT file system driver 00003 * LICENSE: GNU GPLv3 as published by the Free Software Foundation 00004 * FILE: drivers/filesystems/fastfat/dir.c 00005 * PURPOSE: Directory Control 00006 * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org) 00007 */ 00008 00009 /* INCLUDES *****************************************************************/ 00010 00011 #define NDEBUG 00012 #include "fastfat.h" 00013 00014 /* FUNCTIONS *****************************************************************/ 00015 00016 NTSTATUS 00017 NTAPI 00018 FatDirectoryControl(PDEVICE_OBJECT DeviceObject, PIRP Irp) 00019 { 00020 DPRINT1("FatDirectoryControl()\n"); 00021 return STATUS_NOT_IMPLEMENTED; 00022 } 00023 00024 VOID 00025 NTAPI 00026 FatCreateRootDcb(IN PFAT_IRP_CONTEXT IrpContext, 00027 IN PVCB Vcb) 00028 { 00029 PFCB Dcb; 00030 00031 /* Make sure it's not already created */ 00032 ASSERT(!Vcb->RootDcb); 00033 00034 /* Allocate the DCB */ 00035 Dcb = FsRtlAllocatePoolWithTag(NonPagedPool, 00036 sizeof(FCB), 00037 TAG_FCB); 00038 00039 /* Zero it */ 00040 RtlZeroMemory(Dcb, sizeof(FCB)); 00041 00042 /* Assign it to the VCB */ 00043 Vcb->RootDcb = Dcb; 00044 00045 /* Set its header */ 00046 Dcb->Header.NodeTypeCode = FAT_NTC_ROOT_DCB; 00047 Dcb->Header.NodeByteSize = sizeof(FCB); 00048 00049 /* FCB is in a good condition */ 00050 Dcb->Condition = FcbGood; 00051 00052 /* Initialize FCB's resource */ 00053 Dcb->Header.Resource = &Dcb->Resource; 00054 ExInitializeResourceLite(&Dcb->Resource); 00055 00056 /* Initialize Paging Io resource*/ 00057 Dcb->Header.PagingIoResource = &Dcb->PagingIoResource; 00058 ExInitializeResourceLite(&Dcb->PagingIoResource); 00059 00060 /* Initialize a list of parent DCBs*/ 00061 InitializeListHead(&Dcb->ParentDcbLinks); 00062 00063 /* Set VCB */ 00064 Dcb->Vcb = Vcb; 00065 00066 /* Initialize parent's DCB list */ 00067 InitializeListHead(&Dcb->Dcb.ParentDcbList); 00068 00069 /* Initialize the full file name */ 00070 Dcb->FullFileName.Buffer = L"\\"; 00071 Dcb->FullFileName.Length = 1 * sizeof(WCHAR); 00072 Dcb->FullFileName.MaximumLength = 2 * sizeof(WCHAR); 00073 00074 Dcb->ShortName.Name.Ansi.Buffer = "\\"; 00075 Dcb->ShortName.Name.Ansi.Length = 1; 00076 Dcb->ShortName.Name.Ansi.MaximumLength = 2 * sizeof(CHAR); 00077 00078 /* Fill dirent attribute byte copy */ 00079 Dcb->DirentFatFlags = FILE_ATTRIBUTE_DIRECTORY; 00080 00081 /* Initialize advanced FCB header fields */ 00082 ExInitializeFastMutex(&Dcb->HeaderMutex); 00083 FsRtlSetupAdvancedHeader(&Dcb->Header, &Dcb->HeaderMutex); 00084 00085 /* Set up first cluster field depending on FAT type */ 00086 if (TRUE/*FatIsFat32(Vcb)*/) 00087 { 00088 /* First cluster is really the first cluster of this volume */ 00089 Dcb->FirstClusterOfFile = Vcb->Bpb.RootDirFirstCluster; 00090 00091 /* Calculate size of FAT32 root dir */ 00092 Dcb->Header.AllocationSize.LowPart = 0xFFFFFFFF; 00093 //FatLookupFileAllocationSize(IrpContext, Dcb); 00094 DPRINT1("Calculation of a size of a root dir is missing!\n"); 00095 00096 Dcb->Header.FileSize.QuadPart = Dcb->Header.AllocationSize.QuadPart; 00097 } 00098 else 00099 { 00100 #if 0 00101 /* Add MCB entry */ 00102 FatAddMcbEntry(Vcb, 00103 &Dcb->Mcb, 00104 0, 00105 FatRootDirectoryLbo(&Vcb->Bpb), 00106 FatRootDirectorySize(&Vcb->Bpb)); 00107 00108 /* Set a real size of the root directory */ 00109 Dcb->Header.FileSize.QuadPart = FatRootDirectorySize(&Vcb->Bpb); 00110 Dcb->Header.AllocationSize.QuadPart = Dcb->Header.FileSize.QuadPart; 00111 #endif 00112 UNIMPLEMENTED; 00113 } 00114 } 00115 00116 PFCB 00117 NTAPI 00118 FatCreateDcb(IN PFAT_IRP_CONTEXT IrpContext, 00119 IN PVCB Vcb, 00120 IN PFCB ParentDcb, 00121 IN FF_FILE *FileHandle) 00122 { 00123 PFCB Fcb; 00124 00125 /* Allocate it and zero it */ 00126 Fcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(FCB), TAG_FCB); 00127 RtlZeroMemory(Fcb, sizeof(FCB)); 00128 00129 /* Set node types */ 00130 Fcb->Header.NodeTypeCode = FAT_NTC_DCB; 00131 Fcb->Header.NodeByteSize = sizeof(FCB); 00132 Fcb->Condition = FcbGood; 00133 00134 /* Initialize resources */ 00135 Fcb->Header.Resource = &Fcb->Resource; 00136 ExInitializeResourceLite(Fcb->Header.Resource); 00137 00138 Fcb->Header.PagingIoResource = &Fcb->PagingIoResource; 00139 ExInitializeResourceLite(Fcb->Header.PagingIoResource); 00140 00141 /* Initialize mutexes */ 00142 Fcb->Header.FastMutex = &Fcb->HeaderMutex; 00143 ExInitializeFastMutex(&Fcb->HeaderMutex); 00144 FsRtlSetupAdvancedHeader(&Fcb->Header, &Fcb->HeaderMutex); 00145 00146 /* Insert into parent's DCB list */ 00147 InsertHeadList(&ParentDcb->Dcb.ParentDcbList, &Fcb->ParentDcbLinks); 00148 00149 /* Set backlinks */ 00150 Fcb->ParentFcb = ParentDcb; 00151 Fcb->Vcb = Vcb; 00152 00153 /* Initialize parent dcb list */ 00154 InitializeListHead(&Fcb->Dcb.ParentDcbList); 00155 00156 /* Set FullFAT handle */ 00157 Fcb->FatHandle = FileHandle; 00158 00159 /* Set names */ 00160 if (FileHandle) 00161 { 00162 FatSetFcbNames(IrpContext, Fcb); 00163 00164 /* Ensure the full name is set */ 00165 FatSetFullFileNameInFcb(IrpContext, Fcb); 00166 } 00167 00168 return Fcb; 00169 } 00170 00171 IO_STATUS_BLOCK 00172 NTAPI 00173 FatiOpenExistingDcb(IN PFAT_IRP_CONTEXT IrpContext, 00174 IN PFILE_OBJECT FileObject, 00175 IN PVCB Vcb, 00176 IN PFCB Dcb, 00177 IN PACCESS_MASK DesiredAccess, 00178 IN USHORT ShareAccess, 00179 IN ULONG CreateDisposition, 00180 IN BOOLEAN NoEaKnowledge, 00181 IN BOOLEAN DeleteOnClose) 00182 { 00183 IO_STATUS_BLOCK Iosb = {{0}}; 00184 PCCB Ccb; 00185 00186 /* Exclusively lock this FCB */ 00187 FatAcquireExclusiveFcb(IrpContext, Dcb); 00188 00189 /* Check if it's a delete-on-close of a root DCB */ 00190 if (FatNodeType(Dcb) == FAT_NTC_ROOT_DCB && DeleteOnClose) 00191 { 00192 Iosb.Status = STATUS_CANNOT_DELETE; 00193 00194 /* Release the lock and return */ 00195 FatReleaseFcb(IrpContext, Dcb); 00196 return Iosb; 00197 } 00198 00199 /*if (NoEaKnowledge && NodeType(Dcb) != FAT_NTC_ROOT_DCB && 00200 !FatIsFat32(Vcb)) 00201 { 00202 UNIMPLEMENTED; 00203 }*/ 00204 00205 /* Check the create disposition and desired access */ 00206 if ((CreateDisposition != FILE_OPEN) && 00207 (CreateDisposition != FILE_OPEN_IF)) 00208 { 00209 Iosb.Status = STATUS_OBJECT_NAME_COLLISION; 00210 00211 /* Release the lock and return */ 00212 FatReleaseFcb(IrpContext, Dcb); 00213 return Iosb; 00214 } 00215 00216 #if 0 00217 if (!FatCheckFileAccess(IrpContext, 00218 Dcb->DirentFatFlags, 00219 DesiredAccess)) 00220 { 00221 Iosb.Status = STATUS_ACCESS_DENIED; 00222 try_return( Iosb ); 00223 } 00224 #endif 00225 00226 /* If it's already opened - check share access */ 00227 if (Dcb->OpenCount > 0) 00228 { 00229 Iosb.Status = IoCheckShareAccess(*DesiredAccess, 00230 ShareAccess, 00231 FileObject, 00232 &Dcb->ShareAccess, 00233 TRUE); 00234 00235 if (!NT_SUCCESS(Iosb.Status)) 00236 { 00237 /* Release the lock and return */ 00238 FatReleaseFcb(IrpContext, Dcb); 00239 return Iosb; 00240 } 00241 } 00242 else 00243 { 00244 IoSetShareAccess(*DesiredAccess, 00245 ShareAccess, 00246 FileObject, 00247 &Dcb->ShareAccess); 00248 } 00249 00250 /* Set the file object */ 00251 Ccb = FatCreateCcb(); 00252 FatSetFileObject(FileObject, 00253 UserDirectoryOpen, 00254 Dcb, 00255 Ccb); 00256 00257 /* Increase counters */ 00258 Dcb->UncleanCount++; 00259 Dcb->OpenCount++; 00260 Vcb->OpenFileCount++; 00261 if (IsFileObjectReadOnly(FileObject)) Vcb->ReadOnlyCount++; 00262 00263 /* Set delete on close */ 00264 if (DeleteOnClose) 00265 SetFlag(Ccb->Flags, CCB_DELETE_ON_CLOSE); 00266 00267 /* Clear delay close flag */ 00268 ClearFlag(Dcb->State, FCB_STATE_DELAY_CLOSE); 00269 00270 /* That's it */ 00271 Iosb.Status = STATUS_SUCCESS; 00272 Iosb.Information = FILE_OPENED; 00273 00274 /* Release the lock */ 00275 FatReleaseFcb(IrpContext, Dcb); 00276 00277 return Iosb; 00278 } 00279 00280 /* EOF */ Generated on Sat May 26 2012 04:17:03 for ReactOS by
1.7.6.1
|