FreeCalypso > hg > freecalypso-sw
comparison rvinterf/etmsync/fsread.c @ 288:e33d71e9033f
fc-fsio: cpout directory recursion implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Fri, 28 Feb 2014 08:46:14 +0000 |
parents | 211b35db427c |
children | 3dd74b16df82 |
comparison
equal
deleted
inserted
replaced
287:211b35db427c | 288:e33d71e9033f |
---|---|
1 /* | 1 /* |
2 * Commands for reading the content of a GSM device's file system | 2 * Commands for reading the content of a GSM device's file system |
3 */ | 3 */ |
4 | 4 |
5 #include <sys/types.h> | 5 #include <sys/types.h> |
6 #include <sys/param.h> | |
7 #include <sys/stat.h> | |
6 #include <stdio.h> | 8 #include <stdio.h> |
7 #include <stdlib.h> | 9 #include <stdlib.h> |
8 #include <string.h> | 10 #include <string.h> |
9 #include <strings.h> | 11 #include <strings.h> |
12 #include <unistd.h> | |
10 #include "etm.h" | 13 #include "etm.h" |
11 #include "ffs.h" | 14 #include "ffs.h" |
12 #include "tmffs2.h" | 15 #include "tmffs2.h" |
13 #include "limits.h" | 16 #include "limits.h" |
14 #include "localtypes.h" | 17 #include "localtypes.h" |
145 return(rc); | 148 return(rc); |
146 switch (stat.type) { | 149 switch (stat.type) { |
147 case OT_FILE: | 150 case OT_FILE: |
148 return cpout_file(ffspath, &stat, hostpath); | 151 return cpout_file(ffspath, &stat, hostpath); |
149 case OT_DIR: | 152 case OT_DIR: |
150 printf("cpout dir handling not yet implemented\n"); | 153 return cpout_dir(ffspath, hostpath); |
151 return(ERROR_BUG); | |
152 case OT_LINK: | 154 case OT_LINK: |
153 printf("skipping FFS symlink %s\n", ffspath); | 155 printf("skipping FFS symlink %s\n", ffspath); |
154 return(0); | 156 return(0); |
155 default: | 157 default: |
156 printf("error: stat returned bad objtype for %s\n", ffspath); | 158 printf("error: stat returned bad objtype for %s\n", ffspath); |
190 } | 192 } |
191 fclose(of); | 193 fclose(of); |
192 return fd_close(tfd); | 194 return fd_close(tfd); |
193 } | 195 } |
194 | 196 |
197 host_mkdir(pathname) | |
198 char *pathname; | |
199 { | |
200 int rc; | |
201 struct stat st; | |
202 | |
203 rc = stat(pathname, &st); | |
204 if (rc < 0) { | |
205 rc = mkdir(pathname, 0777); | |
206 if (rc < 0) { | |
207 perror(pathname); | |
208 return(ERROR_UNIX); | |
209 } | |
210 return(0); | |
211 } else { | |
212 if (S_ISDIR(st.st_mode)) | |
213 return(0); | |
214 else { | |
215 fprintf(stderr, | |
216 "error: %s already exists and is not a directory\n", | |
217 pathname); | |
218 return(ERROR_UNIX); | |
219 } | |
220 } | |
221 } | |
222 | |
223 cpout_dir(ffspath_dir, hostpath_dir) | |
224 char *ffspath_dir, *hostpath_dir; | |
225 { | |
226 u_char rdstate[4]; | |
227 char rdbuf[TMFFS_STRING_SIZE], ffspath_child[TMFFS_STRING_SIZE*2]; | |
228 char hostpath_child[MAXPATHLEN]; | |
229 int nument, i, rc; | |
230 | |
231 printf("dir %s\n", ffspath_dir); | |
232 rc = host_mkdir(hostpath_dir); | |
233 if (rc) | |
234 return(rc); | |
235 rc = do_opendir(ffspath_dir, rdstate, &nument); | |
236 if (rc) | |
237 return(rc); | |
238 for (i = 0; i < nument; i++) { | |
239 rc = do_readdir(rdstate, rdbuf); | |
240 if (rc) | |
241 return(rc); | |
242 mk_ffs_child_path_from_readdir(ffspath_dir, rdbuf, | |
243 ffspath_child); | |
244 if (rdbuf[0] == '.') { | |
245 printf("skipping %s\n", ffspath_child); | |
246 return(0); | |
247 } | |
248 if (strlen(hostpath_dir) + strlen(rdbuf) + 2 > | |
249 sizeof hostpath_child) { | |
250 fprintf(stderr, | |
251 "error: host side pathname buffer overflow\n"); | |
252 return(ERROR_UNIX); | |
253 } | |
254 sprintf(hostpath_child, "%s/%s", hostpath_dir, rdbuf); | |
255 rc = cpout_object(ffspath_child, hostpath_child); | |
256 if (rc) | |
257 return(rc); | |
258 } | |
259 return(0); | |
260 } | |
261 | |
195 cmd_cpout(argc, argv) | 262 cmd_cpout(argc, argv) |
196 char **argv; | 263 char **argv; |
197 { | 264 { |
198 return cpout_object(argv[1], argv[2]); | 265 return cpout_object(argv[1], argv[2]); |
199 } | 266 } |