2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/fs/vfat/dirwr.c
5 * PURPOSE: VFAT Filesystem : write in directory
9 /* INCLUDES *****************************************************************/
15 * update an existing FAT entry
28 ASSERT(pFcb
->parentFcb
);
30 if (pFcb
->Flags
& FCB_IS_FATX_ENTRY
)
32 SizeDirEntry
= sizeof(FATX_DIR_ENTRY
);
33 dirIndex
= pFcb
->startIndex
;
37 SizeDirEntry
= sizeof(FAT_DIR_ENTRY
);
38 dirIndex
= pFcb
->dirIndex
;
41 DPRINT("updEntry dirIndex %d, PathName \'%wZ\'\n", dirIndex
, &pFcb
->PathNameU
);
43 if (vfatFCBIsRoot(pFcb
) || (pFcb
->Flags
& (FCB_IS_FAT
|FCB_IS_VOLUME
)))
45 return STATUS_SUCCESS
;
48 ASSERT(pFcb
->parentFcb
);
50 Offset
.u
.HighPart
= 0;
51 Offset
.u
.LowPart
= dirIndex
* SizeDirEntry
;
52 if (CcPinRead(pFcb
->parentFcb
->FileObject
, &Offset
, SizeDirEntry
,
53 TRUE
, &Context
, (PVOID
*)&PinEntry
))
55 pFcb
->Flags
&= ~FCB_IS_DIRTY
;
56 RtlCopyMemory(PinEntry
, &pFcb
->entry
, SizeDirEntry
);
57 CcSetDirtyPinnedData(Context
, NULL
);
59 return STATUS_SUCCESS
;
63 DPRINT1("Failed write to \'%wZ\'.\n", &pFcb
->parentFcb
->PathNameU
);
64 return STATUS_UNSUCCESSFUL
;
69 * try to find contiguous entries frees in directory,
70 * extend a directory if is neccesary
74 IN PDEVICE_EXTENSION DeviceExt
,
79 LARGE_INTEGER FileOffset
;
80 ULONG i
, count
, size
, nbFree
= 0;
85 FileOffset
.QuadPart
= 0;
87 if (DeviceExt
->Flags
& VCB_IS_FATX
)
88 SizeDirEntry
= sizeof(FATX_DIR_ENTRY
);
90 SizeDirEntry
= sizeof(FAT_DIR_ENTRY
);
92 count
= pDirFcb
->RFCB
.FileSize
.u
.LowPart
/ SizeDirEntry
;
93 size
= DeviceExt
->FatInfo
.BytesPerCluster
/ SizeDirEntry
;
94 for (i
= 0; i
< count
; i
++, pFatEntry
= (PDIR_ENTRY
)((ULONG_PTR
)pFatEntry
+ SizeDirEntry
))
96 if (Context
== NULL
|| (i
% size
) == 0)
100 CcUnpinData(Context
);
102 /* FIXME: check return value */
103 CcPinRead(pDirFcb
->FileObject
, &FileOffset
, DeviceExt
->FatInfo
.BytesPerCluster
,
104 TRUE
, &Context
, (PVOID
*)&pFatEntry
);
105 FileOffset
.u
.LowPart
+= DeviceExt
->FatInfo
.BytesPerCluster
;
107 if (ENTRY_END(DeviceExt
, pFatEntry
))
111 if (ENTRY_DELETED(DeviceExt
, pFatEntry
))
119 if (nbFree
== nbSlots
)
126 CcUnpinData(Context
);
129 if (nbFree
== nbSlots
)
131 /* found enough contiguous free slots */
132 *start
= i
- nbSlots
+ 1;
137 if (*start
+ nbSlots
> count
)
139 LARGE_INTEGER AllocationSize
;
141 /* extend the directory */
142 if (vfatFCBIsRoot(pDirFcb
) && DeviceExt
->FatInfo
.FatType
!= FAT32
)
144 /* We can't extend a root directory on a FAT12/FAT16/FATX partition */
147 AllocationSize
.QuadPart
= pDirFcb
->RFCB
.FileSize
.u
.LowPart
+ DeviceExt
->FatInfo
.BytesPerCluster
;
148 Status
= VfatSetAllocationSizeInformation(pDirFcb
->FileObject
, pDirFcb
,
149 DeviceExt
, &AllocationSize
);
150 if (!NT_SUCCESS(Status
))
154 /* clear the new dir cluster */
155 FileOffset
.u
.LowPart
= (ULONG
)(pDirFcb
->RFCB
.FileSize
.QuadPart
-
156 DeviceExt
->FatInfo
.BytesPerCluster
);
157 CcPinRead(pDirFcb
->FileObject
, &FileOffset
, DeviceExt
->FatInfo
.BytesPerCluster
,
158 TRUE
, &Context
, (PVOID
*)&pFatEntry
);
159 if (DeviceExt
->Flags
& VCB_IS_FATX
)
160 memset(pFatEntry
, 0xff, DeviceExt
->FatInfo
.BytesPerCluster
);
162 RtlZeroMemory(pFatEntry
, DeviceExt
->FatInfo
.BytesPerCluster
);
164 else if (*start
+ nbSlots
< count
)
166 /* clear the entry after the last new entry */
167 FileOffset
.u
.LowPart
= (*start
+ nbSlots
) * SizeDirEntry
;
168 CcPinRead(pDirFcb
->FileObject
, &FileOffset
, SizeDirEntry
,
169 TRUE
, &Context
, (PVOID
*)&pFatEntry
);
170 if (DeviceExt
->Flags
& VCB_IS_FATX
)
171 memset(pFatEntry
, 0xff, SizeDirEntry
);
173 RtlZeroMemory(pFatEntry
, SizeDirEntry
);
177 CcSetDirtyPinnedData(Context
, NULL
);
178 CcUnpinData(Context
);
181 DPRINT("nbSlots %d nbFree %d, entry number %d\n", nbSlots
, nbFree
, *start
);
186 create a new FAT entry
190 IN PDEVICE_EXTENSION DeviceExt
,
191 IN PUNICODE_STRING NameU
,
193 IN PVFATFCB ParentFcb
,
194 IN ULONG RequestedOptions
,
197 PVOID Context
= NULL
;
198 PFAT_DIR_ENTRY pFatEntry
;
200 USHORT nbSlots
= 0, j
, posCar
;
202 BOOLEAN needTilde
= FALSE
, needLong
= FALSE
;
203 BOOLEAN lCaseBase
= FALSE
, uCaseBase
, lCaseExt
= FALSE
, uCaseExt
;
204 ULONG CurrentCluster
;
205 LARGE_INTEGER SystemTime
, FileOffset
;
206 NTSTATUS Status
= STATUS_SUCCESS
;
215 VFAT_DIRENTRY_CONTEXT DirContext
;
216 WCHAR LongNameBuffer
[LONGNAME_MAX_LENGTH
+ 1];
217 WCHAR ShortNameBuffer
[13];
219 DPRINT("addEntry: Name='%wZ', Dir='%wZ'\n", NameU
, &ParentFcb
->PathNameU
);
221 DirContext
.LongNameU
= *NameU
;
223 /* nb of entry needed for long name+normal entry */
224 nbSlots
= (DirContext
.LongNameU
.Length
/ sizeof(WCHAR
) + 12) / 13 + 1;
225 DPRINT("NameLen= %d, nbSlots =%d\n", DirContext
.LongNameU
.Length
/ sizeof(WCHAR
), nbSlots
);
226 Buffer
= ExAllocatePoolWithTag(NonPagedPool
, (nbSlots
- 1) * sizeof(FAT_DIR_ENTRY
), TAG_VFAT
);
229 return STATUS_INSUFFICIENT_RESOURCES
;
231 RtlZeroMemory(Buffer
, (nbSlots
- 1) * sizeof(FAT_DIR_ENTRY
));
232 pSlots
= (slot
*) Buffer
;
234 NameA
.Buffer
= aName
;
236 NameA
.MaximumLength
= sizeof(aName
);
238 DirContext
.ShortNameU
.Buffer
= ShortNameBuffer
;
239 DirContext
.ShortNameU
.Length
= 0;
240 DirContext
.ShortNameU
.MaximumLength
= sizeof(ShortNameBuffer
);
242 RtlZeroMemory(&DirContext
.DirEntry
.Fat
, sizeof(FAT_DIR_ENTRY
));
244 IsNameLegal
= RtlIsNameLegalDOS8Dot3(&DirContext
.LongNameU
, &NameA
, &SpacesFound
);
246 if (!IsNameLegal
|| SpacesFound
)
248 GENERATE_NAME_CONTEXT NameContext
;
249 VFAT_DIRENTRY_CONTEXT SearchContext
;
250 WCHAR ShortSearchName
[13];
253 RtlZeroMemory(&NameContext
, sizeof(GENERATE_NAME_CONTEXT
));
254 SearchContext
.LongNameU
.Buffer
= LongNameBuffer
;
255 SearchContext
.LongNameU
.MaximumLength
= sizeof(LongNameBuffer
);
256 SearchContext
.ShortNameU
.Buffer
= ShortSearchName
;
257 SearchContext
.ShortNameU
.MaximumLength
= sizeof(ShortSearchName
);
259 for (i
= 0; i
< 100; i
++)
261 RtlGenerate8dot3Name(&DirContext
.LongNameU
, FALSE
, &NameContext
, &DirContext
.ShortNameU
);
262 DirContext
.ShortNameU
.Buffer
[DirContext
.ShortNameU
.Length
/ sizeof(WCHAR
)] = 0;
263 SearchContext
.DirIndex
= 0;
264 Status
= FindFile(DeviceExt
, ParentFcb
, &DirContext
.ShortNameU
, &SearchContext
, TRUE
);
265 if (!NT_SUCCESS(Status
))
270 if (i
== 100) /* FIXME : what to do after this ? */
272 ExFreePoolWithTag(Buffer
, TAG_VFAT
);
274 return STATUS_UNSUCCESSFUL
;
276 IsNameLegal
= RtlIsNameLegalDOS8Dot3(&DirContext
.ShortNameU
, &NameA
, &SpacesFound
);
277 aName
[NameA
.Length
]=0;
281 aName
[NameA
.Length
] = 0;
282 for (posCar
= 0; posCar
< DirContext
.LongNameU
.Length
/ sizeof(WCHAR
); posCar
++)
284 if (DirContext
.LongNameU
.Buffer
[posCar
] == L
'.')
289 /* check if the name and the extension contains upper case characters */
290 RtlDowncaseUnicodeString(&DirContext
.ShortNameU
, &DirContext
.LongNameU
, FALSE
);
291 DirContext
.ShortNameU
.Buffer
[DirContext
.ShortNameU
.Length
/ sizeof(WCHAR
)] = 0;
292 uCaseBase
= wcsncmp(DirContext
.LongNameU
.Buffer
,
293 DirContext
.ShortNameU
.Buffer
, posCar
) ? TRUE
: FALSE
;
294 if (posCar
< DirContext
.LongNameU
.Length
/sizeof(WCHAR
))
296 i
= DirContext
.LongNameU
.Length
/ sizeof(WCHAR
) - posCar
;
297 uCaseExt
= wcsncmp(DirContext
.LongNameU
.Buffer
+ posCar
,
298 DirContext
.ShortNameU
.Buffer
+ posCar
, i
) ? TRUE
: FALSE
;
304 /* check if the name and the extension contains lower case characters */
305 RtlUpcaseUnicodeString(&DirContext
.ShortNameU
, &DirContext
.LongNameU
, FALSE
);
306 DirContext
.ShortNameU
.Buffer
[DirContext
.ShortNameU
.Length
/ sizeof(WCHAR
)] = 0;
307 lCaseBase
= wcsncmp(DirContext
.LongNameU
.Buffer
,
308 DirContext
.ShortNameU
.Buffer
, posCar
) ? TRUE
: FALSE
;
309 if (posCar
< DirContext
.LongNameU
.Length
/ sizeof(WCHAR
))
311 i
= DirContext
.LongNameU
.Length
/ sizeof(WCHAR
) - posCar
;
312 lCaseExt
= wcsncmp(DirContext
.LongNameU
.Buffer
+ posCar
,
313 DirContext
.ShortNameU
.Buffer
+ posCar
, i
) ? TRUE
: FALSE
;
319 if ((lCaseBase
&& uCaseBase
) || (lCaseExt
&& uCaseExt
))
324 DPRINT("'%s', '%wZ', needTilde=%d, needLong=%d\n",
325 aName
, &DirContext
.LongNameU
, needTilde
, needLong
);
326 memset(DirContext
.DirEntry
.Fat
.ShortName
, ' ', 11);
327 for (i
= 0; i
< 8 && aName
[i
] && aName
[i
] != '.'; i
++)
329 DirContext
.DirEntry
.Fat
.Filename
[i
] = aName
[i
];
334 for (j
= 0; j
< 3 && aName
[i
]; j
++, i
++)
336 DirContext
.DirEntry
.Fat
.Ext
[j
] = aName
[i
];
339 if (DirContext
.DirEntry
.Fat
.Filename
[0] == 0xe5)
341 DirContext
.DirEntry
.Fat
.Filename
[0] = 0x05;
346 RtlCopyMemory(LongNameBuffer
, DirContext
.LongNameU
.Buffer
, DirContext
.LongNameU
.Length
);
347 DirContext
.LongNameU
.Buffer
= LongNameBuffer
;
348 DirContext
.LongNameU
.MaximumLength
= sizeof(LongNameBuffer
);
349 DirContext
.LongNameU
.Buffer
[DirContext
.LongNameU
.Length
/ sizeof(WCHAR
)] = 0;
350 memset(DirContext
.LongNameU
.Buffer
+ DirContext
.LongNameU
.Length
/ sizeof(WCHAR
) + 1, 0xff,
351 DirContext
.LongNameU
.MaximumLength
- DirContext
.LongNameU
.Length
- sizeof(WCHAR
));
358 DirContext
.DirEntry
.Fat
.lCase
|= VFAT_CASE_LOWER_BASE
;
362 DirContext
.DirEntry
.Fat
.lCase
|= VFAT_CASE_LOWER_EXT
;
366 DPRINT ("dos name=%11.11s\n", DirContext
.DirEntry
.Fat
.Filename
);
369 DirContext
.DirEntry
.Fat
.Attrib
= ReqAttr
;
370 if (RequestedOptions
& FILE_DIRECTORY_FILE
)
372 DirContext
.DirEntry
.Fat
.Attrib
|= FILE_ATTRIBUTE_DIRECTORY
;
374 /* set dates and times */
375 KeQuerySystemTime(&SystemTime
);
376 FsdSystemTimeToDosDateTime(DeviceExt
, &SystemTime
, &DirContext
.DirEntry
.Fat
.CreationDate
,
377 &DirContext
.DirEntry
.Fat
.CreationTime
);
378 DirContext
.DirEntry
.Fat
.UpdateDate
= DirContext
.DirEntry
.Fat
.CreationDate
;
379 DirContext
.DirEntry
.Fat
.UpdateTime
= DirContext
.DirEntry
.Fat
.CreationTime
;
380 DirContext
.DirEntry
.Fat
.AccessDate
= DirContext
.DirEntry
.Fat
.CreationDate
;
384 /* calculate checksum for 8.3 name */
385 for (pSlots
[0].alias_checksum
= 0, i
= 0; i
< 11; i
++)
387 pSlots
[0].alias_checksum
= (((pSlots
[0].alias_checksum
& 1) << 7
388 | ((pSlots
[0].alias_checksum
& 0xfe) >> 1))
389 + DirContext
.DirEntry
.Fat
.ShortName
[i
]);
391 /* construct slots and entry */
392 for (i
= nbSlots
- 2; i
>= 0; i
--)
394 DPRINT("construct slot %d\n", i
);
395 pSlots
[i
].attr
= 0xf;
398 pSlots
[i
].id
= (unsigned char)(nbSlots
- i
- 1);
402 pSlots
[i
].id
= (unsigned char)(nbSlots
- i
- 1 + 0x40);
404 pSlots
[i
].alias_checksum
= pSlots
[0].alias_checksum
;
405 RtlCopyMemory(pSlots
[i
].name0_4
, DirContext
.LongNameU
.Buffer
+ (nbSlots
- i
- 2) * 13, 10);
406 RtlCopyMemory(pSlots
[i
].name5_10
, DirContext
.LongNameU
.Buffer
+ (nbSlots
- i
- 2) * 13 + 5, 12);
407 RtlCopyMemory(pSlots
[i
].name11_12
, DirContext
.LongNameU
.Buffer
+ (nbSlots
- i
- 2) * 13 + 11, 4);
410 /* try to find nbSlots contiguous entries frees in directory */
411 if (!vfatFindDirSpace(DeviceExt
, ParentFcb
, nbSlots
, &DirContext
.StartIndex
))
413 ExFreePoolWithTag(Buffer
, TAG_VFAT
);
414 return STATUS_DISK_FULL
;
416 DirContext
.DirIndex
= DirContext
.StartIndex
+ nbSlots
- 1;
417 if (RequestedOptions
& FILE_DIRECTORY_FILE
)
420 Status
= NextCluster(DeviceExt
, 0, &CurrentCluster
, TRUE
);
421 if (CurrentCluster
== 0xffffffff || !NT_SUCCESS(Status
))
423 ExFreePoolWithTag(Buffer
, TAG_VFAT
);
424 if (!NT_SUCCESS(Status
))
428 return STATUS_DISK_FULL
;
430 if (DeviceExt
->FatInfo
.FatType
== FAT32
)
432 DirContext
.DirEntry
.Fat
.FirstClusterHigh
= (unsigned short)(CurrentCluster
>> 16);
434 DirContext
.DirEntry
.Fat
.FirstCluster
= (unsigned short)CurrentCluster
;
437 i
= DeviceExt
->FatInfo
.BytesPerCluster
/ sizeof(FAT_DIR_ENTRY
);
438 FileOffset
.u
.HighPart
= 0;
439 FileOffset
.u
.LowPart
= DirContext
.StartIndex
* sizeof(FAT_DIR_ENTRY
);
440 if (DirContext
.StartIndex
/ i
== DirContext
.DirIndex
/ i
)
444 CcPinRead(ParentFcb
->FileObject
, &FileOffset
, nbSlots
* sizeof(FAT_DIR_ENTRY
),
445 TRUE
, &Context
, (PVOID
*)&pFatEntry
);
448 RtlCopyMemory(pFatEntry
, Buffer
, (nbSlots
- 1) * sizeof(FAT_DIR_ENTRY
));
450 RtlCopyMemory(pFatEntry
+ (nbSlots
- 1), &DirContext
.DirEntry
.Fat
, sizeof(FAT_DIR_ENTRY
));
456 size
= DeviceExt
->FatInfo
.BytesPerCluster
-
457 (DirContext
.StartIndex
* sizeof(FAT_DIR_ENTRY
)) % DeviceExt
->FatInfo
.BytesPerCluster
;
458 i
= size
/ sizeof(FAT_DIR_ENTRY
);
459 CcPinRead(ParentFcb
->FileObject
, &FileOffset
, size
, TRUE
,
460 &Context
, (PVOID
*)&pFatEntry
);
461 RtlCopyMemory(pFatEntry
, Buffer
, size
);
462 CcSetDirtyPinnedData(Context
, NULL
);
463 CcUnpinData(Context
);
464 FileOffset
.u
.LowPart
+= size
;
465 CcPinRead(ParentFcb
->FileObject
, &FileOffset
,
466 nbSlots
* sizeof(FAT_DIR_ENTRY
) - size
,
467 TRUE
, &Context
, (PVOID
*)&pFatEntry
);
470 RtlCopyMemory(pFatEntry
, (PVOID
)(Buffer
+ size
), (nbSlots
- 1 - i
) * sizeof(FAT_DIR_ENTRY
));
472 RtlCopyMemory(pFatEntry
+ nbSlots
- 1 - i
, &DirContext
.DirEntry
.Fat
, sizeof(FAT_DIR_ENTRY
));
474 CcSetDirtyPinnedData(Context
, NULL
);
475 CcUnpinData(Context
);
477 /* FIXME: check status */
478 vfatMakeFCBFromDirEntry(DeviceExt
, ParentFcb
, &DirContext
, Fcb
);
480 DPRINT("new : entry=%11.11s\n", (*Fcb
)->entry
.Fat
.Filename
);
481 DPRINT("new : entry=%11.11s\n", DirContext
.DirEntry
.Fat
.Filename
);
483 if (RequestedOptions
& FILE_DIRECTORY_FILE
)
485 FileOffset
.QuadPart
= 0;
486 CcMapData((*Fcb
)->FileObject
, &FileOffset
, DeviceExt
->FatInfo
.BytesPerCluster
, TRUE
,
487 &Context
, (PVOID
*)&pFatEntry
);
488 /* clear the new directory cluster */
489 RtlZeroMemory(pFatEntry
, DeviceExt
->FatInfo
.BytesPerCluster
);
490 /* create '.' and '..' */
491 RtlCopyMemory(&pFatEntry
[0].Attrib
, &DirContext
.DirEntry
.Fat
.Attrib
, sizeof(FAT_DIR_ENTRY
) - 11);
492 RtlCopyMemory(pFatEntry
[0].ShortName
, ". ", 11);
493 RtlCopyMemory(&pFatEntry
[1].Attrib
, &DirContext
.DirEntry
.Fat
.Attrib
, sizeof(FAT_DIR_ENTRY
) - 11);
494 RtlCopyMemory(pFatEntry
[1].ShortName
, ".. ", 11);
495 pFatEntry
[1].FirstCluster
= ParentFcb
->entry
.Fat
.FirstCluster
;
496 pFatEntry
[1].FirstClusterHigh
= ParentFcb
->entry
.Fat
.FirstClusterHigh
;
497 if (vfatFCBIsRoot(ParentFcb
))
499 pFatEntry
[1].FirstCluster
= 0;
500 pFatEntry
[1].FirstClusterHigh
= 0;
502 CcSetDirtyPinnedData(Context
, NULL
);
503 CcUnpinData(Context
);
505 ExFreePoolWithTag(Buffer
, TAG_VFAT
);
506 DPRINT("addentry ok\n");
507 return STATUS_SUCCESS
;
511 create a new FAT entry
515 IN PDEVICE_EXTENSION DeviceExt
,
516 IN PUNICODE_STRING NameU
,
518 IN PVFATFCB ParentFcb
,
519 IN ULONG RequestedOptions
,
522 PVOID Context
= NULL
;
523 LARGE_INTEGER SystemTime
, FileOffset
;
525 VFAT_DIRENTRY_CONTEXT DirContext
;
526 PFATX_DIR_ENTRY pFatXDirEntry
;
529 DPRINT("addEntry: Name='%wZ', Dir='%wZ'\n", NameU
, &ParentFcb
->PathNameU
);
531 DirContext
.LongNameU
= *NameU
;
533 if (DirContext
.LongNameU
.Length
/ sizeof(WCHAR
) > 42)
537 return STATUS_NAME_TOO_LONG
;
540 /* try to find 1 entry free in directory */
541 if (!vfatFindDirSpace(DeviceExt
, ParentFcb
, 1, &DirContext
.StartIndex
))
543 return STATUS_DISK_FULL
;
545 Index
= DirContext
.DirIndex
= DirContext
.StartIndex
;
546 if (!vfatFCBIsRoot(ParentFcb
))
548 DirContext
.DirIndex
+= 2;
549 DirContext
.StartIndex
+= 2;
552 DirContext
.ShortNameU
.Buffer
= 0;
553 DirContext
.ShortNameU
.Length
= 0;
554 DirContext
.ShortNameU
.MaximumLength
= 0;
555 RtlZeroMemory(&DirContext
.DirEntry
.FatX
, sizeof(FATX_DIR_ENTRY
));
556 memset(DirContext
.DirEntry
.FatX
.Filename
, 0xff, 42);
557 DirContext
.DirEntry
.FatX
.FirstCluster
= 0;
558 DirContext
.DirEntry
.FatX
.FileSize
= 0;
561 NameA
.Buffer
= (PCHAR
)DirContext
.DirEntry
.FatX
.Filename
;
563 NameA
.MaximumLength
= 42;
564 RtlUnicodeStringToOemString(&NameA
, &DirContext
.LongNameU
, FALSE
);
565 DirContext
.DirEntry
.FatX
.FilenameLength
= (unsigned char)NameA
.Length
;
568 DirContext
.DirEntry
.FatX
.Attrib
= ReqAttr
;
569 if (RequestedOptions
& FILE_DIRECTORY_FILE
)
571 DirContext
.DirEntry
.FatX
.Attrib
|= FILE_ATTRIBUTE_DIRECTORY
;
574 /* set dates and times */
575 KeQuerySystemTime(&SystemTime
);
576 FsdSystemTimeToDosDateTime(DeviceExt
, &SystemTime
, &DirContext
.DirEntry
.FatX
.CreationDate
,
577 &DirContext
.DirEntry
.FatX
.CreationTime
);
578 DirContext
.DirEntry
.FatX
.UpdateDate
= DirContext
.DirEntry
.FatX
.CreationDate
;
579 DirContext
.DirEntry
.FatX
.UpdateTime
= DirContext
.DirEntry
.FatX
.CreationTime
;
580 DirContext
.DirEntry
.FatX
.AccessDate
= DirContext
.DirEntry
.FatX
.CreationDate
;
581 DirContext
.DirEntry
.FatX
.AccessTime
= DirContext
.DirEntry
.FatX
.CreationTime
;
583 /* add entry into parent directory */
584 FileOffset
.u
.HighPart
= 0;
585 FileOffset
.u
.LowPart
= Index
* sizeof(FATX_DIR_ENTRY
);
586 CcPinRead(ParentFcb
->FileObject
, &FileOffset
, sizeof(FATX_DIR_ENTRY
),
587 TRUE
, &Context
, (PVOID
*)&pFatXDirEntry
);
588 RtlCopyMemory(pFatXDirEntry
, &DirContext
.DirEntry
.FatX
, sizeof(FATX_DIR_ENTRY
));
589 CcSetDirtyPinnedData(Context
, NULL
);
590 CcUnpinData(Context
);
592 /* FIXME: check status */
593 vfatMakeFCBFromDirEntry(DeviceExt
, ParentFcb
, &DirContext
, Fcb
);
595 DPRINT("addentry ok\n");
596 return STATUS_SUCCESS
;
601 IN PDEVICE_EXTENSION DeviceExt
,
602 IN PUNICODE_STRING NameU
,
604 IN PVFATFCB ParentFcb
,
605 IN ULONG RequestedOptions
,
608 if (DeviceExt
->Flags
& VCB_IS_FATX
)
609 return FATXAddEntry(DeviceExt
, NameU
, Fcb
, ParentFcb
, RequestedOptions
, ReqAttr
);
611 return FATAddEntry(DeviceExt
, NameU
, Fcb
, ParentFcb
, RequestedOptions
, ReqAttr
);
615 * deleting an existing FAT entry
619 IN PDEVICE_EXTENSION DeviceExt
,
622 ULONG CurrentCluster
= 0, NextCluster
, i
;
623 PVOID Context
= NULL
;
624 LARGE_INTEGER Offset
;
625 PFAT_DIR_ENTRY pDirEntry
;
628 ASSERT(pFcb
->parentFcb
);
630 DPRINT("delEntry PathName \'%wZ\'\n", &pFcb
->PathNameU
);
631 DPRINT("delete entry: %d to %d\n", pFcb
->startIndex
, pFcb
->dirIndex
);
632 Offset
.u
.HighPart
= 0;
633 for (i
= pFcb
->startIndex
; i
<= pFcb
->dirIndex
; i
++)
635 if (Context
== NULL
|| ((i
* sizeof(FAT_DIR_ENTRY
)) % PAGE_SIZE
) == 0)
639 CcSetDirtyPinnedData(Context
, NULL
);
640 CcUnpinData(Context
);
642 Offset
.u
.LowPart
= (i
* sizeof(FAT_DIR_ENTRY
) / PAGE_SIZE
) * PAGE_SIZE
;
643 CcPinRead(pFcb
->parentFcb
->FileObject
, &Offset
, PAGE_SIZE
, TRUE
,
644 &Context
, (PVOID
*)&pDirEntry
);
646 pDirEntry
[i
% (PAGE_SIZE
/ sizeof(FAT_DIR_ENTRY
))].Filename
[0] = 0xe5;
647 if (i
== pFcb
->dirIndex
)
650 vfatDirEntryGetFirstCluster(DeviceExt
,
651 (PDIR_ENTRY
)&pDirEntry
[i
% (PAGE_SIZE
/ sizeof(FAT_DIR_ENTRY
))]);
656 CcSetDirtyPinnedData(Context
, NULL
);
657 CcUnpinData(Context
);
660 while (CurrentCluster
&& CurrentCluster
!= 0xffffffff)
662 GetNextCluster(DeviceExt
, CurrentCluster
, &NextCluster
);
663 /* FIXME: check status */
664 WriteCluster(DeviceExt
, CurrentCluster
, 0);
665 CurrentCluster
= NextCluster
;
667 return STATUS_SUCCESS
;
671 * deleting an existing FAT entry
675 IN PDEVICE_EXTENSION DeviceExt
,
678 ULONG CurrentCluster
= 0, NextCluster
;
679 PVOID Context
= NULL
;
680 LARGE_INTEGER Offset
;
681 PFATX_DIR_ENTRY pDirEntry
;
685 ASSERT(pFcb
->parentFcb
);
686 ASSERT(pFcb
->Flags
& FCB_IS_FATX_ENTRY
);
688 StartIndex
= pFcb
->startIndex
;
690 DPRINT("delEntry PathName \'%wZ\'\n", &pFcb
->PathNameU
);
691 DPRINT("delete entry: %d\n", StartIndex
);
692 Offset
.u
.HighPart
= 0;
693 Offset
.u
.LowPart
= (StartIndex
* sizeof(FATX_DIR_ENTRY
) / PAGE_SIZE
) * PAGE_SIZE
;
694 if (!CcPinRead(pFcb
->parentFcb
->FileObject
, &Offset
, PAGE_SIZE
, TRUE
,
695 &Context
, (PVOID
*)&pDirEntry
))
697 DPRINT1("CcPinRead(Offset %x:%x, Length %d) failed\n", Offset
.u
.HighPart
, Offset
.u
.LowPart
, PAGE_SIZE
);
698 return STATUS_UNSUCCESSFUL
;
700 pDirEntry
= &pDirEntry
[StartIndex
% (PAGE_SIZE
/ sizeof(FATX_DIR_ENTRY
))];
701 pDirEntry
->FilenameLength
= 0xe5;
702 CurrentCluster
= vfatDirEntryGetFirstCluster(DeviceExt
,
703 (PDIR_ENTRY
)pDirEntry
);
704 CcSetDirtyPinnedData(Context
, NULL
);
705 CcUnpinData(Context
);
707 while (CurrentCluster
&& CurrentCluster
!= 0xffffffff)
709 GetNextCluster(DeviceExt
, CurrentCluster
, &NextCluster
);
710 /* FIXME: check status */
711 WriteCluster(DeviceExt
, CurrentCluster
, 0);
712 CurrentCluster
= NextCluster
;
714 return STATUS_SUCCESS
;
719 IN PDEVICE_EXTENSION DeviceExt
,
722 if (DeviceExt
->Flags
& VCB_IS_FATX
)
723 return FATXDelEntry(DeviceExt
, pFcb
);
725 return FATDelEntry(DeviceExt
, pFcb
);