1#ifndef CACHE_H 2#define CACHE_H 3 4#include <stdio.h> 5#include <sys/stat.h> 6#include <fcntl.h> 7#include <stddef.h> 8#include <stdlib.h> 9#include <stdarg.h> 10#include <errno.h> 11#include <sys/mman.h> 12 13#include <openssl/sha.h> 14#include <zlib.h> 15 16/* 17 * Basic data structures for the directory cache 18 * 19 * NOTE NOTE NOTE! This is all in the native CPU byte format. It's 20 * not even trying to be portable. It's trying to be efficient. It's 21 * just a cache, after all. 22 */ 23 24#define CACHE_SIGNATURE 0x44495243/* "DIRC" */ 25struct cache_header { 26unsigned int signature; 27unsigned int version; 28unsigned int entries; 29unsigned char sha1[20]; 30}; 31 32/* 33 * The "cache_time" is just the low 32 bits of the 34 * time. It doesn't matter if it overflows - we only 35 * check it for equality in the 32 bits we save. 36 */ 37struct cache_time { 38unsigned int sec; 39unsigned int nsec; 40}; 41 42/* 43 * dev/ino/uid/gid/size are also just tracked to the low 32 bits 44 * Again - this is just a (very strong in practice) heuristic that 45 * the inode hasn't changed. 46 */ 47struct cache_entry { 48struct cache_time ctime; 49struct cache_time mtime; 50unsigned int st_dev; 51unsigned int st_ino; 52unsigned int st_mode; 53unsigned int st_uid; 54unsigned int st_gid; 55unsigned int st_size; 56unsigned char sha1[20]; 57unsigned short namelen; 58unsigned char name[0]; 59}; 60 61const char*sha1_file_directory; 62struct cache_entry **active_cache; 63unsigned int active_nr, active_alloc; 64 65#define DB_ENVIRONMENT"SHA1_FILE_DIRECTORY" 66#define DEFAULT_DB_ENVIRONMENT".dircache/objects" 67 68#define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7) 69#define ce_size(ce) cache_entry_size((ce)->namelen) 70 71#define alloc_nr(x) (((x)+16)*3/2) 72 73/* Initialize the cache information */ 74externintread_cache(void); 75 76/* Return a statically allocated filename matching the sha1 signature */ 77externchar*sha1_file_name(unsigned char*sha1); 78 79/* Write a memory buffer out to the sha file */ 80externintwrite_sha1_buffer(unsigned char*sha1,void*buf,unsigned int size); 81 82/* Read and unpack a sha1 file into memory, write memory to a sha1 file */ 83externvoid*read_sha1_file(unsigned char*sha1,char*type,unsigned long*size); 84externintwrite_sha1_file(char*buf,unsigned len); 85 86/* Convert to/from hex/sha1 representation */ 87externintget_sha1_hex(char*hex,unsigned char*sha1); 88externchar*sha1_to_hex(unsigned char*sha1);/* static buffer! */ 89 90/* General helper functions */ 91externvoidusage(const char*err); 92 93#endif/* CACHE_H */