3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * PROJECT: ReactOS kernel
21 * FILE: drivers/fs/vfat/create.c
22 * PURPOSE: VFAT Filesystem
23 * PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
26 /* INCLUDES *****************************************************************/
33 /* FUNCTIONS *****************************************************************/
37 PFAT_DIR_ENTRY pEntry
,
38 PUNICODE_STRING NameU
)
44 RtlCopyMemory(cString
, pEntry
->ShortName
, 11);
46 if (cString
[0] == 0x05)
51 StringA
.Buffer
= cString
;
52 for (StringA
.Length
= 0;
53 StringA
.Length
< 8 && StringA
.Buffer
[StringA
.Length
] != ' ';
55 StringA
.MaximumLength
= StringA
.Length
;
57 RtlOemStringToUnicodeString(NameU
, &StringA
, FALSE
);
59 if (pEntry
->lCase
& VFAT_CASE_LOWER_BASE
)
61 RtlDowncaseUnicodeString(NameU
, NameU
, FALSE
);
64 if (cString
[8] != ' ')
66 Length
= NameU
->Length
;
67 NameU
->Buffer
+= Length
/ sizeof(WCHAR
);
68 if (!FAT_ENTRY_VOLUME(pEntry
))
70 Length
+= sizeof(WCHAR
);
71 NameU
->Buffer
[0] = L
'.';
75 NameU
->MaximumLength
-= Length
;
77 StringA
.Buffer
= &cString
[8];
78 for (StringA
.Length
= 0;
79 StringA
.Length
< 3 && StringA
.Buffer
[StringA
.Length
] != ' ';
81 StringA
.MaximumLength
= StringA
.Length
;
82 RtlOemStringToUnicodeString(NameU
, &StringA
, FALSE
);
83 if (pEntry
->lCase
& VFAT_CASE_LOWER_EXT
)
85 RtlDowncaseUnicodeString(NameU
, NameU
, FALSE
);
87 NameU
->Buffer
-= Length
/ sizeof(WCHAR
);
88 NameU
->Length
+= Length
;
89 NameU
->MaximumLength
+= Length
;
92 NameU
->Buffer
[NameU
->Length
/ sizeof(WCHAR
)] = 0;
93 DPRINT("'%wZ'\n", NameU
);
97 * FUNCTION: Read the volume label
101 PDEVICE_EXTENSION DeviceExt
,
104 PVOID Context
= NULL
;
108 LARGE_INTEGER FileOffset
;
109 UNICODE_STRING NameU
;
111 ULONG EntriesPerPage
;
114 NameU
.Buffer
= Vpb
->VolumeLabel
;
116 NameU
.MaximumLength
= sizeof(Vpb
->VolumeLabel
);
117 *(Vpb
->VolumeLabel
) = 0;
118 Vpb
->VolumeLabelLength
= 0;
120 if (DeviceExt
->Flags
& VCB_IS_FATX
)
122 SizeDirEntry
= sizeof(FATX_DIR_ENTRY
);
123 EntriesPerPage
= FATX_ENTRIES_PER_PAGE
;
127 SizeDirEntry
= sizeof(FAT_DIR_ENTRY
);
128 EntriesPerPage
= FAT_ENTRIES_PER_PAGE
;
131 ExAcquireResourceExclusiveLite(&DeviceExt
->DirResource
, TRUE
);
132 pFcb
= vfatOpenRootFCB(DeviceExt
);
133 ExReleaseResourceLite(&DeviceExt
->DirResource
);
135 FileOffset
.QuadPart
= 0;
136 if (CcMapData(pFcb
->FileObject
, &FileOffset
, SizeDirEntry
, TRUE
, &Context
, (PVOID
*)&Entry
))
140 if (ENTRY_VOLUME(DeviceExt
, Entry
))
142 /* copy volume label */
143 if (DeviceExt
->Flags
& VCB_IS_FATX
)
145 StringO
.Buffer
= (PCHAR
)Entry
->FatX
.Filename
;
146 StringO
.MaximumLength
= StringO
.Length
= Entry
->FatX
.FilenameLength
;
147 RtlOemStringToUnicodeString(&NameU
, &StringO
, FALSE
);
151 vfat8Dot3ToString(&Entry
->Fat
, &NameU
);
153 Vpb
->VolumeLabelLength
= NameU
.Length
;
156 if (ENTRY_END(DeviceExt
, Entry
))
161 Entry
= (PDIR_ENTRY
)((ULONG_PTR
)Entry
+ SizeDirEntry
);
162 if ((DirIndex
% EntriesPerPage
) == 0)
164 CcUnpinData(Context
);
165 FileOffset
.u
.LowPart
+= PAGE_SIZE
;
166 if (!CcMapData(pFcb
->FileObject
, &FileOffset
, SizeDirEntry
, TRUE
, &Context
, (PVOID
*)&Entry
))
175 CcUnpinData(Context
);
178 ExAcquireResourceExclusiveLite(&DeviceExt
->DirResource
, TRUE
);
179 vfatReleaseFCB(DeviceExt
, pFcb
);
180 ExReleaseResourceLite(&DeviceExt
->DirResource
);
182 return STATUS_SUCCESS
;
186 * FUNCTION: Find a file
190 PDEVICE_EXTENSION DeviceExt
,
192 PUNICODE_STRING FileToFindU
,
193 PVFAT_DIRENTRY_CONTEXT DirContext
,
196 PWCHAR PathNameBuffer
;
197 USHORT PathNameBufferLength
;
199 PVOID Context
= NULL
;
203 UNICODE_STRING PathNameU
;
204 UNICODE_STRING FileToFindUpcase
;
207 DPRINT("FindFile(Parent %p, FileToFind '%wZ', DirIndex: %u)\n",
208 Parent
, FileToFindU
, DirContext
->DirIndex
);
209 DPRINT("FindFile: Path %wZ\n",&Parent
->PathNameU
);
211 PathNameBufferLength
= LONGNAME_MAX_LENGTH
* sizeof(WCHAR
);
212 PathNameBuffer
= ExAllocatePoolWithTag(NonPagedPool
, PathNameBufferLength
+ sizeof(WCHAR
), TAG_VFAT
);
215 return STATUS_INSUFFICIENT_RESOURCES
;
218 PathNameU
.Buffer
= PathNameBuffer
;
219 PathNameU
.Length
= 0;
220 PathNameU
.MaximumLength
= PathNameBufferLength
;
222 DirContext
->LongNameU
.Length
= 0;
223 DirContext
->ShortNameU
.Length
= 0;
225 WildCard
= FsRtlDoesNameContainWildCards(FileToFindU
);
227 if (WildCard
== FALSE
)
229 /* if there is no '*?' in the search name, than look first for an existing fcb */
230 RtlCopyUnicodeString(&PathNameU
, &Parent
->PathNameU
);
231 if (!vfatFCBIsRoot(Parent
))
233 PathNameU
.Buffer
[PathNameU
.Length
/ sizeof(WCHAR
)] = L
'\\';
234 PathNameU
.Length
+= sizeof(WCHAR
);
236 RtlAppendUnicodeStringToString(&PathNameU
, FileToFindU
);
237 PathNameU
.Buffer
[PathNameU
.Length
/ sizeof(WCHAR
)] = 0;
238 rcFcb
= vfatGrabFCBFromTable(DeviceExt
, &PathNameU
);
241 ULONG startIndex
= rcFcb
->startIndex
;
242 if ((rcFcb
->Flags
& FCB_IS_FATX_ENTRY
) && !vfatFCBIsRoot(Parent
))
246 if(startIndex
>= DirContext
->DirIndex
)
248 RtlCopyUnicodeString(&DirContext
->LongNameU
, &rcFcb
->LongNameU
);
249 RtlCopyUnicodeString(&DirContext
->ShortNameU
, &rcFcb
->ShortNameU
);
250 RtlCopyMemory(&DirContext
->DirEntry
, &rcFcb
->entry
, sizeof(DIR_ENTRY
));
251 DirContext
->StartIndex
= rcFcb
->startIndex
;
252 DirContext
->DirIndex
= rcFcb
->dirIndex
;
253 DPRINT("FindFile: new Name %wZ, DirIndex %u (%u)\n",
254 &DirContext
->LongNameU
, DirContext
->DirIndex
, DirContext
->StartIndex
);
255 Status
= STATUS_SUCCESS
;
259 DPRINT("FCB not found for %wZ\n", &PathNameU
);
260 Status
= STATUS_UNSUCCESSFUL
;
262 vfatReleaseFCB(DeviceExt
, rcFcb
);
263 ExFreePool(PathNameBuffer
);
268 /* FsRtlIsNameInExpression need the searched string to be upcase,
269 * even if IgnoreCase is specified */
270 Status
= RtlUpcaseUnicodeString(&FileToFindUpcase
, FileToFindU
, TRUE
);
271 if (!NT_SUCCESS(Status
))
273 ExFreePool(PathNameBuffer
);
279 Status
= DeviceExt
->GetNextDirEntry(&Context
, &Page
, Parent
, DirContext
, First
);
281 if (Status
== STATUS_NO_MORE_ENTRIES
)
285 if (ENTRY_VOLUME(DeviceExt
, &DirContext
->DirEntry
))
287 DirContext
->DirIndex
++;
292 Found
= FsRtlIsNameInExpression(&FileToFindUpcase
, &DirContext
->LongNameU
, TRUE
, NULL
) ||
293 FsRtlIsNameInExpression(&FileToFindUpcase
, &DirContext
->ShortNameU
, TRUE
, NULL
);
297 Found
= FsRtlAreNamesEqual(&DirContext
->LongNameU
, FileToFindU
, TRUE
, NULL
) ||
298 FsRtlAreNamesEqual(&DirContext
->ShortNameU
, FileToFindU
, TRUE
, NULL
);
305 RtlCopyUnicodeString(&PathNameU
, &Parent
->PathNameU
);
306 if (!vfatFCBIsRoot(Parent
))
308 PathNameU
.Buffer
[PathNameU
.Length
/ sizeof(WCHAR
)] = L
'\\';
309 PathNameU
.Length
+= sizeof(WCHAR
);
311 RtlAppendUnicodeStringToString(&PathNameU
, &DirContext
->LongNameU
);
312 PathNameU
.Buffer
[PathNameU
.Length
/ sizeof(WCHAR
)] = 0;
313 rcFcb
= vfatGrabFCBFromTable(DeviceExt
, &PathNameU
);
316 RtlCopyMemory(&DirContext
->DirEntry
, &rcFcb
->entry
, sizeof(DIR_ENTRY
));
317 vfatReleaseFCB(DeviceExt
, rcFcb
);
320 DPRINT("%u\n", DirContext
->LongNameU
.Length
);
321 DPRINT("FindFile: new Name %wZ, DirIndex %u\n",
322 &DirContext
->LongNameU
, DirContext
->DirIndex
);
326 CcUnpinData(Context
);
328 RtlFreeUnicodeString(&FileToFindUpcase
);
329 ExFreePool(PathNameBuffer
);
330 return STATUS_SUCCESS
;
332 DirContext
->DirIndex
++;
337 CcUnpinData(Context
);
340 RtlFreeUnicodeString(&FileToFindUpcase
);
341 ExFreePool(PathNameBuffer
);
346 * FUNCTION: Opens a file
351 PDEVICE_EXTENSION DeviceExt
,
352 PUNICODE_STRING PathNameU
,
353 PFILE_OBJECT FileObject
,
354 ULONG RequestedDisposition
,
360 DPRINT("VfatOpenFile(%p, '%wZ', %p, %p)\n", DeviceExt
, PathNameU
, FileObject
, ParentFcb
);
362 if (FileObject
->RelatedFileObject
)
364 DPRINT("'%wZ'\n", &FileObject
->RelatedFileObject
->FileName
);
366 *ParentFcb
= FileObject
->RelatedFileObject
->FsContext
;
367 (*ParentFcb
)->RefCount
++;
374 if (!DeviceExt
->FatInfo
.FixedMedia
)
376 Status
= VfatBlockDeviceIoControl(DeviceExt
->StorageDevice
,
377 IOCTL_DISK_CHECK_VERIFY
,
383 if (!NT_SUCCESS(Status
))
385 DPRINT("Status %lx\n", Status
);
393 (*ParentFcb
)->RefCount
++;
396 /* try first to find an existing FCB in memory */
397 DPRINT("Checking for existing FCB in memory\n");
399 Status
= vfatGetFCBForFile(DeviceExt
, ParentFcb
, &Fcb
, PathNameU
);
400 if (!NT_SUCCESS(Status
))
402 DPRINT ("Could not make a new FCB, status: %x\n", Status
);
405 if (Fcb
->Flags
& FCB_DELETE_PENDING
)
407 vfatReleaseFCB(DeviceExt
, Fcb
);
408 return STATUS_DELETE_PENDING
;
411 /* Fail, if we try to overwrite a read-only file */
412 if ((*Fcb
->Attributes
& FILE_ATTRIBUTE_READONLY
) &&
413 (RequestedDisposition
== FILE_OVERWRITE
))
415 vfatReleaseFCB(DeviceExt
, Fcb
);
416 return STATUS_ACCESS_DENIED
;
419 DPRINT("Attaching FCB to fileObject\n");
420 Status
= vfatAttachFCBToFileObject(DeviceExt
, Fcb
, FileObject
);
421 if (!NT_SUCCESS(Status
))
423 vfatReleaseFCB(DeviceExt
, Fcb
);
429 * FUNCTION: Create or open a file
433 PDEVICE_OBJECT DeviceObject
,
436 PIO_STACK_LOCATION Stack
;
437 PFILE_OBJECT FileObject
;
438 NTSTATUS Status
= STATUS_SUCCESS
;
439 PDEVICE_EXTENSION DeviceExt
;
440 ULONG RequestedDisposition
, RequestedOptions
;
441 PVFATFCB pFcb
= NULL
;
442 PVFATFCB ParentFcb
= NULL
;
444 BOOLEAN PagingFileCreate
= FALSE
;
446 UNICODE_STRING FileNameU
;
447 UNICODE_STRING PathNameU
;
450 /* Unpack the various parameters. */
451 Stack
= IoGetCurrentIrpStackLocation(Irp
);
452 RequestedDisposition
= ((Stack
->Parameters
.Create
.Options
>> 24) & 0xff);
453 RequestedOptions
= Stack
->Parameters
.Create
.Options
& FILE_VALID_OPTION_FLAGS
;
454 PagingFileCreate
= (Stack
->Flags
& SL_OPEN_PAGING_FILE
) ? TRUE
: FALSE
;
455 FileObject
= Stack
->FileObject
;
456 DeviceExt
= DeviceObject
->DeviceExtension
;
458 /* Check their validity. */
459 if (RequestedOptions
& FILE_DIRECTORY_FILE
&&
460 RequestedDisposition
== FILE_SUPERSEDE
)
462 return STATUS_INVALID_PARAMETER
;
465 if (RequestedOptions
& FILE_DIRECTORY_FILE
&&
466 RequestedOptions
& FILE_NON_DIRECTORY_FILE
)
468 return STATUS_INVALID_PARAMETER
;
471 /* This a open operation for the volume itself */
472 if (FileObject
->FileName
.Length
== 0 &&
473 (FileObject
->RelatedFileObject
== NULL
|| FileObject
->RelatedFileObject
->FsContext2
!= NULL
))
475 if (RequestedDisposition
!= FILE_OPEN
&&
476 RequestedDisposition
!= FILE_OPEN_IF
)
478 return STATUS_ACCESS_DENIED
;
481 /* In spite of what is shown in WDK, it seems that Windows FAT driver doesn't perform that test */
482 if (RequestedOptions
& FILE_DIRECTORY_FILE
)
484 return STATUS_NOT_A_DIRECTORY
;
488 pFcb
= DeviceExt
->VolumeFcb
;
489 vfatAttachFCBToFileObject(DeviceExt
, pFcb
, FileObject
);
492 Irp
->IoStatus
.Information
= FILE_OPENED
;
493 return STATUS_SUCCESS
;
496 /* Check for illegal characters and illegale dot sequences in the file name */
497 PathNameU
= FileObject
->FileName
;
498 c
= PathNameU
.Buffer
+ PathNameU
.Length
/ sizeof(WCHAR
);
501 while (c
-- > PathNameU
.Buffer
)
503 if (*c
== L
'\\' || c
== PathNameU
.Buffer
)
505 if (Dots
&& last
> c
)
507 return STATUS_OBJECT_NAME_INVALID
;
517 if (*c
!= '\\' && vfatIsLongIllegal(*c
))
519 return STATUS_OBJECT_NAME_INVALID
;
523 if (FileObject
->RelatedFileObject
&& PathNameU
.Length
>= sizeof(WCHAR
) && PathNameU
.Buffer
[0] == L
'\\')
525 return STATUS_OBJECT_NAME_INVALID
;
528 if (PathNameU
.Length
> sizeof(WCHAR
) && PathNameU
.Buffer
[PathNameU
.Length
/sizeof(WCHAR
)-1] == L
'\\')
530 PathNameU
.Length
-= sizeof(WCHAR
);
533 /* Try opening the file. */
534 Status
= VfatOpenFile(DeviceExt
, &PathNameU
, FileObject
, RequestedDisposition
, &ParentFcb
);
537 * If the directory containing the file to open doesn't exist then
540 if (Status
== STATUS_OBJECT_PATH_NOT_FOUND
||
541 Status
== STATUS_INVALID_PARAMETER
||
542 Status
== STATUS_DELETE_PENDING
)
546 vfatReleaseFCB(DeviceExt
, ParentFcb
);
551 if (!NT_SUCCESS(Status
) && ParentFcb
== NULL
)
553 DPRINT1("VfatOpenFile failed for '%wZ', status %x\n", &PathNameU
, Status
);
557 /* If the file open failed then create the required file */
558 if (!NT_SUCCESS (Status
))
560 if (RequestedDisposition
== FILE_CREATE
||
561 RequestedDisposition
== FILE_OPEN_IF
||
562 RequestedDisposition
== FILE_OVERWRITE_IF
||
563 RequestedDisposition
== FILE_SUPERSEDE
)
565 Attributes
= Stack
->Parameters
.Create
.FileAttributes
& ~FILE_ATTRIBUTE_NORMAL
;
566 if (!(RequestedOptions
& FILE_DIRECTORY_FILE
))
567 Attributes
|= FILE_ATTRIBUTE_ARCHIVE
;
568 vfatSplitPathName(&PathNameU
, NULL
, &FileNameU
);
569 Status
= VfatAddEntry(DeviceExt
, &FileNameU
, &pFcb
, ParentFcb
, RequestedOptions
,
570 (UCHAR
)(Attributes
& FILE_ATTRIBUTE_VALID_FLAGS
));
571 vfatReleaseFCB(DeviceExt
, ParentFcb
);
572 if (NT_SUCCESS(Status
))
574 Status
= vfatAttachFCBToFileObject(DeviceExt
, pFcb
, FileObject
);
575 if (!NT_SUCCESS(Status
))
577 vfatReleaseFCB(DeviceExt
, pFcb
);
581 Irp
->IoStatus
.Information
= FILE_CREATED
;
582 VfatSetAllocationSizeInformation(FileObject
,
585 &Irp
->Overlay
.AllocationSize
);
586 VfatSetExtendedAttributes(FileObject
,
587 Irp
->AssociatedIrp
.SystemBuffer
,
588 Stack
->Parameters
.Create
.EaLength
);
590 if (PagingFileCreate
)
592 pFcb
->Flags
|= FCB_IS_PAGE_FILE
;
604 vfatReleaseFCB(DeviceExt
, ParentFcb
);
613 vfatReleaseFCB(DeviceExt
, ParentFcb
);
616 /* Otherwise fail if the caller wanted to create a new file */
617 if (RequestedDisposition
== FILE_CREATE
)
619 Irp
->IoStatus
.Information
= FILE_EXISTS
;
620 VfatCloseFile(DeviceExt
, FileObject
);
621 return STATUS_OBJECT_NAME_COLLISION
;
624 pFcb
= FileObject
->FsContext
;
626 if (pFcb
->OpenHandleCount
!= 0)
628 Status
= IoCheckShareAccess(Stack
->Parameters
.Create
.SecurityContext
->DesiredAccess
,
629 Stack
->Parameters
.Create
.ShareAccess
,
631 &pFcb
->FCBShareAccess
,
633 if (!NT_SUCCESS(Status
))
635 VfatCloseFile(DeviceExt
, FileObject
);
641 * Check the file has the requested attributes
643 if (RequestedOptions
& FILE_NON_DIRECTORY_FILE
&&
644 *pFcb
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
)
646 VfatCloseFile (DeviceExt
, FileObject
);
647 return STATUS_FILE_IS_A_DIRECTORY
;
649 if (RequestedOptions
& FILE_DIRECTORY_FILE
&&
650 !(*pFcb
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
))
652 VfatCloseFile (DeviceExt
, FileObject
);
653 return STATUS_NOT_A_DIRECTORY
;
655 #ifndef USE_ROS_CC_AND_FS
656 if (!(*pFcb
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
))
658 if (Stack
->Parameters
.Create
.SecurityContext
->DesiredAccess
& FILE_WRITE_DATA
||
659 RequestedDisposition
== FILE_OVERWRITE
||
660 RequestedDisposition
== FILE_OVERWRITE_IF
)
662 if (!MmFlushImageSection(&pFcb
->SectionObjectPointers
, MmFlushForWrite
))
664 DPRINT1("%wZ\n", &pFcb
->PathNameU
);
665 DPRINT1("%d %d %d\n", Stack
->Parameters
.Create
.SecurityContext
->DesiredAccess
& FILE_WRITE_DATA
,
666 RequestedDisposition
== FILE_OVERWRITE
, RequestedDisposition
== FILE_OVERWRITE_IF
);
667 VfatCloseFile (DeviceExt
, FileObject
);
668 return STATUS_SHARING_VIOLATION
;
673 if (PagingFileCreate
)
676 * Do more checking for page files. It is possible,
677 * that the file was opened and closed previously
678 * as a normal cached file. In this case, the cache
679 * manager has referenced the fileobject and the fcb
680 * is held in memory. Try to remove the fileobject
681 * from cache manager and use the fcb.
683 if (pFcb
->RefCount
> 1)
685 if(!(pFcb
->Flags
& FCB_IS_PAGE_FILE
))
687 VfatCloseFile(DeviceExt
, FileObject
);
688 return STATUS_INVALID_PARAMETER
;
693 pFcb
->Flags
|= FCB_IS_PAGE_FILE
;
698 if (pFcb
->Flags
& FCB_IS_PAGE_FILE
)
700 VfatCloseFile(DeviceExt
, FileObject
);
701 return STATUS_INVALID_PARAMETER
;
705 if (RequestedDisposition
== FILE_OVERWRITE
||
706 RequestedDisposition
== FILE_OVERWRITE_IF
||
707 RequestedDisposition
== FILE_SUPERSEDE
)
709 if (!(*pFcb
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
))
711 *pFcb
->Attributes
= Stack
->Parameters
.Create
.FileAttributes
& ~FILE_ATTRIBUTE_NORMAL
;
712 *pFcb
->Attributes
|= FILE_ATTRIBUTE_ARCHIVE
;
713 VfatUpdateEntry(pFcb
);
716 ExAcquireResourceExclusiveLite(&(pFcb
->MainResource
), TRUE
);
717 Status
= VfatSetAllocationSizeInformation(FileObject
,
720 &Irp
->Overlay
.AllocationSize
);
721 ExReleaseResourceLite(&(pFcb
->MainResource
));
722 if (!NT_SUCCESS (Status
))
724 VfatCloseFile(DeviceExt
, FileObject
);
729 if (RequestedDisposition
== FILE_SUPERSEDE
)
731 Irp
->IoStatus
.Information
= FILE_SUPERSEDED
;
733 else if (RequestedDisposition
== FILE_OVERWRITE
||
734 RequestedDisposition
== FILE_OVERWRITE_IF
)
736 Irp
->IoStatus
.Information
= FILE_OVERWRITTEN
;
740 Irp
->IoStatus
.Information
= FILE_OPENED
;
744 if (pFcb
->OpenHandleCount
== 0)
746 IoSetShareAccess(Stack
->Parameters
.Create
.SecurityContext
->DesiredAccess
,
747 Stack
->Parameters
.Create
.ShareAccess
,
749 &pFcb
->FCBShareAccess
);
753 IoUpdateShareAccess(FileObject
,
754 &pFcb
->FCBShareAccess
);
757 if (Irp
->IoStatus
.Information
== FILE_CREATED
)
759 FsRtlNotifyFullReportChange(DeviceExt
->NotifySync
,
760 &(DeviceExt
->NotifyList
),
761 (PSTRING
)&pFcb
->PathNameU
,
762 pFcb
->PathNameU
.Length
- pFcb
->LongNameU
.Length
,
765 ((*pFcb
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
) ?
766 FILE_NOTIFY_CHANGE_DIR_NAME
: FILE_NOTIFY_CHANGE_FILE_NAME
),
771 pFcb
->OpenHandleCount
++;
773 /* FIXME : test write access if requested */
779 * FUNCTION: Create or open a file
783 PVFAT_IRP_CONTEXT IrpContext
)
789 if (IrpContext
->DeviceObject
== VfatGlobalData
->DeviceObject
)
791 /* DeviceObject represents FileSystem instead of logical volume */
792 DPRINT ("FsdCreate called with file system\n");
793 IrpContext
->Irp
->IoStatus
.Information
= FILE_OPENED
;
794 IrpContext
->Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
795 IoCompleteRequest(IrpContext
->Irp
, IO_DISK_INCREMENT
);
796 VfatFreeIrpContext(IrpContext
);
797 return STATUS_SUCCESS
;
800 if (!(IrpContext
->Flags
& IRPCONTEXT_CANWAIT
))
802 return(VfatQueueRequest(IrpContext
));
805 IrpContext
->Irp
->IoStatus
.Information
= 0;
806 ExAcquireResourceExclusiveLite(&IrpContext
->DeviceExt
->DirResource
, TRUE
);
807 Status
= VfatCreateFile(IrpContext
->DeviceObject
, IrpContext
->Irp
);
808 ExReleaseResourceLite(&IrpContext
->DeviceExt
->DirResource
);
810 IrpContext
->Irp
->IoStatus
.Status
= Status
;
811 IoCompleteRequest(IrpContext
->Irp
,
812 (CCHAR
)(NT_SUCCESS(Status
) ? IO_DISK_INCREMENT
: IO_NO_INCREMENT
));
813 VfatFreeIrpContext(IrpContext
);