21.2. rpmlib Functions

There are more than sixty different functions in rpmlib. The tasks they perform range from low-level database record traversal, to high-level package manipulation. We've grouped the functions into different categories for easy reference.

21.2.1. Error Handling

The functions in this section perform rpmlib's basic error handling. All error handling centers on the use of specific status codes. The status codes are defined in rpmlib.h and are of the form RPMERR_xxx, where xxx is the name of the error.

21.2.2. Getting Package Information

The following functions are used to obtain information about a package file.

It should be noted that most information is returned in the form of a Header structure. This data structure is widely used throughout rpmlib. We will discuss more header-related functions in Section 21.2.13 and Section 21.2.14.

21.2.3. Variable Manipulation

The following functions are used to get, set, and interpret RPM's internal variables. Variables are set according to various pieces of system information, as well as from rpmrc files. They control various aspects of RPM's operation.

The variables have symbolic names in the form RPMVAR_xxx, where xxx is the name of the variable. All variable names are defined in rpmlib.h.

21.2.4. rpmrc-Related Information

The functions in this section are all related to rpmrc information — the rpmrc files as well as the variables set from those files. This information also includes the architecture and operating system information based on rpmrc file entries.

21.2.5. RPM Database Manipulation

The functions in this section perform the basic operations on the RPM database. This includes opening and closing the database, as well as creating the database. A function also exists to rebuild a database that has been corrupted.

Every function that accesses the RPM database in some fashion makes use of the rpmdb structure. This structure is used as a handle to refer to a particular RPM database.

21.2.6. RPM Database Traversal

The following functions are used to traverse the RPM database. Also described in this section is a function to retrieve a database record by its record number.

It should be noted that database records are returned in the form of a Header structure. This data structure is widely used throughout rpmlib. We will discuss more header-related functions in Section 21.2.13 and Section 21.2.14.

21.2.7. RPM Database Search

The functions in this section search the various parts of the RPM database. They all return a structure of type dbiIndexSet, which contains the records that match the search term. Here is the definition of the structure, as found in <rpm/dbindex.h>:

typedef struct {
    dbiIndexRecord * recs;
    int count;
} dbiIndexSet;
          

Each dbiIndexRecord is also defined in <rpm/dbindex.h> as follows:

typedef struct {
    unsigned int recOffset;
    unsigned int fileNumber;
} dbiIndexRecord;
          

The recOffset element is the offset of the record from the start of the database file. The fileNumber element is only used by rpmdbFindByFile().

Keep in mind that the rpmdbFindxxx search functions each return dbiIndexSet structures, which must be freed with dbiFreeIndexRecord() when no longer needed.

21.2.8. Package Manipulation

These functions perform the operations most RPM users are familiar with. Functions that install and erase packages are here, along with a few related lower-level support functions.

21.2.8.1. Install Source Package File — rpmInstallSourcePackage()

#include <rpm/rpmlib.h>

int rpmInstallSourcePackage(char * root,
                            int fd,
                            char ** specFile,
                            rpmNotifyFunction notify,
                            char * labelFormat);
          

This function installs the source package file specified by fd. If root is not NULL, it is prepended to the variables RPMVAR_SOURCEDIR and RPMVAR_SPECDIR prior to the actual installation. If specFile is not NULL, the complete path and filename of the just-installed spec file is returned.

The notify parameter is used to specify a progress-tracking function that will be called during the installation. Please refer to Section 21.2.8.3 for more information on this parameter.

The labelFormat parameter can be used to specify how the package label should be formatted. It is used when printing the package label once the package install is ready to proceed. If labelformat is NULL, the package label is not printed.

This function returns the following status values:

  • 0 — The source package was installed successfully.

  • 1 — The source package file contained incorrect magic numbers.

  • 2 — Another type of error occurred.

21.2.8.2. Install Binary Package File — rpmInstallPackage()

#include <rpm/rpmlib.h>

int rpmInstallPackage(char * rootdir,
                      rpmdb db,
                      int fd,
                      char * prefix, 
                      int flags,
                      rpmNotifyFunction notify,
                      char * labelFormat,
                      char * netsharedPath);
          

