From e134f4704c7f0072f230ab4b6a827808e058381a Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 3 Dec 2008 11:25:43 +0100 Subject: [PATCH] blkid: add HPFS Signed-off-by: Karel Zak --- libs/blkid/src/probe.c | 2 +- libs/blkid/src/probers/Makefile.am | 3 +- libs/blkid/src/probers/hpfs.c | 129 +++++++++++++++++++++++++++++ libs/blkid/src/probers/probers.h | 1 + 4 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 libs/blkid/src/probers/hpfs.c diff --git a/libs/blkid/src/probe.c b/libs/blkid/src/probe.c index 76105cbe..374c34f8 100644 --- a/libs/blkid/src/probe.c +++ b/libs/blkid/src/probe.c @@ -72,7 +72,7 @@ static const struct blkid_idinfo *idinfos[] = &hfsplus_idinfo, &hfs_idinfo, &ufs_idinfo, - /* TODO: hpfs */ + &hpfs_idinfo, /* TODO: sysv / xenix */ &ntfs_idinfo, &cramfs_idinfo, diff --git a/libs/blkid/src/probers/Makefile.am b/libs/blkid/src/probers/Makefile.am index 2529e7ef..33c8ad11 100644 --- a/libs/blkid/src/probers/Makefile.am +++ b/libs/blkid/src/probers/Makefile.am @@ -33,7 +33,8 @@ libprobers_a_SOURCES = probers.h \ highpoint_raid.c \ vxfs.c \ minix.c \ - ufs.c + ufs.c \ + hpfs.c \ lvm.c all-local: $(lib_LIBRARIES) diff --git a/libs/blkid/src/probers/hpfs.c b/libs/blkid/src/probers/hpfs.c new file mode 100644 index 00000000..801e6bc1 --- /dev/null +++ b/libs/blkid/src/probers/hpfs.c @@ -0,0 +1,129 @@ +/* + * Copyright (C) 1999, 2001 by Andries Brouwer + * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o + * Copyright (C) 2008 Karel Zak + * + * This file 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 file 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. + */ + +#include +#include +#include +#include +#include + +#include "blkidP.h" + +struct hpfs_boot_block +{ + uint8_t jmp[3]; + uint8_t oem_id[8]; + uint8_t bytes_per_sector[2]; + uint8_t sectors_per_cluster; + uint8_t n_reserved_sectors[2]; + uint8_t n_fats; + uint8_t n_rootdir_entries[2]; + uint8_t n_sectors_s[2]; + uint8_t media_byte; + uint16_t sectors_per_fat; + uint16_t sectors_per_track; + uint16_t heads_per_cyl; + uint32_t n_hidden_sectors; + uint32_t n_sectors_l; + uint8_t drive_number; + uint8_t mbz; + uint8_t sig_28h; + uint8_t vol_serno[4]; + uint8_t vol_label[11]; + uint8_t sig_hpfs[8]; + uint8_t pad[448]; + uint8_t magic[2]; +}; + +struct hpfs_super +{ + uint8_t magic[4]; + uint8_t magic1[4]; + uint8_t version; +}; + +struct hpfs_spare_super +{ + uint8_t magic[4]; + uint8_t magic1[4]; +}; + + +#define HPFS_SB_OFFSET 0x2000 +#define HPFS_SBSPARE_OFFSET 0x2200 + +static int probe_hpfs(blkid_probe pr, const struct blkid_idmag *mag) +{ + struct hpfs_super *hs; + struct hpfs_spare_super *hss; + struct hpfs_boot_block *hbb; + uint8_t version; + + /* super block */ + hs = blkid_probe_get_sb(pr, mag, struct hpfs_super); + if (!hs) + return -1; + version = hs->version; + + /* spare super block */ + hss = (struct hpfs_spare_super *) + blkid_probe_get_buffer(pr, + HPFS_SBSPARE_OFFSET, + sizeof(struct hpfs_spare_super)); + if (!hss) + return -1; + if (memcmp(hss->magic, "\x49\x18\x91\xf9", 4) != 0) + return -1; + + /* boot block (with UUID and LABEL) */ + hbb = (struct hpfs_boot_block *) + blkid_probe_get_buffer(pr, + 0, + sizeof(struct hpfs_boot_block)); + if (!hbb) + return -1; + if (memcmp(hbb->magic, "\x55\xaa", 2) == 0 && + memcmp(hbb->sig_hpfs, "HPFS", 4) == 0 && + hbb->sig_28h == 0x28) { + blkid_probe_set_label(pr, hbb->vol_label, sizeof(hbb->vol_label)); + blkid_probe_sprintf_uuid(pr, + hbb->vol_serno, sizeof(hbb->vol_serno), + "%02X%02X-%02X%02X", + hbb->vol_serno[3], hbb->vol_serno[2], + hbb->vol_serno[1], hbb->vol_serno[0]); + } + blkid_probe_sprintf_version(pr, "%u", version); + + return 0; +} + +const struct blkid_idinfo hpfs_idinfo = +{ + .name = "hpfs", + .usage = BLKID_USAGE_FILESYSTEM, + .probefunc = probe_hpfs, + .magics = + { + { + .magic = "\x49\xe8\x95\xf9", + .len = 4, + .kboff = (HPFS_SB_OFFSET >> 10) + }, + { NULL } + } +}; + + diff --git a/libs/blkid/src/probers/probers.h b/libs/blkid/src/probers/probers.h index 4c2f1f6f..8272c957 100644 --- a/libs/blkid/src/probers/probers.h +++ b/libs/blkid/src/probers/probers.h @@ -52,6 +52,7 @@ extern const struct blkid_idinfo vxfs_idinfo; extern const struct blkid_idinfo minix_idinfo; extern const struct blkid_idinfo vfat_idinfo; extern const struct blkid_idinfo ufs_idinfo; +extern const struct blkid_idinfo hpfs_idinfo; extern const struct blkid_idinfo lvm2_idinfo; extern const struct blkid_idinfo lvm1_idinfo; extern const struct blkid_idinfo luks_idinfo; -- 2.39.5