ReactOS 0.4.16-dev-92-g0c2cdca
format_common.cpp File Reference

Go to the source code of this file.

Functions

JS_DEVICE_TYPE CheckCDType (PCHAR m_szFile, PCHAR VendorId)
 Return CD-RW device type.
 
void InitDeviceList (HWND hDlg, HWND hwndControl, PADD_DEVICE CallBack)
 
HANDLE FmtAcquireDrive_ (PCHAR _Drive, CHAR Level)
 
HANDLE FmtAcquireDrive (PCHAR Drive, CHAR Level)
 
BOOLEAN FmtIsDriveAcquired (PCHAR Drive, CHAR Level)
 
VOID FmtReleaseDrive (HANDLE evt)
 

Variables

CHAR szDisc [4] = ""
 Initial drive selection from command line.
 
BOOL bChanger = FALSE
 

Function Documentation

◆ CheckCDType()

JS_DEVICE_TYPE CheckCDType ( PCHAR  m_szFile,
PCHAR  VendorId 
)

Return CD-RW device type.

Definition at line 13 of file format_common.cpp.

17{
18 HANDLE hDevice;
19 CHAR szDeviceName[256];
20 CHAR ioBuf[4096];
21 ULONG RC;
22 BOOL DvdRW = false;
23 BOOL DvdpRW = false;
24 BOOL DvdRAM = false;
25 BOOL DvdpR = false;
26 BOOL DvdR = false;
27
29
30 // Make string representing full path
31 sprintf(szDeviceName, "\\\\.\\%s", m_szFile);
33
34 // Open device volume
35 hDevice = OpenOurVolume(szDeviceName);
36
37 if (hDevice == ((HANDLE)-1)) {
38 strcpy(VendorId,"");
39 return BUSY;
40 } else {
41
42 // Get our cdrw.sys signature
44 &ioBuf,sizeof(GET_SIGNATURE_USER_OUT),
45 &ioBuf,sizeof(GET_SIGNATURE_USER_OUT),FALSE,NULL);
46
47 if (RC == 1) {
48 // Get device information
50 &ioBuf,sizeof(GET_DEVICE_INFO_USER_OUT),
51 &ioBuf,sizeof(GET_DEVICE_INFO_USER_OUT),FALSE,NULL);
52 if (RC != 1) {
53 strcpy(VendorId,"Unknown Vendor");
54 } else {
55 if(((PGET_DEVICE_INFO_USER_OUT)&ioBuf)->Features & CDRW_FEATURE_CHANGER)
56 bChanger = TRUE;
57 strcpy(VendorId,(PCHAR)&(((PGET_DEVICE_INFO_USER_OUT)&ioBuf)->VendorId[0]));
58 if (((PGET_DEVICE_INFO_USER_OUT)&ioBuf)->Features & CDRW_FEATURE_GET_CFG) {
59 DvdRW = (((PGET_DEVICE_INFO_USER_OUT)&ioBuf)->Features2[0] >> PFNUM_DVDRW_RESTRICTED_OVERWRITE) & 1;
60 DvdRAM = (((PGET_DEVICE_INFO_USER_OUT)&ioBuf)->Features2[0] >> PFNUM_DVDRAM) & 1;
61 DvdpRW = (((PGET_DEVICE_INFO_USER_OUT)&ioBuf)->Features2[0] >> PFNUM_DVDpRW) & 1;
62 DvdR = (((PGET_DEVICE_INFO_USER_OUT)&ioBuf)->Features2[0] >> PFNUM_DVDR) & 1;
63 DvdpR = (((PGET_DEVICE_INFO_USER_OUT)&ioBuf)->Features2[0] >> PFNUM_DVDpR) & 1;
64 }
65 }
66
67 // Get device capabilities
69 &ioBuf,sizeof(GET_CAPABILITIES_USER_OUT),
70 &ioBuf,sizeof(GET_CAPABILITIES_USER_OUT),FALSE,NULL);
71 if(RC != 1) {
72 CloseHandle(hDevice);
73 return OTHER;
74 }
75
76 // Check capabilities
78 DvdRW || DvdpRW || DvdRAM) {
79
80 if (DvdRAM || ((PGET_CAPABILITIES_USER_OUT)&ioBuf)->WriteCap & DevCap_write_dvd_ram) {
81 CloseHandle(hDevice);
82 return DVDRAM;
83 }
84/* if (DvdR) {
85 CloseHandle(hDevice);
86 return DVDR;
87 }*/
88 if (DvdRW) {
89 CloseHandle(hDevice);
90 return DVDRW;
91 }
92 if (DvdpRW) {
93 CloseHandle(hDevice);
94 return DVDPRW;
95 }
96/* if (DvdpR) {
97 CloseHandle(hDevice);
98 return DVDPR;
99 }*/
100 if (((PGET_CAPABILITIES_USER_OUT)&ioBuf)->WriteCap & DevCap_write_dvd_r) {
101 CloseHandle(hDevice);
102 return DVDR;
103 }
104 if (((PGET_CAPABILITIES_USER_OUT)&ioBuf)->WriteCap & DevCap_write_cd_rw) {
105 CloseHandle(hDevice);
106 return CDRW;
107 }
108 if (((PGET_CAPABILITIES_USER_OUT)&ioBuf)->WriteCap & DevCap_write_cd_r) {
109 CloseHandle(hDevice);
110 return CDR;
111 }
112 }
113 else {
114 CloseHandle(hDevice);
115 return OTHER;
116 }
117 } else {
118 strcpy(VendorId,"Unknown Vendor");
119 }
120 CloseHandle(hDevice);
121 }
122
123 return OTHER;
124} // end CheckCDType()
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define DevCap_write_cd_rw
Definition: cdrw_hw.h:3014
#define PFNUM_DVDpRW
Definition: cdrw_hw.h:3338
#define DevCap_write_dvd_ram
Definition: cdrw_hw.h:3017
#define PFNUM_DVDRW_RESTRICTED_OVERWRITE
Definition: cdrw_hw.h:3333
#define PFNUM_DVDRAM
Definition: cdrw_hw.h:3332
#define DevCap_write_cd_r
Definition: cdrw_hw.h:3013
#define PFNUM_DVDR
Definition: cdrw_hw.h:3331
#define DevCap_write_dvd_r
Definition: cdrw_hw.h:3016
#define PFNUM_DVDpR
Definition: cdrw_hw.h:3339
#define CDRW_FEATURE_CHANGER
Definition: cdrw_usr.h:1496
#define CDRW_FEATURE_GET_CFG
Definition: cdrw_usr.h:1482
struct _GET_DEVICE_INFO_USER_OUT * PGET_DEVICE_INFO_USER_OUT
#define IOCTL_CDRW_GET_SIGNATURE
Definition: cdrw_usr.h:95
#define IOCTL_CDRW_GET_DEVICE_INFO
Definition: cdrw_usr.h:119
#define IOCTL_CDRW_GET_CAPABILITIES
Definition: cdrw_usr.h:82
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR szDeviceName[]
Definition: provider.c:56
#define CloseHandle
Definition: compat.h:739
NTSTATUS NTAPI UDFPhSendIOCTL(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, OUT PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN OverrideVerify, OUT PIO_STATUS_BLOCK Iosb OPTIONAL)
Definition: env_spec.cpp:511
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL bChanger
#define BUSY
Definition: options.h:110
#define sprintf(buf, format,...)
Definition: sprintf.c:55
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
HANDLE OpenOurVolume(PCHAR szDeviceName)
Definition: user_lib.cpp:780
@ CDR
Definition: user_lib.h:34
@ CDRW
Definition: user_lib.h:35
@ DVDRW
Definition: user_lib.h:39
@ DVDR
Definition: user_lib.h:38
@ DVDPRW
Definition: user_lib.h:41
@ OTHER
Definition: user_lib.h:33
@ DVDRAM
Definition: user_lib.h:37
char CHAR
Definition: xmlstorage.h:175

