FreeCalypso > hg > freecalypso-sw
annotate rvinterf/etmsync/fswrite.c @ 1023:cd6002e3aefb
doc/Freerunner-Howto: apparently some people still use SHR, so mention it too
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Tue, 03 May 2016 13:48:39 +0000 |
parents | d1333db6385f |
children |
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> |
292
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
6 #include <ctype.h> |
290
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdio.h> |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <stdlib.h> |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <string.h> |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <strings.h> |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "etm.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include "ffs.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "ffserr.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include "tmffs2.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 #include "limits.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 #include "localtypes.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 #include "localstruct.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 #include "exitcodes.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 extern u_char rvi_msg[]; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 extern int rvi_msg_len; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 cmd_mkdir(argc, argv) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 char **argv; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 return do_mkdir_existok(argv[1]); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 } |
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 cmd_delete(argc, argv) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 char **argv; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 int rc, slen; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 slen = strlen(argv[1]); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 if (slen >= TMFFS_STRING_SIZE) { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 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
|
38 return(ERROR_USAGE); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 dp = cmdpkt + 1; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 *dp++ = ETM_FFS2; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 *dp++ = TMFFS_REMOVE; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 *dp++ = slen + 1; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 strcpy(dp, argv[1]); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 dp += slen + 1; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 if (rc) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 return(rc); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 if (rvi_msg_len != 5) { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 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
|
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 if (rvi_msg[3]) { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 report_ffs_err("ffs_remove", rvi_msg[3]); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 return(ERROR_TARGET); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 return(0); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 } |
291
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
59 |
292
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
60 hexdigit(c) |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
61 { |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
62 if (isdigit(c)) |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
63 return(c - '0'); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
64 else if (isupper(c)) |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
65 return(c - 'A' + 10); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
66 else |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
67 return(c - 'a' + 10); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
68 } |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
69 |
291
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
70 fwrite_hex_string(pathname, strarg) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
71 char *pathname, *strarg; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
72 { |
292
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
73 u_char buf[256]; |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
74 int maxlen, len; |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
75 char *cp; |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
76 |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
77 maxlen = max_short_file_write(pathname); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
78 for (cp = strarg, len = 0; ; cp += 2) { |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
79 while (isspace(*cp)) |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
80 cp++; |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
81 if (!*cp) |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
82 break; |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
83 if (!isxdigit(cp[0]) || !isxdigit(cp[1])) { |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
84 fprintf(stderr, "error: invalid hex string argument\n"); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
85 return(ERROR_USAGE); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
86 } |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
87 if (len >= maxlen) { |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
88 fprintf(stderr, |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
89 "error: hex string exceeds write packet limit\n"); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
90 return(ERROR_USAGE); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
91 } |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
92 buf[len++] = hexdigit(cp[0]) << 4 | hexdigit(cp[1]); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
93 } |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
94 return do_short_fwrite(pathname, buf, len); |
291
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
95 } |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
96 |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
97 fwrite_from_file(pathname, srcfile) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
98 char *pathname, *srcfile; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
99 { |
293
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
100 u_char buf[240]; |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
101 FILE *srcf; |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
102 int rc, cc, first, tfd; |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
103 |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
104 srcf = fopen(srcfile, "r"); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
105 if (!srcf) { |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
106 perror(srcfile); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
107 return(ERROR_UNIX); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
108 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
109 for (first = 1; cc = fread(buf, 1, sizeof buf, srcf); first = 0) { |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
110 if (first) { |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
111 if (cc < sizeof buf && |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
112 cc <= max_short_file_write(pathname)) { |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
113 fclose(srcf); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
114 return do_short_fwrite(pathname, buf, cc); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
115 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
116 rc = fd_open(pathname, |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
117 FFS_O_WRONLY | FFS_O_CREATE | FFS_O_TRUNC, |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
118 &tfd); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
119 if (rc) { |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
120 fclose(srcf); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
121 return(rc); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
122 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
123 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
124 rc = fd_write(tfd, buf, cc); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
125 if (rc) { |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
126 fclose(srcf); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
127 fd_close(tfd); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
128 return(rc); |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
129 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
130 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
131 fclose(srcf); |
294
797468042b32
fc-fsio: fwrite from file: handling of 0 length files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
132 if (first) { |
797468042b32
fc-fsio: fwrite from file: handling of 0 length files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
133 /* 0 length file: do an open-for-write to create it */ |
797468042b32
fc-fsio: fwrite from file: handling of 0 length files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
134 rc = fd_open(pathname, |
797468042b32
fc-fsio: fwrite from file: handling of 0 length files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
135 FFS_O_WRONLY | FFS_O_CREATE | FFS_O_TRUNC, |
797468042b32
fc-fsio: fwrite from file: handling of 0 length files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
136 &tfd); |
797468042b32
fc-fsio: fwrite from file: handling of 0 length files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
137 if (rc) |
797468042b32
fc-fsio: fwrite from file: handling of 0 length files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
138 return(rc); |
797468042b32
fc-fsio: fwrite from file: handling of 0 length files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
139 } |
797468042b32
fc-fsio: fwrite from file: handling of 0 length files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
140 return fd_close(tfd); |
291
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
141 } |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
142 |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
143 cmd_fwrite(argc, argv) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
144 char **argv; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
145 { |
295
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
294
diff
changeset
|
146 if (strlen(argv[1]) >= TMFFS_STRING_SIZE) { |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
294
diff
changeset
|
147 fprintf(stderr, |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
294
diff
changeset
|
148 "error: pathname arg exceeds string length limit\n"); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
294
diff
changeset
|
149 return(ERROR_USAGE); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
294
diff
changeset
|
150 } |
291
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
151 if (!strcmp(argv[2], "ascii")) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
152 return do_short_fwrite(argv[1], argv[3], strlen(argv[3])); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
153 else if (!strcmp(argv[2], "hex")) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
154 return fwrite_hex_string(argv[1], argv[3]); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
155 else if (!strcmp(argv[2], "file")) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
156 return fwrite_from_file(argv[1], argv[3]); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
157 else { |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
158 fprintf(stderr, |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
159 "error: middle argument to fwrite cmd must be \"ascii\", \"hex\" or \"file\"\n" |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
160 ); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
161 return(ERROR_USAGE); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
162 } |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
163 } |