annotate rvinterf/etmsync/fsbasics.c @ 305:4dccc9d3305f

gsm-fw: checking in DAR from Leonardo source
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 16 Mar 2014 05:48:58 +0000
parents 3dd74b16df82
children d1333db6385f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
278
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * Basic FFS2 operations
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdlib.h>
279
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
8 #include <string.h>
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
9 #include <strings.h>
278
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "etm.h"
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "ffs.h"
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "tmffs2.h"
279
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
13 #include "limits.h"
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 289
diff changeset
14 #include "ffslimits.h"
282
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
15 #include "localtypes.h"
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
16 #include "localstruct.h"
278
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 #include "exitcodes.h"
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 extern u_char rvi_msg[];
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 extern int rvi_msg_len;
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 cmd_ffs2ver()
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 {
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 u_char cmdpkt[4];
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 int rc;
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 cmdpkt[1] = ETM_FFS2;
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 cmdpkt[2] = TMFFS_VERSION;
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 rc = etm_pkt_exch(cmdpkt, 2);
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 if (rc)
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 return(rc);
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 if (rvi_msg[3]) {
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 printf("FFS2 error %d\n", rvi_msg[3]);
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 return(ERROR_TARGET);
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 }
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 if (rvi_msg_len != 7) {
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 printf("error: FFS2 version response has wrong length\n");
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 return(ERROR_TARGET);
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 }
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 printf("FFS2 version: %02X.%02X\n", rvi_msg[5], rvi_msg[4]);
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 return(0);
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 }
279
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
43
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
44 do_opendir(pathname, statertn, countrtn)
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
45 char *pathname;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
46 u_char *statertn;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
47 int *countrtn;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
48 {
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
49 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
50 int rc, slen;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
51
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
52 slen = strlen(pathname);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
53 if (slen >= TMFFS_STRING_SIZE) {
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
54 printf("error: pathname arg exceeds string length limit\n");
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
55 return(ERROR_USAGE);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
56 }
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
57 dp = cmdpkt + 1;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
58 *dp++ = ETM_FFS2;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
59 *dp++ = TMFFS_OPENDIR;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
60 *dp++ = slen + 1;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
61 strcpy(dp, pathname);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
62 dp += slen + 1;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
63 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
64 if (rc)
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
65 return(rc);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
66 if (rvi_msg[3]) {
289
244f08f58e51 fc-fsio: error decoding implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 282
diff changeset
67 report_ffs_err("opendir", rvi_msg[3]);
279
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
68 return(ERROR_TARGET);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
69 }
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
70 if (rvi_msg_len != 11 || rvi_msg[5] != 4) {
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
71 printf("error: opendir response has wrong length\n");
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
72 return(ERROR_TARGET);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
73 }
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
74 *countrtn = rvi_msg[4];
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
75 bcopy(rvi_msg + 6, statertn, 4);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
76 return(0);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
77 }
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
78
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 289
diff changeset
79 do_readdir(state, namebuf, namebuflen)
279
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
80 u_char *state;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
81 char *namebuf;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
82 {
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
83 u_char cmdpkt[10];
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
84 int rc, slen;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
85
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
86 cmdpkt[1] = ETM_FFS2;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
87 cmdpkt[2] = TMFFS_READDIR;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
88 cmdpkt[3] = 4;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
89 bcopy(state, cmdpkt+4, 4);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
90 cmdpkt[8] = TMFFS_STRING_SIZE;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
91 rc = etm_pkt_exch(cmdpkt, 8);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
92 if (rc)
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
93 return(rc);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
94 if (rvi_msg[3]) {
289
244f08f58e51 fc-fsio: error decoding implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 282
diff changeset
95 report_ffs_err("readdir", rvi_msg[3]);
279
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
96 return(ERROR_TARGET);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
97 }
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
98 if (rvi_msg_len < 14) {
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
99 malformed: printf("error: readdir response is malformed\n");
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
100 return(ERROR_TARGET);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
101 }
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
102 if (rvi_msg[5] != 4)
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
103 goto malformed;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
104 slen = rvi_msg[10];
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 289
diff changeset
105 if (slen < 2 || rvi_msg_len != slen + 12)
279
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
106 goto malformed;
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 289
diff changeset
107 if (slen > namebuflen) {
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 289
diff changeset
108 printf("error: readdir response exceeds provided buffer\n");
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 289
diff changeset
109 return(ERROR_TARGET);
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 289
diff changeset
110 }
279
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
111 if (rvi_msg[11 + slen - 1]) /* must be terminating NUL */
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
112 goto malformed;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
113 bcopy(rvi_msg + 6, state, 4);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
114 strcpy(namebuf, rvi_msg + 11);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
115 return(0);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
116 }
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
117
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
118 cmd_ls(argc, argv)
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
119 char **argv;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
120 {
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
121 u_char state[4];
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 289
diff changeset
122 char namebuf[256];
279
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
123 int nument, i, rc;
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
124
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
125 rc = do_opendir(argv[1], state, &nument);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
126 if (rc)
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
127 return(rc);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
128 if (!nument) {
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
129 printf("<empty dir>\n");
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
130 return(0);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
131 }
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
132 for (i = 0; i < nument; i++) {
295
3dd74b16df82 fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 289
diff changeset
133 rc = do_readdir(state, namebuf, sizeof namebuf);
279
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
134 if (rc)
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
135 return(rc);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
136 printf("%s\n", namebuf);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
137 }
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
138 return(0);
36ad667341fc fc-fsio: ls implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 278
diff changeset
139 }
282
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
140
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
141 do_xlstat(pathname, result)
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
142 char *pathname;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
143 struct stat_info *result;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
144 {
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
145 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
146 int rc, slen;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
147
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
148 slen = strlen(pathname);
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
149 if (slen >= TMFFS_STRING_SIZE) {
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
150 printf("error: pathname arg exceeds string length limit\n");
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
151 return(ERROR_USAGE);
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
152 }
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
153 dp = cmdpkt + 1;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
154 *dp++ = ETM_FFS2;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
155 *dp++ = TMFFS_XLSTAT;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
156 *dp++ = slen + 1;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
157 strcpy(dp, pathname);
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
158 dp += slen + 1;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
159 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1);
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
160 if (rc)
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
161 return(rc);
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
162 if (rvi_msg[3]) {
289
244f08f58e51 fc-fsio: error decoding implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 282
diff changeset
163 report_ffs_err("xlstat", rvi_msg[3]);
282
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
164 return(ERROR_TARGET);
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
165 }
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
166 if (rvi_msg_len != 30 || rvi_msg[4] != 24) {
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
167 printf("error: xlstat response has wrong length\n");
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
168 return(ERROR_TARGET);
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
169 }
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
170 result->type = rvi_msg[5];
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
171 result->flags = rvi_msg[6];
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
172 result->inode = rvi_msg[7] | rvi_msg[8] << 8;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
173 result->size = rvi_msg[9] | rvi_msg[10] << 8 | rvi_msg[11] << 16 |
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
174 rvi_msg[12] << 24;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
175 result->space = rvi_msg[13] | rvi_msg[14] << 8 | rvi_msg[15] << 16 |
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
176 rvi_msg[16] << 24;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
177 result->location = rvi_msg[17] | rvi_msg[18] << 8 | rvi_msg[19] << 16 |
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
178 rvi_msg[20] << 24;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
179 result->block = rvi_msg[22];
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
180 result->sequence = rvi_msg[23] | rvi_msg[24] << 8;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
181 result->updates = rvi_msg[25] | rvi_msg[26] << 8;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
182 return(0);
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
183 }
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
184
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
185 cmd_stat(argc, argv)
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
186 char **argv;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
187 {
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
188 struct stat_info stat;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
189 int rc;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
190 char *type;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
191
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
192 rc = do_xlstat(argv[1], &stat);
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
193 if (rc)
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
194 return(rc);
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
195 switch (stat.type) {
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
196 case OT_FILE:
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
197 type = "file";
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
198 break;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
199 case OT_DIR:
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
200 type = "directory";
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
201 break;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
202 case OT_LINK:
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
203 type = "symlink";
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
204 break;
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
205 default:
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
206 type = "???";
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
207 }
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
208 printf("Type: %s%s\n", type,
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
209 stat.flags & OF_READONLY ? ", read-only" : "");
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
210 printf("inode %x\n", stat.inode);
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
211 printf("size %u, space %u\n", stat.size, stat.space);
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
212 printf("location=%x, block %d\n", stat.location, stat.block);
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
213 return(0);
517e8a428fde fc-fsio: xlstat operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 279
diff changeset
214 }