source: rtems/c/src/lib/include/rtems/libio_.h @ 2a929cc

4.104.114.84.95
Last change on this file since 2a929cc was 2a929cc, checked in by Joel Sherrill <joel.sherrill@…>, on 01/25/01 at 15:59:58

2001-01-25 Fernando Ruiz <fernando.ruiz@…>

  • Alternate email is correo@…
  • libc/privateenv.c: New file.
  • include/rtems/libio_.h, libc/Makefile.am, libc/base_fs.c, libc/unmount.c: Moved default umask, current working directory, root, and links followed count into a structure "user environment" that can then be treated as a unit. This enable giving unique copies of these to individual threads or collection of threads.
  • Property mode set to 100644
File size: 7.4 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 <stdio.h>                      /* O_RDONLY, et.al. */
26#include <fcntl.h>                      /* O_RDONLY, et.al. */
27#include <assert.h>
28#include <stdarg.h>
29#include <errno.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#if !defined(ENOTSUP)
40#define ENOTSUP EOPNOTSUPP
41#endif
42
43#include <errno.h>
44#include <string.h>                     /* strcmp */
45#include <unistd.h>
46#include <stdlib.h>                     /* calloc() */
47
48/*
49 *  Semaphore to protect the io table
50 */
51
52#define RTEMS_LIBIO_SEM         rtems_build_name('L', 'B', 'I', 'O')
53#define RTEMS_LIBIO_IOP_SEM(n)  rtems_build_name('L', 'B', 'I', n)
54
55extern rtems_id                          rtems_libio_semaphore;
56extern rtems_filesystem_file_handlers_r  rtems_filesystem_null_handlers;
57
58/*
59 *  File descriptor Table Information
60 */
61
62extern unsigned32      rtems_libio_number_iops;
63extern rtems_libio_t  *rtems_libio_iops;
64extern rtems_libio_t  *rtems_libio_last_iop;
65extern rtems_libio_t *rtems_libio_iop_freelist;
66
67/*
68 *  set_errno_and_return_minus_one
69 *
70 *  Macro to ease common way to return an error.
71 */
72
73#ifndef set_errno_and_return_minus_one
74#define set_errno_and_return_minus_one( _error ) \
75  do { errno = (_error); return -1; } while(0)
76#endif
77
78/*
79 *  rtems_libio_iop
80 *
81 *  Macro to return the file descriptor pointer.
82 */
83
84#define rtems_libio_iop(_fd) \
85  ((((unsigned32)(_fd)) < rtems_libio_number_iops) ? \
86         &rtems_libio_iops[_fd] : 0)
87
88/* 
89 *  rtems_libio_check_is_open
90 * 
91 *  Macro to check if a file descriptor is actually open.
92 */
93
94#define rtems_libio_check_is_open(_iop) \
95  do {                                               \
96      if (((_iop)->flags & LIBIO_FLAGS_OPEN) == 0) { \
97          errno = EBADF;                             \
98          return -1;                                 \
99      }                                              \
100  } while (0)
101
102/*
103 *  rtems_libio_check_fd
104 *
105 *  Macro to check if a file descriptor number is valid.
106 */
107
108#define rtems_libio_check_fd(_fd) \
109  do {                                                     \
110      if ((unsigned32) (_fd) >= rtems_libio_number_iops) { \
111          errno = EBADF;                                   \
112          return -1;                                       \
113      }                                                    \
114  } while (0)
115
116/*
117 *  rtems_libio_check_buffer
118 *
119 *  Macro to check if a buffer pointer is valid.
120 */
121
122#define rtems_libio_check_buffer(_buffer) \
123  do {                                    \
124      if ((_buffer) == 0) {               \
125          errno = EINVAL;                 \
126          return -1;                      \
127      }                                   \
128  } while (0)
129
130/*
131 *  rtems_libio_check_count
132 *
133 *  Macro to check if a count or length is valid.
134 */
135
136#define rtems_libio_check_count(_count) \
137  do {                                  \
138      if ((_count) == 0) {              \
139          return 0;                     \
140      }                                 \
141  } while (0)
142
143/*
144 *  rtems_libio_check_permissions
145 *
146 *  Macro to check if a file descriptor is open for this operation.
147 */
148
149#define rtems_libio_check_permissions(_iop, _flag)    \
150  do {                                                \
151      if (((_iop)->flags & (_flag)) == 0) {           \
152            set_errno_and_return_minus_one( EINVAL ); \
153            return -1;                                \
154      }                                               \
155  } while (0)
156
157/*
158 *  rtems_filesystem_freenode
159 *
160 *  Macro to free a node.
161 */
162
163#define rtems_filesystem_freenode( _node ) \
164  do { \
165    if ( (_node)->ops->freenod_h ) \
166      (*(_node)->ops->freenod_h)( (_node) ); \
167  } while (0)
168
169/*
170 *  rtems_filesystem_is_separator
171 *
172 *  Macro to determine if a character is a path name separator.
173 *
174 *  NOTE:  This macro handles MS-DOS and UNIX style names.
175 */
176
177#define rtems_filesystem_is_separator( _ch ) \
178   ( ((_ch) == '/') || ((_ch) == '\\') || ((_ch) == '\0'))
179
180/*
181 *  rtems_filesystem_get_start_loc
182 *
183 *  Macro to determine if path is absolute or relative.
184 */
185
186#define rtems_filesystem_get_start_loc( _path, _index, _loc )  \
187  do {                                                         \
188    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
189      *(_loc) = rtems_filesystem_root;                         \
190      *(_index) = 1;                                           \
191    } else {                                                   \
192      *(_loc) = rtems_filesystem_current;                      \
193      *(_index) = 0;                                           \
194    }                                                          \
195  } while (0)
196
197#define rtems_filesystem_get_sym_start_loc( _path, _index, _loc )  \
198  do {                                                         \
199    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
200      *(_loc) = rtems_filesystem_root;                         \
201      *(_index) = 1;                                           \
202    } else {                                                   \
203      *(_index) = 0;                                           \
204    }                                                          \
205  } while (0)
206
207
208/*
209 *  External structures
210 */
211typedef struct {
212 rtems_filesystem_location_info_t current_directory;
213 rtems_filesystem_location_info_t root_directory;
214 /* Default mode for all files. */
215 mode_t                           umask;
216 nlink_t                          link_counts;
217} rtems_user_env_t;
218
219extern rtems_user_env_t * rtems_current_user_env;
220extern rtems_user_env_t   rtems_global_user_env;
221
222#define rtems_filesystem_current     (rtems_current_user_env->current_directory)
223#define rtems_filesystem_root        (rtems_current_user_env->root_directory)
224#define rtems_filesystem_link_counts (rtems_current_user_env->link_counts)
225#define rtems_filesystem_umask       (rtems_current_user_env->umask)
226
227/*
228 *  Instantiate a private copy of the per user information for the calling task.
229 */
230
231rtems_status_code rtems_libio_set_private_env(void);
232
233
234/*
235 *  File Descriptor Routine Prototypes
236 */
237
238rtems_libio_t *rtems_libio_allocate(void);
239
240unsigned32 rtems_libio_fcntl_flags(
241  unsigned32 fcntl_flags
242);
243
244unsigned32 rtems_libio_to_fcntl_flags(
245  unsigned32 flags
246);
247
248void rtems_libio_free(
249  rtems_libio_t *iop
250);
251
252int rtems_libio_is_open_files_in_fs(
253  rtems_filesystem_mount_table_entry_t *mt_entry
254);
255
256int rtems_libio_is_file_open(
257  void  *node_access
258);
259
260/*
261 *  File System Routine Prototypes
262 */
263
264int rtems_filesystem_evaluate_path(
265  const char                        *pathname,
266  int                                flags,
267  rtems_filesystem_location_info_t  *pathloc,
268  int                                follow_link
269);
270
271void rtems_filesystem_initialize();
272
273int init_fs_mount_table();
274
275#ifdef __cplusplus
276}
277#endif
278
279#endif
280/* end of include file */
281
282
283
Note: See TracBrowser for help on using the repository browser.