comparison rvinterf/etmsync/fsread.c @ 287:211b35db427c

fc-fsio: cpout of single files implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 28 Feb 2014 08:22:50 +0000
parents bb28ba9e82c5
children e33d71e9033f
comparison
equal deleted inserted replaced
286:146e7bf3fa4e 287:211b35db427c
131 l = 16; 131 l = 16;
132 hexdump_line(off, databuf + off, l); 132 hexdump_line(off, databuf + off, l);
133 } 133 }
134 return(0); 134 return(0);
135 } 135 }
136
137 cpout_object(ffspath, hostpath)
138 char *ffspath, *hostpath;
139 {
140 struct stat_info stat;
141 int rc;
142
143 rc = do_xlstat(ffspath, &stat);
144 if (rc)
145 return(rc);
146 switch (stat.type) {
147 case OT_FILE:
148 return cpout_file(ffspath, &stat, hostpath);
149 case OT_DIR:
150 printf("cpout dir handling not yet implemented\n");
151 return(ERROR_BUG);
152 case OT_LINK:
153 printf("skipping FFS symlink %s\n", ffspath);
154 return(0);
155 default:
156 printf("error: stat returned bad objtype for %s\n", ffspath);
157 return(ERROR_TARGET);
158 }
159 }
160
161 cpout_file(ffspath, stat, hostpath)
162 char *ffspath, *hostpath;
163 struct stat_info *stat;
164 {
165 int tfd;
166 FILE *of;
167 u_char buf[MAX_READ_DATA];
168 int rc, sz;
169
170 printf("copying %s\n", ffspath);
171 rc = fd_open(ffspath, FFS_O_RDONLY, &tfd);
172 if (rc)
173 return(rc);
174 of = fopen(hostpath, "w");
175 if (!of) {
176 perror(hostpath);
177 fd_close(tfd);
178 return(ERROR_UNIX);
179 }
180 for (;;) {
181 rc = fd_read(tfd, buf, MAX_READ_DATA, &sz);
182 if (rc) {
183 fd_close(tfd);
184 fclose(of);
185 return(rc);
186 }
187 if (!sz)
188 break;
189 fwrite(buf, 1, sz, of);
190 }
191 fclose(of);
192 return fd_close(tfd);
193 }
194
195 cmd_cpout(argc, argv)
196 char **argv;
197 {
198 return cpout_object(argv[1], argv[2]);
199 }