#include "precomp.h" #pragma hdrstop ULONG OpenDiskStatus( IN PSTR NTDeviceName, OUT PHANDLE Handle ) { OBJECT_ATTRIBUTES oa; NTSTATUS status; IO_STATUS_BLOCK status_block; ANSI_STRING AnsiName; UNICODE_STRING UnicodeName; RtlInitAnsiString(&AnsiName,NTDeviceName); status = RtlAnsiStringToUnicodeString(&UnicodeName,&AnsiName,TRUE); if(!NT_SUCCESS(status)) { *Handle = NULL; return(0); } memset(&oa, 0, sizeof(OBJECT_ATTRIBUTES)); oa.Length = sizeof(OBJECT_ATTRIBUTES); oa.ObjectName = &UnicodeName; oa.Attributes = OBJ_CASE_INSENSITIVE; status = NtOpenFile(Handle, SYNCHRONIZE | FILE_READ_DATA | FILE_WRITE_DATA, &oa, &status_block, FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SYNCHRONOUS_IO_ALERT ); RtlFreeUnicodeString(&UnicodeName); return((ULONG)status); } HANDLE OpenDiskNT( IN PSTR NTDeviceName ) { NTSTATUS status; HANDLE Handle = NULL; status = (NTSTATUS)OpenDiskStatus(NTDeviceName,&Handle); return(NT_SUCCESS(status) ? Handle : NULL); } HANDLE OpenDisk( IN PSTR DOSDriveName, IN BOOL WriteAccessDesired ) { OBJECT_ATTRIBUTES oa; IO_STATUS_BLOCK status_block; HANDLE Handle; UNICODE_STRING NTDriveNameW; PWSTR DOSDriveNameW; BOOLEAN b; NTSTATUS status; unsigned CharsInName,i; ACCESS_MASK AccessMask; // convert byte DOS drive name to widechar DOS drive name CharsInName = lstrlen(DOSDriveName); DOSDriveNameW = SAlloc((CharsInName+1)*sizeof(WCHAR)); if(DOSDriveNameW == NULL) { SetErrorText(IDS_ERROR_DLLOOM); return(NULL); } for(i=0; i