chiark / gitweb /
volume_id: add volume_id_get_* functions
[elogind.git] / extras / volume_id / lib / volume_id.c
index bcdbe2feaaf1129a2b053ea1a9ae2a8d5408b2e8..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)
@@ -77,13 +174,13 @@ int volume_id_probe_raid(struct volume_id *id, uint64_t off, uint64_t size)
                        goto found;
        }
 
-       if (volume_id_probe_lvm1(id, off) == 0)
+       if (volume_id_probe_lvm1(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_lvm2(id, off) == 0)
+       if (volume_id_probe_lvm2(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_highpoint_37x_raid(id, off) == 0)
+       if (volume_id_probe_highpoint_37x_raid(id, off, size) == 0)
                goto found;
 
        return -1;
@@ -102,79 +199,79 @@ int volume_id_probe_filesystem(struct volume_id *id, uint64_t off, uint64_t size
        info("probing at offset 0x%llx, size 0x%llx",
            (unsigned long long) off, (unsigned long long) size);
 
-       if (volume_id_probe_luks(id, off) == 0)
+       if (volume_id_probe_vfat(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_vfat(id, off) == 0)
-               goto found;
+       /* fill buffer with maximum */
+       volume_id_get_buffer(id, 0, SB_BUFFER_SIZE);
 
-       if (volume_id_probe_xfs(id, off) == 0)
+       if (volume_id_probe_linux_swap(id, off, size) == 0)
                goto found;
 
-       /* fill buffer with maximum */
-       volume_id_get_buffer(id, 0, SB_BUFFER_SIZE);
+       if (volume_id_probe_luks(id, off, size) == 0)
+               goto found;
 
-       if (volume_id_probe_linux_swap(id, off) == 0)
+       if (volume_id_probe_xfs(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_ext(id, off) == 0)
+       if (volume_id_probe_ext(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_reiserfs(id, off) == 0)
+       if (volume_id_probe_reiserfs(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_jfs(id, off) == 0)
+       if (volume_id_probe_jfs(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_udf(id, off) == 0)
+       if (volume_id_probe_udf(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_iso9660(id, off) == 0)
+       if (volume_id_probe_iso9660(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_hfs_hfsplus(id, off) == 0)
+       if (volume_id_probe_hfs_hfsplus(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_ufs(id, off) == 0)
+       if (volume_id_probe_ufs(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_ntfs(id, off)  == 0)
+       if (volume_id_probe_ntfs(id, off, size)  == 0)
                goto found;
 
-       if (volume_id_probe_cramfs(id, off) == 0)
+       if (volume_id_probe_cramfs(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_romfs(id, off) == 0)
+       if (volume_id_probe_romfs(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_hpfs(id, off) == 0)
+       if (volume_id_probe_hpfs(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_sysv(id, off) == 0)
+       if (volume_id_probe_sysv(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_minix(id, off) == 0)
+       if (volume_id_probe_minix(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_ocfs1(id, off) == 0)
+       if (volume_id_probe_ocfs1(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_ocfs2(id, off) == 0)
+       if (volume_id_probe_ocfs2(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_vxfs(id, off) == 0)
+       if (volume_id_probe_vxfs(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_squashfs(id, off) == 0)
+       if (volume_id_probe_squashfs(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_netware(id, off) == 0)
+       if (volume_id_probe_netware(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_gfs(id, off) == 0)
+       if (volume_id_probe_gfs(id, off, size) == 0)
                goto found;
 
-       if (volume_id_probe_gfs2(id, off) == 0)
+       if (volume_id_probe_gfs2(id, off, size) == 0)
                goto found;
 
        return -1;