int FAST_FUNC volume_id_probe_btrfs(struct volume_id *id /*,uint64_t off*/) { // btrfs has superblocks at 64K, 64M and 256G // minimum btrfs size is 256M // so we never step out the device if we analyze // the first and the second superblocks struct btrfs_super_block *sb; unsigned off = 64; while (off < 64*1024*1024) { off *= 1024; dbg("btrfs: probing at offset 0x%x", off); sb = volume_id_get_buffer(id, off, sizeof(*sb)); if (sb == NULL) return -1; if (memcmp(sb->magic, BTRFS_MAGIC, 8) != 0) return -1; } // N.B.: btrfs natively supports 256 (>VOLUME_ID_LABEL_SIZE) size labels volume_id_set_label_string(id, sb->label, VOLUME_ID_LABEL_SIZE); volume_id_set_uuid(id, sb->fsid, UUID_DCE); return 0; }
int FAST_FUNC volume_id_probe_via_raid(struct volume_id *id, uint64_t off, uint64_t size) { uint64_t meta_off; struct via_meta *via; dbg("probing at offset 0x%llx, size 0x%llx", (unsigned long long) off, (unsigned long long) size); if (size < 0x10000) return -1; meta_off = ((size / 0x200)-1) * 0x200; via = volume_id_get_buffer(id, off + meta_off, 0x200); if (via == NULL) return -1; if (via->signature != cpu_to_le16(VIA_SIGNATURE)) return -1; if (via->version_number > 1) return -1; // volume_id_set_usage(id, VOLUME_ID_RAID); // id->type_version[0] = '0' + via->version_number; // id->type_version[1] = '\0'; // id->type = "via_raid_member"; return 0; }
int FAST_FUNC volume_id_probe_lvm2(struct volume_id *id, uint64_t off) { const uint8_t *buf; unsigned soff; struct lvm2_super_block *lvm; dbg("probing at offset 0x%llx", (unsigned long long) off); buf = volume_id_get_buffer(id, off, LVM2LABEL_SCAN_SECTORS * 0x200); if (buf == NULL) return -1; for (soff = 0; soff < LVM2LABEL_SCAN_SECTORS * 0x200; soff += 0x200) { lvm = (struct lvm2_super_block *) &buf[soff]; if (memcmp(lvm->id, LVM2_LABEL_ID, 8) == 0) goto found; } return -1; found: // memcpy(id->type_version, lvm->type, 8); // volume_id_set_usage(id, VOLUME_ID_RAID); // id->type = "LVM2_member"; return 0; }
static int volume_id_probe_linux_raid1(struct volume_id *id, uint64_t off, uint64_t size) { const uint8_t *buf; struct mdp1_super_block *mdp1; info("probing at offset 0x%" PRIx64 ", size 0x%" PRIx64 "\n", off, size); buf = volume_id_get_buffer(id, off, 0x800); if (buf == NULL) return -1; mdp1 = (struct mdp1_super_block *) buf; if (le32_to_cpu(mdp1->magic) != MD_SB_MAGIC) return -1; if (le32_to_cpu(mdp1->major_version) != 1) return -1; volume_id_set_uuid(id, mdp1->set_uuid, 0, UUID_MD); volume_id_set_label_raw(id, mdp1->set_name, 32); volume_id_set_label_string(id, mdp1->set_name, 32); volume_id_set_usage(id, VOLUME_ID_RAID); id->type = "linux_raid_member"; return 0; }
int volume_id_probe_lvm2(struct volume_id *id, uint64_t off, uint64_t size) { const uint8_t *buf; unsigned int soff; struct lvm2_super_block *lvm; struct lvm2_pv_header *pvhdr; dbg("probing at offset 0x%" PRIx64 "\n", off); buf = volume_id_get_buffer(id, off, LVM2LABEL_SCAN_SECTORS * 0x200); if (buf == NULL) return -1; for (soff = 0; soff < LVM2LABEL_SCAN_SECTORS * 0x200; soff += 0x200) { lvm = (struct lvm2_super_block *) &buf[soff]; if (memcmp(lvm->id, LVM2_LABEL_ID, 8) == 0) goto found; } return -1; found: dbg("found at offset 0x%x (pv hdr offset 0x%x)\n", soff, cpu_to_le32(lvm->offset_xl)); soff += cpu_to_le32(lvm->offset_xl); pvhdr = (struct lvm2_pv_header *) &buf[soff]; memcpy(id->type_version, lvm->type, 8); volume_id_set_usage(id, VOLUME_ID_RAID); volume_id_set_uuid(id, pvhdr->id, 0, UUID_LVM); id->type = "LVM2_member"; return 0; }
int volume_id_probe_intel_software_raid(struct volume_id *id, uint64_t off, uint64_t size) { const uint8_t *buf; uint64_t meta_off; struct isw_meta *isw; info("probing at offset 0x%llx, size 0x%llx", (unsigned long long) off, (unsigned long long) size); if (size < 0x10000) return -1; meta_off = ((size / 0x200)-2) * 0x200; buf = volume_id_get_buffer(id, off + meta_off, 0x200); if (buf == NULL) return -1; isw = (struct isw_meta *) buf; if (memcmp(isw->sig, ISW_SIGNATURE, sizeof(ISW_SIGNATURE)-1) != 0) return -1; volume_id_set_usage(id, VOLUME_ID_RAID); memcpy(id->type_version, &isw->sig[sizeof(ISW_SIGNATURE)-1], 6); id->type = "isw_raid_member"; return 0; }
/* Put the label in *label and uuid in *uuid. * Return 0 if no label/uuid found, NZ if there is a label or uuid. */ int find_label_or_uuid(char *dev_name, char *label, char *uuid) { struct volume_id id; memset(&id, 0x00, sizeof(id)); if (label) *label = 0; if (uuid) *uuid = 0; if ((id.fd = open(dev_name, O_RDONLY)) < 0) return 0; volume_id_get_buffer(&id, 0, SB_BUFFER_SIZE); if (volume_id_probe_linux_swap(&id) == 0 || id.error) goto ret; if (volume_id_probe_vfat(&id) == 0 || id.error) goto ret; if (volume_id_probe_ext(&id) == 0 || id.error) goto ret; if (volume_id_probe_ntfs(&id) == 0 || id.error) goto ret; #if defined(RTCONFIG_HFS) if(volume_id_probe_hfs_hfsplus(&id) == 0 || id.error) goto ret; #endif ret: volume_id_free_buffer(&id); if (label && (*id.label != 0)) strcpy(label, id.label); if (uuid && (*id.uuid != 0)) strcpy(uuid, id.uuid); close(id.fd); return (label && *label != 0) || (uuid && *uuid != 0); }
int volume_id_probe_squashfs(struct volume_id *id, uint64_t off, uint64_t size) { struct squashfs_super *sqs; info("probing at offset 0x%" PRIx64 "\n", off); sqs = (struct squashfs_super *) volume_id_get_buffer(id, off, 0x200); if (sqs == NULL) return -1; if (sqs->s_magic == SQUASHFS_MAGIC || sqs->s_magic == SQUASHFS_MAGIC_LZMA) { snprintf(id->type_version, sizeof(id->type_version), "%u.%u", sqs->s_major, sqs->s_minor); goto found; } if (sqs->s_magic == bswap_32(SQUASHFS_MAGIC) || sqs->s_magic == bswap_32(SQUASHFS_MAGIC_LZMA)) { snprintf(id->type_version, sizeof(id->type_version), "%u.%u", bswap_16(sqs->s_major), bswap_16(sqs->s_minor)); goto found; } return -1; found: volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); id->type = "squashfs"; return 0; }
int FAST_FUNC volume_id_probe_silicon_medley_raid(struct volume_id *id, uint64_t off, uint64_t size) { uint64_t meta_off; struct silicon_meta *sil; dbg("probing at offset 0x%llx, size 0x%llx", (unsigned long long) off, (unsigned long long) size); if (size < 0x10000) return -1; meta_off = ((size / 0x200)-1) * 0x200; sil = volume_id_get_buffer(id, off + meta_off, 0x200); if (sil == NULL) return -1; if (sil->magic != cpu_to_le32(SILICON_MAGIC)) return -1; // volume_id_set_usage(id, VOLUME_ID_RAID); // snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u", // le16_to_cpu(sil->major_ver), le16_to_cpu(sil->minor_ver)); // id->type = "silicon_medley_raid_member"; return 0; }
int volume_id_probe_highpoint_45x_raid(struct volume_id *id, uint64_t off, uint64_t size) { const uint8_t *buf; struct hpt45x_meta *hpt; uint64_t meta_off; uint32_t magic; dbg("probing at offset 0x%" PRIx64 ", size 0x%" PRIx64 "\n", off, size); if (size < 0x10000) return -1; meta_off = ((size / 0x200)-11) * 0x200; buf = volume_id_get_buffer(id, off + meta_off, 0x200); if (buf == NULL) return -1; hpt = (struct hpt45x_meta *) buf; magic = le32_to_cpu(hpt->magic); if (magic != HPT45X_MAGIC_OK && magic != HPT45X_MAGIC_BAD) return -1; volume_id_set_usage(id, VOLUME_ID_RAID); id->type = "highpoint_raid_member"; return 0; }
int find_partition_label(const char *dev_name, char *label){ struct volume_id id; char dev_path[128]; memset(dev_path, 0, 128); sprintf(dev_path, "/dev/%s", dev_name); memset(&id, 0x00, sizeof(id)); if((id.fd = open(dev_path, O_RDONLY)) < 0) return 0; if(label) *label = 0; volume_id_get_buffer(&id, 0, SB_BUFFER_SIZE); if(volume_id_probe_linux_swap(&id) == 0 || id.error) goto ret; if(volume_id_probe_ext(&id) == 0 || id.error) goto ret; if(volume_id_probe_vfat(&id) == 0 || id.error) goto ret; if(volume_id_probe_ntfs(&id) == 0 || id.error) goto ret; ret: volume_id_free_buffer(&id); if(label && (*id.label != 0)) strcpy(label, id.label); close(id.fd); return (label && *label != 0); }
int FAST_FUNC volume_id_probe_f2fs(struct volume_id *id /*,uint64_t off*/) { struct f2fs_super_block *sb; // Go for primary super block (ignore second sb) dbg("f2fs: probing at offset 0x%x", F2FS_SB1_OFFSET); sb = volume_id_get_buffer(id, F2FS_SB1_OFFSET, sizeof(*sb)); if (!sb) return -1; if (sb->magic != cpu_to_le32(F2FS_MAGIC)) return -1; IF_FEATURE_BLKID_TYPE(id->type = "f2fs"); // For version 1.0 we don't know sb structure and can't set label/uuid if (sb->major_ver == cpu_to_le16(1) && sb->minor_ver == cpu_to_le16(0)) return 0; volume_id_set_label_unicode16(id, (uint8_t *)sb->volume_name, LE, MIN(F2FS_LABEL_BYTES, VOLUME_ID_LABEL_SIZE)); volume_id_set_uuid(id, sb->uuid, UUID_DCE); return 0; }
int volume_id_probe_nvidia_raid(struct volume_id *id, uint64_t off, uint64_t size) { uint64_t meta_off; struct nvidia_meta *nv; dbg("probing at offset 0x%llx, size 0x%llx", (unsigned long long) off, (unsigned long long) size); if (size < 0x10000) return -1; meta_off = ((size / 0x200)-2) * 0x200; nv = volume_id_get_buffer(id, off + meta_off, 0x200); if (nv == NULL) return -1; if (memcmp(nv->vendor, NVIDIA_SIGNATURE, sizeof(NVIDIA_SIGNATURE)-1) != 0) return -1; // volume_id_set_usage(id, VOLUME_ID_RAID); // snprintf(id->type_version, sizeof(id->type_version)-1, "%u", le16_to_cpu(nv->version)); // id->type = "nvidia_raid_member"; return 0; }
int FAST_FUNC volume_id_probe_nilfs(struct volume_id *id /*,uint64_t off*/) { struct nilfs2_super_block *sb; // Primary super block dbg("nilfs: probing at offset 0x%x", NILFS_SB1_OFFSET); sb = volume_id_get_buffer(id, NILFS_SB1_OFFSET, sizeof(*sb)); if (sb == NULL) return -1; if (sb->s_magic != NILFS_MAGIC) return -1; // The secondary superblock is not always used, so ignore it for now. // When used it is at 4K from the end of the partition (sb->s_dev_size - NILFS_SB2_OFFSET). volume_id_set_label_string(id, sb->s_volume_name, NILFS_LABEL_SIZE < VOLUME_ID_LABEL_SIZE ? NILFS_LABEL_SIZE : VOLUME_ID_LABEL_SIZE); volume_id_set_uuid(id, sb->s_uuid, UUID_DCE); if (sb->s_rev_level == 2) IF_FEATURE_BLKID_TYPE(id->type = "nilfs2"); return 0; }
int volume_id_probe_ext(struct volume_id *id, uint64_t off) { struct ext2_super_block *es; dbg("ext: probing at offset 0x%llx", (unsigned long long) off); es = volume_id_get_buffer(id, off + EXT_SUPERBLOCK_OFFSET, 0x200); if (es == NULL) return -1; if (es->magic[0] != 0123 || es->magic[1] != 0357) { dbg("ext: no magic found"); return -1; } // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); // volume_id_set_label_raw(id, es->volume_name, 16); volume_id_set_label_string(id, es->volume_name, 16); volume_id_set_uuid(id, es->uuid, UUID_DCE); dbg("ext: label '%s' uuid '%s'", id->label, id->uuid); // if ((le32_to_cpu(es->feature_compat) & EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0) // id->type = "ext3"; // else // id->type = "ext2"; return 0; }
int FAST_FUNC volume_id_probe_romfs(struct volume_id *id /*,uint64_t off*/) { #define off ((uint64_t)0) struct romfs_super *rfs; dbg("probing at offset 0x%llx", (unsigned long long) off); rfs = volume_id_get_buffer(id, off, 0x200); if (rfs == NULL) return -1; if (memcmp(rfs->magic, "-rom1fs-", 4) == 0) { size_t len = strlen((char *)rfs->name); if (len) { // volume_id_set_label_raw(id, rfs->name, len); volume_id_set_label_string(id, rfs->name, len); } // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); id->type = "romfs"; return 0; } return -1; }
int FAST_FUNC volume_id_probe_linux_swap(struct volume_id *id /*,uint64_t off*/) { #define off ((uint64_t)0) struct swap_header_v1_2 *sw; const uint8_t *buf; unsigned page; dbg("probing at offset 0x%llx", (unsigned long long) off); /* the swap signature is at the end of the PAGE_SIZE */ for (page = 0x1000; page <= LARGEST_PAGESIZE; page <<= 1) { buf = volume_id_get_buffer(id, off + page-10, 10); if (buf == NULL) return -1; if (memcmp(buf, "SWAP-SPACE", 10) == 0) { // id->type_version[0] = '1'; // id->type_version[1] = '\0'; goto found; } if (memcmp(buf, "SWAPSPACE2", 10) == 0 || memcmp(buf, "S1SUSPEND", 9) == 0 || memcmp(buf, "S2SUSPEND", 9) == 0 || memcmp(buf, "ULSUSPEND", 9) == 0 ) { sw = volume_id_get_buffer(id, off, sizeof(struct swap_header_v1_2)); if (sw == NULL) return -1; // id->type_version[0] = '2'; // id->type_version[1] = '\0'; // volume_id_set_label_raw(id, sw->volume_name, 16); volume_id_set_label_string(id, sw->volume_name, 16); volume_id_set_uuid(id, sw->uuid, UUID_DCE); goto found; } } return -1; found: // volume_id_set_usage(id, VOLUME_ID_OTHER); // id->type = "swap"; return 0; }
static int volume_id_probe_linux_raid0(struct volume_id *id, uint64_t off, uint64_t size) { const uint8_t *buf; struct mdp0_super_block *mdp0; union { uint32_t ints[4]; uint8_t bytes[16]; } uuid; info("probing at offset 0x%" PRIx64 ", size 0x%" PRIx64 "\n", off, size); if (size < 0x10000) return -1; buf = volume_id_get_buffer(id, off, 0x800); if (buf == NULL) return -1; mdp0 = (struct mdp0_super_block *) buf; if (le32_to_cpu(mdp0->md_magic) == MD_SB_MAGIC) { uuid.ints[0] = bswap_32(mdp0->set_uuid0); if (le32_to_cpu(mdp0->minor_version >= 90)) { uuid.ints[1] = bswap_32(mdp0->set_uuid1); uuid.ints[2] = bswap_32(mdp0->set_uuid2); uuid.ints[3] = bswap_32(mdp0->set_uuid3); } else { uuid.ints[1] = 0; uuid.ints[2] = 0; uuid.ints[3] = 0; } volume_id_set_uuid(id, uuid.bytes, 0, UUID_MD); snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u.%u", le32_to_cpu(mdp0->major_version), le32_to_cpu(mdp0->minor_version), le32_to_cpu(mdp0->patch_version)); } else if (be32_to_cpu(mdp0->md_magic) == MD_SB_MAGIC) { uuid.ints[0] = mdp0->set_uuid0; if (be32_to_cpu(mdp0->minor_version >= 90)) { uuid.ints[1] = mdp0->set_uuid1; uuid.ints[2] = mdp0->set_uuid2; uuid.ints[3] = mdp0->set_uuid3; } else { uuid.ints[1] = 0; uuid.ints[2] = 0; uuid.ints[3] = 0; } volume_id_set_uuid(id, uuid.bytes, 0, UUID_MD); snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u.%u", be32_to_cpu(mdp0->major_version), be32_to_cpu(mdp0->minor_version), be32_to_cpu(mdp0->patch_version)); } else return -1; volume_id_set_usage(id, VOLUME_ID_RAID); id->type = "linux_raid_member"; return 0; }
int volume_id_probe_sysv(struct volume_id *id, uint64_t off, uint64_t size) { struct sysv_super *vs; struct xenix_super *xs; unsigned int boff; info("probing at offset 0x%llx", (unsigned long long) off); for (boff = 0x200; boff <= SYSV_MAX_BLOCKSIZE; boff <<= 1) { vs = (struct sysv_super *) volume_id_get_buffer(id, off + (boff * SYSV_SUPERBLOCK_BLOCK), 0x200); if (vs == NULL) return -1; if (vs->s_magic == cpu_to_le32(SYSV_MAGIC) || vs->s_magic == cpu_to_be32(SYSV_MAGIC)) { volume_id_set_label_raw(id, vs->s_fname, 6); volume_id_set_label_string(id, vs->s_fname, 6); id->type = "sysv"; goto found; } } for (boff = 0x200; boff <= SYSV_MAX_BLOCKSIZE; boff <<= 1) { xs = (struct xenix_super *) volume_id_get_buffer(id, off + (boff + XENIX_SUPERBLOCK_BLOCK), 0x200); if (xs == NULL) return -1; if (xs->s_magic == cpu_to_le32(XENIX_MAGIC) || xs->s_magic == cpu_to_be32(XENIX_MAGIC)) { volume_id_set_label_raw(id, xs->s_fname, 6); volume_id_set_label_string(id, xs->s_fname, 6); id->type = "xenix"; goto found; } } return -1; found: volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); return 0; }
int find_partition_label(const char *dev_name, char *label, int partition_order) { struct volume_id id; char dev_path[128]; char usb_port[8]; int port_num; char nvram_label[32], nvram_value[512]; if(label) *label = 0; memset(usb_port, 0, 8); if(get_usb_port_by_device(dev_name, usb_port, 8) == NULL) return 0; port_num = get_usb_port_number(usb_port); memset(nvram_label, 0, 32); sprintf(nvram_label, "usb_path%d_label%d", port_num, partition_order); memset(nvram_value, 0, 512); strncpy(nvram_value, nvram_safe_get(nvram_label), 512); if(strlen(nvram_value) > 0) { strcpy(label, nvram_value); return (label && *label != 0); } memset(dev_path, 0, 128); sprintf(dev_path, "/dev/%s", dev_name); memset(&id, 0x00, sizeof(id)); if((id.fd = open(dev_path, O_RDONLY)) < 0) return 0; volume_id_get_buffer(&id, 0, SB_BUFFER_SIZE); if(volume_id_probe_linux_swap(&id) == 0 || id.error) goto ret; if(volume_id_probe_ext(&id) == 0 || id.error) goto ret; if(volume_id_probe_vfat(&id) == 0 || id.error) goto ret; if(volume_id_probe_ntfs(&id) == 0 || id.error) goto ret; if(volume_id_probe_hfs_hfsplus(&id) == 0 || id.error) goto ret; ret: volume_id_free_buffer(&id); if(label && (*id.label != 0)) strcpy(label, id.label); else strcpy(label, " "); nvram_set(nvram_label, label); close(id.fd); return (label && *label != 0); }
int volume_id_probe_hpfs(struct volume_id *id, uint64_t off, uint64_t size) { struct hpfs_super *hs; struct hpfs_spare_super *hss; struct hpfs_boot_block *hbb; uint8_t version; info("probing at offset 0x%" PRIx64 "\n", off); hs = (struct hpfs_super *) volume_id_get_buffer(id, off + HPFS_SUPERBLOCK_OFFSET, 0x400); if (hs == NULL) return -1; if (memcmp(hs->magic, "\x49\xe8\x95\xf9", 4) != 0) return -1; hss = (struct hpfs_spare_super *) volume_id_get_buffer(id, off + HPFS_SUPERBLOCK_SPARE_OFFSET, 0x200); if (hss == NULL) return -1; if (memcmp(hss->magic, "\x49\x18\x91\xf9", 4) != 0) return -1; version = hs->version; /* if boot block looks valid, read label and uuid from there */ hbb = (struct hpfs_boot_block *) volume_id_get_buffer(id, off, 0x200); if (hbb == NULL) return -1; if (memcmp(hbb->magic, "\x55\xaa", 2) == 0 && memcmp(hbb->sig_hpfs, "HPFS", 4) == 0 && hbb->sig_28h == 0x28) { volume_id_set_label_raw(id, hbb->vol_label, 11); volume_id_set_label_string(id, hbb->vol_label, 11); volume_id_set_uuid(id, hbb->vol_serno, 0, UUID_DOS); } sprintf(id->type_version, "%u", version); volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); id->type = "hpfs"; return 0; }
int volume_id_probe_ufs(struct volume_id *id, uint64_t off, uint64_t size) { uint32_t magic; int i; struct ufs_super_block *ufs; int offsets[] = {0, 8, 64, 256, -1}; info("probing at offset 0x%" PRIx64 "\n", off); for (i = 0; offsets[i] >= 0; i++) { ufs = (struct ufs_super_block *) volume_id_get_buffer(id, off + (offsets[i] * 0x400), 0x800); if (ufs == NULL) return -1; dbg("offset 0x%x\n", offsets[i] * 0x400); magic = be32_to_cpu(ufs->fs_magic); if ((magic == UFS_MAGIC) || (magic == UFS2_MAGIC) || (magic == UFS_MAGIC_FEA) || (magic == UFS_MAGIC_LFN)) { dbg("magic 0x%08x(be)\n", magic); goto found; } magic = le32_to_cpu(ufs->fs_magic); if ((magic == UFS_MAGIC) || (magic == UFS2_MAGIC) || (magic == UFS_MAGIC_FEA) || (magic == UFS_MAGIC_LFN)) { dbg("magic 0x%08x(le)\n", magic); goto found; } } return -1; found: volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); id->type = "ufs"; switch (magic) { case UFS_MAGIC: strcpy(id->type_version, "1"); break; case UFS2_MAGIC: strcpy(id->type_version, "2"); volume_id_set_label_raw(id, ufs->fs_u11.fs_u2.fs_volname, 32); volume_id_set_label_string(id, ufs->fs_u11.fs_u2.fs_volname, 32); break; default: break; } return 0; }
int volume_id_probe_minix(struct volume_id *id, uint64_t off, uint64_t size) { uint8_t *buf; struct minix_super_block *ms; struct minix3_super_block *m3s; info("probing at offset 0x%" PRIx64 "\n", off); buf = volume_id_get_buffer(id, off + MINIX_SUPERBLOCK_OFFSET, 0x200); if (buf == NULL) return -1; ms = (struct minix_super_block *) buf; if (ms->s_magic == MINIX_SUPER_MAGIC || ms->s_magic == bswap_16(MINIX_SUPER_MAGIC)) { strcpy(id->type_version, "1"); goto found; } if (ms->s_magic == MINIX_SUPER_MAGIC2 || ms->s_magic == bswap_16(MINIX_SUPER_MAGIC2)) { strcpy(id->type_version, "1"); goto found; } if (ms->s_magic == MINIX2_SUPER_MAGIC || ms->s_magic == bswap_16(MINIX2_SUPER_MAGIC)) { strcpy(id->type_version, "2"); goto found; } if (ms->s_magic == MINIX2_SUPER_MAGIC2 || ms->s_magic == bswap_16(MINIX2_SUPER_MAGIC2)) { strcpy(id->type_version, "2"); goto found; } m3s = (struct minix3_super_block *) buf; if (m3s->s_magic == MINIX3_SUPER_MAGIC || m3s->s_magic == bswap_16(MINIX3_SUPER_MAGIC)) { strcpy(id->type_version, "3"); goto found; } goto exit; found: volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); id->type = "minix"; return 0; exit: return -1; }
int FAST_FUNC volume_id_probe_all(struct volume_id *id, /*uint64_t off,*/ uint64_t size) { unsigned i, arsize; /* probe for raid first, cause fs probes may be successful on raid members */ if (size) { arsize=ARRAY_SIZE(raid1); for (i = 0; i < arsize; i++) { if (raid1[i](id, /*off,*/ size) == 0) goto ret; if (id->error) goto ret; } } arsize=ARRAY_SIZE(raid2); for (i = 0; i < arsize; i++) { if (raid2[i](id /*,off*/) == 0) goto ret; if (id->error) goto ret; } /* signature in the first block, only small buffer needed */ arsize=ARRAY_SIZE(fs1); for (i = 0; i < arsize; i++) { if (fs1[i](id /*,off*/) == 0) goto ret; if (id->error) goto ret; } /* fill buffer with maximum */ volume_id_get_buffer(id, 0, SB_BUFFER_SIZE); arsize=ARRAY_SIZE(fs2); for (i = 0; i < arsize; i++) { if (fs2[i](id /*,off*/) == 0) break; if (id->error) break; } volume_id_free_buffer(id); ret: return (- id->error); /* 0 or -1 */ }
int volume_id_probe_luks(struct volume_id *id, uint64_t off, uint64_t size) { struct luks_phdr *header; header = (struct luks_phdr*) volume_id_get_buffer(id, off, LUKS_PHDR_SIZE); if (header == NULL) return -1; if (memcmp(header->magic, LUKS_MAGIC, LUKS_MAGIC_L)) return -1; volume_id_set_usage(id, VOLUME_ID_CRYPTO); volume_id_set_uuid(id, header->uuid, 36, UUID_HEX_STRING); id->type = "crypto_LUKS"; return 0; }
int FAST_FUNC volume_id_probe_luks(struct volume_id *id /*,uint64_t off*/) { #define off ((uint64_t)0) struct luks_phdr *header; header = volume_id_get_buffer(id, off, sizeof(*header)); if (header == NULL) return -1; if (memcmp(header->magic, LUKS_MAGIC, LUKS_MAGIC_L)) return -1; // volume_id_set_usage(id, VOLUME_ID_CRYPTO); volume_id_set_uuid(id, header->uuid, UUID_DCE_STRING); id->type = "crypto_LUKS"; return 0; }
int FAST_FUNC volume_id_probe_lvm1(struct volume_id *id, uint64_t off) { struct lvm1_super_block *lvm; dbg("probing at offset 0x%llx", (unsigned long long) off); lvm = volume_id_get_buffer(id, off + LVM1_SB_OFF, 0x800); if (lvm == NULL) return -1; if (lvm->id[0] != 'H' || lvm->id[1] != 'M') return -1; // volume_id_set_usage(id, VOLUME_ID_RAID); // id->type = "LVM1_member"; return 0; }
int FAST_FUNC volume_id_probe_hpfs(struct volume_id *id, uint64_t off) { struct hpfs_super *hs; dbg("probing at offset 0x%llx", (unsigned long long) off); hs = volume_id_get_buffer(id, off + HPFS_SUPERBLOCK_OFFSET, 0x200); if (hs == NULL) return -1; if (memcmp(hs->magic, "\x49\xe8\x95\xf9", 4) == 0) { // sprintf(id->type_version, "%u", hs->version); // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); // id->type = "hpfs"; return 0; } return -1; }
int volume_id_probe_ext(struct volume_id *id, uint64_t off, uint64_t size) { struct ext2_super_block *es; size_t bsize; info("probing at offset 0x%llx", (unsigned long long) off); es = (struct ext2_super_block *) volume_id_get_buffer(id, off + EXT_SUPERBLOCK_OFFSET, 0x200); if (es == NULL) return -1; if (es->s_magic != cpu_to_le16(EXT_SUPER_MAGIC)) return -1; bsize = 0x400 << le32_to_cpu(es->s_log_block_size); dbg("ext blocksize 0x%zx", bsize); if (bsize < EXT3_MIN_BLOCK_SIZE || bsize > EXT3_MAX_BLOCK_SIZE) { dbg("invalid ext blocksize"); return -1; } volume_id_set_label_raw(id, es->s_volume_name, 16); volume_id_set_label_string(id, es->s_volume_name, 16); volume_id_set_uuid(id, es->s_uuid, 0, UUID_DCE); snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u", le32_to_cpu(es->s_rev_level), le16_to_cpu(es->s_minor_rev_level)); /* check for external journal device */ if ((le32_to_cpu(es->s_feature_incompat) & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) != 0) { volume_id_set_usage(id, VOLUME_ID_OTHER); id->type = "jbd"; return 0; } /* check for ext2 / ext3 */ volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); if ((le32_to_cpu(es->s_feature_compat) & EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0) id->type = "ext3"; else id->type = "ext2"; return 0; }
int volume_id_probe_btrfs(struct volume_id *id, uint64_t off, uint64_t size) { const uint8_t *buf; struct btrfs_super_block *bfs; info("probing at offset 0x%" PRIx64 ", size 0x%" PRIx64 "\n", off, size); buf = volume_id_get_buffer(id, off + 0x10000, 0x200); if (buf == NULL) return -1; bfs = (struct btrfs_super_block *)buf; if (memcmp(bfs->magic, "_BHRfS_M", 8) != 0) return -1; volume_id_set_uuid(id, bfs->fsid, 0, UUID_DCE); volume_id_set_uuid_sub(id, bfs->dev_item.uuid, 0, UUID_DCE); volume_id_set_label_raw(id, bfs->label, 256); volume_id_set_label_string(id, bfs->label, 256); volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); id->type = "btrfs"; return 0; }