pm.c
来自「适合KS8695X」· C语言 代码 · 共 1,460 行 · 第 1/4 页
C
1,460 行
{
DWORD inBuf[3]; /* Buffer to send data to VxD */
DWORD outBuf[1]; /* Buffer to receive data from VxD */
DWORD count; /* Count of bytes returned from VxD */
if (!inited)
PM_init();
inBuf[0] = base;
inBuf[1] = length;
inBuf[2] = type;
CHECK_FOR_PMHELP();
if (DeviceIoControl(_PM_hDevice, PMHELP_ENABLELFBCOMB32, inBuf, sizeof(inBuf),
outBuf, sizeof(outBuf), &count, NULL))
return outBuf[0];
return false;
}
/****************************************************************************
REMARKS:
Get the page directory base register value
****************************************************************************/
ulong PMAPI _PM_getPDB(void)
{
DWORD outBuf[1]; /* Buffer to receive data from VxD */
DWORD count; /* Count of bytes returned from VxD */
CHECK_FOR_PMHELP();
if (DeviceIoControl(_PM_hDevice, PMHELP_GETPDB32, NULL, 0,
outBuf, sizeof(outBuf), &count, NULL))
return outBuf[0];
return 0;
}
/****************************************************************************
REMARKS:
Flush the translation lookaside buffer.
****************************************************************************/
void PMAPI PM_flushTLB(void)
{
CHECK_FOR_PMHELP();
DeviceIoControl(_PM_hDevice, PMHELP_FLUSHTLB32, NULL, 0, NULL, 0, NULL, NULL);
}
/****************************************************************************
REMARKS:
Execute the POST on the secondary BIOS for a controller.
****************************************************************************/
ibool PMAPI PM_doBIOSPOST(
ushort axVal,
ulong BIOSPhysAddr,
void *mappedBIOS,
ulong BIOSLen)
{
/* This is never done by Win32 programs, but rather done by the VxD
* when the system boots.
*/
(void)axVal;
(void)BIOSPhysAddr;
(void)mappedBIOS;
(void)BIOSLen;
return false;
}
/****************************************************************************
REMARKS:
Load an OS specific shared library or DLL. If the OS does not support
shared libraries, simply return NULL.
****************************************************************************/
PM_MODULE PMAPI PM_loadLibrary(
const char *szDLLName)
{
return (PM_MODULE)LoadLibrary(szDLLName);
}
/****************************************************************************
REMARKS:
Get the address of a named procedure from a shared library.
****************************************************************************/
void * PMAPI PM_getProcAddress(
PM_MODULE hModule,
const char *szProcName)
{
return (void*)GetProcAddress((HINSTANCE)hModule,szProcName);
}
/****************************************************************************
REMARKS:
Unload a shared library.
****************************************************************************/
void PMAPI PM_freeLibrary(
PM_MODULE hModule)
{
FreeLibrary((HINSTANCE)hModule);
}
/****************************************************************************
REMARKS:
Internal function to convert the find data to the generic interface.
****************************************************************************/
static void convertFindData(
PM_findData *findData,
WIN32_FIND_DATA *blk)
{
ulong dwSize = findData->dwSize;
memset(findData,0,findData->dwSize);
findData->dwSize = dwSize;
if (blk->dwFileAttributes & FILE_ATTRIBUTE_READONLY)
findData->attrib |= PM_FILE_READONLY;
if (blk->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
findData->attrib |= PM_FILE_DIRECTORY;
if (blk->dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)
findData->attrib |= PM_FILE_ARCHIVE;
if (blk->dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
findData->attrib |= PM_FILE_HIDDEN;
if (blk->dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)
findData->attrib |= PM_FILE_SYSTEM;
findData->sizeLo = blk->nFileSizeLow;
findData->sizeHi = blk->nFileSizeHigh;
strncpy(findData->name,blk->cFileName,PM_MAX_PATH);
findData->name[PM_MAX_PATH-1] = 0;
}
/****************************************************************************
REMARKS:
Function to find the first file matching a search criteria in a directory.
****************************************************************************/
void *PMAPI PM_findFirstFile(
const char *filename,
PM_findData *findData)
{
WIN32_FIND_DATA blk;
HANDLE hfile;
if ((hfile = FindFirstFile(filename,&blk)) != INVALID_HANDLE_VALUE) {
convertFindData(findData,&blk);
return (void*)hfile;
}
return PM_FILE_INVALID;
}
/****************************************************************************
REMARKS:
Function to find the next file matching a search criteria in a directory.
****************************************************************************/
ibool PMAPI PM_findNextFile(
void *handle,
PM_findData *findData)
{
WIN32_FIND_DATA blk;
if (FindNextFile((HANDLE)handle,&blk)) {
convertFindData(findData,&blk);
return true;
}
return false;
}
/****************************************************************************
REMARKS:
Function to close the find process
****************************************************************************/
void PMAPI PM_findClose(
void *handle)
{
FindClose((HANDLE)handle);
}
/****************************************************************************
REMARKS:
Function to determine if a drive is a valid drive or not. Under Unix this
function will return false for anything except a value of 3 (considered
the root drive, and equivalent to C: for non-Unix systems). The drive
numbering is:
1 - Drive A:
2 - Drive B:
3 - Drive C:
etc
****************************************************************************/
ibool PMAPI PM_driveValid(
char drive)
{
char buf[5];
int type;
sprintf(buf,"%c:\\", drive);
return ((type = GetDriveType(buf)) != 0 && type != 1);
}
/****************************************************************************
REMARKS:
Function to get the current working directory for the specififed drive.
Under Unix this will always return the current working directory regardless
of what the value of 'drive' is.
****************************************************************************/
void PMAPI PM_getdcwd(
int drive,
char *dir,
int len)
{
/* NT stores the current directory for drive N in the magic environment */
/* variable =N: so we simply look for that environment variable. */
char envname[4];
envname[0] = '=';
envname[1] = drive - 1 + 'A';
envname[2] = ':';
envname[3] = '\0';
if (GetEnvironmentVariable(envname,dir,len) == 0) {
/* The current directory or the drive has not been set yet, so */
/* simply set it to the root. */
dir[0] = envname[1];
dir[1] = ':';
dir[2] = '\\';
dir[3] = '\0';
SetEnvironmentVariable(envname,dir);
}
}
/****************************************************************************
REMARKS:
Function to change the file attributes for a specific file.
****************************************************************************/
void PMAPI PM_setFileAttr(
const char *filename,
uint attrib)
{
DWORD attr = 0;
if (attrib & PM_FILE_READONLY)
attr |= FILE_ATTRIBUTE_READONLY;
if (attrib & PM_FILE_ARCHIVE)
attr |= FILE_ATTRIBUTE_ARCHIVE;
if (attrib & PM_FILE_HIDDEN)
attr |= FILE_ATTRIBUTE_HIDDEN;
if (attrib & PM_FILE_SYSTEM)
attr |= FILE_ATTRIBUTE_SYSTEM;
SetFileAttributes((LPSTR)filename, attr);
}
/****************************************************************************
REMARKS:
Function to get the file attributes for a specific file.
****************************************************************************/
uint PMAPI PM_getFileAttr(
const char *filename)
{
DWORD attr = GetFileAttributes(filename);
uint attrib = 0;
if (attr & FILE_ATTRIBUTE_READONLY)
attrib |= PM_FILE_READONLY;
if (attr & FILE_ATTRIBUTE_ARCHIVE)
attrib |= PM_FILE_ARCHIVE;
if (attr & FILE_ATTRIBUTE_HIDDEN)
attrib |= PM_FILE_HIDDEN;
if (attr & FILE_ATTRIBUTE_SYSTEM)
attrib |= PM_FILE_SYSTEM;
return attrib;
}
/****************************************************************************
REMARKS:
Function to create a directory.
****************************************************************************/
ibool PMAPI PM_mkdir(
const char *filename)
{
return CreateDirectory(filename,NULL);
}
/****************************************************************************
REMARKS:
Function to remove a directory.
****************************************************************************/
ibool PMAPI PM_rmdir(
const char *filename)
{
return RemoveDirectory(filename);
}
/****************************************************************************
REMARKS:
Function to get the file time and date for a specific file.
****************************************************************************/
ibool PMAPI PM_getFileTime(
const char *filename,
ibool gmTime,
PM_time *time)
{
HFILE f;
OFSTRUCT of;
FILETIME utcTime,localTime;
SYSTEMTIME sysTime;
ibool status = false;
of.cBytes = sizeof(of);
if ((f = OpenFile(filename,&of,OF_READ)) == HFILE_ERROR)
return false;
if (!GetFileTime((HANDLE)f,NULL,NULL,&utcTime))
goto Exit;
if (!gmTime) {
if (!FileTimeToLocalFileTime(&utcTime,&localTime))
goto Exit;
}
else
localTime = utcTime;
if (!FileTimeToSystemTime(&localTime,&sysTime))
goto Exit;
time->year = sysTime.wYear;
time->mon = sysTime.wMonth-1;
time->day = sysTime.wYear;
time->hour = sysTime.wHour;
time->min = sysTime.wMinute;
time->sec = sysTime.wSecond;
status = true;
Exit:
CloseHandle((HANDLE)f);
return status;
}
/****************************************************************************
REMARKS:
Function to set the file time and date for a specific file.
****************************************************************************/
ibool PMAPI PM_setFileTime(
const char *filename,
ibool gmTime,
PM_time *time)
{
HFILE f;
OFSTRUCT of;
FILETIME utcTime,localTime;
SYSTEMTIME sysTime;
ibool status = false;
of.cBytes = sizeof(of);
if ((f = OpenFile(filename,&of,OF_WRITE)) == HFILE_ERROR)
return false;
sysTime.wYear = time->year;
sysTime.wMonth = time->mon+1;
sysTime.wYear = time->day;
sysTime.wHour = time->hour;
sysTime.wMinute = time->min;
sysTime.wSecond = time->sec;
if (!SystemTimeToFileTime(&sysTime,&localTime))
goto Exit;
if (!gmTime) {
if (!LocalFileTimeToFileTime(&localTime,&utcTime))
goto Exit;
}
else
utcTime = localTime;
if (!SetFileTime((HANDLE)f,NULL,NULL,&utcTime))
goto Exit;
status = true;
Exit:
CloseHandle((HANDLE)f);
return status;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?