2 * volume_id - reads volume label and uuid
4 * Copyright (C) 2005-2007 Kay Sievers <kay.sievers@vrfy.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
28 #include "libvolume_id.h"
31 /* the user can overwrite this log function */
32 static void default_log(int priority, const char *file, int line, const char *format, ...)
37 volume_id_log_fn_t volume_id_log_fn = default_log;
39 int volume_id_get_label(struct volume_id *id, const char **label)
45 if (id->usage_id == VOLUME_ID_UNUSED)
52 int volume_id_get_label_raw(struct volume_id *id, const uint8_t **label, size_t *len)
60 if (id->usage_id == VOLUME_ID_UNUSED)
63 *label = id->label_raw;
64 *len = id->label_raw_len;
68 int volume_id_get_uuid(struct volume_id *id, const char **uuid)
74 if (id->usage_id == VOLUME_ID_UNUSED)
81 int volume_id_get_uuid_raw(struct volume_id *id, const uint8_t **uuid, size_t *len)
89 if (id->usage_id == VOLUME_ID_UNUSED)
93 *len = id->uuid_raw_len;
97 int volume_id_get_usage(struct volume_id *id, const char **usage)
103 if (id->usage_id == VOLUME_ID_UNUSED)
110 int volume_id_get_type(struct volume_id *id, const char **type)
116 if (id->usage_id == VOLUME_ID_UNUSED)
123 int volume_id_get_type_version(struct volume_id *id, const char **type_version)
127 if (type_version == NULL)
129 if (id->usage_id == VOLUME_ID_UNUSED)
132 *type_version = id->type_version;
136 int volume_id_probe_raid(struct volume_id *id, uint64_t off, uint64_t size)
141 info("probing at offset 0x%llx, size 0x%llx",
142 (unsigned long long) off, (unsigned long long) size);
144 /* probe for raid first, because fs probes may be successful on raid members */
146 if (volume_id_probe_linux_raid(id, off, size) == 0)
149 if (volume_id_probe_intel_software_raid(id, off, size) == 0)
152 if (volume_id_probe_lsi_mega_raid(id, off, size) == 0)
155 if (volume_id_probe_via_raid(id, off, size) == 0)
158 if (volume_id_probe_silicon_medley_raid(id, off, size) == 0)
161 if (volume_id_probe_nvidia_raid(id, off, size) == 0)
164 if (volume_id_probe_promise_fasttrack_raid(id, off, size) == 0)
167 if (volume_id_probe_highpoint_45x_raid(id, off, size) == 0)
170 if (volume_id_probe_adaptec_raid(id, off, size) == 0)
173 if (volume_id_probe_jmicron_raid(id, off, size) == 0)
177 if (volume_id_probe_lvm1(id, off, size) == 0)
180 if (volume_id_probe_lvm2(id, off, size) == 0)
183 if (volume_id_probe_highpoint_37x_raid(id, off, size) == 0)
189 /* If recognized, we free the allocated buffers */
190 volume_id_free_buffer(id);
194 int volume_id_probe_filesystem(struct volume_id *id, uint64_t off, uint64_t size)
199 info("probing at offset 0x%llx, size 0x%llx",
200 (unsigned long long) off, (unsigned long long) size);
202 if (volume_id_probe_vfat(id, off, size) == 0)
205 /* fill buffer with maximum */
206 volume_id_get_buffer(id, 0, SB_BUFFER_SIZE);
208 if (volume_id_probe_linux_swap(id, off, size) == 0)
211 if (volume_id_probe_luks(id, off, size) == 0)
214 if (volume_id_probe_xfs(id, off, size) == 0)
217 if (volume_id_probe_ext(id, off, size) == 0)
220 if (volume_id_probe_reiserfs(id, off, size) == 0)
223 if (volume_id_probe_jfs(id, off, size) == 0)
226 if (volume_id_probe_udf(id, off, size) == 0)
229 if (volume_id_probe_iso9660(id, off, size) == 0)
232 if (volume_id_probe_hfs_hfsplus(id, off, size) == 0)
235 if (volume_id_probe_ufs(id, off, size) == 0)
238 if (volume_id_probe_ntfs(id, off, size) == 0)
241 if (volume_id_probe_cramfs(id, off, size) == 0)
244 if (volume_id_probe_romfs(id, off, size) == 0)
247 if (volume_id_probe_hpfs(id, off, size) == 0)
250 if (volume_id_probe_sysv(id, off, size) == 0)
253 if (volume_id_probe_minix(id, off, size) == 0)
256 if (volume_id_probe_ocfs1(id, off, size) == 0)
259 if (volume_id_probe_ocfs2(id, off, size) == 0)
262 if (volume_id_probe_vxfs(id, off, size) == 0)
265 if (volume_id_probe_squashfs(id, off, size) == 0)
268 if (volume_id_probe_netware(id, off, size) == 0)
271 if (volume_id_probe_gfs(id, off, size) == 0)
274 if (volume_id_probe_gfs2(id, off, size) == 0)
280 /* If recognized, we free the allocated buffers */
281 volume_id_free_buffer(id);
285 int volume_id_probe_all(struct volume_id *id, uint64_t off, uint64_t size)
290 if (volume_id_probe_raid(id, off, size) == 0)
293 if (volume_id_probe_filesystem(id, off, size) == 0)
299 /* open volume by already open file descriptor */
300 struct volume_id *volume_id_open_fd(int fd)
302 struct volume_id *id;
304 id = malloc(sizeof(struct volume_id));
307 memset(id, 0x00, sizeof(struct volume_id));
314 /* open volume by device node */
315 struct volume_id *volume_id_open_node(const char *path)
317 struct volume_id *id;
320 fd = open(path, O_RDONLY);
322 dbg("unable to open '%s'", path);
326 id = volume_id_open_fd(fd);
330 /* close fd on device close */
336 void volume_id_close(struct volume_id *id)
341 if (id->fd_close != 0)
344 volume_id_free_buffer(id);