Applied change 1505 of the NewOS repository: added the -p option to makeflop
to be able to pad to the floppy block size. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@285 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
19111f404e
commit
16ba498087
@ -2,57 +2,88 @@
|
||||
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
||||
** Distributed under the terms of the NewOS License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
# define O_BINARY 0
|
||||
#endif
|
||||
|
||||
void usage(char **argv)
|
||||
|
||||
void
|
||||
usage(char *progName)
|
||||
{
|
||||
printf("usage: %s bootblock payload outfile\n", argv[0]);
|
||||
printf("usage: %s [-p #padding] bootblock payload outfile\n", progName);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct stat st;
|
||||
int err;
|
||||
unsigned int blocks;
|
||||
unsigned char bootsector[1024];
|
||||
unsigned char buf[512];
|
||||
size_t read_size;
|
||||
size_t written_bytes;
|
||||
int padding = 0;
|
||||
int infd;
|
||||
int outfd;
|
||||
char opt;
|
||||
int err;
|
||||
|
||||
if(argc < 4) {
|
||||
char *progName = argv[0];
|
||||
if (strrchr(progName,'/'))
|
||||
progName = strrchr(progName,'/') + 1;
|
||||
|
||||
while ((opt = getopt(argc, argv, "p:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'p':
|
||||
padding = atoi(optarg);
|
||||
if (padding < 0) {
|
||||
usage(progName);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
usage(progName);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
argc -= optind - 1;
|
||||
argv += optind - 1;
|
||||
|
||||
if (argc < 4) {
|
||||
printf("insufficient args\n");
|
||||
usage(argv);
|
||||
usage(progName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = stat(argv[2], &st);
|
||||
if(err < 0) {
|
||||
if (err < 0) {
|
||||
printf("error stating file '%s'\n", argv[2]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
outfd = open(argv[3], O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, 0666);
|
||||
if(outfd < 0) {
|
||||
if (outfd < 0) {
|
||||
printf("error: cannot open output file '%s'\n", argv[3]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// first read the bootblock
|
||||
infd = open(argv[1], O_BINARY|O_RDONLY);
|
||||
if(infd < 0) {
|
||||
if (infd < 0) {
|
||||
printf("error: cannot open bootblock file '%s'\n", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
if(read(infd, bootsector, sizeof(bootsector)) < sizeof(bootsector)
|
||||
|| lseek(infd, 0, SEEK_END) != sizeof(bootsector)) {
|
||||
if (read(infd, bootsector, sizeof(bootsector)) < sizeof(bootsector)
|
||||
|| lseek(infd, 0, SEEK_END) != sizeof(bootsector)) {
|
||||
printf ("error: size of bootblock file '%s' must match %d bytes.\n", argv[1], sizeof(bootsector));
|
||||
return -1;
|
||||
}
|
||||
@ -65,15 +96,30 @@ int main(int argc, char *argv[])
|
||||
bootsector[3] = (blocks & 0xff00) >> 8;
|
||||
|
||||
write(outfd, bootsector, sizeof(bootsector));
|
||||
written_bytes = sizeof(bootsector);
|
||||
|
||||
infd = open(argv[2], O_BINARY|O_RDONLY);
|
||||
if(infd < 0) {
|
||||
if (infd < 0) {
|
||||
printf("error: cannot open input file '%s'\n", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while((read_size = read(infd, buf, sizeof(buf))) > 0) {
|
||||
while ((read_size = read(infd, buf, sizeof(buf))) > 0) {
|
||||
write(outfd, buf, read_size);
|
||||
written_bytes += read_size;
|
||||
}
|
||||
|
||||
if (padding) {
|
||||
if (written_bytes % padding) {
|
||||
size_t towrite = padding - written_bytes % padding;
|
||||
unsigned char *buf = malloc(towrite);
|
||||
|
||||
memset(buf, 0, towrite);
|
||||
write(outfd, buf, towrite);
|
||||
written_bytes += towrite;
|
||||
|
||||
printf("output file padded to %ld\n", (unsigned long)written_bytes);
|
||||
}
|
||||
}
|
||||
|
||||
close(outfd);
|
||||
|
Loading…
x
Reference in New Issue
Block a user