comparison rvinterf/etmsync/fsupload.c @ 297:0242d5facf7b

fc-fsio: upload-fs implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 01 Mar 2014 09:07:03 +0000
parents
children 91570f916dd3
comparison
equal deleted inserted replaced
296:792f164b63a6 297:0242d5facf7b
1 /*
2 * upload-fs implementation
3 */
4
5 #include <sys/types.h>
6 #include <sys/param.h>
7 #include <sys/stat.h>
8 #include <dirent.h>
9 #include <ctype.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <strings.h>
14 #include "etm.h"
15 #include "ffs.h"
16 #include "ffserr.h"
17 #include "tmffs2.h"
18 #include "limits.h"
19 #include "ffslimits.h"
20 #include "localtypes.h"
21 #include "localstruct.h"
22 #include "exitcodes.h"
23
24 uploadfs_level(srcpath, depth, prefix)
25 char *srcpath, *prefix;
26 {
27 char ffs_childpath[MAX_FULL_PATHNAME+1], *ffs_childp;
28 DIR *rdd;
29 struct dirent *dirent;
30 char hostpath_child[MAXPATHLEN];
31 struct stat hst;
32 int rc;
33
34 strcpy(ffs_childpath, prefix);
35 ffs_childp = index(ffs_childpath, '\0');
36 *ffs_childp++ = '/';
37 rdd = opendir(srcpath);
38 if (!rdd) {
39 perror(srcpath);
40 return(ERROR_UNIX);
41 }
42 while (dirent = readdir(rdd)) {
43 if (dirent->d_name[0] == '.')
44 continue;
45 if (strlen(dirent->d_name) > MAX_FN_COMPONENT) {
46 fprintf(stderr,
47 "error: \"%s\" in %s exceeds the FFS component name limit\n",
48 dirent->d_name, srcpath);
49 closedir(rdd);
50 return(ERROR_USAGE);
51 }
52 if (strlen(srcpath) + strlen(dirent->d_name) + 2 >
53 sizeof hostpath_child) {
54 fprintf(stderr,
55 "error: host side pathname buffer overflow\n");
56 closedir(rdd);
57 return(ERROR_UNIX);
58 }
59 sprintf(hostpath_child, "%s/%s", srcpath, dirent->d_name);
60 if (lstat(hostpath_child, &hst) < 0) {
61 perror(hostpath_child);
62 closedir(rdd);
63 return(ERROR_UNIX);
64 }
65 strcpy(ffs_childp, dirent->d_name);
66 switch (hst.st_mode & S_IFMT) {
67 case S_IFREG:
68 printf("uploading %s\n", ffs_childpath);
69 rc = fwrite_from_file(ffs_childpath, hostpath_child);
70 if (rc) {
71 closedir(rdd);
72 return(rc);
73 }
74 break;
75 case S_IFDIR:
76 if (depth >= MAX_NAME_DEPTH-1) {
77 fprintf(stderr,
78 "error: directory nesting too deep at %s\n",
79 hostpath_child);
80 closedir(rdd);
81 return(ERROR_USAGE);
82 }
83 printf("mkdir %s\n", ffs_childpath);
84 rc = do_mkdir_existok(ffs_childpath);
85 if (rc) {
86 closedir(rdd);
87 return(rc);
88 }
89 rc = uploadfs_level(hostpath_child, depth + 1,
90 ffs_childpath);
91 if (rc) {
92 closedir(rdd);
93 return(rc);
94 }
95 break;
96 default:
97 fprintf(stderr,
98 "error: %s is neither a regular file nor a directory\n",
99 hostpath_child);
100 closedir(rdd);
101 return(ERROR_USAGE);
102 }
103 }
104 closedir(rdd);
105 return(0);
106 }
107
108 cmd_uploadfs(argc, argv)
109 char **argv;
110 {
111 return uploadfs_level(argv[1], 0, "");
112 }