1 | /* |
---|
2 | * RM Shell Command Implmentation |
---|
3 | * |
---|
4 | * Author: Fernando RUIZ CASAS |
---|
5 | * Work: fernando.ruiz@ctv.es |
---|
6 | * Home: correo@fernando-ruiz.com |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.rtems.org/license/LICENSE. |
---|
11 | */ |
---|
12 | |
---|
13 | #ifdef HAVE_CONFIG_H |
---|
14 | #include "config.h" |
---|
15 | #endif |
---|
16 | |
---|
17 | #include <stdio.h> |
---|
18 | #include <unistd.h> |
---|
19 | #include <string.h> |
---|
20 | #include <errno.h> |
---|
21 | #include <fcntl.h> |
---|
22 | |
---|
23 | #include <rtems.h> |
---|
24 | #include <rtems/shell.h> |
---|
25 | #include <rtems/bdbuf.h> |
---|
26 | #include <rtems/blkdev.h> |
---|
27 | #include "internal.h" |
---|
28 | |
---|
29 | static int rtems_shell_main_blksync( |
---|
30 | int argc, |
---|
31 | char *argv[] |
---|
32 | ) |
---|
33 | { |
---|
34 | const char* driver = NULL; |
---|
35 | int arg; |
---|
36 | int fd; |
---|
37 | |
---|
38 | for (arg = 1; arg < argc; arg++) { |
---|
39 | if (argv[arg][0] == '-') { |
---|
40 | fprintf( stderr, "%s: invalid option: %s\n", argv[0], argv[arg]); |
---|
41 | return 1; |
---|
42 | } else { |
---|
43 | if (!driver) |
---|
44 | driver = argv[arg]; |
---|
45 | else { |
---|
46 | fprintf( stderr, "%s: only one driver name allowed: %s\n", |
---|
47 | argv[0], argv[arg]); |
---|
48 | return 1; |
---|
49 | } |
---|
50 | } |
---|
51 | } |
---|
52 | |
---|
53 | fd = open (driver, O_WRONLY, 0); |
---|
54 | if (fd < 0) { |
---|
55 | fprintf( stderr, "%s: driver open failed: %s\n", argv[0], strerror (errno)); |
---|
56 | return 1; |
---|
57 | } |
---|
58 | |
---|
59 | if (rtems_disk_fd_sync (fd) < 0) { |
---|
60 | fprintf( stderr, "%s: driver sync failed: %s\n", argv[0], strerror (errno)); |
---|
61 | return 1; |
---|
62 | } |
---|
63 | |
---|
64 | close (fd); |
---|
65 | return 0; |
---|
66 | } |
---|
67 | |
---|
68 | rtems_shell_cmd_t rtems_shell_BLKSYNC_Command = { |
---|
69 | "blksync", /* name */ |
---|
70 | "blksync driver # sync the block driver", /* usage */ |
---|
71 | "files", /* topic */ |
---|
72 | rtems_shell_main_blksync, /* command */ |
---|
73 | NULL, /* alias */ |
---|
74 | NULL /* next */ |
---|
75 | }; |
---|