RTEMS
libio.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 
11 /*
12  * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef _RTEMS_CONFDEFS_LIBIO_H
37 #define _RTEMS_CONFDEFS_LIBIO_H
38 
39 #ifndef __CONFIGURATION_TEMPLATE_h
40 #error "Do not include this file directly, use <rtems/confdefs.h> instead"
41 #endif
42 
43 #ifdef CONFIGURE_INIT
44 
45 #include <rtems/confdefs/bsp.h>
46 #include <rtems/sysinit.h>
47 
48 #ifdef CONFIGURE_FILESYSTEM_ALL
49  #define CONFIGURE_FILESYSTEM_DOSFS
50  #define CONFIGURE_FILESYSTEM_FTPFS
51  #define CONFIGURE_FILESYSTEM_IMFS
52  #define CONFIGURE_FILESYSTEM_JFFS2
53  #define CONFIGURE_FILESYSTEM_NFS
54  #define CONFIGURE_FILESYSTEM_RFS
55  #define CONFIGURE_FILESYSTEM_TFTPFS
56 #endif
57 
58 #ifdef CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM
59  #ifdef CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
60  #error "CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM cannot be used together with CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM"
61  #endif
62 
63  #define CONFIGURE_IMFS_DISABLE_CHMOD
64  #define CONFIGURE_IMFS_DISABLE_CHOWN
65  #define CONFIGURE_IMFS_DISABLE_LINK
66  #define CONFIGURE_IMFS_DISABLE_READLINK
67  #define CONFIGURE_IMFS_DISABLE_RENAME
68  #define CONFIGURE_IMFS_DISABLE_SYMLINK
69  #define CONFIGURE_IMFS_DISABLE_UNMOUNT
70  #define CONFIGURE_IMFS_DISABLE_UTIME
71 #endif
72 
73 #ifdef CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
74  #define CONFIGURE_IMFS_DISABLE_CHMOD
75  #define CONFIGURE_IMFS_DISABLE_CHOWN
76  #define CONFIGURE_IMFS_DISABLE_LINK
77  #define CONFIGURE_IMFS_DISABLE_MKNOD_FILE
78  #define CONFIGURE_IMFS_DISABLE_MOUNT
79  #define CONFIGURE_IMFS_DISABLE_READDIR
80  #define CONFIGURE_IMFS_DISABLE_READLINK
81  #define CONFIGURE_IMFS_DISABLE_RENAME
82  #define CONFIGURE_IMFS_DISABLE_RMNOD
83  #define CONFIGURE_IMFS_DISABLE_SYMLINK
84  #define CONFIGURE_IMFS_DISABLE_UNMOUNT
85  #define CONFIGURE_IMFS_DISABLE_UTIME
86 #endif
87 
88 #ifndef CONFIGURE_MAXIMUM_FILE_DESCRIPTORS
89  #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 3
90 #endif
91 
92 #if !defined(CONFIGURE_APPLICATION_DISABLE_FILESYSTEM) || \
93  CONFIGURE_MAXIMUM_FILE_DESCRIPTORS > 0
94  #include <rtems/libio.h>
95 #endif
96 
97 #ifdef CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
98  #ifdef CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
99  #error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM"
100  #endif
101 
102  #ifdef CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM
103  #error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM"
104  #endif
105 
106  #ifdef CONFIGURE_FILESYSTEM_DOSFS
107  #error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_FILESYSTEM_DOSFS"
108  #endif
109 
110  #ifdef CONFIGURE_FILESYSTEM_FTPFS
111  #error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_FILESYSTEM_FTPFS"
112  #endif
113 
114  #ifdef CONFIGURE_FILESYSTEM_IMFS
115  #error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_FILESYSTEM_IMFS"
116  #endif
117 
118  #ifdef CONFIGURE_FILESYSTEM_JFFS2
119  #error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_FILESYSTEM_JFFS2"
120  #endif
121 
122  #ifdef CONFIGURE_FILESYSTEM_NFS
123  #error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_FILESYSTEM_NFS"
124  #endif
125 
126  #ifdef CONFIGURE_FILESYSTEM_RFS
127  #error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_FILESYSTEM_RFS"
128  #endif
129 
130  #ifdef CONFIGURE_FILESYSTEM_TFTPFS
131  #error "CONFIGURE_APPLICATION_DISABLE_FILESYSTEM cannot be used together with CONFIGURE_FILESYSTEM_TFTPFS"
132  #endif
133 #else
134  #include <rtems/imfs.h>
135 #endif
136 
137 #ifdef CONFIGURE_FILESYSTEM_DOSFS
138 #include <rtems/dosfs.h>
139 #endif
140 
141 #ifdef CONFIGURE_FILESYSTEM_FTPFS
142 #include <rtems/ftpfs.h>
143 #endif
144 
145 #ifdef CONFIGURE_FILESYSTEM_JFFS2
146 #include <rtems/jffs2.h>
147 #endif
148 
149 #ifdef CONFIGURE_FILESYSTEM_NFS
150 #include <librtemsNfs.h>
151 #endif
152 
153 #ifdef CONFIGURE_FILESYSTEM_RFS
154 #include <rtems/rtems-rfs.h>
155 #endif
156 
157 #ifdef CONFIGURE_FILESYSTEM_TFTPFS
158 #include <rtems/tftp.h>
159 #endif
160 
161 #ifdef __cplusplus
162 extern "C" {
163 #endif
164 
165 #ifndef CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
166 
167 #ifndef CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK
168  #define CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK \
169  IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK
170 #endif
171 
172 #if CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK != 16 && \
173  CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK != 32 && \
174  CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK != 64 && \
175  CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK != 128 && \
176  CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK != 256 && \
177  CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK != 512
178  #error "CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK must be a power of two between 16 and 512"
179 #endif
180 
181 const int imfs_memfile_bytes_per_block = CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK;
182 
183 static IMFS_fs_info_t IMFS_root_fs_info;
184 
185 static const rtems_filesystem_operations_table IMFS_root_ops = {
188  #ifdef CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
189  IMFS_eval_path_devfs,
190  #else
191  IMFS_eval_path,
192  #endif
193  #ifdef CONFIGURE_IMFS_DISABLE_LINK
195  #else
196  IMFS_link,
197  #endif
199  #ifdef CONFIGURE_IMFS_DISABLE_MKNOD
201  #else
202  IMFS_mknod,
203  #endif
204  #ifdef CONFIGURE_IMFS_DISABLE_RMNOD
206  #else
207  IMFS_rmnod,
208  #endif
209  #ifdef CONFIGURE_IMFS_DISABLE_CHMOD
211  #else
212  IMFS_fchmod,
213  #endif
214  #ifdef CONFIGURE_IMFS_DISABLE_CHOWN
216  #else
217  IMFS_chown,
218  #endif
219  IMFS_node_clone,
220  IMFS_node_free,
221  #ifdef CONFIGURE_IMFS_DISABLE_MOUNT
223  #else
224  IMFS_mount,
225  #endif
226  #ifdef CONFIGURE_IMFS_DISABLE_UNMOUNT
228  #else
229  IMFS_unmount,
230  #endif
232  #ifdef CONFIGURE_IMFS_DISABLE_UTIME
234  #else
235  IMFS_utime,
236  #endif
237  #ifdef CONFIGURE_IMFS_DISABLE_SYMLINK
239  #else
240  IMFS_symlink,
241  #endif
242  #ifdef CONFIGURE_IMFS_DISABLE_READLINK
244  #else
245  IMFS_readlink,
246  #endif
247  #ifdef CONFIGURE_IMFS_DISABLE_RENAME
249  #else
250  IMFS_rename,
251  #endif
253 };
254 
255 static const IMFS_mknod_controls IMFS_root_mknod_controls = {
256  #ifdef CONFIGURE_IMFS_DISABLE_READDIR
257  &IMFS_mknod_control_dir_minimal,
258  #else
259  &IMFS_mknod_control_dir_default,
260  #endif
261  #ifdef CONFIGURE_IMFS_DISABLE_MKNOD_DEVICE
262  &IMFS_mknod_control_enosys,
263  #else
264  &IMFS_mknod_control_device,
265  #endif
266  #ifdef CONFIGURE_IMFS_DISABLE_MKNOD_FILE
267  &IMFS_mknod_control_enosys,
268  #else
269  &IMFS_mknod_control_memfile,
270  #endif
271  #ifdef CONFIGURE_IMFS_ENABLE_MKFIFO
272  &IMFS_mknod_control_fifo
273  #else
274  &IMFS_mknod_control_enosys
275  #endif
276 };
277 
278 static const IMFS_mount_data IMFS_root_mount_data = {
279  &IMFS_root_fs_info,
280  &IMFS_root_ops,
281  &IMFS_root_mknod_controls
282 };
283 
285  { "/", IMFS_initialize_support },
286  #ifdef CONFIGURE_FILESYSTEM_DOSFS
287  { RTEMS_FILESYSTEM_TYPE_DOSFS, rtems_dosfs_initialize },
288  #endif
289  #ifdef CONFIGURE_FILESYSTEM_FTPFS
290  { RTEMS_FILESYSTEM_TYPE_FTPFS, rtems_ftpfs_initialize },
291  #endif
292  #ifdef CONFIGURE_FILESYSTEM_IMFS
293  { RTEMS_FILESYSTEM_TYPE_IMFS, IMFS_initialize },
294  #endif
295  #ifdef CONFIGURE_FILESYSTEM_JFFS2
296  { RTEMS_FILESYSTEM_TYPE_JFFS2, rtems_jffs2_initialize },
297  #endif
298  #ifdef CONFIGURE_FILESYSTEM_NFS
299  { RTEMS_FILESYSTEM_TYPE_NFS, rtems_nfs_initialize },
300  #endif
301  #ifdef CONFIGURE_FILESYSTEM_RFS
302  { RTEMS_FILESYSTEM_TYPE_RFS, rtems_rfs_rtems_initialise },
303  #endif
304  #ifdef CONFIGURE_FILESYSTEM_TFTPFS
305  { RTEMS_FILESYSTEM_TYPE_TFTPFS, rtems_tftpfs_initialize },
306  #endif
307  { NULL, NULL }
308 };
309 
311 rtems_filesystem_root_configuration = {
312  NULL,
313  NULL,
314  "/",
315  RTEMS_FILESYSTEM_READ_WRITE,
316  &IMFS_root_mount_data
317 };
318 
319 RTEMS_SYSINIT_ITEM(
321  RTEMS_SYSINIT_ROOT_FILESYSTEM,
322  RTEMS_SYSINIT_ORDER_MIDDLE
323 );
324 
325 #endif /* !CONFIGURE_APPLICATION_DISABLE_FILESYSTEM */
326 
327 #if CONFIGURE_MAXIMUM_FILE_DESCRIPTORS > 0
329 
330  const uint32_t rtems_libio_number_iops = RTEMS_ARRAY_SIZE( rtems_libio_iops );
331 #endif
332 
333 #ifdef __cplusplus
334 }
335 #endif
336 
337 #endif /* CONFIGURE_INIT */
338 
339 #endif /* _RTEMS_CONFDEFS_LIBIO_H */
void rtems_filesystem_initialize(void)
Base File System Initialization.
int rtems_filesystem_default_utime(const rtems_filesystem_location_info_t *loc, time_t actime, time_t modtime)
#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS
This configuration option is an integer define.
Definition: appl-config.h:2658
bool rtems_filesystem_default_are_nodes_equal(const rtems_filesystem_location_info_t *a, const rtems_filesystem_location_info_t *b)
Tests if the node access pointer of one location is equal to the node access pointer of the other loc...
int rtems_filesystem_default_link(const rtems_filesystem_location_info_t *parentloc, const rtems_filesystem_location_info_t *targetloc, const char *name, size_t namelen)
Basic IO API.
const rtems_filesystem_table_t rtems_filesystem_table[]
Static table of file systems.
int rtems_filesystem_default_unmount(rtems_filesystem_mount_table_entry_t *mt_entry)
void rtems_filesystem_default_unlock(const rtems_filesystem_mount_table_entry_t *mt_entry)
Releases the IO library mutex.
File system table entry.
Definition: libio.h:1656
ssize_t rtems_filesystem_default_readlink(const rtems_filesystem_location_info_t *loc, char *buf, size_t bufsize)
int rtems_filesystem_default_fchmod(const rtems_filesystem_location_info_t *loc, mode_t mode)
int rtems_filesystem_default_symlink(const rtems_filesystem_location_info_t *parentloc, const char *name, size_t namelen, const char *target)
int rtems_filesystem_default_rmnod(const rtems_filesystem_location_info_t *parentloc, const rtems_filesystem_location_info_t *loc)
#define CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK
This configuration option is an integer define.
Definition: appl-config.h:2322
File system operations table.
Definition: libio.h:472
int rtems_filesystem_default_mount(rtems_filesystem_mount_table_entry_t *mt_entry)
Evaluate BSP Related Configuration Options.
void rtems_filesystem_default_fsunmount(rtems_filesystem_mount_table_entry_t *mt_entry)
#define RTEMS_ARRAY_SIZE(_array)
Returns the element count of the specified array.
Definition: basedefs.h:459
int rtems_filesystem_default_statvfs(const rtems_filesystem_location_info_t *loc, struct statvfs *buf)
An open file data structure.
Definition: libio.h:1320
int rtems_filesystem_default_rename(const rtems_filesystem_location_info_t *oldparentloc, const rtems_filesystem_location_info_t *oldloc, const rtems_filesystem_location_info_t *newparentloc, const char *name, size_t namelen)
int rtems_filesystem_default_mknod(const rtems_filesystem_location_info_t *parentloc, const char *name, size_t namelen, mode_t mode, dev_t dev)
int rtems_filesystem_default_chown(const rtems_filesystem_location_info_t *loc, uid_t owner, gid_t group)
void rtems_filesystem_default_lock(const rtems_filesystem_mount_table_entry_t *mt_entry)
Obtains the IO library mutex.