FreeCalypso > hg > freecalypso-sw
diff 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 |
line wrap: on
line diff
--- a/rvinterf/etmsync/fsread.c Fri Feb 28 06:45:10 2014 +0000 +++ b/rvinterf/etmsync/fsread.c Fri Feb 28 08:22:50 2014 +0000 @@ -133,3 +133,67 @@ } return(0); } + +cpout_object(ffspath, hostpath) + char *ffspath, *hostpath; +{ + struct stat_info stat; + int rc; + + rc = do_xlstat(ffspath, &stat); + if (rc) + return(rc); + switch (stat.type) { + case OT_FILE: + return cpout_file(ffspath, &stat, hostpath); + case OT_DIR: + printf("cpout dir handling not yet implemented\n"); + return(ERROR_BUG); + case OT_LINK: + printf("skipping FFS symlink %s\n", ffspath); + return(0); + default: + printf("error: stat returned bad objtype for %s\n", ffspath); + return(ERROR_TARGET); + } +} + +cpout_file(ffspath, stat, hostpath) + char *ffspath, *hostpath; + struct stat_info *stat; +{ + int tfd; + FILE *of; + u_char buf[MAX_READ_DATA]; + int rc, sz; + + printf("copying %s\n", ffspath); + rc = fd_open(ffspath, FFS_O_RDONLY, &tfd); + if (rc) + return(rc); + of = fopen(hostpath, "w"); + if (!of) { + perror(hostpath); + fd_close(tfd); + return(ERROR_UNIX); + } + for (;;) { + rc = fd_read(tfd, buf, MAX_READ_DATA, &sz); + if (rc) { + fd_close(tfd); + fclose(of); + return(rc); + } + if (!sz) + break; + fwrite(buf, 1, sz, of); + } + fclose(of); + return fd_close(tfd); +} + +cmd_cpout(argc, argv) + char **argv; +{ + return cpout_object(argv[1], argv[2]); +}