source: rtems/c/src/exec/include/rtems/libio_.h @ 73f6236

4.104.114.84.95
Last change on this file since 73f6236 was 73f6236, checked in by Joel Sherrill <joel.sherrill@…>, on 03/01/99 at 22:40:08

Patch from Eric Norum <eric@…> to eliminate external
IO handlers scheme that was implemented originally just to support
sockets. The file system IO switch is more general and works fine.

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