format.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1987-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Bell Laboratories
*
* pax archive format support
*/
#include "format.h"
/*
* read archive prologue before files are copied
* compression and input archive formats are identified here
*/
int
{
int n;
return 0;
f->name = 0;
f->skip = 0;
f->uncompressed = 0;
/*
* first check if input is compressed
*/
{
goto unknown;
return 0;
}
{
fp = 0;
{
long ops[3];
char* cmd[3];
cmd[2] = 0;
{
error(ERROR_SYSTEM|3, "%s: cannot create %s base temporary file %s", ap->name, cp->undo[0], state.tmp.file);
ops[2] = 0;
}
else
{
ops[1] = 0;
}
if (!proc)
{
error(ERROR_SYSTEM|3, "%s: cannot read %s base temporary file %s", ap->name, cp->undo[0], state.tmp.file);
error(ERROR_SYSTEM|1, "%s: cannot remove %s base temporary file %s", ap->name, cp->undo[0], state.tmp.file);
}
else
{
List_t* p;
nospace();
}
return 0;
break;
}
}
/*
* now identify the format
*/
{
skipped = 0;
for (;;)
{
fp = 0;
{
if ((n = (*fp->getprologue)(&state, fp, ap, f, ((fp->flags & CONV) || CC_NATIVE == CC_ASCII) ? buf : cvt, sizeof(buf))) < 0)
return 0;
if (n > 0)
break;
{
}
}
if (fp)
break;
{
{
return 0;
}
}
skipped++;
}
if (skipped)
error(1, "%s: %I*d byte%s skipped before identifying %s format archive", ap->name, sizeof(skipped), skipped, skipped == 1 ? "" : "s", fp->name);
}
else if (!(fp->flags & ARCHIVE) || !fp->getprologue || (*fp->getprologue)(&state, fp, ap, f, buf, sizeof(buf)) <= 0)
{
else
{
}
}
{
{
}
/*
* no hard links between volumes
*/
if (!(state.linktab = hashalloc(NiL, HASH_set, HASH_ALLOCATE, HASH_namesize, sizeof(Fileid_t), HASH_name, "links", 0)))
}
return 1;
}
/*
* set pseudo file header+trailer info
*/
void
{
long n;
{
{
else if (n > 0)
}
}
}
/*
* output pseudo file header+trailer
*/
void
{
if (!file)
{
nospace();
else
{
sfprintf(np, "%c%s%c%c%c%s", INFO_SEP, ID, INFO_SEP, ap->delta->compress ? TYPE_COMPRESS : TYPE_DELTA, INFO_SEP, (dp = (Delta_format_t*)ap->delta->format->data) ? dp->variant : "");
}
nospace();
}
f->skip = 1;
puttrailer(ap, f);
if (np)
sfstrclose(np);
}
/*
* write archive prologue before files are copied
*/
void
{
{
}
if ((!ap->format->putprologue || (*ap->format->putprologue)(&state, ap, append) >= 0) && !(ap->format->flags & DELTAINFO) && ap->delta && !(ap->delta->format->flags & PSEUDO))
{
else
}
}
/*
* read archive epilogue after all files have been copied
*/
int
{
register char* s;
register off_t n;
register int i;
unsigned int z;
int x;
{
return 0;
}
{
/*
* check for more volumes
* volumes begin on BLOCKSIZE boundaries
* separated by null byte filler
*/
{
goto done;
}
x = 0;
z = 0;
i = 0;
if (!(n = roundof(ap->io->count, BLOCKSIZE) - ap->io->count) || bread(ap, buf, (off_t)0, (off_t)n, 0) > 0)
do
{
z += s - buf;
if (z >= BLOCKSIZE)
x = 1;
if (s < buf + n)
{
if (n == BLOCKSIZE)
{
{
continue;
if (i)
}
goto done;
}
break;
}
n = BLOCKSIZE;
i++;
}
done:
return 1;
}
/*
* write archive epilogue after files have been copied
*/
void
{
register ssize_t n;
{
}
{
}
{
{
else
}
{
}
}
else
{
}
}
/*
* get key [ug]id value
*/
static void
{
{
}
*ip = d;
}
/*
* get key name value
*/
static void
{
{
}
{
*sp = 0;
*ip = d;
}
}
/*
* get key size value
*/
static void
{
NoP(f);
{
{
}
{
}
}
}
/*
* get key time value
*/
static void
{
NoP(f);
{
else
return;
switch (index)
{
case OPT_atime:
break;
case OPT_mtime:
break;
case OPT_ctime:
break;
}
}
{
}
}
/*
* read next archive entry header
*/
int
{
register char* s;
long i;
{
f->uncompressed = 0;
}
do
{
else
{
f->name = 0;
f->skip = 0;
{
return 0;
}
}
if (!f->name)
setidnames(f);
undos(f);
{
*s = 0;
{
}
}
if (f->linkpath)
{
}
else
f->linkpathsize = 0;
getdeltaheader(ap, f);
#if DEBUG
if (error_info.trace)
{
sfsprintf(s, state.tmp.buffersize, " [%c,%d,%d]", f->record.format, state.blocksize, state.record.size);
else
*s = 0;
message((-1, "archive=%s path=%s name=%s entry=%d.%d size=%I*u uncompressed=%I*u delta=%c%s", ap->name, f->path, f->name, ap->volume, ap->entry, sizeof(f->st->st_size), f->st->st_size, sizeof(f->uncompressed), f->uncompressed, f->delta.op ? f->delta.op : DELTA_nop, s));
}
#endif
{
}
return 1;
}
/*
* write next archive entry header
*/
int
{
register int n;
if (!f->extended)
{
setdeltaheader(ap, f);
}
return -1;
if (!n)
{
if (!ap->incomplete)
return 0;
ap->incomplete = 0;
{
return -1;
}
putprologue(ap, 0);
return n;
}
putdeltaheader(ap, f);
{
n = 0;
if (f->st->st_gid != state.gid && ((f->st->st_mode & S_ISGID) || (f->st->st_mode & S_IRGRP) && !(f->st->st_mode & S_IROTH) || (f->st->st_mode & S_IXGRP) && !(f->st->st_mode & S_IXOTH)))
{
n = 1;
}
if (f->st->st_uid != state.uid && ((f->st->st_mode & S_ISUID) || (f->st->st_mode & S_IRUSR) && !(f->st->st_mode & (S_IRGRP|S_IROTH)) || (f->st->st_mode & S_IXUSR) && !(f->st->st_mode & (S_IXGRP|S_IXOTH))))
{
n = 1;
}
}
return 1;
}
/*
* read entry trailer
*/
void
{
register off_t n;
NoP(f);
{
}
getdeltatrailer(ap, f);
{
}
}
/*
* write entry trailer
*/
void
{
register int n;
char* s;
{
if (f->link)
{
{
nospace();
}
}
else
, (f->st->st_uid != state.uid && ((f->st->st_mode & S_ISUID) || (f->st->st_mode & S_IRUSR) && !(f->st->st_mode & (S_IRGRP|S_IROTH)) || (f->st->st_mode & S_IXUSR) && !(f->st->st_mode & (S_IXGRP|S_IXOTH)))) ? fmtuid(f->st->st_uid) : "-"
, (f->st->st_gid != state.gid && ((f->st->st_mode & S_ISGID) || (f->st->st_mode & S_IRGRP) && !(f->st->st_mode & S_IROTH) || (f->st->st_mode & S_IXGRP) && !(f->st->st_mode & S_IXOTH))) ? fmtgid(f->st->st_gid) : "-"
, f->name
);
}
putdeltatrailer(ap, f);
{
}
listentry(f);
}