ReactOS 0.4.15-dev-7906-g1b85a5f
finfo.c File Reference
#include "ntfs.h"
#include <debug.h>
Include dependency graph for finfo.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static NTSTATUS NtfsGetStandardInformation (PNTFS_FCB Fcb, PDEVICE_OBJECT DeviceObject, PFILE_STANDARD_INFORMATION StandardInfo, PULONG BufferLength)
 
static NTSTATUS NtfsGetPositionInformation (PFILE_OBJECT FileObject, PFILE_POSITION_INFORMATION PositionInfo, PULONG BufferLength)
 
static NTSTATUS NtfsGetBasicInformation (PFILE_OBJECT FileObject, PNTFS_FCB Fcb, PDEVICE_OBJECT DeviceObject, PFILE_BASIC_INFORMATION BasicInfo, PULONG BufferLength)
 
static NTSTATUS NtfsGetNameInformation (PFILE_OBJECT FileObject, PNTFS_FCB Fcb, PDEVICE_OBJECT DeviceObject, PFILE_NAME_INFORMATION NameInfo, PULONG BufferLength)
 
static NTSTATUS NtfsGetInternalInformation (PNTFS_FCB Fcb, PFILE_INTERNAL_INFORMATION InternalInfo, PULONG BufferLength)
 
static NTSTATUS NtfsGetNetworkOpenInformation (PNTFS_FCB Fcb, PDEVICE_EXTENSION DeviceExt, PFILE_NETWORK_OPEN_INFORMATION NetworkInfo, PULONG BufferLength)
 
static NTSTATUS NtfsGetStreamInformation (PNTFS_FCB Fcb, PDEVICE_EXTENSION DeviceExt, PFILE_STREAM_INFORMATION StreamInfo, PULONG BufferLength)
 
const PCSTR GetInfoClassName (FILE_INFORMATION_CLASS infoClass)
 
NTSTATUS NtfsQueryInformation (PNTFS_IRP_CONTEXT IrpContext)
 
NtfsSetEndOfFile

@implemented

Sets the end of file (file size) for a given file.

Parameters
FcbPointer to an NTFS_FCB which describes the target file. Fcb->MainResource should have been acquired with ExAcquireResourceSharedLite().
FileObjectPointer to a FILE_OBJECT describing the target file.
DeviceExtPoints to the target disk's DEVICE_EXTENSION
IrpFlagsULONG describing the flags of the original IRP request (Irp->Flags).
CaseSensitiveBoolean 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.
NewFileSizePointer to a LARGE_INTEGER which indicates the new end of file (file size).
Returns
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.
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 function alongside functions that operate on the data attribute directly.
NTSTATUS NtfsSetEndOfFile (PNTFS_FCB Fcb, PFILE_OBJECT FileObject, PDEVICE_EXTENSION DeviceExt, ULONG IrpFlags, BOOLEAN CaseSensitive, PLARGE_INTEGER NewFileSize)
 
NtfsSetInformation

@implemented

Sets the specified file information.

Parameters
IrpContextPoints to an NTFS_IRP_CONTEXT which describes the set operation
Returns
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 is a hack and not a true implementation, but it's enough to make SetEndOfFile() work. All other information classes are TODO.
NTSTATUS NtfsSetInformation (PNTFS_IRP_CONTEXT IrpContext)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 32 of file finfo.c.

Function Documentation

◆ GetInfoClassName()

const PCSTR GetInfoClassName ( FILE_INFORMATION_CLASS  infoClass)

Definition at line 296 of file finfo.c.

