chiark / gitweb /
volume_id: add volume_id_get_* functions
authorKay Sievers <kay.sievers@vrfy.org>
Thu, 3 May 2007 12:22:39 +0000 (14:22 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Thu, 3 May 2007 12:22:39 +0000 (14:22 +0200)
In a future version of libvolume_id, struct volume_id will be
an opaque data type, which can't be accessed directly.

No interface has changed for now, until all known users are
converted not to access the structure directly.

extras/volume_id/lib/Makefile
extras/volume_id/lib/exported_symbols
extras/volume_id/lib/libvolume_id.h
extras/volume_id/lib/util.h
extras/volume_id/lib/volume_id.c

index 41b7ecb7af83b0283d2e645363c32b4c20b08908..fafcc527941011bb30eec0e98ca69d2bd67c0406 100644 (file)
@@ -13,7 +13,7 @@ INSTALL_DATA  = ${INSTALL} -m 644
 INSTALL_LIB = ${INSTALL} -m 755
 
 SHLIB_CUR = 0
-SHLIB_REV = 76
+SHLIB_REV = 77
 SHLIB_AGE = 0
 SHLIB = libvolume_id.so.$(SHLIB_CUR).$(SHLIB_REV).$(SHLIB_AGE)
 
index 57a1feb3dcc1a018d45e6c20466d36cb4e09eb86..c88d993e01be9b20e424c1b8e5fd78107e5a90fd 100644 (file)
@@ -1,5 +1,14 @@
 { global:
        volume_id_log_fn;
+
+       volume_id_get_label;
+       volume_id_get_label_raw;
+       volume_id_get_uuid;
+       volume_id_get_uuid_raw;
+       volume_id_get_usage;
+       volume_id_get_type;
+       volume_id_get_type_version;
+
        volume_id_open_fd;
        volume_id_open_node;
        volume_id_probe_all;
index 98423f08ccd6bfc0a271dd857c2141de0c40777e..523543f7ee413f8cb925d6b280db6ed22eb4f0df 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * volume_id - reads volume label and uuid
  *
- * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2005-2007 Kay Sievers <kay.sievers@vrfy.org>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
 #include <stdint.h>
 #include <stddef.h>
 
-#ifndef PACKED
-#define PACKED                         __attribute__((packed))
-#endif
-
-
 typedef void (*volume_id_log_fn_t)(int priority, const char *file, int line, const char *format, ...)
             __attribute__ ((format(printf, 4, 5)));
 
@@ -61,6 +56,14 @@ struct volume_id {
        int             fd_close:1;
 };
 
+extern int volume_id_get_label(struct volume_id *id, const char **label);
+extern int volume_id_get_label_raw(struct volume_id *id, const uint8_t **label, size_t *len);
+extern int volume_id_get_uuid(struct volume_id *id, const char **uuid);
+extern int volume_id_get_uuid_raw(struct volume_id *id, const uint8_t **uuid, size_t *len);
+extern int volume_id_get_usage(struct volume_id *id, const char **usage);
+extern int volume_id_get_type(struct volume_id *id, const char **type);
+extern int volume_id_get_type_version(struct volume_id *id, const char **type_version);
+
 extern struct volume_id *volume_id_open_fd(int fd);
 extern struct volume_id *volume_id_open_node(const char *path);
 extern int volume_id_probe_all(struct volume_id *id, uint64_t off, uint64_t size);
index 2abf05df745950c16052fd6f3b4ad57882f75d84..964e70196aac90029e69389829af6ddfa71b1fef 100644 (file)
 #include <byteswap.h>
 #include <syslog.h>
 
+#ifndef PACKED
+#define PACKED                         __attribute__((packed))
+#endif
+
 #define err(format, arg...)    volume_id_log_fn(LOG_ERR, __FILE__, __LINE__, format, ##arg)
 #define info(format, arg...)   volume_id_log_fn(LOG_INFO, __FILE__, __LINE__, format, ##arg)
 #ifdef DEBUG
index c6c8d5af6d837810777e31a4df38ae82170ca8da..bf009c72030383b8bcbcc47ec906c3102121914b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * volume_id - reads volume label and uuid
  *
- * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2005-2007 Kay Sievers <kay.sievers@vrfy.org>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
@@ -36,6 +36,103 @@ static void default_log(int priority, const char *file, int line, const char *fo
 
 volume_id_log_fn_t volume_id_log_fn = default_log;
 
+int volume_id_get_label(struct volume_id *id, const char **label)
+{
+       if (id == NULL)
+               return -EINVAL;
+       if (label == NULL)
+               return -EINVAL;
+       if (id->usage_id == VOLUME_ID_UNUSED)
+               return 0;
+
+       *label = id->label;
+       return 1;
+}
+
+int volume_id_get_label_raw(struct volume_id *id, const uint8_t **label, size_t *len)
+{
+       if (id == NULL)
+               return -EINVAL;
+       if (label == NULL)
+               return -EINVAL;
+       if (len == NULL)
+               return -EINVAL;
+       if (id->usage_id == VOLUME_ID_UNUSED)
+               return 0;
+
+       *label = id->label_raw;
+       *len = id->label_raw_len;
+       return 1;
+}
+
+int volume_id_get_uuid(struct volume_id *id, const char **uuid)
+{
+       if (id == NULL)
+               return -EINVAL;
+       if (uuid == NULL)
+               return -EINVAL;
+       if (id->usage_id == VOLUME_ID_UNUSED)
+               return 0;
+
+       *uuid = id->uuid;
+       return 1;
+}
+
+int volume_id_get_uuid_raw(struct volume_id *id, const uint8_t **uuid, size_t *len)
+{
+       if (id == NULL)
+               return -EINVAL;
+       if (uuid == NULL)
+               return -EINVAL;
+       if (len == NULL)
+               return -EINVAL;
+       if (id->usage_id == VOLUME_ID_UNUSED)
+               return 0;
+
+       *uuid = id->uuid_raw;
+       *len = id->uuid_raw_len;
+       return 1;
+}
+
+int volume_id_get_usage(struct volume_id *id, const char **usage)
+{
+       if (id == NULL)
+               return -EINVAL;
+       if (usage == NULL)
+               return -EINVAL;
+       if (id->usage_id == VOLUME_ID_UNUSED)
+               return 0;
+
+       *usage = id->usage;
+       return 1;
+}
+
+int volume_id_get_type(struct volume_id *id, const char **type)
+{
+       if (id == NULL)
+               return -EINVAL;
+       if (type == NULL)
+               return -EINVAL;
+       if (id->usage_id == VOLUME_ID_UNUSED)
+               return 0;
+
+       *type = id->type;
+       return 1;
+}
+
+int volume_id_get_type_version(struct volume_id *id, const char **type_version)
+{
+       if (id == NULL)
+               return -EINVAL;
+       if (type_version == NULL)
+               return -EINVAL;
+       if (id->usage_id == VOLUME_ID_UNUSED)
+               return 0;
+
+       *type_version = id->type_version;
+       return 1;
+}
+
 int volume_id_probe_raid(struct volume_id *id, uint64_t off, uint64_t size)
 {
        if (id == NULL)