13 #define _IOSM_INTERNAL
34 static int strntoul(
const char *str,
char **endptr,
42 buf = (
char *)
alloca(num + 1);
46 ret = strtoul(buf, &end, base);
49 *endptr = ((
char *)str) + (end -
buf);
51 *endptr = ((
char *)str) + strlen(buf);
58 #define _IOSMRC(_rc) \
59 if ((_rc) <= 0) return ((_rc) ? (int) -rc : IOSMERR_HDR_TRAILER)
66 char *
t = (
char *) buf;
70 fprintf(stderr,
"\ttarRead(%p, %p[%u])\n", iosm, buf, (
unsigned)count);
84 if (buf != iosm->
wrbuf)
85 memcpy(t + nb, iosm->
wrbuf, rc);
117 fprintf(stderr,
"\ttarHeaderReadName(%p, %u, %p) rc 0x%x\n", _iosm, (
unsigned)len, fnp, (
unsigned)rc);
134 fprintf(stderr,
" tarHeaderRead(%p, %p)\n", iosm, st);
150 {
const unsigned char * hp = (
const unsigned char *) hdr;
156 memcpy(hdrchecksum, hdr->
checksum,
sizeof(hdrchecksum));
162 memset(checksum, (
int)
' ',
sizeof(checksum));
163 sprintf(checksum,
"%06o", (
unsigned) (sum & 07777777));
165 fprintf(stderr,
"\tmemcmp(\"%s\", \"%s\", %u)\n", hdrchecksum, checksum, (
unsigned)
sizeof(hdrchecksum));
166 if (memcmp(hdrchecksum, checksum,
sizeof(hdrchecksum)))
181 st->st_mode &= ~S_IFMT;
190 st->st_mode |= S_IFREG;
193 st->st_mode |= S_IFREG;
199 st->st_mode |= S_IFLNK;
202 st->st_mode |= S_IFCHR;
205 st->st_mode |= S_IFBLK;
208 st->st_mode |= S_IFDIR;
212 st->st_mode |= S_IFIFO;
240 st->st_ctime = st->st_atime = st->st_mtime;
247 st->st_rdev = st->st_dev;
273 fprintf(stderr,
"\t %06o%3d (%4d,%4d)%12lu %s\n\t-> %s\n",
274 (
unsigned)st->st_mode, (
int)st->st_nlink,
275 (
int)st->st_uid, (
int)st->st_gid, (
unsigned long)st->st_size,
286 const char *
s = (
const char *) buf;
291 fprintf(stderr,
"\t tarWrite(%p, %p[%u])\n", iosm, buf, (
unsigned)count);
297 if (s != iosm->
rdbuf)
298 memmove(iosm->
rdbuf, s + nb, iosm->
rdnb);
301 if (!rc && iosm->
rdnb != iosm->
wrnb)
309 #if defined(JBJ_WRITEPAD)
327 ssize_t
rc =
tarWrite(_iosm, path, strlen(path));
329 #if !defined(JBJ_WRITEPAD)
338 fprintf(stderr,
"\ttarHeaderWriteName(%p, %s) rc 0x%x\n", _iosm, path, (
unsigned)rc);
355 const char *
path = (iosm && iosm->
path ? iosm->
path :
"");
359 fprintf(stderr,
"\ttarHeaderWriteBlock(%p, %p) type %c\n", iosm, hdr, hdr->
typeflag);
361 fprintf(stderr,
"\t %06o%3d (%4d,%4d)%12lu %s\n",
362 (
unsigned)st->st_mode, (
int)st->st_nlink,
363 (
int)st->st_uid, (
int)st->st_gid, (
unsigned long)st->st_size,
370 {
const unsigned char * hp = (
const unsigned char *) hdr;
391 static const char * llname =
"././@LongLink";
393 const char *
path = (iosm && iosm->
path ? iosm->
path :
"");
394 const char * lpath = (iosm && iosm->
lpath ? iosm->
lpath :
"");
401 fprintf(stderr,
" tarHeaderWrite(%p, %p)\n", iosm, st);
404 if (nb >
sizeof(hdr->
name)) {
405 memset(hdr, 0,
sizeof(*hdr));
406 strcpy(hdr->
name, llname);
421 if (lpath && lpath[0] !=
'0') {
423 if (nb >
sizeof(hdr->
name)) {
424 memset(hdr, 0,
sizeof(*hdr));
441 memset(hdr, 0,
sizeof(*hdr));
445 if (lpath && lpath[0] !=
'\0')
448 sprintf(hdr->
mode,
"%07o", (
unsigned int)(st->st_mode & 00007777));
449 sprintf(hdr->
uid,
"%07o", (
unsigned int)(st->st_uid & 07777777));
450 sprintf(hdr->
gid,
"%07o", (
unsigned int)(st->st_gid & 07777777));
452 sprintf(hdr->
filesize,
"%011o", (
unsigned) (st->st_size & 037777777777));
453 sprintf(hdr->
mtime,
"%011o", (
unsigned) (st->st_mtime & 037777777777));
458 else if (S_ISCHR(st->st_mode))
460 else if (S_ISBLK(st->st_mode))
462 else if (S_ISDIR(st->st_mode))
464 else if (S_ISFIFO(st->st_mode))
470 else if (S_ISREG(st->st_mode))
471 hdr->
typeflag = (lpath && lpath[0] !=
'\0' ?
'1' :
'0');
475 if (s ==
NULL) s =
"root";
478 if (s ==
NULL) s =
"root";
482 dev =
major((
unsigned)st->st_dev);
484 dev =
minor((
unsigned)st->st_dev);
491 #if !defined(JBJ_WRITEPAD)
505 fprintf(stderr,
" tarTrailerWrite(%p)\n", iosm);
509 #if defined(JBJ_WRITEPAD)
515 #if defined(JBJ_WRITEPAD)
int tarTrailerWrite(void *_iosm)
Write cpio trailer to payload.
static int strntoul(const char *str, char **endptr, int base, size_t num)
Convert string to unsigned integer (with buffer size check).
static ssize_t tarWrite(void *_iosm, const void *buf, size_t count)
static ssize_t tarHeaderWriteName(void *_iosm, const char *path)
Write long file/link name into tar archive.
static char *size_t nb
fgets(3) analogue that reads \ continuations.
static ssize_t tarHeaderReadName(void *_iosm, size_t len, const char **fnp)
Read long file/link name from tar archive.
char * gidToGname(gid_t gid)
#define Makedev(x, y)
makedev() on QNX takes three parameters the additional one (first place) specifies the node for QNET ...
sprintf(t," (%u)",(unsigned) dig->nbytes)
memset(_r, 0, sizeof(*_r))
fprintf(stderr,"--> %s(%p,%p,%p) sig %p sigp %p\n", __FUNCTION__, dig, t, rsactx, sig, sigp)
int(* _iosmNext)(IOSM_t iosm, iosmFileStage nstage)
Vector to iosmNext.
Structures used for tar(1) archives.
struct tarHeader_s * tarHeader
static ssize_t tarRead(void *_iosm, void *buf, size_t count)
char * stpcpy(char *dest, const char *src)
struct iosm_s * IOSM_t
File state machine data.
char * uidToUname(uid_t uid)
static void
Print copy of spec file, filling in Group/Description/Summary from specspo.
char * buf
Parse (and execute) macro undefinition.
File state machine to handle archive I/O and system call's.
static ssize_t tarHeaderWriteBlock(void *_iosm, struct stat *st, tarHeader hdr)
Write tar header block with checksum into tar archive.
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
int tarHeaderRead(void *_iosm, struct stat *st)
Read tar header from payload.
int tarHeaderWrite(void *_iosm, struct stat *st)
Write tar header to payload.
File name and stat information.