FreeCalypso > hg > freecalypso-sw
view 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 |
line wrap: on
line source
/* * FFS2 file descriptor I/O operations */ #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include "etm.h" #include "ffs.h" #include "tmffs2.h" #include "limits.h" #include "localtypes.h" #include "localstruct.h" #include "exitcodes.h" extern u_char rvi_msg[]; extern int rvi_msg_len; fd_open(pathname, flags, fdrtn) char *pathname; int flags, *fdrtn; { u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; int rc, slen; slen = strlen(pathname); if (slen >= TMFFS_STRING_SIZE) { printf("error: pathname arg exceeds string length limit\n"); return(ERROR_USAGE); } dp = cmdpkt + 1; *dp++ = ETM_FFS2; *dp++ = TMFFS_OPEN; *dp++ = slen + 1; strcpy(dp, pathname); dp += slen + 1; *dp++ = flags; rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1); if (rc) return(rc); if (rvi_msg[3]) { printf("open fd: FFS error %d\n", rvi_msg[3]); return(ERROR_TARGET); } if (rvi_msg_len != 6) { printf("error: open fd response has wrong length\n"); return(ERROR_TARGET); } *fdrtn = rvi_msg[4]; return(0); } fd_read(fd, databuf, rdsize, rdret) u_char *databuf; int fd, rdsize, *rdret; { u_char cmdpkt[6]; int rc, sz; if (rdsize > MAX_READ_DATA) { fprintf(stderr, "BUG: attempt to read more than possible per TMFFS2 protocol\n"); exit(ERROR_BUG); } cmdpkt[1] = ETM_FFS2; cmdpkt[2] = TMFFS_READ; cmdpkt[3] = fd; cmdpkt[4] = rdsize; rc = etm_pkt_exch(cmdpkt, 4); if (rc) return(rc); if (rvi_msg[3]) { printf("read fd: FFS error %d\n", rvi_msg[3]); return(ERROR_TARGET); } if (rvi_msg_len < 6) { *rdret = 0; return(0); } sz = rvi_msg[4]; if (rvi_msg_len != sz + 6 || sz > rdsize) { printf("error: read fd response has wrong length\n"); return(ERROR_TARGET); } bcopy(rvi_msg + 5, databuf, sz); *rdret = sz; return(0); } fd_close(fd) { u_char cmdpkt[5]; int rc; cmdpkt[1] = ETM_FFS2; cmdpkt[2] = TMFFS_CLOSE; cmdpkt[3] = fd; rc = etm_pkt_exch(cmdpkt, 3); if (rc) return(rc); if (rvi_msg[3]) { printf("close fd: FFS error %d\n", rvi_msg[3]); return(ERROR_TARGET); } if (rvi_msg_len != 5) { printf("error: close fd response has wrong length\n"); return(ERROR_TARGET); } return(0); }