5 * Identify a file name path by a unique "finger print".
12 * Finger print cache entry.
13 * This is really a directory and symlink cache. We don't differentiate between
14 * the two. We can prepopulate it, which allows us to easily conduct "fake"
15 * installs of a system w/o actually mounting filesystems.
17 struct fprintCacheEntry_s {
18 const char * dirName; /*!< path to existing directory */
19 dev_t dev; /*!< stat(2) device number */
20 ino_t ino; /*!< stat(2) inode number */
21 int isFake; /*!< (currently unused) */
27 typedef /*@abstract@*/ struct fprintCache_s {
28 hashTable ht; /*!< hashed by dirName */
32 * Associates a trailing sub-directory and final base name with an existing
33 * directory finger print.
35 typedef struct fingerPrint_s {
36 /*! directory finger print entry (the directory path is stat(2)-able */
37 const struct fprintCacheEntry_s * entry;
38 /*! trailing sub-directory path (directories that are not stat(2)-able */
39 /*@owned@*/ /*@null@*/ const char * subDir;
40 /*@dependent@*/ const char * baseName; /*!< file base name */
43 /* only if !scarceMemory */
45 #define fpFree(a) free((void *)(a).baseName)
48 #define FP_ENTRY_EQUAL(a, b) (((a)->dev == (b)->dev) && ((a)->ino == (b)->ino))
51 #define FP_EQUAL(a, b) ( \
52 FP_ENTRY_EQUAL((a).entry, (b).entry) && \
53 !strcmp((a).baseName, (b).baseName) && ( \
54 ((a).subDir == (b).subDir) || \
55 ((a).subDir && (b).subDir && !strcmp((a).subDir, (b).subDir)) \
63 /* Be carefull with the memory... assert(*fullName == '/' || !scareMemory) */
66 * Create finger print cache.
67 * @param sizeHint number of elements expected
68 * @return pointer to initialized fingerprint cache
70 /*@only@*/ fingerPrintCache fpCacheCreate(int sizeHint) /*@*/;
73 * Destroy finger print cache.
74 * @param cache pointer to fingerprint cache
76 void fpCacheFree(/*@only@*/ fingerPrintCache cache);
79 * Return finger print of a file path.
80 * @param cache pointer to fingerprint cache
81 * @param dirName leading directory name of file path
82 * @param baseName base name of file path
84 * @return pointer to the finger print associated with a file path.
86 fingerPrint fpLookup(fingerPrintCache cache, const char * dirName,
87 const char * baseName, int scareMemory) /*@*/;
90 * Return hash value for a finger print.
91 * Hash based on dev and inode only!
92 * @param key pointer to finger print entry
95 unsigned int fpHashFunction(const void * key) /*@*/;
98 * Compare two finger print entries.
99 * exactly equivalent to FP_EQUAL macro.
100 * @param key1 finger print 1
101 * @param key2 finger print 2
102 * @return result of comparing key1 and key2
104 int fpEqual(const void * key1, const void * key2) /*@*/;
107 * Return finger prints of an array of file paths.
108 * @warning: scareMemory is assumed!
109 * @param cache pointer to fingerprint cache
110 * @param dirNames directory names
111 * @param baseNames file base names
112 * @param dirIndexes index into dirNames for each baseNames
113 * @param fileCount number of file entries
114 * @retval fpList pointer to array of finger prints
116 void fpLookupList(fingerPrintCache cache, const char ** dirNames,
117 const char ** baseNames, const int * dirIndexes,
118 int fileCount, fingerPrint * fpList)
119 /*@modifies cache, *fpList @*/;
122 * Return finger prints of all file names in header.
123 * @warning: scareMemory is assumed!
124 * @param cache pointer to fingerprint cache
125 * @param h package header
126 * @retval fpList pointer to array of finger prints
128 void fpLookupHeader(fingerPrintCache cache, Header h, fingerPrint * fpList)
129 /*@modifies h, cache, *fpList @*/;