source: rtems/cpukit/libcsupport/src/__usrenv.c @ ba74ebde

5
Last change on this file since ba74ebde was ba74ebde, checked in by Sebastian Huber <sebastian.huber@…>, on Feb 14, 2020 at 6:09:56 PM

libio: Add POSIX user environment pointer to TCB

The IO library used a POSIX key to store an optional POSIX user
environment pointer. This pulled in the POSIX keys support in every
application configuration. Add a user environment pointer to the thread
control block (TCB) instead. Applications which do not need the POSIX
user environment will just get an overhead of one pointer per thread.

Close #3882.

  • Property mode set to 100644
File size: 5.8 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS File System Location Support
5 *  @ingroup LibIOInternal
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2008.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  Modifications to support reference counting in the file system are
13 *  Copyright (c) 2012 embedded brains GmbH.
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.org/license/LICENSE.
18 */
19
20#if HAVE_CONFIG_H
21  #include "config.h"
22#endif
23
24#include <sys/stat.h>
25
26#include <rtems/libio_.h>
27#include <rtems/score/percpu.h>
28#include <rtems/score/thread.h>
29
30static int null_handler_open(
31  rtems_libio_t *iop,
32  const char *path,
33  int oflag,
34  mode_t mode
35)
36{
37  return -1;
38}
39
40static int null_handler_fstat(
41  const rtems_filesystem_location_info_t *pathloc,
42  struct stat *buf
43)
44{
45  return -1;
46}
47
48const rtems_filesystem_file_handlers_r rtems_filesystem_null_handlers = {
49  .open_h = null_handler_open,
50  .close_h = rtems_filesystem_default_close,
51  .read_h = rtems_filesystem_default_read,
52  .write_h = rtems_filesystem_default_write,
53  .ioctl_h = rtems_filesystem_default_ioctl,
54  .lseek_h = rtems_filesystem_default_lseek,
55  .fstat_h = null_handler_fstat,
56  .ftruncate_h = rtems_filesystem_default_ftruncate,
57  .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
58  .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
59  .fcntl_h = rtems_filesystem_default_fcntl,
60  .kqfilter_h = rtems_filesystem_default_kqfilter,
61  .mmap_h = rtems_filesystem_default_mmap,
62  .poll_h = rtems_filesystem_default_poll,
63  .readv_h = rtems_filesystem_default_readv,
64  .writev_h = rtems_filesystem_default_writev
65};
66
67static void null_op_lock_or_unlock(
68  const rtems_filesystem_mount_table_entry_t *mt_entry
69)
70{
71  /* Do nothing */
72}
73
74static int null_op_mknod(
75  const rtems_filesystem_location_info_t *parentloc,
76  const char *name,
77  size_t namelen,
78  mode_t mode,
79  dev_t dev
80)
81{
82  return -1;
83}
84
85static int null_op_rmnod(
86  const rtems_filesystem_location_info_t *parentloc,
87  const rtems_filesystem_location_info_t *loc
88)
89{
90  return -1;
91}
92
93static int null_op_link(
94  const rtems_filesystem_location_info_t *parentloc,
95  const rtems_filesystem_location_info_t *targetloc,
96  const char *name,
97  size_t namelen
98)
99{
100  return -1;
101}
102
103static int null_op_fchmod(
104  const rtems_filesystem_location_info_t *pathloc,
105  mode_t mode
106)
107{
108  return -1;
109}
110
111static int null_op_chown(
112  const rtems_filesystem_location_info_t *loc,
113  uid_t owner,
114  gid_t group
115)
116{
117  return -1;
118}
119
120static int null_op_clonenode(
121  rtems_filesystem_location_info_t *loc
122)
123{
124  return -1;
125}
126
127static int null_op_mount(
128  rtems_filesystem_mount_table_entry_t *mt_entry
129)
130{
131  return -1;
132}
133
134static int null_op_unmount(
135  rtems_filesystem_mount_table_entry_t *mt_entry
136)
137{
138  return -1;
139}
140
141static void null_op_fsunmount_me(
142  rtems_filesystem_mount_table_entry_t *mt_entry
143)
144{
145  /* Do nothing */
146}
147
148static int null_op_utime(
149  const rtems_filesystem_location_info_t *loc,
150  time_t actime,
151  time_t modtime
152)
153{
154  return -1;
155}
156
157static int null_op_symlink(
158  const rtems_filesystem_location_info_t *parentloc,
159  const char *name,
160  size_t namelen,
161  const char *target
162)
163{
164  return -1;
165}
166
167static ssize_t null_op_readlink(
168  const rtems_filesystem_location_info_t *loc,
169  char *buf,
170  size_t bufsize
171)
172{
173  return -1;
174}
175
176static int null_op_rename(
177  const rtems_filesystem_location_info_t *oldparentloc,
178  const rtems_filesystem_location_info_t *oldloc,
179  const rtems_filesystem_location_info_t *newparentloc,
180  const char *name,
181  size_t namelen
182)
183{
184  return -1;
185}
186
187static int null_op_statvfs(
188  const rtems_filesystem_location_info_t *__restrict loc,
189  struct statvfs *__restrict buf
190)
191{
192  return -1;
193}
194
195static const rtems_filesystem_operations_table null_ops = {
196  .lock_h = null_op_lock_or_unlock,
197  .unlock_h = null_op_lock_or_unlock,
198  .eval_path_h = rtems_filesystem_default_eval_path,
199  .link_h = null_op_link,
200  .are_nodes_equal_h = rtems_filesystem_default_are_nodes_equal,
201  .mknod_h = null_op_mknod,
202  .rmnod_h = null_op_rmnod,
203  .fchmod_h = null_op_fchmod,
204  .chown_h = null_op_chown,
205  .clonenod_h = null_op_clonenode,
206  .freenod_h = rtems_filesystem_default_freenode,
207  .mount_h = null_op_mount,
208  .unmount_h = null_op_unmount,
209  .fsunmount_me_h = null_op_fsunmount_me,
210  .utime_h = null_op_utime,
211  .symlink_h = null_op_symlink,
212  .readlink_h = null_op_readlink,
213  .rename_h = null_op_rename,
214  .statvfs_h = null_op_statvfs
215};
216
217rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry = {
218  .location_chain = RTEMS_CHAIN_INITIALIZER_ONE_NODE(
219    &rtems_filesystem_global_location_null.location.mt_entry_node
220  ),
221  .ops = &null_ops,
222  .mt_point_node = &rtems_filesystem_global_location_null,
223  .mt_fs_root = &rtems_filesystem_global_location_null,
224  .mounted = false,
225  .writeable = false,
226  .type = ""
227};
228
229rtems_filesystem_global_location_t rtems_filesystem_global_location_null = {
230  .location = {
231    .mt_entry_node = RTEMS_CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN(
232      &rtems_filesystem_null_mt_entry.location_chain
233    ),
234    .handlers = &rtems_filesystem_null_handlers,
235    .mt_entry = &rtems_filesystem_null_mt_entry
236  },
237
238  /*
239   * The initial reference count accounts for the following references
240   *  o the root directory of the user environment,
241   *  o the current directory of the user environment,
242   *  o the root node of the null file system instance, and
243   *  o the mount point node of the null file system instance.
244   */
245  .reference_count = 4
246};
247
248rtems_user_env_t rtems_global_user_env = {
249  .current_directory = &rtems_filesystem_global_location_null,
250  .root_directory = &rtems_filesystem_global_location_null,
251  .umask = S_IWGRP | S_IWOTH
252};
253
254rtems_user_env_t *rtems_current_user_env_get(void)
255{
256  Thread_Control *executing = _Thread_Get_executing();
257  rtems_user_env_t *env = executing->user_environment;
258
259  if (env == NULL) {
260    return &rtems_global_user_env;
261  }
262
263  return env;
264}
Note: See TracBrowser for help on using the repository browser.