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