This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate mainline.
[perl5.git] / ext / DB_File / dbinfo
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.03 
8 # Date          17th September 2000
9 #
10 #     Copyright (c) 1998-2000 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 -> 2.7.7",
31                                   7     => "3.0.x",
32                                   8     => "3.1.x or greater",
33                                 }
34                         },
35         0x061561 =>     {
36                           Type     => "Hash",
37                           Versions =>
38                                 {
39                                   1     => "Unknown (older than 1.71)",
40                                   2     => "1.71 -> 1.85",
41                                   3     => "1.86",
42                                   4     => "2.0.0 -> 2.1.0",
43                                   5     => "2.2.6 -> 2.7.7",
44                                   6     => "3.0.x",
45                                   7     => "3.1.x or greater",
46                                 }
47                         },
48         0x042253 =>     {
49                           Type     => "Queue",
50                           Versions =>
51                                 {
52                                   1     => "3.0.x",
53                                   2     => "3.1.x",
54                                   3     => "3.2.x or greater",
55                                 }
56                         },
57         ) ;
58
59 die "Usage: dbinfo file\n" unless @ARGV == 1 ;
60
61 print "testing file $ARGV[0]...\n\n" ;
62 open (F, "<$ARGV[0]") or die "Cannot open file $ARGV[0]: $!\n" ;
63
64 my $buff ;
65 read F, $buff, 20 ;
66
67 my (@info) = unpack("NNNNN", $buff) ;
68 my (@info1) = unpack("VVVVV", $buff) ;
69 my ($magic, $version, $endian) ;
70
71 if ($Data{$info[0]}) # first try DB 1.x format
72 {
73     $magic = $info[0] ;
74     $version = $info[1] ;
75     $endian  = "Unknown" ;
76 }
77 elsif ($Data{$info[3]}) # next DB 2.x big endian
78 {
79     $magic = $info[3] ;
80     $version = $info[4] ;
81     $endian  = "Big Endian" ;
82 }
83 elsif ($Data{$info1[3]}) # next DB 2.x little endian
84 {
85     $magic = $info1[3] ;
86     $version = $info1[4] ;
87     $endian  = "Little Endian" ;
88 }
89 else
90   { die "not a Berkeley DB database file.\n" }
91
92 my $type = $Data{$magic} ;
93 $magic = sprintf "%06X", $magic ;
94
95 my $ver_string = "Unknown" ;
96 $ver_string = $type->{Versions}{$version}
97         if defined $type->{Versions}{$version} ;
98
99 print <<EOM ;
100 File Type:              Berkeley DB $type->{Type} file.
101 File Version ID:        $version
102 Built with Berkeley DB: $ver_string
103 Byte Order:             $endian
104 Magic:                  $magic
105 EOM
106
107 close F ;
108
109 exit ;