]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | /* |
b510f3a1 | 2 | * DEBUG: section 00 UFS Store Dump Tool |
528b2c61 | 3 | * AUTHOR: Robert Collins |
4 | * | |
5 | * SQUID Web Proxy Cache http://www.squid-cache.org/ | |
6 | * ---------------------------------------------------------- | |
7 | * | |
8 | * Squid is the result of efforts by numerous individuals from | |
9 | * the Internet community; see the CONTRIBUTORS file for full | |
10 | * details. Many organizations have provided support for Squid's | |
11 | * development; see the SPONSORS file for full details. Squid is | |
12 | * Copyrighted (C) 2001 by the Regents of the University of | |
13 | * California; see the COPYRIGHT file for full details. Squid | |
14 | * incorporates software developed and/or copyrighted by other | |
15 | * sources; see the CREDITS file for full details. | |
16 | * | |
17 | * This program is free software; you can redistribute it and/or modify | |
18 | * it under the terms of the GNU General Public License as published by | |
19 | * the Free Software Foundation; either version 2 of the License, or | |
20 | * (at your option) any later version. | |
26ac0430 | 21 | * |
528b2c61 | 22 | * This program is distributed in the hope that it will be useful, |
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 | * GNU General Public License for more details. | |
26ac0430 | 26 | * |
528b2c61 | 27 | * You should have received a copy of the GNU General Public License |
28 | * along with this program; if not, write to the Free Software | |
29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
30 | * | |
31 | */ | |
32 | ||
f7f3304a | 33 | #include "squid.h" |
528b2c61 | 34 | #include "Generic.h" |
8822ebee | 35 | #include "mgr/Registration.h" |
602d9612 A |
36 | #include "Store.h" |
37 | #include "store_key_md5.h" | |
38 | #include "StoreMeta.h" | |
39 | #include "StoreMetaUnpacker.h" | |
8822ebee | 40 | |
528b2c61 | 41 | #undef malloc |
42 | #undef free | |
27e059d4 AJ |
43 | |
44 | #if HAVE_STDEXCEPT | |
528b2c61 | 45 | #include <stdexcept> |
27e059d4 AJ |
46 | #endif |
47 | #if HAVE_IOSTREAM | |
528b2c61 | 48 | #include <iostream> |
27e059d4 AJ |
49 | #endif |
50 | #if HAVE_CASSERT | |
7a6dc83d | 51 | #include <cassert> |
27e059d4 | 52 | #endif |
528b2c61 | 53 | |
c21ad0f5 | 54 | /* stub functions for parts of squid not factored to be dynamic yet */ |
74544ee3 AR |
55 | void |
56 | eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata) | |
528b2c61 | 57 | {} |
58 | ||
74544ee3 AR |
59 | // required by storeKeyPublicByRequest* |
60 | // XXX: what pulls in storeKeyPublicByRequest? | |
61 | const char *urlCanonical(HttpRequest *) { assert(false); return NULL; } | |
62 | ||
757a2291 | 63 | void |
74544ee3 AR |
64 | storeAppendPrintf(StoreEntry * e, const char *fmt,...) |
65 | { | |
66 | va_list args; | |
67 | va_start(args, fmt); | |
68 | ||
af6a12ee | 69 | assert(false); |
74544ee3 AR |
70 | |
71 | va_end(args); | |
72 | } | |
73 | ||
c21ad0f5 | 74 | void |
8822ebee | 75 | Mgr::RegisterAction(char const * action, char const * desc, OBJH * handler, int pw_req_flag, int atomic) {} |
74544ee3 | 76 | |
f3f3e961 GS |
77 | /* MinGW needs also a stub of death() */ |
78 | void | |
79 | death(int sig) | |
80 | { | |
81 | std::cout << "Fatal: Signal " << sig; | |
b61a58df | 82 | exit(1); |
f3f3e961 GS |
83 | } |
84 | ||
b61a58df AJ |
85 | void |
86 | fatal(const char *message) | |
87 | { | |
88 | fprintf(stderr, "FATAL: %s\n", message); | |
89 | exit(1); | |
90 | } | |
c21ad0f5 | 91 | |
c21ad0f5 | 92 | /* end stub functions */ |
528b2c61 | 93 | |
26ac0430 | 94 | struct MetaStd { |
47f6e231 | 95 | time_t timestamp; |
26ac0430 AJ |
96 | time_t lastref; |
97 | time_t expires; | |
98 | time_t lastmod; | |
99 | size_t swap_file_sz; | |
f45dd259 AJ |
100 | uint16_t refcount; |
101 | uint16_t flags; | |
47f6e231 | 102 | }; |
103 | ||
26ac0430 AJ |
104 | struct MetaStdLfs { |
105 | time_t timestamp; | |
106 | time_t lastref; | |
107 | time_t expires; | |
108 | time_t lastmod; | |
109 | uint64_t swap_file_sz; | |
f45dd259 AJ |
110 | uint16_t refcount; |
111 | uint16_t flags; | |
47f6e231 | 112 | }; |
113 | ||
26ac0430 AJ |
114 | struct DumpStoreMeta : public unary_function<StoreMeta, void> { |
115 | DumpStoreMeta() {} | |
528b2c61 | 116 | |
26ac0430 | 117 | void operator()(StoreMeta const &x) { |
528b2c61 | 118 | switch (x.getType()) { |
62e76326 | 119 | |
120 | case STORE_META_KEY: | |
121 | std::cout << "MD5: " << storeKeyText((const cache_key *)x.value) << std::endl; | |
122 | break; | |
123 | ||
124 | case STORE_META_STD: | |
26ac0430 AJ |
125 | std::cout << "STD, Size:" << ((struct MetaStd*)x.value)->swap_file_sz << |
126 | " Flags: 0x" << std::hex << ((struct MetaStd*)x.value)->flags << std::dec << | |
127 | " Refcount: " << ((struct MetaStd*)x.value)->refcount << | |
128 | std::endl; | |
47f6e231 | 129 | break; |
130 | ||
131 | case STORE_META_STD_LFS: | |
26ac0430 AJ |
132 | std::cout << "STD_LFS, Size: " << ((struct MetaStdLfs*)x.value)->swap_file_sz << |
133 | " Flags: 0x" << std::hex << ((struct MetaStdLfs*)x.value)->flags << std::dec << | |
134 | " Refcount: " << ((struct MetaStdLfs*)x.value)->refcount << | |
135 | std::endl; | |
62e76326 | 136 | break; |
137 | ||
138 | case STORE_META_URL: | |
139 | assert (((char *)x.value)[x.length - 1] == 0); | |
140 | std::cout << "URL: " << (char *)x.value << std::endl; | |
47f6e231 | 141 | break; |
62e76326 | 142 | |
143 | default: | |
26ac0430 AJ |
144 | std::cout << "Unknown store meta type: " << (int)x.getType() << |
145 | " of length " << x.length << std::endl; | |
62e76326 | 146 | break; |
147 | } | |
528b2c61 | 148 | } |
149 | }; | |
150 | ||
151 | int | |
152 | main(int argc, char *argv[]) | |
153 | { | |
154 | int fd = -1; | |
155 | StoreMeta *metadata = NULL; | |
156 | ||
26ac0430 | 157 | try { |
528b2c61 | 158 | if (argc != 2) |
159 | throw std::runtime_error("No filename provided"); | |
160 | ||
161 | fd = open (argv[1], O_RDONLY | O_BINARY); | |
162 | ||
163 | if (fd < 0) | |
164 | throw std::runtime_error("Could not open file."); | |
165 | ||
166 | char tempbuf[SM_PAGE_SIZE]; | |
167 | ||
168 | int len = read(fd, tempbuf, SM_PAGE_SIZE); | |
169 | ||
170 | if (len < 0) | |
171 | throw std::runtime_error("Could not read header into memory."); | |
172 | ||
173 | close (fd); | |
174 | ||
175 | fd = -1; | |
176 | ||
177 | int hdr_len; | |
178 | ||
179 | StoreMetaUnpacker aBuilder(tempbuf, len, &hdr_len); | |
180 | ||
181 | metadata = aBuilder.createStoreMeta (); | |
182 | ||
c3031d67 | 183 | cache_key key[SQUID_MD5_DIGEST_LENGTH]; |
528b2c61 | 184 | |
c3031d67 | 185 | memset(key, '\0', SQUID_MD5_DIGEST_LENGTH); |
528b2c61 | 186 | |
62e76326 | 187 | DumpStoreMeta dumper; |
188 | ||
189 | for_each(*metadata, dumper); | |
528b2c61 | 190 | |
528b2c61 | 191 | return 0; |
26ac0430 | 192 | } catch (std::runtime_error error) { |
528b2c61 | 193 | std::cout << "Failed : " << error.what() << std::endl; |
194 | ||
195 | if (fd >= 0) | |
196 | close(fd); | |
197 | ||
198 | if (metadata) | |
199 | StoreMeta::FreeList(&metadata); | |
200 | ||
201 | return 1; | |
202 | } | |
203 | } |