首页 > 解决方案 > Create partitions on a disk, and put a filesystem on them with C under linux?

问题描述

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?

标签: clinuxdisk-partitioning

解决方案


推荐阅读