297{
298 const PCSTR fileInfoClassNames[] = { "???????",
299 "FileDirectoryInformation",
300 "FileFullDirectoryInformation",
301 "FileBothDirectoryInformation",
302 "FileBasicInformation",
303 "FileStandardInformation",
304 "FileInternalInformation",
305 "FileEaInformation",
306 "FileAccessInformation",
307 "FileNameInformation",
308 "FileRenameInformation",
309 "FileLinkInformation",
310 "FileNamesInformation",
311 "FileDispositionInformation",
312 "FilePositionInformation",
313 "FileFullEaInformation",
314 "FileModeInformation",
315 "FileAlignmentInformation",
316 "FileAllInformation",
317 "FileAllocationInformation",
318 "FileEndOfFileInformation",
319 "FileAlternateNameInformation",
320 "FileStreamInformation",
321 "FilePipeInformation",
322 "FilePipeLocalInformation",
323 "FilePipeRemoteInformation",
324 "FileMailslotQueryInformation",
325 "FileMailslotSetInformation",
326 "FileCompressionInformation",
327 "FileObjectIdInformation",
328 "FileCompletionInformation",
329 "FileMoveClusterInformation",
330 "FileQuotaInformation",
331 "FileReparsePointInformation",
332 "FileNetworkOpenInformation",
333 "FileAttributeTagInformation",
334 "FileTrackingInformation",
335 "FileIdBothDirectoryInformation",
336 "FileIdFullDirectoryInformation",
337 "FileValidDataLengthInformation",
338 "FileShortNameInformation",
339 "FileIoCompletionNotificationInformation",
340 "FileIoStatusBlockRangeInformation",
341 "FileIoPriorityHintInformation",
342 "FileSfioReserveInformation",
343 "FileSfioVolumeInformation",
344 "FileHardLinkInformation",
345 "FileProcessIdsUsingFileInformation",
346 "FileNormalizedNameInformation",
347 "FileNetworkPhysicalNameInformation",
348 "FileIdGlobalTxDirectoryInformation",
349 "FileIsRemoteDeviceInformation",
350 "FileAttributeCacheInformation",
351 "FileNumaNodeInformation",
352 "FileStandardLinkInformation",
353 "FileRemoteProtocolInformation",
354 "FileReplaceCompletionInformation",
355 "FileMaximumInformation",
356 "FileDirectoryInformation",
357 "FileFullDirectoryInformation",
358 "FileBothDirectoryInformation",
359 "FileBasicInformation",
360 "FileStandardInformation",
361 "FileInternalInformation",
362 "FileEaInformation",
363 "FileAccessInformation",
364 "FileNameInformation",
365 "FileRenameInformation",
366 "FileLinkInformation",
367 "FileNamesInformation",
368 "FileDispositionInformation",
369 "FilePositionInformation",
370 "FileFullEaInformation",
371 "FileModeInformation",
372 "FileAlignmentInformation",
373 "FileAllInformation",
374 "FileAllocationInformation",
375 "FileEndOfFileInformation",
376 "FileAlternateNameInformation",
377 "FileStreamInformation",
378 "FilePipeInformation",
379 "FilePipeLocalInformation",
380 "FilePipeRemoteInformation",
381 "FileMailslotQueryInformation",
382 "FileMailslotSetInformation",
383 "FileCompressionInformation",
384 "FileObjectIdInformation",
385 "FileCompletionInformation",
386 "FileMoveClusterInformation",
387 "FileQuotaInformation",
388 "FileReparsePointInformation",
389 "FileNetworkOpenInformation",
390 "FileAttributeTagInformation",
391 "FileTrackingInformation",
392 "FileIdBothDirectoryInformation",
393 "FileIdFullDirectoryInformation",
394 "FileValidDataLengthInformation",
395 "FileShortNameInformation",
396 "FileIoCompletionNotificationInformation",
397 "FileIoStatusBlockRangeInformation",
398 "FileIoPriorityHintInformation",
399 "FileSfioReserveInformation",
400 "FileSfioVolumeInformation",
401 "FileHardLinkInformation",
402 "FileProcessIdsUsingFileInformation",
403 "FileNormalizedNameInformation",
404 "FileNetworkPhysicalNameInformation",
405 "FileIdGlobalTxDirectoryInformation",
406 "FileIsRemoteDeviceInformation",
407 "FileAttributeCacheInformation",
408 "FileNumaNodeInformation",
409 "FileStandardLinkInformation",
410 "FileRemoteProtocolInformation",
411 "FileReplaceCompletionInformation",
412 "FileMaximumInformation" };
413 return fileInfoClassNames[infoClass];
414}
const char * PCSTR
Definition: typedefs.h:52

Referenced by NtfsQueryInformation(), and NtfsSetInformation().

◆ NtfsGetBasicInformation()

static NTSTATUS NtfsGetBasicInformation ( PFILE_OBJECT  FileObject,
PNTFS_FCB  Fcb,
PDEVICE_OBJECT  DeviceObject,
PFILE_BASIC_INFORMATION  BasicInfo,
PULONG  BufferLength 
)
static

Definition at line 97 of file finfo.c.

