source: examples-v2/misc/qemu_vfat/init.c @ bdaa948

4.11examples-v2-4-10-branch
Last change on this file since bdaa948 was bdaa948, checked in by Joel Sherrill <joel.sherrill@…>, on May 5, 2010 at 3:29:54 PM

2010-05-05 Joel Sherrill <joel.sherrill@…>

  • qemu_vfat/Makefile, qemu_vfat/README, qemu_vfat/init.c: Now includes a start_test example which parses arguments.
  • qemu_vfat/start_test.c: New file.
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2010.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#define CONFIGURE_INIT
13#include "system.h"
14#include <stdio.h>
15#include <string.h>
16#include <unistd.h>
17#include <stdlib.h>
18#include <errno.h>
19#include <rtems.h>
20#include <fcntl.h>
21#include <rtems/error.h>
22#include <rtems/dosfs.h>
23#include <ctype.h>
24#include <rtems/bdpart.h>
25#include <rtems/libcsupport.h>
26#include <rtems/fsmount.h>
27
28/*
29 * Table of FAT file systems that will be mounted
30 * with the "rtems_fsmount" function.
31 * See cpukit/libmisc/fsmount for definition of fields
32 */
33#define MOUNT_POINT "/mnt/test"
34fstab_t fs_table[] = {
35  {
36    "/dev/hda1", MOUNT_POINT,
37    &msdos_ops, RTEMS_FILESYSTEM_READ_WRITE,
38    FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED,
39    0
40  },
41};
42
43#ifndef USE_SHELL
44void start_test(void);
45#endif
46
47#ifdef USE_SHELL
48#include <rtems/shell.h>
49
50static void writeFile(
51  const char *name,
52  mode_t      mode,
53  const char *contents
54)
55{
56  int sc;
57  sc = setuid(0);
58  if ( sc ) {
59    printf( "setuid failed: %s: %s\n", name, strerror(errno) );
60  }
61
62  rtems_shell_write_file( name, contents );
63
64  sc = chmod ( name, mode );
65  if ( sc ) {
66    printf( "chmod %s: %s\n", name, strerror(errno) );
67  }
68}
69
70#define writeScript( _name, _contents ) \
71        writeFile( _name, 0777, _contents )
72
73static void fileio_start_shell(void)
74{
75  int sc;
76
77  sc = mkdir("/scripts", 0777);
78  if ( sc ) {
79    printf( "mkdir /scripts: %s:\n", strerror(errno) );
80  }
81
82  sc = mkdir("/etc", 0777);
83  if ( sc ) {
84    printf( "mkdir /etc: %s:\n", strerror(errno) );
85  }
86
87  fprintf(
88    stderr, 
89    "Creating /etc/passwd and group with three useable accounts\n"
90    "root/pwd , test/pwd, rtems/NO PASSWORD"
91  );
92
93  writeFile(
94    "/etc/passwd",
95    0644,
96    "root:7QR4o148UPtb.:0:0:root::/:/bin/sh\n"
97    "rtems:*:1:1:RTEMS Application::/:/bin/sh\n"
98    "test:8Yy.AaxynxbLI:2:2:test account::/:/bin/sh\n"
99    "tty:!:3:3:tty owner::/:/bin/false\n"
100  );
101  writeFile(
102    "/etc/group",
103    0644,
104    "root:x:0:root\n"
105    "rtems:x:1:rtems\n"
106    "test:x:2:test\n"
107    "tty:x:3:tty\n"
108  );
109
110  rtems_shell_init(
111    "SHLL",                          /* task_name */
112    RTEMS_MINIMUM_STACK_SIZE * 4,    /* task_stacksize */
113    100,                             /* task_priority */
114    "/dev/console",                  /* devname */
115    false,                           /* forever */
116    true,                            /* wait */
117    rtems_shell_login_check          /* login */
118  );
119}
120#endif /* USE_SHELL */
121
122/*
123 * RTEMS Startup Task
124 */
125rtems_task
126Init (rtems_task_argument ignored)
127{
128  rtems_status_code rc;
129
130  puts( "\n\n*** QEMU VFAT AND SHELL TEST ***" );
131
132  rc = rtems_bdpart_register_from_disk("/dev/hda");
133  if ( rc != RTEMS_SUCCESSFUL ) {
134    fprintf( stderr, "Unable to initialize partition table from /dev/hda\n" );
135    exit(1);
136  }
137
138  rc = rtems_fsmount(
139    fs_table,
140    sizeof(fs_table)/sizeof(fs_table[0]),
141    NULL
142  );
143  if ( rc != RTEMS_SUCCESSFUL ) {
144    fprintf( stderr, "Unable to mount /dev/hda1\n" );
145    exit(1);
146  }
147
148#if defined(USE_SHELL)
149  fileio_start_shell ();
150#endif
151#if defined(USE_START_TEST)
152  chdir( MOUNT_POINT );
153  start_test ();
154#endif
155  puts( "*** END OF QEMU VFAT AND SHELL TEST ***" );
156  exit(0);
157}
158
159#if defined(USE_SHELL)
160
161#define CONFIGURE_SHELL_COMMANDS_INIT
162#define CONFIGURE_SHELL_COMMANDS_ALL
163#define CONFIGURE_SHELL_MOUNT_MSDOS
164
165#include <rtems/shellconfig.h>
166#endif
Note: See TracBrowser for help on using the repository browser.