FreeCalypso > hg > freecalypso-sw
comparison rvinterf/etmsync/fsbasics.c @ 279:36ad667341fc
fc-fsio: ls implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 24 Feb 2014 07:27:37 +0000 |
parents | f77480d3dd21 |
children | 517e8a428fde |
comparison
equal
deleted
inserted
replaced
278:f77480d3dd21 | 279:36ad667341fc |
---|---|
3 */ | 3 */ |
4 | 4 |
5 #include <sys/types.h> | 5 #include <sys/types.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | |
9 #include <strings.h> | |
8 #include "etm.h" | 10 #include "etm.h" |
9 #include "ffs.h" | 11 #include "ffs.h" |
10 #include "tmffs2.h" | 12 #include "tmffs2.h" |
13 #include "limits.h" | |
11 #include "exitcodes.h" | 14 #include "exitcodes.h" |
12 | 15 |
13 extern u_char rvi_msg[]; | 16 extern u_char rvi_msg[]; |
14 extern int rvi_msg_len; | 17 extern int rvi_msg_len; |
15 | 18 |
32 return(ERROR_TARGET); | 35 return(ERROR_TARGET); |
33 } | 36 } |
34 printf("FFS2 version: %02X.%02X\n", rvi_msg[5], rvi_msg[4]); | 37 printf("FFS2 version: %02X.%02X\n", rvi_msg[5], rvi_msg[4]); |
35 return(0); | 38 return(0); |
36 } | 39 } |
40 | |
41 do_opendir(pathname, statertn, countrtn) | |
42 char *pathname; | |
43 u_char *statertn; | |
44 int *countrtn; | |
45 { | |
46 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
47 int rc, slen; | |
48 | |
49 slen = strlen(pathname); | |
50 if (slen >= TMFFS_STRING_SIZE) { | |
51 printf("error: pathname arg exceeds string length limit\n"); | |
52 return(ERROR_USAGE); | |
53 } | |
54 dp = cmdpkt + 1; | |
55 *dp++ = ETM_FFS2; | |
56 *dp++ = TMFFS_OPENDIR; | |
57 *dp++ = slen + 1; | |
58 strcpy(dp, pathname); | |
59 dp += slen + 1; | |
60 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1); | |
61 if (rc) | |
62 return(rc); | |
63 if (rvi_msg[3]) { | |
64 printf("opendir: FFS error %d\n", rvi_msg[3]); | |
65 return(ERROR_TARGET); | |
66 } | |
67 if (rvi_msg_len != 11 || rvi_msg[5] != 4) { | |
68 printf("error: opendir response has wrong length\n"); | |
69 return(ERROR_TARGET); | |
70 } | |
71 *countrtn = rvi_msg[4]; | |
72 bcopy(rvi_msg + 6, statertn, 4); | |
73 return(0); | |
74 } | |
75 | |
76 do_readdir(state, namebuf) | |
77 u_char *state; | |
78 char *namebuf; | |
79 { | |
80 u_char cmdpkt[10]; | |
81 int rc, slen; | |
82 | |
83 cmdpkt[1] = ETM_FFS2; | |
84 cmdpkt[2] = TMFFS_READDIR; | |
85 cmdpkt[3] = 4; | |
86 bcopy(state, cmdpkt+4, 4); | |
87 cmdpkt[8] = TMFFS_STRING_SIZE; | |
88 rc = etm_pkt_exch(cmdpkt, 8); | |
89 if (rc) | |
90 return(rc); | |
91 if (rvi_msg[3]) { | |
92 printf("readdir: FFS error %d\n", rvi_msg[3]); | |
93 return(ERROR_TARGET); | |
94 } | |
95 if (rvi_msg_len < 14) { | |
96 malformed: printf("error: readdir response is malformed\n"); | |
97 return(ERROR_TARGET); | |
98 } | |
99 if (rvi_msg[5] != 4) | |
100 goto malformed; | |
101 slen = rvi_msg[10]; | |
102 if (slen < 2 || slen > TMFFS_STRING_SIZE) | |
103 goto malformed; | |
104 if (rvi_msg[11 + slen - 1]) /* must be terminating NUL */ | |
105 goto malformed; | |
106 bcopy(rvi_msg + 6, state, 4); | |
107 strcpy(namebuf, rvi_msg + 11); | |
108 return(0); | |
109 } | |
110 | |
111 cmd_ls(argc, argv) | |
112 char **argv; | |
113 { | |
114 u_char state[4]; | |
115 char namebuf[TMFFS_STRING_SIZE]; | |
116 int nument, i, rc; | |
117 | |
118 rc = do_opendir(argv[1], state, &nument); | |
119 if (rc) | |
120 return(rc); | |
121 if (!nument) { | |
122 printf("<empty dir>\n"); | |
123 return(0); | |
124 } | |
125 for (i = 0; i < nument; i++) { | |
126 rc = do_readdir(state, namebuf); | |
127 if (rc) | |
128 return(rc); | |
129 printf("%s\n", namebuf); | |
130 } | |
131 return(0); | |
132 } |