ReactOS  0.4.14-dev-342-gdc047f9
disk.c File Reference
#include "disk.h"
#include <initguid.h>
#include <ioevent.h>
Include dependency graph for disk.c:

Go to the source code of this file.

Classes

struct  _DISK_GEOMETRY_EX_INTERNAL
 

Macros

#define DiskCompareGuid(_First, _Second)   (memcmp ((_First),(_Second), sizeof (GUID)))
 
#define SendToFdo(Dev, Irp, Rval)
 

Typedefs

typedef struct _DISK_GEOMETRY_EX_INTERNAL DISK_GEOMETRY_EX_INTERNAL
 
typedef struct _DISK_GEOMETRY_EX_INTERNALPDISK_GEOMETRY_EX_INTERNAL
 

Functions

NTSTATUS NTAPI DiskDetermineMediaTypes (IN PDEVICE_OBJECT Fdo, IN PIRP Irp, IN UCHAR MediumType, IN UCHAR DensityCode, IN BOOLEAN MediaPresent, IN BOOLEAN IsWritable)
 
PPARTITION_INFORMATION_EX NTAPI DiskPdoFindPartitionEntry (IN PPHYSICAL_DEVICE_EXTENSION Pdo, IN PDRIVE_LAYOUT_INFORMATION_EX LayoutInfo)
 
PPARTITION_INFORMATION_EX NTAPI DiskFindAdjacentPartition (IN PDRIVE_LAYOUT_INFORMATION_EX LayoutInfo, IN PPARTITION_INFORMATION_EX BasePartition)
 
PPARTITION_INFORMATION_EX NTAPI DiskFindContainingPartition (IN PDRIVE_LAYOUT_INFORMATION_EX LayoutInfo, IN PPARTITION_INFORMATION_EX BasePartition, IN BOOLEAN SearchTopToBottom)
 
