/* * (C) Copyright 1992, ..., 2005 the "DOSEMU-Development-Team". * * for details see file COPYING in the DOSEMU distribution */ /* mkhdimage.c, for the Linux DOS emulator * * cheesy program to create an hdimage header * */ #include #include #include #include #ifdef __linux__ #include #endif #include #include int sectors = 17, heads = 4, cylinders = 40, header_size = 128; static void usage(void) { fprintf(stderr, "mkhdimage [-h ] [-s ] [-c|-t ]\n"); } int main(int argc, char **argv) { int c; int pos = 0; while ((c = getopt(argc, argv, "h:s:t:c:s:")) != EOF) { switch (c) { case 'h': heads = atoi(optarg); break; case 's': sectors = atoi(optarg); break; case 'c': /* cylinders */ case 't': /* tracks */ cylinders = atoi(optarg); break; default: fprintf(stderr, "Unknown option '%c'\n", c); usage(); exit(1); } } #define WRITE(fd, ptr, size) ({ int w_tmp=0; \ do { w_tmp=write(fd,ptr,size); } while ((w_tmp == -1) && (errno == EINTR)); \ if (w_tmp == -1) \ fprintf(stderr, "WRITE ERROR: %d, *%s* in file %s, line %d\n", \ errno, strerror(errno), __FILE__, __LINE__); \ w_tmp; }) pos += WRITE(STDOUT_FILENO, "DOSEMU", 7); pos += WRITE(STDOUT_FILENO, &heads, 4); pos += WRITE(STDOUT_FILENO, §ors, 4); pos += WRITE(STDOUT_FILENO, &cylinders, 4); pos += WRITE(STDOUT_FILENO, &header_size, 4); { char tmp[256]; memset(tmp, 0, 256); pos += WRITE(STDOUT_FILENO, tmp, header_size - pos); fprintf(stderr, "Pos now is %d\n", pos); } return 0; }