source: rtems/cpukit/libcsupport/include/rtems/libio_.h @ 0bda8b4

4.115
Last change on this file since 0bda8b4 was 58f3fab, checked in by Joel Sherrill <joel.sherrill@…>, on 07/22/11 at 16:04:38

2011-07-22 Joel Sherrill <joel.sherrilL@…>

PR 1839/filesystem

  • libcsupport/include/rtems/libio_.h, libcsupport/src/fchdir.c, libcsupport/src/fdatasync.c, libcsupport/src/fpathconf.c, libcsupport/src/fsync.c, libcsupport/src/ftruncate.c, libcsupport/src/read.c, libcsupport/src/readv.c, libcsupport/src/write.c, libcsupport/src/writev.c: Some calls did not return proper status for permission errors or incorrectly permissions at all.
  • Property mode set to 100644
File size: 6.3 KB
Line 
1/**
2 * @file rtems/libio_.h
3 *
4 * This file is the libio internal interface.
5 */
6
7/*
8 *  COPYRIGHT (c) 1989-2011.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 *  $Id$
16 */
17
18#ifndef _RTEMS_RTEMS_LIBIO__H
19#define _RTEMS_RTEMS_LIBIO__H
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#ifdef __cplusplus
29extern "C" {
30#endif
31
32/*
33 *  Semaphore to protect the io table
34 */
35
36#define RTEMS_LIBIO_SEM         rtems_build_name('L', 'B', 'I', 'O')
37#define RTEMS_LIBIO_IOP_SEM(n)  rtems_build_name('L', 'B', 'I', n)
38
39extern rtems_id                          rtems_libio_semaphore;
40
41/*
42 *  File descriptor Table Information
43 */
44
45extern uint32_t        rtems_libio_number_iops;
46extern rtems_libio_t  *rtems_libio_iops;
47extern rtems_libio_t  *rtems_libio_last_iop;
48extern rtems_libio_t *rtems_libio_iop_freelist;
49
50/*
51 *  rtems_libio_iop
52 *
53 *  Macro to return the file descriptor pointer.
54 */
55
56#define rtems_libio_iop(_fd) \
57  ((((uint32_t)(_fd)) < rtems_libio_number_iops) ? \
58         &rtems_libio_iops[_fd] : 0)
59
60/*
61 *  rtems_libio_iop_to_descriptor
62 *
63 *  Macro to convert an internal file descriptor pointer (iop) into
64 *  the integer file descriptor used by the "section 2" system calls.
65 */
66
67#define rtems_libio_iop_to_descriptor(_iop) \
68   ((!(_iop)) ? -1 : (_iop - rtems_libio_iops))
69
70/*
71 *  rtems_libio_check_is_open
72 *
73 *  Macro to check if a file descriptor is actually open.
74 */
75
76#define rtems_libio_check_is_open(_iop) \
77  do {                                               \
78      if (((_iop)->flags & LIBIO_FLAGS_OPEN) == 0) { \
79          errno = EBADF;                             \
80          return -1;                                 \
81      }                                              \
82  } while (0)
83
84/*
85 *  rtems_libio_check_fd
86 *
87 *  Macro to check if a file descriptor number is valid.
88 */
89
90#define rtems_libio_check_fd(_fd) \
91  do {                                                     \
92      if ((uint32_t) (_fd) >= rtems_libio_number_iops) {   \
93          errno = EBADF;                                   \
94          return -1;                                       \
95      }                                                    \
96  } while (0)
97
98/*
99 *  rtems_libio_check_buffer
100 *
101 *  Macro to check if a buffer pointer is valid.
102 */
103
104#define rtems_libio_check_buffer(_buffer) \
105  do {                                    \
106      if ((_buffer) == 0) {               \
107          errno = EINVAL;                 \
108          return -1;                      \
109      }                                   \
110  } while (0)
111
112/*
113 *  rtems_libio_check_count
114 *
115 *  Macro to check if a count or length is valid.
116 */
117
118#define rtems_libio_check_count(_count) \
119  do {                                  \
120      if ((_count) == 0) {              \
121          return 0;                     \
122      }                                 \
123  } while (0)
124
125/*
126 *  rtems_libio_check_permissions_with_error
127 *
128 *  Macro to check if a file descriptor is open for this operation.
129 *  On failure, return the user specified error.
130 */
131
132#define rtems_libio_check_permissions_with_error(_iop, _flag, _errno) \
133  do {                                                      \
134      if (((_iop)->flags & (_flag)) == 0) {                 \
135            rtems_set_errno_and_return_minus_one( _errno ); \
136            return -1;                                      \
137      }                                                     \
138  } while (0)
139
140/*
141 *  rtems_libio_check_permissions
142 *
143 *  Macro to check if a file descriptor is open for this operation.
144 *  On failure, return EINVAL
145 */
146
147#define rtems_libio_check_permissions(_iop, _flag) \
148   rtems_libio_check_permissions_with_error(_iop, _flag, EINVAL )
149
150/*
151 *  rtems_filesystem_freenode
152 *
153 *  Macro to free a node.
154 */
155
156void rtems_filesystem_freenode( rtems_filesystem_location_info_t*  node );
157
158/*
159 *  External structures
160 */
161#include <rtems/userenv.h>
162
163extern rtems_user_env_t * rtems_current_user_env;
164extern rtems_user_env_t   rtems_global_user_env;
165
166/*
167 *  Instantiate a private copy of the per user information for the calling task.
168 */
169
170rtems_status_code rtems_libio_set_private_env(void);
171rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ;
172
173static inline void rtems_libio_lock( void )
174{
175  rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
176}
177
178static inline void rtems_libio_unlock( void )
179{
180  rtems_semaphore_release( rtems_libio_semaphore );
181}
182
183/*
184 *  File Descriptor Routine Prototypes
185 */
186
187rtems_libio_t *rtems_libio_allocate(void);
188
189uint32_t   rtems_libio_fcntl_flags(
190  uint32_t   fcntl_flags
191);
192
193uint32_t   rtems_libio_to_fcntl_flags(
194  uint32_t   flags
195);
196
197void rtems_libio_free(
198  rtems_libio_t *iop
199);
200
201int rtems_libio_is_open_files_in_fs(
202  rtems_filesystem_mount_table_entry_t *mt_entry
203);
204
205int rtems_libio_is_file_open(
206  void  *node_access
207);
208
209/*
210 *  File System Routine Prototypes
211 */
212
213int rtems_filesystem_evaluate_relative_path(
214  const char                        *pathname,
215  size_t                             pathnamelen,
216  int                                flags,
217  rtems_filesystem_location_info_t  *pathloc,
218  int                                follow_link
219);
220
221int rtems_filesystem_evaluate_path(
222  const char                        *pathname,
223  size_t                             pathnamelen,
224  int                                flags,
225  rtems_filesystem_location_info_t  *pathloc,
226  int                                follow_link
227);
228
229int rtems_filesystem_dirname(
230  const char  *pathname
231);
232
233int rtems_filesystem_prefix_separators(
234  const char  *pathname,
235  int          pathnamelen
236);
237
238void rtems_filesystem_initialize(void);
239
240int init_fs_mount_table(void);
241
242int rtems_filesystem_is_separator(char ch);
243
244void rtems_filesystem_get_start_loc(const char *path,
245                                    int *index,
246                                    rtems_filesystem_location_info_t *loc);
247
248void rtems_filesystem_get_sym_start_loc(const char *path,
249                                        int *index,
250                                        rtems_filesystem_location_info_t *loc);
251
252static inline bool rtems_filesystem_is_root_location(
253  const rtems_filesystem_location_info_t *loc
254)
255{
256  return loc->mt_entry->mt_fs_root.node_access == loc->node_access;
257}
258
259#ifdef __cplusplus
260}
261#endif
262
263#endif
264/* end of include file */
Note: See TracBrowser for help on using the repository browser.