ExFreePool(DataBuffer);
}
+NTSTATUS
+IopCheckTopDeviceHint(IN OUT PDEVICE_OBJECT * DeviceObject,
+ IN POPEN_PACKET OpenPacket,
+ BOOLEAN DirectOpen)
+{
+ PDEVICE_OBJECT LocalDevice;
+ DEVICE_TYPE DeviceType;
+
+ LocalDevice = *DeviceObject;
+
+ /* Direct open is not allowed */
+ if (DirectOpen)
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ /* Validate we have a file system device */
+ DeviceType = LocalDevice->DeviceType;
+ if (DeviceType != FILE_DEVICE_DISK_FILE_SYSTEM &&
+ DeviceType != FILE_DEVICE_CD_ROM_FILE_SYSTEM &&
+ DeviceType != FILE_DEVICE_TAPE_FILE_SYSTEM &&
+ DeviceType != FILE_DEVICE_NETWORK_FILE_SYSTEM &&
+ DeviceType != FILE_DEVICE_DFS_FILE_SYSTEM)
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ /* Verify the hint and if it's OK, return it */
+ if (IopVerifyDeviceObjectOnStack(LocalDevice, OpenPacket->TopDeviceObjectHint))
+ {
+ *DeviceObject = OpenPacket->TopDeviceObjectHint;
+ return STATUS_SUCCESS;
+ }
+
+ /* Failure case here */
+ /* If we thought was had come through a mount point,
+ * actually update we didn't and return the error
+ */
+ if (OpenPacket->TraversedMountPoint)
+ {
+ OpenPacket->TraversedMountPoint = FALSE;
+ return STATUS_MOUNT_POINT_NOT_RESOLVED;
+ }
+
+ /* Otherwise, just return the fact the hint is invalid */
+ return STATUS_INVALID_DEVICE_OBJECT_PARAMETER;
+}
+
NTSTATUS
NTAPI
IopParseDevice(IN PVOID ParseObject,
/* Check if we can simply use a dummy file */
UseDummyFile = ((OpenPacket->QueryOnly) || (OpenPacket->DeleteOnly));
-#if 1
- /* FIXME: Small hack still exists, have to check why...
- * This is triggered multiple times by usetup and then once per boot.
- */
- if (ExpInTextModeSetup &&
- !(DirectOpen) &&
- !(RemainingName->Length) &&
- !(OpenPacket->RelatedFileObject) &&
- ((wcsstr(CompleteName->Buffer, L"Harddisk")) ||
- (wcsstr(CompleteName->Buffer, L"Floppy"))) &&
- !(UseDummyFile))
- {
- DPRINT1("Using IopParseDevice() hack. Requested invalid attributes: %lx\n",
- DesiredAccess & ~(SYNCHRONIZE |
- FILE_READ_ATTRIBUTES |
- READ_CONTROL |
- ACCESS_SYSTEM_SECURITY |
- WRITE_OWNER |
- WRITE_DAC));
- DirectOpen = TRUE;
- }
-#endif
-
/* Check if this is a direct open */
if (!(RemainingName->Length) &&
!(OpenPacket->RelatedFileObject) &&
}
}
+ /* If we have a top level device hint, verify it */
if (OpenPacket->InternalFlags & IOP_USE_TOP_LEVEL_DEVICE_HINT)
{
- // FIXME: Verify our device object is good to use
- ASSERT(DirectOpen == FALSE);
+ Status = IopCheckTopDeviceHint(&DeviceObject, OpenPacket, DirectOpen);
+ if (!NT_SUCCESS(Status))
+ {
+ IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
+ if (Vpb) IopDereferenceVpbAndFree(Vpb);
+ return Status;
+ }
}
/* If we traversed a mount point, reset the information */
/* Get buffer pointer */
p = (PWCHAR)(ObjectNameInfo + 1);
- /* Copy the information */
- if (QueryDosName && NoObCall)
+ _SEH2_TRY
{
- ASSERT(PreviousMode == KernelMode);
+ /* Copy the information */
+ if (QueryDosName && NoObCall)
+ {
+ ASSERT(PreviousMode == KernelMode);
- /* Copy structure first */
- RtlCopyMemory(ObjectNameInfo,
- LocalInfo,
- (Length >= LocalReturnLength ? sizeof(OBJECT_NAME_INFORMATION) : Length));
- /* Name then */
- RtlCopyMemory(p, LocalInfo->Name.Buffer,
- (Length >= LocalReturnLength ? LocalInfo->Name.Length : Length - sizeof(OBJECT_NAME_INFORMATION)));
+ /* Copy structure first */
+ RtlCopyMemory(ObjectNameInfo,
+ LocalInfo,
+ (Length >= LocalReturnLength ? sizeof(OBJECT_NAME_INFORMATION) : Length));
+ /* Name then */
+ RtlCopyMemory(p, LocalInfo->Name.Buffer,
+ (Length >= LocalReturnLength ? LocalInfo->Name.Length : Length - sizeof(OBJECT_NAME_INFORMATION)));
- if (FileObject->DeviceObject->DeviceType != FILE_DEVICE_NETWORK_FILE_SYSTEM)
+ if (FileObject->DeviceObject->DeviceType != FILE_DEVICE_NETWORK_FILE_SYSTEM)
+ {
+ ExFreePool(LocalInfo->Name.Buffer);
+ }
+ }
+ else
{
- ExFreePool(LocalInfo->Name.Buffer);
+ RtlCopyMemory(ObjectNameInfo,
+ LocalInfo,
+ (LocalReturnLength > Length) ?
+ Length : LocalReturnLength);
}
- }
- else
- {
- RtlCopyMemory(ObjectNameInfo,
- LocalInfo,
- (LocalReturnLength > Length) ?
- Length : LocalReturnLength);
- }
- /* Set buffer pointer */
- ObjectNameInfo->Name.Buffer = p;
+ /* Set buffer pointer */
+ ObjectNameInfo->Name.Buffer = p;
- /* Advance in buffer */
- p += (LocalInfo->Name.Length / sizeof(WCHAR));
+ /* Advance in buffer */
+ p += (LocalInfo->Name.Length / sizeof(WCHAR));
- /* Check if this already filled our buffer */
- if (LocalReturnLength > Length)
- {
- /* Set the length mismatch to true, so that we can return
- * the proper buffer size to the caller later
- */
- LengthMismatch = TRUE;
+ /* Check if this already filled our buffer */
+ if (LocalReturnLength > Length)
+ {
+ /* Set the length mismatch to true, so that we can return
+ * the proper buffer size to the caller later
+ */
+ LengthMismatch = TRUE;
- /* Save the initial buffer length value */
- *ReturnLength = LocalReturnLength;
- }
+ /* Save the initial buffer length value */
+ *ReturnLength = LocalReturnLength;
+ }
- /* Now get the file name buffer and check the length needed */
- LocalFileInfo = (PFILE_NAME_INFORMATION)LocalInfo;
- FileLength = Length -
- LocalReturnLength +
- FIELD_OFFSET(FILE_NAME_INFORMATION, FileName);
+ /* Now get the file name buffer and check the length needed */
+ LocalFileInfo = (PFILE_NAME_INFORMATION)LocalInfo;
+ FileLength = Length -
+ LocalReturnLength +
+ FIELD_OFFSET(FILE_NAME_INFORMATION, FileName);
- /* Query the File name */
- if (PreviousMode == KernelMode &&
- BooleanFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO))
- {
- Status = IopGetFileInformation(FileObject,
- LengthMismatch ? Length : FileLength,
- FileNameInformation,
- LocalFileInfo,
- &LocalReturnLength);
- }
- else
- {
- Status = IoQueryFileInformation(FileObject,
- FileNameInformation,
- LengthMismatch ? Length : FileLength,
- LocalFileInfo,
- &LocalReturnLength);
- }
- if (NT_ERROR(Status))
- {
- /* Allow status that would mean it's not implemented in the storage stack */
- if (Status != STATUS_INVALID_PARAMETER && Status != STATUS_INVALID_DEVICE_REQUEST &&
- Status != STATUS_NOT_IMPLEMENTED && Status != STATUS_INVALID_INFO_CLASS)
+ /* Query the File name */
+ if (PreviousMode == KernelMode &&
+ BooleanFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO))
{
- ExFreePoolWithTag(LocalInfo, TAG_IO);
- return Status;
+ Status = IopGetFileInformation(FileObject,
+ LengthMismatch ? Length : FileLength,
+ FileNameInformation,
+ LocalFileInfo,
+ &LocalReturnLength);
}
-
- /* In such case, zero output */
- LocalReturnLength = FIELD_OFFSET(FILE_NAME_INFORMATION, FileName);
- LocalFileInfo->FileNameLength = 0;
- LocalFileInfo->FileName[0] = OBJ_NAME_PATH_SEPARATOR;
- }
- else
- {
- /* We'll at least return the name length */
- if (LocalReturnLength < FIELD_OFFSET(FILE_NAME_INFORMATION, FileName))
+ else
+ {
+ Status = IoQueryFileInformation(FileObject,
+ FileNameInformation,
+ LengthMismatch ? Length : FileLength,
+ LocalFileInfo,
+ &LocalReturnLength);
+ }
+ if (NT_ERROR(Status))
{
+ /* Allow status that would mean it's not implemented in the storage stack */
+ if (Status != STATUS_INVALID_PARAMETER && Status != STATUS_INVALID_DEVICE_REQUEST &&
+ Status != STATUS_NOT_IMPLEMENTED && Status != STATUS_INVALID_INFO_CLASS)
+ {
+ _SEH2_LEAVE;
+ }
+
+ /* In such case, zero output */
LocalReturnLength = FIELD_OFFSET(FILE_NAME_INFORMATION, FileName);
+ LocalFileInfo->FileNameLength = 0;
+ LocalFileInfo->FileName[0] = OBJ_NAME_PATH_SEPARATOR;
+ }
+ else
+ {
+ /* We'll at least return the name length */
+ if (LocalReturnLength < FIELD_OFFSET(FILE_NAME_INFORMATION, FileName))
+ {
+ LocalReturnLength = FIELD_OFFSET(FILE_NAME_INFORMATION, FileName);
+ }
}
- }
- /* If the provided buffer is too small, return the required size */
- if (LengthMismatch)
- {
- /* Add the required length */
- *ReturnLength += LocalFileInfo->FileNameLength;
+ /* If the provided buffer is too small, return the required size */
+ if (LengthMismatch)
+ {
+ /* Add the required length */
+ *ReturnLength += LocalFileInfo->FileNameLength;
- /* Free the allocated buffer and return failure */
- ExFreePoolWithTag(LocalInfo, TAG_IO);
- return STATUS_BUFFER_OVERFLOW;
- }
+ /* Free the allocated buffer and return failure */
+ Status = STATUS_BUFFER_OVERFLOW;
+ _SEH2_LEAVE;
+ }
- /* Now calculate the new lengths left */
- FileLength = LocalReturnLength -
- FIELD_OFFSET(FILE_NAME_INFORMATION, FileName);
- LocalReturnLength = (ULONG)((ULONG_PTR)p -
- (ULONG_PTR)ObjectNameInfo +
- LocalFileInfo->FileNameLength);
+ /* Now calculate the new lengths left */
+ FileLength = LocalReturnLength -
+ FIELD_OFFSET(FILE_NAME_INFORMATION, FileName);
+ LocalReturnLength = (ULONG)((ULONG_PTR)p -
+ (ULONG_PTR)ObjectNameInfo +
+ LocalFileInfo->FileNameLength);
- /* Don't copy the name if it's not valid */
- if (LocalFileInfo->FileName[0] != OBJ_NAME_PATH_SEPARATOR)
- {
- /* Free the allocated buffer and return failure */
- ExFreePoolWithTag(LocalInfo, TAG_IO);
- return STATUS_OBJECT_PATH_INVALID;
- }
+ /* Don't copy the name if it's not valid */
+ if (LocalFileInfo->FileName[0] != OBJ_NAME_PATH_SEPARATOR)
+ {
+ /* Free the allocated buffer and return failure */
+ Status = STATUS_OBJECT_PATH_INVALID;
+ _SEH2_LEAVE;
+ }
- /* Write the Name and null-terminate it */
- RtlCopyMemory(p, LocalFileInfo->FileName, FileLength);
- p += (FileLength / sizeof(WCHAR));
- *p = UNICODE_NULL;
- LocalReturnLength += sizeof(UNICODE_NULL);
+ /* Write the Name and null-terminate it */
+ RtlCopyMemory(p, LocalFileInfo->FileName, FileLength);
+ p += (FileLength / sizeof(WCHAR));
+ *p = UNICODE_NULL;
+ LocalReturnLength += sizeof(UNICODE_NULL);
- /* Return the length needed */
- *ReturnLength = LocalReturnLength;
+ /* Return the length needed */
+ *ReturnLength = LocalReturnLength;
- /* Setup the length and maximum length */
- FileLength = (ULONG)((ULONG_PTR)p - (ULONG_PTR)ObjectNameInfo);
- ObjectNameInfo->Name.Length = (USHORT)FileLength -
- sizeof(OBJECT_NAME_INFORMATION);
- ObjectNameInfo->Name.MaximumLength = (USHORT)ObjectNameInfo->Name.Length +
- sizeof(UNICODE_NULL);
+ /* Setup the length and maximum length */
+ FileLength = (ULONG)((ULONG_PTR)p - (ULONG_PTR)ObjectNameInfo);
+ ObjectNameInfo->Name.Length = (USHORT)FileLength -
+ sizeof(OBJECT_NAME_INFORMATION);
+ ObjectNameInfo->Name.MaximumLength = (USHORT)ObjectNameInfo->Name.Length +
+ sizeof(UNICODE_NULL);
+ }
+ _SEH2_FINALLY
+ {
+ /* Free buffer and return */
+ ExFreePoolWithTag(LocalInfo, TAG_IO);
+ } _SEH2_END;
- /* Free buffer and return */
- ExFreePoolWithTag(LocalInfo, TAG_IO);
return Status;
}
NTAPI
IoGetFileObjectFilterContext(IN PFILE_OBJECT FileObject)
{
- if (FileObject->Flags & FO_FILE_OBJECT_HAS_EXTENSION)
+ if (BooleanFlagOn(FileObject->Flags, FO_FILE_OBJECT_HAS_EXTENSION))
{
- UNIMPLEMENTED;
- /* FIXME: return NULL for the moment ~ */
- return NULL;
+ PFILE_OBJECT_EXTENSION FileObjectExtension;
+
+ FileObjectExtension = FileObject->FileObjectExtension;
+ return FileObjectExtension->FilterContext;
}
return NULL;
IN PVOID FilterContext,
IN BOOLEAN Define)
{
- if (!(FileObject->Flags & FO_FILE_OBJECT_HAS_EXTENSION))
+ ULONG_PTR Success;
+ PFILE_OBJECT_EXTENSION FileObjectExtension;
+
+ if (!BooleanFlagOn(FileObject->Flags, FO_FILE_OBJECT_HAS_EXTENSION))
{
return STATUS_INVALID_PARAMETER;
}
- UNIMPLEMENTED;
+ FileObjectExtension = FileObject->FileObjectExtension;
+ if (Define)
+ {
+ /* If define, just set the new value if not value is set
+ * Success will only contain old value. It is valid if it is NULL
+ */
+ Success = (ULONG_PTR)InterlockedCompareExchangePointer(&FileObjectExtension->FilterContext, FilterContext, NULL);
+ }
+ else
+ {
+ /* If not define, we want to reset filter context.
+ * We will remove value (provided by the caller) and set NULL instead.
+ * This will only success if caller provides correct previous value.
+ * To catch whether it worked, we substract previous value to expect value:
+ * If it matches (and thus, we reset), Success will contain 0
+ * Otherwise, it will contain a non-zero value.
+ */
+ Success = (ULONG_PTR)InterlockedCompareExchangePointer(&FileObjectExtension->FilterContext, NULL, FilterContext) - (ULONG_PTR)FilterContext;
+ }
- return STATUS_NOT_IMPLEMENTED;
+ /* If success isn't 0, it means we failed somewhere (set or unset) */
+ if (Success != 0)
+ {
+ return STATUS_ALREADY_COMMITTED;
+ }
+
+ return STATUS_SUCCESS;
}
NTSTATUS