ReactOS 0.4.15-dev-7924-g5949c20
vfdapi.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define VFD_NOT_INSTALLED   0xffffffff
 

Typedefs

typedef enum _VFD_OPERATION VFD_OPERATION
 
typedef enum _VFD_OPERATIONPVFD_OPERATION
 

Enumerations

enum  _VFD_OPERATION {
  VFD_OPERATION_NONE , VFD_OPERATION_INSTALL , VFD_OPERATION_CONFIG , VFD_OPERATION_REMOVE ,
  VFD_OPERATION_START , VFD_OPERATION_STOP , VFD_OPERATION_OPEN , VFD_OPERATION_SAVE ,
  VFD_OPERATION_CLOSE , VFD_OPERATION_SETLINK , VFD_OPERATION_DELLINK , VFD_OPERATION_PROTECT ,
  VFD_OPERATION_SHELL , VFD_OPERATION_MAX
}
 

Functions

DWORD WINAPI VfdInstallDriver (PCSTR sFileName, DWORD nStart)
 
DWORD WINAPI VfdRemoveDriver ()
 
DWORD WINAPI VfdConfigDriver (DWORD nStart)
 
DWORD WINAPI VfdStartDriver (PDWORD pState)
 
DWORD WINAPI VfdStopDriver (PDWORD pState)
 
DWORD WINAPI VfdGetDriverConfig (PSTR sFileName, PDWORD pStart)
 
DWORD WINAPI VfdGetDriverState (PDWORD pState)
 
HANDLE WINAPI VfdOpenDevice (ULONG nTarget)
 
DWORD WINAPI VfdGetDeviceNumber (HANDLE hDevice, PULONG pNumber)
 
DWORD WINAPI VfdGetDeviceName (HANDLE hDevice, PCHAR pName, ULONG nLength)
 
DWORD WINAPI VfdGetDriverVersion (HANDLE hDevice, PULONG pVersion)
 
DWORD WINAPI VfdOpenImage (HANDLE hDevice, PCSTR sFileName, VFD_DISKTYPE nDiskType, VFD_MEDIA nMediaType, VFD_FLAGS nMediaFlags)
 
DWORD WINAPI VfdCloseImage (HANDLE hDevice, BOOL bForce)
 
DWORD WINAPI VfdGetImageInfo (HANDLE hDevice, PSTR sFileName, PVFD_DISKTYPE pDiskType, PVFD_MEDIA pMediaType, PVFD_FLAGS pMediaFlags, PVFD_FILETYPE pFileType, PULONG pImageSize)
 
DWORD WINAPI VfdSaveImage (HANDLE hDevice, PCSTR sFileName, BOOL bOverWrite, BOOL bTruncate)
 
DWORD WINAPI VfdFormatMedia (HANDLE hDevice)
 
DWORD WINAPI VfdGetMediaState (HANDLE hDevice)
 
DWORD WINAPI VfdWriteProtect (HANDLE hDevice, BOOL bProtect)
 
DWORD WINAPI VfdDismountVolume (HANDLE hDevice, BOOL bForce)
 
DWORD WINAPI VfdSetGlobalLink (HANDLE hDevice, CHAR cLetter)
 
DWORD WINAPI VfdGetGlobalLink (HANDLE hDevice, PCHAR pLetter)
 
DWORD WINAPI VfdSetLocalLink (HANDLE hDevice, CHAR cLetter)
 
DWORD WINAPI VfdGetLocalLink (HANDLE hDevice, PCHAR pLetter)
 
CHAR WINAPI VfdChooseLetter ()
 
BOOL WINAPI VfdIsValidPlatform ()
 
UINT WINAPI VfdGetNotifyMessage ()
 
DWORD WINAPI VfdCheckDriverFile (PCSTR sFileName, PULONG pFileVersion)
 
DWORD WINAPI VfdCheckImageFile (PCSTR sFileName, PDWORD pAttributes, PVFD_FILETYPE pFileType, PULONG pImageSize)
 
DWORD WINAPI VfdCreateImageFile (PCSTR sFileName, VFD_MEDIA nMediaType, VFD_FILETYPE nFileType, BOOL bOverWrite)
 
VFD_MEDIA WINAPI VfdLookupMedia (ULONG nSize)
 
ULONG WINAPI VfdGetMediaSize (VFD_MEDIA nMediaType)
 
PCSTR WINAPI VfdMediaTypeName (VFD_MEDIA nMediaType)
 
void WINAPI VfdMakeFileDesc (PSTR pBuffer, ULONG nBufSize, VFD_FILETYPE nFileType, ULONG nFileSize, DWORD nFileAttr)
 
DWORD WINAPI VfdRegisterHandlers ()
 
DWORD WINAPI VfdUnregisterHandlers ()
 
DWORD WINAPI VfdCheckHandlers ()
 
DWORD WINAPI VfdGuiOpen (HWND hParent, ULONG nDevice)
 
DWORD WINAPI VfdGuiSave (HWND hParent, ULONG nDevice)
 
DWORD WINAPI VfdGuiClose (HWND hParent, ULONG nDevice)
 
DWORD WINAPI VfdGuiFormat (HWND hParent, ULONG nDevice)
 
void WINAPI VfdToolTip (HWND hParent, PCSTR sText, int pos_x, int pos_y, BOOL stick)
 
void WINAPI VfdImageTip (HWND hParent, ULONG nDevice)
 

Macro Definition Documentation

◆ VFD_NOT_INSTALLED

#define VFD_NOT_INSTALLED   0xffffffff

Definition at line 20 of file vfdapi.h.

Typedef Documentation

◆ PVFD_OPERATION

◆ VFD_OPERATION

Enumeration Type Documentation

◆ _VFD_OPERATION

Enumerator
VFD_OPERATION_NONE 
VFD_OPERATION_INSTALL 
VFD_OPERATION_CONFIG 
VFD_OPERATION_REMOVE 
VFD_OPERATION_START 
VFD_OPERATION_STOP 
VFD_OPERATION_OPEN 
VFD_OPERATION_SAVE 
VFD_OPERATION_CLOSE 
VFD_OPERATION_SETLINK 
VFD_OPERATION_DELLINK 
VFD_OPERATION_PROTECT 
VFD_OPERATION_SHELL 
VFD_OPERATION_MAX 

Definition at line 25 of file vfdapi.h.

