FreeCalypso > hg > freecalypso-sw
annotate rvinterf/etmsync/fswrite.c @ 900:2caa749fae34
gsm-fw: DSP patch codes added, extracted from TCS211 with tiobjd chararray
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Sun, 05 Jul 2015 03:05:13 +0000 |
parents | 3dd74b16df82 |
children | d1333db6385f |
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 do_mkdir_existok(pathname) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 char *pathname; |
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 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 int rc, slen; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 struct stat_info stat; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 slen = strlen(pathname); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 if (slen >= TMFFS_STRING_SIZE) { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 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
|
33 return(ERROR_USAGE); |
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 dp = cmdpkt + 1; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 *dp++ = ETM_FFS2; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 *dp++ = TMFFS_MKDIR; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 *dp++ = slen + 1; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 strcpy(dp, pathname); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 dp += slen + 1; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 if (rc) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 return(rc); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 if (rvi_msg_len != 5) { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 printf("error: mkdir response has wrong length\n"); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 return(ERROR_TARGET); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 if (!rvi_msg[3]) /* success */ |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 return(0); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 if (rvi_msg[3] != TMFFS_ERR_EXISTS) { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 report_ffs_err("mkdir", rvi_msg[3]); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 return(ERROR_TARGET); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 /* 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
|
55 rc = do_xlstat(pathname, &stat); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 if (rc) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 return(rc); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 if (stat.type == OT_DIR) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 return(0); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 else { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 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
|
62 return(ERROR_TARGET); |
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 |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 cmd_mkdir(argc, argv) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 char **argv; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 return do_mkdir_existok(argv[1]); |
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 |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 cmd_delete(argc, argv) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 char **argv; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 int rc, slen; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 slen = strlen(argv[1]); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 if (slen >= TMFFS_STRING_SIZE) { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 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
|
81 return(ERROR_USAGE); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 dp = cmdpkt + 1; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 *dp++ = ETM_FFS2; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 *dp++ = TMFFS_REMOVE; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 *dp++ = slen + 1; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 strcpy(dp, argv[1]); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 dp += slen + 1; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 if (rc) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 return(rc); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 if (rvi_msg_len != 5) { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 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
|
94 return(ERROR_TARGET); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 if (rvi_msg[3]) { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 report_ffs_err("ffs_remove", rvi_msg[3]); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 return(ERROR_TARGET); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 return(0); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 } |
291
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
102 |
292
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
103 hexdigit(c) |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
104 { |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
105 if (isdigit(c)) |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
106 return(c - '0'); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
107 else if (isupper(c)) |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
108 return(c - 'A' + 10); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
109 else |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
110 return(c - 'a' + 10); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
111 } |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
112 |
291
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
113 fwrite_hex_string(pathname, strarg) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
114 char *pathname, *strarg; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
115 { |
292
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
116 u_char buf[256]; |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
117 int maxlen, len; |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
118 char *cp; |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
119 |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
120 maxlen = max_short_file_write(pathname); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
121 for (cp = strarg, len = 0; ; cp += 2) { |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
122 while (isspace(*cp)) |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
123 cp++; |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
124 if (!*cp) |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
125 break; |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
126 if (!isxdigit(cp[0]) || !isxdigit(cp[1])) { |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
127 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
|
128 return(ERROR_USAGE); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
129 } |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
130 if (len >= maxlen) { |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
131 fprintf(stderr, |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
132 "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
|
133 return(ERROR_USAGE); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
134 } |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
135 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
|
136 } |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
137 return do_short_fwrite(pathname, buf, len); |
291
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
138 } |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
139 |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
140 fwrite_from_file(pathname, srcfile) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
141 char *pathname, *srcfile; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
142 { |
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
|
143 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
|
144 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
|
145 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
|
146 |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 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
|
151 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
159 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
|
160 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
|
161 &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
|
162 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
|
163 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
|
164 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
|
165 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
166 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
173 } |
ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
292
diff
changeset
|
174 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
|
175 if (first) { |
797468042b32
fc-fsio: fwrite from file: handling of 0 length files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
176 /* 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
|
177 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
|
178 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
|
179 &tfd); |
797468042b32
fc-fsio: fwrite from file: handling of 0 length files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
180 if (rc) |
797468042b32
fc-fsio: fwrite from file: handling of 0 length files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
181 return(rc); |
797468042b32
fc-fsio: fwrite from file: handling of 0 length files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
182 } |
797468042b32
fc-fsio: fwrite from file: handling of 0 length files implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
293
diff
changeset
|
183 return fd_close(tfd); |
291
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
184 } |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
185 |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
186 cmd_fwrite(argc, argv) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
187 char **argv; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
188 { |
295
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
294
diff
changeset
|
189 if (strlen(argv[1]) >= TMFFS_STRING_SIZE) { |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
294
diff
changeset
|
190 fprintf(stderr, |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
294
diff
changeset
|
191 "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
|
192 return(ERROR_USAGE); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
294
diff
changeset
|
193 } |
291
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
194 if (!strcmp(argv[2], "ascii")) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
195 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
|
196 else if (!strcmp(argv[2], "hex")) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
197 return fwrite_hex_string(argv[1], argv[3]); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
198 else if (!strcmp(argv[2], "file")) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
199 return fwrite_from_file(argv[1], argv[3]); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
200 else { |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
201 fprintf(stderr, |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
202 "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
|
203 ); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
204 return(ERROR_USAGE); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
205 } |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
206 } |