ReactOS  0.4.14-dev-599-g2d4d3f5
dirctl.c File Reference
#include "ntfs.h"
#include <debug.h>
Include dependency graph for dirctl.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define ULONG_ROUND_UP(x)   ROUND_UP((x), (sizeof(ULONG)))
 

Functions

ULONGLONG NtfsGetFileSize (PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, PCWSTR Stream, ULONG StreamLength, PULONGLONG AllocatedSize)
 
static NTSTATUS NtfsGetNamesInformation (PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, ULONGLONG MFTIndex, PFILE_NAMES_INFORMATION Info, ULONG BufferLength, PULONG Written, BOOLEAN First)
 
static NTSTATUS NtfsGetDirectoryInformation (PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, ULONGLONG MFTIndex, PFILE_DIRECTORY_INFORMATION Info, ULONG BufferLength, PULONG Written, BOOLEAN First)
 
static NTSTATUS NtfsGetFullDirectoryInformation (PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, ULONGLONG MFTIndex, PFILE_FULL_DIRECTORY_INFORMATION Info, ULONG BufferLength, PULONG Written, BOOLEAN First)
 
static NTSTATUS NtfsGetBothDirectoryInformation (PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, ULONGLONG MFTIndex, PFILE_BOTH_DIR_INFORMATION Info, ULONG BufferLength, PULONG Written, BOOLEAN First)
 
NTSTATUS NtfsQueryDirectory (PNTFS_IRP_CONTEXT IrpContext)
 
NTSTATUS NtfsDirectoryControl (PNTFS_IRP_CONTEXT IrpContext)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 32 of file dirctl.c.

◆ ULONG_ROUND_UP

#define ULONG_ROUND_UP (   x)    ROUND_UP((x), (sizeof(ULONG)))

Definition at line 63 of file dirctl.c.

Function Documentation

◆ NtfsDirectoryControl()

NTSTATUS NtfsDirectoryControl ( PNTFS_IRP_CONTEXT  IrpContext)

Definition at line 590 of file dirctl.c.

591 {
593 
594  DPRINT("NtfsDirectoryControl() called\n");
595 
596  switch (IrpContext->MinorFunction)
597  {
599  Status = NtfsQueryDirectory(IrpContext);
600  break;
601 
603  DPRINT1("IRP_MN_NOTIFY_CHANGE_DIRECTORY\n");
605  break;
606 
607  default:
609  break;
610  }
611 
612  if (Status == STATUS_PENDING && IrpContext->Flags & IRPCONTEXT_COMPLETE)
613  {
614  return NtfsMarkIrpContextForQueue(IrpContext);
615  }
616 
617  IrpContext->Irp->IoStatus.Information = 0;
618 
619  return Status;
620 }
#define IRP_MN_NOTIFY_CHANGE_DIRECTORY
Definition: rdpdr.c:56
UCHAR MinorFunction
Definition: ntfs.h:480
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define IRPCONTEXT_COMPLETE
Definition: vfat.h:570
FORCEINLINE NTSTATUS NtfsMarkIrpContextForQueue(PNTFS_IRP_CONTEXT IrpContext)
Definition: ntfs.h:565
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define IRP_MN_QUERY_DIRECTORY
Definition: rdpdr.c:55
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_PENDING
Definition: ntstatus.h:82
NTSTATUS NtfsQueryDirectory(PNTFS_IRP_CONTEXT IrpContext)
Definition: dirctl.c:359
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ULONG Flags
Definition: ntfs.h:477
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8

Referenced by NtfsDispatch().

◆ NtfsGetBothDirectoryInformation()

static NTSTATUS NtfsGetBothDirectoryInformation ( PDEVICE_EXTENSION  DeviceExt,
PFILE_RECORD_HEADER  FileRecord,
ULONGLONG  MFTIndex,
PFILE_BOTH_DIR_INFORMATION  Info,
ULONG  BufferLength,
PULONG  Written,
BOOLEAN  First 
)
static

Definition at line 271 of file dirctl.c.

