├── CTL ├── uSCSICtl.rc ├── resource.h ├── makefile ├── sources └── uSCSICtl.cpp ├── TEST ├── DIRS ├── WT │ ├── SOURCES │ ├── MAKEFILE │ └── WT.C ├── ANYW │ ├── MAKEFILE │ ├── SOURCES │ └── ANYW.C └── COMP │ ├── MAKEFILE │ ├── SOURCES │ └── Comp.c ├── DIRS ├── CPL ├── uSCSICpl.def ├── MTPadDoc.ico ├── resource.h ├── uSCSICpl.rc ├── sources ├── makefile └── uSCSICpl.cpp ├── README.md └── CONSOLE ├── res ├── Hat.ico ├── hh.gif ├── Thumbs.db ├── harddisks.bmp └── harddisks.png ├── makefile ├── console.rc ├── resource.h ├── Console.cpp ├── Monitor.h ├── SOURCES ├── console.exe.manifest ├── precomp.h ├── General.h ├── Extension.h ├── Session.h ├── Target.h └── Console.h /CTL/uSCSICtl.rc: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /TEST/DIRS: -------------------------------------------------------------------------------- 1 | DIRS=anyw wt comp -------------------------------------------------------------------------------- /DIRS: -------------------------------------------------------------------------------- 1 | DIRS= CTL CPL CONSOLE INSTALL -------------------------------------------------------------------------------- /CPL/uSCSICpl.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | CPlApplet @1 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # iSCSI_ctl 2 | iSCSI demo driver tools 3 | 4 | uitilities 5 | -------------------------------------------------------------------------------- /CTL/resource.h: -------------------------------------------------------------------------------- 1 | 2 | #define ID_USCSI_PORT 1000 3 | #define ID_USCSI_DRV 1001 -------------------------------------------------------------------------------- /CPL/MTPadDoc.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldoldman/iSCSI_ctl/HEAD/CPL/MTPadDoc.ico -------------------------------------------------------------------------------- /CONSOLE/res/Hat.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldoldman/iSCSI_ctl/HEAD/CONSOLE/res/Hat.ico -------------------------------------------------------------------------------- /CONSOLE/res/hh.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldoldman/iSCSI_ctl/HEAD/CONSOLE/res/hh.gif -------------------------------------------------------------------------------- /CONSOLE/res/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldoldman/iSCSI_ctl/HEAD/CONSOLE/res/Thumbs.db -------------------------------------------------------------------------------- /CPL/resource.h: -------------------------------------------------------------------------------- 1 | 2 | #define IDR_ICON 1000 3 | 4 | #define IDR_USCSI 1001 5 | #define IDR_DESC 1002 6 | -------------------------------------------------------------------------------- /CONSOLE/res/harddisks.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldoldman/iSCSI_ctl/HEAD/CONSOLE/res/harddisks.bmp -------------------------------------------------------------------------------- /CONSOLE/res/harddisks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldoldman/iSCSI_ctl/HEAD/CONSOLE/res/harddisks.png -------------------------------------------------------------------------------- /CPL/uSCSICpl.rc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | IDR_ICON ICON "MTPadDoc.ico" 4 | 5 | STRINGTABLE 6 | BEGIN 7 | IDR_USCSI "uSCSI" 8 | IDR_DESC "uSCSI Control Panel" 9 | END -------------------------------------------------------------------------------- /CPL/sources: -------------------------------------------------------------------------------- 1 | TARGETNAME=uSCSICpl 2 | TARGETTYPE=DYNLINK 3 | TARGETPATH=obj 4 | 5 | TARGETTEXT=cpl 6 | 7 | TARGETLIBS= $(SDK_LIB_PATH)\kernel32.lib \ 8 | $(SDK_LIB_PATH)\user32.lib 9 | 10 | SOURCES= uSCSICpl.cpp uSCSICpl.rc 11 | -------------------------------------------------------------------------------- /CPL/makefile: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source 3 | # file to this component. This file merely indirects to the real make file 4 | # that is shared by all the driver components of the Windows NT DDK 5 | # 6 | 7 | !INCLUDE $(NTMAKEENV)\makefile.def 8 | 9 | -------------------------------------------------------------------------------- /CTL/makefile: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source 3 | # file to this component. This file merely indirects to the real make file 4 | # that is shared by all the driver components of the Windows NT DDK 5 | # 6 | 7 | !INCLUDE $(NTMAKEENV)\makefile.def 8 | 9 | -------------------------------------------------------------------------------- /TEST/WT/SOURCES: -------------------------------------------------------------------------------- 1 | TARGETNAME=wt 2 | TARGETTYPE=PROGRAM 3 | TARGETPATH=obj 4 | 5 | UMTYPE=console 6 | UMENTRY=main 7 | 8 | USE_MSVCRT=1 9 | 10 | 11 | TARGETLIBS=$(SDK_LIB_PATH)\setupapi.lib \ 12 | $(SDK_LIB_PATH)\kernel32.lib \ 13 | $(SDK_LIB_PATH)\user32.lib 14 | 15 | SOURCES= wt.c 16 | -------------------------------------------------------------------------------- /CONSOLE/makefile: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source 3 | # file to this component. This file merely indirects to the real make file 4 | # that is shared by all the driver components of the Windows NT DDK 5 | # 6 | 7 | !INCLUDE $(NTMAKEENV)\makefile.def 8 | 9 | -------------------------------------------------------------------------------- /TEST/ANYW/MAKEFILE: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source 3 | # file to this component. This file merely indirects to the real make file 4 | # that is shared by all the driver components of the Windows NT DDK 5 | # 6 | 7 | !INCLUDE $(NTMAKEENV)\makefile.def 8 | 9 | -------------------------------------------------------------------------------- /TEST/ANYW/SOURCES: -------------------------------------------------------------------------------- 1 | TARGETNAME=anyw 2 | TARGETTYPE=PROGRAM 3 | TARGETPATH=obj 4 | 5 | UMTYPE=console 6 | UMENTRY=main 7 | 8 | USE_MSVCRT=1 9 | 10 | 11 | TARGETLIBS=$(SDK_LIB_PATH)\setupapi.lib \ 12 | $(SDK_LIB_PATH)\kernel32.lib \ 13 | $(SDK_LIB_PATH)\user32.lib 14 | 15 | SOURCES= anyw.c 16 | -------------------------------------------------------------------------------- /TEST/COMP/MAKEFILE: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source 3 | # file to this component. This file merely indirects to the real make file 4 | # that is shared by all the driver components of the Windows NT DDK 5 | # 6 | 7 | !INCLUDE $(NTMAKEENV)\makefile.def 8 | 9 | -------------------------------------------------------------------------------- /TEST/COMP/SOURCES: -------------------------------------------------------------------------------- 1 | TARGETNAME=comp 2 | TARGETTYPE=PROGRAM 3 | TARGETPATH=obj 4 | 5 | UMTYPE=console 6 | UMENTRY=main 7 | 8 | USE_MSVCRT=1 9 | 10 | 11 | TARGETLIBS=$(SDK_LIB_PATH)\setupapi.lib \ 12 | $(SDK_LIB_PATH)\kernel32.lib \ 13 | $(SDK_LIB_PATH)\user32.lib 14 | 15 | SOURCES= comp.c 16 | -------------------------------------------------------------------------------- /TEST/WT/MAKEFILE: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source 3 | # file to this component. This file merely indirects to the real make file 4 | # that is shared by all the driver components of the Windows NT DDK 5 | # 6 | 7 | !INCLUDE $(NTMAKEENV)\makefile.def 8 | 9 | -------------------------------------------------------------------------------- /CONSOLE/console.rc: -------------------------------------------------------------------------------- 1 | 2 | #include "resource.h" 3 | #include 4 | 5 | IDD_MAIN_DIALOG DIALOG 100,100,200,250 6 | Caption "uSCSI Management Console" 7 | { 8 | } 9 | 10 | LOGO PNG "res\\harddisks.png" 11 | APP ICON "res\\hat.ico" 12 | 13 | ATL_CREATEPROCESS_MANIFEST_RESOURCE_ID ATL_RT_MANIFEST "console.exe.manifest" 14 | -------------------------------------------------------------------------------- /CONSOLE/resource.h: -------------------------------------------------------------------------------- 1 | 2 | #define ID_USCSI_PORT 1000 3 | #define ID_USCSI_DRV 1001 4 | 5 | #define ID_VERSION 1002 6 | 7 | #define ID_SYS_PORT 1003 8 | #define ID_SYS_USCSI 1004 9 | #define ID_ABOUT 1005 10 | 11 | #define ID_MAIN 1006 12 | #define ID_PNG 1007 13 | 14 | #define IDD_MAIN_DIALOG 2000 15 | #define IDD_GENERALPAGE 2001 16 | -------------------------------------------------------------------------------- /CONSOLE/Console.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "console.h" 3 | 4 | CAppModule _Module; 5 | 6 | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR lpCmdLine, int nCmdShow) 7 | { 8 | CConsole Console; 9 | ::InitCommonControls(); 10 | _Module.Init(NULL, hInstance); 11 | 12 | int nRet = Console.DoModal(); 13 | 14 | _Module.Term(); 15 | return nRet; 16 | } -------------------------------------------------------------------------------- /CTL/sources: -------------------------------------------------------------------------------- 1 | TARGETNAME=uSCSICtl 2 | TARGETTYPE=PROGRAM 3 | TARGETPATH=. 4 | UMTYPE=console 5 | UMENTRY=main 6 | USER_C_FLAGS=/EHa 7 | USE_STL=1 8 | USE_MSVCRT=1 9 | INCLUDES=E:\SRC\DrvDev\uSCSI\uSCSI;E:\SRC\DrvDev\uSCSI\uSCSIPort;. 10 | 11 | TARGETLIBS=$(SDK_LIB_PATH)\setupapi.lib \ 12 | $(SDK_LIB_PATH)\kernel32.lib \ 13 | $(SDK_LIB_PATH)\user32.lib 14 | 15 | SOURCES= uSCSICtl.cpp uSCSICtl.rc 16 | -------------------------------------------------------------------------------- /CONSOLE/Monitor.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "precomp.h" 4 | 5 | class CMonitorPage : public CWindowImpl 6 | { 7 | public: 8 | DECLARE_WND_CLASS (_T("CMonitorPage") ) 9 | 10 | BEGIN_MSG_MAP(CMonitorPage) 11 | MESSAGE_HANDLER(WM_CREATE, OnCreate) 12 | END_MSG_MAP() 13 | 14 | LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 15 | { 16 | return 0; 17 | } 18 | private: 19 | 20 | }; -------------------------------------------------------------------------------- /CONSOLE/SOURCES: -------------------------------------------------------------------------------- 1 | TARGETNAME=iScsiConsole 2 | TARGETTYPE=PROGRAM 3 | TARGETPATH=.. 4 | #USER_C_FLAGS=/Za 5 | UMTYPE=windows 6 | UMENTRY=winmain 7 | USE_MSVCRT=1 8 | USE_ATL=1 9 | USE_WTL=1 10 | INCLUDES=.;$(DDK_INC_PATH); 11 | TARGETLIBS= $(SDK_LIB_PATH)\shell32.lib \ 12 | $(SDK_LIB_PATH)\comctl32.lib \ 13 | $(SDK_LIB_PATH)\oleaut32.lib \ 14 | $(SDK_LIB_PATH)\ole32.lib \ 15 | $(SDK_LIB_PATH)\comdlg32.lib \ 16 | $(SDK_LIB_PATH)\gdiplus.lib \ 17 | $(SDK_LIB_PATH)\msimg32.lib 18 | 19 | SOURCES= Console.cpp Console.rc 20 | -------------------------------------------------------------------------------- /CONSOLE/console.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | uSCSI console 6 | 7 | 8 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CONSOLE/precomp.h: -------------------------------------------------------------------------------- 1 | #ifndef _PRECOMP_H 2 | #define _PRECOMP_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #pragma comment(lib,"shell32.lib") 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "resource.h" 15 | 16 | CFont g_Font; 17 | 18 | 19 | #define MARGIN 10 20 | #define TABLE_TOP 30 21 | #define TABLE_WIDTH 350 22 | #define TABLE_HEIGHT 140 23 | #define TABLE_OFFSET 50 24 | 25 | #define LOGO_X 2*MARGIN 26 | #define LOGO_Y 300 + 2*MARGIN 27 | 28 | typedef enum _PAGE 29 | { 30 | General, 31 | Target, 32 | Session, 33 | Extension, 34 | Monitor, 35 | NumPages 36 | }PAGE; 37 | 38 | #define PAGE(p) m_Pages[p] 39 | 40 | #define GeneralPage ((CGeneralPage*)PAGE(General)) 41 | #define TargetPage ((CTargetPage*)PAGE(Target)) 42 | #define SessionPage ((CSessionPage*)PAGE(Session)) 43 | #define ExtensionPage ((CExtensionPage*)PAGE(Extension)) 44 | #define MonitorPage ((CMonitorPage*)PAGE(Monitor)) 45 | 46 | #endif -------------------------------------------------------------------------------- /TEST/WT/WT.C: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | void usage() 7 | { 8 | printf("wt:\n"); 9 | printf(" wt sourcefile\n"); 10 | exit(0); 11 | } 12 | 13 | unsigned char buf[512]; 14 | 15 | int __cdecl main ( int argc , char * args[]) 16 | { 17 | HANDLE dest , source; 18 | char *src_file; 19 | int src_len , totalr = 0 , totalw = 0; 20 | DWORD bytes; 21 | 22 | if ( argc != 2 ) 23 | usage(); 24 | 25 | dest = CreateFile ( "\\\\?\\E:\\Test_file" , 26 | GENERIC_WRITE , 27 | 0 , 28 | NULL , 29 | CREATE_ALWAYS , 30 | FILE_ATTRIBUTE_NORMAL|FILE_FLAG_WRITE_THROUGH , 31 | NULL); 32 | 33 | src_len = strlen( args[1]); 34 | src_file = malloc ( src_len + 4 ); 35 | wsprintf( src_file , "\\\\?\\%s" , args[1]); 36 | printf("Copy %s ...\n" , src_file); 37 | 38 | source = CreateFile ( src_file , 39 | GENERIC_READ , 40 | 0 , 41 | NULL , 42 | OPEN_EXISTING , 43 | FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING , 44 | NULL ); 45 | 46 | while(TRUE) 47 | { 48 | ReadFile ( source , buf , 512 , &bytes , NULL ); 49 | if ( bytes ) 50 | { 51 | totalr += bytes; 52 | printf ("read %d bytes\n" , bytes ); 53 | WriteFile( dest , buf , bytes , &bytes , NULL); 54 | totalw += bytes; 55 | printf ("write %d bytes\n" , bytes ); 56 | } 57 | else 58 | break; 59 | } 60 | printf("total read : %d , total write : %d\n" , totalr , totalw); 61 | CloseHandle ( source ); 62 | CloseHandle ( dest ); 63 | } -------------------------------------------------------------------------------- /CPL/uSCSICpl.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include "resource.h" 6 | 7 | HMODULE g_hModule = NULL; 8 | 9 | extern "C" BOOL APIENTRY DllMain( HANDLE hModule, 10 | DWORD ul_reason_for_call, 11 | LPVOID lpReserved ) 12 | { 13 | switch (ul_reason_for_call) 14 | { 15 | case DLL_PROCESS_ATTACH: 16 | g_hModule = (HMODULE) hModule; 17 | 18 | case DLL_THREAD_ATTACH: 19 | 20 | case DLL_THREAD_DETACH: 21 | 22 | case DLL_PROCESS_DETACH: 23 | break; 24 | } 25 | return TRUE; 26 | } 27 | 28 | extern "C" LONG CALLBACK CPlApplet(HWND hwndCPL, 29 | UINT message, 30 | LPARAM lParam1, 31 | LPARAM lParam2) 32 | { 33 | switch (message) 34 | { 35 | case CPL_INIT: 36 | 37 | return TRUE; 38 | 39 | case CPL_GETCOUNT: 40 | 41 | return 1; 42 | 43 | case CPL_INQUIRE: 44 | { 45 | LPCPLINFO Info = (LPCPLINFO)lParam2; 46 | Info->idIcon = IDR_ICON; 47 | Info->idName = IDR_USCSI; 48 | Info->idInfo = IDR_DESC; 49 | } 50 | return 0; 51 | 52 | case CPL_DBLCLK: 53 | { 54 | PROCESS_INFORMATION pi = {0}; 55 | if (CreateProcess("\\WINDOWS\\NOTEPAD.exe", 56 | NULL, 57 | NULL, 58 | NULL, 59 | FALSE, 60 | 0, 61 | NULL, 62 | NULL, 63 | NULL, 64 | &pi)) 65 | { 66 | CloseHandle(pi.hThread); 67 | CloseHandle(pi.hProcess); 68 | return 0; 69 | } 70 | return 1; // CPlApplet failed. 71 | } 72 | 73 | case CPL_STOP: 74 | case CPL_EXIT: 75 | 76 | default: 77 | return 0; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /TEST/ANYW/ANYW.C: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #define BUF_SIZE 1024 7 | 8 | unsigned char *buf; 9 | 10 | void Write(int count , int bsize) 11 | { 12 | int i , j; 13 | DWORD bytes; 14 | HANDLE file; 15 | 16 | file = CreateFile ( "\\\\?\\E:\\Test_file" , 17 | GENERIC_WRITE , 18 | 0 , 19 | NULL , 20 | CREATE_ALWAYS , 21 | FILE_ATTRIBUTE_NORMAL|FILE_FLAG_WRITE_THROUGH , 22 | NULL); 23 | 24 | for ( i = 0 ; i < count ; i++ ) 25 | { 26 | for ( j = 0 ; j < bsize ; j++ ) 27 | buf[j] = i & 0xFF ; 28 | 29 | WriteFile ( file , 30 | buf, 31 | bsize, 32 | &bytes, 33 | NULL ); 34 | 35 | printf("Pass %d write %d bytes\n" , i , bytes ); 36 | } 37 | 38 | CloseHandle (file); 39 | } 40 | 41 | void Read( int count , int bsize) 42 | { 43 | int i , j; 44 | DWORD bytes; 45 | HANDLE file; 46 | 47 | file = CreateFile ( "\\\\?\\E:\\Test_file" , 48 | GENERIC_READ , 49 | 0 , 50 | NULL , 51 | OPEN_EXISTING , 52 | FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING , 53 | NULL); 54 | 55 | for ( i = 0 ; i < count ; i++ ) 56 | { 57 | ReadFile ( file , 58 | buf, 59 | bsize, 60 | &bytes, 61 | NULL ); 62 | 63 | printf("Pass %d read %d bytes\n" , i , bytes ); 64 | 65 | for ( j = 0 ; j < (int)bytes ; j++ ) 66 | { 67 | if ( j && !(j & 0xf) ) 68 | printf("\n"); 69 | printf("%02X " , buf[j] ); 70 | } 71 | printf("\n"); 72 | 73 | } 74 | } 75 | 76 | void usage() 77 | { 78 | printf("Test:\n"); 79 | printf(" Test -[r|w] -b size -c count\n"); 80 | exit(0); 81 | } 82 | 83 | int __cdecl main ( int argc , char * args[]) 84 | { 85 | unsigned char Op; 86 | int i , count , bufsize; 87 | 88 | if ( argc != 6 ) 89 | usage(); 90 | 91 | for ( i = 1 ; i < 6 ; i++ ) 92 | { 93 | if (args[i][0] == '-' && args[i][1] == 'r' ) 94 | Op = 'R'; 95 | else if ( args[i][0] == '-' && args[i][1] == 'w') 96 | Op = 'W'; 97 | else if ( args[i][0] == '-' && args[i][1] == 'b' ) 98 | bufsize = atoi(args[++i]); 99 | else if (args[i][0] == '-' && args[i][1] == 'c' ) 100 | count = atoi( args[++i] ); 101 | else 102 | usage(); 103 | } 104 | 105 | if ( !bufsize || !count) 106 | usage(); 107 | 108 | buf = malloc (bufsize); 109 | 110 | if (Op == 'R') 111 | Read(count , bufsize); 112 | else if ( Op == 'W') 113 | Write(count , bufsize); 114 | else 115 | usage(); 116 | } -------------------------------------------------------------------------------- /TEST/COMP/Comp.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | void usage() 7 | { 8 | printf("Comp:\n"); 9 | printf(" Comp file1 file2\n"); 10 | exit(0); 11 | } 12 | 13 | void LastErr() 14 | { 15 | DWORD Error = GetLastError(); 16 | LPVOID lpMsgBuf; 17 | 18 | FormatMessage( 19 | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 20 | NULL, 21 | Error, 22 | MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), // Default language 23 | (LPTSTR) &lpMsgBuf, 24 | 0, 25 | NULL ); 26 | 27 | printf("(0x%X)%s" , Error , lpMsgBuf); 28 | LocalFree( lpMsgBuf ); 29 | } 30 | 31 | unsigned char buf1[512]; 32 | unsigned char buf2[512]; 33 | 34 | int __cdecl main ( int argc , char * args[]) 35 | { 36 | HANDLE file1 , file2; 37 | int i , j , k ; 38 | DWORD bytes , pos = 0x10; 39 | 40 | file1 = CreateFile ( "\\\\?\\D:\\d1.img" , 41 | GENERIC_READ , 42 | FILE_SHARE_READ|FILE_SHARE_WRITE , 43 | NULL , 44 | OPEN_EXISTING , 45 | FILE_ATTRIBUTE_NORMAL , 46 | NULL); 47 | if (file1 == INVALID_HANDLE_VALUE) 48 | { 49 | printf("open d1.img failed\n"); 50 | LastErr(); 51 | exit(0); 52 | } 53 | 54 | file2 = CreateFile ( "\\\\?\\D:\\d2.img" , 55 | GENERIC_READ , 56 | FILE_SHARE_READ|FILE_SHARE_WRITE , 57 | NULL , 58 | OPEN_EXISTING , 59 | FILE_ATTRIBUTE_NORMAL , 60 | NULL); 61 | 62 | if (file2 == INVALID_HANDLE_VALUE) 63 | { 64 | printf("open d2.img failed\n"); 65 | LastErr(); 66 | exit(0); 67 | } 68 | while (TRUE) 69 | { 70 | ReadFile ( file1 , buf1 , 512 , &bytes , NULL ); 71 | ReadFile ( file2 , buf2 , 512 , &bytes , NULL ); 72 | 73 | if ( !bytes ) 74 | break; 75 | 76 | for ( i = 0 ; i < (int)bytes ; i++ ) 77 | { 78 | if ( buf1[i] != buf2[i] ) 79 | { 80 | printf ("Start: 0x%X +0x%X\n" , ((pos + i) & ~0xF)>>4 , (pos + i) & 0xF); 81 | 82 | for ( j = i; j < (int)bytes ; j++ ) 83 | if ( buf1[j] == buf2[j] ) 84 | break; 85 | 86 | for ( k =i ; k < j ; k++ ) 87 | printf ("%02X " , buf1[k]); 88 | 89 | for ( k =i ; k < j ; k++ ) 90 | printf ("%C" , buf1[k]>=0x20 && buf1[k]<=0x7E ?buf1[k]:'.'); 91 | 92 | printf("\n"); 93 | 94 | for ( k =i ; k < j ; k++ ) 95 | printf ("%02X " , buf2[k]); 96 | for ( k =i ; k < j ; k++ ) 97 | printf ("%C" , buf2[k]>=0x20 && buf2[k]<=0x7E ?buf2[k]:'.'); 98 | printf("\n"); 99 | 100 | i = j; 101 | } 102 | } 103 | pos += bytes; 104 | } 105 | 106 | CloseHandle (file1); 107 | CloseHandle (file2); 108 | } -------------------------------------------------------------------------------- /CONSOLE/General.h: -------------------------------------------------------------------------------- 1 | 2 | #include "precomp.h" 3 | 4 | class CGeneralPage : public CWindowImpl 5 | { 6 | public: 7 | DECLARE_WND_CLASS (_T("CGeneralPage")) 8 | 9 | BEGIN_MSG_MAP(CGeneralPage) 10 | MESSAGE_HANDLER(WM_CREATE, OnCreate) 11 | MESSAGE_HANDLER(WM_PAINT, OnPaint) 12 | MESSAGE_HANDLER(WM_SIZE, OnSize) 13 | END_MSG_MAP() 14 | 15 | LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 16 | { 17 | RECT ClientRect; 18 | ::GetClientRect ( m_hWnd , &ClientRect); 19 | 20 | m_GeneralInfo.MoveWindow ( ClientRect.left + MARGIN, 21 | 10, 22 | ClientRect.right - ClientRect.left - 2*MARGIN , 23 | 280); 24 | 25 | m_About.MoveWindow ( ClientRect.left + MARGIN, 26 | 300, 27 | ClientRect.right - ClientRect.left - 2*MARGIN , 28 | 110); 29 | 30 | m_Info.MoveWindow ( LOGO_X + m_Logo.GetWidth() + MARGIN, 31 | 300 + 2*MARGIN, 32 | ClientRect.right - ClientRect.left - 5*MARGIN - m_Logo.GetWidth(), 33 | 70); 34 | return 1; 35 | } 36 | 37 | LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 38 | { 39 | IStream *Stream; 40 | HRSRC Logo; 41 | DWORD LogoSize; 42 | LPVOID LogoData , LogoData2; 43 | HGLOBAL LogoHandle; 44 | 45 | Logo = ::FindResource ( NULL , "LOGO" , "PNG"); 46 | LogoSize = ::SizeofResource ( NULL , Logo ); 47 | LogoData = ::LockResource ( ::LoadResource ( NULL , Logo ) ); 48 | if ( LogoData ) 49 | { 50 | LogoHandle = ::GlobalAlloc(GMEM_MOVEABLE, LogoSize); 51 | if ( LogoHandle ) 52 | { 53 | LogoData2 = ::GlobalLock( LogoHandle ); 54 | CopyMemory ( LogoData2, LogoData , LogoSize); 55 | ::CreateStreamOnHGlobal ( LogoHandle , FALSE , &Stream ); 56 | } 57 | } 58 | m_Logo.Load ( Stream ); 59 | 60 | m_GeneralInfo.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE |BS_GROUPBOX ); 61 | m_GeneralInfo.SetFont ( g_Font ); 62 | m_GeneralInfo.SetWindowText ("Initiator Settings"); 63 | 64 | m_About.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE |BS_GROUPBOX ); 65 | m_About.SetFont ( g_Font ); 66 | m_About.SetWindowText ("About"); 67 | 68 | m_Info.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 69 | m_Info.SetFont ( g_Font ); 70 | m_Info.SetWindowText ("uSCSI Mamagement Console\nVersion: 1.0.0.0\nAuthor: yushang"); 71 | 72 | if (LogoHandle) 73 | ::GlobalFree (LogoHandle); 74 | return 1; 75 | } 76 | 77 | LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 78 | { 79 | RECT Rect; 80 | CClientDC Dc(m_hWnd); 81 | 82 | m_Logo.Draw ( Dc , LOGO_X , LOGO_Y); 83 | ::SetRect ( &Rect , LOGO_X , LOGO_Y , LOGO_X+m_Logo.GetWidth() ,LOGO_Y+ m_Logo.GetHeight() ); 84 | ValidateRect ( &Rect ); 85 | bHandled = FALSE; 86 | 87 | return 0; 88 | } 89 | 90 | private: 91 | CButton m_GeneralInfo , m_About; 92 | CImage m_Logo; 93 | CStatic m_Info; 94 | }; -------------------------------------------------------------------------------- /CONSOLE/Extension.h: -------------------------------------------------------------------------------- 1 | 2 | #include "precomp.h" 3 | 4 | class CExtensionPage : public CWindowImpl 5 | { 6 | public: 7 | DECLARE_WND_CLASS (_T("CExtensionPage")) 8 | 9 | BEGIN_MSG_MAP(CExtensionPage) 10 | MESSAGE_HANDLER(WM_CREATE, OnCreate) 11 | MESSAGE_HANDLER(WM_SIZE, OnSize) 12 | END_MSG_MAP() 13 | 14 | LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 15 | { 16 | RECT ClientRect; 17 | ::GetClientRect ( m_hWnd , &ClientRect); 18 | 19 | m_TxtExt.MoveWindow ( ClientRect.left + MARGIN, 20 | TABLE_TOP - 20, 21 | ClientRect.right - ClientRect.left - 2*MARGIN , 22 | 20 ); 23 | 24 | m_Ext.MoveWindow ( ClientRect.left + MARGIN , 25 | TABLE_TOP , 26 | ClientRect.right - ClientRect.left - 2*MARGIN, 27 | TABLE_HEIGHT); 28 | 29 | m_TxtAuth.MoveWindow ( ClientRect.left + MARGIN , 30 | TABLE_TOP + TABLE_HEIGHT + TABLE_OFFSET - 20 , 31 | ClientRect.right - ClientRect.left - 2*MARGIN, 32 | TABLE_HEIGHT); 33 | 34 | m_Auth.MoveWindow ( ClientRect.left + MARGIN , 35 | TABLE_TOP + TABLE_HEIGHT + TABLE_OFFSET , 36 | ClientRect.right - ClientRect.left - 2*MARGIN, 37 | TABLE_HEIGHT); 38 | 39 | // 40 | // 41 | // 42 | m_ExtAdd.MoveWindow ( ClientRect.right - MARGIN - 80, 43 | TABLE_TOP + TABLE_HEIGHT + 10, 44 | 80, 45 | 21); 46 | 47 | m_ExtRemove.MoveWindow ( ClientRect.right - MARGIN - 2*80 - 10, 48 | TABLE_TOP + TABLE_HEIGHT + 10, 49 | 80, 50 | 21); 51 | // 52 | // 53 | // 54 | m_AuthAdd.MoveWindow ( ClientRect.right - MARGIN - 80, 55 | TABLE_TOP + 2*TABLE_HEIGHT + TABLE_OFFSET + 10, 56 | 80, 57 | 21); 58 | 59 | m_AuthRemove.MoveWindow ( ClientRect.right - MARGIN - 2*80 - 10, 60 | TABLE_TOP + 2*TABLE_HEIGHT + TABLE_OFFSET + 10, 61 | 80, 62 | 21); 63 | return 1; 64 | } 65 | 66 | LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 67 | { 68 | m_TxtExt.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 69 | m_TxtExt.SetFont ( g_Font ); 70 | m_TxtExt.SetWindowText ("ExtModule List"); 71 | 72 | m_Ext.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE |WS_BORDER|LVS_REPORT ); 73 | m_Ext.SetFont ( g_Font ); 74 | m_Ext.InsertColumn ( 0 , _T("Command") , LVCFMT_LEFT , 100); 75 | m_Ext.InsertColumn ( 1 , _T("Module") , LVCFMT_LEFT , 100); 76 | 77 | m_TxtAuth.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 78 | m_TxtAuth.SetFont ( g_Font ); 79 | m_TxtAuth.SetWindowText ("AuthMethod List"); 80 | 81 | m_Auth.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE |WS_BORDER|LVS_REPORT ); 82 | m_Auth.SetFont ( g_Font ); 83 | m_Auth.InsertColumn ( 0 , _T("AuthMethod") , LVCFMT_LEFT , 100); 84 | m_Auth.InsertColumn ( 1 , _T("Status") , LVCFMT_LEFT , 100); 85 | 86 | 87 | m_ExtRemove.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 88 | m_ExtRemove.SetFont ( g_Font ); 89 | m_ExtRemove.SetWindowText ("Remove"); 90 | 91 | m_ExtAdd.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 92 | m_ExtAdd.SetFont ( g_Font ); 93 | m_ExtAdd.SetWindowText ("Add"); 94 | 95 | m_AuthRemove.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 96 | m_AuthRemove.SetFont ( g_Font ); 97 | m_AuthRemove.SetWindowText ("Remove"); 98 | 99 | m_AuthAdd.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 100 | m_AuthAdd.SetFont ( g_Font ); 101 | m_AuthAdd.SetWindowText ("Add"); 102 | 103 | return 1; 104 | } 105 | 106 | private: 107 | CStatic m_TxtExt , m_TxtAuth; 108 | CListViewCtrl m_Ext , m_Auth; 109 | CButton m_ExtRemove , m_ExtAdd ; 110 | CButton m_AuthRemove , m_AuthAdd ; 111 | 112 | }; -------------------------------------------------------------------------------- /CONSOLE/Session.h: -------------------------------------------------------------------------------- 1 | 2 | #include "precomp.h" 3 | 4 | class CSessionPage : public CWindowImpl 5 | { 6 | public: 7 | DECLARE_WND_CLASS (_T("CSessionPage")) 8 | 9 | BEGIN_MSG_MAP(CSessionPage) 10 | MESSAGE_HANDLER(WM_CREATE, OnCreate) 11 | MESSAGE_HANDLER(WM_SIZE, OnSize) 12 | END_MSG_MAP() 13 | 14 | LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 15 | { 16 | RECT ClientRect; 17 | ::GetClientRect ( m_hWnd , &ClientRect); 18 | 19 | m_TxtSession.MoveWindow ( ClientRect.left + MARGIN, 20 | TABLE_TOP - 20, 21 | ClientRect.right - ClientRect.left - 2*MARGIN , 22 | 20 ); 23 | 24 | m_Session.MoveWindow ( ClientRect.left + MARGIN , 25 | TABLE_TOP , 26 | ClientRect.right - ClientRect.left - 2*MARGIN, 27 | TABLE_HEIGHT); 28 | 29 | m_TxtConnection.MoveWindow ( ClientRect.left + MARGIN , 30 | TABLE_TOP + TABLE_HEIGHT + TABLE_OFFSET - 20 , 31 | ClientRect.right - ClientRect.left - 2*MARGIN, 32 | TABLE_HEIGHT); 33 | 34 | m_Connection.MoveWindow ( ClientRect.left + MARGIN , 35 | TABLE_TOP + TABLE_HEIGHT + TABLE_OFFSET , 36 | ClientRect.right - ClientRect.left - 2*MARGIN, 37 | TABLE_HEIGHT); 38 | 39 | // 40 | // 41 | // 42 | m_SessionAdd.MoveWindow ( ClientRect.right - MARGIN - 80, 43 | TABLE_TOP + TABLE_HEIGHT + 10, 44 | 80, 45 | 21); 46 | 47 | m_SessionRemove.MoveWindow ( ClientRect.right - MARGIN - 2*80 - 10, 48 | TABLE_TOP + TABLE_HEIGHT + 10, 49 | 80, 50 | 21); 51 | // 52 | // 53 | // 54 | m_ConAdd.MoveWindow ( ClientRect.right - MARGIN - 80, 55 | TABLE_TOP + 2*TABLE_HEIGHT + TABLE_OFFSET + 10, 56 | 80, 57 | 21); 58 | 59 | m_ConRemove.MoveWindow ( ClientRect.right - MARGIN - 2*80 - 10, 60 | TABLE_TOP + 2*TABLE_HEIGHT + TABLE_OFFSET + 10, 61 | 80, 62 | 21); 63 | return 1; 64 | } 65 | 66 | LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 67 | { 68 | m_TxtSession.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 69 | m_TxtSession.SetFont ( g_Font ); 70 | m_TxtSession.SetWindowText ("Session List"); 71 | 72 | m_Session.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE |WS_BORDER|LVS_REPORT ); 73 | m_Session.SetFont ( g_Font ); 74 | m_Session.InsertColumn ( 0 , _T("Session#") , LVCFMT_LEFT , 70); 75 | m_Session.InsertColumn ( 1 , _T("Status") , LVCFMT_LEFT , 50); 76 | m_Session.InsertColumn ( 2 , _T("Target") , LVCFMT_LEFT , 200); 77 | 78 | m_TxtConnection.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 79 | m_TxtConnection.SetFont ( g_Font ); 80 | m_TxtConnection.SetWindowText ("Connection List"); 81 | 82 | m_Connection.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE |WS_BORDER|LVS_REPORT ); 83 | m_Connection.SetFont ( g_Font ); 84 | m_Connection.InsertColumn ( 0 , _T("Connection#") , LVCFMT_LEFT , 100); 85 | m_Connection.InsertColumn ( 1 , _T("Status") , LVCFMT_LEFT , 50); 86 | m_Connection.InsertColumn ( 2 , _T("Adapter") , LVCFMT_RIGHT , 100); 87 | 88 | m_SessionRemove.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 89 | m_SessionRemove.SetFont ( g_Font ); 90 | m_SessionRemove.SetWindowText ("Remove"); 91 | 92 | m_SessionAdd.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 93 | m_SessionAdd.SetFont ( g_Font ); 94 | m_SessionAdd.SetWindowText ("Add"); 95 | 96 | m_ConRemove.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 97 | m_ConRemove.SetFont ( g_Font ); 98 | m_ConRemove.SetWindowText ("Remove"); 99 | 100 | m_ConAdd.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 101 | m_ConAdd.SetFont ( g_Font ); 102 | m_ConAdd.SetWindowText ("Add"); 103 | 104 | return 1; 105 | } 106 | 107 | private: 108 | CStatic m_TxtSession , m_TxtConnection; 109 | CListViewCtrl m_Session , m_Connection; 110 | CButton m_SessionAdd , m_SessionRemove; 111 | CButton m_ConAdd , m_ConRemove; 112 | 113 | }; -------------------------------------------------------------------------------- /CONSOLE/Target.h: -------------------------------------------------------------------------------- 1 | 2 | #include "precomp.h" 3 | 4 | class CTargetPage : public CWindowImpl 5 | { 6 | public: 7 | DECLARE_WND_CLASS (_T("CTargetPage")) 8 | 9 | BEGIN_MSG_MAP(CTargetPage) 10 | MESSAGE_HANDLER(WM_CREATE, OnCreate) 11 | MESSAGE_HANDLER(WM_SIZE, OnSize) 12 | MESSAGE_HANDLER(WM_COMMAND, OnCommand) 13 | END_MSG_MAP() 14 | 15 | LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 16 | { 17 | ::EndDialog ( GetParent().GetParent() , 0); 18 | return 0; 19 | } 20 | 21 | LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 22 | { 23 | RECT ClientRect; 24 | ::GetClientRect ( m_hWnd , &ClientRect); 25 | 26 | m_TxtPortal.MoveWindow ( ClientRect.left + MARGIN, 27 | TABLE_TOP - 20, 28 | ClientRect.right - ClientRect.left - 2*MARGIN , 29 | 20 ); 30 | 31 | m_Portal.MoveWindow ( ClientRect.left + MARGIN , 32 | TABLE_TOP , 33 | ClientRect.right - ClientRect.left - 2*MARGIN, 34 | TABLE_HEIGHT); 35 | 36 | m_TxtTarget.MoveWindow ( ClientRect.left + MARGIN , 37 | TABLE_TOP + TABLE_HEIGHT + TABLE_OFFSET - 20 , 38 | ClientRect.right - ClientRect.left - 2*MARGIN, 39 | TABLE_HEIGHT); 40 | 41 | m_Target.MoveWindow ( ClientRect.left + MARGIN , 42 | TABLE_TOP + TABLE_HEIGHT + TABLE_OFFSET , 43 | ClientRect.right - ClientRect.left - 2*MARGIN, 44 | TABLE_HEIGHT); 45 | 46 | m_TgtAdd.MoveWindow ( ClientRect.right - MARGIN - 80, 47 | TABLE_TOP + 2*TABLE_HEIGHT + TABLE_OFFSET + 10, 48 | 80, 49 | 21); 50 | 51 | m_TgtRemove.MoveWindow ( ClientRect.right - MARGIN - 2*80 - 10, 52 | TABLE_TOP + 2*TABLE_HEIGHT + TABLE_OFFSET + 10, 53 | 80, 54 | 21); 55 | 56 | m_PAdd.MoveWindow ( ClientRect.right - MARGIN - 80, 57 | TABLE_TOP + TABLE_HEIGHT + 10, 58 | 80, 59 | 21); 60 | 61 | m_PRemove.MoveWindow ( ClientRect.right - MARGIN - 2*80 - 10, 62 | TABLE_TOP + TABLE_HEIGHT + 10, 63 | 80, 64 | 21); 65 | 66 | m_PRefresh.MoveWindow ( ClientRect.right - MARGIN - 3*80 - 2*10, 67 | TABLE_TOP + TABLE_HEIGHT + 10, 68 | 80, 69 | 21); 70 | 71 | return 1; 72 | } 73 | 74 | LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 75 | { 76 | RECT ClientRect; 77 | ::GetClientRect ( m_hWnd , &ClientRect); 78 | 79 | m_TxtPortal.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 80 | m_TxtPortal.SetFont ( g_Font ); 81 | m_TxtPortal.SetWindowText ("Portal List"); 82 | 83 | m_Portal.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE |WS_BORDER|LVS_REPORT ); 84 | m_Portal.SetFont ( g_Font ); 85 | m_Portal.InsertColumn ( 0 , _T("Address") , LVCFMT_LEFT , 100); 86 | m_Portal.InsertColumn ( 1 , _T("Port") , LVCFMT_LEFT , 100); 87 | m_Portal.InsertColumn ( 2 , _T("IpAddress") , LVCFMT_LEFT , 100); 88 | 89 | m_TxtTarget.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 90 | m_TxtTarget.SetFont ( g_Font ); 91 | m_TxtTarget.SetWindowText ("Target List"); 92 | 93 | m_Target.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE |WS_BORDER|LVS_REPORT ); 94 | m_Target.SetFont ( g_Font ); 95 | m_Target.InsertColumn ( 0 , _T("Target") , LVCFMT_LEFT , 150); 96 | m_Target.InsertColumn ( 1 , _T("Status") , LVCFMT_LEFT , 100); 97 | m_Target.InsertColumn ( 2 , _T("Address") , LVCFMT_LEFT , 100); 98 | m_Target.InsertColumn ( 3 , _T("Port") , LVCFMT_LEFT , 100); 99 | 100 | m_TgtRemove.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 101 | m_TgtRemove.SetFont ( g_Font ); 102 | m_TgtRemove.SetWindowText ("Remove"); 103 | 104 | m_TgtAdd.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 105 | m_TgtAdd.SetFont ( g_Font ); 106 | m_TgtAdd.SetWindowText ("Add"); 107 | 108 | // 109 | // 110 | // 111 | m_PRefresh.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 112 | m_PRefresh.SetFont ( g_Font ); 113 | m_PRefresh.SetWindowText ("Refresh"); 114 | 115 | m_PRemove.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 116 | m_PRemove.SetFont ( g_Font ); 117 | m_PRemove.SetWindowText ("Remove"); 118 | 119 | m_PAdd.Create ( m_hWnd , NULL , NULL , WS_CHILD | WS_VISIBLE ); 120 | m_PAdd.SetFont ( g_Font ); 121 | m_PAdd.SetWindowText ("Add"); 122 | 123 | return 1; 124 | } 125 | 126 | private: 127 | CStatic m_TxtPortal , m_TxtTarget; 128 | CListViewCtrl m_Portal , m_Target; 129 | CButton m_TgtAdd , m_TgtRemove; 130 | CButton m_PRefresh , m_PAdd , m_PRemove; 131 | }; -------------------------------------------------------------------------------- /CONSOLE/Console.h: -------------------------------------------------------------------------------- 1 | 2 | #include "precomp.h" 3 | 4 | #include "General.h" 5 | #include "Target.h" 6 | #include "Session.h" 7 | #include "Extension.h" 8 | #include "Monitor.h" 9 | 10 | class CConsole : public CDialogImpl 11 | { 12 | public: 13 | 14 | enum {IDD = IDD_MAIN_DIALOG }; 15 | 16 | BEGIN_MSG_MAP(CConsole) 17 | MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) 18 | MESSAGE_HANDLER(WM_CREATE, OnCreate) 19 | MESSAGE_HANDLER(WM_COMMAND, OnCommand) 20 | NOTIFY_CODE_HANDLER(TCN_SELCHANGE , OnPageChanged) 21 | NOTIFY_CODE_HANDLER(TCN_SELCHANGING , OnPageChanging) 22 | END_MSG_MAP() 23 | 24 | CConsole():m_CurrentPage(0) 25 | { 26 | LOGFONT LogFont; 27 | 28 | memset ( &LogFont , 0 , sizeof (LOGFONT)); 29 | LogFont.lfHeight = 15; 30 | strcpy ( LogFont.lfFaceName , "Arial"); 31 | 32 | g_Font.CreateFontIndirect( &LogFont ); 33 | 34 | for (int i = 0 ; i < NumPages ; i++ ) 35 | m_Pages[i] = NULL; 36 | 37 | } 38 | 39 | VOID LayOutDialogBox() 40 | { 41 | CWindow DialogBox = m_hWnd; 42 | RECT rect; 43 | UINT i; 44 | 45 | DialogBox.GetClientRect (&m_ClientBound); 46 | 47 | m_MainTab.rcDefault.left = m_ClientBound.left + 10; 48 | m_MainTab.rcDefault.top = m_ClientBound.top + 10; 49 | m_MainTab.rcDefault.right = m_ClientBound.right - 10; 50 | m_MainTab.rcDefault.bottom = m_ClientBound.bottom - 40; 51 | 52 | m_MainTab.Create ( DialogBox , 53 | NULL , 54 | NULL , 55 | WS_CHILD | WS_VISIBLE | TCS_MULTILINE ); 56 | m_MainTab.SetFont ( g_Font ); 57 | 58 | m_MainTab.AddItem("General"); 59 | m_MainTab.AddItem("Targets"); 60 | m_MainTab.AddItem("Session"); 61 | m_MainTab.AddItem("Extension"); 62 | m_MainTab.AddItem("Monitor"); 63 | 64 | m_MainTab.GetClientRect( &m_TabBound ); 65 | m_MainTab.GetItemRect ( 0 , &rect); 66 | 67 | m_TabBound.left += 5; 68 | m_TabBound.top += ( (rect.bottom - rect.top ) *m_MainTab.GetRowCount() + 5 ); 69 | m_TabBound.right -= 5; 70 | m_TabBound.bottom -= 5; 71 | 72 | PAGE(General) = new CGeneralPage; 73 | PAGE(Target) = new CTargetPage; 74 | PAGE(Session) = new CSessionPage; 75 | PAGE(Extension) = new CExtensionPage; 76 | PAGE(Monitor) = new CMonitorPage; 77 | // 78 | GeneralPage->Create ( m_MainTab , NULL , NULL , WS_CHILD | WS_VISIBLE ); 79 | GeneralPage->MoveWindow ( m_TabBound.left , 80 | m_TabBound.top , 81 | m_TabBound.right - m_TabBound.left , 82 | m_TabBound.bottom - m_TabBound.top ); 83 | // 84 | TargetPage->Create ( m_MainTab , NULL , NULL , WS_CHILD ); 85 | TargetPage->MoveWindow (m_TabBound.left , 86 | m_TabBound.top , 87 | m_TabBound.right - m_TabBound.left , 88 | m_TabBound.bottom - m_TabBound.top); 89 | // 90 | SessionPage->Create ( m_MainTab , NULL , NULL , WS_CHILD ); 91 | SessionPage->SetWindowPos ( NULL , 92 | m_TabBound.left , 93 | m_TabBound.top , 94 | m_TabBound.right - m_TabBound.left , 95 | m_TabBound.bottom - m_TabBound.top , 96 | SWP_HIDEWINDOW); 97 | // 98 | ExtensionPage->Create ( m_MainTab , NULL , NULL , WS_CHILD ); 99 | ExtensionPage->SetWindowPos ( NULL , 100 | m_TabBound.left , 101 | m_TabBound.top , 102 | m_TabBound.right - m_TabBound.left , 103 | m_TabBound.bottom - m_TabBound.top , 104 | SWP_HIDEWINDOW); 105 | // 106 | 107 | MonitorPage->Create ( m_MainTab , NULL , NULL , WS_CHILD ); 108 | MonitorPage->SetWindowPos ( NULL , 109 | m_TabBound.left , 110 | m_TabBound.top , 111 | m_TabBound.right - m_TabBound.left , 112 | m_TabBound.bottom - m_TabBound.top , 113 | SWP_HIDEWINDOW); 114 | // 115 | 116 | // 117 | 118 | m_Ok.rcDefault.right = m_ClientBound.right - 10; 119 | m_Ok.rcDefault.left = m_Ok.rcDefault.right - 80; 120 | m_Ok.rcDefault.bottom = m_ClientBound.bottom - 10; 121 | m_Ok.rcDefault.top = m_Ok.rcDefault.bottom - 21; 122 | m_Ok.Create ( DialogBox , 123 | NULL , 124 | NULL , 125 | WS_CHILD | WS_VISIBLE ); 126 | m_Ok.SetFont ( g_Font ); 127 | m_Ok.SetWindowText(_T("OK")); 128 | 129 | } 130 | 131 | 132 | LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 133 | { 134 | SetFont ( g_Font ); 135 | SetIcon( ::LoadIcon(NULL , "APP") , FALSE ); 136 | return 1; 137 | } 138 | 139 | LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 140 | { 141 | LayOutDialogBox(); 142 | return 1; 143 | } 144 | 145 | LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 146 | { 147 | EndDialog (0); 148 | return 1; 149 | } 150 | 151 | VOID ShowPage(int ShowHide ) 152 | { 153 | CWindow* CurrentPage; 154 | CurrentPage = PAGE(m_CurrentPage); 155 | 156 | if (CurrentPage) 157 | CurrentPage->ShowWindow( ShowHide ); 158 | } 159 | 160 | LRESULT OnPageChanged(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) 161 | { 162 | m_CurrentPage = m_MainTab.GetCurSel(); 163 | ShowPage(SW_SHOW); 164 | return 0; 165 | } 166 | 167 | LRESULT OnPageChanging(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) 168 | { 169 | //Returns TRUE to prevent the selection from changing, 170 | // or FALSE to allow the selection to change 171 | ShowPage(SW_HIDE); 172 | return FALSE; 173 | } 174 | 175 | private: 176 | UINT m_CurrentPage; 177 | RECT m_ClientBound , m_TabBound; 178 | CButton m_Ok; 179 | CTabCtrl m_MainTab; 180 | CWindow *m_Pages[NumPages]; 181 | }; -------------------------------------------------------------------------------- /CTL/uSCSICtl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "public.h" 7 | 8 | using namespace std; 9 | 10 | void LastErr(LPCTSTR Prefix = NULL ) 11 | { 12 | DWORD Error = GetLastError(); 13 | LPVOID lpMsgBuf; 14 | 15 | FormatMessage( 16 | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 17 | NULL, 18 | Error, 19 | MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), // Default language 20 | (LPTSTR) &lpMsgBuf, 21 | 0, 22 | NULL ); 23 | 24 | cout << Prefix << " " << hex << showbase << Error << lpMsgBuf << endl; 25 | LocalFree( lpMsgBuf ); 26 | } 27 | 28 | // 29 | // 30 | // 31 | 32 | HANDLE OpenDevice() 33 | { 34 | DWORD bytes = 0, cnt = 0; 35 | HANDLE file; 36 | HDEVINFO devinfo; 37 | SP_DEVINFO_DATA devinfodata; 38 | SP_DEVICE_INTERFACE_DATA devitfcdata; 39 | PSP_DEVICE_INTERFACE_DETAIL_DATA devitfcdatadtl; 40 | 41 | devinfo = SetupDiGetClassDevs(&USCSI_DISK_INTERFACE , 42 | NULL , 43 | NULL , 44 | DIGCF_DEVICEINTERFACE| DIGCF_PRESENT); 45 | if ( INVALID_HANDLE_VALUE == devinfo ) 46 | { 47 | LastErr("SetupDiGetClassDevs"); 48 | return NULL; 49 | } 50 | 51 | devinfodata.cbSize = sizeof(devinfodata); 52 | devitfcdata.cbSize = sizeof(devitfcdata); 53 | 54 | while(SetupDiEnumDeviceInterfaces( devinfo , 55 | NULL , 56 | &USCSI_DISK_INTERFACE, 57 | cnt++, 58 | &devitfcdata)) 59 | { 60 | DWORD required_size; 61 | 62 | SetupDiGetDeviceInterfaceDetail(devinfo, 63 | &devitfcdata, 64 | NULL, 65 | 0, 66 | &required_size, 67 | NULL); 68 | devitfcdatadtl = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc (required_size); 69 | devitfcdatadtl->cbSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA); 70 | 71 | if(SetupDiGetDeviceInterfaceDetail(devinfo, 72 | &devitfcdata, 73 | devitfcdatadtl, 74 | required_size, 75 | &required_size, 76 | &devinfodata)) 77 | { 78 | 79 | file = CreateFile( 80 | devitfcdatadtl->DevicePath, 81 | GENERIC_READ|GENERIC_WRITE, // Only read access 82 | 0, // FILE_SHARE_READ | FILE_SHARE_WRITE 83 | NULL, // no SECURITY_ATTRIBUTES structure 84 | OPEN_EXISTING, // No special create flags 85 | 0, // No special attributes 86 | NULL); 87 | 88 | free (devitfcdatadtl); 89 | 90 | if (INVALID_HANDLE_VALUE != file) 91 | return file; 92 | else 93 | LastErr("OpenDevice"); 94 | } 95 | else 96 | LastErr("SetupDiGetDeviceInterfaceDetail"); 97 | } 98 | 99 | return NULL; 100 | } 101 | 102 | 103 | VOID AddTarget( PUCHAR Target , ULONG IpAddr , USHORT Port ) 104 | { 105 | PTGTS Tgts; 106 | PTGT Tgt; 107 | ULONG Size; 108 | HANDLE Device; 109 | DWORD Bytes; 110 | 111 | Size = strlen((char*)Target) + 1 + sizeof (TGTS) + sizeof (TGT); 112 | Tgts = (PTGTS)malloc ( Size ); 113 | 114 | if ( Tgts ) 115 | { 116 | Tgts->Count = 1; 117 | Tgts->Size = Size; 118 | 119 | Tgt = (PTGT)(Tgts + 1); 120 | Tgt->TargetName = (PUCHAR)( Tgt + 1 ); 121 | 122 | strcpy ( (char*)Tgt->TargetName , (char*)Target ); 123 | Tgt->Addr = IpAddr; 124 | Tgt->Port = Port; 125 | 126 | Device = OpenDevice(); 127 | 128 | if (Device) 129 | { 130 | if(!DeviceIoControl( Device , 131 | IOCTL_ISCSI_ADD_TARGETS , 132 | Tgts, 133 | Size, 134 | NULL, 135 | 0, 136 | &Bytes, 137 | NULL)) 138 | LastErr("DeviceIoControl"); 139 | else 140 | cout << "Target " << Tgt->TargetName << "@" << Tgt->Addr << ":" << Tgt->Port << " added" << endl; 141 | } 142 | else 143 | goto Out; 144 | } 145 | 146 | Out: 147 | if ( Tgts ) 148 | free ( Tgts ); 149 | if ( Device ) 150 | CloseHandle ( Device); 151 | } 152 | 153 | VOID GetTargets() 154 | { 155 | TGTS Tgts; 156 | PTGTS Tgts2; 157 | PTGT Tgt; 158 | HANDLE Device; 159 | DWORD Bytes; 160 | ULONG i; 161 | 162 | Device = OpenDevice(); 163 | 164 | if (Device) 165 | { 166 | while (TRUE) 167 | { 168 | Tgts.Size = 0; 169 | 170 | if(!DeviceIoControl( Device , 171 | IOCTL_ISCSI_GET_TARGETS , 172 | &Tgts, 173 | sizeof (TGTS), 174 | &Tgts, 175 | sizeof (TGTS), 176 | &Bytes, 177 | NULL)) 178 | { 179 | LastErr("DeviceIoControl"); 180 | } 181 | else if (!Tgts.Size) 182 | break; 183 | else 184 | { 185 | Tgts2 = (PTGTS)malloc ( Tgts.Size ); 186 | Tgts2->Size = Tgts.Size; 187 | 188 | if(!DeviceIoControl( Device , 189 | IOCTL_ISCSI_GET_TARGETS , 190 | Tgts2, 191 | Tgts.Size, 192 | Tgts2, 193 | Tgts.Size, 194 | &Bytes, 195 | NULL)) 196 | { 197 | LastErr("DeviceIoControl"); 198 | } 199 | else 200 | { 201 | cout << "Target list : " << Tgts2->Count << endl; 202 | 203 | Tgt = (PTGT) ( Tgts2 + 1 ); 204 | for ( i = 0 ; i < Tgts2->Count ; i++ ) 205 | { 206 | cout 207 | << i << " " 208 | << ((char*)Tgts2 + Tgt->NameOffset ) 209 | << " Ip " << (Tgt->Addr &0xFF) << "." 210 | << ((Tgt->Addr &0xFF00 ) >> 8) << "." 211 | << ((Tgt->Addr &0xFF0000)>>16) << "." 212 | << ((Tgt->Addr &0xFF000000)>>24) 213 | << " Port " << ((Tgt->Port &0xFF) << 8 | (Tgt->Port &0xFF00) >> 8) 214 | << endl; 215 | 216 | Tgt++; 217 | } 218 | break; 219 | } 220 | 221 | } 222 | } 223 | } 224 | 225 | if ( Tgts2 ) 226 | free ( Tgts2 ); 227 | if ( Device ) 228 | CloseHandle ( Device); 229 | } 230 | 231 | 232 | VOID ConnectTarget( PUCHAR Target) 233 | { 234 | HANDLE Device; 235 | DWORD Bytes; 236 | 237 | Device = OpenDevice(); 238 | 239 | if (Device) 240 | { 241 | if(!DeviceIoControl( Device , 242 | IOCTL_ISCSI_CREATE_SESSION , 243 | Target, 244 | strlen ((char*)Target) + 1, 245 | NULL, 246 | 0, 247 | &Bytes, 248 | NULL)) 249 | LastErr("DeviceIoControl"); 250 | else 251 | cout << "Disk OK" << endl; 252 | 253 | CloseHandle ( Device); 254 | } 255 | } 256 | 257 | VOID Usage() 258 | { 259 | cout << "uSCSICtl" << endl; 260 | cout << "-t TargetName IpAddr [Port] : Add a Target" << endl; 261 | cout << "-l : List all Targets" << endl; 262 | cout << "-c Target : Connect to Target" << endl; 263 | exit(0); 264 | } 265 | 266 | #define INETADDR(a, b, c, d) (a | (b<<8) | (c<<16) | (d<<24)) 267 | #define HTONL(a) (((a&0xFF)<<24) | ((a&0xFF00)<<8) | ((a&0xFF0000)>>8) | ((a&0xFF000000)>>24)) 268 | #define HTONS(a) (((0xFF&a)<<8) | ((0xFF00&a)>>8)) 269 | 270 | BOOLEAN ParseIpAddr( PUCHAR Addr , PULONG IpAddr) 271 | { 272 | PUCHAR Addr2; 273 | UCHAR Comp = 4 , C , AddrComp[4]; 274 | 275 | Addr2 = Addr; 276 | 277 | while ( Comp-- >= 0 ) 278 | { 279 | while ( C = *Addr2 , C != '.' && C != '\0' ) 280 | Addr2++; 281 | 282 | if ( C == '.' ) 283 | *Addr2++ = '\0'; 284 | 285 | AddrComp[Comp] = (UCHAR)atoi ( (char*)Addr ); 286 | Addr = Addr2; 287 | 288 | if ( C == '\0' ) 289 | break; 290 | } 291 | 292 | if ( Comp > 0 ) 293 | return FALSE; 294 | 295 | if ( IpAddr ) 296 | { 297 | *IpAddr = INETADDR (AddrComp[3] , AddrComp[2] , AddrComp[1] , AddrComp[0] ); 298 | return TRUE; 299 | } 300 | else 301 | return FALSE; 302 | 303 | } 304 | 305 | BOOLEAN ParsePort( PUCHAR Port , PUSHORT Port2) 306 | { 307 | USHORT Port3; 308 | Port3 = (USHORT) atoi((char*)Port); 309 | if ( Port2 ) 310 | { 311 | *Port2 = HTONS(Port3); 312 | return TRUE; 313 | } 314 | else 315 | return FALSE; 316 | } 317 | 318 | int __cdecl main(int argc , char * args[]) 319 | { 320 | PUCHAR Target; 321 | ULONG IpAddr; 322 | USHORT Port; 323 | UCHAR Op; 324 | 325 | if ( argc < 2 ) 326 | Usage(); 327 | 328 | if ( argc == 5 ) 329 | { 330 | if ( args[1][0] == '-' && args[1][1] == 't') 331 | { 332 | Op = 'T'; 333 | Target = (PUCHAR)args[2]; 334 | if ( !ParseIpAddr ( (PUCHAR)args[3] , &IpAddr ) || 335 | !ParsePort ( (PUCHAR)args[4] , &Port) ) 336 | Usage(); 337 | } 338 | 339 | } 340 | else if ( argc == 4 ) 341 | { 342 | if ( args[1][0] == '-' && args[1][1] == 't') 343 | { 344 | Op = 'T'; 345 | Target = (PUCHAR)args[2]; 346 | if ( !ParseIpAddr ( (PUCHAR)args[3] , &IpAddr )) 347 | Usage(); 348 | Port = HTONS( 3260 ); 349 | } 350 | } 351 | else if ( argc == 3) 352 | { 353 | if ( args[1][0] == '-' && args[1][1] == 'c') 354 | { 355 | Op = 'C'; 356 | Target = (PUCHAR)args[2]; 357 | } 358 | } 359 | else if ( argc == 2 ) 360 | { 361 | if ( args[1][0] == '-' && args[1][1] == 'l') 362 | Op = 'L'; 363 | } 364 | else 365 | Usage(); 366 | 367 | switch ( Op ) 368 | { 369 | case 'L': 370 | GetTargets(); 371 | break; 372 | case 'T': 373 | AddTarget( Target , IpAddr , Port ); 374 | break; 375 | case 'C': 376 | ConnectTarget ( Target ); 377 | break; 378 | } 379 | 380 | return 0; 381 | } 382 | --------------------------------------------------------------------------------