simple_entry_format.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_FORMAT_H_
  5. #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_FORMAT_H_
  6. #include <stdint.h>
  7. #include "net/base/net_export.h"
  8. namespace disk_cache {
  9. const uint64_t kSimpleInitialMagicNumber = UINT64_C(0xfcfb6d1ba7725c30);
  10. const uint64_t kSimpleFinalMagicNumber = UINT64_C(0xf4fa6f45970d41d8);
  11. const uint64_t kSimpleSparseRangeMagicNumber = UINT64_C(0xeb97bf016553676b);
  12. // A file containing stream 0 and stream 1 in the Simple cache consists of:
  13. // - a SimpleFileHeader.
  14. // - the key.
  15. // - the data from stream 1.
  16. // - a SimpleFileEOF record for stream 1.
  17. // - the data from stream 0.
  18. // - (optionally) the SHA256 of the key.
  19. // - a SimpleFileEOF record for stream 0.
  20. //
  21. // Because stream 0 data (typically HTTP headers) is on the critical path of
  22. // requests, on open, the cache reads the end of the record and does not
  23. // read the SimpleFileHeader. If the key can be validated with a SHA256, then
  24. // the stream 0 data can be returned to the caller without reading the
  25. // SimpleFileHeader. If the key SHA256 is not present, then the cache must
  26. // read the SimpleFileHeader to confirm key equality.
  27. // A file containing stream 2 in the Simple cache consists of:
  28. // - a SimpleFileHeader.
  29. // - the key.
  30. // - the data.
  31. // - at the end, a SimpleFileEOF record.
  32. // This is the number of files we can use for representing normal/dense streams.
  33. static const int kSimpleEntryNormalFileCount = 2;
  34. static const int kSimpleEntryStreamCount = 3;
  35. // Total # of files name we can potentially use; this includes both normal
  36. // API and sparse streams.
  37. static const int kSimpleEntryTotalFileCount = kSimpleEntryNormalFileCount + 1;
  38. // Note that stream 0/stream 1 files rely on the footer to verify the entry,
  39. // so if the format changes, it's insufficient to change the version here;
  40. // likely the EOF magic should be updated as well.
  41. struct NET_EXPORT_PRIVATE SimpleFileHeader {
  42. SimpleFileHeader();
  43. uint64_t initial_magic_number;
  44. uint32_t version;
  45. uint32_t key_length;
  46. uint32_t key_hash;
  47. };
  48. struct NET_EXPORT_PRIVATE SimpleFileEOF {
  49. enum Flags {
  50. FLAG_HAS_CRC32 = (1U << 0),
  51. FLAG_HAS_KEY_SHA256 = (1U << 1), // Preceding the record if present.
  52. };
  53. SimpleFileEOF();
  54. uint64_t final_magic_number;
  55. uint32_t flags;
  56. uint32_t data_crc32;
  57. // |stream_size| is only used in the EOF record for stream 0.
  58. uint32_t stream_size;
  59. };
  60. struct SimpleFileSparseRangeHeader {
  61. SimpleFileSparseRangeHeader();
  62. uint64_t sparse_range_magic_number;
  63. int64_t offset;
  64. int64_t length;
  65. uint32_t data_crc32;
  66. };
  67. } // namespace disk_cache
  68. #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_FORMAT_H_