~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to grub-core/partmap/plan.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-09-13 18:02:04 UTC
  • mfrom: (1.17.15 upstream)
  • mto: (17.6.27 experimental)
  • mto: This revision was merged to the branch mainline in revision 145.
  • Revision ID: package-import@ubuntu.com-20120913180204-mojnmocbimlom4im
Tags: upstream-2.00
ImportĀ upstreamĀ versionĀ 2.00

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  GRUB  --  GRand Unified Bootloader
 
3
 *  Copyright (C) 2010  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
 *  (at your option) any later version.
 
9
 *
 
10
 *  GRUB is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  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
#include <grub/partition.h>
 
20
#include <grub/disk.h>
 
21
#include <grub/mm.h>
 
22
#include <grub/misc.h>
 
23
#include <grub/dl.h>
 
24
#include <grub/symbol.h>
 
25
#include <grub/types.h>
 
26
#include <grub/err.h>
 
27
 
 
28
GRUB_MOD_LICENSE ("GPLv3+");
 
29
 
 
30
static struct grub_partition_map grub_plan_partition_map;
 
31
 
 
32
static grub_err_t
 
33
plan_partition_map_iterate (grub_disk_t disk,
 
34
                            int (*hook) (grub_disk_t disk,
 
35
                                         const grub_partition_t partition))
 
36
{
 
37
  struct grub_partition p;
 
38
  int ptr = 0;
 
39
  grub_err_t err;
 
40
 
 
41
  p.partmap = &grub_plan_partition_map;
 
42
  p.msdostype = 0;
 
43
 
 
44
  for (p.number = 0; ; p.number++)
 
45
    {
 
46
      char sig[sizeof ("part ") - 1];
 
47
      char c;
 
48
 
 
49
      p.offset = (ptr >> GRUB_DISK_SECTOR_BITS) + 1;
 
50
      p.index = ptr & (GRUB_DISK_SECTOR_SIZE - 1);
 
51
 
 
52
      err = grub_disk_read (disk, 1, ptr, sizeof (sig), sig);
 
53
      if (err)
 
54
        return err;
 
55
      if (grub_memcmp (sig, "part ", sizeof ("part ") - 1) != 0)
 
56
        break;
 
57
      ptr += sizeof (sig);
 
58
      do
 
59
        {
 
60
          err = grub_disk_read (disk, 1, ptr, 1, &c);
 
61
          if (err)
 
62
            return err;
 
63
          ptr++;
 
64
        }
 
65
      while (grub_isdigit (c) || grub_isalpha (c));
 
66
      if (c != ' ')
 
67
        break;
 
68
      p.start = 0;
 
69
      while (1)
 
70
        {
 
71
          err = grub_disk_read (disk, 1, ptr, 1, &c);
 
72
          if (err)
 
73
            return err;
 
74
          ptr++;
 
75
          if (!grub_isdigit (c))
 
76
            break;
 
77
          p.start = p.start * 10 + (c - '0');
 
78
        }
 
79
      if (c != ' ')
 
80
        break;
 
81
      p.len = 0;
 
82
      while (1)
 
83
        {
 
84
          err = grub_disk_read (disk, 1, ptr, 1, &c);
 
85
          if (err)
 
86
            return err;
 
87
          ptr++;
 
88
          if (!grub_isdigit (c))
 
89
            break;
 
90
          p.len = p.len * 10 + (c - '0');
 
91
        }
 
92
      if (c != '\n')
 
93
        break;
 
94
      p.len -= p.start;
 
95
      if (hook (disk, &p))
 
96
        return grub_errno;
 
97
    }
 
98
  if (p.number == 0)
 
99
    return grub_error (GRUB_ERR_BAD_PART_TABLE, "not a plan partition table");
 
100
 
 
101
  return GRUB_ERR_NONE;
 
102
}
 
103
 
 
104
/* Partition map type.  */
 
105
static struct grub_partition_map grub_plan_partition_map =
 
106
  {
 
107
    .name = "plan",
 
108
    .iterate = plan_partition_map_iterate,
 
109
  };
 
110
 
 
111
GRUB_MOD_INIT(part_plan)
 
112
{
 
113
  grub_partition_map_register (&grub_plan_partition_map);
 
114
}
 
115
 
 
116
GRUB_MOD_FINI(part_plan)
 
117
{
 
118
  grub_partition_map_unregister (&grub_plan_partition_map);
 
119
}
 
120