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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
int main(int argc, char** argv)
{
char* device = NULL;
/*
* Check for args
*/
if (argc < 2) {
fprintf(stderr, "Usage: %s <device>\n", argv[0]);
exit(1);
}
device = argv[1];
/*
* Check the device we're given is a real one
*/
if (!(fexists(device))) {
fprintf(stderr, "%s: \"%s\": file doesn't exist\n",
argv[0], device);
exit(1);
}
/*
* Check we have root access
*/
if (getuid()) {
fprintf(stderr, "%s: you are not root. This program will only "
"work if run as root.\n", argv[0]);
exit(1);
}
/*
* Write the bootsector and the other files
*/
if (write_mbr(device) < 0) {
fprintf(stderr, "%s: couldn't write MBR to \"%s\"\n",
argv[0], device);
exit(1);
}
if (has_extfs(device)) {
if (write_extfs(device) < 0) {
fprintf(stderr, "%s: couldn't write files to \"%s\"\n",
argv[0], device);
exit(1);
}
} else {
if (write_nofs(device) < 0) {
fprintf(stderr, "%s: couldn't write files to \"%s\"\n",
argv[0], device);
exit(1);
}
}
return 0;
}
|