ReactOS  0.4.12-dev-916-gffc4e30
file.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for file.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI IopCheckBackupRestorePrivilege (IN PACCESS_STATE AccessState, IN OUT PULONG CreateOptions, IN KPROCESSOR_MODE PreviousMode, IN ULONG Disposition)
 
NTSTATUS NTAPI IopCheckDeviceAndDriver (IN POPEN_PACKET OpenPacket, IN PDEVICE_OBJECT DeviceObject)
 
VOID NTAPI IopDoNameTransmogrify (IN PIRP Irp, IN PFILE_OBJECT FileObject, IN PREPARSE_DATA_BUFFER DataBuffer)
 
NTSTATUS IopCheckTopDeviceHint (IN OUT PDEVICE_OBJECT *DeviceObject, IN POPEN_PACKET OpenPacket, BOOLEAN DirectOpen)
 
NTSTATUS NTAPI IopParseDevice (IN PVOID ParseObject, IN PVOID ObjectType, IN OUT PACCESS_STATE AccessState, IN KPROCESSOR_MODE AccessMode, IN ULONG Attributes, IN OUT PUNICODE_STRING CompleteName, IN OUT PUNICODE_STRING RemainingName, IN OUT PVOID Context, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL, OUT PVOID *Object)
 
NTSTATUS NTAPI IopParseFile (IN PVOID ParseObject, IN PVOID ObjectType, IN OUT PACCESS_STATE AccessState, IN KPROCESSOR_MODE AccessMode, IN ULONG Attributes, IN OUT PUNICODE_STRING CompleteName, IN OUT PUNICODE_STRING RemainingName, IN OUT PVOID Context OPTIONAL, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL, OUT PVOID *Object)
 
VOID NTAPI IopDeleteFile (IN PVOID ObjectBody)
 
PDEVICE_OBJECT NTAPI IopGetDeviceAttachmentBase (IN PDEVICE_OBJECT DeviceObject)
 
