ccache_internal.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef CCACHE_INTERNAL_H_
  2. #define CCACHE_INTERNAL_H_
  3. #include <sys/stat.h>
  4. #include <stdint.h>
  5. #include "ccache.h"
  6. #include "ctassert.h"
  7. #include "multitape.h"
  8. #include "patricia.h"
  9. /*
  10. * Maximum number of times tarsnap can be run without accessing a cache
  11. * entry before the entry is removed from the cache.
  12. */
  13. #define MAXAGE 10
  14. /* Cache data structure. */
  15. struct ccache_internal {
  16. PATRICIA * tree; /* Tree of ccache_record structures. */
  17. void * data; /* Mmapped data. */
  18. size_t datalen; /* Size of mmapped data. */
  19. size_t chunksusage; /* Memory used by chunks. */
  20. size_t trailerusage; /* Memory used by trailers. */
  21. };
  22. /* An entry stored in the cache. */
  23. struct ccache_record {
  24. /* Values stored in ccache_record_external structure. */
  25. ino_t ino; /* Inode number. */
  26. off_t size; /* File size. */
  27. time_t mtime; /* Modification time, seconds since epoch. */
  28. size_t nch; /* Number of struct chunkheader records. */
  29. size_t tlen; /* Length of trailer (unchunked data). */
  30. size_t tzlen; /* Length of deflated trailer. */
  31. int age; /* Age of entry in read/write cycles. */
  32. size_t nchalloc; /* Number of records of space allocated. */
  33. struct chunkheader * chp; /* Points to nch records if non-NULL. */
  34. uint8_t * ztrailer; /* Points to deflated trailer if non-NULL. */
  35. int flags; /* CCR_* flags. */
  36. };
  37. #define CCR_ZTRAILER_MALLOC 1
  38. /* On-disk data structure. Integers are little-endian. */
  39. struct ccache_record_external {
  40. uint8_t ino[8];
  41. uint8_t size[8];
  42. uint8_t mtime[8];
  43. uint8_t nch[8];
  44. uint8_t tlen[4];
  45. uint8_t tzlen[4];
  46. uint8_t prefixlen[4];
  47. uint8_t suffixlen[4];
  48. uint8_t age[4];
  49. /* Immediately following each record is suffix[]. */
  50. };
  51. /**
  52. * After all of the ccache_record_external and suffix[] pairs, the
  53. * struct chunkheader chp[] and uint8_t ztrailer[] data is stored in the
  54. * same order.
  55. */
  56. /* Make sure the compiler isn't padding inappropriately. */
  57. CTASSERT(sizeof(struct ccache_record_external) == 52);
  58. #endif /* !CCACHE_INTERNAL_H_ */