6 * Identify a file name path by a unique "finger print".
9 #include <rpm/header.h>
10 #include <rpm/rpmte.h>
11 #include "lib/rpmdb_internal.h"
15 typedef struct fprintCache_s * fingerPrintCache;
18 * @todo Convert to pointer and make abstract.
20 typedef struct fingerPrint_s fingerPrint;
23 * Associates a trailing sub-directory and final base name with an existing
24 * directory finger print.
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 */
31 const char * baseName; /*!< file base name */
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"
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.
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 */
55 struct fprintCache_s {
56 rpmFpEntryHash ht; /*!< hashed by dirName */
59 /* Create new hash table data type */
70 #define HASHTYPE rpmFpHash
71 #define HTKEYTYPE const fingerPrint *
72 #define HTDATATYPE struct rpmffi_s
73 #include "lib/rpmhash.H"
75 /* avoid include cycle problem by including after rpmFpHash definition */
76 #include "lib/rpmts_internal.h"
79 #define FP_ENTRY_EQUAL(a, b) (((a)->dev == (b)->dev) && ((a)->ino == (b)->ino))
82 #define FP_EQUAL(a, b) ( \
83 FP_ENTRY_EQUAL((a).entry, (b).entry) && \
84 !strcmp((a).baseName, (b).baseName) && ( \
85 ((a).subDir == (b).subDir) || \
86 ((a).subDir && (b).subDir && !strcmp((a).subDir, (b).subDir)) \
95 * Create finger print cache.
96 * @param sizeHint number of elements expected
97 * @return pointer to initialized fingerprint cache
100 fingerPrintCache fpCacheCreate(int sizeHint);
103 * Destroy finger print cache.
104 * @param cache pointer to fingerprint cache
105 * @return NULL always
108 fingerPrintCache fpCacheFree(fingerPrintCache cache);
111 * Return finger print of a file path.
112 * @param cache pointer to fingerprint cache
113 * @param dirName leading directory name of file path
114 * @param baseName base name of file path
116 * @return pointer to the finger print associated with a file path.
119 fingerPrint fpLookup(fingerPrintCache cache, const char * dirName,
120 const char * baseName, int scareMemory);
123 * Return hash value for a finger print.
124 * Hash based on dev and inode only!
125 * @param key pointer to finger print entry
129 unsigned int fpHashFunction(const fingerPrint * key);
132 * Compare two finger print entries.
133 * This routine is exactly equivalent to the FP_EQUAL macro.
134 * @param key1 finger print 1
135 * @param key2 finger print 2
136 * @return result of comparing key1 and key2
139 int fpEqual(const fingerPrint * key1, const fingerPrint * key2);
142 * Return finger prints of an array of file paths.
143 * @warning: scareMemory is assumed!
144 * @param cache pointer to fingerprint cache
145 * @param dirNames directory names
146 * @param baseNames file base names
147 * @param dirIndexes index into dirNames for each baseNames
148 * @param fileCount number of file entries
149 * @retval fpList pointer to array of finger prints
152 void fpLookupList(fingerPrintCache cache, const char ** dirNames,
153 const char ** baseNames, const uint32_t * dirIndexes,
154 int fileCount, fingerPrint * fpList);
157 * Check file for to be installed symlinks in their path,
158 * correct their fingerprint and add it to newht.
159 * @param ht hash table containing all files fingerprints
160 * @param newht hash table to add the corrected fingerprints
161 * @param fpc fingerprint cache
162 * @param fi file iterator of the package
163 * @param filenr the number of the file we are dealing with
165 void fpLookupSubdir(rpmFpHash ht, rpmFpHash newht, fingerPrintCache fpc, rpmte p, int filenr);