comparison rvinterf/etmsync/fdcmd.c @ 286:146e7bf3fa4e

fc-fsio: fd debug commands implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 28 Feb 2014 06:45:10 +0000
parents
children 69e8ae2b5ba2
comparison
equal deleted inserted replaced
285:bb28ba9e82c5 286:146e7bf3fa4e
1 /*
2 * File descriptor debug commands
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <strings.h>
10 #include "etm.h"
11 #include "ffs.h"
12 #include "tmffs2.h"
13 #include "limits.h"
14 #include "localtypes.h"
15 #include "localstruct.h"
16 #include "cmdtab.h"
17 #include "exitcodes.h"
18
19 cmd_fd_open(argc, argv)
20 char **argv;
21 {
22 int rc, fd;
23
24 rc = fd_open(argv[1], strtoul(argv[2], 0, 0), &fd);
25 if (rc)
26 return(rc);
27 printf("%d\n", fd);
28 return(0);
29 }
30
31 cmd_fd_read(argc, argv)
32 char **argv;
33 {
34 u_char databuf[MAX_READ_DATA];
35 int rc, sz, off, l;
36
37 rc = fd_read(strtoul(argv[1], 0, 0), databuf, strtoul(argv[2], 0, 0),
38 &sz);
39 if (rc)
40 return(rc);
41 printf("%d bytes read\n", sz);
42 for (off = 0; off < sz; off += 16) {
43 l = sz - off;
44 if (l > 16)
45 l = 16;
46 hexdump_line(off, databuf + off, l);
47 }
48 return(0);
49 }
50
51 cmd_fd_close(argc, argv)
52 char **argv;
53 {
54 return fd_close(strtoul(argv[1], 0, 0));
55 }
56
57 struct cmdtab fd_cmds[] = {
58 {"close", 1, 1, cmd_fd_close},
59 {"open", 2, 2, cmd_fd_open},
60 {"read", 2, 2, cmd_fd_read},
61 {0, 0, 0, 0}
62 };
63
64 cmd_fd(argc, argv)
65 char **argv;
66 {
67 struct cmdtab *tp;
68 int extargs;
69
70 for (tp = fd_cmds; tp->cmd; tp++)
71 if (!strcmp(tp->cmd, argv[1]))
72 break;
73 if (!tp->func) {
74 fprintf(stderr, "error: no such fd command\n");
75 return(ERROR_USAGE);
76 }
77 extargs = argc - 2;
78 if (extargs > tp->maxargs) {
79 fprintf(stderr, "error: too many arguments\n");
80 return(ERROR_USAGE);
81 }
82 if (extargs < tp->minargs) {
83 fprintf(stderr, "error: too few arguments\n");
84 return(ERROR_USAGE);
85 }
86 return tp->func(argc - 1, argv + 1);
87 }