12 #define _IOSM_INTERNAL
30 static int strntoul(
const char *str,
char **endptr,
39 strncpy(buf, str, num);
42 ret = strtoul(buf, &end, base);
45 *endptr = ((
char *)str) + (end - buf);
47 *endptr = ((
char *)str) + strlen(buf);
54 #define _IOSMRC(_rc) \
55 if ((_rc) <= 0) return ((_rc) ? (int) -rc : IOSMERR_HDR_TRAILER)
57 static ssize_t
cpioRead(
void * _iosm,
void * buf,
size_t count)
67 fprintf(stderr,
" cpioRead(%p, %p[%u])\n", iosm, buf, (
unsigned)count);
74 if (!rc && iosm->rdnb != iosm->wrlen)
75 rc = IOSMERR_READ_FAILED;
79 rc = (count > iosm->rdnb ? iosm->rdnb : count);
80 if (buf != iosm->wrbuf)
81 memcpy(t + nb, iosm->wrbuf, rc);
88 #define GET_NUM_FIELD(phys, log) \
89 log = strntoul(phys, &end, 16, sizeof(phys)); \
90 if ( (end - phys) != sizeof(phys) ) return IOSMERR_BAD_HEADER;
91 #define SET_NUM_FIELD(phys, val, space) \
92 sprintf(space, "%8.8lx", (unsigned long) (val)); \
93 memcpy(phys, space, 8)
105 fprintf(stderr,
" cpioHeaderRead(%p, %p)\n", iosm, st);
114 return IOSMERR_BAD_MAGIC;
138 if (nb >= iosm->wrsize)
139 return IOSMERR_BAD_HEADER;
160 if (rc)
return (
int) -rc;
162 nb = (size_t) st->st_size;
179 fprintf(stderr,
"\t %06o%3d (%4d,%4d)%12lu %s\n\t-> %s\n",
180 (
unsigned)st->st_mode, (
int)st->st_nlink,
181 (
int)st->st_uid, (
int)st->st_gid, (
unsigned long)st->st_size,
182 (iosm->path ? iosm->path :
""), (iosm->lpath ? iosm->lpath :
""));
188 static ssize_t
cpioWrite(
void * _iosm,
const void *buf,
size_t count)
193 const char * s = buf;
198 fprintf(stderr,
"\t cpioWrite(%p, %p[%u])\n", iosm, buf, (
unsigned)count);
204 if (s != iosm->rdbuf)
205 memmove(iosm->rdbuf, s + nb, iosm->rdnb);
208 if (!rc && iosm->rdnb != iosm->wrnb)
209 rc = IOSMERR_WRITE_FAILED;
216 #if defined(JBJ_WRITEPAD)
234 fprintf(stderr,
" cpioHeaderWrite(%p, %p)\n", iosm, st);
251 memcpy(hdr->
checksum,
"00000000", 8);
260 assert(iosm->lpath != NULL);
261 #if !defined(JBJ_WRITEPAD)
263 if (rc)
return (
int) rc;
266 nb = strlen(iosm->lpath);
271 #if !defined(JBJ_WRITEPAD)
286 fprintf(stderr,
" cpioTrailerWrite(%p)\n", iosm);
290 memcpy(hdr->
nlink,
"00000001", 8);
291 memcpy(hdr->
namesize,
"0000000b", 8);
305 #if !defined(JBJ_WRITEPAD)