This function installs the binary package specified by fd. If a path is specified in rootdir, the package will be installed with that path acting as the root directory. If a path is specified in prefix, it will be used as the prefix for relocatable packages. The RPM database specified by db is updated to reflect the newly installed package.

The flags parameter is used to control the installation behavior. The flags are defined in rpmlib.h and take the form RPMINSTALL_xxx, where xxx is the name of the flag.

The following flags are currently defined:

The notify parameter is used to specify a progress tracking function that will be called during the installation. Please refer to Section 21.2.8.3 for more information on this parameter.

The labelFormat parameter can be used to specify how the package label should be formatted. This information is used when printing the package label once the package install is ready to proceed. It is used when printing the package label once the package install is ready to proceed. If labelformat is NULL, the package label is not printed.

The netsharedPath parameter is used to specify that part of the local filesystem that is shared with other systems. If there is more than one path that is shared, the paths should be separated with a colon.

This function returns the following status values:

  • 0 — The binary package was installed successfully.

  • 1 — The binary package file contained incorrect magic numbers.

  • 2 — Another type of error occurred.

21.2.9. Package And File Verification

The functions in this section perform the verification operations necessary to ensure that the files comprising a package have not been modified since they were installed.

Verification takes place on three distinct levels:

  1. On the file-by-file level.

  2. On a package-wide level, through the use of the %verifyscript verification script.

  3. On an inter-package level, through RPM's normal dependency processing.

Because of this, there are two functions to perform each specific verification operation.

21.2.10. Dependency-Related Operations

The functions in this section are used to perform the various dependency-related operations supported by rpmlib.

Dependency processing is entirely separate from normal package-based operations. The package installation and removal functions do not perform any dependency processing themselves. Therefore, dependency processing is somewhat different from other aspects of rpmlib's operation.

Dependency processing centers around the rpmDependencies data structure. The operations that are to be performed against the RPM database (adding, removing, and upgrading packages) are performed against this data structure, using functions that are described below. These functions simply populate the data structure according to the operation being performed. They do not perform the actual operation on the package. This is an important point to keep in mind.

Once the data structure has been completely populated, a dependency check function is called to determine if there are any dependency-related problems. The result is a structure of dependency conflicts. This structure, rpmDependencyConflict, is defined in rpmlib.h.

Note that it is necessary to free both the conflicts structure and the rpmDependencies structure when they are no longer needed. However, free() should not be used — special functions for this are provided, and will be discussed in this section.

21.2.11. Diagnostic Output Control

The functions in this section are used to control the amount of diagnostic output produced by other rpmlib functions. The rpmlib library can produce a wealth of diagnostic output, making it easy to see what is going on at any given time.

There are several different verbosity levels defined in rpmlib.h. Their symbolic names are of the form RPMMESS_xxx, where xxx is the name of the verbosity level. It should be noted that the numeric values of the verbosity levels increase with a decrease in verbosity.

Unless otherwise set, the default verbosity level is RPMMESS_NORMAL.

21.2.12. Signature Verification

The functions in this section deal with the verification of package signatures. A package file may contain more than one type of signature. For example, a package may contain a signature that contains the package's size, as well as a signature that contains cryptographically-derived data that can be used to prove the package's origin.

Each type of signature has its own tag value. These tag values are defined in rpmlib.h and are of the form RPMSIGTAG_xxx, where xxx is the type of signature.

21.2.13. Header Manipulation

The header is one of the key data structures in rpmlib. The functions in this section perform basic manipulations of the header.

The header is actually a data structure. It is not necessary to fully understand the actual data structure. However, it is necessary to understand the basic concepts on which the header is based.

The header serves as a kind of miniature database. The header can be searched for specific information, which can be retrieved easily. Like a database, the information contained in the header can be of varying sizes.

21.2.14. Header Entry Manipulation

The functions in this section provide the basic operations necessary to manipulate header entries. The following header entry types are currently defined:

21.2.15. Header Iterator Support

Iterators are used as a means to step from entry to entry, through an entire header. The functions in this section are used to create, use, and free iterators.