12 static int set_immutable(const char *path
, int immutable
)
19 fd
= open(path
, O_RDONLY
);
23 rc
= ioctl(fd
, FS_IOC_GETFLAGS
, &flags
);
32 flags
|= FS_IMMUTABLE_FL
;
34 flags
&= ~FS_IMMUTABLE_FL
;
36 rc
= ioctl(fd
, FS_IOC_SETFLAGS
, &flags
);
43 static int get_immutable(const char *path
)
50 fd
= open(path
, O_RDONLY
);
54 rc
= ioctl(fd
, FS_IOC_GETFLAGS
, &flags
);
62 if (flags
& FS_IMMUTABLE_FL
)
67 int main(int argc
, char **argv
)
74 fprintf(stderr
, "usage: %s <path>\n", argv
[0]);
80 /* attributes: EFI_VARIABLE_NON_VOLATILE |
81 * EFI_VARIABLE_BOOTSERVICE_ACCESS |
82 * EFI_VARIABLE_RUNTIME_ACCESS
84 *(uint32_t *)buf
= 0x7;
87 /* create a test variable */
88 fd
= open(path
, O_WRONLY
| O_CREAT
, 0600);
90 perror("open(O_WRONLY)");
94 rc
= write(fd
, buf
, sizeof(buf
));
95 if (rc
!= sizeof(buf
)) {
102 rc
= get_immutable(path
);
104 perror("ioctl(FS_IOC_GETFLAGS)");
107 rc
= set_immutable(path
, 0);
109 perror("ioctl(FS_IOC_SETFLAGS)");
114 fd
= open(path
, O_RDONLY
);
120 if (unlink(path
) < 0) {
125 rc
= read(fd
, buf
, sizeof(buf
));
127 fprintf(stderr
, "reading from an unlinked variable "
128 "shouldn't be possible\n");