Search code examples
cbindmount

How to mount a directory with submounts via mount(2) function?


I'm curious about mount(2) function.

 int mount(const char *type, const char *dir, int flags, void *data)

Is there any equivalent way to "mount --rbind olddir newdir" to mount with sub-mount ?

Let's say.

/origin/A (mount --bind /tmp /origin/A )
/new (mount --bind /origin /new)

In this case, /new/A doesn't display files in /tmp. So, new directory should be bind with the following command.

$ mount --rbind /origin /new

I wonder if there is a same way via mount function in C program like '-rbind'.


Solution

  • I found there was MS_REC flag for mount() function.