|
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/errno.h>
#include <unistd.h>
#define BUFFER_SIZE 108
#define DEVICE_NAME "/dev/fd0"
#define MY_OFFSET (250*512)
int main (int argc, char **argv)
{
int from_fd,to_fd;
int bytes_read,bytes_write;
char buffer[BUFFER_SIZE];
char *ptr;
if(argc!=2)
{
printf("%s need input filename\n\a",argv[0]);
exit(1);
}
from_fd=open(DEVICE_NAME,O_RDWR);
if(!to_fd)
{
printf("errno is %d\n",errno);
exit(1);
}
if((to_fd=open(argv[1],O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR))==-1)
{
fprintf(stderr,"Open %s Error:%s\n",argv[2],strerror(errno));
exit(1);
}
lseek(to_fd,MY_OFFSET,SEEK_SET);
bytes_read=read(from_fd,buffer,BUFFER_SIZE);
ptr=buffer;
bytes_write=write(to_fd,ptr,bytes_read);
close(from_fd);
close(to_fd);
exit(0);
}
运行后竟将软盘250扇区之后的所有内容都读出来了,可我只想读出108个字节,请问该怎么办?谢谢 |
|