8e389c03f8
Реализовать двухпанельный Commander от платформенного PoC до этапов P6-P20: EMM-каталог, сортировку и выбор, операции с файлами и деревьями, транзакционное копирование, метаданные, политику конфликтов и предварительную проверку свободного места. Добавить проектную документацию, HDD/MAME-сценарии и проверенные артефакты. Расширить libc операцией bank_write_page, исправлением режима O_RDONLY и связанными регрессионными проверками.
86 lines
2.3 KiB
C
86 lines
2.3 KiB
C
/* p11_delete_probe.c — target-регрессия однообъектного F8 delete. */
|
|
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
|
|
static int result_fd = -1;
|
|
static uint8_t failures;
|
|
static char cwd_before[256];
|
|
static char cwd_after[256];
|
|
|
|
static void log_text(const char *text)
|
|
{
|
|
const char *end = text;
|
|
while (*end != '\0') end++;
|
|
if (result_fd >= 0) {
|
|
(void)write(result_fd, text, (uint16_t)(end - text));
|
|
}
|
|
}
|
|
|
|
static void check(uint8_t condition, const char *name)
|
|
{
|
|
log_text(condition ? "PASS " : "FAIL ");
|
|
if (!condition) failures++;
|
|
log_text(name);
|
|
log_text("\r\n");
|
|
}
|
|
|
|
static uint8_t file_has(const char *path, const char *expected)
|
|
{
|
|
char data[24];
|
|
int fd = open(path, O_RDONLY);
|
|
int got;
|
|
uint16_t length = 0u;
|
|
|
|
if (fd < 0) return 0u;
|
|
while (expected[length] != '\0') length++;
|
|
got = read(fd, data, sizeof(data));
|
|
(void)close(fd);
|
|
return got == (int)length && memcmp(data, expected, length) == 0;
|
|
}
|
|
|
|
static uint8_t file_absent(const char *path)
|
|
{
|
|
int fd;
|
|
errno = 0;
|
|
fd = open(path, O_RDONLY);
|
|
if (fd >= 0) {
|
|
(void)close(fd);
|
|
return 0u;
|
|
}
|
|
return errno == ENOENT || errno == ENOPATH;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
int rc;
|
|
|
|
result_fd = open("D:\\DELRES.TXT", O_WRONLY | O_CREAT | O_TRUNC);
|
|
check(getcwd(cwd_before, sizeof(cwd_before)) != 0,
|
|
"CWD captured before delete matrix");
|
|
check(unlink("D:\\DELTEST\\TARGET.TXT") == 0 &&
|
|
file_absent("D:\\DELTEST\\TARGET.TXT"),
|
|
"unlink removes one regular file");
|
|
check(rmdir("D:\\DELTEST\\TEMPDIR") == 0,
|
|
"rmdir removes one empty directory");
|
|
|
|
errno = 0;
|
|
rc = rmdir("D:\\DELTEST\\NONEMPTY");
|
|
check(rc != 0 &&
|
|
file_has("D:\\DELTEST\\NONEMPTY\\CHILD.TXT",
|
|
"child remains\r\n"),
|
|
"nonempty directory is not removed");
|
|
check(file_has("D:\\DELTEST\\KEEP.TXT", "keep remains\r\n"),
|
|
"unrelated file remains intact");
|
|
check(getcwd(cwd_after, sizeof(cwd_after)) != 0 &&
|
|
strcmp(cwd_before, cwd_after) == 0,
|
|
"full-path delete operations preserve CWD");
|
|
|
|
if (failures == 0u) log_text("ALL PASS\r\n");
|
|
if (result_fd >= 0) (void)close(result_fd);
|
|
return failures;
|
|
}
|