source: rtems/c/src/exec/libcsupport/include/rtems/libio_.h @ ce28b283

4.104.114.84.95
Last change on this file since ce28b283 was 9c3fa30, checked in by Joel Sherrill <joel.sherrill@…>, on 09/28/00 at 20:19:23

2000-09-28 Joel Sherrill <joel@…>

  • libc/libio.h (rtems_filesystem_file_handlers_r, rtems_filesystem_operations_table): Added _h to all structure fields to indicate they are "handlers".
  • libc/libio_.h, libc/chdir.c, libc/chmod.c, libc/chown.c, libc/close.c, libc/eval.c, libc/fchdir.c, libc/fchmod.c, libc/fcntl.c, libc/fdatasync.c, libc/fstat.c, libc/fsync.c, libc/ftruncate.c, libc/getdents.c, libc/imfs_eval.c, libc/imfs_unlink.c, libc/ioctl.c, libc/ioman.c, libc/link.c, libc/lseek.c, libc/mknod.c, libc/mount.c, libc/open.c, libc/read.c, libc/readlink.c, libc/rmdir.c, libc/stat.c, libc/symlink.c, libc/unlink.c, libc/unmount.c, libc/utime.c, libc/write.c: Modified to reflect above name change.
  • Property mode set to 100644
File size: 6.8 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 __LIBIO__h
15#define __LIBIO__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 *  Default mode for all files.
69 */
70
71extern mode_t    rtems_filesystem_umask;
72
73/*
74 *  set_errno_and_return_minus_one
75 *
76 *  Macro to ease common way to return an error.
77 */
78
79#ifndef set_errno_and_return_minus_one
80#define set_errno_and_return_minus_one( _error ) \
81  do { errno = (_error); return -1; } while(0)
82#endif
83
84/*
85 *  rtems_libio_iop
86 *
87 *  Macro to return the file descriptor pointer.
88 */
89
90#define rtems_libio_iop(_fd) \
91  ((((unsigned32)(_fd)) < rtems_libio_number_iops) ? \
92         &rtems_libio_iops[_fd] : 0)
93
94/* 
95 *  rtems_libio_check_is_open
96 * 
97 *  Macro to check if a file descriptor is actually open.
98 */
99
100#define rtems_libio_check_is_open(_iop) \
101  do {                                               \
102      if (((_iop)->flags & LIBIO_FLAGS_OPEN) == 0) { \
103          errno = EBADF;                             \
104          return -1;                                 \
105      }                                              \
106  } while (0)
107
108/*
109 *  rtems_libio_check_fd
110 *
111 *  Macro to check if a file descriptor number is valid.
112 */
113
114#define rtems_libio_check_fd(_fd) \
115  do {                                                     \
116      if ((unsigned32) (_fd) >= rtems_libio_number_iops) { \
117          errno = EBADF;                                   \
118          return -1;                                       \
119      }                                                    \
120  } while (0)
121
122/*
123 *  rtems_libio_check_buffer
124 *
125 *  Macro to check if a buffer pointer is valid.
126 */
127
128#define rtems_libio_check_buffer(_buffer) \
129  do {                                    \
130      if ((_buffer) == 0) {               \
131          errno = EINVAL;                 \
132          return -1;                      \
133      }                                   \
134  } while (0)
135
136/*
137 *  rtems_libio_check_count
138 *
139 *  Macro to check if a count or length is valid.
140 */
141
142#define rtems_libio_check_count(_count) \
143  do {                                  \
144      if ((_count) == 0) {              \
145          return 0;                     \
146      }                                 \
147  } while (0)
148
149/*
150 *  rtems_libio_check_permissions
151 *
152 *  Macro to check if a file descriptor is open for this operation.
153 */
154
155#define rtems_libio_check_permissions(_iop, _flag)    \
156  do {                                                \
157      if (((_iop)->flags & (_flag)) == 0) {           \
158            set_errno_and_return_minus_one( EINVAL ); \
159            return -1;                                \
160      }                                               \
161  } while (0)
162
163/*
164 *  rtems_filesystem_freenode
165 *
166 *  Macro to free a node.
167 */
168
169#define rtems_filesystem_freenode( _node ) \
170  do { \
171    if ( (_node)->ops->freenod_h ) \
172      (*(_node)->ops->freenod_h)( (_node) ); \
173  } while (0)
174
175/*
176 *  rtems_filesystem_is_separator
177 *
178 *  Macro to determine if a character is a path name separator.
179 *
180 *  NOTE:  This macro handles MS-DOS and UNIX style names.
181 */
182
183#define rtems_filesystem_is_separator( _ch ) \
184   ( ((_ch) == '/') || ((_ch) == '\\') || ((_ch) == '\0'))
185
186/*
187 *  rtems_filesystem_get_start_loc
188 *
189 *  Macro to determine if path is absolute or relative.
190 */
191
192#define rtems_filesystem_get_start_loc( _path, _index, _loc )  \
193  do {                                                         \
194    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
195      *(_loc) = rtems_filesystem_root;                         \
196      *(_index) = 1;                                           \
197    } else {                                                   \
198      *(_loc) = rtems_filesystem_current;                      \
199      *(_index) = 0;                                           \
200    }                                                          \
201  } while (0)
202
203#define rtems_filesystem_get_sym_start_loc( _path, _index, _loc )  \
204  do {                                                         \
205    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
206      *(_loc) = rtems_filesystem_root;                         \
207      *(_index) = 1;                                           \
208    } else {                                                   \
209      *(_index) = 0;                                           \
210    }                                                          \
211  } while (0)
212
213
214/*
215 *  External structures
216 */
217
218extern rtems_filesystem_location_info_t rtems_filesystem_current;
219extern rtems_filesystem_location_info_t rtems_filesystem_root;
220extern nlink_t                          rtems_filesystem_link_counts;
221
222
223/*
224 *  File Descriptor Routine Prototypes
225 */
226
227rtems_libio_t *rtems_libio_allocate(void);
228
229unsigned32 rtems_libio_fcntl_flags(
230  unsigned32 fcntl_flags
231);
232
233unsigned32 rtems_libio_to_fcntl_flags(
234  unsigned32 flags
235);
236
237void rtems_libio_free(
238  rtems_libio_t *iop
239);
240
241int rtems_libio_is_open_files_in_fs(
242  rtems_filesystem_mount_table_entry_t *mt_entry
243);
244
245int rtems_libio_is_file_open(
246  void  *node_access
247);
248
249/*
250 *  File System Routine Prototypes
251 */
252
253int rtems_filesystem_evaluate_path(
254  const char                        *pathname,
255  int                                flags,
256  rtems_filesystem_location_info_t  *pathloc,
257  int                                follow_link
258);
259
260void rtems_filesystem_initialize();
261
262int init_fs_mount_table();
263
264#ifdef __cplusplus
265}
266#endif
267
268#endif
269/* end of include file */
270
271
272
Note: See TracBrowser for help on using the repository browser.