Referenced by InitDeviceList().

◆ FmtAcquireDrive()

HANDLE FmtAcquireDrive ( PCHAR  Drive,
CHAR  Level 
)

Definition at line 223 of file format_common.cpp.

227{
228 HANDLE evt;
229
231 if(!evt || evt == INVALID_HANDLE_VALUE) {
232 return NULL;
233 }
234 return evt;
235} // end FmtAcquireDrive()
PWCHAR Drive
Definition: chkdsk.c:73
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
HANDLE FmtAcquireDrive_(PCHAR _Drive, CHAR Level)
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56

◆ FmtAcquireDrive_()

HANDLE FmtAcquireDrive_ ( PCHAR  _Drive,
CHAR  Level 
)

Definition at line 199 of file format_common.cpp.

203{
204 WCHAR LockName[32];
205 HANDLE evt;
206
207 WCHAR Drive[1];
208 Drive[0] = _Drive[0] & ~('a' ^ 'A');
209
210 swprintf(LockName, L"DwFmtLock_%1.1S%d", Drive, Level);
211 evt = CreatePublicEvent(LockName);
212 if(!evt) {
213 return NULL;
214 }
216 CloseHandle(evt);
218 }
219 return evt;
220} // end FmtAcquireDrive_()
#define swprintf
Definition: precomp.h:40
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
#define L(x)
Definition: ntvdm.h:50
HANDLE CreatePublicEvent(PWCHAR EventName)
Definition: user_lib.cpp:596
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by FmtAcquireDrive(), and FmtIsDriveAcquired().

