home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / misc / src / rpm / lib / cpio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-17  |  2.7 KB  |  73 lines

  1. #ifndef H_CPIO
  2. #define H_CPIO
  3.  
  4. #include <zlib.h>
  5.  
  6. /* Note the "high" bit is set only if errno is valid */
  7. #define CPIO_CHECK_ERRNO    0x80000000
  8. #define CPIO_READ_FAILED    (-1)
  9. #define CPIO_BAD_MAGIC        (-2            )
  10. #define CPIO_BAD_HEADER        (-3            )
  11. #define CPIO_OPEN_FAILED    (-4   | CPIO_CHECK_ERRNO)
  12. #define CPIO_CHMOD_FAILED    (-5   | CPIO_CHECK_ERRNO)
  13. #define CPIO_CHOWN_FAILED    (-6   | CPIO_CHECK_ERRNO)
  14. #define CPIO_WRITE_FAILED    (-7   | CPIO_CHECK_ERRNO)
  15. #define CPIO_UTIME_FAILED    (-8   | CPIO_CHECK_ERRNO)
  16. #define CPIO_UNLINK_FAILED    (-9   | CPIO_CHECK_ERRNO)
  17. #define CPIO_INTERNAL        (-10            )
  18. #define CPIO_SYMLINK_FAILED    (-11  | CPIO_CHECK_ERRNO)
  19. #define CPIO_STAT_FAILED    (-12  | CPIO_CHECK_ERRNO)
  20. #define CPIO_MKDIR_FAILED    (-13  | CPIO_CHECK_ERRNO)
  21. #define CPIO_MKNOD_FAILED    (-14  | CPIO_CHECK_ERRNO)
  22. #define CPIO_MKFIFO_FAILED    (-15  | CPIO_CHECK_ERRNO)
  23. #define CPIO_LINK_FAILED    (-16  | CPIO_CHECK_ERRNO)
  24. #define CPIO_READLINK_FAILED    (-17  | CPIO_CHECK_ERRNO)
  25.  
  26. /* Don't think this behaves just like standard cpio. It's pretty close, but
  27.    it has some behaviors which are more to RPM's liking. I tried to document
  28.    them inline in cpio.c, but I may have missed some. */
  29.  
  30. #define CPIO_MAP_PATH        (1 << 0)
  31. #define CPIO_MAP_MODE        (1 << 1)
  32. #define CPIO_MAP_UID        (1 << 2)
  33. #define CPIO_MAP_GID        (1 << 3)
  34. #define CPIO_FOLLOW_SYMLINKS    (1 << 4)  /* only for building */
  35.  
  36. struct cpioFileMapping {
  37.     char * archivePath;
  38.     char * fsPath;
  39.     mode_t finalMode;
  40.     uid_t finalUid;
  41.     gid_t finalGid;
  42.     int mapFlags;
  43. };
  44.  
  45. /* on cpio building, only "file" is filled in */
  46. struct cpioCallbackInfo {
  47.     char * file;
  48.     long fileSize;            /* total file size */
  49.     long fileComplete;            /* amount of file unpacked */
  50.     long bytesProcessed;        /* bytes in archive read */
  51. };
  52.  
  53. typedef void (*cpioCallback)(struct cpioCallbackInfo * filespec, void * data);
  54.  
  55. /* If no mappings are passed, this installs everything! If one is passed
  56.    it should be sorted according to cpioFileMapCmp() and only files included
  57.    in the map are installed. Files are installed relative to the current
  58.    directory unless a mapping is given which specifies an absolute 
  59.    directory. The mode mapping is only used for the permission bits, not
  60.    for the file type. The owner/group mappings are ignored for the nonroot
  61.    user. If *failedFile is non-NULL on return, it should be free()d. */
  62. int cpioInstallArchive(gzFile stream, struct cpioFileMapping * mappings, 
  63.                int numMappings, cpioCallback cb, void * cbData,
  64.                char ** failedFile);
  65. int cpioBuildArchive(int fd, struct cpioFileMapping * mappings, 
  66.              int numMappings, cpioCallback cb, void * cbData,
  67.              unsigned int * archiveSize, char ** failedFile);
  68.  
  69. /* This is designed to be qsort/bsearch compatible */
  70. int cpioFileMapCmp(const void * a, const void * b);
  71.  
  72. #endif
  73.