ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

common.c
Go to the documentation of this file.
00001 /*
00002 *  ReactOS kernel
00003 *  Copyright (C) 2002, 2003 ReactOS Team
00004 *
00005 *  This program is free software; you can redistribute it and/or modify
00006 *  it under the terms of the GNU General Public License as published by
00007 *  the Free Software Foundation; either version 2 of the License, or
00008 *  (at your option) any later version.
00009 *
00010 *  This program is distributed in the hope that it will be useful,
00011 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 *  GNU General Public License for more details.
00014 *
00015 *  You should have received a copy of the GNU General Public License along
00016 *  with this program; if not, write to the Free Software Foundation, Inc.,
00017 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 */
00019 /* $Id: common.c 55057 2012-01-21 22:16:46Z cgutman $
00020 *
00021 * COPYRIGHT:        See COPYING in the top level directory
00022 * PROJECT:          ReactOS kernel
00023 * FILE:             drivers/fs/cdfs/common.c
00024 * PURPOSE:          CDROM (ISO 9660) filesystem driver
00025 * PROGRAMMER:       Art Yerkes
00026 *                   Eric Kohl
00027 */
00028 
00029 /* INCLUDES *****************************************************************/
00030 
00031 #include "cdfs.h"
00032 
00033 #define NDEBUG
00034 #include <debug.h>
00035 
00036 /* FUNCTIONS ****************************************************************/
00037 
00038 NTSTATUS
00039 CdfsReadSectors(IN PDEVICE_OBJECT DeviceObject,
00040                 IN ULONG DiskSector,
00041                 IN ULONG SectorCount,
00042                 IN OUT PUCHAR Buffer,
00043                 IN BOOLEAN Override)
00044 {
00045     PIO_STACK_LOCATION Stack;
00046     IO_STATUS_BLOCK IoStatus;
00047     LARGE_INTEGER Offset;
00048     ULONG BlockSize;
00049     KEVENT Event;
00050     PIRP Irp;
00051     NTSTATUS Status;
00052     BOOLEAN LastChance = FALSE;
00053 
00054 again:
00055     KeInitializeEvent(&Event,
00056         NotificationEvent,
00057         FALSE);
00058 
00059     Offset.u.LowPart = DiskSector << 11;
00060     Offset.u.HighPart = DiskSector >> 21;
00061 
00062     BlockSize = BLOCKSIZE * SectorCount;
00063 
00064     DPRINT("CdfsReadSectors(DeviceObject %x, DiskSector %d, Buffer %x)\n",
00065         DeviceObject, DiskSector, Buffer);
00066     DPRINT("Offset %I64x BlockSize %ld\n",
00067         Offset.QuadPart,
00068         BlockSize);
00069 
00070     DPRINT("Building synchronous FSD Request...\n");
00071     Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
00072         DeviceObject,
00073         Buffer,
00074         BlockSize,
00075         &Offset,
00076         &Event,
00077         &IoStatus);
00078     if (Irp == NULL)
00079     {
00080         DPRINT("IoBuildSynchronousFsdRequest failed\n");
00081         return(STATUS_INSUFFICIENT_RESOURCES);
00082     }
00083 
00084     if (Override)
00085     {
00086         Stack = IoGetNextIrpStackLocation(Irp);
00087         Stack->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
00088     }
00089 
00090     DPRINT("Calling IO Driver... with irp %x\n", Irp);
00091     Status = IoCallDriver(DeviceObject, Irp);
00092 
00093     DPRINT("Waiting for IO Operation for %x\n", Irp);
00094     if (Status == STATUS_PENDING)
00095     {
00096         DPRINT("Operation pending\n");
00097         KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
00098         DPRINT("Getting IO Status... for %x\n", Irp);
00099         Status = IoStatus.Status;
00100     }
00101 
00102     if (!NT_SUCCESS(Status))
00103     {
00104         if (Status == STATUS_VERIFY_REQUIRED)
00105         {
00106             PDEVICE_OBJECT DeviceToVerify;
00107 
00108             DeviceToVerify = IoGetDeviceToVerify(PsGetCurrentThread());
00109             IoSetDeviceToVerify(PsGetCurrentThread(), NULL);
00110 
00111             Status = IoVerifyVolume(DeviceToVerify, FALSE);
00112 
00113             if (NT_SUCCESS(Status) && !LastChance)
00114             {
00115                 DPRINT("Volume verify succeeded; trying request again\n");
00116                 LastChance = TRUE;
00117                 goto again;
00118             }
00119             else if (NT_SUCCESS(Status))
00120             {
00121                 DPRINT1("Failed to read after successful verify, aborting\n");
00122                 Status = STATUS_DEVICE_NOT_READY;
00123             }
00124             else
00125             {
00126                 DPRINT1("IoVerifyVolume() failed (Status %lx)\n", Status);
00127             }
00128         }
00129 
00130         DPRINT("CdfsReadSectors() failed (Status %x)\n", Status);
00131         DPRINT("(DeviceObject %x, DiskSector %x, Buffer %x, Offset 0x%I64x)\n",
00132             DeviceObject, DiskSector, Buffer,
00133             Offset.QuadPart);
00134         return(Status);
00135     }
00136 
00137     DPRINT("Block request succeeded for %x\n", Irp);
00138 
00139     return(STATUS_SUCCESS);
00140 }
00141 
00142 
00143 NTSTATUS
00144 CdfsDeviceIoControl (IN PDEVICE_OBJECT DeviceObject,
00145                      IN ULONG CtlCode,
00146                      IN PVOID InputBuffer,
00147                      IN ULONG InputBufferSize,
00148                      IN OUT PVOID OutputBuffer,
00149                      IN OUT PULONG OutputBufferSize,
00150                      IN BOOLEAN Override)
00151 {
00152     PIO_STACK_LOCATION Stack;
00153     IO_STATUS_BLOCK IoStatus;
00154     KEVENT Event;
00155     PIRP Irp;
00156     NTSTATUS Status;
00157     BOOLEAN LastChance = FALSE;
00158 
00159     DPRINT("CdfsDeviceIoControl(DeviceObject %x, CtlCode %x, "
00160         "InputBuffer %x, InputBufferSize %x, OutputBuffer %x, "
00161         "POutputBufferSize %x (%x)\n", DeviceObject, CtlCode,
00162         InputBuffer, InputBufferSize, OutputBuffer, OutputBufferSize,
00163         OutputBufferSize ? *OutputBufferSize : 0);
00164 
00165 again:
00166     KeInitializeEvent (&Event, NotificationEvent, FALSE);
00167 
00168     DPRINT("Building device I/O control request ...\n");
00169     Irp = IoBuildDeviceIoControlRequest(CtlCode,
00170         DeviceObject,
00171         InputBuffer,
00172         InputBufferSize,
00173         OutputBuffer,
00174         (OutputBufferSize != NULL) ? *OutputBufferSize : 0,
00175         FALSE,
00176         &Event,
00177         &IoStatus);
00178     if (Irp == NULL)
00179     {
00180         DPRINT("IoBuildDeviceIoControlRequest failed\n");
00181         return STATUS_INSUFFICIENT_RESOURCES;
00182     }
00183 
00184     if (Override)
00185     {
00186         Stack = IoGetNextIrpStackLocation(Irp);
00187         Stack->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
00188     }
00189 
00190     DPRINT ("Calling IO Driver... with irp %x\n", Irp);
00191     Status = IoCallDriver(DeviceObject, Irp);
00192 
00193     DPRINT ("Waiting for IO Operation for %x\n", Irp);
00194     if (Status == STATUS_PENDING)
00195     {
00196         DPRINT ("Operation pending\n");
00197         KeWaitForSingleObject (&Event, Suspended, KernelMode, FALSE, NULL);
00198         DPRINT ("Getting IO Status... for %x\n", Irp);
00199 
00200         Status = IoStatus.Status;
00201     }
00202 
00203     if (OutputBufferSize != NULL)
00204     {
00205         *OutputBufferSize = IoStatus.Information;
00206     }
00207 
00208     if (Status == STATUS_VERIFY_REQUIRED)
00209     {
00210         PDEVICE_OBJECT DeviceToVerify;
00211 
00212         DeviceToVerify = IoGetDeviceToVerify(PsGetCurrentThread());
00213         IoSetDeviceToVerify(PsGetCurrentThread(), NULL);
00214 
00215         if (DeviceToVerify)
00216         {
00217             Status = IoVerifyVolume(DeviceToVerify, FALSE);
00218             DPRINT("IoVerifyVolume() returned (Status %lx)\n", Status);
00219         }
00220 
00221         if (NT_SUCCESS(Status) && !LastChance)
00222         {
00223             DPRINT1("Volume verify succeeded; trying request again\n");
00224             LastChance = TRUE;
00225             goto again;
00226         }
00227         else if (NT_SUCCESS(Status))
00228         {
00229             DPRINT1("Failed to read after successful verify, aborting\n");
00230             Status = STATUS_DEVICE_NOT_READY;
00231         }
00232         else
00233         {
00234             DPRINT1("IoVerifyVolume() failed (Status %lx)\n", Status);
00235         }
00236     }
00237 
00238     DPRINT("Returning Status %x\n", Status);
00239 
00240     return Status;
00241 }
00242 
00243 /* EOF */

Generated on Sat May 26 2012 04:23:15 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.