PDEVICE_OBJECT NTAPI IopGetDevicePDO (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI IopSetDeviceSecurityDescriptor (IN PDEVICE_OBJECT DeviceObject, IN PSECURITY_INFORMATION SecurityInformation, IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN POOL_TYPE PoolType, IN PGENERIC_MAPPING GenericMapping)
 
NTSTATUS NTAPI IopSetDeviceSecurityDescriptors (IN PDEVICE_OBJECT UpperDeviceObject, IN PDEVICE_OBJECT PhysicalDeviceObject, IN PSECURITY_INFORMATION SecurityInformation, IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN POOL_TYPE PoolType, IN PGENERIC_MAPPING GenericMapping)
 
NTSTATUS NTAPI IopGetSetSecurityObject (IN PVOID ObjectBody, IN SECURITY_OPERATION_CODE OperationCode, IN PSECURITY_INFORMATION SecurityInformation, IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN OUT PULONG BufferLength, IN OUT PSECURITY_DESCRIPTOR *OldSecurityDescriptor, IN POOL_TYPE PoolType, IN OUT PGENERIC_MAPPING GenericMapping)
 
NTSTATUS NTAPI IopQueryName (IN PVOID ObjectBody, IN BOOLEAN HasName, OUT POBJECT_NAME_INFORMATION ObjectNameInfo, IN ULONG Length, OUT PULONG ReturnLength, IN KPROCESSOR_MODE PreviousMode)
 
NTSTATUS NTAPI IopQueryNameInternal (IN PVOID ObjectBody, IN BOOLEAN HasName, IN BOOLEAN QueryDosName, OUT POBJECT_NAME_INFORMATION ObjectNameInfo, IN ULONG Length, OUT PULONG ReturnLength, IN KPROCESSOR_MODE PreviousMode)
 
VOID NTAPI IopCloseFile (IN PEPROCESS Process OPTIONAL, IN PVOID ObjectBody, IN ACCESS_MASK GrantedAccess, IN ULONG HandleCount, IN ULONG SystemHandleCount)
 
NTSTATUS NTAPI IopQueryAttributesFile (IN POBJECT_ATTRIBUTES ObjectAttributes, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG FileInformationSize, OUT PVOID FileInformation)
 
NTSTATUS NTAPI IopAcquireFileObjectLock (_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode, _In_ BOOLEAN Alertable, _Out_ PBOOLEAN LockFailed)
 
PVOID NTAPI IoGetFileObjectFilterContext (IN PFILE_OBJECT FileObject)
 
NTSTATUS NTAPI IoChangeFileObjectFilterContext (IN PFILE_OBJECT FileObject, IN PVOID FilterContext, IN BOOLEAN Define)
 
NTSTATUS NTAPI IopCreateFile (OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength, IN CREATE_FILE_TYPE CreateFileType, IN PVOID ExtraCreateParameters OPTIONAL, IN ULONG Options, IN ULONG Flags, IN PDEVICE_OBJECT DeviceObject OPTIONAL)
 
NTSTATUS NTAPI IoCheckQuerySetFileInformation (IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, IN BOOLEAN SetOperation)
 
NTSTATUS NTAPI IoCheckQuotaBufferValidity (IN PFILE_QUOTA_INFORMATION QuotaBuffer, IN ULONG QuotaLength, OUT PULONG ErrorOffset)
 
NTSTATUS NTAPI IoCreateFile (OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength, IN CREATE_FILE_TYPE CreateFileType, IN PVOID ExtraCreateParameters OPTIONAL, IN ULONG Options)
 
NTSTATUS NTAPI IoCreateFileSpecifyDeviceObjectHint (OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength, IN CREATE_FILE_TYPE CreateFileType, IN PVOID ExtraCreateParameters OPTIONAL, IN ULONG Options, IN PVOID DeviceObject)
 
PFILE_OBJECT NTAPI IoCreateStreamFileObjectEx (IN PFILE_OBJECT FileObject OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, OUT PHANDLE FileObjectHandle OPTIONAL)
 
PFILE_OBJECT NTAPI IoCreateStreamFileObject (IN PFILE_OBJECT FileObject, IN PDEVICE_OBJECT DeviceObject)
 
PFILE_OBJECT NTAPI IoCreateStreamFileObjectLite (IN PFILE_OBJECT FileObject OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL)
 
PGENERIC_MAPPING NTAPI IoGetFileObjectGenericMapping (VOID)
 
BOOLEAN NTAPI IoIsFileOriginRemote (IN PFILE_OBJECT FileObject)
 
BOOLEAN NTAPI IoFastQueryNetworkAttributes (IN POBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK DesiredAccess, IN ULONG OpenOptions, OUT PIO_STATUS_BLOCK IoStatus, OUT PFILE_NETWORK_OPEN_INFORMATION Buffer)
 
VOID NTAPI IoUpdateShareAccess (IN PFILE_OBJECT FileObject, OUT PSHARE_ACCESS ShareAccess)
 
NTSTATUS NTAPI IoCheckShareAccess (IN ACCESS_MASK DesiredAccess, IN ULONG DesiredShareAccess, IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess, IN BOOLEAN Update)
 
VOID NTAPI IoRemoveShareAccess (IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
 
VOID NTAPI IoSetShareAccess (IN ACCESS_MASK DesiredAccess, IN ULONG DesiredShareAccess, IN PFILE_OBJECT FileObject, OUT PSHARE_ACCESS ShareAccess)
 
VOID NTAPI IoCancelFileOpen (IN PDEVICE_OBJECT DeviceObject, IN PFILE_OBJECT FileObject)
 
NTSTATUS NTAPI IoQueryFileDosDeviceName (IN PFILE_OBJECT FileObject, OUT POBJECT_NAME_INFORMATION *ObjectNameInformation)
 
NTSTATUS NTAPI IoSetFileOrigin (IN PFILE_OBJECT FileObject, IN BOOLEAN Remote)
 
NTSTATUS NTAPI NtCreateFile (PHANDLE FileHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PIO_STATUS_BLOCK IoStatusBlock, PLARGE_INTEGER AllocateSize, ULONG FileAttributes, ULONG ShareAccess, ULONG CreateDisposition, ULONG CreateOptions, PVOID EaBuffer, ULONG EaLength)
 
NTSTATUS NTAPI NtCreateMailslotFile (OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG CreateOptions, IN ULONG MailslotQuota, IN ULONG MaxMessageSize, IN PLARGE_INTEGER TimeOut)
 
NTSTATUS NTAPI NtCreateNamedPipeFile (OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG ShareAccess, IN ULONG CreateDisposition, IN ULONG CreateOptions, IN ULONG NamedPipeType, IN ULONG ReadMode, IN ULONG CompletionMode, IN ULONG MaximumInstances, IN ULONG InboundQuota, IN ULONG OutboundQuota, IN PLARGE_INTEGER DefaultTimeout)
 
NTSTATUS NTAPI NtFlushWriteBuffer (VOID)
 
NTSTATUS NTAPI NtOpenFile (OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG ShareAccess, IN ULONG OpenOptions)
 
NTSTATUS NTAPI NtQueryAttributesFile (IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PFILE_BASIC_INFORMATION FileInformation)
 
NTSTATUS NTAPI NtQueryFullAttributesFile (IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PFILE_NETWORK_OPEN_INFORMATION FileInformation)
 
NtCancelIoFile

Cancel all pending I/O operations in the current thread for specified file object.

Parameters
FileHandleHandle to file object to cancel requests for. No specific access rights are needed.
IoStatusBlockPointer to status block which is filled with final completition status on successful return.
Returns
Status.

@implemented

NTSTATUS NTAPI NtCancelIoFile (IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock)
 
NTSTATUS NTAPI NtDeleteFile (IN POBJECT_ATTRIBUTES ObjectAttributes)
 

Variables

ERESOURCE IopSecurityResource
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file file.c.

Function Documentation

◆ IoCancelFileOpen()

VOID NTAPI IoCancelFileOpen ( IN PDEVICE_OBJECT  DeviceObject,
IN PFILE_OBJECT  FileObject 
)

Definition at line 3596 of file file.c.

3598 {
3599  PIRP Irp;
3600  KEVENT Event;
3601  KIRQL OldIrql;
3602  NTSTATUS Status;
3603  PIO_STACK_LOCATION Stack;
3604 
3605  /* Check if handles were already created for the
3606  * open file. If so, that's over.
3607  */
3608  if (FileObject->Flags & FO_HANDLE_CREATED)
3609  KeBugCheckEx(INVALID_CANCEL_OF_FILE_OPEN,
3611  (ULONG_PTR)DeviceObject, 0, 0);
3612 
3613  /* Reset the events */
3615  KeClearEvent(&FileObject->Event);
3616 
3617  /* Allocate the IRP we'll use */
3619  /* Properly set it */
3620  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
3621  Irp->UserEvent = &Event;
3622  Irp->UserIosb = &Irp->IoStatus;
3623  Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
3624  Irp->Tail.Overlay.OriginalFileObject = FileObject;
3625  Irp->RequestorMode = KernelMode;
3627 
3628  Stack = IoGetNextIrpStackLocation(Irp);
3629  Stack->MajorFunction = IRP_MJ_CLEANUP;
3630  Stack->FileObject = FileObject;
3631 
3632  /* Put on top of IRPs list of the thread */
3634 
3635  /* Call the driver */
3637  if (Status == STATUS_PENDING)
3638  {
3640  KernelMode, FALSE, NULL);
3641  }
3642 
3643  /* Remove from IRPs list */
3647 
3648  /* Free the IRP */
3649  IoFreeIrp(Irp);
3650 
3651  /* Clear the event */
3652  KeClearEvent(&FileObject->Event);
3653  /* And finally, mark the open operation as canceled */
3655 }
#define FO_HANDLE_CREATED
Definition: iotypes.h:1750
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define IRP_CLOSE_OPERATION
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
uint32_t ULONG_PTR
Definition: typedefs.h:63
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE VOID IopQueueIrpToThread(IN PIRP Irp)
Definition: io_x.h:49
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
PIRP NTAPI IopAllocateIrpMustSucceed(IN CCHAR StackSize)
Definition: irp.c:716
#define STATUS_PENDING
Definition: ntstatus.h:82
#define FO_FILE_OPEN_CANCELLED
Definition: iotypes.h:1753
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
FORCEINLINE VOID IopUnQueueIrpFromThread(IN PIRP Irp)
Definition: io_x.h:65
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MJ_CLEANUP
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define IRP_SYNCHRONOUS_API
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define APC_LEVEL
Definition: env_spec_w32.h:695
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107

◆ IoChangeFileObjectFilterContext()

NTSTATUS NTAPI IoChangeFileObjectFilterContext ( IN PFILE_OBJECT  FileObject,
IN PVOID  FilterContext,
IN BOOLEAN  Define 
)

Definition at line 2510 of file file.c.

2513 {
2515  PFILE_OBJECT_EXTENSION FileObjectExtension;
2516 
2518  {
2519  return STATUS_INVALID_PARAMETER;
2520  }
2521 
2522  FileObjectExtension = FileObject->FileObjectExtension;
2523  if (Define)
2524  {
2525  /* If define, just set the new value if not value is set
2526  * Success will only contain old value. It is valid if it is NULL
2527  */
2529  }
2530  else
2531  {
2532  /* If not define, we want to reset filter context.
2533  * We will remove value (provided by the caller) and set NULL instead.
2534  * This will only success if caller provides correct previous value.
2535  * To catch whether it worked, we substract previous value to expect value:
2536  * If it matches (and thus, we reset), Success will contain 0
2537  * Otherwise, it will contain a non-zero value.
2538  */
2540  }
2541 
2542  /* If success isn't 0, it means we failed somewhere (set or unset) */
2543  if (Success != 0)
2544  {
2545  return STATUS_ALREADY_COMMITTED;
2546  }
2547 
2548  return STATUS_SUCCESS;
2549 }
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING _In_opt_ PSTRING _In_ ULONG _In_ ULONG _In_opt_ PVOID _In_opt_ PVOID FilterContext
Definition: fsrtlfuncs.h:738
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define STATUS_ALREADY_COMMITTED
Definition: ntstatus.h:256
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
PVOID FilterContext
Definition: io.h:99
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define FO_FILE_OBJECT_HAS_EXTENSION
Definition: iotypes.h:144
return STATUS_SUCCESS
Definition: btrfs.c:2725
static ULONG_PTR
Definition: file.c:106

Referenced by FsRtlInsertPerFileObjectContext(), and FsRtlPTeardownPerFileObjectContexts().

◆ IoCheckQuerySetFileInformation()

NTSTATUS NTAPI IoCheckQuerySetFileInformation ( IN FILE_INFORMATION_CLASS  FileInformationClass,
IN ULONG  Length,
IN BOOLEAN  SetOperation 
)

Definition at line 2983 of file file.c.

2986 {
2987  UNIMPLEMENTED;
2988  return STATUS_NOT_IMPLEMENTED;
2989 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

◆ IoCheckQuotaBufferValidity()

NTSTATUS NTAPI IoCheckQuotaBufferValidity ( IN PFILE_QUOTA_INFORMATION  QuotaBuffer,
IN ULONG  QuotaLength,
OUT PULONG  ErrorOffset 
)

Definition at line 2996 of file file.c.

2999 {
3000  UNIMPLEMENTED;
3001  return STATUS_NOT_IMPLEMENTED;
3002 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

◆ IoCheckShareAccess()

NTSTATUS NTAPI IoCheckShareAccess ( IN ACCESS_MASK  DesiredAccess,
IN ULONG  DesiredShareAccess,
IN PFILE_OBJECT  FileObject,
IN PSHARE_ACCESS  ShareAccess,
IN BOOLEAN  Update 
)

Definition at line 3389 of file file.c.

3394 {
3397  BOOLEAN DeleteAccess;
3398  BOOLEAN SharedRead;
3399  BOOLEAN SharedWrite;
3400  BOOLEAN SharedDelete;
3401  PAGED_CODE();
3402 
3403  /* Get access masks */
3406  DeleteAccess = (DesiredAccess & DELETE) != 0;
3407 
3408  /* Set them in the file object */
3409  FileObject->ReadAccess = ReadAccess;
3410  FileObject->WriteAccess = WriteAccess;
3411  FileObject->DeleteAccess = DeleteAccess;
3412 
3413  /* Check if the file has an extension */
3415  {
3416  /* Check if caller specified to ignore access checks */
3417  //if (FileObject->FoExtFlags & IO_IGNORE_SHARE_ACCESS_CHECK)
3418  {
3419  /* Don't check share access */
3420  return STATUS_SUCCESS;
3421  }
3422  }
3423 
3424  /* Check if we have any access */
3425  if ((ReadAccess) || (WriteAccess) || (DeleteAccess))
3426  {
3427  /* Get shared access masks */
3428  SharedRead = (DesiredShareAccess & FILE_SHARE_READ) != 0;
3429  SharedWrite = (DesiredShareAccess & FILE_SHARE_WRITE) != 0;
3430  SharedDelete = (DesiredShareAccess & FILE_SHARE_DELETE) != 0;
3431 
3432  /* Set them */
3433  FileObject->SharedRead = SharedRead;
3434  FileObject->SharedWrite = SharedWrite;
3435  FileObject->SharedDelete = SharedDelete;
3436 
3437  /* Check if the shared access is violated */
3438  if ((ReadAccess &&
3439  (ShareAccess->SharedRead < ShareAccess->OpenCount)) ||
3440  (WriteAccess &&
3441  (ShareAccess->SharedWrite < ShareAccess->OpenCount)) ||
3442  (DeleteAccess &&
3443  (ShareAccess->SharedDelete < ShareAccess->OpenCount)) ||
3444  ((ShareAccess->Readers != 0) && !SharedRead) ||
3445  ((ShareAccess->Writers != 0) && !SharedWrite) ||
3446  ((ShareAccess->Deleters != 0) && !SharedDelete))
3447  {
3448  /* Sharing violation, fail */
3449  return STATUS_SHARING_VIOLATION;
3450  }
3451 
3452  /* It's not, check if caller wants us to update it */
3453  if (Update)
3454  {
3455  /* Increase open count */
3456  ShareAccess->OpenCount++;
3457 
3458  /* Update shared access */
3459  ShareAccess->Readers += ReadAccess;
3460  ShareAccess->Writers += WriteAccess;
3461  ShareAccess->Deleters += DeleteAccess;
3462  ShareAccess->SharedRead += SharedRead;
3463  ShareAccess->SharedWrite += SharedWrite;
3464  ShareAccess->SharedDelete += SharedDelete;
3465  }
3466  }
3467 
3468  /* Validation successful */
3469  return STATUS_SUCCESS;
3470 }
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#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
#define PAGED_CODE()
Definition: video.h:57
#define FILE_SHARE_READ
Definition: compat.h:125
#define STATUS_SHARING_VIOLATION
Definition: udferr_usr.h:154
#define FILE_READ_DATA
Definition: nt_native.h:628
unsigned char BOOLEAN
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define FILE_WRITE_DATA
Definition: nt_native.h:631
_In_ ULONG DesiredShareAccess
Definition: iofuncs.h:779
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define FO_FILE_OBJECT_HAS_EXTENSION
Definition: iotypes.h:144
#define FILE_EXECUTE
Definition: nt_native.h:642
_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
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define DELETE
Definition: nt_native.h:57

Referenced by Ext2CreateFile(), Ext2CreateVolume(), FatCheckShareAccess(), FFSCreateFile(), FFSCreateVolume(), open_file(), OpenMupFileSystem(), RawCreate(), RfsdCreateFile(), RfsdCreateVolume(), UDFCheckAccessRights(), and VfatCreateFile().

◆ IoCreateFile()

NTSTATUS NTAPI IoCreateFile ( OUT PHANDLE  FileHandle,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES  ObjectAttributes,
OUT PIO_STATUS_BLOCK  IoStatusBlock,
IN PLARGE_INTEGER AllocationSize  OPTIONAL,
IN ULONG  FileAttributes,
IN ULONG  ShareAccess,
IN ULONG  Disposition,
IN ULONG  CreateOptions,
IN PVOID EaBuffer  OPTIONAL,
IN ULONG  EaLength,
IN CREATE_FILE_TYPE  CreateFileType,
IN PVOID ExtraCreateParameters  OPTIONAL,
IN ULONG  Options 
)

Definition at line 3009 of file file.c.

3023 {
3024  PAGED_CODE();
3025 
3026  return IopCreateFile(FileHandle,
3027  DesiredAccess,
3029  IoStatusBlock,
3032  ShareAccess,
3033  Disposition,
3034  CreateOptions,
3035  EaBuffer,
3036  EaLength,
3038  ExtraCreateParameters,
3039  Options,
3040  0,
3041  NULL);
3042 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSTATUS NTAPI IopCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength, IN CREATE_FILE_TYPE CreateFileType, IN PVOID ExtraCreateParameters OPTIONAL, IN ULONG Options, IN ULONG Flags, IN PDEVICE_OBJECT DeviceObject OPTIONAL)
Definition: file.c:2553
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG _In_opt_ PVOID EaBuffer
Definition: iofuncs.h:835
enum OPTION_FLAGS Options
Definition: stats.c:44
_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
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
#define PAGED_CODE()
Definition: video.h:57
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG _In_opt_ PVOID _In_ ULONG _In_ CREATE_FILE_TYPE CreateFileType
Definition: iofuncs.h:835
HANDLE FileHandle
Definition: stats.c:38
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG FileAttributes
Definition: fltkernel.h:1230
IN PVCB IN PDIRENT OUT PULONG EaLength
Definition: fatprocs.h:866
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG CreateOptions
Definition: fltkernel.h:1230
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:310
_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
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75

Referenced by BroadcastOpen(), CreateRemoteDatabaseWorker(), FsRtlTest_OpenTestDirectory(), FsRtlTest_OpenTestFile(), IopOpenLinkOrRenameTarget(), KernelModeTest(), KspCreateObjectType(), NpCreatePipeEx(), NpOpenPipeEx(), NpWaitPipe(), NtCreateFile(), NtCreateMailslotFile(), NtCreateNamedPipeFile(), NtCreatePagingFile(), NtOpenFile(), OpenRemoteDatabase(), TestIoCreateFile(), TestSymlinks(), UserModeTest(), VfatSetRenameInformation(), and WdmAudOpenSysAudioDevice().

◆ IoCreateFileSpecifyDeviceObjectHint()

NTSTATUS NTAPI IoCreateFileSpecifyDeviceObjectHint ( OUT PHANDLE  FileHandle,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES  ObjectAttributes,
OUT PIO_STATUS_BLOCK  IoStatusBlock,
IN PLARGE_INTEGER AllocationSize  OPTIONAL,
IN ULONG  FileAttributes,
IN ULONG  ShareAccess,
IN ULONG  Disposition,
IN ULONG  CreateOptions,
IN PVOID EaBuffer  OPTIONAL,
IN ULONG  EaLength,
IN CREATE_FILE_TYPE  CreateFileType,
IN PVOID ExtraCreateParameters  OPTIONAL,
IN ULONG  Options,
IN PVOID  DeviceObject 
)

Definition at line 3049 of file file.c.

3064 {
3065  ULONG Flags = 0;
3066 
3067  PAGED_CODE();
3068 
3069  /* Check if we were passed a device to send the create request to*/
3070  if (DeviceObject)
3071  {
3072  /* We'll tag this request into a file object extension */
3074  }
3075 
3076  return IopCreateFile(FileHandle,
3077  DesiredAccess,
3079  IoStatusBlock,
3082  ShareAccess,
3083  Disposition,
3084  CreateOptions,
3085  EaBuffer,
3086  EaLength,
3088  ExtraCreateParameters,
3090  Flags,
3091  DeviceObject);
3092 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSTATUS NTAPI IopCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength, IN CREATE_FILE_TYPE CreateFileType, IN PVOID ExtraCreateParameters OPTIONAL, IN ULONG Options, IN ULONG Flags, IN PDEVICE_OBJECT DeviceObject OPTIONAL)
Definition: file.c:2553
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG _In_opt_ PVOID EaBuffer
Definition: iofuncs.h:835
#define IOP_USE_TOP_LEVEL_DEVICE_HINT
Definition: io.h:92
enum OPTION_FLAGS Options
Definition: stats.c:44
_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
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
#define PAGED_CODE()
Definition: video.h:57
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG _In_opt_ PVOID _In_ ULONG _In_ CREATE_FILE_TYPE CreateFileType
Definition: iofuncs.h:835
HANDLE FileHandle
Definition: stats.c:38
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define IO_NO_PARAMETER_CHECKING
Definition: iotypes.h:508
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG FileAttributes
Definition: fltkernel.h:1230
IN PVCB IN PDIRENT OUT PULONG EaLength
Definition: fatprocs.h:866
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG CreateOptions
Definition: fltkernel.h:1230
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:310
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
_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
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define IOP_CREATE_FILE_OBJECT_EXTENSION
Definition: io.h:93
unsigned int ULONG
Definition: retypes.h:1

Referenced by IopOpenLinkOrRenameTarget().

◆ IoCreateStreamFileObject()

PFILE_OBJECT NTAPI IoCreateStreamFileObject ( IN PFILE_OBJECT  FileObject,
IN PDEVICE_OBJECT  DeviceObject 
)

Definition at line 3186 of file file.c.

3188 {
3189  /* Call the newer function */
3191 }
PFILE_OBJECT NTAPI IoCreateStreamFileObjectEx(IN PFILE_OBJECT FileObject OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, OUT PHANDLE FileObjectHandle OPTIONAL)
Definition: file.c:3099
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560

Referenced by _Requires_lock_held_(), Ext2InitializeVcb(), FatOpenEaFile(), FFSInitializeVcb(), mount_vol(), NtfsFCBInitializeCache(), NtfsMountVolume(), PerformTest(), RfsdInitializeVcb(), vfatFCBInitializeCacheFromVolume(), and VfatMount().

◆ IoCreateStreamFileObjectEx()

PFILE_OBJECT NTAPI IoCreateStreamFileObjectEx ( IN PFILE_OBJECT FileObject  OPTIONAL,
IN PDEVICE_OBJECT DeviceObject  OPTIONAL,
OUT PHANDLE FileObjectHandle  OPTIONAL 
)

Definition at line 3099 of file file.c.

3102 {
3103  PFILE_OBJECT CreatedFileObject;
3104  NTSTATUS Status;
3107  PAGED_CODE();
3108  IOTRACE(IO_FILE_DEBUG, "FileObject: %p\n", FileObject);
3109 
3110  /* Choose Device Object */
3111  if (FileObject) DeviceObject = FileObject->DeviceObject;
3112 
3113  /* Reference the device object and initialize attributes */
3114  InterlockedIncrement(&DeviceObject->ReferenceCount);
3116 
3117  /* Create the File Object */
3121  KernelMode,
3122  NULL,
3123  sizeof(FILE_OBJECT),
3124  sizeof(FILE_OBJECT),
3125  0,
3126  (PVOID*)&CreatedFileObject);
3127  if (!NT_SUCCESS(Status))
3128  {
3129  /* Fail */
3132  }
3133 
3134  /* Set File Object Data */
3135  RtlZeroMemory(CreatedFileObject, sizeof(FILE_OBJECT));
3136  CreatedFileObject->DeviceObject = DeviceObject;
3137  CreatedFileObject->Type = IO_TYPE_FILE;
3138  CreatedFileObject->Size = sizeof(FILE_OBJECT);
3139  CreatedFileObject->Flags = FO_STREAM_FILE;
3140 
3141  /* Initialize the wait event */
3142  KeInitializeEvent(&CreatedFileObject->Event, SynchronizationEvent, FALSE);
3143 
3144  /* Insert it to create a handle for it */
3145  Status = ObInsertObject(CreatedFileObject,
3146  NULL,
3148  1,
3149  (PVOID*)&CreatedFileObject,
3150  &FileHandle);
3152 
3153  /* Set the handle created flag */
3154  CreatedFileObject->Flags |= FO_HANDLE_CREATED;
3155  ASSERT(CreatedFileObject->Type == IO_TYPE_FILE);
3156 
3157  /* Check if we have a VPB */
3158  if (DeviceObject->Vpb)
3159  {
3160  /* Reference it */
3161  InterlockedIncrement((PLONG)&DeviceObject->Vpb->ReferenceCount);
3162  }
3163 
3164  /* Check if the caller wants the handle */
3165  if (FileObjectHandle)
3166  {
3167  /* Return it */
3169  ObDereferenceObject(CreatedFileObject);
3170  }
3171  else
3172  {
3173  /* Otherwise, close it */
3175  }
3176 
3177  /* Return the file object */
3178  return CreatedFileObject;
3179 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define FO_HANDLE_CREATED
Definition: iotypes.h:1750
#define IO_TYPE_FILE
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IopDereferenceDeviceObject(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN ForceUnload)
Definition: device.c:462
#define ExRaiseStatus
Definition: ntoskrnl.h:95
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define PAGED_CODE()
Definition: video.h:57
#define IO_FILE_DEBUG
Definition: io.h:20
HANDLE FileHandle
Definition: stats.c:38
#define FILE_READ_DATA
Definition: nt_native.h:628
_In_opt_ PDEVICE_OBJECT _Out_opt_ PHANDLE FileObjectHandle
Definition: iofuncs.h:2170
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:952
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* PFILE_OBJECT
Definition: iotypes.h:1954
#define IOTRACE(x, fmt,...)
Definition: io.h:47
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3376
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSTATUS NTAPI ObInsertObject(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG ObjectPointerBias, OUT PVOID *NewObject OPTIONAL, OUT PHANDLE Handle)
Definition: obhandle.c:2932
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InterlockedIncrement
Definition: armddk.h:53
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
signed int * PLONG
Definition: retypes.h:5
#define FO_STREAM_FILE
Definition: iotypes.h:1739

Referenced by IoCreateStreamFileObject(), and mount_vol().

◆ IoCreateStreamFileObjectLite()

PFILE_OBJECT NTAPI IoCreateStreamFileObjectLite ( IN PFILE_OBJECT FileObject  OPTIONAL,
IN PDEVICE_OBJECT DeviceObject  OPTIONAL 
)

Definition at line 3198 of file file.c.

3200 {
3201  PFILE_OBJECT CreatedFileObject;
3202  NTSTATUS Status;
3204  PAGED_CODE();
3205  IOTRACE(IO_FILE_DEBUG, "FileObject: %p\n", FileObject);
3206 
3207  /* Choose Device Object */
3208  if (FileObject) DeviceObject = FileObject->DeviceObject;
3209 
3210  /* Reference the device object and initialize attributes */
3211  InterlockedIncrement(&DeviceObject->ReferenceCount);
3213 
3214  /* Create the File Object */
3218  KernelMode,
3219  NULL,
3220  sizeof(FILE_OBJECT),
3221  sizeof(FILE_OBJECT),
3222  0,
3223  (PVOID*)&CreatedFileObject);
3224  if (!NT_SUCCESS(Status))
3225  {
3226  /* Fail */
3229  }
3230 
3231  /* Set File Object Data */
3232  RtlZeroMemory(CreatedFileObject, sizeof(FILE_OBJECT));
3233  CreatedFileObject->DeviceObject = DeviceObject;
3234  CreatedFileObject->Type = IO_TYPE_FILE;
3235  CreatedFileObject->Size = sizeof(FILE_OBJECT);
3236  CreatedFileObject->Flags = FO_STREAM_FILE;
3237 
3238  /* Initialize the wait event */
3239  KeInitializeEvent(&CreatedFileObject->Event, SynchronizationEvent, FALSE);
3240 
3241  /* Destroy create information */
3243  ObjectCreateInfo);
3244  OBJECT_TO_OBJECT_HEADER(CreatedFileObject)->ObjectCreateInfo = NULL;
3245 
3246  /* Set the handle created flag */
3247  CreatedFileObject->Flags |= FO_HANDLE_CREATED;
3248  ASSERT(CreatedFileObject->Type == IO_TYPE_FILE);
3249 
3250  /* Check if we have a VPB */
3251  if (DeviceObject->Vpb)
3252  {
3253  /* Reference it */
3254  InterlockedIncrement((PLONG)&DeviceObject->Vpb->ReferenceCount);
3255  }
3256 
3257  /* Return the file object */
3258  return CreatedFileObject;
3259 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define FO_HANDLE_CREATED
Definition: iotypes.h:1750
#define IO_TYPE_FILE
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IopDereferenceDeviceObject(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN ForceUnload)
Definition: device.c:462
#define ExRaiseStatus
Definition: ntoskrnl.h:95
#define PAGED_CODE()
Definition: video.h:57
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
#define IO_FILE_DEBUG
Definition: io.h:20
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:952
VOID NTAPI ObFreeObjectCreateInfoBuffer(IN POBJECT_CREATE_INFORMATION ObjectCreateInfo)
Definition: oblife.c:604
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* PFILE_OBJECT
Definition: iotypes.h:1954
#define IOTRACE(x, fmt,...)
Definition: io.h:47
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InterlockedIncrement
Definition: armddk.h:53
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
signed int * PLONG
Definition: retypes.h:5
#define FO_STREAM_FILE
Definition: iotypes.h:1739

Referenced by CdCreateInternalStream(), and RawMountVolume().

◆ IoFastQueryNetworkAttributes()

BOOLEAN NTAPI IoFastQueryNetworkAttributes ( IN POBJECT_ATTRIBUTES  ObjectAttributes,
IN ACCESS_MASK  DesiredAccess,
IN ULONG  OpenOptions,
OUT PIO_STATUS_BLOCK  IoStatus,
OUT PFILE_NETWORK_OPEN_INFORMATION  Buffer 
)

Definition at line 3288 of file file.c.

3293 {
3294  NTSTATUS Status;
3295  DUMMY_FILE_OBJECT LocalFileObject;
3296  HANDLE Handle;
3297  OPEN_PACKET OpenPacket;
3298  PAGED_CODE();
3299  IOTRACE(IO_FILE_DEBUG, "FileName: %wZ\n", ObjectAttributes->ObjectName);
3300 
3301  /* Setup the Open Packet */
3302  RtlZeroMemory(&OpenPacket, sizeof(OPEN_PACKET));
3303  OpenPacket.Type = IO_TYPE_OPEN_PACKET;
3304  OpenPacket.Size = sizeof(OPEN_PACKET);
3307  OpenPacket.Options = IO_FORCE_ACCESS_CHECK;
3308  OpenPacket.Disposition = FILE_OPEN;
3309  OpenPacket.NetworkInformation = Buffer;
3310  OpenPacket.QueryOnly = TRUE;
3311  OpenPacket.FullAttributes = TRUE;
3312  OpenPacket.LocalFileObject = &LocalFileObject;
3313 
3314  /*
3315  * Attempt opening the file. This will call the I/O Parse Routine for
3316  * the File Object (IopParseDevice) which will use the dummy file obejct
3317  * send the IRP to its device object. Note that we have two statuses
3318  * to worry about: the Object Manager's status (in Status) and the I/O
3319  * status, which is in the Open Packet's Final Status, and determined
3320  * by the Parse Check member.
3321  */
3323  NULL,
3324  KernelMode,
3325  NULL,
3326  DesiredAccess,
3327  &OpenPacket,
3328  &Handle);
3329  if (OpenPacket.ParseCheck == FALSE)
3330  {
3331  /* Parse failed */
3332  IoStatus->Status = Status;
3333  }
3334  else
3335  {
3336  /* Use the Io status */
3337  IoStatus->Status = OpenPacket.FinalStatus;
3338  IoStatus->Information = OpenPacket.Information;
3339  }
3340 
3341  /* Return success */
3342  return TRUE;
3343 }
NTSTATUS NTAPI ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN OUT PVOID ParseContext, OUT PHANDLE Handle)
Definition: obhandle.c:2529
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
USHORT ShareAccess
Definition: io.h:375
#define TRUE
Definition: types.h:120
ULONG Options
Definition: io.h:378
#define IO_FORCE_ACCESS_CHECK
Definition: iotypes.h:507
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _Out_ PUINT _In_ UINT _In_ NDIS_HANDLE _In_ NDIS_HANDLE _In_ PNDIS_STRING _In_ UINT OpenOptions
Definition: ndis.h:5995
ULONG_PTR Information
Definition: io.h:368
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
#define IO_TYPE_OPEN_PACKET
struct _OPEN_PACKET OPEN_PACKET
LONG NTSTATUS
Definition: precomp.h:26
ULONG ParseCheck
Definition: io.h:369
CSHORT Type
Definition: io.h:364
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define PAGED_CODE()
Definition: video.h:57
#define FILE_SHARE_READ
Definition: compat.h:125
CSHORT Size
Definition: io.h:365
#define IO_FILE_DEBUG
Definition: io.h:20
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
BOOLEAN QueryOnly
Definition: io.h:385
PFILE_NETWORK_OPEN_INFORMATION NetworkInformation
Definition: io.h:381
#define IOTRACE(x, fmt,...)
Definition: io.h:47
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
PDUMMY_FILE_OBJECT LocalFileObject
Definition: io.h:388
_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
ULONG CreateOptions
Definition: io.h:373
BOOLEAN FullAttributes
Definition: io.h:387
ULONG Disposition
Definition: io.h:379
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
NTSTATUS FinalStatus
Definition: io.h:367
#define FILE_OPEN_REPARSE_POINT
Definition: from_kernel.h:46

