annotate rvinterf/etmsync/fileio.c @ 284:7b4d4e3e610a

fc-fsio: functions written for file descriptor open/read/close
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 28 Feb 2014 05:50:01 +0000
parents
children bb28ba9e82c5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 }