1 // SPDX-License-Identifier: GPL-2.0
13 static int set_immutable(const char *path, int immutable)
20 fd = open(path, O_RDONLY);
24 rc = ioctl(fd, FS_IOC_GETFLAGS, &flags);
33 flags |= FS_IMMUTABLE_FL;
35 flags &= ~FS_IMMUTABLE_FL;
37 rc = ioctl(fd, FS_IOC_SETFLAGS, &flags);
44 static int get_immutable(const char *path)
51 fd = open(path, O_RDONLY);
55 rc = ioctl(fd, FS_IOC_GETFLAGS, &flags);
63 if (flags & FS_IMMUTABLE_FL)
68 int main(int argc, char **argv)
75 fprintf(stderr, "usage: %s <path>\n", argv[0]);
81 /* attributes: EFI_VARIABLE_NON_VOLATILE |
82 * EFI_VARIABLE_BOOTSERVICE_ACCESS |
83 * EFI_VARIABLE_RUNTIME_ACCESS
85 *(uint32_t *)buf = 0x7;
88 /* create a test variable */
89 fd = open(path, O_WRONLY | O_CREAT, 0600);
91 perror("open(O_WRONLY)");
95 rc = write(fd, buf, sizeof(buf));
96 if (rc != sizeof(buf)) {
103 rc = get_immutable(path);
105 perror("ioctl(FS_IOC_GETFLAGS)");
108 rc = set_immutable(path, 0);
110 perror("ioctl(FS_IOC_SETFLAGS)");
115 fd = open(path, O_RDONLY);
121 if (unlink(path) < 0) {
126 rc = read(fd, buf, sizeof(buf));
128 fprintf(stderr, "reading from an unlinked variable "
129 "shouldn't be possible\n");