chiark / gitweb /
volume_id: ntfs - rely on valid master file table
[elogind.git] / extras / volume_id / lib / ntfs.c
index 23c64fc3071ee251f5df9bd1c9793f83c175a1f6..f63804d711f388e7cad9cdb7d2d241cc2a474333 100644 (file)
@@ -26,7 +26,7 @@
 #include "libvolume_id.h"
 #include "util.h"
 
-struct ntfs_super_block {
+static struct ntfs_super_block {
        uint8_t         jump[3];
        uint8_t         oem_id[8];
        uint16_t        bytes_per_sector;
@@ -53,7 +53,7 @@ struct ntfs_super_block {
        uint16_t        checksum;
 } PACKED *ns;
 
-struct master_file_table_record {
+static struct master_file_table_record {
        uint8_t         magic[4];
        uint16_t        usa_ofs;
        uint16_t        usa_count;
@@ -66,7 +66,7 @@ struct master_file_table_record {
        uint32_t        bytes_allocated;
 } PACKED *mftr;
 
-struct file_attribute {
+static struct file_attribute {
        uint32_t        type;
        uint32_t        len;
        uint8_t         non_resident;
@@ -78,7 +78,7 @@ struct file_attribute {
        uint16_t        value_offset;
 } PACKED *attr;
 
-struct volume_info {
+static struct volume_info {
        uint64_t        reserved;
        uint8_t         major_ver;
        uint8_t         minor_ver;
@@ -90,7 +90,7 @@ 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 +105,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", (unsigned long long) off);
 
        ns = (struct ntfs_super_block *) volume_id_get_buffer(id, off, 0x200);
        if (ns == NULL)
@@ -114,9 +114,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;
@@ -137,13 +140,12 @@ int volume_id_probe_ntfs(struct volume_id *id, uint64_t off)
        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]);
        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);
@@ -186,7 +188,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";