scantape.c

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 1,286 行 · 第 1/3 页

C
1,286
字号
    /*******     *	READ / PROCESS	+-->  HDR1     ******/	if ((i = read(fileno(Magtfp), Labelbuf, BUFSIZE)) <= 0) {	    /*	     * This is the normal way that the LTF currently exits	     * from the  forever loop we are inside of. When it 	     * exhausts the usable data on the input volume, the	     * above read returns a  <= 0 condition. Normally this	     * should be due to the fact that it has reached the	     * set of "double" end of tape marks that signify the 	     * end of data. Empty files may pose a premature exit, 	     * but at this time, enough is not yet known about empty 	     * file handling to determine if this is in fact a 	     * real possiblity. 	     */	    if (i < 0)		ceot();	    /* Complain about files that were not	     * found on the volume.	     */	    for (fstat = F_head; fstat; fstat = fstat->f_next) {		if (!fstat->f_found) {		    if (!Seqno)			PERROR "%s: %s %s\n", Progname,NOTONV, fstat->f_src);		    else			PERROR "%s: %s %s\n", Progname,NOTONP, fstat->f_src);		}	    }/*E for fstat ..*/    	    if (Seqno && skip <= Seqno) {	    	PERROR "\n%s: %s %s\n", Progname, CANTFSF, Magtdev);	    	perror(Magtdev);	        printf("\n");	    	exit(FAIL);	    }	    printf("\n");	    exit(SUCCEED);	}	sscanf(Labelbuf, "%3s%1d%17s%6s%4d%4d%4d%2d%c%5s %5s%*7c%13s", 		L_labid, &L_labno, L_filename, L_volid, &L_fsecno, 		&L_fseqno, &L_gen, &L_genver, &L_crecent, L_credate, 		L_expirdate, L_systemid);	if (Ansiv == '3')	    strcpy(sysvol, L_systemid);	/* Abort if multi-volume indicator is seen !	 */	if (!strcmp(L_labid, "EOV")) {	/*	 * As the LTF is not designed to process multi-volume	 * sets, we must abandon the operation at this point.	 * ie. There is no more data on the tape. A partial	 * file may have been written to the output device.	 * If we were to try to deal with "multi-volume" sets,	 * logic would be added at this point to switch to	 * the next volume and continue ...	 */		PERROR "\n%s: %s\n\n", Progname, MULTIV1);		exit(FAIL);	}	if (strcmp(L_labid, "HDR") || L_labno != 1) {		if (Tape) {hdr1err:			if (!strcmp(L_labid, "UVL")) {		    		PERROR "\n%s: %sUVL%d\n", Progname, INVLFS, L_labno,  BELL); 				continue;			}		    PERROR "\n%s: %s HDR1%c\n", Progname, INVLF, BELL); 		    wbadlab();		}/*T if Tape */		else {			/*			 * If i/o device is not a tape AND			 * we see a dummy tape_mark when we			 * are looking for HDR1, assume it is			 * the double tape mark - end of data			 * on volume condition.			 */			if (!tape_mark(Labelbuf))				goto hdr1err;			else {				cat_misc[0] = 0;					printf("\n");				/* Complain about files that were not				 * found on the volume.				 */				for (fstat = F_head; fstat; fstat = fstat->f_next) {					if (!fstat->f_found) {					    if (!Seqno)					    	PERROR "%s: %s %s\n", Progname,NOTONV, fstat->f_src);					    else					    	PERROR "%s: %s %s\n", Progname,NOTONP, fstat->f_src);					    cat_misc[0] = '\n';					}				}/*E for fstat ..*/				fprintf(stderr,"%c",cat_misc[0]);    	    			if (Seqno && skip <= Seqno) {	    			    PERROR "\n%s: %s %s\n", Progname, CANTFSF, Magtdev);	    			    perror(Magtdev);				    printf("\n");	    			    exit(FAIL);	    			}				exit(SUCCEED);				}		}/*F if tape */	}/*E if HDR1 */	/*	 * Set the flag that tells us whether or not this volume	 * was created by an Ultrix system. Volmo makes sure we	 * do the announcement and flag set only wonce.	 */	if (!Volmo) {		/* 		 * Display the volume label information if requested. 		 */		if (Verbose) {			PROMPT "\n%s: %s %s %s %c\n", Progname, VOLIS, Volid, ANSIV, Ansiv); 			PROMPT "%s: %s %s\n", Progname, OWNRID, L_ownrid);			PROMPT "%s: %s  %s\n", Progname, IMPIDM, L_systemid);		}	}	if (!strncmp(L_systemid,IMPID,13) && !strncmp(L_systemid, sysvol, 13))	    Ultrixvol = TRUE;	else {	    Ultrixvol = FALSE;	    Noheader3 = TRUE;	}	if (strncmp(L_systemid, sysvol, 13))	    PERROR "%s: %s %s\n", Progname, IMPIDC, L_systemid);	/* 	 *	Lower case the HDR1 File ID string. 	 *	IF: We  MUST  use the HDR1 string for this files' name. 	 */	if (!Ultrixvol || Noheader3 || Ansiv != '4') {		cp = L_filename;		while (*cp) {			*cp = isupper(*cp) ? *cp-'A'+'a' : *cp;			cp++;		}	}	/**/	/******* 	*	READ / PROCESS	+-->  HDR2 	******/	if ((i = read(fileno(Magtfp), Labelbuf, BUFSIZE)) <= 0) {		PERROR "\n%s: %s HDR2%c\n", Progname, CANTRL, BELL);		perror(Progname);		if (i < 0)		    ceot();		exit(FAIL);	}	if (Ultrixvol) {	    sscanf(Labelbuf, "%3s%1d%c%5d%5d%6o%4d%4d%4d%3c%1c%10ld%1d%1d%1d%2d",		L_labid, &L_labno, &L_recformat, &L_blklen,		    &L_reclen, &mode, &uid, &gid, &lnk_fseqno,			Tftypes,Dummy,&charcnt,&Lhdrl, &Leofl, 			   &hlink, &Bufoff);	}	else {		sscanf(Labelbuf, "%3s%1d%c%5d%5d%35c%2d", L_labid,		    &L_labno, &L_recformat, &L_blklen, &L_reclen,Dummy, &Bufoff);		strcpy(Tftypes, "???");	}	/*	 * Make sure we are seeing the correct label at this point.	 */	if (strcmp(L_labid, "HDR") || L_labno != 2) {		PERROR "\n%s: %s HDR2%c\n", Progname, INVLF, BELL); 		wbadlab();	}	if (Func == EXTRACT) {	    if (L_blklen < MINBLKSIZE || L_blklen > MAXBLKSIZE) {		PERROR "\n%s: %s %d%s\n", Progname, INVBS, MAXBLKSIZE, BYTES);		exit(FAIL);	    }#ifdef U11	    if ((strncmp(Tftypes, "dir", 3)) && (L_recformat == FIXED) && (L_reclen < 1 || L_reclen > MAXRECSIZE)) {		PERROR "\n%s: %s %d%s\n", Progname, INVRS, MAXRECSIZE, BYTES);		exit(FAIL);	    }#endif	}	/**/	/******* 	*	READ / PROCESS	+-->  HDR3 	******/		/*	If user doesn't want HDR3, etc. data to be used, 	*	skip this stuff that gets name from HDR3 - EOF9. 	*/	if (!Noheader3 && skip >= Seqno) {	    if ((i = read(fileno(Magtfp), Labelbuf, BUFSIZE)) <= 0) {		PERROR "\n%s: %s HDR3%c\n", Progname, CANTRL, BELL);		PERROR "\n%s: %s\n\n", Progname, TRYNH3);		if (i < 0)	    	    ceot();		exit(FAIL);	    }	    Labelbuf[BUFSIZE] = 0;	    /* For one of our volumes, get the	     * data we have on this file from HDR3.	     */	    sscanf(Labelbuf, "%3s%1d%10ld%10c%20c%36s", L_labid, &L_labno, &modtime, Owner, Hostname, pathname);	    if (strcmp(L_labid, "HDR") || L_labno != 3) {		PERROR "\n%s: %s HDR3%c", Progname, INVLF, BELL);		PERROR "\n%s: %s\n\n", Progname, TRYNH3);	        wbadlab();			    }	    /* 	     * If not an ANSI version 4 volume, lower case the	     * pathname string component by default.	     */	    if (Ansiv != '4') {		cp = pathname;		while (*cp) {			*cp = isupper(*cp) ? *cp-'A'+'a' : *cp;			cp++;		}	    }	    /**/	    /*******	    *	READ / PROCESS	+-->  HDR4 thru HDRn	    ******/	    if (Lhdrl > 3) {		char epathname[77];		int labelno=4;		for (;labelno <= Lhdrl; labelno++) {			if ((i = read(fileno(Magtfp), Labelbuf, BUFSIZE)) <= 0) {				PERROR "\n%s: %s HDR%d%c\n", Progname, CANTRL, labelno, BELL);				perror(Progname);				if (i < 0)				    ceot();				exit(FAIL);			}			/*			 * Extract the label number and extended			 * pathname characters from this HDRn.			 */			sscanf(Labelbuf, "%3s%1d%76s", L_labid, &L_labno, epathname);			/*			 * Make sure we are seeing something			 * that looks like the correct			 * HDRn label.			 */			if (strcmp(L_labid, "HDR") || L_labno != labelno) {					PERROR "\n%s: %s HDR%d%c", Progname, INVLF, labelno, BELL);					PERROR "\n%s: %s\n\n", Progname, TRYNH3);    					wbadlab();					}			strncat(pathname,epathname,76);		}/*E for ;labelno ..*/		/*		 * If there are extended path/file name		 * characters tucked away in the EOF labels,		 * extract them and tack them on to the		 * real path name of the file before		 * we read the file data. A tedious, but		 * necessary step.		 */		if (Leofl) {			if (Tape) {			    rew(1);			    /*			     * This should place us at the EOF1			     * label of the file.			     */			    fsf(((L_fseqno - 1) *3) + 2);			}/*T if (Tape) */			else {			    save = ftell(Magtfp);			    fsf(1);			}/*F if (Tape) */			for (labelno =1; labelno <= Leofl; labelno++) {				if ((i = read(fileno(Magtfp), Labelbuf, BUFSIZE)) <= 0) {					PERROR "\n%s: %s EOF%d%c\n", Progname, CANTRL, labelno, BELL);					perror(Progname);					if (i < 0)				    	    ceot();					exit(FAIL);				}				/*			 	 * Extract the label number &				 * extended pathname characters				 * from this EOFn.			 	 */				sscanf(Labelbuf, "%3s%1d%76s", L_labid, &L_labno, epathname);				/*			 	 * Make sure we are seeing				 * something that looks like			 	 * an EOFn label.			 	 */				if (strcmp(L_labid, "EOF") || L_labno != labelno) {						PERROR "\n%s: %s EOF%d%c", Progname, INVLF, labelno, BELL);						PERROR "\n%s: %s\n\n", Progname, TRYNH3);	    					wbadlab();						}				/* First extended path/file				 * name characters appear in				 * EOF3 and can continue thru				 * the EOF9 label.				 */				if(L_labno > 2){					strncat(pathname,epathname,76);				}			}/*E for labelno=1;labelno ..*/			/*			 * Now re-position the volume for			 * reading of the file data after			 * extracting the extended path/file			 * name characters from the EOF			 * label set. We will end up at HDR1			 * of the file and the xtractf() 			 * function will take us forward to			 * the start of the data with a fsf().			 */			if (Tape) {			    rew(1);			    /*			     * This should place us at the HDR1			     * label of the file.			     */			    fsf((L_fseqno - 1) *3);			}/*T if (Tape) */			else {			    fseek(Magtfp, save, 0);			}/*F if (Tape) */		}/*E if (Leofl) */	    }/*E if Lhdrl > 3 */	}/*F if Noheader3 */	/**/	if (!Volmo) {	    if (Verbose && Ultrixvol && !Noheader3) 		PERROR "%s: %s  %s\n", Progname, VOLCRE, Hostname);	    Volmo++;	    printf("\n");	}	if (!Noheader3)    	    strcpy(Name,pathname);	else {    	    modtime = 0l;    	    Owner[0] = NULL;    	    Hostname[0] = NULL;    	    /*    	    * L_filename is 17 characters of the "interchange"    	    * file name from HDR1.    	    */    	    strcpy(Name,L_filename);    	    strcpy(pathname,L_filename);	}	/* Go position to file data, then check if buffer offset	 * is zero.  If not, read past specified bytes 	 */	fsf(1);	if (Bufoff != 0)	    if ((i = read(fileno(Magtfp), Labelbuf, Bufoff)) <= 0) {		PERROR "\n%s: %s %2d %c\n", Progname, CANTBUF, Bufoff, BELL);		perror(Progname);		if (i < 0)		    ceot();		exit(FAIL);	    }	/* If positioning by sequence number and not there yet,	 * increment skipper and go to start of forever loop	 */ 	if (Seqno && skip < Seqno) {	    fsf(2);	    skip++;	    continue;	}/*T if (Seqno ... */	skip++;	/*	* Numrecs equals 0 if no file arguments are specified.	* Thus the entire tape must be processed.	*/	if (! Numrecs || (fstat = Lookup(Name))) {		/* Is this a symbolic link ?		 */		if (!strcmp(Tftypes,"sym") && Ultrixvol) {			char	Inbuf[MAXBLKSIZE+1];			strcpy((char*)lnk_msg,SLINKTO);			linkflag = YES;			/* Read the link from input volume			 * and save it in  lnk_name for later.			 */			if ((nbytes = read(fileno(Magtfp), Inbuf, L_blklen)) <= 0) {				PERROR "\n%s: %s %s%c\n", Progname, CANTRD, Name, BELL);				if (nbytes < 0)		    		    ceot();				exit(FAIL);			}			i = getlen(Inbuf);			if (L_recformat == VARIABLE)			    strncpy(lnk_name,&Inbuf[4],i);			else {			    strncpy(lnk_name,&Inbuf[5],i);			    while (Inbuf[0] != '3') {				if ((nbytes = read(fileno(Magtfp), Inbuf, L_blklen)) <= 0) {				    PERROR "\n%s: %s %s%c\n", Progname, CANTRD, Name, BELL);				    if (nbytes < 0)		    			ceot();				    exit(FAIL);				}				j = getlen(Inbuf);				i += j;				strncat(lnk_name,&Inbuf[5],j);			    }/*E while (&Inbuf[0] != '3') */			}			lnk_name[i] = 0;			if (Func != TABLE) {				unlink(Name);				if (symlink(lnk_name,Name) < 0) {			    		PERROR "\n%s: %s -> %s\n    to -> %s%c\n",					Progname, CANTLF, Name,					lnk_name, BELL);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?