2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #include <asm/types.h>
40 #include "volume_id.h"
54 #include "highpoint.h"
58 #include "silicon_raid.h"
59 #include "nvidia_raid.h"
60 #include "promise_raid.h"
62 #include "linux_swap.h"
63 #include "linux_raid.h"
73 int volume_id_probe_all(struct volume_id *id, unsigned long long off, unsigned long long size)
78 /* probe for raid first, cause fs probes may be successful on raid members */
80 if (volume_id_probe_linux_raid(id, off, size) == 0)
83 if (volume_id_probe_intel_software_raid(id, off, size) == 0)
86 if (volume_id_probe_lsi_mega_raid(id, off, size) == 0)
89 if (volume_id_probe_via_raid(id, off, size) == 0)
92 if (volume_id_probe_silicon_medley_raid(id, off, size) == 0)
95 if (volume_id_probe_nvidia_raid(id, off, size) == 0)
98 if (volume_id_probe_promise_fasttrack_raid(id, off, size) == 0)
101 if (volume_id_probe_highpoint_45x_raid(id, off, size) == 0)
105 if (volume_id_probe_lvm1(id, off) == 0)
108 if (volume_id_probe_lvm2(id, off) == 0)
111 if (volume_id_probe_highpoint_37x_raid(id, off) == 0)
114 if (volume_id_probe_luks(id, off) == 0)
117 /* signature in the first block, only small buffer needed */
118 if (volume_id_probe_vfat(id, off) == 0)
121 if (volume_id_probe_mac_partition_map(id, off) == 0)
124 if (volume_id_probe_xfs(id, off) == 0)
127 /* fill buffer with maximum */
128 volume_id_get_buffer(id, 0, SB_BUFFER_SIZE);
130 if (volume_id_probe_linux_swap(id, off) == 0)
133 if (volume_id_probe_ext(id, off) == 0)
136 if (volume_id_probe_reiserfs(id, off) == 0)
139 if (volume_id_probe_jfs(id, off) == 0)
142 if (volume_id_probe_udf(id, off) == 0)
145 if (volume_id_probe_iso9660(id, off) == 0)
148 if (volume_id_probe_hfs_hfsplus(id, off) == 0)
151 if (volume_id_probe_ufs(id, off) == 0)
154 if (volume_id_probe_ntfs(id, off) == 0)
157 if (volume_id_probe_cramfs(id, off) == 0)
160 if (volume_id_probe_romfs(id, off) == 0)
163 if (volume_id_probe_hpfs(id, off) == 0)
166 if (volume_id_probe_sysv(id, off) == 0)
169 if (volume_id_probe_minix(id, off) == 0)
175 /* If the filestystem in recognized, we free the allocated buffers,
176 otherwise they will stay in place for the possible next probe call */
177 volume_id_free_buffer(id);
182 /* open volume by already open file descriptor */
183 struct volume_id *volume_id_open_fd(int fd)
185 struct volume_id *id;
187 id = malloc(sizeof(struct volume_id));
190 memset(id, 0x00, sizeof(struct volume_id));
197 /* open volume by device node */
198 struct volume_id *volume_id_open_node(const char *path)
200 struct volume_id *id;
203 fd = open(path, O_RDONLY);
205 dbg("unable to open '%s'", path);
209 id = volume_id_open_fd(fd);
213 /* close fd on device close */
219 /* open volume by major/minor */
220 struct volume_id *volume_id_open_dev_t(dev_t devt)
222 struct volume_id *id;
223 __u8 tmp_node[VOLUME_ID_PATH_MAX];
225 snprintf(tmp_node, VOLUME_ID_PATH_MAX,
226 "/dev/.volume_id-%u-%u-%u", getpid(), major(devt), minor(devt));
227 tmp_node[VOLUME_ID_PATH_MAX] = '\0';
229 /* create tempory node to open the block device */
231 if (mknod(tmp_node, (S_IFBLK | 0600), devt) != 0)
234 id = volume_id_open_node(tmp_node);
241 void volume_id_close(struct volume_id *id)
246 if (id->fd_close != 0)
249 volume_id_free_buffer(id);
251 if (id->partitions != NULL)
252 free(id->partitions);