1998-12-27 01:12:50 +08:00
|
|
|
#ifndef H_FINGERPRINT
|
|
|
|
#define H_FINGERPRINT
|
|
|
|
|
2000-01-29 06:55:42 +08:00
|
|
|
/** \file lib/fprint.h
|
|
|
|
* Identify a file name path by a unique "finger print".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1999-10-20 18:22:46 +08:00
|
|
|
#include "hash.h"
|
|
|
|
#include "header.h"
|
|
|
|
|
2000-01-29 06:55:42 +08:00
|
|
|
/**
|
|
|
|
* Finger print cache entry.
|
|
|
|
* This is really a directory and symlink cache. We don't differentiate between
|
|
|
|
* the two. We can prepopulate it, which allows us to easily conduct "fake"
|
|
|
|
* installs of a system w/o actually mounting filesystems.
|
|
|
|
*/
|
1999-10-20 18:22:46 +08:00
|
|
|
struct fprintCacheEntry_s {
|
2000-01-29 06:55:42 +08:00
|
|
|
char * dirName; /*!< path to existing directory */
|
|
|
|
dev_t dev; /*!< stat(2) device number */
|
|
|
|
ino_t ino; /*!< stat(2) inode number */
|
|
|
|
int isFake; /*!< (currently unused) */
|
1999-10-20 18:22:46 +08:00
|
|
|
};
|
|
|
|
|
2000-01-29 06:55:42 +08:00
|
|
|
/**
|
|
|
|
* Finger print cache.
|
|
|
|
*/
|
1999-12-08 05:14:51 +08:00
|
|
|
typedef /*@abstract@*/ struct fprintCache_s {
|
2000-01-29 06:55:42 +08:00
|
|
|
hashTable ht; /*!< hashed by dirName */
|
1999-10-20 18:22:46 +08:00
|
|
|
} * fingerPrintCache;
|
|
|
|
|
2000-01-29 06:55:42 +08:00
|
|
|
/**
|
|
|
|
* Associates a trailing sub-directory and final base name with an existing
|
|
|
|
* directory finger print.
|
|
|
|
*/
|
1999-10-20 18:22:46 +08:00
|
|
|
typedef struct fingerprint_s {
|
2000-01-29 06:55:42 +08:00
|
|
|
/*! directory finger print entry (the directory path is stat(2)-able */
|
1999-10-20 18:22:46 +08:00
|
|
|
const struct fprintCacheEntry_s * entry;
|
2000-01-29 06:55:42 +08:00
|
|
|
/*! trailing sub-directory path (directories that are not stat(2)-able */
|
|
|
|
/*@owned@*/ /*@null@*/ const char * subDir;
|
|
|
|
/*@dependent@*/ const char * baseName; /*!< file base name */
|
1998-12-27 01:12:50 +08:00
|
|
|
} fingerPrint;
|
|
|
|
|
1999-07-14 05:37:57 +08:00
|
|
|
/* only if !scarceMemory */
|
2000-01-29 06:55:42 +08:00
|
|
|
/** */
|
1999-11-27 05:58:42 +08:00
|
|
|
#define fpFree(a) free((void *)(a).baseName)
|
1999-07-14 05:37:57 +08:00
|
|
|
|
2000-01-29 06:55:42 +08:00
|
|
|
/** */
|
1999-12-02 03:57:17 +08:00
|
|
|
#define FP_EQUAL(a, b) ( \
|
|
|
|
(&(a) == &(b)) || ( \
|
|
|
|
((a).entry == (b).entry) && \
|
1999-12-08 05:14:51 +08:00
|
|
|
!strcmp((a).baseName, (b).baseName) && \
|
|
|
|
(((a).subDir && (b).subDir && !strcmp((a).subDir, (b).subDir)) \
|
|
|
|
|| ((a).subDir == (b).subDir)) \
|
|
|
|
) \
|
|
|
|
)
|
1999-12-02 03:57:17 +08:00
|
|
|
|
2000-01-29 06:55:42 +08:00
|
|
|
/** */
|
1999-12-02 03:57:17 +08:00
|
|
|
#define FP_ENTRY_EQUAL(a, b) ( \
|
|
|
|
((a)->dev == (b)->dev) && \
|
|
|
|
((a)->ino == (b)->ino) && \
|
|
|
|
!strcmp((a)->dirName, (b)->dirName))
|
|
|
|
|
2000-01-29 06:55:42 +08:00
|
|
|
/** */
|
1999-12-02 03:57:17 +08:00
|
|
|
#define FP_EQUAL_DIFFERENT_CACHE(a, b) ( \
|
|
|
|
FP_ENTRY_EQUAL((a).entry, (b).entry) && \
|
1999-12-08 05:14:51 +08:00
|
|
|
!strcmp((a).baseName, (b).baseName) && \
|
|
|
|
(((a).subDir && (b).subDir && !strcmp((a).subDir, (b).subDir)) \
|
|
|
|
|| ((a).subDir == (b).subDir)) \
|
|
|
|
)
|
1999-07-14 05:37:57 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
1998-12-27 01:12:50 +08:00
|
|
|
/* Be carefull with the memory... assert(*fullName == '/' || !scareMemory) */
|
2000-01-29 06:55:42 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create finger print cache.
|
|
|
|
* @param sizeHint number of elements expected
|
|
|
|
* @return pointer to initialized fingerprint cache
|
|
|
|
*/
|
|
|
|
/*@only@*/ fingerPrintCache fpCacheCreate(int sizeHint);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy finger print cache.
|
|
|
|
* @param cache pointer to fingerprint cache
|
|
|
|
*/
|
1999-12-08 05:14:51 +08:00
|
|
|
void fpCacheFree(/*@only@*/ fingerPrintCache cache);
|
2000-01-29 06:55:42 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return finger print of a file path.
|
|
|
|
* @param cache pointer to fingerprint cache
|
|
|
|
* @param dirName leading directory name of file path
|
|
|
|
* @param baseName base name of file path
|
|
|
|
* @param scareMemory
|
|
|
|
* @return pointer to the finger print associated with a file path.
|
|
|
|
*/
|
1999-12-08 05:14:51 +08:00
|
|
|
fingerPrint fpLookup(fingerPrintCache cache, const char * dirName,
|
1999-12-01 02:07:08 +08:00
|
|
|
const char * baseName, int scareMemory);
|
1999-10-20 18:22:46 +08:00
|
|
|
|
2000-01-29 06:55:42 +08:00
|
|
|
/**
|
|
|
|
* Return hash value for a finger print.
|
|
|
|
* Hash based on dev and inode only!
|
|
|
|
* @param key pointer to finger print entry
|
|
|
|
* @return hash value
|
|
|
|
*/
|
1999-10-20 18:22:46 +08:00
|
|
|
unsigned int fpHashFunction(const void * key);
|
2000-01-29 06:55:42 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare two finger print entries.
|
|
|
|
* exactly equivalent to FP_EQUAL.
|
|
|
|
* @param key1 finger print 1
|
|
|
|
* @param key2 finger print 2
|
|
|
|
* @return result of comparing key1 and key2
|
|
|
|
*/
|
1998-12-27 02:29:32 +08:00
|
|
|
int fpEqual(const void * key1, const void * key2);
|
1999-10-20 18:22:46 +08:00
|
|
|
|
2000-01-29 06:55:42 +08:00
|
|
|
/**
|
|
|
|
* Return finger prints of an array of file paths.
|
|
|
|
* @warning: scareMemory is assumed!
|
|
|
|
* @param cache pointer to fingerprint cache
|
|
|
|
* @param dirNames directory names
|
|
|
|
* @param baseNames file base names
|
|
|
|
* @param dirIndexes index into dirNames for each baseNames
|
|
|
|
* @param fileCount number of file entries
|
|
|
|
* @retval fpList pointer to array of finger prints
|
|
|
|
*/
|
1999-10-21 10:40:57 +08:00
|
|
|
void fpLookupList(fingerPrintCache cache, const char ** dirNames,
|
|
|
|
const char ** baseNames, const int * dirIndexes,
|
|
|
|
int fileCount, fingerPrint * fpList);
|
2000-01-29 06:55:42 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return finger prints of all file names in header.
|
|
|
|
* @warning: scareMemory is assumed!
|
|
|
|
* @param cache pointer to fingerprint cache
|
|
|
|
* @param h package header
|
|
|
|
* @retval fpList pointer to array of finger prints
|
|
|
|
*/
|
1999-10-20 18:22:46 +08:00
|
|
|
void fpLookupHeader(fingerPrintCache cache, Header h, fingerPrint * fpList);
|
1998-12-27 01:12:50 +08:00
|
|
|
|
1999-07-14 05:37:57 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
1998-12-27 01:12:50 +08:00
|
|
|
|
|
|
|
#endif
|