From 98157a49ce3e3ef250cfdbddaec0ba418eaa59c9 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 9 Oct 2007 21:53:34 +0000 Subject: [PATCH] share FSDEV_ID macro --- include/sigar_private.h | 3 +++ src/os/aix/aix_sigar.c | 8 +++----- src/os/hpux/hpux_sigar.c | 6 ++---- src/os/linux/linux_sigar.c | 6 ++---- src/os/solaris/solaris_sigar.c | 6 ++---- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/include/sigar_private.h b/include/sigar_private.h index 84498086..7ff5618e 100644 --- a/include/sigar_private.h +++ b/include/sigar_private.h @@ -314,6 +314,9 @@ int sigar_group_name_get(sigar_t *sigar, int gid, char *buf, int buflen); fsusage->disk_read_bytes = fsusage->disk_write_bytes = \ fsusage->disk_queue = fsusage->disk_time = SIGAR_FIELD_NOTIMPL; +/* key used for filesystem (/) -> device (/dev/hda1) mapping */ +#define SIGAR_FSDEV_ID(sb) ((sb).st_ino + (sb).st_dev) + #if defined(WIN32) || defined(NETWARE) int sigar_get_iftype(const char *name, int *type, int *inst); #endif diff --git a/src/os/aix/aix_sigar.c b/src/os/aix/aix_sigar.c index becca188..a72ed9df 100644 --- a/src/os/aix/aix_sigar.c +++ b/src/os/aix/aix_sigar.c @@ -1507,8 +1507,6 @@ int sigar_file_system_list_get(sigar_t *sigar, #define LSPV_CMD "/usr/sbin/lspv" -#define FSDEV_ID(sb) (sb.st_ino + sb.st_dev) - typedef struct { char *name; long addr; @@ -1576,7 +1574,7 @@ static int create_diskmap_v4(sigar_t *sigar) aix_diskio_t *diskio = malloc(sizeof(*diskio)); diskio->name = strdup(disk); diskio->addr = -1; - ent = sigar_cache_get(sigar->diskmap, FSDEV_ID(sb)); + ent = sigar_cache_get(sigar->diskmap, SIGAR_FSDEV_ID(sb)); ent->value = diskio; } } @@ -1642,7 +1640,7 @@ static int create_diskmap_v5(sigar_t *sigar) aix_diskio_t *diskio = malloc(sizeof(*diskio)); diskio->name = strdup(disk[i].name); diskio->addr = -1; - ent = sigar_cache_get(sigar->diskmap, FSDEV_ID(sb)); + ent = sigar_cache_get(sigar->diskmap, SIGAR_FSDEV_ID(sb)); ent->value = diskio; } @@ -1811,7 +1809,7 @@ int sigar_file_system_usage_get(sigar_t *sigar, status = stat(dirname, &sb); if (status == 0) { sigar_cache_entry_t *ent = - sigar_cache_get(sigar->diskmap, FSDEV_ID(sb)); + sigar_cache_get(sigar->diskmap, SIGAR_FSDEV_ID(sb)); if (!ent->value) { return SIGAR_OK; } diff --git a/src/os/hpux/hpux_sigar.c b/src/os/hpux/hpux_sigar.c index e14cb071..3412fb0c 100644 --- a/src/os/hpux/hpux_sigar.c +++ b/src/os/hpux/hpux_sigar.c @@ -560,8 +560,6 @@ int sigar_file_system_list_get(sigar_t *sigar, #define SIGAR_FS_BLOCKS_TO_BYTES(buf, f) \ (((sigar_uint64_t)buf.f * (buf.f_bsize / 512)) >> 1) -#define FSDEV_ID(sb) (sb.st_ino + sb.st_dev) - static int create_fsdev_cache(sigar_t *sigar) { sigar_file_system_list_t fslist; @@ -586,7 +584,7 @@ static int create_fsdev_cache(sigar_t *sigar) continue; } - ent = sigar_cache_get(sigar->fsdev, FSDEV_ID(sb)); + ent = sigar_cache_get(sigar->fsdev, SIGAR_FSDEV_ID(sb)); ent->value = strdup(fsp->dev_name); } } @@ -628,7 +626,7 @@ int sigar_file_system_usage_get(sigar_t *sigar, char *devname; int retval; - ent = sigar_cache_get(sigar->fsdev, FSDEV_ID(sb)); + ent = sigar_cache_get(sigar->fsdev, SIGAR_FSDEV_ID(sb)); if (ent->value == NULL) { return SIGAR_OK; } diff --git a/src/os/linux/linux_sigar.c b/src/os/linux/linux_sigar.c index 54f8a237..fb5c819b 100644 --- a/src/os/linux/linux_sigar.c +++ b/src/os/linux/linux_sigar.c @@ -1174,8 +1174,6 @@ int sigar_file_system_list_get(sigar_t *sigar, return SIGAR_OK; } -#define FSDEV_ID(sb) (sb.st_ino + sb.st_dev) - #define FSDEV_IS_DEV(dev) strnEQ(dev, "/dev/", 5) #define ST_MAJOR(sb) major((sb).st_rdev) @@ -1204,7 +1202,7 @@ static iodev_t *get_fsdev(sigar_t *sigar, return NULL; } - id = FSDEV_ID(sb); + id = SIGAR_FSDEV_ID(sb); if (!sigar->fsdev) { sigar->fsdev = sigar_cache_new(15); @@ -1241,7 +1239,7 @@ static iodev_t *get_fsdev(sigar_t *sigar, return NULL; /* cant cache w/o inode */ } - ent = sigar_cache_get(sigar->fsdev, FSDEV_ID(sb)); + ent = sigar_cache_get(sigar->fsdev, SIGAR_FSDEV_ID(sb)); if (ent->value) { continue; /* already cached */ } diff --git a/src/os/solaris/solaris_sigar.c b/src/os/solaris/solaris_sigar.c index 5eb3dcd4..59474095 100644 --- a/src/os/solaris/solaris_sigar.c +++ b/src/os/solaris/solaris_sigar.c @@ -1457,8 +1457,6 @@ static fsdev_path_t *get_fsdev_paths(sigar_t *sigar, return mapping; } -#define FSDEV_ID(sb) (sb.st_ino + sb.st_dev) - static int create_fsdev_cache(sigar_t *sigar) { fsdev_path_t *paths, *mapping; @@ -1530,7 +1528,7 @@ static int create_fsdev_cache(sigar_t *sigar) SIGAR_SSTRCPY(fs_kstat->module, paths->name); fs_kstat->instance = paths->instance; fs_kstat->partition = partition; - ent = sigar_cache_get(sigar->fsdev, FSDEV_ID(sb)); + ent = sigar_cache_get(sigar->fsdev, SIGAR_FSDEV_ID(sb)); ent->value = fs_kstat; if (debug) { @@ -1650,7 +1648,7 @@ int sigar_file_system_usage_get(sigar_t *sigar, if (stat(dirname, &sb) < 0) { return SIGAR_OK; } - ent = sigar_cache_get(sigar->fsdev, FSDEV_ID(sb)); + ent = sigar_cache_get(sigar->fsdev, SIGAR_FSDEV_ID(sb)); if (ent->value == NULL) { return SIGAR_OK; }