2002-06-25 22:23:06 +00:00
|
|
|
/*
|
|
|
|
* ReactOS kernel
|
|
|
|
* Copyright (C) 2002 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2008-03-08 21:45:51 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-06-25 22:23:06 +00:00
|
|
|
*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
2008-02-10 11:20:29 +00:00
|
|
|
* FILE: drivers/filesystem/ntfs/dirctl.c
|
2002-06-25 22:23:06 +00:00
|
|
|
* PURPOSE: NTFS filesystem driver
|
2014-11-02 22:56:38 +00:00
|
|
|
* PROGRAMMERS: Eric Kohl
|
|
|
|
* Hervé Poussineau (hpoussin@reactos.org)
|
[NTFS]
Totally rewrite the way MFT records attributes are handled.
Up to now, we were having really similar loops, only looking at the resident part of the attribute list, not really caring about how the loop was going.
This was leading to some issues:
- In case the attribute we were looking for was stored in the non-resident part of the attribute list, we would miss it (excepted in the case of FindAttribute() which was properly browsing the whole attribute list).
- In the specific case of FindAttribute(), one would have been able to setup a broken MFT record with the resident attribute list pointing on the non resident attribute list which itself would point to the resident attribute list. In such case, the driver would loop forever caught on the loop, allocating tones of memory. It was possible to trigger this by user space, from a non-privileged user, just by browsing the right directory entry.
- In the case of the other loops (non FindAttribute()), another issue (other than missing attributes) was present, one would have been able to setup a broken MFT record with an attribute of null-length. This would have caused the driver to loop forever on the attribute list. This could be triggered from usermode too. And could be triggered by a non-privileged user.
This commit introduces a new set of functions for attributes browsing: FindFirstAttribute(), FindNextAttribute(), FindCloseAttribute(). It allows safely browsing attributes and handles broken cases. It also performs reading of the attribute list when present and makes sure there's only one read. This method should be the only one to use to browse the attributes.
The whole NTFS code base has been converted to use this newly set of functions. This really simplifies the implementation of FindAttribute(), and prevent unsafe code duplication.
CORE-10037 #resolve #comment Fixed with r68829
svn path=/trunk/; revision=68829
2015-08-26 18:20:04 +00:00
|
|
|
* Pierre Schweitzer (pierre@reactos.org)
|
2002-06-25 22:23:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2005-07-20 02:52:52 +00:00
|
|
|
#include "ntfs.h"
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2004-06-05 08:28:37 +00:00
|
|
|
#define NDEBUG
|
2002-06-25 22:23:06 +00:00
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Retrieve the standard file information
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
NTSTATUS
|
2008-03-15 08:51:47 +00:00
|
|
|
NtfsGetStandardInformation(PNTFS_FCB Fcb,
|
2008-01-27 13:16:52 +00:00
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PFILE_STANDARD_INFORMATION StandardInfo,
|
|
|
|
PULONG BufferLength)
|
2002-06-25 22:23:06 +00:00
|
|
|
{
|
2013-07-24 15:24:41 +00:00
|
|
|
UNREFERENCED_PARAMETER(DeviceObject);
|
|
|
|
|
2019-06-15 16:24:27 +00:00
|
|
|
DPRINT("NtfsGetStandardInformation(%p, %p, %p, %p)\n", Fcb, DeviceObject, StandardInfo, BufferLength);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
if (*BufferLength < sizeof(FILE_STANDARD_INFORMATION))
|
2015-08-24 08:45:28 +00:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
/* PRECONDITION */
|
|
|
|
ASSERT(StandardInfo != NULL);
|
|
|
|
ASSERT(Fcb != NULL);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
RtlZeroMemory(StandardInfo,
|
|
|
|
sizeof(FILE_STANDARD_INFORMATION));
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
StandardInfo->AllocationSize = Fcb->RFCB.AllocationSize;
|
|
|
|
StandardInfo->EndOfFile = Fcb->RFCB.FileSize;
|
2014-12-15 21:28:06 +00:00
|
|
|
StandardInfo->NumberOfLinks = Fcb->LinkCount;
|
2013-06-16 12:15:06 +00:00
|
|
|
StandardInfo->DeletePending = FALSE;
|
|
|
|
StandardInfo->Directory = NtfsFCBIsDirectory(Fcb);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
*BufferLength -= sizeof(FILE_STANDARD_INFORMATION);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2002-06-25 22:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
static
|
|
|
|
NTSTATUS
|
2002-06-25 22:23:06 +00:00
|
|
|
NtfsGetPositionInformation(PFILE_OBJECT FileObject,
|
2008-01-27 13:16:52 +00:00
|
|
|
PFILE_POSITION_INFORMATION PositionInfo,
|
|
|
|
PULONG BufferLength)
|
2002-06-25 22:23:06 +00:00
|
|
|
{
|
2014-12-14 21:09:29 +00:00
|
|
|
DPRINT1("NtfsGetPositionInformation(%p, %p, %p)\n", FileObject, PositionInfo, BufferLength);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
if (*BufferLength < sizeof(FILE_POSITION_INFORMATION))
|
2015-08-24 08:45:28 +00:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2014-11-23 19:53:16 +00:00
|
|
|
PositionInfo->CurrentByteOffset.QuadPart = FileObject->CurrentByteOffset.QuadPart;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
DPRINT("Getting position %I64x\n",
|
|
|
|
PositionInfo->CurrentByteOffset.QuadPart);
|
|
|
|
|
|
|
|
*BufferLength -= sizeof(FILE_POSITION_INFORMATION);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
return STATUS_SUCCESS;
|
2002-06-25 22:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
static
|
|
|
|
NTSTATUS
|
2002-06-25 22:23:06 +00:00
|
|
|
NtfsGetBasicInformation(PFILE_OBJECT FileObject,
|
2008-03-15 08:51:47 +00:00
|
|
|
PNTFS_FCB Fcb,
|
2008-01-27 13:16:52 +00:00
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PFILE_BASIC_INFORMATION BasicInfo,
|
|
|
|
PULONG BufferLength)
|
2002-06-25 22:23:06 +00:00
|
|
|
{
|
2014-11-23 19:53:16 +00:00
|
|
|
PFILENAME_ATTRIBUTE FileName = &Fcb->Entry;
|
|
|
|
|
2019-06-15 16:24:27 +00:00
|
|
|
DPRINT("NtfsGetBasicInformation(%p, %p, %p, %p, %p)\n", FileObject, Fcb, DeviceObject, BasicInfo, BufferLength);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
if (*BufferLength < sizeof(FILE_BASIC_INFORMATION))
|
2015-08-24 08:45:28 +00:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2020-09-11 12:47:43 +00:00
|
|
|
RtlZeroMemory(BasicInfo, sizeof(FILE_BASIC_INFORMATION));
|
|
|
|
|
2014-11-23 19:53:16 +00:00
|
|
|
BasicInfo->CreationTime.QuadPart = FileName->CreationTime;
|
|
|
|
BasicInfo->LastAccessTime.QuadPart = FileName->LastAccessTime;
|
|
|
|
BasicInfo->LastWriteTime.QuadPart = FileName->LastWriteTime;
|
|
|
|
BasicInfo->ChangeTime.QuadPart = FileName->ChangeTime;
|
|
|
|
|
|
|
|
NtfsFileFlagsToAttributes(FileName->FileAttributes, &BasicInfo->FileAttributes);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
*BufferLength -= sizeof(FILE_BASIC_INFORMATION);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
return STATUS_SUCCESS;
|
2002-06-25 22:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Retrieve the file name information
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
NTSTATUS
|
2002-06-25 22:23:06 +00:00
|
|
|
NtfsGetNameInformation(PFILE_OBJECT FileObject,
|
2008-03-15 08:51:47 +00:00
|
|
|
PNTFS_FCB Fcb,
|
2008-01-27 13:16:52 +00:00
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PFILE_NAME_INFORMATION NameInfo,
|
|
|
|
PULONG BufferLength)
|
2002-06-25 22:23:06 +00:00
|
|
|
{
|
2014-11-02 22:56:47 +00:00
|
|
|
ULONG BytesToCopy;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-07-24 15:24:41 +00:00
|
|
|
UNREFERENCED_PARAMETER(FileObject);
|
|
|
|
UNREFERENCED_PARAMETER(DeviceObject);
|
|
|
|
|
2019-06-15 16:24:27 +00:00
|
|
|
DPRINT("NtfsGetNameInformation(%p, %p, %p, %p, %p)\n", FileObject, Fcb, DeviceObject, NameInfo, BufferLength);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
ASSERT(NameInfo != NULL);
|
|
|
|
ASSERT(Fcb != NULL);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2014-11-02 22:56:47 +00:00
|
|
|
/* If buffer can't hold at least the file name length, bail out */
|
|
|
|
if (*BufferLength < (ULONG)FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]))
|
2015-08-24 08:45:28 +00:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2014-11-02 22:56:47 +00:00
|
|
|
/* Save file name length, and as much file len, as buffer length allows */
|
|
|
|
NameInfo->FileNameLength = wcslen(Fcb->PathName) * sizeof(WCHAR);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2014-11-02 22:56:47 +00:00
|
|
|
/* Calculate amount of bytes to copy not to overflow the buffer */
|
|
|
|
BytesToCopy = min(NameInfo->FileNameLength,
|
|
|
|
*BufferLength - FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]));
|
|
|
|
|
|
|
|
/* Fill in the bytes */
|
|
|
|
RtlCopyMemory(NameInfo->FileName, Fcb->PathName, BytesToCopy);
|
|
|
|
|
|
|
|
/* Check if we could write more but are not able to */
|
|
|
|
if (*BufferLength < NameInfo->FileNameLength + (ULONG)FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]))
|
|
|
|
{
|
|
|
|
/* Return number of bytes written */
|
|
|
|
*BufferLength -= FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]) + BytesToCopy;
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We filled up as many bytes, as needed */
|
|
|
|
*BufferLength -= (FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]) + NameInfo->FileNameLength);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
return STATUS_SUCCESS;
|
2002-06-25 22:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
static
|
|
|
|
NTSTATUS
|
2008-03-15 08:51:47 +00:00
|
|
|
NtfsGetInternalInformation(PNTFS_FCB Fcb,
|
2008-01-27 13:16:52 +00:00
|
|
|
PFILE_INTERNAL_INFORMATION InternalInfo,
|
|
|
|
PULONG BufferLength)
|
2002-06-25 22:23:06 +00:00
|
|
|
{
|
2014-12-14 21:09:29 +00:00
|
|
|
DPRINT1("NtfsGetInternalInformation(%p, %p, %p)\n", Fcb, InternalInfo, BufferLength);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
ASSERT(InternalInfo);
|
|
|
|
ASSERT(Fcb);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
if (*BufferLength < sizeof(FILE_INTERNAL_INFORMATION))
|
2015-08-24 08:45:28 +00:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2014-12-15 21:28:06 +00:00
|
|
|
InternalInfo->IndexNumber.QuadPart = Fcb->MFTIndex;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
*BufferLength -= sizeof(FILE_INTERNAL_INFORMATION);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
return STATUS_SUCCESS;
|
2002-06-25 22:23:06 +00:00
|
|
|
}
|
|
|
|
|
2014-11-02 22:56:53 +00:00
|
|
|
static
|
|
|
|
NTSTATUS
|
|
|
|
NtfsGetNetworkOpenInformation(PNTFS_FCB Fcb,
|
|
|
|
PDEVICE_EXTENSION DeviceExt,
|
|
|
|
PFILE_NETWORK_OPEN_INFORMATION NetworkInfo,
|
|
|
|
PULONG BufferLength)
|
|
|
|
{
|
|
|
|
PFILENAME_ATTRIBUTE FileName = &Fcb->Entry;
|
|
|
|
|
2019-06-15 16:24:27 +00:00
|
|
|
DPRINT("NtfsGetNetworkOpenInformation(%p, %p, %p, %p)\n", Fcb, DeviceExt, NetworkInfo, BufferLength);
|
2014-12-14 21:09:29 +00:00
|
|
|
|
2014-11-02 22:56:53 +00:00
|
|
|
if (*BufferLength < sizeof(FILE_NETWORK_OPEN_INFORMATION))
|
2015-08-24 08:45:28 +00:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-11-02 22:56:53 +00:00
|
|
|
|
|
|
|
NetworkInfo->CreationTime.QuadPart = FileName->CreationTime;
|
|
|
|
NetworkInfo->LastAccessTime.QuadPart = FileName->LastAccessTime;
|
|
|
|
NetworkInfo->LastWriteTime.QuadPart = FileName->LastWriteTime;
|
|
|
|
NetworkInfo->ChangeTime.QuadPart = FileName->ChangeTime;
|
|
|
|
|
2015-07-05 19:09:20 +00:00
|
|
|
NetworkInfo->EndOfFile = Fcb->RFCB.FileSize;
|
|
|
|
NetworkInfo->AllocationSize = Fcb->RFCB.AllocationSize;
|
2014-11-02 22:56:53 +00:00
|
|
|
|
|
|
|
NtfsFileFlagsToAttributes(FileName->FileAttributes, &NetworkInfo->FileAttributes);
|
|
|
|
|
|
|
|
*BufferLength -= sizeof(FILE_NETWORK_OPEN_INFORMATION);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2015-08-24 08:36:58 +00:00
|
|
|
static
|
|
|
|
NTSTATUS
|
2024-02-22 19:33:34 +00:00
|
|
|
NtfsGetStreamInformation(PNTFS_FCB Fcb,
|
|
|
|
PDEVICE_EXTENSION DeviceExt,
|
|
|
|
PFILE_STREAM_INFORMATION StreamInfo,
|
|
|
|
PULONG BufferLength)
|
2015-08-24 08:36:58 +00:00
|
|
|
{
|
|
|
|
ULONG CurrentSize;
|
[NTFS]
Totally rewrite the way MFT records attributes are handled.
Up to now, we were having really similar loops, only looking at the resident part of the attribute list, not really caring about how the loop was going.
This was leading to some issues:
- In case the attribute we were looking for was stored in the non-resident part of the attribute list, we would miss it (excepted in the case of FindAttribute() which was properly browsing the whole attribute list).
- In the specific case of FindAttribute(), one would have been able to setup a broken MFT record with the resident attribute list pointing on the non resident attribute list which itself would point to the resident attribute list. In such case, the driver would loop forever caught on the loop, allocating tones of memory. It was possible to trigger this by user space, from a non-privileged user, just by browsing the right directory entry.
- In the case of the other loops (non FindAttribute()), another issue (other than missing attributes) was present, one would have been able to setup a broken MFT record with an attribute of null-length. This would have caused the driver to loop forever on the attribute list. This could be triggered from usermode too. And could be triggered by a non-privileged user.
This commit introduces a new set of functions for attributes browsing: FindFirstAttribute(), FindNextAttribute(), FindCloseAttribute(). It allows safely browsing attributes and handles broken cases. It also performs reading of the attribute list when present and makes sure there's only one read. This method should be the only one to use to browse the attributes.
The whole NTFS code base has been converted to use this newly set of functions. This really simplifies the implementation of FindAttribute(), and prevent unsafe code duplication.
CORE-10037 #resolve #comment Fixed with r68829
svn path=/trunk/; revision=68829
2015-08-26 18:20:04 +00:00
|
|
|
FIND_ATTR_CONTXT Context;
|
2015-08-24 08:36:58 +00:00
|
|
|
PNTFS_ATTR_RECORD Attribute;
|
[NTFS]
Totally rewrite the way MFT records attributes are handled.
Up to now, we were having really similar loops, only looking at the resident part of the attribute list, not really caring about how the loop was going.
This was leading to some issues:
- In case the attribute we were looking for was stored in the non-resident part of the attribute list, we would miss it (excepted in the case of FindAttribute() which was properly browsing the whole attribute list).
- In the specific case of FindAttribute(), one would have been able to setup a broken MFT record with the resident attribute list pointing on the non resident attribute list which itself would point to the resident attribute list. In such case, the driver would loop forever caught on the loop, allocating tones of memory. It was possible to trigger this by user space, from a non-privileged user, just by browsing the right directory entry.
- In the case of the other loops (non FindAttribute()), another issue (other than missing attributes) was present, one would have been able to setup a broken MFT record with an attribute of null-length. This would have caused the driver to loop forever on the attribute list. This could be triggered from usermode too. And could be triggered by a non-privileged user.
This commit introduces a new set of functions for attributes browsing: FindFirstAttribute(), FindNextAttribute(), FindCloseAttribute(). It allows safely browsing attributes and handles broken cases. It also performs reading of the attribute list when present and makes sure there's only one read. This method should be the only one to use to browse the attributes.
The whole NTFS code base has been converted to use this newly set of functions. This really simplifies the implementation of FindAttribute(), and prevent unsafe code duplication.
CORE-10037 #resolve #comment Fixed with r68829
svn path=/trunk/; revision=68829
2015-08-26 18:20:04 +00:00
|
|
|
NTSTATUS Status, BrowseStatus;
|
2015-08-24 08:36:58 +00:00
|
|
|
PFILE_RECORD_HEADER FileRecord;
|
|
|
|
PFILE_STREAM_INFORMATION CurrentInfo = StreamInfo, Previous = NULL;
|
|
|
|
|
|
|
|
if (*BufferLength < sizeof(FILE_STREAM_INFORMATION))
|
2015-08-24 08:45:28 +00:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2015-08-24 08:36:58 +00:00
|
|
|
|
2017-12-31 13:14:24 +00:00
|
|
|
FileRecord = ExAllocateFromNPagedLookasideList(&DeviceExt->FileRecLookasideList);
|
2015-08-24 08:36:58 +00:00
|
|
|
if (FileRecord == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("Not enough memory!\n");
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = ReadFileRecord(DeviceExt, Fcb->MFTIndex, FileRecord);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Can't find record!\n");
|
2017-12-31 13:14:24 +00:00
|
|
|
ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
|
2015-08-24 08:36:58 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
[NTFS]
Totally rewrite the way MFT records attributes are handled.
Up to now, we were having really similar loops, only looking at the resident part of the attribute list, not really caring about how the loop was going.
This was leading to some issues:
- In case the attribute we were looking for was stored in the non-resident part of the attribute list, we would miss it (excepted in the case of FindAttribute() which was properly browsing the whole attribute list).
- In the specific case of FindAttribute(), one would have been able to setup a broken MFT record with the resident attribute list pointing on the non resident attribute list which itself would point to the resident attribute list. In such case, the driver would loop forever caught on the loop, allocating tones of memory. It was possible to trigger this by user space, from a non-privileged user, just by browsing the right directory entry.
- In the case of the other loops (non FindAttribute()), another issue (other than missing attributes) was present, one would have been able to setup a broken MFT record with an attribute of null-length. This would have caused the driver to loop forever on the attribute list. This could be triggered from usermode too. And could be triggered by a non-privileged user.
This commit introduces a new set of functions for attributes browsing: FindFirstAttribute(), FindNextAttribute(), FindCloseAttribute(). It allows safely browsing attributes and handles broken cases. It also performs reading of the attribute list when present and makes sure there's only one read. This method should be the only one to use to browse the attributes.
The whole NTFS code base has been converted to use this newly set of functions. This really simplifies the implementation of FindAttribute(), and prevent unsafe code duplication.
CORE-10037 #resolve #comment Fixed with r68829
svn path=/trunk/; revision=68829
2015-08-26 18:20:04 +00:00
|
|
|
BrowseStatus = FindFirstAttribute(&Context, DeviceExt, FileRecord, FALSE, &Attribute);
|
|
|
|
while (NT_SUCCESS(BrowseStatus))
|
2015-08-24 08:36:58 +00:00
|
|
|
{
|
|
|
|
if (Attribute->Type == AttributeData)
|
|
|
|
{
|
2015-08-24 08:43:26 +00:00
|
|
|
CurrentSize = FIELD_OFFSET(FILE_STREAM_INFORMATION, StreamName) + Attribute->NameLength * sizeof(WCHAR) + wcslen(L"::$DATA") * sizeof(WCHAR);
|
2015-08-24 08:36:58 +00:00
|
|
|
|
|
|
|
if (CurrentSize > *BufferLength)
|
|
|
|
{
|
|
|
|
Status = STATUS_BUFFER_OVERFLOW;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrentInfo->NextEntryOffset = 0;
|
2015-08-25 20:11:53 +00:00
|
|
|
CurrentInfo->StreamNameLength = (Attribute->NameLength + wcslen(L"::$DATA")) * sizeof(WCHAR);
|
2015-08-24 08:36:58 +00:00
|
|
|
CurrentInfo->StreamSize.QuadPart = AttributeDataLength(Attribute);
|
|
|
|
CurrentInfo->StreamAllocationSize.QuadPart = AttributeAllocatedLength(Attribute);
|
2015-08-24 08:43:26 +00:00
|
|
|
CurrentInfo->StreamName[0] = L':';
|
|
|
|
RtlMoveMemory(&CurrentInfo->StreamName[1], (PWCHAR)((ULONG_PTR)Attribute + Attribute->NameOffset), CurrentInfo->StreamNameLength);
|
|
|
|
RtlMoveMemory(&CurrentInfo->StreamName[Attribute->NameLength + 1], L":$DATA", sizeof(L":$DATA") - sizeof(UNICODE_NULL));
|
2015-08-24 08:36:58 +00:00
|
|
|
|
|
|
|
if (Previous != NULL)
|
|
|
|
{
|
|
|
|
Previous->NextEntryOffset = (ULONG_PTR)CurrentInfo - (ULONG_PTR)Previous;
|
|
|
|
}
|
|
|
|
Previous = CurrentInfo;
|
|
|
|
CurrentInfo = (PFILE_STREAM_INFORMATION)((ULONG_PTR)CurrentInfo + CurrentSize);
|
|
|
|
*BufferLength -= CurrentSize;
|
|
|
|
}
|
|
|
|
|
[NTFS]
Totally rewrite the way MFT records attributes are handled.
Up to now, we were having really similar loops, only looking at the resident part of the attribute list, not really caring about how the loop was going.
This was leading to some issues:
- In case the attribute we were looking for was stored in the non-resident part of the attribute list, we would miss it (excepted in the case of FindAttribute() which was properly browsing the whole attribute list).
- In the specific case of FindAttribute(), one would have been able to setup a broken MFT record with the resident attribute list pointing on the non resident attribute list which itself would point to the resident attribute list. In such case, the driver would loop forever caught on the loop, allocating tones of memory. It was possible to trigger this by user space, from a non-privileged user, just by browsing the right directory entry.
- In the case of the other loops (non FindAttribute()), another issue (other than missing attributes) was present, one would have been able to setup a broken MFT record with an attribute of null-length. This would have caused the driver to loop forever on the attribute list. This could be triggered from usermode too. And could be triggered by a non-privileged user.
This commit introduces a new set of functions for attributes browsing: FindFirstAttribute(), FindNextAttribute(), FindCloseAttribute(). It allows safely browsing attributes and handles broken cases. It also performs reading of the attribute list when present and makes sure there's only one read. This method should be the only one to use to browse the attributes.
The whole NTFS code base has been converted to use this newly set of functions. This really simplifies the implementation of FindAttribute(), and prevent unsafe code duplication.
CORE-10037 #resolve #comment Fixed with r68829
svn path=/trunk/; revision=68829
2015-08-26 18:20:04 +00:00
|
|
|
BrowseStatus = FindNextAttribute(&Context, &Attribute);
|
2015-08-24 08:36:58 +00:00
|
|
|
}
|
|
|
|
|
[NTFS]
Totally rewrite the way MFT records attributes are handled.
Up to now, we were having really similar loops, only looking at the resident part of the attribute list, not really caring about how the loop was going.
This was leading to some issues:
- In case the attribute we were looking for was stored in the non-resident part of the attribute list, we would miss it (excepted in the case of FindAttribute() which was properly browsing the whole attribute list).
- In the specific case of FindAttribute(), one would have been able to setup a broken MFT record with the resident attribute list pointing on the non resident attribute list which itself would point to the resident attribute list. In such case, the driver would loop forever caught on the loop, allocating tones of memory. It was possible to trigger this by user space, from a non-privileged user, just by browsing the right directory entry.
- In the case of the other loops (non FindAttribute()), another issue (other than missing attributes) was present, one would have been able to setup a broken MFT record with an attribute of null-length. This would have caused the driver to loop forever on the attribute list. This could be triggered from usermode too. And could be triggered by a non-privileged user.
This commit introduces a new set of functions for attributes browsing: FindFirstAttribute(), FindNextAttribute(), FindCloseAttribute(). It allows safely browsing attributes and handles broken cases. It also performs reading of the attribute list when present and makes sure there's only one read. This method should be the only one to use to browse the attributes.
The whole NTFS code base has been converted to use this newly set of functions. This really simplifies the implementation of FindAttribute(), and prevent unsafe code duplication.
CORE-10037 #resolve #comment Fixed with r68829
svn path=/trunk/; revision=68829
2015-08-26 18:20:04 +00:00
|
|
|
FindCloseAttribute(&Context);
|
2017-12-31 13:14:24 +00:00
|
|
|
ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
|
2015-08-24 08:36:58 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2017-07-27 18:22:24 +00:00
|
|
|
// Convert enum value to friendly name
|
|
|
|
const PCSTR
|
|
|
|
GetInfoClassName(FILE_INFORMATION_CLASS infoClass)
|
|
|
|
{
|
|
|
|
const PCSTR fileInfoClassNames[] = { "???????",
|
|
|
|
"FileDirectoryInformation",
|
|
|
|
"FileFullDirectoryInformation",
|
|
|
|
"FileBothDirectoryInformation",
|
|
|
|
"FileBasicInformation",
|
|
|
|
"FileStandardInformation",
|
|
|
|
"FileInternalInformation",
|
|
|
|
"FileEaInformation",
|
|
|
|
"FileAccessInformation",
|
|
|
|
"FileNameInformation",
|
|
|
|
"FileRenameInformation",
|
|
|
|
"FileLinkInformation",
|
|
|
|
"FileNamesInformation",
|
|
|
|
"FileDispositionInformation",
|
|
|
|
"FilePositionInformation",
|
|
|
|
"FileFullEaInformation",
|
|
|
|
"FileModeInformation",
|
|
|
|
"FileAlignmentInformation",
|
|
|
|
"FileAllInformation",
|
|
|
|
"FileAllocationInformation",
|
|
|
|
"FileEndOfFileInformation",
|
|
|
|
"FileAlternateNameInformation",
|
|
|
|
"FileStreamInformation",
|
|
|
|
"FilePipeInformation",
|
|
|
|
"FilePipeLocalInformation",
|
|
|
|
"FilePipeRemoteInformation",
|
|
|
|
"FileMailslotQueryInformation",
|
|
|
|
"FileMailslotSetInformation",
|
|
|
|
"FileCompressionInformation",
|
|
|
|
"FileObjectIdInformation",
|
|
|
|
"FileCompletionInformation",
|
|
|
|
"FileMoveClusterInformation",
|
|
|
|
"FileQuotaInformation",
|
|
|
|
"FileReparsePointInformation",
|
|
|
|
"FileNetworkOpenInformation",
|
|
|
|
"FileAttributeTagInformation",
|
|
|
|
"FileTrackingInformation",
|
|
|
|
"FileIdBothDirectoryInformation",
|
|
|
|
"FileIdFullDirectoryInformation",
|
|
|
|
"FileValidDataLengthInformation",
|
|
|
|
"FileShortNameInformation",
|
|
|
|
"FileIoCompletionNotificationInformation",
|
|
|
|
"FileIoStatusBlockRangeInformation",
|
|
|
|
"FileIoPriorityHintInformation",
|
|
|
|
"FileSfioReserveInformation",
|
|
|
|
"FileSfioVolumeInformation",
|
|
|
|
"FileHardLinkInformation",
|
|
|
|
"FileProcessIdsUsingFileInformation",
|
|
|
|
"FileNormalizedNameInformation",
|
|
|
|
"FileNetworkPhysicalNameInformation",
|
|
|
|
"FileIdGlobalTxDirectoryInformation",
|
|
|
|
"FileIsRemoteDeviceInformation",
|
|
|
|
"FileAttributeCacheInformation",
|
|
|
|
"FileNumaNodeInformation",
|
|
|
|
"FileStandardLinkInformation",
|
|
|
|
"FileRemoteProtocolInformation",
|
|
|
|
"FileReplaceCompletionInformation",
|
|
|
|
"FileMaximumInformation",
|
|
|
|
"FileDirectoryInformation",
|
|
|
|
"FileFullDirectoryInformation",
|
|
|
|
"FileBothDirectoryInformation",
|
|
|
|
"FileBasicInformation",
|
|
|
|
"FileStandardInformation",
|
|
|
|
"FileInternalInformation",
|
|
|
|
"FileEaInformation",
|
|
|
|
"FileAccessInformation",
|
|
|
|
"FileNameInformation",
|
|
|
|
"FileRenameInformation",
|
|
|
|
"FileLinkInformation",
|
|
|
|
"FileNamesInformation",
|
|
|
|
"FileDispositionInformation",
|
|
|
|
"FilePositionInformation",
|
|
|
|
"FileFullEaInformation",
|
|
|
|
"FileModeInformation",
|
|
|
|
"FileAlignmentInformation",
|
|
|
|
"FileAllInformation",
|
|
|
|
"FileAllocationInformation",
|
|
|
|
"FileEndOfFileInformation",
|
|
|
|
"FileAlternateNameInformation",
|
|
|
|
"FileStreamInformation",
|
|
|
|
"FilePipeInformation",
|
|
|
|
"FilePipeLocalInformation",
|
|
|
|
"FilePipeRemoteInformation",
|
|
|
|
"FileMailslotQueryInformation",
|
|
|
|
"FileMailslotSetInformation",
|
|
|
|
"FileCompressionInformation",
|
|
|
|
"FileObjectIdInformation",
|
|
|
|
"FileCompletionInformation",
|
|
|
|
"FileMoveClusterInformation",
|
|
|
|
"FileQuotaInformation",
|
|
|
|
"FileReparsePointInformation",
|
|
|
|
"FileNetworkOpenInformation",
|
|
|
|
"FileAttributeTagInformation",
|
|
|
|
"FileTrackingInformation",
|
|
|
|
"FileIdBothDirectoryInformation",
|
|
|
|
"FileIdFullDirectoryInformation",
|
|
|
|
"FileValidDataLengthInformation",
|
|
|
|
"FileShortNameInformation",
|
|
|
|
"FileIoCompletionNotificationInformation",
|
|
|
|
"FileIoStatusBlockRangeInformation",
|
|
|
|
"FileIoPriorityHintInformation",
|
|
|
|
"FileSfioReserveInformation",
|
|
|
|
"FileSfioVolumeInformation",
|
|
|
|
"FileHardLinkInformation",
|
|
|
|
"FileProcessIdsUsingFileInformation",
|
|
|
|
"FileNormalizedNameInformation",
|
|
|
|
"FileNetworkPhysicalNameInformation",
|
|
|
|
"FileIdGlobalTxDirectoryInformation",
|
|
|
|
"FileIsRemoteDeviceInformation",
|
|
|
|
"FileAttributeCacheInformation",
|
|
|
|
"FileNumaNodeInformation",
|
|
|
|
"FileStandardLinkInformation",
|
|
|
|
"FileRemoteProtocolInformation",
|
|
|
|
"FileReplaceCompletionInformation",
|
|
|
|
"FileMaximumInformation" };
|
|
|
|
return fileInfoClassNames[infoClass];
|
|
|
|
}
|
|
|
|
|
2002-06-25 22:23:06 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Retrieve the specified file information
|
|
|
|
*/
|
2013-06-16 12:15:06 +00:00
|
|
|
NTSTATUS
|
2015-05-03 18:36:58 +00:00
|
|
|
NtfsQueryInformation(PNTFS_IRP_CONTEXT IrpContext)
|
2002-06-25 22:23:06 +00:00
|
|
|
{
|
2013-06-16 12:15:06 +00:00
|
|
|
FILE_INFORMATION_CLASS FileInformationClass;
|
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
PNTFS_FCB Fcb;
|
|
|
|
PVOID SystemBuffer;
|
|
|
|
ULONG BufferLength;
|
2015-05-03 18:36:58 +00:00
|
|
|
PIRP Irp;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
2013-06-16 12:15:06 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
2015-05-03 18:36:58 +00:00
|
|
|
DPRINT1("NtfsQueryInformation(%p)\n", IrpContext);
|
2013-06-16 12:15:06 +00:00
|
|
|
|
2015-05-03 18:36:58 +00:00
|
|
|
Irp = IrpContext->Irp;
|
|
|
|
Stack = IrpContext->Stack;
|
|
|
|
DeviceObject = IrpContext->DeviceObject;
|
2013-06-16 12:15:06 +00:00
|
|
|
FileInformationClass = Stack->Parameters.QueryFile.FileInformationClass;
|
2015-05-03 18:36:58 +00:00
|
|
|
FileObject = IrpContext->FileObject;
|
2013-06-16 12:15:06 +00:00
|
|
|
Fcb = FileObject->FsContext;
|
|
|
|
|
|
|
|
SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
BufferLength = Stack->Parameters.QueryFile.Length;
|
|
|
|
|
2015-05-25 17:06:00 +00:00
|
|
|
if (!ExAcquireResourceSharedLite(&Fcb->MainResource,
|
2015-05-25 17:30:01 +00:00
|
|
|
BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
|
2015-05-25 17:06:00 +00:00
|
|
|
{
|
|
|
|
return NtfsMarkIrpContextForQueue(IrpContext);
|
|
|
|
}
|
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
switch (FileInformationClass)
|
|
|
|
{
|
|
|
|
case FileStandardInformation:
|
|
|
|
Status = NtfsGetStandardInformation(Fcb,
|
|
|
|
DeviceObject,
|
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FilePositionInformation:
|
|
|
|
Status = NtfsGetPositionInformation(FileObject,
|
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileBasicInformation:
|
|
|
|
Status = NtfsGetBasicInformation(FileObject,
|
|
|
|
Fcb,
|
|
|
|
DeviceObject,
|
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileNameInformation:
|
|
|
|
Status = NtfsGetNameInformation(FileObject,
|
2015-05-10 14:36:00 +00:00
|
|
|
Fcb,
|
|
|
|
DeviceObject,
|
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
2013-06-16 12:15:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FileInternalInformation:
|
|
|
|
Status = NtfsGetInternalInformation(Fcb,
|
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
|
|
|
break;
|
|
|
|
|
2014-11-02 22:56:53 +00:00
|
|
|
case FileNetworkOpenInformation:
|
|
|
|
Status = NtfsGetNetworkOpenInformation(Fcb,
|
|
|
|
DeviceObject->DeviceExtension,
|
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
|
|
|
break;
|
|
|
|
|
2015-08-24 08:36:58 +00:00
|
|
|
case FileStreamInformation:
|
2024-02-22 19:33:34 +00:00
|
|
|
Status = NtfsGetStreamInformation(Fcb,
|
|
|
|
DeviceObject->DeviceExtension,
|
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
2015-08-24 08:36:58 +00:00
|
|
|
break;
|
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
case FileAlternateNameInformation:
|
|
|
|
case FileAllInformation:
|
2017-07-27 18:22:24 +00:00
|
|
|
DPRINT1("Unimplemented information class: %s\n", GetInfoClassName(FileInformationClass));
|
2013-06-16 12:15:06 +00:00
|
|
|
Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-07-27 18:22:24 +00:00
|
|
|
DPRINT1("Unimplemented information class: %s\n", GetInfoClassName(FileInformationClass));
|
2013-06-16 12:15:06 +00:00
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2015-05-25 17:06:00 +00:00
|
|
|
ExReleaseResourceLite(&Fcb->MainResource);
|
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
Irp->IoStatus.Information =
|
|
|
|
Stack->Parameters.QueryFile.Length - BufferLength;
|
|
|
|
else
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
|
|
|
|
return Status;
|
2002-06-25 22:23:06 +00:00
|
|
|
}
|
|
|
|
|
2017-05-27 03:20:31 +00:00
|
|
|
/**
|
|
|
|
* @name NtfsSetEndOfFile
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* Sets the end of file (file size) for a given file.
|
|
|
|
*
|
|
|
|
* @param Fcb
|
|
|
|
* Pointer to an NTFS_FCB which describes the target file. Fcb->MainResource should have been
|
|
|
|
* acquired with ExAcquireResourceSharedLite().
|
|
|
|
*
|
|
|
|
* @param FileObject
|
|
|
|
* Pointer to a FILE_OBJECT describing the target file.
|
|
|
|
*
|
|
|
|
* @param DeviceExt
|
|
|
|
* Points to the target disk's DEVICE_EXTENSION
|
|
|
|
*
|
|
|
|
* @param IrpFlags
|
|
|
|
* ULONG describing the flags of the original IRP request (Irp->Flags).
|
|
|
|
*
|
2017-06-24 04:36:28 +00:00
|
|
|
* @param CaseSensitive
|
|
|
|
* Boolean indicating if the function should operate in case-sensitive mode. This will be TRUE
|
|
|
|
* if an application opened the file with the FILE_FLAG_POSIX_SEMANTICS flag.
|
|
|
|
*
|
2017-05-27 03:20:31 +00:00
|
|
|
* @param NewFileSize
|
|
|
|
* Pointer to a LARGE_INTEGER which indicates the new end of file (file size).
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* STATUS_SUCCESS if successful,
|
|
|
|
* STATUS_USER_MAPPED_FILE if trying to truncate a file but MmCanFileBeTruncated() returned false,
|
|
|
|
* STATUS_OBJECT_NAME_NOT_FOUND if there was no $DATA attribute associated with the target file,
|
|
|
|
* STATUS_INVALID_PARAMETER if there was no $FILENAME attribute associated with the target file,
|
|
|
|
* STATUS_INSUFFICIENT_RESOURCES if an allocation failed,
|
|
|
|
* STATUS_ACCESS_DENIED if target file is a volume or if paging is involved.
|
|
|
|
*
|
2021-06-11 12:29:21 +00:00
|
|
|
* @remarks As this function sets the size of a file at the file-level
|
|
|
|
* (and not at the attribute level) it's not recommended to use this
|
2017-05-27 03:20:31 +00:00
|
|
|
* function alongside functions that operate on the data attribute directly.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NtfsSetEndOfFile(PNTFS_FCB Fcb,
|
|
|
|
PFILE_OBJECT FileObject,
|
|
|
|
PDEVICE_EXTENSION DeviceExt,
|
|
|
|
ULONG IrpFlags,
|
2017-06-24 04:36:28 +00:00
|
|
|
BOOLEAN CaseSensitive,
|
2017-05-27 03:20:31 +00:00
|
|
|
PLARGE_INTEGER NewFileSize)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER CurrentFileSize;
|
|
|
|
PFILE_RECORD_HEADER FileRecord;
|
|
|
|
PNTFS_ATTR_CONTEXT DataContext;
|
|
|
|
ULONG AttributeOffset;
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
ULONGLONG AllocationSize;
|
2017-07-05 03:11:13 +00:00
|
|
|
PFILENAME_ATTRIBUTE FileNameAttribute;
|
2017-05-27 03:20:31 +00:00
|
|
|
ULONGLONG ParentMFTId;
|
2017-07-05 03:11:13 +00:00
|
|
|
UNICODE_STRING FileName;
|
2017-05-27 03:20:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Allocate non-paged memory for the file record
|
2017-12-31 13:14:24 +00:00
|
|
|
FileRecord = ExAllocateFromNPagedLookasideList(&DeviceExt->FileRecLookasideList);
|
2017-05-27 03:20:31 +00:00
|
|
|
if (FileRecord == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("Couldn't allocate memory for file record!");
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// read the file record
|
|
|
|
DPRINT("Reading file record...\n");
|
|
|
|
Status = ReadFileRecord(DeviceExt, Fcb->MFTIndex, FileRecord);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
// We couldn't get the file's record. Free the memory and return the error
|
|
|
|
DPRINT1("Can't find record for %wS!\n", Fcb->ObjectName);
|
2017-12-31 13:14:24 +00:00
|
|
|
ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
|
2017-05-27 03:20:31 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT("Found record for %wS\n", Fcb->ObjectName);
|
|
|
|
|
2017-08-04 17:58:06 +00:00
|
|
|
CurrentFileSize.QuadPart = NtfsGetFileSize(DeviceExt, FileRecord, L"", 0, NULL);
|
2017-05-27 03:20:31 +00:00
|
|
|
|
|
|
|
// Are we trying to decrease the file size?
|
|
|
|
if (NewFileSize->QuadPart < CurrentFileSize.QuadPart)
|
|
|
|
{
|
|
|
|
// Is the file mapped?
|
|
|
|
if (!MmCanFileBeTruncated(FileObject->SectionObjectPointer,
|
|
|
|
NewFileSize))
|
|
|
|
{
|
|
|
|
DPRINT1("Couldn't decrease file size!\n");
|
2017-12-31 13:14:24 +00:00
|
|
|
ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
|
2017-05-27 03:20:31 +00:00
|
|
|
return STATUS_USER_MAPPED_FILE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the attribute with the data stream for our file
|
|
|
|
DPRINT("Finding Data Attribute...\n");
|
|
|
|
Status = FindAttribute(DeviceExt,
|
|
|
|
FileRecord,
|
|
|
|
AttributeData,
|
|
|
|
Fcb->Stream,
|
|
|
|
wcslen(Fcb->Stream),
|
|
|
|
&DataContext,
|
|
|
|
&AttributeOffset);
|
|
|
|
|
|
|
|
// Did we fail to find the attribute?
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("No '%S' data stream associated with file!\n", Fcb->Stream);
|
2017-12-31 13:14:24 +00:00
|
|
|
ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
|
2017-05-27 03:20:31 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the size of the data attribute
|
2017-08-06 02:54:15 +00:00
|
|
|
CurrentFileSize.QuadPart = AttributeDataLength(DataContext->pRecord);
|
2017-05-27 03:20:31 +00:00
|
|
|
|
|
|
|
// Are we enlarging the attribute?
|
|
|
|
if (NewFileSize->QuadPart > CurrentFileSize.QuadPart)
|
|
|
|
{
|
|
|
|
// is increasing the stream size not allowed?
|
|
|
|
if ((Fcb->Flags & FCB_IS_VOLUME) ||
|
|
|
|
(IrpFlags & IRP_PAGING_IO))
|
|
|
|
{
|
|
|
|
// TODO - just fail for now
|
|
|
|
ReleaseAttributeContext(DataContext);
|
2017-12-31 13:14:24 +00:00
|
|
|
ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
|
2017-05-27 03:20:31 +00:00
|
|
|
return STATUS_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the attribute data length
|
|
|
|
Status = SetAttributeDataLength(FileObject, Fcb, DataContext, AttributeOffset, FileRecord, NewFileSize);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ReleaseAttributeContext(DataContext);
|
2017-12-31 13:14:24 +00:00
|
|
|
ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
|
2017-05-27 03:20:31 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now we need to update this file's size in every directory index entry that references it
|
|
|
|
// TODO: expand to work with every filename / hardlink stored in the file record.
|
2017-07-05 03:11:13 +00:00
|
|
|
FileNameAttribute = GetBestFileNameFromRecord(Fcb->Vcb, FileRecord);
|
|
|
|
if (FileNameAttribute == NULL)
|
2017-05-27 03:20:31 +00:00
|
|
|
{
|
|
|
|
DPRINT1("Unable to find FileName attribute associated with file!\n");
|
2017-07-05 03:11:13 +00:00
|
|
|
ReleaseAttributeContext(DataContext);
|
2017-12-31 13:14:24 +00:00
|
|
|
ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
|
2017-05-27 03:20:31 +00:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2017-07-05 03:11:13 +00:00
|
|
|
ParentMFTId = FileNameAttribute->DirectoryFileReferenceNumber & NTFS_MFT_MASK;
|
2017-05-27 03:20:31 +00:00
|
|
|
|
2017-07-05 03:11:13 +00:00
|
|
|
FileName.Buffer = FileNameAttribute->Name;
|
|
|
|
FileName.Length = FileNameAttribute->NameLength * sizeof(WCHAR);
|
|
|
|
FileName.MaximumLength = FileName.Length;
|
2017-05-27 03:20:31 +00:00
|
|
|
|
2017-08-06 02:54:15 +00:00
|
|
|
AllocationSize = AttributeAllocatedLength(DataContext->pRecord);
|
2017-05-27 03:20:31 +00:00
|
|
|
|
2017-06-24 04:36:28 +00:00
|
|
|
Status = UpdateFileNameRecord(Fcb->Vcb,
|
|
|
|
ParentMFTId,
|
2017-07-05 03:11:13 +00:00
|
|
|
&FileName,
|
2017-06-24 04:36:28 +00:00
|
|
|
FALSE,
|
|
|
|
NewFileSize->QuadPart,
|
|
|
|
AllocationSize,
|
|
|
|
CaseSensitive);
|
2017-05-27 03:20:31 +00:00
|
|
|
|
|
|
|
ReleaseAttributeContext(DataContext);
|
2017-12-31 13:14:24 +00:00
|
|
|
ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
|
2017-05-27 03:20:31 +00:00
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name NtfsSetInformation
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* Sets the specified file information.
|
|
|
|
*
|
|
|
|
* @param IrpContext
|
|
|
|
* Points to an NTFS_IRP_CONTEXT which describes the set operation
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* STATUS_SUCCESS if successful,
|
|
|
|
* STATUS_NOT_IMPLEMENTED if trying to set an unimplemented information class,
|
|
|
|
* STATUS_USER_MAPPED_FILE if trying to truncate a file but MmCanFileBeTruncated() returned false,
|
|
|
|
* STATUS_OBJECT_NAME_NOT_FOUND if there was no $DATA attribute associated with the target file,
|
|
|
|
* STATUS_INVALID_PARAMETER if there was no $FILENAME attribute associated with the target file,
|
|
|
|
* STATUS_INSUFFICIENT_RESOURCES if an allocation failed,
|
|
|
|
* STATUS_ACCESS_DENIED if target file is a volume or if paging is involved.
|
|
|
|
*
|
|
|
|
* @remarks Called by NtfsDispatch() in response to an IRP_MJ_SET_INFORMATION request.
|
|
|
|
* Only the FileEndOfFileInformation InformationClass is fully implemented. FileAllocationInformation
|
2021-06-11 12:29:21 +00:00
|
|
|
* is a hack and not a true implementation, but it's enough to make SetEndOfFile() work.
|
2017-05-27 03:20:31 +00:00
|
|
|
* All other information classes are TODO.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NtfsSetInformation(PNTFS_IRP_CONTEXT IrpContext)
|
|
|
|
{
|
|
|
|
FILE_INFORMATION_CLASS FileInformationClass;
|
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
PDEVICE_EXTENSION DeviceExt;
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
PNTFS_FCB Fcb;
|
|
|
|
PVOID SystemBuffer;
|
|
|
|
ULONG BufferLength;
|
|
|
|
PIRP Irp;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
NTSTATUS Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
2019-06-15 16:24:27 +00:00
|
|
|
DPRINT("NtfsSetInformation(%p)\n", IrpContext);
|
2017-05-27 03:20:31 +00:00
|
|
|
|
|
|
|
Irp = IrpContext->Irp;
|
|
|
|
Stack = IrpContext->Stack;
|
|
|
|
DeviceObject = IrpContext->DeviceObject;
|
|
|
|
DeviceExt = DeviceObject->DeviceExtension;
|
|
|
|
FileInformationClass = Stack->Parameters.QueryFile.FileInformationClass;
|
|
|
|
FileObject = IrpContext->FileObject;
|
|
|
|
Fcb = FileObject->FsContext;
|
|
|
|
|
|
|
|
SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
BufferLength = Stack->Parameters.QueryFile.Length;
|
|
|
|
|
|
|
|
if (!ExAcquireResourceSharedLite(&Fcb->MainResource,
|
|
|
|
BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
|
|
|
|
{
|
|
|
|
return NtfsMarkIrpContextForQueue(IrpContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (FileInformationClass)
|
|
|
|
{
|
|
|
|
PFILE_END_OF_FILE_INFORMATION EndOfFileInfo;
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
/* TODO: Allocation size is not actually the same as file end for NTFS,
|
2017-05-27 03:20:31 +00:00
|
|
|
however, few applications are likely to make the distinction. */
|
2021-06-11 12:29:21 +00:00
|
|
|
case FileAllocationInformation:
|
2017-05-27 03:20:31 +00:00
|
|
|
DPRINT1("FIXME: Using hacky method of setting FileAllocationInformation.\n");
|
|
|
|
case FileEndOfFileInformation:
|
|
|
|
EndOfFileInfo = (PFILE_END_OF_FILE_INFORMATION)SystemBuffer;
|
2017-06-24 04:36:28 +00:00
|
|
|
Status = NtfsSetEndOfFile(Fcb,
|
|
|
|
FileObject,
|
|
|
|
DeviceExt,
|
|
|
|
Irp->Flags,
|
2017-06-28 18:22:42 +00:00
|
|
|
BooleanFlagOn(Stack->Flags, SL_CASE_SENSITIVE),
|
2017-06-24 04:36:28 +00:00
|
|
|
&EndOfFileInfo->EndOfFile);
|
2017-05-27 03:20:31 +00:00
|
|
|
break;
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2017-05-27 03:20:31 +00:00
|
|
|
// TODO: all other information classes
|
|
|
|
|
|
|
|
default:
|
2017-07-27 18:22:24 +00:00
|
|
|
DPRINT1("FIXME: Unimplemented information class: %s\n", GetInfoClassName(FileInformationClass));
|
2017-05-27 03:20:31 +00:00
|
|
|
Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExReleaseResourceLite(&Fcb->MainResource);
|
|
|
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
Irp->IoStatus.Information =
|
|
|
|
Stack->Parameters.QueryFile.Length - BufferLength;
|
|
|
|
else
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
2002-06-25 22:23:06 +00:00
|
|
|
/* EOF */
|