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_ddf_raid(id, off, size) == 0)
152 if (volume_id_probe_intel_software_raid(id, off, size) == 0)
155 if (volume_id_probe_lsi_mega_raid(id, off, size) == 0)
158 if (volume_id_probe_via_raid(id, off, size) == 0)
161 if (volume_id_probe_silicon_medley_raid(id, off, size) == 0)
164 if (volume_id_probe_nvidia_raid(id, off, size) == 0)
167 if (volume_id_probe_promise_fasttrack_raid(id, off, size) == 0)
170 if (volume_id_probe_highpoint_45x_raid(id, off, size) == 0)
173 if (volume_id_probe_adaptec_raid(id, off, size) == 0)
176 if (volume_id_probe_jmicron_raid(id, off, size) == 0)
180 if (volume_id_probe_lvm1(id, off, size) == 0)
183 if (volume_id_probe_lvm2(id, off, size) == 0)
186 if (volume_id_probe_highpoint_37x_raid(id, off, size) == 0)
192 /* If recognized, we free the allocated buffers */
193 volume_id_free_buffer(id);
197 int volume_id_probe_filesystem(struct volume_id *id, uint64_t off, uint64_t size)
202 info("probing at offset 0x%llx, size 0x%llx",
203 (unsigned long long) off, (unsigned long long) size);
205 if (volume_id_probe_vfat(id, off, size) == 0)
208 /* fill buffer with maximum */
209 volume_id_get_buffer(id, 0, SB_BUFFER_SIZE);
211 if (volume_id_probe_linux_swap(id, off, size) == 0)
214 if (volume_id_probe_luks(id, off, size) == 0)
217 if (volume_id_probe_xfs(id, off, size) == 0)
220 if (volume_id_probe_ext(id, off, size) == 0)
223 if (volume_id_probe_reiserfs(id, off, size) == 0)
226 if (volume_id_probe_jfs(id, off, size) == 0)
229 if (volume_id_probe_udf(id, off, size) == 0)
232 if (volume_id_probe_iso9660(id, off, size) == 0)
235 if (volume_id_probe_hfs_hfsplus(id, off, size) == 0)
238 if (volume_id_probe_ufs(id, off, size) == 0)
241 if (volume_id_probe_ntfs(id, off, size) == 0)
244 if (volume_id_probe_cramfs(id, off, size) == 0)
247 if (volume_id_probe_romfs(id, off, size) == 0)
250 if (volume_id_probe_hpfs(id, off, size) == 0)
253 if (volume_id_probe_sysv(id, off, size) == 0)
256 if (volume_id_probe_minix(id, off, size) == 0)
259 if (volume_id_probe_ocfs1(id, off, size) == 0)
262 if (volume_id_probe_ocfs2(id, off, size) == 0)
265 if (volume_id_probe_vxfs(id, off, size) == 0)
268 if (volume_id_probe_squashfs(id, off, size) == 0)
271 if (volume_id_probe_netware(id, off, size) == 0)
274 if (volume_id_probe_gfs(id, off, size) == 0)
277 if (volume_id_probe_gfs2(id, off, size) == 0)
283 /* If recognized, we free the allocated buffers */
284 volume_id_free_buffer(id);
288 int volume_id_probe_all(struct volume_id *id, uint64_t off, uint64_t size)
293 if (volume_id_probe_raid(id, off, size) == 0)
296 if (volume_id_probe_filesystem(id, off, size) == 0)
302 /* open volume by already open file descriptor */
303 struct volume_id *volume_id_open_fd(int fd)
305 struct volume_id *id;
307 id = malloc(sizeof(struct volume_id));
310 memset(id, 0x00, sizeof(struct volume_id));
317 /* open volume by device node */
318 struct volume_id *volume_id_open_node(const char *path)
320 struct volume_id *id;
323 fd = open(path, O_RDONLY);
325 dbg("unable to open '%s'", path);
329 id = volume_id_open_fd(fd);
333 /* close fd on device close */
339 void volume_id_close(struct volume_id *id)
344 if (id->fd_close != 0)
347 volume_id_free_buffer(id);