NTSTATUS NTAPI DiskIoctlCreateDisk (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlGetDriveLayout (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlGetDriveLayoutEx (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlSetDriveLayout (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlSetDriveLayoutEx (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlGetPartitionInfo (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlGetPartitionInfoEx (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlGetLengthInfo (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlSetPartitionInfo (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlSetPartitionInfoEx (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlGetDriveGeometryEx (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 
VOID NTAPI DiskUnload (IN PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI DiskCreateFdo (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject, IN PULONG DeviceCount, IN BOOLEAN DasdAccessOnly)
 
NTSTATUS NTAPI DiskReadWriteVerification (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskDeviceControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI DiskShutdownFlush (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskModeSelect (IN PDEVICE_OBJECT Fdo, IN PCHAR ModeSelectBuffer, IN ULONG Length, IN BOOLEAN SavePage)
 
VOID NTAPI DisableWriteCache (IN PDEVICE_OBJECT Fdo, IN PIO_WORKITEM WorkItem)
 
VOID NTAPI DiskIoctlVerify (IN PDEVICE_OBJECT Fdo, IN PDISK_VERIFY_WORKITEM_CONTEXT Context)
 
VOID NTAPI DiskFdoProcessError (PDEVICE_OBJECT Fdo, PSCSI_REQUEST_BLOCK Srb, NTSTATUS *Status, BOOLEAN *Retry)
 
VOID NTAPI DiskSetSpecialHacks (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN ULONG_PTR Data)
 
VOID NTAPI DiskScanRegistryForSpecial (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
 
VOID NTAPI ResetBus (IN PDEVICE_OBJECT Fdo)
 
NTSTATUS NTAPI DiskQueryPnpCapabilities (IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_CAPABILITIES Capabilities)
 
NTSTATUS NTAPI DiskGetCacheInformation (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PDISK_CACHE_INFORMATION CacheInfo)
 
NTSTATUS NTAPI DiskSetCacheInformation (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PDISK_CACHE_INFORMATION CacheInfo)
 
NTSTATUS NTAPI DiskGetInfoExceptionInformation (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PMODE_INFO_EXCEPTIONS ReturnPageData)
 
NTSTATUS NTAPI DiskSetInfoExceptionInformation (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PMODE_INFO_EXCEPTIONS PageData)
 
NTSTATUS NTAPI DiskIoctlCreateDisk (IN OUT PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlGetDriveLayout (IN OUT PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlGetDriveLayoutEx (IN OUT PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlSetDriveLayout (IN OUT PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlSetDriveLayoutEx (IN OUT PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlGetPartitionInfo (IN OUT PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlGetPartitionInfoEx (IN OUT PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlGetLengthInfo (IN OUT PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlSetPartitionInfo (IN OUT PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlSetPartitionInfoEx (IN OUT PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS NTAPI DiskIoctlGetDriveGeometryEx (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 

Variables

ULONG DiskDisableGpt
 
const GUID GUID_NULL = { 0 }
 

Macro Definition Documentation

◆ DiskCompareGuid

#define DiskCompareGuid (   _First,
  _Second 
)    (memcmp ((_First),(_Second), sizeof (GUID)))

Definition at line 186 of file disk.c.

◆ SendToFdo

#define SendToFdo (   Dev,
  Irp,
  Rval 
)
Value:
{ \
PCOMMON_DEVICE_EXTENSION ce = Dev->DeviceExtension; \
ASSERT_PDO(Dev); \
IoCopyCurrentIrpStackLocationToNext(Irp); \
Rval = IoCallDriver(ce->LowerDeviceObject, Irp); \
}
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218

Typedef Documentation

◆ DISK_GEOMETRY_EX_INTERNAL

◆ PDISK_GEOMETRY_EX_INTERNAL

Function Documentation

◆ DisableWriteCache()

VOID NTAPI DisableWriteCache ( IN PDEVICE_OBJECT  Fdo,
IN PIO_WORKITEM  WorkItem 
)

Definition at line 3616 of file disk.c.

3621 {
3622  ULONG specialFlags = 0;
3623  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension;
3624  DISK_CACHE_INFORMATION cacheInfo;
3625  NTSTATUS status;
3626 
3627  PAGED_CODE();
3628 
3629  fdoExtension = Fdo->DeviceExtension;
3630 
3631  ASSERT(fdoExtension->CommonExtension.IsFdo);
3632 
3633  DebugPrint((1, "Disk.DisableWriteCache: Disabling Write Cache\n"));
3634 
3635  ClassGetDeviceParameter(fdoExtension,
3638  &specialFlags);
3639 
3640  RtlZeroMemory(&cacheInfo, sizeof(DISK_CACHE_INFORMATION));
3641 
3642  status = DiskGetCacheInformation(fdoExtension, &cacheInfo);
3643 
3644  if (NT_SUCCESS(status) && (cacheInfo.WriteCacheEnabled != FALSE)) {
3645 
3646  cacheInfo.WriteCacheEnabled = FALSE;
3647 
3648  status = DiskSetCacheInformation(fdoExtension, &cacheInfo);
3649 
3651  {
3652  //
3653  // This device does not allow for
3654  // the write cache to be disabled
3655  //
3657 
3659  }
3660 
3661  //
3662  // ISSUE ( April 5, 2001 ) : This should happen inside of DiskSetCacheInformation
3663  //
3664  CLEAR_FLAG(fdoExtension->DeviceFlags, DEV_WRITE_CACHE);
3665  }
3666 
3667  //
3668  // Set a flag in the registry to help
3669  // identify this device across boots
3670  //
3671  SET_FLAG(specialFlags, HackDisableWriteCache);
3672 
3674 
3675  ClassSetDeviceParameter(fdoExtension,
3678  specialFlags);
3679 
3680  IoFreeWorkItem(WorkItem);
3681 }
#define HackDisableWriteCache
Definition: disk.h:311
LONG NTSTATUS
Definition: precomp.h:26
COMMON_DEVICE_EXTENSION CommonExtension
Definition: classpnp.h:695
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define CLASS_SPECIAL_DISABLE_WRITE_CACHE_NOT_SUPPORTED
Definition: classpnp.h:168
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
#define PAGED_CODE()
Definition: video.h:57
#define DEV_WRITE_CACHE
Definition: class2.h:21
VOID NTAPI ClassGetDeviceParameter(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PWSTR SubkeyName OPTIONAL, IN PWSTR ParameterName, IN OUT PULONG ParameterValue)
Definition: utils.c:52
#define DiskDeviceParameterSubkey
Definition: disk.h:317
#define CLASS_SPECIAL_DISABLE_WRITE_CACHE
Definition: classpnp.h:165
#define DiskDeviceSpecialFlags
Definition: disk.h:318
#define CLEAR_FLAG(Flags, Bit)
Definition: classpnp.h:155
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI ClassSetDeviceParameter(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PWSTR SubkeyName OPTIONAL, IN PWSTR ParameterName, IN ULONG ParameterValue)
Definition: utils.c:136
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSTATUS NTAPI DiskGetCacheInformation(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PDISK_CACHE_INFORMATION CacheInfo)
Definition: disk.c:4314
#define HackDisableWriteCacheNotSupported
Definition: disk.h:314
#define SET_FLAG(Flags, Bit)
Definition: classpnp.h:154
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
NTSTATUS NTAPI DiskSetCacheInformation(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PDISK_CACHE_INFORMATION CacheInfo)
Definition: disk.c:4432
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ DiskCreateFdo()

NTSTATUS NTAPI DiskCreateFdo ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  PhysicalDeviceObject,
IN PULONG  DeviceCount,
IN BOOLEAN  DasdAccessOnly 
)

Definition at line 375 of file disk.c.

408 {
409  CCHAR ntNameBuffer[MAXIMUM_FILENAME_LENGTH];
410  //STRING ntNameString;
411  //UNICODE_STRING ntUnicodeString;
412 
413  PUCHAR deviceName = NULL;
414 
415  OBJECT_ATTRIBUTES objectAttributes;
416  HANDLE handle;
417 
419 
420  PDEVICE_OBJECT lowerDevice = NULL;
421  PDEVICE_OBJECT deviceObject = NULL;
422 
423  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension;
424  //STORAGE_PROPERTY_ID propertyId;
425  //PSTORAGE_DEVICE_DESCRIPTOR deviceDescriptor;
426 
427  PAGED_CODE();
428 
429  *DeviceCount = 0;
430 
431  //
432  // Set up an object directory to contain the objects for this
433  // device and all its partitions.
434  //
435 
436  do {
437 
438  WCHAR buffer[64];
439  UNICODE_STRING unicodeDirectoryName;
440 
441  swprintf(buffer, L"\\Device\\Harddisk%d", *DeviceCount);
442 
443  RtlInitUnicodeString(&unicodeDirectoryName, buffer);
444 
445  InitializeObjectAttributes(&objectAttributes,
446  &unicodeDirectoryName,
448  NULL,
449  NULL);
450 
453  &objectAttributes);
454 
455  (*DeviceCount)++;
456 
457  } while((status == STATUS_OBJECT_NAME_COLLISION) ||
459 
460  if (!NT_SUCCESS(status)) {
461 
462  DebugPrint((1, "DiskCreateFdo: Could not create directory - %lx\n",
463  status));
464 
465  return(status);
466  }
467 
468  //
469  // When this loop exits the count is inflated by one - fix that.
470  //
471 
472  (*DeviceCount)--;
473 
474  //
475  // Claim the device.
476  //
477 
479 
480  status = ClassClaimDevice(lowerDevice, FALSE);
481 
482  if (!NT_SUCCESS(status)) {
484  ZwClose(handle);
485  ObDereferenceObject(lowerDevice);
486  return status;
487  }
488 
489  //
490  // Create a device object for this device. Each physical disk will
491  // have at least one device object. The required device object
492  // describes the entire device. Its directory path is
493  // \Device\HarddiskN\Partition0, where N = device number.
494  //
495 
497  *DeviceCount,
498  0,
499  NULL,
500  NULL,
501  &deviceName);
502 
503  if(!NT_SUCCESS(status)) {
504  DebugPrint((1, "DiskCreateFdo - couldn't create name %lx\n",
505  status));
506 
507  goto DiskCreateFdoExit;
508 
509  }
510 
512  deviceName,
514  TRUE,
515  &deviceObject);
516 
517  if (!NT_SUCCESS(status)) {
518 
519  DebugPrint((1,
520  "DiskCreateFdo: Can not create device object %s\n",
521  ntNameBuffer));
522 
523  goto DiskCreateFdoExit;
524  }
525 
526  //
527  // Indicate that IRPs should include MDLs for data transfers.
528  //
529 
530  SET_FLAG(deviceObject->Flags, DO_DIRECT_IO);
531 
532  fdoExtension = deviceObject->DeviceExtension;
533 
534  if(DasdAccessOnly) {
535 
536  //
537  // Indicate that only RAW should be allowed to mount on the root
538  // partition object. This ensures that a file system can't doubly
539  // mount on a super-floppy by mounting once on P0 and once on P1.
540  //
541 
542  SET_FLAG(deviceObject->Vpb->Flags, VPB_RAW_MOUNT);
543  }
544 
545  //
546  // Initialize lock count to zero. The lock count is used to
547  // disable the ejection mechanism on devices that support
548  // removable media. Only the lock count in the physical
549  // device extension is used.
550  //
551 
552  fdoExtension->LockCount = 0;
553 
554  //
555  // Save system disk number.
556  //
557 
558  fdoExtension->DeviceNumber = *DeviceCount;
559 
560  //
561  // Set the alignment requirements for the device based on the
562  // host adapter requirements
563  //
564 
565  if (lowerDevice->AlignmentRequirement > deviceObject->AlignmentRequirement) {
566  deviceObject->AlignmentRequirement = lowerDevice->AlignmentRequirement;
567  }
568 
569  //
570  // Finally, attach to the pdo
571  //
572 
573  fdoExtension->LowerPdo = PhysicalDeviceObject;
574 
575  fdoExtension->CommonExtension.LowerDeviceObject =
577  deviceObject,
579 
580  if(fdoExtension->CommonExtension.LowerDeviceObject == NULL) {
581 
582  //
583  // Uh - oh, we couldn't attach
584  // cleanup and return
585  //
586 
588  goto DiskCreateFdoExit;
589  }
590 
591  {
592  PDISK_DATA diskData = fdoExtension->CommonExtension.DriverData;
593 
594  //
595  // Initialize the partitioning lock as it may be used in the remove
596  // code.
597  //
598 
601  TRUE);
602  }
603 
604 
605  //
606  // Clear the init flag.
607  //
608 
609  CLEAR_FLAG(deviceObject->Flags, DO_DEVICE_INITIALIZING);
610 
611  //
612  // Store a handle to the device object directory for this disk
613  //
614 
615  fdoExtension->DeviceDirectory = handle;
616 
617  ObDereferenceObject(lowerDevice);
618 
619  return STATUS_SUCCESS;
620 
621 DiskCreateFdoExit:
622 
623  //
624  // Release the device since an error occurred.
625  //
626 
627  if (deviceObject != NULL) {
628  IoDeleteDevice(deviceObject);
629  }
630 
631  //
632  // Delete directory and return.
633  //
634 
635  if (!NT_SUCCESS(status)) {
637  ZwClose(handle);
638  }
639 
640  ObDereferenceObject(lowerDevice);
641 
642  return(status);
643 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
unsigned char * PUCHAR
Definition: retypes.h:3
#define STATUS_OBJECT_NAME_EXISTS
Definition: ntstatus.h:114
LONG NTSTATUS
Definition: precomp.h:26
COMMON_DEVICE_EXTENSION CommonExtension
Definition: classpnp.h:695
#define OBJ_PERMANENT
Definition: winternl.h:226
GLuint buffer
Definition: glext.h:5915
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1122
#define MAXIMUM_FILENAME_LENGTH
Definition: env_spec_w32.h:41
#define PAGED_CODE()
Definition: video.h:57
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
ULONG DeviceCount
Definition: mpu401.c:26
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
#define CLEAR_FLAG(Flags, Bit)
Definition: classpnp.h:155
NTSYSAPI NTSTATUS NTAPI ZwCreateDirectoryObject(_Out_ PHANDLE DirectoryHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI ClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject, IN PCCHAR ObjectNameBuffer, IN PDEVICE_OBJECT LowerDevice, IN BOOLEAN IsFdo, IN OUT PDEVICE_OBJECT *DeviceObject)
Definition: class.c:5687
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
NTSTATUS NTAPI DiskGenerateDeviceName(IN BOOLEAN IsFdo, IN ULONG DeviceNumber, IN OPTIONAL ULONG PartitionNumber, IN OPTIONAL PLARGE_INTEGER StartingOffset, IN OPTIONAL PLARGE_INTEGER PartitionLength, OUT PUCHAR *RawName)
Definition: pnp.c:783
KEVENT PartitioningEvent
Definition: disk.h:242
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
char CCHAR
Definition: typedefs.h:50
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static const WCHAR L[]
Definition: oid.c:1250
PDEVICE_OBJECT LowerPdo
Definition: classpnp.h:697
ULONG AlignmentRequirement
Definition: env_spec_w32.h:420
#define SET_FLAG(Flags, Bit)
Definition: classpnp.h:154
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
NTSTATUS NTAPI ClassClaimDevice(IN PDEVICE_OBJECT LowerDeviceObject, IN BOOLEAN Release)
Definition: class.c:5985
#define VPB_RAW_MOUNT
Definition: iotypes.h:1768
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
NTSYSAPI NTSTATUS NTAPI ZwMakeTemporaryObject(_In_ HANDLE Handle)
Definition: ps.c:97

Referenced by DiskAddDevice().

◆ DiskDetermineMediaTypes()

NTSTATUS NTAPI DiskDetermineMediaTypes ( IN PDEVICE_OBJECT  Fdo,
IN PIRP  Irp,
IN UCHAR  MediumType,
IN UCHAR  DensityCode,
IN BOOLEAN  MediaPresent,
IN BOOLEAN  IsWritable 
)

Definition at line 761 of file disk.c.

791 {
792  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = Fdo->DeviceExtension;
793  //PPHYSICAL_DEVICE_EXTENSION pdoExtension = Fdo->DeviceExtension;
794  //PCOMMON_DEVICE_EXTENSION commonExtension = Fdo->DeviceExtension;
796 
797  PGET_MEDIA_TYPES mediaTypes = Irp->AssociatedIrp.SystemBuffer;
798  PDEVICE_MEDIA_INFO mediaInfo = &mediaTypes->MediaInfo[0];
799  BOOLEAN deviceMatched = FALSE;
800 
801  PAGED_CODE();
802 
803  //
804  // this should be checked prior to calling into this routine
805  // as we use the buffer as mediaTypes
806  //
807  ASSERT(irpStack->Parameters.DeviceIoControl.OutputBufferLength >=
808  sizeof(GET_MEDIA_TYPES));
809 
810 
811  //
812  // Determine if this device is removable or fixed.
813  //
814 
815  if (!TEST_FLAG(Fdo->Characteristics, FILE_REMOVABLE_MEDIA)) {
816 
817  //
818  // Fixed disk.
819  //
820 
821  mediaTypes->DeviceType = FILE_DEVICE_DISK;
822  mediaTypes->MediaInfoCount = 1;
823 
824  mediaInfo->DeviceSpecific.DiskInfo.Cylinders.QuadPart = fdoExtension->DiskGeometry.Cylinders.QuadPart;
825  mediaInfo->DeviceSpecific.DiskInfo.TracksPerCylinder = fdoExtension->DiskGeometry.TracksPerCylinder;
826  mediaInfo->DeviceSpecific.DiskInfo.SectorsPerTrack = fdoExtension->DiskGeometry.SectorsPerTrack;
827  mediaInfo->DeviceSpecific.DiskInfo.BytesPerSector = fdoExtension->DiskGeometry.BytesPerSector;
828  mediaInfo->DeviceSpecific.RemovableDiskInfo.NumberMediaSides = 1;
829 
830  mediaInfo->DeviceSpecific.DiskInfo.MediaCharacteristics = (MEDIA_CURRENTLY_MOUNTED | MEDIA_READ_WRITE);
831 
832  if (!IsWritable) {
833  SET_FLAG(mediaInfo->DeviceSpecific.DiskInfo.MediaCharacteristics,
835  }
836 
837  mediaInfo->DeviceSpecific.DiskInfo.MediaType = FixedMedia;
838 
839 
840  } else {
841 
842  PUCHAR vendorId = (PUCHAR) fdoExtension->DeviceDescriptor + fdoExtension->DeviceDescriptor->VendorIdOffset;
843  PUCHAR productId = (PUCHAR) fdoExtension->DeviceDescriptor + fdoExtension->DeviceDescriptor->ProductIdOffset;
844  PUCHAR productRevision = (PUCHAR) fdoExtension->DeviceDescriptor + fdoExtension->DeviceDescriptor->ProductRevisionOffset;
845  DISK_MEDIA_TYPES_LIST const *mediaListEntry;
846  ULONG currentMedia;
847  ULONG i;
848  ULONG j;
849  ULONG sizeNeeded;
850 
851  DebugPrint((1,
852  "DiskDetermineMediaTypes: Vendor %s, Product %s\n",
853  vendorId,
854  productId));
855 
856  //
857  // Run through the list until we find the entry with a NULL Vendor Id.
858  //
859 
860  for (i = 0; DiskMediaTypes[i].VendorId != NULL; i++) {
861 
862  mediaListEntry = &DiskMediaTypes[i];
863 
864  if (strncmp(mediaListEntry->VendorId,vendorId,strlen(mediaListEntry->VendorId))) {
865  continue;
866  }
867 
868  if ((mediaListEntry->ProductId != NULL) &&
869  strncmp(mediaListEntry->ProductId, productId, strlen(mediaListEntry->ProductId))) {
870  continue;
871  }
872 
873  if ((mediaListEntry->Revision != NULL) &&
874  strncmp(mediaListEntry->Revision, productRevision, strlen(mediaListEntry->Revision))) {
875  continue;
876  }
877 
878  deviceMatched = TRUE;
879 
880  mediaTypes->DeviceType = FILE_DEVICE_DISK;
881  mediaTypes->MediaInfoCount = mediaListEntry->NumberOfTypes;
882 
883  //
884  // Ensure that buffer is large enough.
885  //
886 
887  sizeNeeded = FIELD_OFFSET(GET_MEDIA_TYPES, MediaInfo[0]) +
888  (mediaListEntry->NumberOfTypes *
889  sizeof(DEVICE_MEDIA_INFO)
890  );
891 
892  if (irpStack->Parameters.DeviceIoControl.OutputBufferLength <
893  sizeNeeded) {
894 
895  //
896  // Buffer too small
897  //
898 
899  Irp->IoStatus.Information = sizeNeeded;
900  Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
902  }
903 
904  for (j = 0; j < mediaListEntry->NumberOfTypes; j++) {
905 
906  mediaInfo->DeviceSpecific.RemovableDiskInfo.Cylinders.QuadPart = fdoExtension->DiskGeometry.Cylinders.QuadPart;
907  mediaInfo->DeviceSpecific.RemovableDiskInfo.TracksPerCylinder = fdoExtension->DiskGeometry.TracksPerCylinder;
908  mediaInfo->DeviceSpecific.RemovableDiskInfo.SectorsPerTrack = fdoExtension->DiskGeometry.SectorsPerTrack;
909  mediaInfo->DeviceSpecific.RemovableDiskInfo.BytesPerSector = fdoExtension->DiskGeometry.BytesPerSector;
910  mediaInfo->DeviceSpecific.RemovableDiskInfo.NumberMediaSides = mediaListEntry->NumberOfSides;
911 
912  //
913  // Set the type.
914  //
915 
916  mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaType = mediaListEntry->MediaTypes[j];
917 
918  if (mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaType == MO_5_WO) {
919  mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics = MEDIA_WRITE_ONCE;
920  } else {
921  mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics = MEDIA_READ_WRITE;
922  }
923 
924  //
925  // Status will either be success, if media is present, or no media.
926  // It would be optimal to base from density code and medium type, but not all devices
927  // have values for these fields.
928  //
929 
930  if (MediaPresent) {
931 
932  //
933  // The usage of MediumType and DensityCode is device specific, so this may need
934  // to be extended to further key off of product/vendor ids.
935  // Currently, the MO units are the only devices that return this information.
936  //
937 
938  if (MediumType == 2) {
939  currentMedia = MO_5_WO;
940  } else if (MediumType == 3) {
941  currentMedia = MO_5_RW;
942 
943  if (DensityCode == 0x87) {
944 
945  //
946  // Indicate that the pinnacle 4.6 G media
947  // is present. Other density codes will default to normal
948  // RW MO media.
949  //
950 
951  currentMedia = PINNACLE_APEX_5_RW;
952  }
953  } else {
954  currentMedia = 0;
955  }
956 
957  if (currentMedia) {
958  if (mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaType == (STORAGE_MEDIA_TYPE)currentMedia) {
959  SET_FLAG(mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics, MEDIA_CURRENTLY_MOUNTED);
960  }
961 
962  } else {
963  SET_FLAG(mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics, MEDIA_CURRENTLY_MOUNTED);
964  }
965  }
966 
967  if (!IsWritable) {
968  SET_FLAG(mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics, MEDIA_WRITE_PROTECTED);
969  }
970 
971  //
972  // Advance to next entry.
973  //
974 
975  mediaInfo++;
976  }
977  }
978 
979  if (!deviceMatched) {
980 
981  DebugPrint((1,
982  "DiskDetermineMediaTypes: Unknown device. Vendor: %s Product: %s Revision: %s\n",
983  vendorId,
984  productId,
985  productRevision));
986  //
987  // Build an entry for unknown.
988  //
989 
990  mediaInfo->DeviceSpecific.RemovableDiskInfo.Cylinders.QuadPart = fdoExtension->DiskGeometry.Cylinders.QuadPart;
991  mediaInfo->DeviceSpecific.RemovableDiskInfo.TracksPerCylinder = fdoExtension->DiskGeometry.TracksPerCylinder;
992  mediaInfo->DeviceSpecific.RemovableDiskInfo.SectorsPerTrack = fdoExtension->DiskGeometry.SectorsPerTrack;
993  mediaInfo->DeviceSpecific.RemovableDiskInfo.BytesPerSector = fdoExtension->DiskGeometry.BytesPerSector;
994 
995  //
996  // Set the type.
997  //
998 
999  mediaTypes->DeviceType = FILE_DEVICE_DISK;
1000  mediaTypes->MediaInfoCount = 1;
1001 
1002  mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaType = RemovableMedia;
1003  mediaInfo->DeviceSpecific.RemovableDiskInfo.NumberMediaSides = 1;
1004 
1005  mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics = MEDIA_READ_WRITE;
1006  if (MediaPresent) {
1007  SET_FLAG(mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics, MEDIA_CURRENTLY_MOUNTED);
1008  }
1009 
1010  if (!IsWritable) {
1011  SET_FLAG(mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics, MEDIA_WRITE_PROTECTED);
1012  }
1013  }
1014  }
1015 
1016  Irp->IoStatus.Information =
1017  FIELD_OFFSET(GET_MEDIA_TYPES, MediaInfo[0]) +
1018  (mediaTypes->MediaInfoCount * sizeof(DEVICE_MEDIA_INFO));
1019 
1020  return STATUS_SUCCESS;
1021 
1022 }
#define FILE_DEVICE_DISK
Definition: winioctl.h:112
#define TRUE
Definition: types.h:120
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define TEST_FLAG(Flags, Bit)
Definition: classpnp.h:156
DISK_GEOMETRY DiskGeometry
Definition: classpnp.h:704
_In_ PIRP Irp
Definition: csq.h:116
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG BytesPerSector
Definition: ntdddisk.h:381
ULONG TracksPerCylinder
Definition: ntdddisk.h:379
#define MEDIA_WRITE_PROTECTED
Definition: minitape.h:35
#define PAGED_CODE()
Definition: video.h:57
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
enum _STORAGE_MEDIA_TYPE STORAGE_MEDIA_TYPE
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define MEDIA_WRITE_ONCE
Definition: minitape.h:32
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
struct _DEVICE_MEDIA_INFO::@3059::@3060 DiskInfo
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:377
ULONG SectorsPerTrack
Definition: ntdddisk.h:380
PSTORAGE_DEVICE_DESCRIPTOR DeviceDescriptor
Definition: classpnp.h:698
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define MEDIA_READ_WRITE
Definition: minitape.h:34
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
union _DEVICE_MEDIA_INFO::@3059 DeviceSpecific
ULONG DeviceType
Definition: ntddstor.h:402
DISK_MEDIA_TYPES_LIST const DiskMediaTypes[]
Definition: data.c:68
ULONG MediaInfoCount
Definition: ntddstor.h:403
#define SET_FLAG(Flags, Bit)
Definition: classpnp.h:154
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define MEDIA_CURRENTLY_MOUNTED
Definition: minitape.h:36
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
_Must_inspect_result_ _Out_ PBOOLEAN IsWritable
Definition: fltkernel.h:1744
struct _DEVICE_MEDIA_INFO::@3059::@3061 RemovableDiskInfo
struct _DEVICE_MEDIA_INFO DEVICE_MEDIA_INFO
unsigned int ULONG
Definition: retypes.h:1
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
LONGLONG QuadPart
Definition: typedefs.h:112
DEVICE_MEDIA_INFO MediaInfo[1]
Definition: ntddstor.h:404

Referenced by DiskDeviceControl().

◆ DiskDeviceControl()

NTSTATUS NTAPI DiskDeviceControl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 1026 of file disk.c.

1048  { \
1049  PCOMMON_DEVICE_EXTENSION ce = Dev->DeviceExtension; \
1050  ASSERT_PDO(Dev); \
1051  IoCopyCurrentIrpStackLocationToNext(Irp); \
1052  Rval = IoCallDriver(ce->LowerDeviceObject, Irp); \
1053  }
1054 
1055 {
1057  //PPHYSICAL_DEVICE_EXTENSION pdoExtension = DeviceObject->DeviceExtension;
1059 
1061  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
1062  PSCSI_REQUEST_BLOCK srb;
1063  PCDB cdb;
1064  PMODE_PARAMETER_HEADER modeData;
1065  PIRP irp2;
1066  ULONG length;
1067  NTSTATUS status;
1068  KEVENT event;
1069  IO_STATUS_BLOCK ioStatus;
1070 
1071  BOOLEAN b = FALSE;
1072 
1075  DISK_TAG_SRB);
1076  Irp->IoStatus.Information = 0;
1077 
1078  if (srb == NULL) {
1079 
1080  Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
1084  }
1085 
1086  //
1087  // Write zeros to Srb.
1088  //
1089 
1091 
1092  cdb = (PCDB)srb->Cdb;
1093 
1094  switch (irpStack->Parameters.DeviceIoControl.IoControlCode) {
1095 
1097  b = TRUE;
1099 
1100  BOOLEAN getCaching = b;
1101  PDISK_CACHE_INFORMATION cacheInfo = Irp->AssociatedIrp.SystemBuffer;
1102 
1103  if(!commonExtension->IsFdo) {
1104 
1106  ExFreePool(srb);
1108  return status;
1109  }
1110 
1111  //
1112  // Validate the request.
1113  //
1114 
1115  if((getCaching) &&
1116  (irpStack->Parameters.DeviceIoControl.OutputBufferLength <
1117  sizeof(DISK_CACHE_INFORMATION))
1118  ) {
1120  Irp->IoStatus.Information = sizeof(DISK_CACHE_INFORMATION);
1121  break;
1122  }
1123 
1124  if ((!getCaching) &&
1125  (irpStack->Parameters.DeviceIoControl.InputBufferLength <
1126  sizeof(DISK_CACHE_INFORMATION))
1127  ) {
1128 
1130  break;
1131  }
1132 
1133  ASSERT(Irp->AssociatedIrp.SystemBuffer != NULL);
1134 
1135  if (getCaching) {
1136 
1137  status = DiskGetCacheInformation(fdoExtension, cacheInfo);
1138 
1139  if (NT_SUCCESS(status)) {
1140  Irp->IoStatus.Information = sizeof(DISK_CACHE_INFORMATION);
1141  }
1142 
1143  } else {
1144 
1145  if (!cacheInfo->WriteCacheEnabled)
1146  {
1147  if (TEST_FLAG(fdoExtension->ScanForSpecialFlags,
1149  {
1150  //
1151  // This request wants to disable write cache, which is
1152  // not supported on this device. Instead of sending it
1153  // down only to see it fail, return the error code now
1154  //
1156  break;
1157  }
1158  }
1159  else
1160  {
1161  if (TEST_FLAG(fdoExtension->ScanForSpecialFlags,
1163  {
1164  //
1165  // This request wants to enable write cache, which
1166  // has been disabled to protect data integrity. So
1167  // fail this request with access denied
1168  //
1170  break;
1171  }
1172  }
1173 
1174  status = DiskSetCacheInformation(fdoExtension, cacheInfo);
1175 
1176  if (NT_SUCCESS(status))
1177  {
1178  //
1179  // Store the user-defined override in the registry
1180  //
1181  ClassSetDeviceParameter(fdoExtension,
1185  }
1187  {
1188  if (cacheInfo->WriteCacheEnabled == FALSE)
1189  {
1190  //
1191  // This device does not allow for
1192  // the write cache to be disabled
1193  //
1194  ULONG specialFlags = 0;
1195 
1196  ClassGetDeviceParameter(fdoExtension,
1199  &specialFlags);
1200 
1202 
1203  SET_FLAG(fdoExtension->ScanForSpecialFlags,
1205 
1206  ClassSetDeviceParameter(fdoExtension,
1209  specialFlags);
1210  }
1211  }
1212  }
1213 
1214  break;
1215  }
1216 
1217 #if(_WIN32_WINNT >= 0x0500)
1218  case IOCTL_DISK_GET_WRITE_CACHE_STATE: {
1219 
1220  PDISK_WRITE_CACHE_STATE writeCacheState = (PDISK_WRITE_CACHE_STATE)Irp->AssociatedIrp.SystemBuffer;
1221 
1222  if(!commonExtension->IsFdo) {
1223 
1225  ExFreePool(srb);
1227  return status;
1228  }
1229 
1230  //
1231  // Validate the request.
1232  //
1233 
1234  if(irpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(DISK_WRITE_CACHE_STATE)) {
1235 
1237  Irp->IoStatus.Information = sizeof(DISK_WRITE_CACHE_STATE);
1238  break;
1239  }
1240 
1241  *writeCacheState = DiskWriteCacheNormal;
1242 
1243  //
1244  // Determine whether it is possible to disable the write cache
1245  //
1246 
1248  {
1249  *writeCacheState = DiskWriteCacheDisableNotSupported;
1250  }
1251 
1252  //
1253  // Determine whether it is safe to toggle the write cache
1254  //
1255 
1257  {
1258  *writeCacheState = DiskWriteCacheForceDisable;
1259  }
1260 
1261  Irp->IoStatus.Information = sizeof(DISK_WRITE_CACHE_STATE);
1263  break;
1264  }
1265 #endif
1266 
1267  case SMART_GET_VERSION: {
1268 
1269  PUCHAR buffer;
1270  PSRB_IO_CONTROL srbControl;
1271  PGETVERSIONINPARAMS versionParams;
1272 
1273  if(!commonExtension->IsFdo) {
1275  ExFreePool(srb);
1277  return status;
1278  }
1279 
1280  if (irpStack->Parameters.DeviceIoControl.OutputBufferLength <
1281  sizeof(GETVERSIONINPARAMS)) {
1283  Irp->IoStatus.Information = sizeof(GETVERSIONINPARAMS);
1284  break;
1285  }
1286 
1287  //
1288  // Create notification event object to be used to signal the
1289  // request completion.
1290  //
1291 
1293 
1294  srbControl = ExAllocatePoolWithTag(NonPagedPool,
1295  sizeof(SRB_IO_CONTROL) +
1296  sizeof(GETVERSIONINPARAMS),
1297  DISK_TAG_SMART);
1298 
1299  if (!srbControl) {
1301  break;
1302  }
1303 
1304  RtlZeroMemory(srbControl,
1305  sizeof(SRB_IO_CONTROL) + sizeof(GETVERSIONINPARAMS)
1306  );
1307 
1308  //
1309  // fill in srbControl fields
1310  //
1311 
1312  srbControl->HeaderLength = sizeof(SRB_IO_CONTROL);
1313  RtlMoveMemory (srbControl->Signature, "SCSIDISK", 8);
1314  srbControl->Timeout = fdoExtension->TimeOutValue;
1315  srbControl->Length = sizeof(GETVERSIONINPARAMS);
1317 
1318  //
1319  // Point to the 'buffer' portion of the SRB_CONTROL
1320  //
1321 
1322  buffer = (PUCHAR)srbControl;
1323  buffer += srbControl->HeaderLength;
1324 
1325  //
1326  // Ensure correct target is set in the cmd parameters.
1327  //
1328 
1329  versionParams = (PGETVERSIONINPARAMS)buffer;
1330  versionParams->bIDEDeviceMap = diskData->ScsiAddress.TargetId;
1331 
1332  //
1333  // Copy the IOCTL parameters to the srb control buffer area.
1334  //
1335 
1337  Irp->AssociatedIrp.SystemBuffer,
1338  sizeof(GETVERSIONINPARAMS));
1339 
1342  commonExtension->LowerDeviceObject,
1343  srbControl,
1344  sizeof(SRB_IO_CONTROL) + sizeof(GETVERSIONINPARAMS),
1345  sizeof(SRB_IO_CONTROL) + sizeof(GETVERSIONINPARAMS),
1346  FALSE,
1347  &ioStatus);
1348 
1349  status = ioStatus.Status;
1350 
1351  //
1352  // If successful, copy the data received into the output buffer.
1353  // This should only fail in the event that the IDE driver is older
1354  // than this driver.
1355  //
1356 
1357  if (NT_SUCCESS(status)) {
1358 
1359  buffer = (PUCHAR)srbControl;
1360  buffer += srbControl->HeaderLength;
1361 
1362  RtlMoveMemory (Irp->AssociatedIrp.SystemBuffer, buffer,
1363  sizeof(GETVERSIONINPARAMS));
1364  Irp->IoStatus.Information = sizeof(GETVERSIONINPARAMS);
1365  }
1366 
1367  ExFreePool(srbControl);
1368  break;
1369  }
1370 
1371  case SMART_RCV_DRIVE_DATA: {
1372 
1373  PSENDCMDINPARAMS cmdInParameters = ((PSENDCMDINPARAMS)Irp->AssociatedIrp.SystemBuffer);
1374  ULONG controlCode = 0;
1375  PSRB_IO_CONTROL srbControl;
1376  PUCHAR buffer;
1377 
1378  if(!commonExtension->IsFdo) {
1380  ExFreePool(srb);
1382  return status;
1383  }
1384 
1385  if (irpStack->Parameters.DeviceIoControl.InputBufferLength <
1386  (sizeof(SENDCMDINPARAMS) - 1)) {
1388  Irp->IoStatus.Information = 0;
1389  break;
1390 
1391  } else if (irpStack->Parameters.DeviceIoControl.OutputBufferLength <
1392  (sizeof(SENDCMDOUTPARAMS) + 512 - 1)) {
1394  Irp->IoStatus.Information = sizeof(SENDCMDOUTPARAMS) + 512 - 1;
1395  break;
1396  }
1397 
1398  //
1399  // Create notification event object to be used to signal the
1400  // request completion.
1401  //
1402 
1404 
1405  //
1406  // use controlCode as a sort of 'STATUS_SUCCESS' to see if it's
1407  // a valid request type
1408  //
1409 
1410  if (cmdInParameters->irDriveRegs.bCommandReg == ID_CMD) {
1411 
1413  controlCode = IOCTL_SCSI_MINIPORT_IDENTIFY;
1414 
1415  } else if (cmdInParameters->irDriveRegs.bCommandReg == SMART_CMD) {
1416  switch (cmdInParameters->irDriveRegs.bFeaturesReg) {
1417  case READ_ATTRIBUTES:
1420  break;
1421  case READ_THRESHOLDS:
1424  break;
1425  default:
1427  break;
1428  }
1429  } else {
1430 
1432  }
1433 
1434  if (controlCode == 0) {
1436  break;
1437  }
1438 
1439  srbControl = ExAllocatePoolWithTag(NonPagedPool,
1440  sizeof(SRB_IO_CONTROL) + length,
1441  DISK_TAG_SMART);
1442 
1443  if (!srbControl) {
1445  break;
1446  }
1447 
1448  //
1449  // fill in srbControl fields
1450  //
1451 
1452  srbControl->HeaderLength = sizeof(SRB_IO_CONTROL);
1453  RtlMoveMemory (srbControl->Signature, "SCSIDISK", 8);
1454  srbControl->Timeout = fdoExtension->TimeOutValue;
1455  srbControl->Length = length;
1456  srbControl->ControlCode = controlCode;
1457 
1458  //
1459  // Point to the 'buffer' portion of the SRB_CONTROL
1460  //
1461 
1462  buffer = (PUCHAR)srbControl;
1463  buffer += srbControl->HeaderLength;
1464 
1465  //
1466  // Ensure correct target is set in the cmd parameters.
1467  //
1468 
1469  cmdInParameters->bDriveNumber = diskData->ScsiAddress.TargetId;
1470 
1471  //
1472  // Copy the IOCTL parameters to the srb control buffer area.
1473  //
1474 
1476  Irp->AssociatedIrp.SystemBuffer,
1477  sizeof(SENDCMDINPARAMS) - 1);
1478 
1480  commonExtension->LowerDeviceObject,
1481  srbControl,
1482  sizeof(SRB_IO_CONTROL) + sizeof(SENDCMDINPARAMS) - 1,
1483  srbControl,
1484  sizeof(SRB_IO_CONTROL) + length,
1485  FALSE,
1486  &event,
1487  &ioStatus);
1488 
1489  if (irp2 == NULL) {
1491  ExFreePool(srbControl);
1492  break;
1493  }
1494 
1495  //
1496  // Call the port driver with the request and wait for it to complete.
1497  //
1498 
1499  status = IoCallDriver(commonExtension->LowerDeviceObject, irp2);
1500 
1501  if (status == STATUS_PENDING) {
1503  status = ioStatus.Status;
1504  }
1505 
1506  //
1507  // Copy the data received into the output buffer. Since the status buffer
1508  // contains error information also, always perform this copy. IO will will
1509  // either pass this back to the app, or zero it, in case of error.
1510  //
1511 
1512  buffer = (PUCHAR)srbControl;
1513  buffer += srbControl->HeaderLength;
1514 
1515  if (NT_SUCCESS(status)) {
1516 
1517  RtlMoveMemory ( Irp->AssociatedIrp.SystemBuffer, buffer, length - 1);
1518  Irp->IoStatus.Information = length - 1;
1519 
1520  } else {
1521 
1522  RtlMoveMemory ( Irp->AssociatedIrp.SystemBuffer, buffer, (sizeof(SENDCMDOUTPARAMS) - 1));
1523  Irp->IoStatus.Information = sizeof(SENDCMDOUTPARAMS) - 1;
1524 
1525  }
1526 
1527  ExFreePool(srbControl);
1528  break;
1529 
1530  }
1531 
1532  case SMART_SEND_DRIVE_COMMAND: {
1533 
1534  PSENDCMDINPARAMS cmdInParameters = ((PSENDCMDINPARAMS)Irp->AssociatedIrp.SystemBuffer);
1535  PSRB_IO_CONTROL srbControl;
1536  ULONG controlCode = 0;
1537  PUCHAR buffer;
1538 
1539  if(!commonExtension->IsFdo) {
1541  ExFreePool(srb);
1543  return status;
1544  }
1545 
1546  if (irpStack->Parameters.DeviceIoControl.InputBufferLength <
1547  (sizeof(SENDCMDINPARAMS) - 1)) {
1549  Irp->IoStatus.Information = 0;
1550  break;
1551 
1552  } else if (irpStack->Parameters.DeviceIoControl.OutputBufferLength <
1553  (sizeof(SENDCMDOUTPARAMS) - 1)) {
1555  Irp->IoStatus.Information = sizeof(SENDCMDOUTPARAMS) - 1;
1556  break;
1557  }
1558 
1559  //
1560  // Create notification event object to be used to signal the
1561  // request completion.
1562  //
1563 
1565 
1566  length = 0;
1567 
1568  if (cmdInParameters->irDriveRegs.bCommandReg == SMART_CMD) {
1569  switch (cmdInParameters->irDriveRegs.bFeaturesReg) {
1570 
1571  case ENABLE_SMART:
1572  controlCode = IOCTL_SCSI_MINIPORT_ENABLE_SMART;
1573  break;
1574 
1575  case DISABLE_SMART:
1576  controlCode = IOCTL_SCSI_MINIPORT_DISABLE_SMART;
1577  break;
1578 
1579  case RETURN_SMART_STATUS:
1580 
1581  //
1582  // Ensure bBuffer is at least 2 bytes (to hold the values of
1583  // cylinderLow and cylinderHigh).
1584  //
1585 
1586  if (irpStack->Parameters.DeviceIoControl.OutputBufferLength <
1587  (sizeof(SENDCMDOUTPARAMS) - 1 + sizeof(IDEREGS))) {
1588 
1590  Irp->IoStatus.Information =
1591  sizeof(SENDCMDOUTPARAMS) - 1 + sizeof(IDEREGS);
1592  break;
1593  }
1594 
1595  controlCode = IOCTL_SCSI_MINIPORT_RETURN_STATUS;
1596  length = sizeof(IDEREGS);
1597  break;
1598 
1601  break;
1602 
1603  case SAVE_ATTRIBUTE_VALUES:
1605  break;
1606 
1607  case EXECUTE_OFFLINE_DIAGS:
1608  //
1609  // Validate that this is an ok self test command
1610  //
1612  {
1614  }
1615  break;
1616 
1619  break;
1620 
1621  default:
1623  break;
1624  }
1625  } else {
1626 
1628  }
1629 
1630  if (controlCode == 0) {
1632  break;
1633  }
1634 
1635  length += (sizeof(SENDCMDOUTPARAMS) > sizeof(SENDCMDINPARAMS)) ? sizeof(SENDCMDOUTPARAMS) : sizeof(SENDCMDINPARAMS);
1636  srbControl = ExAllocatePoolWithTag(NonPagedPool,
1637  sizeof(SRB_IO_CONTROL) + length,
1638  DISK_TAG_SMART);
1639 
1640  if (!srbControl) {
1642  break;
1643  }
1644 
1645  //
1646  // fill in srbControl fields
1647  //
1648 
1649  srbControl->HeaderLength = sizeof(SRB_IO_CONTROL);
1650  RtlMoveMemory (srbControl->Signature, "SCSIDISK", 8);
1651  srbControl->Timeout = fdoExtension->TimeOutValue;
1652  srbControl->Length = length;
1653 
1654  //
1655  // Point to the 'buffer' portion of the SRB_CONTROL
1656  //
1657 
1658  buffer = (PUCHAR)srbControl;
1659  buffer += srbControl->HeaderLength;
1660 
1661  //
1662  // Ensure correct target is set in the cmd parameters.
1663  //
1664 
1665  cmdInParameters->bDriveNumber = diskData->ScsiAddress.TargetId;
1666 
1667  //
1668  // Copy the IOCTL parameters to the srb control buffer area.
1669  //
1670 
1671  RtlMoveMemory(buffer, Irp->AssociatedIrp.SystemBuffer, sizeof(SENDCMDINPARAMS) - 1);
1672 
1673  srbControl->ControlCode = controlCode;
1674 
1676  commonExtension->LowerDeviceObject,
1677  srbControl,
1678  sizeof(SRB_IO_CONTROL) + sizeof(SENDCMDINPARAMS) - 1,
1679  srbControl,
1680  sizeof(SRB_IO_CONTROL) + length,
1681  FALSE,
1682  &event,
1683  &ioStatus);
1684 
1685  if (irp2 == NULL) {
1687  ExFreePool(srbControl);
1688  break;
1689  }
1690 
1691  //
1692  // Call the port driver with the request and wait for it to complete.
1693  //
1694 
1695  status = IoCallDriver(commonExtension->LowerDeviceObject, irp2);
1696 
1697  if (status == STATUS_PENDING) {
1699  status = ioStatus.Status;
1700  }
1701 
1702  //
1703  // Copy the data received into the output buffer. Since the status buffer
1704  // contains error information also, always perform this copy. IO will will
1705  // either pass this back to the app, or zero it, in case of error.
1706  //
1707 
1708  buffer = (PUCHAR)srbControl;
1709  buffer += srbControl->HeaderLength;
1710 
1711  //
1712  // Update the return buffer size based on the sub-command.
1713  //
1714 
1715  if (cmdInParameters->irDriveRegs.bFeaturesReg == RETURN_SMART_STATUS) {
1716  length = sizeof(SENDCMDOUTPARAMS) - 1 + sizeof(IDEREGS);
1717  } else {
1718  length = sizeof(SENDCMDOUTPARAMS) - 1;
1719  }
1720 
1721  RtlMoveMemory ( Irp->AssociatedIrp.SystemBuffer, buffer, length);
1722  Irp->IoStatus.Information = length;
1723 
1724  ExFreePool(srbControl);
1725  break;
1726 
1727  }
1728 
1730 
1731  PMODE_PARAMETER_BLOCK blockDescriptor;
1732  ULONG modeLength;
1733  ULONG retries = 4;
1734  BOOLEAN writable = FALSE;
1735  BOOLEAN mediaPresent = FALSE;
1736 
1737  DebugPrint((3,
1738  "Disk.DiskDeviceControl: GetMediaTypes\n"));
1739 
1740  if (irpStack->Parameters.DeviceIoControl.OutputBufferLength <
1741  sizeof(GET_MEDIA_TYPES)) {
1743  Irp->IoStatus.Information = sizeof(GET_MEDIA_TYPES);
1744  break;
1745  }
1746 
1747  if(!commonExtension->IsFdo) {
1749  ExFreePool(srb);
1751  return status;
1752  }
1753 
1754  //
1755  // Send a TUR to determine if media is present.
1756  //
1757 
1758  srb->CdbLength = 6;
1759  cdb = (PCDB)srb->Cdb;
1760  cdb->CDB6GENERIC.OperationCode = SCSIOP_TEST_UNIT_READY;
1761 
1762  //
1763  // Set timeout value.
1764  //
1765 
1766  srb->TimeOutValue = fdoExtension->TimeOutValue;
1767 
1769  srb,
1770  NULL,
1771  0,
1772  FALSE);
1773 
1774 
1775  if (NT_SUCCESS(status)) {
1776  mediaPresent = TRUE;
1777  }
1778 
1780 
1781  //
1782  // Allocate memory for mode header and block descriptor.
1783  //
1784 
1785  modeLength = sizeof(MODE_PARAMETER_HEADER) + sizeof(MODE_PARAMETER_BLOCK);
1787  modeLength,
1789 
1790  if (modeData == NULL) {
1792  break;
1793  }
1794 
1795  RtlZeroMemory(modeData, modeLength);
1796 
1797  //
1798  // Build the MODE SENSE CDB.
1799  //
1800 
1801  srb->CdbLength = 6;
1802  cdb = (PCDB)srb->Cdb;
1803 
1804  //
1805  // Set timeout value from device extension.
1806  //
1807 
1808  srb->TimeOutValue = fdoExtension->TimeOutValue;
1809 
1810  //
1811  // Page code of 0 will return header and block descriptor only.
1812  //
1813 
1814  cdb->MODE_SENSE.OperationCode = SCSIOP_MODE_SENSE;
1815  cdb->MODE_SENSE.PageCode = 0;
1816  cdb->MODE_SENSE.AllocationLength = (UCHAR)modeLength;
1817 
1818 Retry:
1820  srb,
1821  modeData,
1822  modeLength,
1823  FALSE);
1824 
1825 
1826  if (status == STATUS_VERIFY_REQUIRED) {
1827 
1828  if (retries--) {
1829 
1830  //
1831  // Retry request.
1832  //
1833 
1834  goto Retry;
1835  }
1836  } else if (SRB_STATUS(srb->SrbStatus) == SRB_STATUS_DATA_OVERRUN) {
1838  }
1839 
1841 
1842  //
1843  // Get the block descriptor.
1844  //
1845 
1846  blockDescriptor = (PMODE_PARAMETER_BLOCK)modeData;
1847  blockDescriptor = (PMODE_PARAMETER_BLOCK)((ULONG_PTR)blockDescriptor + sizeof(MODE_PARAMETER_HEADER));
1848 
1849  //
1850  // Do some validation.
1851  //
1852 
1853  if (modeData->BlockDescriptorLength != sizeof(MODE_PARAMETER_BLOCK)) {
1854 
1855  DebugPrint((1,
1856  "DiskDeviceControl: BlockDescriptor length - "
1857  "Expected %x, actual %x\n",
1858  modeData->BlockDescriptorLength,
1859  sizeof(MODE_PARAMETER_BLOCK)));
1860  }
1861 
1862  DebugPrint((1,
1863  "DiskDeviceControl: DensityCode %x, MediumType %x\n",
1864  blockDescriptor->DensityCode,
1865  modeData->MediumType));
1866 
1867  if (TEST_FLAG(modeData->DeviceSpecificParameter,
1869  writable = FALSE;
1870  } else {
1871  writable = TRUE;
1872  }
1873 
1875  Irp,
1876  modeData->MediumType,
1877  blockDescriptor->DensityCode,
1878  mediaPresent,
1879  writable);
1880 
1881  //
1882  // If the buffer was too small, DetermineMediaTypes updated the status and information and the request will fail.
1883  //
1884 
1885  } else {
1886  DebugPrint((1,
1887  "DiskDeviceControl: Mode sense for header/bd failed. %lx\n",
1888  status));
1889  }
1890 
1891  ExFreePool(modeData);
1892  break;
1893  }
1894 
1896 
1897  DebugPrint((2, "IOCTL_DISK_GET_DRIVE_GEOMETRY to device %p through irp %p\n",
1898  DeviceObject, Irp));
1899  DebugPrint((2, "Device is a%s.\n",
1900  commonExtension->IsFdo ? "n fdo" : " pdo"));
1901 
1902  if (irpStack->Parameters.DeviceIoControl.OutputBufferLength <
1903  sizeof(DISK_GEOMETRY)) {
1904 
1906  Irp->IoStatus.Information = sizeof(DISK_GEOMETRY);
1907  break;
1908  }
1909 
1910  if(!commonExtension->IsFdo) {
1911 
1912  //
1913  // Pdo should issue this request to the lower device object
1914  //
1915 
1917  ExFreePool(srb);
1919  return status;
1920  }
1921 
1922  // DiskAcquirePartitioningLock(fdoExtension);
1923 
1924  if (TEST_FLAG(DeviceObject->Characteristics, FILE_REMOVABLE_MEDIA)) {
1925 
1926  //
1927  // Issue ReadCapacity to update device extension
1928  // with information for current media.
1929  //
1930 
1932  commonExtension->PartitionZeroExtension->DeviceObject);
1933 
1934  //
1935  // Note whether the drive is ready.
1936  //
1937 
1938  diskData->ReadyStatus = status;
1939 
1940  if (!NT_SUCCESS(status)) {
1941  // DiskReleasePartitioningLock(fdoExtension);
1942  break;
1943  }
1944  }
1945 
1946  //
1947  // Copy drive geometry information from device extension.
1948  //
1949 
1950  RtlMoveMemory(Irp->AssociatedIrp.SystemBuffer,
1951  &(fdoExtension->DiskGeometry),
1952  sizeof(DISK_GEOMETRY));
1953 
1955  Irp->IoStatus.Information = sizeof(DISK_GEOMETRY);
1956  // DiskReleasePartitioningLock(fdoExtension);
1957  break;
1958  }
1959 
1961  DebugPrint((1, "IOCTL_DISK_GET_DRIVE_GEOMETRY_EX to device %p through irp %p\n",
1962  DeviceObject, Irp));
1963  DebugPrint((1, "Device Is a%s.\n",
1964  commonExtension->IsFdo ? "n fdo" : " pdo"));
1965 
1966 
1967  if (!commonExtension->IsFdo) {
1968 
1969  //
1970  // Pdo should issue this request to the lower device object
1971  //
1972 
1974  ExFreePool (srb);
1976  return status;
1977 
1978  } else {
1979 
1981  }
1982 
1983  break;
1984  }
1985 
1987 
1988  PSTORAGE_PREDICT_FAILURE checkFailure;
1989  STORAGE_FAILURE_PREDICT_STATUS diskSmartStatus;
1990 
1991  DebugPrint((2, "IOCTL_STORAGE_PREDICT_FAILURE to device %p through irp %p\n",
1992  DeviceObject, Irp));
1993  DebugPrint((2, "Device is a%s.\n",
1994  commonExtension->IsFdo ? "n fdo" : " pdo"));
1995 
1996  checkFailure = (PSTORAGE_PREDICT_FAILURE)Irp->AssociatedIrp.SystemBuffer;
1997 
1998  if (irpStack->Parameters.DeviceIoControl.OutputBufferLength <
1999  sizeof(STORAGE_PREDICT_FAILURE)) {
2000 
2002  Irp->IoStatus.Information = sizeof(STORAGE_PREDICT_FAILURE);
2003  break;
2004  }
2005 
2006  if(!commonExtension->IsFdo) {
2007 
2008  //
2009  // Pdo should issue this request to the lower device object
2010  //
2011 
2013  ExFreePool(srb);
2015  return status;
2016  }
2017 
2018  //
2019  // See if the disk is predicting failure
2020  //
2021 
2023  ULONG readBufferSize;
2024  PUCHAR readBuffer;
2025  PIRP readIrp;
2026  IO_STATUS_BLOCK ioStatus;
2027  PDEVICE_OBJECT topOfStack;
2028 
2029  checkFailure->PredictFailure = 0;
2030 
2032 
2034 
2035  //
2036  // SCSI disks need to have a read sent down to provoke any
2037  // failures to be reported.
2038  //
2039  // Issue a normal read operation. The error-handling code in
2040  // classpnp will take care of a failure prediction by logging the
2041  // correct event.
2042  //
2043 
2044  readBufferSize = fdoExtension->DiskGeometry.BytesPerSector;
2045  readBuffer = ExAllocatePoolWithTag(NonPagedPool,
2046  readBufferSize,
2047  DISK_TAG_SMART);
2048 
2049  if (readBuffer != NULL) {
2051 
2052  offset.QuadPart = 0;
2053  readIrp = IoBuildSynchronousFsdRequest(
2054  IRP_MJ_READ,
2055  topOfStack,
2056  readBuffer,
2057  readBufferSize,
2058  &offset,
2059  &event,
2060  &ioStatus);
2061 
2062 
2063  if (readIrp != NULL) {
2064  status = IoCallDriver(topOfStack, readIrp);
2065  if (status == STATUS_PENDING) {
2067  status = ioStatus.Status;
2068  }
2069  }
2070 
2071  ExFreePool(readBuffer);
2072  }
2073  ObDereferenceObject(topOfStack);
2074  }
2075 
2078  {
2079  status = DiskReadFailurePredictStatus(fdoExtension,
2080  &diskSmartStatus);
2081 
2082  if (NT_SUCCESS(status))
2083  {
2084  status = DiskReadFailurePredictData(fdoExtension,
2085  Irp->AssociatedIrp.SystemBuffer);
2086 
2087  if (diskSmartStatus.PredictFailure)
2088  {
2089  checkFailure->PredictFailure = 1;
2090  } else {
2091  checkFailure->PredictFailure = 0;
2092  }
2093 
2094  Irp->IoStatus.Information = sizeof(STORAGE_PREDICT_FAILURE);
2095  }
2096  } else {
2098  }
2099 
2100  break;
2101  }
2102 
2103  case IOCTL_DISK_VERIFY: {
2104 
2105  PVERIFY_INFORMATION verifyInfo = Irp->AssociatedIrp.SystemBuffer;
2106  LARGE_INTEGER byteOffset;
2107 
2108  DebugPrint((2, "IOCTL_DISK_VERIFY to device %p through irp %p\n",
2109  DeviceObject, Irp));
2110  DebugPrint((2, "Device is a%s.\n",
2111  commonExtension->IsFdo ? "n fdo" : " pdo"));
2112 
2113  //
2114  // Validate buffer length.
2115  //
2116 
2117  if (irpStack->Parameters.DeviceIoControl.InputBufferLength <
2118  sizeof(VERIFY_INFORMATION)) {
2119 
2121  break;
2122  }
2123 
2124  //
2125  // Add disk offset to starting sector.
2126  //
2127 
2128  byteOffset.QuadPart = commonExtension->StartingOffset.QuadPart +
2129  verifyInfo->StartingOffset.QuadPart;
2130 
2131  if(!commonExtension->IsFdo) {
2132 
2133  //
2134  // Adjust the request and forward it down
2135  //
2136 
2137  verifyInfo->StartingOffset.QuadPart = byteOffset.QuadPart;
2138 
2141  ExFreePool(srb);
2142  return status;
2143  }
2144 
2145  //
2146  // Perform a bounds check on the sector range
2147  //
2148 
2149  if ((verifyInfo->StartingOffset.QuadPart > commonExtension->PartitionLength.QuadPart) ||
2150  (verifyInfo->StartingOffset.QuadPart < 0))
2151  {
2153  break;
2154  }
2155  else
2156  {
2157  ULONGLONG bytesRemaining = commonExtension->PartitionLength.QuadPart - verifyInfo->StartingOffset.QuadPart;
2158 
2159  if ((ULONGLONG)verifyInfo->Length > bytesRemaining)
2160  {
2162  break;
2163  }
2164  }
2165 
2166  {
2168 
2172 
2173  if (Context)
2174  {
2175  Context->Irp = Irp;
2176  Context->Srb = srb;
2178 
2179  if (Context->WorkItem)
2180  {
2182 
2183  IoQueueWorkItem(Context->WorkItem,
2186  Context);
2187 
2188  return STATUS_PENDING;
2189  }
2190 
2192  }
2193 
2195  }
2196 
2197  break;
2198  }
2199 
2200  case IOCTL_DISK_CREATE_DISK: {
2201 
2202  if (!commonExtension->IsFdo) {
2204  ExFreePool(srb);
2206  return status;
2207  }
2208 
2210  DeviceObject,
2211  Irp
2212  );
2213  break;
2214  }
2215 
2217 
2218  DebugPrint((1, "IOCTL_DISK_GET_DRIVE_LAYOUT to device %p through irp %p\n",
2219  DeviceObject, Irp));
2220  DebugPrint((1, "Device is a%s.\n",
2221  commonExtension->IsFdo ? "n fdo" : " pdo"));
2222 
2223  if (!commonExtension->IsFdo) {
2225  ExFreePool(srb);
2227  return status;
2228  }
2229 
2231  DeviceObject,
2232  Irp);
2233  break;
2234  }
2235 
2237 
2238  DebugPrint((1, "IOCTL_DISK_GET_DRIVE_LAYOUT_EX to device %p through irp %p\n",
2239  DeviceObject, Irp));
2240  DebugPrint((1, "Device is a%s.\n",
2241  commonExtension->IsFdo ? "n fdo" : " pdo"));
2242 
2243  if (!commonExtension->IsFdo) {
2245  ExFreePool(srb);
2247  return status;
2248  }
2249 
2251  DeviceObject,
2252  Irp);
2253  break;
2254 
2255  }
2256 
2258 
2259  DebugPrint((1, "IOCTL_DISK_SET_DRIVE_LAYOUT to device %p through irp %p\n",
2260  DeviceObject, Irp));
2261  DebugPrint((1, "Device is a%s.\n",
2262  commonExtension->IsFdo ? "n fdo" : " pdo"));
2263 
2264  if(!commonExtension->IsFdo) {
2266  ExFreePool(srb);
2268  return status;
2269  }
2270 
2272 
2273  //
2274  // Notify everyone that the disk layout has changed
2275  //
2276  {
2277  TARGET_DEVICE_CUSTOM_NOTIFICATION Notification;
2278 
2279  Notification.Event = GUID_IO_DISK_LAYOUT_CHANGE;
2280  Notification.Version = 1;
2281  Notification.Size = (USHORT)FIELD_OFFSET(TARGET_DEVICE_CUSTOM_NOTIFICATION, CustomDataBuffer);
2282  Notification.FileObject = NULL;
2283  Notification.NameBufferOffset = -1;
2284 
2286  &Notification,
2287  NULL,
2288  NULL);
2289  }
2290 
2291  break;
2292  }
2293 
2295 
2296  DebugPrint((1, "IOCTL_DISK_SET_DRIVE_LAYOUT_EX to device %p through irp %p\n",
2297  DeviceObject, Irp));
2298  DebugPrint((1, "Device is a%s.\n",
2299  commonExtension->IsFdo ? "n fdo" : " pdo"));
2300 
2301  if (!commonExtension->IsFdo) {
2303  ExFreePool(srb);
2305 
2306  return status;
2307  }
2308 
2310  DeviceObject,
2311  Irp);
2312 
2313  //
2314  // Notify everyone that the disk layout has changed
2315  //
2316  {
2317  TARGET_DEVICE_CUSTOM_NOTIFICATION Notification;
2318 
2319  Notification.Event = GUID_IO_DISK_LAYOUT_CHANGE;
2320  Notification.Version = 1;
2321  Notification.Size = (USHORT)FIELD_OFFSET(TARGET_DEVICE_CUSTOM_NOTIFICATION, CustomDataBuffer);
2322  Notification.FileObject = NULL;
2323  Notification.NameBufferOffset = -1;
2324 
2326  &Notification,
2327  NULL,
2328  NULL);
2329  }
2330 
2331  break;
2332  }
2333 
2335 
2336  DebugPrint((1, "IOCTL_DISK_GET_PARTITION_INFO to device %p through irp %p\n",
2337  DeviceObject, Irp));
2338  DebugPrint((1, "Device is a%s.\n",
2339  commonExtension->IsFdo ? "n fdo" : " pdo"));
2340 
2342  DeviceObject,
2343  Irp);
2344  break;
2345  }
2346 
2348 
2349  DebugPrint((1, "IOCTL_DISK_GET_PARTITION_INFO to device %p through irp %p\n",
2350  DeviceObject, Irp));
2351  DebugPrint((1, "Device is a%s.\n",
2352  commonExtension->IsFdo ? "n fdo" : " pdo"));
2353 
2355  DeviceObject,
2356  Irp);
2357  break;
2358  }
2359 
2361  DebugPrint((1, "IOCTL_DISK_GET_LENGTH_INFO to device %p through irp %p\n",
2362  DeviceObject, Irp));
2363  DebugPrint((1, "Device is a%s.\n",
2364  commonExtension->IsFdo ? "n fdo" : " pdo"));
2365 
2367  DeviceObject,
2368  Irp);
2369  break;
2370  }
2371 
2373 
2374  DebugPrint((1, "IOCTL_DISK_SET_PARTITION_INFO to device %p through irp %p\n",
2375  DeviceObject, Irp));
2376  DebugPrint((1, "Device is a%s.\n",
2377  commonExtension->IsFdo ? "n fdo" : " pdo"));
2378 
2379 
2381  DeviceObject,
2382  Irp);
2383  break;
2384  }
2385 
2386 
2388 
2389  DebugPrint((1, "IOCTL_DISK_SET_PARTITION_INFO_EX to device %p through irp %p\n",
2390  DeviceObject, Irp));
2391  DebugPrint((1, "Device is a%s.\n",
2392  commonExtension->IsFdo ? "n fdo" : " pdo"));
2393 
2395  DeviceObject,
2396  Irp);
2397  break;
2398  }
2399 
2401 
2402  CREATE_DISK CreateDiskInfo;
2403 
2404  //
2405  // Update the disk with new partition information.
2406  //
2407 
2408  DebugPrint((1, "IOCTL_DISK_DELETE_DRIVE_LAYOUT to device %p through irp %p\n",
2409  DeviceObject, Irp));
2410  DebugPrint((1, "Device is a%s.\n",
2411  commonExtension->IsFdo ? "n fdo" : " pdo"));
2412 
2413  if(!commonExtension->IsFdo) {
2414 
2416  ExFreePool(srb);
2418  return status;
2419  }
2420 
2421  DiskAcquirePartitioningLock(fdoExtension);
2422 
2423  DiskInvalidatePartitionTable(fdoExtension, TRUE);
2424 
2425  //
2426  // IoCreateDisk called with a partition style of raw
2427  // will remove any partition tables from the disk.
2428  //
2429 
2430  RtlZeroMemory (&CreateDiskInfo, sizeof (CreateDiskInfo));
2431  CreateDiskInfo.PartitionStyle = PARTITION_STYLE_RAW;
2432 
2433  status = IoCreateDisk(
2434  DeviceObject,
2435  &CreateDiskInfo);
2436 
2437 
2438  DiskReleasePartitioningLock(fdoExtension);
2440 
2441  Irp->IoStatus.Status = status;
2442 
2443  break;
2444  }
2445 
2447 
2448  //
2449  // Map defective blocks to new location on disk.
2450  //
2451 
2452  PREASSIGN_BLOCKS badBlocks = Irp->AssociatedIrp.SystemBuffer;
2453  ULONG bufferSize;
2454  ULONG blockNumber;
2455  ULONG blockCount;
2456 
2457  DebugPrint((2, "IOCTL_DISK_REASSIGN_BLOCKS to device %p through irp %p\n",
2458  DeviceObject, Irp));
2459  DebugPrint((2, "Device is a%s.\n",
2460  commonExtension->IsFdo ? "n fdo" : " pdo"));
2461 
2462  //
2463  // Validate buffer length.
2464  //
2465 
2466  if (irpStack->Parameters.DeviceIoControl.InputBufferLength <
2467  sizeof(REASSIGN_BLOCKS)) {
2468 
2470  break;
2471  }
2472 
2473  //
2474  // Send to FDO
2475  //
2476 
2477  if(!commonExtension->IsFdo) {
2478 
2480  ExFreePool(srb);
2482  return status;
2483  }
2484 
2485  bufferSize = sizeof(REASSIGN_BLOCKS) +
2486  ((badBlocks->Count - 1) * sizeof(ULONG));
2487 
2488  if (irpStack->Parameters.DeviceIoControl.InputBufferLength <
2489  bufferSize) {
2490 
2492  break;
2493  }
2494 
2495  //
2496  // Build the data buffer to be transferred in the input buffer.
2497  // The format of the data to the device is:
2498  //
2499  // 2 bytes Reserved
2500  // 2 bytes Length
2501  // x * 4 btyes Block Address
2502  //
2503  // All values are big endian.
2504  //
2505 
2506  badBlocks->Reserved = 0;
2507  blockCount = badBlocks->Count;
2508 
2509  //
2510  // Convert # of entries to # of bytes.
2511  //
2512 
2513  blockCount *= 4;
2514  badBlocks->Count = (USHORT) ((blockCount >> 8) & 0XFF);
2515  badBlocks->Count |= (USHORT) ((blockCount << 8) & 0XFF00);
2516 
2517  //
2518  // Convert back to number of entries.
2519  //
2520 
2521  blockCount /= 4;
2522 
2523  for (; blockCount > 0; blockCount--) {
2524 
2525  blockNumber = badBlocks->BlockNumber[blockCount-1];
2526 
2527  REVERSE_BYTES((PFOUR_BYTE) &badBlocks->BlockNumber[blockCount-1],
2528  (PFOUR_BYTE) &blockNumber);
2529  }
2530 
2531  srb->CdbLength = 6;
2532 
2533  cdb->CDB6GENERIC.OperationCode = SCSIOP_REASSIGN_BLOCKS;
2534 
2535  //
2536  // Set timeout value.
2537  //
2538 
2539  srb->TimeOutValue = fdoExtension->TimeOutValue;
2540 
2542  srb,
2543  badBlocks,
2544  bufferSize,
2545  TRUE);
2546 
2547  Irp->IoStatus.Status = status;
2548  Irp->IoStatus.Information = 0;
2549  ExFreePool(srb);
2552 
2553  return(status);
2554  }
2555 
2556  case IOCTL_DISK_IS_WRITABLE: {
2557 
2558  //
2559  // This routine mimics IOCTL_STORAGE_GET_MEDIA_TYPES_EX
2560  //
2561 
2562  ULONG modeLength;
2563  ULONG retries = 4;
2564 
2565  DebugPrint((3, "Disk.DiskDeviceControl: IOCTL_DISK_IS_WRITABLE\n"));
2566 
2567  if (!commonExtension->IsFdo)
2568  {
2570  ExFreePool(srb);
2572  return status;
2573  }
2574 
2576 
2577  //
2578  // Allocate memory for a mode header and then some
2579  // for port drivers that need to convert to MODE10
2580  // or always return the MODE_PARAMETER_BLOCK (even
2581  // when memory was not allocated for this purpose)
2582  //
2583 
2584  modeLength = sizeof(MODE_PARAMETER_HEADER) + sizeof(MODE_PARAMETER_BLOCK);
2586  modeLength,
2588 
2589  if (modeData == NULL)
2590  {
2592  break;
2593  }
2594 
2595  RtlZeroMemory(modeData, modeLength);
2596 
2597  //
2598  // Build the MODE SENSE CDB
2599  //
2600 
2601  srb->CdbLength = 6;
2602  cdb = (PCDB)srb->Cdb;
2603 
2604  //
2605  // Set the timeout value from the device extension
2606  //
2607 
2608  srb->TimeOutValue = fdoExtension->TimeOutValue;
2609 
2610  cdb->MODE_SENSE.OperationCode = SCSIOP_MODE_SENSE;
2611  cdb->MODE_SENSE.PageCode = MODE_SENSE_RETURN_ALL;
2612  cdb->MODE_SENSE.AllocationLength = (UCHAR)modeLength;
2613 
2614  while (retries != 0)
2615  {
2617  srb,
2618  modeData,
2619  modeLength,
2620  FALSE);
2621 
2623  {
2625  {
2627  }
2628 
2629  break;
2630  }
2631 
2632  retries--;
2633  }
2634 
2635  if (NT_SUCCESS(status))
2636  {
2638  {
2640  }
2641  }
2642 
2643  ExFreePool(modeData);
2644  break;
2645  }
2646 
2648 
2649  //
2650  // If the caller is kernel mode, set the verify bit.
2651  //
2652 
2653  if (Irp->RequestorMode == KernelMode) {
2654 
2656 
2657  if(commonExtension->IsFdo) {
2658 
2659  Irp->IoStatus.Information = 0;
2660  }
2661  }
2662 
2663  DiskInvalidatePartitionTable(fdoExtension, FALSE);
2664 
2666  break;
2667  }
2668 
2670 
2671  //
2672  // If the caller is kernel mode, clear the verify bit.
2673  //
2674 
2675  if (Irp->RequestorMode == KernelMode) {
2677  }
2679  break;
2680  }
2681 
2683 
2684  DebugPrint((2, "IOCTL_DISK_UPDATE_DRIVE_SIZE to device %p "
2685  "through irp %p\n",
2686  DeviceObject, Irp));
2687 
2688  DebugPrint((2, "Device is a%s.\n",
2689  commonExtension->IsFdo ? "n fdo" : " pdo"));
2690 
2691  if (irpStack->Parameters.DeviceIoControl.OutputBufferLength <
2692  sizeof(DISK_GEOMETRY)) {
2693 
2695  Irp->IoStatus.Information = sizeof(DISK_GEOMETRY);
2696  break;
2697  }
2698 
2699  if(!commonExtension->IsFdo) {
2700 
2701  //
2702  // Pdo should issue this request to the lower device object.
2703  //
2704 
2706  ExFreePool(srb);
2708  return status;
2709  }
2710 
2711  DiskAcquirePartitioningLock(fdoExtension);
2712 
2713  //
2714  // Invalidate the cached partition table.
2715  //
2716 
2717  DiskInvalidatePartitionTable(fdoExtension, TRUE);
2718 
2719  //
2720  // At this point, commonExtension *is* the FDO extension. This
2721  // should be the same as PartitionZeroExtension.
2722  //
2723 
2724  ASSERT(commonExtension ==
2725  &(commonExtension->PartitionZeroExtension->CommonExtension));
2726 
2727  //
2728  // Issue ReadCapacity to update device extension with information
2729  // for current media.
2730  //
2731 
2733 
2734  //
2735  // Note whether the drive is ready.
2736  //
2737 
2738  diskData->ReadyStatus = status;
2739 
2740  //
2741  // The disk's partition tables may be invalid after the drive geometry
2742  // has been updated. The call to IoValidatePartitionTable (below) will
2743  // fix it if this is the case.
2744  //
2745 
2746  if (NT_SUCCESS(status)) {
2747 
2748  status = DiskVerifyPartitionTable (fdoExtension, TRUE);
2749  }
2750 
2751 
2752  if (NT_SUCCESS(status)) {
2753 
2754  //
2755  // Copy drive geometry information from the device extension.
2756  //
2757 
2758  RtlMoveMemory(Irp->AssociatedIrp.SystemBuffer,
2759  &(fdoExtension->DiskGeometry),
2760  sizeof(DISK_GEOMETRY));
2761 
2762  Irp->IoStatus.Information = sizeof(DISK_GEOMETRY);
2764 
2765  }
2766 
2767  DiskReleasePartitioningLock(fdoExtension);
2768 
2769  break;
2770  }
2771 
2773 
2774  PDISK_GROW_PARTITION inputBuffer;
2775 
2776  // PDEVICE_OBJECT pdo;
2777  PCOMMON_DEVICE_EXTENSION pdoExtension;
2778 
2779  LARGE_INTEGER bytesPerCylinder;
2780  LARGE_INTEGER newStoppingOffset;
2781  LARGE_INTEGER newPartitionLength;
2782 
2784 
2785  PDRIVE_LAYOUT_INFORMATION_EX layoutInfo;
2786  PPARTITION_INFORMATION_EX pdoPartition;
2787  PPARTITION_INFORMATION_EX containerPartition;
2788  //ULONG partitionIndex;
2789 
2790  DebugPrint((2, "IOCTL_DISK_GROW_PARTITION to device %p through "
2791  "irp %p\n",
2792  DeviceObject, Irp));
2793 
2794  DebugPrint((2, "Device is a%s.\n",
2795  commonExtension->IsFdo ? "n fdo" : " pdo"));
2796 
2797  Irp->IoStatus.Information = 0;
2798 
2799  if (irpStack->Parameters.DeviceIoControl.InputBufferLength <
2800  sizeof(DISK_GROW_PARTITION)) {
2801 
2803  Irp->IoStatus.Information = sizeof(DISK_GROW_PARTITION);
2804  break;
2805  }
2806 
2807  if(!commonExtension->IsFdo) {
2808 
2809  //
2810  // Pdo should issue this request to the lower device object
2811  //
2812 
2814  ExFreePool(srb);
2816  return status;
2817  }
2818 
2819  DiskAcquirePartitioningLock(fdoExtension);
2820  ClassAcquireChildLock(fdoExtension);
2821 
2822  //
2823  // At this point, commonExtension *is* the FDO extension. This should
2824  // be the same as PartitionZeroExtension.
2825  //
2826 
2827  ASSERT(commonExtension ==
2828  &(commonExtension->PartitionZeroExtension->CommonExtension));
2829 
2830  //
2831  // Get the input parameters
2832  //
2833 
2834  inputBuffer = (PDISK_GROW_PARTITION) Irp->AssociatedIrp.SystemBuffer;
2835 
2836  ASSERT(inputBuffer);
2837 
2838  //
2839  // Make sure that we are actually being asked to grow the partition.
2840  //
2841 
2842  if(inputBuffer->BytesToGrow.QuadPart == 0) {
2843 
2845  ClassReleaseChildLock(fdoExtension);
2846  DiskReleasePartitioningLock(fdoExtension);
2847  break;
2848  }
2849 
2850  //
2851  // Find the partition that matches the supplied number
2852  //
2853 
2854  pdoExtension = &commonExtension->ChildList->CommonExtension;
2855 
2856  while(pdoExtension != NULL) {
2857 
2858  //
2859  // Is this the partition we are searching for?
2860  //
2861 
2862  if(inputBuffer->PartitionNumber == pdoExtension->PartitionNumber) {
2863  break;
2864  }
2865 
2866  pdoExtension = &pdoExtension->ChildList->CommonExtension;
2867  }
2868 
2869  // Did we find the partition?
2870 
2871  if(pdoExtension == NULL) {
2873  ClassReleaseChildLock(fdoExtension);
2874  DiskReleasePartitioningLock(fdoExtension);
2875  break;
2876  }
2877 
2878  ASSERT(pdoExtension);
2879 
2880  //
2881  // Compute the new values for the partition to grow.
2882  //
2883 
2884  newPartitionLength.QuadPart =
2885  (pdoExtension->PartitionLength.QuadPart +
2886  inputBuffer->BytesToGrow.QuadPart);
2887 
2888  newStoppingOffset.QuadPart =
2889  (pdoExtension->StartingOffset.QuadPart +
2890  newPartitionLength.QuadPart - 1);
2891 
2892  //
2893  // Test the partition alignment before getting to involved.
2894  //
2895  // NOTE:
2896  // All partition stopping offsets should be one byte less
2897  // than a cylinder boundary offset. Also, all first partitions
2898  // (within partition0 and within an extended partition) start
2899  // on the second track while all other partitions start on a
2900  // cylinder boundary.
2901  //
2902  bytesPerCylinder.QuadPart =
2903  ((LONGLONG) fdoExtension->DiskGeometry.TracksPerCylinder *
2904  (LONGLONG) fdoExtension->DiskGeometry.SectorsPerTrack *
2905  (LONGLONG) fdoExtension->DiskGeometry.BytesPerSector);
2906 
2907  // Temporarily adjust up to cylinder boundary.
2908 
2909  newStoppingOffset.QuadPart += 1;
2910 
2911  if(newStoppingOffset.QuadPart % bytesPerCylinder.QuadPart) {
2912 
2913  // Adjust the length first...
2914  newPartitionLength.QuadPart -=
2915  (newStoppingOffset.QuadPart % bytesPerCylinder.QuadPart);
2916 
2917  // ...and then the stopping offset.
2918  newStoppingOffset.QuadPart -=
2919  (newStoppingOffset.QuadPart % bytesPerCylinder.QuadPart);
2920 
2921  DebugPrint((2, "IOCTL_DISK_GROW_PARTITION: "
2922  "Adjusted the requested partition size to cylinder boundary"));
2923  }
2924 
2925  // Restore to one byte less than a cylinder boundary.
2926  newStoppingOffset.QuadPart -= 1;
2927 
2928  //
2929  // Will the new partition fit within Partition0?
2930  // Remember: commonExtension == &PartitionZeroExtension->CommonExtension
2931  //
2932 
2933  if(newStoppingOffset.QuadPart >
2934  (commonExtension->StartingOffset.QuadPart +
2935  commonExtension->PartitionLength.QuadPart - 1)) {
2936 
2937  //
2938  // The new partition falls outside Partition0
2939  //
2940 
2942  ClassReleaseChildLock(fdoExtension);
2943  DiskReleasePartitioningLock(fdoExtension);
2944  break;
2945  }
2946 
2947  //
2948  // Search for any partition that will conflict with the new partition.
2949  // This is done before testing for any containing partitions to
2950  // simplify the container handling.
2951  //
2952 
2953  sibling = commonExtension->ChildList;
2954 
2955  while(sibling != NULL) {
2956  //LARGE_INTEGER sibStoppingOffset;
2957  PCOMMON_DEVICE_EXTENSION siblingExtension;
2958 
2959  siblingExtension = &(sibling->CommonExtension);
2960 
2961  ASSERT( siblingExtension );
2962 
2963  /* sibStoppingOffset.QuadPart =
2964  (siblingExtension->StartingOffset.QuadPart +
2965  siblingExtension->PartitionLength.QuadPart - 1); */
2966 
2967  //
2968  // Only check the siblings that start beyond the new partition
2969  // starting offset. Also, assume that since the starting offset
2970  // has not changed, it will not be in conflict with any other
2971  // partitions; only the new stopping offset needs to be tested.
2972  //
2973 
2974  if((inputBuffer->PartitionNumber !=
2975  siblingExtension->PartitionNumber) &&
2976 
2977  (siblingExtension->StartingOffset.QuadPart >
2978  pdoExtension->StartingOffset.QuadPart) &&
2979 
2980  (newStoppingOffset.QuadPart >=
2981  siblingExtension->StartingOffset.QuadPart)) {
2982 
2983  //
2984  // We have a conflict; bail out leaving pdoSibling set.
2985  //
2986 
2987  break;
2988  }
2989  sibling = siblingExtension->ChildList;
2990  }
2991 
2992 
2993  //
2994  // If there is a sibling that conflicts, it will be in pdoSibling; there
2995  // could be more than one, but this is the first one detected.
2996  //
2997 
2998  if(sibling != NULL) {
2999  //
3000  // Report the conflict and abort the grow request.
3001  //
3002 
3004  ClassReleaseChildLock(fdoExtension);
3005  DiskReleasePartitioningLock(fdoExtension);
3006  break;
3007  }
3008 
3009  //
3010  // Read the partition table. Since we're planning on modifying it
3011  // we should bypass the cache.
3012  //
3013 
3014  status = DiskReadPartitionTableEx(fdoExtension, TRUE, &layoutInfo );
3015 
3016  if( !NT_SUCCESS(status) ) {
3017  ClassReleaseChildLock(fdoExtension);
3018  DiskReleasePartitioningLock(fdoExtension);
3019  break;
3020  }
3021 
3022  ASSERT( layoutInfo );
3023 
3024  //
3025  // Search the layout for the partition that matches the
3026  // PDO in hand.
3027  //
3028 
3029  pdoPartition =
3031  (PPHYSICAL_DEVICE_EXTENSION) pdoExtension,
3032  layoutInfo);
3033 
3034  if(pdoPartition == NULL) {
3035  // Looks like something is wrong interally-- error ok?
3037  layoutInfo = NULL;
3038  ClassReleaseChildLock(fdoExtension);
3039  DiskReleasePartitioningLock(fdoExtension);
3040  break;
3041  }
3042 
3043  //
3044  // Search the on-disk partition information to find the root containing
3045  // partition (top-to-bottom).
3046  //
3047  // Remember: commonExtension == &PartitionZeroExtension->CommonExtension
3048  //
3049 
3050  //
3051  // All affected containers will have a new stopping offset
3052  // that is equal to the new partition (logical drive)
3053  // stopping offset. Walk the layout information from
3054  // bottom-to-top searching for logical drive containers and
3055  // propagating the change.
3056  //
3057 
3058  containerPartition =
3060  layoutInfo,
3061  pdoPartition,
3062  FALSE);
3063 
3064  //
3065  // This loop should only execute at most 2 times; once for
3066  // the logical drive container, and once for the root
3067  // extended partition container. If the growing partition
3068  // is not contained, the loop does not run.
3069  //
3070 
3071  while(containerPartition != NULL) {
3072  LARGE_INTEGER containerStoppingOffset;
3073  PPARTITION_INFORMATION_EX nextContainerPartition;
3074 
3075  //
3076  // Plan ahead and get the container's container before
3077  // modifying the current size.
3078  //
3079 
3080  nextContainerPartition =
3082  layoutInfo,
3083  containerPartition,
3084  FALSE);
3085 
3086  //
3087  // Figure out where the current container ends and test
3088  // to see if it already encompasses the containee.
3089  //
3090 
3091  containerStoppingOffset.QuadPart =
3092  (containerPartition->StartingOffset.QuadPart +
3093  containerPartition->PartitionLength.QuadPart - 1);
3094 
3095  if(newStoppingOffset.QuadPart <=
3096  containerStoppingOffset.QuadPart) {
3097 
3098  //
3099  // No need to continue since this container fits
3100  //
3101  break;
3102  }
3103 
3104  //
3105  // Adjust the container to have a stopping offset that
3106  // matches the grown partition stopping offset.
3107  //
3108 
3109  containerPartition->PartitionLength.QuadPart =
3110  newStoppingOffset.QuadPart + 1 -
3111  containerPartition->StartingOffset.QuadPart;
3112 
3113  containerPartition->RewritePartition = TRUE;
3114 
3115  // Continue with the next container
3116  containerPartition = nextContainerPartition;
3117  }
3118 
3119  //
3120  // Wait until after searching the containers to update the
3121  // partition size.
3122  //
3123 
3124  pdoPartition->PartitionLength.QuadPart =
3125  newPartitionLength.QuadPart;
3126 
3127  pdoPartition->RewritePartition = TRUE;
3128 
3129  //
3130  // Commit the changes to disk
3131  //
3132 
3133  status = DiskWritePartitionTableEx(fdoExtension, layoutInfo );
3134 
3135  if( NT_SUCCESS(status) ) {
3136 
3137  //
3138  // Everything looks good so commit the new length to the
3139  // PDO. This has to be done carefully. We may potentially
3140  // grow the partition in three steps:
3141  // * increase the high-word of the partition length
3142  // to be just below the new size - the high word should
3143  // be greater than or equal to the current length.
3144  //
3145  // * change the low-word of the partition length to the
3146  // new value - this value may potentially be lower than
3147  // the current value (if the high part was changed which
3148  // is why we changed that first)
3149  //
3150  // * change the high part to the correct value.
3151  //
3152 
3153  if(newPartitionLength.HighPart >
3154  pdoExtension->PartitionLength.HighPart) {
3155 
3156  //
3157  // Swap in one less than the high word.
3158  //
3159 
3161  &(pdoExtension->PartitionLength.HighPart),
3162  (newPartitionLength.HighPart - 1));
3163  }
3164 
3165  //
3166  // Swap in the low part.
3167  //
3168 
3170  &(pdoExtension->PartitionLength.LowPart),
3171  newPartitionLength.LowPart);
3172 
3173  if(newPartitionLength.HighPart !=
3174  pdoExtension->PartitionLength.HighPart) {
3175 
3176  //
3177  // Swap in one less than the high word.
3178  //
3179 
3181  &(pdoExtension->PartitionLength.HighPart),
3182  newPartitionLength.HighPart);
3183  }
3184  }
3185 
3186  //
3187  // Invalidate and free the cached partition table.
3188  //
3189 
3190  DiskInvalidatePartitionTable(fdoExtension, TRUE);
3191 
3192  //
3193  // Free the partition buffer regardless of the status
3194  //
3195 
3196  ClassReleaseChildLock(fdoExtension);
3197  DiskReleasePartitioningLock(fdoExtension);
3198 
3199  break;
3200  }
3201 
3202 
3204 
3205  //
3206  // Invalidate the partition table and re-enumerate the device.
3207  //
3208 
3209  if(DiskInvalidatePartitionTable(fdoExtension, FALSE)) {
3211  }
3213 
3214  break;
3215  }
3216 
3217  case IOCTL_DISK_MEDIA_REMOVAL: {
3218 
3219  //
3220  // If the disk is not removable then don't allow this command.
3221  //
3222 
3223  DebugPrint((2, "IOCTL_DISK_MEDIA_REMOVAL to device %p through irp %p\n",
3224  DeviceObject, Irp));
3225  DebugPrint((2, "Device is a%s.\n",
3226  commonExtension->IsFdo ? "n fdo" : " pdo"));
3227 
3228  if(!commonExtension->IsFdo) {
3230  ExFreePool(srb);
3232  return status;
3233  }
3234 
3235  if (!TEST_FLAG(DeviceObject->Characteristics, FILE_REMOVABLE_MEDIA)) {
3237  break;
3238  }
3239 
3240  //
3241  // Fall through and let the class driver process the request.
3242  //
3243  goto defaultHandler;
3244 
3245  }
3246 
3247 
3248 
3249 defaultHandler:
3250  default: {
3251 
3252  //
3253  // Free the Srb, since it is not needed.
3254  //
3255 
3256  ExFreePool(srb);
3257 
3258  //
3259  // Pass the request to the common device control routine.
3260  //
3261 
3263 
3264  break;
3265  }
3266 
3267  } // end switch
3268 
3269  Irp->IoStatus.Status = status;
3270 
3272 
3274  }
3275 
3278  ExFreePool(srb);
3279  return(status);
3280 
3281 } // end DiskDeviceControl()
COMMON_DEVICE_EXTENSION CommonExtension
Definition: classpnp.h:628
#define IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
Definition: ntddk_ex.h:208
LARGE_INTEGER PartitionLength
Definition: classpnp.h:594
#define SCSIOP_REASSIGN_BLOCKS
Definition: cdrw_hw.h:873
#define IOCTL_DISK_SET_DRIVE_LAYOUT_EX
Definition: ntdddisk.h:173
struct _DISK_DATA * PDISK_DATA
#define STATUS_NO_MEDIA_IN_DEVICE
Definition: udferr_usr.h:141
NTSTATUS NTAPI DiskIoctlGetDriveGeometryEx(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IOCTL_SCSI_MINIPORT_READ_SMART_ATTRIBS
Definition: cdrw_hw.h:1459
struct _MODE_PARAMETER_HEADER MODE_PARAMETER_HEADER
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
UCHAR bSectorNumberReg
Definition: helper.h:11
VOID NTAPI ClassAcquireChildLock(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: class.c:8483
UCHAR Cdb[16]
Definition: srb.h:271
#define IOCTL_DISK_INTERNAL_SET_VERIFY
Definition: ntdddisk.h:109
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
#define TEST_FLAG(Flags, Bit)
Definition: classpnp.h:156
DISK_GEOMETRY DiskGeometry
Definition: classpnp.h:704
#define IOCTL_SCSI_MINIPORT
Definition: scsi_port.h:48
_In_ PIRP Irp
Definition: csq.h:116
IO_WORKITEM_ROUTINE * PIO_WORKITEM_ROUTINE
Definition: iotypes.h:483
#define SCSIOP_MODE_SENSE
Definition: cdrw_hw.h:896
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define MODE_DSP_WRITE_PROTECT
Definition: cdrw_hw.h:2523
#define DISK_TAG_MODE_DATA
Definition: disk.h:56
#define SMART_GET_VERSION
Definition: ntdddisk.h:194
unsigned char * PUCHAR
Definition: retypes.h:3
NTSTATUS ReadyStatus
Definition: disk.h:222
#define ENABLE_DISABLE_AUTOSAVE
Definition: ntdddisk.h:635
struct _FUNCTIONAL_DEVICE_EXTENSION * PartitionZeroExtension
Definition: classpnp.h:575
VOID NTAPI DiskIoctlVerify(IN PDEVICE_OBJECT Fdo, IN PDISK_VERIFY_WORKITEM_CONTEXT Context)
Definition: disk.c:3688
#define IoIsErrorUserInduced(Status)
Definition: iofuncs.h:2769
Definition: cdrw_hw.h:28
LONG NTSTATUS
Definition: precomp.h:26
#define SCSIOP_TEST_UNIT_READY
Definition: cdrw_hw.h:866
GLintptr offset
Definition: glext.h:5920
VOID NTAPI ClassSendDeviceIoControlSynchronous(IN ULONG IoControlCode, IN PDEVICE_OBJECT TargetDeviceObject, IN OUT PVOID Buffer OPTIONAL, IN ULONG InputBufferLength, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, OUT PIO_STATUS_BLOCK IoStatus)
Definition: class.c:7660
#define REVERSE_BYTES(Destination, Source)
Definition: scsi.h:2707
SCSI_ADDRESS ScsiAddress
Definition: disk.h:236
#define DO_VERIFY_VOLUME
Definition: env_spec_w32.h:393
#define IOCTL_DISK_CREATE_DISK
Definition: ntdddisk.h:52
#define MODE_SENSE_RETURN_ALL
Definition: cdrw_hw.h:857
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
struct _SENDCMDOUTPARAMS SENDCMDOUTPARAMS
#define IOCTL_DISK_IS_WRITABLE
Definition: cdrw_usr.h:172
UCHAR CdbLength
Definition: srb.h:250
#define IOCTL_DISK_UPDATE_DRIVE_SIZE
Definition: ntdddisk.h:182
GLuint buffer
Definition: glext.h:5915
#define CLASS_SPECIAL_DISABLE_WRITE_CACHE_NOT_SUPPORTED
Definition: classpnp.h:168
#define IDENTIFY_BUFFER_SIZE
Definition: ntdddisk.h:621
NTSTATUS NTAPI DiskIoctlCreateDisk(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
ULONG ControlCode
Definition: scsi_port.h:128
ULONG BytesPerSector
Definition: ntdddisk.h:381
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
NTSTATUS NTAPI DiskIoctlGetPartitionInfo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
ULONG TracksPerCylinder
Definition: ntdddisk.h:379
NTSTATUS NTAPI DiskIoctlSetDriveLayoutEx(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
#define DISABLE_SMART
Definition: ntdddisk.h:641
struct _DISK_CACHE_INFORMATION DISK_CACHE_INFORMATION
#define STATUS_VERIFY_REQUIRED
Definition: udferr_usr.h:130
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
ULONG TimeOutValue
Definition: srb.h:254
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
UCHAR TargetId
Definition: scsi_port.h:150
UCHAR SrbStatus
Definition: srb.h:243
#define SRB_STATUS(Status)
Definition: srb.h:381
#define ENABLE_SMART
Definition: ntdddisk.h:640
#define IOCTL_DISK_GET_CACHE_INFORMATION
Definition: ntdddisk.h:67
#define STATUS_NONEXISTENT_SECTOR
Definition: udferr_usr.h:143
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define IOCTL_SCSI_MINIPORT_ENABLE_DISABLE_AUTO_OFFLINE
Definition: scsi.h:1419
NTSTATUS NTAPI DiskIoctlSetDriveLayout(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
#define SendToFdo(Dev, Irp, Rval)
uint32_t ULONG_PTR
Definition: typedefs.h:63
PPARTITION_INFORMATION_EX NTAPI DiskFindContainingPartition(IN PDRIVE_LAYOUT_INFORMATION_EX LayoutInfo, IN PPARTITION_INFORMATION_EX BasePartition, IN BOOLEAN SearchTopToBottom)
Definition: disk.c:4767
struct _SENDCMDINPARAMS SENDCMDINPARAMS
VOID NTAPI ClassGetDeviceParameter(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PWSTR SubkeyName OPTIONAL, IN PWSTR ParameterName, IN OUT PULONG ParameterValue)
Definition: utils.c:52
#define DiskDeviceParameterSubkey
Definition: disk.h:317
NTSTATUS NTAPI ClassSendSrbSynchronous(PDEVICE_OBJECT Fdo, PSCSI_REQUEST_BLOCK Srb, PVOID BufferAddress, ULONG BufferLength, BOOLEAN WriteToDevice)
Definition: class.c:2648
#define IOCTL_SCSI_MINIPORT_ENABLE_DISABLE_AUTOSAVE
Definition: cdrw_hw.h:1464
#define CLASS_SPECIAL_DISABLE_WRITE_CACHE
Definition: classpnp.h:165
#define DiskDeviceSpecialFlags
Definition: disk.h:318
NTSTATUS NTAPI IoCreateDisk(IN PDEVICE_OBJECT DeviceObject, IN struct _CREATE_DISK *Disk)
Definition: fstubex.c:1779
#define IOCTL_DISK_VERIFY
Definition: cdrw_usr.h:170
NTSTATUS NTAPI DiskIoctlSetPartitionInfoEx(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
#define IOCTL_DISK_DELETE_DRIVE_LAYOUT
Definition: ntdddisk.h:55
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
struct _GETVERSIONINPARAMS * PGETVERSIONINPARAMS
#define CLEAR_FLAG(Flags, Bit)
Definition: classpnp.h:155
NTSTATUS NTAPI DiskVerifyPartitionTable(IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN BOOLEAN FixErrors)
Definition: part.c:317
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI DiskDetermineMediaTypes(IN PDEVICE_OBJECT Fdo, IN PIRP Irp, IN UCHAR MediumType, IN UCHAR DensityCode, IN BOOLEAN MediaPresent, IN BOOLEAN IsWritable)
Definition: disk.c:761
#define IOCTL_SCSI_MINIPORT_READ_SMART_THRESHOLDS
Definition: cdrw_hw.h:1460
struct _REASSIGN_BLOCKS REASSIGN_BLOCKS
union _CDB * PCDB
IN PSCSI_REQUEST_BLOCK IN OUT NTSTATUS IN OUT BOOLEAN * Retry
Definition: class2.h:49
UCHAR DeviceSpecificParameter
Definition: cdrw_hw.h:2507
struct _STORAGE_PREDICT_FAILURE * PSTORAGE_PREDICT_FAILURE
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
NTSTATUS NTAPI DiskIoctlGetDriveLayoutEx(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
#define READ_THRESHOLD_BUFFER_SIZE
Definition: ntdddisk.h:622
switch(r->id)
Definition: btrfs.c:2904
#define RETURN_SMART_STATUS
Definition: ntdddisk.h:642
#define READ_ATTRIBUTE_BUFFER_SIZE
Definition: ntdddisk.h:620
#define IOCTL_DISK_SET_PARTITION_INFO
Definition: ntdddisk.h:176
#define SMART_RCV_DRIVE_DATA
Definition: ntdddisk.h:197
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
#define EXECUTE_OFFLINE_DIAGS
Definition: ntdddisk.h:637
#define b
Definition: ke_i.h:79
#define IOCTL_DISK_GET_LENGTH_INFO
Definition: imports.h:192
struct _CDB::_MODE_SENSE MODE_SENSE
LARGE_INTEGER StartingOffset
Definition: classpnp.h:595
struct _GET_MEDIA_TYPES GET_MEDIA_TYPES
int64_t LONGLONG
Definition: typedefs.h:66
#define IOCTL_STORAGE_GET_MEDIA_TYPES_EX
Definition: cdrw_usr.h:190
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define ID_CMD
Definition: helper.h:20
#define READ_THRESHOLDS
Definition: ntdddisk.h:634
#define SAVE_ATTRIBUTE_VALUES
Definition: ntdddisk.h:636
IDEREGS irDriveRegs
Definition: helper.h:32
if(!(yy_init))
Definition: macro.lex.yy.c:714
NTSTATUS NTAPI DiskReadFailurePredictData(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_FAILURE_PREDICT_DATA DiskSmartData)
Definition: diskwmi.c:1083
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define DiskReadDriveCapacity(Fdo)
Definition: disk.h:860
#define IOCTL_DISK_INTERNAL_CLEAR_VERIFY
Definition: ntdddisk.h:106
#define DiskIsValidSmartSelfTest(Subcommand)
Definition: disk.h:533
NTSTATUS NTAPI DiskIoctlGetPartitionInfoEx(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
uint64_t ULONGLONG
Definition: typedefs.h:65
#define IOCTL_SCSI_MINIPORT_EXECUTE_OFFLINE_DIAGS
Definition: cdrw_hw.h:1466
NTSTATUS NTAPI ClassSetDeviceParameter(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PWSTR SubkeyName OPTIONAL, IN PWSTR ParameterName, IN ULONG ParameterValue)
Definition: utils.c:136
ULONG SectorsPerTrack
Definition: ntdddisk.h:380
#define IOCTL_SCSI_MINIPORT_RETURN_STATUS
Definition: cdrw_hw.h:1463
UCHAR bCommandReg
Definition: helper.h:15
struct _PHYSICAL_DEVICE_EXTENSION * ChildList
Definition: classpnp.h:592
#define IOCTL_SCSI_MINIPORT_ENABLE_SMART
Definition: cdrw_hw.h:1461
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
LARGE_INTEGER PartitionLength
Definition: imports.h:222
#define SRB_STATUS_DATA_OVERRUN
Definition: srb.h:349
#define READ_ATTRIBUTES
Definition: ntdddisk.h:633
PARTITION_STYLE PartitionStyle
Definition: winioctl.h:253
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IOCTL_SCSI_MINIPORT_SAVE_ATTRIBUTE_VALUES
Definition: cdrw_hw.h:1465
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
NTSTATUS NTAPI DiskIoctlGetLengthInfo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
LARGE_INTEGER StartingOffset
Definition: imports.h:221
unsigned char UCHAR
Definition: xmlstorage.h:181
NTSTATUS NTAPI DiskIoctlSetPartitionInfo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
NTSTATUS NTAPI DiskGetCacheInformation(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PDISK_CACHE_INFORMATION CacheInfo)
Definition: disk.c:4314
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:88
PDEVICE_OBJECT LowerPdo
Definition: classpnp.h:697
NTSTATUS NTAPI DiskIoctlGetDriveLayout(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
#define HackDisableWriteCacheNotSupported
Definition: disk.h:314
struct _DISK_GROW_PARTITION * PDISK_GROW_PARTITION
LARGE_INTEGER BytesToGrow
Definition: winioctl.h:358
VOID NTAPI DiskReleasePartitioningLock(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: enum.c:1234
ULONG LowPart
Definition: typedefs.h:104
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:257
struct _cl_event * event
Definition: glext.h:7739
struct _GETVERSIONINPARAMS GETVERSIONINPARAMS
#define DISK_TAG_SMART
Definition: disk.h:48
#define IOCTL_DISK_UPDATE_PROPERTIES
Definition: winioctl.h:69
#define InterlockedExchange
Definition: armddk.h:54
#define SET_FLAG(Flags, Bit)
Definition: classpnp.h:154
#define IOCTL_DISK_REASSIGN_BLOCKS
Definition: ntdddisk.h:127
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
#define SMART_CMD
Definition: helper.h:21
#define IOCTL_DISK_GET_DRIVE_LAYOUT
Definition: ntdddisk.h:76
UCHAR bFeaturesReg
Definition: helper.h:9
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
struct _DISK_GEOMETRY DISK_GEOMETRY
#define IOCTL_STORAGE_PREDICT_FAILURE
Definition: ntddstor.h:135
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:5108
VOID NTAPI ClassCompleteRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN CCHAR PriorityBoost)
Definition: lock.c:376
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define IOCTL_DISK_GET_DRIVE_LAYOUT_EX
Definition: ntddk_ex.h:207
PPARTITION_INFORMATION_EX NTAPI DiskPdoFindPartitionEntry(IN PPHYSICAL_DEVICE_EXTENSION Pdo, IN PDRIVE_LAYOUT_INFORMATION_EX LayoutInfo)
Definition: disk.c:4631
struct _STORAGE_PREDICT_FAILURE STORAGE_PREDICT_FAILURE
unsigned short USHORT
Definition: pedump.c:61
struct _SRB_IO_CONTROL SRB_IO_CONTROL
#define DiskDeviceUserWriteCacheSetting
Definition: disk.h:319
struct _CDB::_CDB6GENERIC CDB6GENERIC
#define IOCTL_SCSI_MINIPORT_IDENTIFY
Definition: cdrw_hw.h:1458
#define IOCTL_DISK_SET_PARTITION_INFO_EX
Definition: ntdddisk.h:179
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define SCSI_REQUEST_BLOCK_SIZE
Definition: srb.h:274
#define DISK_TAG_WI_CONTEXT
Definition: disk.h:64
PDEVICE_OBJECT LowerDeviceObject
Definition: classpnp.h:574
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IOCTL_SCSI_MINIPORT_SMART_VERSION
Definition: cdrw_hw.h:1457
#define DISK_TAG_SRB
Definition: disk.h:61
VOID NTAPI ClassInvalidateBusRelations(IN PDEVICE_OBJECT Fdo)
Definition: class.c:6915
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define IRP_MJ_READ
Definition: rdpdr.c:46
NTSTATUS NTAPI DiskReadPartitionTableEx(IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN BOOLEAN BypassCache, OUT PDRIVE_LAYOUT_INFORMATION_EX *DriveLayout)
Definition: part.c:49
UCHAR Signature[8]
Definition: scsi_port.h:126
USHORT Reserved
Definition: ntdddisk.h:524
#define IOCTL_DISK_SET_CACHE_INFORMATION
Definition: ntdddisk.h:154
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
struct _MODE_PARAMETER_BLOCK * PMODE_PARAMETER_BLOCK
NTSTATUS NTAPI DiskSetCacheInformation(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PDISK_CACHE_INFORMATION CacheInfo)
Definition: disk.c:4432
struct _FILE_OBJECT * FileObject
Definition: iotypes.h:975
#define IOCTL_DISK_SET_DRIVE_LAYOUT
Definition: ntdddisk.h:170
VOID NTAPI IoSetHardErrorOrVerifyDevice(IN PIRP Irp, IN PDEVICE_OBJECT DeviceObject)
Definition: util.c:316
struct _IDEREGS IDEREGS
NTSTATUS NTAPI DiskWritePartitionTableEx(IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN PDRIVE_LAYOUT_INFORMATION_EX DriveLayout)
Definition: part.c:199
#define IOCTL_DISK_MEDIA_REMOVAL
Definition: cdrw_usr.h:176
#define IOCTL_SCSI_MINIPORT_DISABLE_SMART
Definition: cdrw_hw.h:1462
UCHAR bDriveNumber
Definition: helper.h:33
ULONG HeaderLength
Definition: scsi_port.h:125
VOID NTAPI ClassReleaseChildLock(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: class.c:8526
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
ULONG BlockNumber[1]
Definition: ntdddisk.h:526
return STATUS_SUCCESS
Definition: btrfs.c:2938
BOOLEAN NTAPI DiskInvalidatePartitionTable(IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN BOOLEAN PartitionLockHeld)
Definition: part.c:291
IoMarkIrpPending(Irp)
NTSTATUS NTAPI IoReportTargetDeviceChangeAsynchronous(IN PDEVICE_OBJECT PhysicalDeviceObject, IN PVOID NotificationStructure, IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback OPTIONAL, IN PVOID Context OPTIONAL)
Definition: pnpreport.c:519
VOID NTAPI DiskAcquirePartitioningLock(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: enum.c:1214
Definition: helper.h:8
static SERVICE_STATUS status
Definition: service.c:31
#define SMART_SEND_DRIVE_COMMAND
Definition: ntdddisk.h:200
NTSTATUS NTAPI DiskReadFailurePredictStatus(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_FAILURE_PREDICT_STATUS DiskSmartStatus)
Definition: diskwmi.c:1007
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
struct _DISK_GROW_PARTITION DISK_GROW_PARTITION
#define IOCTL_DISK_GET_PARTITION_INFO_EX
Definition: ntddk_ex.h:206
LONGLONG QuadPart
Definition: typedefs.h:112
VOID NTAPI ClassReleaseRemoveLock(IN PDEVICE_OBJECT DeviceObject, IN OPTIONAL PIRP Tag)
Definition: lock.c:212
struct _SENDCMDINPARAMS * PSENDCMDINPARAMS
#define IOCTL_DISK_GROW_PARTITION
Definition: ntdddisk.h:94
LARGE_INTEGER StartingOffset
Definition: ntdddisk.h:545
static DRIVER_DISPATCH ClassDeviceControl
Definition: kbdclass.c:22
#define ENABLE_DISABLE_AUTO_OFFLINE
Definition: ntdddisk.h:643
Definition: ps.c:97

Referenced by DriverEntry().

◆ DiskFdoProcessError()

VOID NTAPI DiskFdoProcessError ( PDEVICE_OBJECT  Fdo,
PSCSI_REQUEST_BLOCK  Srb,
NTSTATUS Status,
BOOLEAN Retry 
)

Definition at line 3803 of file disk.c.

3833 {
3834  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = Fdo->DeviceExtension;
3835  PCDB cdb = (PCDB)(Srb->Cdb);
3836 
3837  ASSERT(fdoExtension->CommonExtension.IsFdo);
3838 
3839  if (*Status == STATUS_DATA_OVERRUN &&
3840  ( cdb->CDB10.OperationCode == SCSIOP_WRITE ||
3841  cdb->CDB10.OperationCode == SCSIOP_READ)) {
3842 
3843  *Retry = TRUE;
3844 
3845  //
3846  // Update the error count for the device.
3847  //
3848 
3849  fdoExtension->ErrorCount++;
3850 
3851  } else if (SRB_STATUS(Srb->SrbStatus) == SRB_STATUS_ERROR &&
3852  Srb->ScsiStatus == SCSISTAT_BUSY) {
3853 
3854  //
3855  // a disk drive should never be busy this long. Reset the scsi bus
3856  // maybe this will clear the condition.
3857  //
3858 
3859  ResetBus(Fdo);
3860 
3861  //
3862  // Update the error count for the device.
3863  //
3864 
3865  fdoExtension->ErrorCount++;
3866 
3867  } else {
3868 
3869  BOOLEAN invalidatePartitionTable = FALSE;
3870 
3871  //
3872  // See if this might indicate that something on the drive has changed.
3873  //
3874 
3875  if ((Srb->SrbStatus & SRB_STATUS_AUTOSENSE_VALID) &&
3876  (Srb->SenseInfoBufferLength >=
3877  FIELD_OFFSET(SENSE_DATA, CommandSpecificInformation))) {
3878 
3879  PSENSE_DATA senseBuffer = Srb->SenseInfoBuffer;
3880  ULONG senseKey = senseBuffer->SenseKey & 0xf;
3881  ULONG asc = senseBuffer->AdditionalSenseCode;
3882  ULONG ascq = senseBuffer->AdditionalSenseCodeQualifier;
3883 
3884  switch (senseKey) {
3885 
3887 
3888  switch (asc) {
3889 
3890  case SCSI_ADSENSE_INVALID_CDB: {
3891 
3892  if (((cdb->CDB10.OperationCode == SCSIOP_READ) ||
3893  (cdb->CDB10.OperationCode == SCSIOP_WRITE)) &&
3894  (cdb->CDB10.ForceUnitAccess) &&
3895  TEST_FLAG(fdoExtension->DeviceFlags, DEV_WRITE_CACHE)) {
3896 
3897  //
3898  // This device does not permit FUA while
3899  // the DEV_WRITE_CACHE flag is turned on
3900  //
3901 
3902  PIO_WORKITEM workItem = IoAllocateWorkItem(Fdo);
3903  if (workItem) {
3904 
3905  IoQueueWorkItem(workItem,
3908  workItem);
3909  }
3910 
3911  cdb->CDB10.ForceUnitAccess = FALSE;
3912  *Retry = TRUE;
3913  }
3914 
3915  break;
3916  }
3917  } // end switch(asc)
3918  break;
3919  }
3920 
3921  case SCSI_SENSE_NOT_READY: {
3922 
3923  switch (asc) {
3925  switch (ascq) {
3929  invalidatePartitionTable = TRUE;
3930  break;
3931  }
3932  } // end switch(ascq)
3933  break;
3934  }
3935 
3937  invalidatePartitionTable = TRUE;
3938  break;
3939  }
3940  } // end switch(asc)
3941  break;
3942  }
3943 
3944  case SCSI_SENSE_MEDIUM_ERROR: {
3945  invalidatePartitionTable = TRUE;
3946  break;
3947  }
3948 
3950  invalidatePartitionTable = TRUE;
3951  break;
3952  }
3953 
3955  switch (senseBuffer->AdditionalSenseCode) {
3957  invalidatePartitionTable = TRUE;
3958  break;
3959  }
3960  }
3961  break;
3962  }
3963 
3965  invalidatePartitionTable = TRUE;
3966  break;
3967  }
3968 
3969  } // end switch(senseKey)
3970  } else {
3971 
3972  //
3973  // On any exceptional scsi condition which might indicate that the
3974  // device was changed we will flush out the state of the partition
3975  // table.
3976  //
3977 
3978  switch (SRB_STATUS(Srb->SrbStatus)) {
3981  case SRB_STATUS_NO_DEVICE:
3982  case SRB_STATUS_NO_HBA:
3985  case SRB_STATUS_TIMEOUT:
3990  case SRB_STATUS_ERROR: {
3991  invalidatePartitionTable = TRUE;
3992  break;
3993  }
3994  } // end switch(Srb->SrbStatus)
3995  }
3996 
3997  if(invalidatePartitionTable) {
3998  if(DiskInvalidatePartitionTable(fdoExtension, FALSE)) {
3999  IoInvalidateDeviceRelations(fdoExtension->LowerPdo,
4000  BusRelations);
4001  }
4002  }
4003  }
4004  return;
4005 }
UCHAR SenseKey
Definition: cdrw_hw.h:1167
#define SCSISTAT_BUSY
Definition: cdrw_hw.h:1081
#define TRUE
Definition: types.h:120
#define STATUS_DATA_OVERRUN
Definition: udferr_usr.h:152
#define TEST_FLAG(Flags, Bit)
Definition: classpnp.h:156
#define SRB_STATUS_AUTOSENSE_VALID
Definition: srb.h:379
IO_WORKITEM_ROUTINE * PIO_WORKITEM_ROUTINE
Definition: iotypes.h:483
VOID NTAPI ResetBus(IN PDEVICE_OBJECT Fdo)
Definition: disk.c:4162
Definition: cdrw_hw.h:28
#define SRB_STATUS_REQUEST_FLUSHED
Definition: srb.h:353
COMMON_DEVICE_EXTENSION CommonExtension
Definition: classpnp.h:695
#define SRB_STATUS_COMMAND_TIMEOUT
Definition: srb.h:343
#define SRB_STATUS_NO_DEVICE
Definition: srb.h:340
#define SCSI_ADSENSE_LUN_NOT_READY
Definition: cdrw_hw.h:1218
struct _CDB::_CDB10 CDB10
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
#define SCSI_SENSE_NOT_READY
Definition: cdrw_hw.h:1189
#define SRB_STATUS_INVALID_TARGET_ID
Definition: srb.h:355
#define SRB_STATUS(Status)
Definition: srb.h:381
#define DEV_WRITE_CACHE
Definition: class2.h:21
#define SRB_STATUS_ERROR
Definition: srb.h:336
#define SCSI_SENSE_MEDIUM_ERROR
Definition: cdrw_hw.h:1190
#define SRB_STATUS_PARITY_ERROR
Definition: srb.h:346
#define SCSI_SENSEQ_MANUAL_INTERVENTION_REQUIRED
Definition: cdrw_hw.h:1315
#define SCSIOP_READ
Definition: cdrw_hw.h:905
#define SCSI_ADSENSE_NO_MEDIA_IN_DEVICE
Definition: cdrw_hw.h:1221
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define SCSIOP_WRITE
Definition: cdrw_hw.h:906
unsigned char BOOLEAN
#define SRB_STATUS_NO_HBA
Definition: srb.h:348
union _CDB * PCDB
IN PSCSI_REQUEST_BLOCK IN OUT NTSTATUS IN OUT BOOLEAN * Retry
Definition: class2.h:49
UCHAR AdditionalSenseCodeQualifier
Definition: cdrw_hw.h:1176
VOID NTAPI DisableWriteCache(IN PDEVICE_OBJECT DeviceObject, IN PSCSI_INQUIRY_DATA LunInfo)
Definition: disk.c:3552
#define SCSI_SENSEQ_BECOMING_READY
Definition: cdrw_hw.h:1313
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define SCSI_SENSE_HARDWARE_ERROR
Definition: cdrw_hw.h:1191
PDEVICE_OBJECT LowerPdo
Definition: classpnp.h:697
#define SRB_STATUS_SELECTION_TIMEOUT
Definition: srb.h:342
#define SCSI_SENSE_RECOVERED_ERROR
Definition: cdrw_hw.h:1188
#define SCSI_SENSEQ_CAUSE_NOT_REPORTABLE
Definition: cdrw_hw.h:1312
#define SRB_STATUS_INVALID_LUN
Definition: srb.h:354
Status
Definition: gdiplustypes.h:24
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:5108
#define SRB_STATUS_TIMEOUT
Definition: srb.h:341
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
unsigned int ULONG
Definition: retypes.h:1
#define SRB_STATUS_UNEXPECTED_BUS_FREE
Definition: srb.h:350
#define SRB_STATUS_INVALID_PATH_ID
Definition: srb.h:339
IN PSCSI_REQUEST_BLOCK Srb
Definition: class2.h:49
UCHAR AdditionalSenseCode
Definition: cdrw_hw.h:1175
#define SCSI_SENSE_ILLEGAL_REQUEST
Definition: cdrw_hw.h:1192
BOOLEAN NTAPI DiskInvalidatePartitionTable(IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN BOOLEAN PartitionLockHeld)
Definition: part.c:291
#define SCSI_SENSE_UNIT_ATTENTION
Definition: cdrw_hw.h:1193
#define SCSI_ADSENSE_INVALID_CDB
Definition: cdrw_hw.h:1265
#define SCSI_ADSENSE_MEDIUM_CHANGED
Definition: cdrw_hw.h:1288

Referenced by DriverEntry().

◆ DiskFindAdjacentPartition()

PPARTITION_INFORMATION_EX NTAPI DiskFindAdjacentPartition ( IN PDRIVE_LAYOUT_INFORMATION_EX  LayoutInfo,
IN PPARTITION_INFORMATION_EX  BasePartition 
)

Definition at line 4695 of file disk.c.

4699 {
4700  ULONG partitionIndex;
4701  LONGLONG baseStoppingOffset;
4702  LONGLONG adjacentStartingOffset;
4703  PPARTITION_INFORMATION_EX adjacentPartition = 0;
4704 
4705  ASSERT(LayoutInfo && BasePartition);
4706 
4707  PAGED_CODE();
4708 
4709  DebugPrint((1, "DiskPdoFindAdjacentPartition: Searching layout for adjacent partition.\n"));
4710 
4711  //
4712  // Construct the base stopping offset for comparison
4713  //
4714 
4715  baseStoppingOffset = (BasePartition->StartingOffset.QuadPart +
4716  BasePartition->PartitionLength.QuadPart -
4717  1);
4718 
4719  adjacentStartingOffset = MAXLONGLONG;
4720 
4721  for(partitionIndex = 0;
4722  partitionIndex < LayoutInfo->PartitionCount;
4723  partitionIndex++) {
4724 
4725  PPARTITION_INFORMATION_EX partitionInfo;
4726 
4727  //
4728  // Get the partition entry
4729  //
4730 
4731  partitionInfo = &LayoutInfo->PartitionEntry[partitionIndex];
4732 
4733  //
4734  // See if it is the one we are looking for...
4735  //
4736 
4737  if( LayoutInfo->PartitionStyle == PARTITION_STYLE_MBR &&
4738  partitionInfo->Mbr.PartitionType == PARTITION_ENTRY_UNUSED ) {
4739 
4740  continue;
4741  }
4742 
4743  if( LayoutInfo->PartitionStyle == PARTITION_STYLE_GPT &&
4744  DiskCompareGuid (&partitionInfo->Gpt.PartitionType, &GUID_NULL) == 00 ) {
4745 
4746  continue;
4747  }
4748 
4749 
4750  if((partitionInfo->StartingOffset.QuadPart > baseStoppingOffset) &&
4751  (partitionInfo->StartingOffset.QuadPart < adjacentStartingOffset)) {
4752 
4753  // Found a closer neighbor...update and remember.
4754  adjacentPartition = partitionInfo;
4755 
4756  adjacentStartingOffset = adjacentPartition->StartingOffset.QuadPart;
4757 
4758  DebugPrint((1, "DiskPdoFindAdjacentPartition: Found adjacent "
4759  "partition.\n"));
4760  }
4761  }
4762  return adjacentPartition;
4763 }
#define DiskCompareGuid(_First, _Second)
Definition: disk.c:186
#define MAXLONGLONG
PARTITION_INFORMATION_MBR Mbr
Definition: imports.h:226
#define PAGED_CODE()
Definition: video.h:57
PARTITION_INFORMATION_GPT Gpt
Definition: imports.h:227
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
int64_t LONGLONG
Definition: typedefs.h:66
const GUID GUID_NULL
Definition: disk.c:185
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
LARGE_INTEGER StartingOffset
Definition: imports.h:221
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
unsigned int ULONG
Definition: retypes.h:1
LONGLONG QuadPart
Definition: typedefs.h:112

◆ DiskFindContainingPartition()

PPARTITION_INFORMATION_EX NTAPI DiskFindContainingPartition ( IN PDRIVE_LAYOUT_INFORMATION_EX  LayoutInfo,
IN PPARTITION_INFORMATION_EX  BasePartition,
IN BOOLEAN  SearchTopToBottom 
)

Definition at line 4767 of file disk.c.

4773 {
4774 
4775  LONG partitionIndex;
4776  LONG startIndex;
4777  LONG stopIndex;
4778  LONG stepIndex;
4779 
4780  LONGLONG baseStoppingOffset;
4781  LONGLONG containerStoppingOffset;
4782 
4783  PPARTITION_INFORMATION_EX partitionInfo = 0;
4784  PPARTITION_INFORMATION_EX containerPartition = 0;
4785 
4786  PAGED_CODE();
4787 
4788  ASSERT( LayoutInfo && BasePartition);
4789 
4790  DebugPrint((1, "DiskFindContainingPartition: Searching for extended partition.\n"));
4791 
4792  if( LayoutInfo->PartitionCount != 0) {
4793 
4794  baseStoppingOffset = (BasePartition->StartingOffset.QuadPart +
4795  BasePartition->PartitionLength.QuadPart - 1);
4796 
4797  //
4798  // Determine the search direction and setup the loop
4799  //
4800  if(SearchTopToBottom != FALSE) {
4801 
4802  startIndex = 0;
4803  stopIndex = LayoutInfo->PartitionCount;
4804  stepIndex = +1;
4805  } else {
4806  startIndex = LayoutInfo->PartitionCount - 1;
4807  stopIndex = -1;
4808  stepIndex = -1;
4809  }
4810 
4811  //
4812  // Using the loop parameters, walk the layout information and
4813  // return the first containing partition.
4814  //
4815 
4816  for(partitionIndex = startIndex;
4817  partitionIndex != stopIndex;
4818  partitionIndex += stepIndex) {
4819 
4820  //
4821  // Get the next partition entry
4822  //
4823 
4824  partitionInfo = &LayoutInfo->PartitionEntry[partitionIndex];
4825 
4826  containerStoppingOffset = (partitionInfo->StartingOffset.QuadPart +
4827  partitionInfo->PartitionLength.QuadPart -
4828  1);
4829 
4830  //
4831  // Search for a containing partition without detecting the
4832  // same partition as a container of itself. The starting
4833  // offset of a partition and its container should never be
4834  // the same; however, the stopping offset can be the same.
4835  //
4836 
4837  //
4838  // NOTE: Container partitions are MBR only.
4839  //
4840 
4841  if((LayoutInfo->PartitionStyle == PARTITION_STYLE_MBR) &&
4842  (IsContainerPartition(partitionInfo->Mbr.PartitionType)) &&
4843  (BasePartition->StartingOffset.QuadPart >
4844  partitionInfo->StartingOffset.QuadPart) &&
4845  (baseStoppingOffset <= containerStoppingOffset)) {
4846 
4847  containerPartition = partitionInfo;
4848 
4849  DebugPrint((1, "DiskFindContainingPartition: Found a "
4850  "containing extended partition.\n"));
4851 
4852  break;
4853  }
4854  }
4855  }
4856 
4857  return containerPartition;
4858 }
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:250
PARTITION_INFORMATION_MBR Mbr
Definition: imports.h:226
#define PAGED_CODE()
Definition: video.h:57
long LONG
Definition: pedump.c:60
int64_t LONGLONG
Definition: typedefs.h:66
LARGE_INTEGER PartitionLength
Definition: imports.h:222
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
LARGE_INTEGER StartingOffset
Definition: imports.h:221
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by DiskDeviceControl().

◆ DiskGetCacheInformation()

NTSTATUS NTAPI DiskGetCacheInformation ( IN PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
IN PDISK_CACHE_INFORMATION  CacheInfo 
)

Definition at line 4314 of file disk.c.

4319 {
4320  PMODE_PARAMETER_HEADER modeData;
4321  PMODE_CACHING_PAGE pageData;
4322 
4323  ULONG length;
4324 
4325  //NTSTATUS status;
4326 
4327  PAGED_CODE();
4328 
4332 
4333  if (modeData == NULL) {
4334 
4335  DebugPrint((1, "DiskGetSetCacheInformation: Unable to allocate mode "
4336  "data buffer\n"));
4338  }
4339 
4340  RtlZeroMemory(modeData, MODE_DATA_SIZE);
4341 
4342  length = ClassModeSense(FdoExtension->DeviceObject,
4343  (PUCHAR) modeData,
4346 
4347  if (length < sizeof(MODE_PARAMETER_HEADER)) {
4348 
4349  //
4350  // Retry the request in case of a check condition.
4351  //
4352 
4353  length = ClassModeSense(FdoExtension->DeviceObject,
4354  (PUCHAR) modeData,
4357 
4358  if (length < sizeof(MODE_PARAMETER_HEADER)) {
4359 
4360 
4361  DebugPrint((1, "Disk.DisableWriteCache: Mode Sense failed\n"));
4362 
4363  ExFreePool(modeData);
4364  return STATUS_IO_DEVICE_ERROR;
4365  }
4366  }
4367 
4368  //
4369  // If the length is greater than length indicated by the mode data reset
4370  // the data to the mode data.
4371  //
4372 
4373  if (length > (ULONG) (modeData->ModeDataLength + 1)) {
4374  length = modeData->ModeDataLength + 1;
4375  }
4376 
4377  //
4378  // Check to see if the write cache is enabled.
4379  //
4380 
4381  pageData = ClassFindModePage((PUCHAR) modeData,
4382  length,
4384  TRUE);
4385 
4386  //
4387  // Check if valid caching page exists.
4388  //
4389 
4390  if (pageData == NULL) {
4391  ExFreePool(modeData);
4392  return STATUS_NOT_SUPPORTED;
4393  }
4394 
4395  //
4396  // Copy the parameters over.
4397  //
4398 
4399  RtlZeroMemory(CacheInfo, sizeof(DISK_CACHE_INFORMATION));
4400 
4401  CacheInfo->ParametersSavable = pageData->PageSavable;
4402 
4403  CacheInfo->ReadCacheEnabled = !(pageData->ReadDisableCache);
4404  CacheInfo->WriteCacheEnabled = pageData->WriteCacheEnable;
4405 
4406  CacheInfo->ReadRetentionPriority = pageData->ReadRetensionPriority;
4407  CacheInfo->WriteRetentionPriority = pageData->WriteRetensionPriority;
4408 
4409  CacheInfo->DisablePrefetchTransferLength =
4410  ((pageData->DisablePrefetchTransfer[0] << 8) +
4411  pageData->DisablePrefetchTransfer[1]);
4412 
4413  CacheInfo->ScalarPrefetch.Minimum =
4414  ((pageData->MinimumPrefetch[0] << 8) + pageData->MinimumPrefetch[1]);
4415 
4416  CacheInfo->ScalarPrefetch.Maximum =
4417  ((pageData->MaximumPrefetch[0] << 8) + pageData->MaximumPrefetch[1]);
4418 
4419  if(pageData->MultiplicationFactor) {
4420  CacheInfo->PrefetchScalar = TRUE;
4421  CacheInfo->ScalarPrefetch.MaximumBlocks =
4422  ((pageData->MaximumPrefetchCeiling[0] << 8) +
4423  pageData->MaximumPrefetchCeiling[1]);
4424  }
4425 
4426  ExFreePool(modeData);
4427  return STATUS_SUCCESS;
4428 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
UCHAR WriteCacheEnable
Definition: cdrw_hw.h:2779
#define MODE_PAGE_CACHING
Definition: cdrw_hw.h:846
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG NTAPI ClassModeSense(IN PDEVICE_OBJECT Fdo, IN PCHAR ModeSenseBuffer, IN ULONG Length, IN UCHAR PageMode)
Definition: class.c:4122
#define MODE_SENSE_RETURN_ALL
Definition: cdrw_hw.h:857
UCHAR ReadDisableCache
Definition: cdrw_hw.h:2777
UCHAR ReadRetensionPriority
Definition: cdrw_hw.h:2783
UCHAR MaximumPrefetch[2]
Definition: cdrw_hw.h:2787
#define PAGED_CODE()
Definition: video.h:57
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179
#define MODE_DATA_SIZE
Definition: disk.c:164
UCHAR MultiplicationFactor
Definition: cdrw_hw.h:2778
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI ClassFindModePage(IN PCHAR ModeSenseBuffer, IN ULONG Length, IN UCHAR PageMode, IN BOOLEAN Use6Byte)
Definition: class.c:4209
#define DISK_TAG_DISABLE_CACHE
Definition: disk.h:50
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
UCHAR MinimumPrefetch[2]
Definition: cdrw_hw.h:2786
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
UCHAR DisablePrefetchTransfer[2]
Definition: cdrw_hw.h:2785
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
UCHAR MaximumPrefetchCeiling[2]
Definition: cdrw_hw.h:2788
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
UCHAR WriteRetensionPriority
Definition: cdrw_hw.h:2782
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by DisableWriteCache(), DiskDeviceControl(), and DiskStartFdo().

◆ DiskGetInfoExceptionInformation()

NTSTATUS NTAPI DiskGetInfoExceptionInformation ( IN PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
IN PMODE_INFO_EXCEPTIONS  ReturnPageData 
)

Definition at line 4862 of file disk.c.

4866 {
4867  PMODE_PARAMETER_HEADER modeData;
4868  PMODE_INFO_EXCEPTIONS pageData;
4869  ULONG length;
4870 
4871  NTSTATUS status;
4872 
4873  PAGED_CODE();
4874 
4875  //
4876  // ReturnPageData is allocated by the caller
4877  //
4878 
4882 
4883  if (modeData == NULL) {
4884 
4885  DebugPrint((1, "DiskGetInfoExceptionInformation: Unable to allocate mode "
4886  "data buffer\n"));
4888  }
4889 
4890  RtlZeroMemory(modeData, MODE_DATA_SIZE);
4891 
4892  length = ClassModeSense(FdoExtension->DeviceObject,
4893  (PUCHAR) modeData,
4896 
4897  if (length < sizeof(MODE_PARAMETER_HEADER)) {
4898 
4899  //
4900  // Retry the request in case of a check condition.
4901  //
4902 
4903  length = ClassModeSense(FdoExtension->DeviceObject,
4904  (PUCHAR) modeData,
4907 
4908  if (length < sizeof(MODE_PARAMETER_HEADER)) {
4909 
4910 
4911  DebugPrint((1, "Disk.DisableWriteCache: Mode Sense failed\n"));
4912 
4913  ExFreePool(modeData);
4914  return STATUS_IO_DEVICE_ERROR;
4915  }
4916  }
4917 
4918  //
4919  // If the length is greater than length indicated by the mode data reset
4920  // the data to the mode data.
4921  //
4922 
4923  if (length > (ULONG) (modeData->ModeDataLength + 1)) {
4924  length = modeData->ModeDataLength + 1;
4925  }
4926 
4927  //
4928  // Find the mode page for info exceptions
4929  //
4930 
4931  pageData = ClassFindModePage((PUCHAR) modeData,
4932  length,
4934  TRUE);
4935 
4936  if (pageData != NULL) {
4937  RtlCopyMemory(ReturnPageData, pageData, sizeof(MODE_INFO_EXCEPTIONS));
4939  } else {
4941  }
4942 
4943  DebugPrint((3, "DiskGetInfoExceptionInformation: %s support SMART for device %x\n",
4944  NT_SUCCESS(status) ? "does" : "does not",
4945  FdoExtension->DeviceObject));
4946 
4947 
4948  ExFreePool(modeData);
4949  return(status);
4950 }
#define MODE_PAGE_FAULT_REPORTING
Definition: scsi.h:217
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
ULONG NTAPI ClassModeSense(IN PDEVICE_OBJECT Fdo, IN PCHAR ModeSenseBuffer, IN ULONG Length, IN UCHAR PageMode)
Definition: class.c:4122
#define PAGED_CODE()
Definition: video.h:57
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179
#define DISK_TAG_INFO_EXCEPTION
Definition: disk.h:49
#define MODE_DATA_SIZE
Definition: disk.c:164
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI ClassFindModePage(IN PCHAR ModeSenseBuffer, IN ULONG Length, IN UCHAR PageMode, IN BOOLEAN Use6Byte)
Definition: class.c:4209
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
Definition: ps.c:97

Referenced by DiskFdoExecuteWmiMethod(), and DiskFdoQueryWmiDataBlock().

◆ DiskIoctlCreateDisk() [1/2]

NTSTATUS NTAPI DiskIoctlCreateDisk ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Referenced by DiskDeviceControl().

◆ DiskIoctlCreateDisk() [2/2]

NTSTATUS NTAPI DiskIoctlCreateDisk ( IN OUT PDEVICE_OBJECT  DeviceObject,
IN OUT PIRP  Irp 
)

Definition at line 5171 of file disk.c.

5195 {
5196  NTSTATUS status;
5197  PCOMMON_DEVICE_EXTENSION commonExtension;
5198  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension;
5199  PIO_STACK_LOCATION irpStack;
5200  //PDISK_DATA diskData;
5201  PCREATE_DISK createDiskInfo;
5202 
5203 
5204  PAGED_CODE ();
5205 
5206  ASSERT ( DeviceObject != NULL );
5207  ASSERT ( Irp != NULL );
5208 
5209  //
5210  // Initialization
5211  //
5212 
5213  commonExtension = DeviceObject->DeviceExtension;
5214  fdoExtension = DeviceObject->DeviceExtension;
5215 
5216  irpStack = IoGetCurrentIrpStackLocation(Irp);
5217  //diskData = (PDISK_DATA)(commonExtension->DriverData);
5218 
5219 
5220  ASSERT (commonExtension->IsFdo);
5221 
5222  //
5223  // Check the input buffer size.
5224  //
5225 
5226  if (irpStack->Parameters.DeviceIoControl.InputBufferLength <
5227  sizeof (CREATE_DISK) ) {
5228 
5230  }
5231 
5232  //
5233  // If we are being asked to create a GPT disk on a system that doesn't
5234  // support GPT, fail.
5235  //
5236 
5237  createDiskInfo = (PCREATE_DISK)Irp->AssociatedIrp.SystemBuffer;
5238 
5239  if (DiskDisableGpt &&
5240  createDiskInfo->PartitionStyle == PARTITION_STYLE_GPT) {
5241 
5242  return STATUS_INVALID_PARAMETER;
5243  }
5244 
5245  //
5246  // Call the lower level Io routine to do the dirty work of writing a
5247  // new partition table.
5248  //
5249 
5250  DiskAcquirePartitioningLock(fdoExtension);
5251 
5252  DiskInvalidatePartitionTable(fdoExtension, TRUE);
5253 
5254  status = IoCreateDisk (
5255  commonExtension->PartitionZeroExtension->CommonExtension.DeviceObject,
5256  Irp->AssociatedIrp.SystemBuffer
5257  );
5258  DiskReleasePartitioningLock(fdoExtension);
5260 
5261  Irp->IoStatus.Status = status;
5262 
5263  return status;
5264 }
ULONG DiskDisableGpt
Definition: part.c:44
#define TRUE
Definition: types.h:120
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _FUNCTIONAL_DEVICE_EXTENSION * PartitionZeroExtension
Definition: classpnp.h:575
LONG NTSTATUS
Definition: precomp.h:26
#define PAGED_CODE()
Definition: video.h:57
struct CREATE_DISK * PCREATE_DISK
NTSTATUS NTAPI IoCreateDisk(IN PDEVICE_OBJECT DeviceObject, IN struct _CREATE_DISK *Disk)
Definition: fstubex.c:1779
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
if(!(yy_init))
Definition: macro.lex.yy.c:714
PARTITION_STYLE PartitionStyle
Definition: winioctl.h:253
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI DiskReleasePartitioningLock(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: enum.c:1234
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI ClassInvalidateBusRelations(IN PDEVICE_OBJECT Fdo)
Definition: class.c:6915
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
BOOLEAN NTAPI DiskInvalidatePartitionTable(IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN BOOLEAN PartitionLockHeld)
Definition: part.c:291
VOID NTAPI DiskAcquirePartitioningLock(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: enum.c:1214
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ DiskIoctlGetDriveGeometryEx() [1/2]

NTSTATUS NTAPI DiskIoctlGetDriveGeometryEx ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Referenced by DiskDeviceControl().

◆ DiskIoctlGetDriveGeometryEx() [2/2]

NTSTATUS NTAPI DiskIoctlGetDriveGeometryEx ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PIRP  Irp 
)

Definition at line 6405 of file disk.c.

6429 {
6430  NTSTATUS status;
6431  PIO_STACK_LOCATION irpStack;
6432  PCOMMON_DEVICE_EXTENSION commonExtension;
6433  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension;
6434  PDISK_DATA diskData;
6435  PDISK_GEOMETRY_EX_INTERNAL geometryEx;
6437 
6438  //
6439  // Verification
6440  //
6441 
6442  PAGED_CODE ();
6443 
6444  ASSERT ( DeviceObject != NULL );
6445  ASSERT ( Irp != NULL );
6446 
6447  //
6448  // Setup parameters
6449  //
6450 
6451  commonExtension = DeviceObject->DeviceExtension;
6452  fdoExtension = DeviceObject->DeviceExtension;
6453  diskData = (PDISK_DATA)(commonExtension->DriverData);
6454  irpStack = IoGetCurrentIrpStackLocation ( Irp );
6455  geometryEx = NULL;
6456  OutputBufferLength = irpStack->Parameters.DeviceIoControl.OutputBufferLength;
6457 
6458  //
6459  // This is only valid for the FDO.
6460  //
6461 
6462  ASSERT ( commonExtension->IsFdo );
6463 
6464  //
6465  // Check that the buffer is large enough. It must be large enough
6466  // to hold at lest the Geometry and DiskSize fields of of the
6467  // DISK_GEOMETRY_EX structure.
6468  //
6469 
6471 
6472  //
6473  // Buffer too small. Bail out, telling the caller the required
6474  // size.
6475  //
6476 
6478  Irp->IoStatus.Status = FIELD_OFFSET (DISK_GEOMETRY_EX, Data);
6479  return status;
6480  }
6481 
6482  if (TEST_FLAG (DeviceObject->Characteristics, FILE_REMOVABLE_MEDIA)) {
6483 
6484  //
6485  // Issue a ReadCapacity to update device extension
6486  // with information for the current media.
6487  //
6488 
6490  commonExtension->PartitionZeroExtension->DeviceObject);
6491 
6492  diskData->ReadyStatus = status;
6493 
6494  if (!NT_SUCCESS (status)) {
6495  return status;
6496  }
6497  }
6498 
6499  //
6500  // Copy drive geometry.
6501  //
6502 
6503  geometryEx = (PDISK_GEOMETRY_EX_INTERNAL)Irp->AssociatedIrp.SystemBuffer;
6504  geometryEx->Geometry = fdoExtension->DiskGeometry;
6505  geometryEx->DiskSize = commonExtension->PartitionZeroExtension->CommonExtension.PartitionLength;
6506 
6507  //
6508  // If the user buffer is large enough to hold the partition information
6509  // then add that as well.
6510  //
6511 
6513 
6514  geometryEx->Partition.SizeOfPartitionInfo = sizeof (geometryEx->Partition);
6515  geometryEx->Partition.PartitionStyle = diskData->PartitionStyle;
6516 
6517  switch ( diskData->PartitionStyle ) {
6518 
6519  case PARTITION_STYLE_GPT:
6520 
6521  //
6522  // Copy GPT signature.
6523  //
6524 
6525  geometryEx->Partition.Gpt.DiskId = diskData->Efi.DiskId;
6526  break;
6527 
6528  case PARTITION_STYLE_MBR:
6529 
6530  //
6531  // Copy MBR signature and checksum.
6532  //
6533 
6534  geometryEx->Partition.Mbr.Signature = diskData->Mbr.Signature;
6535  geometryEx->Partition.Mbr.CheckSum = diskData->Mbr.MbrCheckSum;
6536  break;
6537 
6538  default:
6539 
6540  //
6541  // This is a raw disk. Zero out the signature area so
6542  // nobody gets confused.
6543  //
6544 
6545  RtlZeroMemory (
6546  &geometryEx->Partition,
6547  sizeof (geometryEx->Partition));
6548  }
6549  }
6550 
6551  //
6552  // If the buffer is large enough to hold the detection information,
6553  // then also add that.
6554  //
6555 
6557 
6558  geometryEx->Detection.SizeOfDetectInfo =
6559  sizeof (geometryEx->Detection);
6560 
6562  fdoExtension,
6563  &geometryEx->Detection);
6564 
6565  //
6566  // Failed to obtain detection information, set to none.
6567  //
6568 
6569  if (!NT_SUCCESS (status)) {
6570  geometryEx->Detection.DetectionType = DetectNone;
6571  }
6572  }
6573 
6574 
6576  Irp->IoStatus.Information = min (OutputBufferLength,
6577  sizeof (DISK_GEOMETRY_EX_INTERNAL));
6578 
6579  return status;
6580 }
#define DiskGetDetectInfo(FdoExtension, DetectInfo)
Definition: disk.h:976
struct _DISK_DATA * PDISK_DATA
DETECTION_TYPE DetectionType
Definition: ntdddisk.h:367
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
DISK_GEOMETRY Geometry
Definition: disk.c:6396
#define TEST_FLAG(Flags, Bit)
Definition: classpnp.h:156
DISK_GEOMETRY DiskGeometry
Definition: classpnp.h:704
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS ReadyStatus
Definition: disk.h:222
struct _FUNCTIONAL_DEVICE_EXTENSION * PartitionZeroExtension
Definition: classpnp.h:575
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
#define PAGED_CODE()
Definition: video.h:57
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
LARGE_INTEGER DiskSize
Definition: disk.c:6397
struct _DISK_PARTITION_INFO::@3048::@3049 Mbr
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
struct _DISK_GEOMETRY_EX_INTERNAL * PDISK_GEOMETRY_EX_INTERNAL
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
PARTITION_STYLE PartitionStyle
Definition: disk.h:103
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DiskReadDriveCapacity(Fdo)
Definition: disk.h:860
struct _DISK_PARTITION_INFO::@3048::@3050 Gpt
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _DISK_DATA::@1013::@1017 Efi
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define min(a, b)
Definition: monoChain.cc:55
DISK_DETECTION_INFO Detection
Definition: disk.c:6399
struct _DISK_DATA::@1013::@1016 Mbr
DISK_PARTITION_INFO Partition
Definition: disk.c:6398
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
ULONG SizeOfPartitionInfo
Definition: ntdddisk.h:426
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938