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"
24 /* Some detection routines do not set label or uuid anyway,
25 * so they are disabled. */
27 /* Looks for partitions, we don't use it: */
28 #define ENABLE_FEATURE_VOLUMEID_MAC 0
29 /* #define ENABLE_FEATURE_VOLUMEID_MSDOS 0 - NB: this one
30 * was not properly added to probe table anyway - ??! */
32 /* None of RAIDs have label or uuid, except LinuxRAID: */
33 #define ENABLE_FEATURE_VOLUMEID_HIGHPOINTRAID 0
34 #define ENABLE_FEATURE_VOLUMEID_ISWRAID 0
35 #define ENABLE_FEATURE_VOLUMEID_LSIRAID 0
36 #define ENABLE_FEATURE_VOLUMEID_LVM 0
37 #define ENABLE_FEATURE_VOLUMEID_NVIDIARAID 0
38 #define ENABLE_FEATURE_VOLUMEID_PROMISERAID 0
39 #define ENABLE_FEATURE_VOLUMEID_SILICONRAID 0
40 #define ENABLE_FEATURE_VOLUMEID_VIARAID 0
42 /* These filesystems also have no label or uuid: */
43 #define ENABLE_FEATURE_VOLUMEID_MINIX 0
44 #define ENABLE_FEATURE_VOLUMEID_HPFS 0
45 #define ENABLE_FEATURE_VOLUMEID_UFS 0
48 typedef int FAST_FUNC (*raid_probe_fptr
)(struct volume_id
*id
, /*uint64_t off,*/ uint64_t size
);
49 typedef int FAST_FUNC (*probe_fptr
)(struct volume_id
*id
/*, uint64_t off*/);
51 static const raid_probe_fptr raid1
[] = {
52 #if ENABLE_FEATURE_VOLUMEID_LINUXRAID
53 volume_id_probe_linux_raid
,
55 #if ENABLE_FEATURE_VOLUMEID_ISWRAID
56 volume_id_probe_intel_software_raid
,
58 #if ENABLE_FEATURE_VOLUMEID_LSIRAID
59 volume_id_probe_lsi_mega_raid
,
61 #if ENABLE_FEATURE_VOLUMEID_VIARAID
62 volume_id_probe_via_raid
,
64 #if ENABLE_FEATURE_VOLUMEID_SILICONRAID
65 volume_id_probe_silicon_medley_raid
,
67 #if ENABLE_FEATURE_VOLUMEID_NVIDIARAID
68 volume_id_probe_nvidia_raid
,
70 #if ENABLE_FEATURE_VOLUMEID_PROMISERAID
71 volume_id_probe_promise_fasttrack_raid
,
73 #if ENABLE_FEATURE_VOLUMEID_HIGHPOINTRAID
74 volume_id_probe_highpoint_45x_raid
,
78 static const probe_fptr raid2
[] = {
79 #if ENABLE_FEATURE_VOLUMEID_LVM
83 #if ENABLE_FEATURE_VOLUMEID_HIGHPOINTRAID
84 volume_id_probe_highpoint_37x_raid
,
86 #if ENABLE_FEATURE_VOLUMEID_LUKS
91 /* signature in the first block, only small buffer needed */
92 static const probe_fptr fs1
[] = {
93 #if ENABLE_FEATURE_VOLUMEID_FAT
96 #if ENABLE_FEATURE_VOLUMEID_EXFAT
97 volume_id_probe_exfat
,
99 #if ENABLE_FEATURE_VOLUMEID_MAC
100 volume_id_probe_mac_partition_map
,
102 #if ENABLE_FEATURE_VOLUMEID_SQUASHFS
103 volume_id_probe_squashfs
,
105 #if ENABLE_FEATURE_VOLUMEID_XFS
110 /* fill buffer with maximum */
111 static const probe_fptr fs2
[] = {
112 #if ENABLE_FEATURE_VOLUMEID_LINUXSWAP
113 volume_id_probe_linux_swap
,
115 #if ENABLE_FEATURE_VOLUMEID_EXT
118 #if ENABLE_FEATURE_VOLUMEID_BTRFS
119 volume_id_probe_btrfs
,
121 #if ENABLE_FEATURE_VOLUMEID_REISERFS
122 volume_id_probe_reiserfs
,
124 #if ENABLE_FEATURE_VOLUMEID_JFS
127 #if ENABLE_FEATURE_VOLUMEID_UDF
130 #if ENABLE_FEATURE_VOLUMEID_ISO9660
131 volume_id_probe_iso9660
,
133 #if ENABLE_FEATURE_VOLUMEID_HFS
134 volume_id_probe_hfs_hfsplus
,
136 #if ENABLE_FEATURE_VOLUMEID_UFS
139 #if ENABLE_FEATURE_VOLUMEID_NILFS
140 volume_id_probe_nilfs
,
142 #if ENABLE_FEATURE_VOLUMEID_NTFS
143 volume_id_probe_ntfs
,
145 #if ENABLE_FEATURE_VOLUMEID_CRAMFS
146 volume_id_probe_cramfs
,
148 #if ENABLE_FEATURE_VOLUMEID_ROMFS
149 volume_id_probe_romfs
,
151 #if ENABLE_FEATURE_VOLUMEID_HPFS
152 volume_id_probe_hpfs
,
154 #if ENABLE_FEATURE_VOLUMEID_SYSV
155 volume_id_probe_sysv
,
157 #if ENABLE_FEATURE_VOLUMEID_MINIX
158 volume_id_probe_minix
,
160 #if ENABLE_FEATURE_VOLUMEID_OCFS2
161 volume_id_probe_ocfs2
,
165 int FAST_FUNC
volume_id_probe_all(struct volume_id
*id
, /*uint64_t off,*/ uint64_t size
)
169 /* probe for raid first, cause fs probes may be successful on raid members */
171 for (i
= 0; i
< ARRAY_SIZE(raid1
); i
++) {
172 if (raid1
[i
](id
, /*off,*/ size
) == 0)
179 for (i
= 0; i
< ARRAY_SIZE(raid2
); i
++) {
180 if (raid2
[i
](id
/*,off*/) == 0)
186 /* signature in the first block, only small buffer needed */
187 for (i
= 0; i
< ARRAY_SIZE(fs1
); i
++) {
188 if (fs1
[i
](id
/*,off*/) == 0)
194 /* fill buffer with maximum */
195 volume_id_get_buffer(id
, 0, SB_BUFFER_SIZE
);
197 for (i
= 0; i
< ARRAY_SIZE(fs2
); i
++) {
198 if (fs2
[i
](id
/*,off*/) == 0)
205 volume_id_free_buffer(id
);
206 return (- id
->error
); /* 0 or -1 */
209 /* open volume by device node */
210 struct volume_id
* FAST_FUNC
volume_id_open_node(int fd
)
212 struct volume_id
*id
;
214 id
= xzalloc(sizeof(struct volume_id
));
216 ///* close fd on device close */
222 /* open volume by major/minor */
223 struct volume_id
* FAST_FUNC
volume_id_open_dev_t(dev_t devt
)
225 struct volume_id
*id
;
226 char *tmp_node
[VOLUME_ID_PATH_MAX
];
228 tmp_node
= xasprintf("/dev/.volume_id-%u-%u-%u",
229 (unsigned)getpid(), (unsigned)major(devt
), (unsigned)minor(devt
));
231 /* create temporary node to open block device */
233 if (mknod(tmp_node
, (S_IFBLK
| 0600), devt
) != 0)
234 bb_perror_msg_and_die("can't mknod(%s)", tmp_node
);
236 id
= volume_id_open_node(tmp_node
);
243 void FAST_FUNC
free_volume_id(struct volume_id
*id
)
248 //if (id->fd_close != 0) - always true
250 volume_id_free_buffer(id
);
251 #ifdef UNUSED_PARTITION_CODE
252 free(id
->partitions
);