]> git.ipfire.org Git - thirdparty/squid.git/blame - src/StoreSwapLogData.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / StoreSwapLogData.h
CommitLineData
51ee7c82 1/*
262a0e14 2 * $Id$
51ee7c82 3 *
4 * SQUID Web Proxy Cache http://www.squid-cache.org/
5 * ----------------------------------------------------------
6 *
7 * Squid is the result of efforts by numerous individuals from
8 * the Internet community; see the CONTRIBUTORS file for full
9 * details. Many organizations have provided support for Squid's
10 * development; see the SPONSORS file for full details. Squid is
11 * Copyrighted (C) 2001 by the Regents of the University of
12 * California; see the COPYRIGHT file for full details. Squid
13 * incorporates software developed and/or copyrighted by other
14 * sources; see the CREDITS file for full details.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
26ac0430 20 *
51ee7c82 21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26ac0430 25 *
51ee7c82 26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
29 *
30 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
31 */
32
33#ifndef SQUID_STORESWAPLOGDATA_H
34#define SQUID_STORESWAPLOGDATA_H
35
63be0a78 36/**
37 \defgroup FileFormatSwapStateAPI swap.state File Structure
38 \ingroup FileSystems
39 \section ImplementationNotes Implementation Notes
40 \par
41 * When writing an object to disk, we must first write the meta data.
42 * This is done with a couple of functions. First, storeSwapMetaPack()
43 * takes a StoreEntry as a parameter and returns a tlv linked
44 * list. Second, storeSwapMetaPack() converts the tlv list
45 * into a character buffer that we can write.
26ac0430 46 *
63be0a78 47 \note MemObject has a MemObject::swap_hdr_sz.
48 * This value is the size of that character buffer; the size of the
49 * swap file meta data. The StoreEntry has a member
50 * StoreEntry::swap_file_sz that represents the size of the disk file.
51 * Thus, the size of the object "content" is
52 \code StoreEntry->swap_file_sz - MemObject->swap_hdr_sz; \endcode
53 \note The swap file content includes the HTTP reply headers and the HTTP reply body (if any).
26ac0430 54 *
63be0a78 55 \par
56 * When reading a swap file, there is a similar process to extract
57 * the swap meta data. First, storeSwapMetaUnpack() converts a
58 * character buffer into a tlv linked list. It also tells us
59 * the value for MemObject->swap_hdr_sz.
60 */
61
582c2af2
FC
62#include "md5.h"
63#include "MemPool.h"
64#include "typedefs.h"
51ee7c82 65
786f6516 66/// maintains a 24-bit checksum over integer fields
d178daf7
A
67class SwapChecksum24
68{
786f6516
AR
69public:
70 SwapChecksum24() { raw[0] = raw[1] = raw[2] = 0; }
71
d178daf7 72 bool operator ==(const SwapChecksum24 &o) const {
786f6516
AR
73 return raw[0] == o.raw[0] && raw[1] == o.raw[1] && raw[2] == o.raw[2];
74 }
75
d178daf7 76 bool operator !=(const SwapChecksum24 &o) const {
786f6516
AR
77 return !(*this == o);
78 }
79
80 /// compute and store checksum based on three 32bit integers
81 void set(uint32_t f1, uint32_t f2, uint32_t f3);
82
83 /// compute and store checksum based on int32_t and uint64_t integers
84 void set(int32_t f1, uint64_t f2);
85
86 // printing for debugging
87 std::ostream &print(std::ostream &os) const;
88
89private:
90 uint8_t raw[3]; // designed to follow "op" members, in pading space
91};
92
93inline std::ostream &
94operator <<(std::ostream &os, const SwapChecksum24 &sum)
95{
96 return sum.print(os);
97}
98
63be0a78 99/**
100 \ingroup FielFormatSwapStateAPI
63be0a78 101 *
102 \par
786f6516
AR
103 * Defines the structure of a binary swap.state file entry for UFS stores.
104 * TODO: Move to fs/ufs (and remove from COSS).
63be0a78 105 *
106 \note StoreSwapLogData entries are written in native machine byte order
107 * They are not necessarily portable across architectures.
51ee7c82 108 */
51ee7c82 109class StoreSwapLogData
110{
111
112public:
b001e822 113 MEMPROXY_CLASS(StoreSwapLogData);
786f6516
AR
114
115 /// type to use for storing time-related members; must be signed
116 typedef int64_t SwappedTime;
117
51ee7c82 118 StoreSwapLogData();
63be0a78 119
3f9d4dc2
AR
120 /// consistency self-check: whether the data appears to make sense
121 bool sane() const;
122
786f6516
AR
123 /// call this before storing the log entry
124 void finalize();
125
63be0a78 126 /**
127 * Either SWAP_LOG_ADD when an object is added to the disk storage,
128 * or SWAP_LOG_DEL when an object is deleted.
129 */
786f6516
AR
130 uint8_t op;
131
132 /**
133 * Fingerprint to weed out bogus/corrupted swap.state entries.
134 */
135 SwapChecksum24 checksum; // follows "op" because compiler will pad anyway
63be0a78 136
137 /**
138 * The 32-bit file number which maps to a pathname.
139 * Only the low 24-bits are relevant. The high 8-bits are
140 * used as an index to an array of storage directories, and
141 * are set at run time because the order of storage directories
142 * may change over time.
143 */
51ee7c82 144 sfileno swap_filen;
63be0a78 145
146 /**
786f6516 147 * A Unix time value that represents the time when
63be0a78 148 * the origin server generated this response. If the response
149 * has a valid Date: header, this timestamp corresponds
150 * to that time. Otherwise, it is set to the Squid process time
151 * when the response is read (as soon as the end of headers are found).
152 */
786f6516 153 SwappedTime timestamp;
63be0a78 154
155 /**
156 * The last time that a client requested this object.
157 * Strictly speaking, this time is set whenever the StoreEntry
158 * is locked (via storeLockObject()).
159 */
786f6516 160 SwappedTime lastref;
63be0a78 161
162 /**
163 * The value of the response's Expires: header, if any.
164 * If the response does not have an Expires: header, this
165 * is set to -1.
166 * If the response has an invalid (unparseable)
167 * Expires: header, it is also set to -1. There are some cases
168 * where Squid sets expires to -2. This happens for the
169 * internal "netdb" object and for FTP URL responses.
170 */
786f6516 171 SwappedTime expires;
63be0a78 172
173 /**
174 * The value of the response's Last-modified: header, if any.
175 * This is set to -1 if there is no Last-modified: header,
176 * or if it is unparseable.
177 */
786f6516 178 SwappedTime lastmod;
63be0a78 179
180 /**
181 * This is the number of bytes that the object occupies on
182 * disk. It includes the Squid "swap file header".
183 */
47f6e231 184 uint64_t swap_file_sz;
63be0a78 185
186 /**
187 * The number of times that this object has been accessed (referenced).
188 * Since its a 16-bit quantity, it is susceptible to overflow
189 * if a single object is accessed 65,536 times before being replaced.
190 */
f45dd259 191 uint16_t refcount;
63be0a78 192
193 /**
194 * A copy of the StoreEntry flags field. Used as a sanity
195 * check when rebuilding the cache at startup. Objects that
196 * have the KEY_PRIVATE flag set are not added back to the cache.
197 */
f45dd259 198 uint16_t flags;
63be0a78 199
200 /**
201 * The 128-bit MD5 hash for this object.
202 */
c3031d67 203 unsigned char key[SQUID_MD5_DIGEST_LENGTH];
51ee7c82 204};
205
d85b8894 206MEMPROXY_CLASS_INLINE(StoreSwapLogData);
b001e822 207
63be0a78 208/// \ingroup FileFormatSwapStateAPI
786f6516 209/// Swap log starts with this binary structure.
47f6e231 210class StoreSwapLogHeader
211{
212public:
786f6516 213 // sets default values for this Squid version; loaded values may differ
26ac0430 214 StoreSwapLogHeader();
786f6516
AR
215
216 /// consistency self-check: whether the data appears to make sense
217 bool sane() const;
218
219 /// number of bytes after the log header before the first log entry
220 size_t gapSize() const;
221
222 uint8_t op;
223 SwapChecksum24 checksum; // follows "op" because compiler will pad anyway
224 int32_t version;
225 int32_t record_size;
47f6e231 226};
227
51ee7c82 228#endif /* SQUID_STORESWAPLOGDATA_H */