⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0310-0313.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:




<HTML>

<HEAD>

<TITLE>Maximum RPM (RPM):A Guide to the RPM Library API:EarthWeb Inc.-</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!-- ISBN=0672311054 //-->

<!-- TITLE=Maximum RPM (RPM)//-->

<!-- AUTHOR=Edward Bailey//-->

<!-- PUBLISHER=Macmillan Computer Publishing//-->

<!-- IMPRINT=Sams//-->

<!-- CHAPTER=21 //-->

<!-- PAGES=0305-0336 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->









<P><CENTER>

<a href="0305-0309.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0314-0317.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-310"><P>Page 310</P></A>







<P>The building argument should be set to 1 only if a package is being built when this function

is called. Since most rpmlib-based applications will probably not duplicate RPM's

package-building capabilities, building should normally be set to

0.

</P>



<H4><A NAME="ch21_ 16">

21.2.4.2. rpmGetOsName()&#151;Return Operating System Name

</A></H4>



<P>This function returns the name of the operating system, as determined by

rpmlib's normal rpmrc file processing:

</P>

<!-- CODE SNIP //-->

<PRE>

#include  &lt;rpm/rpmlib.h&gt;



char  *rpmGetOsName(void);

</PRE>

<!-- END CODE SNIP //-->



<H4><A NAME="ch21_ 17">

21.2.4.3. rpmGetArchName()&#151;Return Architecture Name

</A></H4>



<P>This function returns the name of the architecture, as determined by rpmlib's normal

rpmrc file processing:

</P>

<!-- CODE SNIP //-->

<PRE>

#include  &lt;rpm/rpmlib.h&gt;



char  *rpmGetArchName(void);

</PRE>

<!-- END CODE SNIP //-->



<H4><A NAME="ch21_ 18">

21.2.4.4. rpmShowRC()&#151;Print All rpmrc-Derived Variables

</A></H4>



<P>This function writes all variable names and their values

to the file f. It always returns 0:

</P>



<!-- CODE SNIP //-->

<PRE>

#include    &lt;rpm/rpmlib.h&gt;



int   rpmShowRC(FILE *f);

</PRE>

<!-- END CODE SNIP //-->



<H4><A NAME="ch21_ 19">

21.2.4.5. rpmArchScore()&#151;Return Architecture Compatibility Score

</A></H4>



<P>This function returns the level of compatibility between the architecture whose name is

specified in arch and the current architecture. Returns

0 if the two architectures are incompatible. The smaller the number returned, the more compatible the two architectures are:

</P>



<!-- CODE SNIP //-->

<PRE>

#include   &lt;rpm/rpmlib.h&gt;



int   rpmArchScore(char * arch);

</PRE>

<!-- END CODE SNIP //-->



<H4><A NAME="ch21_ 20">

21.2.4.6. rpmOsScore()&#151;Return Operating System Compatibility Score

</A></H4>



<P>This function returns the level of compatibility between the operating system whose name

is specified in os and the current operating system.

Returns 0 if the two operating systems are incompatible. The smaller the number returned, the more compatible the two operating

systems are:

</P>



<!-- CODE SNIP //-->

<PRE>

#include   &lt;rpm/rpmlib.h&gt;



int   rpmOsScore(char * os);



</PRE>

<!-- END CODE SNIP //--><A NAME="PAGENUM-311"><P>Page 311</P></A>



<H4>

21.2.5. RPM Database Manipulation

</H4>



<P>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.

</P>



<P>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.

</P>



<H4><A NAME="ch21_ 21">

21.2.5.1. rpmdbOpen()&#151;Open RPM Database

</A></H4>



<P>This function opens the RPM database located in

RPMVAR_DBPATH, returning the rpmdb structure dbp. If

root is specified, it is prepended to

RPMVAR_DBPATH prior to opening. The mode and perms parameters are identical to

open(2)'s flags and mode parameters, respectively:

</P>



<!-- CODE SNIP //-->

<PRE>

#include   &lt;rpm/rpmlib.h&gt;



int   rpmdbOpen(char * root,

               rpmdb * dbp,

                int mode,

                 int perms);

</PRE>

<!-- END CODE SNIP //-->



<P>The function returns 1 on error, and 0 on success.

</P>



<H4><A NAME="ch21_ 22">

21.2.5.2. rpmdbClose()&#151;Close RPM Database

</A></H4>



<P>This function closes the RPM database specified by the

rpmdb structure db. The db structure is also freed:

</P>



<!-- CODE SNIP //-->

<PRE>

#include   &lt;rpm/rpmlib.h&gt;



void   rpmdbClose(rpmdb db);

</PRE>

<!-- END CODE SNIP //-->



<H4><A NAME="ch21_ 23">

21.2.5.3. rpmdbInit()&#151;Create RPM Database

</A></H4>



<P>This function creates a new RPM database to be located in

RPMVAR_DBPATH. If the database already exists, it is left unchanged. If

root is specified, it is prepended to

RPMVAR_DBPATH prior to creation. The perms parameter is identical to

open(2)'s mode parameter:

</P>



<!-- CODE SNIP //-->

<PRE>

#include  &lt;rpm/rpmlib.h&gt;



int  rpmdbInit(char * root,

              int perms);

