csomh / source-git / rpm

Forked from source-git/rpm 4 years ago
Clone
2ff057
#ifndef H_ARCHIVE
2ff057
#define H_ARCHIVE
2ff057
2ff057
/** \ingroup payload
2ff057
 * \file lib/rpmarchive.h
2ff057
 * File archive (aka payload) API.
2ff057
 */
2ff057
2ff057
#define RPMERR_CHECK_ERRNO    -32768
2ff057
2ff057
/** \ingroup payload
2ff057
 * Error codes for archive and file handling
2ff057
 */
2ff057
enum rpmfilesErrorCodes {
2ff057
	RPMERR_ITER_END		= -1,
2ff057
	RPMERR_BAD_MAGIC	= -2,
2ff057
	RPMERR_BAD_HEADER	= -3,
2ff057
	RPMERR_HDR_SIZE	= -4,
2ff057
	RPMERR_UNKNOWN_FILETYPE= -5,
2ff057
	RPMERR_MISSING_FILE	= -6,
2ff057
	RPMERR_DIGEST_MISMATCH	= -7,
2ff057
	RPMERR_INTERNAL	= -8,
2ff057
	RPMERR_UNMAPPED_FILE	= -9,
2ff057
	RPMERR_ENOENT		= -10,
2ff057
	RPMERR_ENOTEMPTY	= -11,
2ff057
	RPMERR_FILE_SIZE	= -12,
2ff057
	RPMERR_ITER_SKIP	= -13,
2ff057
	RPMERR_EXIST_AS_DIR	= -14,
2ff057
2ff057
	RPMERR_OPEN_FAILED	= -32768,
2ff057
	RPMERR_CHMOD_FAILED	= -32769,
2ff057
	RPMERR_CHOWN_FAILED	= -32770,
2ff057
	RPMERR_WRITE_FAILED	= -32771,
2ff057
	RPMERR_UTIME_FAILED	= -32772,
2ff057
	RPMERR_UNLINK_FAILED	= -32773,
2ff057
	RPMERR_RENAME_FAILED	= -32774,
2ff057
	RPMERR_SYMLINK_FAILED	= -32775,
2ff057
	RPMERR_STAT_FAILED	= -32776,
2ff057
	RPMERR_LSTAT_FAILED	= -32777,
2ff057
	RPMERR_MKDIR_FAILED	= -32778,
2ff057
	RPMERR_RMDIR_FAILED	= -32779,
2ff057
	RPMERR_MKNOD_FAILED	= -32780,
2ff057
	RPMERR_MKFIFO_FAILED	= -32781,
2ff057
	RPMERR_LINK_FAILED	= -32782,
2ff057
	RPMERR_READLINK_FAILED	= -32783,
2ff057
	RPMERR_READ_FAILED	= -32784,
2ff057
	RPMERR_COPY_FAILED	= -32785,
2ff057
	RPMERR_LSETFCON_FAILED	= -32786,
2ff057
	RPMERR_SETCAP_FAILED	= -32787,
2ff057
};
2ff057
2ff057
#ifdef __cplusplus
2ff057
extern "C" {
2ff057
#endif
2ff057
2ff057
/** \ingroup payload
2ff057
 * Return formatted error message on payload handling failure.
2ff057
 * @param rc		error code
2ff057
 * @return		formatted error string (malloced)
2ff057
 */
2ff057
char * rpmfileStrerror(int rc);
2ff057
2ff057
/** \ingroup payload
2ff057
 * Get new file iterator for writing the archive content.
2ff057
 * The returned rpmfi will only visit the files needing some content.
2ff057
 * You need to provide the content using rpmfiArchiveWrite() or
2ff057
 * rpmfiArchiveWriteFile(). Make sure to close the rpmfi with
2ff057
 * rpmfiArchiveClose() to get the trailer written.
2ff057
 * rpmfiSetFX() is not supported for this type of iterator.
2ff057
 * @param fd		file
2ff057
 * @param files         file info
2ff057
 * @return		new rpmfi
2ff057
 */
2ff057
rpmfi rpmfiNewArchiveWriter(FD_t fd, rpmfiles files);
2ff057
2ff057
/** \ingroup payload
2ff057
 * Get new file iterator for looping over the archive content.
2ff057
 * Returned rpmfi visites files in the order they are read from the payload.
2ff057
 * Content of the regular files can be retrieved with rpmfiArchiveRead() or
2ff057
 * rpmfiArchiveReadToFile() when they are visited with rpmfiNext().
2ff057
 * rpmfiSetFX() is not supported for this type of iterator.
2ff057
 * @param fd		file
2ff057
 * @param files         file info
2ff057
 * @param itype		how to handle hard links. See rpmFileIter.
2ff057
 * @return		new rpmfi
2ff057
 */
2ff057
    rpmfi rpmfiNewArchiveReader(FD_t fd, rpmfiles files, int itype);
2ff057
2ff057
/** \ingroup payload
2ff057
 * Close payload archive
2ff057
 * @param fi		file info
2ff057
 * @return		> 0 on error
2ff057
 */
2ff057
int rpmfiArchiveClose(rpmfi fi);
2ff057
2ff057
/** \ingroup payload
2ff057
 * Return current position in payload archive
2ff057
 * @param fi		file info
2ff057
 * @return		position
2ff057
 */
2ff057
rpm_loff_t rpmfiArchiveTell(rpmfi fi);
2ff057
2ff057
/** \ingroup payload
2ff057
 * Write content into current file in archive
2ff057
 * @param fi		file info
2ff057
 * @param buf		pointer to content
2ff057
 * @param size		number of bytes to write
2ff057
 * @return		bytes actually written
2ff057
 */
2ff057
size_t rpmfiArchiveWrite(rpmfi fi, const void * buf, size_t size);
2ff057
2ff057
/** \ingroup payload
2ff057
 * Write content from given file into current file in archive
2ff057
 * @param fi		file info
2ff057
 * @param fd		file descriptor of file to read
2ff057
 * @return		> 0 on error
2ff057
 */
2ff057
int rpmfiArchiveWriteFile(rpmfi fi, FD_t fd);
2ff057
2ff057
/** \ingroup payload
2ff057
 * Read content from current file in archive
2ff057
 * @param fi		file info
2ff057
 * @param buf		pointer to buffer
2ff057
 * @param size		number of bytes to read
2ff057
 * @return		bytes actually read
2ff057
 */
2ff057
size_t rpmfiArchiveRead(rpmfi fi, void * buf, size_t size);
2ff057
2ff057
/** \ingroup payload
2ff057
 * Has current file content stored in the archive
2ff057
 * @param fi            file info
2ff057
 * @ return		1 for regular files but 0 for hardlinks without content
2ff057
 */
2ff057
int rpmfiArchiveHasContent(rpmfi fi);
2ff057
2ff057
/** \ingroup payload
2ff057
 * Write content from current file in archive to a file
2ff057
 * @param fi		file info
2ff057
 * @param fd		file descriptor of file to write to
2ff057
 * @param nodigest	omit checksum check if 1
2ff057
 * @return		> 0 on error
2ff057
 */
2ff057
int rpmfiArchiveReadToFile(rpmfi fi, FD_t fd, int nodigest);
2ff057
2ff057
#ifdef __cplusplus
2ff057
}
2ff057
#endif
2ff057
2ff057
#endif	/* H_ARCHIVE */