mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-21 16:33:24 +00:00
Add sys_fdatasync and sync_data
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
5edc110f9d
commit
212dd562a0
5
regression/apps/fdatasync/Makefile
Normal file
5
regression/apps/fdatasync/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
include ../test_common.mk
|
||||
|
||||
EXTRA_C_FLAGS := -static
|
49
regression/apps/fdatasync/fdatasync.c
Normal file
49
regression/apps/fdatasync/fdatasync.c
Normal file
@ -0,0 +1,49 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void test_fdatasync_on_fs(const char *directory)
|
||||
{
|
||||
char filepath[256];
|
||||
snprintf(filepath, sizeof(filepath), "%s/test_fdatasync.txt",
|
||||
directory);
|
||||
|
||||
int fd =
|
||||
open(filepath, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
||||
if (fd == -1) {
|
||||
perror("Error opening file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
char *data = "Hello, fdatasync test!\n";
|
||||
if (write(fd, data, strlen(data)) != strlen(data)) {
|
||||
perror("Error writing data");
|
||||
close(fd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (fdatasync(fd) == -1) {
|
||||
perror("Error syncing data");
|
||||
close(fd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Data written and synced on %s\n", directory);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
printf("Usage: %s <directory>\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
test_fdatasync_on_fs(argv[1]);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Reference in New Issue
Block a user