X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=extras%2Fvolume_id%2Flib%2Fntfs.c;h=8154e7685ae625660a7d8fcface78972a9a6b153;hp=f1e8c4bc294422e6781302ad34d25c7f777e9c88;hb=d4f687c013a18010fdc2ddf937fad064343e635a;hpb=d5618ac96913efa0b52501b6a5c690bee6a33517 diff --git a/extras/volume_id/lib/ntfs.c b/extras/volume_id/lib/ntfs.c index f1e8c4bc2..8154e7685 100644 --- a/extras/volume_id/lib/ntfs.c +++ b/extras/volume_id/lib/ntfs.c @@ -3,19 +3,24 @@ * * Copyright (C) 2004 Kay Sievers * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation version 2 of the License. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #ifndef _GNU_SOURCE #define _GNU_SOURCE 1 #endif -#ifdef HAVE_CONFIG_H -# include -#endif - #include #include #include @@ -24,7 +29,7 @@ #include #include "libvolume_id.h" -#include "util.h" +#include "libvolume_id-private.h" static struct ntfs_super_block { uint8_t jump[3]; @@ -90,7 +95,7 @@ static struct volume_info { #define MFT_RECORD_ATTR_OBJECT_ID 0x40 #define MFT_RECORD_ATTR_END 0xffffffffu -int volume_id_probe_ntfs(struct volume_id *id, uint64_t off) +int volume_id_probe_ntfs(struct volume_id *id, uint64_t off, uint64_t size) { unsigned int sector_size; unsigned int cluster_size; @@ -105,7 +110,7 @@ int volume_id_probe_ntfs(struct volume_id *id, uint64_t off) const uint8_t *buf; const uint8_t *val; - dbg("probing at offset 0x%llx", (unsigned long long) off); + info("probing at offset 0x%llx\n", (unsigned long long) off); ns = (struct ntfs_super_block *) volume_id_get_buffer(id, off, 0x200); if (ns == NULL) @@ -114,9 +119,12 @@ int volume_id_probe_ntfs(struct volume_id *id, uint64_t off) if (memcmp(ns->oem_id, "NTFS", 4) != 0) return -1; - volume_id_set_uuid(id, ns->volume_serial, UUID_NTFS); + 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; @@ -127,26 +135,25 @@ int volume_id_probe_ntfs(struct volume_id *id, uint64_t off) 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); + dbg("sectorsize 0x%x\n", sector_size); + dbg("clustersize 0x%x\n", cluster_size); + dbg("mftcluster %llu\n", (unsigned long long) mft_cluster); + dbg("mftoffset 0x%llx\n", (unsigned long long) 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) - goto found; + return -1; 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]); + 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) - goto found; + return -1; attr_off = le16_to_cpu(mftr->attrs_offset); - dbg("file $Volume's attributes are at offset %i", attr_off); + dbg("file $Volume's attributes are at offset %i\n", attr_off); while (1) { attr = (struct file_attribute*) &buf[attr_off]; @@ -165,18 +172,18 @@ int volume_id_probe_ntfs(struct volume_id *id, uint64_t off) if (attr_type == MFT_RECORD_ATTR_END) break; - dbg("found attribute type 0x%x, len %i, at offset %i", + 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", val_len); + 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", val_len); + dbg("found label, len %i\n", val_len); if (val_len > VOLUME_ID_LABEL_SIZE) val_len = VOLUME_ID_LABEL_SIZE; @@ -186,7 +193,6 @@ int volume_id_probe_ntfs(struct volume_id *id, uint64_t off) } } -found: volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); id->type = "ntfs";