Print this page
grub patch


  75 {
  76   grub_uint16_t *pos;
  77   grub_uint16_t sum = 0;
  78 
  79   for (pos = label;
  80        pos < (label + sizeof (struct grub_sun_block) / 2);
  81        pos++)
  82     sum ^= *pos;
  83 
  84   return ! sum;
  85 }
  86 
  87 static grub_err_t
  88 sun_partition_map_iterate (grub_disk_t disk,
  89                            int (*hook) (grub_disk_t disk,
  90                                         const grub_partition_t partition))
  91 {
  92   struct grub_partition p;
  93   union
  94   {
  95     struct grub_sun_block sun;
  96     grub_uint16_t raw[0];
  97   } block;
  98   int partnum;
  99   grub_err_t err;
 100 
 101   p.partmap = &grub_sun_partition_map;
 102   err = grub_disk_read (disk, 0, 0, sizeof (struct grub_sun_block),
 103                         &block);
 104   if (err)
 105     return err;
 106 
 107   if (GRUB_PARTMAP_SUN_MAGIC != grub_be_to_cpu16 (block.sun.magic))
 108     return grub_error (GRUB_ERR_BAD_PART_TABLE, "not a sun partition table");
 109 
 110   if (! grub_sun_is_valid (block.raw))
 111       return grub_error (GRUB_ERR_BAD_PART_TABLE, "invalid checksum");
 112   
 113   /* Maybe another error value would be better, because partition
 114      table _is_ recognized but invalid.  */
 115   for (partnum = 0; partnum < GRUB_PARTMAP_SUN_MAX_PARTS; partnum++)
 116     {
 117       struct grub_sun_partition_descriptor *desc;
 118 
 119       if (block.sun.infos[partnum].id == 0
 120           || block.sun.infos[partnum].id == GRUB_PARTMAP_SUN_WHOLE_DISK_ID)
 121         continue;
 122 
 123       desc = &block.sun.partitions[partnum];
 124       p.start = ((grub_uint64_t) grub_be_to_cpu32 (desc->start_cylinder)
 125                   * grub_be_to_cpu16 (block.sun.ntrks)
 126                   * grub_be_to_cpu16 (block.sun.nsect));
 127       p.len = grub_be_to_cpu32 (desc->num_sectors);
 128       p.number = p.index = partnum;
 129       if (p.len)
 130         {
 131           if (hook (disk, &p))
 132             partnum = GRUB_PARTMAP_SUN_MAX_PARTS;
 133         }
 134     }
 135 
 136   return grub_errno;
 137 }
 138 
 139 /* Partition map type.  */
 140 static struct grub_partition_map grub_sun_partition_map =
 141   {
 142     .name = "sun",
 143     .iterate = sun_partition_map_iterate,
 144   };
 145 
 146 GRUB_MOD_INIT(part_sun)


  75 {
  76   grub_uint16_t *pos;
  77   grub_uint16_t sum = 0;
  78 
  79   for (pos = label;
  80        pos < (label + sizeof (struct grub_sun_block) / 2);
  81        pos++)
  82     sum ^= *pos;
  83 
  84   return ! sum;
  85 }
  86 
  87 static grub_err_t
  88 sun_partition_map_iterate (grub_disk_t disk,
  89                            int (*hook) (grub_disk_t disk,
  90                                         const grub_partition_t partition))
  91 {
  92   struct grub_partition p;
  93   union
  94   {
  95     struct grub_sun_block sunb;
  96     grub_uint16_t raw[0];
  97   } block;
  98   int partnum;
  99   grub_err_t err;
 100 
 101   p.partmap = &grub_sun_partition_map;
 102   err = grub_disk_read (disk, 0, 0, sizeof (struct grub_sun_block),
 103                         &block);
 104   if (err)
 105     return err;
 106 
 107   if (GRUB_PARTMAP_SUN_MAGIC != grub_be_to_cpu16 (block.sunb.magic))
 108     return grub_error (GRUB_ERR_BAD_PART_TABLE, "not a sun partition table");
 109 
 110   if (! grub_sun_is_valid (block.raw))
 111       return grub_error (GRUB_ERR_BAD_PART_TABLE, "invalid checksum");
 112   
 113   /* Maybe another error value would be better, because partition
 114      table _is_ recognized but invalid.  */
 115   for (partnum = 0; partnum < GRUB_PARTMAP_SUN_MAX_PARTS; partnum++)
 116     {
 117       struct grub_sun_partition_descriptor *desc;
 118 
 119       if (block.sunb.infos[partnum].id == 0
 120           || block.sunb.infos[partnum].id == GRUB_PARTMAP_SUN_WHOLE_DISK_ID)
 121         continue;
 122 
 123       desc = &block.sunb.partitions[partnum];
 124       p.start = ((grub_uint64_t) grub_be_to_cpu32 (desc->start_cylinder)
 125                   * grub_be_to_cpu16 (block.sunb.ntrks)
 126                   * grub_be_to_cpu16 (block.sunb.nsect));
 127       p.len = grub_be_to_cpu32 (desc->num_sectors);
 128       p.number = p.index = partnum;
 129       if (p.len)
 130         {
 131           if (hook (disk, &p))
 132             partnum = GRUB_PARTMAP_SUN_MAX_PARTS;
 133         }
 134     }
 135 
 136   return grub_errno;
 137 }
 138 
 139 /* Partition map type.  */
 140 static struct grub_partition_map grub_sun_partition_map =
 141   {
 142     .name = "sun",
 143     .iterate = sun_partition_map_iterate,
 144   };
 145 
 146 GRUB_MOD_INIT(part_sun)