How to duplicate the Ultrix distribution TK50's?
Allan E Johannesen
aej at manyjars.WPI.EDU
Thu Jun 6 04:15:10 AEST 1991
Since mail bounces, here are the tape-to-disk and disk-to-tape
programs:
#include <sys/file.h>
#include <stdio.h>
int tape, disk, l_read, anything = 1, file_number = 0, files = 0, sfile;
#define l_block 10240
char block[l_block], fname[100], sname[100], *tapename, *getenv();
void
get_tape_name()
{ if ((tapename = getenv("TAPE")) == (char *) NULL)
tapename = "/dev/nrmt0h";
}
main(argc,argv)
int argc;
char **argv;
{ if (argc != 2)
{ printf("usage:\nto-disk set-name\nenv TAPE is tape name, else /dev/nrmt0h\n");
exit(1); };
get_tape_name();
while (anything)
{ if ((tape = open(tapename,O_RDONLY)) < 0)
{ perror("Couldn't open tape");
exit(1); };
sprintf(fname,"%s.%d",argv[1],file_number);
sprintf(sname,"s%s.%d",argv[1],file_number++);
if ((disk = open(fname,O_WRONLY|O_CREAT,0640)) < 0)
{ perror("Couldn't open disk");
exit(1); };
if ((sfile = open(sname,O_WRONLY|O_CREAT,0640)) < 0)
{ perror("Couldn't open size file");
exit(1); };
anything = 0;
while ((l_read = read(tape,block,l_block)) > 0)
{ if (anything++ == 0) files++;
if (sfile)
{ char length[20];
sprintf(length,"%d\n",l_read);
write(sfile,length,strlen(length));
close(sfile);
sfile = 0; };
write(disk,block,l_read); };
close(disk);
if (anything)
if (anything == 1)
printf("file %d, 1 block.\n",file_number);
else
printf("file %d, %d blocks.\n",file_number,anything);
else
{ printf("file %d, empty.\n",file_number);
unlink(fname); };
close(tape);
if (file_number < 3)
anything = 1; };
printf("done, %d files\n",files); }
disk-to-tape:
#include <stdio.h>
#include <sys/file.h>
#include <stdio.h>
FILE *size;
int tape, disk, l_read, anything = 1, file_number = 0, files = 0, block_size;
#define l_block 10240
char block[l_block], fname[100];
main(argc,argv)
int argc;
char **argv;
{ if (argc != 2)
{ printf("usage:\nto-tape disk-set-name\n");
exit(1); };
while (anything)
{ if ((tape = open("/dev/nrmt0h",O_WRONLY)) < 0)
{ perror("Couldn't open tape");
exit(1); };
sprintf(fname,"%s.%d",argv[1],file_number);
if ((disk = open(fname,O_RDONLY)) < 0)
break;
sprintf(fname,"s%s.%d",argv[1],file_number++);
if ((size = fopen(fname,"r")) == (FILE *) NULL)
{ perror("size not found");
exit(1); };
fgets(block,100,size);
fclose(size);
sscanf(block,"%d",&block_size);
printf("file %d blocksize %d ",file_number,block_size);
fflush(stdout);
anything = 0;
while ((l_read = read(disk,block,block_size)) > 0)
{ anything++;
write(tape,block,l_read); };
close(disk);
if (anything == 1)
printf("1 block.\n");
else
printf("%d blocks.\n",anything);
files++;
close(tape); };
printf("done, %d files\n",files); }
More information about the Comp.unix.ultrix
mailing list