summaryrefslogtreecommitdiff
path: root/btt/devmap.c
diff options
context:
space:
mode:
authorAlan D. Brunelle <alan.brunelle@hp.com>2009-02-13 12:43:45 -0500
committerAlan D. Brunelle <alan.brunelle@hp.com>2009-02-13 12:43:45 -0500
commitc053af429559c8f4311cd773262ff223097cdcb3 (patch)
treee54213ccebb11d9dafce4d8376e4027983afb48d /btt/devmap.c
parent8f34184f8c7905bb929862d224a7c4969bc9190e (diff)
downloadblktrace-c053af429559c8f4311cd773262ff223097cdcb3.tar.gz
blktrace-c053af429559c8f4311cd773262ff223097cdcb3.tar.bz2
btt general cleanup plus valgrind clean
Lots of general clean up of code, getting interfaces across different files to be similar (all are no alloc/free), and made it valgrind clean. Signed-off-by: Alan D. Brunelle <alan.brunelle@hp.com
Diffstat (limited to 'btt/devmap.c')
-rw-r--r--btt/devmap.c60
1 files changed, 36 insertions, 24 deletions
diff --git a/btt/devmap.c b/btt/devmap.c
index 5841446..9c0348b 100644
--- a/btt/devmap.c
+++ b/btt/devmap.c
@@ -21,44 +21,49 @@
#include <stdio.h>
#include "globals.h"
-struct devmap *all_devmaps = NULL;
+struct devmap {
+ struct list_head head;
+ char device[32], devno[32];
+};
-void dev_map_exit(void)
+LIST_HEAD(all_devmaps);
+
+static int dev_map_add(char *line)
{
struct devmap *dmp;
- while ((dmp = all_devmaps) != NULL) {
- all_devmaps = dmp->next;
+ if (strstr(line, "Device") != NULL)
+ return 1;
+
+ dmp = malloc(sizeof(struct devmap));
+ if (sscanf(line, "%s %s", dmp->device, dmp->devno) != 2) {
free(dmp);
+ return 1;
}
-}
-void dev_map_add(struct devmap *dmp)
-{
- struct devmap *this = malloc(sizeof(struct devmap));
-
- *this = *dmp;
- this->next = all_devmaps;
- all_devmaps = this;
+ list_add_tail(&dmp->head, &all_devmaps);
+ return 0;
}
-struct devmap *dev_map_find(__u32 device)
+char *dev_map_find(__u32 device)
{
char this[128];
- struct devmap *dmp;
+ struct list_head *p;
sprintf(this, "%u,%u", MAJOR(device), MINOR(device));
- for (dmp = all_devmaps; dmp != NULL; dmp = dmp->next)
+ __list_for_each(p, &all_devmaps) {
+ struct devmap *dmp = list_entry(p, struct devmap, head);
+
if (!strcmp(this, dmp->devno))
- break;
+ return dmp->device;
+ }
- return dmp;
+ return NULL;
}
int dev_map_read(char *fname)
{
char line[256];
- struct devmap dm;
FILE *fp = my_fopen(fname, "r");
if (!fp) {
@@ -67,14 +72,21 @@ int dev_map_read(char *fname)
}
while (fscanf(fp, "%255[a-zA-Z0-9 :.,/_-]\n", line) == 1) {
- if (strstr(line, "Device") != NULL) continue;
- if (sscanf(line, "%s %s %u %u %u %u %s %s %u %u %s",
- &dm.device[0], &dm.model[0], &dm.host, &dm.bus,
- &dm.target, &dm.lun, &dm.node[0], &dm.pci[0],
- &dm.irq, &dm.cpu, &dm.devno[0]) != 11)
+ if (dev_map_add(line))
break;
- dev_map_add(&dm);
}
return 0;
}
+
+void dev_map_exit(void)
+{
+ struct list_head *p, *q;
+
+ list_for_each_safe(p, q, &all_devmaps) {
+ struct devmap *dmp = list_entry(p, struct devmap, head);
+
+ list_del(&dmp->head);
+ free(dmp);
+ }
+}