3 ###############################################################################
5 # hfsutils - tools for reading and writing Macintosh HFS volumes
6 # Copyright (C) 1996, 1997 Robert Leslie
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 ###############################################################################
24 die "Usage: $0 device-path\n" unless (@ARGV == 1);
29 # Partition Type HFS Volume Name Start Length
30 -------------------------------------------------------------------------------
34 @# @<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<< @####### @########
35 $bnum, $pmParType, $drVN, $pmPyPartStart, $pmPartBlkCnt
38 open(DISK, $disk) || die "$disk: $!\n";
43 seek(DISK, 512 * $bnum, 0) || die "seek: $!\n";
44 read(DISK, $block, 512) || die "read: $!\n";
46 ($pmSig, $pmMapBlkCnt, $pmPyPartStart, $pmPartBlkCnt, $pmParType) =
47 (unpack('n2 N3 A32 A32 N10 A16', $block))[0, 2..4, 6];
49 die "$disk: unsupported partition map\n" if ($pmSig == 0x5453);
50 die "$disk: no partition map\n" unless ($pmSig == 0x504d);
52 if ($pmParType eq 'Apple_HFS') {
53 seek(DISK, 512 * ($pmPyPartStart + 2), 0) || die "seek: $!\n";
54 read(DISK, $block, 512) || die "read: $!\n";
56 ($len, $drVN) = (unpack('n N2 n5 N2 n N n c A27', $block))[13, 14];
57 $drVN = substr($drVN, 0, $len);
63 } while ($bnum++ < $pmMapBlkCnt);