3 * Copyright (C) 2002, 2003 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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
22 * FILE: drivers/fs/cdfs/rw.c
23 * PURPOSE: CDROM (ISO 9660) filesystem driver
24 * PROGRAMMER: Art Yerkes
28 /* INCLUDES *****************************************************************/
35 /* FUNCTIONS ****************************************************************/
37 #define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
38 #define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
41 /* FUNCTIONS ****************************************************************/
44 CdfsReadFile(PDEVICE_EXTENSION DeviceExt
,
45 PFILE_OBJECT FileObject
,
52 * FUNCTION: Reads data from a file
55 NTSTATUS Status
= STATUS_SUCCESS
;
57 ULONG ToRead
= Length
;
59 DPRINT("CdfsReadFile(ReadOffset %lu Length %lu)\n", ReadOffset
, Length
);
64 return(STATUS_SUCCESS
);
66 Fcb
= (PFCB
)FileObject
->FsContext
;
68 if (ReadOffset
>= Fcb
->Entry
.DataLengthL
)
69 return(STATUS_END_OF_FILE
);
71 if (ReadOffset
+ Length
> Fcb
->Entry
.DataLengthL
)
72 ToRead
= Fcb
->Entry
.DataLengthL
- ReadOffset
;
74 DPRINT("Reading %u bytes at %u\n", Length
, ReadOffset
);
76 if (!(IrpFlags
& (IRP_NOCACHE
|IRP_PAGING_IO
)))
78 LARGE_INTEGER FileOffset
;
79 IO_STATUS_BLOCK IoStatus
;
80 CC_FILE_SIZES FileSizes
;
82 DPRINT("Using cache\n");
84 if (FileObject
->PrivateCacheMap
== NULL
)
86 FileSizes
.AllocationSize
= Fcb
->RFCB
.AllocationSize
;
87 FileSizes
.FileSize
= Fcb
->RFCB
.FileSize
;
88 FileSizes
.ValidDataLength
= Fcb
->RFCB
.ValidDataLength
;
90 DPRINT("Attach FCB to File: Size %08x%08x\n",
91 Fcb
->RFCB
.ValidDataLength
.HighPart
,
92 Fcb
->RFCB
.ValidDataLength
.LowPart
);
94 CcInitializeCacheMap(FileObject
,
97 &(CdfsGlobalData
->CacheMgrCallbacks
),
101 FileOffset
.QuadPart
= (LONGLONG
)ReadOffset
;
102 CcCopyRead(FileObject
,
108 *LengthRead
= IoStatus
.Information
;
110 Status
= IoStatus
.Status
;
114 ULONG ActualReadOffset
= ROUND_DOWN(ReadOffset
, BLOCKSIZE
);
115 ULONG nBlocks
= (ROUND_UP(ReadOffset
+ ToRead
, BLOCKSIZE
) - ActualReadOffset
) / BLOCKSIZE
;
117 BOOLEAN bFreeBuffer
= FALSE
;
118 if ((ReadOffset
% BLOCKSIZE
) != 0 || (ToRead
% BLOCKSIZE
) != 0)
120 PageBuf
= ExAllocatePool(NonPagedPool
, nBlocks
* BLOCKSIZE
);
123 return STATUS_NO_MEMORY
;
131 Status
= CdfsReadSectors(DeviceExt
->StorageDevice
,
132 Fcb
->Entry
.ExtentLocationL
+ (ActualReadOffset
/ BLOCKSIZE
),
137 if(NT_SUCCESS(Status
))
139 *LengthRead
= ToRead
;
142 /* Copy what we've got */
143 RtlCopyMemory(Buffer
, PageBuf
+ (ReadOffset
- ActualReadOffset
), ToRead
);
145 /* Zero out the rest */
147 RtlZeroMemory(Buffer
+ ToRead
, Length
- ToRead
);
159 CdfsRead(PDEVICE_OBJECT DeviceObject
,
162 PDEVICE_EXTENSION DeviceExt
;
163 PIO_STACK_LOCATION Stack
;
164 PFILE_OBJECT FileObject
;
167 LARGE_INTEGER ReadOffset
;
168 ULONG ReturnedReadLength
= 0;
169 NTSTATUS Status
= STATUS_SUCCESS
;
171 DPRINT("CdfsRead(DeviceObject %p, Irp %p)\n", DeviceObject
, Irp
);
173 DeviceExt
= DeviceObject
->DeviceExtension
;
174 Stack
= IoGetCurrentIrpStackLocation(Irp
);
175 FileObject
= Stack
->FileObject
;
177 ReadLength
= Stack
->Parameters
.Read
.Length
;
178 ReadOffset
= Stack
->Parameters
.Read
.ByteOffset
;
179 if (ReadLength
) Buffer
= MmGetSystemAddressForMdl(Irp
->MdlAddress
);
181 Status
= CdfsReadFile(DeviceExt
,
185 ReadOffset
.u
.LowPart
,
187 &ReturnedReadLength
);
188 if (NT_SUCCESS(Status
))
190 if (FileObject
->Flags
& FO_SYNCHRONOUS_IO
)
192 FileObject
->CurrentByteOffset
.QuadPart
=
193 ReadOffset
.QuadPart
+ ReturnedReadLength
;
195 Irp
->IoStatus
.Information
= ReturnedReadLength
;
199 Irp
->IoStatus
.Information
= 0;
202 Irp
->IoStatus
.Status
= Status
;
203 IoCompleteRequest(Irp
,IO_NO_INCREMENT
);
210 CdfsWrite(PDEVICE_OBJECT DeviceObject
,
213 DPRINT("CdfsWrite(DeviceObject %p Irp %p)\n", DeviceObject
, Irp
);
215 Irp
->IoStatus
.Status
= STATUS_NOT_SUPPORTED
;
216 Irp
->IoStatus
.Information
= 0;
217 return(STATUS_NOT_SUPPORTED
);