63 DPRINT(
"NtfsReadFile(%p, %p, %p, %lu, %lu, %lx, %p)\n", DeviceExt,
FileObject,
Buffer,
Length,
ReadOffset, IrpFlags, LengthRead);
89 FileRecord = ExAllocateFromNPagedLookasideList(&DeviceExt->FileRecLookasideList);
90 if (FileRecord ==
NULL)
92 DPRINT1(
"Not enough memory!\n");
99 DPRINT1(
"Can't find record!\n");
100 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
132 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
139 DPRINT1(
"Reading beyond stream end!\n");
141 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
152 if ((
ReadOffset % DeviceExt->NtfsInfo.BytesPerSector) != 0 || (ToRead % DeviceExt->NtfsInfo.BytesPerSector) != 0)
155 RealLength =
ROUND_UP(ToRead, DeviceExt->NtfsInfo.BytesPerSector);
159 if (RealReadOffset + RealLength + DeviceExt->NtfsInfo.BytesPerSector <=
AttributeAllocatedLength(DataContext->pRecord))
160 RealLength += DeviceExt->NtfsInfo.BytesPerSector;
167 DPRINT1(
"Not enough memory!\n");
169 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
172 AllocatedBuffer =
TRUE;
175 DPRINT(
"Effective read: %lu at %lu for stream '%S'\n", RealLength, RealReadOffset,
Fcb->
Stream);
177 if (RealLengthRead == 0)
181 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
190 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
192 *LengthRead = ToRead;
194 DPRINT(
"%lu got read\n", *LengthRead);
224 ULONG ReturnedReadLength = 0;
229 DPRINT(
"NtfsRead(IrpContext %p)\n", IrpContext);
247 &ReturnedReadLength);
256 Irp->IoStatus.Information = ReturnedReadLength;
260 Irp->IoStatus.Information = 0;
324 ULONG AttributeOffset;
327 DPRINT(
"NtfsWriteFile(%p, %p, %p, %lu, %lu, %x, %s, %p)\n",
334 (CaseSensitive ?
"TRUE" :
"FALSE"),
359 DPRINT(
"Compressed file!\n");
365 FileRecord = ExAllocateFromNPagedLookasideList(&DeviceExt->FileRecLookasideList);
366 if (FileRecord ==
NULL)
373 DPRINT(
"Reading file record...\n");
379 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
386 DPRINT(
"Finding Data Attribute...\n");
418 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
447 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
458 ASSERT(fileNameAttribute);
479 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
495 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
501 if (*LengthWritten !=
Length)
503 DPRINT1(
"\a\tNTFS DRIVER ERROR: length written (%lu) differs from requested (%lu), but no error was indicated!\n",
509 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
545 ULONG ReturnedWriteLength = 0;
550 ULONG BytesPerSector;
552 DPRINT(
"NtfsWrite(IrpContext %p)\n", IrpContext);
561 DPRINT1(
"\t\t\t\tNtfsWrite is called with the main device object.\n");
563 Irp->IoStatus.Information = 0;
572 DPRINT(
"NTFS Version: %d.%d\n",
Fcb->
Vcb->NtfsInfo.MajorVersion,
Fcb->
Vcb->NtfsInfo.MinorVersion);
578 BytesPerSector = DeviceExt->StorageDevice->SectorSize;
589 DPRINT(
"ByteOffset: %I64u\tLength: %lu\tBytes per sector: %lu\n",
ByteOffset.QuadPart,
595 DPRINT1(
"FIXME: Writing to large files is not yet supported at this time.\n");
604 if (
ByteOffset.u.LowPart % BytesPerSector != 0 ||
Length % BytesPerSector != 0)
606 DPRINT1(
"Non-cached writes and non-buffered writes must be sector aligned!\n");
661 DPRINT1(
"FIXME: Async writes not supported in NTFS!\n");
677 DPRINT1(
"Unable to lock user buffer!\n");
684 DPRINT(
"About to write the data. Length: %lu\n",
Length);
696 &ReturnedWriteLength);
715 DPRINT1(
"Write not Succesful!\tReturned length: %lu\n", ReturnedWriteLength);
718 Irp->IoStatus.Information = ReturnedWriteLength;
#define ReadBuffer(BaseIoAddress, Buffer, Count)
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
#define STATUS_NOT_IMPLEMENTED
#define NT_SUCCESS(StatCode)
NTSTATUS FindFirstAttribute(PFIND_ATTR_CONTXT Context, PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord, BOOLEAN OnlyResident, PNTFS_ATTR_RECORD *Attribute)
VOID FindCloseAttribute(PFIND_ATTR_CONTXT Context)
NTSTATUS FindNextAttribute(PFIND_ATTR_CONTXT Context, PNTFS_ATTR_RECORD *Attribute)
PFILENAME_ATTRIBUTE GetBestFileNameFromRecord(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
NTSTATUS NtfsLockUserBuffer(IN PIRP Irp, IN ULONG Length, IN LOCK_OPERATION Operation)
PVOID NtfsGetUserBuffer(PIRP Irp, BOOLEAN Paging)
PNTFS_GLOBAL_DATA NtfsGlobalData
#define IRPCONTEXT_CANWAIT
NTSTATUS NtfsWriteFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, const PUCHAR Buffer, ULONG Length, ULONG WriteOffset, ULONG IrpFlags, BOOLEAN CaseSensitive, PULONG LengthWritten)
NTSTATUS NtfsRead(PNTFS_IRP_CONTEXT IrpContext)
NTSTATUS NtfsWrite(PNTFS_IRP_CONTEXT IrpContext)
static NTSTATUS NtfsReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, PUCHAR Buffer, ULONG Length, ULONG ReadOffset, ULONG IrpFlags, PULONG LengthRead)
#define ExAllocatePoolWithTag(hernya, size, tag)
#define ExAcquireResourceExclusiveLite(res, wait)
#define ROUND_UP(n, align)
#define ROUND_DOWN(n, align)
#define FILE_WRITE_TO_END_OF_FILE
#define BooleanFlagOn(F, SF)
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
#define FILE_NO_INTERMEDIATE_BUFFERING
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSTATUS ReadFileRecord(PDEVICE_EXTENSION Vcb, ULONGLONG index, PFILE_RECORD_HEADER file)
VOID ReleaseAttributeContext(PNTFS_ATTR_CONTEXT Context)
NTSTATUS UpdateFileNameRecord(PDEVICE_EXTENSION Vcb, ULONGLONG ParentMFTIndex, PUNICODE_STRING FileName, BOOLEAN DirSearch, ULONGLONG NewDataSize, ULONGLONG NewAllocationSize, BOOLEAN CaseSensitive)
ULONGLONG AttributeDataLength(PNTFS_ATTR_RECORD AttrRecord)
NTSTATUS FindAttribute(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER MftRecord, ULONG Type, PCWSTR Name, ULONG NameLength, PNTFS_ATTR_CONTEXT *AttrCtx, PULONG Offset)
ULONG ReadAttribute(PDEVICE_EXTENSION Vcb, PNTFS_ATTR_CONTEXT Context, ULONGLONG Offset, PCHAR Buffer, ULONG Length)
NTSTATUS WriteAttribute(PDEVICE_EXTENSION Vcb, PNTFS_ATTR_CONTEXT Context, ULONGLONG Offset, const PUCHAR Buffer, ULONG Length, PULONG RealLengthWritten, PFILE_RECORD_HEADER FileRecord)
ULONGLONG AttributeAllocatedLength(PNTFS_ATTR_RECORD AttrRecord)
NTSTATUS SetAttributeDataLength(PFILE_OBJECT FileObject, PNTFS_FCB Fcb, PNTFS_ATTR_CONTEXT AttrContext, ULONG AttrOffset, PFILE_RECORD_HEADER FileRecord, PLARGE_INTEGER DataSize)
#define ExFreePoolWithTag(_P, _T)
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
_In_ ULONG _In_ ULONG _In_ ULONG Length
BOOLEAN NtfsFCBIsEncrypted(PNTFS_FCB Fcb)
BOOLEAN NtfsFCBIsCompressed(PNTFS_FCB Fcb)
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
#define STATUS_UNEXPECTED_IO_ERROR
#define STATUS_END_OF_FILE
ULONGLONG DirectoryFileReferenceNumber
PDEVICE_OBJECT DeviceObject
PDEVICE_OBJECT DeviceObject
FSRTL_COMMON_FCB_HEADER RFCB
ERESOURCE PagingIoResource
struct _IO_STACK_LOCATION::@4090::@4095 Write
union _IO_STACK_LOCATION::@1605 Parameters
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
#define STATUS_INVALID_DEVICE_REQUEST
#define STATUS_ACCESS_DENIED
#define STATUS_INVALID_PARAMETER
#define STATUS_INSUFFICIENT_RESOURCES
_In_ PDEVICE_OBJECT DeviceObject
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
_Must_inspect_result_ _In_ WDFUSBPIPE _In_ WDFREQUEST _In_opt_ WDFMEMORY _In_opt_ PWDFMEMORY_OFFSET ReadOffset
_Must_inspect_result_ _In_ WDFUSBPIPE _In_ WDFREQUEST _In_opt_ WDFMEMORY _In_opt_ PWDFMEMORY_OFFSET WriteOffset
#define IO_DISK_INCREMENT
#define FO_SYNCHRONOUS_IO
#define SL_CASE_SENSITIVE