FreeCalypso > hg > freecalypso-sw
annotate rvinterf/etmsync/fileio.c @ 954:d25d73815817
c139explore: jump command added
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Wed, 04 Nov 2015 19:57:45 +0000 |
parents | d1333db6385f |
children |
rev | line source |
---|---|
284
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * FFS2 file descriptor I/O operations |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdlib.h> |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <string.h> |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <strings.h> |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include "etm.h" |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "ffs.h" |
910
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
12 #include "ffserr.h" |
284
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "tmffs2.h" |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include "limits.h" |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 #include "localtypes.h" |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 #include "localstruct.h" |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 #include "exitcodes.h" |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 extern u_char rvi_msg[]; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 extern int rvi_msg_len; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 fd_open(pathname, flags, fdrtn) |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 char *pathname; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 int flags, *fdrtn; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 { |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 int rc, slen; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 slen = strlen(pathname); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 if (slen >= TMFFS_STRING_SIZE) { |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 printf("error: pathname arg exceeds string length limit\n"); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 return(ERROR_USAGE); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 dp = cmdpkt + 1; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 *dp++ = ETM_FFS2; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 *dp++ = TMFFS_OPEN; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 *dp++ = slen + 1; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 strcpy(dp, pathname); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 dp += slen + 1; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 *dp++ = flags; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 if (rc) |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 return(rc); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 if (rvi_msg[3]) { |
289
244f08f58e51
fc-fsio: error decoding implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
286
diff
changeset
|
45 report_ffs_err("open fd", rvi_msg[3]); |
284
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 return(ERROR_TARGET); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 if (rvi_msg_len != 6) { |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 printf("error: open fd response has wrong length\n"); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 return(ERROR_TARGET); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 *fdrtn = rvi_msg[4]; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 return(0); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 fd_read(fd, databuf, rdsize, rdret) |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 u_char *databuf; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 int fd, rdsize, *rdret; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 { |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 u_char cmdpkt[6]; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 int rc, sz; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 if (rdsize > MAX_READ_DATA) { |
286
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
285
diff
changeset
|
64 printf("error: # of bytes to read may not exceed %d\n", |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
285
diff
changeset
|
65 MAX_READ_DATA); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
285
diff
changeset
|
66 return(ERROR_USAGE); |
284
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 cmdpkt[1] = ETM_FFS2; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 cmdpkt[2] = TMFFS_READ; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 cmdpkt[3] = fd; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 cmdpkt[4] = rdsize; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 rc = etm_pkt_exch(cmdpkt, 4); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 if (rc) |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 return(rc); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 if (rvi_msg[3]) { |
289
244f08f58e51
fc-fsio: error decoding implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
286
diff
changeset
|
76 report_ffs_err("read fd", rvi_msg[3]); |
284
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 return(ERROR_TARGET); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 if (rvi_msg_len < 6) { |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 *rdret = 0; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 return(0); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 sz = rvi_msg[4]; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 if (rvi_msg_len != sz + 6 || sz > rdsize) { |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 printf("error: read fd response has wrong length\n"); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 return(ERROR_TARGET); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 bcopy(rvi_msg + 5, databuf, sz); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 *rdret = sz; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 return(0); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 |
293
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
93 fd_write(fd, data, wrsize) |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
94 u_char *data; |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
95 { |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
96 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
97 int rc; |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
98 |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
99 if (wrsize > MAX_PKT_TO_TARGET - 6) { |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
100 printf("error: fd write data fails to fit in the packet\n"); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
101 return(ERROR_USAGE); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
102 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
103 dp = cmdpkt + 1; |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
104 *dp++ = ETM_FFS2; |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
105 *dp++ = TMFFS_WRITE; |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
106 *dp++ = fd; |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
107 *dp++ = wrsize; |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
108 bcopy(data, dp, wrsize); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
109 dp += wrsize; |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
110 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
111 if (rc) |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
112 return(rc); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
113 if (rvi_msg[3]) { |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
114 report_ffs_err("fd write", rvi_msg[3]); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
115 return(ERROR_TARGET); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
116 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
117 if (rvi_msg_len != 6) { |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
118 printf("error: TMFFS_WRITE response has wrong length\n"); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
119 return(ERROR_TARGET); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
120 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
121 if (rvi_msg[4] != wrsize) { |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
122 printf("fd write error: # of bytes written != requested\n"); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
123 return(ERROR_TARGET); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
124 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
125 return(0); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
126 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
127 |
284
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
128 fd_close(fd) |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
129 { |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
130 u_char cmdpkt[5]; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
131 int rc; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
132 |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
133 cmdpkt[1] = ETM_FFS2; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
134 cmdpkt[2] = TMFFS_CLOSE; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
135 cmdpkt[3] = fd; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
136 rc = etm_pkt_exch(cmdpkt, 3); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
137 if (rc) |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
138 return(rc); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
139 if (rvi_msg[3]) { |
289
244f08f58e51
fc-fsio: error decoding implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
286
diff
changeset
|
140 report_ffs_err("close fd", rvi_msg[3]); |
284
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
141 return(ERROR_TARGET); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
142 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
143 if (rvi_msg_len != 5) { |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
144 printf("error: close fd response has wrong length\n"); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
145 return(ERROR_TARGET); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
146 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
147 return(0); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
148 } |
285
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
149 |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
150 do_file_read(pathname, databuf, rdsize, rdret) |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
151 char *pathname; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
152 u_char *databuf; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
153 int rdsize, *rdret; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
154 { |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
155 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
156 int rc, slen, sz; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
157 |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
158 slen = strlen(pathname); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
159 if (slen >= TMFFS_STRING_SIZE) { |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
160 printf("error: pathname arg exceeds string length limit\n"); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
161 return(ERROR_USAGE); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
162 } |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
163 if (rdsize > MAX_READ_DATA) { |
286
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
285
diff
changeset
|
164 printf("error: # of bytes to read may not exceed %d\n", |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
285
diff
changeset
|
165 MAX_READ_DATA); |
146e7bf3fa4e
fc-fsio: fd debug commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
285
diff
changeset
|
166 return(ERROR_USAGE); |
285
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
167 } |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
168 dp = cmdpkt + 1; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
169 *dp++ = ETM_FFS2; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
170 *dp++ = TMFFS_FILE_READ; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
171 *dp++ = slen + 1; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
172 strcpy(dp, pathname); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
173 dp += slen + 1; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
174 *dp++ = rdsize; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
175 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
176 if (rc) |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
177 return(rc); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
178 if (rvi_msg[3]) { |
289
244f08f58e51
fc-fsio: error decoding implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
286
diff
changeset
|
179 report_ffs_err("read file", rvi_msg[3]); |
285
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
180 return(ERROR_TARGET); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
181 } |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
182 if (rvi_msg_len < 6) { |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
183 *rdret = 0; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
184 return(0); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
185 } |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
186 sz = rvi_msg[4]; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
187 if (rvi_msg_len != sz + 6 || sz > rdsize) { |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
188 printf("error: read file response has wrong length\n"); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
189 return(ERROR_TARGET); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
190 } |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
191 bcopy(rvi_msg + 5, databuf, sz); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
192 *rdret = sz; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
193 return(0); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
194 } |
291
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
195 |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
196 max_short_file_write(pathname) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
197 char *pathname; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
198 { |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
199 return MAX_PKT_TO_TARGET - 3 - (strlen(pathname) + 2) - 3; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
200 } |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
201 |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
202 do_short_fwrite(pathname, data, datalen) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
203 char *pathname; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
204 u_char *data; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
205 { |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
206 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
207 int rc, slen; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
208 |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
209 slen = strlen(pathname); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
210 if (slen >= TMFFS_STRING_SIZE) { |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
211 printf("error: pathname arg exceeds string length limit\n"); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
212 return(ERROR_USAGE); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
213 } |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
214 if (datalen > max_short_file_write(pathname)) { |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
215 printf("error: short write data fails to fit in the packet\n"); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
216 return(ERROR_USAGE); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
217 } |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
218 dp = cmdpkt + 1; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
219 *dp++ = ETM_FFS2; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
220 *dp++ = TMFFS_FILE_WRITE; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
221 *dp++ = slen + 1; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
222 strcpy(dp, pathname); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
223 dp += slen + 1; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
224 *dp++ = datalen; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
225 bcopy(data, dp, datalen); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
226 dp += datalen; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
227 *dp++ = FFS_O_CREATE | FFS_O_TRUNC; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
228 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
229 if (rc) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
230 return(rc); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
231 if (rvi_msg_len != 5) { |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
232 printf("error: TMFFS_FILE_WRITE response has wrong length\n"); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
233 return(ERROR_TARGET); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
234 } |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
235 if (rvi_msg[3]) { |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
236 report_ffs_err("short file write", rvi_msg[3]); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
237 return(ERROR_TARGET); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
238 } |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
239 return(0); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
289
diff
changeset
|
240 } |
910
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
241 |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
242 do_opendir(pathname, statertn, countrtn) |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
243 char *pathname; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
244 u_char *statertn; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
245 int *countrtn; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
246 { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
247 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
248 int rc, slen; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
249 |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
250 slen = strlen(pathname); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
251 if (slen >= TMFFS_STRING_SIZE) { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
252 printf("error: pathname arg exceeds string length limit\n"); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
253 return(ERROR_USAGE); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
254 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
255 dp = cmdpkt + 1; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
256 *dp++ = ETM_FFS2; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
257 *dp++ = TMFFS_OPENDIR; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
258 *dp++ = slen + 1; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
259 strcpy(dp, pathname); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
260 dp += slen + 1; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
261 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
262 if (rc) |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
263 return(rc); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
264 if (rvi_msg[3]) { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
265 report_ffs_err("opendir", rvi_msg[3]); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
266 return(ERROR_TARGET); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
267 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
268 if (rvi_msg_len != 11 || rvi_msg[5] != 4) { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
269 printf("error: opendir response has wrong length\n"); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
270 return(ERROR_TARGET); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
271 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
272 *countrtn = rvi_msg[4]; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
273 bcopy(rvi_msg + 6, statertn, 4); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
274 return(0); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
275 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
276 |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
277 do_readdir(state, namebuf, namebuflen) |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
278 u_char *state; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
279 char *namebuf; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
280 { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
281 u_char cmdpkt[10]; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
282 int rc, slen; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
283 |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
284 cmdpkt[1] = ETM_FFS2; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
285 cmdpkt[2] = TMFFS_READDIR; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
286 cmdpkt[3] = 4; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
287 bcopy(state, cmdpkt+4, 4); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
288 cmdpkt[8] = TMFFS_STRING_SIZE; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
289 rc = etm_pkt_exch(cmdpkt, 8); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
290 if (rc) |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
291 return(rc); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
292 if (rvi_msg[3]) { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
293 report_ffs_err("readdir", rvi_msg[3]); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
294 return(ERROR_TARGET); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
295 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
296 if (rvi_msg_len < 14) { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
297 malformed: printf("error: readdir response is malformed\n"); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
298 return(ERROR_TARGET); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
299 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
300 if (rvi_msg[5] != 4) |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
301 goto malformed; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
302 slen = rvi_msg[10]; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
303 if (slen < 2 || rvi_msg_len != slen + 12) |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
304 goto malformed; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
305 if (slen > namebuflen) { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
306 printf("error: readdir response exceeds provided buffer\n"); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
307 return(ERROR_TARGET); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
308 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
309 if (rvi_msg[11 + slen - 1]) /* must be terminating NUL */ |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
310 goto malformed; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
311 bcopy(rvi_msg + 6, state, 4); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
312 strcpy(namebuf, rvi_msg + 11); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
313 return(0); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
314 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
315 |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
316 do_xlstat(pathname, result) |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
317 char *pathname; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
318 struct stat_info *result; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
319 { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
320 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
321 int rc, slen; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
322 |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
323 slen = strlen(pathname); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
324 if (slen >= TMFFS_STRING_SIZE) { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
325 printf("error: pathname arg exceeds string length limit\n"); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
326 return(ERROR_USAGE); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
327 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
328 dp = cmdpkt + 1; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
329 *dp++ = ETM_FFS2; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
330 *dp++ = TMFFS_XLSTAT; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
331 *dp++ = slen + 1; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
332 strcpy(dp, pathname); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
333 dp += slen + 1; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
334 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
335 if (rc) |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
336 return(rc); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
337 if (rvi_msg[3]) { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
338 report_ffs_err("xlstat", rvi_msg[3]); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
339 return(ERROR_TARGET); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
340 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
341 if (rvi_msg_len != 30 || rvi_msg[4] != 24) { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
342 printf("error: xlstat response has wrong length\n"); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
343 return(ERROR_TARGET); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
344 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
345 result->type = rvi_msg[5]; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
346 result->flags = rvi_msg[6]; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
347 result->inode = rvi_msg[7] | rvi_msg[8] << 8; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
348 result->size = rvi_msg[9] | rvi_msg[10] << 8 | rvi_msg[11] << 16 | |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
349 rvi_msg[12] << 24; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
350 result->space = rvi_msg[13] | rvi_msg[14] << 8 | rvi_msg[15] << 16 | |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
351 rvi_msg[16] << 24; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
352 result->location = rvi_msg[17] | rvi_msg[18] << 8 | rvi_msg[19] << 16 | |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
353 rvi_msg[20] << 24; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
354 result->block = rvi_msg[22]; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
355 result->sequence = rvi_msg[23] | rvi_msg[24] << 8; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
356 result->updates = rvi_msg[25] | rvi_msg[26] << 8; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
357 return(0); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
358 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
359 |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
360 do_mkdir_existok(pathname) |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
361 char *pathname; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
362 { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
363 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
364 int rc, slen; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
365 struct stat_info stat; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
366 |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
367 slen = strlen(pathname); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
368 if (slen >= TMFFS_STRING_SIZE) { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
369 printf("error: pathname arg exceeds string length limit\n"); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
370 return(ERROR_USAGE); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
371 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
372 dp = cmdpkt + 1; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
373 *dp++ = ETM_FFS2; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
374 *dp++ = TMFFS_MKDIR; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
375 *dp++ = slen + 1; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
376 strcpy(dp, pathname); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
377 dp += slen + 1; |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
378 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
379 if (rc) |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
380 return(rc); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
381 if (rvi_msg_len != 5) { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
382 printf("error: mkdir response has wrong length\n"); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
383 return(ERROR_TARGET); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
384 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
385 if (!rvi_msg[3]) /* success */ |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
386 return(0); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
387 if (rvi_msg[3] != TMFFS_ERR_EXISTS) { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
388 report_ffs_err("mkdir", rvi_msg[3]); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
389 return(ERROR_TARGET); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
390 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
391 /* object already exists: OK if it's a directory, error otherwise */ |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
392 rc = do_xlstat(pathname, &stat); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
393 if (rc) |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
394 return(rc); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
395 if (stat.type == OT_DIR) |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
396 return(0); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
397 else { |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
398 printf("error: %s exists and is not a directory\n", pathname); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
399 return(ERROR_TARGET); |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
400 } |
d1333db6385f
rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
401 } |