c - 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?
解决方案
推荐阅读
- azure-devops - 在模块外访问 Terraform 变量
- ms-word - ContextMenu 项目在 Web Word 中不可见
- javascript - 如何在 Angular 中显示/隐藏按钮
- reactjs - 向表单组件内的字段集标记添加有条件的 core-ui 禁用属性
- java - 如何获取响应对象大小?
- arrays - Xamarin Forms 隔离存储似乎无法保存整个文件
- assembly - 将符号从 0ah 输入复制到另一个变量
- python - 在 tensorflow 上使用自动编码器获取图像名称
- css - 如何为我的 html 背景图片添加 url?
- r - 嵌套 for 循环中的自定义函数