Delete rpmdbFindFpList and skipDir
[platform/upstream/rpm.git] / lib / fprint.h
1 #ifndef H_FINGERPRINT
2 #define H_FINGERPRINT
3
4 /** \ingroup rpmtrans
5  * \file lib/fprint.h
6  * Identify a file name path by a unique "finger print".
7  */
8
9 #include <rpm/header.h>
10 #include <rpm/rpmte.h>
11 #include "lib/rpmdb_internal.h"
12
13 /**
14  */
15 typedef struct fprintCache_s * fingerPrintCache;
16
17 /**
18  * @todo Convert to pointer and make abstract.
19  */
20 typedef struct fingerPrint_s fingerPrint;
21
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 struct rpmffi_s {
62   rpmte p;
63   int   fileno;
64 };
65
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 /* avoid include cycle problem by including after rpmFpHash definition */
76 #include "lib/rpmts_internal.h"
77
78 /** */
79 #define FP_ENTRY_EQUAL(a, b) (((a)->dev == (b)->dev) && ((a)->ino == (b)->ino))
80
81 /** */
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)) \
87         ) \
88     )
89
90 #ifdef __cplusplus
91 extern "C" {
92 #endif
93
94 /**
95  * Create finger print cache.
96  * @param sizeHint      number of elements expected
97  * @return pointer to initialized fingerprint cache
98  */
99 RPM_GNUC_INTERNAL
100 fingerPrintCache fpCacheCreate(int sizeHint);
101
102 /**
103  * Destroy finger print cache.
104  * @param cache         pointer to fingerprint cache
105  * @return              NULL always
106  */
107 RPM_GNUC_INTERNAL
108 fingerPrintCache fpCacheFree(fingerPrintCache cache);
109
110 /**
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
115  * @param scareMemory
116  * @return pointer to the finger print associated with a file path.
117  */
118 RPM_GNUC_INTERNAL
119 fingerPrint fpLookup(fingerPrintCache cache, const char * dirName, 
120                         const char * baseName, int scareMemory);
121
122 /**
123  * Return hash value for a finger print.
124  * Hash based on dev and inode only!
125  * @param key           pointer to finger print entry
126  * @return hash value
127  */
128 RPM_GNUC_INTERNAL
129 unsigned int fpHashFunction(const fingerPrint * key);
130
131 /**
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
137  */
138 RPM_GNUC_INTERNAL
139 int fpEqual(const fingerPrint * key1, const fingerPrint * key2);
140
141 /**
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
150  */
151 RPM_GNUC_INTERNAL
152 void fpLookupList(fingerPrintCache cache, const char ** dirNames, 
153                   const char ** baseNames, const uint32_t * dirIndexes, 
154                   int fileCount, fingerPrint * fpList);
155
156 /**
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
164  */
165 void fpLookupSubdir(rpmFpHash ht, rpmFpHash newht, fingerPrintCache fpc, rpmte p, int filenr);
166
167
168 #ifdef __cplusplus
169 }
170 #endif
171
172 #endif