/[soft]/mgatools/trunk/pm/MGATools/iso.pm
ViewVC logotype

Annotation of /mgatools/trunk/pm/MGATools/iso.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6054 - (hide annotations) (download)
Tue Sep 25 12:24:30 2012 UTC (11 years, 7 months ago) by kharec
File size: 3759 byte(s)
Typo fix
1 boklm 1064 package MGATools::iso;
2    
3     use strict;
4     use Digest::MD5;
5    
6     require Exporter;
7     use URPM;
8 kharec 6054 our @ISA = qw(Exporter);
9 boklm 1064 our @EXPORT = qw(include_md5);
10 kharec 6053 our ($INFO_OFFSET, $SIZE_OFFSET, $SKIP);
11 boklm 1064 $INFO_OFFSET = 883;
12     $SIZE_OFFSET = 84;
13 kharec 6053 $SKIP = 15;
14 boklm 1064
15     =head1 NAME
16    
17     Mageia iso tools
18    
19     =head1 SYNOPSYS
20    
21     require MGATools::iso;
22    
23     =head1 DESCRIPTION
24    
25     <MGATools::iso> includes Mageia iso tools.
26    
27     =head1 SEE ALSO
28    
29     mkcd
30    
31     =head1 COPYRIGHT
32    
33     Copyright (C) 2000,2001,2002,2003,2004 Mandriva <warly@mandriva.com>
34    
35     This program is free software; you can redistribute it and/or modify
36     it under the terms of the GNU General Public License as published by
37     the Free Software Foundation; either version 2, or (at your option)
38     any later version.
39    
40     This program is distributed in the hope that it will be useful,
41     but WITHOUT ANY WARRANTY; without even the implied warranty of
42     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43     GNU General Public License for more details.
44    
45     You should have received a copy of the GNU General Public License
46     along with this program; if not, write to the Free Software
47     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
48    
49     =head1 CREDITS
50    
51     md5 code highly inspired from Redhat anaconda md5 in ISO code
52    
53     =cut
54    
55 kharec 6053
56 boklm 1064 # function copied from Mkcd::Tools
57     # TODO must add some check of maximum authorized size
58     sub include_md5 {
59 kharec 6053 my ($iso, $write, $verbose) = @_;
60     my $ISO;
61 boklm 1064 if ($write) {
62 kharec 6053 open $ISO, "+<$iso" or return "ERROR include_md5: unable to open $iso ($!)\n";
63     } else {
64     open $ISO, $iso or return "ERROR include_md5: unable to open $iso ($!)\n";
65 boklm 1064 }
66     binmode $ISO;
67 kharec 6053 my $offset = 16*2048;
68 boklm 1064 # blank header
69     seek $ISO, $offset, 0;
70 kharec 6053 my ($buf, $msg);
71 boklm 1064 while (1) {
72 kharec 6053 read $ISO,$buf,2048;
73     my $c = ord $buf;
74     last if $c == 1;
75     return "ERROR include_md5: could not find primary volume descriptor\n" if $c == 255;
76     $offset += 2048
77 boklm 1064 }
78 kharec 6053 my $size = ((ord substr $buf, $SIZE_OFFSET, 1) * 0x1000000 +
79     (ord substr $buf, $SIZE_OFFSET + 1, 1) * 0x10000 +
80     (ord substr $buf, $SIZE_OFFSET + 2, 1) * 0x100 +
81     (ord substr $buf, $SIZE_OFFSET + 3, 1)) * 2048;
82     my ($system, $volume, $publisher, $prep, $app) = map { $a = $_ ; $a =~ s/^\s*//; $a =~ s/\s*$//; $a } (substr($buf, 8, 22), substr($buf, 30, 40), substr($buf, 318, 128), substr($buf, 446, 32), substr($buf, 574, 128));
83     print "include_md5:\nSystem: \t$system\nVolume: \t$volume\nPublisher: \t$publisher\nData preparer: \t$prep\nApplication: \t$app\nISO size: \t$size\n" if $verbose;
84 boklm 1064 seek $ISO, $offset + $INFO_OFFSET, 0;
85 kharec 6053 read $ISO, $buf,512;
86 boklm 1064 my ($md5sum) = $buf =~ /.md5 = (\S+)/;
87     $msg .= "include_md5: previous data $buf\n";
88     seek $ISO, 0, 0;
89     my $md5 = new Digest::MD5;
90     my $read = read $ISO, $buf, $offset + $INFO_OFFSET;
91     $md5->add($buf);
92     seek $ISO, 512, 1;
93     $read += 512;
94 kharec 6053 $|=1;
95     my $val = int $size/2048/100;
96 boklm 1064 $verbose and print "\rReading: 0 %";
97 kharec 6053 my ($i, $j);
98     # skip last $SKIP bytes that sometimes are not correctly burned by some drives
99 boklm 1064 my $n = 1;
100 kharec 6053 while ($n && $read < $size - $SKIP * 2048) {
101     $n = read $ISO, $buf,2048;
102     print "\rReading: ", $j++, " %" if ($verbose && !($i++ % $val));
103     $md5->add($buf);
104     $read += $n;
105 boklm 1064 }
106     print "\n";
107     my $digest = $md5->hexdigest;
108     $msg .= "include_md5: computed md5 $digest\n";
109     my $res = $md5sum eq $digest;
110     if ($md5sum) {
111 kharec 6053 $msg .= "include_md5: previous md5 $md5sum\ninclude_md5: md5sum check ";
112     $msg .= $res ? "OK\n" : "FAILED\n"
113 boklm 1064 }
114     print $msg if $verbose;
115     $write or return $res;
116     seek $ISO, $offset + $INFO_OFFSET, 0;
117     my $str = substr "$volume.md5 = $digest", 0, 512;
118     my $l = length $str;
119 kharec 6053 print $ISO ($l > 512 ? substr $str, -1, 512 : $str . ' ' x (512 - $l));
120     close $ISO
121 boklm 1064 }
122    
123     1
124    

  ViewVC Help
Powered by ViewVC 1.1.30