Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从C中的用户空间在/proc文件系统中创建新文件。甚至可能吗?_C_File_Linux Kernel_Kernel_Proc - Fatal编程技术网

无法从C中的用户空间在/proc文件系统中创建新文件。甚至可能吗?

无法从C中的用户空间在/proc文件系统中创建新文件。甚至可能吗?,c,file,linux-kernel,kernel,proc,C,File,Linux Kernel,Kernel,Proc,因此,下面是应该创建字符串并将其写入/proc/minifwdb的函数: int write_to_file(char* rule) { FILE* fin; fin = fopen("/proc/minifwdb", "a"); if (!fin) { printf("Could not open the file /proc/minifwdb, exiting...\n"); return 1; } if

因此,下面是应该创建字符串并将其写入/proc/minifwdb的函数:

int write_to_file(char* rule)
{
    FILE* fin;

    fin = fopen("/proc/minifwdb", "a");

    if (!fin)
    {
        printf("Could not open the file /proc/minifwdb, exiting...\n");
        return 1;
    }

    if (fprintf(fin, "%s\n", rule) < 0)
        return 1;

    fclose(fin);

    return 0;
}
int写入文件(字符*规则)
{
文件*fin;
fin=fopen(“/proc/minifwdb”,“a”);
如果(!fin)
{
printf(“无法打开文件/proc/minifwdb,正在退出…\n”);
返回1;
}
如果(fprintf(fin,“%s\n”,规则)<0)
返回1;
财务总监(财务);
返回0;
}
调用fopen()时,它返回NULL。目前还没有像/proc/minifwdb这样的文件。我是否需要使用LKM创建它,然后使用它来编写信息?
我还试图从没有根访问权限的用户创建它。有什么建议吗?

/proc中的文件用作用户空间和内核之间的接口


可以使用这样的文件将字符串从用户空间传递到内核,但是希望接收字符串的内核代码负责创建该文件。

您不能从用户空间传递字符串,但为什么还要尝试呢?通过在
/proc
中创建一个文件,您试图实现什么?我需要将一个字符串从用户空间传递到内核。然后是的,您需要从内核端执行此操作。我可以使用syscall编写将加载到此函数中的模块,例如>syscall(“sudo insmod create_file.ko”)。模块只需在procfs中创建一个新文件,然后我将在其中写入字符串。这听起来合适吗?不,你不应该这样做。另外,您正试图从syscall运行sudo命令,您似乎真的不知道自己在做什么。您能解释一下为什么要在内核中编写一些东西吗?你的最终目标是什么,也许我们可以帮助你