Sanitize python object -> tag number exception handling
[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 #include "lib/fsm.h"
16
17 /** \ingroup payload
18  * @note CPIO_CHECK_ERRNO bit is set only if errno is valid.
19  */
20 #define CPIOERR_CHECK_ERRNO     0x00008000
21
22 /** \ingroup payload
23  */
24 enum cpioErrorReturns {
25         CPIOERR_BAD_MAGIC       = 2,
26         CPIOERR_BAD_HEADER      = 3,
27         CPIOERR_OPEN_FAILED     = 4     | CPIOERR_CHECK_ERRNO,
28         CPIOERR_CHMOD_FAILED    = 5     | CPIOERR_CHECK_ERRNO,
29         CPIOERR_CHOWN_FAILED    = 6     | CPIOERR_CHECK_ERRNO,
30         CPIOERR_WRITE_FAILED    = 7     | CPIOERR_CHECK_ERRNO,
31         CPIOERR_UTIME_FAILED    = 8     | CPIOERR_CHECK_ERRNO,
32         CPIOERR_UNLINK_FAILED   = 9     | CPIOERR_CHECK_ERRNO,
33         CPIOERR_RENAME_FAILED   = 10    | CPIOERR_CHECK_ERRNO,
34         CPIOERR_SYMLINK_FAILED  = 11    | CPIOERR_CHECK_ERRNO,
35         CPIOERR_STAT_FAILED     = 12    | CPIOERR_CHECK_ERRNO,
36         CPIOERR_LSTAT_FAILED    = 13    | CPIOERR_CHECK_ERRNO,
37         CPIOERR_MKDIR_FAILED    = 14    | CPIOERR_CHECK_ERRNO,
38         CPIOERR_RMDIR_FAILED    = 15    | CPIOERR_CHECK_ERRNO,
39         CPIOERR_MKNOD_FAILED    = 16    | CPIOERR_CHECK_ERRNO,
40         CPIOERR_MKFIFO_FAILED   = 17    | CPIOERR_CHECK_ERRNO,
41         CPIOERR_LINK_FAILED     = 18    | CPIOERR_CHECK_ERRNO,
42         CPIOERR_READLINK_FAILED = 19    | CPIOERR_CHECK_ERRNO,
43         CPIOERR_READ_FAILED     = 20    | CPIOERR_CHECK_ERRNO,
44         CPIOERR_COPY_FAILED     = 21    | CPIOERR_CHECK_ERRNO,
45         CPIOERR_LSETFCON_FAILED = 22    | CPIOERR_CHECK_ERRNO,
46         CPIOERR_HDR_SIZE        = 23,
47         CPIOERR_HDR_TRAILER     = 24,
48         CPIOERR_UNKNOWN_FILETYPE= 25,
49         CPIOERR_MISSING_HARDLINK= 26,
50         CPIOERR_DIGEST_MISMATCH = 27,
51         CPIOERR_INTERNAL        = 28,
52         CPIOERR_UNMAPPED_FILE   = 29,
53         CPIOERR_ENOENT          = 30,
54         CPIOERR_ENOTEMPTY       = 31,
55         CPIOERR_SETCAP_FAILED   = 32    | CPIOERR_CHECK_ERRNO,
56 };
57
58 /*
59  * Size limit for individual files in "new ascii format" cpio archives.
60  * The max size of the entire archive is unlimited from cpio POV,
61  * but subject to filesystem limitations.
62  */
63 #define CPIO_FILESIZE_MAX UINT32_MAX
64
65 #define CPIO_NEWC_MAGIC "070701"
66 #define CPIO_CRC_MAGIC  "070702"
67 #define CPIO_TRAILER    "TRAILER!!!"
68
69 /** \ingroup payload
70  * Cpio archive header information.
71  */
72 struct cpioCrcPhysicalHeader {
73     char magic[6];
74     char inode[8];
75     char mode[8];
76     char uid[8];
77     char gid[8];
78     char nlink[8];
79     char mtime[8];
80     char filesize[8];
81     char devMajor[8];
82     char devMinor[8];
83     char rdevMajor[8];
84     char rdevMinor[8];
85     char namesize[8];
86     char checksum[8];                   /* ignored !! */
87 };
88
89 #define PHYS_HDR_SIZE   110             /* Don't depend on sizeof(struct) */
90
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
94
95 /**
96  * Write cpio trailer.
97  * @retval fsm          file path and stat info
98  * @return              0 on success
99  */
100 RPM_GNUC_INTERNAL
101 int cpioTrailerWrite(FSM_t fsm);
102
103 /**
104  * Write cpio header.
105  * @retval fsm          file path and stat info
106  * @param st
107  * @return              0 on success
108  */
109 RPM_GNUC_INTERNAL
110 int cpioHeaderWrite(FSM_t fsm, struct stat * st);
111
112 /**
113  * Read cpio header.
114  * @retval fsm          file path and stat info
115  * @retval st
116  * @return              0 on success
117  */
118 RPM_GNUC_INTERNAL
119 int cpioHeaderRead(FSM_t fsm, struct stat * st);
120
121 /** \ingroup payload
122  * Return formatted error message on payload handling failure.
123  * @param rc            error code
124  * @return              formatted error string
125  */
126 /* XXX should be RPM_GNUC_INTERNAL too but build/pack.c uses */
127 const char * cpioStrerror(int rc);
128
129 #ifdef __cplusplus
130 }
131 #endif
132
133 #endif  /* H_CPIO */