~ubuntu-branches/debian/sid/rpm/sid

« back to all changes in this revision

Viewing changes to lib/fprint.h

  • Committer: Package Import Robot
  • Author(s): Michal Čihař
  • Date: 2013-06-06 11:39:34 UTC
  • mfrom: (1.1.16)
  • Revision ID: package-import@ubuntu.com-20130606113934-ela3du14fyba0t6u
Tags: 4.11.0.1-1
* New upstream release.
* Bump standards to 3.9.4.
* Refresh patches, update patch from Fedora.
* Build with Lua 5.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * Identify a file name path by a unique "finger print".
7
7
 */
8
8
 
9
 
#include <rpm/header.h>
10
 
#include <rpm/rpmte.h>
11
 
#include "lib/rpmdb_internal.h"
 
9
#include <rpm/rpmtypes.h>
12
10
 
13
11
/**
14
12
 */
19
17
 */
20
18
typedef struct fingerPrint_s fingerPrint;
21
19
 
22
 
/**
23
 
 * Associates a trailing sub-directory and final base name with an existing
24
 
 * directory finger print.
25
 
 */
26
 
struct fingerPrint_s {
27
 
/*! directory finger print entry (the directory path is stat(2)-able */
28
 
    const struct fprintCacheEntry_s * entry;
29
 
/*! trailing sub-directory path (directories that are not stat(2)-able */
30
 
const char * subDir;
31
 
const char * baseName;  /*!< file base name */
32
 
};
33
 
 
34
 
/* Create new hash table data type */
35
 
#define HASHTYPE rpmFpEntryHash
36
 
#define HTKEYTYPE const char *
37
 
#define HTDATATYPE const struct fprintCacheEntry_s *
38
 
#include "lib/rpmhash.H"
39
 
 
40
 
/**
41
 
 * Finger print cache entry.
42
 
 * This is really a directory and symlink cache. We don't differentiate between
43
 
 * the two. We can prepopulate it, which allows us to easily conduct "fake"
44
 
 * installs of a system w/o actually mounting filesystems.
45
 
 */
46
 
struct fprintCacheEntry_s {
47
 
    const char * dirName;               /*!< path to existing directory */
48
 
    dev_t dev;                          /*!< stat(2) device number */
49
 
    ino_t ino;                          /*!< stat(2) inode number */
50
 
};
51
 
 
52
 
/**
53
 
 * Finger print cache.
54
 
 */
55
 
struct fprintCache_s {
56
 
    rpmFpEntryHash ht;                  /*!< hashed by dirName */
57
 
};
58
 
 
59
 
/* Create new hash table data type */
60
 
 
61
20
struct rpmffi_s {
62
21
  rpmte p;
63
22
  int   fileno;
64
23
};
65
24
 
66
 
#undef HASHTYPE
67
 
#undef HTKEYTYPE
68
 
#undef HTDATATYPE
69
 
 
70
 
#define HASHTYPE rpmFpHash
71
 
#define HTKEYTYPE const fingerPrint *
72
 
#define HTDATATYPE struct rpmffi_s
73
 
#include "lib/rpmhash.H"
74
 
 
75
 
/** */
76
 
#define FP_ENTRY_EQUAL(a, b) (((a)->dev == (b)->dev) && ((a)->ino == (b)->ino))
77
 
 
78
 
/** */
79
 
#define FP_EQUAL(a, b) ( \
80
 
        FP_ENTRY_EQUAL((a).entry, (b).entry) && \
81
 
        !strcmp((a).baseName, (b).baseName) && ( \
82
 
            ((a).subDir == (b).subDir) || \
83
 
            ((a).subDir && (b).subDir && !strcmp((a).subDir, (b).subDir)) \
84
 
        ) \
85
 
    )
