diff --git a/ChangeLog b/ChangeLog index f3a6c0659..7638bb3bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-10-04 Vladimir Serbinenko + + Make cryptodisk and diskfilter probe data retrievable programmatically + and not just printable. + 2013-10-04 Vladimir Serbinenko Split random retrieving code into separate files. diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index f291ea698..dc714f641 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -746,31 +746,33 @@ grub_cryptodisk_cheat_insert (grub_cryptodisk_t newdev, const char *name, } void -grub_util_cryptodisk_print_abstraction (grub_disk_t disk) +grub_util_cryptodisk_get_abstraction (grub_disk_t disk, + void (*cb) (const char *val)) { grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data; - grub_printf ("cryptodisk %s ", dev->modname); + cb ("cryptodisk"); + cb (dev->modname); if (dev->cipher) - grub_printf ("%s ", dev->cipher->cipher->modname); + cb (dev->cipher->cipher->modname); if (dev->secondary_cipher) - grub_printf ("%s ", dev->secondary_cipher->cipher->modname); + cb (dev->secondary_cipher->cipher->modname); if (dev->essiv_cipher) - grub_printf ("%s ", dev->essiv_cipher->cipher->modname); + cb (dev->essiv_cipher->cipher->modname); if (dev->hash) - grub_printf ("%s ", dev->hash->modname); + cb (dev->hash->modname); if (dev->essiv_hash) - grub_printf ("%s ", dev->essiv_hash->modname); + cb (dev->essiv_hash->modname); if (dev->iv_hash) - grub_printf ("%s ", dev->iv_hash->modname); + cb (dev->iv_hash->modname); } -void -grub_util_cryptodisk_print_uuid (grub_disk_t disk) +const char * +grub_util_cryptodisk_get_uuid (grub_disk_t disk) { grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data; - grub_printf ("%s ", dev->uuid); + return dev->uuid; } #endif diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c index eef143a1d..44794bfca 100644 --- a/grub-core/disk/diskfilter.c +++ b/grub-core/disk/diskfilter.c @@ -353,7 +353,8 @@ grub_diskfilter_memberlist (grub_disk_t disk) } void -grub_diskfilter_print_partmap (grub_disk_t disk) +grub_diskfilter_get_partmap (grub_disk_t disk, + void (*cb) (const char *pm)) { struct grub_diskfilter_lv *lv = disk->data; struct grub_diskfilter_pv *pv; @@ -375,7 +376,7 @@ grub_diskfilter_print_partmap (grub_disk_t disk) continue; } for (s = 0; pv->partmaps[s]; s++) - grub_printf ("%s ", pv->partmaps[s]); + cb (pv->partmaps[s]); } } diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h index 09e65721d..66f3e1e22 100644 --- a/include/grub/cryptodisk.h +++ b/include/grub/cryptodisk.h @@ -144,7 +144,9 @@ grub_err_t grub_cryptodisk_cheat_insert (grub_cryptodisk_t newdev, const char *name, grub_disk_t source, const char *cheat); void -grub_util_cryptodisk_print_abstraction (grub_disk_t disk); +grub_util_cryptodisk_get_abstraction (grub_disk_t disk, + void (*cb) (const char *val)); + char * grub_util_get_geli_uuid (const char *dev); #endif diff --git a/include/grub/diskfilter.h b/include/grub/diskfilter.h index 3ed806326..042fe04a5 100644 --- a/include/grub/diskfilter.h +++ b/include/grub/diskfilter.h @@ -201,7 +201,8 @@ struct grub_diskfilter_pv * grub_diskfilter_get_pv_from_disk (grub_disk_t disk, struct grub_diskfilter_vg **vg); void -grub_diskfilter_print_partmap (grub_disk_t disk); +grub_diskfilter_get_partmap (grub_disk_t disk, + void (*cb) (const char *val)); #endif #endif /* ! GRUB_RAID_H */ diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h index 4d6b63421..b44efa4b5 100644 --- a/include/grub/emu/hostdisk.h +++ b/include/grub/emu/hostdisk.h @@ -65,7 +65,8 @@ ssize_t grub_util_fd_read (grub_util_fd_t fd, char *buf, size_t len); ssize_t grub_util_fd_write (grub_util_fd_t fd, const char *buf, size_t len); grub_err_t grub_cryptodisk_cheat_mount (const char *sourcedev, const char *cheat); -void grub_util_cryptodisk_print_uuid (grub_disk_t disk); +const char * +grub_util_cryptodisk_get_uuid (grub_disk_t disk); char * grub_util_get_ldm (grub_disk_t disk, grub_disk_addr_t start); int diff --git a/util/grub-probe.c b/util/grub-probe.c index 1f561962a..a7e437399 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -76,6 +76,12 @@ enum { static int print = PRINT_FS; static unsigned int argument_is_device = 0; +static void +do_print (const char *x) +{ + grub_printf ("%s ", x); +} + static void probe_partmap (grub_disk_t disk) { @@ -91,7 +97,7 @@ probe_partmap (grub_disk_t disk) printf ("%s ", part->partmap->name); if (disk->dev->id == GRUB_DISK_DEVICE_DISKFILTER_ID) - grub_diskfilter_print_partmap (disk); + grub_diskfilter_get_partmap (disk, do_print); /* In case of LVM/RAID, check the member devices as well. */ if (disk->dev->memberlist) @@ -125,7 +131,10 @@ probe_cryptodisk_uuid (grub_disk_t disk) list = tmp; } if (disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID) - grub_util_cryptodisk_print_uuid (disk); + { + const char *uu = grub_util_cryptodisk_get_uuid (disk); + grub_printf ("%s ", uu); + } } static int @@ -303,7 +312,7 @@ probe_abstraction (grub_disk_t disk) printf ("ldm "); if (disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID) - grub_util_cryptodisk_print_abstraction (disk); + grub_util_cryptodisk_get_abstraction (disk, do_print); raid_level = probe_raid_level (disk); if (raid_level >= 0)