summaryrefslogtreecommitdiffstats
path: root/perl-install/c.pm
blob: e63c9c5180aca66b050c9887673ddb299a1cf733 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package c; # $Id$

use vars qw($AUTOLOAD);

use c::stuff;
use MDK::Common;

sub AUTOLOAD() {
    $AUTOLOAD =~ /::(.*)/ or return;
    my @l = eval { &{$c::stuff::{$1}} };
    if (my $err = $@) {
	$err =~ /Undefined subroutine &main::/ ?
	  die("can not find function $AUTOLOAD\n" . backtrace()) :
	  die($err);	
    }
    wantarray() ? @l : $l[0];
}

sub total_sectors {
    my ($fd) = @_;

    my ($BLKGETSIZE, $BLKGETSIZE64) = (0x1260, 0x80041272);

    open(my $F, "<& $fd") or return;
    my $ll = '';
    if (ioctl($F, $BLKGETSIZE64, $ll)) {
	my ($v, $v1) = unpack("L2", $ll);
	$v1 * 1024 * 1024 * 8 + $v / 512;
    } elsif (ioctl($F, $BLKGETSIZE, $ll)) {
	unpack("L", $ll);
    } else {
	0;
    }
}

1;