[comp.os.minix] Tar runs out of memory

williams@umaxc.weeg.uiowa.edu (Kent Williams) (04/08/90)

Yes indeedy, tar runs out of memory if you try and tar too many files.
The reason is that it tries to be too smart, in a naive way.  It saves
the name, device and inode of every cotton-picking file it puts in an archive,
so that it doesn't store a linked file more than once.

A less naive way to go about it would be to store information only for files
that have links -- you'd only run out of memory after seeing 200 links, rather
than 200 files.

I haven't done that -- I added a S flag, for stupid.  If you do a

		tar cvSf tarfile file_list

tar will lose its memory, and put multiple copies of linked files into
the archive.  It will be dumber, but accept as many files as you can throw
at it.

-------------------------------Yo, Cut Here--------------------------------
*** tar.c.orig	Sat Apr  7 08:43:22 1990
--- tar.c	Sat Apr  7 08:50:00 1990
***************
*** 42,47 ****
--- 42,48 ----
   *  made lint complains less (On a BSD 4.3 system)		KS 3/10/89
   *  use of directory(3) routines				KS 3/10/89
   *  deleted use of d_namlen selector of struct dirent		KS 18/10/89
+  *  Added stupid flag so it wouldn't run out of memory          KW 07/04/90
   *
   * Bugs:
   *  verbose mode is not reporting consistent
***************
*** 152,157 ****
--- 153,159 ----
  char path[NAME_SIZE];
  char pathname[NAME_SIZE];
  int force_flag = 0;
+ int stupid_flag = 0; 	/* Don't track link information */
  #ifdef ORIGINAL_DEFAULTS
  int chown_flag = 1;
  int verbose_flag = 1;
***************
*** 206,211 ****
--- 208,216 ----
  		break;
  	    case 'f':		/* standard U*IX usage -KS */
  		break;
+ 	    case 'S':		/* STUPID -- don't track links -KW */
+ 		stupid_flag = TRUE;
+ 		break;
  	    default:	error(usage, NIL_PTR);
  	}
    }
***************
*** 739,745 ****
    struct link *new;
    char *malloc();
  
!   if (*file == 0) return;
    new = (struct link *) malloc(sizeof(struct link));
    if (new == NULL) {
  	print("Out of memory\n");
--- 744,750 ----
    struct link *new;
    char *malloc();
  
!   if (*file == 0 || stupid_flag) return;
    new = (struct link *) malloc(sizeof(struct link));
    if (new == NULL) {
  	print("Out of memory\n");
***************
*** 756,762 ****
  struct stat *st;
  {
    struct link *cur = link_top;
! 
    while (cur != NULL)
  	if ((cur->dev == st->st_dev) && (cur->ino == st->st_ino))
  		return cur->name;
--- 761,771 ----
  struct stat *st;
  {
    struct link *cur = link_top;
!   /*
!   ** If you don't care about links, then act like nothing is linked.
!   */	
!   if(stupid_flag)
! 	return NULL;	
    while (cur != NULL)
  	if ((cur->dev == st->st_dev) && (cur->ino == st->st_ino))
  		return cur->name;
----------------------------END OF PATCH-------------------------------
--
Kent Williams                    'Look, I can understand "teenage mutant ninja 
williams@umaxc.weeg.uiowa.edu    turtles", but I can't understand "mutually 
                                 recursive inline functions".' - Paul Chisholm