source: rtems/cpukit/libcsupport/include/rtems/libio_.h @ a953fa1

4.104.114.84.95
Last change on this file since a953fa1 was de2ee43d, checked in by Joel Sherrill <joel.sherrill@…>, on 12/16/03 at 23:41:27

2003-12-16 Joel Sherrill <joel@…>

PR 542/filesystem

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