RTEMS 7.0-rc1
Loading...
Searching...
No Matches
shell.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
9/*
10 * Copyright (C) 2001 Fernando Ruiz Casas <fruizcasas@gmail.com>
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef __RTEMS_SHELL_H__
35#define __RTEMS_SHELL_H__
36
37#include <sys/types.h>
38#include <sys/stat.h>
39#include <rtems.h>
40#include <stdio.h>
41#include <termios.h>
42#include <rtems/fs.h>
43#include <rtems/libio.h>
44#include <rtems/chain.h>
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50/*
51 * Some key labels to define special keys.
52 */
53
54#define RTEMS_SHELL_KEYS_EXTENDED (0x8000)
55#define RTEMS_SHELL_KEYS_NORMAL_MASK (0x00ff)
56#define RTEMS_SHELL_KEYS_INS (0)
57#define RTEMS_SHELL_KEYS_DEL (1)
58#define RTEMS_SHELL_KEYS_UARROW (2)
59#define RTEMS_SHELL_KEYS_DARROW (3)
60#define RTEMS_SHELL_KEYS_LARROW (4)
61#define RTEMS_SHELL_KEYS_RARROW (5)
62#define RTEMS_SHELL_KEYS_HOME (6)
63#define RTEMS_SHELL_KEYS_END (7)
64#define RTEMS_SHELL_KEYS_F1 (8)
65#define RTEMS_SHELL_KEYS_F2 (9)
66#define RTEMS_SHELL_KEYS_F3 (10)
67#define RTEMS_SHELL_KEYS_F4 (11)
68#define RTEMS_SHELL_KEYS_F5 (12)
69#define RTEMS_SHELL_KEYS_F6 (13)
70#define RTEMS_SHELL_KEYS_F7 (14)
71#define RTEMS_SHELL_KEYS_F8 (15)
72#define RTEMS_SHELL_KEYS_F9 (16)
73#define RTEMS_SHELL_KEYS_F10 (17)
74
75typedef bool (*rtems_shell_login_check_t)(
76 const char * /* user */,
77 const char * /* passphrase */
78);
79
80extern bool rtems_shell_login_prompt(
81 FILE *in,
82 FILE *out,
83 const char *device,
84 rtems_shell_login_check_t check
85);
86
87extern bool rtems_shell_login_check(
88 const char *user,
89 const char *passphrase
90);
91
92typedef int (*rtems_shell_command_t)(int argc, char **argv);
93
96
98 const char *name;
99 const char *usage;
100 const char *topic;
101 rtems_shell_command_t command;
102 rtems_shell_cmd_t *alias;
103 rtems_shell_cmd_t *next;
104 mode_t mode;
105 uid_t uid;
106 gid_t gid;
107};
108
109typedef struct {
110 const char *name;
111 const char *alias;
113
116
118 const char *topic;
120};
121
122/*
123 * The return value has RTEMS_SHELL_KEYS_EXTENDED set if the key
124 * is extended, ie a special key.
125 */
126extern unsigned int rtems_shell_getchar(FILE *in);
127
128extern rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char *cmd);
129
130extern rtems_shell_cmd_t *rtems_shell_add_cmd_struct(
131 rtems_shell_cmd_t *shell_cmd
132);
133
134rtems_shell_cmd_t * rtems_shell_add_cmd(
135 const char *cmd,
136 const char *topic,
137 const char *usage,
138 rtems_shell_command_t command
139);
140
141extern rtems_shell_cmd_t * rtems_shell_alias_cmd(
142 const char *cmd,
143 const char *alias
144);
145
146extern int rtems_shell_make_args(
147 char *commandLine,
148 int *argc_p,
149 char **argv_p,
150 int max_args
151);
152
153extern rtems_shell_topic_t * rtems_shell_lookup_topic(
154 const char *topic
155);
156
157extern bool rtems_shell_can_see_cmd(
158 const rtems_shell_cmd_t *shell_cmd
159);
160
161extern int rtems_shell_execute_cmd(
162 const char *cmd, int argc, char *argv[]
163);
164
165/*
166 * Call to set up the shell environment if you need to execute commands before
167 * running a shell.
168 */
169extern void rtems_shell_init_environment(
170 void
171);
172
173extern int rtems_shell_cat_file(
174 FILE *out,
175 const char *name
176);
177
178extern void rtems_shell_write_file(
179 const char *name,
180 const char *content
181);
182
183extern int rtems_shell_script_file(
184 int argc,
185 char **argv
186);
187
201 const char *task_name,
202 size_t task_stacksize,
203 rtems_task_priority task_priority,
204 const char *devname,
205 bool forever,
206 bool wait,
207 rtems_shell_login_check_t login_check
208);
209
224 const char *task_name,
225 size_t task_stacksize, /* 0 default*/
226 rtems_task_priority task_priority,
227 const char *input,
228 const char *output,
229 bool output_append,
230 bool wait,
231 bool echo
232);
233
237typedef struct {
240 bool managed;
241 const char *devname;
242 const char *taskname;
243 bool exit_shell; /* logout */
244 bool forever; /* repeat login */
245 int *exit_code;
246 bool exit_on_error;
247 bool echo;
248 char cwd[256];
249 const char *input;
250 const char *output;
251 bool output_append;
252 FILE *parent_stdin;
253 FILE *parent_stdout;
254 FILE *parent_stderr;
255 rtems_id wake_on_end;
256 rtems_shell_login_check_t login_check;
257
262 uid_t uid;
263
268 gid_t gid;
270
271bool rtems_shell_main_loop(
272 rtems_shell_env_t *rtems_shell_env
273);
274
295 rtems_shell_env_t *shell_env,
296 bool interactive,
297 FILE *line_editor_output
298);
299
300extern const rtems_shell_env_t rtems_global_shell_env;
301
302rtems_shell_env_t *rtems_shell_get_current_env(void);
303void rtems_shell_dup_current_env(rtems_shell_env_t *);
304
305/*
306 * The types of file systems we can mount. We have them broken out
307 * out like this so they can be configured by shellconfig.h. The
308 * mount command needs special treatment due to some file systems
309 * being dependent on the network stack and some not. If we had
310 * all possible file systems being included it would force the
311 * networking stack into the applcation and this may not be
312 * required.
313 */
316
317typedef int (*rtems_shell_filesystems_mounter_t)(
318 const char* driver,
319 const char* path,
322);
323
325 rtems_chain_node link;
326 const char *name;
327 int driver_needed;
329 rtems_shell_filesystems_mounter_t mounter;
330};
331
345extern void rtems_shell_get_prompt(
346 rtems_shell_env_t *shell_env,
347 char *prompt,
348 size_t size
349);
350
360 const char* driver,
361 const char* path,
364);
365
372
379
380typedef void (*rtems_shell_wait_for_input_notification)(
381 int fd,
382 int seconds_remaining,
383 void *arg
384);
385
394 int fd,
395 int timeout_in_seconds,
396 rtems_shell_wait_for_input_notification notification,
397 void *notification_arg
398);
399
411 int fd,
412 int timeout_in_seconds,
413 rtems_shell_wait_for_input_notification notification,
414 void *notification_arg,
415 int desired_input
416);
417
418extern int rtems_shell_main_monitor(int argc, char **argv);
419
420/*
421 * Provide these commands for application use, as their implementation
422 * is tedious.
423 */
424int rtems_shell_main_mv(int argc, char *argv[]);
425int rtems_shell_main_cp(int argc, char *argv[]);
426int rtems_shell_main_rm(int argc, char *argv[]);
427
428#ifdef __cplusplus
429}
430#endif
431
432#endif
This header file provides the Chains API.
rtems_filesystem_options_t
File system options.
Definition: libio.h:1705
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:85
uint32_t rtems_name
This type represents Classic API object names.
Definition: types.h:226
uint32_t rtems_task_priority
This integer type represents task priorities of the Classic API.
Definition: types.h:257
Objects_Id rtems_id
This type represents RTEMS object identifiers.
Definition: types.h:94
Basic Filesystem Types.
Basic IO API.
This header file defines the RTEMS Classic API.
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:107
int rtems_shell_libc_mounter(const char *driver, const char *path, rtems_shell_filesystems_t *fs, rtems_filesystem_options_t options)
bool rtems_shell_run_main_loop(rtems_shell_env_t *shell_env, bool interactive, FILE *line_editor_output)
Runs the shell main loop.
Definition: shell.c:1241
void rtems_shell_mount_add_fsys(rtems_shell_filesystems_t *fs)
void rtems_shell_get_prompt(rtems_shell_env_t *shell_env, char *prompt, size_t size)
Definition: shell_getprompt.c:55
void rtems_shell_mount_del_fsys(rtems_shell_filesystems_t *fs)
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:1499
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:1530
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:74
This structure represents a chain node.
Definition: chain.h:78
File system operations table.
Definition: libio.h:475
Definition: shell.h:109
Definition: shell.h:97
Definition: shell.h:237
gid_t gid
The real and effective GID of the shell task in case no login check is present.
Definition: shell.h:268
uid_t uid
The real and effective UID of the shell task in case no login check is present.
Definition: shell.h:262
rtems_name magic
Definition: shell.h:239
Definition: shell.h:324
Definition: shell.h:117