1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup LibIOEnv |
---|
5 | * @brief User Environment Support |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2011. |
---|
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 | #ifndef _RTEMS_USERENV_H |
---|
21 | #define _RTEMS_USERENV_H |
---|
22 | |
---|
23 | /* |
---|
24 | * According to IEEE Std 1003.1-2001, |
---|
25 | * limits.h is supposed to provide _POSIX_LOGIN_NAME_MAX |
---|
26 | * XXX: We do not rely on this. |
---|
27 | */ |
---|
28 | #include <limits.h> |
---|
29 | |
---|
30 | #include <rtems.h> |
---|
31 | #include <rtems/fs.h> |
---|
32 | |
---|
33 | #ifdef __cplusplus |
---|
34 | extern "C" { |
---|
35 | #endif |
---|
36 | |
---|
37 | /** |
---|
38 | * @defgroup LibIOEnv User Environment |
---|
39 | * |
---|
40 | * @ingroup LibIO |
---|
41 | * |
---|
42 | * @brief Provides a POSIX like user environment for tasks. |
---|
43 | */ |
---|
44 | /**@{**/ |
---|
45 | |
---|
46 | #ifndef LOGIN_NAME_MAX |
---|
47 | #ifdef _POSIX_LOGIN_NAME_MAX |
---|
48 | #define LOGIN_NAME_MAX _POSIX_LOGIN_NAME_MAX |
---|
49 | #else |
---|
50 | /* Fallback */ |
---|
51 | #define LOGIN_NAME_MAX 9 |
---|
52 | #endif |
---|
53 | #endif |
---|
54 | |
---|
55 | typedef struct { |
---|
56 | rtems_filesystem_global_location_t *current_directory; |
---|
57 | rtems_filesystem_global_location_t *root_directory; |
---|
58 | /* Default mode for all files. */ |
---|
59 | mode_t umask; |
---|
60 | /* _POSIX_types */ |
---|
61 | uid_t uid; |
---|
62 | gid_t gid; |
---|
63 | uid_t euid; |
---|
64 | gid_t egid; |
---|
65 | char login_buffer[LOGIN_NAME_MAX]; |
---|
66 | pid_t pgrp; /* process group id */ |
---|
67 | } rtems_user_env_t; |
---|
68 | |
---|
69 | extern rtems_user_env_t rtems_global_user_env; |
---|
70 | |
---|
71 | /** |
---|
72 | * @brief Fetch the pointer to the current user environment. |
---|
73 | * |
---|
74 | * If the task has a private user environment the pointer to it will be |
---|
75 | * returned. Otherwise the pointer to rtems_global_user_env will be returned. |
---|
76 | */ |
---|
77 | rtems_user_env_t * rtems_current_user_env_get(void); |
---|
78 | |
---|
79 | #define rtems_current_user_env rtems_current_user_env_get() |
---|
80 | |
---|
81 | #define rtems_filesystem_current (rtems_current_user_env->current_directory) |
---|
82 | #define rtems_filesystem_root (rtems_current_user_env->root_directory) |
---|
83 | #define rtems_filesystem_umask (rtems_current_user_env->umask) |
---|
84 | |
---|
85 | #define _POSIX_types_Uid (rtems_current_user_env->uid) |
---|
86 | #define _POSIX_types_Gid (rtems_current_user_env->gid) |
---|
87 | #define _POSIX_types_Euid (rtems_current_user_env->euid) |
---|
88 | #define _POSIX_types_Egid (rtems_current_user_env->egid) |
---|
89 | #define _POSIX_types_Getlogin_buffer (rtems_current_user_env->login_buffer) |
---|
90 | |
---|
91 | /** |
---|
92 | * @brief Creates a private environment. |
---|
93 | * |
---|
94 | * If the task has already a private environment nothing will be changed. This |
---|
95 | * function must be called from normal thread context and may block on a mutex. |
---|
96 | * Thread dispatching is disabled to protect some critical sections. |
---|
97 | * |
---|
98 | * The private environment internally uses a POSIX key. The key is added to the |
---|
99 | * configuration implicitly. But for each thread that uses a private environment |
---|
100 | * a key value pair has to be configured by the application. If only the global |
---|
101 | * environment is used there is no need to configure a key value pair. |
---|
102 | * |
---|
103 | * @retval RTEMS_SUCCESSFUL Successful operation. |
---|
104 | * @retval RTEMS_NO_MEMORY Not enough memory. |
---|
105 | * @retval RTEMS_UNSATISFIED Cloning of the current environment failed. |
---|
106 | * @retval RTEMS_TOO_MANY Cannot register the private environment. |
---|
107 | */ |
---|
108 | rtems_status_code rtems_libio_set_private_env(void); |
---|
109 | |
---|
110 | /** |
---|
111 | * @brief Use the global environment. |
---|
112 | * |
---|
113 | * A private environment will be released. This function may be called from |
---|
114 | * every thread context. Thread dispatching is disabled to protect the |
---|
115 | * critical sections. |
---|
116 | */ |
---|
117 | void rtems_libio_use_global_env(void); |
---|
118 | |
---|
119 | /** @} */ |
---|
120 | |
---|
121 | #ifdef __cplusplus |
---|
122 | } |
---|
123 | #endif |
---|
124 | |
---|
125 | #endif |
---|
126 | /* end of include file */ |
---|