partition.h 3.64 KB
Newer Older
1 2
/*
 *  GRUB  --  GRand Unified Bootloader
3
 *  Copyright (C) 1999,2000,2001,2002,2004,2006,2007  Free Software Foundation, Inc.
4
 *
5
 *  GRUB is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation, either version 3 of the License, or
8 9
 *  (at your option) any later version.
 *
10
 *  GRUB is distributed in the hope that it will be useful,
11 12 13 14 15
 *  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
16
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
17 18 19 20 21 22
 */

#ifndef GRUB_PART_HEADER
#define GRUB_PART_HEADER	1

#include <grub/dl.h>
23
#include <grub/list.h>
24 25 26 27 28

struct grub_disk;

typedef struct grub_partition *grub_partition_t;

29 30 31 32 33 34 35
#ifdef GRUB_UTIL
typedef enum
{
  GRUB_EMBED_PCBIOS
} grub_embed_type_t;
#endif

36 37 38 39
typedef int (*grub_partition_iterate_hook_t) (struct grub_disk *disk,
					      const grub_partition_t partition,
					      void *data);

40 41 42
/* Partition map type.  */
struct grub_partition_map
{
43 44
  /* The next partition map type.  */
  struct grub_partition_map *next;
45
  struct grub_partition_map **prev;
46

47 48
  /* The name of the partition map type.  */
  const char *name;
49

50 51
  /* Call HOOK with each partition, until HOOK returns non-zero.  */
  grub_err_t (*iterate) (struct grub_disk *disk,
52
			 grub_partition_iterate_hook_t hook, void *hook_data);
53 54
#ifdef GRUB_UTIL
  /* Determine sectors available for embedding.  */
55
  grub_err_t (*embed) (struct grub_disk *disk, unsigned int *nsectors,
56
		       unsigned int max_nsectors,
57 58
		       grub_embed_type_t embed_type,
		       grub_disk_addr_t **sectors);
59
#endif
60 61 62 63 64 65
};
typedef struct grub_partition_map *grub_partition_map_t;

/* Partition description.  */
struct grub_partition
{
66 67 68
  /* The partition number.  */
  int number;

69
  /* The start sector (relative to parent).  */
70
  grub_disk_addr_t start;
71 72

  /* The length in sector units.  */
73
  grub_uint64_t len;
74 75

  /* The offset of the partition table.  */
76
  grub_disk_addr_t offset;
77 78 79

  /* The index of this partition in the partition table.  */
  int index;
80

81
  /* Parent partition (physically contains this partition).  */
82 83
  struct grub_partition *parent;

84 85
  /* The type partition map.  */
  grub_partition_map_t partmap;
86 87 88 89

  /* The type of partition whne it's on MSDOS.
     Used for embedding detection.  */
  grub_uint8_t msdostype;
90 91 92 93
};

grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk *disk,
						    const char *str);
94
int EXPORT_FUNC(grub_partition_iterate) (struct grub_disk *disk,
95 96
					 grub_partition_iterate_hook_t hook,
					 void *hook_data);
97 98
char *EXPORT_FUNC(grub_partition_get_name) (const grub_partition_t partition);

99

100 101
extern grub_partition_map_t EXPORT_VAR(grub_partition_map_list);

102
#ifndef GRUB_LST_GENERATOR
103 104 105 106 107 108
static inline void
grub_partition_map_register (grub_partition_map_t partmap)
{
  grub_list_push (GRUB_AS_LIST_P (&grub_partition_map_list),
		  GRUB_AS_LIST (partmap));
}
109
#endif
110 111 112 113

static inline void
grub_partition_map_unregister (grub_partition_map_t partmap)
{
114
  grub_list_remove (GRUB_AS_LIST (partmap));
115
}
116

117
#define FOR_PARTITION_MAPS(var) FOR_LIST_ELEMENTS((var), (grub_partition_map_list))
118 119


120
static inline grub_disk_addr_t
121 122
grub_partition_get_start (const grub_partition_t p)
{
123 124 125 126 127 128 129
  grub_partition_t part;
  grub_uint64_t part_start = 0;

  for (part = p; part; part = part->parent)
    part_start += part->start;

  return part_start;
130 131
}

132
static inline grub_uint64_t
133 134 135 136 137 138
grub_partition_get_len (const grub_partition_t p)
{
  return p->len;
}

#endif /* ! GRUB_PART_HEADER */