2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2002,2005,2006,2007,2011 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <grub/partition.h>
2N/A#include <grub/disk.h>
2N/A#include <grub/mm.h>
2N/A#include <grub/misc.h>
2N/A#include <grub/dl.h>
2N/A#include <grub/symbol.h>
2N/A#include <grub/types.h>
2N/A#include <grub/err.h>
2N/A
2N/AGRUB_MOD_LICENSE ("GPLv3+");
2N/A
2N/A#define DVH_MAGIC 0x0be5a941
2N/A
2N/Astruct grub_dvh_partition_descriptor
2N/A{
2N/A grub_uint32_t length;
2N/A grub_uint32_t start;
2N/A grub_uint32_t type;
2N/A} __attribute__ ((packed));
2N/A
2N/Astruct grub_dvh_block
2N/A{
2N/A grub_uint32_t magic;
2N/A grub_uint8_t unused[308];
2N/A struct grub_dvh_partition_descriptor parts[16];
2N/A grub_uint32_t checksum;
2N/A grub_uint32_t unused2;
2N/A} __attribute__ ((packed));
2N/A
2N/Astatic struct grub_partition_map grub_dvh_partition_map;
2N/A
2N/A/* Verify checksum (true=ok). */
2N/Astatic int
2N/Agrub_dvh_is_valid (grub_uint32_t *label)
2N/A{
2N/A grub_uint32_t *pos;
2N/A grub_uint32_t sum = 0;
2N/A
2N/A for (pos = label;
2N/A pos < (label + sizeof (struct grub_dvh_block) / 4);
2N/A pos++)
2N/A sum += *pos;
2N/A
2N/A return ! sum;
2N/A}
2N/A
2N/Astatic grub_err_t
2N/Advh_partition_map_iterate (grub_disk_t disk,
2N/A int (*hook) (grub_disk_t disk,
2N/A const grub_partition_t partition))
2N/A{
2N/A struct grub_partition p;
2N/A union
2N/A {
2N/A struct grub_dvh_block dvh;
2N/A grub_uint32_t raw[0];
2N/A } block;
2N/A unsigned partnum;
2N/A grub_err_t err;
2N/A
2N/A p.partmap = &grub_dvh_partition_map;
2N/A err = grub_disk_read (disk, 0, 0, sizeof (struct grub_dvh_block),
2N/A &block);
2N/A if (err)
2N/A return err;
2N/A
2N/A if (DVH_MAGIC != grub_be_to_cpu32 (block.dvh.magic))
2N/A return grub_error (GRUB_ERR_BAD_PART_TABLE, "not a dvh partition table");
2N/A
2N/A if (! grub_dvh_is_valid (block.raw))
2N/A return grub_error (GRUB_ERR_BAD_PART_TABLE, "invalid checksum");
2N/A
2N/A /* Maybe another error value would be better, because partition
2N/A table _is_ recognized but invalid. */
2N/A for (partnum = 0; partnum < ARRAY_SIZE (block.dvh.parts); partnum++)
2N/A {
2N/A if (block.dvh.parts[partnum].length == 0)
2N/A continue;
2N/A
2N/A if (partnum == 10)
2N/A continue;
2N/A
2N/A p.start = grub_be_to_cpu32 (block.dvh.parts[partnum].start);
2N/A p.len = grub_be_to_cpu32 (block.dvh.parts[partnum].length);
2N/A p.number = p.index = partnum;
2N/A if (hook (disk, &p))
2N/A break;
2N/A }
2N/A
2N/A return grub_errno;
2N/A}
2N/A
2N/A
2N/A/* Partition map type. */
2N/Astatic struct grub_partition_map grub_dvh_partition_map =
2N/A {
2N/A .name = "dvh",
2N/A .iterate = dvh_partition_map_iterate,
2N/A };
2N/A
2N/AGRUB_MOD_INIT(part_dvh)
2N/A{
2N/A grub_partition_map_register (&grub_dvh_partition_map);
2N/A}
2N/A
2N/AGRUB_MOD_FINI(part_dvh)
2N/A{
2N/A grub_partition_map_unregister (&grub_dvh_partition_map);
2N/A}
2N/A