102{
104
105 DPRINT("NtfsGetBasicInformation(%p, %p, %p, %p, %p)\n", FileObject, Fcb, DeviceObject, BasicInfo, BufferLength);
106
109
110 RtlZeroMemory(BasicInfo, sizeof(FILE_BASIC_INFORMATION));
111
112 BasicInfo->CreationTime.QuadPart = FileName->CreationTime;
113 BasicInfo->LastAccessTime.QuadPart = FileName->LastAccessTime;
114 BasicInfo->LastWriteTime.QuadPart = FileName->LastWriteTime;
115 BasicInfo->ChangeTime.QuadPart = FileName->ChangeTime;
116
117 NtfsFileFlagsToAttributes(FileName->FileAttributes, &BasicInfo->FileAttributes);
118
120
121 return STATUS_SUCCESS;
122}
_In_ PFCB Fcb
Definition: cdprocs.h:159
VOID NtfsFileFlagsToAttributes(ULONG NtfsAttributes, PULONG FileAttributes)
Definition: misc.c:105
#define FILE_BASIC_INFORMATION
Definition: disk.h:53
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define DPRINT
Definition: sndvol32.h:71
FILENAME_ATTRIBUTE Entry
Definition: ntfs.h:542
LARGE_INTEGER LastWriteTime
Definition: nt_native.h:941
LARGE_INTEGER CreationTime
Definition: nt_native.h:939
LARGE_INTEGER ChangeTime
Definition: nt_native.h:942
LARGE_INTEGER LastAccessTime
Definition: nt_native.h:940
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771

Referenced by NtfsQueryInformation().

◆ NtfsGetInternalInformation()

static NTSTATUS NtfsGetInternalInformation ( PNTFS_FCB  Fcb,
PFILE_INTERNAL_INFORMATION  InternalInfo,
PULONG  BufferLength 
)
static

Definition at line 177 of file finfo.c.

180{
181 DPRINT1("NtfsGetInternalInformation(%p, %p, %p)\n", Fcb, InternalInfo, BufferLength);
182
183 ASSERT(InternalInfo);
184 ASSERT(Fcb);
185
188
189 InternalInfo->IndexNumber.QuadPart = Fcb->MFTIndex;
190
192
193 return STATUS_SUCCESS;
194}
#define DPRINT1
Definition: precomp.h:8
struct _FILE_INTERNAL_INFORMATION FILE_INTERNAL_INFORMATION
#define ASSERT(a)
Definition: mode.c:44
ULONGLONG MFTIndex
Definition: ntfs.h:539

Referenced by NtfsQueryInformation().

◆ NtfsGetNameInformation()

static NTSTATUS NtfsGetNameInformation ( PFILE_OBJECT  FileObject,
PNTFS_FCB  Fcb,
PDEVICE_OBJECT  DeviceObject,
PFILE_NAME_INFORMATION  NameInfo,
PULONG  BufferLength 
)
static

Definition at line 130 of file finfo.c.

135{
137
140
141 DPRINT("NtfsGetNameInformation(%p, %p, %p, %p, %p)\n", FileObject, Fcb, DeviceObject, NameInfo, BufferLength);
142
143 ASSERT(NameInfo != NULL);
144 ASSERT(Fcb != NULL);
145
146 /* If buffer can't hold at least the file name length, bail out */
149
150 /* Save file name length, and as much file len, as buffer length allows */
151 NameInfo->FileNameLength = wcslen(Fcb->PathName) * sizeof(WCHAR);
152
153 /* Calculate amount of bytes to copy not to overflow the buffer */
154 BytesToCopy = min(NameInfo->FileNameLength,
156
157 /* Fill in the bytes */
159
160 /* Check if we could write more but are not able to */
161 if (*BufferLength < NameInfo->FileNameLength + (ULONG)FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]))
162 {
163 /* Return number of bytes written */
166 }
167
168 /* We filled up as many bytes, as needed */
170
171 return STATUS_SUCCESS;
172}
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ HANDLE _In_ ULONG FileNameLength
Definition: fltkernel.h:1129
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define min(a, b)
Definition: monoChain.cc:55
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3168
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
WCHAR PathName[MAX_PATH]
Definition: ntfs.h:525
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by NtfsQueryInformation().

◆ NtfsGetNetworkOpenInformation()

static NTSTATUS NtfsGetNetworkOpenInformation ( PNTFS_FCB  Fcb,
PDEVICE_EXTENSION  DeviceExt,
PFILE_NETWORK_OPEN_INFORMATION  NetworkInfo,
PULONG  BufferLength 
)
static

Definition at line 198 of file finfo.c.

