1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 17:37:47 +00:00

Add unlink() syscall and /bin/rm.

This patch adds most of the plumbing for working file deletion in Ext2FS.
Directory entries are removed and inode link counts updated.
We don't yet update the inode or block bitmaps, I will do that separately.
This commit is contained in:
Andreas Kling 2019-01-22 07:03:44 +01:00
parent 2f2f28f212
commit bda0c935c2
16 changed files with 142 additions and 6 deletions

1
Userland/.gitignore vendored
View file

@ -24,3 +24,4 @@ more
guitest
guitest2
sysctl
rm

View file

@ -21,7 +21,8 @@ OBJS = \
more.o \
guitest.o \
guitest2.o \
sysctl.o
sysctl.o \
rm.o
APPS = \
id \
@ -47,7 +48,8 @@ APPS = \
more \
guitest \
guitest2 \
sysctl
sysctl \
rm
ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
@ -139,6 +141,9 @@ guitest2: guitest2.o
sysctl: sysctl.o
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
rm: rm.o
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<

18
Userland/rm.cpp Normal file
View file

@ -0,0 +1,18 @@
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
int main(int argc, char** argv)
{
if (argc != 2) {
fprintf(stderr, "usage: rm <path>\n");
return 1;
}
int rc = unlink(argv[1]);
if (rc < 0) {
perror("unlink");
return 1;
}
return 0;
}