# HG changeset patch # User Michael Spacefalcon # Date 1393577174 0 # Node ID e33d71e9033f241bb7b17b737ae5f25af92f1e0b # Parent 211b35db427cbf3988b31661d9773b2a249e174c fc-fsio: cpout directory recursion implemented diff -r 211b35db427c -r e33d71e9033f rvinterf/etmsync/fsread.c --- a/rvinterf/etmsync/fsread.c Fri Feb 28 08:22:50 2014 +0000 +++ b/rvinterf/etmsync/fsread.c Fri Feb 28 08:46:14 2014 +0000 @@ -3,10 +3,13 @@ */ #include +#include +#include #include #include #include #include +#include #include "etm.h" #include "ffs.h" #include "tmffs2.h" @@ -147,8 +150,7 @@ case OT_FILE: return cpout_file(ffspath, &stat, hostpath); case OT_DIR: - printf("cpout dir handling not yet implemented\n"); - return(ERROR_BUG); + return cpout_dir(ffspath, hostpath); case OT_LINK: printf("skipping FFS symlink %s\n", ffspath); return(0); @@ -192,6 +194,71 @@ return fd_close(tfd); } +host_mkdir(pathname) + char *pathname; +{ + int rc; + struct stat st; + + rc = stat(pathname, &st); + if (rc < 0) { + rc = mkdir(pathname, 0777); + if (rc < 0) { + perror(pathname); + return(ERROR_UNIX); + } + return(0); + } else { + if (S_ISDIR(st.st_mode)) + return(0); + else { + fprintf(stderr, + "error: %s already exists and is not a directory\n", + pathname); + return(ERROR_UNIX); + } + } +} + +cpout_dir(ffspath_dir, hostpath_dir) + char *ffspath_dir, *hostpath_dir; +{ + u_char rdstate[4]; + char rdbuf[TMFFS_STRING_SIZE], ffspath_child[TMFFS_STRING_SIZE*2]; + char hostpath_child[MAXPATHLEN]; + int nument, i, rc; + + printf("dir %s\n", ffspath_dir); + rc = host_mkdir(hostpath_dir); + if (rc) + return(rc); + rc = do_opendir(ffspath_dir, rdstate, &nument); + if (rc) + return(rc); + for (i = 0; i < nument; i++) { + rc = do_readdir(rdstate, rdbuf); + if (rc) + return(rc); + mk_ffs_child_path_from_readdir(ffspath_dir, rdbuf, + ffspath_child); + if (rdbuf[0] == '.') { + printf("skipping %s\n", ffspath_child); + return(0); + } + if (strlen(hostpath_dir) + strlen(rdbuf) + 2 > + sizeof hostpath_child) { + fprintf(stderr, + "error: host side pathname buffer overflow\n"); + return(ERROR_UNIX); + } + sprintf(hostpath_child, "%s/%s", hostpath_dir, rdbuf); + rc = cpout_object(ffspath_child, hostpath_child); + if (rc) + return(rc); + } + return(0); +} + cmd_cpout(argc, argv) char **argv; {