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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: drivers/fs/cdfs/rw.c
24 * PURPOSE: CDROM (ISO 9660) filesystem driver
25 * PROGRAMMER: Art Yerkes
29 /* INCLUDES *****************************************************************/
31 #include <ddk/ntddk.h>
32 #include <ntos/minmax.h>
40 /* GLOBALS *******************************************************************/
42 #define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
43 #define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
46 /* FUNCTIONS ****************************************************************/
49 CdfsReadFile(PDEVICE_EXTENSION DeviceExt
,
50 PFILE_OBJECT FileObject
,
57 * FUNCTION: Reads data from a file
60 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
;
87 if (FileObject
->PrivateCacheMap
== NULL
)
89 #ifdef ROS_USE_CC_AND_FS
90 CcRosInitializeFileCache(FileObject
, PAGE_SIZE
);
92 CcInitializeCacheMap(FileObject
,
93 (PCC_FILE_SIZES
)(&Fcb
->RFCB
.AllocationSize
),
100 FileOffset
.QuadPart
= (LONGLONG
)ReadOffset
;
101 CcCopyRead(FileObject
,
107 *LengthRead
= IoStatus
.Information
;
109 return(IoStatus
.Status
);
112 if ((ReadOffset
% BLOCKSIZE
) != 0 || (Length
% BLOCKSIZE
) != 0)
114 return STATUS_INVALID_PARAMETER
;
117 if (ReadOffset
+ Length
> ROUND_UP(Fcb
->Entry
.DataLengthL
, BLOCKSIZE
))
118 Length
= ROUND_UP(Fcb
->Entry
.DataLengthL
, BLOCKSIZE
) - ReadOffset
;
120 Status
= CdfsReadSectors(DeviceExt
->StorageDevice
,
121 Fcb
->Entry
.ExtentLocationL
+ (ReadOffset
/ BLOCKSIZE
),
125 if (NT_SUCCESS(Status
))
127 *LengthRead
= Length
;
128 if (Length
+ ReadOffset
> Fcb
->Entry
.DataLengthL
)
130 memset(Buffer
+ Fcb
->Entry
.DataLengthL
- ReadOffset
,
132 Length
+ ReadOffset
- Fcb
->Entry
.DataLengthL
);
141 CdfsRead(PDEVICE_OBJECT DeviceObject
,
144 PDEVICE_EXTENSION DeviceExt
;
145 PIO_STACK_LOCATION Stack
;
146 PFILE_OBJECT FileObject
;
149 LARGE_INTEGER ReadOffset
;
150 ULONG ReturnedReadLength
= 0;
151 NTSTATUS Status
= STATUS_SUCCESS
;
153 DPRINT("CdfsRead(DeviceObject %x, Irp %x)\n",DeviceObject
,Irp
);
155 DeviceExt
= DeviceObject
->DeviceExtension
;
156 Stack
= IoGetCurrentIrpStackLocation(Irp
);
157 FileObject
= Stack
->FileObject
;
159 ReadLength
= Stack
->Parameters
.Read
.Length
;
160 ReadOffset
= Stack
->Parameters
.Read
.ByteOffset
;
161 Buffer
= MmGetSystemAddressForMdl(Irp
->MdlAddress
);
163 Status
= CdfsReadFile(DeviceExt
,
167 ReadOffset
.u
.LowPart
,
169 &ReturnedReadLength
);
170 if (NT_SUCCESS(Status
))
172 if (FileObject
->Flags
& FO_SYNCHRONOUS_IO
)
174 FileObject
->CurrentByteOffset
.QuadPart
=
175 ReadOffset
.QuadPart
+ ReturnedReadLength
;
177 Irp
->IoStatus
.Information
= ReturnedReadLength
;
181 Irp
->IoStatus
.Information
= 0;
184 Irp
->IoStatus
.Status
= Status
;
185 IoCompleteRequest(Irp
,IO_NO_INCREMENT
);
192 CdfsWrite(PDEVICE_OBJECT DeviceObject
,
195 DPRINT("CdfsWrite(DeviceObject %x Irp %x)\n",DeviceObject
,Irp
);
197 Irp
->IoStatus
.Status
= STATUS_NOT_SUPPORTED
;
198 Irp
->IoStatus
.Information
= 0;
199 return(STATUS_NOT_SUPPORTED
);