Print this page
grub patch


  57 {
  58   grub_uint16_t *pos;
  59   grub_uint16_t sum = 0;
  60 
  61   for (pos = label;
  62        pos < (label + sizeof (struct grub_sun_pc_block) / 2);
  63        pos++)
  64     sum ^= *pos;
  65 
  66   return ! sum;
  67 }
  68 
  69 static grub_err_t
  70 sun_pc_partition_map_iterate (grub_disk_t disk,
  71                               int (*hook) (grub_disk_t disk,
  72                                            const grub_partition_t partition))
  73 {
  74   grub_partition_t p;
  75   union
  76   {
  77     struct grub_sun_pc_block sun;
  78     grub_uint16_t raw[0];
  79   } block;
  80   int partnum;
  81   grub_err_t err;
  82 
  83   p = (grub_partition_t) grub_zalloc (sizeof (struct grub_partition));
  84   if (! p)
  85     return grub_errno;
  86 
  87   p->partmap = &grub_sun_pc_partition_map;
  88   err = grub_disk_read (disk, 1, 0, sizeof (struct grub_sun_pc_block), &block);
  89   if (err)
  90     {
  91       grub_free (p);
  92       return err;
  93     }
  94   
  95   if (GRUB_PARTMAP_SUN_PC_MAGIC != grub_le_to_cpu16 (block.sun.magic))
  96     {
  97       grub_free (p);
  98       return grub_error (GRUB_ERR_BAD_PART_TABLE, 
  99                          "not a sun_pc partition table");
 100     }
 101 
 102   if (! grub_sun_is_valid (block.raw))
 103     {
 104       grub_free (p);
 105       return grub_error (GRUB_ERR_BAD_PART_TABLE, "invalid checksum");
 106     }
 107 
 108   /* Maybe another error value would be better, because partition
 109      table _is_ recognized but invalid.  */
 110   for (partnum = 0; partnum < GRUB_PARTMAP_SUN_PC_MAX_PARTS; partnum++)
 111     {
 112       struct grub_sun_pc_partition_descriptor *desc;
 113 
 114       if (block.sun.partitions[partnum].id == 0
 115           || block.sun.partitions[partnum].id
 116           == GRUB_PARTMAP_SUN_PC_WHOLE_DISK_ID)
 117         continue;
 118 
 119       desc = &block.sun.partitions[partnum];
 120       p->start = grub_le_to_cpu32 (desc->start_sector);
 121       p->len = grub_le_to_cpu32 (desc->num_sectors);
 122       p->number = partnum;
 123       if (p->len)
 124         {
 125           if (hook (disk, p))
 126             partnum = GRUB_PARTMAP_SUN_PC_MAX_PARTS;
 127         }
 128     }
 129 
 130   grub_free (p);
 131 
 132   return grub_errno;
 133 }
 134 
 135 /* Partition map type.  */
 136 static struct grub_partition_map grub_sun_pc_partition_map =
 137   {
 138     .name = "sunpc",
 139     .iterate = sun_pc_partition_map_iterate,


  57 {
  58   grub_uint16_t *pos;
  59   grub_uint16_t sum = 0;
  60 
  61   for (pos = label;
  62        pos < (label + sizeof (struct grub_sun_pc_block) / 2);
  63        pos++)
  64     sum ^= *pos;
  65 
  66   return ! sum;
  67 }
  68 
  69 static grub_err_t
  70 sun_pc_partition_map_iterate (grub_disk_t disk,
  71                               int (*hook) (grub_disk_t disk,
  72                                            const grub_partition_t partition))
  73 {
  74   grub_partition_t p;
  75   union
  76   {
  77     struct grub_sun_pc_block sunb;
  78     grub_uint16_t raw[0];
  79   } block;
  80   int partnum;
  81   grub_err_t err;
  82 
  83   p = (grub_partition_t) grub_zalloc (sizeof (struct grub_partition));
  84   if (! p)
  85     return grub_errno;
  86 
  87   p->partmap = &grub_sun_pc_partition_map;
  88   err = grub_disk_read (disk, 1, 0, sizeof (struct grub_sun_pc_block), &block);
  89   if (err)
  90     {
  91       grub_free (p);
  92       return err;
  93     }
  94   
  95   if (GRUB_PARTMAP_SUN_PC_MAGIC != grub_le_to_cpu16 (block.sunb.magic))
  96     {
  97       grub_free (p);
  98       return grub_error (GRUB_ERR_BAD_PART_TABLE, 
  99                          "not a sun_pc partition table");
 100     }
 101 
 102   if (! grub_sun_is_valid (block.raw))
 103     {
 104       grub_free (p);
 105       return grub_error (GRUB_ERR_BAD_PART_TABLE, "invalid checksum");
 106     }
 107 
 108   /* Maybe another error value would be better, because partition
 109      table _is_ recognized but invalid.  */
 110   for (partnum = 0; partnum < GRUB_PARTMAP_SUN_PC_MAX_PARTS; partnum++)
 111     {
 112       struct grub_sun_pc_partition_descriptor *desc;
 113 
 114       if (block.sunb.partitions[partnum].id == 0
 115           || block.sunb.partitions[partnum].id
 116           == GRUB_PARTMAP_SUN_PC_WHOLE_DISK_ID)
 117         continue;
 118 
 119       desc = &block.sunb.partitions[partnum];
 120       p->start = grub_le_to_cpu32 (desc->start_sector);
 121       p->len = grub_le_to_cpu32 (desc->num_sectors);
 122       p->number = partnum;
 123       if (p->len)
 124         {
 125           if (hook (disk, p))
 126             partnum = GRUB_PARTMAP_SUN_PC_MAX_PARTS;
 127         }
 128     }
 129 
 130   grub_free (p);
 131 
 132   return grub_errno;
 133 }
 134 
 135 /* Partition map type.  */
 136 static struct grub_partition_map grub_sun_pc_partition_map =
 137   {
 138     .name = "sunpc",
 139     .iterate = sun_pc_partition_map_iterate,