~jonathank89/burg/burg-percise

« back to all changes in this revision

Viewing changes to disk/raid.c

  • Committer: Bean
  • Date: 2009-12-18 20:28:39 UTC
  • Revision ID: bean123ch@gmail.com-20091218202839-6rca0kh3455py32d
Eliminate nested functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
}
81
81
 
82
82
static int
83
 
grub_raid_iterate (int (*hook) (const char *name))
 
83
grub_raid_iterate (int (*hook) (const char *name, void *closure),
 
84
                   void *closure)
84
85
{
85
86
  struct grub_raid_array *array;
86
87
 
87
88
  for (array = array_list; array != NULL; array = array->next)
88
89
    {
89
90
      if (grub_is_array_readable (array))
90
 
        if (hook (array->name))
 
91
        if (hook (array->name, closure))
91
92
          return 1;
92
93
    }
93
94
 
621
622
  array_list = 0;
622
623
}
623
624
 
 
625
static int
 
626
grub_raid_register_hook (const char *name, void *closure UNUSED)
 
627
{
 
628
  grub_disk_t disk;
 
629
  struct grub_raid_array array;
 
630
 
 
631
  grub_dprintf ("raid", "Scanning for RAID devices on disk %s\n", name);
 
632
 
 
633
  disk = grub_disk_open (name);
 
634
  if (!disk)
 
635
    return 0;
 
636
 
 
637
  if ((disk->total_sectors != GRUB_ULONG_MAX) &&
 
638
      (! grub_raid_list->detect (disk, &array)) &&
 
639
      (! insert_array (disk, &array, grub_raid_list->name)))
 
640
    return 0;
 
641
 
 
642
  /* This error usually means it's not raid, no need to display
 
643
     it.  */
 
644
  if (grub_errno != GRUB_ERR_OUT_OF_RANGE)
 
645
    grub_print_error ();
 
646
 
 
647
  grub_errno = GRUB_ERR_NONE;
 
648
 
 
649
  grub_disk_close (disk);
 
650
 
 
651
  return 0;
 
652
}
 
653
 
624
654
void
625
655
grub_raid_register (grub_raid_t raid)
626
656
{
627
 
  auto int hook (const char *name);
628
 
  int hook (const char *name)
629
 
    {
630
 
      grub_disk_t disk;
631
 
      struct grub_raid_array array;
632
 
 
633
 
      grub_dprintf ("raid", "Scanning for RAID devices on disk %s\n", name);
634
 
 
635
 
      disk = grub_disk_open (name);
636
 
      if (!disk)
637
 
        return 0;
638
 
 
639
 
      if ((disk->total_sectors != GRUB_ULONG_MAX) &&
640
 
          (! grub_raid_list->detect (disk, &array)) &&
641
 
          (! insert_array (disk, &array, grub_raid_list->name)))
642
 
        return 0;
643
 
 
644
 
      /* This error usually means it's not raid, no need to display
645
 
         it.  */
646
 
      if (grub_errno != GRUB_ERR_OUT_OF_RANGE)
647
 
        grub_print_error ();
648
 
 
649
 
      grub_errno = GRUB_ERR_NONE;
650
 
 
651
 
      grub_disk_close (disk);
652
 
 
653
 
      return 0;
654
 
    }
655
 
 
656
657
  raid->next = grub_raid_list;
657
658
  grub_raid_list = raid;
658
 
  grub_device_iterate (&hook);
 
659
  grub_device_iterate (grub_raid_register_hook, 0);
659
660
}
660
661
 
661
662
void