source: rtems/cpukit/libmisc/shell/shell.h @ e4a3d93

4.104.115
Last change on this file since e4a3d93 was 7baa484, checked in by Chris Johns <chrisj@…>, on 06/12/09 at 01:53:33

2009-06-12 Chris Johns <chrisj@…>

  • libblock/src/bdbuf.c: Update comments.
  • libblock/src/bdpart.c, libblock/src/ide_part_table.c: Get the device from the rdev field of the stat buf.
  • libcsupport/include/rtems/libio.h: Add a path length to evalpath handler. Add parent locations to rmmod and unlink handlers.
  • libcsupport/include/rtems/libio_.h: Add a path length to rtems_filesystem_evaluate_path. Add rtems_filesystem_evaluate_relative_path, rtems_filesystem_dirname, and rtems_filesystem_prefix_separators. Remove rtems_filesystem_evaluate_parent.
  • libcsupport/src/base_fs.c, libcsupport/src/chdir.c, libcsupport/src/chmod.c, libcsupport/src/chown.c, libcsupport/src/chroot.c, libcsupport/src/fchdir.c, libcsupport/src/link.c, libcsupport/src/mount.c, libcsupport/src/open.c, libcsupport/src/privateenv.c, libcsupport/src/readlink.c, libcsupport/src/unmount.c, libcsupport/src/utime.c, libcsupport/src/unmount.c, libcsupport/src/utime.c, libfs/src/devfs/devfs.h, libfs/src/devfs/devfs_eval.c, libfs/src/devfs/devstat.c, libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_misc.c, libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c, libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/ioman.c, libfs/src/pipe/pipe.c, libmisc/fsmount/fsmount.c, libnetworking/lib/ftpfs.c: Add the length parameter to the eval call.
  • libcsupport/src/eval.c: Add rtems_filesystem_prefix_separators, rtems_filesystem_dirname, rtems_filesystem_evaluate_relative_path. Add the length parameter to the eval call.
  • libcsupport/src/rmdir.c: Find the parent pathloc then the node pathloc from that node. Remove the call to find the parent given the node pathloc.
  • libcsupport/src/stat.c: Add the length parameter to the eval call. Set the device into the rdev field.
  • libcsupport/src/unlink.c: Find the parent pathloc then the node pathloc from that node. Remove the call to find the parent given the node pathloc.
  • libfs/src/dosfs/fat.c, libfs/src/dosfs/msdos_format.c: Get the disk device number from the stat rdev field.
  • libfs/src/dosfs/msdos.h: Add the length parameter to the eval call. Add the parent pathloc to the rmnod handler.
  • libfs/src/dosfs/msdos_dir.c: Add the parent pathloc to the rmnod handler.
  • libfs/src/dosfs/msdos_eval.c: Add the length parameter to the eval and token call.
  • libfs/src/imfs/imfs_directory.c: Add the parent pathloc to the rmnod handler.
  • libfs/src/imfs/imfs_fchmod.c: Do not test the mode flags for only the allowed flags. Add the missing flags spec'ed in the POSIX standard.
  • libfs/src/imfs/imfs_fsunmount.c, libfs/src/imfs/imfs_rmnod.c, libfs/src/imfs/imfs_unlink.c, libfs/src/imfs/memfile.c: Add the parent node. Currently ignored in the IMFS.
  • libfs/src/imfs/imfs_stat.c: Return the device number in the rdev field.
  • libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/imfs_symlink.c : Add the length parameter to the token call.
  • libfs/src/nfsclient/src/nfs.c: Add the length parameter to the eval call and parent node to the rmnod and unlink command.
  • libmisc/shell/internal.h: Remove the libc mounter decl to make public.
  • libmisc/shell/main_mount.c: Add support for hooking external mount support for new file systems.
  • libmisc/shell/shell.h: Add helper functions for the mount command.
  • Property mode set to 100644
