1 #ifndef H_ARCHIVE
2 #define H_ARCHIVE
3 
4 /** \ingroup payload
5  * \file lib/rpmarchive.h
6  * File archive (aka payload) API.
7  */
8 
9 #define RPMERR_CHECK_ERRNO    -32768
10 
11 /** \ingroup payload
12  * Error codes for archive and file handling
13  */
14 enum rpmfilesErrorCodes {
15 	RPMERR_ITER_END		= -1,
16 	RPMERR_BAD_MAGIC	= -2,
17 	RPMERR_BAD_HEADER	= -3,
18 	RPMERR_HDR_SIZE	= -4,
19 	RPMERR_UNKNOWN_FILETYPE= -5,
20 	RPMERR_MISSING_FILE	= -6,
21 	RPMERR_DIGEST_MISMATCH	= -7,
22 	RPMERR_INTERNAL	= -8,
23 	RPMERR_UNMAPPED_FILE	= -9,
24 	RPMERR_ENOENT		= -10,
25 	RPMERR_ENOTEMPTY	= -11,
26 	RPMERR_FILE_SIZE	= -12,
27 	RPMERR_ITER_SKIP	= -13,
28 	RPMERR_EXIST_AS_DIR	= -14,
29 
30 	RPMERR_OPEN_FAILED	= -32768,
31 	RPMERR_CHMOD_FAILED	= -32769,
32 	RPMERR_CHOWN_FAILED	= -32770,
33 	RPMERR_WRITE_FAILED	= -32771,
34 	RPMERR_UTIME_FAILED	= -32772,
35 	RPMERR_UNLINK_FAILED	= -32773,
36 	RPMERR_RENAME_FAILED	= -32774,
37 	RPMERR_SYMLINK_FAILED	= -32775,
38 	RPMERR_STAT_FAILED	= -32776,
39 	RPMERR_LSTAT_FAILED	= -32777,
40 	RPMERR_MKDIR_FAILED	= -32778,
41 	RPMERR_RMDIR_FAILED	= -32779,
42 	RPMERR_MKNOD_FAILED	= -32780,
43 	RPMERR_MKFIFO_FAILED	= -32781,
44 	RPMERR_LINK_FAILED	= -32782,
45 	RPMERR_READLINK_FAILED	= -32783,
46 	RPMERR_READ_FAILED	= -32784,
47 	RPMERR_COPY_FAILED	= -32785,
48 	RPMERR_LSETFCON_FAILED	= -32786,
49 	RPMERR_SETCAP_FAILED	= -32787,
50 };
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 /** \ingroup payload
57  * Return formatted error message on payload handling failure.
58  * @param rc		error code
59  * @return		formatted error string (malloced)
60  */
61 char * rpmfileStrerror(int rc);
62 
63 /** \ingroup payload
64  * Get new file iterator for writing the archive content.
65  * The returned rpmfi will only visit the files needing some content.
66  * You need to provide the content using rpmfiArchiveWrite() or
67  * rpmfiArchiveWriteFile(). Make sure to close the rpmfi with
68  * rpmfiArchiveClose() to get the trailer written.
69  * rpmfiSetFX() is not supported for this type of iterator.
70  * @param fd		file
71  * @param files         file info
72  * @return		new rpmfi
73  */
74 rpmfi rpmfiNewArchiveWriter(FD_t fd, rpmfiles files);
75 
76 /** \ingroup payload
77  * Get new file iterator for looping over the archive content.
78  * Returned rpmfi visites files in the order they are read from the payload.
79  * Content of the regular files can be retrieved with rpmfiArchiveRead() or
80  * rpmfiArchiveReadToFile() when they are visited with rpmfiNext().
81  * rpmfiSetFX() is not supported for this type of iterator.
82  * @param fd		file
83  * @param files         file info
84  * @param itype		how to handle hard links. See rpmFileIter.
85  * @return		new rpmfi
86  */
87     rpmfi rpmfiNewArchiveReader(FD_t fd, rpmfiles files, int itype);
88 
89 /** \ingroup payload
90  * Close payload archive
91  * @param fi		file info
92  * @return		> 0 on error
93  */
94 int rpmfiArchiveClose(rpmfi fi);
95 
96 /** \ingroup payload
97  * Return current position in payload archive
98  * @param fi		file info
99  * @return		position
100  */
101 rpm_loff_t rpmfiArchiveTell(rpmfi fi);
102 
103 /** \ingroup payload
104  * Write content into current file in archive
105  * @param fi		file info
106  * @param buf		pointer to content
107  * @param size		number of bytes to write
108  * @return		bytes actually written
109  */
110 size_t rpmfiArchiveWrite(rpmfi fi, const void * buf, size_t size);
111 
112 /** \ingroup payload
113  * Write content from given file into current file in archive
114  * @param fi		file info
115  * @param fd		file descriptor of file to read
116  * @return		> 0 on error
117  */
118 int rpmfiArchiveWriteFile(rpmfi fi, FD_t fd);
119 
120 /** \ingroup payload
121  * Read content from current file in archive
122  * @param fi		file info
123  * @param buf		pointer to buffer
124  * @param size		number of bytes to read
125  * @return		bytes actually read, -1 on error
126  */
127 ssize_t rpmfiArchiveRead(rpmfi fi, void * buf, size_t size);
128 
129 /** \ingroup payload
130  * Has current file content stored in the archive
131  * @param fi            file info
132  * @ return		1 for regular files but 0 for hardlinks without content
133  */
134 int rpmfiArchiveHasContent(rpmfi fi);
135 
136 /** \ingroup payload
137  * Write content from current file in archive to a file
138  * @param fi		file info
139  * @param fd		file descriptor of file to write to
140  * @param nodigest	omit checksum check if 1
141  * @return		> 0 on error
142  */
143 int rpmfiArchiveReadToFile(rpmfi fi, FD_t fd, int nodigest);
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #endif	/* H_ARCHIVE */
150