annotate rvinterf/etmsync/fswrite.c @ 290:76228aecf0d9

fc-fsio: mkdir and delete implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 28 Feb 2014 23:41:53 +0000
parents
children 69e8ae2b5ba2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
290
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * FFS write operation commands
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdlib.h>
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "etm.h"
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "ffs.h"
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "ffserr.h"
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "tmffs2.h"
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include "limits.h"
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 #include "localtypes.h"
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 #include "localstruct.h"
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 #include "exitcodes.h"
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 extern u_char rvi_msg[];
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 extern int rvi_msg_len;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 do_mkdir_existok(pathname)
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 char *pathname;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 {
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 int rc, slen;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 struct stat_info stat;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 slen = strlen(pathname);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 if (slen >= TMFFS_STRING_SIZE) {
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 printf("error: pathname arg exceeds string length limit\n");
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 return(ERROR_USAGE);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 }
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 dp = cmdpkt + 1;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 *dp++ = ETM_FFS2;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 *dp++ = TMFFS_MKDIR;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 *dp++ = slen + 1;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 strcpy(dp, pathname);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 dp += slen + 1;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 if (rc)
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 return(rc);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 if (rvi_msg_len != 5) {
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 printf("error: mkdir response has wrong length\n");
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 return(ERROR_TARGET);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 }
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 if (!rvi_msg[3]) /* success */
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 return(0);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 if (rvi_msg[3] != TMFFS_ERR_EXISTS) {
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 report_ffs_err("mkdir", rvi_msg[3]);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 return(ERROR_TARGET);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 }
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 /* object already exists: OK if it's a directory, error otherwise */
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 rc = do_xlstat(pathname, &stat);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 if (rc)
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 return(rc);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 if (stat.type == OT_DIR)
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 return(0);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 else {
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 printf("error: %s exists and is not a directory\n", pathname);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 return(ERROR_TARGET);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 }
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 }
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 cmd_mkdir(argc, argv)
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 char **argv;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 {
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 return do_mkdir_existok(argv[1]);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 }
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 cmd_delete(argc, argv)
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 char **argv;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 {
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 int rc, slen;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 slen = strlen(argv[1]);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 if (slen >= TMFFS_STRING_SIZE) {
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 printf("error: pathname arg exceeds string length limit\n");
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 return(ERROR_USAGE);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 }
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 dp = cmdpkt + 1;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 *dp++ = ETM_FFS2;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 *dp++ = TMFFS_REMOVE;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 *dp++ = slen + 1;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 strcpy(dp, argv[1]);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 dp += slen + 1;
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 if (rc)
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 return(rc);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 if (rvi_msg_len != 5) {
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 printf("error: TMFFS_REMOVE response has wrong length\n");
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 return(ERROR_TARGET);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 }
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 if (rvi_msg[3]) {
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 report_ffs_err("ffs_remove", rvi_msg[3]);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 return(ERROR_TARGET);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 }
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 return(0);
76228aecf0d9 fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 }