3 * Copyright (C) 2002 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 * COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS kernel
21 * FILE: drivers/filesystem/ntfs/rw.c
22 * PURPOSE: NTFS filesystem driver
23 * PROGRAMMER: Art Yerkes
27 /* INCLUDES *****************************************************************/
36 /* GLOBALS *******************************************************************/
38 #define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
39 #define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
42 /* FUNCTIONS ****************************************************************/
45 * FUNCTION: Reads data from a file
49 NtfsReadFile(PDEVICE_EXTENSION DeviceExt
,
50 PFILE_OBJECT FileObject
,
58 NTSTATUS Status
= STATUS_SUCCESS
;
64 DPRINT("CdfsReadFile(ReadOffset %lu Length %lu)\n", ReadOffset
, Length
);
69 return(STATUS_SUCCESS
);
71 Ccb
= (PCCB
)FileObject
->FsContext2
;
72 Fcb
= (PFCB
)FileObject
->FsContext
;
74 if (ReadOffset
>= Fcb
->Entry
.DataLengthL
)
75 return(STATUS_END_OF_FILE
);
77 DPRINT("Reading %d bytes at %d\n", Length
, ReadOffset
);
79 if (!(IrpFlags
& (IRP_NOCACHE
|IRP_PAGING_IO
)))
81 LARGE_INTEGER FileOffset
;
82 IO_STATUS_BLOCK IoStatus
;
84 if (ReadOffset
+ Length
> Fcb
->Entry
.DataLengthL
)
85 Length
= Fcb
->Entry
.DataLengthL
- ReadOffset
;
86 if (FileObject
->PrivateCacheMap
== NULL
)
88 CcRosInitializeFileCache(FileObject
, PAGE_SIZE
);
91 FileOffset
.QuadPart
= (LONGLONG
)ReadOffset
;
92 CcCopyRead(FileObject
,
98 *LengthRead
= IoStatus
.Information
;
100 return(IoStatus
.Status
);
103 if ((ReadOffset
% BLOCKSIZE
) != 0 || (Length
% BLOCKSIZE
) != 0)
105 return STATUS_INVALID_PARAMETER
;
107 if (ReadOffset
+ Length
> ROUND_UP(Fcb
->Entry
.DataLengthL
, BLOCKSIZE
))
108 Length
= ROUND_UP(Fcb
->Entry
.DataLengthL
, BLOCKSIZE
) - ReadOffset
;
110 Status
= CdfsReadSectors(DeviceExt
->StorageDevice
,
111 Fcb
->Entry
.ExtentLocationL
+ (ReadOffset
/ BLOCKSIZE
),
114 if (NT_SUCCESS(Status
))
116 *LengthRead
= Length
;
117 if (Length
+ ReadOffset
> Fcb
->Entry
.DataLengthL
)
119 memset(Buffer
+ Fcb
->Entry
.DataLengthL
- ReadOffset
,
120 0, Length
+ ReadOffset
- Fcb
->Entry
.DataLengthL
);
126 UNREFERENCED_PARAMETER(DeviceExt
);
127 UNREFERENCED_PARAMETER(FileObject
);
128 UNREFERENCED_PARAMETER(Buffer
);
129 UNREFERENCED_PARAMETER(Length
);
130 UNREFERENCED_PARAMETER(ReadOffset
);
131 UNREFERENCED_PARAMETER(IrpFlags
);
133 return STATUS_END_OF_FILE
;
140 NtfsFsdRead(PDEVICE_OBJECT DeviceObject
,
143 PDEVICE_EXTENSION DeviceExt
;
144 PIO_STACK_LOCATION Stack
;
145 PFILE_OBJECT FileObject
;
148 LARGE_INTEGER ReadOffset
;
149 ULONG ReturnedReadLength
= 0;
150 NTSTATUS Status
= STATUS_SUCCESS
;
152 DPRINT("NtfsRead(DeviceObject %x, Irp %x)\n",DeviceObject
,Irp
);
154 DeviceExt
= DeviceObject
->DeviceExtension
;
155 Stack
= IoGetCurrentIrpStackLocation(Irp
);
156 FileObject
= Stack
->FileObject
;
158 ReadLength
= Stack
->Parameters
.Read
.Length
;
159 ReadOffset
= Stack
->Parameters
.Read
.ByteOffset
;
160 Buffer
= MmGetSystemAddressForMdl(Irp
->MdlAddress
);
162 Status
= NtfsReadFile(DeviceExt
,
166 ReadOffset
.u
.LowPart
,
168 &ReturnedReadLength
);
169 if (NT_SUCCESS(Status
))
171 if (FileObject
->Flags
& FO_SYNCHRONOUS_IO
)
173 FileObject
->CurrentByteOffset
.QuadPart
=
174 ReadOffset
.QuadPart
+ ReturnedReadLength
;
177 Irp
->IoStatus
.Information
= ReturnedReadLength
;
181 Irp
->IoStatus
.Information
= 0;
184 Irp
->IoStatus
.Status
= Status
;
185 IoCompleteRequest(Irp
,IO_NO_INCREMENT
);
193 NtfsFsdWrite(PDEVICE_OBJECT DeviceObject
,
196 DPRINT("NtfwWrite(DeviceObject %x Irp %x)\n",DeviceObject
,Irp
);
198 Irp
->IoStatus
.Status
= STATUS_NOT_SUPPORTED
;
199 Irp
->IoStatus
.Information
= 0;
200 return STATUS_NOT_SUPPORTED
;