From: François Pinard Date: Wed, 16 Nov 1994 02:55:42 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=5aac7fa0e7b3ff355d23f8f27f6eee25452fd56a;p=chaz%2Ftar *** empty log message *** --- diff --git a/src/list.c b/src/list.c index 4820fde..9bd7c60 100644 --- a/src/list.c +++ b/src/list.c @@ -97,11 +97,10 @@ read_and(do_something) case 1: /* Valid header */ /* We should decode next field (mode) first... */ /* Ensure incoming names are null terminated. */ - head->header.name[NAMSIZ-1] = '\0'; - if ( !name_match(head->header.name) + if ( !name_match(current_file_name) || (f_new_files && hstat.st_mtimeheader.name))) { + || (f_exclude && check_exclude(current_file_name))) { int isextended = 0; @@ -113,7 +112,7 @@ read_and(do_something) } if (f_show_omitted_dirs && head->header.linkflag == LF_DIR) - msg ("Omitting %s\n", head->header.name); + msg ("Omitting %s\n", current_file_name); /* Skip past it in the archive */ if (head->header.isextended) isextended = 1; @@ -172,6 +171,7 @@ read_and(do_something) break; }; + restore_saved_dir_info (); close_archive(); names_notfound(); /* Print names not found */ } @@ -204,7 +204,7 @@ list_archive() userec(head); if(f_multivol) { - save_name = head->header.name; + save_name = current_file_name; save_totsize=hstat.st_size; } for(size = hstat.st_size;size>0;size-=written) { @@ -222,7 +222,7 @@ list_archive() check=fwrite(data,sizeof(char), written, msg_file); userec((union record *)(data+written - 1)); if(check!=written) { - msg_perror("only wrote %ld of %ld bytes to file %s",check, written,head->header.name); + msg_perror("only wrote %ld of %ld bytes to file %s",check, written,current_file_name); skip_file((long)(size)-written); break; } @@ -264,7 +264,7 @@ list_archive() } if(f_multivol) - save_name=head->header.name; + save_name=current_file_name; /* Skip to the next header on the archive */ skip_file((long) hstat.st_size); @@ -293,7 +293,13 @@ read_header() register char *p; register union record *header; long from_oct(); + char **longp; + char *bp, *data; + int size, written; + static char *next_long_name, *next_long_link; + recurse: + header = findrec(); head = header; /* This is our current header */ if (NULL == header) @@ -316,17 +322,6 @@ read_header() sum -= 0xFF & header->header.chksum[i]; sum += ' '* sizeof header->header.chksum; - if (sum == recsum) { - /* - * Good record. Decode file size and return. - */ - if (header->header.linkflag == LF_LINK) - hstat.st_size = 0; /* Links 0 size on tape */ - else - hstat.st_size = from_oct(1+12, header->header.size); - return 1; - } - if (sum == 8*' ') { /* * This is a zeroed record...whole record is 0's except @@ -335,7 +330,60 @@ read_header() return 2; } - return 0; + if (sum != recsum) + return 0; + + /* + * Good record. Decode file size and return. + */ + if (header->header.linkflag == LF_LINK) + hstat.st_size = 0; /* Links 0 size on tape */ + else + hstat.st_size = from_oct(1+12, header->header.size); + + head->header.arch_name[NAMSIZ-1] = '\0'; + if (header->header.linkflag == LF_LONGNAME + || header->header.linkflag == LF_LONGLINK) + { + longp = ((header->header.linkflag == LF_LONGNAME) + ? &next_long_name + : &next_long_link); + + if (*longp) + free (*longp); + bp = *longp = (char *) ck_malloc (hstat.st_size); + + for (size = hstat.st_size; + size > 0; + size -= written) + { + data = findrec ()->charptr; + if (data == NULL) + { + msg ("Unexpected EOF on archive file"); + break; + } + written = endofrecs () ->charptr - data; + if (written > size) + written = size; + + bcopy (data, bp, written); + bp += written; + userec ((union record *) (data + written - 1)); + } + goto recurse; + } + else + { + current_file_name = (next_long_name + ? next_long_name + : header->header.arch_name); + current_link_name = (next_long_link + ? next_long_link + : header->header.arch_linkname); + next_long_link = next_long_name = 0; + return 1; + } } @@ -362,8 +410,10 @@ decode_header(header, st, stdp, wantug) int *stdp; int wantug; { - long from_oct(); + char **longp; + char *bp, *data; + int size, written; st->st_mode = from_oct(8, header->header.mode); st->st_mtime = from_oct(1+12, header->header.mtime); @@ -372,9 +422,7 @@ decode_header(header, st, stdp, wantug) st->st_ctime = from_oct(1+12, header->header.ctime); } - /* Older versions of GNU tar wrote "ustar \0" instead of - "ustar\0""00" for the magic/version field. Recognize both. */ - if (0==strncmp(header->header.magic, TMAGIC, 5)) { + if (0==strcmp(header->header.magic, TMAGIC)) { /* Unix Standard tar archive */ *stdp = 1; if (wantug) { @@ -382,8 +430,14 @@ decode_header(header, st, stdp, wantug) st->st_uid = from_oct(8, header->header.uid); st->st_gid = from_oct(8, header->header.gid); #else - st->st_uid = finduid(header->header.uname); - st->st_gid = findgid(header->header.gname); + st->st_uid = + (*header->header.uname + ? finduid (header->header.uname) + : from_oct (8, header->header.uid)); + st->st_gid = + (*header->header.gname + ? findgid (header->header.gname) + : from_oct (8, header->header.gid)); #endif } #if defined(S_IFBLK) || defined(S_IFCHR) @@ -466,20 +520,23 @@ print_header() int pad; char *name; extern long baserec; + static char *longname; + static char *longlink; + int bumplongs; if(f_sayblock) fprintf(msg_file,"rec %10d: ",baserec + (ar_record - ar_block)); /* annofile(msg_file, (char *)NULL); */ - + if (f_verbose <= 1) { /* Just the fax, mam. */ char *name; - name=quote_copy_string(head->header.name); + name=quote_copy_string(current_file_name); if(name==0) - name=head->header.name; + name=current_file_name; fprintf(msg_file, "%s\n", name); - if(name!=head->header.name) + if(name!=current_file_name) free(name); } else { /* File type and modes */ @@ -497,12 +554,17 @@ print_header() modes[0]='N'; break; + case LF_LONGNAME: + case LF_LONGLINK: + msg ("Visible longname error\n"); + break; + case LF_SPARSE: case LF_NORMAL: case LF_OLDNORMAL: case LF_LINK: modes[0] = '-'; - if ('/' == head->header.name[strlen(head->header.name)-1]) + if ('/' == current_file_name[strlen(current_file_name)-1]) modes[0] = 'd'; break; case LF_DUMPDIR:modes[0] = 'd'; break; @@ -527,13 +589,15 @@ print_header() user = head->header.uname; } else { user = uform; - (void)sprintf(uform, "%d", (int)hstat.st_uid); + (void)sprintf(uform, "%d", + from_oct (8, head->header.uid)); } if (*head->header.gname && head_standard) { group = head->header.gname; } else { group = gform; - (void)sprintf(gform, "%d", (int)hstat.st_gid); + (void)sprintf(gform, "%d", + from_oct (8, head->header.gid)); } /* Format the file size or major/minor device numbers */ @@ -558,10 +622,10 @@ print_header() pad = strlen(user) + strlen(group) + strlen(size) + 1; if (pad > ugswidth) ugswidth = pad; - name = quote_copy_string(head->header.name); + name = quote_copy_string(current_file_name); if(!name) - name=head->header.name; - fprintf(msg_file, "%s %s/%s %*s%s %s %s %.*s", + name=current_file_name; + fprintf(msg_file, "%s %s/%s %*s%s %s %s %s", modes, user, group, @@ -569,27 +633,26 @@ print_header() "", size, timestamp+4, timestamp+20, - sizeof(head->header.name), name); - if(name!=head->header.name) + if(name!=current_file_name) free(name); switch (head->header.linkflag) { case LF_SYMLINK: - name=quote_copy_string(head->header.linkname); + name=quote_copy_string(current_link_name); if(!name) - name=head->header.linkname; + name=current_link_name; fprintf(msg_file, " -> %s\n", name); - if(name!=head->header.linkname) + if(name!=current_link_name) free(name); break; case LF_LINK: - name=quote_copy_string(head->header.linkname); + name=quote_copy_string(current_link_name); if(!name) - name=head->header.linkname; - fprintf(msg_file, " link to %s\n", head->header.linkname); - if(name!=head->header.linkname) + name=current_link_name; + fprintf(msg_file, " link to %s\n", current_link_name); + if(name!=current_link_name) free(name); break; diff --git a/src/rtapelib.c b/src/rtapelib.c index c8a41b8..eece76f 100644 --- a/src/rtapelib.c +++ b/src/rtapelib.c @@ -24,7 +24,7 @@ and to separate the various arguments with \n instead of a space. I personally don't think that this is much of a problem, but I wanted to point it out. -- Arnold Robbins - + Originally written by Jeff Lee, modified some by Arnold Robbins. Redone as a library that can replace open, read, write, etc., by Fred Fish, with some additional work by Arnold Robbins. @@ -52,6 +52,14 @@ extern int errno; #endif +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef STDC_HEADERS +#include +#include +#endif + /* Maximum size of a fully qualified host name. */ #define MAXHOSTLEN 257 @@ -74,17 +82,19 @@ extern int errno; #define WRITE(fildes) (to_rmt[fildes][1]) /* The pipes for receiving data from remote tape drives. */ -static int from_rmt[MAXUNIT][2] = {-1, -1, -1, -1, -1, -1, -1, -1}; +static int from_rmt[MAXUNIT][2] = +{-1, -1, -1, -1, -1, -1, -1, -1}; /* The pipes for sending data to remote tape drives. */ -static int to_rmt[MAXUNIT][2] = {-1, -1, -1, -1, -1, -1, -1, -1}; +static int to_rmt[MAXUNIT][2] = +{-1, -1, -1, -1, -1, -1, -1, -1}; /* Temporary variable used by macros in rmt.h. */ char *__rmt_path; /* Close remote tape connection FILDES. */ -static void +static void _rmt_shutdown (fildes) int fildes; { @@ -98,7 +108,7 @@ _rmt_shutdown (fildes) on remote tape connection FILDES. Return 0 if successful, -1 on error. */ -static int +static int command (fildes, buf) int fildes; char *buf; @@ -127,7 +137,7 @@ command (fildes, buf) /* Read and return the status from remote tape connection FILDES. If an error occurred, return -1 and set errno. */ -static int +static int status (fildes) int fildes; { @@ -240,6 +250,7 @@ _rmt_rexec (host, user) return tape_fd; } + #endif /* HAVE_NETDB_H */ /* Open a magtape device on the system specified in PATH, as the given user. @@ -252,7 +263,7 @@ _rmt_rexec (host, user) If successful, return the remote tape pipe number plus BIAS. On error, return -1. */ -int +int __rmt_open (path, oflag, mode, bias) char *path; int oflag; @@ -263,7 +274,7 @@ __rmt_open (path, oflag, mode, bias) char buffer[CMDBUFSIZE]; /* Command buffer. */ char system[MAXHOSTLEN]; /* The remote host name. */ char device[CMDBUFSIZE]; /* The remote device name. */ - char login[CMDBUFSIZE]; /* The remote user name. */ + char login[CMDBUFSIZE]; /* The remote user name. */ char *sys, *dev, *user; /* For copying into the above buffers. */ sys = system; @@ -409,7 +420,7 @@ __rmt_open (path, oflag, mode, bias) /* Close remote tape connection FILDES and shut down. Return 0 if successful, -1 on error. */ -int +int __rmt_close (fildes) int fildes; { @@ -426,7 +437,7 @@ __rmt_close (fildes) /* Read up to NBYTE bytes into BUF from remote tape connection FILDES. Return the number of bytes read on success, -1 on error. */ -int +int __rmt_read (fildes, buf, nbyte) int fildes; char *buf; @@ -441,7 +452,7 @@ __rmt_read (fildes, buf, nbyte) for (i = 0; i < rc; i += nbyte, buf += nbyte) { - nbyte = read (READ (fildes), buf, rc); + nbyte = read (READ (fildes), buf, rc - i); if (nbyte <= 0) { _rmt_shutdown (fildes); @@ -456,7 +467,7 @@ __rmt_read (fildes, buf, nbyte) /* Write NBYTE bytes from BUF to remote tape connection FILDES. Return the number of bytes written on success, -1 on error. */ -int +int __rmt_write (fildes, buf, nbyte) int fildes; char *buf; @@ -486,7 +497,7 @@ __rmt_write (fildes, buf, nbyte) /* Perform an imitation lseek operation on remote tape connection FILDES. Return the new file offset if successful, -1 if on error. */ -long +long __rmt_lseek (fildes, offset, whence) int fildes; long offset; @@ -505,6 +516,7 @@ __rmt_lseek (fildes, offset, whence) Return the results of the ioctl, or -1 on error. */ #ifdef MTIOCTOP +int __rmt_ioctl (fildes, op, arg) int fildes, op; char *arg; @@ -566,4 +578,5 @@ __rmt_ioctl (fildes, op, arg) return 0; } } + #endif