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)
73 if (volume_id_probe_adaptec_raid(id
, off
, size
) == 0)
76 if (volume_id_probe_jmicron_raid(id
, off
, size
) == 0)
80 if (volume_id_probe_lvm1(id
, off
) == 0)
83 if (volume_id_probe_lvm2(id
, off
) == 0)
86 if (volume_id_probe_highpoint_37x_raid(id
, off
) == 0)
92 /* If recognized, we free the allocated buffers */
93 volume_id_free_buffer(id
);
97 int volume_id_probe_filesystem(struct volume_id
*id
, uint64_t off
, uint64_t size
)
102 info("probing at offset 0x%llx, size 0x%llx",
103 (unsigned long long) off
, (unsigned long long) size
);
105 if (volume_id_probe_vfat(id
, off
) == 0)
108 /* fill buffer with maximum */
109 volume_id_get_buffer(id
, 0, SB_BUFFER_SIZE
);
111 if (volume_id_probe_linux_swap(id
, off
) == 0)
114 if (volume_id_probe_luks(id
, off
) == 0)
117 if (volume_id_probe_xfs(id
, off
) == 0)
120 if (volume_id_probe_ext(id
, off
) == 0)
123 if (volume_id_probe_reiserfs(id
, off
) == 0)
126 if (volume_id_probe_jfs(id
, off
) == 0)
129 if (volume_id_probe_udf(id
, off
) == 0)
132 if (volume_id_probe_iso9660(id
, off
) == 0)
135 if (volume_id_probe_hfs_hfsplus(id
, off
) == 0)
138 if (volume_id_probe_ufs(id
, off
) == 0)
141 if (volume_id_probe_ntfs(id
, off
) == 0)
144 if (volume_id_probe_cramfs(id
, off
) == 0)
147 if (volume_id_probe_romfs(id
, off
) == 0)
150 if (volume_id_probe_hpfs(id
, off
) == 0)
153 if (volume_id_probe_sysv(id
, off
) == 0)
156 if (volume_id_probe_minix(id
, off
) == 0)
159 if (volume_id_probe_ocfs1(id
, off
) == 0)
162 if (volume_id_probe_ocfs2(id
, off
) == 0)
165 if (volume_id_probe_vxfs(id
, off
) == 0)
168 if (volume_id_probe_squashfs(id
, off
) == 0)
171 if (volume_id_probe_netware(id
, off
) == 0)
174 if (volume_id_probe_gfs(id
, off
) == 0)
177 if (volume_id_probe_gfs2(id
, off
) == 0)
183 /* If recognized, we free the allocated buffers */
184 volume_id_free_buffer(id
);
188 int volume_id_probe_all(struct volume_id
*id
, uint64_t off
, uint64_t size
)
193 if (volume_id_probe_raid(id
, off
, size
) == 0)
196 if (volume_id_probe_filesystem(id
, off
, size
) == 0)
202 /* open volume by already open file descriptor */
203 struct volume_id
*volume_id_open_fd(int fd
)
205 struct volume_id
*id
;
207 id
= malloc(sizeof(struct volume_id
));
210 memset(id
, 0x00, sizeof(struct volume_id
));
217 /* open volume by device node */
218 struct volume_id
*volume_id_open_node(const char *path
)
220 struct volume_id
*id
;
223 fd
= open(path
, O_RDONLY
);
225 dbg("unable to open '%s'", path
);
229 id
= volume_id_open_fd(fd
);
233 /* close fd on device close */
239 void volume_id_close(struct volume_id
*id
)
244 if (id
->fd_close
!= 0)
247 volume_id_free_buffer(id
);