~kaction/config

ref: 42707d29c994c30956608b9c9f10cbaf1d00add4 config/system-v2/nix-sys/chattr/enable.c -rw-r--r-- 602 bytes
42707d29 — Dmitry Bogatov nix-sys: generate build system inside of build system 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <linux/fs.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>

static int fssetflags(int fd, unsigned int flags)
{
	return ioctl(fd, FS_IOC_SETFLAGS, (void*)&flags);
}

static int path_setattrs(const char *path, unsigned int flags)
{
	int fd;
	int err;

	fd = open(path, O_NONBLOCK|O_RDONLY);
	if (fd < 0)
		return 1;
	err = fssetflags(fd, flags);
	close(fd);

	return err;
}

int immutable_on(const char *path)
{
	return path_setattrs(path, FS_IMMUTABLE_FL);
}

int immutable_off(const char *path)
{
	return path_setattrs(path, 0);
}