RT-11 floppy -- extract.c
John R Blaker
jrb at wdl1.UUCP
Sat Feb 18 04:51:05 AEST 1984
/*==========================================================================*
* == E X T R A C T == *
*==========================================================================*
* John R Blaker -- Ford Aerospace & Communications Corporation -- Oct 1982 *
*==========================================================================*
* This implements the 'extract' function. This file contains the *
* following functions: *
* extract() Extracts files from the disc *
* copy() Does the actual work *
*==========================================================================*
*/
/*
* Include files
*/
#include "rt11.h" /* Global definitions */
/*
* extract()
* This function extracts files from disc. There are two
* cases:
* 1. No files were specified on the command line
* 2. One or more files were specified on the command line
* In case 1 it is assumed that all files are to be extracted. In case
* 2 only the specified files will be extracted.
*/
extract()
{
MEM_DIR *curpos; /* Current entry in directory */
int output; /* File descriptor for output */
int index; /* Loop index */
verbose("EXTRACTING FILES");
trace("Got to extract()");
if (TRACE)
printf("TRACE: COUNT = %d\n", COUNT);
if (COUNT == 0) { /* Case 1 */
curpos = dir_header;
while (curpos != NULL) {
output = creat(curpos -> md_name, 0644);
close(output);
output = open(curpos -> md_name, IO_WT);
if (output < 0) {
error("Can't open file");
unlock("/tmp/disc_lock");
exit(1);
} else {
if (VERBOSE)
printf("extracting %s\n",
curpos -> md_name);
copy(curpos, output);
} /* if...else */
close(output);
curpos = curpos -> md_next;
} /* while */
} else { /* Case 2 */
for (index = 0; index < COUNT; index++) {
curpos = findentry(FILES[index]);
if (curpos != NULL) {
output = creat(curpos -> md_name, 0644);
close(output);
output = open(curpos -> md_name, IO_WT);
if (output < 0) {
error("Can't open file");
unlock("/tmp/disc_lock");
exit(1);
} else {
if (VERBOSE)
printf("extracting %s\n",
curpos -> md_name);
copy(curpos, output);
} /* if...else */
close(output);
} /* if */
} /* for */
} /* if...else */
} /* extract */
/*
* copy()
* Copy file from floppy to UNIX
*/
copy(entry, output)
MEM_DIR *entry; /* Directory entry */
int output; /* File descriptor for output file */
{
unsigned blockno; /* Current block number */
unsigned size; /* Size of file in blocks */
int index; /* Loop index */
char info[BLOCKSIZE]; /* Info from floppy */
trace("Got to copy()");
blockno = entry -> md_addr;
size = ((entry -> md_size) / BLOCKSIZE);
if (TRACE)
printf("TRACE: blockno = %u\tsize = %u\n", blockno, size);
for (index = 0; index < size; index++) {
getblock(blockno, info);
write(output, info, BLOCKSIZE);
blockno += BLOCKSIZE;
} /* for */
} /* copy */
More information about the Comp.sources.unix
mailing list