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

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

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

  • qemu_vfat/.cvsignore, qemu_vfat/Makefile, qemu_vfat/README, qemu_vfat/init.c, qemu_vfat/system.h: New files.
  • Property mode set to 100644
File size: 3.4 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 */
33fstab_t fs_table[] = {
34  {
35    "/dev/hda1", "/mnt/test",
36    &msdos_ops, RTEMS_FILESYSTEM_READ_WRITE,
37    FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED,
38    0
39  },
40};
41
42#ifndef USE_SHELL
43void start_test(void);
44#endif
45
46#ifdef USE_SHELL
47#include <rtems/shell.h>
48
49static void writeFile(
50  const char *name,
51  mode_t      mode,
52  const char *contents
53)
54{
55  int sc;
56  sc = setuid(0);
57  if ( sc ) {
58    printf( "setuid failed: %s: %s\n", name, strerror(errno) );
59  }
60
61  rtems_shell_write_file( name, contents );
62
63  sc = chmod ( name, mode );
64  if ( sc ) {
65    printf( "chmod %s: %s\n", name, strerror(errno) );
66  }
67}
68
69#define writeScript( _name, _contents ) \
70        writeFile( _name, 0777, _contents )
71
72static void fileio_start_shell(void)
73{
74  int sc;
75
76  sc = mkdir("/scripts", 0777);
77  if ( sc ) {
78    printf( "mkdir /scripts: %s:\n", strerror(errno) );
79  }
80
81  sc = mkdir("/etc", 0777);
82  if ( sc ) {
83    printf( "mkdir /etc: %s:\n", strerror(errno) );
84  }
85
86  fprintf(
87    stderr, 
88    "Creating /etc/passwd and group with three useable accounts\n"
89    "root/pwd , test/pwd, rtems/NO PASSWORD"
90  );
91
92  writeFile(
93    "/etc/passwd",
94    0644,
95    "root:7QR4o148UPtb.:0:0:root::/:/bin/sh\n"
96    "rtems:*:1:1:RTEMS Application::/:/bin/sh\n"
97    "test:8Yy.AaxynxbLI:2:2:test account::/:/bin/sh\n"
98    "tty:!:3:3:tty owner::/:/bin/false\n"
99  );
100  writeFile(
101    "/etc/group",
102    0644,
103    "root:x:0:root\n"
104    "rtems:x:1:rtems\n"
105    "test:x:2:test\n"
106    "tty:x:3:tty\n"
107  );
108
109  rtems_shell_init(
110    "SHLL",                          /* task_name */
111    RTEMS_MINIMUM_STACK_SIZE * 4,    /* task_stacksize */
112    100,                             /* task_priority */
113    "/dev/console",                  /* devname */
114    false,                           /* forever */
115    true,                            /* wait */
116    rtems_shell_login_check          /* login */
117  );
118}
119#endif /* USE_SHELL */
120
121/*
122 * RTEMS Startup Task
123 */
124rtems_task
125Init (rtems_task_argument ignored)
126{
127  rtems_status_code rc;
128
129  puts( "\n\n*** QEMU VFAT AND SHELL TEST ***" );
130
131  rc = rtems_bdpart_register_from_disk("/dev/hda");
132  if ( rc != RTEMS_SUCCESSFUL ) {
133    fprintf( stderr, "Unable to initialize partition table from /dev/hda\n" );
134    exit(1);
135  }
136
137  rc = rtems_fsmount(
138    fs_table,
139    sizeof(fs_table)/sizeof(fs_table[0]),
140    NULL
141  );
142  if ( rc != RTEMS_SUCCESSFUL ) {
143    fprintf( stderr, "Unable to mount /dev/hda1\n" );
144    exit(1);
145  }
146
147#if defined(USE_SHELL)
148  fileio_start_shell ();
149#endif
150#if defined(USE_START_TEST)
151  start_test ();
152#endif
153  puts( "*** END OF QEMU VFAT AND SHELL TEST ***" );
154  exit(0);
155}
156
157#if defined(USE_SHELL)
158
159#define CONFIGURE_SHELL_COMMANDS_INIT
160#define CONFIGURE_SHELL_COMMANDS_ALL
161#define CONFIGURE_SHELL_MOUNT_MSDOS
162
163#include <rtems/shellconfig.h>
164#endif
Note: See TracBrowser for help on using the repository browser.