◆ FmtIsDriveAcquired()

BOOLEAN FmtIsDriveAcquired ( PCHAR  Drive,
CHAR  Level 
)

Definition at line 238 of file format_common.cpp.

242{
243 HANDLE evt;
244
246 if(evt == INVALID_HANDLE_VALUE) {
247 return TRUE;
248 }
249 if(evt) {
250 CloseHandle(evt);
251 }
252 return FALSE;
253} // end FmtIsDriveAcquired()

◆ FmtReleaseDrive()

VOID FmtReleaseDrive ( HANDLE  evt)

Definition at line 256 of file format_common.cpp.

259{
260 if(evt) {
261 CloseHandle(evt);
262 }
263} // end FmtReleaseDrive()

◆ InitDeviceList()

void InitDeviceList ( HWND  hDlg,
HWND  hwndControl,
PADD_DEVICE  CallBack 
)

Intialize asbtract device list via calls to CallBack function.

Parameters
hDlgNot used.
hwndControlPassed to the CallBack function. See PADD_DEVICE.
CallBackCallback function. Called on each CD device in system.

Definition at line 132 of file format_common.cpp.

137{
138 char Buffer[MAX_PATH] = "";
139 char VendorId[25];
140 char seps[] = ",";
141 char* token;
142 char info[MAX_PATH];
143 bool add_drive = false;
144
145 JS_DEVICE_TYPE drive_type;
146
147 // Get all device letter in system
149 token = (char *)&Buffer;
150 // Replace all zeroes with comma.
151 while (token != NULL) {
152 token = (char *)memchr(Buffer,'\0',MAX_PATH);
153 if (token) {
154 if (*(token-1) == ',') {
155 token = NULL;
156 } else {
157 *token=',';
158 }
159 }
160 }
161 // Parse string of drive letters separated by comma
162 token = strtok((char *)&Buffer,seps);
163 while (token != NULL) {
164 add_drive = false;
165 switch (GetDriveType(token)) {
166/*
167 case DRIVE_FIXED:
168 add_drive = true;
169 break;
170*/
171 case DRIVE_CDROM:
172 // Determine CD/DVD-ROM type (R,RW,RAM,other)
173 drive_type = CheckCDType(token,&VendorId[0]);
174 add_drive = true;
175 break;
176 }
177 if (add_drive) {
178
179 // Append to drive letter VendorId
181 info[strlen(token)-1]='\0';
182 strcat(info," ");
183 strcat(info,VendorId);
184
185 BOOL bSelect = !strcmp(strupr(szDisc),strupr(token));
186 if (drive_type != OTHER) {
187 CallBack(hwndControl,token,info,MediaTypeStrings[drive_type],bSelect);
188 } else {
189 CallBack(hwndControl,token,info,"[Unsupported]",FALSE);
190 }
191
192 }
193 // Move to the next drive letter in string
194 token = strtok(NULL,seps);
195 }
196} // end InitDeviceList()
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
char * strtok(char *String, const char *Delimiters)
Definition: utclib.c:338
Definition: bufpool.h:45
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
JS_DEVICE_TYPE CheckCDType(PCHAR m_szFile, PCHAR VendorId)
Return CD-RW device type.
CHAR szDisc[4]
Initial drive selection from command line.
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 token
Definition: glfuncs.h:210
#define DRIVE_CDROM
Definition: machpc98.h:119
#define memchr(s, c, n)
Definition: mkisofs.h:875
_CRTIMP char *__cdecl strupr(_Inout_z_ char *_Str)
TCHAR * MediaTypeStrings[]
Definition: user_lib.cpp:25
enum _JS_DEVICE_TYPE JS_DEVICE_TYPE
CD/DVD-RW device types.
#define GetDriveType
Definition: winbase.h:3812
#define GetLogicalDriveStrings
Definition: winbase.h:3822
CHAR * LPTSTR
Definition: xmlstorage.h:192

Variable Documentation

◆ bChanger

BOOL bChanger = FALSE

Definition at line 9 of file format_common.cpp.

Referenced by CheckCDType().

◆ szDisc

CHAR szDisc[4] = ""

Initial drive selection from command line.

Definition at line 8 of file format_common.cpp.

Referenced by InitDeviceList().