Skip to content

Instantly share code, notes, and snippets.

@ChrisPritchard
Last active April 27, 2022 18:52
Show Gist options
  • Save ChrisPritchard/05d98e1d195bc255b30674c8ce0fec50 to your computer and use it in GitHub Desktop.
Save ChrisPritchard/05d98e1d195bc255b30674c8ce0fec50 to your computer and use it in GitHub Desktop.
chattr alternative
#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;
}
@ChrisPritchard
Copy link
Author

compile with -static if no gcc on target (and architecture matches)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment