[7644] in Athena Bugs

home help back first fref pref prev next nref lref last post

patches to tar.c to make Holey files

daemon@ATHENA.MIT.EDU (John T Kohl)
Tue Jun 11 12:16:28 1991

Date: Tue, 11 Jun 91 12:16:06 EDT
From: John T Kohl <jtkohl@MIT.EDU>
To: bugs@MIT.EDU

I found this lying around my homedir.

These patches, when applied to /source/athena/bin/tar.c, will allow tar
to create files with block-aligned zero-filled holes.  The advantage of
this is if you're tarring up large files with lots of null blocks, you
can save space on the output device (only recommended for files!).

John
*** /source/athena/bin/tar.c	Tue Oct 31 00:44:56 1989
--- tar.c	Wed Feb 28 15:07:56 1990
***************
*** 25,30 ****
--- 25,31 ----
  #include <sys/ioctl.h>
  #include <sys/mtio.h>
  #include <sys/time.h>
+ #include <sys/file.h>
  #include <signal.h>
  #include <errno.h>
  #include <fcntl.h>
***************
*** 77,82 ****
--- 78,84 ----
  int	pflag;
  int	wflag;
  int	hflag;
+ int	Hflag;
  int	Bflag;
  int	Fflag;
  
***************
*** 207,212 ****
--- 209,218 ----
  			mflag++;
  			break;
  
+ 		case 'H':
+ 			Hflag++;
+ 			break;
+ 
  		case '-':
  			break;
  
***************
*** 669,674 ****
--- 675,691 ----
  	}
  }
  
+ /* return non-zero if the buffer is all zeroes */
+ 
+ int
+ allzeros(buf, size)
+ char *buf;
+ register int size;
+ {
+     while (size && !buf[--size]) ;
+     return(!size);
+ }
+ 
  doxtract(argv)
  	char *argv[];
  {
***************
*** 765,781 ****
  			register int nread;
  			char	*bufp;
  			register int nwant;
! 			
  			nwant = NBLOCK*TBLOCK;
  			if (nwant > (blocks*TBLOCK))
  				nwant = (blocks*TBLOCK);
  			nread = readtbuf(&bufp, nwant);
! 			if (write(ofile, bufp, (int)min(nread, bytes)) < 0) {
  				fprintf(stderr,
  				    "tar: %s: HELP - extract write error",
  				    dblock.dbuf.name);
  				perror("");
  				done(2);
  			}
  			bytes -= nread;
  			blocks -= (((nread-1)/TBLOCK)+1);
--- 782,813 ----
  			register int nread;
  			char	*bufp;
  			register int nwant;
! 
  			nwant = NBLOCK*TBLOCK;
  			if (nwant > (blocks*TBLOCK))
  				nwant = (blocks*TBLOCK);
  			nread = readtbuf(&bufp, nwant);
! 			if (Hflag && (blocks > (((nread-1)/TBLOCK)+1)) &&
! 			    allzeros(bufp, (int)min(nread, bytes))) {
! 			    /* if this isn't the last block,
! 			       then seek instead of writing zeroes */
! 			    if (lseek(ofile, (int)min(nread, bytes),
! 				      L_INCR) < 0) {
  				fprintf(stderr,
  				    "tar: %s: HELP - extract write error",
  				    dblock.dbuf.name);
  				perror("");
  				done(2);
+ 			    }
+ 			} else {
+ 			    if (write(ofile, bufp,
+ 				      (int)min(nread, bytes)) < 0) {
+ 				fprintf(stderr,
+ 					"tar: %s: HELP - extract write error",
+ 					dblock.dbuf.name);
+ 				perror("");
+ 				done(2);
+ 			    }
  			}
  			bytes -= nread;
  			blocks -= (((nread-1)/TBLOCK)+1);

home help back first fref pref prev next nref lref last post