- 首页
-
- 问答
-
Chong
马甲吧~你~楼上那位我用的GNU不能编译这个程序所以没编译就拿过来我不废话 有错就去改 没什么大不了的可能是最初理解的不太好 lz只是想得到驱动器列表的话 参考下面的代码比较老是实现读取分区信息的 需要改造 主要是bios.h的更新 其中_bios_disk()需要使用新的int biosdisk(int cmd,int driver,int head,int track,int sector,int nsets,void *buf)替换 我这里不能编译带有dos.h的c程序还有追加结构体定义 其实是这个程序里的bios.h比较老 lz的应该比较新struct diskinfo_t{ unsigned drive, head, track, sector, nsectors; /* void __far *buffer;*/};对应的bios.h参考能做的就这么多的#include <stdio.h>#include <dos.h>#include <bios.h>struct direct { char name[10]; unsigned char mode; char reserved[10]; struct stamp { unsigned int mtime; unsigned int mdate; } stamp; unsigned int first; unsigned long fsize;};struct param { short int sysid[9]; int bytes_sector; short int sectors_cluster; int sectors_reserved; short int total_fats; unsigned int root_entries; int total_sectors; short int media_descriptor; int sectors_fat; int sectors_track; int number_heads; int hidden_sectors;};struct param *bbp();main(argc,argv)int argc;char **argv;{ int i, j, retry, strt; unsigned ch, status = 0; char buf[512]; void far *pbuf; struct diskinfo_t info; struct direct *d; struct param *p; memset(buf,'\0', sizeof (buf)); pbuf = (void far *)(&buf[0]); info.buffer = pbuf; info.drive = (argc > 1) ? atoi(argv[1]) : 0; info.head = 0; info.track = 0; info.sector = 1; info.nsectors = 1; for (retry = 0; retry <= 3; retry++) { if ((status = _bios_disk(_DISK_READ, &info)) == info.nsectors) { printf("read OK: sizeof direct=%d\n", sizeof (struct direct)); printf("read OK: sizeof params=%d\n", sizeof (struct param));/* d = (struct direct *)buf; for (i = 0; i < 10; i++) { printf("[%11.11s] first=%x size=%d\n", d->name, d->first, d->fsize); ++d; }*/ p = (struct param *)bbp(pbuf);printf(" sysid=%8.8s\n", p->sysid);printf(" bytes_sector=%d\n", p->bytes_sector);printf(" sectors_cluster=%d\n", p->sectors_cluster);printf("sectors_reserved=%d\n", p->sectors_reserved);printf(" total_fats=%d\n", p->total_fats);printf(" root_entries=%u\n", p->root_entries);printf(" total_sectors=%d\n", p->total_sectors);printf("media_descriptor=%x\n", p->media_descriptor);printf(" sectors_fat=%d\n", p->sectors_fat);printf(" sectors_track=%d\n", p->sectors_track);printf(" number_heads=%d\n", p->number_heads);printf(" hidden_sectors=%d\n", p->hidden_sectors); exit(0); } }}struct param *bbp(p)char far *p;{ static struct param d; strncpy(d.sysid,&p[0x3],8); d.bytes_sector = (int )p[0xb]; d.sectors_cluster = (short int )p[0xd]; d.sectors_reserved = (int )p[0xe]; d.total_fats = (short int )p[0x10]; d.root_entries = (unsigned int)p[0x11]; d.total_sectors = (int )p[0x13]; d.media_descriptor = (short int )p[0x15]; d.sectors_fat = (int )p[0x16]; d.sectors_track = (int )p[0x18]; d.number_heads = (int )p[0x1a]; d.hidden_sectors = (int )p[0x1c]; return (&d);} 我可以帮助你,你先设置我最佳答案后,我百度Hii教你。
-
-
-
-
-
-
-
-
-
求购