有这样一些小程序, 不知道用perl如何实现:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <linux/fs.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
int main(void) {
int fd, ret;
unsigned long long size;
fd = open("/dev/sda", O_RDONLY);
if (fd == -1)
exit(-1);
ret = ioctl(fd, BLKGETSIZE64, &size);
if (ret == 0) {
printf("disk size: %llu\n", size);
}
return(0);
}
% ./get_size
disk size: 160041885696
% cat
size.pl#!/usr/bin/perl
require "sys/
ioctl.ph";
my $buf;
my $ret;
my $fd;
open($fd, "</dev/sda") or die "$!";
$ret = ioctl($fd, BLKGETSIZE64, $buf) || -1;
@data = unpack("LL", $buf);
print "ret = $ret\n";
print "disk size=", $data[0], "\n";
close($fd);
###########################################
% perl
size.pl
ret = -1
disk size=0
返回值应该是64位无符号整形