2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 1999,2000,2001,2002,2004,2007 Free Software Foundation, Inc.
2N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
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#ifndef GRUB_PC_PARTITION_HEADER
2N/A#define GRUB_PC_PARTITION_HEADER 1
2N/A
2N/A#include <grub/symbol.h>
2N/A#include <grub/types.h>
2N/A#include <grub/err.h>
2N/A#include <grub/disk.h>
2N/A#include <grub/partition.h>
2N/A
2N/A/* The signature. */
2N/A#define GRUB_PC_PARTITION_SIGNATURE 0xaa55
2N/A
2N/A/* This is not a flag actually, but used as if it were a flag. */
2N/A#define GRUB_PC_PARTITION_TYPE_HIDDEN_FLAG 0x10
2N/A
2N/A/* DOS partition types. */
2N/A#define GRUB_PC_PARTITION_TYPE_NONE 0
2N/A#define GRUB_PC_PARTITION_TYPE_FAT12 1
2N/A#define GRUB_PC_PARTITION_TYPE_FAT16_LT32M 4
2N/A#define GRUB_PC_PARTITION_TYPE_EXTENDED 5
2N/A#define GRUB_PC_PARTITION_TYPE_FAT16_GT32M 6
2N/A#define GRUB_PC_PARTITION_TYPE_NTFS 7
2N/A#define GRUB_PC_PARTITION_TYPE_FAT32 0xb
2N/A#define GRUB_PC_PARTITION_TYPE_FAT32_LBA 0xc
2N/A#define GRUB_PC_PARTITION_TYPE_FAT16_LBA 0xe
2N/A#define GRUB_PC_PARTITION_TYPE_WIN95_EXTENDED 0xf
2N/A#define GRUB_PC_PARTITION_TYPE_PLAN9 0x39
2N/A#define GRUB_PC_PARTITION_TYPE_EZD 0x55
2N/A#define GRUB_PC_PARTITION_TYPE_MINIX 0x80
2N/A#define GRUB_PC_PARTITION_TYPE_LINUX_MINIX 0x81
2N/A#define GRUB_PC_PARTITION_TYPE_LINUX_SWAP 0x82
2N/A#define GRUB_PC_PARTITION_LEGACY_SUNIXOS GRUB_PC_PARTITION_TYPE_LINUX_SWAP
2N/A#define GRUB_PC_PARTITION_TYPE_EXT2FS 0x83
2N/A#define GRUB_PC_PARTITION_TYPE_LINUX_EXTENDED 0x85
2N/A#define GRUB_PC_PARTITION_TYPE_VSTAFS 0x9e
2N/A#define GRUB_PC_PARTITION_TYPE_FREEBSD 0xa5
2N/A#define GRUB_PC_PARTITION_TYPE_OPENBSD 0xa6
2N/A#define GRUB_PC_PARTITION_TYPE_NETBSD 0xa9
2N/A#define GRUB_PC_PARTITION_TYPE_HFS 0xaf
2N/A#define GRUB_PC_PARTITION_SUNIXOS 0xbf
2N/A#define GRUB_PC_PARTITION_TYPE_GPT_DISK 0xee
2N/A#define GRUB_PC_PARTITION_TYPE_LINUX_RAID 0xfd
2N/A
2N/A/* The partition entry. */
2N/Astruct grub_msdos_partition_entry
2N/A{
2N/A /* If active, 0x80, otherwise, 0x00. */
2N/A grub_uint8_t flag;
2N/A
2N/A /* The head of the start. */
2N/A grub_uint8_t start_head;
2N/A
2N/A /* (S | ((C >> 2) & 0xC0)) where S is the sector of the start and C
2N/A is the cylinder of the start. Note that S is counted from one. */
2N/A grub_uint8_t start_sector;
2N/A
2N/A /* (C & 0xFF) where C is the cylinder of the start. */
2N/A grub_uint8_t start_cylinder;
2N/A
2N/A /* The partition type. */
2N/A grub_uint8_t type;
2N/A
2N/A /* The end versions of start_head, start_sector and start_cylinder,
2N/A respectively. */
2N/A grub_uint8_t end_head;
2N/A grub_uint8_t end_sector;
2N/A grub_uint8_t end_cylinder;
2N/A
2N/A /* The start sector. Note that this is counted from zero. */
2N/A grub_uint32_t start;
2N/A
2N/A /* The length in sector units. */
2N/A grub_uint32_t length;
2N/A} __attribute__ ((packed));
2N/A
2N/A/* The structure of MBR. */
2N/Astruct grub_msdos_partition_mbr
2N/A{
2N/A /* The code area (actually, including BPB). */
2N/A grub_uint8_t code[446];
2N/A
2N/A /* Four partition entries. */
2N/A struct grub_msdos_partition_entry entries[4];
2N/A
2N/A /* The signature 0xaa55. */
2N/A grub_uint16_t signature;
2N/A} __attribute__ ((packed));
2N/A
2N/A
2N/A
2N/Astatic inline int
2N/Agrub_msdos_partition_is_empty (int type)
2N/A{
2N/A return (type == GRUB_PC_PARTITION_TYPE_NONE);
2N/A}
2N/A
2N/Astatic inline int
2N/Agrub_msdos_partition_is_extended (int type)
2N/A{
2N/A return (type == GRUB_PC_PARTITION_TYPE_EXTENDED
2N/A || type == GRUB_PC_PARTITION_TYPE_WIN95_EXTENDED
2N/A || type == GRUB_PC_PARTITION_TYPE_LINUX_EXTENDED);
2N/A}
2N/A
2N/Agrub_err_t
2N/Agrub_partition_msdos_iterate (grub_disk_t disk,
2N/A int (*hook) (grub_disk_t disk,
2N/A const grub_partition_t partition));
2N/A
2N/A#endif /* ! GRUB_PC_PARTITION_HEADER */