source: rtems/c/src/lib/include/rtems/libio_.h @ 07a3253d

4.104.114.84.95
Last change on this file since 07a3253d was 07a3253d, checked in by Joel Sherrill <joel.sherrill@…>, on 11/23/98 at 19:07:58

Added base version of file system infrastructure. This includes a major
overhaul of the RTEMS system call interface. This base file system is
the "In-Memory File System" aka IMFS.

The design and implementation was done by the following people:

+ Joel Sherrill (joel@…)
+ Jennifer Averett (jennifer@…)
+ Steve "Mr Mount" Salitasc (salitasc@…)
+ Kerwin Wade (wade@…)

PROBLEMS
========

+ It is VERY likely that merging this will break the UNIX port. This

can/will be fixed.

+ There is likely some reentrancy/mutual exclusion needed.

+ Eventually, there should be a "mini-IMFS" description table to

eliminate links, symlinks, etc to save memory. All you need to
have "classic RTEMS" functionality is technically directories
and device IO. All the rest could be left out to save memory.

  • Property mode set to 100644
File size: 6.2 KB
Line 
1/*
2 *  Libio Internal Information
3 *
4 *  COPYRIGHT (c) 1989-1998.
5 *  On-Line Applications Research Corporation (OAR).
6 *  Copyright assigned to U.S. Government, 1994.
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#ifndef __LIBIO__h
16#define __LIBIO__h
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#include <rtems.h>
23#include <rtems/assoc.h>                /* assoc.h not included by rtems.h */
24#include <rtems/libio.h>
25
26#include <stdio.h>                      /* O_RDONLY, et.al. */
27#include <fcntl.h>                      /* O_RDONLY, et.al. */
28#include <assert.h>
29#include <stdarg.h>
30
31#if ! defined(O_NDELAY)
32# if defined(solaris2)
33#  define O_NDELAY O_NONBLOCK
34# elif defined(RTEMS_NEWLIB)
35#  define O_NDELAY _FNBIO
36# endif
37#endif
38
39#include <errno.h>
40#include <string.h>                     /* strcmp */
41#include <unistd.h>
42#include <stdlib.h>                     /* calloc() */
43
44#include "libio.h"                      /* libio.h not pulled in by rtems */
45
46
47/*
48 *  Semaphore to protect the io table
49 */
50
51#define RTEMS_LIBIO_SEM         rtems_build_name('L', 'B', 'I', 'O')
52#define RTEMS_LIBIO_IOP_SEM(n)  rtems_build_name('L', 'B', 'I', n)
53
54extern rtems_id        rtems_libio_semaphore;
55
56/*
57 *  File descriptor Table Information
58 */
59
60extern unsigned32      rtems_libio_number_iops;
61extern rtems_libio_t  *rtems_libio_iops;
62extern rtems_libio_t  *rtems_libio_last_iop;
63
64/*
65 *  External I/O Handlers Table
66 *
67 *  Space for all possible handlers is preallocated
68 *  to speed up dispatch to external handlers.
69 */
70
71extern rtems_libio_handler_t   rtems_libio_handlers[15];
72
73/*
74 *  Default mode for all files.
75 */
76
77extern mode_t    rtems_filesystem_umask;
78
79/*
80 *  set_errno_and_return_minus_one
81 *
82 *  Macro to ease common way to return an error.
83 */
84
85#ifndef set_errno_and_return_minus_one
86#define set_errno_and_return_minus_one( _error ) \
87  do { errno = (_error); return -1; } while(0)
88#endif
89
90/*
91 *  rtems_libio_iop
92 *
93 *  Macro to return the file descriptor pointer.
94 */
95
96#define rtems_libio_iop(_fd) \
97  ((((unsigned32)(_fd)) < rtems_libio_number_iops) ? \
98         &rtems_libio_iops[_fd] : 0)
99
100/*
101 *  rtems_libio_check_fd
102 *
103 *  Macro to check if a file descriptor number is valid.
104 */
105
106#define rtems_libio_check_fd(_fd) \
107  do {                                                     \
108      if ((unsigned32) (_fd) >= rtems_libio_number_iops) { \
109          errno = EBADF;                                   \
110          return -1;                                       \
111      }                                                    \
112  } while (0)
113
114/*
115 *  rtems_libio_check_fd
116 *
117 *  Macro to check if a buffer pointer is valid.
118 */
119
120#define rtems_libio_check_buffer(_buffer) \
121  do {                                    \
122      if ((_buffer) == 0) {               \
123          errno = EINVAL;                 \
124          return -1;                      \
125      }                                   \
126  } while (0)
127
128/*
129 *  rtems_libio_check_count
130 *
131 *  Macro to check if a count or length is valid.
132 */
133
134#define rtems_libio_check_count(_count) \
135  do {                                  \
136      if ((_count) == 0) {              \
137          return 0;                     \
138      }                                 \
139  } while (0)
140
141/*
142 *  rtems_libio_check_permissions
143 *
144 *  Macro to check if a file descriptor is open for this operation.
145 */
146
147#define rtems_libio_check_permissions(_iop, _flag)    \
148  do {                                                \
149      if (((_iop)->flags & (_flag)) == 0) {           \
150            set_errno_and_return_minus_one( EINVAL ); \
151            return -1;                                \
152      }                                               \
153  } while (0)
154
155/*
156 *  rtems_filesystem_is_separator
157 *
158 *  Macro to determine if a character is a path name separator.
159 *
160 *  NOTE:  This macro handles MS-DOS and UNIX style names.
161 */
162
163#define rtems_filesystem_is_separator( _ch ) \
164   ( ((_ch) == '/') || ((_ch) == '\\') || ((_ch) == '\0'))
165
166/*
167 *  rtems_filesystem_get_start_loc
168 *
169 *  Macro to determine if path is absolute or relative.
170 */
171
172#define rtems_filesystem_get_start_loc( _path, _index, _loc )  \
173  do {                                                         \
174    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
175      *(_loc) = rtems_filesystem_root;                         \
176      *(_index) = 1;                                           \
177    } else {                                                   \
178      *(_loc) = rtems_filesystem_current;                      \
179      *(_index) = 0;                                           \
180    }                                                          \
181  } while (0)
182
183#define rtems_filesystem_get_sym_start_loc( _path, _index, _loc )  \
184  do {                                                         \
185    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
186      *(_loc) = rtems_filesystem_root;                         \
187      *(_index) = 1;                                           \
188    } else {                                                   \
189      *(_index) = 0;                                           \
190    }                                                          \
191  } while (0)
192
193
194/*
195 *  External structures
196 */
197
198extern rtems_filesystem_location_info_t rtems_filesystem_current;
199extern rtems_filesystem_location_info_t rtems_filesystem_root;
200extern nlink_t                          rtems_filesystem_link_counts;
201
202
203/*
204 *  File Descriptor Routine Prototypes
205 */
206
207rtems_libio_t *rtems_libio_allocate(void);
208
209unsigned32 rtems_libio_fcntl_flags(
210  unsigned32 fcntl_flags
211);
212
213void rtems_libio_free(
214  rtems_libio_t *iop
215);
216
217int rtems_libio_is_open_files_in_fs(
218  rtems_filesystem_mount_table_entry_t *mt_entry
219);
220
221int rtems_libio_is_file_open(
222  void  *node_access
223);
224
225/*
226 *  File System Routine Prototypes
227 */
228
229int rtems_filesystem_evaluate_path(
230  const char                        *pathname,
231  int                                flags,
232  rtems_filesystem_location_info_t  *pathloc,
233  int                                follow_link
234);
235
236void rtems_filesystem_initialize();
237
238int init_fs_mount_table();
239
240#ifdef __cplusplus
241}
242#endif
243
244#endif
245/* end of include file */
246
247
248
Note: See TracBrowser for help on using the repository browser.