chiark / gitweb /
volume_id: add more vfat debugging information
[elogind.git] / extras / volume_id / lib / fat.c
index 759e106f6805c9d6399c64804f3df7badc4e56ac..9d26a987e0a818fd570ce5c96487120452a2f9fa 100644 (file)
@@ -4,19 +4,24 @@
  * Copyright (C) 2004-2007 Kay Sievers <kay.sievers@vrfy.org>
  * Copyright (C) 2007 Ryan Lortie <desrt@desrt.ca>
  *
- *     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 <http://www.gnu.org/licenses/>.
  */
 
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE 1
 #endif
 
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -26,7 +31,6 @@
 
 #include "libvolume_id.h"
 #include "libvolume_id-private.h"
-#include "util.h"
 
 #define FAT12_MAX                      0xff5
 #define FAT16_MAX                      0xfff5
@@ -271,7 +275,7 @@ int volume_id_probe_vfat(struct volume_id *id, uint64_t off, uint64_t size)
        int maxloop;
        size_t fnlen;
 
-       info("probing at offset 0x%llx\n", (unsigned long long) off);
+       info("probing at offset 0x%" PRIx64 "\n", off);
 
        buf = volume_id_get_buffer(id, off, 0x400);
        if (buf == NULL)
@@ -307,6 +311,7 @@ int volume_id_probe_vfat(struct volume_id *id, uint64_t off, uint64_t size)
                return -1;
 
 magic:
+       info("magic found\n");
        /* reserverd sector count */
        if (!vs->reserved)
                return -1;
@@ -329,6 +334,7 @@ magic:
        if (sector_size == 0 || ((sector_size & (sector_size-1)) != 0))
                return -1;
 
+       info("checks passed\n");
        dbg("sector_size 0x%x\n", sector_size);
        dbg("sectors_per_cluster 0x%x\n", vs->sectors_per_cluster);
 
@@ -352,7 +358,7 @@ magic:
                fat_size = fat32_length * vs->fats;
        else
                return -1;
-       dbg("fat_size 0x%x\n", fat_size);
+       info("fat_size 0x%x\n", fat_size);
 
        dir_size = ((dir_entries * sizeof(struct vfat_dir_entry)) +
                        (sector_size-1)) / sector_size;
@@ -360,7 +366,7 @@ magic:
 
        cluster_count = sect_count - (reserved + fat_size + dir_size);
        cluster_count /= vs->sectors_per_cluster;
-       dbg("cluster_count 0x%x\n", cluster_count);
+       info("cluster_count 0x%x\n", cluster_count);
 
        /* must be FAT32 */
        if (!fat_length && fat32_length)
@@ -376,7 +382,7 @@ magic:
 
        /* the label may be an attribute in the root directory */
        root_start = (reserved + fat_size) * sector_size;
-       dbg("root dir start 0x%llx\n", (unsigned long long) root_start);
+       dbg("root dir start 0x%" PRIx64 "\n", root_start);
        root_dir_entries = le16_to_cpu(vs->dir_entries);
        dbg("expected entries 0x%x\n", root_dir_entries);
 
@@ -404,16 +410,24 @@ magic:
        goto found;
 
 fat32:
+       info("looking for FAT32\n");
        /* FAT32 should have a valid signature in the fsinfo block */
        fsinfo_sect = le16_to_cpu(vs->type.fat32.fsinfo_sector);
        buf = volume_id_get_buffer(id, off + (fsinfo_sect * sector_size), 0x200);
        if (buf == NULL)
                return -1;
        fsinfo = (struct fat32_fsinfo *) buf;
+       info("signature1: 0x%02x%02x%02x%02x\n",
+            fsinfo->signature1[0], fsinfo->signature1[1],
+            fsinfo->signature1[2], fsinfo->signature1[3]);
+       info("signature2: 0x%02x%02x%02x%02x\n",
+            fsinfo->signature2[0], fsinfo->signature2[1],
+            fsinfo->signature2[2], fsinfo->signature2[3]);
        if (memcmp(fsinfo->signature1, "\x52\x52\x61\x41", 4) != 0)
                return -1;
        if (memcmp(fsinfo->signature2, "\x72\x72\x41\x61", 4) != 0)
                return -1 ;
+       info("FAT32 signatures match\n");
 
        vs = (struct vfat_super_block *) volume_id_get_buffer(id, off, 0x200);
        if (vs == NULL)
@@ -438,7 +452,7 @@ fat32:
                dbg("next cluster %u\n", next);
                next_sect_off = (next - 2) * vs->sectors_per_cluster;
                next_off = (start_data_sect + next_sect_off) * sector_size;
-               dbg("cluster offset 0x%llx\n", (unsigned long long) next_off);
+               dbg("cluster offset 0x%" PRIx64 "\n", next_off);
 
                /* get cluster */
                buf = volume_id_get_buffer(id, off + next_off, buf_size);