allow rpm to custom systemd installation
[platform/upstream/rpm.git] / lib / cpio.h
1 #ifndef H_CPIO
2 #define H_CPIO
3
4 /** \ingroup payload
5  * \file lib/cpio.h
6  *  Structures used to handle cpio payloads within rpm packages.
7  *
8  *  @warning Rpm's cpio implementation may be different than standard cpio.
9  *  The implementation is pretty close, but it has some behaviors which are
10  *  more to RPM's liking. I tried to document the differing behavior in cpio.c,
11  *  but I may have missed some (ewt).
12  *
13  */
14
15 /** \ingroup payload
16  * @note CPIO_CHECK_ERRNO bit is set only if errno is valid.
17  */
18 #define CPIOERR_CHECK_ERRNO     0x00008000
19
20 /** \ingroup payload
21  */
22 enum cpioErrorReturns {
23         CPIOERR_BAD_MAGIC       = 2,
24         CPIOERR_BAD_HEADER      = 3,
25         CPIOERR_OPEN_FAILED     = 4     | CPIOERR_CHECK_ERRNO,
26         CPIOERR_CHMOD_FAILED    = 5     | CPIOERR_CHECK_ERRNO,
27         CPIOERR_CHOWN_FAILED    = 6     | CPIOERR_CHECK_ERRNO,
28         CPIOERR_WRITE_FAILED    = 7     | CPIOERR_CHECK_ERRNO,
29         CPIOERR_UTIME_FAILED    = 8     | CPIOERR_CHECK_ERRNO,
30         CPIOERR_UNLINK_FAILED   = 9     | CPIOERR_CHECK_ERRNO,
31         CPIOERR_RENAME_FAILED   = 10    | CPIOERR_CHECK_ERRNO,
32         CPIOERR_SYMLINK_FAILED  = 11    | CPIOERR_CHECK_ERRNO,
33         CPIOERR_STAT_FAILED     = 12    | CPIOERR_CHECK_ERRNO,
34         CPIOERR_LSTAT_FAILED    = 13    | CPIOERR_CHECK_ERRNO,
35         CPIOERR_MKDIR_FAILED    = 14    | CPIOERR_CHECK_ERRNO,
36         CPIOERR_RMDIR_FAILED    = 15    | CPIOERR_CHECK_ERRNO,
37         CPIOERR_MKNOD_FAILED    = 16    | CPIOERR_CHECK_ERRNO,
38         CPIOERR_MKFIFO_FAILED   = 17    | CPIOERR_CHECK_ERRNO,
39         CPIOERR_LINK_FAILED     = 18    | CPIOERR_CHECK_ERRNO,
40         CPIOERR_READLINK_FAILED = 19    | CPIOERR_CHECK_ERRNO,
41         CPIOERR_READ_FAILED     = 20    | CPIOERR_CHECK_ERRNO,
42         CPIOERR_COPY_FAILED     = 21    | CPIOERR_CHECK_ERRNO,
43         CPIOERR_LSETFCON_FAILED = 22    | CPIOERR_CHECK_ERRNO,
44         CPIOERR_HDR_SIZE        = 23,
45         CPIOERR_HDR_TRAILER     = 24,
46         CPIOERR_UNKNOWN_FILETYPE= 25,
47         CPIOERR_MISSING_HARDLINK= 26,
48         CPIOERR_DIGEST_MISMATCH = 27,
49         CPIOERR_INTERNAL        = 28,
50         CPIOERR_UNMAPPED_FILE   = 29,
51         CPIOERR_ENOENT          = 30,
52         CPIOERR_ENOTEMPTY       = 31,
53         CPIOERR_SETCAP_FAILED   = 32    | CPIOERR_CHECK_ERRNO,
54         CPIOERR_FILE_SIZE       = 33,
55 };
56
57 /*
58  * Size limit for individual files in "new ascii format" cpio archives.
59  * The max size of the entire archive is unlimited from cpio POV,
60  * but subject to filesystem limitations.
61  */
62 #define CPIO_FILESIZE_MAX UINT32_MAX
63
64 #define CPIO_NEWC_MAGIC "070701"
65 #define CPIO_CRC_MAGIC  "070702"
66 #define CPIO_TRAILER    "TRAILER!!!"
67
68 /** \ingroup payload
69  * Cpio archive header information.
70  */
71 struct cpioCrcPhysicalHeader {
72     char magic[6];
73     char inode[8];
74     char mode[8];
75     char uid[8];
76     char gid[8];
77     char nlink[8];
78     char mtime[8];
79     char filesize[8];
80     char devMajor[8];
81     char devMinor[8];
82     char rdevMajor[8];
83     char rdevMinor[8];
84     char namesize[8];
85     char checksum[8];                   /* ignored !! */
86 };
87
88 #define PHYS_HDR_SIZE   110             /* Don't depend on sizeof(struct) */
89
90 typedef struct rpmcpio_s * rpmcpio_t;
91
92 #ifdef __cplusplus
93 extern "C" {
94 #endif
95
96 /**
97  * Create CPIO file object
98  * @param fd            file
99  * @param mode          XXX
100  * @return CPIO object
101  **/
102 rpmcpio_t rpmcpioOpen(FD_t fd, char mode);
103
104 int rpmcpioClose(rpmcpio_t cpio);
105
106 off_t rpmcpioTell(rpmcpio_t cpio);
107
108 rpmcpio_t rpmcpioFree(rpmcpio_t cpio);
109
110 /**
111  * Write cpio header.
112  * @retval fsm          file path and stat info
113  * @param st
114  * @return              0 on success
115  */
116 RPM_GNUC_INTERNAL
117 int rpmcpioHeaderWrite(rpmcpio_t cpio, char * path, struct stat * st);
118
119 ssize_t rpmcpioWrite(rpmcpio_t cpio, void * buf, size_t size);
120
121 /**
122  * Read cpio header.
123  * @retval fsm          file path and stat info
124  * @retval st
125  * @return              0 on success
126  */
127 RPM_GNUC_INTERNAL
128 int rpmcpioHeaderRead(rpmcpio_t cpio, char ** path, struct stat * st);
129
130 ssize_t rpmcpioRead(rpmcpio_t cpio, void * buf, size_t size);
131
132 /** \ingroup payload
133  * Return formatted error message on payload handling failure.
134  * @param rc            error code
135  * @return              formatted error string
136  */
137 /* XXX should be RPM_GNUC_INTERNAL too but build/pack.c uses */
138 const char * rpmcpioStrerror(int rc);
139
140 #ifdef __cplusplus
141 }
142 #endif
143
144 #endif  /* H_CPIO */