File size: 7.5 KB
Line 
1/**
2 * @file rtems/shell.h
3 *
4 *  Instantatiate a new terminal shell.
5 */
6
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 *  $Id$
17 */
18
19#ifndef __RTEMS_SHELL_H__
20#define __RTEMS_SHELL_H__
21
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
63bool rtems_shell_login_prompt(
64  FILE *in,
65  FILE *out,
66  const char *device,
67  rtems_shell_login_check_t check
68);
69
70bool 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
80struct 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};
88
89typedef struct {
90  const char *name;
91  const char *alias;
92} rtems_shell_alias_t;
93
94/*
95 * The return value has RTEMS_SHELL_KEYS_EXTENDED set if the key
96 * is extended, ie a special key.
97 */
98unsigned int rtems_shell_getchar(FILE *in);
99
100rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char *cmd);
101
102rtems_shell_cmd_t *rtems_shell_add_cmd_struct(
103  rtems_shell_cmd_t *shell_cmd
104);
105
106rtems_shell_cmd_t * rtems_shell_add_cmd(
107  const char            *cmd,
108  const char            *topic,
109  const char            *usage,
110  rtems_shell_command_t  command
111);
112
113rtems_shell_cmd_t * rtems_shell_alias_cmd(
114  const char *cmd,
115  const char *alias
116);
117
118int rtems_shell_make_args(
119  char  *commandLine,
120  int   *argc_p,
121  char **argv_p,
122  int    max_args
123);
124
125int rtems_shell_cat_file(
126  FILE *out,
127  const char *name
128);
129
130void rtems_shell_write_file(
131  const char *name,
132  const char *content
133);
134
135int rtems_shell_script_file(
136  int    argc,
137  char **argv
138);
139
140/**
141 * Initialise the shell creating tasks to login and run the shell
142 * sessions.
143 *
144 * @param task_name Name of the shell task.
145 * @param task_stacksize The size of the stack. If 0 the default size is used.
146 * @param task_priority The priority the shell runs at.
147 * @param forever Repeat logins.
148 * @param wait Caller should block until shell exits.
149 * @param login_check User login check function, NULL disables login checks.
150 *
151 */
152rtems_status_code rtems_shell_init(
153  const char *task_name,
154  size_t task_stacksize,
155  rtems_task_priority task_priority,
156  const char *devname,
157  bool forever,
158  bool wait,
159  rtems_shell_login_check_t login_check
160);
161
162/**
163 * Run a shell script creating a shell tasks to execute the command under.
164 *
165 * @param task_name Name of the shell task.
166 * @param task_stacksize The size of the stack. If 0 the default size is used.
167 * @param task_priority The priority the shell runs at.
168 * @param input The file of commands. Can be 'stdin' to use stdin.
169 * @param output The output file to write commands to. Can be 'stdout',
170 *              'stderr' or '/dev/null'.
171 * @param output_append Append the output to the file or truncate the file.
172 *                      Create if it does not exist.
173 * @param wait Wait for the script to finish.
174 */
175rtems_status_code rtems_shell_script(
176  const char          *task_name,
177  size_t               task_stacksize,  /* 0 default*/
178  rtems_task_priority  task_priority,
179  const char          *input,
180  const char          *output,
181  bool                 output_append,
182  bool                 wait,
183  bool                 echo
184);
185
186/*
187 *  Things that are useful to external entities developing commands and plugging
188 *  them in.
189 */
190int rtems_shell_str2int(const char * s);
191
192typedef struct {
193  rtems_name magic; /* 'S','E','N','V': Shell Environment */
194  const char *devname;
195  const char *taskname;
196  /* user extensions */
197  bool exit_shell; /* logout */
198  bool forever; /* repeat login */
199  int errorlevel;
200  bool echo;
201  char cwd [256];
202  const char *input;
203  const char *output;
204  bool output_append;
205  rtems_id wake_on_end;
206  rtems_shell_login_check_t login_check;
207} rtems_shell_env_t;
208
209bool rtems_shell_main_loop(
210  rtems_shell_env_t *rtems_shell_env
211);
212
213extern rtems_shell_env_t  rtems_global_shell_env;
214extern rtems_shell_env_t *rtems_current_shell_env;
215
216/*
217 * The types of file systems we can mount. We have them broken out
218 * out like this so they can be configured by shellconfig.h. The
219 * mount command needs special treatment due to some file systems
220 * being dependent on the network stack and some not. If we had
221 * all possible file systems being included it would force the
222 * networking stack into the applcation and this may not be
223 * required.
224 */
225struct rtems_shell_filesystems_tt;
226typedef struct rtems_shell_filesystems_tt rtems_shell_filesystems_t;
227
228typedef int (*rtems_shell_filesystems_mounter_t)(
229  const char*                driver,
230  const char*                path,
231  rtems_shell_filesystems_t* fs,
232  rtems_filesystem_options_t options
233);
234
235struct rtems_shell_filesystems_tt {
236  rtems_chain_node                         link;
237  const char                              *name;
238  int                                      driver_needed;
239  const rtems_filesystem_operations_table *fs_ops;
240  rtems_shell_filesystems_mounter_t        mounter;
241};
242
243/**
244 *  This method dynamically builds the command line prompt string
245 *  and places it in @a prompt.
246 *
247 *  @param[in] shell_env is the shell execution environment
248 *  @param[in] prompt is a pointer to a string buffer area
249 *  @param[in] size is length of the prompt buffer area
250 *
251 *  @return This method fills in the memory pointed to by @a prompt.
252 *
253 *  @note An application specific implementation can be provided
254 *        by the user.
255 */
256void rtems_shell_get_prompt(
257  rtems_shell_env_t *shell_env,
258  char              *prompt,
259  size_t             size
260);
261
262/**
263 * Helper for the mount command.
264 *
265 * @param[in] driver The path to the driver.
266 * @param[in] path The path to mount on.
267 * @param[in] fs The file system definition.
268 * @param[in] options Special file system options.
269 */
270int rtems_shell_libc_mounter(
271  const char*                driver,
272  const char*                path,
273  rtems_shell_filesystems_t* fs,
274  rtems_filesystem_options_t options
275);
276
277/**
278 * Add a new file system mount configuration to the mount command.
279 *
280 * @param[in] fs The file system mount data.
281 */
282void rtems_shell_mount_add_fsys(rtems_shell_filesystems_t* fs);
283
284/**
285 * Delete file system mount configuration from the mount command.
286 *
287 * @param[in] fs The file system mount data to remove.
288 */
289void rtems_shell_mount_del_fsys(rtems_shell_filesystems_t* fs);
290
291#ifdef __cplusplus
292}
293#endif
294
295#endif
Note: See TracBrowser for help on using the repository browser.