2 * volume_id - reads filesystem 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 "volume_id.h"
43 #include "highpoint.h"
47 #include "silicon_raid.h"
48 #include "nvidia_raid.h"
49 #include "promise_raid.h"
51 #include "linux_swap.h"
52 #include "linux_raid.h"
64 int volume_id_probe_all(struct volume_id *id, uint64_t off, uint64_t size)
69 /* probe for raid first, cause fs probes may be successful on raid members */
71 if (volume_id_probe_linux_raid(id, off, size) == 0)
74 if (volume_id_probe_intel_software_raid(id, off, size) == 0)
77 if (volume_id_probe_lsi_mega_raid(id, off, size) == 0)
80 if (volume_id_probe_via_raid(id, off, size) == 0)
83 if (volume_id_probe_silicon_medley_raid(id, off, size) == 0)
86 if (volume_id_probe_nvidia_raid(id, off, size) == 0)
89 if (volume_id_probe_promise_fasttrack_raid(id, off, size) == 0)
92 if (volume_id_probe_highpoint_45x_raid(id, off, size) == 0)
96 if (volume_id_probe_lvm1(id, off) == 0)
99 if (volume_id_probe_lvm2(id, off) == 0)
102 if (volume_id_probe_highpoint_37x_raid(id, off) == 0)
105 if (volume_id_probe_luks(id, off) == 0)
108 /* signature in the first block, only small buffer needed */
109 if (volume_id_probe_vfat(id, off) == 0)
112 if (volume_id_probe_xfs(id, off) == 0)
115 /* fill buffer with maximum */
116 volume_id_get_buffer(id, 0, SB_BUFFER_SIZE);
118 if (volume_id_probe_linux_swap(id, off) == 0)
121 if (volume_id_probe_ext(id, off) == 0)
124 if (volume_id_probe_reiserfs(id, off) == 0)
127 if (volume_id_probe_jfs(id, off) == 0)
130 if (volume_id_probe_udf(id, off) == 0)
133 if (volume_id_probe_iso9660(id, off) == 0)
136 if (volume_id_probe_hfs_hfsplus(id, off) == 0)
139 if (volume_id_probe_ufs(id, off) == 0)
142 if (volume_id_probe_ntfs(id, off) == 0)
145 if (volume_id_probe_cramfs(id, off) == 0)
148 if (volume_id_probe_romfs(id, off) == 0)
151 if (volume_id_probe_hpfs(id, off) == 0)
154 if (volume_id_probe_sysv(id, off) == 0)
157 if (volume_id_probe_minix(id, off) == 0)
160 if (volume_id_probe_ocfs1(id, off) == 0)
163 if (volume_id_probe_ocfs2(id, off) == 0)
166 if (volume_id_probe_vxfs(id, off) == 0)
172 /* If the filestystem in recognized, we free the allocated buffers,
173 otherwise they will stay in place for the possible next probe call */
174 volume_id_free_buffer(id);
179 /* open volume by already open file descriptor */
180 struct volume_id *volume_id_open_fd(int fd)
182 struct volume_id *id;
184 id = malloc(sizeof(struct volume_id));
187 memset(id, 0x00, sizeof(struct volume_id));
194 /* open volume by device node */
195 struct volume_id *volume_id_open_node(const char *path)
197 struct volume_id *id;
200 fd = open(path, O_RDONLY);
202 dbg("unable to open '%s'", path);
206 id = volume_id_open_fd(fd);
210 /* close fd on device close */
216 /* open volume by major/minor */
217 struct volume_id *volume_id_open_dev_t(dev_t devt)
219 struct volume_id *id;
220 char tmp_node[VOLUME_ID_PATH_MAX];
222 snprintf(tmp_node, VOLUME_ID_PATH_MAX,
223 "/dev/.volume_id-%u-%u-%u", getpid(), major(devt), minor(devt));
224 tmp_node[VOLUME_ID_PATH_MAX-1] = '\0';
226 /* create tempory node to open the block device */
228 if (mknod(tmp_node, (S_IFBLK | 0600), devt) != 0)
231 id = volume_id_open_node(tmp_node);
238 void volume_id_close(struct volume_id *id)
243 if (id->fd_close != 0)
246 volume_id_free_buffer(id);
248 if (id->partitions != NULL)
249 free(id->partitions);