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
29 if (pFcb
->Flags
& FCB_IS_FATX_ENTRY
)
31 SizeDirEntry
= sizeof(FATX_DIR_ENTRY
);
32 dirIndex
= pFcb
->startIndex
;
36 SizeDirEntry
= sizeof(FAT_DIR_ENTRY
);
37 dirIndex
= pFcb
->dirIndex
;
40 DPRINT("updEntry dirIndex %d, PathName \'%wZ\'\n", dirIndex
, &pFcb
->PathNameU
);
42 if (vfatFCBIsRoot(pFcb
) || (pFcb
->Flags
& (FCB_IS_FAT
|FCB_IS_VOLUME
)))
44 return STATUS_SUCCESS
;
47 ASSERT(pFcb
->parentFcb
);
49 Offset
.u
.HighPart
= 0;
50 Offset
.u
.LowPart
= dirIndex
* SizeDirEntry
;
51 if (CcPinRead(pFcb
->parentFcb
->FileObject
, &Offset
, SizeDirEntry
,
52 TRUE
, &Context
, (PVOID
*)&PinEntry
))
54 pFcb
->Flags
&= ~FCB_IS_DIRTY
;
55 RtlCopyMemory(PinEntry
, &pFcb
->entry
, SizeDirEntry
);
56 CcSetDirtyPinnedData(Context
, NULL
);
58 return STATUS_SUCCESS
;
62 DPRINT1("Failed write to \'%wZ\'.\n", &pFcb
->parentFcb
->PathNameU
);
63 return STATUS_UNSUCCESSFUL
;
68 * try to find contiguous entries frees in directory,
69 * extend a directory if is neccesary
73 IN PDEVICE_EXTENSION DeviceExt
,
78 LARGE_INTEGER FileOffset
;
79 ULONG i
, count
, size
, nbFree
= 0;
80 PDIR_ENTRY pFatEntry
= NULL
;
84 FileOffset
.QuadPart
= 0;
86 if (DeviceExt
->Flags
& VCB_IS_FATX
)
87 SizeDirEntry
= sizeof(FATX_DIR_ENTRY
);
89 SizeDirEntry
= sizeof(FAT_DIR_ENTRY
);
91 count
= pDirFcb
->RFCB
.FileSize
.u
.LowPart
/ SizeDirEntry
;
92 size
= DeviceExt
->FatInfo
.BytesPerCluster
/ SizeDirEntry
;
93 for (i
= 0; i
< count
; i
++, pFatEntry
= (PDIR_ENTRY
)((ULONG_PTR
)pFatEntry
+ SizeDirEntry
))
95 if (Context
== NULL
|| (i
% size
) == 0)
101 /* FIXME: check return value */
102 CcPinRead(pDirFcb
->FileObject
, &FileOffset
, DeviceExt
->FatInfo
.BytesPerCluster
,
103 TRUE
, &Context
, (PVOID
*)&pFatEntry
);
104 FileOffset
.u
.LowPart
+= DeviceExt
->FatInfo
.BytesPerCluster
;
106 if (ENTRY_END(DeviceExt
, pFatEntry
))
110 if (ENTRY_DELETED(DeviceExt
, pFatEntry
))
118 if (nbFree
== nbSlots
)
125 CcUnpinData(Context
);
128 if (nbFree
== nbSlots
)
130 /* found enough contiguous free slots */
131 *start
= i
- nbSlots
+ 1;
136 if (*start
+ nbSlots
> count
)
138 LARGE_INTEGER AllocationSize
;
139 /* extend the directory */
140 if (vfatFCBIsRoot(pDirFcb
) && DeviceExt
->FatInfo
.FatType
!= FAT32
)
142 /* We can't extend a root directory on a FAT12/FAT16/FATX partition */
145 AllocationSize
.QuadPart
= pDirFcb
->RFCB
.FileSize
.u
.LowPart
+ DeviceExt
->FatInfo
.BytesPerCluster
;
146 Status
= VfatSetAllocationSizeInformation(pDirFcb
->FileObject
, pDirFcb
,
147 DeviceExt
, &AllocationSize
);
148 if (!NT_SUCCESS(Status
))
152 /* clear the new dir cluster */
153 FileOffset
.u
.LowPart
= (ULONG
)(pDirFcb
->RFCB
.FileSize
.QuadPart
-
154 DeviceExt
->FatInfo
.BytesPerCluster
);
155 CcPinRead(pDirFcb
->FileObject
, &FileOffset
, DeviceExt
->FatInfo
.BytesPerCluster
,
156 TRUE
, &Context
, (PVOID
*)&pFatEntry
);
157 if (DeviceExt
->Flags
& VCB_IS_FATX
)
158 memset(pFatEntry
, 0xff, DeviceExt
->FatInfo
.BytesPerCluster
);
160 RtlZeroMemory(pFatEntry
, DeviceExt
->FatInfo
.BytesPerCluster
);
162 else if (*start
+ nbSlots
< count
)
164 /* clear the entry after the last new entry */
165 FileOffset
.u
.LowPart
= (*start
+ nbSlots
) * SizeDirEntry
;
166 CcPinRead(pDirFcb
->FileObject
, &FileOffset
, SizeDirEntry
,
167 TRUE
, &Context
, (PVOID
*)&pFatEntry
);
168 if (DeviceExt
->Flags
& VCB_IS_FATX
)
169 memset(pFatEntry
, 0xff, SizeDirEntry
);
171 RtlZeroMemory(pFatEntry
, SizeDirEntry
);
175 CcSetDirtyPinnedData(Context
, NULL
);
176 CcUnpinData(Context
);
179 DPRINT("nbSlots %d nbFree %d, entry number %d\n", nbSlots
, nbFree
, *start
);
184 create a new FAT entry
188 IN PDEVICE_EXTENSION DeviceExt
,
189 IN PUNICODE_STRING NameU
,
191 IN PVFATFCB ParentFcb
,
192 IN ULONG RequestedOptions
,
195 PVOID Context
= NULL
;
196 PFAT_DIR_ENTRY pFatEntry
;
198 USHORT nbSlots
= 0, j
, posCar
;
200 BOOLEAN needTilde
= FALSE
, needLong
= FALSE
;
201 BOOLEAN lCaseBase
= FALSE
, uCaseBase
, lCaseExt
= FALSE
, uCaseExt
;
202 ULONG CurrentCluster
;
203 LARGE_INTEGER SystemTime
, FileOffset
;
204 NTSTATUS Status
= STATUS_SUCCESS
;
213 VFAT_DIRENTRY_CONTEXT DirContext
;
214 WCHAR LongNameBuffer
[LONGNAME_MAX_LENGTH
+ 1];
215 WCHAR ShortNameBuffer
[13];
217 DPRINT("addEntry: Name='%wZ', Dir='%wZ'\n", NameU
, &ParentFcb
->PathNameU
);
219 DirContext
.LongNameU
= *NameU
;
221 /* nb of entry needed for long name+normal entry */
222 nbSlots
= (DirContext
.LongNameU
.Length
/ sizeof(WCHAR
) + 12) / 13 + 1;
223 DPRINT("NameLen= %d, nbSlots =%d\n", DirContext
.LongNameU
.Length
/ sizeof(WCHAR
), nbSlots
);
224 Buffer
= ExAllocatePoolWithTag(NonPagedPool
, (nbSlots
- 1) * sizeof(FAT_DIR_ENTRY
), TAG_VFAT
);
227 return STATUS_INSUFFICIENT_RESOURCES
;
229 RtlZeroMemory(Buffer
, (nbSlots
- 1) * sizeof(FAT_DIR_ENTRY
));
230 pSlots
= (slot
*) Buffer
;
232 NameA
.Buffer
= aName
;
234 NameA
.MaximumLength
= sizeof(aName
);
236 DirContext
.ShortNameU
.Buffer
= ShortNameBuffer
;
237 DirContext
.ShortNameU
.Length
= 0;
238 DirContext
.ShortNameU
.MaximumLength
= sizeof(ShortNameBuffer
);
240 RtlZeroMemory(&DirContext
.DirEntry
.Fat
, sizeof(FAT_DIR_ENTRY
));
242 IsNameLegal
= RtlIsNameLegalDOS8Dot3(&DirContext
.LongNameU
, &NameA
, &SpacesFound
);
244 if (!IsNameLegal
|| SpacesFound
)
246 GENERATE_NAME_CONTEXT NameContext
;
247 VFAT_DIRENTRY_CONTEXT SearchContext
;
248 WCHAR ShortSearchName
[13];
251 RtlZeroMemory(&NameContext
, sizeof(GENERATE_NAME_CONTEXT
));
252 SearchContext
.LongNameU
.Buffer
= LongNameBuffer
;
253 SearchContext
.LongNameU
.MaximumLength
= sizeof(LongNameBuffer
);
254 SearchContext
.ShortNameU
.Buffer
= ShortSearchName
;
255 SearchContext
.ShortNameU
.MaximumLength
= sizeof(ShortSearchName
);
257 for (i
= 0; i
< 100; i
++)
259 RtlGenerate8dot3Name(&DirContext
.LongNameU
, FALSE
, &NameContext
, &DirContext
.ShortNameU
);
260 DirContext
.ShortNameU
.Buffer
[DirContext
.ShortNameU
.Length
/ sizeof(WCHAR
)] = 0;
261 SearchContext
.DirIndex
= 0;
262 Status
= FindFile(DeviceExt
, ParentFcb
, &DirContext
.ShortNameU
, &SearchContext
, TRUE
);
263 if (!NT_SUCCESS(Status
))
268 if (i
== 100) /* FIXME : what to do after this ? */
270 ExFreePoolWithTag(Buffer
, TAG_VFAT
);
271 return STATUS_UNSUCCESSFUL
;
273 IsNameLegal
= RtlIsNameLegalDOS8Dot3(&DirContext
.ShortNameU
, &NameA
, &SpacesFound
);
274 aName
[NameA
.Length
]=0;
278 aName
[NameA
.Length
] = 0;
279 for (posCar
= 0; posCar
< DirContext
.LongNameU
.Length
/ sizeof(WCHAR
); posCar
++)
281 if (DirContext
.LongNameU
.Buffer
[posCar
] == L
'.')
286 /* check if the name and the extension contains upper case characters */
287 RtlDowncaseUnicodeString(&DirContext
.ShortNameU
, &DirContext
.LongNameU
, FALSE
);
288 DirContext
.ShortNameU
.Buffer
[DirContext
.ShortNameU
.Length
/ sizeof(WCHAR
)] = 0;
289 uCaseBase
= wcsncmp(DirContext
.LongNameU
.Buffer
,
290 DirContext
.ShortNameU
.Buffer
, posCar
) ? TRUE
: FALSE
;
291 if (posCar
< DirContext
.LongNameU
.Length
/sizeof(WCHAR
))
293 i
= DirContext
.LongNameU
.Length
/ sizeof(WCHAR
) - posCar
;
294 uCaseExt
= wcsncmp(DirContext
.LongNameU
.Buffer
+ posCar
,
295 DirContext
.ShortNameU
.Buffer
+ posCar
, i
) ? TRUE
: FALSE
;
301 /* check if the name and the extension contains lower case characters */
302 RtlUpcaseUnicodeString(&DirContext
.ShortNameU
, &DirContext
.LongNameU
, FALSE
);
303 DirContext
.ShortNameU
.Buffer
[DirContext
.ShortNameU
.Length
/ sizeof(WCHAR
)] = 0;
304 lCaseBase
= wcsncmp(DirContext
.LongNameU
.Buffer
,
305 DirContext
.ShortNameU
.Buffer
, posCar
) ? TRUE
: FALSE
;
306 if (posCar
< DirContext
.LongNameU
.Length
/ sizeof(WCHAR
))
308 i
= DirContext
.LongNameU
.Length
/ sizeof(WCHAR
) - posCar
;
309 lCaseExt
= wcsncmp(DirContext
.LongNameU
.Buffer
+ posCar
,
310 DirContext
.ShortNameU
.Buffer
+ posCar
, i
) ? TRUE
: FALSE
;
316 if ((lCaseBase
&& uCaseBase
) || (lCaseExt
&& uCaseExt
))
321 DPRINT("'%s', '%wZ', needTilde=%d, needLong=%d\n",
322 aName
, &DirContext
.LongNameU
, needTilde
, needLong
);
323 memset(DirContext
.DirEntry
.Fat
.ShortName
, ' ', 11);
324 for (i
= 0; i
< 8 && aName
[i
] && aName
[i
] != '.'; i
++)
326 DirContext
.DirEntry
.Fat
.Filename
[i
] = aName
[i
];
331 for (j
= 0; j
< 3 && aName
[i
]; j
++, i
++)
333 DirContext
.DirEntry
.Fat
.Ext
[j
] = aName
[i
];
336 if (DirContext
.DirEntry
.Fat
.Filename
[0] == 0xe5)
338 DirContext
.DirEntry
.Fat
.Filename
[0] = 0x05;
343 RtlCopyMemory(LongNameBuffer
, DirContext
.LongNameU
.Buffer
, DirContext
.LongNameU
.Length
);
344 DirContext
.LongNameU
.Buffer
= LongNameBuffer
;
345 DirContext
.LongNameU
.MaximumLength
= sizeof(LongNameBuffer
);
346 DirContext
.LongNameU
.Buffer
[DirContext
.LongNameU
.Length
/ sizeof(WCHAR
)] = 0;
347 memset(DirContext
.LongNameU
.Buffer
+ DirContext
.LongNameU
.Length
/ sizeof(WCHAR
) + 1, 0xff,
348 DirContext
.LongNameU
.MaximumLength
- DirContext
.LongNameU
.Length
- sizeof(WCHAR
));
355 DirContext
.DirEntry
.Fat
.lCase
|= VFAT_CASE_LOWER_BASE
;
359 DirContext
.DirEntry
.Fat
.lCase
|= VFAT_CASE_LOWER_EXT
;
363 DPRINT ("dos name=%11.11s\n", DirContext
.DirEntry
.Fat
.Filename
);
366 DirContext
.DirEntry
.Fat
.Attrib
= ReqAttr
;
367 if (RequestedOptions
& FILE_DIRECTORY_FILE
)
369 DirContext
.DirEntry
.Fat
.Attrib
|= FILE_ATTRIBUTE_DIRECTORY
;
371 /* set dates and times */
372 KeQuerySystemTime(&SystemTime
);
373 FsdSystemTimeToDosDateTime(DeviceExt
, &SystemTime
, &DirContext
.DirEntry
.Fat
.CreationDate
,
374 &DirContext
.DirEntry
.Fat
.CreationTime
);
375 DirContext
.DirEntry
.Fat
.UpdateDate
= DirContext
.DirEntry
.Fat
.CreationDate
;
376 DirContext
.DirEntry
.Fat
.UpdateTime
= DirContext
.DirEntry
.Fat
.CreationTime
;
377 DirContext
.DirEntry
.Fat
.AccessDate
= DirContext
.DirEntry
.Fat
.CreationDate
;
381 /* calculate checksum for 8.3 name */
382 for (pSlots
[0].alias_checksum
= 0, i
= 0; i
< 11; i
++)
384 pSlots
[0].alias_checksum
= (((pSlots
[0].alias_checksum
& 1) << 7
385 | ((pSlots
[0].alias_checksum
& 0xfe) >> 1))
386 + DirContext
.DirEntry
.Fat
.ShortName
[i
]);
388 /* construct slots and entry */
389 for (i
= nbSlots
- 2; i
>= 0; i
--)
391 DPRINT("construct slot %d\n", i
);
392 pSlots
[i
].attr
= 0xf;
395 pSlots
[i
].id
= (unsigned char)(nbSlots
- i
- 1);
399 pSlots
[i
].id
= (unsigned char)(nbSlots
- i
- 1 + 0x40);
401 pSlots
[i
].alias_checksum
= pSlots
[0].alias_checksum
;
402 RtlCopyMemory(pSlots
[i
].name0_4
, DirContext
.LongNameU
.Buffer
+ (nbSlots
- i
- 2) * 13, 10);
403 RtlCopyMemory(pSlots
[i
].name5_10
, DirContext
.LongNameU
.Buffer
+ (nbSlots
- i
- 2) * 13 + 5, 12);
404 RtlCopyMemory(pSlots
[i
].name11_12
, DirContext
.LongNameU
.Buffer
+ (nbSlots
- i
- 2) * 13 + 11, 4);
407 /* try to find nbSlots contiguous entries frees in directory */
408 if (!vfatFindDirSpace(DeviceExt
, ParentFcb
, nbSlots
, &DirContext
.StartIndex
))
410 ExFreePoolWithTag(Buffer
, TAG_VFAT
);
411 return STATUS_DISK_FULL
;
413 DirContext
.DirIndex
= DirContext
.StartIndex
+ nbSlots
- 1;
414 if (RequestedOptions
& FILE_DIRECTORY_FILE
)
417 Status
= NextCluster(DeviceExt
, 0, &CurrentCluster
, TRUE
);
418 if (CurrentCluster
== 0xffffffff || !NT_SUCCESS(Status
))
420 ExFreePoolWithTag(Buffer
, TAG_VFAT
);
421 if (!NT_SUCCESS(Status
))
425 return STATUS_DISK_FULL
;
427 if (DeviceExt
->FatInfo
.FatType
== FAT32
)
429 DirContext
.DirEntry
.Fat
.FirstClusterHigh
= (unsigned short)(CurrentCluster
>> 16);
431 DirContext
.DirEntry
.Fat
.FirstCluster
= (unsigned short)CurrentCluster
;
434 i
= DeviceExt
->FatInfo
.BytesPerCluster
/ sizeof(FAT_DIR_ENTRY
);
435 FileOffset
.u
.HighPart
= 0;
436 FileOffset
.u
.LowPart
= DirContext
.StartIndex
* sizeof(FAT_DIR_ENTRY
);
437 if (DirContext
.StartIndex
/ i
== DirContext
.DirIndex
/ i
)
440 CcPinRead(ParentFcb
->FileObject
, &FileOffset
, nbSlots
* sizeof(FAT_DIR_ENTRY
),
441 TRUE
, &Context
, (PVOID
*)&pFatEntry
);
444 RtlCopyMemory(pFatEntry
, Buffer
, (nbSlots
- 1) * sizeof(FAT_DIR_ENTRY
));
446 RtlCopyMemory(pFatEntry
+ (nbSlots
- 1), &DirContext
.DirEntry
.Fat
, sizeof(FAT_DIR_ENTRY
));
451 size
= DeviceExt
->FatInfo
.BytesPerCluster
-
452 (DirContext
.StartIndex
* sizeof(FAT_DIR_ENTRY
)) % DeviceExt
->FatInfo
.BytesPerCluster
;
453 i
= size
/ sizeof(FAT_DIR_ENTRY
);
454 CcPinRead(ParentFcb
->FileObject
, &FileOffset
, size
, TRUE
,
455 &Context
, (PVOID
*)&pFatEntry
);
456 RtlCopyMemory(pFatEntry
, Buffer
, size
);
457 CcSetDirtyPinnedData(Context
, NULL
);
458 CcUnpinData(Context
);
459 FileOffset
.u
.LowPart
+= size
;
460 CcPinRead(ParentFcb
->FileObject
, &FileOffset
,
461 nbSlots
* sizeof(FAT_DIR_ENTRY
) - size
,
462 TRUE
, &Context
, (PVOID
*)&pFatEntry
);
465 RtlCopyMemory(pFatEntry
, (PVOID
)(Buffer
+ size
), (nbSlots
- 1 - i
) * sizeof(FAT_DIR_ENTRY
));
467 RtlCopyMemory(pFatEntry
+ nbSlots
- 1 - i
, &DirContext
.DirEntry
.Fat
, sizeof(FAT_DIR_ENTRY
));
469 CcSetDirtyPinnedData(Context
, NULL
);
470 CcUnpinData(Context
);
472 /* FIXME: check status */
473 vfatMakeFCBFromDirEntry(DeviceExt
, ParentFcb
, &DirContext
, Fcb
);
475 DPRINT("new : entry=%11.11s\n", (*Fcb
)->entry
.Fat
.Filename
);
476 DPRINT("new : entry=%11.11s\n", DirContext
.DirEntry
.Fat
.Filename
);
478 if (RequestedOptions
& FILE_DIRECTORY_FILE
)
480 FileOffset
.QuadPart
= 0;
481 CcPinRead((*Fcb
)->FileObject
, &FileOffset
, DeviceExt
->FatInfo
.BytesPerCluster
, TRUE
,
482 &Context
, (PVOID
*)&pFatEntry
);
483 /* clear the new directory cluster */
484 RtlZeroMemory(pFatEntry
, DeviceExt
->FatInfo
.BytesPerCluster
);
485 /* create '.' and '..' */
486 RtlCopyMemory(&pFatEntry
[0].Attrib
, &DirContext
.DirEntry
.Fat
.Attrib
, sizeof(FAT_DIR_ENTRY
) - 11);
487 RtlCopyMemory(pFatEntry
[0].ShortName
, ". ", 11);
488 RtlCopyMemory(&pFatEntry
[1].Attrib
, &DirContext
.DirEntry
.Fat
.Attrib
, sizeof(FAT_DIR_ENTRY
) - 11);
489 RtlCopyMemory(pFatEntry
[1].ShortName
, ".. ", 11);
490 pFatEntry
[1].FirstCluster
= ParentFcb
->entry
.Fat
.FirstCluster
;
491 pFatEntry
[1].FirstClusterHigh
= ParentFcb
->entry
.Fat
.FirstClusterHigh
;
492 if (vfatFCBIsRoot(ParentFcb
))
494 pFatEntry
[1].FirstCluster
= 0;
495 pFatEntry
[1].FirstClusterHigh
= 0;
497 CcSetDirtyPinnedData(Context
, NULL
);
498 CcUnpinData(Context
);
500 ExFreePoolWithTag(Buffer
, TAG_VFAT
);
501 DPRINT("addentry ok\n");
502 return STATUS_SUCCESS
;
506 create a new FAT entry
510 IN PDEVICE_EXTENSION DeviceExt
,
511 IN PUNICODE_STRING NameU
,
513 IN PVFATFCB ParentFcb
,
514 IN ULONG RequestedOptions
,
517 PVOID Context
= NULL
;
518 LARGE_INTEGER SystemTime
, FileOffset
;
520 VFAT_DIRENTRY_CONTEXT DirContext
;
521 PFATX_DIR_ENTRY pFatXDirEntry
;
524 DPRINT("addEntry: Name='%wZ', Dir='%wZ'\n", NameU
, &ParentFcb
->PathNameU
);
526 DirContext
.LongNameU
= *NameU
;
528 if (DirContext
.LongNameU
.Length
/ sizeof(WCHAR
) > 42)
531 return STATUS_NAME_TOO_LONG
;
534 /* try to find 1 entry free in directory */
535 if (!vfatFindDirSpace(DeviceExt
, ParentFcb
, 1, &DirContext
.StartIndex
))
537 return STATUS_DISK_FULL
;
539 Index
= DirContext
.DirIndex
= DirContext
.StartIndex
;
540 if (!vfatFCBIsRoot(ParentFcb
))
542 DirContext
.DirIndex
+= 2;
543 DirContext
.StartIndex
+= 2;
546 DirContext
.ShortNameU
.Buffer
= 0;
547 DirContext
.ShortNameU
.Length
= 0;
548 DirContext
.ShortNameU
.MaximumLength
= 0;
549 RtlZeroMemory(&DirContext
.DirEntry
.FatX
, sizeof(FATX_DIR_ENTRY
));
550 memset(DirContext
.DirEntry
.FatX
.Filename
, 0xff, 42);
551 DirContext
.DirEntry
.FatX
.FirstCluster
= 0;
552 DirContext
.DirEntry
.FatX
.FileSize
= 0;
555 NameA
.Buffer
= (PCHAR
)DirContext
.DirEntry
.FatX
.Filename
;
557 NameA
.MaximumLength
= 42;
558 RtlUnicodeStringToOemString(&NameA
, &DirContext
.LongNameU
, FALSE
);
559 DirContext
.DirEntry
.FatX
.FilenameLength
= (unsigned char)NameA
.Length
;
562 DirContext
.DirEntry
.FatX
.Attrib
= ReqAttr
;
563 if (RequestedOptions
& FILE_DIRECTORY_FILE
)
565 DirContext
.DirEntry
.FatX
.Attrib
|= FILE_ATTRIBUTE_DIRECTORY
;
568 /* set dates and times */
569 KeQuerySystemTime(&SystemTime
);
570 FsdSystemTimeToDosDateTime(DeviceExt
, &SystemTime
, &DirContext
.DirEntry
.FatX
.CreationDate
,
571 &DirContext
.DirEntry
.FatX
.CreationTime
);
572 DirContext
.DirEntry
.FatX
.UpdateDate
= DirContext
.DirEntry
.FatX
.CreationDate
;
573 DirContext
.DirEntry
.FatX
.UpdateTime
= DirContext
.DirEntry
.FatX
.CreationTime
;
574 DirContext
.DirEntry
.FatX
.AccessDate
= DirContext
.DirEntry
.FatX
.CreationDate
;
575 DirContext
.DirEntry
.FatX
.AccessTime
= DirContext
.DirEntry
.FatX
.CreationTime
;
577 /* add entry into parent directory */
578 FileOffset
.u
.HighPart
= 0;
579 FileOffset
.u
.LowPart
= Index
* sizeof(FATX_DIR_ENTRY
);
580 CcPinRead(ParentFcb
->FileObject
, &FileOffset
, sizeof(FATX_DIR_ENTRY
),
581 TRUE
, &Context
, (PVOID
*)&pFatXDirEntry
);
582 RtlCopyMemory(pFatXDirEntry
, &DirContext
.DirEntry
.FatX
, sizeof(FATX_DIR_ENTRY
));
583 CcSetDirtyPinnedData(Context
, NULL
);
584 CcUnpinData(Context
);
586 /* FIXME: check status */
587 vfatMakeFCBFromDirEntry(DeviceExt
, ParentFcb
, &DirContext
, Fcb
);
589 DPRINT("addentry ok\n");
590 return STATUS_SUCCESS
;
595 IN PDEVICE_EXTENSION DeviceExt
,
596 IN PUNICODE_STRING NameU
,
598 IN PVFATFCB ParentFcb
,
599 IN ULONG RequestedOptions
,
602 if (DeviceExt
->Flags
& VCB_IS_FATX
)
603 return FATXAddEntry(DeviceExt
, NameU
, Fcb
, ParentFcb
, RequestedOptions
, ReqAttr
);
605 return FATAddEntry(DeviceExt
, NameU
, Fcb
, ParentFcb
, RequestedOptions
, ReqAttr
);
609 * deleting an existing FAT entry
613 IN PDEVICE_EXTENSION DeviceExt
,
616 ULONG CurrentCluster
= 0, NextCluster
, i
;
617 PVOID Context
= NULL
;
618 LARGE_INTEGER Offset
;
619 PFAT_DIR_ENTRY pDirEntry
= NULL
;
622 ASSERT(pFcb
->parentFcb
);
624 DPRINT("delEntry PathName \'%wZ\'\n", &pFcb
->PathNameU
);
625 DPRINT("delete entry: %d to %d\n", pFcb
->startIndex
, pFcb
->dirIndex
);
626 Offset
.u
.HighPart
= 0;
627 for (i
= pFcb
->startIndex
; i
<= pFcb
->dirIndex
; i
++)
629 if (Context
== NULL
|| ((i
* sizeof(FAT_DIR_ENTRY
)) % PAGE_SIZE
) == 0)
633 CcSetDirtyPinnedData(Context
, NULL
);
634 CcUnpinData(Context
);
636 Offset
.u
.LowPart
= (i
* sizeof(FAT_DIR_ENTRY
) / PAGE_SIZE
) * PAGE_SIZE
;
637 CcPinRead(pFcb
->parentFcb
->FileObject
, &Offset
, PAGE_SIZE
, TRUE
,
638 &Context
, (PVOID
*)&pDirEntry
);
640 pDirEntry
[i
% (PAGE_SIZE
/ sizeof(FAT_DIR_ENTRY
))].Filename
[0] = 0xe5;
641 if (i
== pFcb
->dirIndex
)
644 vfatDirEntryGetFirstCluster(DeviceExt
,
645 (PDIR_ENTRY
)&pDirEntry
[i
% (PAGE_SIZE
/ sizeof(FAT_DIR_ENTRY
))]);
650 CcSetDirtyPinnedData(Context
, NULL
);
651 CcUnpinData(Context
);
654 while (CurrentCluster
&& CurrentCluster
!= 0xffffffff)
656 GetNextCluster(DeviceExt
, CurrentCluster
, &NextCluster
);
657 /* FIXME: check status */
658 WriteCluster(DeviceExt
, CurrentCluster
, 0);
659 CurrentCluster
= NextCluster
;
661 return STATUS_SUCCESS
;
665 * deleting an existing FAT entry
669 IN PDEVICE_EXTENSION DeviceExt
,
672 ULONG CurrentCluster
= 0, NextCluster
;
673 PVOID Context
= NULL
;
674 LARGE_INTEGER Offset
;
675 PFATX_DIR_ENTRY pDirEntry
;
679 ASSERT(pFcb
->parentFcb
);
680 ASSERT(pFcb
->Flags
& FCB_IS_FATX_ENTRY
);
682 StartIndex
= pFcb
->startIndex
;
684 DPRINT("delEntry PathName \'%wZ\'\n", &pFcb
->PathNameU
);
685 DPRINT("delete entry: %d\n", StartIndex
);
686 Offset
.u
.HighPart
= 0;
687 Offset
.u
.LowPart
= (StartIndex
* sizeof(FATX_DIR_ENTRY
) / PAGE_SIZE
) * PAGE_SIZE
;
688 if (!CcPinRead(pFcb
->parentFcb
->FileObject
, &Offset
, PAGE_SIZE
, TRUE
,
689 &Context
, (PVOID
*)&pDirEntry
))
691 DPRINT1("CcPinRead(Offset %x:%x, Length %d) failed\n", Offset
.u
.HighPart
, Offset
.u
.LowPart
, PAGE_SIZE
);
692 return STATUS_UNSUCCESSFUL
;
694 pDirEntry
= &pDirEntry
[StartIndex
% (PAGE_SIZE
/ sizeof(FATX_DIR_ENTRY
))];
695 pDirEntry
->FilenameLength
= 0xe5;
696 CurrentCluster
= vfatDirEntryGetFirstCluster(DeviceExt
,
697 (PDIR_ENTRY
)pDirEntry
);
698 CcSetDirtyPinnedData(Context
, NULL
);
699 CcUnpinData(Context
);
701 while (CurrentCluster
&& CurrentCluster
!= 0xffffffff)
703 GetNextCluster(DeviceExt
, CurrentCluster
, &NextCluster
);
704 /* FIXME: check status */
705 WriteCluster(DeviceExt
, CurrentCluster
, 0);
706 CurrentCluster
= NextCluster
;
708 return STATUS_SUCCESS
;
713 IN PDEVICE_EXTENSION DeviceExt
,
716 if (DeviceExt
->Flags
& VCB_IS_FATX
)
717 return FATXDelEntry(DeviceExt
, pFcb
);
719 return FATDelEntry(DeviceExt
, pFcb
);