Squid Web Cache
master
Loading...
Searching...
No Matches
StoreSwapLogData.cc
Go to the documentation of this file.
1
/*
2
* Copyright (C) 1996-2025 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
/* DEBUG: section 47 Store Directory Routines */
10
11
#include "
squid.h
"
12
#include "
StoreSwapLogData.h
"
13
#include "
swap_log_op.h
"
14
15
#include <ostream>
16
17
// Based on Internet Checksum (RFC 1071) algorithm but takes three 32bit ints.
18
// TODO: Consider Fletcher's checksum algorithm as a higher quality alternative
19
void
20
SwapChecksum24::set
(uint32_t f1, uint32_t f2, uint32_t f3)
21
{
22
uint64_t sum = f1;
23
sum += f2;
24
sum += f3;
25
26
while
(
const
uint64_t higherBits = sum >> 24)
27
sum = (sum & 0xFFFFFF) + higherBits;
28
29
sum = ~sum;
30
31
raw
[0] =
static_cast<
uint8_t
>
(sum);
32
raw
[1] =
static_cast<
uint8_t
>
(sum >> 8);
33
raw
[2] =
static_cast<
uint8_t
>
(sum >> 16);
34
}
35
37
void
38
SwapChecksum24::set
(int32_t f1, uint64_t f2)
39
{
40
// split the second 64bit word into two 32bit words
41
set
(
static_cast<
uint32_t
>
(f1),
42
static_cast<
uint32_t
>
(f2 >> 32),
43
static_cast<
uint32_t
>
(f2 & 0xFFFFFFFF));
44
}
45
46
std::ostream &
47
SwapChecksum24::print
(std::ostream &os)
const
48
{
49
return
os <<
raw
[0] <<
'-'
<<
raw
[1] <<
'-'
<<
raw
[2];
50
}
51
52
bool
53
StoreSwapLogData::sane
()
const
54
{
55
SwapChecksum24
actualSum;
56
actualSum.
set
(
swap_filen
,
swap_file_sz
);
57
if
(
checksum
!= actualSum)
58
return
false
;
59
60
const
time_t minTime = -2;
// -1 is common; expires sometimes uses -2
61
62
// Check what we safely can; for some fields any value might be valid
63
return
SWAP_LOG_NOP
<
op
&&
op
<
SWAP_LOG_MAX
&&
64
swap_filen
>= 0 &&
65
timestamp
>= minTime &&
66
lastref
>= minTime &&
67
expires
>= minTime &&
68
lastmod
>= minTime &&
69
swap_file_sz
> 0;
// because swap headers ought to consume space
70
}
71
72
void
73
StoreSwapLogData::finalize
()
74
{
75
checksum
.
set
(
swap_filen
,
swap_file_sz
);
76
}
77
78
StoreSwapLogHeader::StoreSwapLogHeader
(): op(
SWAP_LOG_VERSION
),
version
(2),
79
record_size(sizeof(
StoreSwapLogData
))
80
{
81
checksum
.
set
(
version
,
record_size
, 0);
82
}
83
84
bool
85
StoreSwapLogHeader::sane
()
const
86
{
87
SwapChecksum24
actualSum;
88
actualSum.
set
(
version
,
record_size
, 0);
89
if
(
checksum
!= actualSum)
90
return
false
;
91
92
return
op
==
SWAP_LOG_VERSION
&&
version
>= 2 &&
record_size
> 0;
93
}
94
95
size_t
96
StoreSwapLogHeader::gapSize
()
const
97
{
98
assert
(
record_size
> 0);
99
assert
(
static_cast<
size_t
>
(
record_size
) >
sizeof
(*
this
));
100
return
static_cast<
size_t
>
(
record_size
) -
sizeof
(*
this
);
101
}
102
StoreSwapLogData.h
assert
#define assert(EX)
Definition
assert.h:17
version
static int version
Definition
basic_ldap_auth.cc:166
StoreSwapLogData
Definition
StoreSwapLogData.h:83
StoreSwapLogData::timestamp
SwappedTime timestamp
Definition
StoreSwapLogData.h:123
StoreSwapLogData::lastref
SwappedTime lastref
Definition
StoreSwapLogData.h:128
StoreSwapLogData::sane
bool sane() const
consistency self-check: whether the data appears to make sense
Definition
StoreSwapLogData.cc:53
StoreSwapLogData::swap_file_sz
uint64_t swap_file_sz
Definition
StoreSwapLogData.h:152
StoreSwapLogData::lastmod
SwappedTime lastmod
Definition
StoreSwapLogData.h:146
StoreSwapLogData::expires
SwappedTime expires
Definition
StoreSwapLogData.h:139
StoreSwapLogData::finalize
void finalize()
call this before storing the log entry
Definition
StoreSwapLogData.cc:73
StoreSwapLogData::swap_filen
sfileno swap_filen
Definition
StoreSwapLogData.h:114
StoreSwapLogData::checksum
SwapChecksum24 checksum
Definition
StoreSwapLogData.h:105
StoreSwapLogData::op
uint8_t op
Definition
StoreSwapLogData.h:100
StoreSwapLogHeader::gapSize
size_t gapSize() const
number of bytes after the log header before the first log entry
Definition
StoreSwapLogData.cc:96
StoreSwapLogHeader::sane
bool sane() const
consistency self-check: whether the data appears to make sense
Definition
StoreSwapLogData.cc:85
StoreSwapLogHeader::checksum
SwapChecksum24 checksum
Definition
StoreSwapLogData.h:189
StoreSwapLogHeader::version
int32_t version
Definition
StoreSwapLogData.h:190
StoreSwapLogHeader::op
uint8_t op
Definition
StoreSwapLogData.h:188
StoreSwapLogHeader::StoreSwapLogHeader
StoreSwapLogHeader()
Definition
StoreSwapLogData.cc:78
StoreSwapLogHeader::record_size
int32_t record_size
Definition
StoreSwapLogData.h:191
SwapChecksum24
maintains a 24-bit checksum over integer fields
Definition
StoreSwapLogData.h:41
SwapChecksum24::set
void set(uint32_t f1, uint32_t f2, uint32_t f3)
compute and store checksum based on three 32bit integers
Definition
StoreSwapLogData.cc:20
SwapChecksum24::raw
uint8_t raw[3]
Definition
StoreSwapLogData.h:63
SwapChecksum24::print
std::ostream & print(std::ostream &os) const
Definition
StoreSwapLogData.cc:47
squid.h
swap_log_op.h
SWAP_LOG_MAX
@ SWAP_LOG_MAX
Definition
swap_log_op.h:17
SWAP_LOG_NOP
@ SWAP_LOG_NOP
Definition
swap_log_op.h:13
SWAP_LOG_VERSION
@ SWAP_LOG_VERSION
Definition
swap_log_op.h:16
squid
src
StoreSwapLogData.cc
Generated by
1.9.8