ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/staticperl/perl/ext/DB_File/dbinfo
Revision: 1.1
Committed: Thu Jun 30 14:26:44 2005 UTC (21 years, 3 months ago) by root
Branch: MAIN
CVS Tags: PERL-5-8-7, HEAD
Branch point for: PERL
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.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 <Paul.Marquess@btinternet.com>
7     # Version: 1.05
8     # Date 1sh November 2003
9     #
10     # Copyright (c) 1998-2003 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 => [0, "Unknown (older than 1.71)"],
26     2 => [0, "Unknown (older than 1.71)"],
27     3 => [0, "1.71 -> 1.85, 1.86"],
28     4 => [0, "Unknown"],
29     5 => [0, "2.0.0 -> 2.3.0"],
30     6 => [0, "2.3.1 -> 2.7.7"],
31     7 => [0, "3.0.x"],
32     8 => [0, "3.1.x -> 4.0.x"],
33     9 => [1, "4.1.x or greater"],
34     }
35     },
36     0x061561 => {
37     Type => "Hash",
38     Versions =>
39     {
40     1 => [0, "Unknown (older than 1.71)"],
41     2 => [0, "1.71 -> 1.85"],
42     3 => [0, "1.86"],
43     4 => [0, "2.0.0 -> 2.1.0"],
44     5 => [0, "2.2.6 -> 2.7.7"],
45     6 => [0, "3.0.x"],
46     7 => [0, "3.1.x -> 4.0.x"],
47     8 => [1, "4.1.x or greater"],
48     }
49     },
50     0x042253 => {
51     Type => "Queue",
52     Versions =>
53     {
54     1 => [0, "3.0.x"],
55     2 => [0, "3.1.x"],
56     3 => [0, "3.2.x -> 4.0.x"],
57     4 => [1, "4.1.x or greater"],
58     }
59     },
60     ) ;
61    
62     die "Usage: dbinfo file\n" unless @ARGV == 1 ;
63    
64     print "testing file $ARGV[0]...\n\n" ;
65     open (F, "<$ARGV[0]") or die "Cannot open file $ARGV[0]: $!\n" ;
66    
67     my $buff ;
68     read F, $buff, 30 ;
69    
70    
71     my (@info) = unpack("NNNNNNC", $buff) ;
72     my (@info1) = unpack("VVVVVVC", $buff) ;
73     my ($magic, $version, $endian, $encrypt) ;
74    
75     if ($Data{$info[0]}) # first try DB 1.x format, big endian
76     {
77     $magic = $info[0] ;
78     $version = $info[1] ;
79     $endian = "Big Endian" ;
80     $encrypt = "Not Supported";
81     }
82     elsif ($Data{$info1[0]}) # first try DB 1.x format, little endian
83     {
84     $magic = $info1[0] ;
85     $version = $info1[1] ;
86     $endian = "Little Endian" ;
87     $encrypt = "Not Supported";
88     }
89     elsif ($Data{$info[3]}) # next DB 2.x big endian
90     {
91     $magic = $info[3] ;
92     $version = $info[4] ;
93     $endian = "Big Endian" ;
94     }
95     elsif ($Data{$info1[3]}) # next DB 2.x little endian
96     {
97     $magic = $info1[3] ;
98     $version = $info1[4] ;
99     $endian = "Little Endian" ;
100     }
101     else
102     { die "not a Berkeley DB database file.\n" }
103    
104     my $type = $Data{$magic} ;
105     $magic = sprintf "%06X", $magic ;
106    
107     my $ver_string = "Unknown" ;
108    
109     if ( defined $type->{Versions}{$version} )
110     {
111     $ver_string = $type->{Versions}{$version}[1];
112     if ($type->{Versions}{$version}[0] )
113     { $encrypt = $info[6] ? "Enabled" : "Disabled" }
114     else
115     { $encrypt = "Not Supported" }
116     }
117    
118     print <<EOM ;
119     File Type: Berkeley DB $type->{Type} file.
120     File Version ID: $version
121     Built with Berkeley DB: $ver_string
122     Byte Order: $endian
123     Magic: $magic
124     Encryption: $encrypt
125     EOM
126    
127     close F ;
128    
129     exit ;