25 {
26 VFD_OPERATION_NONE, // No operation
27 VFD_OPERATION_INSTALL, // The driver was installed
28 VFD_OPERATION_CONFIG, // The driver config was changed
29 VFD_OPERATION_REMOVE, // The driver was removed
30 VFD_OPERATION_START, // The driver was started
31 VFD_OPERATION_STOP, // The driver was stopped
32 VFD_OPERATION_OPEN, // An image was opened
33 VFD_OPERATION_SAVE, // An image was saved
34 VFD_OPERATION_CLOSE, // An image was closed
35 VFD_OPERATION_SETLINK, // A drive letter was created
36 VFD_OPERATION_DELLINK, // A drive letter was removed
37 VFD_OPERATION_PROTECT, // Write protect state was changed
38 VFD_OPERATION_SHELL, // Shell extension was installed/removed
39 VFD_OPERATION_MAX // Maximum value place holder
@ VFD_OPERATION_NONE
Definition: vfdapi.h:26
@ VFD_OPERATION_PROTECT
Definition: vfdapi.h:37
@ VFD_OPERATION_CONFIG
Definition: vfdapi.h:28
@ VFD_OPERATION_OPEN
Definition: vfdapi.h:32
@ VFD_OPERATION_DELLINK
Definition: vfdapi.h:36
@ VFD_OPERATION_SETLINK
Definition: vfdapi.h:35
@ VFD_OPERATION_SAVE
Definition: vfdapi.h:33
@ VFD_OPERATION_SHELL
Definition: vfdapi.h:38
@ VFD_OPERATION_MAX
Definition: vfdapi.h:39
@ VFD_OPERATION_INSTALL
Definition: vfdapi.h:27
@ VFD_OPERATION_REMOVE
Definition: vfdapi.h:29
@ VFD_OPERATION_START
Definition: vfdapi.h:30
@ VFD_OPERATION_CLOSE
Definition: vfdapi.h:34
@ VFD_OPERATION_STOP
Definition: vfdapi.h:31
enum _VFD_OPERATION VFD_OPERATION
enum _VFD_OPERATION * PVFD_OPERATION

Function Documentation

◆ VfdCheckDriverFile()

DWORD WINAPI VfdCheckDriverFile ( PCSTR  sFileName,
PULONG  pFileVersion 
)

Definition at line 2867 of file vfdctl.c.

2870{
2871#undef FUNC
2872#define FUNC "VfdCheckDriverFile"
2873 DWORD result;
2874 DWORD dummy;
2875 PVOID info;
2876 VS_FIXEDFILEINFO *fixedinfo;
2878 PSTR str;
2879
2880 // Check parameter
2881
2882 if (!sFileName || !*sFileName) {
2884 }
2885
2886 if (pFileVersion) {
2887 *pFileVersion = 0;
2888 }
2889
2890 // check file existence
2891
2892 if (GetFileAttributes(sFileName) == INVALID_FILE_ATTRIBUTES) {
2893 ret = GetLastError();
2894
2895 VFDTRACE(0,
2896 (FUNC ": GetFileAttributes - %s\n",
2897 SystemMessage(ret)));
2898
2899 return ret;
2900 }
2901
2902 // check file version
2903
2904 result = GetFileVersionInfoSize((PSTR)sFileName, &dummy);
2905
2906 if (result == 0) {
2907 VFDTRACE(0,
2908 (FUNC ": GetFileVersionInfoSize == 0\n"));
2909
2910 return ERROR_BAD_DRIVER;
2911 }
2912
2914
2915 if (info == NULL) {
2916 ret = GetLastError();
2917
2918 VFDTRACE(0,
2919 (FUNC ": LocalAlloc(%lu) - %s\n",
2921
2922 return ret;
2923 }
2924
2925 if (!GetFileVersionInfo((PSTR)sFileName, 0, result, info)) {
2926 ret = GetLastError();
2927
2928 VFDTRACE(0,
2929 (FUNC ": GetFileVersionInfo - %s", SystemMessage(ret)));
2930
2931 goto cleanup;
2932 }
2933
2934 result = sizeof(fixedinfo);
2935
2936 if (!VerQueryValue(info, "\\", (PVOID *)&fixedinfo, (PUINT)&result)) {
2937 ret = GetLastError();
2938
2939 VFDTRACE(0,
2940 (FUNC ": VerQueryValue(\"\\\") - %s", SystemMessage(ret)));
2941
2942 goto cleanup;
2943 }
2944
2945 if (fixedinfo->dwFileOS != VOS_NT_WINDOWS32 ||
2946 fixedinfo->dwFileType != VFT_DRV ||
2947 fixedinfo->dwFileSubtype != VFT2_DRV_SYSTEM) {
2948
2949 VFDTRACE(0,
2950 (FUNC ": Invalid file type flags\n"));
2951
2953
2954 goto cleanup;
2955 }
2956
2957 if (pFileVersion) {
2958 *pFileVersion = fixedinfo->dwFileVersionMS;
2959
2960 if (fixedinfo->dwFileFlags & VS_FF_DEBUG) {
2961 *pFileVersion |= 0x80000000;
2962 }
2963 }
2964
2965 if (!VerQueryValue(info,
2966 "\\StringFileInfo\\" VFD_VERSIONINFO_LANG "\\OriginalFileName",
2967 (PVOID *)&str, (PUINT)&result)) {
2968 ret = GetLastError();
2969
2970 VFDTRACE(0,
2971 (FUNC ": VerQueryValue(\"OriginalFileName\") - %s",
2972 SystemMessage(ret)));
2973
2974 goto cleanup;
2975 }
2976
2978 VFDTRACE(0,
2979 (FUNC ": Invalid original file name\n"));
2980
2982
2983 goto cleanup;
2984 }
2985
2986 if (fixedinfo->dwFileVersionMS != MAKELONG(VFD_DRIVER_MINOR, VFD_DRIVER_MAJOR) ||
2987 fixedinfo->dwProductVersionMS != MAKELONG(VFD_PRODUCT_MINOR, VFD_PRODUCT_MAJOR)) {
2988
2989 VFDTRACE(0,
2990 (FUNC ": Invalid version values - file:%08x, prod: %08x\n",
2991 fixedinfo->dwFileVersionMS, fixedinfo->dwProductVersionMS));
2992
2994
2995 goto cleanup;
2996 }
2997
2998 // Ensure that the driver binary is located on a local drive
2999 // because device driver cannot be started on network drives.
3000
3001 if (*sFileName == '\\' && *(sFileName + 1) == '\\') {
3002 // full path is a UNC path -- \\server\dir\...
3003
3004 VFDTRACE(0,
3005 (FUNC ": Driver is located on a network drive\n"));
3006
3008 }
3009 else {
3010 // ensure that the drive letter is not a network drive
3011
3012 CHAR root[] = " :\\";
3013
3014 root[0] = *sFileName;
3015
3016 if (GetDriveType(root) == DRIVE_REMOTE) {
3017 // the drive is a network drive
3018
3019 VFDTRACE(0,
3020 (FUNC ": Driver is located on a network drive\n"));
3021
3023 }
3024 }
3025
3026cleanup:
3027 LocalFree(info);
3028
3029 return ret;
3030}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
static void cleanup(void)
Definition: main.c:1335
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint64EXT * result
Definition: glext.h:11304
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
unsigned int * PUINT
Definition: ndis.h:50
const WCHAR * str
char * PSTR
Definition: typedefs.h:51
#define MAKELONG(a, b)
Definition: typedefs.h:249
#define VOS_NT_WINDOWS32
Definition: verrsrc.h:71
#define VFT2_DRV_SYSTEM
Definition: verrsrc.h:91
#define VFT_DRV
Definition: verrsrc.h:77
#define VS_FF_DEBUG
Definition: verrsrc.h:42
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define FUNC
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
PCSTR SystemMessage(DWORD nError)
Definition: vfdlib.c:147
#define VFD_DRIVER_MINOR
Definition: vfdver.h:21
#define VFD_VERSIONINFO_LANG
Definition: vfdver.h:33
#define VFD_DRIVER_MAJOR
Definition: vfdver.h:20
#define VFD_DRIVER_FILENAME
Definition: vfdver.h:19
#define VFD_PRODUCT_MAJOR
Definition: vfdver.h:15
#define VFD_PRODUCT_MINOR
Definition: vfdver.h:16
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define GetDriveType
Definition: winbase.h:3812
#define GetFileAttributes
Definition: winbase.h:3815
#define DRIVE_REMOTE
Definition: winbase.h:253
#define LPTR
Definition: winbase.h:381
#define ERROR_BAD_DRIVER
Definition: winerror.h:1180
#define ERROR_NETWORK_ACCESS_DENIED
Definition: winerror.h:157
#define VerQueryValue
Definition: winver.h:56
#define GetFileVersionInfo
Definition: winver.h:54
#define GetFileVersionInfoSize
Definition: winver.h:53
char CHAR
Definition: xmlstorage.h:175

Referenced by CheckDriver(), Status(), and VfdInstallDriver().

◆ VfdCheckHandlers()

DWORD WINAPI VfdCheckHandlers ( )

Definition at line 393 of file vfdshutil.cpp.

394{
396 TCHAR guid_str[40];
397 DWORD temp;
398 DWORD ret;
399
400 MakeGuidString(guid_str, CLSID_VfdShellExt);
401
402 sprintf(buf, "CLSID\\%s", guid_str);
403
404 VFDTRACE(0, ("HKCR\\%s\n", buf));
405
406 temp = sizeof(buf);
407
409
410 if (ret != ERROR_SUCCESS) {
411 return ret;
412 }
413
416 }
417
418 return ERROR_SUCCESS;
419}
#define _stricmp
Definition: cat.c:22
#define MAX_PATH
Definition: compat.h:34
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static calc_node_t temp
Definition: rpn_ieee.c:38
int32_t * PLONG
Definition: typedefs.h:58
#define VFDEXT_DESCRIPTION
Definition: vfdlib.h:58
static void MakeGuidString(LPTSTR str, const GUID &guid)
Definition: vfdshutil.cpp:88
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
#define RegQueryValue
Definition: winreg.h:523
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
char TCHAR
Definition: xmlstorage.h:189

Referenced by Shell(), and Status().

◆ VfdCheckImageFile()

DWORD WINAPI VfdCheckImageFile ( PCSTR  sFileName,
PDWORD  pAttributes,
PVFD_FILETYPE  pFileType,
PULONG  pImageSize 
)

Definition at line 3035 of file vfdctl.c.

3040{
3041#undef FUNC
3042#define FUNC "VfdCheckImageFile"
3043 HANDLE hFile;
3045
3046 if (!sFileName || !*sFileName || !pAttributes || !pImageSize || !pFileType) {
3048 }
3049
3050 // get file attributes
3051
3052 *pAttributes = GetFileAttributes(sFileName);
3053
3054 if (*pAttributes == INVALID_FILE_ATTRIBUTES) {
3055 ret = GetLastError();
3056
3057 if (ret != ERROR_FILE_NOT_FOUND) {
3058 VFDTRACE(0,
3059 (FUNC ": GetFileAttributes(%s) - %s\n",
3060 sFileName, SystemMessage(ret)));
3061 }
3062
3063 return ret;
3064 }
3065
3066 // Open the target file
3067
3069 0, NULL, OPEN_EXISTING, 0, NULL);
3070
3071 if (hFile == INVALID_HANDLE_VALUE) {
3072
3073 // failed to open
3074
3075 ret = GetLastError();
3076
3077 if (ret != ERROR_ACCESS_DENIED) {
3078 VFDTRACE(0,
3079 (FUNC ": CreateFile(%s) - %s\n",
3080 sFileName, SystemMessage(ret)));
3081
3082 return ret;
3083 }
3084
3085 // try opening it read-only
3086
3087 hFile = CreateFile(sFileName, GENERIC_READ,
3089
3090 if (hFile == INVALID_HANDLE_VALUE) {
3091
3092 // cannot open even read-only
3093
3094 ret = GetLastError();
3095
3096 VFDTRACE(0,
3097 (FUNC ": CreateFile(%s) - %s\n",
3098 sFileName, SystemMessage(ret)));
3099
3100 return ret;
3101 }
3102
3103 // file can be opened read-only
3104 *pAttributes |= FILE_ATTRIBUTE_READONLY;
3106 }
3107
3108 // check if the image is an IMZ file
3109
3110 if (ExtractZipInfo(hFile, pImageSize) == ERROR_SUCCESS) {
3111 *pFileType = VFD_FILETYPE_ZIP;
3112 }
3113 else {
3114 *pImageSize = GetFileSize(hFile, NULL);
3115 *pFileType = VFD_FILETYPE_RAW;
3116 }
3117
3119
3120 return ret;
3121}
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define FILE_SHARE_READ
Definition: compat.h:136
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
_In_ HANDLE hFile
Definition: mswsock.h:90
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define GENERIC_WRITE
Definition: nt_native.h:90
DWORD ExtractZipInfo(HANDLE hFile, ULONG *pSize)
Definition: vfdzip.c:133
@ VFD_FILETYPE_RAW
Definition: vfdtypes.h:52
@ VFD_FILETYPE_ZIP
Definition: vfdtypes.h:53
#define CreateFile
Definition: winbase.h:3749

Referenced by CVfdShExt::DoVfdDrop(), OnImage(), OnTarget(), Open(), and Save().

◆ VfdChooseLetter()

CHAR WINAPI VfdChooseLetter ( )

Definition at line 3205 of file vfdctl.c.

3206{
3207 DWORD logical_drives = GetLogicalDrives();
3208 CHAR drive_letter = 'A';
3209
3210 if (logical_drives == 0) {
3211 return '\0';
3212 }
3213
3214 while (logical_drives & 0x1) {
3215 logical_drives >>= 1;
3216 drive_letter++;
3217 }
3218
3219 if (drive_letter > 'Z') {
3220 return '\0';
3221 }
3222
3223 return drive_letter;
3224}
DWORD WINAPI GetLogicalDrives(void)
Definition: disk.c:110

Referenced by Link(), and Open().

◆ VfdCloseImage()

DWORD WINAPI VfdCloseImage ( HANDLE  hDevice,
BOOL  bForce 
)

Definition at line 1702 of file vfdctl.c.

1705{
1706#undef FUNC
1707#define FUNC "VfdCloseImage"
1708 DWORD result;
1710 int retry = 0;
1711
1712lock_retry:
1713 if (!DeviceIoControl(
1714 hDevice,
1716 NULL,
1717 0,
1718 NULL,
1719 0,
1720 &result,
1721 NULL))
1722 {
1723 ret = GetLastError();
1724
1725 VFDTRACE(0,
1726 (FUNC ": DeviceIoControl(FSCTL_LOCK_VOLUME) - %s",
1727 SystemMessage(ret)));
1728
1729 if (ret != ERROR_ACCESS_DENIED || retry == 5) {
1730 // error other than access denied or
1731 // operation kept failing for 5 seconds
1732 return ret;
1733 }
1734
1735 if (!bForce) {
1736 // error is access denied and
1737 // the force flag is not set
1738
1739 if (retry == 0) {
1740
1741 // send the MEDIAREMOVED notification to the shell and
1742 // see if the shell releases the target drive
1743
1744 CHAR root[] = "A:\\";
1745
1746 VfdGetGlobalLink(hDevice, &root[0]);
1747
1748 if (isalpha(root[0])) {
1750 }
1751
1752 while (VfdGetLocalLink(hDevice, &root[0]) == ERROR_SUCCESS &&
1753 isalpha(root[0])) {
1755 }
1756 }
1757
1758 Sleep(1000);
1759 retry++;
1760
1761 goto lock_retry;
1762 }
1763 }
1764
1766
1767 if (!DeviceIoControl(
1768 hDevice,
1770 NULL,
1771 0,
1772 NULL,
1773 0,
1774 &result,
1775 NULL))
1776 {
1777 ret = GetLastError();
1778
1779 VFDTRACE(0,
1780 (FUNC ": DeviceIoControl(FSCTL_DISMOUNT_VOLUME) - %s",
1781 SystemMessage(ret)));
1782
1783 return ret;
1784 }
1785
1786 if (!DeviceIoControl(
1787 hDevice,
1789 NULL,
1790 0,
1791 NULL,
1792 0,
1793 &result,
1794 NULL))
1795 {
1796 ret = GetLastError();
1797
1798 if (ret != ERROR_NOT_READY) {
1799 VFDTRACE(0,
1800 (FUNC ": DeviceIoControl(IOCTL_VFD_CLOSE_FILE) - %s",
1801 SystemMessage(ret)));
1802 }
1803
1804 return ret;
1805 }
1806
1807 if (!DeviceIoControl(
1808 hDevice,
1810 NULL,
1811 0,
1812 NULL,
1813 0,
1814 &result,
1815 NULL))
1816 {
1817 // This should not be fatal because the volume is unlocked
1818 // when the handle is closed anyway
1819 VFDTRACE(0,
1820 (FUNC ": DeviceIoControl(FSCTL_UNLOCK_VOLUME) - %s",
1822 }
1823
1824 // Broadcast the successful operation
1825 if (ret == ERROR_SUCCESS) {
1826 ULONG number;
1827
1828 if (VfdGetDeviceNumber(hDevice, &number) == ERROR_SUCCESS) {
1830 }
1831 }
1832
1833 return ret;
1834}
#define isalpha(c)
Definition: acclib.h:74
EXTERN_C void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
static unsigned int number
Definition: dsound.c:1479
#define FSCTL_LOCK_VOLUME
Definition: nt_native.h:832
#define FSCTL_UNLOCK_VOLUME
Definition: nt_native.h:833
#define FSCTL_DISMOUNT_VOLUME
Definition: nt_native.h:834
#define SHCNE_MEDIAREMOVED
Definition: shlobj.h:1881
#define SHCNF_PATH
Definition: shlobj.h:1917
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
uint32_t ULONG
Definition: typedefs.h:59
static __inline void VfdNotify(WPARAM wParam, LPARAM lParam)
Definition: vfdctl.c:120
DWORD WINAPI VfdGetGlobalLink(HANDLE hDevice, PCHAR pLetter)
Definition: vfdctl.c:2114
DWORD WINAPI VfdGetLocalLink(HANDLE hDevice, PCHAR pLetter)
Definition: vfdctl.c:2281
DWORD WINAPI VfdGetDeviceNumber(HANDLE hDevice, PULONG pNumber)
Definition: vfdctl.c:2359
#define IOCTL_VFD_CLOSE_IMAGE
Definition: vfdio.h:133
#define ERROR_NOT_READY
Definition: winerror.h:124

◆ VfdConfigDriver()

DWORD WINAPI VfdConfigDriver ( DWORD  nStart)

Definition at line 468 of file vfdctl.c.

470{
471#undef FUNC
472#define FUNC "VfdConfigDriver"
473 SC_HANDLE hScManager; // Service Control Manager
474 SC_HANDLE hService; // Service (= Driver)
476
477 // Connect to the Service Control Manager
478
479 hScManager = OpenSCManager(NULL, NULL, 0);
480
481 if (hScManager == NULL) {
482 ret = GetLastError();
483
484 VFDTRACE(0,
485 (FUNC ": OpenSCManager() - %s",
487
488 return ret;
489 }
490
491 // Open the VFD driver entry in the service database
492
493 hService = OpenService(
494 hScManager, // Service control manager
495 VFD_DEVICE_BASENAME, // service name
496 SERVICE_CHANGE_CONFIG); // service access mode
497
498 if (hService == NULL) {
499 ret = GetLastError();
500
501 VFDTRACE(0,
502 (FUNC ": OpenService(SERVICE_CHANGE_CONFIG) - %s",
504
505 goto cleanup;
506 }
507
508 // Change the start method of the VFD driver
509
511 hService,
513 nStart,
515 NULL,
516 NULL,
517 NULL,
518 NULL,
519 NULL,
520 NULL,
521 NULL)) {
522
523 ret = GetLastError();
524
525 VFDTRACE(0,
526 (FUNC ": ChangeServiceConfig() - %s",
528
529 goto cleanup;
530 }
531
532cleanup:
533 // Close the service object handle
534
535 if (hService) {
536 CloseServiceHandle(hService);
537 }
538
539 // Close handle to the service control manager.
540
541 if (hScManager) {
542 CloseServiceHandle(hScManager);
543 }
544
545 // Broadcast the successful operation
546
547 if (ret == ERROR_SUCCESS) {
549 }
550
551 return ret;
552}
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
#define VFD_DEVICE_BASENAME
Definition: vfdio.h:35
#define OpenSCManager
Definition: winsvc.h:575
#define SERVICE_NO_CHANGE
Definition: winsvc.h:20
#define SERVICE_CHANGE_CONFIG
Definition: winsvc.h:54
#define ChangeServiceConfig
Definition: winsvc.h:567
#define OpenService
Definition: winsvc.h:576

Referenced by Config().

◆ VfdCreateImageFile()

DWORD WINAPI VfdCreateImageFile ( PCSTR  sFileName,
VFD_MEDIA  nMediaType,
VFD_FILETYPE  nFileType,
BOOL  bOverWrite 
)

Definition at line 3126 of file vfdctl.c.

3131{
3132#undef FUNC
3133#define FUNC "VfdCreateImageFile"
3134 HANDLE hFile;
3136 PUCHAR image_buf = NULL;
3137 DWORD result;
3139
3140 if (nFileType != VFD_FILETYPE_RAW) {
3142 }
3143
3144 file_size = VfdGetMediaSize(nMediaType);
3145
3146 if (file_size == 0) {
3148 }
3149
3150 hFile = CreateFile(sFileName, GENERIC_WRITE, 0, NULL,
3151 bOverWrite ? CREATE_ALWAYS : CREATE_NEW, 0, NULL);
3152
3153 if (hFile == INVALID_HANDLE_VALUE) {
3154 ret = GetLastError();
3155
3156 VFDTRACE(0,
3157 (FUNC ": CreateFile - %s",
3158 SystemMessage(ret)));
3159
3160 return ret;
3161 }
3162
3163 image_buf = (PUCHAR)LocalAlloc(LPTR, file_size);
3164
3165 if (image_buf == NULL) {
3166 ret = GetLastError();
3167
3168 VFDTRACE(0,
3169 (FUNC ": LocalAlloc - %s",
3170 SystemMessage(ret)));
3171
3172 goto exit_func;
3173 }
3174
3176
3177 if (!WriteFile(hFile, image_buf, file_size, &result, NULL) ||
3178 file_size != result) {
3179
3180 ret = GetLastError();
3181
3182 VFDTRACE(0,
3183 (FUNC ": WriteFile - %s",
3184 SystemMessage(ret)));
3185
3186 goto exit_func;
3187 }
3188
3190
3191exit_func:
3193
3194 if (image_buf) {
3195 LocalFree(image_buf);
3196 }
3197
3198 return ret;
3199}
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1004
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define CREATE_ALWAYS
Definition: disk.h:72
#define CREATE_NEW
Definition: disk.h:69
static unsigned int file_size
Definition: regtests2xml.c:47
unsigned char * PUCHAR
Definition: typedefs.h:53
ULONG WINAPI VfdGetMediaSize(VFD_MEDIA nMediaType)
Definition: vfdctl.c:3272
DWORD FormatBufferFat(PUCHAR pBuffer, ULONG nSectors)
Definition: vfdfat.c:116
#define VFD_BYTE_TO_SECTOR(b)
Definition: vfdio.h:44

Referenced by OnOK(), and Open().

◆ VfdDismountVolume()

DWORD WINAPI VfdDismountVolume ( HANDLE  hDevice,
BOOL  bForce 
)

Definition at line 2629 of file vfdctl.c.

2632{
2633#undef FUNC
2634#define FUNC "VfdDismountVolume"
2635 DWORD result;
2637
2638 // Lock the target volume
2639
2640 if (!DeviceIoControl(
2641 hDevice,
2643 NULL,
2644 0,
2645 NULL,
2646 0,
2647 &result,
2648 NULL))
2649 {
2650 ret = GetLastError();
2651
2652 VFDTRACE(0,
2653 (FUNC ": DeviceIoControl(FSCTL_LOCK_VOLUME) - %s",
2654 SystemMessage(ret)));
2655
2656 if (ret != ERROR_ACCESS_DENIED || !bForce) {
2657 return ret;
2658 }
2659 }
2660
2661 // Dismount the target volume
2662
2663 if (!DeviceIoControl(
2664 hDevice,
2666 NULL,
2667 0,
2668 NULL,
2669 0,
2670 &result,
2671 NULL))
2672 {
2673 ret = GetLastError();
2674
2675 VFDTRACE(0,
2676 (FUNC ": DeviceIoControl(FSCTL_DISMOUNT_VOLUME) - %s",
2677 SystemMessage(ret)));
2678 }
2679
2680 return ret;
2681}

Referenced by Format(), OnOK(), Save(), and VfdGuiFormat().

◆ VfdFormatMedia()

DWORD WINAPI VfdFormatMedia ( HANDLE  hDevice)

Definition at line 2523 of file vfdctl.c.

2525{
2526#undef FUNC
2527#define FUNC "VfdFormatMedia"
2528 DWORD result;
2530 PUCHAR buf = NULL;
2532
2533 // Get the media size
2534
2535 if (!DeviceIoControl(
2536 hDevice,
2538 NULL,
2539 0,
2540 &length,
2541 sizeof(length),
2542 &result,
2543 NULL))
2544 {
2545 ret = GetLastError();
2546
2547 VFDTRACE(0,
2548 (FUNC ": DeviceIoControl(IOCTL_DISK_GET_LENGTH_INFO) - %s",
2549 SystemMessage(ret)));
2550
2551 goto exit_func;
2552 }
2553
2554 // Prepare a formatted image buffer
2555
2556 buf = (PUCHAR)LocalAlloc(LPTR, length.Length.LowPart);
2557
2558 if (buf == NULL) {
2559 ret = GetLastError();
2560
2561 VFDTRACE(0,
2562 (FUNC ": LocalAlloc - %s",
2563 SystemMessage(ret)));
2564
2565 goto exit_func;
2566 }
2567
2568 // format the buffer
2569
2571 VFD_BYTE_TO_SECTOR(length.Length.LowPart));
2572
2573 if (ret != ERROR_SUCCESS) {
2574 goto exit_func;
2575 }
2576
2577 // seek the top of the media
2578
2579 if (SetFilePointer(hDevice, 0, NULL, FILE_BEGIN) != 0) {
2580 ret = GetLastError();
2581
2582 VFDTRACE(0,
2583 (FUNC ": SetFilePointer - %s",
2584 SystemMessage(ret)));
2585
2586 goto exit_func;
2587 }
2588
2589 // write the image into the media
2590
2591 if (!WriteFile(hDevice, buf, length.Length.LowPart, &result, NULL) ||
2592 result != length.Length.LowPart) {
2593 ret = GetLastError();
2594
2595 VFDTRACE(0,
2596 (FUNC ": WriteFile - %s",
2597 SystemMessage(ret)));
2598
2599 goto exit_func;
2600 }
2601
2602exit_func:
2603 // unlock the target volume
2604 if (!DeviceIoControl(
2605 hDevice,
2607 NULL,
2608 0,
2609 NULL,
2610 0,
2611 &result,
2612 NULL))
2613 {
2614 VFDTRACE(0,
2615 (FUNC ": DeviceIoControl(FSCTL_UNLOCK_VOLUME) - %s",
2617 }
2618
2619 // release the format image buffer
2620 if (buf) {
2621 LocalFree(buf);
2622 }
2623
2624 return ret;
2625}
#define FILE_BEGIN
Definition: compat.h:761
#define SetFilePointer
Definition: compat.h:743
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define IOCTL_DISK_GET_LENGTH_INFO
Definition: vfdctl.c:37

Referenced by Format(), and VfdGuiFormat().

◆ VfdGetDeviceName()

DWORD WINAPI VfdGetDeviceName ( HANDLE  hDevice,
PCHAR  pName,
ULONG  nLength 
)

Definition at line 2396 of file vfdctl.c.

2400{
2401#undef FUNC
2402#define FUNC "VfdGetDeviceName"
2403 DWORD result;
2404 WCHAR wname[MAX_PATH];
2406
2407 if (!pName || !nLength) {
2409 }
2410
2412
2413 if (!DeviceIoControl(
2414 hDevice,
2416 NULL,
2417 0,
2418 wname,
2419 sizeof(wname),
2420 &result,
2421 NULL))
2422 {
2423 ret = GetLastError();
2424
2425 VFDTRACE(0,
2426 (FUNC ": DeviceIoControl(IOCTL_VFD_QUERY_NUMBER) - %s",
2427 SystemMessage(ret)));
2428 }
2429
2430 if (!WideCharToMultiByte(CP_OEMCP, 0, &wname[1],
2431 wname[0] / sizeof(WCHAR), pName, nLength, NULL, NULL)) {
2432
2433 ret = GetLastError();
2434
2435 VFDTRACE(0,
2436 (FUNC ": WideCharToMultiByte - %s",
2437 SystemMessage(ret)));
2438 }
2439
2440 return ret;
2441}
#define WideCharToMultiByte
Definition: compat.h:111
static LPSTR pName
Definition: security.c:75
#define IOCTL_VFD_QUERY_NAME
Definition: vfdio.h:358
#define ZeroMemory
Definition: winbase.h:1712
_In_ DWORD nLength
Definition: wincon.h:473
#define CP_OEMCP
Definition: winnls.h:231
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by VfdGetLocalLink(), and VfdSetLocalLink().

◆ VfdGetDeviceNumber()

DWORD WINAPI VfdGetDeviceNumber ( HANDLE  hDevice,
PULONG  pNumber 
)

Definition at line 2359 of file vfdctl.c.

2362{
2363#undef FUNC
2364#define FUNC "VfdGetDeviceNumber"
2365 DWORD result;
2367
2368 if (!pNumber) {
2370 }
2371
2372 *pNumber = 0;
2373
2374 if (!DeviceIoControl(
2375 hDevice,
2377 NULL,
2378 0,
2379 pNumber,
2380 sizeof(ULONG),
2381 &result,
2382 NULL))
2383 {
2384 ret = GetLastError();
2385
2386 VFDTRACE(0,
2387 (FUNC ": DeviceIoControl(IOCTL_VFD_QUERY_NUMBER) - %s",
2388 SystemMessage(ret)));
2389 }
2390
2391 return ret;
2392}
#define IOCTL_VFD_QUERY_NUMBER
Definition: vfdio.h:325

Referenced by CVfdShExt::Initialize(), Link(), PrintImageInfo(), Unlink(), VfdCloseImage(), VfdOpenImage(), VfdSetGlobalLink(), VfdSetLocalLink(), and VfdWriteProtect().

◆ VfdGetDriverConfig()

DWORD WINAPI VfdGetDriverConfig ( PSTR  sFileName,
PDWORD  pStart 
)

Definition at line 959 of file vfdctl.c.

962{
963#undef FUNC
964#define FUNC "VfdGetDriverConfig"
965 SC_HANDLE hScManager; // Service Control Manager
966 SC_HANDLE hService; // Service (= Driver)
970
971 if (sFileName) {
972 ZeroMemory(sFileName, MAX_PATH);
973 }
974
975 if (pStart) {
976 *pStart = 0;
977 }
978
979 // Connect to the Service Control Manager
980
981 hScManager = OpenSCManager(NULL, NULL, 0);
982
983 if (hScManager == NULL) {
984 ret = GetLastError();
985
986 VFDTRACE(0,
987 (FUNC ": OpenSCManager() - %s", SystemMessage(ret)));
988
989 return ret;
990 }
991
992 // Open the VFD driver entry in the service database
993
994 hService = OpenService(
995 hScManager, // Service control manager
996 VFD_DEVICE_BASENAME, // service name
997 SERVICE_QUERY_CONFIG); // service access mode
998
999 if (hService == NULL) {
1000 ret = GetLastError();
1001
1002 VFDTRACE(0,
1003 (FUNC ": OpenService(SERVICE_QUERY_CONFIG) - %s",
1004 SystemMessage(ret)));
1005
1006 goto cleanup;
1007 }
1008
1009 // Get the length of config information
1010
1011 if (!QueryServiceConfig(hService, NULL, 0, &result)) {
1012 ret = GetLastError();
1013
1016 }
1017 else {
1018 VFDTRACE(0,
1019 (FUNC ": QueryServiceConfig() - %s",
1020 SystemMessage(ret)));
1021
1022 goto cleanup;
1023 }
1024 }
1025
1026 // allocate a required buffer
1027
1029
1030 if (config == NULL) {
1031 ret = GetLastError();
1032
1033 VFDTRACE(0,
1034 (FUNC ": LocalAlloc(%lu) - %s\n",
1036
1037 goto cleanup;
1038 }
1039
1040 // get the config information
1041
1042 if (!QueryServiceConfig(hService, config, result, &result)) {
1043 ret = GetLastError();
1044
1045 VFDTRACE(0,
1046 (FUNC ": QueryServiceConfig() - %s",
1047 SystemMessage(ret)));
1048
1049 goto cleanup;
1050 }
1051
1052 // copy information to output buffer
1053
1054 if (sFileName) {
1055 if (strncmp(config->lpBinaryPathName, "\\??\\", 4) == 0) {
1056
1057 // driver path is an absolute UNC path
1058 strncpy(
1059 sFileName,
1060 config->lpBinaryPathName + 4,
1061 MAX_PATH);
1062 }
1063 else if (config->lpBinaryPathName[0] == '\\' ||
1064 (isalpha(config->lpBinaryPathName[0]) &&
1065 config->lpBinaryPathName[1] == ':')) {
1066
1067 // driver path is an absolute path
1068 strncpy(sFileName,
1069 config->lpBinaryPathName,
1070 MAX_PATH);
1071 }
1072 else {
1073 // driver path is relative to the SystemRoot
1074// DWORD len = GetEnvironmentVariable(
1075// "SystemRoot", sFileName, MAX_PATH);
1076
1077 DWORD len = GetWindowsDirectory(sFileName, MAX_PATH);
1078
1079 if (len == 0 || len > MAX_PATH) {
1080 VFDTRACE(0,
1081 (FUNC ": %%SystemRoot%% is empty or too long.\n"));
1082
1084 goto cleanup;
1085 }
1086
1087 sprintf((sFileName + len), "\\%s",
1088 config->lpBinaryPathName);
1089 }
1090 }
1091
1092 if (pStart) {
1093 *pStart = config->dwStartType;
1094 }
1095
1096cleanup:
1097 // Free service config buffer
1098
1099 if (config) {
1101 }
1102
1103 // Close the service object handle
1104
1105 if (hService) {
1106 CloseServiceHandle(hService);
1107 }
1108
1109 // Close handle to the service control manager.
1110
1111 if (hScManager) {
1112 CloseServiceHandle(hScManager);
1113 }
1114
1115 return ret;
1116}
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
GLenum GLsizei len
Definition: glext.h:6722
#define GetWindowsDirectory
Definition: winbase.h:3857
#define ERROR_BAD_ENVIRONMENT
Definition: winerror.h:113
#define QueryServiceConfig
Definition: winsvc.h:580
QUERY_SERVICE_CONFIGA * LPQUERY_SERVICE_CONFIG
Definition: winsvc.h:550
#define SERVICE_QUERY_CONFIG
Definition: winsvc.h:53

Referenced by CheckDriver(), Status(), and VfdRemoveDriver().

◆ VfdGetDriverState()

DWORD WINAPI VfdGetDriverState ( PDWORD  pState)

Definition at line 1121 of file vfdctl.c.

1123{
1124#undef FUNC
1125#define FUNC "VfdGetDriverState"
1126 SC_HANDLE hScManager = NULL; // Service Control Manager
1127 SC_HANDLE hService = NULL; // Service (= Driver)
1130
1131 if (pState) {
1132 *pState = 0;
1133 }
1134
1135 // Connect to the Service Control Manager
1136
1137 hScManager = OpenSCManager(NULL, NULL, 0);
1138
1139 if (hScManager == NULL) {
1140 ret = GetLastError();
1141
1142 VFDTRACE(0,
1143 (FUNC ": OpenSCManager() - %s",
1144 SystemMessage(ret)));
1145
1146 return ret;
1147 }
1148
1149 // Open the VFD driver entry in the service database
1150
1151 hService = OpenService(
1152 hScManager, // Service control manager
1153 VFD_DEVICE_BASENAME, // service name
1154 SERVICE_QUERY_STATUS); // service access mode
1155
1156 if (hService == NULL) {
1157
1158 ret = GetLastError();
1159
1161
1162 if (pState) {
1163 *pState = VFD_NOT_INSTALLED;
1164 }
1165
1167 }
1168 else {
1169 VFDTRACE(0,
1170 (FUNC ": OpenService(SERVICE_QUERY_STATUS) - %s",
1171 SystemMessage(ret)));
1172 }
1173
1174 goto cleanup;
1175 }
1176
1177 // Get current driver status
1178
1179 ZeroMemory(&status, sizeof(status));
1180
1181 if (!QueryServiceStatus(hService, &status)) {
1182 ret = GetLastError();
1183
1184 VFDTRACE(0,
1185 (FUNC ": QueryServiceStatus() - %s",
1186 SystemMessage(ret)));
1187
1188 goto cleanup;
1189 }
1190
1191 if (pState) {
1192 *pState = status.dwCurrentState;
1193 }
1194
1195cleanup:
1196 // Close the service object handle
1197
1198 if (hService) {
1199 CloseServiceHandle(hService);
1200 }
1201
1202 // Close handle to the service control manager.
1203
1204 if (hScManager) {
1205 CloseServiceHandle(hScManager);
1206 }
1207
1208 return ret;
1209}
BOOL WINAPI QueryServiceStatus(SC_HANDLE hService, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:2845
Definition: ps.c:97
#define VFD_NOT_INSTALLED
Definition: vfdapi.h:20
#define ERROR_SERVICE_DOES_NOT_EXIST
Definition: winerror.h:611
#define SERVICE_QUERY_STATUS
Definition: winsvc.h:55

Referenced by Install(), ProcessCommandLine(), and Remove().

◆ VfdGetDriverVersion()

DWORD WINAPI VfdGetDriverVersion ( HANDLE  hDevice,
PULONG  pVersion 
)

Definition at line 2446 of file vfdctl.c.

2449{
2450#undef FUNC
2451#define FUNC "VfdGetDriverVersion"
2452 DWORD result;
2454
2455 if (!pVersion) {
2457 }
2458
2459 *pVersion = '\0';
2460
2461 if (!DeviceIoControl(
2462 hDevice,
2464 NULL,
2465 0,
2466 pVersion,
2467 sizeof(ULONG),
2468 &result,
2469 NULL))
2470 {
2471 ret = GetLastError();
2472
2473 VFDTRACE(0,
2474 (FUNC ": DeviceIoControl(IOCTL_VFD_QUERY_VERSION) - %s",
2475 SystemMessage(ret)));
2476 }
2477
2478 return ret;
2479}
#define IOCTL_VFD_QUERY_VERSION
Definition: vfdio.h:387

Referenced by Status(), and VfdOpenDevice().

◆ VfdGetGlobalLink()

DWORD WINAPI VfdGetGlobalLink ( HANDLE  hDevice,
PCHAR  pLetter 
)

Definition at line 2114 of file vfdctl.c.

2117{
2118#undef FUNC
2119#define FUNC "VfdGetGlobalLinks"
2120 DWORD result;
2121 DWORD ret;
2122
2123 if (!pLetter) {
2125 }
2126
2127 *pLetter = 0;
2128
2129 if (!DeviceIoControl(
2130 hDevice,
2132 NULL,
2133 0,
2134 pLetter,
2135 sizeof(*pLetter),
2136 &result,
2137 NULL))
2138 {
2139 ret = GetLastError();
2140
2141 VFDTRACE(0,
2142 (FUNC ": DeviceIoControl(IOCTL_VFD_QUERY_LINK) - %s",
2143 SystemMessage(ret)));
2144
2145 return ret;
2146 }
2147
2148 return ERROR_SUCCESS;
2149}
#define IOCTL_VFD_QUERY_LINK
Definition: vfdio.h:221

Referenced by Open(), PrintDriveLetter(), VfdCloseImage(), VfdGetLocalLink(), VfdOpenImage(), VfdSetGlobalLink(), VfdSetLocalLink(), VfdStartDriver(), and VfdStopDriver().

◆ VfdGetImageInfo()

DWORD WINAPI VfdGetImageInfo ( HANDLE  hDevice,
PSTR  sFileName,
PVFD_DISKTYPE  pDiskType,
PVFD_MEDIA  pMediaType,
PVFD_FLAGS  pMediaFlags,
PVFD_FILETYPE  pFileType,
PULONG  pImageSize 
)

Definition at line 1839 of file vfdctl.c.

1847{
1848#undef FUNC
1849#define FUNC "VfdGetImageInfo"
1850 PVFD_IMAGE_INFO image_info;
1851 DWORD result;
1853
1854 image_info = (PVFD_IMAGE_INFO)LocalAlloc(
1855 LPTR, sizeof(VFD_IMAGE_INFO) + MAX_PATH);
1856
1857 if (image_info == NULL) {
1858 ret = GetLastError();
1859
1860 VFDTRACE(0,
1861 (FUNC ": LocalAlloc(%lu) - %s\n",
1863
1864 return ret;
1865 }
1866
1867 ZeroMemory(image_info, sizeof(VFD_IMAGE_INFO) + MAX_PATH);
1868
1869 // Query file information
1870
1871 if (!DeviceIoControl(
1872 hDevice,
1874 NULL,
1875 0,
1876 image_info,
1877 sizeof(VFD_IMAGE_INFO) + MAX_PATH,
1878 &result,
1879 NULL))
1880 {
1881 ret = GetLastError();
1882
1883 if (ret != ERROR_MORE_DATA) {
1884 VFDTRACE(0,
1885 (FUNC ": DeviceIoControl(IOCTL_VFD_QUERY_FILE) - %s",
1886 SystemMessage(ret)));
1887
1888 goto cleanup;
1889 }
1890 }
1891
1892 // copy obtained information to output buffer
1893
1894 if (sFileName) {
1895
1896 // if filename is too long, clip it
1897
1898 if (image_info->NameLength >= MAX_PATH) {
1899 image_info->NameLength = MAX_PATH - 1;
1900 }
1901
1902 // ensure the name is properly terminated
1903
1904 image_info->FileName[image_info->NameLength] = '\0';
1905
1906 if (strncmp(image_info->FileName, "\\??\\UNC", 7) == 0) {
1907 *sFileName = '\\';
1908 strcpy(sFileName + 1, image_info->FileName + 7);
1909 }
1910 else if (strncmp(image_info->FileName, "\\??\\", 4) == 0) {
1911 strcpy(sFileName, image_info->FileName + 4);
1912 }
1913 else {
1914 strcpy(sFileName, image_info->FileName);
1915 }
1916 }
1917
1918 if (pDiskType) {
1919 *pDiskType = image_info->DiskType;
1920 }
1921
1922 if (pMediaType) {
1923 *pMediaType = image_info->MediaType;
1924 }
1925
1926 if (pMediaFlags) {
1927 *pMediaFlags = image_info->MediaFlags;
1928 }
1929
1930 if (pFileType) {
1931 *pFileType = image_info->FileType;
1932 }
1933
1934 if (pImageSize) {
1935 *pImageSize = image_info->ImageSize;
1936 }
1937
1938cleanup:
1939 if (image_info) {
1940 LocalFree(image_info);
1941 }
1942
1943 return ret;
1944}
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define ERROR_MORE_DATA
Definition: dderror.h:13
VFD_FLAGS MediaFlags
Definition: vfdio.h:66
VFD_FILETYPE FileType
Definition: vfdio.h:67
CHAR FileName[0]
Definition: vfdio.h:70
VFD_DISKTYPE DiskType
Definition: vfdio.h:64
ULONG ImageSize
Definition: vfdio.h:68
USHORT NameLength
Definition: vfdio.h:69
VFD_MEDIA MediaType
Definition: vfdio.h:65
#define IOCTL_VFD_QUERY_IMAGE
Definition: vfdio.h:163
struct _VFD_IMAGE_INFO * PVFD_IMAGE_INFO

Referenced by Close(), PrintImageInfo(), Save(), UpdateImageInfo(), VfdGuiClose(), VfdGuiSave(), and VfdImageTip().

◆ VfdGetLocalLink()

DWORD WINAPI VfdGetLocalLink ( HANDLE  hDevice,
PCHAR  pLetter 
)

Definition at line 2281 of file vfdctl.c.

2284{
2285#undef FUNC
2286#define FUNC "VfdGetLocalLinks"
2287 CHAR global;
2288 ULONG logical;
2289 CHAR dos_name[] = "A:";
2291 CHAR dos_target[MAX_PATH * 2];
2292 DWORD ret;
2293
2294 if (!pLetter) {
2296 }
2297
2298 // Get the VFD device name
2299
2300 ret = VfdGetDeviceName(hDevice, dev_name, sizeof(dev_name));
2301
2302 if (ret != ERROR_SUCCESS) {
2303 return ret;
2304 }
2305
2306 // Get global drive letter
2307
2308 ret = VfdGetGlobalLink(hDevice, &global);
2309
2310 if (ret != ERROR_SUCCESS) {
2311 return ret;
2312 }
2313
2314 // Get logical drives
2315
2316 logical = GetLogicalDrives();
2317
2318 // exclude the global drive letter
2319
2320 if (isalpha(global)) {
2321 logical &= ~(1 << (toupper(global) - 'A'));
2322 }
2323
2324 // start searching from the next drive letter
2325
2326 if (isalpha(*pLetter)) {
2327 dos_name[0] = (CHAR)(toupper(*pLetter) + 1);
2328 logical >>= (dos_name[0] - 'A');
2329 }
2330
2331 // Check dos device targets
2332
2333 *pLetter = '\0';
2334
2335 while (logical) {
2336 if (logical & 0x01) {
2337 if (QueryDosDevice(dos_name, dos_target, sizeof(dos_target))) {
2338 if (_stricmp(dos_target, dev_name) == 0) {
2339 *pLetter = dos_name[0];
2340 break;
2341 }
2342 }
2343 else {
2344 VFDTRACE(0,
2345 (FUNC ": QueryDosDevice(%s) - %s",
2346 dos_name, SystemMessage(GetLastError())));
2347 }
2348 }
2349 logical >>= 1;
2350 dos_name[0]++;
2351 }
2352
2353 return ERROR_SUCCESS;
2354}
int toupper(int c)
Definition: utclib.c:881
#define CHAR(Char)
int global
Definition: ehframes.cpp:22
const char * dev_name(int device)
Definition: wave.c:211
DWORD WINAPI VfdGetDeviceName(HANDLE hDevice, PCHAR pName, ULONG nLength)
Definition: vfdctl.c:2396
#define QueryDosDevice
Definition: winbase.h:3892

Referenced by Open(), PrintDriveLetter(), VfdCloseImage(), VfdOpenImage(), VfdSetGlobalLink(), VfdSetLocalLink(), and VfdStopDriver().

◆ VfdGetMediaSize()

ULONG WINAPI VfdGetMediaSize ( VFD_MEDIA  nMediaType)

Definition at line 3272 of file vfdctl.c.

3274{
3275 return nMediaType < VFD_MEDIA_MAX ? media_tbl[nMediaType].Size : 0;
3276}
static const struct @1560 media_tbl[VFD_MEDIA_MAX]
@ VFD_MEDIA_MAX
Definition: vfdtypes.h:43

Referenced by OnMediaType(), OnTarget(), Open(), VfdCreateImageFile(), and VfdOpenImage().

◆ VfdGetMediaState()

DWORD WINAPI VfdGetMediaState ( HANDLE  hDevice)

Definition at line 1949 of file vfdctl.c.

1951{
1952#undef FUNC
1953#define FUNC "VfdGetMediaState"
1954 DWORD result;
1956
1957 // Query file information
1958
1959 if (!DeviceIoControl(
1960 hDevice,
1962 NULL,
1963 0,
1964 NULL,
1965 0,
1966 &result,
1967 NULL))
1968 {
1969 ret = GetLastError();
1970
1971 if (ret != ERROR_NOT_READY) {
1972 VFDTRACE(0,
1973 (FUNC ": DeviceIoControl(IOCTL_DISK_IS_WRITABLE) - %s",
1974 SystemMessage(ret)));
1975 }
1976 }
1977
1978 return ret;
1979}
#define IOCTL_DISK_IS_WRITABLE
Definition: cdrw_usr.h:172

Referenced by CVfdShExt::DoVfdProtect(), Format(), Open(), Protect(), and CVfdShExt::QueryContextMenu().

◆ VfdGetNotifyMessage()

UINT WINAPI VfdGetNotifyMessage ( )

Definition at line 115 of file vfdlib.c.

116{
117 return g_nNotifyMsg;
118}
UINT g_nNotifyMsg

◆ VfdGuiClose()

DWORD WINAPI VfdGuiClose ( HWND  hParent,
ULONG  nDevice 
)

Definition at line 114 of file vfdguiut.c.

117{
118 HANDLE hDevice;
121 HCURSOR hourglass;
122 DWORD ret;
123 int reply;
124
125 VFDTRACE(0, ("VfdGuiClose()\n"));
126
127 hDevice = VfdOpenDevice(nDevice);
128
129 if (hDevice == INVALID_HANDLE_VALUE) {
130 return GetLastError();
131 }
132
133 // get current image information
134
136 hDevice,
137 path,
138 &param.DiskType,
139 &param.MediaType,
140 &param.MediaFlags,
141 &param.FileType,
142 &param.ImageSize);
143
144 if (ret != ERROR_SUCCESS) {
145 CloseHandle(hDevice);
146 return ret;
147 }
148
149 param.hDevice = hDevice;
150 param.ImageName = path;
151
152 // check if RAM image is modified
153
154 if (param.MediaFlags & VFD_FLAG_DATA_MODIFIED) {
155 PSTR msg = ModuleMessage(MSG_MEDIA_MODIFIED);
156
157 for (;;) {
158 reply = MessageBox(hParent, msg ? msg : "save?",
160
161 if (reply != IDYES) {
162 break;
163 }
164
165 if (GuiSaveParam(hParent, &param) == ERROR_SUCCESS) {
166 break;
167 }
168 }
169
170 if (msg) {
171 LocalFree(msg);
172 }
173
174 if (reply == IDCANCEL) {
175 CloseHandle(hDevice);
176 return ERROR_CANCELLED;
177 }
178 }
179
180 // close the image
181
182 hourglass = LoadCursor(NULL, IDC_WAIT);
183
184 for (;;) {
185
186 // show the hourglass cursor
187
188 HCURSOR original = SetCursor(hourglass);
189
190 // close the current image
191
192 ret = VfdCloseImage(hDevice, FALSE);
193
194 // restore the original cursor
195
196 SetCursor(original);
197
198 if (ret != ERROR_ACCESS_DENIED) {
199 // success or errors other than access denied
200 break;
201 }
202
203 if (IS_WINDOWS_NT()) {
204
205 // Windows NT -- cannot force close
206 // show retry / cancel message box
207
208 PSTR msg = ModuleMessage(MSG_UNMOUNT_FAILED);
209
210 reply = MessageBox(
211 hParent, msg ? msg : "retry", VFD_MSGBOX_TITLE,
213
214 if (msg) {
215 LocalFree(msg);
216 }
217 }
218 else {
219
220 // Windows 2000 and later -- possible to force
221 // show cancel / retry / continue message box
222
223 PSTR msg = ModuleMessage(MSG_UNMOUNT_CONFIRM);
224
225 reply = MessageBox(
226 hParent, msg ? msg : "retry", VFD_MSGBOX_TITLE,
228
229 if (msg) {
230 LocalFree(msg);
231 }
232
233 if (reply == IDCONTINUE) {
234
235 // try forced close
236
237 ret = VfdCloseImage(hDevice, TRUE);
238 }
239 }
240
241 if (reply == IDCANCEL) {
243 break;
244 }
245 else if (reply == IDCONTINUE) {
246
247 // try forced close
248
249 ret = VfdCloseImage(hDevice, TRUE);
250 break;
251 }
252 }
253
254 CloseHandle(hDevice);
255
256 return ret;
257}
#define msg(x)
Definition: auth_time.c:54
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLfloat param
Definition: glext.h:5796
DWORD WINAPI VfdGetImageInfo(HANDLE hDevice, PSTR sFileName, PVFD_DISKTYPE pDiskType, PVFD_MEDIA pMediaType, PVFD_FLAGS pMediaFlags, PVFD_FILETYPE pFileType, PULONG pImageSize)
Definition: vfdctl.c:1839
HANDLE WINAPI VfdOpenDevice(ULONG nTarget)
Definition: vfdctl.c:1215
#define IS_WINDOWS_NT()
Definition: vfdcmd.c:159
VOID VfdCloseImage(IN PDEVICE_EXTENSION DeviceExtension)
Definition: vfdimg.c:435
DWORD GuiSaveParam(HWND hParent, PCSAVE_PARAM pParam)
Definition: vfdguisave.c:101
#define IDCONTINUE
Definition: vfdguiut.c:42
#define MB_CANCELTRYCONTINUE
Definition: vfdguiut.c:34
PSTR ModuleMessage(DWORD nFormat,...)
Definition: vfdlib.c:124
#define VFD_MSGBOX_TITLE
Definition: vfdlib.h:53
#define VFD_FLAG_DATA_MODIFIED
Definition: vfdtypes.h:69
HICON HCURSOR
Definition: windef.h:299
#define ERROR_CANCELLED
Definition: winerror.h:726
#define IDCANCEL
Definition: winuser.h:831
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
#define MB_RETRYCANCEL
Definition: winuser.h:805
#define LoadCursor
Definition: winuser.h:5812
#define MB_ICONEXCLAMATION
Definition: winuser.h:785
#define MB_ICONQUESTION
Definition: winuser.h:789
#define MessageBox
Definition: winuser.h:5822
#define IDC_WAIT
Definition: winuser.h:689
#define IDYES
Definition: winuser.h:835
#define MB_YESNOCANCEL
Definition: winuser.h:818

Referenced by CVfdShExt::DoVfdClose().

◆ VfdGuiFormat()

DWORD WINAPI VfdGuiFormat ( HWND  hParent,
ULONG  nDevice 
)

Definition at line 262 of file vfdguiut.c.

265{
266 HANDLE hDevice;
267 ULONG ret;
268 PSTR msg;
269
270 msg = ModuleMessage(MSG_FORMAT_WARNING);
271
272 ret = MessageBox(hParent,
273 msg ? msg : "Format?",
276
277 if (msg) {
278 LocalFree(msg);
279 }
280
281 if (ret == IDCANCEL) {
282 MessageBox(hParent,
285
286 return ERROR_CANCELLED;
287 }
288
289 hDevice = VfdOpenDevice(nDevice);
290
291 if (hDevice == INVALID_HANDLE_VALUE) {
292 ret = GetLastError();
293 }
294 else {
295 HCURSOR original;
296
297retry:
298 original = SetCursor(LoadCursor(NULL, IDC_WAIT));
299
300 ret = VfdDismountVolume(hDevice, FALSE);
301
302 if (ret == ERROR_ACCESS_DENIED) {
303 PSTR msg;
304 int reply;
305
306 SetCursor(original);
307
308 msg = ModuleMessage(MSG_UNMOUNT_CONFIRM);
309
310 reply = MessageBox(
311 hParent, msg ? msg : "retry", VFD_MSGBOX_TITLE,
313
314 if (msg) {
315 LocalFree(msg);
316 }
317
318 if (reply == IDRETRY) {
319 goto retry;
320 }
321 else if (reply == IDCANCEL) {
323 }
324 else {
325 VfdDismountVolume(hDevice, TRUE);
327 }
328 }
329
330 if (ret == ERROR_SUCCESS) {
331 ret = VfdFormatMedia(hDevice);
332 }
333
334 SetCursor(original);
335
336 CloseHandle(hDevice);
337 }
338
339 MessageBox(hParent,
343
344 return ret;
345}
DWORD WINAPI VfdFormatMedia(HANDLE hDevice)
Definition: vfdctl.c:2523
DWORD WINAPI VfdDismountVolume(HANDLE hDevice, BOOL bForce)
Definition: vfdctl.c:2629
#define MB_OKCANCEL
Definition: winuser.h:804
#define MB_ICONINFORMATION
Definition: winuser.h:802
#define MB_ICONSTOP
Definition: winuser.h:803
#define IDRETRY
Definition: winuser.h:833

Referenced by VfdPageDlgProc().

◆ VfdGuiOpen()

DWORD WINAPI VfdGuiOpen ( HWND  hParent,
ULONG  nDevice 
)

Definition at line 71 of file vfdguiopen.c.

74{
75 switch (DialogBoxParam(
78 hParent,
80 nDevice))
81 {
82 case IDOK:
83 return ERROR_SUCCESS;
84
85 case IDCANCEL:
86 return ERROR_CANCELLED;
87
88 default:
89 return GetLastError();
90 }
91}
static INT CALLBACK OpenDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: vfdguiopen.c:97
#define IDD_OPENDIALOG
Definition: vfdguirc.h:6
HINSTANCE g_hDllModule
#define DialogBoxParam
Definition: winuser.h:5764
#define IDOK
Definition: winuser.h:830
#define MAKEINTRESOURCE
Definition: winuser.h:591

Referenced by CVfdShExt::DoVfdOpen().

◆ VfdGuiSave()

DWORD WINAPI VfdGuiSave ( HWND  hParent,
ULONG  nDevice 
)

Definition at line 58 of file vfdguisave.c.

61{
64 DWORD ret;
65
66 // open the source device
67
68 param.hDevice = VfdOpenDevice(nDevice);
69
70 if (param.hDevice == INVALID_HANDLE_VALUE) {
71 return GetLastError();
72 }
73
74 // get current image information
75
76 param.ImageName = path;
77
79 param.hDevice,
80 param.ImageName,
81 &param.DiskType,
82 &param.MediaType,
83 &param.MediaFlags,
84 &param.FileType,
85 &param.ImageSize);
86
87 if (ret == ERROR_SUCCESS) {
88
89 // show dialog box
90
91 ret = GuiSaveParam(hParent, &param);
92 }
93
94 // close the source device
95
96 CloseHandle(param.hDevice);
97
98 return ret;
99}

Referenced by CVfdShExt::DoVfdSave().

◆ VfdImageTip()

void WINAPI VfdImageTip ( HWND  hParent,
ULONG  nDevice 
)

Definition at line 266 of file vfdguitip.c.

269{
270 HANDLE hDevice;
271 PSTR info_str = NULL;
272 PSTR type_str = NULL;
273 PSTR prot_str = NULL;
274 PCSTR media_str = NULL;
277 VFD_DISKTYPE disk_type;
278 VFD_MEDIA media_type;
279 VFD_FLAGS media_flags;
282 DWORD file_attr;
283 ULONG ret;
284
285 hDevice = VfdOpenDevice(nDevice);
286
287 if (hDevice == INVALID_HANDLE_VALUE) {
288 VfdToolTip(hParent,
289 SystemMessage(GetLastError()), -1, -1, FALSE);
290 return;
291 }
292
294 hDevice,
295 path,
296 &disk_type,
297 &media_type,
298 &media_flags,
299 &file_type,
300 &image_size);
301
302 CloseHandle(hDevice);
303
304 if (ret != ERROR_SUCCESS) {
305 VfdToolTip(hParent, SystemMessage(ret), -1, -1, FALSE);
306 return;
307 }
308
309 if (path[0]) {
310 file_attr = GetFileAttributes(path);
311 }
312 else {
313 if (disk_type != VFD_DISKTYPE_FILE) {
314 strcpy(path, "<RAM>");
315 }
316 file_attr = 0;
317 }
318
319 VfdMakeFileDesc(desc, sizeof(desc),
320 file_type, image_size, file_attr);
321
322 if (disk_type == VFD_DISKTYPE_FILE) {
323 type_str = "FILE";
324 }
325 else {
326 type_str = "RAM";
327 }
328
329 media_str = VfdMediaTypeName(media_type);
330
331 if (media_flags & VFD_FLAG_WRITE_PROTECTED) {
332 prot_str = ModuleMessage(MSG_WRITE_PROTECTED);
333 }
334 else {
335 prot_str = ModuleMessage(MSG_WRITE_ALLOWED);
336 }
337
338 info_str = ModuleMessage(
339 MSG_IMAGE_INFOTIP,
340 path,
341 desc,
342 type_str ? type_str : "",
343 media_str ? media_str : "",
344 prot_str ? prot_str : "");
345
346 if (info_str) {
347 VfdToolTip(hParent, info_str, -1, -1, FALSE);
348 LocalFree(info_str);
349 }
350
351 if (prot_str) {
352 LocalFree(prot_str);
353 }
354}
static GLint image_size(GLint width, GLint height, GLenum format, GLenum type)
Definition: mipmap.c:4858
static const WCHAR desc[]
Definition: protectdata.c:36
FD_TYPE file_type(FDSC **curr, char *fixed)
Definition: file.c:221
const char * PCSTR
Definition: typedefs.h:52
void WINAPI VfdMakeFileDesc(PSTR pBuffer, ULONG nBufSize, VFD_FILETYPE nFileType, ULONG nFileSize, DWORD nFileAttr)
Definition: vfdguiut.c:376
PCSTR WINAPI VfdMediaTypeName(VFD_MEDIA nMediaType)
Definition: vfdctl.c:3280
void WINAPI VfdToolTip(HWND hParent, PCSTR sText, int pos_x, int pos_y, BOOL stick)
Definition: vfdguitip.c:134
UCHAR VFD_FILETYPE
Definition: vfdtypes.h:62
UCHAR VFD_MEDIA
Definition: vfdtypes.h:61
UCHAR VFD_DISKTYPE
Definition: vfdtypes.h:60
@ VFD_DISKTYPE_FILE
Definition: vfdtypes.h:18
#define VFD_FLAG_WRITE_PROTECTED
Definition: vfdtypes.h:68
UCHAR VFD_FLAGS
Definition: vfdtypes.h:63

Referenced by CVfdShExt::InvokeCommand().

◆ VfdInstallDriver()

DWORD WINAPI VfdInstallDriver ( PCSTR  sFileName,
DWORD  nStart 
)

Definition at line 241 of file vfdctl.c.

244{
245#undef FUNC
246#define FUNC "VfdInstallDriver"
247 SC_HANDLE hScManager; // Service Control Manager
248 SC_HANDLE hService = NULL; // Service (= Driver)
249#ifndef VFD_EMBED_DRIVER
252#endif // VFD_EMBED_DRIVER
253 CHAR system_dir[MAX_PATH];
254 PSTR inst_path;
255 DWORD len;
257
258#ifdef __REACTOS__
259 CHAR full_file_path[MAX_PATH];
260#endif
261
262 // get SystemRoot directory path
263
264// len = GetEnvironmentVariable(
265// "SystemRoot", system_dir, sizeof(system_dir));
266 len = GetWindowsDirectory(system_dir, sizeof(system_dir));
267
268 if (len == 0 || len > sizeof(system_dir)) {
269 VFDTRACE(0,
270 (FUNC ": %%SystemRoot%% is empty or too long.\n"));
271
273 }
274
275 inst_path = &system_dir[len];
276
277#ifdef __REACTOS__
278 strcpy(full_file_path, system_dir);
279 strcat(full_file_path, VFD_INSTALL_DIRECTORY);
280 strcat(full_file_path, VFD_DRIVER_FILENAME);
281#endif
282
283#ifdef VFD_EMBED_DRIVER
284 //
285 // use embedded driver file
286 //
288
289 ret = VfdRestoreDriver(system_dir);
290
291 if (ret != ERROR_SUCCESS) {
292 return ret;
293 }
294
295#else // VFD_EMBED_DRIVER
296 // Prepare driver binary's full path
297
298 if (sFileName == NULL || *sFileName == '\0') {
299
300 // default driver file is vfd.sys in the same directory as executable
301
303 NULL, file_path, sizeof(file_path));
304
305 if (len == 0) {
306 ret = GetLastError();
307
308 VFDTRACE(0,
309 (FUNC ": GetModuleFileName - %s",
311
312 return ret;
313 }
314
315 // search the last '\' character
316
317 while (len > 0 && file_path[len - 1] != '\\') {
318 len --;
319 }
320
321 // supply the file name (vfd.sys)
322
325 }
326 else {
327
328 // ensure that tha path is an absolute full path
329
331 sFileName,
332 sizeof(file_path),
333 file_path,
334 &file_name);
335
336 if (len == 0) {
337 ret = GetLastError();
338
339 VFDTRACE(0,
340 (FUNC ": GetFullPathName(%s) - %s\n",
341 sFileName, SystemMessage(ret)));
342
343 return ret;
344 }
345
347 // if the specified path is a directory,
348 // supply the file name (vfd.sys)
349
352 }
353 }
354
355#ifdef __REACTOS__
356 // Check install directory & file exist or use full_file_path
357
359 strcpy(file_path, full_file_path);
360 }
361#endif
362
363 // Check if the file is a valid Virtual Floppy driver
364
366
367 if (ret != ERROR_SUCCESS) {
368 VFDTRACE(0,
369 (FUNC ": VfdCheckDriverFile(%s)\n", file_path));
370
371 return ret;
372 }
373
374 // if the path is under the system directory, make it relative
375 // to the system directory
376
377 len = strlen(system_dir);
378
379 if (!_strnicmp(file_path, system_dir, len)) {
380 inst_path = &file_path[len];
381
382 while (*inst_path == '\\') {
383 inst_path++;
384 }
385 }
386 else {
387 inst_path = &file_path[0];
388 }
389#endif // VFD_EMBED_DRIVER
390
391 // Connect to the Service Control Manager
392
393 hScManager = OpenSCManager(
394 NULL, // local machine
395 NULL, // local database
396 SC_MANAGER_CREATE_SERVICE); // access required
397
398 if (hScManager == NULL) {
399 ret = GetLastError();
400
401 VFDTRACE(0,
402 (FUNC ": OpenSCManager() - %s",
404
405 goto cleanup;
406 }
407
408 // Create a new service object
409
410 hService = CreateService(
411 hScManager, // service control manager
412 VFD_DEVICE_BASENAME, // internal service name
413 VFD_DEVICE_BASENAME, // display name
414 SERVICE_ALL_ACCESS, // access mode
415 SERVICE_KERNEL_DRIVER, // service type
416 nStart, // service start type
417 SERVICE_ERROR_NORMAL, // start error sevirity
418 inst_path, // service image file path
419 NULL, // service group
420 NULL, // service tag
421 NULL, // service dependency
422 NULL, // use LocalSystem account
423 NULL // password for the account
424 );
425
426 if (!hService) {
427 // Failed to create a service object
428 ret = GetLastError();
429
430 VFDTRACE(0,
431 (FUNC ": CreateService() - %s",
433
434 goto cleanup;
435 }
436
437cleanup:
438 // Close the service object handle
439
440 if (hService) {
441 CloseServiceHandle(hService);
442 }
443
444 // Close handle to the service control manager.
445
446 if (hScManager) {
447 CloseServiceHandle(hScManager);
448 }
449
450 if (ret == ERROR_SUCCESS) {
451 // Broadcast the successful operation
453 }
454#ifdef VFD_EMBED_DRIVER
455 else {
456 // Delete the restored driver file
457 DeleteFile(system_dir);
458 }
459#endif // VFD_EMBED_DRIVER
460
461 return ret;
462}
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:636
static LPCWSTR file_name
Definition: protocol.c:147
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
TCHAR file_path[MAX_PATH]
Definition: sndrec32.cpp:57
#define VFD_INSTALL_DIRECTORY
Definition: vfdctl.c:56
DWORD WINAPI VfdCheckDriverFile(PCSTR sFileName, PULONG pFileVersion)
Definition: vfdctl.c:2867
#define DeleteFile
Definition: winbase.h:3764
#define GetModuleFileName
Definition: winbase.h:3831
#define GetFullPathName
Definition: winbase.h:3821
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#define CreateService
Definition: winsvc.h:569
#define SC_MANAGER_CREATE_SERVICE
Definition: winsvc.h:15
#define SERVICE_KERNEL_DRIVER
Definition: cmtypes.h:953
#define SERVICE_ERROR_NORMAL
Definition: cmtypes.h:982

Referenced by Install().

◆ VfdIsValidPlatform()

BOOL WINAPI VfdIsValidPlatform ( )

Definition at line 87 of file vfdlib.c.

88{
89 BOOL (WINAPI *pfnIsWow64Process)(HANDLE, PBOOL);
90 BOOL wow64;
91
92 if (GetVersion() & 0x80000000) {
93 return FALSE; // doesn't work on Win9x
94 }
95
96 pfnIsWow64Process = (BOOL (WINAPI *)(HANDLE, PBOOL))
97 GetProcAddress(GetModuleHandle("kernel32.dll"), "IsWow64Process");
98
99 if (pfnIsWow64Process == NULL) {
100 return TRUE; // NT4 or 2000 -- assured to be 32 bit
101 }
102
103 wow64 = FALSE;
104
105 if (!pfnIsWow64Process(GetCurrentProcess(), &wow64)) {
106 return FALSE;
107 }
108
109 return !wow64;
110}
#define GetProcAddress(x, y)
Definition: compat.h:753
#define GetCurrentProcess()
Definition: compat.h:759
unsigned int BOOL
Definition: ntddk_ex.h:94
#define BOOL
Definition: nt_native.h:43
static BOOL wow64
Definition: psapi_main.c:44
DWORD WINAPI GetVersion()
Definition: redirtest.c:5
PVOID HANDLE
Definition: typedefs.h:73
#define GetModuleHandle
Definition: winbase.h:3827
BOOL * PBOOL
Definition: windef.h:161
#define WINAPI
Definition: msvc.h:6

Referenced by main().

◆ VfdLookupMedia()

VFD_MEDIA WINAPI VfdLookupMedia ( ULONG  nSize)

Definition at line 3256 of file vfdctl.c.

3258{
3259 VFD_MEDIA i;
3260
3261 for (i = 1; i < VFD_MEDIA_MAX; i++) {
3262 if (nSize < media_tbl[i].Size) {
3263 break;
3264 }
3265 }
3266
3267 return (--i);
3268}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2084

Referenced by CVfdShExt::DoVfdDrop(), OnImage(), and Open().

◆ VfdMakeFileDesc()

void WINAPI VfdMakeFileDesc ( PSTR  pBuffer,
ULONG  nBufSize,
VFD_FILETYPE  nFileType,
ULONG  nFileSize,
DWORD  nFileAttr 
)

Definition at line 376 of file vfdguiut.c.

382{
383 PSTR type_str;
384 PSTR size_str;
385 PSTR attr_ro;
386 PSTR attr_enc;
388
389 ZeroMemory(pBuffer, nBufSize);
390
391 switch (nFileType) {
392 case VFD_FILETYPE_RAW:
393 type_str = ModuleMessage(MSG_FILETYPE_RAW);
394 break;
395
396 case VFD_FILETYPE_ZIP:
397 type_str = ModuleMessage(MSG_FILETYPE_ZIP);
398 break;
399
400 default:
401 type_str = NULL;
402 }
403
404 if (nFileSize == INVALID_FILE_SIZE) {
405 size_str = ModuleMessage(MSG_DESC_NEW_FILE);
406 }
407 else {
408 CHAR buf[20], buf2[20];
409 size_str = ModuleMessage(MSG_DESC_FILESIZE,
410 FormatSizeBytes(nFileSize, buf),
411 FormatSizeUnits(nFileSize, buf2));
412 }
413
414 attr_ro = NULL;
415 attr_cmp = NULL;
416 attr_enc = NULL;
417
418 if (nFileAttr != INVALID_FILE_ATTRIBUTES) {
419 if (nFileAttr & FILE_ATTRIBUTE_READONLY) {
420 attr_ro = ModuleMessage(MSG_ATTR_READONLY);
421 }
422
423 if (nFileAttr & FILE_ATTRIBUTE_COMPRESSED) {
424 attr_cmp = ModuleMessage(MSG_ATTR_COMPRESSED);
425 }
426
427 if (nFileAttr & FILE_ATTRIBUTE_ENCRYPTED) {
428 attr_enc = ModuleMessage(MSG_ATTR_ENCRYPTED);
429 }
430 }
431
432 _snprintf(pBuffer, nBufSize - 1, "%s %s %s %s %s",
433 type_str ? type_str : "",
434 size_str ? size_str : "",
435 attr_ro ? attr_ro : "",
436 attr_cmp ? attr_cmp : "",
437 attr_enc ? attr_enc : "");
438
439 if (type_str) {
440 LocalFree(type_str);
441 }
442 if (size_str) {
443 LocalFree(size_str);
444 }
445 if (attr_ro) {
446 LocalFree(attr_ro);
447 }
448 if (attr_cmp) {
450 }
451 if (attr_enc) {
452 LocalFree(attr_enc);
453 }
454}
int attr_cmp(struct attr_cache_entry *lhs, struct attr_cache_entry *rhs)
Definition: name_cache.c:113
#define FILE_ATTRIBUTE_COMPRESSED
Definition: nt_native.h:711
#define FILE_ATTRIBUTE_ENCRYPTED
Definition: ntifs_ex.h:385
PVOID pBuffer
static PSTR FormatSizeUnits(ULONG size, PSTR buf)
Definition: vfdguiut.c:68
static PSTR FormatSizeBytes(ULONG size, PSTR buf)
Definition: vfdguiut.c:48
#define INVALID_FILE_SIZE
Definition: winbase.h:548
#define _snprintf
Definition: xmlstorage.h:200

Referenced by OnImage(), OnTarget(), PrintImageInfo(), UpdateImageInfo(), and VfdImageTip().

◆ VfdMediaTypeName()

PCSTR WINAPI VfdMediaTypeName ( VFD_MEDIA  nMediaType)

Definition at line 3280 of file vfdctl.c.

3282{
3283 return nMediaType < VFD_MEDIA_MAX ? media_tbl[nMediaType].Name : NULL;
3284}

Referenced by OnInit(), Open(), PrintImageInfo(), UpdateImageInfo(), VfdImageTip(), and VfdOpenImage().

◆ VfdOpenDevice()

HANDLE WINAPI VfdOpenDevice ( ULONG  nTarget)

Definition at line 1215 of file vfdctl.c.

1217{
1218#undef FUNC
1219#define FUNC "VfdOpenDevice"
1220 CHAR dev_name[20];
1221 UINT err_mode;
1222 HANDLE hDevice;
1223
1224 // format a device name string
1225
1226 if (isalpha(nTarget)) {
1227 // nTarget is a drive letter
1228 // \\.<x>:
1229#ifndef __REACTOS__
1231#else
1233#endif
1234 }
1235 else if (isdigit(nTarget)) {
1236 // nTarget is a device number in character
1237 // \\.\VirtualFD<n>
1238 sprintf(dev_name, VFD_DEVICE_TEMPLATE, nTarget - '0');
1239 }
1240 else {
1241 // nTarget is a device number value
1242 // \\.\VirtualFD<n>
1244 }
1245
1246 // change error mode in order to avoid "Insert Floppy" dialog
1247
1249
1250 // open the target drive
1251
1252 hDevice = CreateFile(
1253 dev_name,
1256 NULL,
1259 NULL);
1260
1261 // revert to the original error mode
1262
1263 SetErrorMode(err_mode);
1264
1265 if (hDevice != INVALID_HANDLE_VALUE) {
1266
1267 // check if the target is a valid VFD drive
1268
1269 ULONG version;
1270
1271 if (VfdGetDriverVersion(hDevice, &version) != ERROR_SUCCESS) {
1272
1273 // Failed to get the driver version
1274
1275 CloseHandle(hDevice);
1276 hDevice = INVALID_HANDLE_VALUE;
1277 }
1278 else if ((version & ~0x80000000) !=
1280
1281 // the driver version mismatch
1282
1283// CloseHandle(hDevice);
1284// hDevice = INVALID_HANDLE_VALUE;
1285
1287 }
1288 }
1289 else {
1290 VFDTRACE(0,(
1291 "CreateFile(%s) - %s", dev_name,
1293 }
1294
1295 return hDevice;
1296}
#define isdigit(c)
Definition: acclib.h:68
#define SetLastError(x)
Definition: compat.h:752
static const WCHAR version[]
Definition: asmname.c:66
UINT WINAPI SetErrorMode(IN UINT uMode)
Definition: except.c:751
#define FILE_FLAG_NO_BUFFERING
Definition: disk.h:45
unsigned int UINT
Definition: ndis.h:50
#define SEM_FAILCRITICALERRORS
Definition: rtltypes.h:69
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define VFD_VOLUME_TEMPLATE
Definition: vfdctl.c:54
#define VFD_DEVICE_TEMPLATE
Definition: vfdctl.c:50
DWORD WINAPI VfdGetDriverVersion(HANDLE hDevice, PULONG pVersion)
Definition: vfdctl.c:2446
#define ERROR_REVISION_MISMATCH
Definition: winerror.h:788

Referenced by CheckDriver(), Close(), CVfdShExt::DoVfdDrop(), CVfdShExt::DoVfdProtect(), Format(), CVfdShExt::Initialize(), Link(), OnOK(), Open(), Protect(), CVfdShExt::QueryContextMenu(), Save(), Status(), Unlink(), UpdateImageInfo(), VfdGuiClose(), VfdGuiFormat(), VfdGuiSave(), VfdImageTip(), VfdStartDriver(), and VfdStopDriver().

◆ VfdOpenImage()

DWORD WINAPI VfdOpenImage ( HANDLE  hDevice,
PCSTR  sFileName,
VFD_DISKTYPE  nDiskType,
VFD_MEDIA  nMediaType,
VFD_FLAGS  nMediaFlags 
)

Definition at line 1301 of file vfdctl.c.

1307{
1308#undef FUNC
1309#define FUNC "VfdOpenImage"
1310 PCSTR prefix;
1311 CHAR abspath[MAX_PATH];
1312 DWORD name_len;
1313 DWORD result;
1315
1316 PVFD_IMAGE_INFO image_info = NULL;
1317 PUCHAR image_buf = NULL;
1320
1321 //
1322 // Check parameters
1323 //
1324
1325 if (hDevice == NULL ||
1326 hDevice == INVALID_HANDLE_VALUE) {
1327 return ERROR_INVALID_HANDLE;
1328 }
1329
1330 if (nMediaType == VFD_MEDIA_NONE ||
1331 nMediaType >= VFD_MEDIA_MAX) {
1332
1333 VFDTRACE(0,
1334 (FUNC ": Invalid MediaType - %u\n", nMediaType));
1335
1337 }
1338
1339
1340 if (sFileName && *sFileName) {
1341
1342 // check file contents and attributes
1343
1344 HANDLE hFile = CreateFile(sFileName, GENERIC_READ,
1346
1347 if (hFile == INVALID_HANDLE_VALUE) {
1348 ret = GetLastError();
1349
1350 VFDTRACE(0,
1351 (FUNC ": CreateFile(%s) - %s",
1352 sFileName, SystemMessage(ret)));
1353
1354 return ret;
1355 }
1356
1357 // try extracting image data from zip compressed file
1358
1359 ExtractZipImage(hFile, &image_buf, &image_size);
1360
1361 if (image_buf) {
1362
1364
1365 // imz file must be opened in RAM mode
1366
1367 if (nDiskType == VFD_DISKTYPE_FILE) {
1368
1369 VFDTRACE(0,
1370 (FUNC ": %s is a zip compressed file",
1371 sFileName));
1372
1375
1376 goto exit_func;
1377 }
1378 }
1379 else {
1380
1382
1383 if (nDiskType == VFD_DISKTYPE_FILE) {
1384
1385 // direct image file must not be compressed or encrypted
1386
1388
1390 ret = GetLastError();
1391
1392 VFDTRACE(0,
1393 (FUNC ": GetFileInformationByHandle - %s",
1394 SystemMessage(ret)));
1395
1397
1398 return ret;
1399 }
1400
1401 if (info.dwFileAttributes &
1403
1404 VFDTRACE(0,
1405 (FUNC ": file is compressed/encrypted"));
1406
1408
1409 return ERROR_FILE_ENCRYPTED;
1410 }
1411
1412 image_size = info.nFileSizeLow;
1413 }
1414 else {
1415
1416 // prepare image data for a file based RAM disk
1417
1419
1420 if (image_size == 0 || image_size == INVALID_FILE_SIZE) {
1421 ret = GetLastError();
1422
1423 VFDTRACE(0,
1424 (FUNC ": GetFileSize - %s",
1425 SystemMessage(ret)));
1426
1428
1429 return ret;
1430 }
1431
1432 image_buf = (PUCHAR)LocalAlloc(LPTR, image_size);
1433
1434 if (image_buf == NULL) {
1435 ret = GetLastError();
1436
1437 VFDTRACE(0,
1438 (FUNC ": LocalAlloc - %s",
1439 SystemMessage(ret)));
1440
1442
1443 return ret;
1444 }
1445
1446 if (SetFilePointer(hFile, 0, NULL, FILE_BEGIN) != 0) {
1447 ret = GetLastError();
1448
1449 VFDTRACE(0,
1450 (FUNC ": SetFilePointer - %s",
1451 SystemMessage(ret)));
1452
1454
1455 goto exit_func;
1456 }
1457
1458 if (!ReadFile(hFile, image_buf, image_size, &result, NULL) ||
1459 image_size != result) {
1460
1461 ret = GetLastError();
1462
1463 VFDTRACE(0,
1464 (FUNC ": ReadFile - %s",
1465 SystemMessage(ret)));
1466
1468
1469 goto exit_func;
1470 }
1471 }
1472 }
1473
1475
1476 // Prepare absolute path in the kernel namespace
1477
1478 if (*sFileName == '\\' && *(sFileName + 1) == '\\') {
1479
1480 // \\server\share\path\floppy.img
1481
1482 prefix = "\\??\\UNC";
1483 sFileName++; // drip the first '\'
1484 }
1485 else {
1486
1487 // local path
1488
1489 PSTR file_part;
1490
1491 if (GetFullPathName(sFileName,
1492 sizeof(abspath), abspath, &file_part) == 0) {
1493
1494 ret = GetLastError();
1495
1496 VFDTRACE(0,
1497 (FUNC ": GetFullPathName(%s) - %s\n",
1498 sFileName, SystemMessage(ret)));
1499
1500 goto exit_func;
1501 }
1502
1503 prefix = "\\??\\";
1504 sFileName = abspath;
1505 }
1506
1507 name_len = strlen(prefix) + strlen(sFileName);
1508 }
1509 else {
1510
1511 // filename is not specified -- pure RAM disk
1512
1513 nDiskType = VFD_DISKTYPE_RAM;
1515
1516 prefix = NULL;
1517 name_len = 0;
1518
1519 // prepare a FAT formatted RAM image
1520
1521 image_size = VfdGetMediaSize(nMediaType);
1522
1523 image_buf = (PUCHAR)LocalAlloc(LPTR, image_size);
1524
1525 if (image_buf == NULL) {
1526 ret = GetLastError();
1527
1528 VFDTRACE(0,
1529 (FUNC ": LocalAlloc - %s",
1530 SystemMessage(ret)));
1531
1532 return ret;
1533 }
1534
1536 }
1537
1538 if (image_size < VfdGetMediaSize(nMediaType)) {
1539
1540 // image is too small for the specified media type
1541
1542 VFDTRACE(0,
1543 (FUNC ": Image is too small for the specified media type\n"));
1544
1546 goto exit_func;
1547 }
1548
1549 // prepare VFD_IMAGE_INFO structure
1550
1551 image_info = (PVFD_IMAGE_INFO)LocalAlloc(LPTR,
1552 sizeof(VFD_IMAGE_INFO) + name_len + 1);
1553
1554 if (image_info == NULL) {
1555 ret = GetLastError();
1556
1557 VFDTRACE(0,
1558 (FUNC ": LocalAlloc(%lu) - %s\n",
1559 sizeof(VFD_IMAGE_INFO) + name_len + 1,
1560 SystemMessage(ret)));
1561
1562 goto exit_func;
1563 }
1564
1565 ZeroMemory(image_info,
1566 sizeof(VFD_IMAGE_INFO) + name_len + 1);
1567
1568 if (name_len) {
1569 sprintf(image_info->FileName,
1570 "%s%s", prefix, sFileName);
1571 }
1572
1573 image_info->NameLength = (USHORT)name_len;
1574
1575 image_info->DiskType = nDiskType;
1576 image_info->MediaType = nMediaType;
1577 image_info->MediaFlags = nMediaFlags;
1578 image_info->FileType = file_type;
1579 image_info->ImageSize = image_size;
1580
1581 if (nDiskType != VFD_DISKTYPE_FILE) {
1582 // protect flag for a RAM disk is set after
1583 // initializing the image buffer
1584 image_info->MediaFlags &= ~VFD_FLAG_WRITE_PROTECTED;
1585 }
1586
1587 VFDTRACE(0,
1588 (FUNC ": Opening file \"%s\" (%lu bytes) %s %s %s %s\n",
1589 name_len ? image_info->FileName : "<RAM>",
1590 image_info->ImageSize,
1591 (file_type == VFD_FILETYPE_ZIP) ? "ZIP image" : "RAW image",
1592 VfdMediaTypeName(nMediaType),
1593 (nDiskType == VFD_DISKTYPE_FILE) ? "FILE disk" : "RAM disk",
1594 (nMediaFlags & VFD_FLAG_WRITE_PROTECTED) ? "Protected" : "Writable"));
1595
1596 // Open the image file / create a ram disk
1597
1598 if (!DeviceIoControl(
1599 hDevice,
1601 image_info,
1602 sizeof(VFD_IMAGE_INFO) + name_len,
1603 NULL,
1604 0,
1605 &result,
1606 NULL))
1607 {
1608 ret = GetLastError();
1609
1610 VFDTRACE(0,
1611 (FUNC ": DeviceIoControl(IOCTL_VFD_OPEN_FILE) - %s",
1612 SystemMessage(ret)));
1613
1614 goto exit_func;
1615 }
1616
1617 // initialize the RAM disk image
1618
1619 if (nDiskType != VFD_DISKTYPE_FILE) {
1620
1621 image_size &= ~VFD_SECTOR_ALIGN_MASK;
1622
1623 if (SetFilePointer(hDevice, 0, NULL, FILE_BEGIN) != 0) {
1624 ret = GetLastError();
1625
1626 VFDTRACE(0,
1627 (FUNC ": SetFilePointer - %s",
1628 SystemMessage(ret)));
1629
1630 goto exit_func;
1631 }
1632
1633 if (!WriteFile(hDevice, image_buf, image_size, &result, NULL) ||
1634 image_size != result) {
1635
1636 ret = GetLastError();
1637
1638 VFDTRACE(0,
1639 (FUNC ": WriteFile - %s",
1640 SystemMessage(ret)));
1641
1642 goto exit_func;
1643 }
1644
1645 if (nMediaFlags & VFD_FLAG_WRITE_PROTECTED) {
1646 VfdWriteProtect(hDevice, TRUE);
1647 }
1648
1649 if (!DeviceIoControl(
1650 hDevice,
1652 NULL,
1653 0,
1654 NULL,
1655 0,
1656 &result,
1657 NULL))
1658 {
1659 VFDTRACE(0,
1660 (FUNC ": DeviceIoControl(IOCTL_VFD_RESET_MODIFY) - %s",
1662 }
1663 }
1664
1665 // Broadcast the successful operation
1666
1667 if (ret == ERROR_SUCCESS) {
1668 ULONG number;
1669 CHAR root[] = "A:\\";
1670
1671 if (VfdGetDeviceNumber(hDevice, &number) == ERROR_SUCCESS) {
1673 }
1674
1675 VfdGetGlobalLink(hDevice, &root[0]);
1676
1677 if (isalpha(root[0])) {
1679 }
1680
1681 while (VfdGetLocalLink(hDevice, &root[0]) == ERROR_SUCCESS &&
1682 isalpha(root[0])) {
1684 }
1685 }
1686
1687exit_func:
1688 if (image_info) {
1689 LocalFree(image_info);
1690 }
1691
1692 if (image_buf) {
1693 LocalFree(image_buf);
1694 }
1695
1696 return ret;
1697}
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
BOOL WINAPI GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
Definition: fileinfo.c:458
unsigned short USHORT
Definition: pedump.c:61
#define SHCNE_MEDIAINSERTED
Definition: shlobj.h:1880
DWORD WINAPI VfdWriteProtect(HANDLE hDevice, BOOL bProtect)
Definition: vfdctl.c:2484
PCSTR WINAPI VfdMediaTypeName(VFD_MEDIA nMediaType)
Definition: vfdctl.c:3280
#define IOCTL_VFD_RESET_MODIFY
Definition: vfdio.h:299
#define IOCTL_VFD_OPEN_IMAGE
Definition: vfdio.h:107
DWORD ExtractZipImage(HANDLE hFile, PUCHAR *pBuffer, PULONG pLength)
Definition: vfdzip.c:182
@ VFD_MEDIA_NONE
Definition: vfdtypes.h:27
@ VFD_DISKTYPE_RAM
Definition: vfdtypes.h:19
@ VFD_FILETYPE_NONE
Definition: vfdtypes.h:51
#define ERROR_FILE_ENCRYPTED
Definition: winerror.h:1400

◆ VfdRegisterHandlers()

DWORD WINAPI VfdRegisterHandlers ( )

Definition at line 100 of file vfdshutil.cpp.

101{
103 TCHAR guid_str[40];
104 HKEY hKey;
105 DWORD temp;
106 DWORD ret;
107
108 MakeGuidString(guid_str, CLSID_VfdShellExt);
109
110 //
111 // Register the GUID in the CLSID subtree
112 //
113 sprintf(buf, "CLSID\\%s", guid_str);
114
115 VFDTRACE(0, ("HKCR\\%s\n", buf));
116
119 0, KEY_ALL_ACCESS, NULL, &hKey, &temp);
120
121 if (ret != ERROR_SUCCESS) {
122 return ret;
123 }
124
126 temp = sizeof(buf);
127
129 hKey, NULL, NULL, NULL, (PBYTE)buf, &temp);
130
131 if (ret != ERROR_SUCCESS) {
133 return ret;
134 }
135
138 return ERROR_FILE_EXISTS;
139 }
140 }
141 else {
142
143 VFDTRACE(0, ("@=" VFDEXT_DESCRIPTION "\n"));
144
147
149
150 if (ret != ERROR_SUCCESS) {
151 return ret;
152 }
153 }
154
155 //
156 // Register the executable path
157 //
158 sprintf(buf, "CLSID\\%s\\InProcServer32", guid_str);
159
160 VFDTRACE(0, ("HKCR\\%s\n", buf));
161
165
166 if (ret != ERROR_SUCCESS) {
167 return ret;
168 }
169
171
172 VFDTRACE(0, ("@=%s\n", buf));
173
175 hKey, NULL, NULL, REG_SZ, (PBYTE)buf, temp + 1);
176
177 if (ret != ERROR_SUCCESS) {
179 return ret;
180 }
181
182 VFDTRACE(0, ("ThreadingModel=Apartment\n"));
183
184 ret = RegSetValueEx(hKey, "ThreadingModel", NULL, REG_SZ,
185 (PBYTE)"Apartment", sizeof("Apartment"));
186
188
189 if (ret != ERROR_SUCCESS) {
190 return ret;
191 }
192
193 //
194 // Register context menu handler
195 //
196 VFDTRACE(0, ("HKCR\\" VFDEXT_MENU_REGKEY "\n"));
197
201
202 if (ret != ERROR_SUCCESS) {
203 return ret;
204 }
205
206 VFDTRACE(0, ("@=%s\n", guid_str));
207
209 (PBYTE)guid_str, strlen(guid_str) + 1);
210
212
213 if (ret != ERROR_SUCCESS) {
214 return ret;
215 }
216
217 //
218 // Register Drag&Drop handler
219 //
220 if (!IS_WINDOWS_NT()) {
221 //
222 // Windows NT does not support Drag&Drop handlers ???
223 //
224 VFDTRACE(0, ("HKCR\\" VFDEXT_DND_REGKEY "\n"));
225
229
230 if (ret != ERROR_SUCCESS) {
231 return ret;
232 }
233
234 VFDTRACE(0, ("@=%s\n", guid_str));
235
237 (PBYTE)guid_str, strlen(guid_str) + 1);
238
240
241 if (ret != ERROR_SUCCESS) {
242 return ret;
243 }
244 }
245
246 //
247 // Register property sheet handler
248 //
249 VFDTRACE(0, ("HKCR\\" VFDEXT_PROP_REGKEY "\n"));
250
254
255 if (ret != ERROR_SUCCESS) {
256 return ret;
257 }
258
259 VFDTRACE(0, ("@=%s\n", guid_str));
260
262 (PBYTE)guid_str, strlen(guid_str) + 1);
263
265
266 if (ret != ERROR_SUCCESS) {
267 return ret;
268 }
269
270 //
271 // Register approved extensions entry
272 //
273 VFDTRACE(0, ("HKLM\\" REGKEY_APPROVED "\n"));
274
277 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
278
279 if (ret != ERROR_SUCCESS) {
280 return ret;
281 }
282
283 VFDTRACE(0,
284 ("%s=" VFDEXT_DESCRIPTION "\n", guid_str));
285
286 ret = RegSetValueEx(hKey, guid_str, NULL, REG_SZ,
288
290
291 return ret;
292}
#define RegCloseKey(hKey)
Definition: registry.h:49
FxAutoRegKey hKey
#define REG_SZ
Definition: layer.c:22
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
BYTE * PBYTE
Definition: pedump.c:66
#define VFDEXT_MENU_REGKEY
Definition: vfdlib.h:59
#define VFDEXT_PROP_REGKEY
Definition: vfdlib.h:61
#define VFDEXT_DND_REGKEY
Definition: vfdlib.h:60
#define REGKEY_APPROVED
Definition: vfdshutil.cpp:39
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
#define RegQueryValueEx
Definition: winreg.h:524

Referenced by Shell().

◆ VfdRemoveDriver()

DWORD WINAPI VfdRemoveDriver ( )

Definition at line 557 of file vfdctl.c.

558{
559#undef FUNC
560#define FUNC "VfdRemoveDriver"
561 SC_HANDLE hScManager; // Service Control Manager
562 SC_HANDLE hService; // Service (= Driver)
565
566 // Get the current driver path
567
569
570 if (ret != ERROR_SUCCESS) {
571 return ret;
572 }
573
574 // Connect to the Service Control Manager
575
576 hScManager = OpenSCManager(NULL, NULL, 0);
577
578 if (hScManager == NULL) {
579 ret = GetLastError();
580
581 VFDTRACE(0,
582 (FUNC ": OpenSCManager() - %s",
584
585 return ret;
586 }
587
588 // Open the VFD driver entry in the service database
589
590 hService = OpenService(
591 hScManager, // Service control manager
592 VFD_DEVICE_BASENAME, // service name
593 DELETE); // service access mode
594
595 if (hService == NULL) {
596 ret = GetLastError();
597
598 VFDTRACE(0,
599 (FUNC ": OpenService(DELETE) - %s",
601
602 goto cleanup;
603 }
604
605 // Remove driver entry from registry
606
607 if (!DeleteService(hService)) {
608 ret = GetLastError();
609
610 VFDTRACE(0,
611 (FUNC ": DeleteService() - %s",
613
614 goto cleanup;
615 }
616
617cleanup:
618 // Close the service object handle
619
620 if (hService) {
621 CloseServiceHandle(hService);
622 }
623
624 // Close handle to the service control manager.
625
626 if (hScManager) {
627 CloseServiceHandle(hScManager);
628 }
629
630 // Broadcast the successful operation
631
632 if (ret == ERROR_SUCCESS) {
634
635#ifdef VFD_EMBED_DRIVER
636 // Remove the driver file
638#endif // VFD_EMBED_DRIVER
639 }
640
641 return ret;
642}
#define DELETE
Definition: nt_native.h:57
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:921
DWORD WINAPI VfdGetDriverConfig(PSTR sFileName, PDWORD pStart)
Definition: vfdctl.c:959

Referenced by Remove().

◆ VfdSaveImage()

DWORD WINAPI VfdSaveImage ( HANDLE  hDevice,
PCSTR  sFileName,
BOOL  bOverWrite,
BOOL  bTruncate 
)

Definition at line 2685 of file vfdctl.c.

2690{
2691#undef FUNC
2692#define FUNC "VfdSaveImage"
2694 DWORD result;
2696 PUCHAR buf = NULL;
2698
2699
2701
2702 // Get the media size
2703
2704 if (!DeviceIoControl(
2705 hDevice,
2707 NULL,
2708 0,
2709 &length,
2710 sizeof(length),
2711 &result,
2712 NULL))
2713 {
2714 ret = GetLastError();
2715
2716 VFDTRACE(0,
2717 (FUNC ": DeviceIoControl(IOCTL_DISK_GET_LENGTH_INFO) - %s",
2718 SystemMessage(ret)));
2719
2720 goto exit_func;
2721 }
2722
2723 // Prepare an intermediate image buffer
2724
2725 buf = (PUCHAR)LocalAlloc(LPTR, length.Length.LowPart);
2726
2727 if (buf == NULL) {
2728 ret = GetLastError();
2729
2730 VFDTRACE(0,
2731 (FUNC ": LocalAlloc - %s",
2732 SystemMessage(ret)));
2733
2734 goto exit_func;
2735 }
2736
2737 // seek the top of the media
2738
2739 if (SetFilePointer(hDevice, 0, NULL, FILE_BEGIN) != 0) {
2740 ret = GetLastError();
2741
2742 VFDTRACE(0,
2743 (FUNC ": SetFilePointer - %s",
2744 SystemMessage(ret)));
2745
2746 goto exit_func;
2747 }
2748
2749 // read the image data
2750
2751 if (!ReadFile(hDevice, buf, length.Length.LowPart, &result, NULL) ||
2752 result != length.Length.LowPart) {
2753 ret = GetLastError();
2754
2755 VFDTRACE(0,
2756 (FUNC ": ReadFile - %s",
2757 SystemMessage(ret)));
2758
2759 goto exit_func;
2760 }
2761
2762 // open the destination file
2763
2764 hFile = CreateFile(sFileName, GENERIC_WRITE, 0, NULL,
2765 bOverWrite ? OPEN_ALWAYS : CREATE_NEW, 0, NULL);
2766
2767 if (hFile == INVALID_HANDLE_VALUE) {
2768 ret = GetLastError();
2769
2770 VFDTRACE(0,
2771 (FUNC ": CreateFile - %s",
2772 SystemMessage(ret)));
2773
2774 goto exit_func;
2775 }
2776
2777 // seek the top of the file
2778
2779 if (SetFilePointer(hFile, 0, NULL, FILE_BEGIN) != 0) {
2780 ret = GetLastError();
2781
2782 VFDTRACE(0,
2783 (FUNC ": SetFilePointer - %s",
2784 SystemMessage(ret)));
2785
2786 goto exit_func;
2787 }
2788
2789 // write the image data
2790
2791 if (!WriteFile(hFile, buf, length.Length.LowPart, &result, NULL) ||
2792 result != length.Length.LowPart) {
2793 ret = GetLastError();
2794
2795 VFDTRACE(0,
2796 (FUNC ": WriteFile - %s",
2797 SystemMessage(ret)));
2798
2799 goto exit_func;
2800 }
2801
2802 // truncate the target file
2803
2804 if (bTruncate && !SetEndOfFile(hFile)) {
2805 ret = GetLastError();
2806
2807 VFDTRACE(0,
2808 (FUNC ": SetEndOfFile - %s",
2809 SystemMessage(ret)));
2810
2811 goto exit_func;
2812 }
2813
2814 // reset the media modified flag
2815
2816 if (!DeviceIoControl(
2817 hDevice,
2819 NULL,
2820 0,
2821 NULL,
2822 0,
2823 &result,
2824 NULL))
2825 {
2826 VFDTRACE(0,
2827 (FUNC ": DeviceIoControl(IOCTL_VFD_RESET_MODIFY) - %s",
2829 }
2830
2831exit_func:
2832 // unlock the target volume
2833
2834 if (!DeviceIoControl(
2835 hDevice,
2837 NULL,
2838 0,
2839 NULL,
2840 0,
2841 &result,
2842 NULL))
2843 {
2844 VFDTRACE(0,
2845 (FUNC ": DeviceIoControl(FSCTL_UNLOCK_VOLUME) - %s",
2847 }
2848
2849 // release the format image buffer
2850
2851 if (buf) {
2852 LocalFree(buf);
2853 }
2854
2855 // close the image file
2856
2857 if (hFile != INVALID_HANDLE_VALUE) {
2859 }
2860
2861 return ret;
2862}
#define OPEN_ALWAYS
Definition: disk.h:70

Referenced by OnOK(), and Save().

◆ VfdSetGlobalLink()

DWORD WINAPI VfdSetGlobalLink ( HANDLE  hDevice,
CHAR  cLetter 
)

Definition at line 1984 of file vfdctl.c.

1987{
1988#undef FUNC
1989#define FUNC "VfdSetGlobalLink"
1990 CHAR letter;
1991 ULONG number;
1992 DWORD result;
1993 DWORD ret;
1994
1995 if (isalpha(cLetter)) {
1996
1997 // make sure the drive does not have a drive letter
1998
1999 letter = 0;
2000
2001 VfdGetGlobalLink(hDevice, &letter);
2002
2003 if (isalpha(letter)) {
2004 VFDTRACE(0,
2005 (FUNC ": Drive already has a drive letter %c\n", letter));
2007 }
2008
2009 VfdGetLocalLink(hDevice, &letter);
2010
2011 if (isalpha(letter)) {
2012 VFDTRACE(0,
2013 (FUNC ": Drive already has a drive letter %c\n", letter));
2015 }
2016
2017 // make sure drive letter is not in use
2018
2019 cLetter = (CHAR)toupper(cLetter);
2020
2021 if (GetLogicalDrives() & (1 << (cLetter - 'A'))) {
2022 VFDTRACE(0,
2023 (FUNC ": Drive letter %c already used\n", cLetter));
2025 }
2026
2027 // Assign a new drive letter
2028
2029 if (!DeviceIoControl(
2030 hDevice,
2032 &cLetter,
2033 sizeof(cLetter),
2034 NULL,
2035 0,
2036 &result,
2037 NULL))
2038 {
2039 ret = GetLastError();
2040
2041 VFDTRACE(0,
2042 (FUNC ": DeviceIoControl(IOCTL_VFD_SET_LINK) - %s",
2043 SystemMessage(ret)));
2044
2045 return ret;
2046 }
2047
2048 // broadcast system message
2049
2051
2052 // broadcast VFD message
2053
2054 if (VfdGetDeviceNumber(hDevice, &number) == ERROR_SUCCESS) {
2056 }
2057
2058 return ERROR_SUCCESS;
2059 }
2060 else if (!cLetter) {
2061
2062 // make sure the drive has a global drive letter
2063
2064 letter = 0;
2065
2066 VfdGetGlobalLink(hDevice, &letter);
2067
2068 if (!isalpha(letter)) {
2069 VFDTRACE(0,
2070 (FUNC ": Drive does not have a drive letter\n"));
2072 }
2073
2074 // Remove drive letters
2075
2076 if (!DeviceIoControl(
2077 hDevice,
2079 &cLetter,
2080 sizeof(cLetter),
2081 NULL,
2082 0,
2083 &result,
2084 NULL))
2085 {
2086 ret = GetLastError();
2087
2088 VFDTRACE(0,
2089 (FUNC ": DeviceIoControl(IOCTL_VFD_SET_LINK) - %s",
2090 SystemMessage(ret)));
2091
2092 return ret;
2093 }
2094
2095 // broadcast system message
2096
2098
2099 // broadcast VFD message
2100 if (VfdGetDeviceNumber(hDevice, &number) == ERROR_SUCCESS) {
2102 }
2103
2104 return ERROR_SUCCESS;
2105 }
2106 else {
2108 }
2109}
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
#define VFD_LINK_CREATED
Definition: vfdctl.c:74
static void VfdBroadcastLink(CHAR cLetter, BOOL bRemoved)
Definition: vfdctl.c:77
#define VFD_LINK_REMOVED
Definition: vfdctl.c:75
#define IOCTL_VFD_SET_LINK
Definition: vfdio.h:194
#define ERROR_ALREADY_ASSIGNED
Definition: winerror.h:169

Referenced by Link(), and Unlink().

◆ VfdSetLocalLink()

DWORD WINAPI VfdSetLocalLink ( HANDLE  hDevice,
CHAR  cLetter 
)

Definition at line 2154 of file vfdctl.c.

2157{
2158#undef FUNC
2159#define FUNC "VfdSetLocalLink"
2160 CHAR letter;
2161 CHAR dos_name[] = "A:";
2163 ULONG number;
2164 DWORD ret;
2165
2166 if (isalpha(cLetter)) {
2167
2168 // make sure the drive does not have a drive letter
2169
2170 letter = 0;
2171
2172 VfdGetGlobalLink(hDevice, &letter);
2173
2174 if (isalpha(letter)) {
2175 VFDTRACE(0,
2176 (FUNC ": Drive already has a drive letter %c\n", letter));
2178 }
2179
2180 VfdGetLocalLink(hDevice, &letter);
2181
2182 if (isalpha(letter)) {
2183 VFDTRACE(0,
2184 (FUNC ": Drive already has a drive letter %c\n", letter));
2186 }
2187
2188 // make sure drive letters are not in use
2189
2190 cLetter = (CHAR)toupper(cLetter);
2191
2192 if (GetLogicalDrives() & (1 << (cLetter - 'A'))) {
2193 VFDTRACE(0,
2194 (FUNC ": Drive letter already used\n"));
2195
2197 }
2198
2199 // get VFD device name
2200
2201 ret = VfdGetDeviceName(hDevice, dev_name, sizeof(dev_name));
2202
2203 if (ret != ERROR_SUCCESS) {
2204 return ret;
2205 }
2206
2207 // assign a drive letter
2208
2209 dos_name[0] = cLetter;
2210
2211 if (!DefineDosDevice(DDD_RAW_TARGET_PATH, dos_name, dev_name)) {
2212 ret = GetLastError();
2213
2214 VFDTRACE(0,
2215 (FUNC ": DefineDosDevice(%s,%s) - %s",
2216 dos_name, dev_name, SystemMessage(ret)));
2217 }
2218
2219 if (ret == ERROR_SUCCESS) {
2220 // broadcast VFD message
2221
2222 if (VfdGetDeviceNumber(hDevice, &number) == ERROR_SUCCESS) {
2224 }
2225 }
2226
2227 return ret;
2228 }
2229 else if (!cLetter) {
2230
2231 // make sure the drive has a local drive letter
2232
2233 letter = 0;
2234
2235 VfdGetLocalLink(hDevice, &letter);
2236
2237 if (!isalpha(letter)) {
2238 VFDTRACE(0,
2239 (FUNC ": Drive letter is not assigned to this drive\n"));
2241 }
2242
2243 // get VFD device name
2244
2245 ret = VfdGetDeviceName(hDevice, dev_name, sizeof(dev_name));
2246
2247 if (ret != ERROR_SUCCESS) {
2248 return ret;
2249 }
2250
2251 // remove drive letters
2252#define DDD_FLAGS (DDD_REMOVE_DEFINITION | DDD_RAW_TARGET_PATH | DDD_EXACT_MATCH_ON_REMOVE)
2253
2254 dos_name[0] = (CHAR)toupper(letter);
2255
2256 if (!DefineDosDevice(DDD_FLAGS, dos_name, dev_name)) {
2257 ret = GetLastError();
2258
2259 VFDTRACE(0,
2260 (FUNC ": DefineDosDevice(%s,%s) - %s",
2261 dos_name, dev_name, SystemMessage(ret)));
2262 }
2263
2264 if (ret == ERROR_SUCCESS) {
2265 // broadcast VFD message
2266 if (VfdGetDeviceNumber(hDevice, &number) == ERROR_SUCCESS) {
2268 }
2269 }
2270
2271 return ret;
2272 }
2273 else {
2275 }
2276}
#define DDD_FLAGS
#define DDD_RAW_TARGET_PATH
Definition: winbase.h:523
#define DefineDosDevice
Definition: winbase.h:3763

Referenced by Link(), Open(), Unlink(), and VfdStopDriver().

◆ VfdStartDriver()

DWORD WINAPI VfdStartDriver ( PDWORD  pState)

Definition at line 647 of file vfdctl.c.

649{
650#undef FUNC
651#define FUNC "VfdStartDriver"
652 SC_HANDLE hScManager; // Service Control Manager
653 SC_HANDLE hService; // Service (= Driver)
656 HCURSOR original;
657 int i;
658
659 if (pState) {
660 *pState = 0;
661 }
662
663 // Connect to the Service Control Manager
664
665 hScManager = OpenSCManager(NULL, NULL, 0);
666
667 if (hScManager == NULL) {
668 ret = GetLastError();
669
670 VFDTRACE(0,
671 (FUNC ": OpenSCManager() - %s",
673
674 return ret;
675 }
676
677 // show an hourglass cursor
678
679 original = SetCursor(LoadCursor(NULL, IDC_WAIT));
680
681 // Open the VFD driver entry in the service database
682
683 hService = OpenService(
684 hScManager, // Service control manager
685 VFD_DEVICE_BASENAME, // service name
687 | SERVICE_QUERY_STATUS); // service access mode
688
689 if (hService == NULL) {
690 ret = GetLastError();
691
692 VFDTRACE(0,
693 (FUNC ": OpenService(SERVICE_START) - %s",
695
696 goto cleanup;
697 }
698
699 // Start the driver
700
701 if (!StartService(hService, 0, NULL)) {
702 ret = GetLastError();
703
704 VFDTRACE(0,
705 (FUNC ": StartService() - %s",
707
708 goto cleanup;
709 }
710
711 // Wait until the driver is properly running
712
713 i = 0;
714
715 for (;;) {
716 if (!QueryServiceStatus(hService, &stat)) {
717 ret = GetLastError();
718
719 VFDTRACE(0,
720 (FUNC ": QueryServiceStatus() - %s",
722
723 break;
724 }
725
726 if (stat.dwCurrentState == SERVICE_RUNNING || ++i == 5) {
727 break;
728 }
729
730 Sleep(1000);
731 }
732
733 if (stat.dwCurrentState == SERVICE_RUNNING) {
734
735 // Broadcast the successful operation
736
737 if (ret == ERROR_SUCCESS) {
739 }
740
741 // broadcast the arrival of VFD drives
742 // otherwise WinXP explorer doesn't recognize the VFD drives
743
744 for (i = 0; i < VFD_MAXIMUM_DEVICES; i++) {
745 HANDLE hDevice;
746 CHAR letter = 0;
747
748 hDevice = VfdOpenDevice(i);
749
750 if (hDevice != INVALID_HANDLE_VALUE) {
751
752 VfdGetGlobalLink(hDevice, &letter);
753
754 CloseHandle(hDevice);
755
756 if (isalpha(letter)) {
759 }
760 }
761 else {
762 VFDTRACE(0,
763 (FUNC ": VfdOpenDevice(%d) - %s",
765 }
766 }
767 }
768 else {
769 // somehow failed to start the driver
770
772 }
773
774 if (pState) {
775 *pState = stat.dwCurrentState;
776 }
777
778cleanup:
779 // Close the service object handle
780
781 if (hService) {
782 CloseServiceHandle(hService);
783 }
784
785 // Close handle to the service control manager.
786
787 if (hScManager) {
788 CloseServiceHandle(hScManager);
789 }
790
791 // revert to the original cursor
792
793 SetCursor(original);
794
795 return ret;
796}
#define stat
Definition: acwin.h:99
Definition: stat.h:55
HANDLE WINAPI VfdOpenDevice(ULONG nTarget)
Definition: vfdctl.c:1215
#define VFD_MAXIMUM_DEVICES
Definition: vfdtypes.h:75
#define ERROR_SERVICE_NOT_ACTIVE
Definition: winerror.h:613
#define SERVICE_START
Definition: winsvc.h:57
#define StartService
Definition: winsvc.h:585
#define SERVICE_RUNNING
Definition: winsvc.h:24

Referenced by Start().

◆ VfdStopDriver()

DWORD WINAPI VfdStopDriver ( PDWORD  pState)

Definition at line 801 of file vfdctl.c.

803{
804#undef FUNC
805#define FUNC "VfdStopDriver"
806 SC_HANDLE hScManager; // Service Control Manager
807 SC_HANDLE hService; // Service (= Driver)
809 CHAR drive_letters[VFD_MAXIMUM_DEVICES];
811 int i;
812 HCURSOR original;
813
814 if (pState) {
815 *pState = 0;
816 }
817
818 // Connect to the Service Control Manager
819
820 hScManager = OpenSCManager(NULL, NULL, 0);
821
822 if (hScManager == NULL) {
823 ret = GetLastError();
824
825 VFDTRACE(0,
826 (FUNC ": OpenSCManager() - %s",
828
829 return ret;
830 }
831
832 // Show the hourglass cursor
833
834 original = SetCursor(LoadCursor(NULL, IDC_WAIT));
835
836 // Open the VFD driver entry in the service database
837
838 hService = OpenService(
839 hScManager, // Service control manager
840 VFD_DEVICE_BASENAME, // service name
842 | SERVICE_QUERY_STATUS); // service access mode
843
844 if (hService == NULL) {
845 ret = GetLastError();
846
847 VFDTRACE(0,
848 (FUNC ": OpenService(SERVICE_STOP) - %s",
850
851 goto cleanup;
852 }
853
854 // Get assigned drive letters
855
856 for (i = 0; i < VFD_MAXIMUM_DEVICES; i++) {
857 HANDLE hDevice;
858 CHAR letter;
859
860 hDevice = VfdOpenDevice(i);
861
862 if (hDevice != INVALID_HANDLE_VALUE) {
863
864 // remove all session local drive letters
865
866 while (VfdGetLocalLink(hDevice, &letter) == ERROR_SUCCESS &&
867 isalpha(letter)) {
868 VfdSetLocalLink(hDevice, 0);
869 }
870
871 // store existing persistent drive letters
872
873 VfdGetGlobalLink(hDevice, &drive_letters[i]);
874
875 CloseHandle(hDevice);
876 }
877 else {
878 VFDTRACE(0,
879 (FUNC ": VfdOpenDevice(%d) - %s",
881 }
882 }
883
884 // Stop the driver
885
886 if (!ControlService(hService, SERVICE_CONTROL_STOP, &stat)) {
887 ret = GetLastError();
888
889 VFDTRACE(0,
890 (FUNC ": ControlService(SERVICE_CONTROL_STOP) - %s",
892
893 goto cleanup;
894 }
895
896 // Wait until the driver is stopped
897
898 i = 0;
899
900 while (stat.dwCurrentState != SERVICE_STOPPED && ++i < 5) {
901 Sleep(1000);
902
903 if (!QueryServiceStatus(hService, &stat)) {
904 ret = GetLastError();
905
906 VFDTRACE(0,
907 (FUNC ": QueryServiceStatus() - %s",
909
910 break;
911 }
912 }
913
914 if (stat.dwCurrentState != SERVICE_RUNNING) {
915
916 // broadcast the removal of persistent drive letters
917
918 for (i = 0; i < VFD_MAXIMUM_DEVICES; i++) {
919 if (isalpha(drive_letters[i])) {
920 VfdBroadcastLink(drive_letters[i], VFD_LINK_REMOVED);
922 }
923 }
924 }
925
926 if (pState) {
927 *pState = stat.dwCurrentState;
928 }
929
930cleanup:
931 // Close the service object handle
932
933 if (hService) {
934 CloseServiceHandle(hService);
935 }
936
937 // Close handle to the service control manager.
938
939 if (hScManager) {
940 CloseServiceHandle(hScManager);
941 }
942
943 // Broadcast the successful operation
944
945 if (ret == ERROR_SUCCESS) {
947 }
948
949 // revert to the original cursor
950
951 SetCursor(original);
952
953 return ret;
954}
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:622
DWORD WINAPI VfdSetLocalLink(HANDLE hDevice, CHAR cLetter)
Definition: vfdctl.c:2154
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_STOP
Definition: winsvc.h:58
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36

Referenced by Stop().

◆ VfdToolTip()

void WINAPI VfdToolTip ( HWND  hParent,
PCSTR  sText,
int  pos_x,
int  pos_y,
BOOL  stick 
)

Definition at line 134 of file vfdguitip.c.

140{
141#ifndef __REACTOS__
142 HWND hWnd;
143#endif
144 WNDCLASS wc = {0};
145 LOGFONT lf;
146 HFONT font;
147 HDC dc;
148 int len;
149 SIZE sz;
150 RECT rc;
151 int scr_x;
152 int scr_y;
153
154 //
155 // Register Window Class
156 //
157
161 wc.hbrBackground = (HBRUSH)(COLOR_INFOBK + 1);
163
164 RegisterClass(&wc);
165
166 //
167 // Create Tool Tip Font (== Icon title font)
168 //
169
171 SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);
172
174
175 //
176 // Calculate Tool Tip Window size
177 //
178
179 dc = GetDC(hParent);
180
182
183 len = strlen(sText);
184
185 GetTextExtentPoint32(dc, sText, len, &sz);
186
187 rc.left = 0;
188 rc.top = 0;
189 rc.right = sz.cx;
190 rc.bottom = sz.cy;
191
192 DrawText(dc, sText, len, &rc, DT_CALCRECT | DT_LEFT | DT_TOP);
193
194 ReleaseDC(hParent, dc);
195
196 sz.cx = rc.right - rc.left + 16;
197 sz.cy = rc.bottom - rc.top + 16;
198
199 //
200 // Decide the window position
201 //
202 if (pos_x == -1 || pos_y == -1) {
203 //
204 // Use current cursor position
205 //
206 POINT pt;
207
209
210 pos_x = pt.x - (sz.cx / 2);
211 pos_y = pt.y - (sz.cy / 2);
212 }
213 else {
214 pos_x = pos_x - (sz.cx / 2);
215 }
216
217 //
218 // make sure the tip window fits in visible area
219 //
222
223 if (pos_x < 0) {
224 pos_x = 0;
225 }
226 if (pos_x + sz.cx > scr_x) {
227 pos_x = scr_x - sz.cx;
228 }
229 if (pos_y < 0) {
230 pos_y = 0;
231 }
232 if (pos_y + sz.cy > scr_y) {
233 pos_y = scr_y - sz.cy;
234 }
235
236 //
237 // Create the tool tip window
238 //
239#ifndef __REACTOS__
241#else
243#endif
244 stick ? 0 : WS_EX_TOPMOST,
246 sText,
248 pos_x, pos_y,
249 sz.cx, sz.cy,
250 hParent,
251 NULL,
252 NULL,
253 (PVOID)font);
254
255 //
256 // Give focus if it is not a stick tool-tip
257 //
258 if (!stick) {
259 SetFocus(hParent);
260 }
261}
HWND hWnd
Definition: settings.c:17
#define pt(x, y)
Definition: drawing.c:79
if(dx< 0)
Definition: linetemp.h:194
static const WCHAR dc[]
static HDC
Definition: imagelist.c:92
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
Definition: mk_font.cpp:20
#define WS_BORDER
Definition: pedump.c:625
#define WS_POPUP
Definition: pedump.c:616
#define WS_VISIBLE
Definition: pedump.c:620
#define WS_EX_TOPMOST
Definition: pedump.c:647
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
HBRUSH hbrBackground
Definition: winuser.h:3170
HINSTANCE hInstance
Definition: winuser.h:3167
HCURSOR hCursor
Definition: winuser.h:3169
LPCSTR lpszClassName
Definition: winuser.h:3172
WNDPROC lpfnWndProc
Definition: winuser.h:3164
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
static LRESULT CALLBACK ToolTipProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: vfdguitip.c:35
#define VFD_INFOTIP_WNDCLASS
Definition: vfdguitip.c:30
#define GetTextExtentPoint32
Definition: wingdi.h:4472
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
#define CreateFontIndirect
Definition: wingdi.h:4444
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define CreateWindowEx
Definition: winuser.h:5755
#define COLOR_INFOBK
Definition: winuser.h:942
#define SM_CYSCREEN
Definition: winuser.h:960
#define IDC_ARROW
Definition: winuser.h:687
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2670
#define SPI_GETICONTITLELOGFONT
Definition: winuser.h:1380
#define DrawText
Definition: winuser.h:5771
#define DT_LEFT
Definition: winuser.h:534
#define DT_TOP
Definition: winuser.h:542
HWND WINAPI SetFocus(_In_opt_ HWND)
HDC WINAPI GetDC(_In_opt_ HWND)
#define RegisterClass
Definition: winuser.h:5836
#define SM_CXSCREEN
Definition: winuser.h:959
#define DT_CALCRECT
Definition: winuser.h:526
#define SystemParametersInfo
Definition: winuser.h:5858
int WINAPI GetSystemMetrics(_In_ int)

Referenced by ShowHelpWindow(), and VfdImageTip().

◆ VfdUnregisterHandlers()

DWORD WINAPI VfdUnregisterHandlers ( )

Definition at line 297 of file vfdshutil.cpp.

298{
300 TCHAR guid_str[40];
301 HKEY hKey;
302 DWORD temp;
303 DWORD ret;
304
305 MakeGuidString(guid_str, CLSID_VfdShellExt);
306
307 sprintf(buf, "CLSID\\%s", guid_str);
308
309 VFDTRACE(0, ("HKCR\\%s\n", buf));
310
311 temp = sizeof(buf);
312
314
315 if (ret != ERROR_SUCCESS) {
316 return ret;
317 }
318
321 }
322
323 sprintf(buf, "CLSID\\%s\\InProcServer32", guid_str);
324
325 VFDTRACE(0, ("HKCR\\%s\n", buf));
326
328
329 if (ret != ERROR_SUCCESS) {
330 return ret;
331 }
332
333 sprintf(buf, "CLSID\\%s", guid_str);
334
335 VFDTRACE(0, ("HKCR\\%s\n", buf));
336
338
339 if (ret != ERROR_SUCCESS) {
340 return ret;
341 }
342
343 VFDTRACE(0, ("HKCR\\" VFDEXT_MENU_REGKEY "\n"));
344
346
347 if (ret != ERROR_SUCCESS) {
348 return ret;
349 }
350
351 if (!IS_WINDOWS_NT()) {
352
353 // Windows NT doesn't support Drag & Drop handlers ???
354
355 VFDTRACE(0, ("HKCR\\" VFDEXT_DND_REGKEY "\n"));
356
358
359 if (ret != ERROR_SUCCESS) {
360 return ret;
361 }
362 }
363
364 VFDTRACE(0, ("HKCR\\" VFDEXT_PROP_REGKEY "\n"));
365
367
368 if (ret != ERROR_SUCCESS) {
369 return ret;
370 }
371
372 VFDTRACE(0, ("HKLM\\" REGKEY_APPROVED "\n"));
373
377 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
378
379 if (ret != ERROR_SUCCESS) {
380 return ret;
381 }
382
383 ret = RegDeleteValue(hKey, guid_str);
384
386
387 return ret;
388}
#define RegDeleteKey
Definition: winreg.h:502
#define RegDeleteValue
Definition: winreg.h:508

Referenced by Shell().

◆ VfdWriteProtect()

DWORD WINAPI VfdWriteProtect ( HANDLE  hDevice,
BOOL  bProtect 
)

Definition at line 2484 of file vfdctl.c.

2487{
2488#undef FUNC
2489#define FUNC "VfdWriteProtect"
2490 DWORD result;
2492
2493 if (!DeviceIoControl(
2494 hDevice,
2496 NULL,
2497 0,
2498 NULL,
2499 0,
2500 &result,
2501 NULL))
2502 {
2503 ret = GetLastError();
2504
2505 VFDTRACE(0,
2506 (FUNC ": DeviceIoControl(IOCTL_VFD_SET_PROTECT) - %s",
2507 SystemMessage(ret)));
2508 }
2509
2510 if (ret == ERROR_SUCCESS) {
2511 ULONG number;
2512
2513 if (VfdGetDeviceNumber(hDevice, &number) == ERROR_SUCCESS) {
2515 }
2516 }
2517
2518 return ret;
2519}
#define IOCTL_VFD_SET_PROTECT
Definition: vfdio.h:247
#define IOCTL_VFD_CLEAR_PROTECT
Definition: vfdio.h:273

Referenced by CVfdShExt::DoVfdProtect(), Protect(), and VfdOpenImage().