ReactOS  0.4.13-dev-982-g9853eab
protos.h File Reference
#include "mem.h"
#include "namesup.h"
Include dependency graph for protos.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define UDF_CLOSE_NTREQFCB_DELETED   0x01
 
#define UDF_CLOSE_FCB_DELETED   0x02
 
#define UDFCloseAllDelayedInDir(Vcb, FI)   UDFCloseAllXXXDelayedInDir(Vcb,FI,FALSE);
 
#define UDFCloseAllSystemDelayedInDir(Vcb, FI)   UDFCloseAllXXXDelayedInDir(Vcb,FI,TRUE);
 
#define UDFRemoveFromDelayedQueue(Fcb)   UDFCloseAllDelayedInDir((Fcb)->Vcb, (Fcb)->FileInfo)
 
#define UDFRemoveFromSystemDelayedQueue(Fcb)   UDFCloseAllSystemDelayedInDir((Fcb)->Vcb, (Fcb)->FileInfo)
 
#define UDFRemoveFileId__(Vcb, fi)   UDFRemoveFileId(Vcb, UDFGetNTFileId(Vcb, fi, &(fi->Fcb->FCBName->ObjectName)));
 
#define UDFZeroDataEx(NtReqFcb, Offset, Length, CanWait, Vcb, FileObject)   UDFPurgeCacheEx_(NtReqFcb, Offset, Length, CanWait, Vcb, FileObject)
 
#define UDFPurgeCacheEx(NtReqFcb, Offset, Length, CanWait, Vcb, FileObject)   UDFPurgeCacheEx_(NtReqFcb, Offset, Length, CanWait, Vcb, FileObject)
 

Functions

