示例#1
0
/* Open an archive file.  The argument specifies whether we are
   reading or writing, or both.  */
static void _open_archive(shfs_arch_t *arch, int wanted_access)
{

  if (arch->record_size == 0)
return;

  if (archive_names == 0)
return;

  tar_stat_destroy (&current_stat_info);

  arch->arch_record_index = 0;
  shfs_arch_init_buffer(arch);

  /* When updating the archive, we start with reading.  */
  arch->access_mode = wanted_access == ACCESS_UPDATE ? ACCESS_READ : wanted_access;
  check_tty (arch->access_mode);

  read_full_records = read_full_records_option;

  arch->records_read = 0;

  switch (wanted_access)
  {
    case ACCESS_READ:
      open_compressed_archive(arch);
      break;

    case ACCESS_WRITE:
      break;

    case ACCESS_UPDATE:
      break;
  }

  switch (wanted_access)
  {
    case ACCESS_READ:
      shfs_arch_buffer_next(arch);       /* read it in, check for EOF */
      break;

    case ACCESS_UPDATE:
    case ACCESS_WRITE:
      arch->records_written = 0;
      break;
  }
}
示例#2
0
/** Close the archive file.  */
void shfs_arch_close_archive(shfs_arch_t *arch)
{
  if (arch->time_to_start_writing || arch->access_mode == ACCESS_WRITE)
    {
      shfs_flush_archive(arch);
      if (current_block > record_start)
        shfs_flush_archive(arch);
    }

  _compute_duration(arch);

  tar_stat_destroy (&current_stat_info);
#if 0
  free (record_buffer[0]);
  free (record_buffer[1]);
#endif
  bufmap_free (NULL);
}
示例#3
0
文件: DumpTar.c 项目: geoffmcl/dump4
int  IsTARFile( LPDFSTR lpdf, LPTSTR lpf, PBYTE pb, DWORD dwmax )
{
   int  bRet = 0;
   LPTSTR   lpb = &gcOutBuf[0];  // [16K]
   PTAR  pt = (PTAR)pb;
   PUSTAR put = (PUSTAR)pb;
   char * pv = (char *)lpdf->df_pVoid;
   size_t off, count, boff, fsz, remains, len, culen;
   struct posix_header * pph = (struct posix_header *)lpdf->df_pVoid;
   int i;

   iMaxNameLen = 0;
   iMaxFileSize = 0;
   iMinFileSize = 0x7fffffff;
   iFileCount = 0;
   iDirCount = 0;
   if(!pv || !pb)
      return bRet;

   tar_stat_destroy(&current_stat_info);
   current_header = (union block *)pph;
   rdhdr = tar_checksum ((union block *)pph, TRUE);
   current_format = -1;
   decode_header_format ((union block *)pph, &current_stat_info, &current_format, 0);
   if( VERB5 )
   {
      sprtf( "%s: Format appears to be [%s] (%d)..."MEOR,
         get_header_stg( rdhdr ),
         get_format_stg(current_format),
         current_format );
   }

   switch(current_format)
   {
   case V7_FORMAT:
      break;
   case OLDGNU_FORMAT:
      poldgnu_header = (struct oldgnu_header *)pph;
      break;
   case USTAR_FORMAT:
      break;
   case POSIX_FORMAT:
      pheader = (struct posix_header * )pph;
      break;
   case STAR_FORMAT:
      pstar_header = (struct star_header *)pph; 
      break;
   case GNU_FORMAT:
      break;
   default:
      break;
   }

   if(( _strnicmp(put->ustar, "ustar", 5) == 0  )||
      ( rdhdr == HEADER_SUCCESS ) ) {
      off = 1;
      count = 0;
      while(off)
      {
         boff = count * BLOCKSIZE;
         pph = (struct posix_header *) &pv[boff];
         if( (boff + BLOCKSIZE) > lpdf->dwmax )
         {
            sprtf( "ERROR: Offset %d GREATER THAN max %d ..."MEOR,
               (boff + BLOCKSIZE), lpdf->dwmax );
            return 0;
         }
         off = 0;
         fsz = 0;
         i = collect_octal_size( lpb, pph, &fsz, 0 );
         if( i == 1 )
         {
            if(( pph->typeflag == REGTYPE ) || ( pph->typeflag == AREGTYPE ))
            {
               if(fsz > iMaxFileSize)
                  iMaxFileSize = fsz;
               if(fsz < iMinFileSize)
                  iMinFileSize = fsz;
            }
         }
         off = collect_prefix_name( lpb, pph );
         if( off ) {
            if( off > iMaxNameLen )
               iMaxNameLen = off;
            //sprtf( "Entry [%s] is %s ... size %d"MEOR, lpb,
            //   get_type_string(pph->typeflag),
            //   fsz );
            switch(pph->typeflag)
            {
            case REGTYPE:
            case AREGTYPE:
               iFileCount++;
               remains = fsz;
               while(remains)
               {
                  count++;
                  boff = count * BLOCKSIZE;
                  if( (boff + BLOCKSIZE) > lpdf->dwmax )
                  {
                     sprtf( "ERROR: Offset %d GREATER THAN max %d ..."MEOR,
                        (boff + BLOCKSIZE), lpdf->dwmax );
                     return 0;
                  }
                  if(remains > BLOCKSIZE)
                     len = BLOCKSIZE;
                  else
                     len = remains;
                  culen = 0;
                  pph = (struct posix_header *) &pv[boff];
                  if(remains > BLOCKSIZE)
                     remains -= BLOCKSIZE;
                  else
                     remains = 0;
               }
               break;
            case DIRTYPE:  // , "directory" },     //  '5'		/* directory */
               iDirCount++;            
               break;
            case LNKTYPE:  // , "link" },
            case SYMTYPE:  //, "reserved" },
            case CHRTYPE:  // , "character special" },
            case BLKTYPE:  //, "block special" }, //  '4'		/* block special */
            case FIFOTYPE: //, "FIFO special" }, // '6'		/* FIFO special */
            case CONTTYPE: //, "reserved" },     // '7'		/* reserved */
               break;
            case XHDTYPE:  //, "extended header" }, //  'x'   /* Extended header referring to the next file in the archive */
               // should bump to NEXT, but this is only a CHECK of TAR, not decode yet

               break;
            case XGLTYPE:  //, "global header" }, //  'g'            /* Global extended header */
               break;
            default:
               //sprtf("WARNING: Uncased type %c!!!"MEOR, pph->typeflag);
               break;
            }
         } else {
            break;
         }
         count++;
      }
      count++;
      boff = count * BLOCKSIZE;
      if( (boff + BLOCKSIZE) > lpdf->dwmax )
      {
         sprtf( "ERROR: Offset %d GREATER THAN max %d ..."MEOR,
            (boff + BLOCKSIZE), lpdf->dwmax );
         return 0;
      }
      if(VERB5) {
         remains = (lpdf->dwmax - (boff + BLOCKSIZE));
         strcpy(lpb, (remains == 0 ? "perfect" : "remainder " ));
         if(remains) sprintf(EndBuf(lpb)," %d", remains );
         sprtf( "Tested to offset %d of %d ... %s"MEOR,
            (boff + BLOCKSIZE), lpdf->dwmax, lpb );
         if( remains && VERB9 )
         {
            while(remains)
            {
               boff = count * BLOCKSIZE;
               if(remains > BLOCKSIZE)
                  len = BLOCKSIZE;
               else
                  len = remains;
               culen = 0;
               pph = (struct posix_header *) &pv[boff];
               if(remains > BLOCKSIZE)
                  remains -= BLOCKSIZE;
               else
                  remains = 0;
               count++;
            }
         }
      }
      return 2;
   } else {
      // NOT ustar 
      // what to do ...
   }

   return bRet;
}
示例#4
0
文件: DumpTar.c 项目: geoffmcl/dump4
BOOL  DumpTAR_FAILED( LPDFSTR lpdf )
{
   BOOL  bRet = FALSE;
   LPTSTR   lpb = &gcOutBuf[0];  // [16K]
   LPTSTR   lpb2 = &gcOutBuf2[0];  // [16K]
   char * pv = (char *)lpdf->df_pVoid;
   struct posix_header * pph = (struct posix_header *)lpdf->df_pVoid;
   char * cp;
   size_t   off, boff, count, fsz, remains, len, hlen, culen;
   int   i;
   char c;
   size_t maxcnt = iFileCount + iDirCount;
   size_t entry = 0;
   enum read_header h;
   struct tar_stat_info * info = &current_stat_info;
   DWORD dwm = lpdf->dwmax;
   union block * p;
   if( !pph )
      return bRet;

   iMaxFileSize = 0;
   iMinFileSize = 0x7fffffff;
   current_block = (union block *)pv;
   dwm = lpdf->dwmax;
   p = current_block;
   while(dwm)
   {
      record_end = p;
      p++;
      if(dwm >= BLOCKSIZE)
      {
         dwm -= BLOCKSIZE;
         if(dwm == 0)
            record_end = p;
      }
      else
         dwm = 0;
   }

   if(( _strnicmp(pph->magic, TMAGIC, 5) == 0 )||
      ( rdhdr == HEADER_SUCCESS ) ){
      // we have a USTAR format
      off = 1;
      count = 0;
      sprtf( "TAR [%s] is [%s] format ..."MEOR,
         lpdf->fn,
         get_format_stg(current_format) );
      while(off)
      {
         entry++;
         boff = count * BLOCKSIZE;
         pph = (struct posix_header *) &pv[boff];
         if( (boff + BLOCKSIZE) > lpdf->dwmax )
         {
            sprtf( "WARNING: DATA EXPIRED BEFORE ZERO BLOCK!"MEOR );
            break;
         }
         tar_stat_destroy(info);
         current_header = (union block *)pph;
         h = tar_checksum ((union block *)pph, TRUE);
         form = -1;
         decode_header ((union block *)pph, info, &form, 0);
         //      if (header->header.typeflag == LNKTYPE)
         if( pph->typeflag == LNKTYPE )
            info->stat.st_size = 0;	/* links 0 size on tape */
         else
            info->stat.st_size = OFF_FROM_HEADER (pph->size);
         fsz = (size_t)info->stat.st_size;
         if( VERB5 )
         {
            cp = (char *)pph;
            sprtf( "%s: form [%s](%d): type [%s]: size %9d; offset %#08X; time %s"MEOR,
               get_header_stg( h ),
               get_format_stg(form),
               form,
               get_type_string( pph->typeflag),
               info->stat.st_size,
               (cp - pv),
               tartime( info->mtime, 0 ));
         }
         // else if (header->header.typeflag == XHDTYPE
		   // || header->header.typeflag == SOLARIS_XHDTYPE)
         if(( h == HEADER_SUCCESS )&&
            (( pph->typeflag == XHDTYPE )||
             ( pph->typeflag == SOLARIS_XHDTYPE )))
         {
            // we need to READ the xheader ...
            struct posix_header * pph_save = pph;
            fsz = (size_t)info->stat.st_size;
            len = 1;
            xheader_read (&info->xhdr, (union block *)pph, (size_t)fsz);
            if( VERB9 )
               sprtf( "Skipping %d extended header blocks ...\n", len );
            boff = ((count + len) * BLOCKSIZE);
            pph = (struct posix_header *)&pv[boff];
            if( (boff + BLOCKSIZE) > lpdf->dwmax )
            {
               sprtf( "WARNING: DATA EXPIRED BEFORE ZERO BLOCK!"MEOR );
               pph = pph_save;
               break;
            }
            tar_stat_destroy(info);
            pph = (struct posix_header *)current_block; // move up to this block
            current_header = (union block *)pph;
            h = tar_checksum ((union block *)pph, TRUE);
            form = -1;
            decode_header ((union block *)pph, info, &form, 0);
            if( pph->typeflag == LNKTYPE )
               info->stat.st_size = 0;	/* links 0 size on tape */
            else
               info->stat.st_size = OFF_FROM_HEADER (pph->size);
            fsz = (size_t)info->stat.st_size;
            if( h == HEADER_SUCCESS ) {
               XHDTYPE_count++;
               if( VERB5 )
               {
                  cp = (char *)pph;
                  sprtf( "%s: form [%s](%d): type [%s]: size %9d; offset %#08X; time %s"MEOR,
                     get_header_stg( h ),
                     get_format_stg(form),
                     form,
                     get_type_string( pph->typeflag),
                     info->stat.st_size,
                     (cp - pv),
                     tartime( info->mtime, 0 ));
               }
               count += len;
            } else {
               pph = pph_save;
               tar_stat_destroy(info);
               current_header = (union block *)pph;
               h = tar_checksum ((union block *)pph, TRUE);
               form = -1;
               decode_header ((union block *)pph, info, &form, 0);
            }
         }

         fsz = 0;
         i = collect_octal_size( lpb, pph, &fsz, 1 );
         off = collect_prefix_name( lpb, pph );
         if( off ) {
            // we GOT a NAME
            sprtf( "%5d %-50s %s %10d %s"MEOR,
               entry,
               lpb,
               get_type_string(pph->typeflag),
               fsz,
               tartime( info->mtime, 0 ));
            // gather counts
            switch(pph->typeflag)
            {
            case REGTYPE:
            case AREGTYPE:
               REGTYPE_count++;
               if( fsz > iMaxFileSize )
                  iMaxFileSize = fsz;
               if( fsz < iMinFileSize )
                  iMinFileSize = fsz;
               remains = fsz;
               while(remains)
               {
                  count++;
                  boff = count * BLOCKSIZE;
                  if(remains > BLOCKSIZE)
                     len = BLOCKSIZE;
                  else
                     len = remains;
                  culen = 0;
                  if( VERB9 && bExtraDebug )
                  {
                     while( len )
                     {
                        if(len > 16)
                           hlen = 16;
                        else
                           hlen = len;
                        *lpb = 0;
                        GetHEXString( lpb, &pv[boff+culen], hlen, pv, FALSE );
                        sprtf( "%s"MEOR, lpb );
                        len -= hlen;
                        culen += hlen;
                     }
                  }
                  pph = (struct posix_header *) &pv[boff];
                  if(remains > BLOCKSIZE)
                     remains -= BLOCKSIZE;
                  else
                     remains = 0;
               }
               break;
            case LNKTYPE:  // , "link" },
               LNKTYPE_count++;
               break;
            case SYMTYPE:  //, "reserved" },
               SYMTYPE_count++;
               break;
            case CHRTYPE:  // , "character special" },
               CHRTYPE_count++;
               break;
            case BLKTYPE:  //, "block special" }, //  '4'		/* block special */
               BLKTYPE_count++;
               break;
            case DIRTYPE:  // , "directory" },     //  '5'		/* directory */
               DIRTYPE_count++;
               break;
            case FIFOTYPE: //, "FIFO special" }, // '6'		/* FIFO special */
               FIFOTYPE_count++;
               break;
            case CONTTYPE: //, "reserved" },     // '7'		/* reserved */
               CONTTYPE_count++;
               break;
            case XHDTYPE:  //, "extended header" }, //  'x'   /* Extended header referring to the next file in the archive */
               XHDTYPE_count++;
               break;
            case XGLTYPE:  //, "global header" }, //  'g'            /* Global extended header */
               XGLTYPE_count++;
               break;
            default:
               default_count++;
               sprtf("WARNING: Uncased type %c!!!"MEOR, pph->typeflag);
               break;
            }
         }
         count++;
      }  // while ...

      if( max_warn_count < warn_count )
      {
         sprtf( "WARNING: Plus another [%d] OUT OF OCTAL RANGE!!!"MEOR,
            warn_count - max_warn_count );
      }

      // fell out because of a BLANK block
      sprtf( "Processed %d entries", maxcnt );
      if( REGTYPE_count ) {
         // case AREGTYPE: counted with above
         sprtf( ", %d file%s (min %d, max %d)",
            REGTYPE_count,
            ((REGTYPE_count == 1) ? "" : "s"),
            iMinFileSize,
            iMaxFileSize );
      }
      if( LNKTYPE_count )
         sprtf( ", %d link%s", LNKTYPE_count, ((LNKTYPE_count == 1) ? "" : "s") );
      if( SYMTYPE_count )
         sprtf( ", %d sym%s", SYMTYPE_count, ((SYMTYPE_count == 1) ? "" : "s") );
      if( CHRTYPE_count )
         sprtf( ", %d char%s", CHRTYPE_count, ((CHRTYPE_count == 1) ? "" : "s") );
      if( BLKTYPE_count )
         sprtf( ", %d block%s", BLKTYPE_count, ((BLKTYPE_count == 1) ? "" : "s") );
      if( DIRTYPE_count )
         sprtf( ", %d dir%s", DIRTYPE_count, ((DIRTYPE_count == 1) ? "" : "s") );
      if( FIFOTYPE_count )
         sprtf( ", %d fifo%s", FIFOTYPE_count, ((FIFOTYPE_count == 1) ? "" : "s") );
      if( CONTTYPE_count )
         sprtf( ", %d cont%s", CONTTYPE_count, ((CONTTYPE_count == 1) ? "" : "s") );
      if( XHDTYPE_count )
         sprtf( ", %d xhdr%s", XHDTYPE_count, ((XHDTYPE_count == 1) ? "" : "s") );
      if( XGLTYPE_count )
         sprtf( ", %d xgl%s", XGLTYPE_count, ((XGLTYPE_count == 1) ? "" : "s") );
      if( default_count )
         sprtf( ", %d default%s", default_count, ((default_count == 1) ? "" : "s") );
      sprtf( " (blocks %d)"MEOR,
         count );

      count++;
      boff = count * BLOCKSIZE;
      remains = (lpdf->dwmax - (boff + BLOCKSIZE));
      strcpy(lpb, (remains == 0 ? "perfect" : "remainder " ));
      if(remains) sprintf(EndBuf(lpb)," %d", remains );
      if(remains > 0)
      {
         off = 0;
         boff = count * BLOCKSIZE;
         if( VERB )
            sprtf( "Reached offset %d of %d ... %s"MEOR,
            (boff + BLOCKSIZE), lpdf->dwmax, lpb );
         while(remains > 0)
         {
            if(remains > BLOCKSIZE)
               len = BLOCKSIZE;
            else
               len = remains;
            culen = 0;
            remains -= len;
            while( len )
            {
               if(len > 16)
                  hlen = 16;
               else
                  hlen = len;
               for( i = 0; i < (int)hlen; i++ )
               {
                  c = pv[boff+culen+i];
                  if(c)
                     break;
               }
               if(c) {
                  if(VERB5)
                  {
                     *lpb = 0;
                     GetHEXString( lpb, &pv[boff+culen], hlen, pv, FALSE );
                     sprtf( "%s"MEOR, lpb );
                  }
                  off++;
               }
               len -= hlen;
               culen += hlen;
            }
            count++;
         }
         // done the remainder
         if( off == 0 ) {
            // NO HEX OUTPUT
            sprtf( "But it was ALL zeros ... (to %d)"MEOR, ((count+1) * BLOCKSIZE) );
         }
      }
      bRet = TRUE;
   }

   return bRet;
}
示例#5
0
/* Implement the 'r' (add files to end of archive), and 'u' (add files
   to end of archive if they aren't there, or are more up to date than
   the version in the archive) commands.  */
