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/>.
25 #include <sys/ioctl.h>
27 #define IMAGE_FILE "inst.img"
29 int main (int argc
, char **argv
)
31 printf ("ZeX/OS Installer\n");
34 printf ("syntax: inst <device>\n\texample: inst /dev/hda\n");
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");
47 if (c
== 'n' || c
== 'N') {
48 printf ("Installer was aborted\n");
50 } else if (c
== 'y' || c
== 'Y')
51 printf ("Loading data ..\n");
53 printf ("Installer was aborted - wrong option '%c'\n", c
);
57 int fd
= open (IMAGE_FILE
, O_RDONLY
);
60 printf ("ERROR -> image file '%s' not found\n", IMAGE_FILE
);
64 unsigned flen
= 2048*1024; /* 2MB image */
66 printf ("Image size: %dkB\n", flen
/1024);
69 memcpy (rq
.dev
, dev
, dev_len
);
70 rq
.dev
[dev_len
] = '\0';
73 for (s
= 0; s
< flen
/512; s
++) {
76 memset (rq
.data
, 0, 512);
77 int l
= read (fd
, rq
.data
, 512);
80 printf ("ERROR -> read () == 0; image data are probably corrupted\n");
84 int r
= ioctl (IOATAWRITE
, &rq
, sizeof (struct ioatarq_t
));
87 printf ("WARNING -> ioctl (IOATAWRITE) == -1; repeating\n");
89 r
= ioctl (IOATAWRITE
, &rq
, sizeof (struct ioatarq_t
));
91 printf ("ERROR -> ioctl (IOATAWRITE) == -1; installation failed !\n");
97 printf ("\b\b\b\b\b%d %c", s
/41+1, '%');
102 printf ("\nInstallation was finished\nCongratulation !\n");