RTEMS: cpukit/include/rtems/shell.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
shell.h
Go to the documentation of this file.
1
7/*
8 * Author:
9 *
10 * WORK: fernando.ruiz@ctv.es
11 * HOME: correo@fernando-ruiz.com
12 *
13 * Thanks at:
14 * Chris Johns
15 */
16
17#ifndef __RTEMS_SHELL_H__
18#define __RTEMS_SHELL_H__
19
20#include <sys/types.h>
21#include <sys/stat.h>
22#include <rtems.h>
23#include <stdio.h>
24#include <termios.h>
25#include <rtems/fs.h>
26#include <rtems/libio.h>
27#include <rtems/chain.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/*
34 * Some key labels to define special keys.
35 */
36
37#define RTEMS_SHELL_KEYS_EXTENDED (0x8000)
38#define RTEMS_SHELL_KEYS_NORMAL_MASK (0x00ff)
39#define RTEMS_SHELL_KEYS_INS (0)
40#define RTEMS_SHELL_KEYS_DEL (1)
41#define RTEMS_SHELL_KEYS_UARROW (2)
42#define RTEMS_SHELL_KEYS_DARROW (3)
43#define RTEMS_SHELL_KEYS_LARROW (4)
44#define RTEMS_SHELL_KEYS_RARROW (5)
45#define RTEMS_SHELL_KEYS_HOME (6)
46#define RTEMS_SHELL_KEYS_END (7)
47#define RTEMS_SHELL_KEYS_F1 (8)
48#define RTEMS_SHELL_KEYS_F2 (9)
49#define RTEMS_SHELL_KEYS_F3 (10)
50#define RTEMS_SHELL_KEYS_F4 (11)
51#define RTEMS_SHELL_KEYS_F5 (12)
52#define RTEMS_SHELL_KEYS_F6 (13)
53#define RTEMS_SHELL_KEYS_F7 (14)
54#define RTEMS_SHELL_KEYS_F8 (15)
55#define RTEMS_SHELL_KEYS_F9 (16)
56#define RTEMS_SHELL_KEYS_F10 (17)
57
58typedef bool (*rtems_shell_login_check_t)(
59 const char * /* user */,
60 const char * /* passphrase */
61);
62
63extern bool rtems_shell_login_prompt(
64 FILE *in,
65 FILE *out,
66 const char *device,
67 rtems_shell_login_check_t check
68);
69
70extern bool rtems_shell_login_check(
71 const char *user,
72 const char *passphrase
73);
74
75typedef int (*rtems_shell_command_t)(int argc, char **argv);
76
77struct rtems_shell_cmd_tt;
78typedef struct rtems_shell_cmd_tt rtems_shell_cmd_t;
79
80 struct rtems_shell_cmd_tt {
81 const char *name;
82 const char *usage;
83 const char *topic;
84 rtems_shell_command_t command;
85 rtems_shell_cmd_t *alias;
86 rtems_shell_cmd_t *next;
87 mode_t mode;
88 uid_t uid;
89 gid_t gid;
90};
91
92 typedef struct {
93 const char *name;
94 const char *alias;
95} rtems_shell_alias_t;
96
97struct rtems_shell_topic_tt;
98typedef struct rtems_shell_topic_tt rtems_shell_topic_t;
99
100 struct rtems_shell_topic_tt {
101 const char *topic;
102 rtems_shell_topic_t *next;
103};
104
105/*
106 * The return value has RTEMS_SHELL_KEYS_EXTENDED set if the key
107 * is extended, ie a special key.
108 */
109extern unsigned int rtems_shell_getchar(FILE *in);
110
111extern rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char *cmd);
112
113extern rtems_shell_cmd_t *rtems_shell_add_cmd_struct(
114 rtems_shell_cmd_t *shell_cmd
115);
116
117 rtems_shell_cmd_t * rtems_shell_add_cmd(
118 const char *cmd,
119 const char *topic,
120 const char *usage,
121 rtems_shell_command_t command
122);
123
124extern rtems_shell_cmd_t * rtems_shell_alias_cmd(
125 const char *cmd,
126 const char *alias
127);
128
129extern int rtems_shell_make_args(
130 char *commandLine,
131 int *argc_p,
132 char **argv_p,
133 int max_args
134);
135
136extern rtems_shell_topic_t * rtems_shell_lookup_topic(
137 const char *topic
138);
139
140extern bool rtems_shell_can_see_cmd(
141 const rtems_shell_cmd_t *shell_cmd
142);
143
144extern int rtems_shell_execute_cmd(
145 const char *cmd, int argc, char *argv[]
146);
147
148/*
149 * Call to set up the shell environment if you need to execute commands before
150 * running a shell.
151 */
152extern void rtems_shell_init_environment(
153 void
154);
155
156extern int rtems_shell_cat_file(
157 FILE *out,
158 const char *name
159);
160
161extern void rtems_shell_write_file(
162 const char *name,
163 const char *content
164);
165
166extern int rtems_shell_script_file(
167 int argc,
168 char **argv
169);
170
183extern rtems_status_code rtems_shell_init(
184 const char *task_name,
185 size_t task_stacksize,
186 rtems_task_priority task_priority,
187 const char *devname,
188 bool forever,
189 bool wait,
190 rtems_shell_login_check_t login_check
191);
192
206extern rtems_status_code rtems_shell_script(
207 const char *task_name,
208 size_t task_stacksize, /* 0 default*/
209 rtems_task_priority task_priority,
210 const char *input,
211 const char *output,
212 bool output_append,
213 bool wait,
214 bool echo
215);
216
220 typedef struct {
222 rtems_name magic;
223 bool managed;
224 const char *devname;
225 const char *taskname;
226 bool exit_shell; /* logout */
227 bool forever; /* repeat login */
228 int *exit_code;
229 bool exit_on_error;
230 bool echo;
231 char cwd[256];
232 const char *input;
233 const char *output;
234 bool output_append;
235 FILE *parent_stdin;
236 FILE *parent_stdout;
237 FILE *parent_stderr;
238 rtems_id wake_on_end;
239 rtems_shell_login_check_t login_check;
240
245 uid_t uid;
246
251 gid_t gid;
252} rtems_shell_env_t;
253
254bool rtems_shell_main_loop(
255 rtems_shell_env_t *rtems_shell_env
256);
257
258extern const rtems_shell_env_t rtems_global_shell_env;
259
260 rtems_shell_env_t *rtems_shell_get_current_env(void);
261void rtems_shell_dup_current_env(rtems_shell_env_t *);
262
263/*
264 * The types of file systems we can mount. We have them broken out
265 * out like this so they can be configured by shellconfig.h. The
266 * mount command needs special treatment due to some file systems
267 * being dependent on the network stack and some not. If we had
268 * all possible file systems being included it would force the
269 * networking stack into the applcation and this may not be
270 * required.
271 */
272struct rtems_shell_filesystems_tt;
273typedef struct rtems_shell_filesystems_tt rtems_shell_filesystems_t;
274
275typedef int (*rtems_shell_filesystems_mounter_t)(
276 const char* driver,
277 const char* path,
278 rtems_shell_filesystems_t* fs,
279 rtems_filesystem_options_t options
280);
281
282 struct rtems_shell_filesystems_tt {
283 rtems_chain_node link;
284 const char *name;
285 int driver_needed;
286 const rtems_filesystem_operations_table *fs_ops;
287 rtems_shell_filesystems_mounter_t mounter;
288};
289
303extern void rtems_shell_get_prompt(
304 rtems_shell_env_t *shell_env,
305 char *prompt,
306 size_t size
307);
308
317 extern int rtems_shell_libc_mounter(
318 const char* driver,
319 const char* path,
320 rtems_shell_filesystems_t* fs,
321 rtems_filesystem_options_t options
322);
323
329 extern void rtems_shell_mount_add_fsys(rtems_shell_filesystems_t* fs);
330
336 extern void rtems_shell_mount_del_fsys(rtems_shell_filesystems_t* fs);
337
338typedef void (*rtems_shell_wait_for_input_notification)(
339 int fd,
340 int seconds_remaining,
341 void *arg
342);
343
351extern rtems_status_code rtems_shell_wait_for_input(
352 int fd,
353 int timeout_in_seconds,
354 rtems_shell_wait_for_input_notification notification,
355 void *notification_arg
356);
357
368extern rtems_status_code rtems_shell_wait_for_explicit_input(
369 int fd,
370 int timeout_in_seconds,
371 rtems_shell_wait_for_input_notification notification,
372 void *notification_arg,
373 int desired_input
374);
375
376extern int rtems_shell_main_monitor(int argc, char **argv);
377
378/*
379 * Provide these commands for application use, as their implementation
380 * is tedious.
381 */
382int rtems_shell_main_mv(int argc, char *argv[]);
383int rtems_shell_main_cp(int argc, char *argv[]);
384int rtems_shell_main_rm(int argc, char *argv[]);
385
386#ifdef __cplusplus
387}
388#endif
389
390#endif
chain.h
Chain API.
rtems_status_code
rtems_status_code
Classic API Status.
Definition: status.h:43
rtems_name
uint32_t rtems_name
Classic API object name type.
Definition: types.h:77
rtems_task_priority
uint32_t rtems_task_priority
Definition: tasks.h:55
rtems_id
Objects_Id rtems_id
Used to manage and manipulate RTEMS object identifiers.
Definition: types.h:83
rtems_filesystem_options_t
rtems_filesystem_options_t
File system options.
Definition: libio.h:1647
fs.h
Basic Filesystem Types.
libio.h
Basic IO API.
rtems.h
rtems_shell_wait_for_input
rtems_status_code rtems_shell_wait_for_input(int fd, int timeout_in_seconds, rtems_shell_wait_for_input_notification notification, void *notification_arg)
Waits for input.
Definition: shell-wait-for-input.c:89
rtems_shell_libc_mounter
int rtems_shell_libc_mounter(const char *driver, const char *path, rtems_shell_filesystems_t *fs, rtems_filesystem_options_t options)
rtems_shell_mount_add_fsys
void rtems_shell_mount_add_fsys(rtems_shell_filesystems_t *fs)
rtems_shell_get_prompt
void rtems_shell_get_prompt(rtems_shell_env_t *shell_env, char *prompt, size_t size)
Definition: shell_getprompt.c:31
rtems_shell_mount_del_fsys
void rtems_shell_mount_del_fsys(rtems_shell_filesystems_t *fs)
rtems_shell_init
rtems_status_code rtems_shell_init(const char *task_name, size_t task_stacksize, rtems_task_priority task_priority, const char *devname, bool forever, bool wait, rtems_shell_login_check_t login_check)
Definition: shell.c:1222
rtems_shell_script
rtems_status_code rtems_shell_script(const char *task_name, size_t task_stacksize, rtems_task_priority task_priority, const char *input, const char *output, bool output_append, bool wait, bool echo)
Definition: shell.c:1255
rtems_shell_wait_for_explicit_input
rtems_status_code rtems_shell_wait_for_explicit_input(int fd, int timeout_in_seconds, rtems_shell_wait_for_input_notification notification, void *notification_arg, int desired_input)
Waits for explicit input.
Definition: shell-wait-for-input.c:56
Chain_Node_struct
Definition: chain.h:68
_rtems_filesystem_operations_table
File system operations table.
Definition: libio.h:472
device
Definition: rtemscompat1.h:15
rtems_shell_alias_t
Definition: shell.h:92
rtems_shell_cmd_tt
Definition: shell.h:80
rtems_shell_env_t
Definition: shell.h:220
rtems_shell_env_t::gid
gid_t gid
The real and effective GID of the shell task in case no login check is present.
Definition: shell.h:251
rtems_shell_env_t::uid
uid_t uid
The real and effective UID of the shell task in case no login check is present.
Definition: shell.h:245
rtems_shell_env_t::magic
rtems_name magic
Definition: shell.h:222
rtems_shell_filesystems_tt
Definition: shell.h:282
rtems_shell_topic_tt
Definition: shell.h:100