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
21 #include "volume_id_internal.h"
23 typedef int (*raid_probe_fptr)(struct volume_id *id, uint64_t off, uint64_t size);
24 typedef int (*probe_fptr)(struct volume_id *id, uint64_t off);
26 static const raid_probe_fptr raid1[] = {
27 #if ENABLE_FEATURE_VOLUMEID_LINUXRAID
28 volume_id_probe_linux_raid,
30 #if ENABLE_FEATURE_VOLUMEID_ISWRAID
31 volume_id_probe_intel_software_raid,
33 #if ENABLE_FEATURE_VOLUMEID_LSIRAID
34 volume_id_probe_lsi_mega_raid,
36 #if ENABLE_FEATURE_VOLUMEID_VIARAID
37 volume_id_probe_via_raid,
39 #if ENABLE_FEATURE_VOLUMEID_SILICONRAID
40 volume_id_probe_silicon_medley_raid,
42 #if ENABLE_FEATURE_VOLUMEID_NVIDIARAID
43 volume_id_probe_nvidia_raid,
45 #if ENABLE_FEATURE_VOLUMEID_PROMISERAID
46 volume_id_probe_promise_fasttrack_raid,
48 #if ENABLE_FEATURE_VOLUMEID_HIGHPOINTRAID
49 volume_id_probe_highpoint_45x_raid,
53 static const probe_fptr raid2[] = {
54 #if ENABLE_FEATURE_VOLUMEID_LVM
58 #if ENABLE_FEATURE_VOLUMEID_HIGHPOINTRAID
59 volume_id_probe_highpoint_37x_raid,
61 #if ENABLE_FEATURE_VOLUMEID_LUKS
66 /* signature in the first block, only small buffer needed */
67 static const probe_fptr fs1[] = {
68 #if ENABLE_FEATURE_VOLUMEID_FAT
71 // This one only looks for partitions, we don't use it
72 //#if ENABLE_FEATURE_VOLUMEID_MAC
73 // volume_id_probe_mac_partition_map,
75 #if ENABLE_FEATURE_VOLUMEID_XFS
80 /* fill buffer with maximum */
81 static const probe_fptr fs2[] = {
82 #if ENABLE_FEATURE_VOLUMEID_LINUXSWAP
83 volume_id_probe_linux_swap,
85 #if ENABLE_FEATURE_VOLUMEID_EXT
88 #if ENABLE_FEATURE_VOLUMEID_REISERFS
89 volume_id_probe_reiserfs,
91 #if ENABLE_FEATURE_VOLUMEID_JFS
94 #if ENABLE_FEATURE_VOLUMEID_UDF
97 #if ENABLE_FEATURE_VOLUMEID_ISO9660
98 volume_id_probe_iso9660,
100 #if ENABLE_FEATURE_VOLUMEID_HFS
101 volume_id_probe_hfs_hfsplus,
103 #if ENABLE_FEATURE_VOLUMEID_UFS
106 #if ENABLE_FEATURE_VOLUMEID_NTFS
107 volume_id_probe_ntfs,
109 #if ENABLE_FEATURE_VOLUMEID_CRAMFS
110 volume_id_probe_cramfs,
112 #if ENABLE_FEATURE_VOLUMEID_ROMFS
113 volume_id_probe_romfs,
115 #if ENABLE_FEATURE_VOLUMEID_HPFS
116 volume_id_probe_hpfs,
118 #if ENABLE_FEATURE_VOLUMEID_SYSV
119 volume_id_probe_sysv,
121 #if ENABLE_FEATURE_VOLUMEID_MINIX
122 volume_id_probe_minix,
124 #if ENABLE_FEATURE_VOLUMEID_OCFS2
125 volume_id_probe_ocfs2,
129 int volume_id_probe_all(struct volume_id *id, uint64_t off, uint64_t size)
136 /* probe for raid first, cause fs probes may be successful on raid members */
138 for (i = 0; i < ARRAY_SIZE(raid1); i++)
139 if (raid1[i](id, off, size) == 0)
143 for (i = 0; i < ARRAY_SIZE(raid2); i++)
144 if (raid2[i](id, off) == 0)
147 /* signature in the first block, only small buffer needed */
148 for (i = 0; i < ARRAY_SIZE(fs1); i++)
149 if (fs1[i](id, off) == 0)
152 /* fill buffer with maximum */
153 volume_id_get_buffer(id, 0, SB_BUFFER_SIZE);
155 for (i = 0; i < ARRAY_SIZE(fs2); i++)
156 if (fs2[i](id, off) == 0)
161 /* If the filestystem in recognized, we free the allocated buffers,
162 otherwise they will stay in place for the possible next probe call */
163 volume_id_free_buffer(id);
168 /* open volume by device node */
169 struct volume_id *volume_id_open_node(const char *path)
171 struct volume_id *id;
174 fd = open(path, O_RDONLY);
177 id = xzalloc(sizeof(struct volume_id));
179 ///* close fd on device close */
186 /* open volume by major/minor */
187 struct volume_id *volume_id_open_dev_t(dev_t devt)
189 struct volume_id *id;
190 char *tmp_node[VOLUME_ID_PATH_MAX];
192 tmp_node = xasprintf("/dev/.volume_id-%u-%u-%u",
193 (unsigned)getpid(), (unsigned)major(devt), (unsigned)minor(devt));
195 /* create temporary node to open block device */
197 if (mknod(tmp_node, (S_IFBLK | 0600), devt) != 0)
198 bb_perror_msg_and_die("cannot mknod(%s)", tmp_node);
200 id = volume_id_open_node(tmp_node);
207 void free_volume_id(struct volume_id *id)
212 //if (id->fd_close != 0) - always true
214 volume_id_free_buffer(id);
215 #ifdef UNUSED_PARTITION_CODE
216 free(id->partitions);