1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(void)
{
int fd;
char bootloader[512];
int err;
char diskPath[]="/dev/sda";
char blPath[] = "./bootloader";
fd = open(diskPath,O_RDONLY);
if(fd<0)
{
printf("Error, can't open %s.\n",diskPath);
return fd;
}
printf("Loading the bootloader....\n");
err = read(fd,bootloader,512);
if(err<0){
printf("Can't read %s",diskPath);
}
close(fd);
printf("Saving the bootloader to %s\n",blPath);
fd = open(blPath,O_WRONLY | O_CREAT);
if(fd<0)
{
printf("Error, can't open %s.\n",blPath);
return fd;
}
write(fd,bootloader,512);
close(fd);
return 0;
} |
Partager