278 {
279  ULONG Length;
281  ULONG BytesToCopy = 0;
282  PFILENAME_ATTRIBUTE FileName, ShortFileName;
283  PSTANDARD_INFORMATION StdInfo;
284 
285  DPRINT("NtfsGetBothDirectoryInformation() called\n");
286 
287  *Written = 0;
290  {
291  return Status;
292  }
293 
294  FileName = GetBestFileNameFromRecord(DeviceExt, FileRecord);
295  if (FileName == NULL)
296  {
297  DPRINT1("No name information for file ID: %#I64x\n", MFTIndex);
298  NtfsDumpFileAttributes(DeviceExt, FileRecord);
300  }
301  ShortFileName = GetFileNameFromRecord(DeviceExt, FileRecord, NTFS_FILE_NAME_DOS);
302 
303  StdInfo = GetStandardInformationFromRecord(DeviceExt, FileRecord);
304  ASSERT(StdInfo != NULL);
305 
306  Length = FileName->NameLength * sizeof (WCHAR);
308  {
309  Info->FileNameLength = Length;
310 
312  Info->NextEntryOffset = 0;
314  {
317  *Written += BytesToCopy;
318 
319  if (BytesToCopy == Length)
320  {
321  Info->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_BOTH_DIR_INFORMATION) +
322  BytesToCopy);
324  }
325  }
326 
327  if (ShortFileName)
328  {
329  /* Should we upcase the filename? */
330  ASSERT(ShortFileName->NameLength <= ARRAYSIZE(Info->ShortName));
331  Info->ShortNameLength = ShortFileName->NameLength * sizeof(WCHAR);
332  RtlCopyMemory(Info->ShortName, ShortFileName->Name, Info->ShortNameLength);
333  }
334  else
335  {
336  Info->ShortName[0] = 0;
337  Info->ShortNameLength = 0;
338  }
339 
340  Info->CreationTime.QuadPart = FileName->CreationTime;
341  Info->LastAccessTime.QuadPart = FileName->LastAccessTime;
342  Info->LastWriteTime.QuadPart = FileName->LastWriteTime;
343  Info->ChangeTime.QuadPart = FileName->ChangeTime;
344 
345  /* Convert file flags */
346  NtfsFileFlagsToAttributes(FileName->FileAttributes | StdInfo->FileAttribute, &Info->FileAttributes);
347 
348  Info->EndOfFile.QuadPart = NtfsGetFileSize(DeviceExt, FileRecord, L"", 0, (PULONGLONG)&Info->AllocationSize.QuadPart);
349 
350  Info->FileIndex = MFTIndex;
351  Info->EaSize = 0;
352  }
353 
354  return Status;
355 }
#define NTFS_FILE_NAME_DOS
Definition: ntfs.h:65
PFILENAME_ATTRIBUTE GetBestFileNameFromRecord(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
Definition: attrib.c:1985
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
WCHAR Name[1]
Definition: ntfs.h:375
#define ULONG_ROUND_UP(x)
Definition: dirctl.c:63
PFILENAME_ATTRIBUTE GetFileNameFromRecord(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord, UCHAR NameType)
Definition: attrib.c:1809
LONG NTSTATUS
Definition: precomp.h:26
ULONG FileAttribute
Definition: ntfs.h:330
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
UCHAR NameLength
Definition: ntfs.h:373
PSTANDARD_INFORMATION GetStandardInformationFromRecord(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
Definition: attrib.c:1940
struct TraceInfo Info
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3167
WCHAR First[]
Definition: FormatMessage.c:11
_In_ ULONG BufferLength
Definition: usbdlib.h:225
VOID NtfsDumpFileAttributes(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
Definition: attrib.c:1790
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
ULONGLONG NtfsGetFileSize(PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, PCWSTR Stream, ULONG StreamLength, PULONGLONG AllocatedSize)
Definition: dirctl.c:38
TCHAR Name[MAX_PATH]
Definition: filecomp.c:349
VOID NtfsFileFlagsToAttributes(ULONG NtfsAttributes, PULONG FileAttributes)
Definition: misc.c:105
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
struct _FileName FileName
Definition: fatprocs.h:884
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define min(a, b)
Definition: monoChain.cc:55
#define DPRINT1
Definition: precomp.h:8
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:390
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by NtfsQueryDirectory().

◆ NtfsGetDirectoryInformation()

static NTSTATUS NtfsGetDirectoryInformation ( PDEVICE_EXTENSION  DeviceExt,
PFILE_RECORD_HEADER  FileRecord,
ULONGLONG  MFTIndex,
PFILE_DIRECTORY_INFORMATION  Info,
ULONG  BufferLength,
PULONG  Written,
BOOLEAN  First 
)
static

Definition at line 124 of file dirctl.c.

131 {
132  ULONG Length;
134  ULONG BytesToCopy = 0;
136  PSTANDARD_INFORMATION StdInfo;
137 
138  DPRINT("NtfsGetDirectoryInformation() called\n");
139 
140  *Written = 0;
143  {
144  return Status;
145  }
146 
147  FileName = GetBestFileNameFromRecord(DeviceExt, FileRecord);
148  if (FileName == NULL)
149  {
150  DPRINT1("No name information for file ID: %#I64x\n", MFTIndex);
151  NtfsDumpFileAttributes(DeviceExt, FileRecord);
153  }
154 
155  StdInfo = GetStandardInformationFromRecord(DeviceExt, FileRecord);
156  ASSERT(StdInfo != NULL);
157 
158  Length = FileName->NameLength * sizeof (WCHAR);
160  {
161  Info->FileNameLength = Length;
162 
164  Info->NextEntryOffset = 0;
166  {
169  *Written += BytesToCopy;
170 
171  if (BytesToCopy == Length)
172  {
173  Info->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_DIRECTORY_INFORMATION) +
174  BytesToCopy);
176  }
177  }
178 
179  Info->CreationTime.QuadPart = FileName->CreationTime;
180  Info->LastAccessTime.QuadPart = FileName->LastAccessTime;
181  Info->LastWriteTime.QuadPart = FileName->LastWriteTime;
182  Info->ChangeTime.QuadPart = FileName->ChangeTime;
183 
184  /* Convert file flags */
185  NtfsFileFlagsToAttributes(FileName->FileAttributes | StdInfo->FileAttribute, &Info->FileAttributes);
186 
187  Info->EndOfFile.QuadPart = NtfsGetFileSize(DeviceExt, FileRecord, L"", 0, (PULONGLONG)&Info->AllocationSize.QuadPart);
188 
189  Info->FileIndex = MFTIndex;
190  }
191 
192  return Status;
193 }
PFILENAME_ATTRIBUTE GetBestFileNameFromRecord(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
Definition: attrib.c:1985
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define ULONG_ROUND_UP(x)
Definition: dirctl.c:63
LONG NTSTATUS
Definition: precomp.h:26
ULONG FileAttribute
Definition: ntfs.h:330
PSTANDARD_INFORMATION GetStandardInformationFromRecord(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
Definition: attrib.c:1940
struct TraceInfo Info
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3167
WCHAR First[]
Definition: FormatMessage.c:11
_In_ ULONG BufferLength
Definition: usbdlib.h:225
VOID NtfsDumpFileAttributes(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
Definition: attrib.c:1790
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
ULONGLONG NtfsGetFileSize(PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, PCWSTR Stream, ULONG StreamLength, PULONGLONG AllocatedSize)
Definition: dirctl.c:38
TCHAR Name[MAX_PATH]
Definition: filecomp.c:349
VOID NtfsFileFlagsToAttributes(ULONG NtfsAttributes, PULONG FileAttributes)
Definition: misc.c:105
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
struct _FileName FileName
Definition: fatprocs.h:884
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define min(a, b)
Definition: monoChain.cc:55
#define DPRINT1
Definition: precomp.h:8
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:390
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by NtfsQueryDirectory().

◆ NtfsGetFileSize()

ULONGLONG NtfsGetFileSize ( PDEVICE_EXTENSION  DeviceExt,
PFILE_RECORD_HEADER  FileRecord,
PCWSTR  Stream,
ULONG  StreamLength,
PULONGLONG  AllocatedSize 
)

Definition at line 38 of file dirctl.c.

43 {
44  ULONGLONG Size = 0ULL;
47  PNTFS_ATTR_CONTEXT DataContext;
48 
49  Status = FindAttribute(DeviceExt, FileRecord, AttributeData, Stream, StreamLength, &DataContext, NULL);
50  if (NT_SUCCESS(Status))
51  {
52  Size = AttributeDataLength(DataContext->pRecord);
53  Allocated = AttributeAllocatedLength(DataContext->pRecord);
54  ReleaseAttributeContext(DataContext);
55  }
56 
57  if (AllocatedSize != NULL) *AllocatedSize = Allocated;
58 
59  return Size;
60 }
ULONGLONG AttributeAllocatedLength(PNTFS_ATTR_RECORD AttrRecord)
Definition: mft.c:249
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS FindAttribute(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER MftRecord, ULONG Type, PCWSTR Name, ULONG NameLength, PNTFS_ATTR_CONTEXT *AttrCtx, PULONG Offset)
Definition: mft.c:131
IN PFCB IN VBO OUT PLBO OUT PULONG OUT PBOOLEAN Allocated
Definition: fatprocs.h:297
smooth NULL
Definition: ftsmooth.c:416
#define ULL(a, b)
Definition: format_msg.c:27
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:65
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
VOID ReleaseAttributeContext(PNTFS_ATTR_CONTEXT Context)
Definition: mft.c:104
ULONGLONG AttributeDataLength(PNTFS_ATTR_RECORD AttrRecord)
Definition: mft.c:259
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by NtfsGetBothDirectoryInformation(), NtfsGetDirectoryInformation(), NtfsGetFullDirectoryInformation(), NtfsMakeFCBFromDirEntry(), and NtfsSetEndOfFile().

◆ NtfsGetFullDirectoryInformation()

static NTSTATUS NtfsGetFullDirectoryInformation ( PDEVICE_EXTENSION  DeviceExt,
PFILE_RECORD_HEADER  FileRecord,
ULONGLONG  MFTIndex,
PFILE_FULL_DIRECTORY_INFORMATION  Info,
ULONG  BufferLength,
PULONG  Written,
BOOLEAN  First 
)
static

Definition at line 197 of file dirctl.c.

204 {
205  ULONG Length;
207  ULONG BytesToCopy = 0;
209  PSTANDARD_INFORMATION StdInfo;
210 
211  DPRINT("NtfsGetFullDirectoryInformation() called\n");
212 
213  *Written = 0;
216  {
217  return Status;
218  }
219 
220  FileName = GetBestFileNameFromRecord(DeviceExt, FileRecord);
221  if (FileName == NULL)
222  {
223  DPRINT1("No name information for file ID: %#I64x\n", MFTIndex);
224  NtfsDumpFileAttributes(DeviceExt, FileRecord);
226  }
227 
228  StdInfo = GetStandardInformationFromRecord(DeviceExt, FileRecord);
229  ASSERT(StdInfo != NULL);
230 
231  Length = FileName->NameLength * sizeof (WCHAR);
233  {
234  Info->FileNameLength = Length;
235 
237  Info->NextEntryOffset = 0;
239  {
242  *Written += BytesToCopy;
243 
244  if (BytesToCopy == Length)
245  {
246  Info->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_FULL_DIR_INFORMATION) +
247  BytesToCopy);
249  }
250  }
251 
252  Info->CreationTime.QuadPart = FileName->CreationTime;
253  Info->LastAccessTime.QuadPart = FileName->LastAccessTime;
254  Info->LastWriteTime.QuadPart = FileName->LastWriteTime;
255  Info->ChangeTime.QuadPart = FileName->ChangeTime;
256 
257  /* Convert file flags */
258  NtfsFileFlagsToAttributes(FileName->FileAttributes | StdInfo->FileAttribute, &Info->FileAttributes);
259 
260  Info->EndOfFile.QuadPart = NtfsGetFileSize(DeviceExt, FileRecord, L"", 0, (PULONGLONG)&Info->AllocationSize.QuadPart);
261 
262  Info->FileIndex = MFTIndex;
263  Info->EaSize = 0;
264  }
265 
266  return Status;
267 }
PFILENAME_ATTRIBUTE GetBestFileNameFromRecord(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
Definition: attrib.c:1985
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define ULONG_ROUND_UP(x)
Definition: dirctl.c:63
LONG NTSTATUS
Definition: precomp.h:26
ULONG FileAttribute
Definition: ntfs.h:330
PSTANDARD_INFORMATION GetStandardInformationFromRecord(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
Definition: attrib.c:1940
struct TraceInfo Info
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3167
WCHAR First[]
Definition: FormatMessage.c:11
_In_ ULONG BufferLength
Definition: usbdlib.h:225
VOID NtfsDumpFileAttributes(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
Definition: attrib.c:1790
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
ULONGLONG NtfsGetFileSize(PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, PCWSTR Stream, ULONG StreamLength, PULONGLONG AllocatedSize)
Definition: dirctl.c:38
TCHAR Name[MAX_PATH]
Definition: filecomp.c:349
VOID NtfsFileFlagsToAttributes(ULONG NtfsAttributes, PULONG FileAttributes)
Definition: misc.c:105
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
struct _FileName FileName
Definition: fatprocs.h:884
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define min(a, b)
Definition: monoChain.cc:55
#define DPRINT1
Definition: precomp.h:8
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:390
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by NtfsQueryDirectory().

◆ NtfsGetNamesInformation()

static NTSTATUS NtfsGetNamesInformation ( PDEVICE_EXTENSION  DeviceExt,
PFILE_RECORD_HEADER  FileRecord,
ULONGLONG  MFTIndex,
PFILE_NAMES_INFORMATION  Info,
ULONG  BufferLength,
PULONG  Written,
BOOLEAN  First 
)
static

Definition at line 67 of file dirctl.c.

74 {
75  ULONG Length;
77  ULONG BytesToCopy = 0;
79 
80  DPRINT("NtfsGetNamesInformation() called\n");
81 
82  *Written = 0;
85  {
86  return Status;
87  }
88 
89  FileName = GetBestFileNameFromRecord(DeviceExt, FileRecord);
90  if (FileName == NULL)
91  {
92  DPRINT1("No name information for file ID: %#I64x\n", MFTIndex);
93  NtfsDumpFileAttributes(DeviceExt, FileRecord);
95  }
96 
97  Length = FileName->NameLength * sizeof (WCHAR);
99  {
100  Info->FileNameLength = Length;
101 
103  Info->NextEntryOffset = 0;
105  {
108  *Written += BytesToCopy;
109 
110  if (BytesToCopy == Length)
111  {
112  Info->NextEntryOffset = ULONG_ROUND_UP(sizeof(FILE_NAMES_INFORMATION) +
113  BytesToCopy);
115  }
116  }
117  }
118 
119  return Status;
120 }
PFILENAME_ATTRIBUTE GetBestFileNameFromRecord(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
Definition: attrib.c:1985
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define ULONG_ROUND_UP(x)
Definition: dirctl.c:63
LONG NTSTATUS
Definition: precomp.h:26
struct TraceInfo Info
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3167
WCHAR First[]
Definition: FormatMessage.c:11
_In_ ULONG BufferLength
Definition: usbdlib.h:225
VOID NtfsDumpFileAttributes(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
Definition: attrib.c:1790
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
TCHAR Name[MAX_PATH]
Definition: filecomp.c:349
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Status
Definition: gdiplustypes.h:24
struct _FileName FileName
Definition: fatprocs.h:884
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define min(a, b)
Definition: monoChain.cc:55
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by NtfsQueryDirectory().

◆ NtfsQueryDirectory()

NTSTATUS NtfsQueryDirectory ( PNTFS_IRP_CONTEXT  IrpContext)

Definition at line 359 of file dirctl.c.

360 {
361  PIRP Irp;
363  PDEVICE_EXTENSION DeviceExtension;
364  LONG BufferLength = 0;
365  PUNICODE_STRING SearchPattern = NULL;
367  ULONG FileIndex = 0;
368  PUCHAR Buffer = NULL;
369  PFILE_NAMES_INFORMATION Buffer0 = NULL;
370  PNTFS_FCB Fcb;
371  PNTFS_CCB Ccb;
372  BOOLEAN First = FALSE;
373  PIO_STACK_LOCATION Stack;
376  PFILE_RECORD_HEADER FileRecord;
377  ULONGLONG MFTRecord, OldMFTRecord = 0;
378  UNICODE_STRING Pattern;
379  ULONG Written;
380 
381  DPRINT("NtfsQueryDirectory() called\n");
382 
383  ASSERT(IrpContext);
384  Irp = IrpContext->Irp;
385  DeviceObject = IrpContext->DeviceObject;
386 
387  DeviceExtension = DeviceObject->DeviceExtension;
389  FileObject = Stack->FileObject;
390 
391  Ccb = (PNTFS_CCB)FileObject->FsContext2;
392  Fcb = (PNTFS_FCB)FileObject->FsContext;
393 
394  /* Obtain the callers parameters */
395  BufferLength = Stack->Parameters.QueryDirectory.Length;
396  SearchPattern = Stack->Parameters.QueryDirectory.FileName;
397  FileInformationClass = Stack->Parameters.QueryDirectory.FileInformationClass;
398  FileIndex = Stack->Parameters.QueryDirectory.FileIndex;
399 
401  {
402  DPRINT1("Compressed directory!\n");
404  return STATUS_NOT_IMPLEMENTED;
405  }
406 
408  BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
409  {
410  return STATUS_PENDING;
411  }
412 
413  if (SearchPattern != NULL)
414  {
415  if (!Ccb->DirectorySearchPattern)
416  {
417  First = TRUE;
418  Pattern.Length = 0;
419  Pattern.MaximumLength = SearchPattern->Length + sizeof(WCHAR);
420  Ccb->DirectorySearchPattern = Pattern.Buffer =
422  if (!Ccb->DirectorySearchPattern)
423  {
426  }
427 
428  memcpy(Ccb->DirectorySearchPattern, SearchPattern->Buffer, SearchPattern->Length);
429  Ccb->DirectorySearchPattern[SearchPattern->Length / sizeof(WCHAR)] = 0;
430  }
431  }
432  else if (!Ccb->DirectorySearchPattern)
433  {
434  First = TRUE;
435  Ccb->DirectorySearchPattern = ExAllocatePoolWithTag(NonPagedPool, 2 * sizeof(WCHAR), TAG_NTFS);
436  if (!Ccb->DirectorySearchPattern)
437  {
440  }
441 
442  Ccb->DirectorySearchPattern[0] = L'*';
443  Ccb->DirectorySearchPattern[1] = 0;
444  }
445 
446  RtlInitUnicodeString(&Pattern, Ccb->DirectorySearchPattern);
447  DPRINT("Search pattern '%S'\n", Ccb->DirectorySearchPattern);
448  DPRINT("In: '%S'\n", Fcb->PathName);
449 
450  /* Determine directory index */
451  if (Stack->Flags & SL_INDEX_SPECIFIED)
452  {
453  Ccb->Entry = FileIndex;
454  }
455  else if (First || (Stack->Flags & SL_RESTART_SCAN))
456  {
457  Ccb->Entry = 0;
458  }
459 
460  /* Get Buffer for result */
462 
463  DPRINT("Buffer=%p tofind=%S\n", Buffer, Ccb->DirectorySearchPattern);
464 
465  if (!ExAcquireResourceExclusiveLite(&DeviceExtension->DirResource,
466  BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
467  {
469  return STATUS_PENDING;
470  }
471 
472  Written = 0;
473  while (Status == STATUS_SUCCESS && BufferLength > 0)
474  {
475  Status = NtfsFindFileAt(DeviceExtension,
476  &Pattern,
477  &Ccb->Entry,
478  &FileRecord,
479  &MFTRecord,
480  Fcb->MFTIndex,
482 
483  if (NT_SUCCESS(Status))
484  {
485  /* HACK: files with both a short name and a long name are present twice in the index.
486  * Ignore the second entry, if it is immediately following the first one.
487  */
488  if (MFTRecord == OldMFTRecord)
489  {
490  DPRINT1("Ignoring duplicate MFT entry 0x%x\n", MFTRecord);
491  Ccb->Entry++;
492  ExFreeToNPagedLookasideList(&DeviceExtension->FileRecLookasideList, FileRecord);
493  continue;
494  }
495  OldMFTRecord = MFTRecord;
496 
497  switch (FileInformationClass)
498  {
500  Status = NtfsGetNamesInformation(DeviceExtension,
501  FileRecord,
502  MFTRecord,
504  BufferLength,
505  &Written,
506  Buffer0 == NULL);
507  break;
508 
510  Status = NtfsGetDirectoryInformation(DeviceExtension,
511  FileRecord,
512  MFTRecord,
514  BufferLength,
515  &Written,
516  Buffer0 == NULL);
517  break;
518 
520  Status = NtfsGetFullDirectoryInformation(DeviceExtension,
521  FileRecord,
522  MFTRecord,
524  BufferLength,
525  &Written,
526  Buffer0 == NULL);
527  break;
528 
530  Status = NtfsGetBothDirectoryInformation(DeviceExtension,
531  FileRecord,
532  MFTRecord,
534  BufferLength,
535  &Written,
536  Buffer0 == NULL);
537  break;
538 
539  default:
541  }
542 
544  {
545  break;
546  }
547  }
548  else
549  {
551  break;
552  }
553 
554  Buffer0 = (PFILE_NAMES_INFORMATION)Buffer;
555  Buffer0->FileIndex = FileIndex++;
556  Ccb->Entry++;
557  BufferLength -= Buffer0->NextEntryOffset;
558 
559  ExFreeToNPagedLookasideList(&DeviceExtension->FileRecLookasideList, FileRecord);
560 
561  if (Stack->Flags & SL_RETURN_SINGLE_ENTRY)
562  {
563  break;
564  }
565 
566  Buffer += Buffer0->NextEntryOffset;
567  }
568 
569  if (Buffer0)
570  {
571  Buffer0->NextEntryOffset = 0;
573  IrpContext->Irp->IoStatus.Information = Stack->Parameters.QueryDirectory.Length - BufferLength;
574  }
575  else
576  {
578  ASSERT(Written <= Stack->Parameters.QueryDirectory.Length);
579  IrpContext->Irp->IoStatus.Information = Written;
580  }
581 
582  ExReleaseResourceLite(&DeviceExtension->DirResource);
584 
585  return Status;
586 }
static NTSTATUS NtfsGetFullDirectoryInformation(PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, ULONGLONG MFTIndex, PFILE_FULL_DIRECTORY_INFORMATION Info, ULONG BufferLength, PULONG Written, BOOLEAN First)
Definition: dirctl.c:197
static NTSTATUS NtfsGetNamesInformation(PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, ULONGLONG MFTIndex, PFILE_NAMES_INFORMATION Info, ULONG BufferLength, PULONG Written, BOOLEAN First)
Definition: dirctl.c:67
PDEVICE_OBJECT DeviceObject
Definition: ntfs.h:484
#define TRUE
Definition: types.h:120
#define SL_CASE_SENSITIVE
Definition: iotypes.h:1777
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define SL_INDEX_SPECIFIED
Definition: iotypes.h:1794
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
USHORT MaximumLength
Definition: env_spec_w32.h:370
_In_ PIRP Irp
Definition: csq.h:116
Definition: cdstruc.h:908
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:75
WCHAR PathName[MAX_PATH]
Definition: ntfs.h:521
ULONGLONG MFTIndex
Definition: ntfs.h:535
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
WCHAR First[]
Definition: FormatMessage.c:11
Definition: ntfs.h:129
static NTSTATUS NtfsGetDirectoryInformation(PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, ULONGLONG MFTIndex, PFILE_DIRECTORY_INFORMATION Info, ULONG BufferLength, PULONG Written, BOOLEAN First)
Definition: dirctl.c:124
long LONG
Definition: pedump.c:60
_In_ ULONG BufferLength
Definition: usbdlib.h:225
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define IRPCONTEXT_CANWAIT
Definition: vfat.h:569
void DPRINT(...)
Definition: polytest.cpp:61
struct _FILE_NAMES_INFORMATION * PFILE_NAMES_INFORMATION
Definition: bufpool.h:45
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
enum _FILE_INFORMATION_CLASS FILE_INFORMATION_CLASS
Definition: directory.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NO_MORE_FILES
Definition: udferr_usr.h:128
uint64_t ULONGLONG
Definition: typedefs.h:65
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1955
#define TAG_NTFS
Definition: ntfs.h:12
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
struct NTFS_CCB * PNTFS_CCB
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:226
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
ULONG Flags
Definition: ntfs.h:477
ERESOURCE MainResource
Definition: ntfs.h:524
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define SL_RETURN_SINGLE_ENTRY
Definition: iotypes.h:1793
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define STATUS_NO_SUCH_FILE
Definition: udferr_usr.h:137
#define SL_RESTART_SCAN
Definition: iotypes.h:1792
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
#define DPRINT1
Definition: precomp.h:8
PVOID NtfsGetUserBuffer(PIRP Irp, BOOLEAN Paging)
Definition: misc.c:120
BOOLEAN NtfsFCBIsCompressed(PNTFS_FCB Fcb)
Definition: fcb.c:141
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define UNIMPLEMENTED
Definition: debug.h:114
static NTSTATUS NtfsGetBothDirectoryInformation(PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, ULONGLONG MFTIndex, PFILE_BOTH_DIR_INFORMATION Info, ULONG BufferLength, PULONG Written, BOOLEAN First)
Definition: dirctl.c:271
NTSTATUS NtfsFindFileAt(PDEVICE_EXTENSION Vcb, PUNICODE_STRING SearchPattern, PULONG FirstEntry, PFILE_RECORD_HEADER *FileRecord, PULONGLONG MFTIndex, ULONGLONG CurrentMFTIndex, BOOLEAN CaseSensitive)
Definition: mft.c:3355
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2938
FILENAME_ATTRIBUTE Entry
Definition: ntfs.h:538

Referenced by NtfsDirectoryControl().