mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:57:35 +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:
parent
ad53f6afd3
commit
c30e2c8d44
22 changed files with 156 additions and 4 deletions
1
Userland/.gitignore
vendored
1
Userland/.gitignore
vendored
|
@ -28,3 +28,4 @@ rm
|
|||
cp
|
||||
rmdir
|
||||
dmesg
|
||||
chmod
|
||||
|
|
|
@ -25,6 +25,7 @@ OBJS = \
|
|||
cp.o \
|
||||
rmdir.o \
|
||||
dmesg.o \
|
||||
chmod.o \
|
||||
rm.o
|
||||
|
||||
APPS = \
|
||||
|
@ -55,6 +56,7 @@ APPS = \
|
|||
cp \
|
||||
rmdir \
|
||||
dmesg \
|
||||
chmod \
|
||||
rm
|
||||
|
||||
ARCH_FLAGS =
|
||||
|
@ -159,6 +161,9 @@ rm: rm.o
|
|||
rmdir: rmdir.o
|
||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||
|
||||
chmod: chmod.o
|
||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||
|
||||
.cpp.o:
|
||||
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||
|
||||
|
|
27
Userland/chmod.cpp
Normal file
27
Userland/chmod.cpp
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue