139 lines
3.9 KiB
C
139 lines
3.9 KiB
C
/*
|
||
* VasEBoot -- GRand Unified Bootloader
|
||
* Copyright (C) 1999,2000,2001,2002,2004,2006,2007 Free Software Foundation, Inc.
|
||
*
|
||
* VasEBoot 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 3 of the License, or
|
||
* (at your option) any later version.
|
||
*
|
||
* VasEBoot 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 VasEBoot. If not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
|
||
#ifndef VasEBoot_PART_HEADER
|
||
#define VasEBoot_PART_HEADER 1
|
||
|
||
#include <VasEBoot/dl.h>
|
||
#include <VasEBoot/list.h>
|
||
|
||
struct VasEBoot_disk;
|
||
|
||
typedef struct VasEBoot_partition *VasEBoot_partition_t;
|
||
|
||
#ifdef VasEBoot_UTIL
|
||
typedef enum
|
||
{
|
||
VasEBoot_EMBED_PCBIOS
|
||
} VasEBoot_embed_type_t;
|
||
#endif
|
||
|
||
typedef int (*VasEBoot_partition_iterate_hook_t) (struct VasEBoot_disk *disk,
|
||
const VasEBoot_partition_t partition,
|
||
void *data);
|
||
|
||
/* Partition map type. */
|
||
struct VasEBoot_partition_map
|
||
{
|
||
/* The next partition map type. */
|
||
struct VasEBoot_partition_map *next;
|
||
struct VasEBoot_partition_map **prev;
|
||
|
||
/* The name of the partition map type. */
|
||
const char *name;
|
||
|
||
/* Call HOOK with each partition, until HOOK returns non-zero. */
|
||
VasEBoot_err_t (*iterate) (struct VasEBoot_disk *disk,
|
||
VasEBoot_partition_iterate_hook_t hook, void *hook_data);
|
||
#ifdef VasEBoot_UTIL
|
||
/* Determine sectors available for embedding. */
|
||
VasEBoot_err_t (*embed) (struct VasEBoot_disk *disk, unsigned int *nsectors,
|
||
unsigned int max_nsectors,
|
||
VasEBoot_embed_type_t embed_type,
|
||
VasEBoot_disk_addr_t **sectors);
|
||
#endif
|
||
};
|
||
typedef struct VasEBoot_partition_map *VasEBoot_partition_map_t;
|
||
|
||
/* Partition description. */
|
||
struct VasEBoot_partition
|
||
{
|
||
/* The partition number. */
|
||
int number;
|
||
|
||
/* The start sector (relative to parent). */
|
||
VasEBoot_disk_addr_t start;
|
||
|
||
/* The length in sector units. */
|
||
VasEBoot_uint64_t len;
|
||
|
||
/* The offset of the partition table. */
|
||
VasEBoot_disk_addr_t offset;
|
||
|
||
/* The index of this partition in the partition table. */
|
||
int index;
|
||
|
||
/* Parent partition (physically contains this partition). */
|
||
struct VasEBoot_partition *parent;
|
||
|
||
/* The type partition map. */
|
||
VasEBoot_partition_map_t partmap;
|
||
|
||
/* The type of partition whne it's on MSDOS.
|
||
Used for embedding detection. */
|
||
VasEBoot_uint8_t msdostype;
|
||
};
|
||
|
||
VasEBoot_partition_t EXPORT_FUNC(VasEBoot_partition_probe) (struct VasEBoot_disk *disk,
|
||
const char *str);
|
||
int EXPORT_FUNC(VasEBoot_partition_iterate) (struct VasEBoot_disk *disk,
|
||
VasEBoot_partition_iterate_hook_t hook,
|
||
void *hook_data);
|
||
char *EXPORT_FUNC(VasEBoot_partition_get_name) (const VasEBoot_partition_t partition);
|
||
|
||
|
||
extern VasEBoot_partition_map_t EXPORT_VAR(VasEBoot_partition_map_list);
|
||
|
||
#ifndef VasEBoot_LST_GENERATOR
|
||
static inline void
|
||
VasEBoot_partition_map_register (VasEBoot_partition_map_t partmap)
|
||
{
|
||
VasEBoot_list_push (VasEBoot_AS_LIST_P (&VasEBoot_partition_map_list),
|
||
VasEBoot_AS_LIST (partmap));
|
||
}
|
||
#endif
|
||
|
||
static inline void
|
||
VasEBoot_partition_map_unregister (VasEBoot_partition_map_t partmap)
|
||
{
|
||
VasEBoot_list_remove (VasEBoot_AS_LIST (partmap));
|
||
}
|
||
|
||
#define FOR_PARTITION_MAPS(var) FOR_LIST_ELEMENTS((var), (VasEBoot_partition_map_list))
|
||
|
||
|
||
static inline VasEBoot_disk_addr_t
|
||
VasEBoot_partition_get_start (const VasEBoot_partition_t p)
|
||
{
|
||
VasEBoot_partition_t part;
|
||
VasEBoot_uint64_t part_start = 0;
|
||
|
||
for (part = p; part; part = part->parent)
|
||
part_start += part->start;
|
||
|
||
return part_start;
|
||
}
|
||
|
||
static inline VasEBoot_uint64_t
|
||
VasEBoot_partition_get_len (const VasEBoot_partition_t p)
|
||
{
|
||
return p->len;
|
||
}
|
||
|
||
#endif /* ! VasEBoot_PART_HEADER */
|