00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "ad_ntfs.h"
00015
00016 void ADIOI_NTFS_IwriteContig(ADIO_File fd, void *buf, int count,
00017 MPI_Datatype datatype, int file_ptr_type,
00018 ADIO_Offset offset, ADIO_Request *request, int *error_code)
00019 {
00020 int len, typesize;
00021 int err=FALSE;
00022 #ifndef PRINT_ERR_MSG
00023 static char myname[] = "ADIOI_NTFS_IWRITECONTIG";
00024 #endif
00025
00026 *request = ADIOI_Malloc_request();
00027 (*request)->optype = ADIOI_WRITE;
00028 (*request)->fd = fd;
00029 (*request)->datatype = datatype;
00030
00031 MPI_Type_size(datatype, &typesize);
00032 len = count * typesize;
00033
00034 if (file_ptr_type == ADIO_INDIVIDUAL) offset = fd->fp_ind;
00035 err = ADIOI_NTFS_aio(fd, buf, len, offset, 1, &((*request)->handle));
00036 if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind += len;
00037
00038 (*request)->queued = 1;
00039 ADIOI_Add_req_to_list(request);
00040
00041 #ifdef PRINT_ERR_MSG
00042 *error_code = (err == FALSE) ? MPI_ERR_UNKNOWN : MPI_SUCCESS;
00043 #else
00044 if (err == FALSE) {
00045 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00046 myname, "I/O Error", "%s", strerror(errno));
00047 ADIOI_Error(fd, *error_code, myname);
00048 }
00049 else *error_code = MPI_SUCCESS;
00050 #endif
00051
00052 fd->fp_sys_posn = -1;
00053 fd->async_count++;
00054 }
00055
00056
00057
00058
00059 void ADIOI_NTFS_IwriteStrided(ADIO_File fd, void *buf, int count,
00060 MPI_Datatype datatype, int file_ptr_type,
00061 ADIO_Offset offset, ADIO_Request *request, int
00062 *error_code)
00063 {
00064 ADIO_Status status;
00065 #ifdef HAVE_STATUS_SET_BYTES
00066 int typesize;
00067 #endif
00068
00069 *request = ADIOI_Malloc_request();
00070 (*request)->optype = ADIOI_WRITE;
00071 (*request)->fd = fd;
00072 (*request)->datatype = datatype;
00073 (*request)->queued = 0;
00074 (*request)->handle = 0;
00075
00076
00077 ADIOI_NTFS_WriteStrided(fd, buf, count, datatype, file_ptr_type,
00078 offset, &status, error_code);
00079
00080 fd->async_count++;
00081
00082 #ifdef HAVE_STATUS_SET_BYTES
00083 if (*error_code == MPI_SUCCESS) {
00084 MPI_Type_size(datatype, &typesize);
00085 (*request)->nbytes = count * typesize;
00086 }
00087 #endif
00088 }
00089
00090
00091
00092
00093
00094
00095 int ADIOI_NTFS_aio(ADIO_File fd, void *buf, int len, ADIO_Offset offset,
00096 int wr, void *handle)
00097 {
00098 DWORD dwNumWritten=0, dwNumRead=0;
00099 BOOL ret_val = FALSE;
00100 FDTYPE fd_sys;
00101
00102 OVERLAPPED *pOvl;
00103
00104 fd_sys = fd->fd_sys;
00105
00106 pOvl = (OVERLAPPED *) ADIOI_Calloc(sizeof(OVERLAPPED), 1);
00107 pOvl->hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
00108 pOvl->Offset = DWORDLOW(offset);
00109 pOvl->OffsetHigh = DWORDHIGH(offset);
00110
00111 if (wr)
00112 {
00113 ret_val = WriteFile(fd_sys, buf, len, &dwNumWritten, pOvl);
00114
00115
00116 }
00117 else
00118 {
00119 ret_val = ReadFile(fd_sys, buf, len, &dwNumRead, pOvl);
00120
00121 }
00122
00123 if (ret_val == FALSE)
00124 {
00125 errno = GetLastError();
00126 if (errno != ERROR_IO_PENDING)
00127 {
00128 if (wr)
00129 FPRINTF(stderr, "WriteFile error: len %d, dwNumWritten %d\n", len, dwNumWritten);
00130 else
00131 FPRINTF(stderr, "ReadFile error: len %d, dwNumRead %d\n", len, dwNumRead);
00132 FPRINTF(stderr, "Unknown errno %d in ADIOI_NTFS_aio\n", errno);
00133 MPI_Abort(MPI_COMM_WORLD, 1);
00134 }
00135 ret_val = TRUE;
00136 }
00137
00138 *((OVERLAPPED **) handle) = pOvl;
00139
00140 return ret_val;
00141 }