63 DPRINT(
"NtfsReadFile(%p, %p, %p, %lu, %lu, %lx, %p)\n", DeviceExt,
FileObject,
Buffer,
Length,
ReadOffset, IrpFlags, LengthRead);
82 FileRecord = ExAllocateFromNPagedLookasideList(&DeviceExt->FileRecLookasideList);
83 if (FileRecord ==
NULL)
85 DPRINT1(
"Not enough memory!\n");
92 DPRINT1(
"Can't find record!\n");
93 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
125 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
132 DPRINT1(
"Reading beyond stream end!\n");
134 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
145 if ((
ReadOffset % DeviceExt->NtfsInfo.BytesPerSector) != 0 || (ToRead % DeviceExt->NtfsInfo.BytesPerSector) != 0)
148 RealLength =
ROUND_UP(ToRead, DeviceExt->NtfsInfo.BytesPerSector);
152 if (RealReadOffset + RealLength + DeviceExt->NtfsInfo.BytesPerSector <=
AttributeAllocatedLength(DataContext->pRecord))
153 RealLength += DeviceExt->NtfsInfo.BytesPerSector;
160 DPRINT1(
"Not enough memory!\n");
162 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
165 AllocatedBuffer =
TRUE;
168 DPRINT(
"Effective read: %lu at %lu for stream '%S'\n", RealLength, RealReadOffset,
Fcb->
Stream);
170 if (RealLengthRead == 0)
174 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
183 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
185 *LengthRead = ToRead;
187 DPRINT(
"%lu got read\n", *LengthRead);
217 ULONG ReturnedReadLength = 0;
222 DPRINT(
"NtfsRead(IrpContext %p)\n", IrpContext);
240 &ReturnedReadLength);
249 Irp->IoStatus.Information = ReturnedReadLength;
253 Irp->IoStatus.Information = 0;
317 ULONG AttributeOffset;
320 DPRINT(
"NtfsWriteFile(%p, %p, %p, %lu, %lu, %x, %s, %p)\n",
327 (CaseSensitive ?
"TRUE" :
"FALSE"),
352 DPRINT(
"Compressed file!\n");
358 FileRecord = ExAllocateFromNPagedLookasideList(&DeviceExt->FileRecLookasideList);
359 if (FileRecord ==
NULL)
366 DPRINT(
"Reading file record...\n");
372 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
379 DPRINT(
"Finding Data Attribute...\n");
411 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
440 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
451 ASSERT(fileNameAttribute);
472 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
488 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
494 if (*LengthWritten !=
Length)
496 DPRINT1(
"\a\tNTFS DRIVER ERROR: length written (%lu) differs from requested (%lu), but no error was indicated!\n",
502 ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
538 ULONG ReturnedWriteLength = 0;
543 ULONG BytesPerSector;
545 DPRINT(
"NtfsWrite(IrpContext %p)\n", IrpContext);
554 DPRINT1(
"\t\t\t\tNtfsWrite is called with the main device object.\n");
556 Irp->IoStatus.Information = 0;
565 DPRINT(
"NTFS Version: %d.%d\n",
Fcb->
Vcb->NtfsInfo.MajorVersion,
Fcb->
Vcb->NtfsInfo.MinorVersion);
571 BytesPerSector = DeviceExt->StorageDevice->SectorSize;
582 DPRINT(
"ByteOffset: %I64u\tLength: %lu\tBytes per sector: %lu\n",
ByteOffset.QuadPart,
588 DPRINT1(
"FIXME: Writing to large files is not yet supported at this time.\n");
597 if (
ByteOffset.u.LowPart % BytesPerSector != 0 ||
Length % BytesPerSector != 0)
599 DPRINT1(
"Non-cached writes and non-buffered writes must be sector aligned!\n");
654 DPRINT1(
"FIXME: Async writes not supported in NTFS!\n");
670 DPRINT1(
"Unable to lock user buffer!\n");
677 DPRINT(
"About to write the data. Length: %lu\n",
Length);
689 &ReturnedWriteLength);
708 DPRINT1(
"Write not Succesful!\tReturned length: %lu\n", ReturnedWriteLength);
711 Irp->IoStatus.Information = ReturnedWriteLength;
ULONGLONG AttributeAllocatedLength(PNTFS_ATTR_RECORD AttrRecord)
PFILENAME_ATTRIBUTE GetBestFileNameFromRecord(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
PDEVICE_OBJECT DeviceObject
#define SL_CASE_SENSITIVE
#define STATUS_INSUFFICIENT_RESOURCES
_In_ ULONG _In_ ULONG _In_ ULONG Length
#define ROUND_UP(n, align)
IN BOOLEAN OUT PSTR Buffer
#define STATUS_INVALID_PARAMETER
#define BooleanFlagOn(F, SF)
_Must_inspect_result_ _In_ WDFUSBPIPE _In_ WDFREQUEST _In_opt_ WDFMEMORY _In_opt_ PWDFMEMORY_OFFSET WriteOffset
#define ReadBuffer(BaseIoAddress, Buffer, Count)
static NTSTATUS NtfsReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, PUCHAR Buffer, ULONG Length, ULONG ReadOffset, ULONG IrpFlags, PULONG LengthRead)
#define STATUS_INVALID_DEVICE_REQUEST
NTSTATUS FindAttribute(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER MftRecord, ULONG Type, PCWSTR Name, ULONG NameLength, PNTFS_ATTR_CONTEXT *AttrCtx, PULONG Offset)
PNTFS_GLOBAL_DATA NtfsGlobalData
#define STATUS_END_OF_FILE
#define FO_SYNCHRONOUS_IO
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
_In_ PDEVICE_OBJECT DeviceObject
return STATUS_NOT_IMPLEMENTED
#define FILE_NO_INTERMEDIATE_BUFFERING
#define IO_DISK_INCREMENT
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
_Must_inspect_result_ _In_ WDFUSBPIPE _In_ WDFREQUEST _In_opt_ WDFMEMORY _In_opt_ PWDFMEMORY_OFFSET ReadOffset
NTSTATUS NtfsWrite(PNTFS_IRP_CONTEXT IrpContext)
#define IRPCONTEXT_CANWAIT
NTSTATUS FindNextAttribute(PFIND_ATTR_CONTXT Context, PNTFS_ATTR_RECORD *Attribute)
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
FSRTL_COMMON_FCB_HEADER RFCB
#define FILE_WRITE_TO_END_OF_FILE
#define NT_SUCCESS(StatCode)
#define STATUS_ACCESS_DENIED
NTSTATUS NtfsRead(PNTFS_IRP_CONTEXT IrpContext)
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
NTSTATUS UpdateFileNameRecord(PDEVICE_EXTENSION Vcb, ULONGLONG ParentMFTIndex, PUNICODE_STRING FileName, BOOLEAN DirSearch, ULONGLONG NewDataSize, ULONGLONG NewAllocationSize, BOOLEAN CaseSensitive)
NTSTATUS WriteAttribute(PDEVICE_EXTENSION Vcb, PNTFS_ATTR_CONTEXT Context, ULONGLONG Offset, const PUCHAR Buffer, ULONG Length, PULONG RealLengthWritten, PFILE_RECORD_HEADER FileRecord)
#define ExAllocatePoolWithTag(hernya, size, tag)
VOID FindCloseAttribute(PFIND_ATTR_CONTXT Context)
ULONGLONG DirectoryFileReferenceNumber
PDEVICE_OBJECT DeviceObject
NTSTATUS NtfsWriteFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, const PUCHAR Buffer, ULONG Length, ULONG WriteOffset, ULONG IrpFlags, BOOLEAN CaseSensitive, PULONG LengthWritten)
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
#define ROUND_DOWN(n, align)
NTSTATUS FindFirstAttribute(PFIND_ATTR_CONTXT Context, PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord, BOOLEAN OnlyResident, PNTFS_ATTR_RECORD *Attribute)
NTSTATUS ReadFileRecord(PDEVICE_EXTENSION Vcb, ULONGLONG index, PFILE_RECORD_HEADER file)
VOID ReleaseAttributeContext(PNTFS_ATTR_CONTEXT Context)
ULONG ReadAttribute(PDEVICE_EXTENSION Vcb, PNTFS_ATTR_CONTEXT Context, ULONGLONG Offset, PCHAR Buffer, ULONG Length)
NTSTATUS SetAttributeDataLength(PFILE_OBJECT FileObject, PNTFS_FCB Fcb, PNTFS_ATTR_CONTEXT AttrContext, ULONG AttrOffset, PFILE_RECORD_HEADER FileRecord, PLARGE_INTEGER DataSize)
#define STATUS_UNEXPECTED_IO_ERROR
NTSTATUS NtfsLockUserBuffer(IN PIRP Irp, IN ULONG Length, IN LOCK_OPERATION Operation)
PVOID NtfsGetUserBuffer(PIRP Irp, BOOLEAN Paging)
BOOLEAN NtfsFCBIsCompressed(PNTFS_FCB Fcb)
struct tagContext Context
ERESOURCE PagingIoResource
#define RtlZeroMemory(Destination, Length)
#define RtlCopyMemory(Destination, Source, Length)
#define ExFreePoolWithTag(_P, _T)
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
ULONGLONG AttributeDataLength(PNTFS_ATTR_RECORD AttrRecord)
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset