Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!rpi!bu.edu!m2c!wpi.WPI.EDU!wpi!aej From: aej@manyjars.WPI.EDU (Allan E Johannesen) Newsgroups: comp.unix.ultrix Subject: Re: How to duplicate the Ultrix distribution TK50's? Message-ID: Date: 5 Jun 91 18:15:10 GMT References: <2378@netmbx.UUCP> Sender: news@wpi.WPI.EDU (News) Distribution: comp Organization: Worcester Polytechnic Institute, Worcester, MA 01609-2280 Lines: 123 In-Reply-To: aej@manyjars.WPI.EDU's message of Wed, 5 Jun 1991 16: 45:43 GMT Nntp-Posting-Host: manyjars.wpi.edu Since mail bounces, here are the tape-to-disk and disk-to-tape programs: #include #include 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 #include #include 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); }