当前位置: 技术问答>linux和unix
急!谁解决了这个问题,就是不断申请帐号也会帮他加1000分!!!!说话绝对算数!
来源: 互联网 发布时间:2015-03-11
本文导语: help!!! 求一命令代码 功能如下: 命令名 writetofd0(叫什么都成) 有一个参数 运行 #writetofd0 filename 后 就把filename这个文件写入软盘的固定扇区内(注意,是固定扇区) 还有将filename的文件名和大小也写进去(也是固...
help!!!
求一命令代码
功能如下:
命令名 writetofd0(叫什么都成) 有一个参数
运行 #writetofd0 filename 后
就把filename这个文件写入软盘的固定扇区内(注意,是固定扇区)
还有将filename的文件名和大小也写进去(也是固定扇区)
谢谢
求一命令代码
功能如下:
命令名 writetofd0(叫什么都成) 有一个参数
运行 #writetofd0 filename 后
就把filename这个文件写入软盘的固定扇区内(注意,是固定扇区)
还有将filename的文件名和大小也写进去(也是固定扇区)
谢谢
|
int readFloppy(unsigned char *outData, //读出数据的存储BUF,输出
int *outDataLen, //读出数据的长度,输入
int sectorNum) //扇区号
{
int retVal;
int fd;
unsigned char readBuf[1024];//大小为512的整数倍
memset(readBuf, 0, 1024);
printf("read floppy disk begin.");
fd = open("/dev/rfd0135ds18", O_RDWR);//打开软驱
if(fd == -1)
{
printf("the floppy disk not ready.");
return -1;
}
lseek(fd, (sectorNum*512), SEEK_SET);//定位文件指针,此处用来定义磁头
retVal = read(fd, readBuf, 512);
if(retVal != 512)
{
printf("readFloppy read %d sector error. read %d byte.", sectorNum, retVal);
return -1;
}
printf("read %d sector ok", sectorNum);
memcpy(outData, readBuf, outDataLen);
close(fd);
return 0;
}
// 主要参数说明同上,如果要写入的数据大于512,分批多次写入即可
int wrtFloppy(unsigned char *inData, int inDataLen, int sectorNum)
{
int retVal;
int fd;
unsigned char wrtBuf1[512];
memset(wrtBuf1, 0, 512);
printf("write floppy disk begin. inDataLen = %d, sectorNum = %d", inDataLen, sectorNum);
fd = open("/dev/rfd0135ds18", O_RDWR);
if(fd == -1)
{
printf("the floppy disk not ready");
return fd;
}
memcpy(wrtBuf1, inData, inDataLen);
lseek(fd, (sectorNum*512), SEEK_SET);
retVal = write(fd, wrtBuf1, 512);
if(retVal != 512)
{
printf("wrtFloppy write %d sector error. write %d byte.", sectorNum, retVal);
return FD_FLOPPY_ERROR;
}
close(fd);
printf("write floppy disk OK.");
return 0;
}
int *outDataLen, //读出数据的长度,输入
int sectorNum) //扇区号
{
int retVal;
int fd;
unsigned char readBuf[1024];//大小为512的整数倍
memset(readBuf, 0, 1024);
printf("read floppy disk begin.");
fd = open("/dev/rfd0135ds18", O_RDWR);//打开软驱
if(fd == -1)
{
printf("the floppy disk not ready.");
return -1;
}
lseek(fd, (sectorNum*512), SEEK_SET);//定位文件指针,此处用来定义磁头
retVal = read(fd, readBuf, 512);
if(retVal != 512)
{
printf("readFloppy read %d sector error. read %d byte.", sectorNum, retVal);
return -1;
}
printf("read %d sector ok", sectorNum);
memcpy(outData, readBuf, outDataLen);
close(fd);
return 0;
}
// 主要参数说明同上,如果要写入的数据大于512,分批多次写入即可
int wrtFloppy(unsigned char *inData, int inDataLen, int sectorNum)
{
int retVal;
int fd;
unsigned char wrtBuf1[512];
memset(wrtBuf1, 0, 512);
printf("write floppy disk begin. inDataLen = %d, sectorNum = %d", inDataLen, sectorNum);
fd = open("/dev/rfd0135ds18", O_RDWR);
if(fd == -1)
{
printf("the floppy disk not ready");
return fd;
}
memcpy(wrtBuf1, inData, inDataLen);
lseek(fd, (sectorNum*512), SEEK_SET);
retVal = write(fd, wrtBuf1, 512);
if(retVal != 512)
{
printf("wrtFloppy write %d sector error. write %d byte.", sectorNum, retVal);
return FD_FLOPPY_ERROR;
}
close(fd);
printf("write floppy disk OK.");
return 0;
}