source: rtems/c/src/exec/include/rtems/libio_.h @ 6ba9c27

4.104.114.84.95
Last change on this file since 6ba9c27 was 8217c40, checked in by Joel Sherrill <joel.sherrill@…>, on 01/04/02 at 17:57:28

2001-12-22 Ralf Corsepius <corsepiu@…>

  • configure.ac: Use AS_IF instead of if/then/else. Add AC_DEFINE_UNQUOTED(RTEMS_UNIX) for RTEMS_CPU==unix. Add AC_DEFINE_UNQUOTED(RTEMS_UNIXLIB) for RTEMS_CPU==unix. Add include/Makefile to CONFIG_FILES. Add AC_ENABLE_MULITLIB. Remove wrapup/rtems, wrapup/itron, wrapup/posix. Remove */optman/Makefile from CONFIG_FILES.
  • Makefile.am: Add include to SUBDIRS.
  • rtems/Makefile.am: Remove optman from SUBDIRS.
  • sapi/Makefile.am: Remove optman from SUBDIRS.
  • include/Makefile.am: New file.
  • include/rtems/bspIo.h: Relocated from lib/include.
  • include/rtems/libio_.h: Relocated from lib/include.
  • Property mode set to 100644
File size: 8.3 KB
Line 
1/*
2 *  Libio Internal Information
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.OARcorp.com/rtems/license.html.
10 *
11 *  $Id$
12 */
13
14#ifndef __RTEMS_LIBIO_INTERNAL__h
15#define __RTEMS_LIBIO_INTERNAL__h
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#include <rtems.h>
22#include <rtems/libio.h>                /* include before standard IO */
23#include <rtems/assoc.h>                /* assoc.h not included by rtems.h */
24
25#include <sys/types.h>                 
26       
27#include <stdio.h>                      /* O_RDONLY, et.al. */
28#include <fcntl.h>                      /* O_RDONLY, et.al. */
29#include <assert.h>
30#include <stdarg.h>
31#include <limits.h>
32#include <errno.h>
33
34#if ! defined(O_NDELAY)
35# if defined(solaris2)
36#  define O_NDELAY O_NONBLOCK
37# elif defined(RTEMS_NEWLIB)
38#  define O_NDELAY _FNBIO
39# endif
40#endif
41
42#if !defined(ENOTSUP)
43#define ENOTSUP EOPNOTSUPP
44#endif
45
46#include <errno.h>
47#include <string.h>                     /* strcmp */
48#include <unistd.h>
49#include <stdlib.h>                     /* calloc() */
50
51/*
52 *  Semaphore to protect the io table
53 */
54
55#define RTEMS_LIBIO_SEM         rtems_build_name('L', 'B', 'I', 'O')
56#define RTEMS_LIBIO_IOP_SEM(n)  rtems_build_name('L', 'B', 'I', n)
57
58extern rtems_id                          rtems_libio_semaphore;
59extern rtems_filesystem_file_handlers_r  rtems_filesystem_null_handlers;
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 *  set_errno_and_return_minus_one
72 *
73 *  Macro to ease common way to return an error.
74 */
75
76#ifndef set_errno_and_return_minus_one
77#define set_errno_and_return_minus_one( _error ) \
78  do { errno = (_error); return -1; } while(0)
79#endif
80
81/*
82 *  rtems_libio_iop
83 *
84 *  Macro to return the file descriptor pointer.
85 */
86
87#define rtems_libio_iop(_fd) \
88  ((((unsigned32)(_fd)) < rtems_libio_number_iops) ? \
89         &rtems_libio_iops[_fd] : 0)
90
91/* 
92 *  rtems_libio_check_is_open
93 * 
94 *  Macro to check if a file descriptor is actually open.
95 */
96
97#define rtems_libio_check_is_open(_iop) \
98  do {                                               \
99      if (((_iop)->flags & LIBIO_FLAGS_OPEN) == 0) { \
100          errno = EBADF;                             \
101          return -1;                                 \
102      }                                              \
103  } while (0)
104
105/*
106 *  rtems_libio_check_fd
107 *
108 *  Macro to check if a file descriptor number is valid.
109 */
110
111#define rtems_libio_check_fd(_fd) \
112  do {                                                     \
113      if ((unsigned32) (_fd) >= rtems_libio_number_iops) { \
114          errno = EBADF;                                   \
115          return -1;                                       \
116      }                                                    \
117  } while (0)
118
119/*
120 *  rtems_libio_check_buffer
121 *
122 *  Macro to check if a buffer pointer is valid.
123 */
124
125#define rtems_libio_check_buffer(_buffer) \
126  do {                                    \
127      if ((_buffer) == 0) {               \
128          errno = EINVAL;                 \
129          return -1;                      \
130      }                                   \
131  } while (0)
132
133/*
134 *  rtems_libio_check_count
135 *
136 *  Macro to check if a count or length is valid.
137 */
138
139#define rtems_libio_check_count(_count) \
140  do {                                  \
141      if ((_count) == 0) {              \
142          return 0;                     \
143      }                                 \
144  } while (0)
145
146/*
147 *  rtems_libio_check_permissions
148 *
149 *  Macro to check if a file descriptor is open for this operation.
150 */
151
152#define rtems_libio_check_permissions(_iop, _flag)    \
153  do {                                                \
154      if (((_iop)->flags & (_flag)) == 0) {           \
155            set_errno_and_return_minus_one( EINVAL ); \
156            return -1;                                \
157      }                                               \
158  } while (0)
159
160/*
161 *  rtems_filesystem_freenode
162 *
163 *  Macro to free a node.
164 */
165
166#define rtems_filesystem_freenode( _node ) \
167  do { \
168    if ( (_node)->ops )\
169      if ( (_node)->ops->freenod_h ) \
170        (*(_node)->ops->freenod_h)( (_node) ); \
171  } while (0)
172
173/*
174 *  rtems_filesystem_is_separator
175 *
176 *  Macro to determine if a character is a path name separator.
177 *
178 *  NOTE:  This macro handles MS-DOS and UNIX style names.
179 */
180
181#define rtems_filesystem_is_separator( _ch ) \
182   ( ((_ch) == '/') || ((_ch) == '\\') || ((_ch) == '\0'))
183
184/*
185 *  rtems_filesystem_get_start_loc
186 *
187 *  Macro to determine if path is absolute or relative.
188 */
189
190#define rtems_filesystem_get_start_loc( _path, _index, _loc )  \
191  do {                                                         \
192    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
193      *(_loc) = rtems_filesystem_root;                         \
194      *(_index) = 1;                                           \
195    } else {                                                   \
196      *(_loc) = rtems_filesystem_current;                      \
197      *(_index) = 0;                                           \
198    }                                                          \
199  } while (0)
200
201#define rtems_filesystem_get_sym_start_loc( _path, _index, _loc )  \
202  do {                                                         \
203    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
204      *(_loc) = rtems_filesystem_root;                         \
205      *(_index) = 1;                                           \
206    } else {                                                   \
207      *(_index) = 0;                                           \
208    }                                                          \
209  } while (0)
210
211
212/*
213 *  External structures
214 */
215#if !defined(LOGIN_NAME_MAX)
216#if defined(__linux__)
217#define LOGIN_NAME_MAX _POSIX_LOGIN_NAME_MAX
218#else
219#error "don't know how to set LOGIN_NAME_MAX"
220#endif
221#endif
222
223typedef struct {
224 rtems_id                         task_id;     
225 rtems_filesystem_location_info_t current_directory;
226 rtems_filesystem_location_info_t root_directory;
227 /* Default mode for all files. */
228 mode_t                           umask;
229 nlink_t                          link_counts;
230 /* _POSIX_types */
231 uid_t                            uid;
232 gid_t                            gid;
233 uid_t                            euid;
234 gid_t                            egid;
235 char      login_buffer[LOGIN_NAME_MAX];
236
237 pid_t                            pgrp; /* process group id */
238} rtems_user_env_t;
239
240extern rtems_user_env_t * rtems_current_user_env;
241extern rtems_user_env_t   rtems_global_user_env;
242
243#define rtems_filesystem_current     (rtems_current_user_env->current_directory)
244#define rtems_filesystem_root        (rtems_current_user_env->root_directory)
245#define rtems_filesystem_link_counts (rtems_current_user_env->link_counts)
246#define rtems_filesystem_umask       (rtems_current_user_env->umask)
247
248#define _POSIX_types_Uid             (rtems_current_user_env->uid)
249#define _POSIX_types_Gid             (rtems_current_user_env->gid)
250#define _POSIX_types_Euid            (rtems_current_user_env->euid)
251#define _POSIX_types_Egid            (rtems_current_user_env->egid)
252#define _POSIX_types_Getlogin_buffer (rtems_current_user_env->login_buffer)
253
254
255/*
256 *  Instantiate a private copy of the per user information for the calling task.
257 */
258
259rtems_status_code rtems_libio_set_private_env(void);
260rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ;
261       
262
263
264/*
265 *  File Descriptor Routine Prototypes
266 */
267
268rtems_libio_t *rtems_libio_allocate(void);
269
270unsigned32 rtems_libio_fcntl_flags(
271  unsigned32 fcntl_flags
272);
273
274unsigned32 rtems_libio_to_fcntl_flags(
275  unsigned32 flags
276);
277
278void rtems_libio_free(
279  rtems_libio_t *iop
280);
281
282int rtems_libio_is_open_files_in_fs(
283  rtems_filesystem_mount_table_entry_t *mt_entry
284);
285
286int rtems_libio_is_file_open(
287  void  *node_access
288);
289
290/*
291 *  File System Routine Prototypes
292 */
293
294int rtems_filesystem_evaluate_path(
295  const char                        *pathname,
296  int                                flags,
297  rtems_filesystem_location_info_t  *pathloc,
298  int                                follow_link
299);
300
301void rtems_filesystem_initialize();
302
303int init_fs_mount_table();
304
305#ifdef __cplusplus
306}
307#endif
308
309#endif
310/* end of include file */
Note: See TracBrowser for help on using the repository browser.