Lightweight disk identity, mount, and S.M.A.R.T. extraction toolkit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

123 lines
3.6 KiB

#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include "../../include/bsdiskinfo.h"
MODULE = bsdiskinfo PACKAGE = bsdiskinfo
PROTOTYPES: DISABLE
bool
exists(base_disk)
const char * base_disk
CODE:
RETVAL = diskinfo_exists(base_disk);
OUTPUT:
RETVAL
SV *
get_properties(base_disk)
const char * base_disk
PREINIT:
struct disk_properties props;
HV *hv;
CODE:
if (diskinfo_get_properties(base_disk, &props) != 0) {
XSRETURN_UNDEF;
}
/* Create a new Perl Hash to store properties */
hv = newHV();
/* Populate strings */
hv_store(hv, "model", 5, newSVpv(props.model, 0), 0);
hv_store(hv, "serial", 6, newSVpv(props.serial, 0), 0);
hv_store(hv, "fw_version", 10, newSVpv(props.fw_version, 0), 0);
hv_store(hv, "wwn", 3, newSVpv(props.wwn, 0), 0);
hv_store(hv, "type", 4, newSVpv(props.type_str, 0), 0);
/* Populate numeric capacities as NV (double) for safe 64-bit integer handling in Perl */
hv_store(hv, "mediasize", 9, newSVnv((NV)props.mediasize), 0);
/* Populate geometry integers */
hv_store(hv, "logical_sector_size", 19, newSViv(props.logical_sector_size), 0);
hv_store(hv, "physical_sector_size", 20, newSViv(props.physical_sector_size), 0);
if (props.rotation_rate >= 0) {
hv_store(hv, "rotation_rate", 13, newSViv(props.rotation_rate), 0);
}
if (props.smart_supported >= 0) {
hv_store(hv, "smart_supported", 15, boolSV(props.smart_supported == 1), 0);
hv_store(hv, "smart_enabled", 13, boolSV(props.smart_enabled == 1), 0);
}
/* Return as a reference to the hash */
RETVAL = newRV_noinc((SV *)hv);
OUTPUT:
RETVAL
SV *
get_mounts(base_disk)
const char * base_disk
PREINIT:
struct disk_mount mounts[MAX_MOUNTS];
AV *av;
int count, i;
CODE:
count = diskinfo_get_mounts(base_disk, mounts, MAX_MOUNTS);
if (count < 0) {
XSRETURN_UNDEF;
}
/* Create a new Perl Array Container */
av = newAV();
for (i = 0; i < count; i++) {
HV *hv = newHV();
hv_store(hv, "device", 6, newSVpv(mounts[i].device, 0), 0);
hv_store(hv, "path", 4, newSVpv(mounts[i].path, 0), 0);
hv_store(hv, "fstype", 6, newSVpv(mounts[i].fstype, 0), 0);
/* Push reference into array without incrementing refcount manually */
av_push(av, newRV_noinc((SV *)hv));
}
RETVAL = newRV_noinc((SV *)av);
OUTPUT:
RETVAL
SV *
get_smart_counters(base_disk)
const char * base_disk
PREINIT:
struct smart_counter counters[30];
AV *av;
int count, i;
CODE:
count = diskinfo_get_smart_counters(base_disk, counters, 30);
if (count < 0) {
XSRETURN_UNDEF;
}
av = newAV();
for (i = 0; i < count; i++) {
HV *hv = newHV();
hv_store(hv, "id", 2, newSViv(counters[i].id), 0);
hv_store(hv, "value", 5, newSViv(counters[i].value), 0);
hv_store(hv, "worst", 5, newSViv(counters[i].worst), 0);
/* High capacity vendor attributes pushed as double float */
hv_store(hv, "raw_val", 7, newSVnv((NV)counters[i].raw_val), 0);
av_push(av, newRV_noinc((SV *)hv));
}
RETVAL = newRV_noinc((SV *)av);
OUTPUT:
RETVAL