磁盘过滤驱动中关于DiskDeviceControl处理

http://bbs.pediy.com/showthread.php?t=167696


你看看WDK src\storage\class\disk\disk.c里的DiskDeviceControl,里边有磁盘设备需要处理的所有IOCTL的过程

PS:如果你测试的是XP系统,那么不要看最新的WDK里的DISK源码,要看与XP匹配WDK的DISK源码才好。


代码:
__control_entrypoint(DeviceDriver)
NTSTATUS
DiskDeviceControl(
    PDEVICE_OBJECT DeviceObject,
    PIRP Irp
    )

/*++

Routine Description:

    I/O system entry for device controls to SCSI disks.

Arguments:

    Fdo - Pointer to functional device object created by system.
    Irp - IRP involved.

Return Value:

    Status is returned.

--*/

{
    PIO_STACK_LOCATION  irpStack = IoGetCurrentIrpStackLocation(Irp);
    NTSTATUS            status = STATUS_SUCCESS;
    ULONG               ioctlCode;

    ASSERT(DeviceObject != NULL);

    Irp->IoStatus.Information = 0;
    ioctlCode = irpStack->Parameters.DeviceIoControl.IoControlCode;

    TracePrint((TRACE_LEVEL_VERBOSE, TRACE_FLAG_IOCTL, "DiskDeviceControl: Received IOCTL 0x%X for device %p through IRP %p\n",
                ioctlCode, DeviceObject, Irp));

    switch (ioctlCode) {

        case IOCTL_DISK_GET_CACHE_INFORMATION: {
            status = DiskIoctlGetCacheInformation(DeviceObject, Irp);
            break;
        }

        case IOCTL_DISK_SET_CACHE_INFORMATION: {
            status = DiskIoctlSetCacheInformation(DeviceObject, Irp);
            break;
        }

        case IOCTL_DISK_GET_CACHE_SETTING: {
            status = DiskIoctlGetCacheSetting(DeviceObject, Irp);
            break;
        }

        case IOCTL_DISK_SET_CACHE_SETTING: {
            status = DiskIoctlSetCacheSetting(DeviceObject, Irp);
            break;
        }

        case IOCTL_DISK_GET_DRIVE_GEOMETRY: {
            status = DiskIoctlGetDriveGeometry(DeviceObject, Irp);
            break;
        }

        case IOCTL_DISK_GET_DRIVE_GEOMETRY_EX: {
            status = DiskIoctlGetDriveGeometryEx( DeviceObject, Irp );
            break;
        }

        case IOCTL_DISK_VERIFY: {
            status = DiskIoctlVerify(DeviceObject, Irp);
            break;
        }

        case IOCTL_DISK_GET_LENGTH_INFO: {
            status = DiskIoctlGetLengthInfo(DeviceObject, Irp);
            break;
        }

        case IOCTL_DISK_IS_WRITABLE: {
            status = DiskIoctlIsWritable(DeviceObject, Irp);
            break;
        }

        case IOCTL_DISK_UPDATE_DRIVE_SIZE: {
            status = DiskIoctlUpdateDriveSize(DeviceObject, Irp);
            break;
        }

        case IOCTL_DISK_REASSIGN_BLOCKS: {
            status = DiskIoctlReassignBlocks(DeviceObject, Irp);
            break;
        }

        case IOCTL_DISK_REASSIGN_BLOCKS_EX: {
            status = DiskIoctlReassignBlocksEx(DeviceObject, Irp);
            break;
        }

        case IOCTL_DISK_INTERNAL_SET_VERIFY: {
            status = DiskIoctlSetVerify(DeviceObject, Irp);
            break;
        }

        case IOCTL_DISK_INTERNAL_CLEAR_VERIFY: {
            status = DiskIoctlClearVerify(DeviceObject, Irp);
            break;
        }

        case IOCTL_STORAGE_GET_MEDIA_TYPES_EX: {
            status = DiskIoctlGetMediaTypesEx(DeviceObject, Irp);
            break;
        }

        case IOCTL_STORAGE_PREDICT_FAILURE : {
            status = DiskIoctlPredictFailure(DeviceObject, Irp);
            break;
        }

        case SMART_GET_VERSION: {
            status = DiskIoctlSmartGetVersion(DeviceObject, Irp);
            break;
        }

        case SMART_RCV_DRIVE_DATA: {
            status = DiskIoctlSmartReceiveDriveData(DeviceObject, Irp);
            break;
        }

        case SMART_SEND_DRIVE_COMMAND: {
            status = DiskIoctlSmartSendDriveCommand(DeviceObject, Irp);
            break;
        }

        case IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS:
        case IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS_ADMIN: {
            status = DiskIoctlGetVolumeDiskExtents(DeviceObject, Irp);
            break;
        }

        default: {

            //
            // Pass the request to the common device control routine.
            //
            return(ClassDeviceControl(DeviceObject, Irp));
            break;
        }
    } // end switch

    if (!NT_SUCCESS(status)) {

        TracePrint((TRACE_LEVEL_ERROR, TRACE_FLAG_IOCTL, "DiskDeviceControl: IOCTL 0x%X to device %p failed with error 0x%X\n",
                    ioctlCode, DeviceObject, status));
        if (IoIsErrorUserInduced(status) &&
            (Irp->Tail.Overlay.Thread != NULL)) {
            IoSetHardErrorOrVerifyDevice(Irp, DeviceObject);
        }
    }

    //
    // DiskIoctlVerify() (IOCTL_DISK_VERIFY) function returns STATUS_PENDING
    // and completes the IRP in the work item. Do not touch or complete
    // the IRP if STATUS_PENDING is returned.
    //

    if (status != STATUS_PENDING) {
        Irp->IoStatus.Status = status;
        ClassReleaseRemoveLock(DeviceObject, Irp);
        ClassCompleteRequest(DeviceObject, Irp, IO_NO_INCREMENT);
    }

    return(status);
} // end DiskDeviceControl()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Disk Controls is set of 22+ components that can make your life much easier if you developing software that works with disks (Hard / Floppy / CD / RAM / Network), shell and file system. The DiskControls pack contains: Two advanced search engines, which will find any file or folder by specified criterias (DiskScanner and MultiDiskScanner components); The FolderListView component which let's you to display filtered contents of any directory and looks and feels like Windows Explorer. Supports big number of features such like automatical sorting of the list items with arrow-style sort mark on the header section, individual context menus for every shell object, possibility to hide or show some list columns, automatic drag'n'drop support via OLE and so on…; The FolderMonitor, which will check your folders for any changes; The VirtualDrives engine, which can define, redefine or delete the virtual drives from the file system; The FileTail utility, which works like tail command in Unix, and can monitor the file for its changes; Several components that provide you with detailed information about any shell objects (files, folders or drives), can retrieve the version information from executable files and dynamic-link libraries; Component which can install or uninstall new file types into the shell (dcFileAssociation); Component which performs the operations with files and folders on shell level (dcFileOperations); Several advanced edit controls and dialogs for browsing and selecting the files and folders; much more... see Components Overview for more details. Compatibility DiskControls compatible with Delphi 3/4/5/6/7 and BCB 3/4/5/6, and has been tested on Win95, Win95OSR2, Win98, WinME, NT4, Win2000 and WinXP. Improvements Currently the DiskControls pack contains 22 components. However, we constantly updating the package and adding more useful utilities and new great features in existing components. If you have any suggestions to help us to improve the DiskControls — please contact us and never hesitate to do it for any question. Updates Registering of the DiskControls entitles you to unlimited support (via email or personal panel at AppControls.Com website), minor updates indefinitely and major version updates for 6 month from date of purchase.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值