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

📄 debug.c

📁 This is a ReiserFs file system driver for Windows NT/2000/XP/Vista.
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
 * COPYRIGHT:        GNU GENERAL PUBLIC LICENSE VERSION 2
 * PROJECT:          ReiserFs file system driver for Windows NT/2000/XP/Vista.
 * FILE:             debug.c
 * PURPOSE:          
 * PROGRAMMER:       Mark Piper, Matt Wu, Bo Brant閚.
 * HOMEPAGE:         
 * UPDATE HISTORY: 
 */

#if DBG

/* INCLUDES **************************************************************/

#include "stdarg.h"
#include "stdio.h"
#include "rfsd.h"


/* GLOBALS ***************************************************************/

#define SYSTEM_PROCESS_NAME "System"

extern PRFSD_GLOBAL RfsdGlobal;

LONG   DebugLevel = DBG_FUNC;

ULONG  ProcessNameOffset = 0;


/* DEFINITIONS ***********************************************************/

#ifdef ALLOC_PRAGMA
#pragma alloc_text (PAGE, RfsdPrintf)
#pragma alloc_text (PAGE, RfsdNIPrintf)
#pragma alloc_text (PAGE, RfsdGetProcessNameOffset)
#pragma alloc_text (PAGE, RfsdDbgPrintCall)
#pragma alloc_text (PAGE, RfsdDbgPrintComplete)
#pragma alloc_text (PAGE, RfsdNtStatusToString)
#endif // ALLOC_PRAGMA

/* Static Definitions ****************************************************/

#define MAX_IRP_IDENTIFIER 28
static PUCHAR IrpMjStrings[] = {
    "IRP_MJ_CREATE",
    "IRP_MJ_CREATE_NAMED_PIPE",
    "IRP_MJ_CLOSE",
    "IRP_MJ_READ",
    "IRP_MJ_WRITE",
    "IRP_MJ_QUERY_INFORMATION",
    "IRP_MJ_SET_INFORMATION",
    "IRP_MJ_QUERY_EA",
    "IRP_MJ_SET_EA",
    "IRP_MJ_FLUSH_BUFFERS",
    "IRP_MJ_QUERY_VOLUME_INFORMATION",
    "IRP_MJ_SET_VOLUME_INFORMATION",
    "IRP_MJ_DIRECTORY_CONTROL",
    "IRP_MJ_FILE_SYSTEM_CONTROL",
    "IRP_MJ_DEVICE_CONTROL",
    "IRP_MJ_INTERNAL_DEVICE_CONTROL",
    "IRP_MJ_SHUTDOWN",
    "IRP_MJ_LOCK_CONTROL",
    "IRP_MJ_CLEANUP",
    "IRP_MJ_CREATE_MAILSLOT",
    "IRP_MJ_QUERY_SECURITY",
    "IRP_MJ_SET_SECURITY",
    "IRP_MJ_POWER",
    "IRP_MJ_SYSTEM_CONTROL",
    "IRP_MJ_DEVICE_CHANGE",
    "IRP_MJ_QUERY_QUOTA",
    "IRP_MJ_SET_QUOTA",
    "IRP_MJ_PNP"
};

static PUCHAR FileInformationClassStrings[] = {
    "Unknown FileInformationClass 0",
    "FileDirectoryInformation",
    "FileFullDirectoryInformation",
    "FileBothDirectoryInformation",
    "FileBasicInformation",
    "FileStandardInformation",
    "FileInternalInformation",
    "FileEaInformation",
    "FileAccessInformation",
    "FileNameInformation",
    "FileRenameInformation",
    "FileLinkInformation",
    "FileNamesInformation",
    "FileDispositionInformation",
    "FilePositionInformation",
    "FileFullEaInformation",
    "FileModeInformation",
    "FileAlignmentInformation",
    "FileAllInformation",
    "FileAllocationInformation",
    "FileEndOfFileInformation",
    "FileAlternateNameInformation",
    "FileStreamInformation",
    "FilePipeInformation",
    "FilePipeLocalInformation",
    "FilePipeRemoteInformation",
    "FileMailslotQueryInformation",
    "FileMailslotSetInformation",
    "FileCompressionInformation",
    "FileObjectIdInformation",
    "FileCompletionInformation",
    "FileMoveClusterInformation",
    "FileQuotaInformation",
    "FileReparsePointInformation",
    "FileNetworkOpenInformation",
    "FileAttributeTagInformation",
    "FileTrackingInformation"
};

static PUCHAR FsInformationClassStrings[] = {
    "Unknown FsInformationClass 0",
    "FileFsVolumeInformation",
    "FileFsLabelInformation",
    "FileFsSizeInformation",
    "FileFsDeviceInformation",
    "FileFsAttributeInformation",
    "FileFsControlInformation",
    "FileFsFullSizeInformation",
    "FileFsObjectIdInformation"
};

