如何将选项传递给挂载系统调用?

How to pass options into the mount system call?

我想在 Linux 的 C 程序中安装 100 MB tmpfs。 如何将挂载选项(即 -o size=100M,mode=0755)传递给 mount 系统调用?

C:

的挂载接口
#include <sys/mount.h>

int mount(const char *source, const char *target,
            const char *filesystemtype, unsigned long mountflags,
            const void *data);

正在阅读mount(2) man-page, it seems that filesystem independent options are given in mountflags as combination of different flags, and other filesystem specific options in data as comma-separated string exactly as they are used in mount(8)

所以在你的情况下,只需将这些选项作为字符串传递:

const char *data = "size=100M,mode=0755";
...
mount(source, target, filesystemtype, mountflags, data);