void
update_archive (void)
{
  enum read_header previous_status = HEADER_STILL_UNREAD;
  bool found_end = false;

  name_gather ();
  open_archive (ACCESS_UPDATE);
  xheader_write_global ();

  while (!found_end)
    {
      enum read_header status = read_header (false);

      switch (status)
	{
	case HEADER_STILL_UNREAD:
	case HEADER_SUCCESS_EXTENDED:
	  abort ();

	case HEADER_SUCCESS:
	  {
	    struct name *name;

	    decode_header (current_header, &current_stat_info,
			   &current_format, 0);
	    archive_format = current_format;
	    
	    if (subcommand_option == UPDATE_SUBCOMMAND
		&& (name = name_scan (current_stat_info.file_name)) != NULL)
	      {
		struct stat s;

		chdir_do (name->change_dir);
		if (deref_stat (dereference_option,
				current_stat_info.file_name, &s) == 0
		    && s.st_mtime <= current_stat_info.stat.st_mtime)
		  add_avoided_name (current_stat_info.file_name);
	      }

	    skip_member ();
	    break;
	  }

	case HEADER_ZERO_BLOCK:
	  current_block = current_header;
	  found_end = true;
	  break;

	case HEADER_END_OF_FILE:
	  found_end = true;
	  break;

	case HEADER_FAILURE:
	  set_next_block_after (current_header);
	  switch (previous_status)
	    {
	    case HEADER_STILL_UNREAD:
	      WARN ((0, 0, _("This does not look like a tar archive")));
	      /* Fall through.  */

	    case HEADER_SUCCESS:
	    case HEADER_ZERO_BLOCK:
	      ERROR ((0, 0, _("Skipping to next header")));
	      /* Fall through.  */

	    case HEADER_FAILURE:
	      break;

	    case HEADER_END_OF_FILE:
	    case HEADER_SUCCESS_EXTENDED:
	      abort ();
	    }
	  break;
	}

      tar_stat_destroy (&current_stat_info);
      xheader_destroy (&extended_header);
      previous_status = status;
    }

  reset_eof ();
  time_to_start_writing = true;
  output_start = current_block->buffer;

  {
    char *file_name;

    while ((file_name = name_from_list ()) != NULL)
      {
	if (excluded_name (file_name))
	  continue;
	if (interactive_option && !confirm ("add", file_name))
	  continue;
	if (subcommand_option == CAT_SUBCOMMAND)
	  append_file (file_name);
	else
	  dump_file (file_name, 1, (dev_t) 0);
      }
  }

  write_eot ();
  close_archive ();
  names_notfound ();
}
示例#6
0
文件: incremen.c 项目: Distrotech/tar
/* Recursively scan the directory identified by ST.  */
struct directory *
scan_directory (struct tar_stat_info *st)
{
  char const *dir = st->orig_file_name;
  char *dirp = get_directory_entries (st);
  dev_t device = st->stat.st_dev;
  bool cmdline = ! st->parent;
  namebuf_t nbuf;
  char *tmp;
  struct directory *directory;
  char ch;

  if (! dirp)
    savedir_error (dir);

  info_attach_exclist (st);

  tmp = xstrdup (dir);
  zap_slashes (tmp);

  directory = procdir (tmp, st,
		       (cmdline ? PD_FORCE_INIT : 0),
		       &ch);

  free (tmp);

  nbuf = namebuf_create (dir);

  if (dirp)
    {
      if (directory->children != NO_CHILDREN)
	{
	  char *entry;	/* directory entry being scanned */
	  struct dumpdir_iter *itr;

	  makedumpdir (directory, dirp);

	  for (entry = dumpdir_first (directory->dump, 1, &itr);
	       entry;
	       entry = dumpdir_next (itr))
	    {
	      char *full_name = namebuf_name (nbuf, entry + 1);

	      if (*entry == 'I') /* Ignored entry */
		*entry = 'N';
	      else if (excluded_name (full_name, st))
		*entry = 'N';
	      else
		{
		  int fd = st->fd;
		  void (*diag) (char const *) = 0;
		  struct tar_stat_info stsub;
		  tar_stat_init (&stsub);

		  if (fd < 0)
		    {
		      errno = - fd;
		      diag = open_diag;
		    }
		  else if (fstatat (fd, entry + 1, &stsub.stat,
				    fstatat_flags) != 0)
		    diag = stat_diag;
		  else if (S_ISDIR (stsub.stat.st_mode))
		    {
		      int subfd = subfile_open (st, entry + 1,
						open_read_flags);
		      if (subfd < 0)
			diag = open_diag;
		      else
			{
			  stsub.fd = subfd;
			  if (fstat (subfd, &stsub.stat) != 0)
			    diag = stat_diag;
			}
		    }

		  if (diag)
		    {
		      file_removed_diag (full_name, false, diag);
		      *entry = 'N';
		    }
		  else if (S_ISDIR (stsub.stat.st_mode))
		    {
		      int pd_flag = 0;
		      if (!recursion_option)
			pd_flag |= PD_FORCE_CHILDREN | NO_CHILDREN;
		      else if (directory->children == ALL_CHILDREN)
			pd_flag |= PD_FORCE_CHILDREN | ALL_CHILDREN;
		      *entry = 'D';

		      stsub.parent = st;
		      procdir (full_name, &stsub, pd_flag, entry);
		      restore_parent_fd (&stsub);
		    }
		  else if (one_file_system_option &&
			   device != stsub.stat.st_dev)
		    *entry = 'N';
		  else if (*entry == 'Y')
		    /* New entry, skip further checks */;
		  /* FIXME: if (S_ISHIDDEN (stat_data.st_mode))?? */
		  else if (OLDER_STAT_TIME (stsub.stat, m)
			   && (!after_date_option
			       || OLDER_STAT_TIME (stsub.stat, c)))
		    *entry = 'N';
		  else
		    *entry = 'Y';

		  tar_stat_destroy (&stsub);
		}
	    }
	  free (itr);
	}
      else if (directory->tagfile)
	maketagdumpdir (directory);
    }

  namebuf_free (nbuf);

  free (dirp);

  return directory;
}
示例#7
0
int shfs_arch_write_flush(shfs_arch_t *arch, size_t buffer_level)
{
  ssize_t status;
  union block *header;
  char *copy_ptr;
  size_t copy_size;
  size_t bufsize;
  struct bufmap *map;

  status = shfs_arch_buffer_write(arch->archive, record_start->buffer, arch->record_size);
  if (status != arch->record_size && !multi_volume_option)
{}
  else
    {
      if (status)
        arch->records_written++;
      bytes_written += status;
    }

  if (status == arch->record_size)
    {
      return;
    }

  map = bufmap_locate (status);



  tar_stat_destroy (&dummy);

  //increase_volume_number ();
  prev_written += bytes_written;
  bytes_written = 0;

  copy_ptr = record_start->buffer + status;
  copy_size = buffer_level - status;

  /* Switch to the next buffer */
  arch->arch_record_index = !arch->arch_record_index;
  shfs_arch_init_buffer(arch);

  inhibit_map = 1;

  tar_stat_destroy (&dummy);

  header = shfs_arch_buffer_next(arch);
  bufmap_reset (map, header - record_start);
  bufsize = available_space_after (header);
  inhibit_map = 0;
  while (bufsize < copy_size)
    {
      memcpy (header->buffer, copy_ptr, bufsize);
      copy_ptr += bufsize;
      copy_size -= bufsize;
      shfs_arch_set_next_block_after(arch, header + (bufsize - 1) / BLOCKSIZE);
      header = shfs_arch_buffer_next(arch);
      bufsize = available_space_after (header);
    }
  memcpy (header->buffer, copy_ptr, copy_size);
  memset (header->buffer + copy_size, 0, bufsize - copy_size);
  shfs_arch_set_next_block_after(arch, header + (copy_size - 1) / BLOCKSIZE);
  shfs_arch_buffer_next(arch);

  return (0);
}