202{
204
205 DPRINT("NtfsGetNetworkOpenInformation(%p, %p, %p, %p)\n", Fcb, DeviceExt, NetworkInfo, BufferLength);
206
209
210 NetworkInfo->CreationTime.QuadPart = FileName->CreationTime;
211 NetworkInfo->LastAccessTime.QuadPart = FileName->LastAccessTime;
212 NetworkInfo->LastWriteTime.QuadPart = FileName->LastWriteTime;
213 NetworkInfo->ChangeTime.QuadPart = FileName->ChangeTime;
214
215 NetworkInfo->EndOfFile = Fcb->RFCB.FileSize;
216 NetworkInfo->AllocationSize = Fcb->RFCB.AllocationSize;
217
218 NtfsFileFlagsToAttributes(FileName->FileAttributes, &NetworkInfo->FileAttributes);
219
221 return STATUS_SUCCESS;
222}
struct _FILE_NETWORK_OPEN_INFORMATION FILE_NETWORK_OPEN_INFORMATION
FSRTL_COMMON_FCB_HEADER RFCB
Definition: ntfs.h:517
LARGE_INTEGER AllocationSize
Definition: env_spec_w32.h:755

Referenced by NtfsQueryInformation().

◆ NtfsGetPositionInformation()

static NTSTATUS NtfsGetPositionInformation ( PFILE_OBJECT  FileObject,
PFILE_POSITION_INFORMATION  PositionInfo,
PULONG  BufferLength 
)
static

Definition at line 75 of file finfo.c.

78{
79 DPRINT1("NtfsGetPositionInformation(%p, %p, %p)\n", FileObject, PositionInfo, BufferLength);
80
83
84 PositionInfo->CurrentByteOffset.QuadPart = FileObject->CurrentByteOffset.QuadPart;
85
86 DPRINT("Getting position %I64x\n",
87 PositionInfo->CurrentByteOffset.QuadPart);
88
90
91 return STATUS_SUCCESS;
92}
struct _FILE_POSITION_INFORMATION FILE_POSITION_INFORMATION
LARGE_INTEGER CurrentByteOffset
Definition: nt_native.h:955

Referenced by NtfsQueryInformation().

◆ NtfsGetStandardInformation()

static NTSTATUS NtfsGetStandardInformation ( PNTFS_FCB  Fcb,
PDEVICE_OBJECT  DeviceObject,
PFILE_STANDARD_INFORMATION  StandardInfo,
PULONG  BufferLength 
)
static

Definition at line 42 of file finfo.c.

