2 * probe.c - identify a block device by its contents, and return a dev
3 * struct with the details
5 * Copyright (C) 1999 by Andries Brouwer
6 * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
7 * Copyright (C) 2001 by Andreas Dilger
10 * This file may be redistributed under the terms of the
11 * GNU Lesser General Public License.
20 #include <sys/types.h>
21 #ifdef HAVE_SYS_STAT_H
24 #ifdef HAVE_SYS_MKDEV_H
25 #include <sys/mkdev.h>
31 #include "uuid/uuid.h"
34 static int figure_label_len(const unsigned char *label, int len)
36 const unsigned char *end = label + len - 1;
38 while ((*end == ' ' || *end == 0) && end >= label)
42 return end - label + 1;
47 static unsigned char *get_buffer(struct blkid_probe *pr,
48 unsigned off, size_t len)
51 unsigned char *newbuf;
53 if (off + len <= SB_BUFFER_SIZE) {
55 pr->sbbuf = malloc(SB_BUFFER_SIZE);
58 if (lseek(pr->fd, 0, SEEK_SET) < 0)
60 ret_read = read(pr->fd, pr->sbbuf, SB_BUFFER_SIZE);
63 pr->sb_valid = ret_read;
65 if (off+len > pr->sb_valid)
67 return pr->sbbuf + off;
69 if (len > pr->buf_max) {
70 newbuf = realloc(pr->buf, len);
76 if (lseek(pr->fd, off, SEEK_SET) < 0)
78 ret_read = read(pr->fd, pr->buf, len);
79 if (ret_read != (ssize_t) len)
87 * This is a special case code to check for an MDRAID device. We do
88 * this special since it requires checking for a superblock at the end
91 static int check_mdraid(int fd, unsigned char *ret_uuid)
93 struct mdp_superblock_s *md;
98 return -BLKID_ERR_PARAM;
100 offset = (blkid_get_dev_size(fd) & ~((blkid_loff_t)65535)) - 65536;
102 if (blkid_llseek(fd, offset, 0) < 0 ||
103 read(fd, buf, 4096) != 4096)
104 return -BLKID_ERR_IO;
106 /* Check for magic number */
107 if (memcmp("\251+N\374", buf, 4))
108 return -BLKID_ERR_PARAM;
114 /* The MD UUID is not contiguous in the superblock, make it so */
115 md = (struct mdp_superblock_s *)buf;
116 if (md->set_uuid0 || md->set_uuid1 || md->set_uuid2 || md->set_uuid3) {
117 memcpy(ret_uuid, &md->set_uuid0, 4);
118 memcpy(ret_uuid, &md->set_uuid1, 12);
123 static void set_uuid(blkid_dev dev, uuid_t uuid)
127 if (!uuid_is_null(uuid)) {
128 uuid_unparse(uuid, str);
129 blkid_set_tag(dev, "UUID", str, sizeof(str));
133 static void get_ext2_info(blkid_dev dev, unsigned char *buf)
135 struct ext2_super_block *es = (struct ext2_super_block *) buf;
136 const char *label = 0;
138 DBG(DEBUG_PROBE, printf("ext2_sb.compat = %08X:%08X:%08X\n",
139 blkid_le32(es->s_feature_compat),
140 blkid_le32(es->s_feature_incompat),
141 blkid_le32(es->s_feature_ro_compat)));
143 if (strlen(es->s_volume_name))
144 label = es->s_volume_name;
145 blkid_set_tag(dev, "LABEL", label, sizeof(es->s_volume_name));
147 set_uuid(dev, es->s_uuid);
150 static int probe_ext3(struct blkid_probe *probe,
151 struct blkid_magic *id __BLKID_ATTR((unused)),
154 struct ext2_super_block *es;
156 es = (struct ext2_super_block *)buf;
158 /* Distinguish between jbd and ext2/3 fs */
159 if (blkid_le32(es->s_feature_incompat) &
160 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)
161 return -BLKID_ERR_PARAM;
163 /* Distinguish between ext3 and ext2 */
164 if (!(blkid_le32(es->s_feature_compat) &
165 EXT3_FEATURE_COMPAT_HAS_JOURNAL))
166 return -BLKID_ERR_PARAM;
168 get_ext2_info(probe->dev, buf);
170 blkid_set_tag(probe->dev, "SEC_TYPE", "ext2", sizeof("ext2"));
175 static int probe_ext2(struct blkid_probe *probe,
176 struct blkid_magic *id __BLKID_ATTR((unused)),
179 struct ext2_super_block *es;
181 es = (struct ext2_super_block *)buf;
183 /* Distinguish between jbd and ext2/3 fs */
184 if (blkid_le32(es->s_feature_incompat) &
185 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)
186 return -BLKID_ERR_PARAM;
188 /* Distinguish between ext3 and ext2 */
189 if ((blkid_le32(es->s_feature_compat) &
190 EXT3_FEATURE_COMPAT_HAS_JOURNAL))
191 return -BLKID_ERR_PARAM;
193 get_ext2_info(probe->dev, buf);
198 static int probe_jbd(struct blkid_probe *probe,
199 struct blkid_magic *id __BLKID_ATTR((unused)),
202 struct ext2_super_block *es = (struct ext2_super_block *) buf;
204 if (!(blkid_le32(es->s_feature_incompat) &
205 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV))
206 return -BLKID_ERR_PARAM;
208 get_ext2_info(probe->dev, buf);
213 static int probe_fat(struct blkid_probe *probe,
214 struct blkid_magic *id __BLKID_ATTR((unused)),
217 struct vfat_super_block *vs = (struct vfat_super_block *) buf;
218 struct msdos_super_block *ms = (struct msdos_super_block *) buf;
220 const unsigned char *label = 0, *vol_label = 0;
221 unsigned char *vol_serno;
232 /* sector size check */
233 sector_size = blkid_le16(*((__u16 *) &ms->ms_sector_size));
234 if (sector_size != 0x200 && sector_size != 0x400 &&
235 sector_size != 0x800 && sector_size != 0x1000)
238 dir_entries = blkid_le16(*((__u16 *) &ms->ms_dir_entries));
239 reserved = blkid_le16(ms->ms_reserved);
240 sect_count = blkid_le16(*((__u16 *) &ms->ms_sectors));
242 sect_count = blkid_le32(ms->ms_total_sect);
244 fat_length = blkid_le16(ms->ms_fat_length);
246 fat_length = blkid_le32(vs->vs_fat32_length);
248 fat_size = fat_length * ms->ms_fats;
249 dir_size = ((dir_entries * sizeof(struct vfat_dir_entry)) +
250 (sector_size-1)) / sector_size;
252 cluster_count = sect_count - (reserved + fat_size + dir_size);
253 cluster_count /= ms->ms_cluster_size;
255 if (cluster_count > FAT32_MAX)
258 if (ms->ms_fat_length) {
259 vol_label = ms->ms_label;
260 vol_serno = ms->ms_serno;
262 blkid_set_tag(probe->dev, "SEC_TYPE", "msdos", sizeof("msdos"));
264 vol_label = vs->vs_label;
265 vol_serno = vs->vs_serno;
268 if (vol_label && memcmp(vol_label, "NO NAME ", 11)) {
270 label_len = figure_label_len(vol_label, 11);
273 /* We can't just print them as %04X, because they are unaligned */
274 sprintf(serno, "%02X%02X-%02X%02X", vol_serno[3], vol_serno[2],
275 vol_serno[1], vol_serno[0]);
277 blkid_set_tag(probe->dev, "LABEL", (const char *) label, label_len);
278 blkid_set_tag(probe->dev, "UUID", serno, sizeof(serno)-1);
284 * The FAT filesystem could be without a magic string in superblock
285 * (e.g. old floppies). This heuristic for FAT detection is inspired
286 * by http://vrfy.org/projects/volume_id/ and Linux kernel.
287 * [7-Jul-2005, Karel Zak <kzak@redhat.com>]
289 static int probe_fat_nomagic(struct blkid_probe *probe,
290 struct blkid_magic *id __BLKID_ATTR((unused)),
293 struct vfat_super_block *vs;
295 vs = (struct vfat_super_block *)buf;
298 if (vs->vs_heads == 0)
301 /* cluster size check*/
302 if (vs->vs_cluster_size == 0 ||
303 (vs->vs_cluster_size & (vs->vs_cluster_size-1)))
307 if (vs->vs_media < 0xf8 && vs->vs_media != 0xf0)
310 /* fat counts(Linux kernel expects at least 1 FAT table) */
314 return probe_fat(probe, id, buf);
317 static int probe_xfs(struct blkid_probe *probe,
318 struct blkid_magic *id __BLKID_ATTR((unused)),
321 struct xfs_super_block *xs;
322 const char *label = 0;
324 xs = (struct xfs_super_block *)buf;
326 if (strlen(xs->xs_fname))
327 label = xs->xs_fname;
328 blkid_set_tag(probe->dev, "LABEL", label, sizeof(xs->xs_fname));
329 set_uuid(probe->dev, xs->xs_uuid);
333 static int probe_reiserfs(struct blkid_probe *probe,
334 struct blkid_magic *id, unsigned char *buf)
336 struct reiserfs_super_block *rs = (struct reiserfs_super_block *) buf;
337 unsigned int blocksize;
338 const char *label = 0;
340 blocksize = blkid_le16(rs->rs_blocksize);
342 /* If the superblock is inside the journal, we have the wrong one */
343 if (id->bim_kboff/(blocksize>>10) > blkid_le32(rs->rs_journal_block))
344 return -BLKID_ERR_BIG;
346 /* LABEL/UUID are only valid for later versions of Reiserfs v3.6. */
347 if (id->bim_magic[6] == '2' || id->bim_magic[6] == '3') {
348 if (strlen(rs->rs_label))
349 label = rs->rs_label;
350 set_uuid(probe->dev, rs->rs_uuid);
352 blkid_set_tag(probe->dev, "LABEL", label, sizeof(rs->rs_label));
357 static int probe_reiserfs4(struct blkid_probe *probe,
358 struct blkid_magic *id __BLKID_ATTR((unused)),
361 struct reiser4_super_block *rs4 = (struct reiser4_super_block *) buf;
362 const unsigned char *label = 0;
364 if (strlen((char *) rs4->rs4_label))
365 label = rs4->rs4_label;
366 set_uuid(probe->dev, rs4->rs4_uuid);
367 blkid_set_tag(probe->dev, "LABEL", (const char *) label,
368 sizeof(rs4->rs4_label));
373 static int probe_jfs(struct blkid_probe *probe,
374 struct blkid_magic *id __BLKID_ATTR((unused)),
377 struct jfs_super_block *js;
378 const char *label = 0;
380 js = (struct jfs_super_block *)buf;
382 if (strlen((char *) js->js_label))
383 label = (char *) js->js_label;
384 blkid_set_tag(probe->dev, "LABEL", label, sizeof(js->js_label));
385 set_uuid(probe->dev, js->js_uuid);
389 static int probe_romfs(struct blkid_probe *probe,
390 struct blkid_magic *id __BLKID_ATTR((unused)),
393 struct romfs_super_block *ros;
394 const char *label = 0;
396 ros = (struct romfs_super_block *)buf;
398 if (strlen((char *) ros->ros_volume))
399 label = (char *) ros->ros_volume;
400 blkid_set_tag(probe->dev, "LABEL", label, 0);
404 static int probe_cramfs(struct blkid_probe *probe,
405 struct blkid_magic *id __BLKID_ATTR((unused)),
408 struct cramfs_super_block *csb;
409 const char *label = 0;
411 csb = (struct cramfs_super_block *)buf;
413 if (strlen((char *) csb->name))
414 label = (char *) csb->name;
415 blkid_set_tag(probe->dev, "LABEL", label, 0);
419 static int probe_swap0(struct blkid_probe *probe,
420 struct blkid_magic *id __BLKID_ATTR((unused)),
421 unsigned char *buf __BLKID_ATTR((unused)))
423 blkid_set_tag(probe->dev, "UUID", 0, 0);
424 blkid_set_tag(probe->dev, "LABEL", 0, 0);
428 static int probe_swap1(struct blkid_probe *probe,
429 struct blkid_magic *id __BLKID_ATTR((unused)),
430 unsigned char *buf __BLKID_ATTR((unused)))
432 struct swap_id_block *sws;
434 probe_swap0(probe, id, buf);
436 * Version 1 swap headers are always located at offset of 1024
437 * bytes, although the swap signature itself is located at the
438 * end of the page (which may vary depending on hardware
441 sws = (struct swap_id_block *) get_buffer(probe, 1024, 1024);
445 /* arbitrary sanity check.. is there any garbage down there? */
446 if (sws->sws_pad[32] == 0 && sws->sws_pad[33] == 0) {
447 if (sws->sws_volume[0])
448 blkid_set_tag(probe->dev, "LABEL", sws->sws_volume,
449 sizeof(sws->sws_volume));
450 if (sws->sws_uuid[0])
451 set_uuid(probe->dev, sws->sws_uuid);
456 static int probe_iso9660(struct blkid_probe *probe,
457 struct blkid_magic *id __BLKID_ATTR((unused)),
460 struct iso_volume_descriptor *iso;
461 const unsigned char *label;
463 iso = (struct iso_volume_descriptor *) buf;
464 label = iso->volume_id;
466 blkid_set_tag(probe->dev, "LABEL", (const char *) label,
467 figure_label_len(label, 32));
473 *udf_magic[] = { "BEA01", "BOOT2", "CD001", "CDW02", "NSR02",
474 "NSR03", "TEA01", 0 };
476 static int probe_udf(struct blkid_probe *probe,
477 struct blkid_magic *id __BLKID_ATTR((unused)),
478 unsigned char *buf __BLKID_ATTR((unused)))
481 struct iso_volume_descriptor *isosb;
484 /* determine the block size by scanning in 2K increments
485 (block sizes larger than 2K will be null padded) */
486 for (bs = 1; bs < 16; bs++) {
487 isosb = (struct iso_volume_descriptor *)
488 get_buffer(probe, bs*2048+32768, sizeof(isosb));
495 /* Scan up to another 64 blocks looking for additional VSD's */
496 for (j = 1; j < 64; j++) {
498 isosb = (struct iso_volume_descriptor *)
499 get_buffer(probe, j*bs*2048+32768,
504 /* If we find NSR0x then call it udf:
507 NSR03 for UDF 2.00 */
508 if (!strncmp(isosb->vd_id, "NSR0", 4))
510 for (m = udf_magic; *m; m++)
511 if (!strncmp(*m, isosb->vd_id, 5))
519 static int probe_ocfs(struct blkid_probe *probe,
520 struct blkid_magic *id __BLKID_ATTR((unused)),
523 struct ocfs_volume_header ovh;
524 struct ocfs_volume_label ovl;
527 memcpy(&ovh, buf, sizeof(ovh));
528 memcpy(&ovl, buf+512, sizeof(ovl));
530 major = ocfsmajor(ovh);
532 blkid_set_tag(probe->dev,"SEC_TYPE","ocfs1",sizeof("ocfs1"));
534 blkid_set_tag(probe->dev,"SEC_TYPE","ntocfs",sizeof("ntocfs"));
536 blkid_set_tag(probe->dev, "LABEL", ovl.label, ocfslabellen(ovl));
537 blkid_set_tag(probe->dev, "MOUNT", ovh.mount, ocfsmountlen(ovh));
538 set_uuid(probe->dev, ovl.vol_id);
542 static int probe_ocfs2(struct blkid_probe *probe,
543 struct blkid_magic *id __BLKID_ATTR((unused)),
546 struct ocfs2_super_block *osb;
548 osb = (struct ocfs2_super_block *)buf;
550 blkid_set_tag(probe->dev, "LABEL", osb->s_label, sizeof(osb->s_label));
551 set_uuid(probe->dev, osb->s_uuid);
555 static int probe_oracleasm(struct blkid_probe *probe,
556 struct blkid_magic *id __BLKID_ATTR((unused)),
559 struct oracle_asm_disk_label *dl;
561 dl = (struct oracle_asm_disk_label *)buf;
563 blkid_set_tag(probe->dev, "LABEL", dl->dl_id, sizeof(dl->dl_id));
568 * BLKID_BLK_OFFS is at least as large as the highest bim_kboff defined
569 * in the type_array table below + bim_kbalign.
571 * When probing for a lot of magics, we handle everything in 1kB buffers so
572 * that we don't have to worry about reading each combination of block sizes.
574 #define BLKID_BLK_OFFS 64 /* currently reiserfs */
577 * Various filesystem magics that we can check for. Note that kboff and
578 * sboff are in kilobytes and bytes respectively. All magics are in
579 * byte strings so we don't worry about endian issues.
581 static struct blkid_magic type_array[] = {
582 /* type kboff sboff len magic probe */
583 { "oracleasm", 0, 32, 8, "ORCLDISK", probe_oracleasm },
584 { "ntfs", 0, 3, 8, "NTFS ", 0 },
585 { "jbd", 1, 0x38, 2, "\123\357", probe_jbd },
586 { "ext3", 1, 0x38, 2, "\123\357", probe_ext3 },
587 { "ext2", 1, 0x38, 2, "\123\357", probe_ext2 },
588 { "reiserfs", 8, 0x34, 8, "ReIsErFs", probe_reiserfs },
589 { "reiserfs", 64, 0x34, 9, "ReIsEr2Fs", probe_reiserfs },
590 { "reiserfs", 64, 0x34, 9, "ReIsEr3Fs", probe_reiserfs },
591 { "reiserfs", 64, 0x34, 8, "ReIsErFs", probe_reiserfs },
592 { "reiserfs", 8, 20, 8, "ReIsErFs", probe_reiserfs },
593 { "reiser4", 64, 0, 7, "ReIsEr4", probe_reiserfs4 },
594 { "vfat", 0, 0x52, 5, "MSWIN", probe_fat },
595 { "vfat", 0, 0x52, 8, "FAT32 ", probe_fat },
596 { "vfat", 0, 0x36, 5, "MSDOS", probe_fat },
597 { "vfat", 0, 0x36, 8, "FAT16 ", probe_fat },
598 { "vfat", 0, 0x36, 8, "FAT12 ", probe_fat },
599 { "vfat", 0, 0, 2, "\353\220", probe_fat_nomagic },
600 { "vfat", 0, 0, 1, "\351", probe_fat_nomagic },
601 { "minix", 1, 0x10, 2, "\177\023", 0 },
602 { "minix", 1, 0x10, 2, "\217\023", 0 },
603 { "minix", 1, 0x10, 2, "\150\044", 0 },
604 { "minix", 1, 0x10, 2, "\170\044", 0 },
605 { "vxfs", 1, 0, 4, "\365\374\001\245", 0 },
606 { "xfs", 0, 0, 4, "XFSB", probe_xfs },
607 { "romfs", 0, 0, 8, "-rom1fs-", probe_romfs },
608 { "bfs", 0, 0, 4, "\316\372\173\033", 0 },
609 { "cramfs", 0, 0, 4, "E=\315\050", probe_cramfs },
610 { "qnx4", 0, 4, 6, "QNX4FS", 0 },
611 { "udf", 32, 1, 5, "BEA01", probe_udf },
612 { "udf", 32, 1, 5, "BOOT2", probe_udf },
613 { "udf", 32, 1, 5, "CD001", probe_udf },
614 { "udf", 32, 1, 5, "CDW02", probe_udf },
615 { "udf", 32, 1, 5, "NSR02", probe_udf },
616 { "udf", 32, 1, 5, "NSR03", probe_udf },
617 { "udf", 32, 1, 5, "TEA01", probe_udf },
618 { "iso9660", 32, 1, 5, "CD001", probe_iso9660 },
619 { "iso9660", 32, 9, 5, "CDROM", probe_iso9660 },
620 { "jfs", 32, 0, 4, "JFS1", probe_jfs },
621 { "hfs", 1, 0, 2, "BD", 0 },
622 { "ufs", 8, 0x55c, 4, "T\031\001\000", 0 },
623 { "hpfs", 8, 0, 4, "I\350\225\371", 0 },
624 { "sysv", 0, 0x3f8, 4, "\020~\030\375", 0 },
625 { "swap", 0, 0xff6, 10, "SWAP-SPACE", probe_swap0 },
626 { "swap", 0, 0xff6, 10, "SWAPSPACE2", probe_swap1 },
627 { "swsuspend", 0, 0xff6, 9, "S1SUSPEND", probe_swap1 },
628 { "swsuspend", 0, 0xff6, 9, "S2SUSPEND", probe_swap1 },
629 { "swap", 0, 0x1ff6, 10, "SWAP-SPACE", probe_swap0 },
630 { "swap", 0, 0x1ff6, 10, "SWAPSPACE2", probe_swap1 },
631 { "swsuspend", 0, 0x1ff6, 9, "S1SUSPEND", probe_swap1 },
632 { "swsuspend", 0, 0x1ff6, 9, "S2SUSPEND", probe_swap1 },
633 { "swap", 0, 0x3ff6, 10, "SWAP-SPACE", probe_swap0 },
634 { "swap", 0, 0x3ff6, 10, "SWAPSPACE2", probe_swap1 },
635 { "swsuspend", 0, 0x3ff6, 9, "S1SUSPEND", probe_swap1 },
636 { "swsuspend", 0, 0x3ff6, 9, "S2SUSPEND", probe_swap1 },
637 { "swap", 0, 0x7ff6, 10, "SWAP-SPACE", probe_swap0 },
638 { "swap", 0, 0x7ff6, 10, "SWAPSPACE2", probe_swap1 },
639 { "swsuspend", 0, 0x7ff6, 9, "S1SUSPEND", probe_swap1 },
640 { "swsuspend", 0, 0x7ff6, 9, "S2SUSPEND", probe_swap1 },
641 { "swap", 0, 0xfff6, 10, "SWAP-SPACE", probe_swap0 },
642 { "swap", 0, 0xfff6, 10, "SWAPSPACE2", probe_swap1 },
643 { "swsuspend", 0, 0xfff6, 9, "S1SUSPEND", probe_swap1 },
644 { "swsuspend", 0, 0xfff6, 9, "S2SUSPEND", probe_swap1 },
645 { "ocfs", 0, 8, 9, "OracleCFS", probe_ocfs },
646 { "ocfs2", 1, 0, 6, "OCFSV2", probe_ocfs2 },
647 { "ocfs2", 2, 0, 6, "OCFSV2", probe_ocfs2 },
648 { "ocfs2", 4, 0, 6, "OCFSV2", probe_ocfs2 },
649 { "ocfs2", 8, 0, 6, "OCFSV2", probe_ocfs2 },
650 { NULL, 0, 0, 0, NULL, NULL }
654 * Verify that the data in dev is consistent with what is on the actual
655 * block device (using the devname field only). Normally this will be
656 * called when finding items in the cache, but for long running processes
657 * is also desirable to revalidate an item before use.
659 * If we are unable to revalidate the data, we return the old data and
660 * do not set the BLKID_BID_FL_VERIFIED flag on it.
662 blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev)
664 struct blkid_magic *id;
665 struct blkid_probe probe;
676 diff = now - dev->bid_time;
678 if ((now < dev->bid_time) ||
679 (diff < BLKID_PROBE_MIN) ||
680 (dev->bid_flags & BLKID_BID_FL_VERIFIED &&
681 diff < BLKID_PROBE_INTERVAL))
685 printf("need to revalidate %s (time since last check %lu)\n",
686 dev->bid_name, diff));
688 if (((probe.fd = open(dev->bid_name, O_RDONLY)) < 0) ||
689 (fstat(probe.fd, &st) < 0)) {
690 if (errno == ENXIO || errno == ENODEV || errno == ENOENT) {
694 /* We don't have read permission, just return cache data. */
696 printf("returning unverified data for %s\n",
708 * Iterate over the type array. If we already know the type,
709 * then try that first. If it doesn't work, then blow away
710 * the type information, and try again.
715 if (!dev->bid_type || !strcmp(dev->bid_type, "mdraid")) {
718 if (check_mdraid(probe.fd, uuid) == 0) {
724 for (id = type_array; id->bim_type; id++) {
726 strcmp(id->bim_type, dev->bid_type))
729 idx = id->bim_kboff + (id->bim_sboff >> 10);
730 buf = get_buffer(&probe, idx << 10, 1024);
734 if (memcmp(id->bim_magic, buf + (id->bim_sboff&0x3ff),
738 if ((id->bim_probe == NULL) ||
739 (id->bim_probe(&probe, id, buf) == 0)) {
745 if (!id->bim_type && dev->bid_type) {
747 * Zap the device filesystem type and try again
749 blkid_set_tag(dev, "TYPE", 0, 0);
750 blkid_set_tag(dev, "SEC_TYPE", 0, 0);
751 blkid_set_tag(dev, "LABEL", 0, 0);
752 blkid_set_tag(dev, "UUID", 0, 0);
756 if (!dev->bid_type) {
763 dev->bid_devno = st.st_rdev;
764 dev->bid_time = time(0);
765 dev->bid_flags |= BLKID_BID_FL_VERIFIED;
766 cache->bic_flags |= BLKID_BIC_FL_CHANGED;
768 blkid_set_tag(dev, "TYPE", type, 0);
770 DBG(DEBUG_PROBE, printf("%s: devno 0x%04llx, type %s\n",
771 dev->bid_name, st.st_rdev, type));
783 int blkid_known_fstype(const char *fstype)
785 struct blkid_magic *id;
787 for (id = type_array; id->bim_type; id++) {
788 if (strcmp(fstype, id->bim_type) == 0)
795 int main(int argc, char **argv)
802 fprintf(stderr, "Usage: %s device\n"
803 "Probe a single device to determine type\n", argv[0]);
806 if ((ret = blkid_get_cache(&cache, "/dev/null")) != 0) {
807 fprintf(stderr, "%s: error creating cache (%d)\n",
811 dev = blkid_get_dev(cache, argv[1], BLKID_DEV_NORMAL);
813 printf("%s: %s has an unsupported type\n", argv[0], argv[1]);
816 printf("TYPE='%s'\n", dev->bid_type ? dev->bid_type : "(null)");
818 printf("LABEL='%s'\n", dev->bid_label);
820 printf("UUID='%s'\n", dev->bid_uuid);