◆ IoGetFileObjectFilterContext()

PVOID NTAPI IoGetFileObjectFilterContext ( IN PFILE_OBJECT  FileObject)

Definition at line 2495 of file file.c.

2496 {
2498  {
2499  PFILE_OBJECT_EXTENSION FileObjectExtension;
2500 
2501  FileObjectExtension = FileObject->FileObjectExtension;
2502  return FileObjectExtension->FilterContext;
2503  }
2504 
2505  return NULL;
2506 }
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
PVOID FilterContext
Definition: io.h:99
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define FO_FILE_OBJECT_HAS_EXTENSION
Definition: iotypes.h:144

Referenced by FsRtlInsertPerFileObjectContext(), FsRtlLookupPerFileObjectContext(), FsRtlPTeardownPerFileObjectContexts(), and FsRtlRemovePerFileObjectContext().

◆ IoGetFileObjectGenericMapping()

◆ IoIsFileOriginRemote()

BOOLEAN NTAPI IoIsFileOriginRemote ( IN PFILE_OBJECT  FileObject)

Definition at line 3277 of file file.c.

3278 {
3279  /* Return the flag status */
3280  return FileObject->Flags & FO_REMOTE_ORIGIN ? TRUE : FALSE;
3281 }
#define TRUE
Definition: types.h:120
#define FO_REMOTE_ORIGIN
Definition: iotypes.h:1755
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593

Referenced by CcCanIWrite().

◆ IopAcquireFileObjectLock()

NTSTATUS NTAPI IopAcquireFileObjectLock ( _In_ PFILE_OBJECT  FileObject,
_In_ KPROCESSOR_MODE  WaitMode,
_In_ BOOLEAN  Alertable,
_Out_ PBOOLEAN  LockFailed 
)

Definition at line 2449 of file file.c.

2454 {
2455  NTSTATUS Status;
2456 
2457  PAGED_CODE();
2458 
2460 
2462  do
2463  {
2464  if (!InterlockedExchange((PLONG)&FileObject->Busy, TRUE))
2465  {
2466  break;
2467  }
2469  Executive,
2470  WaitMode,
2471  Alertable,
2472  NULL);
2473  } while (Status == STATUS_SUCCESS);
2474 
2476  if (Status == STATUS_SUCCESS)
2477  {
2479  *LockFailed = FALSE;
2480  }
2481  else
2482  {
2483  if (!FileObject->Busy && FileObject->Waiters)
2484  {
2486  }
2487  *LockFailed = TRUE;
2488  }
2489 
2490  return Status;
2491 }
_In_ PVOID _In_ BOOLEAN Alertable
Definition: exfuncs.h:452
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define InterlockedDecrement
Definition: armddk.h:52
#define InterlockedExchange
Definition: armddk.h:54
Status
Definition: gdiplustypes.h:24
#define InterlockedIncrement
Definition: armddk.h:53
#define ObReferenceObject
Definition: obfuncs.h:204
#define IO_NO_INCREMENT
Definition: iotypes.h:565
return STATUS_SUCCESS
Definition: btrfs.c:2725
signed int * PLONG
Definition: retypes.h:5

Referenced by IopLockFileObject().

◆ IopCheckBackupRestorePrivilege()

VOID NTAPI IopCheckBackupRestorePrivilege ( IN PACCESS_STATE  AccessState,
IN OUT PULONG  CreateOptions,
IN KPROCESSOR_MODE  PreviousMode,
IN ULONG  Disposition 
)

Definition at line 25 of file file.c.

29 {
32  BOOLEAN AccessGranted, HaveBackupPriv = FALSE, CheckRestore = FALSE;
33  PAGED_CODE();
34 
35  /* Don't do anything if privileges were checked already */
36  if (AccessState->Flags & SE_BACKUP_PRIVILEGES_CHECKED) return;
37 
38  /* Check if the file was actually opened for backup purposes */
40  {
41  /* Set the check flag since were doing it now */
43 
44  /* Set the access masks required */
50  WRITE_OWNER |
55  DELETE;
56  DesiredAccess = AccessState->RemainingDesiredAccess;
57 
58  /* Check if desired access was the maximum */
60  {
61  /* Then add all the access masks required */
63  }
64 
65  /* Check if the file already exists */
66  if (Disposition & FILE_OPEN)
67  {
68  /* Check if desired access has the read mask */
70  {
71  /* Setup the privilege check lookup */
72  Privileges.PrivilegeCount = 1;
74  Privileges.Privilege[0].Luid = SeBackupPrivilege;
75  Privileges.Privilege[0].Attributes = 0;
77  &AccessState->
79  PreviousMode);
80  if (AccessGranted)
81  {
82  /* Remember that backup was allowed */
83  HaveBackupPriv = TRUE;
84 
85  /* Append the privileges and update the access state */
87  AccessState->PreviouslyGrantedAccess |= (DesiredAccess & ReadAccess);
88  AccessState->RemainingDesiredAccess &= ~ReadAccess;
90 
91  /* Set backup privilege for the token */
93  }
94  }
95  }
96  else
97  {
98  /* Caller is creating the file, check restore privileges later */
99  CheckRestore = TRUE;
100  }
101 
102  /* Check if caller wants write access or if it's creating a file */
103  if ((WriteAccess & DesiredAccess) || (CheckRestore))
104  {
105  /* Setup the privilege lookup and do it */
106  Privileges.PrivilegeCount = 1;
108  Privileges.Privilege[0].Luid = SeRestorePrivilege;
109  Privileges.Privilege[0].Attributes = 0;
111  &AccessState->SubjectSecurityContext,
112  PreviousMode);
113  if (AccessGranted)
114  {
115  /* Remember that privilege was given */
116  HaveBackupPriv = TRUE;
117 
118  /* Append the privileges and update the access state */
120  AccessState->PreviouslyGrantedAccess |= (DesiredAccess & WriteAccess);
121  AccessState->RemainingDesiredAccess &= ~WriteAccess;
122 
123  /* Set restore privilege for the token */
125  }
126  }
127 
128  /* If we don't have the privilege, remove the option */
129  if (!HaveBackupPriv) *CreateOptions &= ~FILE_OPEN_FOR_BACKUP_INTENT;
130  }
131 }
#define FILE_GENERIC_READ
Definition: nt_native.h:653
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define TRUE
Definition: types.h:120
#define ACCESS_SYSTEM_SECURITY
Definition: nt_native.h:77
const LUID SeBackupPrivilege
Definition: priv.c:38
#define WRITE_OWNER
Definition: nt_native.h:60
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
#define PAGED_CODE()
Definition: video.h:57
#define FILE_TRAVERSE
Definition: nt_native.h:643
#define FILE_ADD_FILE
Definition: nt_native.h:632
#define PRIVILEGE_SET_ALL_NECESSARY
Definition: setypes.h:83
NTSTATUS NTAPI SeAppendPrivileges(IN OUT PACCESS_STATE AccessState, IN PPRIVILEGE_SET Privileges)
Definition: priv.c:407
unsigned char BOOLEAN
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define TOKEN_HAS_RESTORE_PRIVILEGE
Definition: setypes.h:1126
const LUID SeRestorePrivilege
Definition: priv.c:39
#define WRITE_DAC
Definition: nt_native.h:59
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG CreateOptions
Definition: fltkernel.h:1230
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET * Privileges
Definition: sefuncs.h:13
#define READ_CONTROL
Definition: nt_native.h:58
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:414
#define FILE_ADD_SUBDIRECTORY
Definition: nt_native.h:635
BOOLEAN NTAPI SePrivilegeCheck(PPRIVILEGE_SET Privileges, PSECURITY_SUBJECT_CONTEXT SubjectContext, KPROCESSOR_MODE PreviousMode)
Definition: priv.c:491
#define FILE_GENERIC_WRITE
Definition: nt_native.h:660
#define FILE_OPEN
Definition: from_kernel.h:54
#define SE_BACKUP_PRIVILEGES_CHECKED
Definition: setypes.h:1133
_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
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE _In_ BOOLEAN _In_ BOOLEAN AccessGranted
Definition: sefuncs.h:414
#define FILE_OPEN_FOR_BACKUP_INTENT
Definition: from_kernel.h:42
#define TOKEN_HAS_BACKUP_PRIVILEGE
Definition: setypes.h:1125
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define DELETE
Definition: nt_native.h:57
_In_ PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext
Definition: sefuncs.h:13

Referenced by IopParseDevice().

◆ IopCheckDeviceAndDriver()

NTSTATUS NTAPI IopCheckDeviceAndDriver ( IN POPEN_PACKET  OpenPacket,
IN PDEVICE_OBJECT  DeviceObject 
)

Definition at line 135 of file file.c.

