FatCreateCcb has no params.
[reactos.git] / reactos / drivers / filesystems / fastfat_new / dir.c
1 /*
2 * PROJECT: ReactOS FAT file system driver
3 * LICENSE: GNU GPLv3 as published by the Free Software Foundation
4 * FILE: drivers/filesystems/fastfat/dir.c
5 * PURPOSE: Directory Control
6 * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #define NDEBUG
12 #include "fastfat.h"
13
14 /* FUNCTIONS *****************************************************************/
15
16 NTSTATUS
17 NTAPI
18 FatDirectoryControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
19 {
20 DPRINT1("FatDirectoryControl()\n");
21 return STATUS_NOT_IMPLEMENTED;
22 }
23
24 VOID
25 NTAPI
26 FatCreateRootDcb(IN PFAT_IRP_CONTEXT IrpContext,
27 IN PVCB Vcb)
28 {
29 PFCB Dcb;
30
31 /* Make sure it's not already created */
32 ASSERT(!Vcb->RootDcb);
33
34 /* Allocate the DCB */
35 Dcb = FsRtlAllocatePoolWithTag(NonPagedPool,
36 sizeof(FCB),
37 TAG_FCB);
38
39 /* Zero it */
40 RtlZeroMemory(Dcb, sizeof(FCB));
41
42 /* Assign it to the VCB */
43 Vcb->RootDcb = Dcb;
44
45 /* Set its header */
46 Dcb->Header.NodeTypeCode = FAT_NTC_ROOT_DCB;
47 Dcb->Header.NodeByteSize = sizeof(FCB);
48
49 /* FCB is in a good condition */
50 Dcb->Condition = FcbGood;
51
52 /* Initialize FCB's resource */
53 Dcb->Header.Resource = &Dcb->Resource;
54 ExInitializeResourceLite(&Dcb->Resource);
55
56 /* Initialize Paging Io resource*/
57 Dcb->Header.PagingIoResource = &Dcb->PagingIoResource;
58 ExInitializeResourceLite(&Dcb->PagingIoResource);
59
60 /* Initialize a list of parent DCBs*/
61 InitializeListHead(&Dcb->ParentDcbLinks);
62
63 /* Set VCB */
64 Dcb->Vcb = Vcb;
65
66 /* Initialize parent's DCB list */
67 InitializeListHead(&Dcb->Dcb.ParentDcbList);
68
69 /* Initialize the full file name */
70 Dcb->FullFileName.Buffer = L"\\";
71 Dcb->FullFileName.Length = 1 * sizeof(WCHAR);
72 Dcb->FullFileName.MaximumLength = 2 * sizeof(WCHAR);
73
74 Dcb->ShortName.Name.Ansi.Buffer = "\\";
75 Dcb->ShortName.Name.Ansi.Length = 1;
76 Dcb->ShortName.Name.Ansi.MaximumLength = 2 * sizeof(CHAR);
77
78 /* Fill dirent attribute byte copy */
79 Dcb->DirentFatFlags = FILE_ATTRIBUTE_DIRECTORY;
80
81 /* Initialize advanced FCB header fields */
82 ExInitializeFastMutex(&Dcb->HeaderMutex);
83 FsRtlSetupAdvancedHeader(&Dcb->Header, &Dcb->HeaderMutex);
84
85 /* Set up first cluster field depending on FAT type */
86 if (TRUE/*FatIsFat32(Vcb)*/)
87 {
88 /* First cluster is really the first cluster of this volume */
89 Dcb->FirstClusterOfFile = Vcb->Bpb.RootDirFirstCluster;
90
91 /* Calculate size of FAT32 root dir */
92 Dcb->Header.AllocationSize.LowPart = 0xFFFFFFFF;
93 //FatLookupFileAllocationSize(IrpContext, Dcb);
94 DPRINT1("Calculation of a size of a root dir is missing!\n");
95
96 Dcb->Header.FileSize.QuadPart = Dcb->Header.AllocationSize.QuadPart;
97 }
98 else
99 {
100 #if 0
101 /* Add MCB entry */
102 FatAddMcbEntry(Vcb,
103 &Dcb->Mcb,
104 0,
105 FatRootDirectoryLbo(&Vcb->Bpb),
106 FatRootDirectorySize(&Vcb->Bpb));
107
108 /* Set a real size of the root directory */
109 Dcb->Header.FileSize.QuadPart = FatRootDirectorySize(&Vcb->Bpb);
110 Dcb->Header.AllocationSize.QuadPart = Dcb->Header.FileSize.QuadPart;
111 #endif
112 UNIMPLEMENTED;
113 }
114 }
115
116 PFCB
117 NTAPI
118 FatCreateDcb(IN PFAT_IRP_CONTEXT IrpContext,
119 IN PVCB Vcb,
120 IN PFCB ParentDcb,
121 IN FF_FILE *FileHandle)
122 {
123 PFCB Fcb;
124
125 /* Allocate it and zero it */
126 Fcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(FCB), TAG_FCB);
127 RtlZeroMemory(Fcb, sizeof(FCB));
128
129 /* Set node types */
130 Fcb->Header.NodeTypeCode = FAT_NTC_DCB;
131 Fcb->Header.NodeByteSize = sizeof(FCB);
132 Fcb->Condition = FcbGood;
133
134 /* Initialize resources */
135 Fcb->Header.Resource = &Fcb->Resource;
136 ExInitializeResourceLite(Fcb->Header.Resource);
137
138 Fcb->Header.PagingIoResource = &Fcb->PagingIoResource;
139 ExInitializeResourceLite(Fcb->Header.PagingIoResource);
140
141 /* Initialize mutexes */
142 Fcb->Header.FastMutex = &Fcb->HeaderMutex;
143 ExInitializeFastMutex(&Fcb->HeaderMutex);
144 FsRtlSetupAdvancedHeader(&Fcb->Header, &Fcb->HeaderMutex);
145
146 /* Insert into parent's DCB list */
147 InsertHeadList(&ParentDcb->Dcb.ParentDcbList, &Fcb->ParentDcbLinks);
148
149 /* Set backlinks */
150 Fcb->ParentFcb = ParentDcb;
151 Fcb->Vcb = Vcb;
152
153 /* Initialize parent dcb list */
154 InitializeListHead(&Fcb->Dcb.ParentDcbList);
155
156 /* Set FullFAT handle */
157 Fcb->FatHandle = FileHandle;
158
159 /* Set names */
160 if (FileHandle)
161 {
162 FatSetFcbNames(IrpContext, Fcb);
163
164 /* Ensure the full name is set */
165 FatSetFullFileNameInFcb(IrpContext, Fcb);
166 }
167
168 return Fcb;
169 }
170
171 IO_STATUS_BLOCK
172 NTAPI
173 FatiOpenExistingDcb(IN PFAT_IRP_CONTEXT IrpContext,
174 IN PFILE_OBJECT FileObject,
175 IN PVCB Vcb,
176 IN PFCB Dcb,
177 IN PACCESS_MASK DesiredAccess,
178 IN USHORT ShareAccess,
179 IN ULONG CreateDisposition,
180 IN BOOLEAN NoEaKnowledge,
181 IN BOOLEAN DeleteOnClose)
182 {
183 IO_STATUS_BLOCK Iosb = {{0}};
184 PCCB Ccb;
185
186 /* Exclusively lock this FCB */
187 FatAcquireExclusiveFcb(IrpContext, Dcb);
188
189 /* Check if it's a delete-on-close of a root DCB */
190 if (FatNodeType(Dcb) == FAT_NTC_ROOT_DCB && DeleteOnClose)
191 {
192 Iosb.Status = STATUS_CANNOT_DELETE;
193
194 /* Release the lock and return */
195 FatReleaseFcb(IrpContext, Dcb);
196 return Iosb;
197 }
198
199 /*if (NoEaKnowledge && NodeType(Dcb) != FAT_NTC_ROOT_DCB &&
200 !FatIsFat32(Vcb))
201 {
202 UNIMPLEMENTED;
203 }*/
204
205 /* Check the create disposition and desired access */
206 if ((CreateDisposition != FILE_OPEN) &&
207 (CreateDisposition != FILE_OPEN_IF))
208 {
209 Iosb.Status = STATUS_OBJECT_NAME_COLLISION;
210
211 /* Release the lock and return */
212 FatReleaseFcb(IrpContext, Dcb);
213 return Iosb;
214 }
215
216 #if 0
217 if (!FatCheckFileAccess(IrpContext,
218 Dcb->DirentFatFlags,
219 DesiredAccess))
220 {
221 Iosb.Status = STATUS_ACCESS_DENIED;
222 try_return( Iosb );
223 }
224 #endif
225
226 /* If it's already opened - check share access */
227 if (Dcb->OpenCount > 0)
228 {
229 Iosb.Status = IoCheckShareAccess(*DesiredAccess,
230 ShareAccess,
231 FileObject,
232 &Dcb->ShareAccess,
233 TRUE);
234
235 if (!NT_SUCCESS(Iosb.Status))
236 {
237 /* Release the lock and return */
238 FatReleaseFcb(IrpContext, Dcb);
239 return Iosb;
240 }
241 }
242 else
243 {
244 IoSetShareAccess(*DesiredAccess,
245 ShareAccess,
246 FileObject,
247 &Dcb->ShareAccess);
248 }
249
250 /* Set the file object */
251 Ccb = FatCreateCcb();
252 FatSetFileObject(FileObject,
253 UserDirectoryOpen,
254 Dcb,
255 Ccb);
256
257 /* Increase counters */
258 Dcb->UncleanCount++;
259 Dcb->OpenCount++;
260 Vcb->OpenFileCount++;
261 if (IsFileObjectReadOnly(FileObject)) Vcb->ReadOnlyCount++;
262
263 /* Set delete on close */
264 if (DeleteOnClose)
265 SetFlag(Ccb->Flags, CCB_DELETE_ON_CLOSE);
266
267 /* Clear delay close flag */
268 ClearFlag(Dcb->State, FCB_STATE_DELAY_CLOSE);
269
270 /* That's it */
271 Iosb.Status = STATUS_SUCCESS;
272 Iosb.Information = FILE_OPENED;
273
274 /* Release the lock */
275 FatReleaseFcb(IrpContext, Dcb);
276
277 return Iosb;
278 }
279
280 /* EOF */