for (i = 0; i < ARRAY_SIZE(topology_vals); i++) {
struct topology_val *val = &topology_vals[i];
- unsigned int data;
+ unsigned int data = 0;
int rc;
- if (ioctl(pr->fd, val->ioc, &data) == -1)
+ if (val->ioc == BLKALIGNOFF) {
+ int sdata = 0;
+ if (ioctl(pr->fd, val->ioc, &sdata) == -1)
+ goto nothing;
+ data = sdata < 0 ? 0 : sdata;
+
+ } else if (ioctl(pr->fd, val->ioc, &data) == -1)
goto nothing;
+
rc = val->set_result(pr, (unsigned long) data);
if (rc)
goto err;
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
+#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "topology.h"
-static unsigned long dev_topology_attribute(const char *attribute,
- dev_t dev, dev_t *primary)
+static int dev_topology_attribute(const char *attribute,
+ dev_t dev, dev_t *primary, int64_t *result)
{
const char *sysfs_fmt_str = "/sys/dev/block/%d:%d/%s";
char path[PATH_MAX];
int len;
FILE *fp = NULL;
struct stat info;
- unsigned long result = 0UL;
len = snprintf(path, sizeof(path), sysfs_fmt_str,
major(dev), minor(dev), attribute);
goto err;
}
- if (fscanf(fp, "%lu", &result) != 1) {
+ if (fscanf(fp, "%" SCNd64, result) != 1) {
DBG(DEBUG_LOWPROBE, printf(
"topology: %s: unexpected file format\n", path));
goto err;
fclose(fp);
DBG(DEBUG_LOWPROBE,
- printf("topology: attribute %s = %lu\n", attribute, result));
+ printf("topology: attribute %s = %"PRId64"\n", attribute, *result));
- return result;
+ return 0;
err:
if (fp)
fclose(fp);
DBG(DEBUG_LOWPROBE,
printf("topology: failed to read %s attribute\n", attribute));
- return 0;
+ return -1;
}
/*
for (i = 0; i < ARRAY_SIZE(topology_vals); i++) {
struct topology_val *val = &topology_vals[i];
- unsigned long data;
-
- /*
- * Don't bother reporting any of the topology information
- * if it's zero.
- */
- data = dev_topology_attribute(val->sysfs_name, dev, &pri_dev);
- if (!data)
+ int64_t data = 0;
+
+ if (dev_topology_attribute(val->sysfs_name, dev,
+ &pri_dev, &data))
continue;
- rc = val->set_result(pr, data);
+ if (!strcmp(val->sysfs_name, "alignment_offset") && data < 0)
+ data = 0;
+
+ rc = val->set_result(pr, (unsigned long) data);
if (rc)
goto err;
count++;
* @ALIGNMENT_OFFSET: indicates how many bytes the beginning o the device is
* offset from the disk's natural alignment.
*
+ * The NAME=value tags are not defined when the corresponding topology value
+ * is zero. The MINIMUM_IO_SIZE should be always defined if kernel provides
+ * topology information.
+ *
* Binary interface:
*
* blkid_probe_get_tolology()
if (!chn)
return -1;
+ if (!data)
+ return 0; /* ignore zeros */
if (chn->binary) {
unsigned long *v =