How to create a directory in user space in a Linux kernel module

℡╲_俬逩灬. 提交于 2019-12-11 11:44:15

问题


The following will create a file in user space but how can I create a directory?

struct file *filp = filp_open("/home/myuser/Desktop/newfile", O_CREAT, S_IRWXU);

回答1:


The best way I know how is to use:

mkdir("your/directory", 0700);

David Heffernan's comment shows the specifics.

Edit: This page will show you the different mode parameters you can give for your directory and what they do.

http://osdir.com/ml/linux.c-programming/2002-06/msg00069.html




回答2:


Just set O_DIRECTORY in filp_open flags.



来源:https://stackoverflow.com/questions/27431725/how-to-create-a-directory-in-user-space-in-a-linux-kernel-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!