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.
29 #include "libvolume_id.h"
32 /* the user can overwrite this log function */
33 static void default_log(int priority, const char *file, int line, const char *format, ...)
38 volume_id_log_fn_t volume_id_log_fn = default_log;
40 int volume_id_probe_raid(struct volume_id *id, uint64_t off, uint64_t size)
45 /* probe for raid first, because fs probes may be successful on raid members */
47 if (volume_id_probe_linux_raid(id, off, size) == 0)
50 if (volume_id_probe_intel_software_raid(id, off, size) == 0)
53 if (volume_id_probe_lsi_mega_raid(id, off, size) == 0)
56 if (volume_id_probe_via_raid(id, off, size) == 0)
59 if (volume_id_probe_silicon_medley_raid(id, off, size) == 0)
62 if (volume_id_probe_nvidia_raid(id, off, size) == 0)
65 if (volume_id_probe_promise_fasttrack_raid(id, off, size) == 0)
68 if (volume_id_probe_highpoint_45x_raid(id, off, size) == 0)
72 if (volume_id_probe_lvm1(id, off) == 0)
75 if (volume_id_probe_lvm2(id, off) == 0)
78 if (volume_id_probe_highpoint_37x_raid(id, off) == 0)
84 /* If recognized, we free the allocated buffers */
85 volume_id_free_buffer(id);
89 int volume_id_probe_filesystem(struct volume_id *id, uint64_t off, uint64_t size)
94 if (volume_id_probe_luks(id, off) == 0)
97 /* signature in the first block, only small buffer needed */
98 if (volume_id_probe_vfat(id, off) == 0)
101 if (volume_id_probe_xfs(id, off) == 0)
104 /* fill buffer with maximum */
105 volume_id_get_buffer(id, 0, SB_BUFFER_SIZE);
107 if (volume_id_probe_linux_swap(id, off) == 0)
110 if (volume_id_probe_ext(id, off) == 0)
113 if (volume_id_probe_reiserfs(id, off) == 0)
116 if (volume_id_probe_jfs(id, off) == 0)
119 if (volume_id_probe_udf(id, off) == 0)
122 if (volume_id_probe_iso9660(id, off) == 0)
125 if (volume_id_probe_hfs_hfsplus(id, off) == 0)
128 if (volume_id_probe_ufs(id, off) == 0)
131 if (volume_id_probe_ntfs(id, off) == 0)
134 if (volume_id_probe_cramfs(id, off) == 0)
137 if (volume_id_probe_romfs(id, off) == 0)
140 if (volume_id_probe_hpfs(id, off) == 0)
143 if (volume_id_probe_sysv(id, off) == 0)
146 if (volume_id_probe_minix(id, off) == 0)
149 if (volume_id_probe_ocfs1(id, off) == 0)
152 if (volume_id_probe_ocfs2(id, off) == 0)
155 if (volume_id_probe_vxfs(id, off) == 0)
158 if (volume_id_probe_squashfs(id, off) == 0)
164 /* If recognized, we free the allocated buffers */
165 volume_id_free_buffer(id);
169 int volume_id_probe_all(struct volume_id *id, uint64_t off, uint64_t size)
174 if (volume_id_probe_raid(id, off, size) == 0)
177 if (volume_id_probe_filesystem(id, off, size) == 0)
183 /* open volume by already open file descriptor */
184 struct volume_id *volume_id_open_fd(int fd)
186 struct volume_id *id;
188 id = malloc(sizeof(struct volume_id));
191 memset(id, 0x00, sizeof(struct volume_id));
198 /* open volume by device node */
199 struct volume_id *volume_id_open_node(const char *path)
201 struct volume_id *id;
204 fd = open(path, O_RDONLY);
206 dbg("unable to open '%s'", path);
210 id = volume_id_open_fd(fd);
214 /* close fd on device close */
220 void volume_id_close(struct volume_id *id)
225 if (id->fd_close != 0)
228 volume_id_free_buffer(id);