2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6 * The superblock structs are taken from the linux kernel sources
7 * and the libblkid living inside the e2fsprogs. This is a simple
8 * straightforward implementation for reading the label strings of the
9 * most common filesystems.
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
42 #include <asm/types.h>
44 #include "volume_id.h"
45 #include "volume_id_logging.h"
47 #define bswap16(x) (__u16)((((__u16)(x) & 0x00ffu) << 8) | \
48 (((__u16)(x) & 0xff00u) >> 8))
50 #define bswap32(x) (__u32)((((__u32)(x) & 0xff000000u) >> 24) | \
51 (((__u32)(x) & 0x00ff0000u) >> 8) | \
52 (((__u32)(x) & 0x0000ff00u) << 8) | \
53 (((__u32)(x) & 0x000000ffu) << 24))
55 #define bswap64(x) (__u64)((((__u64)(x) & 0xff00000000000000ull) >> 56) | \
56 (((__u64)(x) & 0x00ff000000000000ull) >> 40) | \
57 (((__u64)(x) & 0x0000ff0000000000ull) >> 24) | \
58 (((__u64)(x) & 0x000000ff00000000ull) >> 8) | \
59 (((__u64)(x) & 0x00000000ff000000ull) << 8) | \
60 (((__u64)(x) & 0x0000000000ff0000ull) << 24) | \
61 (((__u64)(x) & 0x000000000000ff00ull) << 40) | \
62 (((__u64)(x) & 0x00000000000000ffull) << 56))
64 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
65 #define le16_to_cpu(x) (x)
66 #define le32_to_cpu(x) (x)
67 #define le64_to_cpu(x) (x)
68 #define be16_to_cpu(x) bswap16(x)
69 #define be32_to_cpu(x) bswap32(x)
70 #elif (__BYTE_ORDER == __BIG_ENDIAN)
71 #define le16_to_cpu(x) bswap16(x)
72 #define le32_to_cpu(x) bswap32(x)
73 #define le64_to_cpu(x) bswap64(x)
74 #define be16_to_cpu(x) (x)
75 #define be32_to_cpu(x) (x)
78 /* size of superblock buffer, reiserfs block is at 64k */
79 #define SB_BUFFER_SIZE 0x11000
80 /* size of seek buffer 4k */
81 #define SEEK_BUFFER_SIZE 0x1000
84 static void set_label_raw(struct volume_id *id,
85 const __u8 *buf, unsigned int count)
87 memcpy(id->label_raw, buf, count);
88 id->label_raw_len = count;
91 static void set_label_string(struct volume_id *id,
92 const __u8 *buf, unsigned int count)
96 memcpy(id->label, buf, count);
98 /* remove trailing whitespace */
99 i = strnlen(id->label, count);
101 if (! isspace(id->label[i]))
104 id->label[i+1] = '\0';
109 static void set_label_unicode16(struct volume_id *id,
111 unsigned int endianess,
118 for (i = 0; i + 2 <= count; i += 2) {
120 c = (buf[i+1] << 8) | buf[i];
122 c = (buf[i] << 8) | buf[i+1];
126 } else if (c < 0x80) {
127 id->label[j++] = (__u8) c;
128 } else if (c < 0x800) {
129 id->label[j++] = (__u8) (0xc0 | (c >> 6));
130 id->label[j++] = (__u8) (0x80 | (c & 0x3f));
132 id->label[j++] = (__u8) (0xe0 | (c >> 12));
133 id->label[j++] = (__u8) (0x80 | ((c >> 6) & 0x3f));
134 id->label[j++] = (__u8) (0x80 | (c & 0x3f));
146 static void set_uuid(struct volume_id *id, const __u8 *buf, enum uuid_format format)
149 unsigned int count = 0;
162 memcpy(id->uuid_raw, buf, count);
164 /* if set, create string in the same format, the native platform uses */
165 for (i = 0; i < count; i++)
173 sprintf(id->uuid, "%02X%02X-%02X%02X",
174 buf[3], buf[2], buf[1], buf[0]);
177 sprintf(id->uuid,"%02X%02X%02X%02X%02X%02X%02X%02X",
178 buf[7], buf[6], buf[5], buf[4],
179 buf[3], buf[2], buf[1], buf[0]);
182 sprintf(id->uuid,"%02X%02X%02X%02X%02X%02X%02X%02X",
183 buf[0], buf[1], buf[2], buf[3],
184 buf[4], buf[5], buf[6], buf[7]);
188 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
189 buf[0], buf[1], buf[2], buf[3],
193 buf[10], buf[11], buf[12], buf[13], buf[14],buf[15]);
198 static __u8 *get_buffer(struct volume_id *id, __u64 off, unsigned int len)
200 unsigned int buf_len;
202 dbg("get buffer off 0x%llx, len 0x%x", off, len);
203 /* check if requested area fits in superblock buffer */
204 if (off + len <= SB_BUFFER_SIZE) {
205 if (id->sbbuf == NULL) {
206 id->sbbuf = malloc(SB_BUFFER_SIZE);
207 if (id->sbbuf == NULL)
211 /* check if we need to read */
212 if ((off + len) > id->sbbuf_len) {
213 dbg("read sbbuf len:0x%llx", off + len);
214 lseek(id->fd, 0, SEEK_SET);
215 buf_len = read(id->fd, id->sbbuf, off + len);
216 dbg("got 0x%x (%i) bytes", buf_len, buf_len);
217 id->sbbuf_len = buf_len;
218 if (buf_len < off + len)
222 return &(id->sbbuf[off]);
224 if (len > SEEK_BUFFER_SIZE)
225 len = SEEK_BUFFER_SIZE;
227 /* get seek buffer */
228 if (id->seekbuf == NULL) {
229 id->seekbuf = malloc(SEEK_BUFFER_SIZE);
230 if (id->seekbuf == NULL)
234 /* check if we need to read */
235 if ((off < id->seekbuf_off) ||
236 ((off + len) > (id->seekbuf_off + id->seekbuf_len))) {
237 dbg("read seekbuf off:0x%llx len:0x%x", off, len);
238 if (lseek(id->fd, off, SEEK_SET) == -1)
240 buf_len = read(id->fd, id->seekbuf, len);
241 dbg("got 0x%x (%i) bytes", buf_len, buf_len);
242 id->seekbuf_off = off;
243 id->seekbuf_len = buf_len;
248 return &(id->seekbuf[off - id->seekbuf_off]);
252 static void free_buffer(struct volume_id *id)
254 if (id->sbbuf != NULL) {
259 if (id->seekbuf != NULL) {
266 #define LVM1_SB_OFF 0x400
267 #define LVM1_MAGIC "HM"
268 static int probe_lvm1(struct volume_id *id, __u64 off)
270 struct lvm2_super_block {
272 } __attribute__((packed)) *lvm;
276 buf = get_buffer(id, off + LVM1_SB_OFF, 0x800);
280 lvm = (struct lvm2_super_block *) buf;
282 if (strncmp(lvm->id, LVM1_MAGIC, 2) != 0)
285 id->usage_id = VOLUME_ID_RAID;
286 id->type_id = VOLUME_ID_LVM1;
287 id->type = "LVM1_member";
292 #define LVM2_LABEL_ID "LABELONE"
293 #define LVM2LABEL_SCAN_SECTORS 4
294 static int probe_lvm2(struct volume_id *id, __u64 off)
296 struct lvm2_super_block {
302 } __attribute__((packed)) *lvm;
307 buf = get_buffer(id, off, LVM2LABEL_SCAN_SECTORS * 0x200);
312 for (soff = 0; soff < LVM2LABEL_SCAN_SECTORS * 0x200; soff += 0x200) {
313 lvm = (struct lvm2_super_block *) &buf[soff];
315 if (strncmp(lvm->id, LVM2_LABEL_ID, 8) == 0)
322 strncpy(id->type_version, lvm->type, 8);
323 id->usage_id = VOLUME_ID_RAID;
324 id->type_id = VOLUME_ID_LVM2;
325 id->type = "LVM2_member";
330 #define MD_RESERVED_BYTES 0x10000
331 #define MD_MAGIC 0xa92b4efc
332 static int probe_linux_raid(struct volume_id *id, __u64 off, __u64 size)
334 struct mdp_super_block {
347 __u32 not_persistent;
351 } __attribute__((packed)) *mdp;
360 sboff = (size & ~(MD_RESERVED_BYTES - 1)) - MD_RESERVED_BYTES;
361 buf = get_buffer(id, off + sboff, 0x800);
365 mdp = (struct mdp_super_block *) buf;
367 if (le32_to_cpu(mdp->md_magic) != MD_MAGIC)
370 memcpy(uuid, &mdp->set_uuid0, 4);
371 memcpy(&uuid[4], &mdp->set_uuid1, 12);
372 set_uuid(id, uuid, UUID_DCE);
374 snprintf(id->type_version, VOLUME_ID_FORMAT_SIZE-1, "%u.%u.%u",
375 le32_to_cpu(mdp->major_version),
376 le32_to_cpu(mdp->minor_version),
377 le32_to_cpu(mdp->patch_version));
379 dbg("found raid signature");
380 id->usage_id = VOLUME_ID_RAID;
381 id->type = "linux_raid_member";
386 #define MSDOS_MAGIC "\x55\xaa"
387 #define MSDOS_PARTTABLE_OFFSET 0x1be
388 #define MSDOS_SIG_OFF 0x1fe
390 #define DOS_EXTENDED_PARTITION 0x05
391 #define LINUX_EXTENDED_PARTITION 0x85
392 #define WIN98_EXTENDED_PARTITION 0x0f
393 #define LINUX_RAID_PARTITION 0xfd
394 #define is_extended(type) \
395 (type == DOS_EXTENDED_PARTITION || \
396 type == WIN98_EXTENDED_PARTITION || \
397 type == LINUX_EXTENDED_PARTITION)
398 #define is_raid(type) \
399 (type == LINUX_RAID_PARTITION)
400 static int probe_msdos_part_table(struct volume_id *id, __u64 off)
402 struct msdos_partition_entry {
413 } __attribute__((packed)) *part;
424 struct volume_id_partition *p;
426 buf = get_buffer(id, off, 0x200);
430 if (strncmp(&buf[MSDOS_SIG_OFF], MSDOS_MAGIC, 2) != 0)
433 /* check flags on all entries for a valid partition table */
434 part = (struct msdos_partition_entry*) &buf[MSDOS_PARTTABLE_OFFSET];
435 for (i = 0; i < 4; i++) {
436 if (part[i].boot_ind != 0 &&
437 part[i].boot_ind != 0x80)
440 if (le32_to_cpu(part[i].nr_sects) != 0)
446 if (id->partitions != NULL)
447 free(id->partitions);
448 id->partitions = malloc(VOLUME_ID_PARTITIONS_MAX *
449 sizeof(struct volume_id_partition));
450 if (id->partitions == NULL)
452 memset(id->partitions, 0x00,
453 VOLUME_ID_PARTITIONS_MAX * sizeof(struct volume_id_partition));
455 for (i = 0; i < 4; i++) {
456 poff = (__u64) le32_to_cpu(part[i].start_sect) * BSIZE;
457 plen = (__u64) le32_to_cpu(part[i].nr_sects) * BSIZE;
462 p = &id->partitions[i];
464 p->partition_type_raw = part[i].sys_ind;
466 if (is_extended(part[i].sys_ind)) {
467 dbg("found extended partition at 0x%llx", poff);
468 p->usage_id = VOLUME_ID_PARTITIONTABLE;
469 p->type_id = VOLUME_ID_MSDOSEXTENDED;
470 p->type = "msdos_extended_partition";
472 extended = off + poff;
474 dbg("found 0x%x data partition at 0x%llx, len 0x%llx",
475 part[i].sys_ind, poff, plen);
477 if (is_raid(part[i].sys_ind))
478 p->usage_id = VOLUME_ID_RAID;
480 p->usage_id = VOLUME_ID_UNPROBED;
485 id->partition_count = i+1;
492 /* follow extended partition chain and add data partitions */
495 dbg("extended chain limit reached");
499 buf = get_buffer(id, current, 0x200);
503 part = (struct msdos_partition_entry*) &buf[MSDOS_PARTTABLE_OFFSET];
505 if (strncmp(&buf[MSDOS_SIG_OFF], MSDOS_MAGIC, 2) != 0)
510 for (i = 0; i < 4; i++) {
511 poff = (__u64) le32_to_cpu(part[i].start_sect) * BSIZE;
512 plen = (__u64) le32_to_cpu(part[i].nr_sects) * BSIZE;
517 if (is_extended(part[i].sys_ind)) {
518 dbg("found extended partition at 0x%llx", poff);
520 next = extended + poff;
522 dbg("found 0x%x data partition at 0x%llx, len 0x%llx",
523 part[i].sys_ind, poff, plen);
525 /* we always start at the 5th entry */
526 while (id->partition_count < 4)
527 id->partitions[id->partition_count++].usage_id =
530 p = &id->partitions[id->partition_count];
532 if (is_raid(part[i].sys_ind))
533 p->usage_id = VOLUME_ID_RAID;
535 p->usage_id = VOLUME_ID_UNPROBED;
537 p->off = current + poff;
539 id->partition_count++;
541 p->partition_type_raw = part[i].sys_ind;
543 if (id->partition_count >= VOLUME_ID_PARTITIONS_MAX) {
544 dbg("to many partitions");
553 id->usage_id = VOLUME_ID_PARTITIONTABLE;
554 id->type_id = VOLUME_ID_MSDOSPARTTABLE;
555 id->type = "msdos_partition_table";
560 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x00000004
561 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x00000008
562 #define EXT_SUPERBLOCK_OFFSET 0x400
563 static int probe_ext(struct volume_id *id, __u64 off)
565 struct ext2_super_block {
568 __u32 r_blocks_count;
569 __u32 free_blocks_count;
570 __u32 free_inodes_count;
571 __u32 first_data_block;
572 __u32 log_block_size;
577 __u32 feature_compat;
578 __u32 feature_incompat;
579 __u32 feature_ro_compat;
581 __u8 volume_name[16];
582 } __attribute__((__packed__)) *es;
584 es = (struct ext2_super_block *)
585 get_buffer(id, off + EXT_SUPERBLOCK_OFFSET, 0x200);
589 if (es->magic[0] != 0123 ||
590 es->magic[1] != 0357)
593 set_label_raw(id, es->volume_name, 16);
594 set_label_string(id, es->volume_name, 16);
595 set_uuid(id, es->uuid, UUID_DCE);
597 if ((le32_to_cpu(es->feature_compat) &
598 EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0) {
599 id->usage_id = VOLUME_ID_FILESYSTEM;
600 id->type_id = VOLUME_ID_EXT3;
603 id->usage_id = VOLUME_ID_FILESYSTEM;
604 id->type_id = VOLUME_ID_EXT2;
611 #define REISERFS1_SUPERBLOCK_OFFSET 0x2000
612 #define REISERFS_SUPERBLOCK_OFFSET 0x10000
613 static int probe_reiserfs(struct volume_id *id, __u64 off)
615 struct reiserfs_super_block {
621 __u32 orig_journal_size;
629 } __attribute__((__packed__)) *rs;
631 rs = (struct reiserfs_super_block *)
632 get_buffer(id, off + REISERFS_SUPERBLOCK_OFFSET, 0x200);
636 if (strncmp(rs->magic, "ReIsEr2Fs", 9) == 0) {
637 strcpy(id->type_version, "3.6");
641 if (strncmp(rs->magic, "ReIsEr3Fs", 9) == 0) {
642 strcpy(id->type_version, "JR");
646 rs = (struct reiserfs_super_block *)
647 get_buffer(id, off + REISERFS1_SUPERBLOCK_OFFSET, 0x200);
651 if (strncmp(rs->magic, "ReIsErFs", 8) == 0) {
652 strcpy(id->type_version, "3.5");
659 set_label_raw(id, rs->label, 16);
660 set_label_string(id, rs->label, 16);
661 set_uuid(id, rs->uuid, UUID_DCE);
663 id->usage_id = VOLUME_ID_FILESYSTEM;
664 id->type_id = VOLUME_ID_REISERFS;
665 id->type = "reiserfs";
670 static int probe_xfs(struct volume_id *id, __u64 off)
672 struct xfs_super_block {
685 } __attribute__((__packed__)) *xs;
687 xs = (struct xfs_super_block *) get_buffer(id, off, 0x200);
691 if (strncmp(xs->magic, "XFSB", 4) != 0)
694 set_label_raw(id, xs->fname, 12);
695 set_label_string(id, xs->fname, 12);
696 set_uuid(id, xs->uuid, UUID_DCE);
698 id->usage_id = VOLUME_ID_FILESYSTEM;
699 id->type_id = VOLUME_ID_XFS;
705 #define JFS_SUPERBLOCK_OFFSET 0x8000
706 static int probe_jfs(struct volume_id *id, __u64 off)
708 struct jfs_super_block {
719 } __attribute__((__packed__)) *js;
721 js = (struct jfs_super_block *)
722 get_buffer(id, off + JFS_SUPERBLOCK_OFFSET, 0x200);
726 if (strncmp(js->magic, "JFS1", 4) != 0)
729 set_label_raw(id, js->label, 16);
730 set_label_string(id, js->label, 16);
731 set_uuid(id, js->uuid, UUID_DCE);
733 id->usage_id = VOLUME_ID_FILESYSTEM;
734 id->type_id = VOLUME_ID_JFS;
740 #define FAT12_MAX 0xff5
741 #define FAT16_MAX 0xfff5
742 #define FAT_ATTR_VOLUME 0x08
743 static int probe_vfat(struct volume_id *id, __u64 off)
745 struct vfat_super_block {
749 __u8 sectors_per_cluster;
761 struct fat_super_block {
768 } __attribute__((__packed__)) fat;
769 struct fat32_super_block {
783 } __attribute__((__packed__)) fat32;
784 } __attribute__((__packed__)) type;
785 } __attribute__((__packed__)) *vs;
787 struct vfat_dir_entry {
799 } __attribute__((__packed__)) *dir;
811 __u32 start_data_sect;
812 __u16 root_dir_entries;
820 vs = (struct vfat_super_block *) get_buffer(id, off, 0x200);
824 /* believe only that's fat, don't trust the version
825 * the cluster_count will tell us
827 if (strncmp(vs->type.fat32.magic, "MSWIN", 5) == 0)
830 if (strncmp(vs->type.fat32.magic, "FAT32 ", 8) == 0)
833 if (strncmp(vs->type.fat.magic, "FAT16 ", 8) == 0)
836 if (strncmp(vs->type.fat.magic, "MSDOS", 5) == 0)
839 if (strncmp(vs->type.fat.magic, "FAT12 ", 8) == 0)
843 * There are old floppies out there without a magic, so we check
844 * for well known values and guess if it's a fat volume
847 /* boot jump address check */
848 if ((vs->boot_jump[0] != 0xeb || vs->boot_jump[2] != 0x90) &&
849 vs->boot_jump[0] != 0xe9)
856 /* cluster size check*/
857 if (vs->sectors_per_cluster == 0 ||
858 (vs->sectors_per_cluster & (vs->sectors_per_cluster-1)))
862 if (vs->media < 0xf8 && vs->media != 0xf0)
870 /* sector size check */
871 sector_size = le16_to_cpu(vs->sector_size);
872 if (sector_size != 0x200 && sector_size != 0x400 &&
873 sector_size != 0x800 && sector_size != 0x1000)
876 dbg("sector_size 0x%x", sector_size);
877 dbg("sectors_per_cluster 0x%x", vs->sectors_per_cluster);
879 dir_entries = le16_to_cpu(vs->dir_entries);
880 reserved = le16_to_cpu(vs->reserved);
881 dbg("reserved 0x%x", reserved);
883 sect_count = le16_to_cpu(vs->sectors);
885 sect_count = le32_to_cpu(vs->total_sect);
886 dbg("sect_count 0x%x", sect_count);
888 fat_length = le16_to_cpu(vs->fat_length);
890 fat_length = le32_to_cpu(vs->type.fat32.fat32_length);
891 dbg("fat_length 0x%x", fat_length);
893 fat_size = fat_length * vs->fats;
894 dir_size = ((dir_entries * sizeof(struct vfat_dir_entry)) +
895 (sector_size-1)) / sector_size;
896 dbg("dir_size 0x%x", dir_size);
898 cluster_count = sect_count - (reserved + fat_size + dir_size);
899 cluster_count /= vs->sectors_per_cluster;
900 dbg("cluster_count 0x%x", cluster_count);
902 if (cluster_count < FAT12_MAX) {
903 strcpy(id->type_version, "FAT12");
904 } else if (cluster_count < FAT16_MAX) {
905 strcpy(id->type_version, "FAT16");
907 strcpy(id->type_version, "FAT32");
911 /* the label may be an attribute in the root directory */
912 root_start = (reserved + fat_size) * sector_size;
913 dbg("root dir start 0x%llx", root_start);
914 root_dir_entries = le16_to_cpu(vs->dir_entries);
915 dbg("expected entries 0x%x", root_dir_entries);
917 buf_size = root_dir_entries * sizeof(struct vfat_dir_entry);
918 buf = get_buffer(id, off + root_start, buf_size);
922 dir = (struct vfat_dir_entry*) buf;
924 for (i = 0; i <= root_dir_entries; i++) {
926 if (dir[i].name[0] == 0x00) {
932 if (dir[i].name[0] == 0xe5)
935 if (dir[i].attr == FAT_ATTR_VOLUME) {
936 dbg("found ATTR_VOLUME id in root dir");
940 dbg("skip dir entry");
943 if (label != NULL && strncmp(label, "NO NAME ", 11) != 0) {
944 set_label_raw(id, label, 11);
945 set_label_string(id, label, 11);
946 } else if (strncmp(vs->type.fat.label, "NO NAME ", 11) != 0) {
947 set_label_raw(id, vs->type.fat.label, 11);
948 set_label_string(id, vs->type.fat.label, 11);
950 set_uuid(id, vs->type.fat.serno, UUID_DOS);
954 /* FAT32 root dir is a cluster chain like any other directory */
955 buf_size = vs->sectors_per_cluster * sector_size;
956 root_cluster = le32_to_cpu(vs->type.fat32.root_cluster);
957 dbg("root dir cluster %u", root_cluster);
958 start_data_sect = reserved + fat_size;
968 dbg("next cluster %u", next);
969 next_sect_off = (next - 2) * vs->sectors_per_cluster;
970 next_off = (start_data_sect + next_sect_off) * sector_size;
971 dbg("cluster offset 0x%llx", next_off);
974 buf = get_buffer(id, off + next_off, buf_size);
978 dir = (struct vfat_dir_entry*) buf;
979 count = buf_size / sizeof(struct vfat_dir_entry);
980 dbg("expected entries 0x%x", count);
982 for (i = 0; i <= count; i++) {
984 if (dir[i].name[0] == 0x00) {
990 if (dir[i].name[0] == 0xe5)
993 if (dir[i].attr == FAT_ATTR_VOLUME) {
994 dbg("found ATTR_VOLUME id in root dir");
999 dbg("skip dir entry");
1003 fat_entry_off = (reserved * sector_size) + (next * sizeof(__u32));
1004 buf = get_buffer(id, off + fat_entry_off, buf_size);
1008 /* set next cluster */
1009 next = le32_to_cpu(*((__u32 *) buf) & 0x0fffffff);
1014 dbg("reached maximum follow count of root cluster chain, give up");
1017 if (label != NULL && strncmp(label, "NO NAME ", 11) != 0) {
1018 set_label_raw(id, label, 11);
1019 set_label_string(id, label, 11);
1020 } else if (strncmp(vs->type.fat32.label, "NO NAME ", 11) == 0) {
1021 set_label_raw(id, vs->type.fat32.label, 11);
1022 set_label_string(id, vs->type.fat32.label, 11);
1024 set_uuid(id, vs->type.fat32.serno, UUID_DOS);
1027 id->usage_id = VOLUME_ID_FILESYSTEM;
1028 id->type_id = VOLUME_ID_VFAT;
1034 #define UDF_VSD_OFFSET 0x8000
1035 static int probe_udf(struct volume_id *id, __u64 off)
1037 struct volume_descriptor {
1038 struct descriptor_tag {
1047 } __attribute__((__packed__)) tag;
1049 struct anchor_descriptor {
1052 } __attribute__((__packed__)) anchor;
1053 struct primary_descriptor {
1059 } __attribute__((__packed__)) ident;
1060 } __attribute__((__packed__)) primary;
1061 } __attribute__((__packed__)) type;
1062 } __attribute__((__packed__)) *vd;
1064 struct volume_structure_descriptor {
1077 vsd = (struct volume_structure_descriptor *)
1078 get_buffer(id, off + UDF_VSD_OFFSET, 0x200);
1082 if (strncmp(vsd->id, "NSR02", 5) == 0)
1084 if (strncmp(vsd->id, "NSR03", 5) == 0)
1086 if (strncmp(vsd->id, "BEA01", 5) == 0)
1088 if (strncmp(vsd->id, "BOOT2", 5) == 0)
1090 if (strncmp(vsd->id, "CD001", 5) == 0)
1092 if (strncmp(vsd->id, "CDW02", 5) == 0)
1094 if (strncmp(vsd->id, "TEA03", 5) == 0)
1099 /* search the next VSD to get the logical block size of the volume */
1100 for (bs = 0x800; bs < 0x8000; bs += 0x800) {
1101 vsd = (struct volume_structure_descriptor *)
1102 get_buffer(id, off + UDF_VSD_OFFSET + bs, 0x800);
1105 dbg("test for blocksize: 0x%x", bs);
1106 if (vsd->id[0] != '\0')
1112 /* search the list of VSDs for a NSR descriptor */
1113 for (b = 0; b < 64; b++) {
1114 vsd = (struct volume_structure_descriptor *)
1115 get_buffer(id, off + UDF_VSD_OFFSET + (b * bs), 0x800);
1119 dbg("vsd: %c%c%c%c%c",
1120 vsd->id[0], vsd->id[1], vsd->id[2], vsd->id[3], vsd->id[4]);
1122 if (vsd->id[0] == '\0')
1124 if (strncmp(vsd->id, "NSR02", 5) == 0)
1126 if (strncmp(vsd->id, "NSR03", 5) == 0)
1132 /* read anchor volume descriptor */
1133 vd = (struct volume_descriptor *)
1134 get_buffer(id, off + (256 * bs), 0x200);
1138 type = le16_to_cpu(vd->tag.id);
1139 if (type != 2) /* TAG_ID_AVDP */
1142 /* get desriptor list address and block count */
1143 count = le32_to_cpu(vd->type.anchor.length) / bs;
1144 loc = le32_to_cpu(vd->type.anchor.location);
1145 dbg("0x%x descriptors starting at logical secor 0x%x", count, loc);
1147 /* pick the primary descriptor from the list */
1148 for (b = 0; b < count; b++) {
1149 vd = (struct volume_descriptor *)
1150 get_buffer(id, off + ((loc + b) * bs), 0x200);
1154 type = le16_to_cpu(vd->tag.id);
1155 dbg("descriptor type %i", type);
1157 /* check validity */
1160 if (le32_to_cpu(vd->tag.location) != loc + b)
1163 if (type == 1) /* TAG_ID_PVD */
1169 set_label_raw(id, &(vd->type.primary.ident.clen), 32);
1171 clen = vd->type.primary.ident.clen;
1172 dbg("label string charsize=%i bit", clen);
1174 set_label_string(id, vd->type.primary.ident.c, 31);
1175 else if (clen == 16)
1176 set_label_unicode16(id, vd->type.primary.ident.c, BE,31);
1179 id->usage_id = VOLUME_ID_FILESYSTEM;
1180 id->type_id = VOLUME_ID_UDF;
1186 #define ISO_SUPERBLOCK_OFFSET 0x8000
1187 static int probe_iso9660(struct volume_id *id, __u64 off)
1189 union iso_super_block {
1197 } __attribute__((__packed__)) iso;
1203 } __attribute__((__packed__)) hs;
1204 } __attribute__((__packed__)) *is;
1206 is = (union iso_super_block *)
1207 get_buffer(id, off + ISO_SUPERBLOCK_OFFSET, 0x200);
1211 if (strncmp(is->iso.id, "CD001", 5) == 0) {
1212 set_label_raw(id, is->iso.volume_id, 32);
1213 set_label_string(id, is->iso.volume_id, 32);
1216 if (strncmp(is->hs.id, "CDROM", 5) == 0)
1221 id->usage_id = VOLUME_ID_FILESYSTEM;
1222 id->type_id = VOLUME_ID_ISO9660;
1223 id->type = "iso9660";
1228 #define UFS_MAGIC 0x00011954
1229 #define UFS2_MAGIC 0x19540119
1230 #define UFS_MAGIC_FEA 0x00195612
1231 #define UFS_MAGIC_LFN 0x00095014
1234 static int probe_ufs(struct volume_id *id, __u64 off)
1236 struct ufs_super_block {
1270 __u32 fs_npsect_state;
1271 __u32 fs_interleave;
1289 } __attribute__((__packed__)) fs_cstotal;
1299 __u32 fs_maxcluster;
1301 __u16 fs_opostbl[16][8];
1302 } __attribute__((__packed__)) fs_u1;
1305 __u8 fs_volname[32];
1310 __u32 fs_contigdirs;
1312 __u32 fs_maxcluster;
1316 __s64 fs_sparecon64[17];
1318 struct ufs2_csum_total {
1323 __u64 cs_numclusters;
1325 } __attribute__((__packed__)) fs_cstotal;
1326 struct ufs_timeval {
1329 } __attribute__((__packed__)) fs_time;
1333 __s64 fs_pendingblocks;
1334 __s32 fs_pendinginodes;
1335 } __attribute__((__packed__)) fs_u2;
1339 __s32 fs_sparecon[53];
1341 __s32 fs_sparecon2[1];
1345 } __attribute__((__packed__)) fs_sun;
1347 __s32 fs_sparecon[53];
1349 __s32 fs_sparecon2[1];
1353 } __attribute__((__packed__)) fs_sunx86;
1355 __s32 fs_sparecon[50];
1356 __s32 fs_contigsumsize;
1357 __s32 fs_maxsymlinklen;
1359 __u32 fs_maxfilesize[2];
1363 } __attribute__((__packed__)) fs_44;
1365 __s32 fs_postblformat;
1371 } __attribute__((__packed__)) *ufs;
1375 int offsets[] = {0, 8, 64, 256, -1};
1377 for (i = 0; offsets[i] >= 0; i++) {
1378 ufs = (struct ufs_super_block *)
1379 get_buffer(id, off + (offsets[i] * 0x400), 0x800);
1383 dbg("offset 0x%x", offsets[i] * 0x400);
1384 magic = be32_to_cpu(ufs->fs_magic);
1385 if ((magic == UFS_MAGIC) ||
1386 (magic == UFS2_MAGIC) ||
1387 (magic == UFS_MAGIC_FEA) ||
1388 (magic == UFS_MAGIC_LFN)) {
1389 dbg("magic 0x%08x(be)", magic);
1392 magic = le32_to_cpu(ufs->fs_magic);
1393 if ((magic == UFS_MAGIC) ||
1394 (magic == UFS2_MAGIC) ||
1395 (magic == UFS_MAGIC_FEA) ||
1396 (magic == UFS_MAGIC_LFN)) {
1397 dbg("magic 0x%08x(le)", magic);
1404 id->usage_id = VOLUME_ID_FILESYSTEM;
1405 id->type_id = VOLUME_ID_UFS;
1411 static int probe_mac_partition_map(struct volume_id *id, __u64 off)
1413 struct mac_driver_desc {
1417 } __attribute__((__packed__)) *driver;
1419 struct mac_partition {
1427 } __attribute__((__packed__)) *part;
1431 buf = get_buffer(id, off, 0x200);
1435 part = (struct mac_partition *) buf;
1436 if ((strncmp(part->signature, "PM", 2) == 0) &&
1437 (strncmp(part->type, "Apple_partition_map", 19) == 0)) {
1438 /* linux creates an own subdevice for the map
1439 * just return the type if the drive header is missing */
1440 id->usage_id = VOLUME_ID_PARTITIONTABLE;
1441 id->type_id = VOLUME_ID_MACPARTMAP;
1442 id->type = "mac_partition_map";
1446 driver = (struct mac_driver_desc *) buf;
1447 if (strncmp(driver->signature, "ER", 2) == 0) {
1448 /* we are on a main device, like a CD
1449 * just try to probe the first partition from the map */
1450 unsigned int bsize = be16_to_cpu(driver->block_size);
1454 /* get first entry of partition table */
1455 buf = get_buffer(id, off + bsize, 0x200);
1459 part = (struct mac_partition *) buf;
1460 if (strncmp(part->signature, "PM", 2) != 0)
1463 part_count = be32_to_cpu(part->map_count);
1464 dbg("expecting %d partition entries", part_count);
1466 if (id->partitions != NULL)
1467 free(id->partitions);
1469 malloc(part_count * sizeof(struct volume_id_partition));
1470 if (id->partitions == NULL)
1472 memset(id->partitions, 0x00, sizeof(struct volume_id_partition));
1474 id->partition_count = part_count;
1476 for (i = 0; i < part_count; i++) {
1480 buf = get_buffer(id, off + ((i+1) * bsize), 0x200);
1484 part = (struct mac_partition *) buf;
1485 if (strncmp(part->signature, "PM", 2) != 0)
1488 poff = be32_to_cpu(part->start_block) * bsize;
1489 plen = be32_to_cpu(part->block_count) * bsize;
1490 dbg("found '%s' partition entry at 0x%llx, len 0x%llx",
1491 part->type, poff, plen);
1493 id->partitions[i].off = poff;
1494 id->partitions[i].len = plen;
1496 if (strncmp(part->type, "Apple_Free", 10) == 0) {
1497 id->partitions[i].usage_id = VOLUME_ID_UNUSED;
1498 } else if (strncmp(part->type, "Apple_partition_map", 19) == 0) {
1499 id->partitions[i].usage_id = VOLUME_ID_PARTITIONTABLE;
1500 id->partitions[i].type_id = VOLUME_ID_MACPARTMAP;
1502 id->partitions[i].usage_id = VOLUME_ID_UNPROBED;
1505 id->usage_id = VOLUME_ID_PARTITIONTABLE;
1506 id->type_id = VOLUME_ID_MACPARTMAP;
1507 id->type = "mac_partition_map";
1514 #define HFS_SUPERBLOCK_OFFSET 0x400
1515 #define HFS_NODE_LEAF 0xff
1516 #define HFSPLUS_POR_CNID 1
1517 #define HFSPLUS_EXTENT_COUNT 8
1518 static int probe_hfs_hfsplus(struct volume_id *id, __u64 off)
1520 struct hfs_finder_info{
1528 } __attribute__((__packed__));
1549 __u32 xt_clump_size;
1550 __u32 ct_clump_size;
1551 __u16 num_root_dirs;
1554 struct hfs_finder_info finder_info;
1556 __u16 embed_startblock;
1557 __u16 embed_blockcount;
1558 } __attribute__((__packed__)) *hfs;
1560 struct hfsplus_bnode_descriptor {
1567 } __attribute__((__packed__));
1569 struct hfsplus_bheader_record {
1576 } __attribute__((__packed__));
1578 struct hfsplus_catalog_key {
1582 __u8 unicode[255 * 2];
1583 } __attribute__((__packed__));
1585 struct hfsplus_extent {
1588 } __attribute__((__packed__));
1590 struct hfsplus_fork {
1594 struct hfsplus_extent extents[HFSPLUS_EXTENT_COUNT];
1595 } __attribute__((__packed__));
1597 struct hfsplus_vol_header {
1601 __u32 last_mount_vers;
1613 __u32 rsrc_clump_sz;
1614 __u32 data_clump_sz;
1617 __u64 encodings_bmp;
1618 struct hfs_finder_info finder_info;
1619 struct hfsplus_fork alloc_file;
1620 struct hfsplus_fork ext_file;
1621 struct hfsplus_fork cat_file;
1622 struct hfsplus_fork attr_file;
1623 struct hfsplus_fork start_file;
1624 } __attribute__((__packed__)) *hfsplus;
1626 unsigned int blocksize;
1627 unsigned int cat_block;
1628 unsigned int ext_block_start;
1629 unsigned int ext_block_count;
1631 unsigned int leaf_node_head;
1632 unsigned int leaf_node_count;
1633 unsigned int leaf_node_size;
1634 unsigned int leaf_block;
1636 unsigned int alloc_block_size;
1637 unsigned int alloc_first_block;
1638 unsigned int embed_first_block;
1639 unsigned int record_count;
1640 struct hfsplus_bnode_descriptor *descr;
1641 struct hfsplus_bheader_record *bnode;
1642 struct hfsplus_catalog_key *key;
1643 unsigned int label_len;
1644 struct hfsplus_extent extents[HFSPLUS_EXTENT_COUNT];
1647 buf = get_buffer(id, off + HFS_SUPERBLOCK_OFFSET, 0x200);
1651 hfs = (struct hfs_mdb *) buf;
1652 if (strncmp(hfs->signature, "BD", 2) != 0)
1655 /* it may be just a hfs wrapper for hfs+ */
1656 if (strncmp(hfs->embed_sig, "H+", 2) == 0) {
1657 alloc_block_size = be32_to_cpu(hfs->al_blk_size);
1658 dbg("alloc_block_size 0x%x", alloc_block_size);
1660 alloc_first_block = be16_to_cpu(hfs->al_bl_st);
1661 dbg("alloc_first_block 0x%x", alloc_first_block);
1663 embed_first_block = be16_to_cpu(hfs->embed_startblock);
1664 dbg("embed_first_block 0x%x", embed_first_block);
1666 off += (alloc_first_block * 512) +
1667 (embed_first_block * alloc_block_size);
1668 dbg("hfs wrapped hfs+ found at offset 0x%llx", off);
1670 buf = get_buffer(id, off + HFS_SUPERBLOCK_OFFSET, 0x200);
1676 if (hfs->label_len > 0 && hfs->label_len < 28) {
1677 set_label_raw(id, hfs->label, hfs->label_len);
1678 set_label_string(id, hfs->label, hfs->label_len) ;
1681 set_uuid(id, hfs->finder_info.id, UUID_HFS);
1683 id->usage_id = VOLUME_ID_FILESYSTEM;
1684 id->type_id = VOLUME_ID_HFS;
1690 hfsplus = (struct hfsplus_vol_header *) buf;
1691 if (strncmp(hfsplus->signature, "H+", 2) == 0)
1693 if (strncmp(hfsplus->signature, "HX", 2) == 0)
1698 set_uuid(id, hfsplus->finder_info.id, UUID_HFS);
1700 blocksize = be32_to_cpu(hfsplus->blocksize);
1701 dbg("blocksize %u", blocksize);
1703 memcpy(extents, hfsplus->cat_file.extents, sizeof(extents));
1704 cat_block = be32_to_cpu(extents[0].start_block);
1705 dbg("catalog start block 0x%x", cat_block);
1707 buf = get_buffer(id, off + (cat_block * blocksize), 0x2000);
1711 bnode = (struct hfsplus_bheader_record *)
1712 &buf[sizeof(struct hfsplus_bnode_descriptor)];
1714 leaf_node_head = be32_to_cpu(bnode->leaf_head);
1715 dbg("catalog leaf node 0x%x", leaf_node_head);
1717 leaf_node_size = be16_to_cpu(bnode->node_size);
1718 dbg("leaf node size 0x%x", leaf_node_size);
1720 leaf_node_count = be32_to_cpu(bnode->leaf_count);
1721 dbg("leaf node count 0x%x", leaf_node_count);
1722 if (leaf_node_count == 0)
1725 leaf_block = (leaf_node_head * leaf_node_size) / blocksize;
1727 /* get physical location */
1728 for (ext = 0; ext < HFSPLUS_EXTENT_COUNT; ext++) {
1729 ext_block_start = be32_to_cpu(extents[ext].start_block);
1730 ext_block_count = be32_to_cpu(extents[ext].block_count);
1731 dbg("extent start block 0x%x, count 0x%x", ext_block_start, ext_block_count);
1733 if (ext_block_count == 0)
1736 /* this is our extent */
1737 if (leaf_block < ext_block_count)
1740 leaf_block -= ext_block_count;
1742 if (ext == HFSPLUS_EXTENT_COUNT)
1744 dbg("found block in extent %i", ext);
1746 leaf_off = (ext_block_start + leaf_block) * blocksize;
1748 buf = get_buffer(id, off + leaf_off, leaf_node_size);
1752 descr = (struct hfsplus_bnode_descriptor *) buf;
1753 dbg("descriptor type 0x%x", descr->type);
1755 record_count = be16_to_cpu(descr->num_recs);
1756 dbg("number of records %u", record_count);
1757 if (record_count == 0)
1760 if (descr->type != HFS_NODE_LEAF)
1763 key = (struct hfsplus_catalog_key *)
1764 &buf[sizeof(struct hfsplus_bnode_descriptor)];
1766 dbg("parent id 0x%x", be32_to_cpu(key->parent_id));
1767 if (be32_to_cpu(key->parent_id) != HFSPLUS_POR_CNID)
1770 label_len = be16_to_cpu(key->unicode_len) * 2;
1771 dbg("label unicode16 len %i", label_len);
1772 set_label_raw(id, key->unicode, label_len);
1773 set_label_unicode16(id, key->unicode, BE, label_len);
1776 id->usage_id = VOLUME_ID_FILESYSTEM;
1777 id->type_id = VOLUME_ID_HFSPLUS;
1778 id->type = "hfsplus";
1783 #define MFT_RECORD_VOLUME 3
1784 #define MFT_RECORD_ATTR_VOLUME_NAME 0x60
1785 #define MFT_RECORD_ATTR_VOLUME_INFO 0x70
1786 #define MFT_RECORD_ATTR_OBJECT_ID 0x40
1787 #define MFT_RECORD_ATTR_END 0xffffffffu
1788 static int probe_ntfs(struct volume_id *id, __u64 off)
1790 struct ntfs_super_block {
1793 __u16 bytes_per_sector;
1794 __u8 sectors_per_cluster;
1795 __u16 reserved_sectors;
1800 __u16 sectors_per_fat;
1801 __u16 sectors_per_track;
1803 __u32 hidden_sectors;
1804 __u32 large_sectors;
1806 __u64 number_of_sectors;
1807 __u64 mft_cluster_location;
1808 __u64 mft_mirror_cluster_location;
1809 __s8 cluster_per_mft_record;
1811 __s8 cluster_per_index_record;
1813 __u8 volume_serial[8];
1815 } __attribute__((__packed__)) *ns;
1817 struct master_file_table_record {
1822 __u16 sequence_number;
1827 __u32 bytes_allocated;
1828 } __attribute__((__packed__)) *mftr;
1830 struct file_attribute {
1840 } __attribute__((__packed__)) *attr;
1842 struct volume_info {
1846 } __attribute__((__packed__)) *info;
1848 unsigned int sector_size;
1849 unsigned int cluster_size;
1852 unsigned int mft_record_size;
1853 unsigned int attr_type;
1854 unsigned int attr_off;
1855 unsigned int attr_len;
1856 unsigned int val_off;
1857 unsigned int val_len;
1861 ns = (struct ntfs_super_block *) get_buffer(id, off, 0x200);
1865 if (strncmp(ns->oem_id, "NTFS", 4) != 0)
1868 set_uuid(id, ns->volume_serial, UUID_NTFS);
1870 sector_size = le16_to_cpu(ns->bytes_per_sector);
1871 cluster_size = ns->sectors_per_cluster * sector_size;
1872 mft_cluster = le64_to_cpu(ns->mft_cluster_location);
1873 mft_off = mft_cluster * cluster_size;
1875 if (ns->cluster_per_mft_record < 0)
1876 /* size = -log2(mft_record_size); normally 1024 Bytes */
1877 mft_record_size = 1 << -ns->cluster_per_mft_record;
1879 mft_record_size = ns->cluster_per_mft_record * cluster_size;
1881 dbg("sectorsize 0x%x", sector_size);
1882 dbg("clustersize 0x%x", cluster_size);
1883 dbg("mftcluster %lli", mft_cluster);
1884 dbg("mftoffset 0x%llx", mft_off);
1885 dbg("cluster per mft_record %i", ns->cluster_per_mft_record);
1886 dbg("mft record size %i", mft_record_size);
1888 buf = get_buffer(id, off + mft_off + (MFT_RECORD_VOLUME * mft_record_size),
1893 mftr = (struct master_file_table_record*) buf;
1895 dbg("mftr->magic '%c%c%c%c'", mftr->magic[0], mftr->magic[1], mftr->magic[2], mftr->magic[3]);
1896 if (strncmp(mftr->magic, "FILE", 4) != 0)
1899 attr_off = le16_to_cpu(mftr->attrs_offset);
1900 dbg("file $Volume's attributes are at offset %i", attr_off);
1903 attr = (struct file_attribute*) &buf[attr_off];
1904 attr_type = le32_to_cpu(attr->type);
1905 attr_len = le16_to_cpu(attr->len);
1906 val_off = le16_to_cpu(attr->value_offset);
1907 val_len = le32_to_cpu(attr->value_len);
1908 attr_off += attr_len;
1913 if (attr_off >= mft_record_size)
1916 if (attr_type == MFT_RECORD_ATTR_END)
1919 dbg("found attribute type 0x%x, len %i, at offset %i",
1920 attr_type, attr_len, attr_off);
1922 if (attr_type == MFT_RECORD_ATTR_VOLUME_INFO) {
1923 dbg("found info, len %i", val_len);
1924 info = (struct volume_info*) (((__u8 *) attr) + val_off);
1925 snprintf(id->type_version, VOLUME_ID_FORMAT_SIZE-1,
1926 "%u.%u", info->major_ver, info->minor_ver);
1929 if (attr_type == MFT_RECORD_ATTR_VOLUME_NAME) {
1930 dbg("found label, len %i", val_len);
1931 if (val_len > VOLUME_ID_LABEL_SIZE)
1932 val_len = VOLUME_ID_LABEL_SIZE;
1934 val = ((__u8 *) attr) + val_off;
1935 set_label_raw(id, val, val_len);
1936 set_label_unicode16(id, val, LE, val_len);
1941 id->usage_id = VOLUME_ID_FILESYSTEM;
1942 id->type_id = VOLUME_ID_NTFS;
1948 #define LARGEST_PAGESIZE 0x4000
1949 static int probe_swap(struct volume_id *id, __u64 off)
1954 /* huhh, the swap signature is on the end of the PAGE_SIZE */
1955 for (page = 0x1000; page <= LARGEST_PAGESIZE; page <<= 1) {
1956 sig = get_buffer(id, off + page-10, 10);
1960 if (strncmp(sig, "SWAP-SPACE", 10) == 0) {
1961 strcpy(id->type_version, "1");
1964 if (strncmp(sig, "SWAPSPACE2", 10) == 0) {
1965 strcpy(id->type_version, "2");
1972 id->usage_id = VOLUME_ID_OTHER;
1973 id->type_id = VOLUME_ID_SWAP;
1979 /* probe volume for filesystem type and try to read label+uuid */
1980 int volume_id_probe(struct volume_id *id,
1981 enum volume_id_type type,
1982 unsigned long long off,
1983 unsigned long long size)
1991 case VOLUME_ID_MSDOSPARTTABLE:
1992 rc = probe_msdos_part_table(id, off);
1994 case VOLUME_ID_EXT3:
1995 case VOLUME_ID_EXT2:
1996 rc = probe_ext(id, off);
1998 case VOLUME_ID_REISERFS:
1999 rc = probe_reiserfs(id, off);
2002 rc = probe_xfs(id, off);
2005 rc = probe_jfs(id, off);
2007 case VOLUME_ID_VFAT:
2008 rc = probe_vfat(id, off);
2011 rc = probe_udf(id, off);
2013 case VOLUME_ID_ISO9660:
2014 rc = probe_iso9660(id, off);
2016 case VOLUME_ID_MACPARTMAP:
2017 rc = probe_mac_partition_map(id, off);
2020 case VOLUME_ID_HFSPLUS:
2021 rc = probe_hfs_hfsplus(id, off);
2024 rc = probe_ufs(id, off);
2026 case VOLUME_ID_NTFS:
2027 rc = probe_ntfs(id, off);
2029 case VOLUME_ID_SWAP:
2030 rc = probe_swap(id, off);
2032 case VOLUME_ID_LINUX_RAID:
2033 rc = probe_linux_raid(id, off, size);
2035 case VOLUME_ID_LVM1:
2036 rc = probe_lvm1(id, off);
2038 case VOLUME_ID_LVM2:
2039 rc = probe_lvm2(id, off);
2043 /* probe for raid first, cause fs probes may be successful on raid members */
2044 rc = probe_linux_raid(id, off, size);
2047 rc = probe_lvm1(id, off);
2050 rc = probe_lvm2(id, off);
2054 /* signature in the first block, only small buffer needed */
2055 rc = probe_msdos_part_table(id, off);
2058 rc = probe_ntfs(id, off);
2061 rc = probe_vfat(id, off);
2064 rc = probe_mac_partition_map(id, off);
2067 rc = probe_xfs(id, off);
2071 /* fill buffer with maximum */
2072 get_buffer(id, 0, SB_BUFFER_SIZE);
2074 rc = probe_swap(id, off);
2077 rc = probe_ext(id, off);
2080 rc = probe_reiserfs(id, off);
2083 rc = probe_jfs(id, off);
2086 rc = probe_udf(id, off);
2089 rc = probe_iso9660(id, off);
2092 rc = probe_hfs_hfsplus(id, off);
2095 rc = probe_ufs(id, off);
2102 /* If the filestystem in recognized, we free the allocated buffers,
2103 otherwise they will stay in place for the possible next probe call */
2110 /* open volume by already open file descriptor */
2111 struct volume_id *volume_id_open_fd(int fd)
2113 struct volume_id *id;
2115 id = malloc(sizeof(struct volume_id));
2118 memset(id, 0x00, sizeof(struct volume_id));
2125 /* open volume by device node */
2126 struct volume_id *volume_id_open_node(const char *path)
2128 struct volume_id *id;
2131 fd = open(path, O_RDONLY);
2133 dbg("unable to open '%s'", path);
2137 id = volume_id_open_fd(fd);
2141 /* close fd on device close */
2147 /* open volume by major/minor */
2148 struct volume_id *volume_id_open_dev_t(dev_t devt)
2150 struct volume_id *id;
2151 __u8 tmp_node[VOLUME_ID_PATH_MAX];
2153 snprintf(tmp_node, VOLUME_ID_PATH_MAX,
2154 "/tmp/volume-%u-%u-%u", getpid(), major(devt), minor(devt));
2155 tmp_node[VOLUME_ID_PATH_MAX] = '\0';
2157 /* create tempory node to open the block device */
2159 if (mknod(tmp_node, (S_IFBLK | 0600), devt) != 0)
2162 id = volume_id_open_node(tmp_node);
2169 /* free allocated volume info */
2170 void volume_id_close(struct volume_id *id)
2175 if (id->fd_close != 0)
2180 if (id->partitions != NULL)
2181 free(id->partitions);