Commit | Line | Data |
a9fd575d |
1 | #!/usr/local/bin/perl |
2 | |
3 | # Name: dbinfo -- identify berkeley DB version used to create |
4 | # a database file |
5 | # |
6 | # Author: Paul Marquess |
7 | # Version: 1.01 |
8 | # Date 16th April 1998 |
9 | # |
10 | # Copyright (c) 1998 Paul Marquess. All rights reserved. |
11 | # This program is free software; you can redistribute it and/or |
12 | # modify it under the same terms as Perl itself. |
13 | |
14 | # Todo: Print more stats on a db file, e.g. no of records |
15 | # add log/txn/lock files |
16 | |
17 | use strict ; |
18 | |
19 | my %Data = |
20 | ( |
21 | 0x053162 => { |
22 | Type => "Btree", |
23 | Versions => |
24 | { |
25 | 1 => "Unknown (older than 1.71)", |
26 | 2 => "Unknown (older than 1.71)", |
27 | 3 => "1.71 -> 1.85, 1.86", |
28 | 4 => "Unknown", |
29 | 5 => "2.0.0 -> 2.3.0", |
30 | 6 => "2.3.1 or greater", |
31 | } |
32 | }, |
33 | 0x061561 => { |
34 | Type => "Hash", |
35 | Versions => |
36 | { |
37 | 1 => "Unknown (older than 1.71)", |
38 | 2 => "1.71 -> 1.85", |
39 | 3 => "1.86", |
40 | 4 => "2.0.0 -> 2.1.0", |
41 | 5 => "2.2.6 or greater", |
42 | } |
43 | }, |
44 | ) ; |
45 | |
46 | die "Usage: dbinfo file\n" unless @ARGV == 1 ; |
47 | |
48 | print "testing file $ARGV[0]...\n\n" ; |
49 | open (F, "<$ARGV[0]") or die "Cannot open file $ARGV[0]: $!\n" ; |
50 | |
51 | my $buff ; |
52 | read F, $buff, 20 ; |
53 | |
54 | my (@info) = unpack("NNNNN", $buff) ; |
55 | my (@info1) = unpack("VVVVV", $buff) ; |
56 | my ($magic, $version, $endian) ; |
57 | |
58 | if ($Data{$info[0]}) # first try DB 1.x format |
59 | { |
60 | $magic = $info[0] ; |
61 | $version = $info[1] ; |
62 | $endian = "Unknown" ; |
63 | } |
64 | elsif ($Data{$info[3]}) # next DB 2.x big endian |
65 | { |
66 | $magic = $info[3] ; |
67 | $version = $info[4] ; |
68 | $endian = "Big Endian" ; |
69 | } |
70 | elsif ($Data{$info1[3]}) # next DB 2.x little endian |
71 | { |
72 | $magic = $info1[3] ; |
73 | $version = $info1[4] ; |
74 | $endian = "Little Endian" ; |
75 | } |
76 | else |
77 | { die "not a Berkeley DB database file.\n" } |
78 | |
79 | my $type = $Data{$magic} ; |
80 | my $magic = sprintf "%06X", $magic ; |
81 | |
82 | my $ver_string = "Unknown" ; |
83 | $ver_string = $type->{Versions}{$version} |
84 | if defined $type->{Versions}{$version} ; |
85 | |
86 | print <<EOM ; |
87 | File Type: Berkeley DB $type->{Type} file. |
88 | File Version ID: $version |
89 | Built with Berkeley DB: $ver_string |
90 | Byte Order: $endian |
91 | Magic: $magic |
92 | EOM |
93 | |
94 | close F ; |
95 | |
96 | exit ; |