</PRE>

<!-- END CODE SNIP //-->



<P>The function returns 1 on error, and 0 on success.

</P>



<A NAME="PAGENUM-312"><P>Page 312</P></A>





<H4><A NAME="ch21_ 24">

21.2.5.4. rpmdbRebuild()&#151;Rebuild RPM Database

</A></H4>



<P>This function rebuilds the RPM database located in

RPMVAR_DBPATH. If root is specified, it is prepended to

RPMVAR_DBPATH prior to rebuilding:

</P>



<!-- CODE SNIP //-->

<PRE>

#include  &lt;rpm/rpmlib.h&gt;



int  rpmdbRebuild(char * root);

</PRE>

<!-- END CODE SNIP //-->



<P>The function returns 1 on error, and 0 on success.

</P>



<H4><A NAME="ch21_ 25">

21.2.6. RPM Database Traversal

</A></H4>



<P>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.

</P>



<P>Note 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

sections 21.2.13 and 21.2.14.

</P>



<H4><A NAME="ch21_ 26">

21.2.6.1. rpmdbFirstRecNum()&#151;Begin RPM Database Traversal

</A></H4>



<P>This function returns the record number of the first record

in the database specified by db:

</P>



<!-- CODE SNIP //-->

<PRE>

#include   &lt;rpm/rpmlib.h&gt;



unsigned  int   rpmdbFirstRecNum(rpmdb db);

</PRE>

<!-- END CODE SNIP //-->



<P>On error, it returns 0.

</P>



<H4><A NAME="ch21_ 27">

21.2.6.2. rpmdbNextRecNum()&#151;Traverse to Next RPM Database Record

</A></H4>



<P>This function returns the record number of the record following the

record number passed in lastOffset, in the database specified by

db:

</P>



<!-- CODE SNIP //-->

<PRE>

#include   &lt;rpm/rpmlib.h&gt;



unsigned  int  rpmdbNextRecNum(rpmdb db,

                                   unsigned int lastOffset);

</PRE>

<!-- END CODE SNIP //-->



<P>On error, this function returns 0.

</P>



<H4><A NAME="ch21_ 28">

21.2.6.3. rpmdbGetRecord()&#151;Return Record from RPM Database

</A></H4>



<P>This function returns the record at the record number specified by

offset from the database specified by db:

</P>



<!-- CODE SNIP //-->

<PRE>

#include   &lt;rpm/rpmlib.h&gt;



Header   rpmdbGetRecord(rpmdb db,

                      unsigned int offset);

</PRE>

<!-- END CODE SNIP //-->



<P>This function returns NULL on error.

</P>



<A NAME="PAGENUM-313"><P>Page 313</P></A>



<H4><A NAME="ch21_ 29">

21.2.7. RPM Database Search

</A></H4>



<P>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

&lt;rpm/dbindex.h&gt;:

</P>



<!-- CODE SNIP //-->

<PRE>

typedef struct {

    dbiIndexRecord * recs;

    int count;

} dbiIndexSet;

</PRE>

<!-- END CODE SNIP //-->



<P>Each dbiIndexRecord is also defined in

&lt;rpm/dbindex.h&gt;, as follows:

</P>

<!-- CODE SNIP //-->

<PRE>

typedef struct {

     unsigned int recOffset;

    unsigned int fileNumber;

} dbiIndexRecord;

</PRE>

<!-- END CODE SNIP //-->



<P>The recOffset element is the offset of the record from the start of the database file.

The fileNumber element is only used by

rpmdbFindByFile().

</P>



<P>Keep in mind that the rpmdbFindxxx() search functions each return

dbiIndexSet structures, which must be freed with

dbiFreeIndexRecord() when no longer needed.

</P>



<H4><A NAME="ch21_ 30">

21.2.7.1. dbiFreeIndexRecord()&#151;Free Database Index

</A></H4>



<P>This function frees the database index set specified by

set:

</P>

<!-- CODE SNIP //-->

<PRE>

#include  &lt;rpm/rpmlib.h&gt;

#include  &lt;rpm/dbindex.h&gt;



void   dbiFreeIndexRecord(dbiIndexSet set);

</PRE>

<!-- END CODE SNIP //-->



<H4><A NAME="ch21_ 31">

21.2.7.2. rpmdbFindByFile()&#151;Search RPM Database by File

</A></H4>



<P>This function searches the RPM database specified by

db for the package that owns the file specified by

filespec. It returns matching records in matches:

</P>



<!-- CODE SNIP //-->

<PRE>

#include   &lt;rpm/rpmlib.h&gt;

#include   &lt;rpm/dbindex.h&gt;



int   rpmdbFindByFile(rpmdb db,

                    char * filespec,

               dbiIndexSet * matches);

</PRE>

<!-- END CODE SNIP //-->



<P>This function returns the following status values:

</P>

<BLOCKQUOTE>

-1&#151;An error occurred while reading a database record.<BR>

0&#151;The search completed normally.<BR>

1&#151;The search term was not found.<BR>

</BLOCKQUOTE>



<P><CENTER>

<a href="0305-0309.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0314-0317.html">Next</A>

</CENTER></P>











</td>
</tr>
</table>

<!-- begin footer information -->







</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -