13 #include <openssl/sha.h>
17 * Basic data structures for the directory cache
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.
24 #define CACHE_SIGNATURE 0x44495243 /* "DIRC" */
26 unsigned int signature
;
29 unsigned char sha1
[20];
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.
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.
48 struct cache_time ctime
;
49 struct cache_time mtime
;
56 unsigned char sha1
[20];
57 unsigned short namelen
;
58 unsigned char name
[0];
61 const char *sha1_file_directory
;
62 struct cache_entry
**active_cache
;
63 unsigned int active_nr
, active_alloc
;
65 #define DB_ENVIRONMENT "SHA1_FILE_DIRECTORY"
66 #define DEFAULT_DB_ENVIRONMENT ".dircache/objects"
68 #define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7)
69 #define ce_size(ce) cache_entry_size((ce)->namelen)
71 #define alloc_nr(x) (((x)+16)*3/2)
73 /* Initialize the cache information */
74 extern int read_cache(void);
76 /* Return a statically allocated filename matching the sha1 signature */
77 extern char *sha1_file_name(unsigned char *sha1
);
79 /* Write a memory buffer out to the sha file */
80 extern int write_sha1_buffer(unsigned char *sha1
, void *buf
, unsigned int size
);
82 /* Read and unpack a sha1 file into memory, write memory to a sha1 file */
83 extern void * read_sha1_file(unsigned char *sha1
, char *type
, unsigned long *size
);
84 extern int write_sha1_file(char *buf
, unsigned len
);
86 /* Convert to/from hex/sha1 representation */
87 extern int get_sha1_hex(char *hex
, unsigned char *sha1
);
88 extern char *sha1_to_hex(unsigned char *sha1
); /* static buffer! */
90 /* General helper functions */
91 extern void usage(const char *err
);