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"
76 #define FP_ENTRY_EQUAL(a, b) (((a)->dev == (b)->dev) && ((a)->ino == (b)->ino))
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)) \
92 * Create finger print cache.
93 * @param sizeHint number of elements expected
94 * @return pointer to initialized fingerprint cache
97 fingerPrintCache fpCacheCreate(int sizeHint);
100 * Destroy finger print cache.
101 * @param cache pointer to fingerprint cache
102 * @return NULL always
105 fingerPrintCache fpCacheFree(fingerPrintCache cache);
108 * Return finger print of a file path.
109 * @param cache pointer to fingerprint cache
110 * @param dirName leading directory name of file path
111 * @param baseName base name of file path
113 * @return pointer to the finger print associated with a file path.
116 fingerPrint fpLookup(fingerPrintCache cache, const char * dirName,
117 const char * baseName, int scareMemory);
120 * Return hash value for a finger print.
121 * Hash based on dev and inode only!
122 * @param key pointer to finger print entry
126 unsigned int fpHashFunction(const fingerPrint * key);
129 * Compare two finger print entries.
130 * This routine is exactly equivalent to the FP_EQUAL macro.
131 * @param key1 finger print 1
132 * @param key2 finger print 2
133 * @return result of comparing key1 and key2
136 int fpEqual(const fingerPrint * key1, const fingerPrint * key2);
139 * Return finger prints of an array of file paths.
140 * @warning: scareMemory is assumed!
141 * @param cache pointer to fingerprint cache
142 * @param dirNames directory names
143 * @param baseNames file base names
144 * @param dirIndexes index into dirNames for each baseNames
145 * @param fileCount number of file entries
146 * @retval fpList pointer to array of finger prints
149 void fpLookupList(fingerPrintCache cache, const char ** dirNames,
150 const char ** baseNames, const uint32_t * dirIndexes,
151 int fileCount, fingerPrint * fpList);
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
162 void fpLookupSubdir(rpmFpHash symlinks, rpmFpHash fphash, fingerPrintCache fpc, rpmte p, int filenr);