char _io_dun_read_char ( /* [IN] the file handle for the device */ MQX_FILE_PTR fd_ptr ) { /* Body */ IODUN_STRUCT_PTR ras_ptr = fd_ptr->DEV_DATA_PTR; IODUN_DEV_STRUCT_PTR dev_ptr = fd_ptr->DEV_PTR->DRIVER_INIT_PTR; if (ras_ptr->STATE == 0) { ras_ptr->PARSE = dev_ptr->RECV; for (;;) { ras_ptr->F_CHAR = _io_fgetc(ras_ptr->F_PTR); ras_ptr->STATE++; if (ras_ptr->F_CHAR != *ras_ptr->PARSE++) { ras_ptr->PARSE = dev_ptr->RECV; break; } /* Endif */ if (ras_ptr->STATE == dev_ptr->RECV_SIZE) { _io_write(ras_ptr->F_PTR, dev_ptr->SEND, dev_ptr->SEND_SIZE); ras_ptr->STATE = 0; ras_ptr->PARSE = dev_ptr->RECV; } /* Endif */ } /* Endfor */ } /* Endif */ if (--ras_ptr->STATE) { return *ras_ptr->PARSE++; } else { return ras_ptr->F_CHAR; } /* Endif */ } /* Endbody */
gboolean io_write_raw (IOStream *io, gsize nbytes, gconstpointer buf, GError **err) { gconstpointer bufiter = buf; g_assert (io->mode == IO_MODE_WRITE); while (nbytes > 0) { gsize ntowrite; ntowrite = MIN (nbytes, io->bufsz - io->s.write.curpos); if (io->s.write.curpos == 0 && ntowrite == io->bufsz) { /* We'd write an entire buffer of data. We can short-circuit * the copying of the data to the write buffer. */ if (_io_fd_write (io->fd, bufiter, ntowrite, err)) return TRUE; } else { memcpy (io->s.write.buf + io->s.write.curpos, bufiter, ntowrite); io->s.write.curpos += ntowrite; } if (io->s.write.curpos == io->bufsz) { /* We've filled up the buffer. Write it out. */ if (_io_write (io, err)) return TRUE; } bufiter += ntowrite; nbytes -= ntowrite; } return FALSE; }
_mqx_int _io_dun_write ( /* [IN] the file handle for the device */ MQX_FILE_PTR fd_ptr, /* [IN] where the characters are */ char_ptr data_ptr, /* [IN] the number of characters to output */ _mqx_int num ) { /* Body */ IODUN_STRUCT_PTR ras_ptr = fd_ptr->DEV_DATA_PTR; return _io_write(ras_ptr->F_PTR, data_ptr, num); } /* Endbody */
gboolean io_write_typed (IOStream *io, DSType type, gsize nvals, gconstpointer buf, GError **err) { gconstpointer bufiter = buf; guint8 tsize = ds_type_sizes[type]; gsize nbytes = nvals * tsize; g_assert (io->mode == IO_MODE_WRITE); while (nbytes > 0) { gsize nbytestowrite, nvalstowrite; nbytestowrite = MIN (nbytes, io->bufsz - io->s.write.curpos); if (nbytestowrite % tsize != 0) { g_assert (0); /*g_set_error (err, foo, foo, "Alignment error in typed data write");*/ return TRUE; } nvalstowrite = nbytestowrite / tsize; /* Unlike the untyped write, we can't save a copy in the whole- * buffer case since we need to byteswap the data anyway. */ io_recode_data_copy (bufiter, io->s.write.buf + io->s.write.curpos, type, nvalstowrite); io->s.write.curpos += nbytestowrite; if (io->s.write.curpos == io->bufsz) { /* We've filled up the buffer. Write it out. */ if (_io_write (io, err)) return TRUE; } bufiter += nbytestowrite; nbytes -= nbytestowrite; } return FALSE; }
gboolean io_pipe (IOStream *input, IOStream *output, GError **err) { gsize neof; /* Invariants to make life easier. */ g_return_val_if_fail (input->bufsz == output->bufsz, TRUE); g_assert (input->mode & IO_MODE_READ); g_assert (output->mode & IO_MODE_WRITE); if (input->s.read.curpos == input->bufsz) { if (_io_read (input, err)) return TRUE; } if (output->s.write.curpos == output->bufsz) { if (_io_write (output, err)) return TRUE; } g_return_val_if_fail (input->s.read.curpos == output->s.write.curpos, TRUE); while (!input->s.read.eof) { if (_io_fd_write (output->fd, input->s.read.buf + input->s.read.curpos, input->bufsz - input->s.read.curpos, err)) return TRUE; if (_io_read (input, err)) return TRUE; } neof = input->s.read.endpos - input->s.read.curpos; if (neof > 0) { if (_io_fd_write (output->fd, input->s.read.buf + input->s.read.curpos, neof, err)) return TRUE; } return FALSE; }
int cow_dfield_write(cow_dfield *f, char *fname) { #if (COW_HDF5) #if (COW_MPI) if (f->domain->cart_rank == 0) { #endif // ------------------------------------------------------------------------- // The write functions assume the file is already created. Have master // create the file if it's not there already. // ------------------------------------------------------------------------- FILE *testf = fopen(fname, "r"); hid_t fid; if (testf == NULL) { fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); } else { fclose(testf); fid = H5Fopen(fname, H5F_ACC_RDWR, H5P_DEFAULT); } if (H5Lexists(fid, f->name, H5P_DEFAULT)) { H5Gunlink(fid, f->name); } hid_t memb = H5Gcreate(fid, f->name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Gclose(memb); H5Fclose(fid); #if (COW_MPI) } #endif clock_t start = clock(); _io_write(f, fname); double sec = (double)(clock() - start) / CLOCKS_PER_SEC; printf("[%s] write to %s/%s took %f minutes\n", MODULE, fname, f->name, sec/60.0); fflush(stdout); #endif return 0; }
_mqx_int _io_dun_open ( /* [IN] the file handle for the device being opened */ MQX_FILE_PTR fd_ptr, /* [IN] the name of the device */ char_ptr open_name_ptr, /* [IN] the flags to be used during operation: ** echo, translation, xon/xoff, encoded into a pointer. */ char_ptr f_ptr ) { /* Body */ IODUN_DEV_STRUCT_PTR dev_ptr = fd_ptr->DEV_PTR->DRIVER_INIT_PTR; IODUN_STRUCT_PTR ras_ptr = _mem_alloc_system_zero(sizeof(IODUN_STRUCT)); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (ras_ptr == NULL) { return(MQX_OUT_OF_MEMORY); } /* Endif */ #endif _mem_set_type(ras_ptr,MEM_TYPE_IO_DUN); fd_ptr->DEV_DATA_PTR = ras_ptr; _lwsem_create(&ras_ptr->LWSEM,1); ras_ptr->STATE = 0; ras_ptr->F_PTR = (MQX_FILE_PTR)f_ptr; ras_ptr->PARSE = dev_ptr->RECV; _io_write(ras_ptr->F_PTR, dev_ptr->SEND, dev_ptr->SEND_SIZE); return(MQX_OK); } /* Endbody */
int_32 Shell_TFTP_client(int_32 argc, char_ptr argv[] ) { _ip_address hostaddr; char hostname[MAX_HOSTNAMESIZE]=""; char_ptr file_ptr; uint_32 tftp_handle, buffer_size,byte_number; uchar_ptr buffer_ptr; TFTP_DATA_STRUCT tftp_data; MQX_FILE_PTR fd; int_32 error; boolean print_usage, shorthelp = FALSE; int_32 return_code = SHELL_EXIT_SUCCESS; char path[SHELL_MAX_FILELEN]; boolean trans = FALSE; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if ((argc >= 3) && (argc <= 5)) { RTCS_resolve_ip_address( argv[1], &hostaddr, hostname, MAX_HOSTNAMESIZE ); if (!hostaddr) { printf("Unable to resolve host.\n"); return_code = SHELL_EXIT_ERROR; } else { tftp_data.SERVER = hostaddr; tftp_data.FILENAME = argv[2]; tftp_data.FILEMODE = "netascii"; if (argc > 3) { file_ptr = argv[3]; if (argc > 4) { tftp_data.FILEMODE = argv[4]; } else { tftp_data.FILEMODE = "netascii"; } } else { file_ptr = argv[2]; } #if SHELLCFG_USES_MFS Shell_create_prefixed_filename(path, file_ptr, argv); fd = fopen(path,"a"); if (fd) { printf("\nDownloading file %s from TFTP server: %s [%ld.%ld.%ld.%ld]\n", tftp_data.FILENAME,hostname, IPBYTES(hostaddr)); tftp_handle = (*FT_TFTP->OPEN)( (pointer) &tftp_data ); if ( tftp_handle != RTCS_OK ) { printf("\nError opening file %s\n",tftp_data.FILENAME); return_code = SHELL_EXIT_ERROR; } else { if (! (*FT_TFTP->EOFT)()) { do { buffer_ptr = (*FT_TFTP->READ)( &buffer_size ); if ((buffer_ptr != NULL) && (buffer_size)) { fseek(fd, 0 , IO_SEEK_CUR); _io_write(fd,buffer_ptr,buffer_size); trans = TRUE; } else { switch (buffer_size) { case 0: // end of file break; case (RTCSERR_TFTP_ERROR + 1): printf("\nFile %s not found\n", tftp_data.FILENAME); break; case (RTCSERR_TFTP_ERROR + 2): printf("\nAccess violation\n"); break; case (RTCSERR_TFTP_ERROR + 3): printf("\nDisk full or allocation exceeded\n"); break; case (RTCSERR_TFTP_ERROR + 4): printf("\nIllegal TFTP operation\n"); break; case (RTCSERR_TFTP_ERROR + 5): printf("\nUnknown transfer ID\n"); break; case (RTCSERR_TFTP_ERROR + 6): printf("\nFile already exists\n"); break; case (RTCSERR_TFTP_ERROR + 7): printf("\nNo such user\n"); break; default: if(trans) { trans =FALSE; break; } else printf("\nError reading file %s\n", tftp_data.FILENAME); } /* Endswitch */ } } while((buffer_ptr !=NULL) && buffer_size && (! (*FT_TFTP->EOFT)()) ); fclose(fd); } error = (*FT_TFTP->CLOSE)(); } } else { printf("\nError opening local file %s\n",file_ptr); return_code = SHELL_EXIT_ERROR; } #else tftp_handle = (*FT_TFTP->OPEN)( (pointer) &tftp_data ); if ( tftp_handle != RTCS_OK ) { printf("\nError opening file %s\n",tftp_data.FILENAME); return_code = SHELL_EXIT_ERROR; } else { printf("SHELLCFG_USES_MFS is not set to 1 in user_config.h - file wont be written to disk\n"); } error = (*FT_TFTP->CLOSE)(); #endif } } else { printf("Error, %s invoked with incorrect number of arguments\n", argv[0]); print_usage = TRUE; } } if (print_usage) { if (shorthelp) { printf("%s <host> <source> [<dest>] [<mode>]\n", argv[0]); } else { printf("Usage: %s <host> <source> [<dest>] [<mode>]\n", argv[0]); printf(" <host> = host ip address or name\n"); printf(" <source> = remote file name\n"); printf(" <dest> = local file name\n"); printf(" <mode> = file transfer mode (netascii, etc.)\n"); } } return return_code; } /* Endbody */