This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Sync up with Digest-MD5-2.38 from CPAN
[perl5.git] / ext / DB_File / dbinfo
CommitLineData
a9fd575d
PM
1#!/usr/local/bin/perl
2
3# Name: dbinfo -- identify berkeley DB version used to create
4# a database file
5#
6ca2e664 6# Author: Paul Marquess <Paul.Marquess@btinternet.com>
083e9212
PM
7# Version: 1.06
8# Date 27th MArch 2008
a9fd575d 9#
083e9212 10# Copyright (c) 1998-2008 Paul Marquess. All rights reserved.
a9fd575d
PM
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
17use strict ;
18
19my %Data =
20 (
083e9212
PM
21 0x053162 => # DB_BTREEMAGIC
22 {
039d031f 23 Type => "Btree",
083e9212 24 Versions => # DB_BTREEVERSION
a9fd575d 25 {
6d02d21f
PM
26 1 => [0, "Unknown (older than 1.71)"],
27 2 => [0, "Unknown (older than 1.71)"],
28 3 => [0, "1.71 -> 1.85, 1.86"],
29 4 => [0, "Unknown"],
30 5 => [0, "2.0.0 -> 2.3.0"],
31 6 => [0, "2.3.1 -> 2.7.7"],
32 7 => [0, "3.0.x"],
33 8 => [0, "3.1.x -> 4.0.x"],
34 9 => [1, "4.1.x or greater"],
a9fd575d
PM
35 }
36 },
083e9212
PM
37 0x061561 => # DB_HASHMAGIC
38 {
039d031f 39 Type => "Hash",
083e9212 40 Versions => # DB_HASHVERSION
a9fd575d 41 {
6d02d21f
PM
42 1 => [0, "Unknown (older than 1.71)"],
43 2 => [0, "1.71 -> 1.85"],
44 3 => [0, "1.86"],
45 4 => [0, "2.0.0 -> 2.1.0"],
46 5 => [0, "2.2.6 -> 2.7.7"],
47 6 => [0, "3.0.x"],
48 7 => [0, "3.1.x -> 4.0.x"],
49 8 => [1, "4.1.x or greater"],
083e9212 50 9 => [1, "4.6.x or greater"],
039d031f
PM
51 }
52 },
083e9212
PM
53 0x042253 => # DB_QAMMAGIC
54 {
039d031f 55 Type => "Queue",
083e9212 56 Versions => # DB_QAMVERSION
039d031f 57 {
6d02d21f
PM
58 1 => [0, "3.0.x"],
59 2 => [0, "3.1.x"],
60 3 => [0, "3.2.x -> 4.0.x"],
61 4 => [1, "4.1.x or greater"],
a9fd575d
PM
62 }
63 },
64 ) ;
65
66die "Usage: dbinfo file\n" unless @ARGV == 1 ;
67
68print "testing file $ARGV[0]...\n\n" ;
69open (F, "<$ARGV[0]") or die "Cannot open file $ARGV[0]: $!\n" ;
70
71my $buff ;
6d02d21f 72read F, $buff, 30 ;
a9fd575d 73
a9fd575d 74
6d02d21f
PM
75my (@info) = unpack("NNNNNNC", $buff) ;
76my (@info1) = unpack("VVVVVVC", $buff) ;
77my ($magic, $version, $endian, $encrypt) ;
78
79if ($Data{$info[0]}) # first try DB 1.x format, big endian
a9fd575d
PM
80{
81 $magic = $info[0] ;
82 $version = $info[1] ;
6d02d21f
PM
83 $endian = "Big Endian" ;
84 $encrypt = "Not Supported";
85}
86elsif ($Data{$info1[0]}) # first try DB 1.x format, little endian
87{
88 $magic = $info1[0] ;
89 $version = $info1[1] ;
90 $endian = "Little Endian" ;
91 $encrypt = "Not Supported";
a9fd575d
PM
92}
93elsif ($Data{$info[3]}) # next DB 2.x big endian
94{
95 $magic = $info[3] ;
96 $version = $info[4] ;
97 $endian = "Big Endian" ;
98}
99elsif ($Data{$info1[3]}) # next DB 2.x little endian
100{
101 $magic = $info1[3] ;
102 $version = $info1[4] ;
103 $endian = "Little Endian" ;
104}
105else
106 { die "not a Berkeley DB database file.\n" }
107
108my $type = $Data{$magic} ;
73969f8f 109$magic = sprintf "%06X", $magic ;
a9fd575d
PM
110
111my $ver_string = "Unknown" ;
6d02d21f
PM
112
113if ( defined $type->{Versions}{$version} )
114{
115 $ver_string = $type->{Versions}{$version}[1];
116 if ($type->{Versions}{$version}[0] )
117 { $encrypt = $info[6] ? "Enabled" : "Disabled" }
118 else
119 { $encrypt = "Not Supported" }
120}
a9fd575d
PM
121
122print <<EOM ;
123File Type: Berkeley DB $type->{Type} file.
124File Version ID: $version
125Built with Berkeley DB: $ver_string
126Byte Order: $endian
127Magic: $magic
6d02d21f 128Encryption: $encrypt
a9fd575d
PM
129EOM
130
131close F ;
132
133exit ;