1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +00:00

Implement basic chmod() syscall and /bin/chmod helper.

Only raw octal modes are supported right now.
This patch also changes mode_t from 32-bit to 16-bit to match the on-disk
type used by Ext2FS.

I also ran into EPERM being errno=0 which was confusing, so I inserted an
ESUCCESS in its place.
This commit is contained in:
Andreas Kling 2019-01-29 04:55:08 +01:00
parent ad53f6afd3
commit c30e2c8d44
22 changed files with 156 additions and 4 deletions

27
Userland/chmod.cpp Normal file
View file

@ -0,0 +1,27 @@
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
if (argc != 3) {
printf("usage: chmod <octal-mode> <path>\n");
return 1;
}
mode_t mode;
int rc = sscanf(argv[1], "%o", &mode);
if (rc != 1) {
perror("sscanf");
return 1;
}
rc = chmod(argv[2], mode);
if (rc < 0) {
perror("chmod");
return 1;
}
return 0;
}