im starting to get into the partitioning side of of things. Ive started with this small routine that parses /proc/mounts into debconf. I figure ill do one that parses /proc/partitions and then one to get known filesystems. With those three lots of information in debconf format and mount functions can be done. Obviously the format will have to depend on a seperate udeb for each possible filesystem type, so there may end up being a fair few different udebs for the partitioning side of things. Glenn
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <cdebconf/debconfclient.h> int main(int argc, char **argv) { FILE *proc_mounts; struct debconfclient *client; char *device, *mount_point, *fs_type; char *table = NULL; char raw_line[80]; char *line = NULL; device = (char *) malloc(80); mount_point = (char *) malloc(80); fs_type = (char *) malloc(80); table = (char *) malloc(1); if ((proc_mounts = fopen("/proc/mounts", "r")) == NULL) { printf("FIXME: need to mount /proc first\n"); return EXIT_FAILURE; } client = debconfclient_new (); client->command (client, "title", "Mounted Partitions", NULL); while (fgets(raw_line, 80, proc_mounts) != NULL) { int line_length; sscanf(raw_line, "%s %s %s ", device, mount_point, fs_type); line_length = strlen(device) + strlen(mount_point) + strlen(fs_type) + 30; line = realloc(line, line_length); sprintf(line,"%-10s\t%-10s\t%-10s\n", device, mount_point, fs_type); table = realloc(table, line_length + strlen(table)); strcat(table, line); } fclose(proc_mounts); client->command (client, "subst", "ddetect/mounted", "partition_table", table, NULL); client->command (client, "go", NULL); printf("done, table was [%s]\n",table); return EXIT_SUCCESS; }
Template: ddetect/mounted Type: text Description: Current partition table Device Mount Point Filesystem '${partition_table}'