summaryrefslogtreecommitdiffstats
path: root/isys/cpio.h
diff options
context:
space:
mode:
Diffstat (limited to 'isys/cpio.h')
-rw-r--r--isys/cpio.h89
1 files changed, 55 insertions, 34 deletions
diff --git a/isys/cpio.h b/isys/cpio.h
index 2ee92f1ce..07160bd27 100644
--- a/isys/cpio.h
+++ b/isys/cpio.h
@@ -2,18 +2,44 @@
#define H_CPIO
#include <zlib.h>
-#define HAVE_ZLIB_H 1
-#include <glob.h> /* XXX rpmlib.h */
-#include <dirent.h> /* XXX rpmlib.h */
+#include <sys/types.h>
-#define HAVE_LIBIO 1
-#include <rpmlib.h>
+/* Note the CPIO_CHECK_ERRNO bit is set only if errno is valid. These have to
+ be positive numbers or this setting the high bit stuff is a bad idea. */
+#define CPIOERR_CHECK_ERRNO 0x80000000
-#define CPIO_MAP_PATH (1 << 0)
-#define CPIO_MAP_MODE (1 << 1)
-#define CPIO_MAP_UID (1 << 2)
-#define CPIO_MAP_GID (1 << 3)
-#define CPIO_FOLLOW_SYMLINKS (1 << 4) /* only for building */
+#define CPIOERR_BAD_MAGIC (2 )
+#define CPIOERR_BAD_HEADER (3 )
+#define CPIOERR_OPEN_FAILED (4 | CPIOERR_CHECK_ERRNO)
+#define CPIOERR_CHMOD_FAILED (5 | CPIOERR_CHECK_ERRNO)
+#define CPIOERR_CHOWN_FAILED (6 | CPIOERR_CHECK_ERRNO)
+#define CPIOERR_WRITE_FAILED (7 | CPIOERR_CHECK_ERRNO)
+#define CPIOERR_UTIME_FAILED (8 | CPIOERR_CHECK_ERRNO)
+#define CPIOERR_UNLINK_FAILED (9 | CPIOERR_CHECK_ERRNO)
+
+#define CPIOERR_SYMLINK_FAILED (11 | CPIOERR_CHECK_ERRNO)
+#define CPIOERR_STAT_FAILED (12 | CPIOERR_CHECK_ERRNO)
+#define CPIOERR_MKDIR_FAILED (13 | CPIOERR_CHECK_ERRNO)
+#define CPIOERR_MKNOD_FAILED (14 | CPIOERR_CHECK_ERRNO)
+#define CPIOERR_MKFIFO_FAILED (15 | CPIOERR_CHECK_ERRNO)
+#define CPIOERR_LINK_FAILED (16 | CPIOERR_CHECK_ERRNO)
+#define CPIOERR_READLINK_FAILED (17 | CPIOERR_CHECK_ERRNO)
+#define CPIOERR_READ_FAILED (18 | CPIOERR_CHECK_ERRNO)
+#define CPIOERR_COPY_FAILED (19 | CPIOERR_CHECK_ERRNO)
+#define CPIOERR_INTERNAL (20 )
+#define CPIOERR_HDR_SIZE (21 )
+#define CPIOERR_UNKNOWN_FILETYPE (22 )
+
+
+/* Don't think this behaves just like standard cpio. It's pretty close, but
+ it has some behaviors which are more to RPM's liking. I tried to document
+ them inline in cpio.c, but I may have missed some. */
+
+#define CPIO_MAP_PATH (1 << 0)
+#define CPIO_MAP_MODE (1 << 1)
+#define CPIO_MAP_UID (1 << 2)
+#define CPIO_MAP_GID (1 << 3)
+#define CPIO_FOLLOW_SYMLINKS (1 << 4) /* only for building */
struct cpioFileMapping {
char * archivePath;
@@ -27,37 +53,32 @@ struct cpioFileMapping {
/* on cpio building, only "file" is filled in */
struct cpioCallbackInfo {
char * file;
- long fileSize; /* total file size */
- long fileComplete; /* amount of file unpacked */
- long bytesProcessed; /* bytes in archive read */
+ long fileSize; /* total file size */
+ long fileComplete; /* amount of file unpacked */
+ long bytesProcessed; /* bytes in archive read */
};
-typedef struct CFD {
- union {
- FD_t _cfdu_fd;
-#define cpioFd _cfdu._cfdu_fd
- FILE * _cfdu_fp;
-#define cpioFp _cfdu._cfdu_fp
- FD_t _cfdu_gzfd;
-#define cpioGzFd _cfdu._cfdu_gzfd
- } _cfdu;
- int cpioPos;
- enum cpioIoType {
- cpioIoTypeDebug,
- cpioIoTypeFd,
- cpioIoTypeFp,
- cpioIoTypeGzFd,
- } cpioIoType;
-} CFD_t;
-
typedef void (*cpioCallback)(struct cpioCallbackInfo * filespec, void * data);
-/* librpm provides these */
-int cpioInstallArchive(FD_t cfd, struct cpioFileMapping * mappings,
+/* If no mappings are passed, this installs everything! If one is passed
+ it should be sorted according to cpioFileMapCmp() and only files included
+ in the map are installed. Files are installed relative to the current
+ directory unless a mapping is given which specifies an absolute
+ directory. The mode mapping is only used for the permission bits, not
+ for the file type. The owner/group mappings are ignored for the nonroot
+ user. If *failedFile is non-NULL on return, it should be free()d. */
+int cpioInstallArchive(gzFile stream, struct cpioFileMapping * mappings,
int numMappings, cpioCallback cb, void * cbData,
const char ** failedFile);
+int cpioBuildArchive(int fd, struct cpioFileMapping * mappings,
+ int numMappings, cpioCallback cb, void * cbData,
+ unsigned int * archiveSize, char ** failedFile);
+
+/* This is designed to be qsort/bsearch compatible */
+int cpioFileMapCmp(const void * a, const void * b);
+
const char *cpioStrerror(int rc);
-int installCpioFile(FD_t fd, char * cpioName, char * outName, int inWin);
+int installCpioFile(gzFile fd, char * cpioName, char * outName, int inWin);
#endif