I would like to use a C program to create and edit the disk label, and the partitions of block devices. Is this possible in User-space, is there a syscall to do this, or do I need a kernel module in order to do this?
I know it's possible by doing it like this:
#include <stdlib.h>
static const char *cmds[] =
{
"parted /dev/sda.....",
"fdisk /dev/sdb....",
0,
};
int main(void)
{
int i;
for (i = 0; cmds[i] != 0; i++)
if (system(cmds[i]) != 0)
exit(EXIT_FAILURE);
return 0;
}
but that's not the way I want to do it, because I can never be sure that the commands are executable on the system the program is used.
So, is there any way to do it with a C library?