File indexing completed on 2025-05-11 08:24:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031
0032 #include "tmacros.h"
0033
0034 #include <sys/stat.h>
0035 #include <errno.h>
0036 #include <string.h>
0037 #include <stdint.h>
0038 #include <unistd.h>
0039 #include <fcntl.h>
0040
0041 #include <rtems/libio.h>
0042 #include <rtems/blkdev.h>
0043 #include <rtems/dosfs.h>
0044 #include <rtems/ramdisk.h>
0045
0046 const char rtems_test_name[] = "FSDOSFSSYNC 1";
0047
0048 static void create_file(const char *file)
0049 {
0050 int fd;
0051 int rv;
0052
0053 fd = creat(file, S_IRWXU | S_IRWXG | S_IRWXO);
0054 rtems_test_assert(fd >= 0);
0055
0056 rv = fsync(fd);
0057 rtems_test_assert(rv == 0);
0058
0059 rv = close(fd);
0060 rtems_test_assert(rv == 0);
0061 }
0062
0063 static void write_to_file(const char *file, bool sync)
0064 {
0065 int fd;
0066 char buf [1];
0067 ssize_t n;
0068 off_t pos;
0069 int rv;
0070
0071 fd = open(file, O_RDWR);
0072 rtems_test_assert(fd >= 0);
0073
0074 n = write(fd, buf, sizeof(buf));
0075 rtems_test_assert(n == (ssize_t) sizeof(buf));
0076
0077 pos = lseek(fd, 0, SEEK_END);
0078 rtems_test_assert(pos == sizeof(buf));
0079
0080 if (sync) {
0081 rv = fsync(fd);
0082 rtems_test_assert(rv == 0);
0083 }
0084
0085 rv = close(fd);
0086 rtems_test_assert(rv == 0);
0087 }
0088
0089 static void check_file_size(const char *file, off_t size)
0090 {
0091 int fd;
0092 off_t pos;
0093 int rv;
0094
0095 fd = open(file, O_RDWR);
0096 rtems_test_assert(fd >= 0);
0097
0098 pos = lseek(fd, 0, SEEK_END);
0099 rtems_test_assert(pos == size);
0100
0101 rv = close(fd);
0102 rtems_test_assert(rv == 0);
0103 }
0104
0105 static void test(const char *rda, const char *mnt, const char *file)
0106 {
0107 static const msdos_format_request_param_t rqdata = {
0108 .quick_format = true,
0109 .sync_device = true
0110 };
0111
0112 int disk_fd;
0113 int rv;
0114
0115 disk_fd = open(rda, O_RDWR);
0116 rtems_test_assert(disk_fd >= 0);
0117
0118 rv = msdos_format(rda, &rqdata);
0119 rtems_test_assert(rv == 0);
0120
0121 rv = mount_and_make_target_path(
0122 rda,
0123 mnt,
0124 RTEMS_FILESYSTEM_TYPE_DOSFS,
0125 RTEMS_FILESYSTEM_READ_WRITE,
0126 NULL
0127 );
0128 rtems_test_assert(rv == 0);
0129
0130 create_file(file);
0131 rv = rtems_disk_fd_purge(disk_fd);
0132 rtems_test_assert(rv == 0);
0133
0134 write_to_file(file, false);
0135 rv = rtems_disk_fd_purge(disk_fd);
0136 rtems_test_assert(rv == 0);
0137 check_file_size(file, 0);
0138
0139 write_to_file(file, true);
0140 rv = rtems_disk_fd_purge(disk_fd);
0141 rtems_test_assert(rv == 0);
0142 check_file_size(file, 1);
0143
0144 rv = unmount(mnt);
0145 rtems_test_assert(rv == 0);
0146
0147 rv = close(disk_fd);
0148 rtems_test_assert(rv == 0);
0149 }
0150
0151 static void Init(rtems_task_argument arg)
0152 {
0153 TEST_BEGIN();
0154
0155 test("/dev/rda", "/mnt", "/mnt/file");
0156
0157 TEST_END();
0158 rtems_test_exit(0);
0159 }
0160
0161 rtems_ramdisk_config rtems_ramdisk_configuration [] = {
0162 { .block_size = 512, .block_num = 1024 }
0163 };
0164
0165 size_t rtems_ramdisk_configuration_size = 1;
0166
0167 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0168 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0169 #define CONFIGURE_APPLICATION_EXTRA_DRIVERS RAMDISK_DRIVER_TABLE_ENTRY
0170 #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
0171
0172 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 6
0173
0174 #define CONFIGURE_FILESYSTEM_DOSFS
0175
0176 #define CONFIGURE_MAXIMUM_TASKS 2
0177
0178 #define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024)
0179
0180 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0181
0182 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0183
0184 #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
0185
0186 #define CONFIGURE_INIT
0187
0188 #include <rtems/confdefs.h>