]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | /* |
f6e9a3ee | 2 | * Copyright (C) 1996-2019 The Squid Software Foundation and contributors |
528b2c61 | 3 | * |
bbc27441 AJ |
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. | |
528b2c61 | 7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 00 UFS Store Dump Tool */ |
10 | ||
f7f3304a | 11 | #include "squid.h" |
528b2c61 | 12 | #include "Generic.h" |
0a38d7d0 | 13 | #include "md5.h" |
8822ebee | 14 | #include "mgr/Registration.h" |
602d9612 A |
15 | #include "Store.h" |
16 | #include "store_key_md5.h" | |
17 | #include "StoreMeta.h" | |
18 | #include "StoreMetaUnpacker.h" | |
8822ebee | 19 | |
528b2c61 | 20 | #undef malloc |
21 | #undef free | |
27e059d4 | 22 | |
7a6dc83d | 23 | #include <cassert> |
074d6a40 AJ |
24 | #include <iostream> |
25 | #include <stdexcept> | |
528b2c61 | 26 | |
c21ad0f5 | 27 | /* stub functions for parts of squid not factored to be dynamic yet */ |
74544ee3 AR |
28 | void |
29 | eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata) | |
528b2c61 | 30 | {} |
31 | ||
74544ee3 AR |
32 | // required by storeKeyPublicByRequest* |
33 | // XXX: what pulls in storeKeyPublicByRequest? | |
34 | const char *urlCanonical(HttpRequest *) { assert(false); return NULL; } | |
35 | ||
757a2291 | 36 | void |
74544ee3 AR |
37 | storeAppendPrintf(StoreEntry * e, const char *fmt,...) |
38 | { | |
39 | va_list args; | |
40 | va_start(args, fmt); | |
41 | ||
af6a12ee | 42 | assert(false); |
74544ee3 AR |
43 | |
44 | va_end(args); | |
45 | } | |
46 | ||
c21ad0f5 | 47 | void |
8822ebee | 48 | Mgr::RegisterAction(char const * action, char const * desc, OBJH * handler, int pw_req_flag, int atomic) {} |
74544ee3 | 49 | |
f3f3e961 GS |
50 | /* MinGW needs also a stub of death() */ |
51 | void | |
52 | death(int sig) | |
53 | { | |
54 | std::cout << "Fatal: Signal " << sig; | |
24885773 | 55 | exit(EXIT_FAILURE); |
f3f3e961 GS |
56 | } |
57 | ||
b61a58df AJ |
58 | void |
59 | fatal(const char *message) | |
60 | { | |
61 | fprintf(stderr, "FATAL: %s\n", message); | |
24885773 | 62 | exit(EXIT_FAILURE); |
b61a58df | 63 | } |
c21ad0f5 | 64 | |
c21ad0f5 | 65 | /* end stub functions */ |
528b2c61 | 66 | |
26ac0430 | 67 | struct MetaStd { |
47f6e231 | 68 | time_t timestamp; |
26ac0430 AJ |
69 | time_t lastref; |
70 | time_t expires; | |
71 | time_t lastmod; | |
72 | size_t swap_file_sz; | |
f45dd259 AJ |
73 | uint16_t refcount; |
74 | uint16_t flags; | |
47f6e231 | 75 | }; |
76 | ||
26ac0430 AJ |
77 | struct MetaStdLfs { |
78 | time_t timestamp; | |
79 | time_t lastref; | |
80 | time_t expires; | |
81 | time_t lastmod; | |
82 | uint64_t swap_file_sz; | |
f45dd259 AJ |
83 | uint16_t refcount; |
84 | uint16_t flags; | |
47f6e231 | 85 | }; |
86 | ||
26ac0430 AJ |
87 | struct DumpStoreMeta : public unary_function<StoreMeta, void> { |
88 | DumpStoreMeta() {} | |
528b2c61 | 89 | |
26ac0430 | 90 | void operator()(StoreMeta const &x) { |
528b2c61 | 91 | switch (x.getType()) { |
62e76326 | 92 | |
93 | case STORE_META_KEY: | |
94 | std::cout << "MD5: " << storeKeyText((const cache_key *)x.value) << std::endl; | |
95 | break; | |
96 | ||
97 | case STORE_META_STD: | |
26ac0430 AJ |
98 | std::cout << "STD, Size:" << ((struct MetaStd*)x.value)->swap_file_sz << |
99 | " Flags: 0x" << std::hex << ((struct MetaStd*)x.value)->flags << std::dec << | |
100 | " Refcount: " << ((struct MetaStd*)x.value)->refcount << | |
101 | std::endl; | |
47f6e231 | 102 | break; |
103 | ||
104 | case STORE_META_STD_LFS: | |
26ac0430 AJ |
105 | std::cout << "STD_LFS, Size: " << ((struct MetaStdLfs*)x.value)->swap_file_sz << |
106 | " Flags: 0x" << std::hex << ((struct MetaStdLfs*)x.value)->flags << std::dec << | |
107 | " Refcount: " << ((struct MetaStdLfs*)x.value)->refcount << | |
108 | std::endl; | |
62e76326 | 109 | break; |
110 | ||
111 | case STORE_META_URL: | |
112 | assert (((char *)x.value)[x.length - 1] == 0); | |
113 | std::cout << "URL: " << (char *)x.value << std::endl; | |
47f6e231 | 114 | break; |
62e76326 | 115 | |
116 | default: | |
26ac0430 AJ |
117 | std::cout << "Unknown store meta type: " << (int)x.getType() << |
118 | " of length " << x.length << std::endl; | |
62e76326 | 119 | break; |
120 | } | |
528b2c61 | 121 | } |
122 | }; | |
123 | ||
124 | int | |
125 | main(int argc, char *argv[]) | |
126 | { | |
127 | int fd = -1; | |
128 | StoreMeta *metadata = NULL; | |
129 | ||
26ac0430 | 130 | try { |
528b2c61 | 131 | if (argc != 2) |
132 | throw std::runtime_error("No filename provided"); | |
133 | ||
134 | fd = open (argv[1], O_RDONLY | O_BINARY); | |
135 | ||
136 | if (fd < 0) | |
137 | throw std::runtime_error("Could not open file."); | |
138 | ||
139 | char tempbuf[SM_PAGE_SIZE]; | |
140 | ||
141 | int len = read(fd, tempbuf, SM_PAGE_SIZE); | |
142 | ||
143 | if (len < 0) | |
144 | throw std::runtime_error("Could not read header into memory."); | |
145 | ||
146 | close (fd); | |
147 | ||
148 | fd = -1; | |
149 | ||
150 | int hdr_len; | |
151 | ||
152 | StoreMetaUnpacker aBuilder(tempbuf, len, &hdr_len); | |
153 | ||
154 | metadata = aBuilder.createStoreMeta (); | |
155 | ||
c3031d67 | 156 | cache_key key[SQUID_MD5_DIGEST_LENGTH]; |
528b2c61 | 157 | |
c3031d67 | 158 | memset(key, '\0', SQUID_MD5_DIGEST_LENGTH); |
528b2c61 | 159 | |
62e76326 | 160 | DumpStoreMeta dumper; |
161 | ||
162 | for_each(*metadata, dumper); | |
528b2c61 | 163 | |
4c2f8b72 EB |
164 | } catch (const std::exception &e) { |
165 | std::cout << "Failed : " << e.what() << std::endl; | |
528b2c61 | 166 | |
167 | if (fd >= 0) | |
168 | close(fd); | |
169 | ||
170 | if (metadata) | |
171 | StoreMeta::FreeList(&metadata); | |
172 | ||
24885773 | 173 | return EXIT_FAILURE; |
528b2c61 | 174 | } |
24885773 AJ |
175 | |
176 | return EXIT_SUCCESS; | |
528b2c61 | 177 | } |
f53969cc | 178 |