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