]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ufsdump.cc
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 00 UFS Store Dump Tool */
14 #include "mgr/Registration.h"
16 #include "store_key_md5.h"
17 #include "StoreMeta.h"
18 #include "StoreMetaUnpacker.h"
27 /* stub functions for parts of squid not factored to be dynamic yet */
29 eventAdd(const char *name
, EVH
* func
, void *arg
, double when
, int, bool cbdata
)
32 // required by storeKeyPublicByRequest*
33 // XXX: what pulls in storeKeyPublicByRequest?
34 const char *urlCanonical(HttpRequest
*) { assert(false); return NULL
; }
37 storeAppendPrintf(StoreEntry
* e
, const char *fmt
,...)
48 Mgr::RegisterAction(char const * action
, char const * desc
, OBJH
* handler
, int pw_req_flag
, int atomic
) {}
50 /* MinGW needs also a stub of death() */
54 std::cout
<< "Fatal: Signal " << sig
;
59 fatal(const char *message
)
61 fprintf(stderr
, "FATAL: %s\n", message
);
65 /* end stub functions */
82 uint64_t swap_file_sz
;
87 struct DumpStoreMeta
: public unary_function
<StoreMeta
, void> {
90 void operator()(StoreMeta
const &x
) {
91 switch (x
.getType()) {
94 std::cout
<< "MD5: " << storeKeyText((const cache_key
*)x
.value
) << std::endl
;
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
<<
104 case STORE_META_STD_LFS
:
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
<<
112 assert (((char *)x
.value
)[x
.length
- 1] == 0);
113 std::cout
<< "URL: " << (char *)x
.value
<< std::endl
;
117 std::cout
<< "Unknown store meta type: " << (int)x
.getType() <<
118 " of length " << x
.length
<< std::endl
;
125 main(int argc
, char *argv
[])
128 StoreMeta
*metadata
= NULL
;
132 throw std::runtime_error("No filename provided");
134 fd
= open (argv
[1], O_RDONLY
| O_BINARY
);
137 throw std::runtime_error("Could not open file.");
139 char tempbuf
[SM_PAGE_SIZE
];
141 int len
= read(fd
, tempbuf
, SM_PAGE_SIZE
);
144 throw std::runtime_error("Could not read header into memory.");
152 StoreMetaUnpacker
aBuilder(tempbuf
, len
, &hdr_len
);
154 metadata
= aBuilder
.createStoreMeta ();
156 cache_key key
[SQUID_MD5_DIGEST_LENGTH
];
158 memset(key
, '\0', SQUID_MD5_DIGEST_LENGTH
);
160 DumpStoreMeta dumper
;
162 for_each(*metadata
, dumper
);
165 } catch (std::runtime_error error
) {
166 std::cout
<< "Failed : " << error
.what() << std::endl
;
172 StoreMeta::FreeList(&metadata
);