137 {
138  /* Make sure the object is valid */
139  if ((IoGetDevObjExtension(DeviceObject)->ExtensionFlags &
145  {
146  /* It's unloading or initializing, so fail */
147  DPRINT1("You are seeing this because the following ROS driver: %wZ\n"
148  " sucks. Please fix it's AddDevice Routine\n",
149  &DeviceObject->DriverObject->DriverName);
150  return STATUS_NO_SUCH_DEVICE;
151  }
152  else if ((DeviceObject->Flags & DO_EXCLUSIVE) &&
153  (DeviceObject->ReferenceCount) &&
154  !(OpenPacket->RelatedFileObject) &&
155  !(OpenPacket->Options & IO_ATTACH_DEVICE))
156  {
157  return STATUS_ACCESS_DENIED;
158  }
159 
160  else
161  {
162  /* Increase reference count */
163  InterlockedIncrement(&DeviceObject->ReferenceCount);
164  return STATUS_SUCCESS;
165  }
166 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define DOE_UNLOAD_PENDING
Definition: iotypes.h:149
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
#define IO_ATTACH_DEVICE
Definition: iotypes.h:4073
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define DOE_DELETE_PENDING
Definition: iotypes.h:150
#define DOE_REMOVE_PENDING
Definition: iotypes.h:151
#define DOE_REMOVE_PROCESSED
Definition: iotypes.h:152
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define InterlockedIncrement
Definition: armddk.h:53
#define DPRINT1
Definition: precomp.h:8
#define DO_EXCLUSIVE
Definition: env_spec_w32.h:395
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define IoGetDevObjExtension(DeviceObject)
Definition: io.h:125

Referenced by IopParseDevice().

◆ IopCheckTopDeviceHint()

NTSTATUS IopCheckTopDeviceHint ( IN OUT PDEVICE_OBJECT DeviceObject,
IN POPEN_PACKET  OpenPacket,
BOOLEAN  DirectOpen 
)

Definition at line 275 of file file.c.

278 {
281 
283 
284  /* Direct open is not allowed */
285  if (DirectOpen)
286  {
288  }
289 
290  /* Validate we have a file system device */
291  DeviceType = LocalDevice->DeviceType;
297  {
299  }
300 
301  /* Verify the hint and if it's OK, return it */
302  if (IopVerifyDeviceObjectOnStack(LocalDevice, OpenPacket->TopDeviceObjectHint))
303  {
304  *DeviceObject = OpenPacket->TopDeviceObjectHint;
305  return STATUS_SUCCESS;
306  }
307 
308  /* Failure case here */
309  /* If we thought was had come through a mount point,
310  * actually update we didn't and return the error
311  */
312  if (OpenPacket->TraversedMountPoint)
313  {
314  OpenPacket->TraversedMountPoint = FALSE;
316  }
317 
318  /* Otherwise, just return the fact the hint is invalid */
320 }
#define FILE_DEVICE_TAPE_FILE_SYSTEM
Definition: winioctl.h:137
#define FILE_DEVICE_DFS_FILE_SYSTEM
Definition: winioctl.h:158
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
DeviceType
Definition: mmdrv.h:41
BOOLEAN NTAPI IopVerifyDeviceObjectOnStack(IN PDEVICE_OBJECT BaseDeviceObject, IN PDEVICE_OBJECT TopDeviceObjectHint)
Definition: device.c:695
#define STATUS_MOUNT_POINT_NOT_RESOLVED
Definition: ntstatus.h:900
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:113
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define DEVICE_TYPE
Definition: guid.c:10
#define FILE_DEVICE_NETWORK_FILE_SYSTEM
Definition: winioctl.h:125
#define STATUS_INVALID_DEVICE_OBJECT_PARAMETER
Definition: ntstatus.h:901
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM
Definition: winioctl.h:108
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by IopParseDevice().

◆ IopCloseFile()

VOID NTAPI IopCloseFile ( IN PEPROCESS Process  OPTIONAL,
IN PVOID  ObjectBody,
IN ACCESS_MASK  GrantedAccess,
IN ULONG  HandleCount,
IN ULONG  SystemHandleCount 
)

Definition at line 2177 of file file.c.

2182 {
2183  PFILE_OBJECT FileObject = (PFILE_OBJECT)ObjectBody;
2184  KEVENT Event;
2185  PIRP Irp;
2186  PIO_STACK_LOCATION StackPtr;
2187  NTSTATUS Status;
2189  KIRQL OldIrql;
2191  IOTRACE(IO_FILE_DEBUG, "ObjectBody: %p\n", ObjectBody);
2192 
2193  /* If this isn't the last handle for the current process, quit */
2194  if (HandleCount != 1) return;
2195 
2196  /* Check if the file is locked and has more then one handle opened */
2197  if ((FileObject->LockOperation) && (SystemHandleCount != 1))
2198  {
2199  /* Check if this is a direct open or not */
2201  {
2202  /* Get the attached device */
2203  DeviceObject = IoGetAttachedDevice(FileObject->DeviceObject);
2204  }
2205  else
2206  {
2207  /* Get the FO's device */
2209  }
2210 
2211  /* Check if this is a sync FO and lock it */
2213  {
2215  }
2216 
2217  /* Go the FastIO path if possible, otherwise fall back to IRP */
2218  if (DeviceObject->DriverObject->FastIoDispatch == NULL ||
2219  DeviceObject->DriverObject->FastIoDispatch->FastIoUnlockAll == NULL ||
2220  !DeviceObject->DriverObject->FastIoDispatch->FastIoUnlockAll(FileObject, PsGetCurrentProcess(), &IoStatusBlock, DeviceObject))
2221  {
2222  /* Clear and set up Events */
2223  KeClearEvent(&FileObject->Event);
2225 
2226  /* Allocate an IRP */
2228 
2229  /* Set it up */
2230  Irp->UserEvent = &Event;
2231  Irp->UserIosb = &Irp->IoStatus;
2232  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
2233  Irp->Tail.Overlay.OriginalFileObject = FileObject;
2234  Irp->RequestorMode = KernelMode;
2235  Irp->Flags = IRP_SYNCHRONOUS_API;
2236  Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
2238 
2239  /* Set up Stack Pointer Data */
2240  StackPtr = IoGetNextIrpStackLocation(Irp);
2241  StackPtr->MajorFunction = IRP_MJ_LOCK_CONTROL;
2242  StackPtr->MinorFunction = IRP_MN_UNLOCK_ALL;
2243  StackPtr->FileObject = FileObject;
2244 
2245  /* Queue the IRP */
2247 
2248  /* Call the FS Driver */
2250  if (Status == STATUS_PENDING)
2251  {
2252  /* Wait for completion */
2254  }
2255 
2256  /* IO will unqueue & free for us */
2257  }
2258 
2259  /* Release the lock if we were holding it */
2261  {
2263  }
2264  }
2265 
2266  /* Make sure this is the last handle */
2267  if (SystemHandleCount != 1) return;
2268 
2269  /* Check if this is a direct open or not */
2270  if (FileObject->Flags & FO_DIRECT_DEVICE_OPEN)
2271  {
2272  /* Get the attached device */
2273  DeviceObject = IoGetAttachedDevice(FileObject->DeviceObject);
2274  }
2275  else
2276  {
2277  /* Get the FO's device */
2279  }
2280 
2281  /* Set the handle created flag */
2282  FileObject->Flags |= FO_HANDLE_CREATED;
2283 
2284  /* Check if this is a sync FO and lock it */
2285  if (Process != NULL &&
2287  {
2289  }
2290 
2291  /* Clear and set up Events */
2292  KeClearEvent(&FileObject->Event);
2294 
2295  /* Allocate an IRP */
2297 
2298  /* Set it up */
2299  Irp->UserEvent = &Event;
2300  Irp->UserIosb = &Irp->IoStatus;
2301  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
2302  Irp->Tail.Overlay.OriginalFileObject = FileObject;
2303  Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
2305 
2306  /* Set up Stack Pointer Data */
2307  StackPtr = IoGetNextIrpStackLocation(Irp);
2308  StackPtr->MajorFunction = IRP_MJ_CLEANUP;
2309  StackPtr->FileObject = FileObject;
2310 
2311  /* Queue the IRP */
2313 
2314  /* Update operation counts */
2316 
2317  /* Call the FS Driver */
2319  if (Status == STATUS_PENDING)
2320  {
2321  /* Wait for completion */
2323  }
2324 
2325  /* Unqueue the IRP */
2329 
2330  /* Free the IRP */
2331  IoFreeIrp(Irp);
2332 
2333  /* Release the lock if we were holding it */
2334  if (Process != NULL &&
2336  {
2338  }
2339 }
#define FO_HANDLE_CREATED
Definition: iotypes.h:1750
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define IRP_CLOSE_OPERATION
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define FO_DIRECT_DEVICE_OPEN
Definition: iotypes.h:1743
_In_ PIRP Irp
Definition: csq.h:116
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1538
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1732
#define IO_FILE_DEBUG
Definition: io.h:20
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
#define PsGetCurrentProcess
Definition: psfuncs.h:17
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE VOID IopQueueIrpToThread(IN PIRP Irp)
Definition: io_x.h:49
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
PIRP NTAPI IopAllocateIrpMustSucceed(IN CCHAR StackSize)
Definition: irp.c:716
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MN_UNLOCK_ALL
Definition: iotypes.h:4055
* PFILE_OBJECT
Definition: iotypes.h:1954
#define IOTRACE(x, fmt,...)
Definition: io.h:47
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
FORCEINLINE VOID IopUnQueueIrpFromThread(IN PIRP Irp)
Definition: io_x.h:65
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
PDEVICE_OBJECT NTAPI IoGetAttachedDevice(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1384
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
static __inline VOID IopUnlockFileObject(IN PFILE_OBJECT FileObject)
Definition: io_x.h:36
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define IRP_MJ_CLEANUP
#define ObReferenceObject
Definition: obfuncs.h:204
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
static __inline VOID IopUpdateOperationCount(IN IOP_TRANSFER_TYPE Type)
Definition: io_x.h:77
#define IRP_SYNCHRONOUS_API
static VOID(WINAPI *pRtlFreeUnicodeString)(PUNICODE_STRING)
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define APC_LEVEL
Definition: env_spec_w32.h:695

Referenced by IopCreateObjectTypes(), and IopDeleteFile().

◆ IopCreateFile()

NTSTATUS NTAPI IopCreateFile ( OUT PHANDLE  FileHandle,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES  ObjectAttributes,
OUT PIO_STATUS_BLOCK  IoStatusBlock,
IN PLARGE_INTEGER AllocationSize  OPTIONAL,
IN ULONG  FileAttributes,
IN ULONG  ShareAccess,
IN ULONG  Disposition,
IN ULONG  CreateOptions,
IN PVOID EaBuffer  OPTIONAL,
IN ULONG  EaLength,
IN CREATE_FILE_TYPE  CreateFileType,
IN PVOID ExtraCreateParameters  OPTIONAL,
IN ULONG  Options,
IN ULONG  Flags,
IN PDEVICE_OBJECT DeviceObject  OPTIONAL 
)

Definition at line 2553 of file file.c.

2569 {
2571  HANDLE LocalHandle = 0;
2572  LARGE_INTEGER SafeAllocationSize;
2574  PNAMED_PIPE_CREATE_PARAMETERS NamedPipeCreateParameters;
2575  POPEN_PACKET OpenPacket;
2576  ULONG EaErrorOffset;
2577  PAGED_CODE();
2578 
2579  IOTRACE(IO_FILE_DEBUG, "FileName: %wZ\n", ObjectAttributes->ObjectName);
2580 
2581 
2582  /* Check if we have no parameter checking to do */
2584  {
2585  /* Then force kernel-mode access to avoid checks */
2587  }
2588  else
2589  {
2590  /* Otherwise, use the actual mode */
2592  }
2593 
2594  /* Check if we need to do parameter checking */
2596  {
2597  /* Validate parameters */
2599  {
2600  DPRINT1("File Create 'FileAttributes' Parameter contains invalid flags!\n");
2601  return STATUS_INVALID_PARAMETER;
2602  }
2603 
2605  {
2606  DPRINT1("File Create 'ShareAccess' Parameter contains invalid flags!\n");
2607  return STATUS_INVALID_PARAMETER;
2608  }
2609 
2611  {
2612  DPRINT1("File Create 'Disposition' Parameter is out of range!\n");
2613  return STATUS_INVALID_PARAMETER;
2614  }
2615 
2617  {
2618  DPRINT1("File Create 'CreateOptions' parameter contains invalid flags!\n");
2619  return STATUS_INVALID_PARAMETER;
2620  }
2621 
2623  (!(DesiredAccess & SYNCHRONIZE)))
2624  {
2625  DPRINT1("File Create 'CreateOptions' parameter FILE_SYNCHRONOUS_IO_* requested, but 'DesiredAccess' does not have SYNCHRONIZE!\n");
2626  return STATUS_INVALID_PARAMETER;
2627  }
2628 
2630  {
2631  DPRINT1("File Create 'CreateOptions' parameter FILE_DELETE_ON_CLOSE requested, but 'DesiredAccess' does not have DELETE!\n");
2632  return STATUS_INVALID_PARAMETER;
2633  }
2634 
2637  {
2638  DPRINT1("File Create 'FileAttributes' parameter both FILE_SYNCHRONOUS_IO_NONALERT and FILE_SYNCHRONOUS_IO_ALERT specified!\n");
2639  return STATUS_INVALID_PARAMETER;
2640  }
2641 
2654  {
2655  DPRINT1("File Create 'CreateOptions' Parameter has flags incompatible with FILE_DIRECTORY_FILE!\n");
2656  return STATUS_INVALID_PARAMETER;
2657  }
2658 
2661  {
2662  DPRINT1("File Create 'CreateOptions' Parameter FILE_DIRECTORY_FILE requested, but 'Disposition' is not FILE_CREATE/FILE_OPEN/FILE_OPEN_IF!\n");
2663  return STATUS_INVALID_PARAMETER;
2664  }
2665 
2667  {
2668  DPRINT1("File Create 'CreateOptions' Parameter both FILE_COMPLETE_IF_OPLOCKED and FILE_RESERVE_OPFILTER specified!\n");
2669  return STATUS_INVALID_PARAMETER;
2670  }
2671 
2673  {
2674  DPRINT1("File Create 'CreateOptions' parameter FILE_NO_INTERMEDIATE_BUFFERING requested, but 'DesiredAccess' FILE_APPEND_DATA requires it!\n");
2675  return STATUS_INVALID_PARAMETER;
2676  }
2677 
2678  /* Now check if this is a named pipe */
2680  {
2681  /* Make sure we have extra parameters */
2682  if (!ExtraCreateParameters)
2683  {
2684  DPRINT1("Invalid parameter: ExtraCreateParameters == 0!\n");
2685  return STATUS_INVALID_PARAMETER;
2686  }
2687 
2688  /* Get the parameters and validate them */
2689  NamedPipeCreateParameters = ExtraCreateParameters;
2690  if ((NamedPipeCreateParameters->NamedPipeType > FILE_PIPE_MESSAGE_TYPE) ||
2691  (NamedPipeCreateParameters->ReadMode > FILE_PIPE_MESSAGE_MODE) ||
2692  (NamedPipeCreateParameters->CompletionMode > FILE_PIPE_COMPLETE_OPERATION) ||
2696  {
2697  /* Invalid named pipe create */
2698  DPRINT1("Invalid named pipe create\n");
2699  return STATUS_INVALID_PARAMETER;
2700  }
2701  }
2703  {
2704  /* Make sure we have extra parameters */
2705  if (!ExtraCreateParameters)
2706  {
2707  DPRINT1("Invalid parameter: ExtraCreateParameters == 0!\n");
2708  return STATUS_INVALID_PARAMETER;
2709  }
2710 
2711  /* Get the parameters and validate them */
2712  if ((ShareAccess & FILE_SHARE_DELETE) ||
2713  !(ShareAccess & ~FILE_SHARE_WRITE) ||
2714  (Disposition != FILE_CREATE) ||
2716  {
2717  /* Invalid mailslot create */
2718  DPRINT1("Invalid mailslot create\n");
2719  return STATUS_INVALID_PARAMETER;
2720  }
2721  }
2722  }
2723 
2724  /* Allocate the open packet */
2725  OpenPacket = ExAllocatePoolWithTag(NonPagedPool, sizeof(*OpenPacket), 'pOoI');
2726  if (!OpenPacket) return STATUS_INSUFFICIENT_RESOURCES;
2727  RtlZeroMemory(OpenPacket, sizeof(*OpenPacket));
2728 
2729  /* Check if the call came from user mode */
2730  if (AccessMode != KernelMode)
2731  {
2732  _SEH2_TRY
2733  {
2734  /* Probe the output parameters */
2737 
2738  /* Probe the allocation size if one was passed in */
2739  if (AllocationSize)
2740  {
2741  SafeAllocationSize = ProbeForReadLargeInteger(AllocationSize);
2742  }
2743  else
2744  {
2745  SafeAllocationSize.QuadPart = 0;
2746  }
2747 
2748  /* Make sure it's valid */
2749  if (SafeAllocationSize.QuadPart < 0)
2750  {
2752  }
2753 
2754  /* Check if EA was passed in */
2755  if ((EaBuffer) && (EaLength))
2756  {
2757  /* Probe it */
2758  ProbeForRead(EaBuffer, EaLength, sizeof(ULONG));
2759 
2760  /* And marshall it */
2762  EaLength,
2763  TAG_EA);
2764  OpenPacket->EaLength = EaLength;
2765  RtlCopyMemory(OpenPacket->EaBuffer, EaBuffer, EaLength);
2766 
2767  /* Validate the buffer */
2768  Status = IoCheckEaBufferValidity(OpenPacket->EaBuffer,
2769  EaLength,
2770  &EaErrorOffset);
2771  if (!NT_SUCCESS(Status))
2772  {
2773  /* Undo everything if it's invalid */
2774  DPRINT1("Invalid EA buffer\n");
2776  IoStatusBlock->Information = EaErrorOffset;
2778  }
2779  }
2780  }
2782  {
2783  /* Return the exception code */
2784  if (OpenPacket->EaBuffer != NULL) ExFreePool(OpenPacket->EaBuffer);
2785  ExFreePool(OpenPacket);
2787  }
2788  _SEH2_END;
2789  }
2790  else
2791  {
2792  /* Check if this is a device attach */
2794  {
2795  /* Set the flag properly */
2798  }
2799 
2800  /* Check if we have allocation size */
2801  if (AllocationSize)
2802  {
2803  /* Capture it */
2804  SafeAllocationSize = *AllocationSize;
2805  }
2806  else
2807  {
2808  /* Otherwise, no size */
2809  SafeAllocationSize.QuadPart = 0;
2810  }
2811 
2812  /* Check if we have an EA packet */
2813  if ((EaBuffer) && (EaLength))
2814  {
2815  /* Allocate the kernel copy */
2817  EaLength,
2818  TAG_EA);
2819  if (!OpenPacket->EaBuffer)
2820  {
2821  ExFreePool(OpenPacket);
2822  DPRINT1("Failed to allocate open packet EA buffer\n");
2824  }
2825 
2826  /* Copy the data */
2827  OpenPacket->EaLength = EaLength;
2828  RtlCopyMemory(OpenPacket->EaBuffer, EaBuffer, EaLength);
2829 
2830  /* Validate the buffer */
2831  Status = IoCheckEaBufferValidity(OpenPacket->EaBuffer,
2832  EaLength,
2833  &EaErrorOffset);
2834  if (!NT_SUCCESS(Status))
2835  {
2836  /* Undo everything if it's invalid */
2837  DPRINT1("Invalid EA buffer\n");
2838  ExFreePool(OpenPacket->EaBuffer);
2840  IoStatusBlock->Information = EaErrorOffset;
2841  ExFreePool(OpenPacket);
2842  return Status;
2843  }
2844  }
2845  }
2846 
2847  /* Setup the Open Packet */
2848  OpenPacket->Type = IO_TYPE_OPEN_PACKET;
2849  OpenPacket->Size = sizeof(*OpenPacket);
2850  OpenPacket->AllocationSize = SafeAllocationSize;
2851  OpenPacket->CreateOptions = CreateOptions;
2852  OpenPacket->FileAttributes = (USHORT)FileAttributes;
2853  OpenPacket->ShareAccess = (USHORT)ShareAccess;
2854  OpenPacket->Options = Options;
2855  OpenPacket->Disposition = Disposition;
2856  OpenPacket->CreateFileType = CreateFileType;
2857  OpenPacket->ExtraCreateParameters = ExtraCreateParameters;
2858  OpenPacket->InternalFlags = Flags;
2859  OpenPacket->TopDeviceObjectHint = DeviceObject;
2860 
2861  /* Update the operation count */
2863 
2864  /*
2865  * Attempt opening the file. This will call the I/O Parse Routine for
2866  * the File Object (IopParseDevice) which will create the object and
2867  * send the IRP to its device object. Note that we have two statuses
2868  * to worry about: the Object Manager's status (in Status) and the I/O
2869  * status, which is in the Open Packet's Final Status, and determined
2870  * by the Parse Check member.
2871  */
2873  NULL,
2874  AccessMode,
2875  NULL,
2876  DesiredAccess,
2877  OpenPacket,
2878  &LocalHandle);
2879 
2880  /* Free the EA Buffer */
2881  if (OpenPacket->EaBuffer) ExFreePool(OpenPacket->EaBuffer);
2882 
2883  /* Now check for Ob or Io failure */
2884  if (!(NT_SUCCESS(Status)) || (OpenPacket->ParseCheck == FALSE))
2885  {
2886  /* Check if Ob thinks well went well */
2887  if (NT_SUCCESS(Status))
2888  {
2889  /*
2890  * Tell it otherwise. Because we didn't use an ObjectType,
2891  * it incorrectly returned us a handle to God knows what.
2892  */
2895  }
2896 
2897  /* Now check the Io status */
2898  if (!NT_SUCCESS(OpenPacket->FinalStatus))
2899  {
2900  /* Use this status instead of Ob's */
2901  Status = OpenPacket->FinalStatus;
2902 
2903  /* Check if it was only a warning */
2904  if (NT_WARNING(Status))
2905  {
2906  /* Protect write with SEH */
2907  _SEH2_TRY
2908  {
2909  /* In this case, we copy the I/O Status back */
2910  IoStatusBlock->Information = OpenPacket->Information;
2911  IoStatusBlock->Status = OpenPacket->FinalStatus;
2912  }
2914  {
2915  /* Get exception code */
2917  }
2918  _SEH2_END;
2919  }
2920  }
2921  else if ((OpenPacket->FileObject) && (OpenPacket->ParseCheck == FALSE))
2922  {
2923  /*
2924  * This can happen in the very bizarre case where the parse routine
2925  * actually executed more then once (due to a reparse) and ended
2926  * up failing after already having created the File Object.
2927  */
2928  if (OpenPacket->FileObject->FileName.Length)
2929  {
2930  /* It had a name, free it */
2931  ExFreePoolWithTag(OpenPacket->FileObject->FileName.Buffer, TAG_IO_NAME);
2932  }
2933 
2934  /* Clear the device object to invalidate the FO, and dereference */
2935  OpenPacket->FileObject->DeviceObject = NULL;
2936  ObDereferenceObject(OpenPacket->FileObject);
2937  }
2938  }
2939  else
2940  {
2941  /* We reached success and have a valid file handle */
2942  OpenPacket->FileObject->Flags |= FO_HANDLE_CREATED;
2943  ASSERT(OpenPacket->FileObject->Type == IO_TYPE_FILE);
2944 
2945  /* Enter SEH for write back */
2946  _SEH2_TRY
2947  {
2948  /* Write back the handle and I/O Status */
2950  IoStatusBlock->Information = OpenPacket->Information;
2951  IoStatusBlock->Status = OpenPacket->FinalStatus;
2952 
2953  /* Get the Io status */
2954  Status = OpenPacket->FinalStatus;
2955  }
2957  {
2958  /* Get the exception status */
2960  }
2961  _SEH2_END;
2962  }
2963 
2964  /* Check if we were 100% successful */
2965  if ((OpenPacket->ParseCheck != FALSE) && (OpenPacket->FileObject))
2966  {
2967  /* Dereference the File Object */
2968  ObDereferenceObject(OpenPacket->FileObject);
2969  }
2970 
2971  /* Return status */
2972  ExFreePool(OpenPacket);
2973  return Status;
2974 }
NTSTATUS NTAPI ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN OUT PVOID ParseContext, OUT PHANDLE Handle)
Definition: obhandle.c:2529
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define FO_HANDLE_CREATED
Definition: iotypes.h:1750
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
#define FILE_NO_COMPRESSION
Definition: from_kernel.h:43
#define ProbeForWriteIoStatusBlock(Ptr)
Definition: probe.h:52
USHORT ShareAccess
Definition: io.h:375
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ULONG Options
Definition: io.h:378
#define FILE_OPEN_IF
Definition: from_kernel.h:56
ULONG_PTR Information
Definition: io.h:368
#define FILE_VALID_MAILSLOT_OPTION_FLAGS
Definition: nt_native.h:761
ULONG EaLength
Definition: io.h:377
#define IO_TYPE_FILE
#define TAG_IO_NAME
Definition: tag.h:72
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define IO_TYPE_OPEN_PACKET
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
#define FILE_ATTRIBUTE_VALID_FLAGS
Definition: nt_native.h:714
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG _In_opt_ PVOID EaBuffer
Definition: iofuncs.h:835
LONG NTSTATUS
Definition: precomp.h:26
ULONG ParseCheck
Definition: io.h:369
PVOID ExtraCreateParameters
Definition: io.h:383
#define FILE_CREATE
Definition: from_kernel.h:55
LARGE_INTEGER AllocationSize
Definition: io.h:372
#define FILE_PIPE_MESSAGE_TYPE
Definition: iotypes.h:76
CSHORT Type
Definition: io.h:364
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2966
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_APPEND_DATA
Definition: nt_native.h:634
enum OPTION_FLAGS Options
Definition: stats.c:44
#define FILE_RESERVE_OPFILTER
Definition: from_kernel.h:45
_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
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
#define FILE_VALID_OPTION_FLAGS
Definition: nt_native.h:759
#define PAGED_CODE()
Definition: video.h:57
#define FILE_OPEN_BY_FILE_ID
Definition: from_kernel.h:41
_SEH2_TRY
Definition: create.c:4250
CSHORT Size
Definition: io.h:365
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG _In_opt_ PVOID _In_ ULONG _In_ CREATE_FILE_TYPE CreateFileType
Definition: iofuncs.h:835
PFILE_OBJECT FileObject
Definition: io.h:366
PVOID EaBuffer
Definition: io.h:376
#define NT_WARNING(Status)
Definition: umtypes.h:105
#define IO_FILE_DEBUG
Definition: io.h:20
HANDLE FileHandle
Definition: stats.c:38
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
#define FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
CREATE_FILE_TYPE CreateFileType
Definition: io.h:382
#define IO_NO_PARAMETER_CHECKING
Definition: iotypes.h:508
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define FILE_WRITE_THROUGH
Definition: from_kernel.h:26
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI IoCheckEaBufferValidity(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: util.c:191
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG FileAttributes
Definition: fltkernel.h:1230
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: ntstatus.h:259
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
IN PVCB IN PDIRENT OUT PULONG EaLength
Definition: fatprocs.h:866
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
USHORT FileAttributes
Definition: io.h:374
#define IO_ATTACH_DEVICE
Definition: iotypes.h:4073
#define IO_ATTACH_DEVICE_API
Definition: iotypes.h:209
#define ProbeForWriteHandle(Ptr)
Definition: probe.h:43
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG CreateOptions
Definition: fltkernel.h:1230
ULONG InternalFlags
Definition: io.h:390
#define ProbeForReadLargeInteger(Ptr)
Definition: probe.h:75
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define IOTRACE(x, fmt,...)
Definition: io.h:47
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define FILE_PIPE_COMPLETE_OPERATION
Definition: iotypes.h:80
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_SHARE_VALID_FLAGS
Definition: nt_native.h:683
#define FILE_VALID_PIPE_OPTION_FLAGS
Definition: nt_native.h:760
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:310
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
_SEH2_END
Definition: create.c:4424
#define FILE_OPEN_FOR_FREE_SPACE_QUERY
Definition: constants.h:495
unsigned short USHORT
Definition: pedump.c:61
#define FILE_PIPE_MESSAGE_MODE
Definition: iotypes.h:78
_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 FILE_OPEN_FOR_BACKUP_INTENT
Definition: from_kernel.h:42
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define DPRINT1
Definition: precomp.h:8
ULONG CreateOptions
Definition: io.h:373
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define FILE_MAXIMUM_DISPOSITION
Definition: from_kernel.h:59
#define TAG_EA
Definition: tag.h:71
static __inline VOID IopUpdateOperationCount(IN IOP_TRANSFER_TYPE Type)
Definition: io_x.h:77
ULONG Disposition
Definition: io.h:379
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
HLOCAL NTAPI LocalHandle(LPCVOID pMem)
Definition: heapmem.c:1588
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
PDEVICE_OBJECT TopDeviceObjectHint
Definition: io.h:391
return STATUS_SUCCESS
Definition: btrfs.c:2725
NTSTATUS FinalStatus
Definition: io.h:367
#define FILE_OPEN_REPARSE_POINT
Definition: from_kernel.h:46
#define FILE_COMPLETE_IF_OPLOCKED
Definition: constants.h:493
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define DELETE
Definition: nt_native.h:57
LONGLONG QuadPart
Definition: typedefs.h:112
#define IO_CHECK_CREATE_PARAMETERS
Definition: iotypes.h:4072

Referenced by IoCreateFile(), and IoCreateFileSpecifyDeviceObjectHint().

◆ IopDeleteFile()

VOID NTAPI IopDeleteFile ( IN PVOID  ObjectBody)

Definition at line 1354 of file file.c.

1355 {
1356  PFILE_OBJECT FileObject = (PFILE_OBJECT)ObjectBody;
1357  PIRP Irp;
1358  PIO_STACK_LOCATION StackPtr;
1359  NTSTATUS Status;
1360  KEVENT Event;
1362  BOOLEAN DereferenceDone = FALSE;
1363  PVPB Vpb;
1364  KIRQL OldIrql;
1365  IOTRACE(IO_FILE_DEBUG, "ObjectBody: %p\n", ObjectBody);
1366 
1367  /* Check if the file has a device object */
1368  if (FileObject->DeviceObject)
1369  {
1370  /* Check if this is a direct open or not */
1371  if (FileObject->Flags & FO_DIRECT_DEVICE_OPEN)
1372  {
1373  /* Get the attached device */
1374  DeviceObject = IoGetAttachedDevice(FileObject->DeviceObject);
1375  }
1376  else
1377  {
1378  /* Use the file object's device object */
1380  }
1381 
1382  /* Sanity check */
1383  ASSERT(!(FileObject->Flags & FO_SYNCHRONOUS_IO) ||
1384  (InterlockedExchange((PLONG)&FileObject->Busy, TRUE) == FALSE));
1385 
1386  /* Check if the handle wasn't created yet */
1387  if (!(FileObject->Flags & FO_HANDLE_CREATED))
1388  {
1389  /* Send the cleanup IRP */
1390  IopCloseFile(NULL, ObjectBody, 0, 1, 1);
1391  }
1392 
1393  /* Clear and set up Events */
1394  KeClearEvent(&FileObject->Event);
1396 
1397  /* Allocate an IRP */
1399 
1400  /* Set it up */
1401  Irp->UserEvent = &Event;
1402  Irp->UserIosb = &Irp->IoStatus;
1403  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
1404  Irp->Tail.Overlay.OriginalFileObject = FileObject;
1406 
1407  /* Set up Stack Pointer Data */
1408  StackPtr = IoGetNextIrpStackLocation(Irp);
1409  StackPtr->MajorFunction = IRP_MJ_CLOSE;
1410  StackPtr->FileObject = FileObject;
1411 
1412  /* Queue the IRP */
1414 
1415  /* Get the VPB and check if this isn't a direct open */
1416  Vpb = FileObject->Vpb;
1417  if ((Vpb) && !(FileObject->Flags & FO_DIRECT_DEVICE_OPEN))
1418  {
1419  /* Dereference the VPB before the close */
1420  InterlockedDecrement((PLONG)&Vpb->ReferenceCount);
1421  }
1422 
1423  /* Check if the FS will never disappear by itself */
1424  if (FileObject->DeviceObject->Flags & DO_NEVER_LAST_DEVICE)
1425  {
1426  /* Dereference it */
1427  InterlockedDecrement(&FileObject->DeviceObject->ReferenceCount);
1428  DereferenceDone = TRUE;
1429  }
1430 
1431  /* Call the FS Driver */
1433  if (Status == STATUS_PENDING)
1434  {
1435  /* Wait for completion */
1437  }
1438 
1439  /* De-queue the IRP */
1443 
1444  /* Free the IRP */
1445  IoFreeIrp(Irp);
1446 
1447  /* Clear the file name */
1448  if (FileObject->FileName.Buffer)
1449  {
1450  /*
1451  * Don't use TAG_IO_NAME since the FileObject's FileName
1452  * may have been re-allocated using a different tag
1453  * by a filesystem.
1454  */
1455  ExFreePoolWithTag(FileObject->FileName.Buffer, 0);
1456  FileObject->FileName.Buffer = NULL;
1457  }
1458 
1459  /* Check if the FO had a completion port */
1460  if (FileObject->CompletionContext)
1461  {
1462  /* Free it */
1463  ObDereferenceObject(FileObject->CompletionContext->Port);
1464  ExFreePool(FileObject->CompletionContext);
1465  }
1466 
1467  /* Check if the FO had extension */
1469  {
1470  /* Release filter context structure if any */
1472  }
1473 
1474  /* Check if dereference has been done yet */
1475  if (!DereferenceDone)
1476  {
1477  /* Dereference device object */
1479  }
1480  }
1481 }
#define FO_HANDLE_CREATED
Definition: iotypes.h:1750
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define TRUE
Definition: types.h:120
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define IRP_CLOSE_OPERATION
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
VOID NTAPI FsRtlPTeardownPerFileObjectContexts(IN PFILE_OBJECT FileObject)
Definition: filtrctx.c:28
#define FO_DIRECT_DEVICE_OPEN
Definition: iotypes.h:1743
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IopDereferenceDeviceObject(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN ForceUnload)
Definition: device.c:462
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1538
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1732
#define IO_FILE_DEBUG
Definition: io.h:20
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE VOID IopQueueIrpToThread(IN PIRP Irp)
Definition: io_x.h:49
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
PIRP NTAPI IopAllocateIrpMustSucceed(IN CCHAR StackSize)
Definition: irp.c:716
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID NTAPI IopCloseFile(IN PEPROCESS Process OPTIONAL, IN PVOID ObjectBody, IN ACCESS_MASK GrantedAccess, IN ULONG HandleCount, IN ULONG SystemHandleCount)
Definition: file.c:2177
#define DO_NEVER_LAST_DEVICE
Definition: env_spec_w32.h:402
* PFILE_OBJECT
Definition: iotypes.h:1954
#define IOTRACE(x, fmt,...)
Definition: io.h:47
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define InterlockedDecrement
Definition: armddk.h:52
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define FO_FILE_OBJECT_HAS_EXTENSION
Definition: iotypes.h:144
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
#define InterlockedExchange
Definition: armddk.h:54
Status
Definition: gdiplustypes.h:24
FORCEINLINE VOID IopUnQueueIrpFromThread(IN PIRP Irp)
Definition: io_x.h:65
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
PDEVICE_OBJECT NTAPI IoGetAttachedDevice(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1384
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
Definition: iotypes.h:166
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define IRP_SYNCHRONOUS_API
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
signed int * PLONG
Definition: retypes.h:5
#define APC_LEVEL
Definition: env_spec_w32.h:695
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1664
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by IopCreateObjectTypes(), and IopParseDevice().

◆ IopDoNameTransmogrify()

VOID NTAPI IopDoNameTransmogrify ( IN PIRP  Irp,
IN PFILE_OBJECT  FileObject,
IN PREPARSE_DATA_BUFFER  DataBuffer 
)

Definition at line 170 of file file.c.

173 {
174  PWSTR Buffer;
175  USHORT Length;
177  PWSTR NewBuffer;
178 
179  PAGED_CODE();
180 
181  ASSERT(Irp->IoStatus.Status == STATUS_REPARSE);
182  ASSERT(Irp->IoStatus.Information == IO_REPARSE_TAG_MOUNT_POINT);
183  ASSERT(Irp->Tail.Overlay.AuxiliaryBuffer != NULL);
184  ASSERT(DataBuffer != NULL);
185  ASSERT(DataBuffer->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT);
186  ASSERT(DataBuffer->ReparseDataLength < MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
187  ASSERT(DataBuffer->Reserved < MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
188 
189  /* First of all, validate data */
190  if (DataBuffer->ReparseDataLength < REPARSE_DATA_BUFFER_HEADER_SIZE ||
191  (DataBuffer->SymbolicLinkReparseBuffer.PrintNameLength +
192  DataBuffer->SymbolicLinkReparseBuffer.SubstituteNameLength +
194  {
195  Irp->IoStatus.Status = STATUS_IO_REPARSE_DATA_INVALID;
196  }
197 
198  /* Everything went right */
199  if (NT_SUCCESS(Irp->IoStatus.Status))
200  {
201  /* Compute buffer & length */
202  Buffer = (PWSTR)((ULONG_PTR)DataBuffer->MountPointReparseBuffer.PathBuffer +
203  DataBuffer->MountPointReparseBuffer.SubstituteNameOffset);
204  Length = DataBuffer->MountPointReparseBuffer.SubstituteNameLength;
205 
206  /* Check we don't overflow */
207  if (((ULONG)MAXUSHORT - DataBuffer->Reserved) <= (Length + sizeof(UNICODE_NULL)))
208  {
209  Irp->IoStatus.Status = STATUS_IO_REPARSE_DATA_INVALID;
210  }
211  else
212  {
213  /* Compute how much memory we'll need */
214  RequiredLength = DataBuffer->Reserved + Length + sizeof(UNICODE_NULL);
215 
216  /* Check if FileObject can already hold what we need */
217  if (FileObject->FileName.MaximumLength >= RequiredLength)
218  {
219  NewBuffer = FileObject->FileName.Buffer;
220  }
221  else
222  {
223  /* Allocate otherwise */
225  if (NewBuffer == NULL)
226  {
227  Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
228  }
229  }
230  }
231  }
232 
233  /* Everything went right */
234  if (NT_SUCCESS(Irp->IoStatus.Status))
235  {
236  /* Copy the reserved data */
237  if (DataBuffer->Reserved)
238  {
239  RtlMoveMemory((PWSTR)((ULONG_PTR)NewBuffer + Length),
240  (PWSTR)((ULONG_PTR)FileObject->FileName.Buffer + FileObject->FileName.Length - DataBuffer->Reserved),
241  DataBuffer->Reserved);
242  }
243 
244  /* Then the buffer */
245  if (Length)
246  {
247  RtlCopyMemory(NewBuffer, Buffer, Length);
248  }
249 
250  /* And finally replace buffer if new one was allocated */
251  FileObject->FileName.Length = RequiredLength - sizeof(UNICODE_NULL);
252  if (NewBuffer != FileObject->FileName.Buffer)
253  {
254  if (FileObject->FileName.Buffer)
255  {
256  /*
257  * Don't use TAG_IO_NAME since the FileObject's FileName
258  * may have been re-allocated using a different tag
259  * by a filesystem.
260  */
261  ExFreePoolWithTag(FileObject->FileName.Buffer, 0);
262  }
263 
264  FileObject->FileName.Buffer = NewBuffer;
265  FileObject->FileName.MaximumLength = RequiredLength;
266  FileObject->FileName.Buffer[RequiredLength / sizeof(WCHAR) - 1] = UNICODE_NULL;
267  }
268  }
269 
270  /* We don't need them anymore - it was allocated by the driver */
271  ExFreePool(DataBuffer);
272 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define TAG_IO_NAME
Definition: tag.h:72
_In_ PIRP Irp
Definition: csq.h:116
uint16_t * PWSTR
Definition: typedefs.h:54
#define PAGED_CODE()
Definition: video.h:57
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define IO_REPARSE_TAG_MOUNT_POINT
Definition: iotypes.h:6874
WCHAR PathBuffer[1]
Definition: shellext.h:152
#define UNICODE_NULL
#define STATUS_IO_REPARSE_DATA_INVALID
Definition: ntstatus.h:742
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define REPARSE_DATA_BUFFER_HEADER_SIZE
Definition: iotypes.h:6842
unsigned short USHORT
Definition: pedump.c:61
_In_ ULONG _Out_opt_ PULONG RequiredLength
Definition: wmifuncs.h:29
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define STATUS_REPARSE
Definition: ntstatus.h:83
#define MAXUSHORT
Definition: typedefs.h:81
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define MAXIMUM_REPARSE_DATA_BUFFER_SIZE
Definition: iotypes.h:6856
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by IopCompleteRequest(), and IopParseDevice().

◆ IopGetDeviceAttachmentBase()

PDEVICE_OBJECT NTAPI IopGetDeviceAttachmentBase ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 1485 of file file.c.

1486 {
1488 
1489  /* Go down the stack to attempt to get the PDO */
1490  for (; ((PEXTENDED_DEVOBJ_EXTENSION)PDO->DeviceObjectExtension)->AttachedTo != NULL;
1491  PDO = ((PEXTENDED_DEVOBJ_EXTENSION)PDO->DeviceObjectExtension)->AttachedTo);
1492 
1493  return PDO;
1494 }
struct _EXTENDED_DEVOBJ_EXTENSION * PEXTENDED_DEVOBJ_EXTENSION
smooth NULL
Definition: ftsmooth.c:416
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560

Referenced by IopGetDevicePDO().

◆ IopGetDevicePDO()

PDEVICE_OBJECT NTAPI IopGetDevicePDO ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 1498 of file file.c.

1499 {
1500  KIRQL OldIrql;
1501  PDEVICE_OBJECT PDO;
1502 
1503  ASSERT(DeviceObject != NULL);
1504 
1506  /* Get the base DO */
1508  /* Check whether that's really a PDO and if so, keep it */
1510  {
1511  PDO = NULL;
1512  }
1513  else
1514  {
1515  ObReferenceObject(PDO);
1516  }
1518 
1519  return PDO;
1520 }
PDEVICE_OBJECT NTAPI IopGetDeviceAttachmentBase(IN PDEVICE_OBJECT DeviceObject)
Definition: file.c:1485
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
#define DO_BUS_ENUMERATED_DEVICE
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by IopGetSetSecurityObject().

◆ IopGetSetSecurityObject()

NTSTATUS NTAPI IopGetSetSecurityObject ( IN PVOID  ObjectBody,
IN SECURITY_OPERATION_CODE  OperationCode,
IN PSECURITY_INFORMATION  SecurityInformation,
IN PSECURITY_DESCRIPTOR  SecurityDescriptor,
IN OUT PULONG  BufferLength,
IN OUT PSECURITY_DESCRIPTOR OldSecurityDescriptor,
IN POOL_TYPE  PoolType,
IN OUT PGENERIC_MAPPING  GenericMapping 
)

Definition at line 1653 of file file.c.

1661 {
1663  PIO_STACK_LOCATION StackPtr;
1666  PIRP Irp;
1667  BOOLEAN LocalEvent = FALSE;
1668  KEVENT Event;
1670  PAGED_CODE();
1671  IOTRACE(IO_FILE_DEBUG, "ObjectBody: %p\n", ObjectBody);
1672 
1673  /* Check if this is a device or file */
1674  if (((PFILE_OBJECT)ObjectBody)->Type == IO_TYPE_DEVICE)
1675  {
1676  /* It's a device */
1677  DeviceObject = (PDEVICE_OBJECT)ObjectBody;
1678  FileObject = NULL;
1679  }
1680  else
1681  {
1682  /* It's a file */
1683  FileObject = (PFILE_OBJECT)ObjectBody;
1684 
1685  /* Check if this is a direct open */
1686  if (FileObject->Flags & FO_DIRECT_DEVICE_OPEN)
1687  {
1688  /* Get the Device Object */
1689  DeviceObject = IoGetAttachedDevice(FileObject->DeviceObject);
1690  }
1691  else
1692  {
1693  /* Otherwise, use the direct device*/
1694  DeviceObject = FileObject->DeviceObject;
1695  }
1696  }
1697 
1698  /* Check if the request was for a device object */
1699  if (!(FileObject) ||
1700  (!(FileObject->FileName.Length) && !(FileObject->RelatedFileObject)) ||
1701  (FileObject->Flags & FO_DIRECT_DEVICE_OPEN))
1702  {
1703  /* Check what kind of request this was */
1704  if (OperationCode == QuerySecurityDescriptor)
1705  {
1708  BufferLength,
1709  &DeviceObject->SecurityDescriptor);
1710  }
1711  else if (OperationCode == DeleteSecurityDescriptor)
1712  {
1713  /* Simply return success */
1714  return STATUS_SUCCESS;
1715  }
1716  else if (OperationCode == AssignSecurityDescriptor)
1717  {
1719 
1720  /* Make absolutely sure this is a device object */
1721  if (!(FileObject) || !(FileObject->Flags & FO_STREAM_FILE))
1722  {
1723  PSECURITY_DESCRIPTOR CachedSecurityDescriptor;
1724 
1725  /* Add the security descriptor in cache */
1726  Status = ObLogSecurityDescriptor(SecurityDescriptor, &CachedSecurityDescriptor, 1);
1727  if (NT_SUCCESS(Status))
1728  {
1731 
1732  /* Assign the Security Descriptor */
1733  DeviceObject->SecurityDescriptor = CachedSecurityDescriptor;
1734 
1737  }
1738  }
1739 
1740  /* Return status */
1741  return Status;
1742  }
1743  else if (OperationCode == SetSecurityDescriptor)
1744  {
1745  /* Get the Physical Device Object if any */
1747 
1748  if (PDO != NULL)
1749  {
1750  /* Apply the new SD to any DO in the path from PDO to current DO */
1755  ObDereferenceObject(PDO);
1756  }
1757  else
1758  {
1759  /* Otherwise, just set for ourselves */
1764  }
1765 
1766  return STATUS_SUCCESS;
1767  }
1768 
1769  /* Shouldn't happen */
1770  return STATUS_SUCCESS;
1771  }
1772  else if (OperationCode == DeleteSecurityDescriptor)
1773  {
1774  /* Same as for devices, do nothing */
1775  return STATUS_SUCCESS;
1776  }
1777 
1778  /* At this point, we know we're a file. Reference it */
1780 
1781  /* Check if we should use Sync IO or not */
1782  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
1783  {
1784  /* Lock the file object */
1786  if (Status != STATUS_SUCCESS)
1787  {
1789  return Status;
1790  }
1791  }
1792  else
1793  {
1794  /* Use local event */
1796  LocalEvent = TRUE;
1797  }
1798 
1799  /* Clear the File Object event */
1800  KeClearEvent(&FileObject->Event);
1801 
1802  /* Get the device object */
1804 
1805  /* Allocate the IRP */
1807  if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, NULL);
1808 
1809  /* Set the IRP */
1810  Irp->Tail.Overlay.OriginalFileObject = FileObject;
1811  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
1812  Irp->RequestorMode = ExGetPreviousMode();
1813  Irp->UserIosb = &IoStatusBlock;
1814  Irp->UserEvent = (LocalEvent) ? &Event : NULL;
1815  Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
1816  Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
1817 
1818  /* Set Stack Parameters */
1819  StackPtr = IoGetNextIrpStackLocation(Irp);
1820  StackPtr->FileObject = FileObject;
1821 
1822  /* Check if this is a query or set */
1823  if (OperationCode == QuerySecurityDescriptor)
1824  {
1825  /* Set the major function and parameters */
1827  StackPtr->Parameters.QuerySecurity.SecurityInformation =
1829  StackPtr->Parameters.QuerySecurity.Length = *BufferLength;
1830  Irp->UserBuffer = SecurityDescriptor;
1831  }
1832  else
1833  {
1834  /* Set the major function and parameters for a set */
1835  StackPtr->MajorFunction = IRP_MJ_SET_SECURITY;
1836  StackPtr->Parameters.SetSecurity.SecurityInformation =
1838  StackPtr->Parameters.SetSecurity.SecurityDescriptor =
1840  }
1841 
1842  /* Queue the IRP */
1844 
1845  /* Update operation counts */
1847 
1848  /* Call the Driver */
1850 
1851  /* Check if this was async I/O */
1852  if (LocalEvent)
1853  {
1854  /* Check if the IRP is pending completion */
1855  if (Status == STATUS_PENDING)
1856  {
1857  /* Wait on the local event */
1859  Executive,
1860  KernelMode,
1861  FALSE,
1862  NULL);
1864  }
1865  }
1866  else
1867  {
1868  /* Check if the IRP is pending completion */
1869  if (Status == STATUS_PENDING)
1870  {
1871  /* Wait on the file object */
1873  Executive,
1874  KernelMode,
1875  FALSE,
1876  NULL);
1877  Status = FileObject->FinalStatus;
1878  }
1879 
1880  /* Release the lock */
1882  }
1883 
1884  /* This Driver doesn't implement Security, so try to give it a default */
1886  {
1887  /* Was this a query? */
1888  if (OperationCode == QuerySecurityDescriptor)
1889  {
1890  /* Set a World Security Descriptor */
1893  BufferLength);
1894  }
1895  else
1896  {
1897  /* It wasn't a query, so just fake success */
1899  }
1900  }
1901  else if (OperationCode == QuerySecurityDescriptor)
1902  {
1903  /* Callers usually expect the normalized form */
1905 
1906  _SEH2_TRY
1907  {
1908  /* Return length */
1910  }
1912  {
1913  /* Get the exception code */
1915  }
1916  _SEH2_END;
1917  }
1918 
1919  /* Return Status */
1920  return Status;
1921 }
#define TRUE
Definition: types.h:120
Type
Definition: Type.h:6
#define IRP_MJ_QUERY_SECURITY
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define FO_DIRECT_DEVICE_OPEN
Definition: iotypes.h:1743
_In_ PIRP Irp
Definition: csq.h:116
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:182
struct _DEVICE_OBJECT * PDEVICE_OBJECT
#define IRP_MJ_SET_SECURITY
static ULONG
Definition: file.c:43
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2966
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1538
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
_SEH2_TRY
Definition: create.c:4250
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1732
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define IO_FILE_DEBUG
Definition: io.h:20
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
_In_ ULONG BufferLength
Definition: usbdlib.h:225
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define IO_TYPE_DEVICE
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI IopSetDeviceSecurityDescriptors(IN PDEVICE_OBJECT UpperDeviceObject, IN PDEVICE_OBJECT PhysicalDeviceObject, IN PSECURITY_INFORMATION SecurityInformation, IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN POOL_TYPE PoolType, IN PGENERIC_MAPPING GenericMapping)
Definition: file.c:1605
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ SECURITY_INFORMATION SecurityInformation
Definition: fltkernel.h:1339
FORCEINLINE VOID IopQueueIrpToThread(IN PIRP Irp)
Definition: io_x.h:49
NTSTATUS NTAPI IopSetDeviceSecurityDescriptor(IN PDEVICE_OBJECT DeviceObject, IN PSECURITY_INFORMATION SecurityInformation, IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN POOL_TYPE PoolType, IN PGENERIC_MAPPING GenericMapping)
Definition: file.c:1524
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
NTSTATUS NTAPI IopCleanupFailedIrp(IN PFILE_OBJECT FileObject, IN PKEVENT EventObject, IN PVOID Buffer OPTIONAL)
Definition: irp.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1954
#define IOTRACE(x, fmt,...)
Definition: io.h:47
NTSTATUS NTAPI ObLogSecurityDescriptor(IN PSECURITY_DESCRIPTOR InputSecurityDescriptor, OUT PSECURITY_DESCRIPTOR *OutputSecurityDescriptor, IN ULONG RefBias)
Definition: obsdcach.c:364
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
NTSTATUS NTAPI SeSetWorldSecurityDescriptor(SECURITY_INFORMATION SecurityInformation, PISECURITY_DESCRIPTOR SecurityDescriptor, PULONG BufferLength)
Definition: sd.c:119
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
ERESOURCE IopSecurityResource
Definition: iomgr.c:60
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
static GENERIC_MAPPING GenericMapping
Definition: SeInheritance.c:11
PDEVICE_OBJECT NTAPI IopGetDevicePDO(IN PDEVICE_OBJECT DeviceObject)
Definition: file.c:1498
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
_SEH2_END
Definition: create.c:4424
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
PDEVICE_OBJECT NTAPI IoGetAttachedDevice(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1384
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
static __inline VOID IopUnlockFileObject(IN PFILE_OBJECT FileObject)
Definition: io_x.h:36
#define ObReferenceObject
Definition: obfuncs.h:204
static __inline VOID IopUpdateOperationCount(IN IOP_TRANSFER_TYPE Type)
Definition: io_x.h:77
#define IRP_SYNCHRONOUS_API
NTKERNELAPI NTSTATUS NTAPI SeQuerySecurityDescriptorInfo(_In_ PSECURITY_INFORMATION SecurityInformation, _Out_writes_bytes_(*Length) PSECURITY_DESCRIPTOR SecurityDescriptor, _Inout_ PULONG Length, _Inout_ PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor)
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2725
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T _In_ POOL_TYPE PoolType
Definition: fltkernel.h:1444
#define FO_STREAM_FILE
Definition: iotypes.h:1739

◆ IopParseDevice()

NTSTATUS NTAPI IopParseDevice ( IN PVOID  ParseObject,
IN PVOID  ObjectType,
IN OUT PACCESS_STATE  AccessState,
IN KPROCESSOR_MODE  AccessMode,
IN ULONG  Attributes,
IN OUT PUNICODE_STRING  CompleteName,
IN OUT PUNICODE_STRING  RemainingName,
IN OUT PVOID  Context,
IN PSECURITY_QUALITY_OF_SERVICE SecurityQos  OPTIONAL,
OUT PVOID Object 
)

Definition at line 324 of file file.c.

334 {
335  POPEN_PACKET OpenPacket = (POPEN_PACKET)Context;
336  PDEVICE_OBJECT OriginalDeviceObject = (PDEVICE_OBJECT)ParseObject;
337  PDEVICE_OBJECT DeviceObject, OwnerDevice;
340  PVPB Vpb = NULL;
341  PIRP Irp;
342  PIO_STACK_LOCATION StackLoc;
343  IO_SECURITY_CONTEXT SecurityContext;
345  BOOLEAN DirectOpen = FALSE, OpenCancelled, UseDummyFile;
347  KIRQL OldIrql;
348  PDUMMY_FILE_OBJECT LocalFileObject;
349  PFILE_BASIC_INFORMATION FileBasicInfo;
351  KPROCESSOR_MODE CheckMode;
352  BOOLEAN VolumeOpen = FALSE;
354  BOOLEAN AccessGranted, LockHeld = FALSE;
356  UNICODE_STRING FileString;
357  USHORT Attempt;
358  IOTRACE(IO_FILE_DEBUG, "ParseObject: %p. RemainingName: %wZ\n",
359  ParseObject, RemainingName);
360 
361  for (Attempt = 0; Attempt < IOP_MAX_REPARSE_TRAVERSAL; ++Attempt)
362  {
363  /* Assume failure */
364  *Object = NULL;
365 
366  /* Validate the open packet */
367  if (!IopValidateOpenPacket(OpenPacket)) return STATUS_OBJECT_TYPE_MISMATCH;
368 
369  /* Valide reparse point in case we traversed a mountpoint */
370  if (OpenPacket->TraversedMountPoint)
371  {
372  /* This is a reparse point we understand */
374 
375  /* Make sure we're dealing with correct DO */
376  if (OriginalDeviceObject->DeviceType != FILE_DEVICE_DISK &&
377  OriginalDeviceObject->DeviceType != FILE_DEVICE_CD_ROM &&
378  OriginalDeviceObject->DeviceType != FILE_DEVICE_VIRTUAL_DISK &&
379  OriginalDeviceObject->DeviceType != FILE_DEVICE_TAPE)
380  {
383  }
384  }
385 
386  /* Check if we have a related file object */
387  if (OpenPacket->RelatedFileObject)
388  {
389  /* Use the related file object's device object */
390  OriginalDeviceObject = OpenPacket->RelatedFileObject->DeviceObject;
391  }
392 
393  /* Validate device status */
394  Status = IopCheckDeviceAndDriver(OpenPacket, OriginalDeviceObject);
395  if (!NT_SUCCESS(Status))
396  {
397  /* We failed, return status */
398  OpenPacket->FinalStatus = Status;
399  return Status;
400  }
401 
402  /* Map the generic mask and set the new mapping in the access state */
403  RtlMapGenericMask(&AccessState->RemainingDesiredAccess,
405  RtlMapGenericMask(&AccessState->OriginalDesiredAccess,
409  DesiredAccess = AccessState->RemainingDesiredAccess;
410 
411  /* Check what kind of access checks to do */
412  if ((AccessMode != KernelMode) ||
413  (OpenPacket->Options & IO_FORCE_ACCESS_CHECK))
414  {
415  /* Call is from user-mode or kernel is forcing checks */
416  CheckMode = UserMode;
417  }
418  else
419  {
420  /* Call is from the kernel */
421  CheckMode = KernelMode;
422  }
423 
424  /* Check privilege for backup or restore operation */
426  &OpenPacket->CreateOptions,
427  CheckMode,
428  OpenPacket->Disposition);
429 
430  /* Check if we are re-parsing */
431  if (((OpenPacket->Override) && !(RemainingName->Length)) ||
433  {
434  /* Get granted access from the last call */
435  DesiredAccess |= AccessState->PreviouslyGrantedAccess;
436  }
437 
438  /* Check if this is a volume open */
439  if ((OpenPacket->RelatedFileObject) &&
440  (OpenPacket->RelatedFileObject->Flags & FO_VOLUME_OPEN) &&
441  !(RemainingName->Length))
442  {
443  /* It is */
444  VolumeOpen = TRUE;
445  }
446 
447  /* Now check if we need access checks */
448  if (((AccessMode != KernelMode) ||
449  (OpenPacket->Options & IO_FORCE_ACCESS_CHECK)) &&
450  (!(OpenPacket->RelatedFileObject) || (VolumeOpen)) &&
451  !(OpenPacket->Override))
452  {
455 
456  /* Check if a device object is being parsed */
457  if (!RemainingName->Length)
458  {
459  /* Lock the subject context */
460  SeLockSubjectContext(&AccessState->SubjectSecurityContext);
461  LockHeld = TRUE;
462 
463  /* Do access check */
464  AccessGranted = SeAccessCheck(OriginalDeviceObject->
466  &AccessState->SubjectSecurityContext,
467  LockHeld,
469  0,
470  &Privileges,
472  TypeInfo.GenericMapping,
473  UserMode,
474  &GrantedAccess,
475  &Status);
476  if (Privileges)
477  {
478  /* Append and free the privileges */
481  }
482 
483  /* Check if we got access */
484  if (AccessGranted)
485  {
486  /* Update access state */
487  AccessState->PreviouslyGrantedAccess |= GrantedAccess;
488  AccessState->RemainingDesiredAccess &= ~(GrantedAccess |
490  OpenPacket->Override= TRUE;
491  }
492 
493  FileString.Length = 8;
494  FileString.MaximumLength = 8;
495  FileString.Buffer = L"File";
496 
497  /* Do Audit/Alarm for open operation */
498  SeOpenObjectAuditAlarm(&FileString,
499  OriginalDeviceObject,
500  CompleteName,
501  OriginalDeviceObject->SecurityDescriptor,
502  AccessState,
503  FALSE,
505  UserMode,
506  &AccessState->GenerateOnClose);
507  }
508  else
509  {
510  /* Check if we need to do traverse validation */
511  if (!(AccessState->Flags & TOKEN_HAS_TRAVERSE_PRIVILEGE) ||
512  ((OriginalDeviceObject->DeviceType == FILE_DEVICE_DISK) ||
513  (OriginalDeviceObject->DeviceType == FILE_DEVICE_CD_ROM)))
514  {
515  /* Check if this is a restricted token */
516  if (!(AccessState->Flags & TOKEN_IS_RESTRICTED))
517  {
518  /* Do the FAST traverse check */
519  AccessGranted = SeFastTraverseCheck(OriginalDeviceObject->SecurityDescriptor,
520  AccessState,
522  UserMode);
523  }
524  else
525  {
526  /* Fail */
528  }
529 
530  /* Check if we failed to get access */
531  if (!AccessGranted)
532  {
533  /* Lock the subject context */
534  SeLockSubjectContext(&AccessState->SubjectSecurityContext);
535  LockHeld = TRUE;
536 
537  /* Do access check */
538  AccessGranted = SeAccessCheck(OriginalDeviceObject->
540  &AccessState->SubjectSecurityContext,
541  LockHeld,
543  0,
544  &Privileges,
546  TypeInfo.GenericMapping,
547  UserMode,
548  &GrantedAccess,
549  &Status);
550  if (Privileges)
551  {
552  /* Append and free the privileges */
555  }
556  }
557 
558  /* FIXME: Do Audit/Alarm for traverse check */
559  }
560  else
561  {
562  /* Access automatically granted */
564  }
565  }
566 
569 
570  /* Check if we hold the lock */
571  if (LockHeld)
572  {
573  /* Release it */
574  SeUnlockSubjectContext(&AccessState->SubjectSecurityContext);
575  }
576 
577  /* Check if access failed */
578  if (!AccessGranted)
579  {
580  /* Dereference the device and fail */
581  DPRINT1("Traverse access failed!\n");
582  IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
583  return STATUS_ACCESS_DENIED;
584  }
585  }
586 
587  /* Check if we can simply use a dummy file */
588  UseDummyFile = ((OpenPacket->QueryOnly) || (OpenPacket->DeleteOnly));
589 
590  /* Check if this is a direct open */
591  if (!(RemainingName->Length) &&
592  !(OpenPacket->RelatedFileObject) &&
593  ((DesiredAccess & ~(SYNCHRONIZE |
595  READ_CONTROL |
597  WRITE_OWNER |
598  WRITE_DAC)) == 0) &&
599  !(UseDummyFile))
600  {
601  /* Remember this for later */
602  DirectOpen = TRUE;
603  }
604 
605  /* Check if we have a related FO that wasn't a direct open */
606  if ((OpenPacket->RelatedFileObject) &&
607  !(OpenPacket->RelatedFileObject->Flags & FO_DIRECT_DEVICE_OPEN))
608  {
609  /* The device object is the one we were given */
610  DeviceObject = ParseObject;
611 
612  /* Check if the related FO had a VPB */
613  if (OpenPacket->RelatedFileObject->Vpb)
614  {
615  /* Yes, remember it */
616  Vpb = OpenPacket->RelatedFileObject->Vpb;
617 
618  /* Reference it */
619  InterlockedIncrement((PLONG)&Vpb->ReferenceCount);
620 
621  /* Check if we were given a specific top level device to use */
623  {
624  DeviceObject = Vpb->DeviceObject;
625  }
626  }
627  }
628  else
629  {
630  /* Check if it has a VPB */
631  if ((OriginalDeviceObject->Vpb) && !(DirectOpen))
632  {
633  /* Check if the VPB is mounted, and mount it */
634  Vpb = IopCheckVpbMounted(OpenPacket,
635  OriginalDeviceObject,
637  &Status);
638  if (!Vpb) return Status;
639 
640  /* Get the VPB's device object */
641  DeviceObject = Vpb->DeviceObject;
642  }
643  else
644  {
645  /* The device object is the one we were given */
646  DeviceObject = OriginalDeviceObject;
647  }
648 
649  /* If we weren't given a specific top level device, look for an attached device */
650  if (!(OpenPacket->InternalFlags & IOP_USE_TOP_LEVEL_DEVICE_HINT) &&
651  DeviceObject->AttachedDevice)
652  {
653  /* Get the attached device */
655  }
656  }
657 
658  /* If we have a top level device hint, verify it */
660  {
661  Status = IopCheckTopDeviceHint(&DeviceObject, OpenPacket, DirectOpen);
662  if (!NT_SUCCESS(Status))
663  {
664  IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
666  return Status;
667  }
668  }
669 
670  /* If we traversed a mount point, reset the information */
671  if (OpenPacket->TraversedMountPoint)
672  {
673  OpenPacket->TraversedMountPoint = FALSE;
674  }
675 
676  /* Check if this is a secure FSD */
677  if ((DeviceObject->Characteristics & FILE_DEVICE_SECURE_OPEN) &&
678  ((OpenPacket->RelatedFileObject) || (RemainingName->Length)) &&
679  (!VolumeOpen))
680  {
681  Privileges = NULL;
682  GrantedAccess = 0;
683 
686 
687  /* Lock the subject context */
688  SeLockSubjectContext(&AccessState->SubjectSecurityContext);
689 
690  /* Do access check */
691  AccessGranted = SeAccessCheck(OriginalDeviceObject->SecurityDescriptor,
692  &AccessState->SubjectSecurityContext,
693  TRUE,
695  0,
696  &Privileges,
698  UserMode,
699  &GrantedAccess,
700  &Status);
701  if (Privileges != NULL)
702  {
703  /* Append and free the privileges */
706  }
707 
708  /* Check if we got access */
709  if (GrantedAccess)
710  {
711  AccessState->PreviouslyGrantedAccess |= GrantedAccess;
712  AccessState->RemainingDesiredAccess &= ~(GrantedAccess | MAXIMUM_ALLOWED);
713  }
714 
715  FileString.Length = 8;
716  FileString.MaximumLength = 8;
717  FileString.Buffer = L"File";
718 
719  /* Do Audit/Alarm for open operation
720  * NOTA: we audit target device object
721  */
722  SeOpenObjectAuditAlarm(&FileString,
723  DeviceObject,
724  CompleteName,
725  OriginalDeviceObject->SecurityDescriptor,
726  AccessState,
727  FALSE,
729  UserMode,
730  &AccessState->GenerateOnClose);
731 
732  SeUnlockSubjectContext(&AccessState->SubjectSecurityContext);
733 
736 
737  /* Check if access failed */
738  if (!AccessGranted)
739  {
740  /* Dereference the device and fail */
741  IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
743  return STATUS_ACCESS_DENIED;
744  }
745  }
746 
747  /* Allocate the IRP */
749  if (!Irp)
750  {
751  /* Dereference the device and VPB, then fail */
752  IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
755  }
756 
757  /* Now set the IRP data */
758  Irp->RequestorMode = AccessMode;
760  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
761  Irp->UserIosb = &IoStatusBlock;
762  Irp->MdlAddress = NULL;
763  Irp->PendingReturned = FALSE;
764  Irp->UserEvent = NULL;
765  Irp->Cancel = FALSE;
766  Irp->CancelRoutine = NULL;
767  Irp->Tail.Overlay.AuxiliaryBuffer = NULL;
768 
769  /* Setup the security context */
770  SecurityContext.SecurityQos = SecurityQos;
771  SecurityContext.AccessState = AccessState;
772  SecurityContext.DesiredAccess = AccessState->RemainingDesiredAccess;
773  SecurityContext.FullCreateOptions = OpenPacket->CreateOptions;
774 
775  /* Get the I/O Stack location */
776  StackLoc = IoGetNextIrpStackLocation(Irp);
777  StackLoc->Control = 0;
778 
779  /* Check what kind of file this is */
780  switch (OpenPacket->CreateFileType)
781  {
782  /* Normal file */
783  case CreateFileTypeNone:
784 
785  /* Set the major function and EA Length */
786  StackLoc->MajorFunction = IRP_MJ_CREATE;
787  StackLoc->Parameters.Create.EaLength = OpenPacket->EaLength;
788 
789  /* Set the flags */
790  StackLoc->Flags = (UCHAR)OpenPacket->Options;
792  break;
793 
794  /* Named pipe */
796 
797  /* Set the named pipe MJ and set the parameters */
799  StackLoc->Parameters.CreatePipe.Parameters = OpenPacket->ExtraCreateParameters;
800  break;
801 
802  /* Mailslot */
804 
805  /* Set the mailslot MJ and set the parameters */
807  StackLoc->Parameters.CreateMailslot.Parameters = OpenPacket->ExtraCreateParameters;
808  break;
809  }
810 
811  /* Set the common data */
812  Irp->Overlay.AllocationSize = OpenPacket->AllocationSize;
813  Irp->AssociatedIrp.SystemBuffer = OpenPacket->EaBuffer;
814  StackLoc->Parameters.Create.Options = (OpenPacket->Disposition << 24) |
815  (OpenPacket->CreateOptions &
816  0xFFFFFF);
817  StackLoc->Parameters.Create.FileAttributes = OpenPacket->FileAttributes;
818  StackLoc->Parameters.Create.ShareAccess = OpenPacket->ShareAccess;
819  StackLoc->Parameters.Create.SecurityContext = &SecurityContext;
820 
821  /* Check if we really need to create an object */
822  if (!UseDummyFile)
823  {
824  ULONG ObjectSize = sizeof(FILE_OBJECT);
825 
826  /* Tag on space for a file object extension */
828  ObjectSize += sizeof(FILE_OBJECT_EXTENSION);
829 
830  /* Create the actual file object */
832  NULL,
833  Attributes,
834  NULL,
835  NULL);
839  AccessMode,
840  NULL,
841  ObjectSize,
842  0,
843  0,
844  (PVOID*)&FileObject);
845  if (!NT_SUCCESS(Status))
846  {
847  /* Create failed, free the IRP */
848  IoFreeIrp(Irp);
849 
850  /* Dereference the device and VPB */
851  IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
853 
854  /* We failed, return status */
855  OpenPacket->FinalStatus = Status;
856  return Status;
857  }
858 
859  /* Clear the file object */
861 
862  /* Check if this is Synch I/O */
863  if (OpenPacket->CreateOptions &
865  {
866  /* Set the synch flag */
867  FileObject->Flags |= FO_SYNCHRONOUS_IO;
868 
869  /* Check if it's also alertable */
870  if (OpenPacket->CreateOptions & FILE_SYNCHRONOUS_IO_ALERT)
871  {
872  /* It is, set the alertable flag */
873  FileObject->Flags |= FO_ALERTABLE_IO;
874  }
875  }
876 
877  /* Check if this is synch I/O */
878  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
879  {
880  /* Initialize the event */
882  }
883 
884  /* Check if the caller requested no intermediate buffering */
886  {
887  /* Set the correct flag for the FSD to read */
889  }
890 
891  /* Check if the caller requested write through support */
892  if (OpenPacket->CreateOptions & FILE_WRITE_THROUGH)
893  {
894  /* Set the correct flag for the FSD to read */
895  FileObject->Flags |= FO_WRITE_THROUGH;
896  }
897 
898  /* Check if the caller says the file will be only read sequentially */
899  if (OpenPacket->CreateOptions & FILE_SEQUENTIAL_ONLY)
900  {
901  /* Set the correct flag for the FSD to read */
902  FileObject->Flags |= FO_SEQUENTIAL_ONLY;
903  }
904 
905  /* Check if the caller believes the file will be only read randomly */
906  if (OpenPacket->CreateOptions & FILE_RANDOM_ACCESS)
907  {
908  /* Set the correct flag for the FSD to read */
909  FileObject->Flags |= FO_RANDOM_ACCESS;
910  }
911 
912  /* Check if we were asked to setup a file object extension */
914  {
915  PFILE_OBJECT_EXTENSION FileObjectExtension;
916 
917  /* Make sure the file object knows it has an extension */
919 
920  FileObjectExtension = (PFILE_OBJECT_EXTENSION)(FileObject + 1);
921  FileObject->FileObjectExtension = FileObjectExtension;
922 
923  /* Add the top level device which we'll send the request to */
925  {
926  FileObjectExtension->TopDeviceObjectHint = DeviceObject;
927  }
928  }
929  }
930  else
931  {
932  /* Use the dummy object instead */
933  LocalFileObject = OpenPacket->LocalFileObject;
934  RtlZeroMemory(LocalFileObject, sizeof(DUMMY_FILE_OBJECT));
935 
936  /* Set it up */
937  FileObject = (PFILE_OBJECT)&LocalFileObject->ObjectHeader.Body;
938  LocalFileObject->ObjectHeader.Type = IoFileObjectType;
939  LocalFileObject->ObjectHeader.PointerCount = 1;
940  }
941 
942  /* Setup the file header */
943  FileObject->Type = IO_TYPE_FILE;
944  FileObject->Size = sizeof(FILE_OBJECT);
945  FileObject->RelatedFileObject = OpenPacket->RelatedFileObject;
946  FileObject->DeviceObject = OriginalDeviceObject;
947 
948  /* Check if this is a direct device open */
949  if (DirectOpen) FileObject->Flags |= FO_DIRECT_DEVICE_OPEN;
950 
951  /* Check if the caller wants case sensitivity */
953  {
954  /* Tell the driver about it */
956  }
957 
958  /* Now set the file object */
959  Irp->Tail.Overlay.OriginalFileObject = FileObject;
960  StackLoc->FileObject = FileObject;
961 
962  /* Check if the file object has a name */
963  if (RemainingName->Length)
964  {
965  /* Setup the unicode string */
966  FileObject->FileName.MaximumLength = RemainingName->Length + sizeof(WCHAR);
967  FileObject->FileName.Buffer = ExAllocatePoolWithTag(PagedPool,
968  FileObject->FileName.MaximumLength,
969  TAG_IO_NAME);
970  if (!FileObject->FileName.Buffer)
971  {
972  /* Failed to allocate the name, free the IRP */
973  IoFreeIrp(Irp);
974 
975  /* Dereference the device object and VPB */
976  IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
978 
979  /* Clear the FO and dereference it */
980  FileObject->DeviceObject = NULL;
981  if (!UseDummyFile) ObDereferenceObject(FileObject);
982 
983  /* Fail */
985  }
986  }
987 
988  /* Copy the name */
990 
991  /* Initialize the File Object event and set the FO */
993  OpenPacket->FileObject = FileObject;
994 
995  /* Queue the IRP and call the driver */
998  if (Status == STATUS_PENDING)
999  {
1000  /* Wait for the driver to complete the create */
1002  Executive,
1003  KernelMode,
1004  FALSE,
1005  NULL);
1006 
1007  /* Get the new status */
1009  }
1010  else
1011  {
1012  /* We'll have to complete it ourselves */
1013  ASSERT(!Irp->PendingReturned);
1014  ASSERT(!Irp->MdlAddress);
1015 
1016  /* Handle name change if required */
1017  if (Status == STATUS_REPARSE)
1018  {
1019  /* Check this is a mount point */
1020  if (Irp->IoStatus.Information == IO_REPARSE_TAG_MOUNT_POINT)
1021  {
1022  PREPARSE_DATA_BUFFER ReparseData;
1023 
1024  /* Reparse point attributes were passed by the driver in the auxiliary buffer */
1025  ASSERT(Irp->Tail.Overlay.AuxiliaryBuffer != NULL);
1026  ReparseData = (PREPARSE_DATA_BUFFER)Irp->Tail.Overlay.AuxiliaryBuffer;
1027 
1028  ASSERT(ReparseData->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT);
1031 
1032  IopDoNameTransmogrify(Irp, FileObject, ReparseData);
1033  }
1034  }
1035 
1036  /* Completion happens at APC_LEVEL */
1038 
1039  /* Get the new I/O Status block ourselves */
1040  IoStatusBlock = Irp->IoStatus;
1042 
1043  /* Manually signal the even, we can't have any waiters */
1044  FileObject->Event.Header.SignalState = 1;
1045 
1046  /* Now that we've signaled the events, de-associate the IRP */
1048 
1049  /* Check if the IRP had an input buffer */
1050  if ((Irp->Flags & IRP_BUFFERED_IO) &&
1051  (Irp->Flags & IRP_DEALLOCATE_BUFFER))
1052  {
1053  /* Free it. A driver might've tacked one on */
1054  ExFreePool(Irp->AssociatedIrp.SystemBuffer);
1055  }
1056 
1057  /* Free the IRP and bring the IRQL back down */
1058  IoFreeIrp(Irp);
1060  }
1061 
1062  /* Copy the I/O Status */
1063  OpenPacket->Information = IoStatusBlock.Information;
1064 
1065  /* The driver failed to create the file */
1066  if (!NT_SUCCESS(Status))
1067  {
1068  /* Check if we have a name and if so, free it */
1069  if (FileObject->FileName.Length)
1070  {
1071  /*
1072  * Don't use TAG_IO_NAME since the FileObject's FileName
1073  * may have been re-allocated using a different tag
1074  * by a filesystem.
1075  */
1076  ExFreePoolWithTag(FileObject->FileName.Buffer, 0);
1077  FileObject->FileName.Buffer = NULL;
1078  FileObject->FileName.Length = 0;
1079  }
1080 
1081  /* Clear its device object */
1082  FileObject->DeviceObject = NULL;
1083 
1084  /* Save this now because the FO might go away */
1085  OpenCancelled = FileObject->Flags & FO_FILE_OPEN_CANCELLED ?
1086  TRUE : FALSE;
1087 
1088  /* Clear the file object in the open packet */
1089  OpenPacket->FileObject = NULL;
1090 
1091  /* Dereference the file object */
1092  if (!UseDummyFile) ObDereferenceObject(FileObject);
1093 
1094  /* Dereference the device object */
1095  IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
1096 
1097  /* Unless the driver cancelled the open, dereference the VPB */
1098  if (!(OpenCancelled) && (Vpb)) IopDereferenceVpbAndFree(Vpb);
1099 
1100  /* Set the status and return */
1101  OpenPacket->FinalStatus = Status;
1102  return Status;
1103  }
1104  else if (Status == STATUS_REPARSE)
1105  {
1106  if (OpenPacket->Information == IO_REPARSE ||
1107  OpenPacket->Information == IO_REPARSE_TAG_MOUNT_POINT)
1108  {
1109  /* Update CompleteName with reparse info which got updated in IopDoNameTransmogrify() */
1110  if (CompleteName->MaximumLength < FileObject->FileName.Length)
1111  {
1112  PWSTR NewCompleteName;
1113 
1114  /* Allocate a new buffer for the string */
1115  NewCompleteName = ExAllocatePoolWithTag(PagedPool, FileObject->FileName.Length, TAG_IO_NAME);
1116  if (NewCompleteName == NULL)
1117  {
1120  }
1121 
1122  /* Release the old one */
1123  if (CompleteName->Buffer != NULL)
1124  {
1125  /*
1126  * Don't use TAG_IO_NAME since the FileObject's FileName
1127  * may have been re-allocated using a different tag
1128  * by a filesystem.
1129  */
1130  ExFreePoolWithTag(CompleteName->Buffer, 0);
1131  }
1132 
1133  /* And setup the new one */
1134  CompleteName->Buffer = NewCompleteName;
1135  CompleteName->MaximumLength = FileObject->FileName.Length;
1136  }
1137 
1138  /* Copy our new complete name */
1139  RtlCopyUnicodeString(CompleteName, &FileObject->FileName);
1140 
1141  if (OpenPacket->Information == IO_REPARSE_TAG_MOUNT_POINT)
1142  {
1143  OpenPacket->RelatedFileObject = NULL;
1144  }
1145  }
1146 
1147  /* Check if we have a name and if so, free it */
1148  if (FileObject->FileName.Length)
1149  {
1150  /*
1151  * Don't use TAG_IO_NAME since the FileObject's FileName
1152  * may have been re-allocated using a different tag
1153  * by a filesystem.
1154  */
1155  ExFreePoolWithTag(FileObject->FileName.Buffer, 0);
1156  FileObject->FileName.Buffer = NULL;
1157  FileObject->FileName.Length = 0;
1158  }
1159 
1160  /* Clear its device object */
1161  FileObject->DeviceObject = NULL;
1162 
1163  /* Clear the file object in the open packet */
1164  OpenPacket->FileObject = NULL;
1165 
1166  /* Dereference the file object */
1167  if (!UseDummyFile) ObDereferenceObject(FileObject);
1168 
1169  /* Dereference the device object */
1170  IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
1171 
1172  /* Unless the driver cancelled the open, dereference the VPB */
1174 
1175  if (OpenPacket->Information != IO_REMOUNT)
1176  {
1177  OpenPacket->RelatedFileObject = NULL;
1178 
1179  /* Inform we traversed a mount point for later attempt */
1180  if (OpenPacket->Information == IO_REPARSE_TAG_MOUNT_POINT)
1181  {
1182  OpenPacket->TraversedMountPoint = 1;
1183  }
1184 
1185  /* In case we override checks, but got this on volume open, fail hard */
1186  if (OpenPacket->Override)
1187  {
1188  KeBugCheckEx(DRIVER_RETURNED_STATUS_REPARSE_FOR_VOLUME_OPEN,
1189  (ULONG_PTR)OriginalDeviceObject,
1191  (ULONG_PTR)CompleteName,
1192  OpenPacket->Information);
1193  }
1194 
1195  /* Return to IO/OB so that information can be upgraded */
1196  return STATUS_REPARSE;
1197  }
1198 
1199  /* Loop again and reattempt an opening */
1200  continue;
1201  }
1202 
1203  break;
1204  }
1205 
1206  if (Attempt == IOP_MAX_REPARSE_TRAVERSAL)
1207  return STATUS_UNSUCCESSFUL;
1208 
1209  /* Get the owner of the File Object */
1210  OwnerDevice = IoGetRelatedDeviceObject(FileObject);
1211 
1212  /*
1213  * It's possible that the device to whom we sent the IRP to
1214  * isn't actually the device that ended opening the file object
1215  * internally.
1216  */
1217  if (OwnerDevice != DeviceObject)
1218  {
1219  /* We have to de-reference the VPB we had associated */
1221 
1222  /* And re-associate with the actual one */
1223  Vpb = FileObject->Vpb;
1224  if (Vpb) InterlockedIncrement((PLONG)&Vpb->ReferenceCount);
1225  }
1226 
1227  /* Make sure we are not using a dummy */
1228  if (!UseDummyFile)
1229  {
1230  /* Check if this was a volume open */
1231  if ((!(FileObject->RelatedFileObject) ||
1232  (FileObject->RelatedFileObject->Flags & FO_VOLUME_OPEN)) &&
1233  !(FileObject->FileName.Length))
1234  {
1235  /* All signs point to it, but make sure it was actually an FSD */
1236  if ((OwnerDevice->DeviceType == FILE_DEVICE_DISK_FILE_SYSTEM) ||
1237  (OwnerDevice->DeviceType == FILE_DEVICE_CD_ROM_FILE_SYSTEM) ||
1238  (OwnerDevice->DeviceType == FILE_DEVICE_TAPE_FILE_SYSTEM) ||
1239  (OwnerDevice->DeviceType == FILE_DEVICE_FILE_SYSTEM))
1240  {
1241  /* The owner device is an FSD, so this is a volume open for real */
1242  FileObject->Flags |= FO_VOLUME_OPEN;
1243  }
1244  }
1245 
1246  /* Reference the object and set the parse check */
1248  *Object = FileObject;
1249  OpenPacket->FinalStatus = IoStatusBlock.Status;
1250  OpenPacket->ParseCheck = TRUE;
1251  return OpenPacket->FinalStatus;
1252  }
1253  else
1254  {
1255  /* Check if this was a query */
1256  if (OpenPacket->QueryOnly)
1257  {
1258  /* Check if the caller wants basic info only */
1259  if (!OpenPacket->FullAttributes)
1260  {
1261  /* Allocate the buffer */
1262  FileBasicInfo = ExAllocatePoolWithTag(NonPagedPool,
1263  sizeof(*FileBasicInfo),
1264  TAG_IO);
1265  if (FileBasicInfo)
1266  {
1267  /* Do the query */
1270  sizeof(*FileBasicInfo),
1271  FileBasicInfo,
1272  &ReturnLength);
1273  if (NT_SUCCESS(Status))
1274  {
1275  /* Copy the data */
1276  RtlCopyMemory(OpenPacket->BasicInformation,
1277  FileBasicInfo,
1278  ReturnLength);
1279  }
1280 
1281  /* Free our buffer */
1282  ExFreePoolWithTag(FileBasicInfo, TAG_IO);
1283  }
1284  else
1285  {
1286  /* Fail */
1288  }
1289  }
1290  else
1291  {
1292  /* This is a full query */
1294