malloc does page alignments.
SCCS-vsn: old/tar/tar.c 4.22
static char *sccsid = "@(#)tar.c 4.22 (Berkeley) %G%";
#endif
static char *sccsid = "@(#)tar.c 4.22 (Berkeley) %G%";
#endif
-/*
- * T A R . C
- *
- * $Revision: 1.4 $
- *
- * $Log: tar.c,v $
- * Revision 1.4 84/11/14 00:08:15 root
- * New more efficient version. Minimizes the number of bcopys
- * and maximizes block buffering. Page aligns block buffers.
- *
- * Revision 1.3 84/02/23 20:24:42 dpk
- * Added missing close(infile) to prevent running out of fd's
- *
- * Revision 1.2 84/02/23 20:17:02 dpk
- * Added distinctive RCS header
- *
- */
-#ifndef lint
-static char RCSid[] = "@(#)$Header: tar.c,v 1.4 84/11/14 00:08:15 root Exp $";
-#endif
-
-
/*
* Tape Archival Program
*/
/*
* Tape Archival Program
*/
daddr_t high;
daddr_t bsrch();
daddr_t high;
daddr_t bsrch();
FILE *tfile;
char tname[] = "/tmp/tarXXXXXX";
char *usefile;
FILE *tfile;
char tname[] = "/tmp/tarXXXXXX";
char *usefile;
if (!rflag && !xflag && !tflag)
usage();
if (!rflag && !xflag && !tflag)
usage();
-#ifndef vax
- tbuf = (union hblock *)malloc(nblock*TBLOCK);
-#else
- /*
- * The following is for 4.2BSD and related systems to force
- * the buffer to be page aligned. The kernel will avoid
- * bcopy()'s on disk IO this way by manipulating the page tables.
- */
- {
- int pagesize = getpagesize();
-
- tbuf = (union hblock *)malloc((nblock*TBLOCK)+pagesize);
- tbuf = (union hblock *)(((int)tbuf+pagesize)&~(pagesize-1));
- }
-#endif vax
- if (tbuf == NULL) {
- fprintf(stderr, "tar: blocksize %d too big, can't get memory\n",
- nblock);
- done(1);
- }
if (rflag) {
if (cflag && tfile != NULL)
usage();
if (rflag) {
if (cflag && tfile != NULL)
usage();
"tar: can only create standard output archives\n");
done(1);
}
"tar: can only create standard output archives\n");
done(1);
}
+ vfile = stderr;
+ setlinebuf(vfile);
mt = dup(1);
nblock = 1;
} else if ((mt = open(usefile, 2)) < 0) {
mt = dup(1);
nblock = 1;
} else if ((mt = open(usefile, 2)) < 0) {
int infile = 0;
long blocks;
char buf[TBLOCK];
int infile = 0;
long blocks;
char buf[TBLOCK];
char *bigbuf;
register char *cp, *cp2;
struct direct *dp;
char *bigbuf;
register char *cp, *cp2;
struct direct *dp;
dblock.dbuf.linkname[i] = '\0';
dblock.dbuf.linkflag = '2';
if (vflag) {
dblock.dbuf.linkname[i] = '\0';
dblock.dbuf.linkflag = '2';
if (vflag) {
- fprintf(stderr, "a %s ", longname);
- fprintf(stderr, "symbolic link to %s\n",
+ fprintf(vfile, "a %s ", longname);
+ fprintf(vfile, "symbolic link to %s\n",
dblock.dbuf.linkname);
}
sprintf(dblock.dbuf.size, "%11lo", 0);
dblock.dbuf.linkname);
}
sprintf(dblock.dbuf.size, "%11lo", 0);
sprintf(dblock.dbuf.chksum, "%6o", checksum());
writetape( (char *) &dblock);
if (vflag) {
sprintf(dblock.dbuf.chksum, "%6o", checksum());
writetape( (char *) &dblock);
if (vflag) {
- fprintf(stderr, "a %s ", longname);
- fprintf(stderr, "link to %s\n",
+ fprintf(vfile, "a %s ", longname);
+ fprintf(vfile, "link to %s\n",
lp->pathname);
}
lp->count--;
lp->pathname);
}
lp->count--;
}
blocks = (stbuf.st_size + (TBLOCK-1)) / TBLOCK;
if (vflag) {
}
blocks = (stbuf.st_size + (TBLOCK-1)) / TBLOCK;
if (vflag) {
- fprintf(stderr, "a %s ", longname);
- fprintf(stderr, "%ld blocks\n", blocks);
+ fprintf(vfile, "a %s ", longname);
+ fprintf(vfile, "%ld blocks\n", blocks);
}
sprintf(dblock.dbuf.chksum, "%6o", checksum());
hint = writetape((char *)&dblock);
maxread = max(stbuf.st_blksize, (nblock * TBLOCK));
}
sprintf(dblock.dbuf.chksum, "%6o", checksum());
hint = writetape((char *)&dblock);
maxread = max(stbuf.st_blksize, (nblock * TBLOCK));
if ((bigbuf = malloc(maxread)) == 0) {
maxread = TBLOCK;
bigbuf = buf;
}
if ((bigbuf = malloc(maxread)) == 0) {
maxread = TBLOCK;
bigbuf = buf;
}
-#else
- /*
- * The following is for 4.2BSD and related systems to force
- * the buffer to be page aligned. The kernel will avoid
- * bcopy()'s on disk IO this way by manipulating the page tables.
- */
- {
- int pagesize = getpagesize();
-
- if ((origbuf = malloc(maxread+pagesize)) == 0) {
- maxread = TBLOCK;
- bigbuf = buf;
- } else {
- bigbuf = (char *)(((int)origbuf+pagesize)&~(pagesize-1));
- }
- }
-#endif vax
while ((i = read(infile, bigbuf, min((hint*TBLOCK), maxread))) > 0
&& blocks > 0) {
while ((i = read(infile, bigbuf, min((hint*TBLOCK), maxread))) > 0
&& blocks > 0) {
}
close(infile);
if (bigbuf != buf)
}
close(infile);
if (bigbuf != buf)
-#else
- free(origbuf);
-#endif
if (blocks != 0 || i != 0)
fprintf(stderr, "tar: %s: file changed size\n",
longname);
if (blocks != 0 || i != 0)
fprintf(stderr, "tar: %s: file changed size\n",
longname);
- fprintf(stderr, "x %s symbolic link to %s\n",
+ fprintf(vfile, "x %s symbolic link to %s\n",
dblock.dbuf.name, dblock.dbuf.linkname);
dblock.dbuf.name, dblock.dbuf.linkname);
-#ifdef notdef
- /* ignore alien orders */
- chown(dblock.dbuf.name, stbuf.st_uid, stbuf.st_gid);
- if (mflag == 0) {
- struct timeval tv[2];
-
- tv[0].tv_sec = time(0);
- tv[0].tv_usec = 0;
- tv[1].tv_sec = stbuf.st_mtime;
- tv[1].tv_usec = 0;
- utimes(dblock.dbuf.name, tv);
- }
- if (pflag)
- chmod(dblock.dbuf.name, stbuf.st_mode & 07777);
-#endif
continue;
}
if (dblock.dbuf.linkflag == '1') {
continue;
}
if (dblock.dbuf.linkflag == '1') {
- fprintf(stderr, "%s linked to %s\n",
+ fprintf(vfile, "%s linked to %s\n",
dblock.dbuf.name, dblock.dbuf.linkname);
continue;
}
dblock.dbuf.name, dblock.dbuf.linkname);
continue;
}
chown(dblock.dbuf.name, stbuf.st_uid, stbuf.st_gid);
blocks = ((bytes = stbuf.st_size) + TBLOCK-1)/TBLOCK;
if (vflag)
chown(dblock.dbuf.name, stbuf.st_uid, stbuf.st_gid);
blocks = ((bytes = stbuf.st_size) + TBLOCK-1)/TBLOCK;
if (vflag)
- fprintf(stderr, "x %s, %ld bytes, %ld tape blocks\n",
+ fprintf(vfile, "x %s, %ld bytes, %ld tape blocks\n",
dblock.dbuf.name, bytes, blocks);
for (; blocks > 0;) {
register int nread;
dblock.dbuf.name, bytes, blocks);
for (; blocks > 0;) {
register int nread;
- if ((mode & S_IFMT) == S_IFDIR)
- return (strcmp(name, "SCCS") != 0);
+ if ((mode & S_IFMT) == S_IFDIR){
+ if ((strcmp(name, "SCCS")==0) || (strcmp(name, "RCS")==0))
+ return(0);
+ return(1);
+ }
if ((l = strlen(name)) < 3)
return (1);
if (howmuch > 1 && name[l-2] == '.' && name[l-1] == 'o')
if ((l = strlen(name)) < 3)
return (1);
if (howmuch > 1 && name[l-2] == '.' && name[l-1] == 'o')
+ if (first==0) getbuf();
readtbuf (&bufp, TBLOCK);
bcopy(bufp, buffer, TBLOCK);
return(TBLOCK);
readtbuf (&bufp, TBLOCK);
bcopy(bufp, buffer, TBLOCK);
return(TBLOCK);
register char *buffer;
register int n;
{
register char *buffer;
register int n;
{
+ if (first==0) getbuf();
first = 1;
if (recno >= nblock) {
if (write(mt, tbuf, TBLOCK*nblock) < 0) {
first = 1;
if (recno >= nblock) {
if (write(mt, tbuf, TBLOCK*nblock) < 0) {
+
+getbuf()
+{
+#ifdef nodef
+ if ( mtdev == 1) {
+ fstat(mt, &stbuf);
+ if ((stbuf.st_mode & S_IFMT) == S_IFCHR)
+ mtdev = 0;
+ else
+ mtdev = -1;
+ }
+ if (first==0 && nblock==0) {
+ if (mtdev == 0)
+ nblock = FILEBLOCK;
+ else {
+ fstat(mt, &stbuf);
+ nblock = stbuf.st_blocks / TBLOCK;
+ }
+ }
+ if (nblock ==0) nblock = FILEBLOCK;
+#endif nodef
+ tbuf = (union hblock *)malloc(nblock*TBLOCK);
+ if (tbuf == NULL) {
+ fprintf(stderr, "tar: blocksize %d too big, can't get memory\n",
+ nblock);
+ done(1);
+ }
+}