-
-
Save ChrisPritchard/05d98e1d195bc255b30674c8ce0fec50 to your computer and use it in GitHub Desktop.
chattr alternative
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/stat.h> | |
#include <sys/ioctl.h> | |
#include <linux/fs.h> | |
int main(int argc, char **argv) | |
{ | |
FILE *fp; | |
if ((fp = fopen(argv[1], "r")) == NULL) { | |
perror("fopen(3) error"); | |
exit(EXIT_FAILURE); | |
} | |
int val = atoi(argv[2]); // 16 adds the immutable flag, 0 removes it | |
if (ioctl(fileno(fp), FS_IOC_SETFLAGS, &val) < 0) | |
perror("ioctl(2) error"); | |
fclose(fp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
compile with -static if no gcc on target (and architecture matches)