1 /*
2  * Copyright (C) 1996-2021 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_UFS_REBUILDSTATE_H
10 #define SQUID_FS_UFS_REBUILDSTATE_H
11 
12 #include "base/RefCount.h"
13 #include "store_rebuild.h"
14 #include "UFSSwapDir.h"
15 #include "UFSSwapLogParser.h"
16 
17 class StoreEntry;
18 
19 namespace Fs
20 {
21 namespace Ufs
22 {
23 
24 class RebuildState
25 {
26     CBDATA_CLASS(RebuildState);
27 
28 public:
29     static EVH RebuildStep;
30 
31     RebuildState(RefCount<UFSSwapDir> sd);
32     virtual ~RebuildState();
33 
34     virtual bool error() const;
35     virtual bool isDone() const;
36 
37     RefCount<UFSSwapDir> sd;
38     int n_read;
39     /*    FILE *log;*/
40     Fs::Ufs::UFSSwapLogParser *LogParser;
41     int curlvl1;
42     int curlvl2;
43 
44     struct Flags {
FlagsFlags45         Flags() : need_to_validate(false), clean(false), init(false) {}
46         bool need_to_validate;
47         bool clean;
48         bool init;
49     } flags;
50     int in_dir;
51     int done;
52     int fn;
53 
54     dirent_t *entry;
55     DIR *td;
56     char fullpath[MAXPATHLEN];
57     char fullfilename[MAXPATHLEN*2];
58 
59     StoreRebuildData counts;
60 
61 private:
62     void rebuildFromDirectory();
63     void rebuildFromSwapLog();
64     void rebuildStep();
65     void addIfFresh(const cache_key *key,
66                     sfileno file_number,
67                     uint64_t swap_file_sz,
68                     time_t expires,
69                     time_t timestamp,
70                     time_t lastref,
71                     time_t lastmod,
72                     uint32_t refcount,
73                     uint16_t flags);
74     bool evictStaleAndContinue(const cache_key *candidateKey, const time_t maxRef, int &staleCount);
75     int getNextFile(sfileno *, int *size);
76     bool fromLog;
77     bool _done;
78     /// \bug (callback) should be hidden behind a proper human readable name
79     void (callback)(void *cbdata);
80     void *cbdata;
81 };
82 
83 } /* namespace Ufs */
84 } /* namespace Fs */
85 
86 #endif /* SQUID_FS_UFS_REBUILDSTATE_H */
87 
88