X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=extras%2Fvolume_id%2Flib%2Fvolume_id.c;h=a66b4a5769c735638f59710eb24fbf360bd6f1f4;hp=4662b210dc37b789ea5afbc7bc35248747d73284;hb=444f07fea49bc40207df5e7910907492529b9bce;hpb=e688ad2d0da96db1e801ccc21189111ddee1bf40 diff --git a/extras/volume_id/lib/volume_id.c b/extras/volume_id/lib/volume_id.c index 4662b210d..a66b4a576 100644 --- a/extras/volume_id/lib/volume_id.c +++ b/extras/volume_id/lib/volume_id.c @@ -1,7 +1,7 @@ /* * volume_id - reads volume label and uuid * - * Copyright (C) 2005 Kay Sievers + * Copyright (C) 2005-2007 Kay Sievers * * 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 @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -35,18 +34,121 @@ static void default_log(int priority, const char *file, int line, const char *fo return; } -volume_id_log_fn volume_id_log = default_log; +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) return -EINVAL; + info("probing at offset 0x%llx, size 0x%llx", + (unsigned long long) off, (unsigned long long) size); + /* probe for raid first, because fs probes may be successful on raid members */ if (size) { if (volume_id_probe_linux_raid(id, off, size) == 0) goto found; + if (volume_id_probe_ddf_raid(id, off, size) == 0) + goto found; + if (volume_id_probe_intel_software_raid(id, off, size) == 0) goto found; @@ -67,15 +169,21 @@ int volume_id_probe_raid(struct volume_id *id, uint64_t off, uint64_t size) if (volume_id_probe_highpoint_45x_raid(id, off, size) == 0) goto found; + + if (volume_id_probe_adaptec_raid(id, off, size) == 0) + goto found; + + if (volume_id_probe_jmicron_raid(id, off, size) == 0) + 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; @@ -91,71 +199,82 @@ int volume_id_probe_filesystem(struct volume_id *id, uint64_t off, uint64_t size if (id == NULL) return -EINVAL; - if (volume_id_probe_luks(id, off) == 0) + info("probing at offset 0x%llx, size 0x%llx", + (unsigned long long) off, (unsigned long long) size); + + if (volume_id_probe_vfat(id, off, size) == 0) goto found; - /* signature in the first block, only small buffer needed */ - if (volume_id_probe_vfat(id, off) == 0) + /* fill buffer with maximum */ + volume_id_get_buffer(id, 0, SB_BUFFER_SIZE); + + if (volume_id_probe_linux_swap(id, off, size) == 0) goto found; - if (volume_id_probe_xfs(id, off) == 0) + if (volume_id_probe_luks(id, off, size) == 0) goto found; - /* fill buffer with maximum */ - volume_id_get_buffer(id, 0, SB_BUFFER_SIZE); + if (volume_id_probe_xfs(id, off, size) == 0) + goto found; + + if (volume_id_probe_ext(id, off, size) == 0) + goto found; + + if (volume_id_probe_reiserfs(id, off, size) == 0) + goto found; - if (volume_id_probe_linux_swap(id, off) == 0) + if (volume_id_probe_jfs(id, off, size) == 0) goto found; - if (volume_id_probe_ext(id, off) == 0) + if (volume_id_probe_udf(id, off, size) == 0) goto found; - if (volume_id_probe_reiserfs(id, off) == 0) + if (volume_id_probe_iso9660(id, off, size) == 0) goto found; - if (volume_id_probe_jfs(id, off) == 0) + if (volume_id_probe_hfs_hfsplus(id, off, size) == 0) goto found; - if (volume_id_probe_udf(id, off) == 0) + if (volume_id_probe_ufs(id, off, size) == 0) goto found; - if (volume_id_probe_iso9660(id, off) == 0) + if (volume_id_probe_ntfs(id, off, size) == 0) goto found; - if (volume_id_probe_hfs_hfsplus(id, off) == 0) + if (volume_id_probe_cramfs(id, off, size) == 0) goto found; - if (volume_id_probe_ufs(id, off) == 0) + if (volume_id_probe_romfs(id, off, size) == 0) goto found; - if (volume_id_probe_ntfs(id, off) == 0) + if (volume_id_probe_hpfs(id, off, size) == 0) goto found; - if (volume_id_probe_cramfs(id, off) == 0) + if (volume_id_probe_sysv(id, off, size) == 0) goto found; - if (volume_id_probe_romfs(id, off) == 0) + if (volume_id_probe_minix(id, off, size) == 0) goto found; - if (volume_id_probe_hpfs(id, off) == 0) + if (volume_id_probe_ocfs1(id, off, size) == 0) goto found; - if (volume_id_probe_sysv(id, off) == 0) + if (volume_id_probe_ocfs2(id, off, size) == 0) goto found; - if (volume_id_probe_minix(id, off) == 0) + if (volume_id_probe_vxfs(id, off, size) == 0) goto found; - if (volume_id_probe_ocfs1(id, off) == 0) + if (volume_id_probe_squashfs(id, off, size) == 0) goto found; - if (volume_id_probe_ocfs2(id, off) == 0) + if (volume_id_probe_netware(id, off, size) == 0) goto found; - if (volume_id_probe_vxfs(id, off) == 0) + if (volume_id_probe_gfs(id, off, size) == 0) goto found; - if (volume_id_probe_squashfs(id, off) == 0) + if (volume_id_probe_gfs2(id, off, size) == 0) goto found; return -1;