feat: 实现并测试 newfstatat 系统调用 (#1153)

* feat: 实现并测试 newfstatat 系统调用

新增了 newfstatat 系统调用的实现,并添加了相应的测试应用。

Signed-off-by: longjin <longjin@DragonOS.org>

* feat(loongarch64/riscv64): 添加文件系统模块并实现GenericPosixStat结构

为loongarch64和riscv64架构添加filesystem模块,包含stat子模块,并实现GenericPosixStat结构用于处理文件状态信息。

Signed-off-by: longjin <longjin@DragonOS.org>

---------

Signed-off-by: longjin <longjin@DragonOS.org>
This commit is contained in:
LoGin
2025-05-09 23:04:58 +08:00
committed by GitHub
parent 5422256d63
commit cd3289e4b4
18 changed files with 397 additions and 14 deletions

1
user/apps/test_newfstatat/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
test_newfstatat

View File

@ -0,0 +1,20 @@
ifeq ($(ARCH), x86_64)
CROSS_COMPILE=x86_64-linux-musl-
else ifeq ($(ARCH), riscv64)
CROSS_COMPILE=riscv64-linux-musl-
endif
CC=$(CROSS_COMPILE)gcc
.PHONY: all
all: main.c
$(CC) -static -o test_newfstatat main.c
.PHONY: install clean
install: all
mv test_newfstatat $(DADK_CURRENT_BUILD_DIR)/test_newfstatat
clean:
rm test_newfstatat *.o
fmt:

View File

@ -0,0 +1,65 @@
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <sys/syscall.h>
#define TEST_DIR "test_dir"
#define TEST_FILE "test_file"
void create_test_files() {
mkdir(TEST_DIR, 0755);
int fd = open(TEST_FILE, O_CREAT | O_RDWR, 0644);
if (fd >= 0) close(fd);
}
void cleanup_test_files() {
unlink(TEST_FILE);
rmdir(TEST_DIR);
}
void run_test(const char *name, int (*test_func)(), int expected) {
printf("Testing %s... ", name);
int result = test_func();
if (result == expected) {
printf("[PASS]\n");
} else {
printf("[FAILED] (expected %d, got %d)\n", expected, result);
}
}
int test_normal_file() {
struct stat st;
return syscall(__NR_newfstatat, AT_FDCWD, TEST_FILE, &st, 0);
}
int test_directory() {
struct stat st;
return syscall(__NR_newfstatat, AT_FDCWD, TEST_DIR, &st, 0);
}
int test_invalid_fd() {
struct stat st;
return syscall(__NR_newfstatat, -1, TEST_FILE, &st, 0);
}
int test_nonexistent_path() {
struct stat st;
return syscall(__NR_newfstatat, AT_FDCWD, "nonexistent_file", &st, 0);
}
int main() {
create_test_files();
run_test("normal file stat", test_normal_file, 0);
run_test("directory stat", test_directory, 0);
run_test("invalid file descriptor", test_invalid_fd, -1);
run_test("nonexistent path", test_nonexistent_path, -1);
cleanup_test_files();
return 0;
}

View File

@ -0,0 +1,36 @@
# 用户程序名称
name = "test_newfstatat"
# 版本号
version = "0.1.0"
# 用户程序描述信息
description = "一个用来测试 newfstatat 能够正常运行的app"
# (可选)默认: false 是否只构建一次如果为trueDADK会在构建成功后将构建结果缓存起来下次构建时直接使用缓存的构建结果
build-once = false
# (可选) 默认: false 是否只安装一次如果为trueDADK会在安装成功后不再重复安装
install-once = false
# 目标架构
# 可选值:"x86_64", "aarch64", "riscv64", "loongarch64"
target-arch = ["x86_64", "riscv64"]
# 任务源
[task-source]
# 构建类型
# 可选值:"build-from_source", "install-from-prebuilt"
type = "build-from-source"
# 构建来源
# "build_from_source" 可选值:"git", "local", "archive"
# "install_from_prebuilt" 可选值:"local", "archive"
source = "local"
# 路径或URL
source-path = "user/apps/test_newfstatat"
# 构建相关信息
[build]
# (可选)构建命令
build-command = "make install"
# 安装相关信息
[install]
# 可选安装到DragonOS的路径
in-dragonos-path = "/bin"
# 清除相关信息
[clean]
# (可选)清除命令
clean-command = "make clean"