Martin Vegter
Martin Vegter

Reputation: 527

using the syscall mount() to remount ext4 filesystem read-only

I want to write a simple C program with hardcoded options, which does nothing else than remount root filesystem to read-only

I see, the mount() syscall takes following parameters:

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

I have following C code:

#include <stdio.h>
#include <errno.h>
#include <sys/mount.h>

int main(int argc, char *argv[]) {
    return mount ("/dev/sda1", "/", "ext4", "MS_RDONLY", NULL);
}

I know, in place of MS_RDONLY I should use a type int. But where do I find the value corresponding to MS_RDONLY (or which ever option I need to use) ?

Upvotes: 1

Views: 3215

Answers (2)

Andrew Henle
Andrew Henle

Reputation: 1

It's #define'd in sys/mount.h.

mount ("/dev/sda1", "/", "ext4", MS_RDONLY, NULL);

Upvotes: 0

christophetd
christophetd

Reputation: 3874

MS_RDONLY should be defined in mount.h, that you already included in your code. Changing "MS_RDONLY" to MS_RDONLY should do the trick.

Upvotes: 3

Related Questions