46{
48
49 DPRINT("NtfsGetStandardInformation(%p, %p, %p, %p)\n", Fcb, DeviceObject, StandardInfo, BufferLength);
50
53
54 /* PRECONDITION */
55 ASSERT(StandardInfo != NULL);
56 ASSERT(Fcb != NULL);
57
58 RtlZeroMemory(StandardInfo,
60
61 StandardInfo->AllocationSize = Fcb->RFCB.AllocationSize;
62 StandardInfo->EndOfFile = Fcb->RFCB.FileSize;
63 StandardInfo->NumberOfLinks = Fcb->LinkCount;
64 StandardInfo->DeletePending = FALSE;
65 StandardInfo->Directory = NtfsFCBIsDirectory(Fcb);
66
68
69 return STATUS_SUCCESS;
70}
#define FALSE
Definition: types.h:117
#define FILE_STANDARD_INFORMATION
Definition: disk.h:54
BOOLEAN NtfsFCBIsDirectory(PNTFS_FCB Fcb)
Definition: fcb.c:132
USHORT LinkCount
Definition: ntfs.h:540
LARGE_INTEGER AllocationSize
Definition: propsheet.cpp:54

Referenced by NtfsQueryInformation().

◆ NtfsGetStreamInformation()

static NTSTATUS NtfsGetStreamInformation ( PNTFS_FCB  Fcb,
PDEVICE_EXTENSION  DeviceExt,
PFILE_STREAM_INFORMATION  StreamInfo,
PULONG  BufferLength 
)
static

Definition at line 226 of file finfo.c.

230{
231 ULONG CurrentSize;
233 PNTFS_ATTR_RECORD Attribute;
234 NTSTATUS Status, BrowseStatus;
235 PFILE_RECORD_HEADER FileRecord;
236 PFILE_STREAM_INFORMATION CurrentInfo = StreamInfo, Previous = NULL;
237
240
241 FileRecord = ExAllocateFromNPagedLookasideList(&DeviceExt->FileRecLookasideList);
242 if (FileRecord == NULL)
243 {
244 DPRINT1("Not enough memory!\n");
246 }
247
248 Status = ReadFileRecord(DeviceExt, Fcb->MFTIndex, FileRecord);
249 if (!NT_SUCCESS(Status))
250 {
251 DPRINT1("Can't find record!\n");
252 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
253 return Status;
254 }
255
256 BrowseStatus = FindFirstAttribute(&Context, DeviceExt, FileRecord, FALSE, &Attribute);
257 while (NT_SUCCESS(BrowseStatus))
258 {
259 if (Attribute->Type == AttributeData)
260 {
261 CurrentSize = FIELD_OFFSET(FILE_STREAM_INFORMATION, StreamName) + Attribute->NameLength * sizeof(WCHAR) + wcslen(L"::$DATA") * sizeof(WCHAR);
262
263 if (CurrentSize > *BufferLength)
264 {
266 break;
267 }
268
269 CurrentInfo->NextEntryOffset = 0;
270 CurrentInfo->StreamNameLength = (Attribute->NameLength + wcslen(L"::$DATA")) * sizeof(WCHAR);
271 CurrentInfo->StreamSize.QuadPart = AttributeDataLength(Attribute);
273 CurrentInfo->StreamName[0] = L':';
274 RtlMoveMemory(&CurrentInfo->StreamName[1], (PWCHAR)((ULONG_PTR)Attribute + Attribute->NameOffset), CurrentInfo->StreamNameLength);
275 RtlMoveMemory(&CurrentInfo->StreamName[Attribute->NameLength + 1], L":$DATA", sizeof(L":$DATA") - sizeof(UNICODE_NULL));
276
277 if (Previous != NULL)
278 {
279 Previous->NextEntryOffset = (ULONG_PTR)CurrentInfo - (ULONG_PTR)Previous;
280 }
281 Previous = CurrentInfo;
282 CurrentInfo = (PFILE_STREAM_INFORMATION)((ULONG_PTR)CurrentInfo + CurrentSize);
283 *BufferLength -= CurrentSize;
284 }
285
286 BrowseStatus = FindNextAttribute(&Context, &Attribute);
287 }
288
290 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
291 return Status;
292}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS FindFirstAttribute(PFIND_ATTR_CONTXT Context, PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord, BOOLEAN OnlyResident, PNTFS_ATTR_RECORD *Attribute)
Definition: attrib.c:1383
VOID FindCloseAttribute(PFIND_ATTR_CONTXT Context)
Definition: attrib.c:1465
NTSTATUS FindNextAttribute(PFIND_ATTR_CONTXT Context, PNTFS_ATTR_RECORD *Attribute)
Definition: attrib.c:1431
@ AttributeData
Definition: ntfs.h:168
#define ULONG_PTR
Definition: config.h:101
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING StreamName
Definition: fsrtlfuncs.h:741
Status
Definition: gdiplustypes.h:25
struct _FILE_STREAM_INFORMATION * PFILE_STREAM_INFORMATION
NTSTATUS ReadFileRecord(PDEVICE_EXTENSION Vcb, ULONGLONG index, PFILE_RECORD_HEADER file)
Definition: mft.c:1631
ULONGLONG AttributeDataLength(PNTFS_ATTR_RECORD AttrRecord)
Definition: mft.c:259
ULONGLONG AttributeAllocatedLength(PNTFS_ATTR_RECORD AttrRecord)
Definition: mft.c:249
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
USHORT NameOffset
Definition: ntfs.h:130
UCHAR NameLength
Definition: ntfs.h:129
ULONG Type
Definition: ntfs.h:126
LARGE_INTEGER StreamSize
Definition: winternl.h:721
LARGE_INTEGER StreamAllocationSize
Definition: winternl.h:722
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
uint16_t * PWCHAR
Definition: typedefs.h:56
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

Referenced by NtfsQueryInformation().

◆ NtfsQueryInformation()

NTSTATUS NtfsQueryInformation ( PNTFS_IRP_CONTEXT  IrpContext)

Definition at line 420 of file finfo.c.

421{
426 PVOID SystemBuffer;
428 PIRP Irp;
431
432 DPRINT1("NtfsQueryInformation(%p)\n", IrpContext);
433
434 Irp = IrpContext->Irp;
435 Stack = IrpContext->Stack;
436 DeviceObject = IrpContext->DeviceObject;
437 FileInformationClass = Stack->Parameters.QueryFile.FileInformationClass;
438 FileObject = IrpContext->FileObject;
439 Fcb = FileObject->FsContext;
440
441 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
442 BufferLength = Stack->Parameters.QueryFile.Length;
443
446 {
447 return NtfsMarkIrpContextForQueue(IrpContext);
448 }
449
450 switch (FileInformationClass)
451 {
455 SystemBuffer,
456 &BufferLength);
457 break;
458
461 SystemBuffer,
462 &BufferLength);
463 break;
464
467 Fcb,
469 SystemBuffer,
470 &BufferLength);
471 break;
472
475 Fcb,
477 SystemBuffer,
478 &BufferLength);
479 break;
480
483 SystemBuffer,
484 &BufferLength);
485 break;
486
489 DeviceObject->DeviceExtension,
490 SystemBuffer,
491 &BufferLength);
492 break;
493
496 DeviceObject->DeviceExtension,
497 SystemBuffer,
498 &BufferLength);
499 break;
500
503 DPRINT1("Unimplemented information class: %s\n", GetInfoClassName(FileInformationClass));
505 break;
506
507 default:
508 DPRINT1("Unimplemented information class: %s\n", GetInfoClassName(FileInformationClass));
510 }
511
513
514 if (NT_SUCCESS(Status))
515 Irp->IoStatus.Information =
516 Stack->Parameters.QueryFile.Length - BufferLength;
517 else
518 Irp->IoStatus.Information = 0;
519
520 return Status;
521}
_In_ PIRP Irp
Definition: csq.h:116
FORCEINLINE NTSTATUS NtfsMarkIrpContextForQueue(PNTFS_IRP_CONTEXT IrpContext)
Definition: ntfs.h:569
#define IRPCONTEXT_CANWAIT
Definition: ntfs.h:474
#define ExAcquireResourceSharedLite(res, wait)
Definition: env_spec_w32.h:621
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
@ FilePositionInformation
Definition: from_kernel.h:75
@ FileAllInformation
Definition: from_kernel.h:79
@ FileInternalInformation
Definition: from_kernel.h:67
@ FileAlternateNameInformation
Definition: from_kernel.h:82
@ FileNameInformation
Definition: from_kernel.h:70
@ FileNetworkOpenInformation
Definition: from_kernel.h:95
@ FileStreamInformation
Definition: from_kernel.h:83
@ FileBasicInformation
Definition: from_kernel.h:65
enum _FILE_INFORMATION_CLASS FILE_INFORMATION_CLASS
Definition: directory.c:44
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:75
static NTSTATUS NtfsGetNameInformation(PFILE_OBJECT FileObject, PNTFS_FCB Fcb, PDEVICE_OBJECT DeviceObject, PFILE_NAME_INFORMATION NameInfo, PULONG BufferLength)
Definition: finfo.c:130
static NTSTATUS NtfsGetStreamInformation(PNTFS_FCB Fcb, PDEVICE_EXTENSION DeviceExt, PFILE_STREAM_INFORMATION StreamInfo, PULONG BufferLength)
Definition: finfo.c:226
static NTSTATUS NtfsGetPositionInformation(PFILE_OBJECT FileObject, PFILE_POSITION_INFORMATION PositionInfo, PULONG BufferLength)
Definition: finfo.c:75
const PCSTR GetInfoClassName(FILE_INFORMATION_CLASS infoClass)
Definition: finfo.c:296
static NTSTATUS NtfsGetStandardInformation(PNTFS_FCB Fcb, PDEVICE_OBJECT DeviceObject, PFILE_STANDARD_INFORMATION StandardInfo, PULONG BufferLength)
Definition: finfo.c:42
static NTSTATUS NtfsGetNetworkOpenInformation(PNTFS_FCB Fcb, PDEVICE_EXTENSION DeviceExt, PFILE_NETWORK_OPEN_INFORMATION NetworkInfo, PULONG BufferLength)
Definition: finfo.c:198
static NTSTATUS NtfsGetInternalInformation(PNTFS_FCB Fcb, PFILE_INTERNAL_INFORMATION InternalInfo, PULONG BufferLength)
Definition: finfo.c:177
static NTSTATUS NtfsGetBasicInformation(PFILE_OBJECT FileObject, PNTFS_FCB Fcb, PDEVICE_OBJECT DeviceObject, PFILE_BASIC_INFORMATION BasicInfo, PULONG BufferLength)
Definition: finfo.c:97
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define FileStandardInformation
Definition: propsheet.cpp:61
PFILE_OBJECT FileObject
Definition: ntfs.h:489
ULONG Flags
Definition: ntfs.h:481
PIO_STACK_LOCATION Stack
Definition: ntfs.h:482
PDEVICE_OBJECT DeviceObject
Definition: ntfs.h:488
Definition: cdstruc.h:902
ERESOURCE MainResource
Definition: ntfs.h:528
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
* PFILE_OBJECT
Definition: iotypes.h:1998

