source: rtems/c/src/lib/libc/libio_.h @ 458bd34

4.104.114.84.95
Last change on this file since 458bd34 was 51435fc7, checked in by Joel Sherrill <joel.sherrill@…>, on 10/12/99 at 19:26:37

Split null handlers table to own file and renamed.

Renamed IMFS handler tables to include IMFS prefix.

  • Property mode set to 100644
File size: 6.9 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/libio.h>                /* include before standard IO */
24#include <rtems/assoc.h>                /* assoc.h not included by rtems.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#include <errno.h>
31
32#if ! defined(O_NDELAY)
33# if defined(solaris2)
34#  define O_NDELAY O_NONBLOCK
35# elif defined(RTEMS_NEWLIB)
36#  define O_NDELAY _FNBIO
37# endif
38#endif
39
40#if !defined(ENOTSUP)
41#define ENOTSUP EOPNOTSUPP
42#endif
43
44#include <errno.h>
45#include <string.h>                     /* strcmp */
46#include <unistd.h>
47#include <stdlib.h>                     /* calloc() */
48
49/*
50 *  Semaphore to protect the io table
51 */
52
53#define RTEMS_LIBIO_SEM         rtems_build_name('L', 'B', 'I', 'O')
54#define RTEMS_LIBIO_IOP_SEM(n)  rtems_build_name('L', 'B', 'I', n)
55
56extern rtems_id                          rtems_libio_semaphore;
57extern rtems_filesystem_file_handlers_r  rtems_filesystem_null_handlers;
58
59/*
60 *  File descriptor Table Information
61 */
62
63extern unsigned32      rtems_libio_number_iops;
64extern rtems_libio_t  *rtems_libio_iops;
65extern rtems_libio_t  *rtems_libio_last_iop;
66extern rtems_libio_t *rtems_libio_iop_freelist;
67
68/*
69 *  Default mode for all files.
70 */
71
72extern mode_t    rtems_filesystem_umask;
73
74/*
75 *  set_errno_and_return_minus_one
76 *
77 *  Macro to ease common way to return an error.
78 */
79
80#ifndef set_errno_and_return_minus_one
81#define set_errno_and_return_minus_one( _error ) \
82  do { errno = (_error); return -1; } while(0)
83#endif
84
85/*
86 *  rtems_libio_iop
87 *
88 *  Macro to return the file descriptor pointer.
89 */
90
91#define rtems_libio_iop(_fd) \
92  ((((unsigned32)(_fd)) < rtems_libio_number_iops) ? \
93         &rtems_libio_iops[_fd] : 0)
94
95/* 
96 *  rtems_libio_check_is_open
97 * 
98 *  Macro to check if a file descriptor is actually open.
99 */
100
101#define rtems_libio_check_is_open(_iop) \
102  do {                                               \
103      if (((_iop)->flags & LIBIO_FLAGS_OPEN) == 0) { \
104          errno = EBADF;                             \
105          return -1;                                 \
106      }                                              \
107  } while (0)
108
109/*
110 *  rtems_libio_check_fd
111 *
112 *  Macro to check if a file descriptor number is valid.
113 */
114
115#define rtems_libio_check_fd(_fd) \
116  do {                                                     \
117      if ((unsigned32) (_fd) >= rtems_libio_number_iops) { \
118          errno = EBADF;                                   \
119          return -1;                                       \
120      }                                                    \
121  } while (0)
122
123/*
124 *  rtems_libio_check_buffer
125 *
126 *  Macro to check if a buffer pointer is valid.
127 */
128
129#define rtems_libio_check_buffer(_buffer) \
130  do {                                    \
131      if ((_buffer) == 0) {               \
132          errno = EINVAL;                 \
133          return -1;                      \
134      }                                   \
135  } while (0)
136
137/*
138 *  rtems_libio_check_count
139 *
140 *  Macro to check if a count or length is valid.
141 */
142
143#define rtems_libio_check_count(_count) \
144  do {                                  \
145      if ((_count) == 0) {              \
146          return 0;                     \
147      }                                 \
148  } while (0)
149
150/*
151 *  rtems_libio_check_permissions
152 *
153 *  Macro to check if a file descriptor is open for this operation.
154 */
155
156#define rtems_libio_check_permissions(_iop, _flag)    \
157  do {                                                \
158      if (((_iop)->flags & (_flag)) == 0) {           \
159            set_errno_and_return_minus_one( EINVAL ); \
160            return -1;                                \
161      }                                               \
162  } while (0)
163
164/*
165 *  rtems_filesystem_freenode
166 *
167 *  Macro to free a node.
168 */
169
170#define rtems_filesystem_freenode( _node ) \
171  do { \
172    if ( (_node)->ops->freenod ) \
173      (*(_node)->ops->freenod)( (_node) ); \
174  } while (0)
175
176/*
177 *  rtems_filesystem_is_separator
178 *
179 *  Macro to determine if a character is a path name separator.
180 *
181 *  NOTE:  This macro handles MS-DOS and UNIX style names.
182 */
183
184#define rtems_filesystem_is_separator( _ch ) \
185   ( ((_ch) == '/') || ((_ch) == '\\') || ((_ch) == '\0'))
186
187/*
188 *  rtems_filesystem_get_start_loc
189 *
190 *  Macro to determine if path is absolute or relative.
191 */
192
193#define rtems_filesystem_get_start_loc( _path, _index, _loc )  \
194  do {                                                         \
195    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
196      *(_loc) = rtems_filesystem_root;                         \
197      *(_index) = 1;                                           \
198    } else {                                                   \
199      *(_loc) = rtems_filesystem_current;                      \
200      *(_index) = 0;                                           \
201    }                                                          \
202  } while (0)
203
204#define rtems_filesystem_get_sym_start_loc( _path, _index, _loc )  \
205  do {                                                         \
206    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
207      *(_loc) = rtems_filesystem_root;                         \
208      *(_index) = 1;                                           \
209    } else {                                                   \
210      *(_index) = 0;                                           \
211    }                                                          \
212  } while (0)
213
214
215/*
216 *  External structures
217 */
218
219extern rtems_filesystem_location_info_t rtems_filesystem_current;
220extern rtems_filesystem_location_info_t rtems_filesystem_root;
221extern nlink_t                          rtems_filesystem_link_counts;
222
223
224/*
225 *  File Descriptor Routine Prototypes
226 */
227
228rtems_libio_t *rtems_libio_allocate(void);
229
230unsigned32 rtems_libio_fcntl_flags(
231  unsigned32 fcntl_flags
232);
233
234unsigned32 rtems_libio_to_fcntl_flags(
235  unsigned32 flags
236);
237
238void rtems_libio_free(
239  rtems_libio_t *iop
240);
241
242int rtems_libio_is_open_files_in_fs(
243  rtems_filesystem_mount_table_entry_t *mt_entry
244);
245
246int rtems_libio_is_file_open(
247  void  *node_access
248);
249
250/*
251 *  File System Routine Prototypes
252 */
253
254int rtems_filesystem_evaluate_path(
255  const char                        *pathname,
256  int                                flags,
257  rtems_filesystem_location_info_t  *pathloc,
258  int                                follow_link
259);
260
261void rtems_filesystem_initialize();
262
263int init_fs_mount_table();
264
265#ifdef __cplusplus
266}
267#endif
268
269#endif
270/* end of include file */
271
272
273
Note: See TracBrowser for help on using the repository browser.