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_ntfs(struct volume_id *id, uint64_t off, uint64_t size) { unsigned int sector_size; unsigned int cluster_size; uint64_t mft_cluster; uint64_t mft_off; unsigned int mft_record_size; unsigned int attr_type; unsigned int attr_off; unsigned int attr_len; unsigned int val_off; unsigned int val_len; const uint8_t *buf; const uint8_t *val; info("probing at offset 0x%" PRIx64 "\n", off); ns = (struct ntfs_super_block *) volume_id_get_buffer(id, off, 0x200); if (ns == NULL) return -1; if (memcmp(ns->oem_id, "NTFS", 4) != 0) return -1; volume_id_set_uuid(id, ns->volume_serial, 0, UUID_64BIT_LE); sector_size = le16_to_cpu(ns->bytes_per_sector); if (sector_size < 0x200) return -1; cluster_size = ns->sectors_per_cluster * sector_size; mft_cluster = le64_to_cpu(ns->mft_cluster_location); mft_off = mft_cluster * cluster_size; if (ns->cluster_per_mft_record < 0) /* size = -log2(mft_record_size); normally 1024 Bytes */ mft_record_size = 1 << -ns->cluster_per_mft_record; else mft_record_size = ns->cluster_per_mft_record * cluster_size; dbg("sectorsize 0x%x\n", sector_size); dbg("clustersize 0x%x\n", cluster_size); dbg("mftcluster %" PRIu64 "\n", mft_cluster); dbg("mftoffset 0x%" PRIx64 "\n", mft_off); dbg("cluster per mft_record %i\n", ns->cluster_per_mft_record); dbg("mft record size %i\n", mft_record_size); buf = volume_id_get_buffer(id, off + mft_off + (MFT_RECORD_VOLUME * mft_record_size), mft_record_size); if (buf == NULL) return -1; mftr = (struct master_file_table_record*) buf; dbg("mftr->magic '%c%c%c%c'\n", mftr->magic[0], mftr->magic[1], mftr->magic[2], mftr->magic[3]); if (memcmp(mftr->magic, "FILE", 4) != 0) return -1; attr_off = le16_to_cpu(mftr->attrs_offset); dbg("file $Volume's attributes are at offset %i\n", attr_off); while (1) { attr = (struct file_attribute*) &buf[attr_off]; attr_type = le32_to_cpu(attr->type); attr_len = le16_to_cpu(attr->len); val_off = le16_to_cpu(attr->value_offset); val_len = le32_to_cpu(attr->value_len); attr_off += attr_len; if (attr_len == 0) break; if (attr_off >= mft_record_size) break; if (attr_type == MFT_RECORD_ATTR_END) break; dbg("found attribute type 0x%x, len %i, at offset %i\n", attr_type, attr_len, attr_off); if (attr_type == MFT_RECORD_ATTR_VOLUME_INFO) { dbg("found info, len %i\n", val_len); info = (struct volume_info*) (((uint8_t *) attr) + val_off); snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u", info->major_ver, info->minor_ver); } if (attr_type == MFT_RECORD_ATTR_VOLUME_NAME) { dbg("found label, len %i\n", val_len); if (val_len > VOLUME_ID_LABEL_SIZE) val_len = VOLUME_ID_LABEL_SIZE; val = ((uint8_t *) attr) + val_off; volume_id_set_label_raw(id, val, val_len); volume_id_set_label_unicode16(id, val, LE, val_len); } } volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); id->type = "ntfs"; /* we think this is ntfs, but we make sure no other signatures are found */ id->force_unique_result = 1; return 0; }
int FAST_FUNC volume_id_probe_udf(struct volume_id *id /*,uint64_t off*/) { #define off ((uint64_t)0) struct volume_descriptor *vd; struct volume_structure_descriptor *vsd; unsigned bs; unsigned b; unsigned type; unsigned count; unsigned loc; unsigned clen; dbg("probing at offset 0x%llx", (unsigned long long) off); vsd = volume_id_get_buffer(id, off + UDF_VSD_OFFSET, 0x200); if (vsd == NULL) return -1; if (memcmp(vsd->id, "NSR02", 5) == 0) goto blocksize; if (memcmp(vsd->id, "NSR03", 5) == 0) goto blocksize; if (memcmp(vsd->id, "BEA01", 5) == 0) goto blocksize; if (memcmp(vsd->id, "BOOT2", 5) == 0) goto blocksize; if (memcmp(vsd->id, "CD001", 5) == 0) goto blocksize; if (memcmp(vsd->id, "CDW02", 5) == 0) goto blocksize; if (memcmp(vsd->id, "TEA03", 5) == 0) goto blocksize; return -1; blocksize: /* search the next VSD to get the logical block size of the volume */ for (bs = 0x800; bs < 0x8000; bs += 0x800) { vsd = volume_id_get_buffer(id, off + UDF_VSD_OFFSET + bs, 0x800); if (vsd == NULL) return -1; dbg("test for blocksize: 0x%x", bs); if (vsd->id[0] != '\0') goto nsr; } return -1; nsr: /* search the list of VSDs for a NSR descriptor */ for (b = 0; b < 64; b++) { vsd = volume_id_get_buffer(id, off + UDF_VSD_OFFSET + (b * bs), 0x800); if (vsd == NULL) return -1; dbg("vsd: %c%c%c%c%c", vsd->id[0], vsd->id[1], vsd->id[2], vsd->id[3], vsd->id[4]); if (vsd->id[0] == '\0') return -1; if (memcmp(vsd->id, "NSR02", 5) == 0) goto anchor; if (memcmp(vsd->id, "NSR03", 5) == 0) goto anchor; } return -1; anchor: /* read anchor volume descriptor */ vd = volume_id_get_buffer(id, off + (256 * bs), 0x200); if (vd == NULL) return -1; type = le16_to_cpu(vd->tag.id); if (type != 2) /* TAG_ID_AVDP */ goto found; /* get desriptor list address and block count */ count = le32_to_cpu(vd->type.anchor.length) / bs; loc = le32_to_cpu(vd->type.anchor.location); dbg("0x%x descriptors starting at logical secor 0x%x", count, loc); /* pick the primary descriptor from the list */ for (b = 0; b < count; b++) { vd = volume_id_get_buffer(id, off + ((loc + b) * bs), 0x200); if (vd == NULL) return -1; type = le16_to_cpu(vd->tag.id); dbg("descriptor type %i", type); /* check validity */ if (type == 0) goto found; if (le32_to_cpu(vd->tag.location) != loc + b) goto found; if (type == 1) /* TAG_ID_PVD */ goto pvd; } goto found; pvd: // volume_id_set_label_raw(id, &(vd->type.primary.ident.clen), 32); clen = vd->type.primary.ident.clen; dbg("label string charsize=%i bit", clen); if (clen == 8) volume_id_set_label_string(id, vd->type.primary.ident.c, 31); else if (clen == 16) volume_id_set_label_unicode16(id, vd->type.primary.ident.c, BE, 31); found: // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); // id->type = "udf"; return 0; }
int volume_id_probe_ntfs(struct volume_id *id /*,uint64_t off*/) { #define off ((uint64_t)0) unsigned sector_size; unsigned cluster_size; uint64_t mft_cluster; uint64_t mft_off; unsigned mft_record_size; unsigned attr_type; unsigned attr_off; unsigned attr_len; unsigned val_off; unsigned val_len; struct master_file_table_record *mftr; struct ntfs_super_block *ns; const uint8_t *buf; const uint8_t *val; dbg("probing at offset 0x%llx", (unsigned long long) off); ns = volume_id_get_buffer(id, off, 0x200); if (ns == NULL) return -1; if (memcmp(ns->oem_id, "NTFS", 4) != 0) return -1; volume_id_set_uuid(id, ns->volume_serial, UUID_NTFS); sector_size = le16_to_cpu(ns->bytes_per_sector); cluster_size = ns->sectors_per_cluster * sector_size; mft_cluster = le64_to_cpu(ns->mft_cluster_location); mft_off = mft_cluster * cluster_size; if (ns->cluster_per_mft_record < 0) /* size = -log2(mft_record_size); normally 1024 Bytes */ mft_record_size = 1 << -ns->cluster_per_mft_record; else mft_record_size = ns->cluster_per_mft_record * cluster_size; dbg("sectorsize 0x%x", sector_size); dbg("clustersize 0x%x", cluster_size); dbg("mftcluster %llu", (unsigned long long) mft_cluster); dbg("mftoffset 0x%llx", (unsigned long long) mft_off); dbg("cluster per mft_record %i", ns->cluster_per_mft_record); dbg("mft record size %i", mft_record_size); buf = volume_id_get_buffer(id, off + mft_off + (MFT_RECORD_VOLUME * mft_record_size), mft_record_size); if (buf == NULL) goto found; mftr = (struct master_file_table_record*) buf; dbg("mftr->magic '%c%c%c%c'", mftr->magic[0], mftr->magic[1], mftr->magic[2], mftr->magic[3]); if (memcmp(mftr->magic, "FILE", 4) != 0) goto found; attr_off = le16_to_cpu(mftr->attrs_offset); dbg("file $Volume's attributes are at offset %i", attr_off); while (1) { struct file_attribute *attr; attr = (struct file_attribute*) &buf[attr_off]; attr_type = le32_to_cpu(attr->type); attr_len = le16_to_cpu(attr->len); val_off = le16_to_cpu(attr->value_offset); val_len = le32_to_cpu(attr->value_len); attr_off += attr_len; if (attr_len == 0) break; if (attr_off >= mft_record_size) break; if (attr_type == MFT_RECORD_ATTR_END) break; dbg("found attribute type 0x%x, len %i, at offset %i", attr_type, attr_len, attr_off); // if (attr_type == MFT_RECORD_ATTR_VOLUME_INFO) { // struct volume_info *info; // dbg("found info, len %i", val_len); // info = (struct volume_info*) (((uint8_t *) attr) + val_off); // snprintf(id->type_version, sizeof(id->type_version)-1, // "%u.%u", info->major_ver, info->minor_ver); // } if (attr_type == MFT_RECORD_ATTR_VOLUME_NAME) { dbg("found label, len %i", val_len); if (val_len > VOLUME_ID_LABEL_SIZE) val_len = VOLUME_ID_LABEL_SIZE; val = ((uint8_t *) attr) + val_off; // volume_id_set_label_raw(id, val, val_len); volume_id_set_label_unicode16(id, val, LE, val_len); } } found: // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); // id->type = "ntfs"; return 0; }