X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=compat%2Flib%2Fbylabel.c;h=065d52985c5629ec810e53f2ae46953bf045b4c1;hb=43460f04f3920ae39f345a2fb39d000a890a4283;hp=c91457d3d232d7b47ff0209dc2a7c0531c79d4c6;hpb=1099d48c9c09059aade8605beddfa4ef98f575aa;p=dump.git diff --git a/compat/lib/bylabel.c b/compat/lib/bylabel.c index c91457d..065d529 100644 --- a/compat/lib/bylabel.c +++ b/compat/lib/bylabel.c @@ -11,6 +11,7 @@ * - Ported to dump/restore */ +#include #include #include #include @@ -23,7 +24,10 @@ #define PROC_PARTITIONS "/proc/partitions" #define DEVLABELDIR "/dev" -#define EXT2_SUPER_MAGIC 0xEF53 +#define EXT2_SUPER_OFFSET 1024 +#define EXT2_SUPER_SIZE sizeof(struct ext2_super_block) +#define EXT2_SUPER_MAGIC 0xEF53 + struct ext2_super_block { unsigned char s_dummy1[56]; unsigned char s_magic[2]; @@ -55,9 +59,9 @@ get_label_uuid(const char *device, char **label, char *uuid) { if (fd < 0) return 1; - if (lseek(fd, 1024, SEEK_SET) != 1024 - || read(fd, (char *) &e2sb, sizeof(e2sb)) != sizeof(e2sb) - || (ext2magic(e2sb) != EXT2_SUPER_MAGIC)) { + if (lseek(fd, EXT2_SUPER_OFFSET, SEEK_SET) != EXT2_SUPER_OFFSET || + read(fd, (char *) &e2sb, EXT2_SUPER_SIZE) != EXT2_SUPER_SIZE || + ext2magic(e2sb) != EXT2_SUPER_MAGIC) { close(fd); return 1; } @@ -229,3 +233,18 @@ get_device_name(const char * item) { return rc; } + +const char * +get_device_label(const char * spec) { + struct uuidCache_s *uc; + + uuidcache_init(); + uc = uuidCache; + + while(uc) { + if (!strcmp(spec, uc->device)) + return uc->label[0] == '\0' ? NULL : strdup(uc->label); + uc = uc->next; + } + return NULL; +}