2002-06-25 22:23:06 +00:00
|
|
|
/*
|
|
|
|
* ReactOS kernel
|
2014-11-02 21:50:40 +00:00
|
|
|
* Copyright (C) 2002, 2003, 2014 ReactOS Team
|
2002-06-25 22:23:06 +00:00
|
|
|
*
|
|
|
|
* 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 21:50:40 +00:00
|
|
|
* PROGRAMMERS: Eric Kohl
|
|
|
|
* Pierre Schweitzer (pierre@reactos.org)
|
2014-11-02 22:56:38 +00:00
|
|
|
* Hervé Poussineau (hpoussin@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 ****************************************************************/
|
|
|
|
|
2015-07-05 19:04:05 +00:00
|
|
|
ULONGLONG
|
2015-06-28 21:26:19 +00:00
|
|
|
NtfsGetFileSize(PDEVICE_EXTENSION DeviceExt,
|
|
|
|
PFILE_RECORD_HEADER FileRecord,
|
2015-07-05 19:04:05 +00:00
|
|
|
PCWSTR Stream,
|
|
|
|
ULONG StreamLength,
|
|
|
|
PULONGLONG AllocatedSize)
|
2015-06-28 20:55:29 +00:00
|
|
|
{
|
2015-07-05 19:04:05 +00:00
|
|
|
ULONGLONG Size = 0ULL;
|
|
|
|
ULONGLONG Allocated = 0ULL;
|
2015-06-28 21:26:19 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PNTFS_ATTR_CONTEXT DataContext;
|
2015-06-28 20:55:29 +00:00
|
|
|
|
2016-06-22 21:20:50 +00:00
|
|
|
Status = FindAttribute(DeviceExt, FileRecord, AttributeData, Stream, StreamLength, &DataContext, NULL);
|
2015-06-28 21:26:19 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
2015-06-28 20:55:29 +00:00
|
|
|
{
|
2017-08-06 02:54:15 +00:00
|
|
|
Size = AttributeDataLength(DataContext->pRecord);
|
|
|
|
Allocated = AttributeAllocatedLength(DataContext->pRecord);
|
2015-06-28 21:26:19 +00:00
|
|
|
ReleaseAttributeContext(DataContext);
|
2015-06-28 20:55:29 +00:00
|
|
|
}
|
|
|
|
|
2015-07-05 19:04:05 +00:00
|
|
|
if (AllocatedSize != NULL) *AllocatedSize = Allocated;
|
|
|
|
|
2015-06-28 20:55:29 +00:00
|
|
|
return Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
#define ULONG_ROUND_UP(x) ROUND_UP((x), (sizeof(ULONG)))
|
|
|
|
|
|
|
|
|
2002-06-25 22:23:06 +00:00
|
|
|
static NTSTATUS
|
2017-12-10 10:25:48 +00:00
|
|
|
NtfsGetNamesInformation(PDEVICE_EXTENSION DeviceExt,
|
|
|
|
PFILE_RECORD_HEADER FileRecord,
|
|
|
|
ULONGLONG MFTIndex,
|
|
|
|
PFILE_NAMES_INFORMATION Info,
|
2018-01-06 20:39:25 +00:00
|
|
|
ULONG BufferLength,
|
|
|
|
PULONG Written,
|
|
|
|
BOOLEAN First)
|
2002-06-25 22:23:06 +00:00
|
|
|
{
|
2014-10-15 21:02:05 +00:00
|
|
|
ULONG Length;
|
2018-01-06 20:39:25 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG BytesToCopy = 0;
|
2014-10-15 21:02:05 +00:00
|
|
|
PFILENAME_ATTRIBUTE FileName;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2017-12-10 10:25:48 +00:00
|
|
|
DPRINT("NtfsGetNamesInformation() called\n");
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
*Written = 0;
|
|
|
|
Status = STATUS_BUFFER_OVERFLOW;
|
|
|
|
if (FIELD_OFFSET(FILE_NAMES_INFORMATION, FileName) > BufferLength)
|
|
|
|
{
|
|
|
|
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
|
|
|
FileName = GetBestFileNameFromRecord(DeviceExt, FileRecord);
|
2015-06-27 13:40:05 +00:00
|
|
|
if (FileName == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("No name information for file ID: %#I64x\n", MFTIndex);
|
2015-06-27 15:06:25 +00:00
|
|
|
NtfsDumpFileAttributes(DeviceExt, FileRecord);
|
2015-06-27 13:40:05 +00:00
|
|
|
return STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
}
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2014-10-19 16:29:38 +00:00
|
|
|
Length = FileName->NameLength * sizeof (WCHAR);
|
2018-01-06 20:39:25 +00:00
|
|
|
if (First || (BufferLength >= FIELD_OFFSET(FILE_NAMES_INFORMATION, FileName) + Length))
|
|
|
|
{
|
|
|
|
Info->FileNameLength = Length;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
*Written = FIELD_OFFSET(FILE_NAMES_INFORMATION, FileName);
|
|
|
|
Info->NextEntryOffset = 0;
|
|
|
|
if (BufferLength > FIELD_OFFSET(FILE_NAMES_INFORMATION, FileName))
|
|
|
|
{
|
|
|
|
BytesToCopy = min(Length, BufferLength - FIELD_OFFSET(FILE_NAMES_INFORMATION, FileName));
|
|
|
|
RtlCopyMemory(Info->FileName, FileName->Name, BytesToCopy);
|
|
|
|
*Written += BytesToCopy;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
if (BytesToCopy == Length)
|
|
|
|
{
|
|
|
|
Info->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_NAMES_INFORMATION) +
|
|
|
|
BytesToCopy);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
2002-06-25 22:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static NTSTATUS
|
2014-10-15 21:02:05 +00:00
|
|
|
NtfsGetDirectoryInformation(PDEVICE_EXTENSION DeviceExt,
|
|
|
|
PFILE_RECORD_HEADER FileRecord,
|
2015-01-08 20:29:04 +00:00
|
|
|
ULONGLONG MFTIndex,
|
2014-10-15 21:02:05 +00:00
|
|
|
PFILE_DIRECTORY_INFORMATION Info,
|
2018-01-06 20:39:25 +00:00
|
|
|
ULONG BufferLength,
|
|
|
|
PULONG Written,
|
|
|
|
BOOLEAN First)
|
2002-06-25 22:23:06 +00:00
|
|
|
{
|
2014-10-15 21:02:05 +00:00
|
|
|
ULONG Length;
|
2018-01-06 20:39:25 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG BytesToCopy = 0;
|
2014-10-15 21:02:05 +00:00
|
|
|
PFILENAME_ATTRIBUTE FileName;
|
2015-01-08 20:28:25 +00:00
|
|
|
PSTANDARD_INFORMATION StdInfo;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2014-10-15 21:02:05 +00:00
|
|
|
DPRINT("NtfsGetDirectoryInformation() called\n");
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
*Written = 0;
|
|
|
|
Status = STATUS_BUFFER_OVERFLOW;
|
|
|
|
if (FIELD_OFFSET(FILE_DIRECTORY_INFORMATION, FileName) > BufferLength)
|
|
|
|
{
|
|
|
|
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
|
|
|
FileName = GetBestFileNameFromRecord(DeviceExt, FileRecord);
|
2015-06-27 13:40:05 +00:00
|
|
|
if (FileName == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("No name information for file ID: %#I64x\n", MFTIndex);
|
2015-06-27 15:06:25 +00:00
|
|
|
NtfsDumpFileAttributes(DeviceExt, FileRecord);
|
2015-06-27 13:40:05 +00:00
|
|
|
return STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
}
|
2002-06-25 22:23:06 +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
|
|
|
StdInfo = GetStandardInformationFromRecord(DeviceExt, FileRecord);
|
2015-01-08 20:28:25 +00:00
|
|
|
ASSERT(StdInfo != NULL);
|
|
|
|
|
2014-10-19 16:29:38 +00:00
|
|
|
Length = FileName->NameLength * sizeof (WCHAR);
|
2018-01-06 20:39:25 +00:00
|
|
|
if (First || (BufferLength >= FIELD_OFFSET(FILE_DIRECTORY_INFORMATION, FileName) + Length))
|
|
|
|
{
|
|
|
|
Info->FileNameLength = Length;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
*Written = FIELD_OFFSET(FILE_DIRECTORY_INFORMATION, FileName);
|
|
|
|
Info->NextEntryOffset = 0;
|
|
|
|
if (BufferLength > FIELD_OFFSET(FILE_DIRECTORY_INFORMATION, FileName))
|
|
|
|
{
|
|
|
|
BytesToCopy = min(Length, BufferLength - FIELD_OFFSET(FILE_DIRECTORY_INFORMATION, FileName));
|
|
|
|
RtlCopyMemory(Info->FileName, FileName->Name, BytesToCopy);
|
|
|
|
*Written += BytesToCopy;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
if (BytesToCopy == Length)
|
|
|
|
{
|
|
|
|
Info->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_DIRECTORY_INFORMATION) +
|
|
|
|
BytesToCopy);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
Info->CreationTime.QuadPart = FileName->CreationTime;
|
|
|
|
Info->LastAccessTime.QuadPart = FileName->LastAccessTime;
|
|
|
|
Info->LastWriteTime.QuadPart = FileName->LastWriteTime;
|
|
|
|
Info->ChangeTime.QuadPart = FileName->ChangeTime;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
/* Convert file flags */
|
|
|
|
NtfsFileFlagsToAttributes(FileName->FileAttributes | StdInfo->FileAttribute, &Info->FileAttributes);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
Info->EndOfFile.QuadPart = NtfsGetFileSize(DeviceExt, FileRecord, L"", 0, (PULONGLONG)&Info->AllocationSize.QuadPart);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
Info->FileIndex = MFTIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
2002-06-25 22:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static NTSTATUS
|
2014-10-15 21:02:05 +00:00
|
|
|
NtfsGetFullDirectoryInformation(PDEVICE_EXTENSION DeviceExt,
|
|
|
|
PFILE_RECORD_HEADER FileRecord,
|
2014-12-15 21:44:52 +00:00
|
|
|
ULONGLONG MFTIndex,
|
2014-10-15 21:02:05 +00:00
|
|
|
PFILE_FULL_DIRECTORY_INFORMATION Info,
|
2018-01-06 20:39:25 +00:00
|
|
|
ULONG BufferLength,
|
|
|
|
PULONG Written,
|
|
|
|
BOOLEAN First)
|
2002-06-25 22:23:06 +00:00
|
|
|
{
|
2014-10-15 21:02:05 +00:00
|
|
|
ULONG Length;
|
2018-01-06 20:39:25 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG BytesToCopy = 0;
|
2014-10-15 21:02:05 +00:00
|
|
|
PFILENAME_ATTRIBUTE FileName;
|
2015-01-08 20:28:25 +00:00
|
|
|
PSTANDARD_INFORMATION StdInfo;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2014-10-15 21:02:05 +00:00
|
|
|
DPRINT("NtfsGetFullDirectoryInformation() called\n");
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
*Written = 0;
|
|
|
|
Status = STATUS_BUFFER_OVERFLOW;
|
|
|
|
if (FIELD_OFFSET(FILE_FULL_DIR_INFORMATION, FileName) > BufferLength)
|
|
|
|
{
|
|
|
|
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
|
|
|
FileName = GetBestFileNameFromRecord(DeviceExt, FileRecord);
|
2015-06-27 13:40:05 +00:00
|
|
|
if (FileName == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("No name information for file ID: %#I64x\n", MFTIndex);
|
2015-06-27 15:06:25 +00:00
|
|
|
NtfsDumpFileAttributes(DeviceExt, FileRecord);
|
2015-06-27 13:40:05 +00:00
|
|
|
return STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
}
|
2002-06-25 22:23:06 +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
|
|
|
StdInfo = GetStandardInformationFromRecord(DeviceExt, FileRecord);
|
2015-01-08 20:28:25 +00:00
|
|
|
ASSERT(StdInfo != NULL);
|
|
|
|
|
2014-10-19 16:29:38 +00:00
|
|
|
Length = FileName->NameLength * sizeof (WCHAR);
|
2018-01-06 20:39:25 +00:00
|
|
|
if (First || (BufferLength >= FIELD_OFFSET(FILE_FULL_DIR_INFORMATION, FileName) + Length))
|
|
|
|
{
|
|
|
|
Info->FileNameLength = Length;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
*Written = FIELD_OFFSET(FILE_FULL_DIR_INFORMATION, FileName);
|
|
|
|
Info->NextEntryOffset = 0;
|
|
|
|
if (BufferLength > FIELD_OFFSET(FILE_FULL_DIR_INFORMATION, FileName))
|
|
|
|
{
|
|
|
|
BytesToCopy = min(Length, BufferLength - FIELD_OFFSET(FILE_FULL_DIR_INFORMATION, FileName));
|
|
|
|
RtlCopyMemory(Info->FileName, FileName->Name, BytesToCopy);
|
|
|
|
*Written += BytesToCopy;
|
|
|
|
|
|
|
|
if (BytesToCopy == Length)
|
|
|
|
{
|
|
|
|
Info->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_FULL_DIR_INFORMATION) +
|
|
|
|
BytesToCopy);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
Info->CreationTime.QuadPart = FileName->CreationTime;
|
|
|
|
Info->LastAccessTime.QuadPart = FileName->LastAccessTime;
|
|
|
|
Info->LastWriteTime.QuadPart = FileName->LastWriteTime;
|
|
|
|
Info->ChangeTime.QuadPart = FileName->ChangeTime;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
/* Convert file flags */
|
|
|
|
NtfsFileFlagsToAttributes(FileName->FileAttributes | StdInfo->FileAttribute, &Info->FileAttributes);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
Info->EndOfFile.QuadPart = NtfsGetFileSize(DeviceExt, FileRecord, L"", 0, (PULONGLONG)&Info->AllocationSize.QuadPart);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
Info->FileIndex = MFTIndex;
|
|
|
|
Info->EaSize = 0;
|
|
|
|
}
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
return Status;
|
2002-06-25 22:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static NTSTATUS
|
2014-10-15 21:02:05 +00:00
|
|
|
NtfsGetBothDirectoryInformation(PDEVICE_EXTENSION DeviceExt,
|
|
|
|
PFILE_RECORD_HEADER FileRecord,
|
2014-12-15 21:44:52 +00:00
|
|
|
ULONGLONG MFTIndex,
|
2014-10-15 21:02:05 +00:00
|
|
|
PFILE_BOTH_DIR_INFORMATION Info,
|
2018-01-06 20:39:25 +00:00
|
|
|
ULONG BufferLength,
|
|
|
|
PULONG Written,
|
|
|
|
BOOLEAN First)
|
2002-06-25 22:23:06 +00:00
|
|
|
{
|
2014-10-15 21:02:05 +00:00
|
|
|
ULONG Length;
|
2018-01-06 20:39:25 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG BytesToCopy = 0;
|
2014-10-26 19:10:39 +00:00
|
|
|
PFILENAME_ATTRIBUTE FileName, ShortFileName;
|
2015-01-08 20:28:25 +00:00
|
|
|
PSTANDARD_INFORMATION StdInfo;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2014-10-15 21:02:05 +00:00
|
|
|
DPRINT("NtfsGetBothDirectoryInformation() called\n");
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
*Written = 0;
|
|
|
|
Status = STATUS_BUFFER_OVERFLOW;
|
|
|
|
if (FIELD_OFFSET(FILE_BOTH_DIR_INFORMATION, FileName) > BufferLength)
|
|
|
|
{
|
|
|
|
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
|
|
|
FileName = GetBestFileNameFromRecord(DeviceExt, FileRecord);
|
2015-06-27 13:40:05 +00:00
|
|
|
if (FileName == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("No name information for file ID: %#I64x\n", MFTIndex);
|
2015-06-27 15:06:25 +00:00
|
|
|
NtfsDumpFileAttributes(DeviceExt, FileRecord);
|
2015-06-27 13:40:05 +00:00
|
|
|
return STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
}
|
[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
|
|
|
ShortFileName = GetFileNameFromRecord(DeviceExt, FileRecord, NTFS_FILE_NAME_DOS);
|
2002-06-25 22:23:06 +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
|
|
|
StdInfo = GetStandardInformationFromRecord(DeviceExt, FileRecord);
|
2015-01-08 20:28:25 +00:00
|
|
|
ASSERT(StdInfo != NULL);
|
|
|
|
|
2014-10-19 16:29:38 +00:00
|
|
|
Length = FileName->NameLength * sizeof (WCHAR);
|
2018-01-06 20:39:25 +00:00
|
|
|
if (First || (BufferLength >= FIELD_OFFSET(FILE_BOTH_DIR_INFORMATION, FileName) + Length))
|
|
|
|
{
|
|
|
|
Info->FileNameLength = Length;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
*Written = FIELD_OFFSET(FILE_BOTH_DIR_INFORMATION, FileName);
|
|
|
|
Info->NextEntryOffset = 0;
|
|
|
|
if (BufferLength > FIELD_OFFSET(FILE_BOTH_DIR_INFORMATION, FileName))
|
|
|
|
{
|
|
|
|
BytesToCopy = min(Length, BufferLength - FIELD_OFFSET(FILE_BOTH_DIR_INFORMATION, FileName));
|
|
|
|
RtlCopyMemory(Info->FileName, FileName->Name, BytesToCopy);
|
|
|
|
*Written += BytesToCopy;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
if (BytesToCopy == Length)
|
|
|
|
{
|
|
|
|
Info->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_BOTH_DIR_INFORMATION) +
|
|
|
|
BytesToCopy);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ShortFileName)
|
|
|
|
{
|
|
|
|
/* Should we upcase the filename? */
|
|
|
|
ASSERT(ShortFileName->NameLength <= ARRAYSIZE(Info->ShortName));
|
|
|
|
Info->ShortNameLength = ShortFileName->NameLength * sizeof(WCHAR);
|
|
|
|
RtlCopyMemory(Info->ShortName, ShortFileName->Name, Info->ShortNameLength);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Info->ShortName[0] = 0;
|
|
|
|
Info->ShortNameLength = 0;
|
|
|
|
}
|
2014-10-26 19:10:39 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
Info->CreationTime.QuadPart = FileName->CreationTime;
|
|
|
|
Info->LastAccessTime.QuadPart = FileName->LastAccessTime;
|
|
|
|
Info->LastWriteTime.QuadPart = FileName->LastWriteTime;
|
|
|
|
Info->ChangeTime.QuadPart = FileName->ChangeTime;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
/* Convert file flags */
|
|
|
|
NtfsFileFlagsToAttributes(FileName->FileAttributes | StdInfo->FileAttribute, &Info->FileAttributes);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
Info->EndOfFile.QuadPart = NtfsGetFileSize(DeviceExt, FileRecord, L"", 0, (PULONGLONG)&Info->AllocationSize.QuadPart);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
Info->FileIndex = MFTIndex;
|
|
|
|
Info->EaSize = 0;
|
|
|
|
}
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
return Status;
|
2002-06-25 22:23:06 +00:00
|
|
|
}
|
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
|
2008-03-09 13:58:25 +00:00
|
|
|
NTSTATUS
|
|
|
|
NtfsQueryDirectory(PNTFS_IRP_CONTEXT IrpContext)
|
2002-06-25 22:23:06 +00:00
|
|
|
{
|
2013-06-16 12:15:06 +00:00
|
|
|
PIRP Irp;
|
2014-10-15 21:02:05 +00:00
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
PDEVICE_EXTENSION DeviceExtension;
|
|
|
|
LONG BufferLength = 0;
|
2013-06-16 12:15:06 +00:00
|
|
|
PUNICODE_STRING SearchPattern = NULL;
|
2014-10-15 21:02:05 +00:00
|
|
|
FILE_INFORMATION_CLASS FileInformationClass;
|
2013-06-16 12:15:06 +00:00
|
|
|
ULONG FileIndex = 0;
|
|
|
|
PUCHAR Buffer = NULL;
|
|
|
|
PFILE_NAMES_INFORMATION Buffer0 = NULL;
|
2014-10-15 21:02:05 +00:00
|
|
|
PNTFS_FCB Fcb;
|
2013-06-16 12:15:06 +00:00
|
|
|
PNTFS_CCB Ccb;
|
|
|
|
BOOLEAN First = FALSE;
|
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
PFILE_OBJECT FileObject;
|
2014-10-15 21:02:05 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
PFILE_RECORD_HEADER FileRecord;
|
2014-11-02 20:18:34 +00:00
|
|
|
ULONGLONG MFTRecord, OldMFTRecord = 0;
|
2014-10-15 21:02:05 +00:00
|
|
|
UNICODE_STRING Pattern;
|
2018-01-06 20:39:25 +00:00
|
|
|
ULONG Written;
|
2013-06-16 12:15:06 +00:00
|
|
|
|
2019-06-15 16:24:27 +00:00
|
|
|
DPRINT("NtfsQueryDirectory() called\n");
|
2013-06-16 12:15:06 +00:00
|
|
|
|
|
|
|
ASSERT(IrpContext);
|
|
|
|
Irp = IrpContext->Irp;
|
2014-10-15 21:02:05 +00:00
|
|
|
DeviceObject = IrpContext->DeviceObject;
|
2013-06-16 12:15:06 +00:00
|
|
|
|
2014-10-15 21:02:05 +00:00
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
2013-06-16 12:15:06 +00:00
|
|
|
Stack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
FileObject = Stack->FileObject;
|
|
|
|
|
|
|
|
Ccb = (PNTFS_CCB)FileObject->FsContext2;
|
2014-10-15 21:02:05 +00:00
|
|
|
Fcb = (PNTFS_FCB)FileObject->FsContext;
|
2013-06-16 12:15:06 +00:00
|
|
|
|
|
|
|
/* Obtain the callers parameters */
|
2014-10-15 21:02:05 +00:00
|
|
|
BufferLength = Stack->Parameters.QueryDirectory.Length;
|
2013-06-16 12:15:06 +00:00
|
|
|
SearchPattern = Stack->Parameters.QueryDirectory.FileName;
|
2014-10-15 21:02:05 +00:00
|
|
|
FileInformationClass = Stack->Parameters.QueryDirectory.FileInformationClass;
|
2013-06-16 12:15:06 +00:00
|
|
|
FileIndex = Stack->Parameters.QueryDirectory.FileIndex;
|
|
|
|
|
2016-02-14 22:44:54 +00:00
|
|
|
if (NtfsFCBIsCompressed(Fcb))
|
|
|
|
{
|
|
|
|
DPRINT1("Compressed directory!\n");
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2016-02-23 22:19:38 +00:00
|
|
|
if (!ExAcquireResourceSharedLite(&Fcb->MainResource,
|
|
|
|
BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
|
|
|
|
{
|
|
|
|
return STATUS_PENDING;
|
|
|
|
}
|
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
if (SearchPattern != NULL)
|
2002-06-25 22:23:06 +00:00
|
|
|
{
|
2013-06-16 12:15:06 +00:00
|
|
|
if (!Ccb->DirectorySearchPattern)
|
|
|
|
{
|
|
|
|
First = TRUE;
|
2014-11-02 20:18:27 +00:00
|
|
|
Pattern.Length = 0;
|
|
|
|
Pattern.MaximumLength = SearchPattern->Length + sizeof(WCHAR);
|
|
|
|
Ccb->DirectorySearchPattern = Pattern.Buffer =
|
|
|
|
ExAllocatePoolWithTag(NonPagedPool, Pattern.MaximumLength, TAG_NTFS);
|
2013-06-16 12:15:06 +00:00
|
|
|
if (!Ccb->DirectorySearchPattern)
|
|
|
|
{
|
2016-02-23 22:19:38 +00:00
|
|
|
ExReleaseResourceLite(&Fcb->MainResource);
|
2013-06-16 12:15:06 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2014-11-23 15:49:24 +00:00
|
|
|
memcpy(Ccb->DirectorySearchPattern, SearchPattern->Buffer, SearchPattern->Length);
|
2013-06-16 12:15:06 +00:00
|
|
|
Ccb->DirectorySearchPattern[SearchPattern->Length / sizeof(WCHAR)] = 0;
|
|
|
|
}
|
2002-06-25 22:23:06 +00:00
|
|
|
}
|
2013-06-16 12:15:06 +00:00
|
|
|
else if (!Ccb->DirectorySearchPattern)
|
2002-06-25 22:23:06 +00:00
|
|
|
{
|
2013-06-16 12:15:06 +00:00
|
|
|
First = TRUE;
|
|
|
|
Ccb->DirectorySearchPattern = ExAllocatePoolWithTag(NonPagedPool, 2 * sizeof(WCHAR), TAG_NTFS);
|
|
|
|
if (!Ccb->DirectorySearchPattern)
|
|
|
|
{
|
2016-02-23 22:19:38 +00:00
|
|
|
ExReleaseResourceLite(&Fcb->MainResource);
|
2013-06-16 12:15:06 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ccb->DirectorySearchPattern[0] = L'*';
|
|
|
|
Ccb->DirectorySearchPattern[1] = 0;
|
2002-06-25 22:23:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-15 21:02:05 +00:00
|
|
|
RtlInitUnicodeString(&Pattern, Ccb->DirectorySearchPattern);
|
2014-11-02 20:18:27 +00:00
|
|
|
DPRINT("Search pattern '%S'\n", Ccb->DirectorySearchPattern);
|
|
|
|
DPRINT("In: '%S'\n", Fcb->PathName);
|
2013-06-16 12:15:06 +00:00
|
|
|
|
|
|
|
/* Determine directory index */
|
|
|
|
if (Stack->Flags & SL_INDEX_SPECIFIED)
|
|
|
|
{
|
2018-01-06 20:39:25 +00:00
|
|
|
Ccb->Entry = FileIndex;
|
2013-06-16 12:15:06 +00:00
|
|
|
}
|
|
|
|
else if (First || (Stack->Flags & SL_RESTART_SCAN))
|
|
|
|
{
|
|
|
|
Ccb->Entry = 0;
|
|
|
|
}
|
|
|
|
|
2015-05-25 17:45:04 +00:00
|
|
|
/* Get Buffer for result */
|
|
|
|
Buffer = NtfsGetUserBuffer(Irp, FALSE);
|
2013-06-16 12:15:06 +00:00
|
|
|
|
|
|
|
DPRINT("Buffer=%p tofind=%S\n", Buffer, Ccb->DirectorySearchPattern);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2016-02-25 20:49:31 +00:00
|
|
|
if (!ExAcquireResourceExclusiveLite(&DeviceExtension->DirResource,
|
|
|
|
BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
|
|
|
|
{
|
|
|
|
ExReleaseResourceLite(&Fcb->MainResource);
|
|
|
|
return STATUS_PENDING;
|
|
|
|
}
|
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
Written = 0;
|
2014-10-15 21:02:05 +00:00
|
|
|
while (Status == STATUS_SUCCESS && BufferLength > 0)
|
2002-06-25 22:23:06 +00:00
|
|
|
{
|
2014-10-15 21:02:05 +00:00
|
|
|
Status = NtfsFindFileAt(DeviceExtension,
|
|
|
|
&Pattern,
|
|
|
|
&Ccb->Entry,
|
|
|
|
&FileRecord,
|
|
|
|
&MFTRecord,
|
2017-06-24 04:36:28 +00:00
|
|
|
Fcb->MFTIndex,
|
2017-06-28 18:22:42 +00:00
|
|
|
BooleanFlagOn(Stack->Flags, SL_CASE_SENSITIVE));
|
2014-10-15 21:02:05 +00:00
|
|
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
2014-11-02 20:18:34 +00:00
|
|
|
/* HACK: files with both a short name and a long name are present twice in the index.
|
|
|
|
* Ignore the second entry, if it is immediately following the first one.
|
|
|
|
*/
|
|
|
|
if (MFTRecord == OldMFTRecord)
|
|
|
|
{
|
2015-07-05 19:04:05 +00:00
|
|
|
DPRINT1("Ignoring duplicate MFT entry 0x%x\n", MFTRecord);
|
2014-11-02 20:18:34 +00:00
|
|
|
Ccb->Entry++;
|
2017-12-31 13:14:24 +00:00
|
|
|
ExFreeToNPagedLookasideList(&DeviceExtension->FileRecLookasideList, FileRecord);
|
2014-11-02 20:18:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
OldMFTRecord = MFTRecord;
|
|
|
|
|
2014-10-15 21:02:05 +00:00
|
|
|
switch (FileInformationClass)
|
|
|
|
{
|
2017-12-10 10:25:48 +00:00
|
|
|
case FileNamesInformation:
|
|
|
|
Status = NtfsGetNamesInformation(DeviceExtension,
|
|
|
|
FileRecord,
|
|
|
|
MFTRecord,
|
|
|
|
(PFILE_NAMES_INFORMATION)Buffer,
|
2018-01-06 20:39:25 +00:00
|
|
|
BufferLength,
|
|
|
|
&Written,
|
|
|
|
Buffer0 == NULL);
|
2014-10-15 21:02:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FileDirectoryInformation:
|
|
|
|
Status = NtfsGetDirectoryInformation(DeviceExtension,
|
|
|
|
FileRecord,
|
2015-01-08 20:29:04 +00:00
|
|
|
MFTRecord,
|
2014-10-15 21:02:05 +00:00
|
|
|
(PFILE_DIRECTORY_INFORMATION)Buffer,
|
2018-01-06 20:39:25 +00:00
|
|
|
BufferLength,
|
|
|
|
&Written,
|
|
|
|
Buffer0 == NULL);
|
2014-10-15 21:02:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FileFullDirectoryInformation:
|
|
|
|
Status = NtfsGetFullDirectoryInformation(DeviceExtension,
|
|
|
|
FileRecord,
|
2014-12-15 21:44:52 +00:00
|
|
|
MFTRecord,
|
2014-10-15 21:02:05 +00:00
|
|
|
(PFILE_FULL_DIRECTORY_INFORMATION)Buffer,
|
2018-01-06 20:39:25 +00:00
|
|
|
BufferLength,
|
|
|
|
&Written,
|
|
|
|
Buffer0 == NULL);
|
2014-10-15 21:02:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FileBothDirectoryInformation:
|
|
|
|
Status = NtfsGetBothDirectoryInformation(DeviceExtension,
|
|
|
|
FileRecord,
|
2014-12-15 21:44:52 +00:00
|
|
|
MFTRecord,
|
2014-10-15 21:02:05 +00:00
|
|
|
(PFILE_BOTH_DIR_INFORMATION)Buffer,
|
2018-01-06 20:39:25 +00:00
|
|
|
BufferLength,
|
|
|
|
&Written,
|
|
|
|
Buffer0 == NULL);
|
2014-10-15 21:02:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Status = STATUS_INVALID_INFO_CLASS;
|
|
|
|
}
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2018-01-06 20:39:25 +00:00
|
|
|
if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_INVALID_INFO_CLASS)
|
2014-10-15 21:02:05 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-06 20:39:25 +00:00
|
|
|
Status = (First ? STATUS_NO_SUCH_FILE : STATUS_NO_MORE_FILES);
|
2014-10-15 21:02:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2014-10-15 21:02:05 +00:00
|
|
|
Buffer0 = (PFILE_NAMES_INFORMATION)Buffer;
|
|
|
|
Buffer0->FileIndex = FileIndex++;
|
|
|
|
Ccb->Entry++;
|
2018-01-06 20:39:25 +00:00
|
|
|
BufferLength -= Buffer0->NextEntryOffset;
|
|
|
|
|
|
|
|
ExFreeToNPagedLookasideList(&DeviceExtension->FileRecLookasideList, FileRecord);
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2014-10-15 21:02:05 +00:00
|
|
|
if (Stack->Flags & SL_RETURN_SINGLE_ENTRY)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2018-01-06 20:39:25 +00:00
|
|
|
|
2014-10-15 21:02:05 +00:00
|
|
|
Buffer += Buffer0->NextEntryOffset;
|
2002-06-25 22:23:06 +00:00
|
|
|
}
|
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
if (Buffer0)
|
|
|
|
{
|
|
|
|
Buffer0->NextEntryOffset = 0;
|
2018-01-06 20:39:25 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
IrpContext->Irp->IoStatus.Information = Stack->Parameters.QueryDirectory.Length - BufferLength;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ASSERT(Status != STATUS_SUCCESS || BufferLength == 0);
|
|
|
|
ASSERT(Written <= Stack->Parameters.QueryDirectory.Length);
|
|
|
|
IrpContext->Irp->IoStatus.Information = Written;
|
2013-06-16 12:15:06 +00:00
|
|
|
}
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2016-02-25 20:49:31 +00:00
|
|
|
ExReleaseResourceLite(&DeviceExtension->DirResource);
|
2016-02-23 22:19:38 +00:00
|
|
|
ExReleaseResourceLite(&Fcb->MainResource);
|
|
|
|
|
2014-10-15 21:02:05 +00:00
|
|
|
return Status;
|
2002-06-25 22:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-16 12:15:06 +00:00
|
|
|
NTSTATUS
|
2015-05-10 10:17:29 +00:00
|
|
|
NtfsDirectoryControl(PNTFS_IRP_CONTEXT IrpContext)
|
2002-06-25 22:23:06 +00:00
|
|
|
{
|
2013-06-16 12:15:06 +00:00
|
|
|
NTSTATUS Status = STATUS_UNSUCCESSFUL;
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2019-06-15 16:24:27 +00:00
|
|
|
DPRINT("NtfsDirectoryControl() called\n");
|
2002-06-25 22:23:06 +00:00
|
|
|
|
2015-05-10 10:17:29 +00:00
|
|
|
switch (IrpContext->MinorFunction)
|
2008-03-09 13:58:25 +00:00
|
|
|
{
|
2015-05-10 10:17:29 +00:00
|
|
|
case IRP_MN_QUERY_DIRECTORY:
|
|
|
|
Status = NtfsQueryDirectory(IrpContext);
|
|
|
|
break;
|
2013-06-16 12:15:06 +00:00
|
|
|
|
2015-05-10 10:17:29 +00:00
|
|
|
case IRP_MN_NOTIFY_CHANGE_DIRECTORY:
|
|
|
|
DPRINT1("IRP_MN_NOTIFY_CHANGE_DIRECTORY\n");
|
|
|
|
Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
break;
|
2013-06-16 12:15:06 +00:00
|
|
|
|
2015-05-10 10:17:29 +00:00
|
|
|
default:
|
|
|
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
|
|
|
break;
|
2008-03-09 13:58:25 +00:00
|
|
|
}
|
2013-06-16 12:15:06 +00:00
|
|
|
|
2016-02-24 07:54:20 +00:00
|
|
|
if (Status == STATUS_PENDING && IrpContext->Flags & IRPCONTEXT_COMPLETE)
|
|
|
|
{
|
|
|
|
return NtfsMarkIrpContextForQueue(IrpContext);
|
|
|
|
}
|
|
|
|
|
2015-05-10 10:17:29 +00:00
|
|
|
IrpContext->Irp->IoStatus.Information = 0;
|
2013-06-16 12:15:06 +00:00
|
|
|
|
|
|
|
return Status;
|
2002-06-25 22:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|