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