How to create a directory in user space in a Linux

2019-08-05 21:34发布

问题:

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.