⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sync.c

📁 操作系统引导的一些介绍,对学习引导的有很大的帮助与提高
💻 C
字号:
//
// (C) Copyright 1997 OSR Open Systems Resources, Inc.
// All Rights Reserved
//

#include <ntddk.h>

//
// SendSyncIrp
//
//  This is a demonstration routine on how to build your own IRP
//  using the IoBuildSynchronousFsdRequest.
//
// Inputs:
//  DeviceObject - the device to call when passing the IRP
//  MajorFunction - IRP_MJ_* where * is READ, WRITE, FLUSH_BUFFERS or SHUTDOWN
//  FileObject - the file object to use when calling the underlying driver.
//               This is only useful for the case where you are working
//               with a file system. Can be NULL
//  Buffer - pointer to the buffer where the data is located.  Can be NULL
//  BufferLength - zero if Buffer is null, otherwise the # of bytes to
//                 be transferred as part of this operation.
//  Offset - the file/device offset for this operation.
//  Event - the event to be signaled when the I/O is done.
//
// Outputs:
//  IoStatusBlock - the results of the I/O operation.
//
// Returns:
//  TRUE if the IRP was sent
//  FALSE otherwise.
//
// Notes:
//  The restriction of using READ, WRITE, FLUSH, or SHUTDOWN is one imposed
//  by this routine.
//
//  The I/O Manager adds the IRP created to the thread's oustanding I/O list
//  so you MUST complete this via the I/O Manager.
//
//  The I/O Manager will do any IRP cleanup processing necessary - no need for
//  your driver to do it.
// 


BOOLEAN SendSyncIrp(PDEVICE_OBJECT DeviceObject,
                    ULONG MajorFunction, // read, write, flush, etc.
                    PFILE_OBJECT FileObject,
                    PVOID Buffer,
                    ULONG BufferLength,
                    ULONG Offset,
                    PKEVENT Event,
                    IO_STATUS_BLOCK IoStatusBlock)

{
    PIRP Irp;
    LARGE_INTEGER StartingOffset;
    IO_STATUS_BLOCK Iosb;

    //
    // The starting offset is a quad.  For this example we restricted to ULONG
    // so we do the conversion here.  For YOUR work, you can use a quad if that's
    // what's needed.
    //

    StartingOffset.QuadPart = (LONGLONG) Offset;

    //
    // We're going to build the I/O request.  Note that this is an ASYNCHRONOUS
    // request, so we don't provide it with an Event to set when the I/O itself
    // is done.
    //

    Irp = IoBuildSynchronousFsdRequest(MajorFunction,
                                        DeviceObject,
                                        Buffer,
                                        BufferLength,
                                        &StartingOffset,
                                        Event,
                                        &Iosb);

    if (!Irp) {

        //
        // Creation of the IRP failed.  This may happen when there is insufficient memory to
        // create the IRP (non-paged pool exhaustion.)
        //

        return FALSE;

    }

    //
    // If you are going to call your own driver with this IRP, you should advance
    // the I/O stack location (c.f. floppy.c for an example of this) using the
    // IoSetNextIrpStackLocation() call.
    //
    
    // IoSetNextIrpStackLocation(Irp);

    //
    // Pass along to the underlying device
    //

    (void) IoCallDriver(DeviceObject, Irp);

    //
    // Done!
    //

    return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -