source: rtems/testsuites/fstests/fsdosfssync01/init.c @ 60e8cd4

4.115
Last change on this file since 60e8cd4 was 86ef0df, checked in by Sebastian Huber <sebastian.huber@…>, on 05/09/12 at 12:33:51

dosfs: Remove fat_file_datasync()

The fat_file_datasync() read every cluster of the file into the cache
and then synchronized it step-by-step. For unmodified buffers this is a
non-operation. For modified buffers this will wake-up the swapout task
which performs then a single buffer write operation. This is usually
quite inefficient. Firstly we do single buffer writes, secondly we
may perform a lot of unnecessary read operations (for huge files this is
really bad), and thirdly this leads likely to cache evictions.

The synchronization procedure is replaced by a simple
rtems_bdbuf_sync_dev(). This has the side-effect that also buffers not
related to the file are synchronized, but since the modified list is
normally short this should be acceptable.

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Obere Lagerstr. 30
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.com/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include "tmacros.h"
20
21#include <sys/stat.h>
22#include <errno.h>
23#include <string.h>
24#include <stdint.h>
25#include <unistd.h>
26#include <fcntl.h>
27
28#include <rtems/libio.h>
29#include <rtems/blkdev.h>
30#include <rtems/dosfs.h>
31#include <rtems/ramdisk.h>
32
33static void create_file(const char *file)
34{
35  int fd;
36  int rv;
37
38  fd = creat(file, S_IRWXU | S_IRWXG | S_IRWXO);
39  rtems_test_assert(fd >= 0);
40
41  rv = fsync(fd);
42  rtems_test_assert(rv == 0);
43
44  rv = close(fd);
45  rtems_test_assert(rv == 0);
46}
47
48static void write_to_file(const char *file, bool sync)
49{
50  int fd;
51  char buf [1];
52  ssize_t n;
53  off_t pos;
54  int rv;
55
56  fd = open(file, O_RDWR);
57  rtems_test_assert(fd >= 0);
58
59  n = write(fd, buf, sizeof(buf));
60  rtems_test_assert(n == (ssize_t) sizeof(buf));
61
62  pos = lseek(fd, 0, SEEK_END);
63  rtems_test_assert(pos == sizeof(buf));
64
65  if (sync) {
66    rv = fsync(fd);
67    rtems_test_assert(rv == 0);
68  }
69
70  rv = close(fd);
71  rtems_test_assert(rv == 0);
72}
73
74static void check_file_size(const char *file, off_t size)
75{
76  int fd;
77  off_t pos;
78  int rv;
79
80  fd = open(file, O_RDWR);
81  rtems_test_assert(fd >= 0);
82
83  pos = lseek(fd, 0, SEEK_END);
84  rtems_test_assert(pos == size);
85
86  rv = close(fd);
87  rtems_test_assert(rv == 0);
88}
89
90static void test(const char *rda, const char *mnt, const char *file)
91{
92  rtems_status_code sc;
93  int disk_fd;
94  int rv;
95
96  sc = rtems_disk_io_initialize();
97  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
98
99  disk_fd = open(rda, O_RDWR);
100  rtems_test_assert(disk_fd >= 0);
101
102  rv = msdos_format(rda, NULL);
103  rtems_test_assert(rv == 0);
104
105  rv = mount_and_make_target_path(
106    rda,
107    mnt,
108    RTEMS_FILESYSTEM_TYPE_DOSFS,
109    RTEMS_FILESYSTEM_READ_WRITE,
110    NULL
111  );
112  rtems_test_assert(rv == 0);
113
114  create_file(file);
115  rv = rtems_disk_fd_purge(disk_fd);
116  rtems_test_assert(rv == 0);
117
118  write_to_file(file, false);
119  rv = rtems_disk_fd_purge(disk_fd);
120  rtems_test_assert(rv == 0);
121  check_file_size(file, 0);
122
123  write_to_file(file, true);
124  rv = rtems_disk_fd_purge(disk_fd);
125  rtems_test_assert(rv == 0);
126  check_file_size(file, 1);
127
128  rv = unmount(mnt);
129  rtems_test_assert(rv == 0);
130
131  rv = close(disk_fd);
132  rtems_test_assert(rv == 0);
133}
134
135static void Init(rtems_task_argument arg)
136{
137  puts("\n\n*** TEST FSDOSFSSYNC 1 ***");
138
139  test("/dev/rda", "/mnt", "/mnt/file");
140
141  puts("*** END OF TEST FSDOSFSSYNC 1 ***");
142
143  rtems_test_exit(0);
144}
145
146rtems_ramdisk_config rtems_ramdisk_configuration [] = {
147  { .block_size = 512, .block_num = 1024 }
148};
149
150size_t rtems_ramdisk_configuration_size = 1;
151
152#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
153#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
154#define CONFIGURE_APPLICATION_EXTRA_DRIVERS RAMDISK_DRIVER_TABLE_ENTRY
155#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
156
157#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
158
159#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
160
161#define CONFIGURE_FILESYSTEM_DOSFS
162
163#define CONFIGURE_MAXIMUM_TASKS 2
164
165#define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024)
166
167#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
168
169#define CONFIGURE_INIT
170
171#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.