2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #include "libvolume_id.h"
32 #include "libvolume_id-private.h"
34 struct hpfs_boot_block
38 uint8_t bytes_per_sector[2];
39 uint8_t sectors_per_cluster;
40 uint8_t n_reserved_sectors[2];
42 uint8_t n_rootdir_entries[2];
43 uint8_t n_sectors_s[2];
45 uint16_t sectors_per_fat;
46 uint16_t sectors_per_track;
47 uint16_t heads_per_cyl;
48 uint32_t n_hidden_sectors;
54 uint8_t vol_label[11];
68 struct hpfs_spare_super
74 #define HPFS_SUPERBLOCK_OFFSET 0x2000
75 #define HPFS_SUPERBLOCK_SPARE_OFFSET 0x2200
77 int volume_id_probe_hpfs(struct volume_id *id, uint64_t off, uint64_t size)
79 struct hpfs_super *hs;
80 struct hpfs_spare_super *hss;
81 struct hpfs_boot_block *hbb;
83 info("probing at offset 0x%llx\n", (unsigned long long) off);
85 hs = (struct hpfs_super *) volume_id_get_buffer(id, off + HPFS_SUPERBLOCK_OFFSET, 0x400);
88 if (memcmp(hs->magic, "\x49\xe8\x95\xf9", 4) != 0)
91 hss = (struct hpfs_spare_super *) volume_id_get_buffer(id, off + HPFS_SUPERBLOCK_SPARE_OFFSET, 0x200);
94 if (memcmp(hss->magic, "\x49\x18\x91\xf9", 4) != 0)
97 sprintf(id->type_version, "%u", hs->version);
98 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
101 /* if boot block looks valid, read label and uuid from there */
102 hbb = (struct hpfs_boot_block *) volume_id_get_buffer(id, off, 0x200);
105 if (memcmp(hbb->magic, "\x55\xaa", 2) == 0 &&
106 memcmp(hbb->sig_hpfs, "HPFS", 4) == 0 &&
107 hbb->sig_28h == 0x28) {
108 volume_id_set_label_raw(id, hbb->vol_label, 11);
109 volume_id_set_label_string(id, hbb->vol_label, 11);
110 volume_id_set_uuid(id, hbb->vol_serno, 0, UUID_DOS);