[fastfat_new]
[reactos.git] / reactos / drivers / filesystems / fastfat_new / dir.c
1 /*
2 * PROJECT: ReactOS FAT file system driver
3 * LICENSE: GPL - See COPYING in the top level directory
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->FileName.Name.Ansi.Buffer = "\\";
75 Dcb->FileName.Name.Ansi.Length = 1;
76 Dcb->FileName.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 /* Initialize MCB */
86 FsRtlInitializeLargeMcb(&Dcb->Mcb, NonPagedPool);
87
88 /* Set up first cluster field depending on FAT type */
89 if (TRUE/*FatIsFat32(Vcb)*/)
90 {
91 /* First cluster is really the first cluster of this volume */
92 Dcb->FirstClusterOfFile = Vcb->Bpb.RootDirFirstCluster;
93
94 /* Calculate size of FAT32 root dir */
95 Dcb->Header.AllocationSize.LowPart = 0xFFFFFFFF;
96 //FatLookupFileAllocationSize(IrpContext, Dcb);
97 DPRINT1("Calculation of a size of a root dir is missing!\n");
98
99 Dcb->Header.FileSize.QuadPart = Dcb->Header.AllocationSize.QuadPart;
100 }
101 else
102 {
103 #if 0
104 /* Add MCB entry */
105 FatAddMcbEntry(Vcb,
106 &Dcb->Mcb,
107 0,
108 FatRootDirectoryLbo(&Vcb->Bpb),
109 FatRootDirectorySize(&Vcb->Bpb));
110
111 /* Set a real size of the root directory */
112 Dcb->Header.FileSize.QuadPart = FatRootDirectorySize(&Vcb->Bpb);
113 Dcb->Header.AllocationSize.QuadPart = Dcb->Header.FileSize.QuadPart;
114 #endif
115 UNIMPLEMENTED;
116 }
117
118 /* Initialize free dirent bitmap */
119 RtlInitializeBitMap(&Dcb->Dcb.FreeBitmap, NULL, 0);
120
121 /* Fill the dirent bitmap */
122 DPRINT1("Filling the free dirent bitmap is missing\n");
123 //FatCheckFreeDirentBitmap( IrpContext, Dcb );
124 }
125
126 PFCB
127 NTAPI
128 FatCreateDcb(IN PFAT_IRP_CONTEXT IrpContext,
129 IN PVCB Vcb,
130 IN PFCB ParentDcb)
131 {
132 PFCB Fcb;
133
134 /* Allocate it and zero it */
135 Fcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(FCB), TAG_FCB);
136 RtlZeroMemory(Fcb, sizeof(FCB));
137
138 /* Set node types */
139 Fcb->Header.NodeTypeCode = FAT_NTC_DCB;
140 Fcb->Header.NodeByteSize = sizeof(FCB);
141 Fcb->Condition = FcbGood;
142
143 /* Initialize resources */
144 Fcb->Header.Resource = &Fcb->Resource;
145 ExInitializeResourceLite(Fcb->Header.Resource);
146
147 Fcb->Header.PagingIoResource = &Fcb->PagingIoResource;
148 ExInitializeResourceLite(Fcb->Header.PagingIoResource);
149
150 /* Initialize mutexes */
151 Fcb->Header.FastMutex = &Fcb->HeaderMutex;
152 ExInitializeFastMutex(&Fcb->HeaderMutex);
153 FsRtlSetupAdvancedHeader(&Fcb->Header, &Fcb->HeaderMutex);
154
155 /* Insert into parent's DCB list */
156 InsertHeadList(&ParentDcb->Dcb.ParentDcbList, &Fcb->ParentDcbLinks);
157
158 /* Set backlinks */
159 Fcb->ParentFcb = ParentDcb;
160 Fcb->Vcb = Vcb;
161
162 /* Initialize parent dcb list */
163 InitializeListHead(&Fcb->Dcb.ParentDcbList);
164
165 return Fcb;
166 }
167
168 /* EOF */