The attached patch corrects the FIXME for getting a list of devices according to the libparted docs.
Unfortunately, when trying this in a test app, also attached, no devices are detected by libparted. If someone can see the mistake I'm making, that would be great. The code looks exactly correct to me. michael -- michael cardenas | lead software engineer | lindows.com | hyperpoem.net "Man's main task in life is to give birth to himself." - Erich Fromm
--- partkit.c.orig Tue Aug 27 08:23:42 2002 +++ partkit.c Tue Aug 27 09:02:59 2002 @@ -412,18 +412,49 @@ { int finished = 0; PedDevice *dev = NULL; - char *ptr; + char *ptr = 0; + int drivelistlen = 0; client = debconfclient_new (); client->command (client, "title", "Partition Editor", NULL); + //mbc - should install an exception handler here + ped_init(); + do { - /* FIXME: how to get a list of available devices ? */ - ptr = /* get_device_list() */ "/dev/hdb"; + ped_device_probe_all(); + + //mbc - unfortunately, do two passes for now to do the malloc... + while((dev = ped_device_get_next(dev))) + { + drivelistlen += strlen(dev->path); + } + + if(drivelistlen) + { + ptr = (char *)malloc(drivelistlen); + + if(ptr) + { + *ptr = 0; + dev = NULL; + + while((dev = ped_device_get_next(dev))) + { + if(*ptr == 0) + strcpy(ptr, dev->path); + else if (*ptr != 0) + strcat(ptr, dev->path); + } + } + + } client->command (client, "subst", "partkit/select_device", "choices", ptr, NULL); + free(ptr); + /*FIXME: how to get a default device? */ client->command (client, "subst", "partkit/select_device", "default", ptr, NULL); @@ -452,6 +483,8 @@ finished = 1; } while (!finished); + + ped_done(); return 0; }
#include <string.h> #include <parted/parted.h> int main (int argc, char *argv[]) { int finished = 0; PedDevice *dev = NULL; char *ptr = 0; int drivelistlen = 0; if(ped_init() == 0) printf("libparted init failed\n"); do { ped_device_probe_all(); //unfortunately, do two passes for now to do the malloc... printf("dev: %p\n", dev); dev = ped_device_get_next(dev); printf("dev: %p\n", dev); while(dev) { drivelistlen += strlen(dev->path); dev = ped_device_get_next(dev); printf("%d, %p\n", drivelistlen, dev); } printf("%d, %p\n", drivelistlen, dev); if(drivelistlen) { ptr = (char *)malloc(drivelistlen); if(ptr) { *ptr = 0; dev = NULL; dev = ped_device_get_next(dev); while(dev) { if(*ptr == 0) strcpy(ptr, dev->path); else if (*ptr != 0) strcat(ptr, dev->path); dev = ped_device_get_next(dev); } } } printf("ptr: %s\n", ptr); ped_done(); return 0; } while(1); ped_done(); return 0; }
msg21612/pgp00000.pgp
Description: PGP signature