cfs/test/client/testDumpToVfs.cc
/**
 * Copies a file from FSP to VFS
 * @param path relative path from root of FSP to copy
 * @return 0 on success
 */
Copies a file from FSP to VFS
@param path relative path from root of FSP to copy
@return 0 on success
Copies a file from FSP to VFS @param path relative path from root of FSP to copy @return 0 on success
int copy_file(const std::string &path) {
  int orig_fd = fs_open(path.c_str(), O_RDONLY, 0);
  if (orig_fd == -1) {
    fprintf(stderr, "Cannot open file on FSP: %s", path.c_str());
  }
  int dest_fd = openat(dir_fd, path.c_str(), O_WRONLY | O_CREAT | O_EXCL, 0644); 
  if (dest_fd == -1) {
    if (errno == EEXIST) {
      fprintf(stderr, "WARNING: Overwriting existing file %s\n", path.c_str());
      dest_fd = openat(dir_fd, path.c_str(), O_WRONLY, 0644);
    } else {
      perror(("Cannot create regular file " + path).c_str());
      fs_close(orig_fd);
      return -1;
    }
  }
  std::cout << "FILE " << path << std::endl;
  char buf[COPY_BUF_SIZE];
  while (ssize_t size_read = fs_read(orig_fd, buf, COPY_BUF_SIZE)) {
    if (size_read == -1) {
      fprintf(stderr, "Error occurred when reading from CFS\n");
      return -1;
    }
    ssize_t size_written = write(dest_fd, buf, size_read);
    if (size_written == -1) {
      perror("Error occurred when writing output");
      return -1;
    }
  }
  close(dest_fd);
  fs_close(orig_fd);
  return 0;
}
int copy_file ( const std :: string & path ) { int orig_fd = fs_open ( path . c_str ( ) , O_RDONLY , 0 ) ; if ( orig_fd == -1 ) { fprintf ( stderr , " " , path . c_str ( ) ) ; } int dest_fd = openat ( dir_fd , path . c_str ( ) , O_WRONLY | O_CREAT | O_EXCL , 0644 ) ; if ( dest_fd == -1 ) { if ( errno == EEXIST ) { fprintf ( stderr , " \n " , path . c_str ( ) ) ; dest_fd = openat ( dir_fd , path . c_str ( ) , O_WRONLY , 0644 ) ; } else { perror ( ( " " + path ) . c_str ( ) ) ; fs_close ( orig_fd ) ; return -1 ; } } std :: cout << " " << path << std :: endl ; char buf [ COPY_BUF_SIZE ] ; while ( ssize_t size_read = fs_read ( orig_fd , buf , COPY_BUF_SIZE ) ) { if ( size_read == -1 ) { fprintf ( stderr , " \n " ) ; return -1 ; } ssize_t size_written = write ( dest_fd , buf , size_read ) ; if ( size_written == -1 ) { perror ( " " ) ; return -1 ; } } close ( dest_fd ) ; fs_close ( orig_fd ) ; return 0 ; }
Copies a file from FSP to VFS
 @param path relative path from root of FSP to copy
 @return 0 on success
Copies a file from FSP to VFS @param path relative path from root of FSP to copy @return 0 on success
// Open original file from FSP for reading // Create a new file for writing // NOLINT(hicpp-signed-bitwise) // Copy