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 *****************************************************************/
31 /* FUNCTIONS *****************************************************************/
35 PFAT_DIR_ENTRY pEntry
,
36 PUNICODE_STRING NameU
)
42 RtlCopyMemory(cString
, pEntry
->ShortName
, 11);
44 if (cString
[0] == 0x05)
49 StringA
.Buffer
= cString
;
50 for (StringA
.Length
= 0;
51 StringA
.Length
< 8 && StringA
.Buffer
[StringA
.Length
] != ' ';
53 StringA
.MaximumLength
= StringA
.Length
;
55 RtlOemStringToUnicodeString(NameU
, &StringA
, FALSE
);
57 if (pEntry
->lCase
& VFAT_CASE_LOWER_BASE
)
59 RtlDowncaseUnicodeString(NameU
, NameU
, FALSE
);
62 if (cString
[8] != ' ')
64 Length
= NameU
->Length
;
65 NameU
->Buffer
+= Length
/ sizeof(WCHAR
);
66 if (!FAT_ENTRY_VOLUME(pEntry
))
68 Length
+= sizeof(WCHAR
);
69 NameU
->Buffer
[0] = L
'.';
73 NameU
->MaximumLength
-= Length
;
75 StringA
.Buffer
= &cString
[8];
76 for (StringA
.Length
= 0;
77 StringA
.Length
< 3 && StringA
.Buffer
[StringA
.Length
] != ' ';
79 StringA
.MaximumLength
= StringA
.Length
;
80 RtlOemStringToUnicodeString(NameU
, &StringA
, FALSE
);
81 if (pEntry
->lCase
& VFAT_CASE_LOWER_EXT
)
83 RtlDowncaseUnicodeString(NameU
, NameU
, FALSE
);
85 NameU
->Buffer
-= Length
/ sizeof(WCHAR
);
86 NameU
->Length
+= Length
;
87 NameU
->MaximumLength
+= Length
;
90 NameU
->Buffer
[NameU
->Length
/ sizeof(WCHAR
)] = 0;
91 DPRINT("'%wZ'\n", NameU
);
95 * FUNCTION: Read the volume label
99 PDEVICE_EXTENSION DeviceExt
,
102 PVOID Context
= NULL
;
106 LARGE_INTEGER FileOffset
;
107 UNICODE_STRING NameU
;
109 ULONG EntriesPerPage
;
112 NameU
.Buffer
= Vpb
->VolumeLabel
;
114 NameU
.MaximumLength
= sizeof(Vpb
->VolumeLabel
);
115 *(Vpb
->VolumeLabel
) = 0;
116 Vpb
->VolumeLabelLength
= 0;
118 if (DeviceExt
->Flags
& VCB_IS_FATX
)
120 SizeDirEntry
= sizeof(FATX_DIR_ENTRY
);
121 EntriesPerPage
= FATX_ENTRIES_PER_PAGE
;
125 SizeDirEntry
= sizeof(FAT_DIR_ENTRY
);
126 EntriesPerPage
= FAT_ENTRIES_PER_PAGE
;
129 ExAcquireResourceExclusiveLite(&DeviceExt
->DirResource
, TRUE
);
130 pFcb
= vfatOpenRootFCB(DeviceExt
);
131 ExReleaseResourceLite(&DeviceExt
->DirResource
);
133 FileOffset
.QuadPart
= 0;
134 if (CcMapData(pFcb
->FileObject
, &FileOffset
, SizeDirEntry
, TRUE
, &Context
, (PVOID
*)&Entry
))
138 if (ENTRY_VOLUME(DeviceExt
, Entry
))
140 /* copy volume label */
141 if (DeviceExt
->Flags
& VCB_IS_FATX
)
143 StringO
.Buffer
= (PCHAR
)Entry
->FatX
.Filename
;
144 StringO
.MaximumLength
= StringO
.Length
= Entry
->FatX
.FilenameLength
;
145 RtlOemStringToUnicodeString(&NameU
, &StringO
, FALSE
);
149 vfat8Dot3ToString(&Entry
->Fat
, &NameU
);
151 Vpb
->VolumeLabelLength
= NameU
.Length
;
154 if (ENTRY_END(DeviceExt
, Entry
))
159 Entry
= (PDIR_ENTRY
)((ULONG_PTR
)Entry
+ SizeDirEntry
);
160 if ((DirIndex
% EntriesPerPage
) == 0)
162 CcUnpinData(Context
);
163 FileOffset
.u
.LowPart
+= PAGE_SIZE
;
164 if (!CcMapData(pFcb
->FileObject
, &FileOffset
, SizeDirEntry
, TRUE
, &Context
, (PVOID
*)&Entry
))
173 CcUnpinData(Context
);
176 ExAcquireResourceExclusiveLite(&DeviceExt
->DirResource
, TRUE
);
177 vfatReleaseFCB(DeviceExt
, pFcb
);
178 ExReleaseResourceLite(&DeviceExt
->DirResource
);
180 return STATUS_SUCCESS
;
184 * FUNCTION: Find a file
188 PDEVICE_EXTENSION DeviceExt
,
190 PUNICODE_STRING FileToFindU
,
191 PVFAT_DIRENTRY_CONTEXT DirContext
,
194 PWCHAR PathNameBuffer
;
195 USHORT PathNameBufferLength
;
197 PVOID Context
= NULL
;
201 UNICODE_STRING PathNameU
;
202 UNICODE_STRING FileToFindUpcase
;
205 DPRINT("FindFile(Parent %p, FileToFind '%wZ', DirIndex: %u)\n",
206 Parent
, FileToFindU
, DirContext
->DirIndex
);
207 DPRINT("FindFile: Path %wZ\n",&Parent
->PathNameU
);
209 PathNameBufferLength
= LONGNAME_MAX_LENGTH
* sizeof(WCHAR
);
210 PathNameBuffer
= ExAllocatePoolWithTag(NonPagedPool
, PathNameBufferLength
+ sizeof(WCHAR
), TAG_VFAT
);
213 return STATUS_INSUFFICIENT_RESOURCES
;
216 PathNameU
.Buffer
= PathNameBuffer
;
217 PathNameU
.Length
= 0;
218 PathNameU
.MaximumLength
= PathNameBufferLength
;
220 DirContext
->LongNameU
.Length
= 0;
221 DirContext
->ShortNameU
.Length
= 0;
223 WildCard
= FsRtlDoesNameContainWildCards(FileToFindU
);
225 if (WildCard
== FALSE
)
227 /* if there is no '*?' in the search name, than look first for an existing fcb */
228 RtlCopyUnicodeString(&PathNameU
, &Parent
->PathNameU
);
229 if (!vfatFCBIsRoot(Parent
))
231 PathNameU
.Buffer
[PathNameU
.Length
/ sizeof(WCHAR
)] = L
'\\';
232 PathNameU
.Length
+= sizeof(WCHAR
);
234 RtlAppendUnicodeStringToString(&PathNameU
, FileToFindU
);
235 PathNameU
.Buffer
[PathNameU
.Length
/ sizeof(WCHAR
)] = 0;
236 rcFcb
= vfatGrabFCBFromTable(DeviceExt
, &PathNameU
);
239 ULONG startIndex
= rcFcb
->startIndex
;
240 if ((rcFcb
->Flags
& FCB_IS_FATX_ENTRY
) && !vfatFCBIsRoot(Parent
))
244 if(startIndex
>= DirContext
->DirIndex
)
246 RtlCopyUnicodeString(&DirContext
->LongNameU
, &rcFcb
->LongNameU
);
247 RtlCopyUnicodeString(&DirContext
->ShortNameU
, &rcFcb
->ShortNameU
);
248 RtlCopyMemory(&DirContext
->DirEntry
, &rcFcb
->entry
, sizeof(DIR_ENTRY
));
249 DirContext
->StartIndex
= rcFcb
->startIndex
;
250 DirContext
->DirIndex
= rcFcb
->dirIndex
;
251 DPRINT("FindFile: new Name %wZ, DirIndex %u (%u)\n",
252 &DirContext
->LongNameU
, DirContext
->DirIndex
, DirContext
->StartIndex
);
253 Status
= STATUS_SUCCESS
;
257 DPRINT("FCB not found for %wZ\n", &PathNameU
);
258 Status
= STATUS_UNSUCCESSFUL
;
260 vfatReleaseFCB(DeviceExt
, rcFcb
);
261 ExFreePool(PathNameBuffer
);
266 /* FsRtlIsNameInExpression need the searched string to be upcase,
267 * even if IgnoreCase is specified */
268 Status
= RtlUpcaseUnicodeString(&FileToFindUpcase
, FileToFindU
, TRUE
);
269 if (!NT_SUCCESS(Status
))
271 ExFreePool(PathNameBuffer
);
277 Status
= DeviceExt
->GetNextDirEntry(&Context
, &Page
, Parent
, DirContext
, First
);
279 if (Status
== STATUS_NO_MORE_ENTRIES
)
283 if (ENTRY_VOLUME(DeviceExt
, &DirContext
->DirEntry
))
285 DirContext
->DirIndex
++;
290 Found
= FsRtlIsNameInExpression(&FileToFindUpcase
, &DirContext
->LongNameU
, TRUE
, NULL
) ||
291 FsRtlIsNameInExpression(&FileToFindUpcase
, &DirContext
->ShortNameU
, TRUE
, NULL
);
295 Found
= FsRtlAreNamesEqual(&DirContext
->LongNameU
, FileToFindU
, TRUE
, NULL
) ||
296 FsRtlAreNamesEqual(&DirContext
->ShortNameU
, FileToFindU
, TRUE
, NULL
);
303 RtlCopyUnicodeString(&PathNameU
, &Parent
->PathNameU
);
304 if (!vfatFCBIsRoot(Parent
))
306 PathNameU
.Buffer
[PathNameU
.Length
/ sizeof(WCHAR
)] = L
'\\';
307 PathNameU
.Length
+= sizeof(WCHAR
);
309 RtlAppendUnicodeStringToString(&PathNameU
, &DirContext
->LongNameU
);
310 PathNameU
.Buffer
[PathNameU
.Length
/ sizeof(WCHAR
)] = 0;
311 rcFcb
= vfatGrabFCBFromTable(DeviceExt
, &PathNameU
);
314 RtlCopyMemory(&DirContext
->DirEntry
, &rcFcb
->entry
, sizeof(DIR_ENTRY
));
315 vfatReleaseFCB(DeviceExt
, rcFcb
);
318 DPRINT("%u\n", DirContext
->LongNameU
.Length
);
319 DPRINT("FindFile: new Name %wZ, DirIndex %u\n",
320 &DirContext
->LongNameU
, DirContext
->DirIndex
);
324 CcUnpinData(Context
);
326 RtlFreeUnicodeString(&FileToFindUpcase
);
327 ExFreePool(PathNameBuffer
);
328 return STATUS_SUCCESS
;
330 DirContext
->DirIndex
++;
335 CcUnpinData(Context
);
338 RtlFreeUnicodeString(&FileToFindUpcase
);
339 ExFreePool(PathNameBuffer
);
344 * FUNCTION: Opens a file
349 PDEVICE_EXTENSION DeviceExt
,
350 PUNICODE_STRING PathNameU
,
351 PFILE_OBJECT FileObject
,
357 DPRINT("VfatOpenFile(%p, '%wZ', %p, %p)\n", DeviceExt
, PathNameU
, FileObject
, ParentFcb
);
359 if (FileObject
->RelatedFileObject
)
361 DPRINT("'%wZ'\n", &FileObject
->RelatedFileObject
->FileName
);
363 *ParentFcb
= FileObject
->RelatedFileObject
->FsContext
;
364 (*ParentFcb
)->RefCount
++;
371 if (!DeviceExt
->FatInfo
.FixedMedia
)
373 Status
= VfatBlockDeviceIoControl(DeviceExt
->StorageDevice
,
374 IOCTL_DISK_CHECK_VERIFY
,
380 if (!NT_SUCCESS(Status
))
382 DPRINT ("Status %lx\n", Status
);
390 (*ParentFcb
)->RefCount
++;
393 /* try first to find an existing FCB in memory */
394 DPRINT("Checking for existing FCB in memory\n");
396 Status
= vfatGetFCBForFile(DeviceExt
, ParentFcb
, &Fcb
, PathNameU
);
397 if (!NT_SUCCESS (Status
))
399 DPRINT ("Could not make a new FCB, status: %x\n", Status
);
402 if (Fcb
->Flags
& FCB_DELETE_PENDING
)
404 vfatReleaseFCB (DeviceExt
, Fcb
);
405 return STATUS_DELETE_PENDING
;
407 DPRINT("Attaching FCB to fileObject\n");
408 Status
= vfatAttachFCBToFileObject(DeviceExt
, Fcb
, FileObject
);
409 if (!NT_SUCCESS(Status
))
411 vfatReleaseFCB (DeviceExt
, Fcb
);
417 * FUNCTION: Create or open a file
421 PDEVICE_OBJECT DeviceObject
,
424 PIO_STACK_LOCATION Stack
;
425 PFILE_OBJECT FileObject
;
426 NTSTATUS Status
= STATUS_SUCCESS
;
427 PDEVICE_EXTENSION DeviceExt
;
428 ULONG RequestedDisposition
, RequestedOptions
;
429 PVFATFCB pFcb
= NULL
;
430 PVFATFCB ParentFcb
= NULL
;
432 BOOLEAN PagingFileCreate
= FALSE
;
434 UNICODE_STRING FileNameU
;
435 UNICODE_STRING PathNameU
;
438 /* Unpack the various parameters. */
439 Stack
= IoGetCurrentIrpStackLocation (Irp
);
440 RequestedDisposition
= ((Stack
->Parameters
.Create
.Options
>> 24) & 0xff);
441 RequestedOptions
= Stack
->Parameters
.Create
.Options
& FILE_VALID_OPTION_FLAGS
;
442 PagingFileCreate
= (Stack
->Flags
& SL_OPEN_PAGING_FILE
) ? TRUE
: FALSE
;
443 FileObject
= Stack
->FileObject
;
444 DeviceExt
= DeviceObject
->DeviceExtension
;
446 /* Check their validity. */
447 if (RequestedOptions
& FILE_DIRECTORY_FILE
&&
448 RequestedDisposition
== FILE_SUPERSEDE
)
450 return STATUS_INVALID_PARAMETER
;
453 if (RequestedOptions
& FILE_DIRECTORY_FILE
&&
454 RequestedOptions
& FILE_NON_DIRECTORY_FILE
)
456 return STATUS_INVALID_PARAMETER
;
459 /* This a open operation for the volume itself */
460 if (FileObject
->FileName
.Length
== 0 &&
461 (FileObject
->RelatedFileObject
== NULL
|| FileObject
->RelatedFileObject
->FsContext2
!= NULL
))
463 if (RequestedDisposition
!= FILE_OPEN
&&
464 RequestedDisposition
!= FILE_OPEN_IF
)
466 return STATUS_ACCESS_DENIED
;
469 /* In spite of what is shown in WDK, it seems that Windows FAT driver doesn't perform that test */
470 if (RequestedOptions
& FILE_DIRECTORY_FILE
)
472 return STATUS_NOT_A_DIRECTORY
;
476 pFcb
= DeviceExt
->VolumeFcb
;
477 vfatAttachFCBToFileObject(DeviceExt
, pFcb
, FileObject
);
480 Irp
->IoStatus
.Information
= FILE_OPENED
;
481 return STATUS_SUCCESS
;
484 /* Check for illegal characters and illegale dot sequences in the file name */
485 PathNameU
= FileObject
->FileName
;
486 c
= PathNameU
.Buffer
+ PathNameU
.Length
/ sizeof(WCHAR
);
489 while (c
-- > PathNameU
.Buffer
)
491 if (*c
== L
'\\' || c
== PathNameU
.Buffer
)
493 if (Dots
&& last
> c
)
495 return STATUS_OBJECT_NAME_INVALID
;
505 if (*c
!= '\\' && vfatIsLongIllegal(*c
))
507 return STATUS_OBJECT_NAME_INVALID
;
511 if (FileObject
->RelatedFileObject
&& PathNameU
.Length
>= sizeof(WCHAR
) && PathNameU
.Buffer
[0] == L
'\\')
513 return STATUS_OBJECT_NAME_INVALID
;
516 if (PathNameU
.Length
> sizeof(WCHAR
) && PathNameU
.Buffer
[PathNameU
.Length
/sizeof(WCHAR
)-1] == L
'\\')
518 PathNameU
.Length
-= sizeof(WCHAR
);
521 /* Try opening the file. */
522 Status
= VfatOpenFile(DeviceExt
, &PathNameU
, FileObject
, &ParentFcb
);
525 * If the directory containing the file to open doesn't exist then
528 if (Status
== STATUS_OBJECT_PATH_NOT_FOUND
||
529 Status
== STATUS_INVALID_PARAMETER
||
530 Status
== STATUS_DELETE_PENDING
)
534 vfatReleaseFCB(DeviceExt
, ParentFcb
);
539 if (!NT_SUCCESS(Status
) && ParentFcb
== NULL
)
541 DPRINT1("VfatOpenFile faild for '%wZ', status %x\n", &PathNameU
, Status
);
545 /* If the file open failed then create the required file */
546 if (!NT_SUCCESS (Status
))
548 if (RequestedDisposition
== FILE_CREATE
||
549 RequestedDisposition
== FILE_OPEN_IF
||
550 RequestedDisposition
== FILE_OVERWRITE_IF
||
551 RequestedDisposition
== FILE_SUPERSEDE
)
553 Attributes
= Stack
->Parameters
.Create
.FileAttributes
& ~FILE_ATTRIBUTE_NORMAL
;
554 if (!(RequestedOptions
& FILE_DIRECTORY_FILE
))
555 Attributes
|= FILE_ATTRIBUTE_ARCHIVE
;
556 vfatSplitPathName(&PathNameU
, NULL
, &FileNameU
);
557 Status
= VfatAddEntry(DeviceExt
, &FileNameU
, &pFcb
, ParentFcb
, RequestedOptions
,
558 (UCHAR
)(Attributes
& FILE_ATTRIBUTE_VALID_FLAGS
));
559 vfatReleaseFCB(DeviceExt
, ParentFcb
);
560 if (NT_SUCCESS(Status
))
562 Status
= vfatAttachFCBToFileObject(DeviceExt
, pFcb
, FileObject
);
563 if (!NT_SUCCESS(Status
))
565 vfatReleaseFCB(DeviceExt
, pFcb
);
569 Irp
->IoStatus
.Information
= FILE_CREATED
;
570 VfatSetAllocationSizeInformation(FileObject
,
573 &Irp
->Overlay
.AllocationSize
);
574 VfatSetExtendedAttributes(FileObject
,
575 Irp
->AssociatedIrp
.SystemBuffer
,
576 Stack
->Parameters
.Create
.EaLength
);
578 if (PagingFileCreate
)
580 pFcb
->Flags
|= FCB_IS_PAGE_FILE
;
592 vfatReleaseFCB(DeviceExt
, ParentFcb
);
601 vfatReleaseFCB(DeviceExt
, ParentFcb
);
604 /* Otherwise fail if the caller wanted to create a new file */
605 if (RequestedDisposition
== FILE_CREATE
)
607 Irp
->IoStatus
.Information
= FILE_EXISTS
;
608 VfatCloseFile(DeviceExt
, FileObject
);
609 return STATUS_OBJECT_NAME_COLLISION
;
612 pFcb
= FileObject
->FsContext
;
614 if (pFcb
->OpenHandleCount
!= 0)
616 Status
= IoCheckShareAccess(Stack
->Parameters
.Create
.SecurityContext
->DesiredAccess
,
617 Stack
->Parameters
.Create
.ShareAccess
,
619 &pFcb
->FCBShareAccess
,
621 if (!NT_SUCCESS(Status
))
623 VfatCloseFile(DeviceExt
, FileObject
);
629 * Check the file has the requested attributes
631 if (RequestedOptions
& FILE_NON_DIRECTORY_FILE
&&
632 *pFcb
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
)
634 VfatCloseFile (DeviceExt
, FileObject
);
635 return STATUS_FILE_IS_A_DIRECTORY
;
637 if (RequestedOptions
& FILE_DIRECTORY_FILE
&&
638 !(*pFcb
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
))
640 VfatCloseFile (DeviceExt
, FileObject
);
641 return STATUS_NOT_A_DIRECTORY
;
643 #ifndef USE_ROS_CC_AND_FS
644 if (!(*pFcb
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
))
646 if (Stack
->Parameters
.Create
.SecurityContext
->DesiredAccess
& FILE_WRITE_DATA
||
647 RequestedDisposition
== FILE_OVERWRITE
||
648 RequestedDisposition
== FILE_OVERWRITE_IF
)
650 if (!MmFlushImageSection(&pFcb
->SectionObjectPointers
, MmFlushForWrite
))
652 DPRINT1("%wZ\n", &pFcb
->PathNameU
);
653 DPRINT1("%d %d %d\n", Stack
->Parameters
.Create
.SecurityContext
->DesiredAccess
& FILE_WRITE_DATA
,
654 RequestedDisposition
== FILE_OVERWRITE
, RequestedDisposition
== FILE_OVERWRITE_IF
);
655 VfatCloseFile (DeviceExt
, FileObject
);
656 return STATUS_SHARING_VIOLATION
;
661 if (PagingFileCreate
)
664 * Do more checking for page files. It is possible,
665 * that the file was opened and closed previously
666 * as a normal cached file. In this case, the cache
667 * manager has referenced the fileobject and the fcb
668 * is held in memory. Try to remove the fileobject
669 * from cache manager and use the fcb.
671 if (pFcb
->RefCount
> 1)
673 if(!(pFcb
->Flags
& FCB_IS_PAGE_FILE
))
675 VfatCloseFile(DeviceExt
, FileObject
);
676 return STATUS_INVALID_PARAMETER
;
681 pFcb
->Flags
|= FCB_IS_PAGE_FILE
;
686 if (pFcb
->Flags
& FCB_IS_PAGE_FILE
)
688 VfatCloseFile(DeviceExt
, FileObject
);
689 return STATUS_INVALID_PARAMETER
;
693 if (RequestedDisposition
== FILE_OVERWRITE
||
694 RequestedDisposition
== FILE_OVERWRITE_IF
||
695 RequestedDisposition
== FILE_SUPERSEDE
)
697 if (!(*pFcb
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
))
699 *pFcb
->Attributes
= Stack
->Parameters
.Create
.FileAttributes
& ~FILE_ATTRIBUTE_NORMAL
;
700 *pFcb
->Attributes
|= FILE_ATTRIBUTE_ARCHIVE
;
701 VfatUpdateEntry(pFcb
);
704 ExAcquireResourceExclusiveLite(&(pFcb
->MainResource
), TRUE
);
705 Status
= VfatSetAllocationSizeInformation(FileObject
,
708 &Irp
->Overlay
.AllocationSize
);
709 ExReleaseResourceLite(&(pFcb
->MainResource
));
710 if (!NT_SUCCESS (Status
))
712 VfatCloseFile(DeviceExt
, FileObject
);
717 if (RequestedDisposition
== FILE_SUPERSEDE
)
719 Irp
->IoStatus
.Information
= FILE_SUPERSEDED
;
721 else if (RequestedDisposition
== FILE_OVERWRITE
||
722 RequestedDisposition
== FILE_OVERWRITE_IF
)
724 Irp
->IoStatus
.Information
= FILE_OVERWRITTEN
;
728 Irp
->IoStatus
.Information
= FILE_OPENED
;
732 if (pFcb
->OpenHandleCount
== 0)
734 IoSetShareAccess(Stack
->Parameters
.Create
.SecurityContext
->DesiredAccess
,
735 Stack
->Parameters
.Create
.ShareAccess
,
737 &pFcb
->FCBShareAccess
);
741 IoUpdateShareAccess(FileObject
,
742 &pFcb
->FCBShareAccess
);
745 pFcb
->OpenHandleCount
++;
747 /* FIXME : test write access if requested */
753 * FUNCTION: Create or open a file
757 PVFAT_IRP_CONTEXT IrpContext
)
763 if (IrpContext
->DeviceObject
== VfatGlobalData
->DeviceObject
)
765 /* DeviceObject represents FileSystem instead of logical volume */
766 DPRINT ("FsdCreate called with file system\n");
767 IrpContext
->Irp
->IoStatus
.Information
= FILE_OPENED
;
768 IrpContext
->Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
769 IoCompleteRequest(IrpContext
->Irp
, IO_DISK_INCREMENT
);
770 VfatFreeIrpContext(IrpContext
);
771 return STATUS_SUCCESS
;
774 if (!(IrpContext
->Flags
& IRPCONTEXT_CANWAIT
))
776 return(VfatQueueRequest(IrpContext
));
779 IrpContext
->Irp
->IoStatus
.Information
= 0;
780 ExAcquireResourceExclusiveLite(&IrpContext
->DeviceExt
->DirResource
, TRUE
);
781 Status
= VfatCreateFile(IrpContext
->DeviceObject
, IrpContext
->Irp
);
782 ExReleaseResourceLite(&IrpContext
->DeviceExt
->DirResource
);
784 IrpContext
->Irp
->IoStatus
.Status
= Status
;
785 IoCompleteRequest(IrpContext
->Irp
,
786 (CCHAR
)(NT_SUCCESS(Status
) ? IO_DISK_INCREMENT
: IO_NO_INCREMENT
));
787 VfatFreeIrpContext(IrpContext
);