scroll mode for very long start menus
[reactos.git] / reactos / drivers / fs / cdfs / rw.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2002, 2003 ReactOS Team
4 *
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.
9 *
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.
14 *
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.
18 */
19 /* $Id: rw.c,v 1.12 2003/11/13 15:25:08 ekohl Exp $
20 *
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
26 * Eric Kohl
27 */
28
29 /* INCLUDES *****************************************************************/
30
31 #include <ddk/ntddk.h>
32 #include <ntos/minmax.h>
33
34 #define NDEBUG
35 #include <debug.h>
36
37 #include "cdfs.h"
38
39
40 /* GLOBALS *******************************************************************/
41
42 #define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
43 #define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
44
45
46 /* FUNCTIONS ****************************************************************/
47
48 static NTSTATUS
49 CdfsReadFile(PDEVICE_EXTENSION DeviceExt,
50 PFILE_OBJECT FileObject,
51 PUCHAR Buffer,
52 ULONG Length,
53 ULONG ReadOffset,
54 ULONG IrpFlags,
55 PULONG LengthRead)
56 /*
57 * FUNCTION: Reads data from a file
58 */
59 {
60 NTSTATUS Status = STATUS_SUCCESS;
61 PCCB Ccb;
62 PFCB Fcb;
63
64 DPRINT("CdfsReadFile(ReadOffset %lu Length %lu)\n", ReadOffset, Length);
65
66 *LengthRead = 0;
67
68 if (Length == 0)
69 return(STATUS_SUCCESS);
70
71 Ccb = (PCCB)FileObject->FsContext2;
72 Fcb = (PFCB)FileObject->FsContext;
73
74 if (ReadOffset >= Fcb->Entry.DataLengthL)
75 return(STATUS_END_OF_FILE);
76
77 DPRINT("Reading %d bytes at %d\n", Length, ReadOffset);
78
79 if (!(IrpFlags & (IRP_NOCACHE|IRP_PAGING_IO)))
80 {
81 LARGE_INTEGER FileOffset;
82 IO_STATUS_BLOCK IoStatus;
83
84 if (ReadOffset + Length > Fcb->Entry.DataLengthL)
85 Length = Fcb->Entry.DataLengthL - ReadOffset;
86
87 if (FileObject->PrivateCacheMap == NULL)
88 {
89 CcRosInitializeFileCache(FileObject, PAGE_SIZE);
90 }
91
92 FileOffset.QuadPart = (LONGLONG)ReadOffset;
93 CcCopyRead(FileObject,
94 &FileOffset,
95 Length,
96 TRUE,
97 Buffer,
98 &IoStatus);
99 *LengthRead = IoStatus.Information;
100
101 return(IoStatus.Status);
102 }
103
104 if ((ReadOffset % BLOCKSIZE) != 0 || (Length % BLOCKSIZE) != 0)
105 {
106 return STATUS_INVALID_PARAMETER;
107 }
108
109 if (ReadOffset + Length > ROUND_UP(Fcb->Entry.DataLengthL, BLOCKSIZE))
110 Length = ROUND_UP(Fcb->Entry.DataLengthL, BLOCKSIZE) - ReadOffset;
111
112 Status = CdfsReadSectors(DeviceExt->StorageDevice,
113 Fcb->Entry.ExtentLocationL + (ReadOffset / BLOCKSIZE),
114 Length / BLOCKSIZE,
115 Buffer,
116 FALSE);
117 if (NT_SUCCESS(Status))
118 {
119 *LengthRead = Length;
120 if (Length + ReadOffset > Fcb->Entry.DataLengthL)
121 {
122 memset(Buffer + Fcb->Entry.DataLengthL - ReadOffset,
123 0,
124 Length + ReadOffset - Fcb->Entry.DataLengthL);
125 }
126 }
127
128 return Status;
129 }
130
131
132 NTSTATUS STDCALL
133 CdfsRead(PDEVICE_OBJECT DeviceObject,
134 PIRP Irp)
135 {
136 PDEVICE_EXTENSION DeviceExt;
137 PIO_STACK_LOCATION Stack;
138 PFILE_OBJECT FileObject;
139 PVOID Buffer;
140 ULONG ReadLength;
141 LARGE_INTEGER ReadOffset;
142 ULONG ReturnedReadLength = 0;
143 NTSTATUS Status = STATUS_SUCCESS;
144
145 DPRINT("CdfsRead(DeviceObject %x, Irp %x)\n",DeviceObject,Irp);
146
147 DeviceExt = DeviceObject->DeviceExtension;
148 Stack = IoGetCurrentIrpStackLocation(Irp);
149 FileObject = Stack->FileObject;
150
151 ReadLength = Stack->Parameters.Read.Length;
152 ReadOffset = Stack->Parameters.Read.ByteOffset;
153 Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
154
155 Status = CdfsReadFile(DeviceExt,
156 FileObject,
157 Buffer,
158 ReadLength,
159 ReadOffset.u.LowPart,
160 Irp->Flags,
161 &ReturnedReadLength);
162 if (NT_SUCCESS(Status))
163 {
164 if (FileObject->Flags & FO_SYNCHRONOUS_IO)
165 {
166 FileObject->CurrentByteOffset.QuadPart =
167 ReadOffset.QuadPart + ReturnedReadLength;
168 }
169 Irp->IoStatus.Information = ReturnedReadLength;
170 }
171 else
172 {
173 Irp->IoStatus.Information = 0;
174 }
175
176 Irp->IoStatus.Status = Status;
177 IoCompleteRequest(Irp,IO_NO_INCREMENT);
178
179 return(Status);
180 }
181
182
183 NTSTATUS STDCALL
184 CdfsWrite(PDEVICE_OBJECT DeviceObject,
185 PIRP Irp)
186 {
187 DPRINT("CdfsWrite(DeviceObject %x Irp %x)\n",DeviceObject,Irp);
188
189 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
190 Irp->IoStatus.Information = 0;
191 return(STATUS_NOT_SUPPORTED);
192 }
193
194 /* EOF */