2 * volume_id - reads volume label and uuid
4 * Copyright (C) 2005 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_probe_raid(struct volume_id *id, uint64_t off, uint64_t size)
44 info("probing at offset 0x%llx, size 0x%llx",
45 (unsigned long long) off, (unsigned long long) size);
47 /* probe for raid first, because fs probes may be successful on raid members */
49 if (volume_id_probe_linux_raid(id, off, size) == 0)
52 if (volume_id_probe_intel_software_raid(id, off, size) == 0)
55 if (volume_id_probe_lsi_mega_raid(id, off, size) == 0)
58 if (volume_id_probe_via_raid(id, off, size) == 0)
61 if (volume_id_probe_silicon_medley_raid(id, off, size) == 0)
64 if (volume_id_probe_nvidia_raid(id, off, size) == 0)
67 if (volume_id_probe_promise_fasttrack_raid(id, off, size) == 0)
70 if (volume_id_probe_highpoint_45x_raid(id, off, size) == 0)
74 if (volume_id_probe_lvm1(id, off) == 0)
77 if (volume_id_probe_lvm2(id, off) == 0)
80 if (volume_id_probe_highpoint_37x_raid(id, off) == 0)
86 /* If recognized, we free the allocated buffers */
87 volume_id_free_buffer(id);
91 int volume_id_probe_filesystem(struct volume_id *id, uint64_t off, uint64_t size)
96 info("probing at offset 0x%llx, size 0x%llx",
97 (unsigned long long) off, (unsigned long long) size);
99 if (volume_id_probe_luks(id, off) == 0)
102 /* signature in the first block, only small buffer needed */
103 if (volume_id_probe_vfat(id, off) == 0)
106 if (volume_id_probe_xfs(id, off) == 0)
109 /* fill buffer with maximum */
110 volume_id_get_buffer(id, 0, SB_BUFFER_SIZE);
112 if (volume_id_probe_linux_swap(id, off) == 0)
115 if (volume_id_probe_ext(id, off) == 0)
118 if (volume_id_probe_reiserfs(id, off) == 0)
121 if (volume_id_probe_jfs(id, off) == 0)
124 if (volume_id_probe_udf(id, off) == 0)
127 if (volume_id_probe_iso9660(id, off) == 0)
130 if (volume_id_probe_hfs_hfsplus(id, off) == 0)
133 if (volume_id_probe_ufs(id, off) == 0)
136 if (volume_id_probe_ntfs(id, off) == 0)
139 if (volume_id_probe_cramfs(id, off) == 0)
142 if (volume_id_probe_romfs(id, off) == 0)
145 if (volume_id_probe_hpfs(id, off) == 0)
148 if (volume_id_probe_sysv(id, off) == 0)
151 if (volume_id_probe_minix(id, off) == 0)
154 if (volume_id_probe_ocfs1(id, off) == 0)
157 if (volume_id_probe_ocfs2(id, off) == 0)
160 if (volume_id_probe_vxfs(id, off) == 0)
163 if (volume_id_probe_squashfs(id, off) == 0)
166 if (volume_id_probe_netware(id, off) == 0)
172 /* If recognized, we free the allocated buffers */
173 volume_id_free_buffer(id);
177 int volume_id_probe_all(struct volume_id *id, uint64_t off, uint64_t size)
182 if (volume_id_probe_raid(id, off, size) == 0)
185 if (volume_id_probe_filesystem(id, off, size) == 0)
191 /* open volume by already open file descriptor */
192 struct volume_id *volume_id_open_fd(int fd)
194 struct volume_id *id;
196 id = malloc(sizeof(struct volume_id));
199 memset(id, 0x00, sizeof(struct volume_id));
206 /* open volume by device node */
207 struct volume_id *volume_id_open_node(const char *path)
209 struct volume_id *id;
212 fd = open(path, O_RDONLY);
214 dbg("unable to open '%s'", path);
218 id = volume_id_open_fd(fd);
222 /* close fd on device close */
228 void volume_id_close(struct volume_id *id)
233 if (id->fd_close != 0)
236 volume_id_free_buffer(id);