/*
 * RfsdPrintf
 *   This function is variable-argument, level-sensitive debug print routine.
 *   If the specified debug level for the print statement is lower or equal
 *   to the current debug level, the message will be printed.
 *
 * Arguments:
 *   DebugPrintLevel - Specifies at which debugging level the string should
 *                     be printed
 *   DebugMessage - Variable argument ascii c string
 *
 * Return Value:
 *   N/A
 *
 * NOTES: 
 *   N/A
 */

VOID
RfsdPrintf(
    LONG  DebugPrintLevel,
    PCHAR DebugMessage,
    ...
    )
{
    va_list             ap;
    LARGE_INTEGER       CurrentTime;
    TIME_FIELDS         TimeFields;

    ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);

    if (DebugPrintLevel <= DebugLevel) {
        CHAR Buffer[0x100];
        va_start(ap, DebugMessage);
       
        KeQuerySystemTime( &CurrentTime);
        RtlTimeToTimeFields(&CurrentTime, &TimeFields);

        vsprintf(Buffer, DebugMessage, ap);

        /*DbgPrint(DRIVER_NAME": %2.2d:%2.2d:%2.2d:%3.3d %8.8x:   %s",
                 TimeFields.Hour, TimeFields.Minute,
                 TimeFields.Second, TimeFields.Milliseconds,
                 PsGetCurrentThread(), Buffer);*/

		  DbgPrint(DRIVER_NAME": %s",
                 Buffer);

        va_end(ap);
    }


    ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);

} // RfsdPrintf()


/*
 * RfsdNIPrintf
 *   This function is variable-argument, level-sensitive debug print routine.
 *   If the specified debug level for the print statement is lower or equal
 *   to the current debug level, the message will be printed.
 *
 * Arguments:
 *   DebugPrintLevel - Specifies at which debugging level the string should
 *                     be printed
 *   DebugMessage - Variable argument ascii c string
 *
 * Return Value:
 *   N/A
 *
 * NOTES: 
 *   N/A
 */

VOID
RfsdNIPrintf(
    LONG  DebugPrintLevel,
    PCHAR DebugMessage,
    ...
    )
{
    va_list             ap;
    LARGE_INTEGER       CurrentTime;
    TIME_FIELDS         TimeFields;

    ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);

    if (DebugPrintLevel <= DebugLevel) {
        CHAR Buffer[0x100];
        va_start(ap, DebugMessage);
       
        KeQuerySystemTime( &CurrentTime);
        RtlTimeToTimeFields(&CurrentTime, &TimeFields);

        vsprintf(Buffer, DebugMessage, ap);

        DbgPrint(DRIVER_NAME": %2.2d:%2.2d:%2.2d:%3.3d %8.8x: %s",
                 TimeFields.Hour, TimeFields.Minute,
                 TimeFields.Second, TimeFields.Milliseconds,
                 PsGetCurrentThread(), Buffer);

        va_end(ap);
    }


    ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);

} // RfsdNIPrintf()

ULONG 
RfsdGetProcessNameOffset ( VOID )
{
    PEPROCESS   Process;
    ULONG       i;

    Process = PsGetCurrentProcess();

    for(i = 0; i < PAGE_SIZE; i++) {
        if(!strncmp(
            SYSTEM_PROCESS_NAME,
            (PCHAR) Process + i,
            strlen(SYSTEM_PROCESS_NAME)
            )) {

            return i;
        }
    }

    RfsdPrint((DBG_ERROR, ": *** FsdGetProcessNameOffset failed ***\n"));

    return 0;
}


VOID
RfsdDbgPrintCall (IN PDEVICE_OBJECT   DeviceObject,
          IN PIRP             Irp )
{
    PIO_STACK_LOCATION      IoStackLocation;
    PFILE_OBJECT            FileObject;
    PUCHAR                  FileName;
    PRFSD_FCB               Fcb;
    FILE_INFORMATION_CLASS  FileInformationClass;
    FS_INFORMATION_CLASS    FsInformationClass;

    IoStackLocation = IoGetCurrentIrpStackLocation(Irp);

    FileObject = IoStackLocation->FileObject;

    FileName = "Unknown";

    if (DeviceObject == RfsdGlobal->DeviceObject) {

        FileName = "\\" DRIVER_NAME;

    } else if (FileObject && FileObject->FsContext) {

        Fcb = (PRFSD_FCB) FileObject->FsContext;

        if (Fcb->Identifier.Type == RFSDVCB)  {
            FileName = "\\Volume";
        } else if (Fcb->Identifier.Type == RFSDFCB && Fcb->AnsiFileName.Buffer) {
            FileName = Fcb->AnsiFileName.Buffer;
        }
    }

⌨️ 快捷键说明

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