From 9517e0c622ea43b876b82bc6e4eeaf1d31129c38 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sat, 10 Jan 2015 10:21:26 +0100 Subject: [PATCH] Prints also the disk name when listing devices. --- cmdline/portable.h | 1 + cmdline/spin.c | 2 ++ cmdline/unix.c | 11 ++++++----- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cmdline/portable.h b/cmdline/portable.h index eaadc562..001ea262 100644 --- a/cmdline/portable.h +++ b/cmdline/portable.h @@ -306,6 +306,7 @@ int randomize(void* ptr, size_t size); * Disk entry. */ struct disk_struct { + char name[PATH_MAX]; /**< Name of the disk. */ char path[PATH_MAX]; /**< Mount point or contained directory. */ uint64_t device; /**< Device ID. */ #if HAVE_PTHREAD_CREATE diff --git a/cmdline/spin.c b/cmdline/spin.c index 8b6eee21..fb97f7c2 100644 --- a/cmdline/spin.c +++ b/cmdline/spin.c @@ -40,6 +40,7 @@ void state_spin(struct snapraid_state* state, int operation) entry = malloc_nofail(sizeof(disk_t)); + pathcpy(entry->name, sizeof(entry->name), disk->name); pathprint(entry->path, sizeof(entry->path), "%s", disk->dir); entry->device = disk->device; @@ -52,6 +53,7 @@ void state_spin(struct snapraid_state* state, int operation) entry = malloc_nofail(sizeof(disk_t)); + pathcpy(entry->name, sizeof(entry->name), lev_config_name(j)); pathprint(entry->path, sizeof(entry->path), "%s", state->parity[j].path); pathcut(entry->path); /* remove the parity file */ entry->device = state->parity[j].device; diff --git a/cmdline/unix.c b/cmdline/unix.c index f67f3f31..dfe64b25 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -403,7 +403,7 @@ static dev_t devread(const char* path) * Read a device tree filling the specified list of disk_t entries. */ #if HAVE_LINUX_DEVICE -static int devtree(dev_t device, tommy_list* list) +static int devtree(const char* name, dev_t device, tommy_list* list) { char path[PATH_MAX]; DIR* d; @@ -428,7 +428,7 @@ static int devtree(dev_t device, tommy_list* list) /* LCOV_EXCL_STOP */ } - if (devtree(device, list) != 0) { + if (devtree(name, device, list) != 0) { /* LCOV_EXCL_START */ return -1; /* LCOV_EXCL_STOP */ @@ -491,6 +491,7 @@ static int devtree(dev_t device, tommy_list* list) disk = malloc_nofail(sizeof(disk_t)); + pathcpy(disk->name, sizeof(disk->name), name); pathprint(disk->path, sizeof(disk->path), "/dev/%s", buf + 3); disk->device = device; @@ -653,7 +654,7 @@ static int spin_devices(tommy_list* list) tommy_list_init(&tree); /* expand the tree of devices */ - if (devtree(disk->device, &tree) != 0) { + if (devtree(disk->name, disk->device, &tree) != 0) { /* LCOV_EXCL_START */ tommy_list_foreach(&tree, free); fprintf(stderr, "Failed to expand device '%u:%u'.\n", major(disk->device), minor(disk->device)); @@ -663,7 +664,7 @@ static int spin_devices(tommy_list* list) for (j = tommy_list_head(&tree); j != 0; j = j->next) { disk_t* entry = j->data; - printf("%u:%u\t%s\t%u:%u\t%s\n", major(entry->device), minor(entry->device), entry->path, major(disk->device), minor(disk->device), disk->path); + printf("%u:%u\t%s\t%u:%u\t%s\t%s\n", major(entry->device), minor(entry->device), entry->path, major(disk->device), minor(disk->device), disk->name, disk->path); } tommy_list_foreach(&tree, free); @@ -758,7 +759,7 @@ int diskspin(tommy_list* list, int operation) disk_t* disk = i->data; /* expand the tree of devices */ - if (devtree(disk->device, &tree) != 0) { + if (devtree(disk->name, disk->device, &tree) != 0) { /* LCOV_EXCL_START */ tommy_list_foreach(&tree, free); fprintf(stderr, "Failed to expand device '%u:%u'.\n", major(disk->device), minor(disk->device));