]> git.sesse.net Git - pistorm/blob - ide/makedisk.c
9e4defb8f23b358bbc709785ee901446f7b46283
[pistorm] / ide / makedisk.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <fcntl.h>
4 #include <unistd.h>
5 #include "ide.h"
6
7 int main(int argc, const char *argv[])
8 {
9   int t, fd;
10   if (argc != 3) {
11     fprintf(stderr, "%s [type] [path]\n", argv[0]);
12     exit(1);
13   }
14   t = atoi(argv[1]);
15   if (t < 1 || t > MAX_DRIVE_TYPE) {
16     fprintf(stderr, "%s: unknown drive type.\n", argv[0]);
17     exit(1);
18   }
19   fd = open(argv[2], O_WRONLY|O_TRUNC|O_CREAT|O_EXCL, 0666);
20   if (fd == -1) {
21     perror(argv[2]);
22     exit(1);
23   }
24   if (ide_make_drive(t, fd) < 0) {
25     perror(argv[2]);
26     exit(1);
27   }
28   return 0;
29 }