2001-02-11 00:47:40 +08:00
|
|
|
/** \ingroup payload
|
2000-08-28 03:18:25 +08:00
|
|
|
* \file lib/cpio.c
|
2000-03-23 23:49:50 +08:00
|
|
|
* Handle cpio payloads within rpm packages.
|
|
|
|
*
|
2000-08-28 03:18:25 +08:00
|
|
|
* \warning FIXME: We don't translate between cpio and system mode bits! These
|
2000-03-23 23:49:50 +08:00
|
|
|
* should both be the same, but really odd things are going to happen if
|
|
|
|
* that's not true!
|
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
2001-01-23 03:11:19 +08:00
|
|
|
|
2009-12-23 20:14:35 +08:00
|
|
|
#if MAJOR_IN_MKDEV
|
|
|
|
#include <sys/mkdev.h>
|
|
|
|
#elif MAJOR_IN_SYSMACROS
|
|
|
|
#include <sys/sysmacros.h>
|
|
|
|
#else
|
|
|
|
#include <sys/types.h> /* already included from system.h */
|
|
|
|
#endif
|
2010-01-05 21:25:31 +08:00
|
|
|
#include <errno.h>
|
2012-03-30 20:27:51 +08:00
|
|
|
#include <string.h>
|
2009-12-23 20:14:35 +08:00
|
|
|
|
2008-01-30 17:49:25 +08:00
|
|
|
#include <rpm/rpmio.h>
|
2008-01-30 23:05:29 +08:00
|
|
|
#include <rpm/rpmlog.h>
|
2012-04-18 16:38:29 +08:00
|
|
|
#include <rpm/rpmstring.h>
|
2002-04-13 09:28:20 +08:00
|
|
|
|
2007-11-23 18:39:29 +08:00
|
|
|
#include "lib/cpio.h"
|
2002-04-13 09:28:20 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
1997-05-06 04:46:58 +08:00
|
|
|
|
2000-03-23 23:49:50 +08:00
|
|
|
|
2012-03-22 20:58:02 +08:00
|
|
|
struct rpmcpio_s {
|
|
|
|
FD_t fd;
|
|
|
|
char mode;
|
|
|
|
off_t offset;
|
|
|
|
off_t fileend;
|
|
|
|
};
|
|
|
|
|
|
|
|
rpmcpio_t rpmcpioOpen(FD_t fd, char mode)
|
|
|
|
{
|
|
|
|
if ((mode & O_ACCMODE) != O_RDONLY &&
|
|
|
|
(mode & O_ACCMODE) != O_WRONLY)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
rpmcpio_t cpio = xcalloc(1, sizeof(*cpio));
|
2012-04-17 23:03:29 +08:00
|
|
|
cpio->fd = fdLink(fd);
|
2012-03-22 20:58:02 +08:00
|
|
|
cpio->mode = mode;
|
|
|
|
cpio->offset = 0;
|
|
|
|
return cpio;
|
|
|
|
}
|
|
|
|
|
|
|
|
off_t rpmcpioTell(rpmcpio_t cpio)
|
|
|
|
{
|
|
|
|
return cpio->offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-24 21:46:51 +08:00
|
|
|
/**
|
|
|
|
* Convert string to unsigned integer (with buffer size check).
|
2002-04-09 02:56:01 +08:00
|
|
|
* @param str input string
|
|
|
|
* @retval endptr address of 1st character not processed
|
2000-10-24 21:46:51 +08:00
|
|
|
* @param base numerical conversion base
|
|
|
|
* @param num max no. of bytes to read
|
|
|
|
* @return converted integer
|
|
|
|
*/
|
2008-06-30 16:24:34 +08:00
|
|
|
static unsigned long strntoul(const char *str,char **endptr, int base, size_t num)
|
1999-09-18 05:31:38 +08:00
|
|
|
{
|
2008-04-29 00:10:25 +08:00
|
|
|
char buf[num+1], * end;
|
1998-03-28 01:41:19 +08:00
|
|
|
unsigned long ret;
|
1997-01-04 10:48:55 +08:00
|
|
|
|
2008-05-09 00:03:12 +08:00
|
|
|
strncpy(buf, str, num);
|
|
|
|
buf[num] = '\0';
|
1997-01-04 10:48:55 +08:00
|
|
|
|
1998-03-28 01:23:20 +08:00
|
|
|
ret = strtoul(buf, &end, base);
|
2001-04-29 09:05:43 +08:00
|
|
|
if (*end != '\0')
|
1998-12-06 07:22:41 +08:00
|
|
|
*endptr = ((char *)str) + (end - buf); /* XXX discards const */
|
1998-03-28 01:23:20 +08:00
|
|
|
else
|
2001-04-18 02:23:58 +08:00
|
|
|
*endptr = ((char *)str) + strlen(buf);
|
1998-03-28 01:23:20 +08:00
|
|
|
|
2000-10-24 21:46:51 +08:00
|
|
|
return ret;
|
1997-01-04 10:48:55 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 20:58:02 +08:00
|
|
|
|
|
|
|
static int rpmcpioWritePad(rpmcpio_t cpio, ssize_t modulo)
|
|
|
|
{
|
|
|
|
char buf[modulo];
|
|
|
|
ssize_t left, writen;
|
|
|
|
memset(buf, 0, modulo);
|
|
|
|
left = (modulo - ((cpio->offset) % modulo)) % modulo;
|
|
|
|
if (left <= 0)
|
|
|
|
return 0;
|
|
|
|
writen = Fwrite(&buf, left, 1, cpio->fd);
|
|
|
|
if (writen != left) {
|
|
|
|
return CPIOERR_WRITE_FAILED;
|
|
|
|
}
|
|
|
|
cpio->offset += writen;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rpmcpioReadPad(rpmcpio_t cpio)
|
|
|
|
{
|
|
|
|
ssize_t modulo = 4;
|
|
|
|
char buf[4];
|
|
|
|
ssize_t left, read;
|
|
|
|
left = (modulo - (cpio->offset % modulo)) % modulo;
|
|
|
|
if (left <= 0)
|
|
|
|
return 0;
|
|
|
|
read = Fread(&buf, left, 1, cpio->fd);
|
|
|
|
cpio->offset += read;
|
|
|
|
if (read != left) {
|
|
|
|
return CPIOERR_READ_FAILED;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-01-04 10:48:55 +08:00
|
|
|
#define GET_NUM_FIELD(phys, log) \
|
2007-09-12 01:07:39 +08:00
|
|
|
\
|
1997-01-04 10:48:55 +08:00
|
|
|
log = strntoul(phys, &end, 16, sizeof(phys)); \
|
2007-09-12 01:07:39 +08:00
|
|
|
\
|
2001-04-18 02:23:58 +08:00
|
|
|
if ( (end - phys) != sizeof(phys) ) return CPIOERR_BAD_HEADER;
|
1997-07-24 02:07:46 +08:00
|
|
|
#define SET_NUM_FIELD(phys, val, space) \
|
|
|
|
sprintf(space, "%8.8lx", (unsigned long) (val)); \
|
2007-09-12 01:07:39 +08:00
|
|
|
\
|
2002-07-03 07:54:35 +08:00
|
|
|
memcpy(phys, space, 8) \
|
1997-01-04 10:48:55 +08:00
|
|
|
|
2012-03-22 20:58:02 +08:00
|
|
|
static int rpmcpioTrailerWrite(rpmcpio_t cpio)
|
2001-02-04 10:04:09 +08:00
|
|
|
{
|
2012-03-22 20:58:02 +08:00
|
|
|
struct cpioCrcPhysicalHeader hdr;
|
2001-02-04 10:04:09 +08:00
|
|
|
int rc;
|
2012-03-22 20:58:02 +08:00
|
|
|
size_t writen;
|
2001-02-04 10:04:09 +08:00
|
|
|
|
2012-03-22 20:58:02 +08:00
|
|
|
if (cpio->fileend != cpio->offset) {
|
|
|
|
return CPIOERR_WRITE_FAILED;
|
|
|
|
}
|
2001-02-04 10:04:09 +08:00
|
|
|
|
2012-03-22 20:58:02 +08:00
|
|
|
rc = rpmcpioWritePad(cpio, 4);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
memset(&hdr, '0', PHYS_HDR_SIZE);
|
|
|
|
memcpy(&hdr.magic, CPIO_NEWC_MAGIC, sizeof(hdr.magic));
|
|
|
|
memcpy(&hdr.nlink, "00000001", 8);
|
|
|
|
memcpy(&hdr.namesize, "0000000b", 8);
|
|
|
|
writen = Fwrite(&hdr, PHYS_HDR_SIZE, 1, cpio->fd);
|
|
|
|
cpio->offset += writen;
|
|
|
|
if (writen != PHYS_HDR_SIZE) {
|
|
|
|
return CPIOERR_WRITE_FAILED;
|
|
|
|
}
|
|
|
|
writen = Fwrite(&CPIO_TRAILER, sizeof(CPIO_TRAILER), 1, cpio->fd);
|
|
|
|
cpio->offset += writen;
|
|
|
|
if (writen != sizeof(CPIO_TRAILER)) {
|
|
|
|
return CPIOERR_WRITE_FAILED;
|
|
|
|
}
|
2001-02-04 10:04:09 +08:00
|
|
|
|
|
|
|
/*
|
2012-03-22 20:58:02 +08:00
|
|
|
* XXX GNU cpio pads to 512 bytes. This may matter for
|
|
|
|
* tape device(s) and/or concatenated cpio archives.
|
2001-02-04 10:04:09 +08:00
|
|
|
*/
|
2012-03-22 20:58:02 +08:00
|
|
|
|
|
|
|
rc = rpmcpioWritePad(cpio, 4);
|
2001-02-04 10:04:09 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2012-03-22 20:58:02 +08:00
|
|
|
int rpmcpioHeaderWrite(rpmcpio_t cpio, char * path, struct stat * st)
|
2001-02-03 22:30:57 +08:00
|
|
|
{
|
2012-03-22 20:58:02 +08:00
|
|
|
struct cpioCrcPhysicalHeader hdr_s;
|
|
|
|
struct cpioCrcPhysicalHeader * hdr = &hdr_s;
|
2001-02-03 22:30:57 +08:00
|
|
|
char field[64];
|
2012-03-22 20:58:02 +08:00
|
|
|
size_t len, writen;
|
2001-02-03 22:30:57 +08:00
|
|
|
dev_t dev;
|
|
|
|
int rc = 0;
|
|
|
|
|
2012-03-22 20:58:02 +08:00
|
|
|
if ((cpio->mode & O_ACCMODE) != O_WRONLY) {
|
|
|
|
return CPIOERR_WRITE_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpio->fileend != cpio->offset) {
|
|
|
|
return CPIOERR_WRITE_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = rpmcpioWritePad(cpio, 4);
|
|
|
|
if (rc) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2001-02-03 22:30:57 +08:00
|
|
|
memcpy(hdr->magic, CPIO_NEWC_MAGIC, sizeof(hdr->magic));
|
|
|
|
SET_NUM_FIELD(hdr->inode, st->st_ino, field);
|
|
|
|
SET_NUM_FIELD(hdr->mode, st->st_mode, field);
|
|
|
|
SET_NUM_FIELD(hdr->uid, st->st_uid, field);
|
|
|
|
SET_NUM_FIELD(hdr->gid, st->st_gid, field);
|
|
|
|
SET_NUM_FIELD(hdr->nlink, st->st_nlink, field);
|
|
|
|
SET_NUM_FIELD(hdr->mtime, st->st_mtime, field);
|
|
|
|
SET_NUM_FIELD(hdr->filesize, st->st_size, field);
|
|
|
|
|
2007-12-14 16:30:01 +08:00
|
|
|
dev = major(st->st_dev); SET_NUM_FIELD(hdr->devMajor, dev, field);
|
|
|
|
dev = minor(st->st_dev); SET_NUM_FIELD(hdr->devMinor, dev, field);
|
|
|
|
dev = major(st->st_rdev); SET_NUM_FIELD(hdr->rdevMajor, dev, field);
|
|
|
|
dev = minor(st->st_rdev); SET_NUM_FIELD(hdr->rdevMinor, dev, field);
|
2001-02-03 22:30:57 +08:00
|
|
|
|
2012-03-22 20:58:02 +08:00
|
|
|
len = strlen(path) + 1;
|
|
|
|
SET_NUM_FIELD(hdr->namesize, len, field);
|
|
|
|
|
2009-03-19 16:15:49 +08:00
|
|
|
memcpy(hdr->checksum, "00000000", 8);
|
2012-03-22 20:58:02 +08:00
|
|
|
|
|
|
|
writen = Fwrite(hdr, PHYS_HDR_SIZE, 1, cpio->fd);
|
|
|
|
cpio->offset += writen;
|
|
|
|
if (writen != PHYS_HDR_SIZE) {
|
|
|
|
return CPIOERR_WRITE_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
writen = Fwrite(path, len, 1, cpio->fd);
|
|
|
|
cpio->offset += writen;
|
|
|
|
if (writen != len) {
|
|
|
|
return CPIOERR_WRITE_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = rpmcpioWritePad(cpio, 4);
|
|
|
|
|
|
|
|
cpio->fileend = cpio->offset + st->st_size;
|
|
|
|
|
2001-02-03 22:30:57 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2012-03-22 20:58:02 +08:00
|
|
|
ssize_t rpmcpioWrite(rpmcpio_t cpio, void * buf, size_t size)
|
|
|
|
{
|
|
|
|
size_t writen, left;
|
|
|
|
|
|
|
|
if ((cpio->mode & O_ACCMODE) != O_WRONLY) {
|
|
|
|
return CPIOERR_WRITE_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not write beyond file length
|
|
|
|
left = cpio->fileend - cpio->offset;
|
|
|
|
size = size > left ? left : size;
|
|
|
|
writen = Fwrite(buf, size, 1, cpio->fd);
|
|
|
|
cpio->offset += writen;
|
|
|
|
return writen;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int rpmcpioHeaderRead(rpmcpio_t cpio, char ** path, struct stat * st)
|
1999-09-18 05:31:38 +08:00
|
|
|
{
|
2001-02-03 22:30:57 +08:00
|
|
|
struct cpioCrcPhysicalHeader hdr;
|
1997-01-04 10:48:55 +08:00
|
|
|
int nameSize;
|
|
|
|
char * end;
|
2007-12-14 19:38:58 +08:00
|
|
|
unsigned int major, minor;
|
2001-02-03 22:30:57 +08:00
|
|
|
int rc = 0;
|
2012-03-22 20:58:02 +08:00
|
|
|
ssize_t read;
|
1997-01-04 10:48:55 +08:00
|
|
|
|
2012-03-22 20:58:02 +08:00
|
|
|
if ((cpio->mode & O_ACCMODE) != O_RDONLY) {
|
|
|
|
return CPIOERR_READ_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to next file */
|
|
|
|
if (cpio->fileend != cpio->offset) {
|
2012-03-27 17:09:45 +08:00
|
|
|
/* XXX try using Fseek() - which is currently broken */
|
|
|
|
char buf[8*BUFSIZ];
|
|
|
|
while (cpio->fileend != cpio->offset) {
|
|
|
|
read = cpio->fileend - cpio->offset > 8*BUFSIZ ? 8*BUFSIZ : cpio->fileend - cpio->offset;
|
|
|
|
if (rpmcpioRead(cpio, &buf, read) != read) {
|
|
|
|
return CPIOERR_READ_FAILED;
|
2012-03-22 20:58:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-27 17:09:45 +08:00
|
|
|
|
2012-03-22 20:58:02 +08:00
|
|
|
rc = rpmcpioReadPad(cpio);
|
2001-02-03 22:30:57 +08:00
|
|
|
if (rc) return rc;
|
2012-03-22 20:58:02 +08:00
|
|
|
|
|
|
|
read = Fread(&hdr, PHYS_HDR_SIZE, 1, cpio->fd);
|
|
|
|
cpio->offset += read;
|
|
|
|
if (read != PHYS_HDR_SIZE)
|
|
|
|
return CPIOERR_READ_FAILED;
|
1997-01-04 10:48:55 +08:00
|
|
|
|
2001-02-03 22:30:57 +08:00
|
|
|
if (strncmp(CPIO_CRC_MAGIC, hdr.magic, sizeof(CPIO_CRC_MAGIC)-1) &&
|
2012-03-22 20:58:02 +08:00
|
|
|
strncmp(CPIO_NEWC_MAGIC, hdr.magic, sizeof(CPIO_NEWC_MAGIC)-1)) {
|
1998-12-06 07:22:41 +08:00
|
|
|
return CPIOERR_BAD_MAGIC;
|
2012-03-22 20:58:02 +08:00
|
|
|
}
|
2001-02-03 22:30:57 +08:00
|
|
|
GET_NUM_FIELD(hdr.inode, st->st_ino);
|
|
|
|
GET_NUM_FIELD(hdr.mode, st->st_mode);
|
|
|
|
GET_NUM_FIELD(hdr.uid, st->st_uid);
|
|
|
|
GET_NUM_FIELD(hdr.gid, st->st_gid);
|
|
|
|
GET_NUM_FIELD(hdr.nlink, st->st_nlink);
|
|
|
|
GET_NUM_FIELD(hdr.mtime, st->st_mtime);
|
|
|
|
GET_NUM_FIELD(hdr.filesize, st->st_size);
|
1997-01-04 10:48:55 +08:00
|
|
|
|
2001-02-03 22:30:57 +08:00
|
|
|
GET_NUM_FIELD(hdr.devMajor, major);
|
|
|
|
GET_NUM_FIELD(hdr.devMinor, minor);
|
2002-01-19 06:51:30 +08:00
|
|
|
st->st_dev = makedev(major, minor);
|
1997-01-04 10:48:55 +08:00
|
|
|
|
2001-02-03 22:30:57 +08:00
|
|
|
GET_NUM_FIELD(hdr.rdevMajor, major);
|
|
|
|
GET_NUM_FIELD(hdr.rdevMinor, minor);
|
2002-01-19 06:51:30 +08:00
|
|
|
st->st_rdev = makedev(major, minor);
|
1997-01-04 10:48:55 +08:00
|
|
|
|
2001-02-03 22:30:57 +08:00
|
|
|
GET_NUM_FIELD(hdr.namesize, nameSize);
|
1997-01-04 10:48:55 +08:00
|
|
|
|
2012-03-22 20:58:02 +08:00
|
|
|
*path = xmalloc(nameSize + 1);
|
|
|
|
read = Fread(*path, nameSize, 1, cpio->fd);
|
|
|
|
(*path)[nameSize] = '\0';
|
|
|
|
cpio->offset += read;
|
|
|
|
if (read != nameSize ) {
|
|
|
|
return CPIOERR_BAD_HEADER;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = rpmcpioReadPad(cpio);
|
|
|
|
cpio->fileend = cpio->offset + st->st_size;
|
1997-01-04 10:48:55 +08:00
|
|
|
|
2012-04-18 16:38:29 +08:00
|
|
|
if (!rc && rstreq(*path, CPIO_TRAILER))
|
|
|
|
rc = CPIOERR_HDR_TRAILER;
|
|
|
|
|
2012-03-22 20:58:02 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t rpmcpioRead(rpmcpio_t cpio, void * buf, size_t size)
|
|
|
|
{
|
|
|
|
size_t read, left;
|
|
|
|
|
|
|
|
if ((cpio->mode & O_ACCMODE) != O_RDONLY) {
|
|
|
|
return CPIOERR_READ_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
left = cpio->fileend - cpio->offset;
|
|
|
|
size = size > left ? left : size;
|
|
|
|
read = Fread(buf, size, 1, cpio->fd);
|
|
|
|
cpio->offset += read;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rpmcpioClose(rpmcpio_t cpio)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
if ((cpio->mode & O_ACCMODE) == O_WRONLY) {
|
|
|
|
rc = rpmcpioTrailerWrite(cpio);
|
2011-05-30 22:13:51 +08:00
|
|
|
}
|
2012-04-18 15:30:11 +08:00
|
|
|
cpio->fd = fdFree(cpio->fd);
|
2011-05-30 22:13:51 +08:00
|
|
|
return rc;
|
1997-01-04 10:48:55 +08:00
|
|
|
}
|
|
|
|
|
2012-04-18 15:30:11 +08:00
|
|
|
rpmcpio_t rpmcpioFree(rpmcpio_t cpio)
|
|
|
|
{
|
|
|
|
if (cpio) {
|
|
|
|
if (cpio->fd)
|
|
|
|
(void) rpmcpioClose(cpio);
|
|
|
|
free(cpio);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-22 20:58:02 +08:00
|
|
|
const char * rpmcpioStrerror(int rc)
|
1998-12-06 07:22:41 +08:00
|
|
|
{
|
|
|
|
static char msg[256];
|
2007-12-14 21:17:59 +08:00
|
|
|
const char *s;
|
2007-12-14 16:30:01 +08:00
|
|
|
int myerrno = errno;
|
|
|
|
size_t l;
|
1998-12-06 07:22:41 +08:00
|
|
|
|
|
|
|
strcpy(msg, "cpio: ");
|
|
|
|
switch (rc) {
|
2007-12-14 21:17:59 +08:00
|
|
|
default: {
|
|
|
|
char *t = msg + strlen(msg);
|
|
|
|
sprintf(t, _("(error 0x%x)"), (unsigned)rc);
|
1998-12-06 07:22:41 +08:00
|
|
|
s = NULL;
|
|
|
|
break;
|
2007-12-14 21:17:59 +08:00
|
|
|
}
|
1998-12-06 07:22:41 +08:00
|
|
|
case CPIOERR_BAD_MAGIC: s = _("Bad magic"); break;
|
1999-01-22 01:18:38 +08:00
|
|
|
case CPIOERR_BAD_HEADER: s = _("Bad/unreadable header");break;
|
1998-12-06 07:22:41 +08:00
|
|
|
|
|
|
|
case CPIOERR_OPEN_FAILED: s = "open"; break;
|
|
|
|
case CPIOERR_CHMOD_FAILED: s = "chmod"; break;
|
|
|
|
case CPIOERR_CHOWN_FAILED: s = "chown"; break;
|
|
|
|
case CPIOERR_WRITE_FAILED: s = "write"; break;
|
|
|
|
case CPIOERR_UTIME_FAILED: s = "utime"; break;
|
|
|
|
case CPIOERR_UNLINK_FAILED: s = "unlink"; break;
|
2001-01-28 10:13:48 +08:00
|
|
|
case CPIOERR_RENAME_FAILED: s = "rename"; break;
|
1998-12-06 07:22:41 +08:00
|
|
|
case CPIOERR_SYMLINK_FAILED: s = "symlink"; break;
|
|
|
|
case CPIOERR_STAT_FAILED: s = "stat"; break;
|
2001-01-28 10:13:48 +08:00
|
|
|
case CPIOERR_LSTAT_FAILED: s = "lstat"; break;
|
1998-12-06 07:22:41 +08:00
|
|
|
case CPIOERR_MKDIR_FAILED: s = "mkdir"; break;
|
2001-01-28 10:13:48 +08:00
|
|
|
case CPIOERR_RMDIR_FAILED: s = "rmdir"; break;
|
1998-12-06 07:22:41 +08:00
|
|
|
case CPIOERR_MKNOD_FAILED: s = "mknod"; break;
|
|
|
|
case CPIOERR_MKFIFO_FAILED: s = "mkfifo"; break;
|
|
|
|
case CPIOERR_LINK_FAILED: s = "link"; break;
|
|
|
|
case CPIOERR_READLINK_FAILED: s = "readlink"; break;
|
|
|
|
case CPIOERR_READ_FAILED: s = "read"; break;
|
|
|
|
case CPIOERR_COPY_FAILED: s = "copy"; break;
|
2003-12-26 07:00:44 +08:00
|
|
|
case CPIOERR_LSETFCON_FAILED: s = "lsetfilecon"; break;
|
2008-10-29 17:49:38 +08:00
|
|
|
case CPIOERR_SETCAP_FAILED: s = "cap_set_file"; break;
|
1998-12-06 07:22:41 +08:00
|
|
|
|
|
|
|
case CPIOERR_HDR_SIZE: s = _("Header size too big"); break;
|
|
|
|
case CPIOERR_UNKNOWN_FILETYPE: s = _("Unknown file type"); break;
|
2001-06-20 14:29:20 +08:00
|
|
|
case CPIOERR_MISSING_HARDLINK: s = _("Missing hard link(s)"); break;
|
2009-02-27 21:34:39 +08:00
|
|
|
case CPIOERR_DIGEST_MISMATCH: s = _("Digest mismatch"); break;
|
1999-05-12 04:05:43 +08:00
|
|
|
case CPIOERR_INTERNAL: s = _("Internal error"); break;
|
2001-07-25 04:39:19 +08:00
|
|
|
case CPIOERR_UNMAPPED_FILE: s = _("Archive file not in header"); break;
|
2003-03-23 08:36:13 +08:00
|
|
|
case CPIOERR_ENOENT: s = strerror(ENOENT); break;
|
|
|
|
case CPIOERR_ENOTEMPTY: s = strerror(ENOTEMPTY); break;
|
1998-12-06 07:22:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
l = sizeof(msg) - strlen(msg) - 1;
|
|
|
|
if (s != NULL) {
|
|
|
|
if (l > 0) strncat(msg, s, l);
|
|
|
|
l -= strlen(s);
|
|
|
|
}
|
2000-01-25 06:13:45 +08:00
|
|
|
if ((rc & CPIOERR_CHECK_ERRNO) && myerrno) {
|
1998-12-06 07:22:41 +08:00
|
|
|
s = _(" failed - ");
|
|
|
|
if (l > 0) strncat(msg, s, l);
|
|
|
|
l -= strlen(s);
|
|
|
|
if (l > 0) strncat(msg, strerror(myerrno), l);
|
|
|
|
}
|
|
|
|
return msg;
|
|
|
|
}
|