FreeCalypso > hg > freecalypso-sw
annotate rvinterf/etmsync/fileio.c @ 285:bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Fri, 28 Feb 2014 06:16:02 +0000 |
parents | 7b4d4e3e610a |
children | 146e7bf3fa4e |
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" |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include "tmffs2.h" |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "limits.h" |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include "localtypes.h" |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 #include "localstruct.h" |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 #include "exitcodes.h" |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 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
|
19 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
|
20 |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 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
|
22 char *pathname; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 int flags, *fdrtn; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 { |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 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
|
26 int rc, slen; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 slen = strlen(pathname); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 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
|
30 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
|
31 return(ERROR_USAGE); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 dp = cmdpkt + 1; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 *dp++ = ETM_FFS2; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 *dp++ = TMFFS_OPEN; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 *dp++ = slen + 1; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 strcpy(dp, pathname); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 dp += slen + 1; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 *dp++ = flags; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 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
|
41 if (rc) |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 return(rc); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 if (rvi_msg[3]) { |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 printf("open fd: FFS error %d\n", rvi_msg[3]); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 return(ERROR_TARGET); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 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
|
48 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
|
49 return(ERROR_TARGET); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 *fdrtn = rvi_msg[4]; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 return(0); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 } |
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 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
|
56 u_char *databuf; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 int fd, rdsize, *rdret; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 { |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 u_char cmdpkt[6]; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 int rc, sz; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 if (rdsize > MAX_READ_DATA) { |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 fprintf(stderr, |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 "BUG: attempt to read more than possible per TMFFS2 protocol\n"); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 exit(ERROR_BUG); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 cmdpkt[1] = ETM_FFS2; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 cmdpkt[2] = TMFFS_READ; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 cmdpkt[3] = fd; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 cmdpkt[4] = rdsize; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 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
|
72 if (rc) |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 return(rc); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 if (rvi_msg[3]) { |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 printf("read fd: FFS error %d\n", rvi_msg[3]); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 return(ERROR_TARGET); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 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
|
79 *rdret = 0; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 return(0); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 sz = rvi_msg[4]; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 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
|
84 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
|
85 return(ERROR_TARGET); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 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
|
88 *rdret = sz; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 return(0); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 } |
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 fd_close(fd) |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 { |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 u_char cmdpkt[5]; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 int rc; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 cmdpkt[1] = ETM_FFS2; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 cmdpkt[2] = TMFFS_CLOSE; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 cmdpkt[3] = fd; |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 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
|
101 if (rc) |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 return(rc); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 if (rvi_msg[3]) { |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 printf("close fd: FFS error %d\n", rvi_msg[3]); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 return(ERROR_TARGET); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
106 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
107 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
|
108 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
|
109 return(ERROR_TARGET); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
110 } |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
111 return(0); |
7b4d4e3e610a
fc-fsio: functions written for file descriptor open/read/close
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
112 } |
285
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
113 |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
114 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
|
115 char *pathname; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
116 u_char *databuf; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
117 int rdsize, *rdret; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
118 { |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
119 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
|
120 int rc, slen, sz; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
121 |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
122 slen = strlen(pathname); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
123 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
|
124 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
|
125 return(ERROR_USAGE); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
126 } |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
127 if (rdsize > MAX_READ_DATA) { |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
128 fprintf(stderr, |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
129 "BUG: attempt to read more than possible per TMFFS2 protocol\n"); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
130 exit(ERROR_BUG); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
131 } |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
132 dp = cmdpkt + 1; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
133 *dp++ = ETM_FFS2; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
134 *dp++ = TMFFS_FILE_READ; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
135 *dp++ = slen + 1; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
136 strcpy(dp, pathname); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
137 dp += slen + 1; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
138 *dp++ = rdsize; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
139 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
|
140 if (rc) |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
141 return(rc); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
142 if (rvi_msg[3]) { |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
143 printf("read file: FFS error %d\n", rvi_msg[3]); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
144 return(ERROR_TARGET); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
145 } |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
146 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
|
147 *rdret = 0; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
148 return(0); |
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 sz = rvi_msg[4]; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
151 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
|
152 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
|
153 return(ERROR_TARGET); |
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 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
|
156 *rdret = sz; |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
157 return(0); |
bb28ba9e82c5
fc-fsio: file read primitive and hd command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
284
diff
changeset
|
158 } |