86
 
 
87
25
#ifdef __cplusplus
88
26
extern "C" {
89
27
#endif
91
29
/**
92
30
 * Create finger print cache.
93
31
 * @param sizeHint      number of elements expected
 
32
 * @param pool          string pool (or NULL for private)
94
33
 * @return pointer to initialized fingerprint cache
95
34
 */
96
35
RPM_GNUC_INTERNAL
97
 
fingerPrintCache fpCacheCreate(int sizeHint);
 
36
fingerPrintCache fpCacheCreate(int sizeHint, rpmstrPool pool);
98
37
 
99
38
/**
100
39
 * Destroy finger print cache.
104
43
RPM_GNUC_INTERNAL
105
44
fingerPrintCache fpCacheFree(fingerPrintCache cache);
106
45
 
 
46
RPM_GNUC_INTERNAL
 
47
fingerPrint * fpCacheGetByFp(fingerPrintCache cache,
 
48
                             struct fingerPrint_s * fp, int ix,
 
49
                             struct rpmffi_s ** recs, int * numRecs);
 
50
 
 
51
RPM_GNUC_INTERNAL
 
52
void fpCachePopulate(fingerPrintCache cache, rpmts ts, int fileCount);
 
53
 
 
54
/* compare an existing fingerprint with a looked-up fingerprint for db/bn */
 
55
RPM_GNUC_INTERNAL
 
56
int fpLookupEquals(fingerPrintCache cache, fingerPrint * fp,
 
57
                   const char * dirName, const char * baseName);
 
58
 
 
59
RPM_GNUC_INTERNAL
 
60
const char *fpEntryDir(fingerPrintCache cache, fingerPrint *fp);
 
61
 
 
62
RPM_GNUC_INTERNAL
 
63
dev_t fpEntryDev(fingerPrintCache cache, fingerPrint *fp);
 
64
 
107
65
/**
108
66
 * Return finger print of a file path.
109
67
 * @param cache         pointer to fingerprint cache
110
68
 * @param dirName       leading directory name of file path
111
69
 * @param baseName      base name of file path
112
 
 * @param scareMemory
113
 
 * @return pointer to the finger print associated with a file path.
114
 
 */
115
 
RPM_GNUC_INTERNAL
116
 
fingerPrint fpLookup(fingerPrintCache cache, const char * dirName, 
117
 
                        const char * baseName, int scareMemory);
118
 
 
119
 
/**
120
 
 * Return hash value for a finger print.
121
 
 * Hash based on dev and inode only!
122
 
 * @param key           pointer to finger print entry
123
 
 * @return hash value
124
 
 */
125
 
RPM_GNUC_INTERNAL
126
 
unsigned int fpHashFunction(const fingerPrint * key);
 
70
 * @retval fp           pointer of fingerprint struct to fill out
 
71
 * @return              0 on success
 
72
 */
 
73
RPM_GNUC_INTERNAL
 
74
int fpLookup(fingerPrintCache cache,
 
75
             const char * dirName, const char * baseName,
 
76
             fingerPrint **fp);
127
77
 
128
78
/**
129
79
 * Compare two finger print entries.
137
87
 
138
88
/**
139
89
 * Return finger prints of an array of file paths.
140
 
 * @warning: scareMemory is assumed!
141
90
 * @param cache         pointer to fingerprint cache
 
91
 * @param pool          pointer to file name pool
142
92
 * @param dirNames      directory names
143
93
 * @param baseNames     file base names
144
94
 * @param dirIndexes    index into dirNames for each baseNames
145
95
 * @param fileCount     number of file entries
146
 
 * @retval fpList       pointer to array of finger prints
147
 
 */
148
 
RPM_GNUC_INTERNAL
149
 
void fpLookupList(fingerPrintCache cache, const char ** dirNames, 
150
 
                  const char ** baseNames, const uint32_t * dirIndexes, 
151
 
                  int fileCount, fingerPrint * fpList);
152
 
 
153
 
/**
154
 
 * Check file for to be installed symlinks in their path,
155
 
 *  correct their fingerprint and add it to newht.
156
 
 * @param ht            hash table containing all files fingerprints
157
 
 * @param newht         hash table to add the corrected fingerprints
158
 
 * @param fpc           fingerprint cache
159
 
 * @param fi            file iterator of the package
160
 
 * @param filenr        the number of the file we are dealing with
161
 
 */
162
 
RPM_GNUC_INTERNAL
163
 
void fpLookupSubdir(rpmFpHash symlinks, rpmFpHash fphash, fingerPrintCache fpc, rpmte p, int filenr);
164
 
 
 
96
 * @return              pointer to array of finger prints
 
97
 */
 
98
RPM_GNUC_INTERNAL
 
99
fingerPrint * fpLookupList(fingerPrintCache cache, rpmstrPool pool,
 
100
                           rpmsid * dirNames, rpmsid * baseNames,
 
101
                           const uint32_t * dirIndexes, int fileCount);
165
102
 
166
103
#ifdef __cplusplus
167
104
}