source: rtems/testsuites/fstests/fsrofs01/init.c @ 3ba4f828

4.115
Last change on this file since 3ba4f828 was 3ba4f828, checked in by Sebastian Huber <sebastian.huber@…>, on 03/02/12 at 09:18:10

Filesystem: Read-only file system checks

o Make sure EROFS is indicated for write operations on a read-only file

system.

o Add error indication for read-only file systems in fchmod() and

fchown() according to POSIX.

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[3ba4f828]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 <fcntl.h>
23#include <errno.h>
24#include <unistd.h>
25#include <stdio.h>
26
27#include <rtems/libio.h>
28#include <rtems/rtems-rfs-format.h>
29#include <rtems/ramdisk.h>
30
31static const rtems_rfs_format_config rfs_config;
32
33static const char rda [] = "/dev/rda";
34
35static const char mnt [] = "/mnt";
36
37static const char file [] = "/mnt/file";
38
39static const char not_exist [] = "/mnt/not_exist";
40
41static void test_mount(bool writeable)
42{
43  int rv;
44  const void *data = NULL;
45
46  rv = mount(
47    rda,
48    mnt,
49    RTEMS_FILESYSTEM_TYPE_RFS,
50    writeable ? RTEMS_FILESYSTEM_READ_WRITE : 0,
51    data
52  );
53  rtems_test_assert(rv == 0);
54}
55
56static void test_create_file_system(void)
57{
58  int rv;
59
60  rv = mkdir(mnt, S_IRWXU | S_IRWXG | S_IRWXO);
61  rtems_test_assert(rv == 0);
62
63  rv = rtems_rfs_format(rda, &rfs_config);
64  rtems_test_assert(rv == 0);
65
66  test_mount(true);
67
68  rv = mknod(file, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0);
69  rtems_test_assert(rv == 0);
70
71  rv = unmount(mnt);
72  rtems_test_assert(rv == 0);
73}
74
75static void test_rofs(void)
76{
77  int rv;
78  int fd;
79  char buf [1];
80  ssize_t n;
81
82  test_mount(false);
83
84  fd = open(file, O_RDONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
85  rtems_test_assert(fd >= 0);
86
87  n = read(fd, buf, sizeof(buf));
88  rtems_test_assert(n == 0);
89
90  errno = 0;
91  n = write(fd, buf, sizeof(buf));
92  rtems_test_assert(n == -1);
93  rtems_test_assert(errno == EBADF);
94
95  errno = 0;
96  rv = ftruncate(fd, 0);
97  rtems_test_assert(rv == -1);
98  rtems_test_assert(errno == EINVAL);
99
100  errno = 0;
101  rv = fchmod(fd, 0);
102  rtems_test_assert(rv == -1);
103  rtems_test_assert(errno == EROFS);
104
105  errno = 0;
106  rv = fchown(fd, 0, 0);
107  rtems_test_assert(rv == -1);
108  rtems_test_assert(errno == EROFS);
109
110  rv = close(fd);
111  rtems_test_assert(rv == 0);
112
113  errno = 0;
114  fd = open(not_exist, O_RDONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
115  rtems_test_assert(fd == -1);
116  rtems_test_assert(errno == EROFS);
117
118  errno = 0;
119  rv = mknod(not_exist, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0);
120  rtems_test_assert(rv == -1);
121  rtems_test_assert(errno == EROFS);
122
123  errno = 0;
124  rv = mkdir(not_exist, S_IRWXU | S_IRWXG | S_IRWXO);
125  rtems_test_assert(rv == -1);
126  rtems_test_assert(errno == EROFS);
127
128  errno = 0;
129  rv = rename(file, not_exist);
130  rtems_test_assert(rv == -1);
131  rtems_test_assert(errno == EROFS);
132
133  errno = 0;
134  rv = link(file, not_exist);
135  rtems_test_assert(rv == -1);
136  rtems_test_assert(errno == EROFS);
137
138  errno = 0;
139  rv = unlink(file);
140  rtems_test_assert(rv == -1);
141  rtems_test_assert(errno == EROFS);
142
143  errno = 0;
144  rv = symlink(file, not_exist);
145  rtems_test_assert(rv == -1);
146  rtems_test_assert(errno == EROFS);
147
148  rv = unmount(mnt);
149  rtems_test_assert(rv == 0);
150}
151
152static void Init(rtems_task_argument arg)
153{
154  printf("\n\n*** TEST FSROFS 1 ***\n");
155
156  test_create_file_system();
157  test_rofs();
158
159  printf("*** END OF TEST FSROFS 1 ***\n");
160
161  rtems_test_exit(0);
162}
163
164rtems_ramdisk_config rtems_ramdisk_configuration [] = {
165  { .block_size = 512, .block_num = 1024 }
166};
167
168size_t rtems_ramdisk_configuration_size = 1;
169
170#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
171#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
172#define CONFIGURE_APPLICATION_EXTRA_DRIVERS RAMDISK_DRIVER_TABLE_ENTRY
173#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
174
175#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
176
177#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
178#define CONFIGURE_FILESYSTEM_RFS
179
180#define CONFIGURE_MAXIMUM_TASKS 2
181
182#define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024)
183
184#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
185
186#define CONFIGURE_INIT
187
188#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.