Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / apps / inst / main.c
blob082c20b37a5bb027b1ead74346f3a7195252e5d8
1 /*
2 * ZeX/OS
3 * Copyright (C) 2010 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <fcntl.h>
25 #include <sys/ioctl.h>
27 #define IMAGE_FILE "inst.img"
29 int main (int argc, char **argv)
31 printf ("ZeX/OS Installer\n");
33 if (argc < 2) {
34 printf ("syntax: inst <device>\n\texample: inst /dev/hda\n");
35 return -1;
38 char *dev = argv[1];
39 unsigned dev_len = strlen (dev);
41 printf ("Device: %s\n----------------", dev);
43 printf ("\nAre you sure you want lose all data on the current device ? (y/N)\n");
45 char c = getchar ();
47 if (c == 'n' || c == 'N') {
48 printf ("Installer was aborted\n");
49 return 0;
50 } else if (c == 'y' || c == 'Y')
51 printf ("Loading data ..\n");
52 else {
53 printf ("Installer was aborted - wrong option '%c'\n", c);
54 return 0;
57 int fd = open (IMAGE_FILE, O_RDONLY);
59 if (!fd) {
60 printf ("ERROR -> image file '%s' not found\n", IMAGE_FILE);
61 return -1;
64 unsigned flen = 2048*1024; /* 2MB image */
66 printf ("Image size: %dkB\n", flen/1024);
68 struct ioatarq_t rq;
69 memcpy (rq.dev, dev, dev_len);
70 rq.dev[dev_len] = '\0';
72 unsigned long s = 0;
73 for (s = 0; s < flen/512; s ++) {
74 rq.sector = s;
76 memset (rq.data, 0, 512);
77 int l = read (fd, rq.data, 512);
79 if (!l) {
80 printf ("ERROR -> read () == 0; image data are probably corrupted\n");
81 break;
84 int r = ioctl (IOATAWRITE, &rq, sizeof (struct ioatarq_t));
86 if (r == -1) {
87 printf ("WARNING -> ioctl (IOATAWRITE) == -1; repeating\n");
88 sleep (1);
89 r = ioctl (IOATAWRITE, &rq, sizeof (struct ioatarq_t));
90 if (r == -1) {
91 printf ("ERROR -> ioctl (IOATAWRITE) == -1; installation failed !\n");
92 break;
96 usleep (1);
97 printf ("\b\b\b\b\b%d %c", s/41+1, '%');
100 close (fd);
102 printf ("\nInstallation was finished\nCongratulation !\n");
104 return 0;