]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/rock/RockDbCell.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / fs / rock / RockDbCell.h
1 /*
2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_FS_ROCK_DB_CELL_H
10 #define SQUID_FS_ROCK_DB_CELL_H
11
12 #include "store/forward.h"
13
14 namespace Rock
15 {
16
17 /** \ingroup Rock
18 * Meta-information at the beginning of every db cell.
19 * Links multiple map slots belonging to the same entry into an entry chain.
20 * Stored on disk and used as sizeof() argument so it must remain POD.
21 */
22 class DbCellHeader
23 {
24 public:
25 DbCellHeader();
26
27 /// true iff no entry occupies this slot
28 bool empty() const { return !firstSlot && !nextSlot && !payloadSize; }
29
30 /* members below are not meaningful if empty() */
31
32 /// whether this slot is not corrupted
33 bool sane(const size_t slotSize, int slotLimit) const {
34 return
35 0 <= firstSlot && firstSlot < slotLimit &&
36 -1 <= nextSlot && nextSlot < slotLimit &&
37 version > 0 &&
38 0 < payloadSize && payloadSize <= slotSize - sizeof(DbCellHeader);
39 }
40
41 uint64_t key[2]; ///< StoreEntry key
42 uint64_t entrySize; ///< total entry content size or zero if still unknown
43 uint32_t payloadSize; ///< slot contents size, always positive
44 uint32_t version; ///< detects conflicts among same-key entries
45 sfileno firstSlot; ///< slot ID of the first slot occupied by the entry
46 sfileno nextSlot; ///< slot ID of the next slot occupied by the entry
47 };
48
49 } // namespace Rock
50
51 #endif /* SQUID_FS_ROCK_DB_CELL_H */
52