home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
zip
/
diskutil
/
unixflop.lzh
/
UNIXFLOP
/
TAR2RAW.C
< prev
next >
Wrap
C/C++ Source or Header
|
1987-04-22
|
2KB
|
101 lines
#include <stdio.h>
#include <fcntl.h>
#include <osbind.h>
int size = 0;
int fd, s = 0, s_max = 512 * 9 * 2 * 80;
int track = 0, side = 0;
int block=0;
char buf[5120];
char filename[80];
int
main(argc,argv)
int argc;
char *argv[];
{
puts("Insert raw disk in drive A. Hit CR to read file D:\\A.TAR\n");
puts("or type file name: ");
gets(filename);
if (!filename[0])
strcpy(filename, "D:\\A.TAR");
fd = open(filename, O_RDONLY | O_BINARY);
if (!fd) {
char mess[80];
sprintf(mess, "Cannot open file %d\n", filename);
fatal_error(mess);
}
for (;;) {
if(convert_track(1, 0)) break;
if(convert_track(0, 1)) break;
}
close(fd);
puts("Ok, done. Hit CR.\n");
getchar();
return 0;
}
convert_track(next_side, incr_track)
int next_side, incr_track;
{
static long total_size;
int read_size = read(fd, buf, 512 * 9);
total_size += read_size;
if (read_size != 512 * 9) {
s_max=total_size/512/9;
bzero(buf+read_size, 512*9 - read_size);
}
if (Flopwr(buf, 0L, 0, 1, track, side, 9)) {
char mess[80];
sprintf(mess, "error writing track %d, side %d\n", track, side);
fatal_error(mess);
}
block = print_names(block, s, s +9 < s_max ? s+9 : s_max);
side = next_side; s += 9; track += incr_track;
if (read_size != 512 * 9) {
long pos = lseek(fd, 0L, 2);
if (pos == -1) {
fatal_error("could not reach end of file\n");
} else if (pos != total_size) {
fatal_error("cannot read whole file\n");
} else if (read_size > 512 * 7) {
return 0;
} else {
return 1;
}
} else
return 0;
}
int print_names(block, s, s_end)
int block, s, s_end;
{
/* printf("Block %d, s = %d, s_end = %d\n", block,s,s_end); */
while (block >= s && block < s_end) {
if (buf[(block-s) * 512] == '\0') {
/* end of tape reached */
printf("End of file at block %d\n", block);
block = -1;
s_max = block + 2;
} else {
long size;
sscanf(buf + (block-s) * 512 + 124, " %lo", &size);
printf("Block %d: %.100s %ld\n", block, buf + (block-s) * 512, size);
if (size)
block = block + 2 + (int) ((size - 1)/ 512);
else
block++;
}
}
return block;
}
fatal_error(s)
char *s;
{
puts(s);
puts("\007Aborting... Press CR\n");
getchar();
exit(1);
}