annotate rvinterf/etmsync/fsbasics.c @ 291:69e8ae2b5ba2

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