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