NTSTATUS NTAPI UDFCreate (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS UDFCommonCreate (IN PtrUDFIrpContext PtrIrpContext, IN PIRP Irp)
 
NTSTATUS UDFFirstOpenFile (IN PVCB Vcb, IN PFILE_OBJECT PtrNewFileObject, OUT PtrUDFFCB *PtrNewFcb, IN PUDF_FILE_INFO RelatedFileInfo, IN PUDF_FILE_INFO NewFileInfo, IN PUNICODE_STRING LocalPath, IN PUNICODE_STRING CurName)
 
NTSTATUS UDFOpenFile (IN PVCB Vcb, IN PFILE_OBJECT PtrNewFileObject, IN PtrUDFFCB PtrNewFcb)
 
NTSTATUS UDFInitializeFCB (IN PtrUDFFCB PtrNewFcb, IN PVCB Vcb, IN PtrUDFObjectName PtrObjectName, IN ULONG Flags, IN PFILE_OBJECT FileObject)
 
NTSTATUS NTAPI UDFCleanup (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS UDFCommonCleanup (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
NTSTATUS UDFCloseFileInfoChain (IN PVCB Vcb, IN PUDF_FILE_INFO fi, IN ULONG TreeLength, IN BOOLEAN VcbAcquired)
 
NTSTATUS NTAPI UDFClose (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS UDFCommonClose (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
ULONG UDFCleanUpFcbChain (IN PVCB Vcb, IN PUDF_FILE_INFO fi, IN ULONG TreeLength, IN BOOLEAN VcbAcquired)
 
VOID UDFCloseAllDelayed (PVCB Vcb)
 
VOID NTAPI UDFDelayedClose (PVOID unused=NULL)
 
NTSTATUS UDFCloseAllXXXDelayedInDir (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN BOOLEAN System)
 
NTSTATUS UDFQueueDelayedClose (PtrUDFIrpContext IrpContext, PtrUDFFCB Fcb)
 
NTSTATUS NTAPI UDFDirControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI UDFCommonDirControl (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
NTSTATUS NTAPI UDFQueryDirectory (PtrUDFIrpContext PtrIrpContext, PIRP Irp, PIO_STACK_LOCATION IrpSp, PFILE_OBJECT FileObject, PtrUDFFCB Fcb, PtrUDFCCB Ccb)
 
NTSTATUS NTAPI UDFNotifyChangeDirectory (PtrUDFIrpContext PtrIrpContext, PIRP Irp, PIO_STACK_LOCATION IrpSp, PFILE_OBJECT FileObject, PtrUDFFCB Fcb, PtrUDFCCB Ccb)
 
NTSTATUS NTAPI UDFDeviceControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI UDFCommonDeviceControl (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
NTSTATUS NTAPI UDFDevIoctlCompletion (PDEVICE_OBJECT PtrDeviceObject, PIRP Irp, PVOID Context)
 
NTSTATUS NTAPI UDFHandleQueryPath (PVOID BufferPointer)
 
BOOLEAN NTAPI UDFFastIoCheckIfPossible (IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, IN ULONG LockKey, IN BOOLEAN CheckForReadOperation, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
 
FAST_IO_POSSIBLE NTAPI UDFIsFastIoPossible (IN PtrUDFFCB Fcb)
 
BOOLEAN NTAPI UDFFastIoQueryBasicInfo (IN PFILE_OBJECT FileObject, IN BOOLEAN Wait, OUT PFILE_BASIC_INFORMATION Buffer, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
 
BOOLEAN NTAPI UDFFastIoQueryStdInfo (IN PFILE_OBJECT FileObject, IN BOOLEAN Wait, OUT PFILE_STANDARD_INFORMATION Buffer, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
 
VOID NTAPI UDFFastIoAcqCreateSec (IN PFILE_OBJECT FileObject)
 
VOID NTAPI UDFFastIoRelCreateSec (IN PFILE_OBJECT FileObject)
 
BOOLEAN NTAPI UDFAcqLazyWrite (IN PVOID Context, IN BOOLEAN Wait)
 
VOID NTAPI UDFRelLazyWrite (IN PVOID Context)
 
BOOLEAN NTAPI UDFAcqReadAhead (IN PVOID Context, IN BOOLEAN Wait)
 
VOID NTAPI UDFRelReadAhead (IN PVOID Context)
 
VOID NTAPI UDFDriverUnload (IN PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI UDFFileInfo (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS UDFCommonFileInfo (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
NTSTATUS UDFGetBasicInformation (IN PFILE_OBJECT FileObject, IN PtrUDFFCB Fcb, IN PFILE_BASIC_INFORMATION PtrBuffer, IN OUT LONG *PtrReturnedLength)
 
NTSTATUS UDFGetNetworkInformation (IN PtrUDFFCB Fcb, IN PFILE_NETWORK_OPEN_INFORMATION PtrBuffer, IN OUT PLONG PtrReturnedLength)
 
NTSTATUS UDFGetStandardInformation (IN PtrUDFFCB Fcb, IN PFILE_STANDARD_INFORMATION PtrBuffer, IN OUT PLONG PtrReturnedLength)
 
NTSTATUS UDFGetInternalInformation (PtrUDFIrpContext PtrIrpContext, IN PtrUDFFCB Fcb, IN PtrUDFCCB Ccb, IN PFILE_INTERNAL_INFORMATION PtrBuffer, IN OUT PLONG PtrReturnedLength)
 
NTSTATUS UDFGetEaInformation (PtrUDFIrpContext PtrIrpContext, IN PtrUDFFCB Fcb, IN PFILE_EA_INFORMATION PtrBuffer, IN OUT PLONG PtrReturnedLength)
 
NTSTATUS UDFGetFullNameInformation (IN PFILE_OBJECT FileObject, IN PFILE_NAME_INFORMATION PtrBuffer, IN OUT PLONG PtrReturnedLength)
 
NTSTATUS UDFGetAltNameInformation (IN PtrUDFFCB Fcb, IN PFILE_NAME_INFORMATION PtrBuffer, IN OUT PLONG PtrReturnedLength)
 
NTSTATUS UDFGetPositionInformation (IN PFILE_OBJECT FileObject, IN PFILE_POSITION_INFORMATION PtrBuffer, IN OUT PLONG PtrReturnedLength)
 
NTSTATUS UDFGetFileStreamInformation (IN PtrUDFFCB Fcb, IN PFILE_STREAM_INFORMATION PtrBuffer, IN OUT PLONG PtrReturnedLength)
 
NTSTATUS UDFSetBasicInformation (IN PtrUDFFCB Fcb, IN PtrUDFCCB Ccb, IN PFILE_OBJECT FileObject, IN PFILE_BASIC_INFORMATION PtrBuffer)
 
NTSTATUS UDFMarkStreamsForDeletion (IN PVCB Vcb, IN PtrUDFFCB Fcb, IN BOOLEAN ForDel)
 
NTSTATUS UDFSetDispositionInformation (IN PtrUDFFCB Fcb, IN PtrUDFCCB Ccb, IN PVCB Vcb, IN PFILE_OBJECT FileObject, IN BOOLEAN Delete)
 
NTSTATUS UDFSetAllocationInformation (IN PtrUDFFCB Fcb, IN PtrUDFCCB Ccb, IN PVCB Vcb, IN PFILE_OBJECT FileObject, IN PtrUDFIrpContext PtrIrpContext, IN PIRP Irp, IN PFILE_ALLOCATION_INFORMATION PtrBuffer)
 
NTSTATUS UDFSetEOF (IN PIO_STACK_LOCATION PtrSp, IN PtrUDFFCB Fcb, IN PtrUDFCCB Ccb, IN PVCB Vcb, IN PFILE_OBJECT FileObject, IN PIRP Irp, IN PFILE_END_OF_FILE_INFORMATION PtrBuffer)
 
NTSTATUS UDFRename (IN PIO_STACK_LOCATION IrpSp, IN PtrUDFFCB Fcb, IN PtrUDFCCB Ccb, IN PFILE_OBJECT FileObject, IN PFILE_RENAME_INFORMATION PtrBuffer)
 
NTSTATUS UDFStoreFileId (IN PVCB Vcb, IN PtrUDFCCB Ccb, IN PUDF_FILE_INFO fi, IN LONGLONG Id)
 
NTSTATUS UDFRemoveFileId (IN PVCB Vcb, IN LONGLONG Id)
 
VOID UDFReleaseFileIdCache (IN PVCB Vcb)
 
NTSTATUS UDFGetOpenParamsByFileId (IN PVCB Vcb, IN LONGLONG Id, OUT PUNICODE_STRING *FName, OUT BOOLEAN *CaseSens)
 
NTSTATUS UDFHardLink (IN PIO_STACK_LOCATION PtrSp, IN PtrUDFFCB Fcb1, IN PtrUDFCCB Ccb1, IN PFILE_OBJECT FileObject1, IN PFILE_LINK_INFORMATION PtrBuffer)
 
NTSTATUS NTAPI UDFFlush (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS UDFCommonFlush (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
ULONG UDFFlushAFile (PtrUDFFCB Fcb, PtrUDFCCB Ccb, PIO_STATUS_BLOCK PtrIoStatus, IN ULONG FlushFlags=0)
 
ULONG UDFFlushADirectory (IN PVCB Vcb, IN PUDF_FILE_INFO FI, OUT PIO_STATUS_BLOCK PtrIoStatus, ULONG FlushFlags=0)
 
ULONG UDFFlushLogicalVolume (PtrUDFIrpContext PtrIrpContext, PIRP Irp, PVCB Vcb, ULONG FlushFlags=0)
 
NTSTATUS NTAPI UDFFlushCompletion (PDEVICE_OBJECT PtrDeviceObject, PIRP Irp, PVOID Context)
 
BOOLEAN UDFFlushIsBreaking (IN PVCB Vcb, IN ULONG FlushFlags=0)
 
VOID UDFFlushTryBreak (IN PVCB Vcb)
 
NTSTATUS NTAPI UDFFSControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI UDFCommonFSControl (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
NTSTATUS NTAPI UDFUserFsCtrlRequest (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
NTSTATUS NTAPI UDFMountVolume (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
NTSTATUS UDFStartEjectWaiter (IN PVCB Vcb)
 
VOID UDFScanForDismountedVcb (IN PtrUDFIrpContext IrpContext)
 
NTSTATUS UDFCompleteMount (IN PVCB Vcb)
 
VOID UDFCloseResidual (IN PVCB Vcb)
 
VOID UDFCleanupVCB (IN PVCB Vcb)
 
NTSTATUS UDFIsVolumeMounted (IN PtrUDFIrpContext IrpContext, IN PIRP Irp)
 
NTSTATUS UDFIsVolumeDirty (IN PtrUDFIrpContext IrpContext, IN PIRP Irp)
 
NTSTATUS UDFGetStatistics (IN PtrUDFIrpContext IrpContext, IN PIRP Irp)
 
NTSTATUS UDFLockVolume (IN PtrUDFIrpContext IrpContext, IN PIRP Irp, IN ULONG PID=-1)
 
NTSTATUS UDFUnlockVolume (IN PtrUDFIrpContext IrpContext, IN PIRP Irp, IN ULONG PID=-1)
 
NTSTATUS UDFIsPathnameValid (IN PtrUDFIrpContext IrpContext, IN PIRP Irp)
 
NTSTATUS UDFDismountVolume (IN PtrUDFIrpContext IrpContext, IN PIRP Irp)
 
NTSTATUS UDFGetVolumeBitmap (IN PtrUDFIrpContext IrpContext, IN PIRP Irp)
 
NTSTATUS UDFGetRetrievalPointers (IN PtrUDFIrpContext IrpContext, IN PIRP Irp, IN ULONG Special)
 
NTSTATUS UDFInvalidateVolumes (IN PtrUDFIrpContext IrpContext, IN PIRP Irp)
 
NTSTATUS NTAPI UDFLockControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI UDFCommonLockControl (IN PtrUDFIrpContext PtrIrpContext, IN PIRP Irp)
 
BOOLEAN NTAPI UDFFastLock (IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER Length, PEPROCESS ProcessId, ULONG Key, BOOLEAN FailImmediately, BOOLEAN ExclusiveLock, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
 
BOOLEAN NTAPI UDFFastUnlockSingle (IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER Length, PEPROCESS ProcessId, ULONG Key, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
 
BOOLEAN NTAPI UDFFastUnlockAll (IN PFILE_OBJECT FileObject, PEPROCESS ProcessId, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
 
BOOLEAN NTAPI UDFFastUnlockAllByKey (IN PFILE_OBJECT FileObject, PEPROCESS ProcessId, ULONG Key, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS UDFInitializeZones (VOID)
 
VOID UDFDestroyZones (VOID)
 
BOOLEAN __fastcall UDFIsIrpTopLevel (PIRP Irp)
 
long UDFExceptionFilter (PtrUDFIrpContext PtrIrpContext, PEXCEPTION_POINTERS PtrExceptionPointers)
 
NTSTATUS UDFExceptionHandler (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
VOID UDFLogEvent (NTSTATUS UDFEventLogId, NTSTATUS RC)
 
PtrUDFObjectName UDFAllocateObjectName (VOID)
 
VOID __fastcall UDFReleaseObjectName (PtrUDFObjectName PtrObjectName)
 
PtrUDFCCB UDFAllocateCCB (VOID)
 
VOID __fastcall UDFReleaseCCB (PtrUDFCCB Ccb)
 
VOID __fastcall UDFCleanUpCCB (PtrUDFCCB Ccb)
 
PtrUDFFCB UDFAllocateFCB (VOID)
 
__inline VOID UDFReleaseFCB (PtrUDFFCB Fcb)
 
VOID __fastcall UDFCleanUpFCB (PtrUDFFCB Fcb)
 
PtrUDFIrpContext UDFAllocateIrpContext (PIRP Irp, PDEVICE_OBJECT PtrTargetDeviceObject)
 
VOID UDFReleaseIrpContext (PtrUDFIrpContext PtrIrpContext)
 
NTSTATUS UDFPostRequest (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
VOID NTAPI UDFCommonDispatch (VOID *Context)
 
NTSTATUS UDFInitializeVCB (PDEVICE_OBJECT PtrVolumeDeviceObject, PDEVICE_OBJECT PtrTargetDeviceObject, PVPB PtrVPB)
 
VOID UDFReadRegKeys (PVCB Vcb, BOOLEAN Update, BOOLEAN UseCfg)
 
ULONG UDFGetRegParameter (IN PVCB Vcb, IN PCWSTR Name, IN ULONG DefValue=0)
 
ULONG UDFGetCfgParameter (IN PVCB Vcb, IN PCWSTR Name, IN ULONG DefValue)
 
VOID UDFReleaseVCB (PVCB Vcb)
 
ULONG UDFRegCheckParameterValue (IN PUNICODE_STRING RegistryPath, IN PCWSTR Name, IN PUNICODE_STRING PtrVolumePath, IN PCWSTR DefaultPath, IN ULONG DefValue=0)
 
VOID UDFInitializeIrpContextFromLite (OUT PtrUDFIrpContext *IrpContext, IN PtrUDFIrpContextLite IrpContextLite)
 
NTSTATUS UDFInitializeIrpContextLite (OUT PtrUDFIrpContextLite *IrpContextLite, IN PtrUDFIrpContext IrpContext, IN PtrUDFFCB Fcb)
 
NTSTATUS NTAPI UDFQuerySetEA (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
ULONG UDFIsResourceAcquired (IN PERESOURCE Resource)
 
BOOLEAN UDFAcquireResourceExclusiveWithCheck (IN PERESOURCE Resource)
 
BOOLEAN UDFAcquireResourceSharedWithCheck (IN PERESOURCE Resource)
 
NTSTATUS UDFWCacheErrorHandler (IN PVOID Context, IN PWCACHE_ERROR_CONTEXT ErrorInfo)
 
NTSTATUS UDFPnp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
OSSTATUS NTAPI UDFRead (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS UDFPostStackOverflowRead (IN PtrUDFIrpContext PtrIrpContext, IN PIRP Irp, IN PtrUDFFCB Fcb)
 
VOID NTAPI UDFStackOverflowRead (IN PVOID Context, IN PKEVENT Event)
 
NTSTATUS UDFCommonRead (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
PVOID UDFGetCallersBuffer (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
NTSTATUS UDFLockCallersBuffer (PtrUDFIrpContext PtrIrpContext, PIRP Irp, BOOLEAN IsReadOperation, uint32 Length)
 
NTSTATUS UDFUnlockCallersBuffer (PtrUDFIrpContext PtrIrpContext, PIRP Irp, PVOID SystemBuffer)
 
VOID UDFMdlComplete (PtrUDFIrpContext PtrIrpContext, PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN ReadCompletion)
 
NTSTATUS UDFGetSecurity (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS UDFSetSecurity (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS UDFCommonGetSecurity (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
NTSTATUS UDFCommonSetSecurity (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
NTSTATUS UDFReadSecurity (IN PVCB Vcb, IN PtrUDFFCB Fcb, IN PSECURITY_DESCRIPTOR *SecurityDesc)
 
NTSTATUS UDFAssignAcl (IN PVCB Vcb, IN PFILE_OBJECT FileObject, IN PtrUDFFCB Fcb, IN PtrUDFNTRequiredFCB NtReqFcb)
 
VOID UDFDeassignAcl (IN PtrUDFNTRequiredFCB NtReqFcb, IN BOOLEAN AutoInherited)
 
NTSTATUS UDFWriteSecurity (IN PVCB Vcb, IN PtrUDFFCB Fcb, IN PSECURITY_DESCRIPTOR *SecurityDesc)
 
NTSTATUS UDFCheckAccessRights (PFILE_OBJECT FileObject, PACCESS_STATE AccessState, PtrUDFFCB Fcb, PtrUDFCCB Ccb, ACCESS_MASK DesiredAccess, USHORT ShareAccess)
 
NTSTATUS UDFSetAccessRights (PFILE_OBJECT FileObject, PACCESS_STATE AccessState, PtrUDFFCB Fcb, PtrUDFCCB Ccb, ACCESS_MASK DesiredAccess, USHORT ShareAccess)
 
NTSTATUS NTAPI UDFShutdown (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS UDFCommonShutdown (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
BOOLEAN UDFDebugAcquireResourceSharedLite (IN PERESOURCE Resource, IN BOOLEAN Wait, ULONG BugCheckId, ULONG Line)
 
BOOLEAN UDFDebugAcquireSharedStarveExclusive (IN PERESOURCE Resource, IN BOOLEAN Wait, ULONG BugCheckId, ULONG Line)
 
BOOLEAN UDFDebugAcquireResourceExclusiveLite (IN PERESOURCE Resource, IN BOOLEAN Wait, ULONG BugCheckId, ULONG Line)
 
VOID UDFDebugReleaseResourceForThreadLite (IN PERESOURCE Resource, IN ERESOURCE_THREAD ResourceThreadId, ULONG BugCheckId, ULONG Line)
 
VOID UDFDebugDeleteResource (IN PERESOURCE Resource, IN ERESOURCE_THREAD ResourceThreadId, ULONG BugCheckId, ULONG Line)
 
NTSTATUS UDFDebugInitializeResourceLite (IN PERESOURCE Resource, IN ERESOURCE_THREAD ResourceThreadId, ULONG BugCheckId, ULONG Line)
 
VOID UDFDebugConvertExclusiveToSharedLite (IN PERESOURCE Resource, IN ERESOURCE_THREAD ResourceThreadId, ULONG BugCheckId, ULONG Line)
 
BOOLEAN UDFDebugAcquireSharedWaitForExclusive (IN PERESOURCE Resource, IN BOOLEAN Wait, ULONG BugCheckId, ULONG Line)
 
LONG UDFDebugInterlockedIncrement (IN PLONG addr, ULONG BugCheckId, ULONG Line)
 
LONG UDFDebugInterlockedDecrement (IN PLONG addr, ULONG BugCheckId, ULONG Line)
 
LONG UDFDebugInterlockedExchangeAdd (IN PLONG addr, IN LONG i, ULONG BugCheckId, ULONG Line)
 
NTSTATUS NTAPI DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
 
VOID NTAPI UDFInitializeFunctionPointers (PDRIVER_OBJECT DriverObject)
 
VOID NTAPI UDFFsNotification (IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN FsActive)
 
BOOLEAN UDFGetInstallVersion (PULONG iVer)
 
BOOLEAN UDFGetInstallTime (PULONG iTime)
 
BOOLEAN UDFGetTrialEnd (PULONG iTrial)
 
NTSTATUS UDFVerifyVcb (IN PtrUDFIrpContext IrpContext, IN PVCB Vcb)
 
NTSTATUS UDFVerifyVolume (IN PIRP Irp)
 
NTSTATUS UDFPerformVerify (IN PtrUDFIrpContext IrpContext, IN PIRP Irp, IN PDEVICE_OBJECT DeviceToVerify)
 
BOOLEAN UDFCheckForDismount (IN PtrUDFIrpContext IrpContext, IN PVCB Vcb, IN BOOLEAN VcbAcquired)
 
BOOLEAN UDFDismountVcb (IN PVCB Vcb, IN BOOLEAN VcbAcquired)
 
NTSTATUS UDFCompareVcb (IN PVCB OldVcb, IN PVCB NewVcb, IN BOOLEAN PhysicalOnly)
 
NTSTATUS NTAPI UDFQueryVolInfo (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS UDFCommonQueryVolInfo (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
NTSTATUS NTAPI UDFSetVolInfo (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS UDFCommonSetVolInfo (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
NTSTATUS NTAPI UDFWrite (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS UDFCommonWrite (PtrUDFIrpContext PtrIrpContext, PIRP Irp)
 
VOID NTAPI UDFDeferredWriteCallBack (VOID *Context1, VOID *Context2)
 
VOID UDFPurgeCacheEx_ (PtrUDFNTRequiredFCB NtReqFcb, LONGLONG Offset, LONGLONG Length, BOOLEAN CanWait, PVCB Vcb, PFILE_OBJECT FileObject)
 

Macro Definition Documentation

◆ UDF_CLOSE_FCB_DELETED

#define UDF_CLOSE_FCB_DELETED   0x02

Definition at line 81 of file protos.h.

◆ UDF_CLOSE_NTREQFCB_DELETED

#define UDF_CLOSE_NTREQFCB_DELETED   0x01

Definition at line 80 of file protos.h.

◆ UDFCloseAllDelayedInDir

#define UDFCloseAllDelayedInDir (   Vcb,
  FI 
)    UDFCloseAllXXXDelayedInDir(Vcb,FI,FALSE);

Definition at line 96 of file protos.h.

◆ UDFCloseAllSystemDelayedInDir

#define UDFCloseAllSystemDelayedInDir (   Vcb,
  FI 
)    UDFCloseAllXXXDelayedInDir(Vcb,FI,TRUE);

Definition at line 99 of file protos.h.

◆ UDFPurgeCacheEx

#define UDFPurgeCacheEx (   NtReqFcb,
  Offset,
  Length,
  CanWait,
  Vcb,
  FileObject 
)    UDFPurgeCacheEx_(NtReqFcb, Offset, Length, CanWait, Vcb, FileObject)

Definition at line 1148 of file protos.h.

◆ UDFRemoveFileId__

#define UDFRemoveFileId__ (   Vcb,
  fi 
)    UDFRemoveFileId(Vcb, UDFGetNTFileId(Vcb, fi, &(fi->Fcb->FCBName->ObjectName)));

Definition at line 407 of file protos.h.

◆ UDFRemoveFromDelayedQueue

#define UDFRemoveFromDelayedQueue (   Fcb)    UDFCloseAllDelayedInDir((Fcb)->Vcb, (Fcb)->FileInfo)

Definition at line 106 of file protos.h.

◆ UDFRemoveFromSystemDelayedQueue

#define UDFRemoveFromSystemDelayedQueue (   Fcb)    UDFCloseAllSystemDelayedInDir((Fcb)->Vcb, (Fcb)->FileInfo)

Definition at line 109 of file protos.h.

◆ UDFZeroDataEx

#define UDFZeroDataEx (   NtReqFcb,
  Offset,
  Length,
  CanWait,
  Vcb,
  FileObject 
)    UDFPurgeCacheEx_(NtReqFcb, Offset, Length, CanWait, Vcb, FileObject)

Definition at line 1146 of file protos.h.

Function Documentation

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( PDRIVER_OBJECT  DriverObject,
PUNICODE_STRING  RegistryPath 
)

Definition at line 16 of file battc.c.

18 {
19  DPRINT("Battery class driver initialized\n");
20 
21  return STATUS_SUCCESS;
22 }
void DPRINT(...)
Definition: polytest.cpp:61
return STATUS_SUCCESS
Definition: btrfs.c:2777

◆ UDFAcqLazyWrite()

BOOLEAN NTAPI UDFAcqLazyWrite ( IN PVOID  Context,
IN BOOLEAN  Wait 
)

Definition at line 423 of file fastio.cpp.

426 {
427  // The context is whatever we passed to the Cache Manager when invoking
428  // the CcInitializeCacheMaps() function. In the case of the UDF FSD
429  // implementation, this context is a pointer to the NT_REQ_FCB structure.
431 
432  MmPrint((" UDFAcqLazyWrite()\n"));
433 
434  // Acquire the PagingIoResource in the NT_REQ_FCB exclusively. Then, set the
435  // lazy-writer thread id in the NT_REQ_FCB structure for identification
436  // when an actual write request is received by the FSD.
437  // Note: The lazy-writer typically always supplies WAIT set to TRUE.
438  if (!UDFAcquireResourceExclusive(&(NtReqFcb->PagingIoResource), Wait))
439  return FALSE;
440 
441  // Now, set the lazy-writer thread id.
442  ASSERT(!(NtReqFcb->LazyWriterThreadID));
443  NtReqFcb->LazyWriterThreadID = HandleToUlong(PsGetCurrentThreadId());
444 
447 
448  // If our FSD needs to perform some special preparations in anticipation
449  // of receving a lazy-writer request, do so now.
450  return TRUE;
451 } // end UDFAcqLazyWrite()
#define UDFAcquireResourceExclusive(Resource, CanWait)
Definition: env_spec_w32.h:656
#define TRUE
Definition: types.h:120
#define HandleToUlong(h)
Definition: basetsd.h:79
smooth NULL
Definition: ftsmooth.c:416
PsGetCurrentThreadId
Definition: CrNtStubs.h:7
PIRP NTAPI IoGetTopLevelIrp(VOID)
Definition: irp.c:1843
#define MmPrint(_x_)
Definition: env_spec_w32.h:289
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define NtReqFcb
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define FSRTL_CACHE_TOP_LEVEL_IRP
Definition: fsrtltypes.h:60
struct _UDFNTRequiredFCB * PtrUDFNTRequiredFCB
IN BOOLEAN Wait
Definition: fatprocs.h:1529

Referenced by UDFInitializeFunctionPointers().

◆ UDFAcqReadAhead()

BOOLEAN NTAPI UDFAcqReadAhead ( IN PVOID  Context,
IN BOOLEAN  Wait 
)

Definition at line 514 of file fastio.cpp.

518 {
519  // The context is whatever we passed to the Cache Manager when invoking
520  // the CcInitializeCacheMaps() function. In the case of the UDF FSD
521  // implementation, this context is a pointer to the NT_REQ_FCB structure.
522 #define NtReqFcb ((PtrUDFNTRequiredFCB)Context)
523 
524  MmPrint((" AcqForReadAhead()\n"));
525 
526  // Acquire the MainResource in the NT_REQ_FCB shared.
527  // Note: The read-ahead thread typically always supplies WAIT set to TRUE.
529  if (!UDFAcquireResourceShared(&(NtReqFcb->MainResource), Wait))
530  return FALSE;
531 
534 
535  return TRUE;
536 #undef NtReqFcb
537 
538 } // end UDFAcqReadAhead()
#define TRUE
Definition: types.h:120
smooth NULL
Definition: ftsmooth.c:416
PIRP NTAPI IoGetTopLevelIrp(VOID)
Definition: irp.c:1843
#define MmPrint(_x_)
Definition: env_spec_w32.h:289
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define NtReqFcb
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define UDFAcquireResourceShared(Resource, CanWait)
Definition: env_spec_w32.h:658
#define UDF_CHECK_PAGING_IO_RESOURCE(NTReqFCB)
Definition: udffs.h:262
#define FSRTL_CACHE_TOP_LEVEL_IRP
Definition: fsrtltypes.h:60
IN BOOLEAN Wait
Definition: fatprocs.h:1529

Referenced by UDFInitializeFunctionPointers().

◆ UDFAcquireResourceExclusiveWithCheck()

BOOLEAN UDFAcquireResourceExclusiveWithCheck ( IN PERESOURCE  Resource)

Definition at line 2529 of file misc.cpp.

2532 {
2533  ULONG ReAcqRes =
2536  if(ReAcqRes) {
2537  UDFPrint(("UDFAcquireResourceExclusiveWithCheck: ReAcqRes, %x\n", ReAcqRes));
2538  } else {
2539 // BrutePoint();
2540  }
2541 
2542  if(ReAcqRes == 1) {
2543  // OK
2544  } else
2545  if(ReAcqRes == 2) {
2546  UDFPrint(("UDFAcquireResourceExclusiveWithCheck: !!! Shared !!!\n"));
2547  //BrutePoint();
2548  } else {
2550  return TRUE;
2551  }
2552  return FALSE;
2553 } // end UDFAcquireResourceExclusiveWithCheck()
#define UDFAcquireResourceExclusive(Resource, CanWait)
Definition: env_spec_w32.h:656
#define UDFPrint(Args)
Definition: udffs.h:225
#define TRUE
Definition: types.h:120
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:848
BOOLEAN NTAPI ExIsResourceAcquiredExclusiveLite(IN PERESOURCE Resource)
Definition: resource.c:1619
unsigned int ULONG
Definition: retypes.h:1
ULONG NTAPI ExIsResourceAcquiredSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1658

Referenced by UDFCommonCleanup(), UDFCommonWrite(), UDFSetAllocationInformation(), UDFSetEOF(), and UDFTSendIOCTL().

◆ UDFAcquireResourceSharedWithCheck()

BOOLEAN UDFAcquireResourceSharedWithCheck ( IN PERESOURCE  Resource)

Definition at line 2556 of file misc.cpp.

2559 {
2560  ULONG ReAcqRes =
2563  if(ReAcqRes) {
2564  UDFPrint(("UDFAcquireResourceSharedWithCheck: ReAcqRes, %x\n", ReAcqRes));
2565 /* } else {
2566  BrutePoint();*/
2567  }
2568 
2569  if(ReAcqRes == 2) {
2570  // OK
2571  } else
2572  if(ReAcqRes == 1) {
2573  UDFPrint(("UDFAcquireResourceSharedWithCheck: Exclusive\n"));
2574  //BrutePoint();
2575  } else {
2577  return TRUE;
2578  }
2579  return FALSE;
2580 } // end UDFAcquireResourceSharedWithCheck()
#define UDFPrint(Args)
Definition: udffs.h:225
#define TRUE
Definition: types.h:120
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:848
BOOLEAN NTAPI ExIsResourceAcquiredExclusiveLite(IN PERESOURCE Resource)
Definition: resource.c:1619
#define UDFAcquireResourceShared(Resource, CanWait)
Definition: env_spec_w32.h:658
unsigned int ULONG
Definition: retypes.h:1
ULONG NTAPI ExIsResourceAcquiredSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1658

Referenced by UDFCommonRead().

◆ UDFAllocateCCB()

PtrUDFCCB UDFAllocateCCB ( VOID  )

Definition at line 707 of file misc.cpp.

708 {
709  PtrUDFCCB Ccb = NULL;
710  BOOLEAN AllocatedFromZone = TRUE;
711  KIRQL CurrentIrql;
712 
713  // first, __try to allocate out of the zone
714  KeAcquireSpinLock(&(UDFGlobalData.ZoneAllocationSpinLock), &CurrentIrql);
715  if (!ExIsFullZone(&(UDFGlobalData.CCBZoneHeader))) {
716  // we have enough memory
717  Ccb = (PtrUDFCCB)ExAllocateFromZone(&(UDFGlobalData.CCBZoneHeader));
718 
719  // release the spinlock
720  KeReleaseSpinLock(&(UDFGlobalData.ZoneAllocationSpinLock), CurrentIrql);
721  } else {
722  // release the spinlock
723  KeReleaseSpinLock(&(UDFGlobalData.ZoneAllocationSpinLock), CurrentIrql);
724 
725  // if we failed to obtain from the zone, get it directly from the VMM
727  AllocatedFromZone = FALSE;
728 // UDFPrint((" CCB allocated @%x\n",Ccb));
729  }
730 
731  if (!Ccb) {
732  return NULL;
733  }
734 
735  // zero out the allocated memory block
737 
738  // set up some fields ...
739  Ccb->NodeIdentifier.NodeType = UDF_NODE_TYPE_CCB;
740  Ccb->NodeIdentifier.NodeSize = UDFQuadAlign(sizeof(UDFCCB));
741 
742 
743  if (!AllocatedFromZone) {
745  }
746 
747  UDFPrint(("UDFAllocateCCB: %x\n", Ccb));
748  return(Ccb);
749 } // end UDFAllocateCCB()
#define UDF_CCB_NOT_FROM_ZONE
Definition: struct.h:175
#define UDFPrint(Args)
Definition: udffs.h:225
#define TRUE
Definition: types.h:120
struct _UDFContextControlBlock * PtrUDFCCB
#define UDFSetFlag(Flag, Value)
Definition: udffs.h:191
#define ExIsFullZone(Zone)
Definition: exfuncs.h:329
UCHAR KIRQL
Definition: env_spec_w32.h:591
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define MyAllocatePool__(type, size)
Definition: mem_tools.h:149
#define UDF_NODE_TYPE_CCB
Definition: struct.h:59
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
UDFData UDFGlobalData
Definition: udfinit.cpp:25
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
#define UDFQuadAlign(Value)
Definition: udffs.h:196
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by UDFOpenFile().

◆ UDFAllocateFCB()

PtrUDFFCB UDFAllocateFCB ( VOID  )

Definition at line 854 of file misc.cpp.

855 {
856  PtrUDFFCB Fcb = NULL;
857 
859 
860  if (!Fcb) {
861  return NULL;
862  }
863 
864  // zero out the allocated memory block
866 
867  // set up some fields ...
868  Fcb->NodeIdentifier.NodeType = UDF_NODE_TYPE_FCB;
869  Fcb->NodeIdentifier.NodeSize = UDFQuadAlign(sizeof(UDFFCB));
870 
871  UDFPrint(("UDFAllocateFCB: %x\n", Fcb));
872  return(Fcb);
873 } // end UDFAllocateFCB()
#define UDFPrint(Args)
Definition: udffs.h:225
#define UDF_NODE_TYPE_FCB
Definition: struct.h:60
#define UDF_FCB_MT
Definition: struct.h:241
struct _UDFFileControlBlock * PtrUDFFCB
smooth NULL
Definition: ftsmooth.c:416
#define MyAllocatePool__(type, size)
Definition: mem_tools.h:149
#define UDFQuadAlign(Value)
Definition: udffs.h:196
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_In_ PFCB Fcb
Definition: cdprocs.h:151

Referenced by UDFBlankMount(), UDFCompleteMount(), and UDFFirstOpenFile().

◆ UDFAllocateIrpContext()

PtrUDFIrpContext UDFAllocateIrpContext ( PIRP  Irp,
PDEVICE_OBJECT  PtrTargetDeviceObject 
)

Definition at line 985 of file misc.cpp.

989 {
990  PtrUDFIrpContext PtrIrpContext = NULL;
991  BOOLEAN AllocatedFromZone = TRUE;
992  KIRQL CurrentIrql;
994 
995  // first, __try to allocate out of the zone
996  KeAcquireSpinLock(&(UDFGlobalData.ZoneAllocationSpinLock), &CurrentIrql);
997  if (!ExIsFullZone(&(UDFGlobalData.IrpContextZoneHeader))) {
998  // we have enough memory
999  PtrIrpContext = (PtrUDFIrpContext)ExAllocateFromZone(&(UDFGlobalData.IrpContextZoneHeader));
1000 
1001  // release the spinlock
1002  KeReleaseSpinLock(&(UDFGlobalData.ZoneAllocationSpinLock), CurrentIrql);
1003  } else {
1004  // release the spinlock
1005  KeReleaseSpinLock(&(UDFGlobalData.ZoneAllocationSpinLock), CurrentIrql);
1006 
1007  // if we failed to obtain from the zone, get it directly from the VMM
1009  AllocatedFromZone = FALSE;
1010  }
1011 
1012  // if we could not obtain the required memory, bug-check.
1013  // Do NOT do this in your commercial driver, instead handle the error gracefully ...
1014  if (!PtrIrpContext) {
1015  return NULL;
1016  }
1017 
1018 #ifdef UDF_DBG
1019  IrpContextCounter++;
1020 #endif //UDF_DBG
1021 
1022  // zero out the allocated memory block
1023  RtlZeroMemory(PtrIrpContext, UDFQuadAlign(sizeof(UDFIrpContext)));
1024 
1025  // set up some fields ...
1027  PtrIrpContext->NodeIdentifier.NodeSize = UDFQuadAlign(sizeof(UDFIrpContext));
1028 
1029 
1030  PtrIrpContext->Irp = Irp;
1031  PtrIrpContext->TargetDeviceObject = PtrTargetDeviceObject;
1032 
1033  // copy over some fields from the IRP and set appropriate flag values
1034  if (Irp) {
1036  ASSERT(IrpSp);
1037 
1038  PtrIrpContext->MajorFunction = IrpSp->MajorFunction;
1039  PtrIrpContext->MinorFunction = IrpSp->MinorFunction;
1040 
1041  // Often, a FSD cannot honor a request for asynchronous processing
1042  // of certain critical requests. For example, a "close" request on
1043  // a file object can typically never be deferred. Therefore, do not
1044  // be surprised if sometimes our FSD (just like all other FSD
1045  // implementations on the Windows NT system) has to override the flag
1046  // below.
1047  if (IrpSp->FileObject == NULL) {
1048  PtrIrpContext->IrpContextFlags |= UDF_IRP_CONTEXT_CAN_BLOCK;
1049  } else {
1051  PtrIrpContext->IrpContextFlags |= UDF_IRP_CONTEXT_CAN_BLOCK;
1052  }
1053  }
1054  }
1055 
1056  if (!AllocatedFromZone) {
1058  }
1059 
1060  // Are we top-level ? This information is used by the dispatching code
1061  // later (and also by the FSD dispatch routine)
1062  if (IoGetTopLevelIrp() != Irp) {
1063  // We are not top-level. Note this fact in the context structure
1065  }
1066 
1067  return(PtrIrpContext);
1068 } // end UDFAllocateIrpContext()
#define TRUE
Definition: types.h:120
#define UDF_IRP_CONTEXT_NOT_TOP_LEVEL
Definition: struct.h:390
_In_ PIRP Irp
Definition: csq.h:116
#define UDFSetFlag(Flag, Value)
Definition: udffs.h:191
#define UDF_IRP_CONTEXT_NOT_FROM_ZONE
Definition: struct.h:399
#define ExIsFullZone(Zone)
Definition: exfuncs.h:329
PDEVICE_OBJECT TargetDeviceObject
Definition: struct.h:374
BOOLEAN NTAPI IoIsOperationSynchronous(IN PIRP Irp)
Definition: irp.c:1882
#define UDF_IRP_CONTEXT_CAN_BLOCK
Definition: struct.h:385
UCHAR KIRQL
Definition: env_spec_w32.h:591
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
uint32 IrpContextFlags
Definition: struct.h:364
uint32 NodeType
Definition: struct.h:75
#define MyAllocatePool__(type, size)
Definition: mem_tools.h:149
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
PIRP NTAPI IoGetTopLevelIrp(VOID)
Definition: irp.c:1843
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _UDFIrpContext * PtrUDFIrpContext
UDFData UDFGlobalData
Definition: udfinit.cpp:25
uint32 NodeSize
Definition: struct.h:76
#define UDFQuadAlign(Value)
Definition: udffs.h:196
UDFIdentifier NodeIdentifier
Definition: struct.h:363
uint8 MinorFunction
Definition: struct.h:368
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define UDF_NODE_TYPE_IRP_CONTEXT
Definition: struct.h:62
uint8 MajorFunction
Definition: struct.h:366

Referenced by UDFCleanup(), UDFClose(), UDFCreate(), UDFDeviceControl(), UDFDirControl(), UDFFileInfo(), UDFFlush(), UDFFSControl(), UDFInitializeIrpContextFromLite(), UDFLockControl(), UDFPnp(), UDFQueryVolInfo(), UDFRead(), UDFSetVolInfo(), UDFShutdown(), and UDFWrite().

◆ UDFAllocateObjectName()

PtrUDFObjectName UDFAllocateObjectName ( VOID  )

Definition at line 611 of file misc.cpp.

612 {
613  PtrUDFObjectName PtrObjectName = NULL;
614  BOOLEAN AllocatedFromZone = TRUE;
615  KIRQL CurrentIrql;
616 
617  // first, __try to allocate out of the zone
618  KeAcquireSpinLock(&(UDFGlobalData.ZoneAllocationSpinLock), &CurrentIrql);
619  if (!ExIsFullZone(&(UDFGlobalData.ObjectNameZoneHeader))) {
620  // we have enough memory
621  PtrObjectName = (PtrUDFObjectName)ExAllocateFromZone(&(UDFGlobalData.ObjectNameZoneHeader));
622 
623  // release the spinlock
624  KeReleaseSpinLock(&(UDFGlobalData.ZoneAllocationSpinLock), CurrentIrql);
625  } else {
626  // release the spinlock
627  KeReleaseSpinLock(&(UDFGlobalData.ZoneAllocationSpinLock), CurrentIrql);
628 
629  // if we failed to obtain from the zone, get it directly from the VMM
631  AllocatedFromZone = FALSE;
632  }
633 
634  if (!PtrObjectName) {
635  return NULL;
636  }
637 
638  // zero out the allocated memory block
639  RtlZeroMemory(PtrObjectName, UDFQuadAlign(sizeof(UDFObjectName)));
640 
641  // set up some fields ...
643  PtrObjectName->NodeIdentifier.NodeSize = UDFQuadAlign(sizeof(UDFObjectName));
644 
645 
646  if (!AllocatedFromZone) {
648  }
649 
650  return(PtrObjectName);
651 } // end UDFAllocateObjectName()
#define UDF_NODE_TYPE_OBJECT_NAME
Definition: struct.h:58
#define TRUE
Definition: types.h:120
struct _UDFObjectName * PtrUDFObjectName
#define UDFSetFlag(Flag, Value)
Definition: udffs.h:191
#define ExIsFullZone(Zone)
Definition: exfuncs.h:329
UCHAR KIRQL
Definition: env_spec_w32.h:591
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
uint32 NodeType
Definition: struct.h:75
#define MyAllocatePool__(type, size)
Definition: mem_tools.h:149
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
UDFIdentifier NodeIdentifier
Definition: struct.h:91
UDFData UDFGlobalData
Definition: udfinit.cpp:25
uint32 NodeSize
Definition: struct.h:76
#define UDFQuadAlign(Value)
Definition: udffs.h:196
uint32 ObjectNameFlags
Definition: struct.h:92
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define UDF_OBJ_NAME_NOT_FROM_ZONE
Definition: struct.h:97

Referenced by UDFBlankMount(), UDFCompleteMount(), UDFFirstOpenFile(), and UDFRename().

◆ UDFAssignAcl()

NTSTATUS UDFAssignAcl ( IN PVCB  Vcb,
IN PFILE_OBJECT  FileObject,
IN PtrUDFFCB  Fcb,
IN PtrUDFNTRequiredFCB  NtReqFcb 
)

Definition at line 706 of file secursup.cpp.

712 {
714 #ifdef UDF_ENABLE_SECURITY
715 // SECURITY_INFORMATION SecurityInformation;
716 
717 // UDFPrint((" UDFAssignAcl\n"));
718  if(!NtReqFcb->SecurityDesc) {
719 
720  PSECURITY_DESCRIPTOR ExplicitSecurity = NULL;
721 
722  if(UDFIsAStreamDir(Fcb->FileInfo) || UDFIsAStream(Fcb->FileInfo)) {
723  // Stream/SDir security
724  NtReqFcb->SecurityDesc = Fcb->FileInfo->ParentFile->Dloc->CommonFcb->SecurityDesc;
725  return STATUS_SUCCESS;
726  } else
727  if(!Fcb->FileInfo) {
728  // Volume security
729  if(Vcb->RootDirFCB &&
730  Vcb->RootDirFCB->FileInfo &&
731  Vcb->RootDirFCB->FileInfo->Dloc &&
732  Vcb->RootDirFCB->FileInfo->Dloc->CommonFcb) {
733  RC = UDFInheritAcl(Vcb, &(Vcb->RootDirFCB->FileInfo->Dloc->CommonFcb->SecurityDesc), &ExplicitSecurity);
734  } else {
735  NtReqFcb->SecurityDesc = NULL;
737  }
738  return RC;
739  }
740 
741  RC = UDFReadSecurity(Vcb, Fcb, &ExplicitSecurity);
742  if(RC == STATUS_NO_SECURITY_ON_OBJECT) {
743  if(!Fcb->FileInfo->ParentFile) {
744  RC = UDFBuildFullControlAcl(Vcb, &ExplicitSecurity);
745  } else {
746  RC = UDFInheritAcl(Vcb, &(Fcb->FileInfo->ParentFile->Dloc->CommonFcb->SecurityDesc), &ExplicitSecurity);
747  }
748 /* if(NT_SUCCESS(RC)) {
749  NtReqFcb->NtReqFCBFlags |= UDF_NTREQ_FCB_SD_MODIFIED;
750  }*/
751  }
752  if(NT_SUCCESS(RC)) {
753 
754 // SecurityInformation = FULL_SECURITY_INFORMATION;
755  NtReqFcb->SecurityDesc = ExplicitSecurity;
756 
757 /* RC = SeSetSecurityDescriptorInfo(FileObject,
758  &SecurityInformation,
759  ExplicitSecurity,
760  &(NtReqFcb->SecurityDesc),
761  NonPagedPool,
762  IoGetFileObjectGenericMapping() );*/
763 
764  }
765  }
766 #endif //UDF_ENABLE_SECURITY
767  return RC;
768 } // end UDFAssignAcl()
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS UDFReadSecurity(IN PVCB Vcb, IN PtrUDFFCB Fcb, IN PSECURITY_DESCRIPTOR *SecurityDesc)
Definition: secursup.cpp:420
#define UDFIsAStreamDir(FI)
Definition: udf_info.h:998
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define Vcb
Definition: cdprocs.h:1425
#define STATUS_NO_SECURITY_ON_OBJECT
Definition: ntstatus.h:437
#define NtReqFcb
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2777
#define UDFIsAStream(FI)
Definition: udf_info.h:1002

Referenced by UDFCompleteMount(), and UDFLookUpAcl().

◆ UDFCheckAccessRights()

NTSTATUS UDFCheckAccessRights ( PFILE_OBJECT  FileObject,
PACCESS_STATE  AccessState,
PtrUDFFCB  Fcb,
PtrUDFCCB  Ccb,
ACCESS_MASK  DesiredAccess,
USHORT  ShareAccess 
)

Definition at line 927 of file secursup.cpp.

935 {
936  NTSTATUS RC;
937  BOOLEAN ROCheck = FALSE;
938 #ifdef UDF_ENABLE_SECURITY
939  BOOLEAN SecurityCheck;
940  PSECURITY_DESCRIPTOR SecDesc;
942  ACCESS_MASK LocalAccessMask;
943 #endif //UDF_ENABLE_SECURITY
944 
945  // Check attr compatibility
946  ASSERT(Fcb);
947  ASSERT(Fcb->Vcb);
948 #ifdef UDF_READ_ONLY_BUILD
949  goto treat_as_ro;
950 #endif //UDF_READ_ONLY_BUILD
951 
952  if(Fcb->FCBFlags & UDF_FCB_READ_ONLY) {
953  ROCheck = TRUE;
954  } else
955  if((Fcb->Vcb->origIntegrityType == INTEGRITY_TYPE_OPEN) &&
956  Ccb && !(Ccb->CCBFlags & UDF_CCB_VOLUME_OPEN) &&
957  (Fcb->Vcb->CompatFlags & UDF_VCB_IC_DIRTY_RO)) {
958  AdPrint(("force R/O on dirty\n"));
959  ROCheck = TRUE;
960  }
961  if(ROCheck) {
962 #ifdef UDF_READ_ONLY_BUILD
963 treat_as_ro:
964 #endif //UDF_READ_ONLY_BUILD
965  ACCESS_MASK DesiredAccessMask = 0;
966 
967  if(Fcb->Vcb->CompatFlags & UDF_VCB_IC_WRITE_IN_RO_DIR) {
968  if(Fcb->FCBFlags & UDF_FCB_DIRECTORY) {
969  DesiredAccessMask = (FILE_WRITE_EA |
970  DELETE);
971  } else {
972  DesiredAccessMask = (FILE_WRITE_DATA |
974  FILE_WRITE_EA |
975  DELETE);
976  }
977  } else {
978  DesiredAccessMask = (FILE_WRITE_DATA |
980  FILE_WRITE_EA |
983  FILE_ADD_FILE |
984  DELETE);
985  }
986  if(DesiredAccess & DesiredAccessMask)
987  return STATUS_ACCESS_DENIED;
988  }
989 #ifdef UDF_ENABLE_SECURITY
990  // Check Security
991  // NOTE: we should not perform security check if an empty DesiredAccess
992  // was specified. AFAIU, SeAccessCheck() will return FALSE in this case.
993  SecDesc = UDFLookUpAcl(Fcb->Vcb, FileObject, Fcb);
994  if(SecDesc && DesiredAccess) {
996  SecurityCheck =
997  SeAccessCheck(SecDesc,
999  FALSE,
1000  DesiredAccess,
1001  Ccb ? Ccb->PreviouslyGrantedAccess : 0,
1002  NULL,
1004  UserMode,
1005  Ccb ? &(Ccb->PreviouslyGrantedAccess) : &LocalAccessMask,
1006  &RC);
1008 
1009  if(!SecurityCheck) {
1010  return RC;
1011  } else
1012 #endif //UDF_ENABLE_SECURITY
1015  return STATUS_ACCESS_DENIED;
1016  Ccb->PreviouslyGrantedAccess |= ACCESS_SYSTEM_SECURITY;
1017  }
1018 #ifdef UDF_ENABLE_SECURITY
1019  }
1020 #endif //UDF_ENABLE_SECURITY
1021  if(FileObject) {
1022  if (Fcb->OpenHandleCount) {
1023  // The FCB is currently in use by some thread.
1024  // We must check whether the requested access/share access
1025  // conflicts with the existing open operations.
1027  &(Fcb->NTRequiredFCB->FCBShareAccess), TRUE);
1028 #ifndef UDF_ENABLE_SECURITY
1029  if(Ccb)
1030  Ccb->PreviouslyGrantedAccess |= DesiredAccess;
1031  IoUpdateShareAccess(FileObject, &(Fcb->NTRequiredFCB->FCBShareAccess));
1032 #endif //UDF_ENABLE_SECURITY
1033  } else {
1034  IoSetShareAccess(DesiredAccess, ShareAccess, FileObject, &(Fcb->NTRequiredFCB->FCBShareAccess));
1035 #ifndef UDF_ENABLE_SECURITY
1036  if(Ccb)
1037  Ccb->PreviouslyGrantedAccess = DesiredAccess;
1038 #endif //UDF_ENABLE_SECURITY
1039  RC = STATUS_SUCCESS;
1040  }
1041  } else {
1042  // we get here if given file was opened for internal purposes
1043  RC = STATUS_SUCCESS;
1044  }
1045  return RC;
1046 } // end UDFCheckAccessRights()
PGENERIC_MAPPING NTAPI IoGetFileObjectGenericMapping(VOID)
Definition: file.c:3266
#define UDF_VCB_IC_WRITE_IN_RO_DIR
Definition: udf_common.h:499
VOID NTAPI SeCaptureSubjectContext(OUT PSECURITY_SUBJECT_CONTEXT SubjectContext)
Definition: access.c:301
BOOLEAN NTAPI SeAccessCheck(IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext, IN BOOLEAN SubjectContextLocked, IN ACCESS_MASK DesiredAccess, IN ACCESS_MASK PreviouslyGrantedAccess, OUT PPRIVILEGE_SET *Privileges, IN PGENERIC_MAPPING GenericMapping, IN KPROCESSOR_MODE AccessMode, OUT PACCESS_MASK GrantedAccess, OUT PNTSTATUS AccessStatus)
Definition: accesschk.c:340
#define FILE_WRITE_EA
Definition: nt_native.h:640
_Inout_ PLIST_ENTRY _In_ PVOID _In_ PSTRING _In_ BOOLEAN _In_ BOOLEAN _In_ ULONG _In_ PFLT_CALLBACK_DATA _In_opt_ PCHECK_FOR_TRAVERSE_ACCESS _In_opt_ PSECURITY_SUBJECT_CONTEXT SubjectContext
Definition: fltkernel.h:2239
VOID NTAPI SeReleaseSubjectContext(IN PSECURITY_SUBJECT_CONTEXT SubjectContext)
Definition: access.c:360
#define TRUE
Definition: types.h:120
#define AdPrint(_x_)
Definition: env_spec_w32.h:292
#define ACCESS_SYSTEM_SECURITY
Definition: nt_native.h:77
LONG NTSTATUS
Definition: precomp.h:26
PSECURITY_DESCRIPTOR UDFLookUpAcl(IN PVCB Vcb, PFILE_OBJECT FileObject, IN PtrUDFFCB Fcb)
Definition: secursup.cpp:915
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
VOID NTAPI IoSetShareAccess(IN ACCESS_MASK DesiredAccess, IN ULONG DesiredShareAccess, IN PFILE_OBJECT FileObject, OUT PSHARE_ACCESS ShareAccess)
Definition: file.c:3516
#define FILE_APPEND_DATA
Definition: nt_native.h:634
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK _In_ USHORT ShareAccess
Definition: create.c:4157
LUID SeSecurityPrivilege
Definition: setypes.h:1147
#define UDF_VCB_IC_DIRTY_RO
Definition: udf_common.h:516
#define FILE_DELETE_CHILD
Definition: nt_native.h:645
#define FILE_ADD_FILE
Definition: nt_native.h:632
PSE_EXPORTS SeExports
Definition: semgr.c:18
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define FILE_WRITE_DATA
Definition: nt_native.h:631
ULONG OpenHandleCount
Definition: ntfs.h:533
#define UDF_CCB_VOLUME_OPEN
Definition: struct.h:166
#define UDF_FCB_DIRECTORY
Definition: struct.h:303
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define FILE_ADD_SUBDIRECTORY
Definition: nt_native.h:635
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
NTSTATUS NTAPI IoCheckShareAccess(IN ACCESS_MASK DesiredAccess, IN ULONG DesiredShareAccess, IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess, IN BOOLEAN Update)
Definition: file.c:3389
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
#define UDF_FCB_READ_ONLY
Definition: struct.h:312
#define INTEGRITY_TYPE_OPEN
Definition: ecma_167.h:357
PVCB Vcb
Definition: cdstruc.h:939
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2777
VOID NTAPI IoUpdateShareAccess(IN PFILE_OBJECT FileObject, OUT PSHARE_ACCESS ShareAccess)
Definition: file.c:3350
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define DELETE
Definition: nt_native.h:57

Referenced by UDFCommonCreate(), UDFDoesOSAllowFileToBeTargetForRename__(), UDFSetAccessRights(), and UDFSetDispositionInformation().

◆ UDFCheckForDismount()

BOOLEAN UDFCheckForDismount ( IN PtrUDFIrpContext  IrpContext,
IN PVCB  Vcb,
IN BOOLEAN  VcbAcquired 
)

Definition at line 629 of file verfysup.cpp.

634 {
635  BOOLEAN VcbPresent = TRUE;
636  KIRQL SavedIrql;
637  BOOLEAN VcbAcquired;
638  ULONG ResidualReferenceCount;
639 
640  UDFPrint(("UDFCheckForDismount:\n"));
641  if(!Vcb) return FALSE;
642 
643  // GlobalDataResource is already acquired
644  if(!_VcbAcquired) {
645  VcbAcquired = UDFAcquireResourceExclusive(&(Vcb->VCBResource), TRUE/*FALSE*/ );
646  if(!VcbAcquired)
647  return TRUE;
648  } else {
649  VcbAcquired = TRUE;
650  }
651 
652  if ((IrpContext->MajorFunction == IRP_MJ_CREATE) &&
653  (IrpContext->TargetDeviceObject == Vcb->TargetDeviceObject)) {
654 
655  ResidualReferenceCount = 2;
656 
657  } else {
658 
659  ResidualReferenceCount = 1;
660  }
661 
662  // If the dismount is not already underway then check if the
663  // user reference count has gone to zero. If so start the teardown
664  // on the Vcb.
665  if (!(Vcb->VCBFlags & UDF_VCB_FLAGS_BEING_DISMOUNTED)) {
666  if (Vcb->VCBOpenCount <= UDF_RESIDUAL_REFERENCE) {
667  VcbPresent = UDFDismountVcb(Vcb, VcbAcquired);
668  }
669  VcbAcquired = VcbAcquired && VcbPresent;
670 
671  // If the teardown is underway and there are absolutely no references
672  // remaining then delete the Vcb. References here include the
673  // references in the Vcb and Vpb.
674  } else if (!(Vcb->VCBOpenCount)) {
675 
676  IoAcquireVpbSpinLock( &SavedIrql );
677  // If there are no file objects and no reference counts in the
678  // Vpb we can delete the Vcb. Don't forget that we have the
679  // last reference in the Vpb.
680  if (Vcb->Vpb->ReferenceCount <= ResidualReferenceCount) {
681 
682  IoReleaseVpbSpinLock( SavedIrql );
683  if(VcbAcquired)
684  UDFReleaseResource(&(Vcb->VCBResource));
687  VcbAcquired =
688  VcbPresent = FALSE;
689 
690  } else {
691 
692  IoReleaseVpbSpinLock( SavedIrql );
693  }
694  }
695 
696  // Release any resources still acquired.
697  if (!_VcbAcquired && VcbAcquired) {
698  UDFReleaseResource(&(Vcb->VCBResource));
699  }
700 
701  return VcbPresent;
702 } // end UDFCheckForDismount()
#define UDFAcquireResourceExclusive(Resource, CanWait)
Definition: env_spec_w32.h:656
#define UDFPrint(Args)
Definition: udffs.h:225
#define TRUE
Definition: types.h:120
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define UDFReleaseResource(Resource)
Definition: env_spec_w32.h:661
VOID NTAPI IoAcquireVpbSpinLock(OUT PKIRQL Irql)
Definition: volume.c:1209
VOID UDFReleaseVCB(PVCB Vcb)
Definition: misc.cpp:2137
BOOLEAN UDFDismountVcb(IN PVCB Vcb, IN BOOLEAN VcbAcquired)
Definition: verfysup.cpp:727
UCHAR KIRQL
Definition: env_spec_w32.h:591
VOID UDFStopEjectWaiter(PVCB Vcb)
Definition: phys_eject.cpp:673
unsigned char BOOLEAN
#define Vcb
Definition: cdprocs.h:1425
#define UDF_VCB_FLAGS_BEING_DISMOUNTED
Definition: udf_common.h:461
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI IoReleaseVpbSpinLock(IN KIRQL Irql)
Definition: volume.c:1220
#define UDF_RESIDUAL_REFERENCE
Definition: struct.h:336

Referenced by UDFCommonClose(), UDFPerformVerify(), UDFPnpQueryRemove(), UDFPnpRemove(), UDFPnpSurpriseRemove(), and UDFScanForDismountedVcb().

◆ UDFCleanup()

NTSTATUS NTAPI UDFCleanup ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 43 of file cleanup.cpp.

47 {
49  PtrUDFIrpContext PtrIrpContext = NULL;
50  BOOLEAN AreWeTopLevel = FALSE;
51 
52  TmPrint(("UDFCleanup\n"));
53 
56  ASSERT(Irp);
57 
58  // If we were called with our file system device object instead of a
59  // volume device object, just complete this request with STATUS_SUCCESS
60  if (UDFIsFSDevObj(DeviceObject)) {
61  // this is a cleanup of the FSD itself
62  Irp->IoStatus.Status = RC;
63  Irp->IoStatus.Information = 0;
64 
66  UDFPrint(("Deregister Autoformat\n"));
68  }
69 
72  return(RC);
73  }
74 
75  // set the top level context
76  AreWeTopLevel = UDFIsIrpTopLevel(Irp);
77 
78  _SEH2_TRY {
79 
80  // get an IRP context structure and issue the request
81  PtrIrpContext = UDFAllocateIrpContext(Irp, DeviceObject);
82  if(PtrIrpContext) {
83  RC = UDFCommonCleanup(PtrIrpContext, Irp);
84  } else {
86  Irp->IoStatus.Status = RC;
87  Irp->IoStatus.Information = 0;
88  // complete the IRP
90  }
91 
93 
94  RC = UDFExceptionHandler(PtrIrpContext, Irp);
95 
97  } _SEH2_END;
98 
99  if (AreWeTopLevel) {
101  }
102 
104 
105  return(RC);
106 } // end UDFCleanup()
PtrUDFIrpContext UDFAllocateIrpContext(PIRP Irp, PDEVICE_OBJECT PtrTargetDeviceObject)
Definition: misc.cpp:985
#define UDFPrint(Args)
Definition: udffs.h:225
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
VOID UDFLogEvent(NTSTATUS UDFEventLogId, NTSTATUS RC)
Definition: misc.cpp:575
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
_SEH2_TRY
Definition: create.c:4250
#define IO_DISK_INCREMENT
Definition: iotypes.h:567
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:11
unsigned char BOOLEAN
#define TmPrint(_x_)
Definition: env_spec_w32.h:290
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
NTSTATUS UDFExceptionHandler(PtrUDFIrpContext PtrIrpContext, PIRP Irp)
Definition: misc.cpp:358
PVOID AutoFormatCount
Definition: udf_common.h:629
NTSTATUS UDFCommonCleanup(PtrUDFIrpContext PtrIrpContext, PIRP Irp)
Definition: cleanup.cpp:126
BOOLEAN __fastcall UDFIsIrpTopLevel(PIRP Irp)
Definition: misc.cpp:228
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
UDFData UDFGlobalData
Definition: udfinit.cpp:25
long UDFExceptionFilter(PtrUDFIrpContext PtrIrpContext, PEXCEPTION_POINTERS PtrExceptionPointers)
Definition: misc.cpp:265
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define UDF_ERROR_INTERNAL_ERROR
Definition: errmsg.h:71
_SEH2_END
Definition: create.c:4424
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
return STATUS_SUCCESS
Definition: btrfs.c:2777

Referenced by UDFInitializeFunctionPointers().

◆ UDFCleanUpCCB()

VOID __fastcall UDFCleanUpCCB ( PtrUDFCCB  Ccb)

Definition at line 805 of file misc.cpp.

807 {
808 // ASSERT(Ccb);
809  if(!Ccb) return; // probably, we havn't allocated it...
810  ASSERT(Ccb->NodeIdentifier.NodeType == UDF_NODE_TYPE_CCB);
811 
812  _SEH2_TRY {
813  if(Ccb->Fcb) {
814  UDFTouch(&(Ccb->Fcb->CcbListResource));
815  UDFAcquireResourceExclusive(&(Ccb->Fcb->CcbListResource),TRUE);
816  RemoveEntryList(&(Ccb->NextCCB));
817  UDFReleaseResource(&(Ccb->Fcb->CcbListResource));
818  } else {
819  BrutePoint();
820  }
821 
822  if (Ccb->DirectorySearchPattern) {
823  if (Ccb->DirectorySearchPattern->Buffer) {
824  MyFreePool__(Ccb->DirectorySearchPattern->Buffer);
825  Ccb->DirectorySearchPattern->Buffer = NULL;
826  }
827 
828  MyFreePool__(Ccb->DirectorySearchPattern);
829  Ccb->DirectorySearchPattern = NULL;
830  }
831 
834  BrutePoint();
835  } _SEH2_END;
836 } // end UDFCleanUpCCB()
#define UDFAcquireResourceExclusive(Resource, CanWait)
Definition: env_spec_w32.h:656
#define TRUE
Definition: types.h:120
VOID __fastcall UDFReleaseCCB(PtrUDFCCB Ccb)
Definition: misc.cpp:768
#define UDFReleaseResource(Resource)
Definition: env_spec_w32.h:661
_SEH2_TRY
Definition: create.c:4250
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define UDFTouch(a)
Definition: env_spec_w32.h:303
#define UDF_NODE_TYPE_CCB
Definition: struct.h:59
#define MyFreePool__(addr)
Definition: mem_tools.h:152
#define BrutePoint()
Definition: env_spec_w32.h:504
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
struct _FCB::@691::@694 Fcb
_SEH2_END
Definition: create.c:4424
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6

Referenced by UDFCommonClose(), and UDFCommonCreate().

◆ UDFCleanUpFCB()

VOID __fastcall UDFCleanUpFCB ( PtrUDFFCB  Fcb)

Definition at line 908 of file misc.cpp.

911 {
912  UDFPrint(("UDFCleanUpFCB: %x\n", Fcb));
913  if(!Fcb) return;
914 
915  ASSERT(Fcb->NodeIdentifier.NodeType == UDF_NODE_TYPE_FCB);
916 
917  _SEH2_TRY {
918  // Deinitialize FCBName field
919  if (Fcb->FCBName) {
920  if(Fcb->FCBName->ObjectName.Buffer) {
921  MyFreePool__(Fcb->FCBName->ObjectName.Buffer);
922  Fcb->FCBName->ObjectName.Buffer = NULL;
923 #ifdef UDF_DBG
924  Fcb->FCBName->ObjectName.Length =
925  Fcb->FCBName->ObjectName.MaximumLength = 0;
926 #endif
927  }
928 #ifdef UDF_DBG
929  else {
930  UDFPrint(("UDF: Fcb has invalid FCBName Buffer\n"));
931  BrutePoint();
932  }
933 #endif
934  UDFReleaseObjectName(Fcb->FCBName);
935  Fcb->FCBName = NULL;
936  }
937 #ifdef UDF_DBG
938  else {
939  UDFPrint(("UDF: Fcb has invalid FCBName field\n"));
940  BrutePoint();
941  }
942 #endif
943 
944 
945  // begin transaction {
946  UDFTouch(&(Fcb->Vcb->FcbListResource));
947  UDFAcquireResourceExclusive(&(Fcb->Vcb->FcbListResource), TRUE);
948  // Remove this FCB from list of all FCB in VCB
949  RemoveEntryList(&(Fcb->NextFCB));
950  UDFReleaseResource(&(Fcb->Vcb->FcbListResource));
951  // } end transaction
952 
954  UDFDeleteResource(&(Fcb->CcbListResource));
955 
956  // Free memory
959  BrutePoint();
960  } _SEH2_END;
961 } // end UDFCleanUpFCB()
#define UDFAcquireResourceExclusive(Resource, CanWait)
Definition: env_spec_w32.h:656
VOID __fastcall UDFReleaseObjectName(PtrUDFObjectName PtrObjectName)
Definition: misc.cpp:670
#define UDFPrint(Args)
Definition: udffs.h:225
#define TRUE
Definition: types.h:120
#define UDF_NODE_TYPE_FCB
Definition: struct.h:60
#define UDFReleaseResource(Resource)
Definition: env_spec_w32.h:661
#define UDF_FCB_INITIALIZED_CCB_LIST_RESOURCE
Definition: struct.h:316
_SEH2_TRY
Definition: create.c:4250
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
__inline VOID UDFReleaseFCB(PtrUDFFCB Fcb)
Definition: protos.h:620
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
WCHAR * ObjectName
Definition: ntfs.h:520
#define UDFTouch(a)
Definition: env_spec_w32.h:303
#define UDFDeleteResource(Resource)
Definition: env_spec_w32.h:663
#define MyFreePool__(addr)
Definition: mem_tools.h:152
#define BrutePoint()
Definition: env_spec_w32.h:504
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_SEH2_END
Definition: create.c:4424
PVCB Vcb
Definition: cdstruc.h:939
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
_In_ PFCB Fcb
Definition: cdprocs.h:151

Referenced by UDFBlankMount(), UDFCleanUpFcbChain(), UDFCommonCreate(), and UDFCompleteMount().

◆ UDFCleanUpFcbChain()

ULONG UDFCleanUpFcbChain ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  fi,
IN ULONG  TreeLength,
IN BOOLEAN  VcbAcquired 
)

Definition at line 400 of file close.cpp.

406 {
407  PtrUDFFCB Fcb = NULL;
409  PUDF_FILE_INFO ParentFI;
411  ULONG CleanCode;
412  LONG RefCount, ComRefCount;
413  BOOLEAN Delete = FALSE;
414  ULONG ret_val = 0;
415 
416  ValidateFileInfo(fi);
417  AdPrint(("UDFCleanUpFcbChain\n"));
418 
419  ASSERT(TreeLength);
420 
421  // we can't process Tree until we can acquire Vcb
422  if(!VcbAcquired)
423  UDFAcquireResourceShared(&(Vcb->VCBResource),TRUE);
424 
425  // cleanup parent chain (if any & unused)
426  while(fi) {
427 
428  // acquire parent
429  if((ParentFI = fi->ParentFile)) {
430  ASSERT(fi->Fcb);
431  ParentFcb = fi->Fcb->ParentFcb;
432  ASSERT(ParentFcb);
433  ASSERT(ParentFcb->NTRequiredFCB);
434  UDF_CHECK_PAGING_IO_RESOURCE(ParentFcb->NTRequiredFCB);
436  } else {
437  // we get to RootDir, it has no parent
438  if(!VcbAcquired)
439  UDFAcquireResourceShared(&(Vcb->VCBResource),TRUE);
440  }
441  Fcb = fi->Fcb;
442  ASSERT(Fcb->NodeIdentifier.NodeType == UDF_NODE_TYPE_FCB);
443 
444  NtReqFcb = Fcb->NTRequiredFCB;
445  ASSERT(NtReqFcb->CommonFCBHeader.NodeTypeCode == UDF_NODE_TYPE_NT_REQ_FCB);
446 
447  // acquire current file/dir
448  // we must assure that no more threads try to re-use this object
449 #ifdef UDF_DBG
450  _SEH2_TRY {
451 #endif // UDF_DBG
453  UDFAcquireResourceExclusive(&(NtReqFcb->MainResource),TRUE);
454 #ifdef UDF_DBG
456  BrutePoint();
457  if(ParentFI) {
458  UDF_CHECK_PAGING_IO_RESOURCE(ParentFcb->NTRequiredFCB);
459  UDFReleaseResource(&(ParentFcb->NTRequiredFCB->MainResource));
460  } else {
461  if(!VcbAcquired)
462  UDFReleaseResource(&(Vcb->VCBResource));
463  }
464  break;
465  } _SEH2_END;
466 #endif // UDF_DBG
467  ASSERT_REF((Fcb->ReferenceCount > fi->RefCount) || !TreeLength);
468  // If we haven't pass through all files opened
469  // in UDFCommonCreate before target file (TreeLength specfies
470  // the number of such files) dereference them.
471  // Otherwise we'll just check if the file has no references.
472 #ifdef UDF_DBG
473  if(Fcb) {
474  if(TreeLength) {
475  ASSERT(Fcb->ReferenceCount);
476  ASSERT(NtReqFcb->CommonRefCount);
477  RefCount = UDFInterlockedDecrement((PLONG)&(Fcb->ReferenceCount));
478  ComRefCount = UDFInterlockedDecrement((PLONG)&(NtReqFcb->CommonRefCount));
479  }
480  } else {
481  BrutePoint();
482  }
483  if(TreeLength)
484  TreeLength--;
485  ASSERT(Fcb->OpenHandleCount <= Fcb->ReferenceCount);
486 #else
487  if(TreeLength) {
488  RefCount = UDFInterlockedDecrement((PLONG)&(Fcb->ReferenceCount));
489  ComRefCount = UDFInterlockedDecrement((PLONG)&(NtReqFcb->CommonRefCount));
490  TreeLength--;
491  }
492 #endif
493 
494 /* if(Fcb && Fcb->FCBName && Fcb->FCBName->ObjectName.Buffer) {
495  AdPrint((" %ws (%x)\n",
496  Fcb->FCBName->ObjectName.Buffer,Fcb->ReferenceCount));
497  } else if (Fcb) {
498  AdPrint((" ??? (%x)\n",Fcb->ReferenceCount));
499  } else {
500  AdPrint((" ??? (??)\n"));
501  }*/
502  // ...and delete if it has gone
503 
504  if(!RefCount && !Fcb->OpenHandleCount) {
505  // no more references... current file/dir MUST DIE!!!
506  BOOLEAN AutoInherited = UDFIsAStreamDir(fi) || UDFIsAStream(fi);
507 
508  if(Vcb->VCBFlags & UDF_VCB_FLAGS_RAW_DISK) {
509  // do nothing
510  } else
511 #ifndef UDF_READ_ONLY_BUILD
512  if(Delete) {
513 /* if(!(Fcb->FCBFlags & UDF_FCB_DIRECTORY)) {
514  // set file size to zero (for UdfInfo package)
515  // we should not do this for directories
516  UDFResizeFile__(Vcb, fi, 0);
517  }*/
518  UDFReferenceFile__(fi);
519  ASSERT(Fcb->ReferenceCount < fi->RefCount);
520  UDFFlushFile__(Vcb, fi);
521  UDFUnlinkFile__(Vcb, fi, TRUE);
522  UDFCloseFile__(Vcb, fi);
523  ASSERT(Fcb->ReferenceCount == fi->RefCount);
524  Fcb->FCBFlags |= UDF_FCB_DELETED;
525  Delete = FALSE;
526  } else
527 #endif //UDF_READ_ONLY_BUILD
528  if(!(Fcb->FCBFlags & UDF_FCB_DELETED)) {
529  UDFFlushFile__(Vcb, fi);
530  } else {
531 // BrutePoint();
532  }
533 #ifndef UDF_READ_ONLY_BUILD
534  // check if we should try to delete Parent for the next time
535  if(Fcb->FCBFlags & UDF_FCB_DELETE_PARENT)
536  Delete = TRUE;
537 #endif //UDF_READ_ONLY_BUILD
538 
539  // remove references to OS-specific structures
540  // to let UDF_INFO release FI & Co
541  fi->Fcb = NULL;
542  if(!ComRefCount) {
543  // CommonFcb is also completly dereferenced
544  // Kill it!
545  fi->Dloc->CommonFcb = NULL;
546  }
547 
548  if((CleanCode = UDFCleanUpFile__(Vcb, fi))) {
549  // Check, if we can uninitialize & deallocate CommonFcb part
550  // kill some cross links
551  Fcb->FileInfo = NULL;
552  // release allocated resources
553  if(CleanCode & UDF_FREE_DLOC) {
554  // Obviously, it is a good time & place to release
555  // CommonFcb structure
556 
557 // NtReqFcb->NtReqFCBFlags &= ~UDF_NTREQ_FCB_VALID;
558  // Unitialize byte-range locks support structure
559  FsRtlUninitializeFileLock(&(NtReqFcb->FileLock));
560  // Remove resources
562  UDFReleaseResource(&(NtReqFcb->MainResource));
563  if(NtReqFcb->CommonFCBHeader.Resource) {
564  UDFDeleteResource(&(NtReqFcb->MainResource));
565  UDFDeleteResource(&(NtReqFcb->PagingIoResource));
566  }
567  NtReqFcb->CommonFCBHeader.Resource =
568  NtReqFcb->CommonFCBHeader.PagingIoResource = NULL;
569  UDFDeassignAcl(NtReqFcb, AutoInherited);
570  UDFPrint(("UDFReleaseNtReqFCB: %x\n", NtReqFcb));
571 #ifdef DBG
572 // NtReqFcb->FileObject->FsContext2 = NULL;
573 // ASSERT(NtReqFcb->FileObject);
574 /* if(NtReqFcb->FileObject) {
575  ASSERT(!NtReqFcb->FileObject->FsContext2);
576  NtReqFcb->FileObject->FsContext = NULL;
577  NtReqFcb->FileObject->SectionObjectPointer = NULL;
578  }*/
579 #endif //DBG
581  ret_val |= UDF_CLOSE_NTREQFCB_DELETED;
582  } else {
583  // we usually get here when the file has some opened links
585  UDFReleaseResource(&(NtReqFcb->MainResource));
586  }
587  // remove some references & free Fcb structure
588  Fcb->NTRequiredFCB = NULL;
589  Fcb->ParentFcb = NULL;
591  MyFreePool__(fi);
592  ret_val |= UDF_CLOSE_FCB_DELETED;
593  // get pointer to parent FCB
594  fi = ParentFI;
595  // free old parent's resource...
596  if(fi) {
597  UDF_CHECK_PAGING_IO_RESOURCE(ParentFcb->NTRequiredFCB);
598  UDFReleaseResource(&(ParentFcb->NTRequiredFCB->MainResource));
599  } else {
600  if(!VcbAcquired)
601  UDFReleaseResource(&(Vcb->VCBResource));
602  }
603  } else {
604  // Stop cleaning up
605 
606  // Restore pointers
607  fi->Fcb = Fcb;
608  fi->Dloc->CommonFcb = NtReqFcb;
609  // free all acquired resources
611  UDFReleaseResource(&(NtReqFcb->MainResource));
612  fi = ParentFI;
613  if(fi) {
614  UDF_CHECK_PAGING_IO_RESOURCE(ParentFcb->NTRequiredFCB);
615  UDFReleaseResource(&(ParentFcb->NTRequiredFCB->MainResource));
616  } else {
617  if(!VcbAcquired)
618  UDFReleaseResource(&(Vcb->VCBResource));
619  }
620  // If we have dereferenced all parents 'associated'
621  // with input file & current file is still in use
622  // then it isn't worth walking down the tree
623  // 'cause in this case all the rest files are also used
624  if(!TreeLength)
625  break;
626 // AdPrint(("Stop on referenced File/Dir\n"));
627  }
628  } else {
629  // we get to referenced file/dir. Stop search & release resource
631  UDFReleaseResource(&(NtReqFcb->MainResource));
632  if(ParentFI) {
633  UDF_CHECK_PAGING_IO_RESOURCE(ParentFcb->NTRequiredFCB);
634  UDFReleaseResource(&(ParentFcb->NTRequiredFCB->MainResource));
635  } else {
636  if(!VcbAcquired)
637  UDFReleaseResource(&(Vcb->VCBResource));
638  }
639  Delete = FALSE;
640  if(!TreeLength)
641  break;
642  fi = ParentFI;
643  }
644  }
645  if(fi) {
646  Fcb = fi->Fcb;
647  for(;TreeLength && fi;TreeLength--) {
648  if(Fcb) {
650  ASSERT(Fcb->ReferenceCount);
651  ASSERT(Fcb->NTRequiredFCB->CommonRefCount);
652  ASSERT_REF(Fcb->ReferenceCount > fi->RefCount);
653  UDFInterlockedDecrement((PLONG)&(Fcb->ReferenceCount));
654  UDFInterlockedDecrement((PLONG)&(Fcb->NTRequiredFCB->CommonRefCount));
655 #ifdef UDF_DBG
656  } else {
657  BrutePoint();
658 #endif
659  }
660  Fcb = ParentFcb;
661  }
662  }
663  if(!VcbAcquired)
664  UDFReleaseResource(&(Vcb->VCBResource));
665  return ret_val;
666 
667 } // end UDFCleanUpFcbChain()
#define UDFAcquireResourceExclusive(Resource, CanWait)
Definition: env_spec_w32.h:656
#define UDF_CLOSE_NTREQFCB_DELETED
Definition: protos.h:80
#define UDFReferenceFile__(fi)
Definition: udf_info.h:1043
#define UDF_CLOSE_FCB_DELETED
Definition: protos.h:81
#define ASSERT_REF(_a_)
Definition: udf_dbg.h:267
#define UDFPrint(Args)
Definition: udffs.h:225
#define TRUE
Definition: types.h:120
#define AdPrint(_x_)
Definition: env_spec_w32.h:292
#define UDF_FCB_DELETE_PARENT
Definition: struct.h:319
VOID NTAPI FsRtlUninitializeFileLock(IN PFILE_LOCK FileLock)
Definition: filelock.c:1278
#define UDF_NODE_TYPE_FCB
Definition: struct.h:60
#define UDFReleaseResource(Resource)
Definition: env_spec_w32.h:661
#define UDF_NODE_TYPE_NT_REQ_FCB
Definition: struct.h:57
_SEH2_TRY
Definition: create.c:4250
#define UDF_VCB_FLAGS_RAW_DISK
Definition: udf_common.h:476
long LONG
Definition: pedump.c:60
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
#define UDFInterlockedDecrement(addr)
Definition: env_spec_w32.h:677
LONG RefCount
Definition: ntfs.h:531
smooth NULL
Definition: ftsmooth.c:416
OSSTATUS UDFFlushFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN ULONG FlushFlags)
Definition: udf_info.cpp:4119
#define UDFIsAStreamDir(FI)
Definition: udf_info.h:998
uint32 UDFCleanUpFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:2276
ULONG OpenHandleCount
Definition: ntfs.h:533
#define Vcb
Definition: cdprocs.h:1425
#define UDFDeleteResource(Resource)
Definition: env_spec_w32.h:663
#define MyFreePool__(addr)
Definition: mem_tools.h:152
#define BrutePoint()
Definition: env_spec_w32.h:504
_In_ PFCB ParentFcb
Definition: cdprocs.h:741
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define NtReqFcb
#define ValidateFileInfo(fi)
Definition: env_spec_w32.h:516
#define UDF_FCB_DELETED
Definition: struct.h:314
#define UDFAcquireResourceShared(Resource, CanWait)
Definition: env_spec_w32.h:658
ERESOURCE MainResource
Definition: ntfs.h:524
OSSTATUS UDFCloseFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:2994
#define UDF_FREE_DLOC
Definition: udf_info.h:650
struct _FCB::@691::@694 Fcb
_SEH2_END
Definition: create.c:4424
#define UDF_CHECK_PAGING_IO_RESOURCE(NTReqFCB)
Definition: udffs.h:262
OSSTATUS UDFUnlinkFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN BOOLEAN FreeSpace)
Definition: udf_info.cpp:1766
VOID __fastcall UDFCleanUpFCB(PtrUDFFCB Fcb)
Definition: misc.cpp:908
unsigned int ULONG
Definition: retypes.h:1
struct _FCB * ParentFcb
Definition: cdstruc.h:946
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
_In_ PFCB Fcb
Definition: cdprocs.h:151
#define UDFIsAStream(FI)
Definition: udf_info.h:1002
signed int * PLONG
Definition: retypes.h:5
BOOL Delete(LPCTSTR ServiceName)
Definition: delete.c:12
VOID UDFDeassignAcl(IN PtrUDFNTRequiredFCB NtReqFcb, IN BOOLEAN AutoInherited)
Definition: secursup.cpp:772

Referenced by UDFCloseResidual(), UDFCommonClose(), UDFCommonCreate(), and UDFRename().

◆ UDFCleanupVCB()

VOID UDFCleanupVCB ( IN PVCB  Vcb)

Definition at line 1428 of file fscntrl.cpp.

1431 {
1432  _SEH2_TRY {
1436  BrutePoint();
1437  } _SEH2_END;
1438 
1439  if(Vcb->ShutdownRegistered && Vcb->VCBDeviceObject) {
1440  IoUnregisterShutdownNotification(Vcb->VCBDeviceObject);
1441  Vcb->ShutdownRegistered = FALSE;
1442  }
1443 
1444  MyFreeMemoryAndPointer(Vcb->Partitions);
1445  MyFreeMemoryAndPointer(Vcb->LVid);
1447  MyFreeMemoryAndPointer(Vcb->SparingTable);
1448 
1449  if(Vcb->FSBM_Bitmap) {
1450  DbgFreePool(Vcb->FSBM_Bitmap);
1451  Vcb->FSBM_Bitmap = NULL;
1452  }
1453  if(Vcb->ZSBM_Bitmap) {
1454  DbgFreePool(Vcb->ZSBM_Bitmap);
1455  Vcb->ZSBM_Bitmap = NULL;
1456  }
1457  if(Vcb->BSBM_Bitmap) {
1458  DbgFreePool(Vcb->BSBM_Bitmap);
1459  Vcb->BSBM_Bitmap = NULL;
1460  }
1461 #ifdef UDF_TRACK_ONDISK_ALLOCATION_OWNERS
1462  if(Vcb->FSBM_Bitmap_owners) {
1463  DbgFreePool(Vcb->FSBM_Bitmap_owners);
1464  Vcb->FSBM_Bitmap_owners = NULL;
1465  }
1466 #endif //UDF_TRACK_ONDISK_ALLOCATION_OWNERS
1467  if(Vcb->FSBM_OldBitmap) {
1468  DbgFreePool(Vcb->FSBM_OldBitmap);
1469  Vcb->FSBM_OldBitmap = NULL;
1470  }
1471 
1472  MyFreeMemoryAndPointer(Vcb->Statistics);
1473  MyFreeMemoryAndPointer(Vcb->NTRequiredFCB);
1474  MyFreeMemoryAndPointer(Vcb->VolIdent.Buffer);
1475  MyFreeMemoryAndPointer(Vcb->TargetDevName.Buffer);
1476 
1477  if(Vcb->ZBuffer) {
1478  DbgFreePool(Vcb->ZBuffer);
1479  Vcb->ZBuffer = NULL;
1480  }
1481 
1482  if(Vcb->fZBuffer) {
1483  DbgFreePool(Vcb->fZBuffer);
1484  Vcb->fZBuffer = NULL;
1485  }
1486 
1487  MyFreeMemoryAndPointer(Vcb->OPCh);
1488  MyFreeMemoryAndPointer(Vcb->WParams);
1489  MyFreeMemoryAndPointer(Vcb->Error);
1490  MyFreeMemoryAndPointer(Vcb->TrackMap);
1491 
1492 } // end UDFCleanupVCB()
void UDFReleaseDlocList(IN PVCB Vcb)
Definition: dirtree.cpp:1396
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define DbgFreePool
Definition: env_spec_w32.h:334
#define MyFreeMemoryAndPointer(ptr)
Definition: mem_tools.h:13
VOID UDFReleaseFileIdCache(IN PVCB Vcb)
Definition: fileinfo.cpp:2456
#define Vcb
Definition: cdprocs.h:1425
#define BrutePoint()
Definition: env_spec_w32.h:504
VOID NTAPI IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1725
_SEH2_END
Definition: create.c:4424
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6

Referenced by UDFReleaseVCB(), and UDFVerifyVolume().

◆ UDFClose()

NTSTATUS NTAPI UDFClose ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 62 of file close.cpp.

66 {
68  PtrUDFIrpContext PtrIrpContext = NULL;
69  BOOLEAN AreWeTopLevel = FALSE;
70 
71  AdPrint(("UDFClose: \n"));
72 
75  ASSERT(Irp);
76 
77  // If we were called with our file system device object instead of a
78  // volume device object, just complete this request with STATUS_SUCCESS
79  if (UDFIsFSDevObj(DeviceObject)) {
80  // this is a close of the FSD itself
81  Irp->IoStatus.Status = RC;
82  Irp->IoStatus.Information = 0;
83 
86  return(RC);
87  }
88 
89  // set the top level context
90  AreWeTopLevel = UDFIsIrpTopLevel(Irp);
91 
92  _SEH2_TRY {
93 
94  // get an IRP context structure and issue the request
95  PtrIrpContext = UDFAllocateIrpContext(Irp, DeviceObject);
96  ASSERT(PtrIrpContext);
97 
98  RC = UDFCommonClose(PtrIrpContext, Irp);
99 
101 
102  RC = UDFExceptionHandler(PtrIrpContext, Irp);
103 
105  } _SEH2_END;
106 
107  if (AreWeTopLevel) {
109  }
110 
112 
113  return(RC);
114 }
PtrUDFIrpContext UDFAllocateIrpContext(PIRP Irp, PDEVICE_OBJECT PtrTargetDeviceObject)
Definition: misc.cpp:985
#define FsRtlEnterFileSystem
#define AdPrint(_x_)
Definition: env_spec_w32.h:292
#define FsRtlExitFileSystem
VOID UDFLogEvent(NTSTATUS UDFEventLogId, NTSTATUS RC)
Definition: misc.cpp:575
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
_SEH2_TRY
Definition: create.c:4250
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:11
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
NTSTATUS UDFExceptionHandler(PtrUDFIrpContext PtrIrpContext, PIRP Irp)
Definition: misc.cpp:358
NTSTATUS UDFCommonClose(PtrUDFIrpContext PtrIrpContext, PIRP Irp)
Definition: close.cpp:137
BOOLEAN __fastcall UDFIsIrpTopLevel(PIRP Irp)
Definition: misc.cpp:228
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
long UDFExceptionFilter(PtrUDFIrpContext PtrIrpContext, PEXCEPTION_POINTERS PtrExceptionPointers)
Definition: misc.cpp:265
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define UDF_ERROR_INTERNAL_ERROR
Definition: errmsg.h:71
_SEH2_END
Definition: create.c:4424
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
return STATUS_SUCCESS
Definition: btrfs.c:2777

Referenced by UDFInitializeFunctionPointers().

◆ UDFCloseAllDelayed()

VOID UDFCloseAllDelayed ( PVCB  Vcb)

◆ UDFCloseAllXXXDelayedInDir()

NTSTATUS UDFCloseAllXXXDelayedInDir ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo,
IN BOOLEAN  System 
)

Definition at line 918 of file close.cpp.

923 {
924  PUDF_FILE_INFO* PassedList = NULL;
925  ULONG PassedListSize = 0;
926  PUDF_FILE_INFO* FoundList = NULL;
927  ULONG FoundListSize = 0;
928  NTSTATUS RC;
929  ULONG i;
930  BOOLEAN ResAcq = FALSE;
931  BOOLEAN AcquiredVcb = FALSE;
933  PUDF_FILE_INFO CurFileInfo;
934  PFE_LIST_ENTRY CurListPtr;
935  PFE_LIST_ENTRY* ListPtrArray = NULL;
936 
937  _SEH2_TRY {
938 
939  UDFPrint((" UDFCloseAllXXXDelayedInDir(): Acquire DelayedCloseResource\n"));
940  // Acquire DelayedCloseResource
941  UDFAcquireResourceExclusive(&(UDFGlobalData.DelayedCloseResource), TRUE);
942  ResAcq = TRUE;
943 
944  UDFAcquireResourceExclusive(&(Vcb->VCBResource), TRUE);
945  AcquiredVcb = TRUE;
946 
949  &PassedList, &PassedListSize, &FoundList, &FoundListSize);
950 
951  if(!NT_SUCCESS(RC)) {
952  UDFPrint((" UDFBuildTreeItemsList(): error %x\n", RC));
953  try_return(RC);
954  }
955 
956  if(!FoundList || !FoundListSize) {
958  }
959 
960  // build array of referenced pointers
961  ListPtrArray = (PFE_LIST_ENTRY*)(MyAllocatePool__(NonPagedPool, FoundListSize*sizeof(PFE_LIST_ENTRY)));
962  if(!ListPtrArray) {
963  UDFPrint((" Can't alloc ListPtrArray for %x items\n", FoundListSize));
965  }
966 
967  for(i=0;i<FoundListSize;i++) {
968 
969  _SEH2_TRY {
970 
971  CurFileInfo = FoundList[i];
972  if(!CurFileInfo->ListPtr) {
974  if(!CurFileInfo->ListPtr) {
975  UDFPrint((" Can't alloc ListPtrEntry for items %x\n", i));
977  }
978  CurFileInfo->ListPtr->FileInfo = CurFileInfo;
979  CurFileInfo->ListPtr->EntryRefCount = 0;
980  }
981  CurFileInfo->ListPtr->EntryRefCount++;
982  ListPtrArray[i] = CurFileInfo->ListPtr;
983 
985  BrutePoint();
986  } _SEH2_END;
987  }
988 
989  UDFReleaseResource(&(Vcb->VCBResource));
990  AcquiredVcb = FALSE;
991 
992  if(System) {
993  // Remove from system queue
994  PtrUDFFCB Fcb;
996  BOOLEAN NoDelayed = (Vcb->VCBFlags & UDF_VCB_FLAGS_NO_DELAYED_CLOSE) ?
997  TRUE : FALSE;
998 
999  Vcb->VCBFlags |= UDF_VCB_FLAGS_NO_DELAYED_CLOSE;
1000  for(i=FoundListSize;i>0;i--) {
1001  UDFAcquireResourceExclusive(&(Vcb->VCBResource), TRUE);
1002  AcquiredVcb = TRUE;
1003  _SEH2_TRY {
1004 
1005  CurListPtr = ListPtrArray[i-1];
1006  CurFileInfo = CurListPtr->FileInfo;
1007  if(CurFileInfo &&
1008  (Fcb = CurFileInfo->Fcb)) {
1009  NtReqFcb = Fcb->NTRequiredFCB;
1010  ASSERT((ULONG_PTR)NtReqFcb > 0x1000);
1011 // ASSERT((ULONG)(NtReqFcb->SectionObject) > 0x1000);
1012  if(!(NtReqFcb->NtReqFCBFlags & UDF_NTREQ_FCB_DELETED) &&
1013  (NtReqFcb->NtReqFCBFlags & UDF_NTREQ_FCB_MODIFIED)) {
1014  MmPrint((" CcFlushCache()\n"));
1015  CcFlushCache(&(NtReqFcb->SectionObject), NULL, 0, &IoStatus);
1016  }
1017  if(NtReqFcb->SectionObject.ImageSectionObject) {
1018  MmPrint((" MmFlushImageSection()\n"));
1019  MmFlushImageSection(&(NtReqFcb->SectionObject), MmFlushForWrite);
1020  }
1021  if(NtReqFcb->SectionObject.DataSectionObject) {
1022  MmPrint((" CcPurgeCacheSection()\n"));
1023  CcPurgeCacheSection( &(NtReqFcb->SectionObject), NULL, 0, FALSE );
1024  }
1025  } else {
1026  MmPrint((" Skip item: deleted\n"));
1027  }
1028  CurListPtr->EntryRefCount--;
1029  if(!CurListPtr->EntryRefCount) {
1030  if(CurListPtr->FileInfo)
1031  CurListPtr->FileInfo->ListPtr = NULL;
1032  MyFreePool__(CurListPtr);
1033  }
1035  BrutePoint();
1036  } _SEH2_END;
1037  UDFReleaseResource(&(Vcb->VCBResource));
1038  AcquiredVcb = FALSE;
1039  }
1040  if(!NoDelayed)
1041  Vcb->VCBFlags &= ~UDF_VCB_FLAGS_NO_DELAYED_CLOSE;
1042  } else {
1043  // Remove from internal queue
1044  PtrUDFIrpContextLite NextIrpContextLite;
1045 
1046  for(i=FoundListSize;i>0;i--) {
1047 
1048  UDFAcquireResourceExclusive(&(Vcb->VCBResource), TRUE);
1049  AcquiredVcb = TRUE;
1050 
1051  CurListPtr = ListPtrArray[i-1];
1052  CurFileInfo = CurListPtr->FileInfo;
1053 
1054  if(CurFileInfo &&
1055  CurFileInfo->Fcb &&
1056  (NextIrpContextLite = CurFileInfo->Fcb->IrpContextLite)) {
1057  RemoveEntryList( &(NextIrpContextLite->DelayedCloseLinks) );
1058  if (NextIrpContextLite->Fcb->FCBFlags & UDF_FCB_DIRECTORY) {
1059 // BrutePoint();
1060  UDFGlobalData.DirDelayedCloseCount--;
1061  } else {
1062  UDFGlobalData.DelayedCloseCount--;
1063  }
1064  UDFDoDelayedClose(NextIrpContextLite);
1065  }
1066  CurListPtr->EntryRefCount--;
1067  if(!CurListPtr->EntryRefCount) {
1068  if(CurListPtr->FileInfo)
1069  CurListPtr->FileInfo->ListPtr = NULL;
1070  MyFreePool__(CurListPtr);
1071  }
1072  UDFReleaseResource(&(Vcb->VCBResource));
1073  AcquiredVcb = FALSE;
1074  }
1075  }
1076  RC = STATUS_SUCCESS;
1077 
1078 try_exit: NOTHING;
1079 
1080  } _SEH2_FINALLY {
1081  // release Vcb
1082  if(AcquiredVcb)
1083  UDFReleaseResource(&(Vcb->VCBResource));
1084  // Release DelayedCloseResource
1085  if(ResAcq)
1086  UDFReleaseResource(&(UDFGlobalData.DelayedCloseResource));
1087 
1088  if(ListPtrArray)
1089  MyFreePool__(ListPtrArray);
1090  if(PassedList)
1091  MyFreePool__(PassedList);
1092  if(FoundList)
1093  MyFreePool__(FoundList);
1094  } _SEH2_END;
1095 
1096  return RC;
1097 } // end UDFCloseAllXXXDelayedInDir(
#define UDFAcquireResourceExclusive(Resource, CanWait)
Definition: env_spec_w32.h:656
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:384
#define UDFPrint(Args)
Definition: udffs.h:225
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ULONG EntryRefCount
Definition: udf_rel.h:416
NTSTATUS UDFBuildTreeItemsList(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN PCHECK_TREE_ITEM CheckItemProc, IN PUDF_DATALOC_INFO **PassedList, IN PULONG PassedListSize, IN PUDF_DATALOC_INFO **FoundList, IN PULONG FoundListSize)
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
Definition: udf_rel.h:414
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
#define UDFReleaseResource(Resource)
Definition: env_spec_w32.h:661
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN UDFIsInDelayedCloseQueue(PUDF_FILE_INFO FileInfo)
Definition: close.cpp:895
struct _FE_LIST_ENTRY * PFE_LIST_ENTRY
_SEH2_TRY
Definition: create.c:4250
uint32_t ULONG_PTR
Definition: typedefs.h:63
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define MyAllocatePool__(type, size)
Definition: mem_tools.h:149
VOID UDFDoDelayedClose(IN PtrUDFIrpContextLite NextIrpContextLite)
Definition: close.cpp:670
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOLEAN NTAPI MmFlushImageSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN MMFLUSH_TYPE FlushType)
Definition: section.c:4795
#define try_return(S)
Definition: cdprocs.h:2189
struct _FE_LIST_ENTRY * ListPtr
Definition: udf_rel.h:411
#define Vcb
Definition: cdprocs.h:1425
#define MyFreePool__(addr)
Definition: mem_tools.h:152
#define UDF_FCB_DIRECTORY
Definition: struct.h:303
#define BrutePoint()
Definition: env_spec_w32.h:504
#define MmPrint(_x_)
Definition: env_spec_w32.h:289
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define NtReqFcb
#define UDF_NTREQ_FCB_DELETED
Definition: struct.h:235
#define UDF_VCB_FLAGS_NO_DELAYED_CLOSE
Definition: udf_common.h:480
UDFData UDFGlobalData
Definition: udfinit.cpp:25
#define NOTHING
Definition: env_spec_w32.h:461
LIST_ENTRY DelayedCloseLinks
Definition: struct.h:410
_SEH2_END
Definition: create.c:4424
_SEH2_FINALLY
Definition: create.c:4395
BOOLEAN UDFIsLastClose(PUDF_FILE_INFO FileInfo)
Definition: close.cpp:903
_UDFFileControlBlock * Fcb
Definition: struct.h:408
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
struct _UDFFileControlBlock * Fcb
Definition: udf_rel.h:362
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2777
PUDF_FILE_INFO FileInfo
Definition: udf_rel.h:415
#define UDF_NTREQ_FCB_MODIFIED
Definition: struct.h:236

◆ UDFCloseFileInfoChain()

NTSTATUS UDFCloseFileInfoChain ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  fi,
IN ULONG  TreeLength,
IN BOOLEAN  VcbAcquired 
)

Definition at line 696 of file cleanup.cpp.

702 {
703  PUDF_FILE_INFO ParentFI;
704  PtrUDFFCB Fcb;
707  NTSTATUS RC2;
708 
709  // we can't process Tree until we can acquire Vcb
710  if(!VcbAcquired)
711  UDFAcquireResourceShared(&(Vcb->VCBResource),TRUE);
712 
713  AdPrint(("UDFCloseFileInfoChain\n"));
714  for(; TreeLength && fi; TreeLength--) {
715 
716  // close parent chain (if any)
717  // if we started path parsing not from RootDir on Create,
718  // we would never get RootDir here
719  ValidateFileInfo(fi);
720 
721  // acquire parent
722  if((ParentFI = fi->ParentFile)) {
723  ParentFcb = fi->Fcb->ParentFcb;
724  ASSERT(ParentFcb);
725  ASSERT(ParentFcb->NTRequiredFCB);
726  UDF_CHECK_PAGING_IO_RESOURCE(ParentFcb->NTRequiredFCB);
728  ASSERT(ParentFcb->NodeIdentifier.NodeType == UDF_NODE_TYPE_FCB);
729  ASSERT(ParentFcb->NTRequiredFCB->CommonFCBHeader.NodeTypeCode == UDF_NODE_TYPE_NT_REQ_FCB);
730  } else {
731  AdPrint(("Acquiring VCB...\n"));
732  UDFAcquireResourceShared(&(Vcb->VCBResource),TRUE);
733  AdPrint(("Done\n"));
734  }
735  // acquire current file/dir
736  // we must assure that no more threads try to reuse this object
737  if((Fcb = fi->Fcb)) {
738  UDF_CHECK_PAGING_IO_RESOURCE(Fcb->NTRequiredFCB);
739  UDFAcquireResourceExclusive(&(Fcb->NTRequiredFCB->MainResource),TRUE);
740  ASSERT_REF(Fcb->ReferenceCount >= fi->RefCount);
741  if(!(Fcb->FCBFlags & UDF_FCB_DELETED) &&
742  (Fcb->FCBFlags & UDF_FCB_VALID))
743  UDFWriteSecurity(Vcb, Fcb, &(Fcb->NTRequiredFCB->SecurityDesc));
744  RC2 = UDFCloseFile__(Vcb,fi);
745  if(!NT_SUCCESS(RC2))
746  RC = RC2;
747  ASSERT_REF(Fcb->ReferenceCount > fi->RefCount);
748  UDF_CHECK_PAGING_IO_RESOURCE(Fcb->NTRequiredFCB);
749  UDFReleaseResource(&(Fcb->NTRequiredFCB->MainResource));
750  } else {
751  BrutePoint();
752  RC2 = UDFCloseFile__(Vcb,fi);
753  if(!NT_SUCCESS(RC2))
754  RC = RC2;
755  }
756 
757  if(ParentFI) {
758  UDF_CHECK_PAGING_IO_RESOURCE(ParentFcb->NTRequiredFCB);
759  UDFReleaseResource(&(ParentFcb->NTRequiredFCB->MainResource));
760  } else {
761  UDFReleaseResource(&(Vcb->VCBResource));
762  }
763  fi = ParentFI;
764  }
765 
766  if(!VcbAcquired)
767  UDFReleaseResource(&(Vcb->VCBResource));
768 
769  return RC;
770 
771 } // end UDFCloseFileInfoChain()
#define UDFAcquireResourceExclusive(Resource, CanWait)
Definition: env_spec_w32.h:656
#define ASSERT_REF(_a_)
Definition: udf_dbg.h:267
#define TRUE
Definition: types.h:120
#define AdPrint(_x_)
Definition: env_spec_w32.h:292
#define UDF_NODE_TYPE_FCB
Definition: struct.h:60
#define UDFReleaseResource(Resource)
Definition: env_spec_w32.h:661
NTSTATUS UDFWriteSecurity(IN PVCB Vcb, IN PtrUDFFCB Fcb, IN PSECURITY_DESCRIPTOR *SecurityDesc)
Definition: secursup.cpp:796
LONG NTSTATUS
Definition: precomp.h:26
#define UDF_FCB_VALID
Definition: struct.h:300
#define UDF_NODE_TYPE_NT_REQ_FCB
Definition: struct.h:57
LONG RefCount
Definition: ntfs.h:531
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define Vcb
Definition: cdprocs.h:1425
#define BrutePoint()
Definition: env_spec_w32.h:504
_In_ PFCB ParentFcb
Definition: cdprocs.h:741
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ValidateFileInfo(fi)
Definition: env_spec_w32.h:516
#define UDF_FCB_DELETED
Definition: struct.h:314
#define UDFAcquireResourceShared(Resource, CanWait)
Definition: env_spec_w32.h:658
ERESOURCE MainResource
Definition: ntfs.h:524
OSSTATUS UDFCloseFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:2994
struct _FCB::@691::@694 Fcb
#define UDF_CHECK_PAGING_IO_RESOURCE(NTReqFCB)
Definition: udffs.h:262
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2777

Referenced by UDFCommonCleanup(), and UDFCommonCreate().

◆ UDFCloseResidual()

VOID UDFCloseResidual ( IN PVCB  Vcb)

Definition at line 1349 of file fscntrl.cpp.

1352 {
1353  // Deinitialize Non-alloc file
1354  if(Vcb->VCBOpenCount)
1355  UDFInterlockedDecrement((PLONG)&(Vcb->VCBOpenCount));
1356  UDFPrint(("UDFCloseResidual: NonAllocFileInfo %x\n", Vcb->NonAllocFileInfo));
1357  if(Vcb->NonAllocFileInfo) {
1358  UDFCloseFile__(Vcb,Vcb->NonAllocFileInfo);
1359  UDFCleanUpFile__(Vcb, Vcb->NonAllocFileInfo);
1360  MyFreePool__(Vcb->NonAllocFileInfo);
1361  Vcb->NonAllocFileInfo = NULL;
1362  }
1363  // Deinitialize Unique ID Mapping
1364  UDFPrint(("UDFCloseResidual: NonAllocFileInfo %x\n", Vcb->NonAllocFileInfo));
1365  if(Vcb->UniqueIDMapFileInfo) {
1366  UDFCloseFile__(Vcb,Vcb->UniqueIDMapFileInfo);
1367  UDFCleanUpFile__(Vcb, Vcb->UniqueIDMapFileInfo);
1368  MyFreePool__(Vcb->UniqueIDMapFileInfo);
1369  Vcb->UniqueIDMapFileInfo = NULL;
1370  }
1371  // Deinitialize VAT file
1372  UDFPrint(("UDFCloseResidual: VatFileInfo %x\n", Vcb->VatFileInfo));
1373  if(Vcb->VatFileInfo) {
1374  UDFCloseFile__(Vcb,Vcb->VatFileInfo);
1375  UDFCleanUpFile__(Vcb, Vcb->VatFileInfo);
1376  MyFreePool__(Vcb->VatFileInfo);
1377  Vcb->VatFileInfo = NULL;
1378  }
1379  // System StreamDir
1380  UDFPrint(("UDFCloseResidual: SysSDirFileInfo %x\n", Vcb->SysSDirFileInfo));
1381  if(Vcb->SysSDirFileInfo) {
1382  UDFCloseFile__(Vcb, Vcb->SysSDirFileInfo);
1383  UDFCleanUpFile__(Vcb, Vcb->SysSDirFileInfo);
1384  MyFreePool__(Vcb->SysSDirFileInfo);
1385  Vcb->SysSDirFileInfo = NULL;
1386  }
1387 /* // Deinitialize root dir fcb
1388  if(Vcb->RootDirFCB) {
1389  UDFCloseFile__(Vcb,Vcb->RootDirFCB->FileInfo);
1390  UDFCleanUpFile__(Vcb, Vcb->RootDirFCB->FileInfo);
1391  MyFreePool__(Vcb->RootDirFCB->FileInfo);
1392  UDFCleanUpFCB(Vcb->RootDirFCB);
1393  // Remove root FCB reference in vcb
1394  if(Vcb->VCBOpenCount) Vcb->VCBOpenCount--;
1395  }
1396 
1397  // Deinitialize Non-alloc file
1398  if(Vcb->VCBOpenCount) Vcb->VCBOpenCount--;
1399  if(Vcb->NonAllocFileInfo) {
1400  UDFCloseFile__(Vcb,Vcb->NonAllocFileInfo);
1401  // We must release VCB here !!!!
1402 // UDFCleanUpFcbChain(Vcb, Vcb->NonAllocFileInfo, 1);
1403  Vcb->NonAllocFileInfo = NULL;
1404  }
1405  // Deinitialize VAT file
1406  if(Vcb->VatFileInfo) {
1407  UDFCloseFile__(Vcb,Vcb->VatFileInfo);
1408  // We must release VCB here !!!!
1409 // UDFCleanUpFcbChain(Vcb, Vcb->VatFileInfo, 1);
1410  Vcb->VatFileInfo = NULL;
1411  }*/
1412 
1413  // Deinitialize root dir fcb
1414  UDFPrint(("UDFCloseResidual: RootDirFCB %x\n", Vcb->RootDirFCB));
1415  if(Vcb->RootDirFCB) {
1416  UDFCloseFile__(Vcb,Vcb->RootDirFCB->FileInfo);
1417  if(Vcb->RootDirFCB->OpenHandleCount)
1418  Vcb->RootDirFCB->OpenHandleCount--;
1419  UDFCleanUpFcbChain(Vcb, Vcb->RootDirFCB->FileInfo, 1, TRUE);
1420  // Remove root FCB reference in vcb
1421  if(Vcb->VCBOpenCount)
1422  UDFInterlockedDecrement((PLONG)&(Vcb->VCBOpenCount));
1423  Vcb->RootDirFCB = NULL;
1424  }
1425 } // end UDFCloseResidual()
#define UDFPrint(Args)
Definition: udffs.h:225
#define TRUE
Definition: types.h:120
ULONG UDFCleanUpFcbChain(IN PVCB Vcb, IN PUDF_FILE_INFO fi, IN ULONG TreeLength, IN BOOLEAN VcbAcquired)
Definition: close.cpp:400
#define UDFInterlockedDecrement(addr)
Definition: env_spec_w32.h:677
smooth NULL
Definition: ftsmooth.c:416
uint32 UDFCleanUpFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:2276
#define Vcb
Definition: cdprocs.h:1425
#define MyFreePool__(addr)
Definition: mem_tools.h:152
OSSTATUS UDFCloseFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:2994
signed int * PLONG
Definition: retypes.h:5

Referenced by UDFDismountVcb(), and UDFMountVolume().

◆ UDFCommonCleanup()

NTSTATUS UDFCommonCleanup ( PtrUDFIrpContext  PtrIrpContext,
PIRP  Irp 
)

Definition at line 126 of file cleanup.cpp.

129 {
132  NTSTATUS RC2;
135  PtrUDFFCB Fcb = NULL;
136  PtrUDFCCB Ccb = NULL;
137  PVCB Vcb = NULL;
139  ULONG lc = 0;
140  BOOLEAN AcquiredVcb = FALSE;
141  BOOLEAN AcquiredFCB = FALSE;
142  BOOLEAN AcquiredParentFCB = FALSE;
143 
144 // BOOLEAN CompleteIrp = TRUE;
145 // BOOLEAN PostRequest = FALSE;
146  BOOLEAN ChangeTime = FALSE;
147 #ifdef UDF_DBG
148  BOOLEAN CanWait = FALSE;
149 #endif // UDF_DBG
150  BOOLEAN ForcedCleanUp = FALSE;
151 
152  PUDF_FILE_INFO NextFileInfo = NULL;
153 #ifdef UDF_DBG
154  UNICODE_STRING CurName;
155  PDIR_INDEX_HDR DirNdx;
156 #endif // UDF_DBG
157 // PUDF_DATALOC_INFO Dloc;
158 
159  TmPrint(("UDFCommonCleanup\n"));
160 
161 // BrutePoint();
162 
163  _SEH2_TRY {
164  // First, get a pointer to the current I/O stack location
167 
169 
170  // Get the FCB and CCB pointers
171  Ccb = (PtrUDFCCB)(FileObject->FsContext2);
172  ASSERT(Ccb);
173  Fcb = Ccb->Fcb;
174  ASSERT(Fcb);
175 
176  Vcb = (PVCB)(PtrIrpContext->TargetDeviceObject->DeviceExtension);
177  ASSERT(Vcb);
178  ASSERT(Vcb->NodeIdentifier.NodeType == UDF_NODE_TYPE_VCB);
179 // Vcb->VCBFlags |= UDF_VCB_SKIP_EJECT_CHECK;
180 #ifdef UDF_DBG
181  CanWait = (PtrIrpContext->IrpContextFlags & UDF_IRP_CONTEXT_CAN_BLOCK) ? TRUE : FALSE;
182  AdPrint((" %s\n", CanWait ? "Wt" : "nw"));
183  ASSERT(CanWait);
184 #endif // UDF_DBG
185  UDFAcquireResourceShared(&(Vcb->VCBResource), TRUE);
186  AcquiredVcb = TRUE;
187  // Steps we shall take at this point are:
188  // (a) Acquire the file (FCB) exclusively
189  // (b) Flush file data to disk
190  // (c) Talk to the FSRTL package (if we use it) about pending oplocks.
191  // (d) Notify the FSRTL package for use with pending notification IRPs
192  // (e) Unlock byte-range locks (if any were acquired by process)
193  // (f) Update time stamp values (e.g. fast-IO had been performed)
194  // (g) Inform the Cache Manager to uninitialize Cache Maps ...
195  // and other similar stuff.
196  // BrutePoint();
197  NtReqFcb = Fcb->NTRequiredFCB;
198 
199  if (Fcb->NodeIdentifier.NodeType == UDF_NODE_TYPE_VCB) {
200  AdPrint(("Cleaning up Volume\n"));
201  AdPrint(("UDF: OpenHandleCount: %x\n",Fcb->OpenHandleCount));
202 
204  UDFInterlockedDecrement((PLONG)&(Vcb->VCBHandleCount));
205  if(FileObject->Flags & FO_CACHE_SUPPORTED) {
206  // we've cached close
207  UDFInterlockedDecrement((PLONG)&(Fcb->CachedOpenHandleCount));
208  }
209  ASSERT(Fcb->OpenHandleCount <= (Fcb->ReferenceCount-1));
210 
211  // If this handle had write access, and actually wrote something,
212  // flush the device buffers, and then set the verify bit now
213  // just to be safe (in case there is no dismount).
214  if( FileObject->WriteAccess &&
215  (FileObject->Flags & FO_FILE_MODIFIED)) {
216 
217  Vcb->Vpb->RealDevice->Flags |= DO_VERIFY_VOLUME;
218  }
219  // User may decide to close locked volume without call to unlock proc
220  // So, handle this situation properly & unlock it now...
221  if (FileObject == Vcb->VolumeLockFileObject) {
222  Vcb->VolumeLockFileObject = NULL;
223  Vcb->VolumeLockPID = -1;
224  Vcb->VCBFlags &= ~UDF_VCB_FLAGS_VOLUME_LOCKED;
225  Vcb->Vpb->Flags &= ~VPB_LOCKED;
227  }
228 
229  MmPrint((" CcUninitializeCacheMap()\n"));
231  // reset device
232  if(!(Vcb->VCBFlags & UDF_VCB_FLAGS_VOLUME_MOUNTED) &&
233  (Vcb->VCBFlags & UDF_VCB_FLAGS_OUR_DEVICE_DRIVER)) {
234  // this call doesn't modify data buffer
235  // it just requires its presence
236  UDFResetDeviceDriver(Vcb, Vcb->TargetDeviceObject, TRUE);
237  }
238  // We must clean up the share access at this time, since we may not
239  // get a Close call for awhile if the file was mapped through this
240  // File Object.
241  IoRemoveShareAccess( FileObject, &(NtReqFcb->FCBShareAccess) );
242 
244  }
245 // BrutePoint();
246 #ifdef UDF_DBG
247  DirNdx = UDFGetDirIndexByFileInfo(Fcb->FileInfo);
248  if(DirNdx) {
249  CurName.Buffer = UDFDirIndex(DirNdx, Fcb->FileInfo->Index)->FName.Buffer;
250  if(CurName.Buffer) {
251  AdPrint(("Cleaning up file: %ws %8.8x\n", CurName.Buffer, FileObject));
252  } else {
253  AdPrint(("Cleaning up file: ??? \n"));
254  }
255  }
256 #endif //UDF_DBG
257  AdPrint(("UDF: OpenHandleCount: %x\n",Fcb->OpenHandleCount));
258  // Acquire parent object
259  if(Fcb->FileInfo->ParentFile) {
260  UDF_CHECK_PAGING_IO_RESOURCE(Fcb->FileInfo->ParentFile->Fcb->NTRequiredFCB);
261  UDFAcquireResourceExclusive(&(Fcb->FileInfo->ParentFile->Fcb->NTRequiredFCB->MainResource),TRUE);
262  } else {
263  UDFAcquireResourceShared(&(Vcb->VCBResource),TRUE);
264  }
265  AcquiredParentFCB = TRUE;
266  // Acquire current object
268  UDFAcquireResourceExclusive(&(NtReqFcb->MainResource),TRUE);
269  AcquiredFCB = TRUE;
270  // dereference object
272  UDFInterlockedDecrement((PLONG)&(Vcb->VCBHandleCount));
273  if(FileObject->Flags & FO_CACHE_SUPPORTED) {
274  // we've cached close
275  UDFInterlockedDecrement((PLONG)&(Fcb->CachedOpenHandleCount));
276  }
277  ASSERT(Fcb->OpenHandleCount <= (Fcb->ReferenceCount-1));
278  // check if Ccb being cleaned up has DeleteOnClose flag set
279 #ifndef UDF_READ_ONLY_BUILD
280  if(Ccb->CCBFlags & UDF_CCB_DELETE_ON_CLOSE) {
281  AdPrint((" DeleteOnClose\n"));
282  // Ok, now we'll become 'delete on close'...
283  ASSERT(!(Fcb->FCBFlags & UDF_FCB_ROOT_DIRECTORY));
284  Fcb->FCBFlags |= UDF_FCB_DELETE_ON_CLOSE;
285  FileObject->DeletePending = TRUE;
286  // Report this to the dir notify package for a directory.
287  if(Fcb->FCBFlags & UDF_FCB_DIRECTORY) {
288  FsRtlNotifyFullChangeDirectory( Vcb->NotifyIRPMutex, &(Vcb->NextNotifyIRP),
289  (PVOID)Ccb, NULL, FALSE, FALSE,
290  0, NULL, NULL, NULL );
291  }
292  }
293 #endif //UDF_READ_ONLY_BUILD
294 
295  if(!(Fcb->FCBFlags & UDF_FCB_DIRECTORY)) {
296  // Unlock all outstanding file locks.
297  FsRtlFastUnlockAll(&(NtReqFcb->FileLock),
298  FileObject,
300  NULL);
301  }
302  // get Link count
303  lc = UDFGetFileLinkCount(Fcb->FileInfo);
304 
305 #ifndef UDF_READ_ONLY_BUILD
306  if( (Fcb->FCBFlags & UDF_FCB_DELETE_ON_CLOSE) &&
307  !(Fcb->OpenHandleCount)) {
308  // This can be useful for Streams, those were brutally deleted
309  // (together with parent object)
310  ASSERT(!(Fcb->FCBFlags & UDF_FCB_ROOT_DIRECTORY));
311  FileObject->DeletePending = TRUE;
312 
313  // we should mark all streams of the file being deleted
314  // for deletion too, if there are no more Links to
315  // main data stream
316  if((lc <= 1) &&
317  !UDFIsSDirDeleted(Fcb->FileInfo->Dloc->SDirInfo)) {
318  RC = UDFMarkStreamsForDeletion(Vcb, Fcb, TRUE); // Delete
319  }
320  // we can release these resources 'cause UDF_FCB_DELETE_ON_CLOSE
321  // flag is already set & the file can't be opened
323  UDFReleaseResource(&(NtReqFcb->MainResource));
324  AcquiredFCB = FALSE;
325  if(Fcb->FileInfo->ParentFile) {
326  UDF_CHECK_PAGING_IO_RESOURCE(Fcb->ParentFcb->NTRequiredFCB);
327  UDFReleaseResource(&(Fcb->ParentFcb->NTRequiredFCB->MainResource));
328  } else {
329  UDFReleaseResource(&(Vcb->VCBResource));
330  }
331  AcquiredParentFCB = FALSE;
332  UDFReleaseResource(&(Vcb->VCBResource));
333  AcquiredVcb = FALSE;
334 
335  // Make system to issue last Close request
336  // for our Target ...
338 
339 #ifdef UDF_DELAYED_CLOSE
340  // remove file from our DelayedClose queue
342  ASSERT(!Fcb->IrpContextLite);
343 #endif //UDF_DELAYED_CLOSE
344 
345  UDFAcquireResourceShared(&(Vcb->VCBResource), TRUE);
346  AcquiredVcb = TRUE;
347  if(Fcb->FileInfo->ParentFile) {
348  UDF_CHECK_PAGING_IO_RESOURCE(Fcb->ParentFcb->NTRequiredFCB);
349  UDFAcquireResourceExclusive(&(Fcb->ParentFcb->NTRequiredFCB->MainResource),TRUE);
350  } else {
351  UDFAcquireResourceShared(&(Vcb->VCBResource),TRUE);
352  }
353  AcquiredParentFCB = TRUE;
355  UDFAcquireResourceExclusive(&(NtReqFcb->MainResource),TRUE);
356  AcquiredFCB = TRUE;
357 
358  // we should set file sizes to zero if there are no more
359  // links to this file
360  if(lc <= 1) {
361  // Synchronize here with paging IO
362  UDFAcquireResourceExclusive(&(NtReqFcb->PagingIoResource),TRUE);
363  // set file size to zero (for system cache manager)
364 // NtReqFcb->CommonFCBHeader.ValidDataLength.QuadPart =
365  NtReqFcb->CommonFCBHeader.FileSize.QuadPart =
366  NtReqFcb->CommonFCBHeader.ValidDataLength.QuadPart = 0;
367  CcSetFileSizes(FileObject, (PCC_FILE_SIZES)&(NtReqFcb->CommonFCBHeader.AllocationSize));
368 
369  UDFReleaseResource(&(NtReqFcb->PagingIoResource));
370  }
371  }
372 #endif //UDF_READ_ONLY_BUILD
373 
374 #ifdef UDF_DELAYED_CLOSE
375  if ((Fcb->ReferenceCount == 1) &&
376  /*(Fcb->NodeIdentifier.NodeType != UDF_NODE_TYPE_VCB) &&*/ // see above
377  (!(Fcb->FCBFlags & UDF_FCB_DELETE_ON_CLOSE)) ) {
378  Fcb->FCBFlags |= UDF_FCB_DELAY_CLOSE;
379  }
380 #endif //UDF_DELAYED_CLOSE
381 
382  NextFileInfo = Fcb->FileInfo;
383 
384 #ifndef UDF_READ_ONLY_BUILD
385  // do we need to delete it now ?
386  if( (Fcb->FCBFlags & UDF_FCB_DELETE_ON_CLOSE) &&
387  !(Fcb->OpenHandleCount)) {
388 
389  // can we do it ?
390  if(Fcb->FCBFlags & UDF_FCB_DIRECTORY) {
391  ASSERT(!(Fcb->FCBFlags & UDF_FCB_ROOT_DIRECTORY));
392  if(!UDFIsDirEmpty__(NextFileInfo)) {
393  // forget about it
394  Fcb->FCBFlags &= ~UDF_FCB_DELETE_ON_CLOSE;
395  goto DiscardDelete;
396  }
397  } else
398  if (lc <= 1) {
399  // Synchronize here with paging IO
400  BOOLEAN AcquiredPagingIo;
401  AcquiredPagingIo = UDFAcquireResourceExclusiveWithCheck(&(NtReqFcb->PagingIoResource));
402  // set file size to zero (for UdfInfo package)
403  // we should not do this for directories and linked files
404  UDFResizeFile__(Vcb, NextFileInfo, 0);
405  if(AcquiredPagingIo) {
406  UDFReleaseResource(&(NtReqFcb->PagingIoResource));
407  }
408  }
409  // mark parent object for deletion if requested
410  if((Fcb->FCBFlags & UDF_FCB_DELETE_PARENT) &&
411  Fcb->ParentFcb) {
412  ASSERT(!(Fcb->ParentFcb->FCBFlags & UDF_FCB_ROOT_DIRECTORY));
413  Fcb->ParentFcb->FCBFlags |= UDF_FCB_DELETE_ON_CLOSE;
414  }
415  // flush file. It is required by UDFUnlinkFile__()
416  RC = UDFFlushFile__(Vcb, NextFileInfo);
417  if(!NT_SUCCESS(RC)) {
418  AdPrint(("Error flushing file !!!\n"));
419  }
420  // try to unlink
421  if((RC = UDFUnlinkFile__(Vcb, NextFileInfo, TRUE)) == STATUS_CANNOT_DELETE) {
422  // If we can't delete file with Streams due to references,
423  // mark SDir & Streams
424  // for Deletion. We shall also set DELETE_PARENT flag to
425  // force Deletion of the current file later... when curently
426  // opened Streams would be cleaned up.
427 
428  // WARNING! We should keep SDir & Streams if there is a
429  // link to this file
430  if(NextFileInfo->Dloc &&
431  NextFileInfo->Dloc->SDirInfo &&
432  NextFileInfo->Dloc->SDirInfo->Fcb) {
433 
434  BrutePoint();
435  if(!UDFIsSDirDeleted(NextFileInfo->Dloc->SDirInfo)) {
436 // RC = UDFMarkStreamsForDeletion(Vcb, Fcb, TRUE); // Delete
437 //#ifdef UDF_ALLOW_PRETEND_DELETED
438  UDFPretendFileDeleted__(Vcb, Fcb->FileInfo);
439 //#endif //UDF_ALLOW_PRETEND_DELETED
440  }
441  goto NotifyDelete;
442 
443  } else {
444  // Getting here means that we can't delete file because of
445  // References/PemissionsDenied/Smth.Else,
446  // but not Linked+OpenedStream
447  BrutePoint();
448 // RC = STATUS_SUCCESS;
449  goto DiscardDelete_1;
450  }
451  } else {
452 DiscardDelete_1:
453  // We have got an ugly ERROR, or
454  // file is deleted, so forget about it
455  ASSERT(!(Fcb->FCBFlags & UDF_FCB_ROOT_DIRECTORY));
456  ForcedCleanUp = TRUE;
457  if(NT_SUCCESS(RC))
458  Fcb->FCBFlags &= ~UDF_FCB_DELETE_ON_CLOSE;
459  Fcb->FCBFlags |= UDF_FCB_DELETED;
460  RC = STATUS_SUCCESS;
461  }
462 NotifyDelete:
463  // We should prevent SetEOF operations on completly
464  // deleted data streams
465  if(lc < 1) {
466  NtReqFcb->NtReqFCBFlags |= UDF_NTREQ_FCB_DELETED;
467  }
468  // Report that we have removed an entry.
469  if(UDFIsAStream(NextFileInfo)) {
470  UDFNotifyFullReportChange( Vcb, NextFileInfo,
473  } else {
474  UDFNotifyFullReportChange( Vcb, NextFileInfo,
477  }
478  } else
479  if(Fcb->FCBFlags & UDF_FCB_DELETE_ON_CLOSE) {
480 DiscardDelete:
481  UDFNotifyFullReportChange( Vcb, NextFileInfo,
484  0,
486  }
487 #endif //UDF_READ_ONLY_BUILD
488 
489  if(Fcb->FCBFlags & UDF_FCB_DIRECTORY) {
490  // Report to the dir notify package for a directory.
491  FsRtlNotifyCleanup( Vcb->NotifyIRPMutex, &(Vcb->NextNotifyIRP), (PVOID)Ccb );
492  }
493 
494  // we can't purge Cache when more than one link exists
495  if(lc > 1) {
496  ForcedCleanUp = FALSE;
497  }
498 
499  if ( (FileObject->Flags & FO_CACHE_SUPPORTED) &&
500  (NtReqFcb->SectionObject.DataSectionObject) ) {
501  BOOLEAN LastNonCached = (!Fcb->CachedOpenHandleCount &&
503  // If this was the last cached open, and there are open
504  // non-cached handles, attempt a flush and purge operation
505  // to avoid cache coherency overhead from these non-cached
506  // handles later. We ignore any I/O errors from the flush.
507  // We shall not flush deleted files
508  RC = STATUS_SUCCESS;
509  if( LastNonCached
510  ||
511  (!Fcb->OpenHandleCount &&
512  !ForcedCleanUp) ) {
513 
514 #ifndef UDF_READ_ONLY_BUILD
515  LONGLONG OldFileSize, NewFileSize;
516 
517  if( (OldFileSize = NtReqFcb->CommonFCBHeader.ValidDataLength.QuadPart) <
518  (NewFileSize = NtReqFcb->CommonFCBHeader.FileSize.QuadPart)) {
519 /* UDFZeroDataEx(NtReqFcb,
520  OldFileSize,
521  NewFileSize - OldFileSize,
522  TRUE, Vcb, FileObject);*/
523 
524  NtReqFcb->CommonFCBHeader.ValidDataLength.QuadPart = NewFileSize;
525  }
526 #endif //UDF_READ_ONLY_BUILD
527  MmPrint((" CcFlushCache()\n"));
528  CcFlushCache( &(NtReqFcb->SectionObject), NULL, 0, &IoStatus );
529  if(!NT_SUCCESS(IoStatus.Status)) {
530  MmPrint((" CcFlushCache() error: %x\n", IoStatus.Status));
531  RC = IoStatus.Status;
532  }
533  }
534  // If file is deleted or it is last cached open, but there are
535  // some non-cached handles we should purge cache section
536  if(ForcedCleanUp || LastNonCached) {
537  if(NtReqFcb->SectionObject.DataSectionObject) {
538  MmPrint((" CcPurgeCacheSection()\n"));
539  CcPurgeCacheSection( &(NtReqFcb->SectionObject), NULL, 0, FALSE );
540  }
541 /* MmPrint((" CcPurgeCacheSection()\n"));
542  CcPurgeCacheSection( &(NtReqFcb->SectionObject), NULL, 0, FALSE );*/
543  }
544  // we needn't Flush here. It will be done in UDFCloseFileInfoChain()
545  }
546 
547 #ifndef UDF_READ_ONLY_BUILD
548  // Update FileTimes & Attrs
549  if(!(Vcb->VCBFlags & UDF_VCB_FLAGS_VOLUME_READ_ONLY) &&
550  !(Fcb->FCBFlags & (UDF_FCB_DELETE_ON_CLOSE |
551  UDF_FCB_DELETED /*|
552  UDF_FCB_DIRECTORY |
553  UDF_FCB_READ_ONLY*/)) &&
554  !UDFIsAStreamDir(NextFileInfo)) {
556  LONGLONG ASize;
558  // Check if we should set ARCHIVE bit & LastWriteTime
559  if(FileObject->Flags & FO_FILE_MODIFIED) {
560  ULONG Attr;
561  PDIR_INDEX_ITEM DirNdx;
562  DirNdx = UDFDirIndex(UDFGetDirIndexByFileInfo(NextFileInfo), NextFileInfo->Index);
563  ASSERT(DirNdx);
564  // Archive bit
565  if(!(Ccb->CCBFlags & UDF_CCB_ATTRIBUTES_SET) &&
566  (Vcb->CompatFlags & UDF_VCB_IC_UPDATE_ARCH_BIT)) {
567  Attr = UDFAttributesToNT(DirNdx, NextFileInfo->Dloc->FileEntry);
568  if(!(Attr & FILE_ATTRIBUTE_ARCHIVE))
569  UDFAttributesToUDF(DirNdx, NextFileInfo->Dloc->FileEntry, Attr | FILE_ATTRIBUTE_ARCHIVE);
570  }
571  // WriteTime
572  if(!(Ccb->CCBFlags & UDF_CCB_WRITE_TIME_SET) &&
573  (Vcb->CompatFlags & UDF_VCB_IC_UPDATE_MODIFY_TIME)) {
574  UDFSetFileXTime(NextFileInfo, NULL, &NtTime, NULL, &NtTime);
575  NtReqFcb->LastWriteTime.QuadPart =
576  NtReqFcb->LastAccessTime.QuadPart = NtTime;
577  ChangeTime = TRUE;
578  }
579  }
580  if(!(Fcb->FCBFlags & UDF_FCB_DIRECTORY)) {
581  // Update sizes in DirIndex
582  if(!Fcb->OpenHandleCount) {
583  ASize = UDFGetFileAllocationSize(Vcb, NextFileInfo);
584 // NtReqFcb->CommonFCBHeader.AllocationSize.QuadPart;
585  UDFSetFileSizeInDirNdx(Vcb, NextFileInfo, &ASize);
586  } else
587  if(FileObject->Flags & FO_FILE_SIZE_CHANGED) {
588  ASize = //UDFGetFileAllocationSize(Vcb, NextFileInfo);
589  NtReqFcb->CommonFCBHeader.AllocationSize.QuadPart;
590  UDFSetFileSizeInDirNdx(Vcb, NextFileInfo, &ASize);
591  }
592  }
593  // AccessTime
594  if((FileObject->Flags & FO_FILE_FAST_IO_READ) &&
595  !(Ccb->CCBFlags & UDF_CCB_ACCESS_TIME_SET) &&
596  (Vcb->CompatFlags & UDF_VCB_IC_UPDATE_ACCESS_TIME)) {
597  UDFSetFileXTime(NextFileInfo, NULL, &NtTime, NULL, NULL);
598  NtReqFcb->LastAccessTime.QuadPart = NtTime;
599 // ChangeTime = TRUE;
600  }
601  // ChangeTime (AttrTime)
602  if(!(Ccb->CCBFlags & UDF_CCB_MODIFY_TIME_SET) &&
603  (Vcb->CompatFlags & UDF_VCB_IC_UPDATE_ATTR_TIME) &&
604  (ChangeTime || (Ccb->CCBFlags & (UDF_CCB_ATTRIBUTES_SET |
608  UDFSetFileXTime(NextFileInfo, NULL, NULL, &NtTime, NULL);
609  NtReqFcb->ChangeTime.QuadPart = NtTime;
610  }
611  }
612 #endif //UDF_READ_ONLY_BUILD
613 
614  if(!(Fcb->FCBFlags & UDF_FCB_DIRECTORY) &&
615  ForcedCleanUp) {
616  // flush system cache
617  MmPrint((" CcUninitializeCacheMap()\n"));
619  } else {
620  MmPrint((" CcUninitializeCacheMap()\n"));
622  }
623 
624  // release resources now.
625  // they'll be acquired in UDFCloseFileInfoChain()
627  UDFReleaseResource(&(NtReqFcb->MainResource));
628  AcquiredFCB = FALSE;
629 
630  if(Fcb->FileInfo->ParentFile) {
631  UDF_CHECK_PAGING_IO_RESOURCE(Fcb->FileInfo->ParentFile->Fcb->NTRequiredFCB);
632  UDFReleaseResource(&(Fcb->FileInfo->ParentFile->Fcb->NTRequiredFCB->MainResource));
633  } else {
634  UDFReleaseResource(&(Vcb->VCBResource));
635  }
636  AcquiredParentFCB = FALSE;
637  // close the chain
638  ASSERT(AcquiredVcb);
639  RC2 = UDFCloseFileInfoChain(Vcb, NextFileInfo, Ccb->TreeLength, TRUE);
640  if(NT_SUCCESS(RC))
641  RC = RC2;
642 
643  Ccb->CCBFlags |= UDF_CCB_CLEANED;
644 
645  // We must clean up the share access at this time, since we may not
646  // get a Close call for awhile if the file was mapped through this
647  // File Object.
648  IoRemoveShareAccess( FileObject, &(NtReqFcb->FCBShareAccess) );
649 
650  NtReqFcb->CommonFCBHeader.IsFastIoPossible = UDFIsFastIoPossible(Fcb);
651 
653 
654 try_exit: NOTHING;
655 
656  } _SEH2_FINALLY {
657 
658  if(AcquiredFCB) {
660  UDFReleaseResource(&(NtReqFcb->MainResource));
661  }
662 
663  if(AcquiredParentFCB) {
664  if(Fcb->FileInfo->ParentFile) {
665  UDF_CHECK_PAGING_IO_RESOURCE(Fcb->FileInfo->ParentFile->Fcb->NTRequiredFCB);
666  UDFReleaseResource(&(Fcb->FileInfo->ParentFile->Fcb->NTRequiredFCB->MainResource));
667  } else {
668  UDFReleaseResource(&(Vcb->VCBResource));
669  }
670  }
671 
672  if(AcquiredVcb) {
673  UDFReleaseResource(&(Vcb->VCBResource));
674  AcquiredVcb = FALSE;
675  }
676 
677  if (!_SEH2_AbnormalTermination()) {
678  // complete the IRP
679  Irp->IoStatus.Status = RC;
680  Irp->IoStatus.Information = 0;
682  // Free up the Irp Context
683  UDFReleaseIrpContext(PtrIrpContext);
684  }
685 
686  } _SEH2_END; // end of "__finally" processing
687  return(RC);
688 } // end UDFCommonCleanup()
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define UDFAcquireResourceExclusive(Resource, CanWait)
Definition: env_spec_w32.h:656
VOID UDFReleaseIrpContext(PtrUDFIrpContext PtrIrpContext)
Definition: misc.cpp:1086
PEPROCESS NTAPI IoGetRequestorProcess(IN PIRP Irp)
Definition: irp.c:1782
UNICODE_STRING FName
Definition: udf_rel.h:173
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:384
#define TRUE
Definition: types.h:120
#define UDFRemoveFromDelayedQueue(Fcb)
Definition: protos.h:106
struct _UDFContextControlBlock * PtrUDFCCB
#define AdPrint(_x_)
Definition: env_spec_w32.h:292
#define UDFGetFileAllocationSize(Vcb, FileInfo)
Definition: udf_info.h:797
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
VOID NTAPI FsRtlNotifyFullChangeDirectory(IN PNOTIFY_SYNC NotifySync, IN PLIST_ENTRY NotifyList, IN PVOID FsContext, IN PSTRING FullDirectoryName, IN BOOLEAN WatchTree, IN BOOLEAN IgnoreBuffer, IN ULONG CompletionFilter, IN PIRP NotifyIrp, IN PCHECK_FOR_TRAVERSE_ACCESS TraverseCallback OPTIONAL, IN PSECURITY_SUBJECT_CONTEXT SubjectContext OPTIONAL)
Definition: notify.c:1458
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
_In_ PIRP Irp
Definition: csq.h:116
#define UDF_FCB_DELETE_PARENT
Definition: struct.h:319
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define UDF_NODE_TYPE_VCB
Definition: struct.h:61
#define UDF_CCB_ATTRIBUTES_SET
Definition: struct.h:157
#define UDFReleaseResource(Resource)
Definition: env_spec_w32.h:661
LONG NTSTATUS
Definition: precomp.h:26
#define UDF_FCB_DELETE_ON_CLOSE
Definition: struct.h:309
__inline PDIR_INDEX_ITEM UDFDirIndex(IN PDIR_INDEX_HDR hDirNdx, IN uint_di i)
Definition: udf_info.h:1105
#define FSRTL_VOLUME_UNLOCK
Definition: ntifs_ex.h:443
#define DO_VERIFY_VOLUME
Definition: env_spec_w32.h:393
Definition: cdstruc.h:504
#define FILE_NOTIFY_CHANGE_LAST_WRITE
NTSTATUS UDFMarkStreamsForDeletion(IN PVCB Vcb, IN PtrUDFFCB Fcb, IN BOOLEAN ForDel)
Definition: fileinfo.cpp:1137
#define FILE_NOTIFY_CHANGE_FILE_NAME
PUDF_DATALOC_INFO Dloc
Definition: udf_rel.h:367
PDEVICE_OBJECT TargetDeviceObject
Definition: struct.h:374
void UDFSetFileSizeInDirNdx(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN int64 *ASize)
Definition: udf_info.cpp:1190
#define FILE_NOTIFY_CHANGE_DIR_NAME
#define FILE_ACTION_REMOVED_STREAM
#define UDF_IRP_CONTEXT_CAN_BLOCK
Definition: struct.h:385
VOID NTAPI IoRemoveShareAccess(IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
Definition: file.c:3477
#define UDF_CCB_MODIFY_TIME_SET
Definition: struct.h:154
_SEH2_TRY
Definition: create.c:4250
VOID NTAPI FsRtlNotifyCleanup(IN PNOTIFY_SYNC NotifySync, IN PLIST_ENTRY NotifyList, IN PVOID FsContext)
Definition: notify.c:635
#define FO_FILE_SIZE_CHANGED
Definition: iotypes.h:1745
#define UDF_VCB_FLAGS_VOLUME_READ_ONLY
Definition: udf_common.h:463
#define FO_FILE_MODIFIED
Definition: iotypes.h:1744
#define IO_DISK_INCREMENT
Definition: iotypes.h:567
PDIR_INDEX_HDR UDFGetDirIndexByFileInfo(IN PUDF_FILE_INFO FileInfo)
Definition: dirtree.cpp:1092
#define FO_FILE_FAST_IO_READ
Definition: iotypes.h:1751
#define UDFIsADirectory(FileInfo)
Definition: udf_info.h:792
#define VPB_LOCKED
Definition: iotypes.h:1764
#define UDF_CCB_CLEANED
Definition: struct.h:146
#define FILE_ACTION_MODIFIED
#define FILE_ACTION_MODIFIED_STREAM
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
#define UDFInterlockedDecrement(addr)
Definition: env_spec_w32.h:677
#define TmPrint(_x_)
Definition: env_spec_w32.h:290
smooth NULL
Definition: ftsmooth.c:416
#define FILE_ACTION_REMOVED
#define _SEH2_AbnormalTermination()
Definition: pseh2_64.h:13
#define IoCompleteRequest
Definition: irp.c:1240
OSSTATUS UDFFlushFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN ULONG FlushFlags)
Definition: udf_info.cpp:4119
uint32 IrpContextFlags
Definition: struct.h:364
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
OSSTATUS UDFPretendFileDeleted__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:5566
#define UDF_VCB_IC_UPDATE_ACCESS_TIME
Definition: udf_common.h:493
__inline VOID UDFNotifyFullReportChange(PVCB V, PUDF_FILE_INFO FI, ULONG E, ULONG A)
Definition: env_spec.h:99
#define UDFIsAStreamDir(FI)
Definition: udf_info.h:998
#define UDF_CCB_CREATE_TIME_SET
Definition: struct.h:155
ULONG OpenHandleCount
Definition: ntfs.h:533
#define UDF_VCB_IC_UPDATE_MODIFY_TIME
Definition: udf_common.h:494
int64_t LONGLONG
Definition: typedefs.h:66
#define UDFRemoveFromSystemDelayedQueue(Fcb)
Definition: protos.h:109
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint_di Index
Definition: udf_rel.h:392
#define try_return(S)
Definition: cdprocs.h:2189
#define UDF_VCB_FLAGS_OUR_DEVICE_DRIVER
Definition: udf_common.h:466
#define UDF_VCB_IC_UPDATE_ARCH_BIT
Definition: udf_common.h:496
#define Vcb
Definition: cdprocs.h:1425
#define FILE_NOTIFY_CHANGE_STREAM_NAME
#define UDF_FCB_DIRECTORY
Definition: struct.h:303
#define BrutePoint()
Definition: env_spec_w32.h:504
#define UDF_CCB_DELETE_ON_CLOSE
Definition: struct.h:162
#define MmPrint(_x_)
Definition: env_spec_w32.h:289
VOID UDFSetFileXTime(IN PUDF_FILE_INFO FileInfo, IN LONGLONG *CrtTime, IN LONGLONG *AccTime, IN LONGLONG *AttrTime, IN LONGLONG *ChgTime)
* PFILE_OBJECT
Definition: iotypes.h:1954
#define UDF_FCB_ROOT_DIRECTORY
Definition: struct.h:304
#define FO_CACHE_SUPPORTED
Definition: iotypes.h:1737
_In_opt_ PLARGE_INTEGER NewFileSize
Definition: mmfuncs.h:609
struct _UDF_FILE_INFO * SDirInfo
Definition: udf_rel.h:319
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define FILE_ATTRIBUTE_ARCHIVE
Definition: nt_native.h:706
#define NtReqFcb
#define STATUS_CANNOT_DELETE
Definition: shellext.h:66
#define UDF_NTREQ_FCB_DELETED
Definition: struct.h:235
#define UDF_VCB_FLAGS_VOLUME_MOUNTED
Definition: udf_common.h:459
_In_ PLARGE_INTEGER NtTime
Definition: fatprocs.h:1905
#define UDFIsSDirDeleted(FI)
Definition: udf_info.h:1004
#define UDF_FCB_DELETED
Definition: struct.h:314
UDFData UDFGlobalData
Definition: udfinit.cpp:25
#define UDF_FCB_DELAY_CLOSE
Definition: struct.h:313
#define UDFIsDirEmpty__(fi)
Definition: udf_info.h:1070
#define UDF_VCB_IC_UPDATE_ATTR_TIME
Definition: udf_common.h:495
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
#define NOTHING
Definition: env_spec_w32.h:461
struct _VCB * PVCB
Definition: fatstruc.h:556
NTSTATUS NTAPI FsRtlFastUnlockAll(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PEPROCESS Process, IN PVOID Context OPTIONAL)
Definition: filelock.c:1026
OSSTATUS UDFResetDeviceDriver(IN PVCB Vcb, IN PDEVICE_OBJECT TargetDeviceObject, IN BOOLEAN Unlock)
Definition: phys_lib.cpp:4199
#define UDFAcquireResourceShared(Resource, CanWait)
Definition: env_spec_w32.h:658
#define UDF_CCB_ACCESS_TIME_SET
Definition: struct.h:153
NTSTATUS UDFCloseFileInfoChain(IN PVCB Vcb, IN PUDF_FILE_INFO fi, IN ULONG TreeLength, IN BOOLEAN VcbAcquired)
Definition: cleanup.cpp:696
FAST_IO_POSSIBLE NTAPI UDFIsFastIoPossible(IN PtrUDFFCB Fcb)
Definition: fastio.cpp:118
struct _FCB::@691::@694 Fcb
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
VOID UDFAttributesToUDF(IN PDIR_INDEX_ITEM FileDirNdx, IN tag *FileEntry, IN ULONG NTAttr)
_SEH2_END
Definition: create.c:4424
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:284
#define FO_CLEANUP_COMPLETE
Definition: iotypes.h:1746
#define FILE_NOTIFY_CHANGE_ATTRIBUTES
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
VOID NTAPI CcSetFileSizes(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes)
Definition: fssup.c:354
#define UDF_CHECK_PAGING_IO_RESOURCE(NTReqFCB)
Definition: udffs.h:262
OSSTATUS UDFResizeFile__(IN PVCB Vcb, IN OUT PUDF_FILE_INFO FileInfo, IN int64 NewLength)
Definition: udf_info.cpp:3468
_SEH2_FINALLY
Definition: create.c:4395
OSSTATUS UDFUnlinkFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN BOOLEAN FreeSpace)
Definition: udf_info.cpp:1766
#define UDF_CCB_WRITE_TIME_SET
Definition: struct.h:156
ULONG UDFAttributesToNT(IN PDIR_INDEX_ITEM FileDirNdx, IN tag *FileEntry)
#define UDFNotifyVolumeEvent(FileObject, EventCode)
Definition: env_spec.h:114
unsigned int ULONG
Definition: retypes.h:1
struct _FCB * ParentFcb
Definition: cdstruc.h:946
BOOLEAN UDFAcquireResourceExclusiveWithCheck(IN PERESOURCE Resource)
Definition: misc.cpp:2529
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2777
#define UDFIsAStream(FI)
Definition: udf_info.h:1002
#define FILE_NOTIFY_CHANGE_LAST_ACCESS
signed int * PLONG
Definition: retypes.h:5
uint16 UDFGetFileLinkCount(IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:1355
#define UDF_VCB_FLAGS_VOLUME_LOCKED
Definition: udf_common.h:460

Referenced by UDFCleanup(), and UDFCommonDispatch().

◆ UDFCommonClose()

NTSTATUS UDFCommonClose ( PtrUDFIrpContext  PtrIrpContext,
PIRP  Irp 
)

Definition at line 137 of file close.cpp.

141 {
145  PtrUDFFCB Fcb = NULL;
146  PtrUDFCCB Ccb = NULL;
147  PVCB Vcb = NULL;
148 // PERESOURCE PtrResourceAcquired = NULL;
149  BOOLEAN AcquiredVcb = FALSE;
150  BOOLEAN AcquiredGD = FALSE;
151  PUDF_FILE_INFO fi;
152  ULONG i = 0;
153 // ULONG clean_stat = 0;
154 
155 // BOOLEAN CompleteIrp = TRUE;
156  BOOLEAN PostRequest = FALSE;
157 
158 #ifdef UDF_DBG
159  UNICODE_STRING CurName;
160  PDIR_INDEX_HDR DirNdx;
161 #endif
162 
163  AdPrint(("UDFCommonClose: \n"));
164 
165  _SEH2_TRY {
166  if (Irp) {
167 
168  // If this is the first (IOManager) request
169  // First, get a pointer to the current I/O stack location
171  ASSERT(IrpSp);
172 
175 
176  // Get the FCB and CCB pointers
177  Ccb = (PtrUDFCCB)(FileObject->FsContext2);
178  ASSERT(Ccb);
179  if(Ccb->CCBFlags & UDF_CCB_READ_ONLY) {
180  PtrIrpContext->IrpContextFlags |= UDF_IRP_CONTEXT_READ_ONLY;
181  }
182  Fcb = Ccb->Fcb;
183  } else {
184  // If this is a queued call (for our dispatch)
185  // Get saved Fcb address
186  Fcb = PtrIrpContext->Fcb;
187  i = PtrIrpContext->TreeLength;
188  }
189 
190  ASSERT(Fcb);
191  Vcb = (PVCB)(PtrIrpContext->TargetDeviceObject->DeviceExtension);
192  ASSERT(Vcb);
193  ASSERT(Vcb->NodeIdentifier.NodeType == UDF_NODE_TYPE_VCB);
194 // Vcb->VCBFlags |= UDF_VCB_SKIP_EJECT_CHECK;
195 
196  // Steps we shall take at this point are:
197  // (a) Acquire the VCB shared
198  // (b) Acquire the FCB's CCB list exclusively
199  // (c) Delete the CCB structure (free memory)
200  // (d) If this is the last close, release the FCB structure
201  // (unless we keep these around for "delayed close" functionality.
202  // Note that it is often the case that the close dispatch entry point is invoked
203  // in the most inconvenient of situations (when it is not possible, for example,
204  // to safely acquire certain required resources without deadlocking or waiting).
205  // Therefore, be extremely careful in implementing this close dispatch entry point.
206  // Also note that we do not have the option of returning a failure code from the
207  // close dispatch entry point; the system expects that the close will always succeed.
208 
209  UDFAcquireResourceShared(&(Vcb->VCBResource), TRUE);
210  AcquiredVcb = TRUE;
211 
212  // Is this is the first (IOManager) request ?
213  if (Irp) {
214  PtrIrpContext->TreeLength =
215  i = Ccb->TreeLength;
216  // remember the number of incomplete Close requests
217  InterlockedIncrement((PLONG)&(Fcb->CcbCount));
218  // we can release CCB in any case
220  FileObject->FsContext2 = NULL;
221 #ifdef DBG
222 /* } else {
223  ASSERT(Fcb->NTRequiredFCB);
224  if(Fcb->NTRequiredFCB) {
225  ASSERT(Fcb->NTRequiredFCB->FileObject);
226  if(Fcb->NTRequiredFCB->FileObject) {
227  ASSERT(!Fcb->NTRequiredFCB->FileObject->FsContext2);
228  }
229  }*/
230 #endif //DBG
231  }
232 
233 #ifdef UDF_DELAYED_CLOSE
234  // check if this is the last Close (no more Handles)
235  // and try to Delay it....
236  if((Fcb->FCBFlags & UDF_FCB_DELAY_CLOSE) &&
237  (Vcb->VCBFlags & UDF_VCB_FLAGS_VOLUME_MOUNTED) &&
238  !(Vcb->VCBFlags & UDF_VCB_FLAGS_NO_DELAYED_CLOSE) &&
239  !(Fcb->OpenHandleCount)) {
240  UDFReleaseResource(&(Vcb->VCBResource));
241  AcquiredVcb = FALSE;
242  if((RC = UDFQueueDelayedClose(PtrIrpContext,Fcb)) == STATUS_SUCCESS)
244  // do standard Close if we can't Delay this opeartion
245  AdPrint((" Cant queue Close Irp, status=%x\n", RC));
246  }
247 #endif //UDF_DELAYED_CLOSE
248 
249  if(Irp) {
250  // We should post actual procesing if this is a recursive call
251  if((PtrIrpContext->IrpContextFlags & UDF_IRP_CONTEXT_NOT_TOP_LEVEL) ||
252  (Fcb->NTRequiredFCB->AcqFlushCount)) {
253  AdPrint((" post NOT_TOP_LEVEL Irp\n"));
254  PostRequest = TRUE;
256  }
257  }
258 
259  // Close request is near completion, Vcb is acquired.
260  // Now we can safely decrease CcbCount, because no Rename
261  // operation can run until Vcb release.
262  InterlockedDecrement((PLONG)&(Fcb->CcbCount));
263 
264  UDFInterlockedDecrement((PLONG)&(Vcb->VCBOpenCount));
265  if(PtrIrpContext->IrpContextFlags & UDF_IRP_CONTEXT_READ_ONLY)
266  UDFInterlockedDecrement((PLONG)&(Vcb->VCBOpenCountRO));
267 
268  if(!i || (Fcb->NodeIdentifier.NodeType == UDF_NODE_TYPE_VCB)) {
269 
270  AdPrint(("UDF: Closing volume\n"));
271  AdPrint(("UDF: ReferenceCount: %x\n",Fcb->ReferenceCount));
272 
273  if (Vcb->VCBOpenCount > UDF_RESIDUAL_REFERENCE) {
274  ASSERT(Fcb->NodeIdentifier.NodeType == UDF_NODE_TYPE_VCB);
275  UDFInterlockedDecrement((PLONG)&(Fcb->ReferenceCount));
276  ASSERT(Fcb->NTRequiredFCB);
277  UDFInterlockedDecrement((PLONG)&(Fcb->NTRequiredFCB->CommonRefCount));
278 
280  }
281 
282  UDFInterlockedIncrement((PLONG)&(Vcb->VCBOpenCount));
283 
284  if(AcquiredVcb) {
285  UDFReleaseResource(&(Vcb->VCBResource));
286  AcquiredVcb = FALSE;
287  } else {
288  BrutePoint();
289  }
290  // Acquire GlobalDataResource
291  UDFAcquireResourceExclusive(&(UDFGlobalData.GlobalDataResource), TRUE);
292  AcquiredGD = TRUE;
293 // // Acquire Vcb
294  UDFAcquireResourceExclusive(&(Vcb->VCBResource), TRUE);
295  AcquiredVcb = TRUE;
296 
297  UDFInterlockedDecrement((PLONG)&(Vcb->VCBOpenCount));
298 
299 
300  ASSERT(Fcb->NodeIdentifier.NodeType == UDF_NODE_TYPE_VCB);
301  UDFInterlockedDecrement((PLONG)&(Fcb->ReferenceCount));
302  ASSERT(Fcb->NTRequiredFCB);
303  UDFInterlockedDecrement((PLONG)&(Fcb->NTRequiredFCB->CommonRefCount));
304 
305  //AdPrint(("UDF: Closing volume, reset driver (e.g. stop BGF)\n"));
306  //UDFResetDeviceDriver(Vcb, Vcb->TargetDeviceObject, FALSE);
307 
308  AdPrint(("UDF: Closing volume, reset write status\n"));
309  RC = UDFPhSendIOCTL(IOCTL_CDRW_RESET_WRITE_STATUS, Vcb->TargetDeviceObject,
310  NULL, 0, NULL, 0, TRUE, NULL);
311 
312  if((Vcb->VCBFlags & UDF_VCB_FLAGS_BEING_DISMOUNTED) ||
313  ((!(Vcb->VCBFlags & UDF_VCB_FLAGS_VOLUME_MOUNTED)) && (Vcb->VCBOpenCount <= UDF_RESIDUAL_REFERENCE))) {
314  // Try to KILL dismounted volume....
315  // w2k requires this, NT4 - recomends
316  AcquiredVcb = UDFCheckForDismount(PtrIrpContext, Vcb, TRUE);
317  }
318 
320  }
321 
322  fi = Fcb->FileInfo;
323 #ifdef UDF_DBG
324  if(!fi) {
325  BrutePoint();
326  }
327 
328  DirNdx = UDFGetDirIndexByFileInfo(fi);
329  if(DirNdx) {
330  CurName.Buffer = UDFDirIndex(DirNdx,fi->Index)->FName.Buffer;
331  if(CurName.Buffer) {
332  AdPrint(("Closing file: %ws %8.8x\n", CurName.Buffer, FileObject));
333  } else {
334  AdPrint(("Closing file: ??? \n"));
335  }
336  }
337  AdPrint(("UDF: ReferenceCount: %x\n",Fcb->ReferenceCount));
338 #endif // UDF_DBG
339  // try to clean up as long chain as it is possible
340  UDFCleanUpFcbChain(Vcb, fi, i, TRUE);
341 
342 try_exit: NOTHING;
343 
344  } _SEH2_FINALLY {
345 
346  if(AcquiredVcb) {
347  UDFReleaseResource(&(Vcb->VCBResource));
348  }
349  if(AcquiredGD) {
350  UDFReleaseResource(&(UDFGlobalData.GlobalDataResource));
351  }
352 
353  // Post IRP if required
354  if (PostRequest) {
355 
356  // Perform the post operation & complete the IRP
357  // if this is first call of UDFCommonClose
358  // and will return STATUS_SUCCESS back to us
359  PtrIrpContext->Irp = NULL;
360  PtrIrpContext->Fcb = Fcb;
361  UDFPostRequest(PtrIrpContext, NULL);
362  }
363 
364  if (!_SEH2_AbnormalTermination()) {
365  // If this is not async close complete the IRP
366  if (Irp) {
367 /* if( FileObject ) {
368  if(clean_stat & UDF_CLOSE_NTREQFCB_DELETED) {
369 // ASSERT(!FileObject->FsContext2);
370  FileObject->FsContext = NULL;
371 #ifdef DBG
372  } else {
373  UDFNTRequiredFCB* NtReqFcb = ((UDFNTRequiredFCB*)(FileObject->FsContext));
374  if(NtReqFcb->FileObject == FileObject) {
375  NtReqFcb->FileObject = NULL;
376  }
377 #endif //DBG
378  }
379  }*/
380  Irp->IoStatus.Status = STATUS_SUCCESS;
381  Irp->IoStatus.Information = 0;
383  }
384  // Free up the Irp Context
385  if(!PostRequest)
386  UDFReleaseIrpContext(PtrIrpContext);
387  }
388 
389  } _SEH2_END; // end of "__finally" processing
390 
391  return STATUS_SUCCESS ;
392 } // end UDFCommonClose()
#define UDFAcquireResourceExclusive(Resource, CanWait)
Definition: env_spec_w32.h:656
VOID UDFReleaseIrpContext(PtrUDFIrpContext PtrIrpContext)
Definition: misc.cpp:1086
UNICODE_STRING FName
Definition: udf_rel.h:173
#define TRUE
Definition: types.h:120
struct _UDFContextControlBlock * PtrUDFCCB
#define UDF_CCB_READ_ONLY
Definition: struct.h:170
NTSTATUS NTAPI UDFPhSendIOCTL(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, OUT PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN OverrideVerify, OUT PIO_STATUS_BLOCK Iosb OPTIONAL)
Definition: env_spec.cpp:511
BOOLEAN UDFCheckForDismount(IN PtrUDFIrpContext IrpContext, IN PVCB Vcb, IN BOOLEAN VcbAcquired)
Definition: verfysup.cpp:629
#define AdPrint(_x_)
Definition: env_spec_w32.h:292
ULONG UDFCleanUpFcbChain(IN PVCB Vcb, IN PUDF_FILE_INFO fi, IN ULONG TreeLength, IN BOOLEAN VcbAcquired)
Definition: close.cpp:400
#define UDF_IRP_CONTEXT_NOT_TOP_LEVEL
Definition: struct.h:390
_In_ PIRP Irp
Definition: csq.h:116
#define UDF_NODE_TYPE_VCB
Definition: struct.h:61
#define UDFReleaseResource(Resource)
Definition: env_spec_w32.h:661
LONG NTSTATUS
Definition: precomp.h:26
__inline PDIR_INDEX_ITEM UDFDirIndex(IN PDIR_INDEX_HDR hDirNdx, IN uint_di i)
Definition: udf_info.h:1105
Definition: cdstruc.h:504
_UDFFileControlBlock * Fcb
Definition: struct.h:378
PDEVICE_OBJECT TargetDeviceObject
Definition: struct.h:374
_SEH2_TRY
Definition: create.c:4250
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define IO_DISK_INCREMENT
Definition: iotypes.h:567
PDIR_INDEX_HDR UDFGetDirIndexByFileInfo(IN PUDF_FILE_INFO FileInfo)
Definition: dirtree.cpp:1092
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
#define UDFInterlockedDecrement(addr)
Definition: env_spec_w32.h:677
smooth NULL
Definition: ftsmooth.c:416
#define _SEH2_AbnormalTermination()
Definition: pseh2_64.h:13
#define IoCompleteRequest
Definition: irp.c:1240
uint32 IrpContextFlags
Definition: struct.h:364
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
ULONG TreeLength
Definition: struct.h:379
ULONG OpenHandleCount
Definition: ntfs.h:533
uint_di Index
Definition: udf_rel.h:392
#define try_return(S)
Definition: cdprocs.h:2189
#define Vcb
Definition: cdprocs.h:1425
#define BrutePoint()
Definition: env_spec_w32.h:504
* PFILE_OBJECT
Definition: iotypes.h:1954
NTSTATUS UDFQueueDelayedClose(PtrUDFIrpContext IrpContext, PtrUDFFCB Fcb)
Definition: close.cpp:1106
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define UDF_VCB_FLAGS_VOLUME_MOUNTED
Definition: udf_common.h:459
#define UDF_VCB_FLAGS_NO_DELAYED_CLOSE
Definition: udf_common.h:480
#define InterlockedDecrement
Definition: armddk.h:52
UDFData UDFGlobalData
Definition: udfinit.cpp:25
#define UDF_FCB_DELAY_CLOSE
Definition: struct.h:313
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
#define NOTHING
Definition: env_spec_w32.h:461
struct _VCB * PVCB
Definition: fatstruc.h:556
#define UDFAcquireResourceShared(Resource, CanWait)
Definition: env_spec_w32.h:658
#define UDFInterlockedIncrement(addr)
Definition: env_spec_w32.h:675
struct _FCB::@691::@694 Fcb
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
NTSTATUS UDFPostRequest(IN PtrUDFIrpContext PtrIrpContext, IN PIRP Irp)
Definition: misc.cpp:1128
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
#define UDF_IRP_CONTEXT_READ_ONLY
Definition: struct.h:394
#define UDF_VCB_FLAGS_BEING_DISMOUNTED
Definition: udf_common.h:461
_SEH2_END
Definition: create.c:4424
#define InterlockedIncrement
Definition: armddk.h:53
VOID __fastcall UDFCleanUpCCB(PtrUDFCCB Ccb)
Definition: misc.cpp:805
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
_SEH2_FINALLY
Definition: create.c:4395
#define IOCTL_CDRW_RESET_WRITE_STATUS
Definition: cdrw_usr.h:102
unsigned int ULONG
Definition: retypes.h:1
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2777
signed int * PLONG
Definition: retypes.h:5
#define UDF_RESIDUAL_REFERENCE
Definition: struct.h:336

Referenced by UDFClose(), UDFCommonDispatch(), and UDFDoDelayedClose().

◆ UDFCommonCreate()

NTSTATUS UDFCommonCreate ( IN PtrUDFIrpContext  PtrIrpContext,
IN PIRP  Irp 
)

◆ UDFCommonDeviceControl()

NTSTATUS NTAPI UDFCommonDeviceControl ( PtrUDFIrpContext  PtrIrpContext,
PIRP  Irp 
)

Definition at line 149 of file devcntrl.cpp.

153 {
156 // PIO_STACK_LOCATION PtrNextIoStackLocation = NULL;
158  PtrUDFFCB Fcb = NULL;
159  PtrUDFCCB Ccb = NULL;
160  PVCB Vcb = NULL;
162  ULONG IoControlCode = 0;
163 // PVOID BufferPointer = NULL;
164  BOOLEAN AcquiredVcb = FALSE;
165  BOOLEAN FSDevObj;
166  ULONG TrackNumber;
167  BOOLEAN UnsafeIoctl = TRUE;
168  UCHAR ScsiCommand;
169  PPREVENT_MEDIA_REMOVAL_USER_IN Buf = NULL; // FSD buffer
170  PCDB Cdb;
171  PCHAR CdbData;
172  PCHAR ModeSelectData;
173 
174  UDFPrint(("UDFCommonDeviceControl\n"));
175 
176  _SEH2_TRY {
177  // First, get a pointer to the current I/O stack location
179  ASSERT(IrpSp);
180 
181  // Get the IoControlCode value
182  IoControlCode = IrpSp->Parameters.DeviceIoControl.IoControlCode;
183 
186 
187  FSDevObj = UDFIsFSDevObj(PtrIrpContext->TargetDeviceObject);
188 
189  if(FSDevObj) {
190  switch (IoControlCode) {
194 #ifndef UDF_READ_ONLY_BUILD
196 #endif //UDF_READ_ONLY_BUILD
198  break;
199  default:
200