Referenced by NtfsDispatch().

◆ NtfsSetEndOfFile()

NTSTATUS NtfsSetEndOfFile ( PNTFS_FCB  Fcb,
PFILE_OBJECT  FileObject,
PDEVICE_EXTENSION  DeviceExt,
ULONG  IrpFlags,
BOOLEAN  CaseSensitive,
PLARGE_INTEGER  NewFileSize 
)

Definition at line 563 of file finfo.c.

569{
570 LARGE_INTEGER CurrentFileSize;
571 PFILE_RECORD_HEADER FileRecord;
572 PNTFS_ATTR_CONTEXT DataContext;
573 ULONG AttributeOffset;
576 PFILENAME_ATTRIBUTE FileNameAttribute;
577 ULONGLONG ParentMFTId;
579
580
581 // Allocate non-paged memory for the file record
582 FileRecord = ExAllocateFromNPagedLookasideList(&DeviceExt->FileRecLookasideList);
583 if (FileRecord == NULL)
584 {
585 DPRINT1("Couldn't allocate memory for file record!");
587 }
588
589 // read the file record
590 DPRINT("Reading file record...\n");
591 Status = ReadFileRecord(DeviceExt, Fcb->MFTIndex, FileRecord);
592 if (!NT_SUCCESS(Status))
593 {
594 // We couldn't get the file's record. Free the memory and return the error
595 DPRINT1("Can't find record for %wS!\n", Fcb->ObjectName);
596 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
597 return Status;
598 }
599
600 DPRINT("Found record for %wS\n", Fcb->ObjectName);
601
602 CurrentFileSize.QuadPart = NtfsGetFileSize(DeviceExt, FileRecord, L"", 0, NULL);
603
604 // Are we trying to decrease the file size?
605 if (NewFileSize->QuadPart < CurrentFileSize.QuadPart)
606 {
607 // Is the file mapped?
608 if (!MmCanFileBeTruncated(FileObject->SectionObjectPointer,
610 {
611 DPRINT1("Couldn't decrease file size!\n");
612 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
614 }
615 }
616
617 // Find the attribute with the data stream for our file
618 DPRINT("Finding Data Attribute...\n");
619 Status = FindAttribute(DeviceExt,
620 FileRecord,
622 Fcb->Stream,
623 wcslen(Fcb->Stream),
624 &DataContext,
625 &AttributeOffset);
626
627 // Did we fail to find the attribute?
628 if (!NT_SUCCESS(Status))
629 {
630 DPRINT1("No '%S' data stream associated with file!\n", Fcb->Stream);
631 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
632 return Status;
633 }
634
635 // Get the size of the data attribute
636 CurrentFileSize.QuadPart = AttributeDataLength(DataContext->pRecord);
637
638 // Are we enlarging the attribute?
639 if (NewFileSize->QuadPart > CurrentFileSize.QuadPart)
640 {
641 // is increasing the stream size not allowed?
642 if ((Fcb->Flags & FCB_IS_VOLUME) ||
643 (IrpFlags & IRP_PAGING_IO))
644 {
645 // TODO - just fail for now
646 ReleaseAttributeContext(DataContext);
647 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
649 }
650 }
651
652 // set the attribute data length
653 Status = SetAttributeDataLength(FileObject, Fcb, DataContext, AttributeOffset, FileRecord, NewFileSize);
654 if (!NT_SUCCESS(Status))
655 {
656 ReleaseAttributeContext(DataContext);
657 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
658 return Status;
659 }
660
661 // now we need to update this file's size in every directory index entry that references it
662 // TODO: expand to work with every filename / hardlink stored in the file record.
663 FileNameAttribute = GetBestFileNameFromRecord(Fcb->Vcb, FileRecord);
664 if (FileNameAttribute == NULL)
665 {
666 DPRINT1("Unable to find FileName attribute associated with file!\n");
667 ReleaseAttributeContext(DataContext);
668 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
670 }
671
672 ParentMFTId = FileNameAttribute->DirectoryFileReferenceNumber & NTFS_MFT_MASK;
673
674 FileName.Buffer = FileNameAttribute->Name;
675 FileName.Length = FileNameAttribute->NameLength * sizeof(WCHAR);
676 FileName.MaximumLength = FileName.Length;
677
678 AllocationSize = AttributeAllocatedLength(DataContext->pRecord);
679
681 ParentMFTId,
682 &FileName,
683 FALSE,
686 CaseSensitive);
687
688 ReleaseAttributeContext(DataContext);
689 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
690
691 return Status;
692}
#define NTFS_MFT_MASK
Definition: ntfs.h:68
PFILENAME_ATTRIBUTE GetBestFileNameFromRecord(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
Definition: attrib.c:1985
#define FCB_IS_VOLUME
Definition: ntfs.h:510
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:322
struct _FileName FileName
Definition: fatprocs.h:896
VOID ReleaseAttributeContext(PNTFS_ATTR_CONTEXT Context)
Definition: mft.c:104
NTSTATUS UpdateFileNameRecord(PDEVICE_EXTENSION Vcb, ULONGLONG ParentMFTIndex, PUNICODE_STRING FileName, BOOLEAN DirSearch, ULONGLONG NewDataSize, ULONGLONG NewAllocationSize, BOOLEAN CaseSensitive)
Definition: mft.c:1660
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
NTSTATUS SetAttributeDataLength(PFILE_OBJECT FileObject, PNTFS_FCB Fcb, PNTFS_ATTR_CONTEXT AttrContext, ULONG AttrOffset, PFILE_RECORD_HEADER FileRecord, PLARGE_INTEGER DataSize)
Definition: mft.c:615
ULONGLONG NtfsGetFileSize(PDEVICE_EXTENSION DeviceExt, PFILE_RECORD_HEADER FileRecord, PCWSTR Stream, ULONG StreamLength, PULONGLONG AllocatedSize)
Definition: dirctl.c:38
#define STATUS_USER_MAPPED_FILE
Definition: ntstatus.h:711
BOOLEAN NTAPI MmCanFileBeTruncated(_In_ PSECTION_OBJECT_POINTERS SectionObjectPointer, _In_opt_ PLARGE_INTEGER NewFileSize)
Definition: section.c:4255
UCHAR NameLength
Definition: ntfs.h:377
ULONGLONG DirectoryFileReferenceNumber
Definition: ntfs.h:360
WCHAR Name[1]
Definition: ntfs.h:379
ULONG Flags
Definition: ntfs.h:536
PVCB Vcb
Definition: cdstruc.h:933
WCHAR Stream[MAX_PATH]
Definition: ntfs.h:523
WCHAR * ObjectName
Definition: ntfs.h:524
uint64_t ULONGLONG
Definition: typedefs.h:67
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define IRP_PAGING_IO
_In_opt_ PLARGE_INTEGER NewFileSize
Definition: mmfuncs.h:608

Referenced by NtfsSetInformation().

◆ NtfsSetInformation()

NTSTATUS NtfsSetInformation ( PNTFS_IRP_CONTEXT  IrpContext)

Definition at line 719 of file finfo.c.

720{
723 PDEVICE_EXTENSION DeviceExt;
726 PVOID SystemBuffer;
728 PIRP Irp;
731
732 DPRINT("NtfsSetInformation(%p)\n", IrpContext);
733
734 Irp = IrpContext->Irp;
735 Stack = IrpContext->Stack;
736 DeviceObject = IrpContext->DeviceObject;
737 DeviceExt = DeviceObject->DeviceExtension;
738 FileInformationClass = Stack->Parameters.QueryFile.FileInformationClass;
739 FileObject = IrpContext->FileObject;
740 Fcb = FileObject->FsContext;
741
742 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
743 BufferLength = Stack->Parameters.QueryFile.Length;
744
747 {
748 return NtfsMarkIrpContextForQueue(IrpContext);
749 }
750
751 switch (FileInformationClass)
752 {
753 PFILE_END_OF_FILE_INFORMATION EndOfFileInfo;
754
755 /* TODO: Allocation size is not actually the same as file end for NTFS,
756 however, few applications are likely to make the distinction. */
758 DPRINT1("FIXME: Using hacky method of setting FileAllocationInformation.\n");
760 EndOfFileInfo = (PFILE_END_OF_FILE_INFORMATION)SystemBuffer;
763 DeviceExt,
764 Irp->Flags,
766 &EndOfFileInfo->EndOfFile);
767 break;
768
769 // TODO: all other information classes
770
771 default:
772 DPRINT1("FIXME: Unimplemented information class: %s\n", GetInfoClassName(FileInformationClass));
774 }
775
777
778 if (NT_SUCCESS(Status))
779 Irp->IoStatus.Information =
780 Stack->Parameters.QueryFile.Length - BufferLength;
781 else
782 Irp->IoStatus.Information = 0;
783
784 return Status;
785}
@ FileEndOfFileInformation
Definition: from_kernel.h:81
@ FileAllocationInformation
Definition: from_kernel.h:80
struct _FILE_END_OF_FILE_INFORMATION * PFILE_END_OF_FILE_INFORMATION
NTSTATUS NtfsSetEndOfFile(PNTFS_FCB Fcb, PFILE_OBJECT FileObject, PDEVICE_EXTENSION DeviceExt, ULONG IrpFlags, BOOLEAN CaseSensitive, PLARGE_INTEGER NewFileSize)
Definition: finfo.c:563
#define SL_CASE_SENSITIVE
Definition: iotypes.h:1820

Referenced by NtfsDispatch().