中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » [求助]获取驱动器信息,有什么办法不出现提示信息?
作者:
标题: [求助]获取驱动器信息,有什么办法不出现提示信息? 上一主题 | 下一主题
devang
新手上路





积分 12
发帖 4
注册 2010-9-1
状态 离线
『楼 主』:  [求助]获取驱动器信息,有什么办法不出现提示信息? 使用 LLM 解释/回答一下

DOS6.2 + BC3.1

实际项目中是图形界面,drive=0,1 时(A:,B:),_chdrivee有效,
但_dos_getdiskfree出错,应该是在执行21号中断是提示出错信息(General failure reaing drive A),破坏图形环境。
另外用 DUSE49 加载驱动参数为 drivers=3,则后两个盘符也会提示出错信息(Invalid unit reading drive F)。

Windows XP 下执行是光驱和虚拟光驱报错。

有什么办法不出现提示信息?自己知道这个驱动器不能用就行了。

代码如下:



C/C++ code
// crt_getdrive.c
// compile with: /c
// Illustrates drive functions including:
// _getdrive _chdrive _getdcwd
//

#include <dos.h>
#include <stdio.h>
#include <direct.h>
#include <stdlib.h>
#include <ctype.h>
int main( void )
{
int ch, drive, curdrive;
long LM;
static char path;
struct diskfree_t diskspace;

curdrive = _getdrive(); // Save current drive.
for( drive = 1; drive <= 26; drive++ ) // If we can switch to the drive, it exists.
{
if( !_chdrive( drive ) )
{
printf( "%c:", drive + 'A' - 1 );

if( _getdcwd( drive, path, _MAX_PATH ) != NULL )
printf( " (Current directory is %s)", path );

if(0==_dos_getdiskfree(drive,&diskspace))
{
LM=(unsigned long)(diskspace.avail_clusters)
*(unsigned long)(diskspace.sectors_per_cluster)
*(unsigned long)(diskspace.bytes_per_sector)/1024/1024;
printf( " %ld MBytes free",LM);
}
putchar( '\n' );
}
}
_chdrive( curdrive ); // Restore original drive.
}


2010-9-2 23:36
查看资料  发短消息  网志   编辑帖子  回复  引用回复
devang
新手上路





积分 12
发帖 4
注册 2010-9-1
状态 离线
『第 2 楼』:  MSDN上查到合适的例子,不能在纯DOS下执行 使用 LLM 解释/回答一下


// crt_getdiskfree.c
// compile with: /c
#include <windows.h>
#include <direct.h>
#include <stdio.h>
#include <tchar.h>

TCHAR g_szBorder = _T("======================================================================\n");
TCHAR g_szTitle1 = _T("|DRIVE|TOTAL CLUSTERS|AVAIL CLUSTERS|SECTORS / CLUSTER|BYTES / SECTOR|\n");
TCHAR g_szTitle2 = _T("|=====|==============|==============|=================|==============|\n");
TCHAR g_szLine = _T("| A: | | | | |\n");

void utoiRightJustified(TCHAR* szLeft, TCHAR* szRight, unsigned uVal);

int main(int argc, char* argv) {
TCHAR szMsg;
struct _diskfree_t df = {0};
ULONG uDriveMask = _getdrives();
unsigned uErr, uLen, uDrive;

printf(g_szBorder);
printf(g_szTitle1);
printf(g_szTitle2);

for (uDrive=1; uDrive<=26; ++uDrive) {
if (uDriveMask & 1) {
uErr = _getdiskfree(uDrive, &df);
memcpy(szMsg, g_szLine, sizeof(g_szLine));
szMsg = uDrive + 'A' - 1;

if (uErr == 0) {
utoiRightJustified(szMsg+8, szMsg+19, df.total_clusters);
utoiRightJustified(szMsg+23, szMsg+34, df.avail_clusters);
utoiRightJustified(szMsg+38, szMsg+52, df.sectors_per_cluster);
utoiRightJustified(szMsg+56, szMsg+67, df.bytes_per_sector);
}
else {
uLen = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL,
uErr, 0, szMsg+8, 4100, NULL);
szMsg = ' ';
szMsg = ' ';
szMsg = ' ';
}

printf(szMsg);
}

uDriveMask >>= 1;
}

printf(g_szBorder);
}

void utoiRightJustified(TCHAR* szLeft, TCHAR* szRight, unsigned uVal) {
TCHAR* szCur = szRight;
int nComma = 0;

if (uVal) {
while (uVal && (szCur >= szLeft)) {
if (nComma == 3) {
*szCur = ',';
nComma = 0;
}
else {
*szCur = (uVal % 10) | 0x30;
uVal /= 10;
++nComma;
}

--szCur;
}
}
else {
*szCur = '0';
--szCur;
}

if (uVal) {
szCur = szLeft;

while (szCur <= szRight) {
*szCur = '*';
++szCur;
}
}
}


结果如下,中间未提示错误信息,这样就好

======================================================================
|DRIVE|TOTAL CLUSTERS|AVAIL CLUSTERS|SECTORS / CLUSTER|BYTES / SECTOR|
|=====|==============|==============|=================|==============|
| C: | 7,681,070 | 5,276,989 | 8 | 512 |
| D: | 23,041,218 | 18,417,512 | 8 | 512 |
| E: | 23,041,218 | 16,398,257 | 8 | 512 |
| F: | 21,818,270 | 2,858,339 | 8 | 512 |
| G: | 2,560,351 | 2,543,733 | 8 | 512 |
| H: | 设备未就绪。 | | |
| I: | 设备未就绪。 | | |
======================================================================


2010-9-2 23:39
查看资料  发短消息  网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: