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

4.104.114.84.95
Last change on this file since d8a9155 was d8a9155, checked in by Joel Sherrill <joel.sherrill@…>, on 04/20/01 at 21:11:25

2001-04-20 Correo Fernando-ruiz <correo@…>

  • include/rtems/libio_.h, libc/chroot.c, libc/privateenv.c: Private environment and chroot() enhancements and fixes. Comments: + privateenv has been modified to let at chroot() to be more

POSIX like Sergei Organov recommended.

+ A task owner lets that rtems_set_private_env() will be

called twice or more times.

+ chroot() can be called without a previous

rtems_set_private_env(); (transpanrently)

+ The second call of rtems_set_private_env() makes a internal

chroot("/") into global imfs_root.

+ chroot() runs like chdir() without a previous chdir("/") with

the global root.

+ The current directory can be in a wrong place like Linux and

many other Unices.

  • Property mode set to 100644
File size: 7.5 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_id                         task_id;     
213 rtems_filesystem_location_info_t current_directory;
214 rtems_filesystem_location_info_t root_directory;
215 /* Default mode for all files. */
216 mode_t                           umask;
217 nlink_t                          link_counts;
218} rtems_user_env_t;
219
220extern rtems_user_env_t * rtems_current_user_env;
221extern rtems_user_env_t   rtems_global_user_env;
222
223#define rtems_filesystem_current     (rtems_current_user_env->current_directory)
224#define rtems_filesystem_root        (rtems_current_user_env->root_directory)
225#define rtems_filesystem_link_counts (rtems_current_user_env->link_counts)
226#define rtems_filesystem_umask       (rtems_current_user_env->umask)
227
228/*
229 *  Instantiate a private copy of the per user information for the calling task.
230 */
231
232rtems_status_code rtems_libio_set_private_env(void);
233rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ;
234       
235
236
237/*
238 *  File Descriptor Routine Prototypes
239 */
240
241rtems_libio_t *rtems_libio_allocate(void);
242
243unsigned32 rtems_libio_fcntl_flags(
244  unsigned32 fcntl_flags
245);
246
247unsigned32 rtems_libio_to_fcntl_flags(
248  unsigned32 flags
249);
250
251void rtems_libio_free(
252  rtems_libio_t *iop
253);
254
255int rtems_libio_is_open_files_in_fs(
256  rtems_filesystem_mount_table_entry_t *mt_entry
257);
258
259int rtems_libio_is_file_open(
260  void  *node_access
261);
262
263/*
264 *  File System Routine Prototypes
265 */
266
267int rtems_filesystem_evaluate_path(
268  const char                        *pathname,
269  int                                flags,
270  rtems_filesystem_location_info_t  *pathloc,
271  int                                follow_link
272);
273
274void rtems_filesystem_initialize();
275
276int init_fs_mount_table();
277
278#ifdef __cplusplus
279}
280#endif
281
282#endif
283/* end of include file */
284
285
286
Note: See TracBrowser for help on using the repository browser.