Annotation of ntddk/src/vdd/dosioctl/ioctlvdd/ioctlvdd.c, revision 1.1

1.1     ! root        1: /*++
        !             2: 
        !             3: Copyright (c) 1991, Microsoft Corporation
        !             4: 
        !             5: Module Name:
        !             6: 
        !             7:     ioctlvdd.c
        !             8: 
        !             9: Abstract:
        !            10: 
        !            11:     Virtual Device Driver for DOSIOCTL sample
        !            12: 
        !            13: Environment:
        !            14: 
        !            15:     NT-MVDM (User Mode VDD)
        !            16: 
        !            17: Notes:
        !            18: 
        !            19:     This VDD presents a private interface for the DOSDRVR component
        !            20:     of the DOSIOCTL sample. The three functions (OPEN, CLOSE, INFO)
        !            21:     correspond to calls that the DOSAPP in the sample makes. To show
        !            22:     how nicely symetrical a VDD can be architected, this VDD simply
        !            23:     converts each of these calls made by the DOS device driver into
        !            24:     NT-kernel device driver calls using WIN32 functions.
        !            25: 
        !            26:     Thus, when the DOS application of the sample issues a DOS OPEN,
        !            27:     the DOS driver gets the request and calls our entry point with
        !            28:     the VDD's VDDOPEN call. The VDD then calls the Win32 function
        !            29:     CreateFile() to get a handle to the NT driver in the sample.
        !            30: 
        !            31:     When the DOS application does an IOCTL read, the DOS driver
        !            32:     calls VDDINFO, which issues a Win32 DeviceIOControl() to the
        !            33:     NT driver, after getting a flat address for the application's
        !            34:     buffer.
        !            35: 
        !            36:     Finally, the DOSAPP's CLOSE is translated similarly to a WIN32
        !            37:     CloseHandle().
        !            38: 
        !            39:     Note that the functions VDDOPEN, VDDCLOSE and VDDINFO are not
        !            40:     architected in the NT VDD interface, and were invented just for
        !            41:     this sample. The interface between the DOS driver and the VDD
        !            42:     could have been defined completely differently. This VDD was
        !            43:     coded only to show one possibility for designing a VDD interface.
        !            44: 
        !            45: 
        !            46: --*/
        !            47: 
        !            48: 
        !            49: #include "ioctlvdd.h"
        !            50: #include "devioctl.h"
        !            51: 
        !            52: 
        !            53: BOOL
        !            54: VDDInitialize(
        !            55:     HANDLE hVdd,
        !            56:     DWORD dwReason,
        !            57:     LPVOID lpReserved
        !            58:     )
        !            59: 
        !            60: /*++
        !            61: 
        !            62: Routine Description:
        !            63: 
        !            64:     The entry point for the Vdd which handles intialization and termination.
        !            65: 
        !            66: Arguments:
        !            67: 
        !            68:     hVdd   - The handle to the VDD
        !            69: 
        !            70:     Reason - flag word that indicates why Dll Entry Point was invoked
        !            71: 
        !            72:     lpReserved - Unused
        !            73: 
        !            74: Return Value:
        !            75:     BOOL bRet - if (dwReason == DLL_PROCESS_ATTACH)
        !            76:                    TRUE    - Dll Intialization successful
        !            77:                    FALSE   - Dll Intialization failed
        !            78:                 else
        !            79:                    always returns TRUE
        !            80: --*/
        !            81: 
        !            82: {
        !            83:     HANDLE hDriver;
        !            84: 
        !            85:     switch ( dwReason ) {
        !            86: 
        !            87:         case DLL_PROCESS_ATTACH:
        !            88: 
        !            89: 
        !            90:             //
        !            91:             // The following call is here only to test the existence of
        !            92:             // the KRNLDRVR component. If it isn't there, then there is
        !            93:             // no reason to load.
        !            94:             //
        !            95: 
        !            96:             hDriver = CreateFile("\\\\.\\krnldrvr",    /* open KRNLDRVR      */
        !            97:                             GENERIC_READ | GENERIC_WRITE,  /* open for r/w   */
        !            98:                             0,                         /* can't share        */
        !            99:                             (LPSECURITY_ATTRIBUTES) NULL, /* no security     */
        !           100:                             OPEN_EXISTING,             /* existing file only */
        !           101:                             FILE_FLAG_OVERLAPPED,      /* overlapped I/O     */
        !           102:                             (HANDLE) NULL);            /* no attr template   */
        !           103: 
        !           104:             if (hDriver == INVALID_HANDLE_VALUE) {
        !           105:                 MessageBox (NULL, "Unable to locate Kernel driver",
        !           106:                         "Sample VDD", MB_OK | MB_ICONEXCLAMATION);
        !           107:                 return FALSE;                           /* Abort load       */
        !           108:                 }
        !           109: 
        !           110:             //
        !           111:             // The call to CreateFile succeeded, close the handle again
        !           112:             //
        !           113: 
        !           114:             CloseHandle (hDriver);
        !           115: 
        !           116:             break;
        !           117: 
        !           118:         default:
        !           119: 
        !           120:             break;
        !           121: 
        !           122:     }
        !           123: 
        !           124:     return TRUE;
        !           125: 
        !           126: }
        !           127: 
        !           128: 
        !           129: 
        !           130: VOID
        !           131: VDDRegisterInit(
        !           132:     VOID
        !           133:     )
        !           134: /*++
        !           135: 
        !           136: Arguments:
        !           137: 
        !           138: Return Value:
        !           139: 
        !           140:     SUCCESS - Client Carry Clear
        !           141:     FAILURE - Client Carry Set
        !           142: 
        !           143: --*/
        !           144: 
        !           145: 
        !           146: {
        !           147:     // This routine is called when the DOSDRVR issues the RegisterModule
        !           148:     // call.
        !           149: 
        !           150:     setCF(0);
        !           151:     return;
        !           152: }
        !           153: 
        !           154: 
        !           155: 
        !           156: VOID
        !           157: VDDDispatch(
        !           158:     VOID
        !           159:     )
        !           160: /*++
        !           161: 
        !           162: Routine Description:
        !           163: 
        !           164:     This subroutine implements the funcionality of the VDD. It handles
        !           165:     client VDM calls from the DOS driver. The operation is as follows:
        !           166: 
        !           167:     VDDOPEN - Issue Win32 CreateFile() to "krnldrvr"
        !           168:     VDDINFO - Issue Win32 DeviceIoControl() to "krnldrvr"
        !           169:     VDDCLOSE - Issue Win32 CloseHandle()
        !           170: 
        !           171: Arguments:
        !           172: 
        !           173:     Client (DX)    = Command code (VDDOPEN, VDDCLOSE, VDDINFO)
        !           174: 
        !           175:     For VDDINFO:
        !           176:     Client (ES:DI) = IOCTL Read Buffer address
        !           177:     Client (CX)    = Buffer Size
        !           178: 
        !           179: Return Value:
        !           180: 
        !           181:     SUCCESS - Client Carry Clear
        !           182:     FAILURE - Client Carry Set
        !           183: 
        !           184: --*/
        !           185: 
        !           186: 
        !           187: {
        !           188:     LPVOID  Buffer;
        !           189:     ULONG   VDMAddress;
        !           190:     DWORD   dwCount;
        !           191:     BOOL    Success = TRUE;
        !           192:     DWORD   BytesReturned;
        !           193:     static HANDLE hDriver = INVALID_HANDLE_VALUE;
        !           194: 
        !           195:     switch (getDX()) {
        !           196: 
        !           197:         case VDDOPEN:
        !           198: 
        !           199:             hDriver = CreateFile("\\\\.\\krnldrvr",    /* open KRNLDRVR      */
        !           200:                             GENERIC_READ | GENERIC_WRITE,  /* open for r/w   */
        !           201:                             0,                         /* can't share        */
        !           202:                             (LPSECURITY_ATTRIBUTES) NULL, /* no security     */
        !           203:                             OPEN_EXISTING,             /* existing file only */
        !           204:                             0,                         /* flags              */
        !           205:                             (HANDLE) NULL);            /* no attr template   */
        !           206: 
        !           207:             if (hDriver == INVALID_HANDLE_VALUE) {
        !           208:                 setCF(1);
        !           209:             } else
        !           210:                 setCF(0);
        !           211: 
        !           212:             break;
        !           213: 
        !           214:         case VDDCLOSE:
        !           215: 
        !           216:             if (hDriver != INVALID_HANDLE_VALUE) {
        !           217:                 CloseHandle (hDriver);
        !           218:                 hDriver = INVALID_HANDLE_VALUE;
        !           219:             }
        !           220: 
        !           221:             break;
        !           222: 
        !           223:         case VDDINFO:
        !           224: 
        !           225:             dwCount = (DWORD) getCX();
        !           226: 
        !           227:             VDMAddress = (ULONG) (getES()<<16 | getDI());
        !           228: 
        !           229:             Buffer = (LPVOID) GetVDMPointer (VDMAddress, dwCount, FALSE);
        !           230: 
        !           231:             Success = DeviceIoControl (hDriver,
        !           232:                 (DWORD) IOCTL_KRNLDRVR_GET_INFORMATION,
        !           233:                 (LPVOID) NULL, 0,
        !           234:                 Buffer, dwCount,
        !           235:                 &BytesReturned, (LPVOID) NULL);
        !           236: 
        !           237:             if (Success) {
        !           238:                 setCF(0);
        !           239:                 setCX((WORD)BytesReturned);
        !           240:             } else
        !           241:                 setCF(1);
        !           242: 
        !           243:             FreeVDMPointer (VDMAddress, dwCount, Buffer, FALSE);
        !           244: 
        !           245:             break;
        !           246: 
        !           247:         default:
        !           248:             setCF(1);
        !           249:     }
        !           250:     return;
        !           251: }
        !           252: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.