mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 11:16:47 +00:00
* 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>
66 lines
1.4 KiB
C
66 lines
1.4 KiB
C
#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;
|
|
}
|