drpm
A library for making, reading and applying deltarpm packages
Loading...
Searching...
No Matches
drpm.h
Go to the documentation of this file.
1/*
2 Authors:
3 Pavel Tobias <ptobias@redhat.com>
4 Matej Chalk <mchalk@redhat.com>
5
6 Copyright (C) 2014 Red Hat
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22/**
23 * @file
24 * @author Pavel Tobias <ptobias@redhat.com>
25 * @author Matej Chalk <mchalk@redhat.com>
26 * @date 2014-2016
27 * @copyright Copyright &copy; 2014-2016 Red Hat, Inc.
28 * This project is released under the GNU Lesser Public License.
29 */
30
31#ifndef _DRPM_H_
32#define _DRPM_H_
33
34#ifdef HAVE_CONFIG_H
35#include <config.h>
36#endif
37
38#if __GNUC__ >= 4
39#define DRPM_VISIBLE __attribute__((visibility("default")))
40#else
41#define DRPM_VISIBLE
42#endif
43
44/**
45 * @defgroup drpmMake DRPM Make
46 * Tools for creating a DeltaRPM file from two RPM files,
47 * providing the same functionality as
48 * [makedeltarpm(8)](http://linux.die.net/man/8/makedeltarpm).
49 * @{
50 * @defgroup drpmMakeOptions DRPM Make Options
51 * Tools for customizing DeltaRPM creation.
52 * @}
53 *
54 * @defgroup drpmApply DRPM Apply
55 * Tools for applying a DeltaRPM file to re-create a new RPM file
56 * (from an old RPM file or from filesystem data),
57 * providing the same functionality as
58 * [applydeltarpm(8)](http://linux.die.net/man/8/applydeltarpm).
59 * @{
60 * @defgroup drpmCheck DRPM Check
61 * Tools for checking if the reconstruction is possible
62 * (like <tt>applydeltarpm { -c | -C }</tt>).
63 * @}
64 *
65 * @defgroup drpmRead DRPM Read
66 * Tools for extracting information from DeltaRPM files.
67 */
68
69/**
70 * @name Errors / Return values
71 * @{
72 */
73#define DRPM_ERR_OK 0 /**< no error */
74#define DRPM_ERR_MEMORY 1 /**< memory allocation error */
75#define DRPM_ERR_ARGS 2 /**< bad arguments */
76#define DRPM_ERR_IO 3 /**< I/O error */
77#define DRPM_ERR_FORMAT 4 /**< wrong file format */
78#define DRPM_ERR_CONFIG 5 /**< misconfigured external library */
79#define DRPM_ERR_OTHER 6 /**< unspecified/unknown error */
80#define DRPM_ERR_OVERFLOW 7 /**< file too large */
81#define DRPM_ERR_PROG 8 /**< internal programming error */
82#define DRPM_ERR_MISMATCH 9 /**< file changed */
83#define DRPM_ERR_NOINSTALL 10 /**< old RPM not installed */
84/** @} */
85
86/**
87 * @name Delta Types
88 * @{
89 */
90#define DRPM_TYPE_STANDARD 0 /**< standard deltarpm */
91#define DRPM_TYPE_RPMONLY 1 /**< rpm-only deltarpm */
92/** @} */
93
94/**
95 * @name Compression Types
96 * @{
97 */
98#define DRPM_COMP_NONE 0 /**< no compression */
99#define DRPM_COMP_GZIP 1 /**< gzip */
100#define DRPM_COMP_BZIP2 2 /**< bzip2 */
101#define DRPM_COMP_LZMA 3 /**< lzma */
102#define DRPM_COMP_XZ 4 /**< xz */
103#ifdef HAVE_LZLIB_DEVEL
104/**
105 * @brief lzip
106 *
107 * The original deltarpm implementation does not support lzip.
108 * DeltaRPM packages compressed with lzip will work within this API, but
109 * will not be backwards-compatible.
110 *
111 * This compression algorithm is supported because newer versions
112 * of RPM packages may be compressed with lzip.
113 */
114#endif
115#define DRPM_COMP_LZIP 5 /**< lzip */
116#define DRPM_COMP_ZSTD 6 /**< zstd */
117/** @} */
118
119/**
120 * @name Info Tags
121 * @{
122 */
123#define DRPM_TAG_FILENAME 0 /**< file name */
124#define DRPM_TAG_VERSION 1 /**< version */
125#define DRPM_TAG_TYPE 2 /**< delta type */
126#define DRPM_TAG_COMP 3 /**< compression type */
127#define DRPM_TAG_SEQUENCE 4 /**< sequence */
128#define DRPM_TAG_SRCNEVR 5 /**< source NEVR (name-epoch:version-release) */
129#define DRPM_TAG_TGTNEVR 6 /**< target NEVR (name-epoch:version-release) */
130#define DRPM_TAG_TGTSIZE 7 /**< target size */
131#define DRPM_TAG_TGTMD5 8 /**< target MD5 */
132#define DRPM_TAG_TGTCOMP 9 /**< target compression type */
133#define DRPM_TAG_TGTCOMPPARAM 10 /**< target compression parameter block */
134#define DRPM_TAG_TGTHEADERLEN 11 /**< target header length */
135#define DRPM_TAG_ADJELEMS 12 /**< offset adjustment elements */
136#define DRPM_TAG_TGTLEAD 13 /**< lead/signatures of the new rpm */
137#define DRPM_TAG_PAYLOADFMTOFF 14 /**< payload format offset */
138#define DRPM_TAG_INTCOPIES 15 /**< copies from internal data (number of external copies to do before internal copy & length of internal copy) */
139#define DRPM_TAG_EXTCOPIES 16 /**< copies from external data (offset adjustment of external copy & length of external copy) */
140#define DRPM_TAG_EXTDATALEN 17 /**< length of external data */
141#define DRPM_TAG_INTDATALEN 18 /**< length of internal data */
142/** @} */
143
144/**
145 * @name Compression Levels
146 * @{
147 */
148#define DRPM_COMP_LEVEL_DEFAULT 0 /**< default compression level for given compression type */
149/** @} */
150
151/**
152 * @name Check Modes
153 * @{
154 */
155#define DRPM_CHECK_NONE 0 /**< no file checking */
156#define DRPM_CHECK_FULL 1 /**< full (i.e.\ slow) on-disk checking */
157#define DRPM_CHECK_FILESIZES 2 /**< only checking if filesizes have changed */
158/** @} */
159
160/**
161 * @brief DeltaRPM package info
162 * @ingroup drpmRead
163 */
164typedef struct drpm drpm;
165
166/**
167 * @brief Options for drpm_make()
168 * @ingroup drpmMakeOptions
169 */
171
172/**
173 * @ingroup drpmApply
174 * @brief Applies a DeltaRPM to an old RPM or on-disk data to re-create a new RPM.
175 * @param [in] oldrpm Name of old RPM file (if @c NULL, filesystem data is used).
176 * @param [in] deltarpm Name of DeltaRPM file.
177 * @param [in] newrpm Name of new RPM file to be (re-)created.
178 * @return Error code.
179 */
180DRPM_VISIBLE
181int drpm_apply(const char *oldrpm, const char *deltarpm, const char *newrpm);
182
183/**
184 * @ingroup drpmCheck
185 * @brief Checks if the reconstruction is possible based on DeltaRPM file.
186 * @param [in] deltarpm Name of DeltaRPM file.
187 * @param [in] checkmode Full check or filesize changes only.
188 * @return Error code.
189 * @see DRPM_CHECK_FULL, DRPM_CHECK_FILESIZES
190 */
191DRPM_VISIBLE
192int drpm_check(const char *deltarpm, int checkmode);
193
194/**
195 * @ingroup drpmCheck
196 * @brief Checks if the reconstruction is possible based on sequence ID.
197 * @param [in] oldrpm Name of old RPM file (if @c NULL, filesystem data is used).
198 * @param [in] sequence Sequence ID of the DeltaRPM.
199 * @param [in] checkmode Full check or filesize changes only.
200 * @return Error code.
201 * @see DRPM_CHECK_FULL, DRPM_CHECK_FILESIZES
202 */
203DRPM_VISIBLE
204int drpm_check_sequence(const char *oldrpm, const char *sequence, int checkmode);
205
206/**
207 * @ingroup drpmMake
208 * @brief Creates a DeltaRPM from two RPMs.
209 * The DeltaRPM can later be used to recreate the new RPM from either
210 * filesystem data or the old RPM.
211 *
212 * Does the same thing as the
213 * [makedeltarpm(8)](http://linux.die.net/man/8/makedeltarpm)
214 * command-line utility.
215 *
216 * Examples of function calls (without error handling):
217 * @code
218 * // makedeltarpm foo.rpm goo.rpm fg.drpm
219 * drpm_make("foo.rpm", "goo.rpm", "fg.drpm", NULL);
220 * @endcode
221 * @code
222 * // makedeltarpm -r -z xz.6 -s seqfile.txt foo.rpm goo.rpm fg.drpm
223 *
224 * drpm_make_options *opts;
225 *
226 * drpm_make_options_init(&opts);
227 * drpm_make_options_set_type(opts, DRPM_TYPE_RPMONLY);
228 * drpm_make_options_set_seqfile(opts, "seqfile.txt");
229 * drpm_make_options_set_delta_comp(opts, DRPM_COMP_XZ, 6);
230 *
231 * drpm_make("foo.rpm", "goo.rpm", "fg.drpm", &opts);
232 *
233 * drpm_make_options_destroy(&opts);
234 * @endcode
235 * @code
236 * // makedeltarpm -V 2 -z gzip,off -p foo-print.rpml foo-patch.rpml foo.rpm goo.rpm fg.drpm
237 *
238 * drpm_make_options *opts;
239 *
240 * drpm_make_options_init(&opts);
241 * drpm_make_options_set_version(opts, 2);
242 * drpm_make_options_set_delta_comp(opts, DRPM_COMP_GZIP, DRPM_COMP_LEVEL_DEFAULT);
243 * drpm_make_options_forbid_addblk(opts);
244 * drpm_make_options_add_patches(opts, "foo-print.rpml", "foo-patch.rpml");
245 *
246 * drpm_make("foo.rpm", "goo.rpm", "fg.drpm", &opts);
247 *
248 * drpm_make_options_destroy(&opts);
249 * @endcode
250 * @code
251 * // makedeltarpm -z uncompressed,bzip2.9 foo.rpm goo.rpm fg.drpm
252 *
253 * drpm_make_options *opts;
254 *
255 * drpm_make_options_init(&opts);
256 * drpm_make_options_set_delta_comp(opts, DRPM_COMP_NONE, 0);
257 * drpm_make_options_set_addblk_comp(opts, DRPM_COMP_BZIP2, 9);
258 *
259 * drpm_make("foo.rpm", "goo.rpm", "fg.drpm", &opts);
260 *
261 * drpm_make_options_destroy(&opts);
262 * @endcode
263 * @code
264 * // makedeltarpm -u foo.rpm foo.drpm
265 * drpm_make("foo.rpm", NULL, "foo.drpm", NULL);
266 * @endcode
267 * @param [in] oldrpm Name of old RPM file.
268 * @param [in] newrpm Name of new RPM file.
269 * @param [in] deltarpm Name of DeltaRPM file to be created.
270 * @param [in] opts Options (if @c NULL, defaults used).
271 * @return Error code.
272 * @note If either @p old_rpm or @p new_rpm is @c NULL, an "identity"
273 * deltarpm is created (may be useful to just replace the signature
274 * of an RPM or to reconstruct an RPM from the filesystem).
275 * @warning If not @c NULL, @p opts should have been initialized with
276 * drpm_make_options_init(), otherwise behaviour is undefined.
277 */
278DRPM_VISIBLE
279int drpm_make(const char *oldrpm, const char *newrpm, const char *deltarpm, const drpm_make_options *opts);
280
281/**
282 * @addtogroup drpmMakeOptions
283 * @{
284 */
285
286/**
287 * @brief Initializes ::drpm_make_options with default options.
288 * Passing @p *opts to drpm_make() immediately after would have the same
289 * effect as passing @c NULL instead.
290 * @param [out] opts Address of options structure pointer.
291 * @return Error code.
292 * @see drpm_make()
293 */
294DRPM_VISIBLE
296
297/**
298 * @brief Frees ::drpm_make_options.
299 * @param [out] opts Address of options structure pointer.
300 * @return Error code.
301 * @see drpm_make()
302 */
303DRPM_VISIBLE
305
306/**
307 * @brief Resets options to default values.
308 * Passing @p opts to drpm_make() immediately after would have the same
309 * effect as passing @c NULL instead.
310 * @param [out] opts Structure specifying options for drpm_make().
311 * @return Error code.
312 * @see drpm_make()
313 */
314DRPM_VISIBLE
316
317/**
318 * @brief Copies ::drpm_make_options.
319 * Copies data from @p src to @p dst.
320 * @param [out] dst Destination options.
321 * @param [in] src Source options.
322 * @return Error code.
323 * @warning @p dst should have also been initialized with
324 * drpm_make_options_init() previously, otherwise behaviour is undefined.
325 * @see drpm_make()
326 */
327DRPM_VISIBLE
329
330/**
331 * @brief Sets DeltaRPM type.
332 * There are two types of DeltaRPMs: standard and "rpm-only".
333 * The latter was introduced in version 3.
334 * It does not work with filesystem data but is smaller and faster to
335 * combine.
336 * @param [out] opts Structure specifying options for drpm_make().
337 * @param [in] type Type of deltarpm.
338 * @return Error code.
339 * @see drpm_make()
340 * @see DRPM_TYPE_STANDARD, DRPM_TYPE_RPMONLY
341 */
342DRPM_VISIBLE
343int drpm_make_options_set_type(drpm_make_options *opts, unsigned short type);
344
345/**
346 * @brief Sets DeltaRPM version.
347 * The default DeltaRPM format is V3, but an older version may also be
348 * specified.
349 * @param [out] opts Structure specifying options for drpm_make().
350 * @param [in] version Version (1-3).
351 * @return Error code.
352 * @see drpm_make()
353 */
354DRPM_VISIBLE
355int drpm_make_options_set_version(drpm_make_options *opts, unsigned short version);
356
357/**
358 * @brief Sets DeltaRPM compression type and level.
359 * By default, the compression method is the same as used in the new RPM.
360 * @param [out] opts Structure specifying options for drpm_make().
361 * @param [in] comp Compression type.
362 * @param [in] level Compression level (1-9 or default).
363 * @return Error code.
364 * @see drpm_make()
365 * @see DRPM_COMP_NONE, DRPM_COMP_GZIP, DRPM_COMP_BZIP2,
366 * DRPM_COMP_LZMA, DRPM_COMP_XZ
367 * @see DRPM_COMP_LEVEL_DEFAULT
368 */
369DRPM_VISIBLE
370int drpm_make_options_set_delta_comp(drpm_make_options *opts, unsigned short comp, unsigned short level);
371
372/**
373 * @brief DeltaRPM compression method is the same as used in the new RPM.
374 * May be used to reset DeltaRPM compression option after previously
375 * calling drpm_make_options_delta_comp().
376 * @param [out] opts Structure specifying options for drpm_make().
377 * @return Error code.
378 * @see drpm_make()
379 */
380DRPM_VISIBLE
382
383/**
384 * @brief Forbids add block creation.
385 * An "add block" is a highly compressible block used to store
386 * bytewise subtractions of segments where less than half the bytes
387 * have changed.
388 * It is used in re-creating the new RPM with drpm_apply(), unless this
389 * functions is called to tell drpm_make() not to create an add block.
390 * @param [out] opts Structure specifying options for drpm_make().
391 * @return Error code.
392 * @see drpm_make()
393 */
394DRPM_VISIBLE
396
397/**
398 * @brief Sets add block compression type and level.
399 * The default add block compression type is bzip2, which gives the best
400 * results.
401 * @param [out] opts Structure specifying options for drpm_make().
402 * @param [in] comp Compression type.
403 * @param [in] level Compression level (1-9 or default).
404 * @return Error code.
405 * @see drpm_make()
406 * @see DRPM_COMP_NONE, DRPM_COMP_GZIP, DRPM_COMP_BZIP2,
407 * DRPM_COMP_LZMA, DRPM_COMP_XZ
408 * @see DRPM_COMP_LEVEL_DEFAULT
409 */
410DRPM_VISIBLE
411int drpm_make_options_set_addblk_comp(drpm_make_options *opts, unsigned short comp, unsigned short level);
412
413/**
414 * @brief Specifies file to which to write DeltaRPM sequence ID.
415 * If a valid file name is given, drpm_make() will write out
416 * the sequence ID to the file @p seqfile.
417 * @param [out] opts Structure specifying options for drpm_make().
418 * @param [in] seqfile Name of file to which to write out sequence.
419 * @return Error code.
420 * @note If @p seqfile is @c NULL, sequence ID shall not be written.
421 * @see drpm_make()
422 */
423DRPM_VISIBLE
424int drpm_make_options_set_seqfile(drpm_make_options *opts, const char *seqfile);
425
426/**
427 * @brief Requests incorporation of RPM patch files for the old RPM.
428 * This option enables the usage of patch RPMs, telling drpm_make() to
429 * exclude all files that were not included in the patch RPM but are not
430 * bytewise identical to the ones in the old RPM.
431 * @param [out] opts Structure specifying options for drpm_make().
432 * @param [in] oldrpmprint The rpm-print of the old RPM.
433 * @param [in] oldpatchrpm The created patch RPM.
434 * @return Error code.
435 * @see drpm_make()
436 */
437DRPM_VISIBLE
438int drpm_make_options_add_patches(drpm_make_options *opts, const char *oldrpmprint, const char *oldpatchrpm);
439
440/**
441 * @brief Limits memory usage.
442 * As drpm_make() normally needs about three to four times the size of
443 * the rpm's uncompressed payload, this option may be used to enable
444 * a sliding block algorithm that needs @p mbytes megabytes of memory.
445 * This trades memory usage with the size of the created DeltaRPM.
446 * @param [out] opts Structure specifying options for drpm_make().
447 * @param [in] mbytes Permitted memory usage in megabytes.
448 * @return Error code.
449 * @see drpm_make()
450 */
451//int drpm_make_options_set_memlimit(drpm_make_options *opts, unsigned mbytes);
452
453/** @} */
454
455/**
456 * @addtogroup drpmRead
457 * @{
458 */
459
460/**
461 * @brief Reads information from a DeltaRPM.
462 * Reads information from DeltaRPM package @p filename into @p *delta.
463 * Example of usage:
464 * @code
465 * drpm *delta = NULL;
466 *
467 * int error = drpm_read(&delta, "foo.drpm");
468 *
469 * if (error != DRPM_ERR_OK) {
470 * fprintf(stderr, "drpm error: %s\n", drpm_strerror(error));
471 * return;
472 * }
473 * @endcode
474 * @param [out] delta DeltaRPM to be filled with info.
475 * @param [in] filename Name of DeltaRPM file whose data is to be read.
476 * @return Error code.
477 * @note Memory allocated by calling drpm_read() should later be freed
478 * by calling drpm_destroy().
479 */
480DRPM_VISIBLE
481int drpm_read(drpm **delta, const char *filename);
482
483/**
484 * @brief Fetches information representable as an unsigned integer.
485 * Fetches information identified by @p tag from @p delta and copies it
486 * to address pointed to by @p target.
487 *
488 * Example of usage:
489 * @code
490 * unsigned type;
491 *
492 * int error = drpm_get_uint(delta, DRPM_TAG_TYPE, &type);
493 *
494 * if (error != DRPM_ERR_OK) {
495 * fprintf(stderr, "drpm error: %s\n", drpm_strerror(error));
496 * return;
497 * }
498 *
499 * printf("This is a %s deltarpm\n", (type == DRPM_TYPE_STANDARD) ? "standard" : "rpm-only");
500 * @endcode
501 * @param [in] delta DeltaRPM containing required info.
502 * @param [in] tag Identifies which info is required.
503 * @param [out] target Tagged info will be copied here.
504 * @return error number
505 * @warning @p delta should have been previously initialized with
506 * drpm_read(), otherwise behaviour is undefined.
507 * @see DRPM_TAG_VERSION
508 * @see DRPM_TAG_TYPE
509 * @see DRPM_TAG_COMP
510 * @see DRPM_TAG_TGTCOMP
511 */
512DRPM_VISIBLE
513int drpm_get_uint(drpm *delta, int tag, unsigned *target);
514
515/**
516 * @brief Fetches information representable as an unsigned long integer.
517 * Fetches information identified by @p tag from @p delta and copies it
518 * to address pointed to by @p target.
519 *
520 * Example of usage:
521 * @code
522 * unsigned long tgt_size;
523 *
524 * int error = drpm_get_ulong(delta, DRPM_TAG_TGTSIZE, &tgt_size);
525 *
526 * if (error != DRPM_ERR_OK) {
527 * fprintf(stderr, "drpm error: %s\n", drpm_strerror(error));
528 * return;
529 * }
530 *
531 * printf("Size of new RPM: %lu\n", tgt_size);
532 * @endcode
533 * @param [in] delta Deltarpm containing required info.
534 * @param [in] tag Identifies which info is required.
535 * @param [out] target Tagged info will be copied here.
536 * @return Error code.
537 * @warning @p delta should have been previously initialized with
538 * drpm_read(), otherwise behaviour is undefined.
539 * @see DRPM_TAG_TGTSIZE
540 * @see DRPM_TAG_TGTHEADERLEN
541 * @see DRPM_TAG_PAYLOADFMTOFF
542 */
543DRPM_VISIBLE
544int drpm_get_ulong(drpm *delta, int tag, unsigned long *target);
545
546/**
547 * @brief Fetches information representable as an unsigned long long integer.
548 * Fetches information identified by @p tag from @p delta and copies it
549 * to address pointed to by @p target.
550 *
551 * Example of usage:
552 * @code
553 * unsigned long long int_data_len;
554 *
555 * int error = drpm_get_ullong(delta, DRPM_TAG_INTDATALEN, &int_data_len);
556 *
557 * if (error != DRPM_ERR_OK) {
558 * fprintf(stderr, "drpm error: %s\n", drpm_strerror(error));
559 * return;
560 * }
561 *
562 * printf("Length of internal data: %llu\n", int_data_len);
563 * @endcode
564 * @param [in] delta Deltarpm containing required info.
565 * @param [in] tag Identifies which info is required.
566 * @param [out] target Tagged info will be copied here.
567 * @return Error code.
568 * @warning @p delta should have been previously initialized with
569 * drpm_read(), otherwise behaviour is undefined.
570 * @see DRPM_TAG_EXTDATALEN
571 * @see DRPM_TAG_INTDATALEN
572 */
573DRPM_VISIBLE
574int drpm_get_ullong(drpm *delta, int tag, unsigned long long *target);
575
576/**
577 * @brief Fetches information representable as a string.
578 * Fetches string-type information identified by @p tag from @p delta,
579 * copies it to space previously allocated by the function itself and
580 * saves the address to @p *target.
581 *
582 * Example of usage:
583 * @code
584 * char *tgt_nevr;
585 *
586 * int error = drpm_get_string(delta, DRPM_TAG_TGTNEVR, &tgt_nevr);
587 *
588 * if (error != DRPM_ERR_OK) {
589 * fprintf(stderr, "drpm error: %s\n", drpm_strerror(error));
590 * return;
591 * }
592 *
593 * printf("Target NEVR: %s\n", tgt_nevr);
594 *
595 * free(tgt_nevr);
596 * @endcode
597 * @param [in] delta Deltarpm containing required info.
598 * @param [in] tag Identifies which info is required.
599 * @param [out] target Tagged info will be copied here.
600 * @return Error code.
601 * @note @p *target should be freed manually by the user when no longer needed.
602 * @warning @p delta should have been previously initialized with
603 * drpm_read(), otherwise behaviour is undefined.
604 * @see DRPM_TAG_FILENAME
605 * @see DRPM_TAG_SEQUENCE
606 * @see DRPM_TAG_SRCNEVR
607 * @see DRPM_TAG_TGTNEVR
608 * @see DRPM_TAG_TGTMD5
609 * @see DRPM_TAG_TGTCOMPPARAM
610 * @see DRPM_TAG_TGTLEAD
611 */
612DRPM_VISIBLE
613int drpm_get_string(drpm *delta, int tag, char **target);
614
615/**
616 * @brief Fetches information representable as an array of unsigned long integers.
617 * Fetches information identified by @p tag from @p delta,
618 * copies it to space previously allocated by the function itself,
619 * saves the address to @p *target and stores size in @p *size.
620 *
621 * Example of usage:
622 * @code
623 * unsigned long *ext_copies;
624 * unsigned long ext_copies_size;
625 *
626 * int error = drpm_get_ulong_array(delta, DRPM_TAG_EXTCOPIES, &ext_copies, &ext_copies_size);
627 *
628 * if (error != DRPM_ERR_OK) {
629 * fprintf(stderr, "drpm error: %s\n", drpm_strerror(error));
630 * return;
631 * }
632 *
633 * for (unsigned long i = 1; i < ext_copies_size; i += 2)
634 * printf("External copy: offset adjustment = %lu, length = %lu\n", ext_copies[i-1], ext_copies[i]);
635 *
636 * free(ext_copies);
637 * @endcode
638 * @param [in] delta Deltarpm containing required info.
639 * @param [in] tag Identifies which info is required.
640 * @param [out] target Tagged info will be copied here.
641 * @param [out] size Size of array will be copied here.
642 * @return Error code.
643 * @note @p *target should be freed manually by the user when no longer needed.
644 * @warning @p delta should have been previously initialized with
645 * drpm_read(), otherwise behaviour is undefined.
646 * @see DRPM_TAG_ADJELEMS
647 * @see DRPM_TAG_INTCOPIES
648 * @see DRPM_TAG_EXTCOPIES
649 */
650DRPM_VISIBLE
651int drpm_get_ulong_array(drpm *delta, int tag, unsigned long **target, unsigned long *size);
652
653/**
654 * @brief Frees memory allocated by drpm_read().
655 * Frees memory pointed to by @p *delta and sets @p *delta to @c NULL.
656 *
657 * Example of usage:
658 * @code
659 * int error = drpm_destroy(&delta);
660 *
661 * if (error != DRPM_ERR_OK) {
662 * fprintf(stderr, "drpm error: %s\n", drpm_strerror(error));
663 * return;
664 * }
665 * @endcode
666 * @param [out] delta Deltarpm that is to be freed.
667 * @return Error code.
668 * @warning @p delta should have been previously initialized with
669 * drpm_read(), otherwise behaviour is undefined.
670 */
671DRPM_VISIBLE
672int drpm_destroy(drpm **delta);
673
674/** @} */
675
676/**
677 * @brief Returns description of error code as a string.
678 * Works very similarly to
679 * [strerror(3)](http://linux.die.net/man/3/strerror).
680 * @param [in] error error code
681 * @return error description
682 */
683DRPM_VISIBLE
684const char *drpm_strerror(int error);
685
686#endif
DRPM_VISIBLE const char * drpm_strerror(int error)
Returns description of error code as a string.
DRPM_VISIBLE int drpm_apply(const char *oldrpm, const char *deltarpm, const char *newrpm)
Applies a DeltaRPM to an old RPM or on-disk data to re-create a new RPM.
DRPM_VISIBLE int drpm_check_sequence(const char *oldrpm, const char *sequence, int checkmode)
Checks if the reconstruction is possible based on sequence ID.
DRPM_VISIBLE int drpm_check(const char *deltarpm, int checkmode)
Checks if the reconstruction is possible based on DeltaRPM file.
struct drpm_make_options drpm_make_options
Options for drpm_make()
Definition drpm.h:170
DRPM_VISIBLE int drpm_make_options_set_version(drpm_make_options *opts, unsigned short version)
Sets DeltaRPM version.
DRPM_VISIBLE int drpm_make_options_set_delta_comp(drpm_make_options *opts, unsigned short comp, unsigned short level)
Sets DeltaRPM compression type and level.
DRPM_VISIBLE int drpm_make_options_set_seqfile(drpm_make_options *opts, const char *seqfile)
Specifies file to which to write DeltaRPM sequence ID.
DRPM_VISIBLE int drpm_make_options_set_addblk_comp(drpm_make_options *opts, unsigned short comp, unsigned short level)
Sets add block compression type and level.
DRPM_VISIBLE int drpm_make_options_copy(drpm_make_options *dst, const drpm_make_options *src)
Copies drpm_make_options.
DRPM_VISIBLE int drpm_make_options_init(drpm_make_options **opts)
Initializes drpm_make_options with default options.
DRPM_VISIBLE int drpm_make_options_get_delta_comp_from_rpm(drpm_make_options *opts)
DeltaRPM compression method is the same as used in the new RPM.
DRPM_VISIBLE int drpm_make_options_set_type(drpm_make_options *opts, unsigned short type)
Sets DeltaRPM type.
DRPM_VISIBLE int drpm_make_options_destroy(drpm_make_options **opts)
Frees drpm_make_options.
DRPM_VISIBLE int drpm_make_options_defaults(drpm_make_options *opts)
Resets options to default values.
DRPM_VISIBLE int drpm_make_options_forbid_addblk(drpm_make_options *opts)
Forbids add block creation.
DRPM_VISIBLE int drpm_make_options_add_patches(drpm_make_options *opts, const char *oldrpmprint, const char *oldpatchrpm)
Requests incorporation of RPM patch files for the old RPM.
DRPM_VISIBLE int drpm_make(const char *oldrpm, const char *newrpm, const char *deltarpm, const drpm_make_options *opts)
Creates a DeltaRPM from two RPMs.
DRPM_VISIBLE int drpm_get_ulong(drpm *delta, int tag, unsigned long *target)
Fetches information representable as an unsigned long integer.
DRPM_VISIBLE int drpm_get_string(drpm *delta, int tag, char **target)
Fetches information representable as a string.
DRPM_VISIBLE int drpm_get_ullong(drpm *delta, int tag, unsigned long long *target)
Fetches information representable as an unsigned long long integer.
DRPM_VISIBLE int drpm_read(drpm **delta, const char *filename)
Reads information from a DeltaRPM.
DRPM_VISIBLE int drpm_get_ulong_array(drpm *delta, int tag, unsigned long **target, unsigned long *size)
Fetches information representable as an array of unsigned long integers.
DRPM_VISIBLE int drpm_destroy(drpm **delta)
Frees memory allocated by drpm_read().
struct drpm drpm
DeltaRPM package info.
Definition drpm.h:164
DRPM_VISIBLE int drpm_get_uint(drpm *delta, int tag, unsigned *target)
Fetches information representable as an unsigned integer.