00001
00002
00003
00004
00005
00006
00007 #include "ad_ntfs.h"
00008
00009 void ADIOI_NTFS_ReadContig(ADIO_File fd, void *buf, int count,
00010 MPI_Datatype datatype, int file_ptr_type,
00011 ADIO_Offset offset, ADIO_Status *status,
00012 int *error_code)
00013 {
00014 LONG dwTemp;
00015 DWORD dwNumRead = 0;
00016 int err=-1, datatype_size, len;
00017 static char myname[] = "ADIOI_NTFS_ReadContig";
00018 OVERLAPPED *pOvl;
00019
00020
00021
00022 if(file_ptr_type == ADIO_INDIVIDUAL){
00023 offset = fd->fp_ind;
00024 }
00025
00026 MPI_Type_size(datatype, &datatype_size);
00027 len = datatype_size * count;
00028
00029 pOvl = (OVERLAPPED *) ADIOI_Calloc(sizeof(OVERLAPPED), 1);
00030 if (pOvl == NULL)
00031 {
00032 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00033 myname, __LINE__, MPI_ERR_IO,
00034 "**nomem", "**nomem %s", "OVERLAPPED");
00035 return;
00036 }
00037 pOvl->hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
00038 if (pOvl->hEvent == NULL)
00039 {
00040 char errMsg[ADIOI_NTFS_ERR_MSG_MAX];
00041 err = GetLastError();
00042 ADIOI_NTFS_Strerror(err, errMsg, ADIOI_NTFS_ERR_MSG_MAX);
00043 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00044 myname, __LINE__, MPI_ERR_IO,
00045 "**io", "**io %s", errMsg);
00046 ADIOI_Free(pOvl);
00047 return;
00048 }
00049 pOvl->Offset = DWORDLOW(offset);
00050 pOvl->OffsetHigh = DWORDHIGH(offset);
00051
00052 if (file_ptr_type == ADIO_EXPLICIT_OFFSET)
00053 {
00054 if (fd->fp_sys_posn != offset)
00055 {
00056 dwTemp = DWORDHIGH(offset);
00057 if (SetFilePointer(fd->fd_sys, DWORDLOW(offset), &dwTemp, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
00058 {
00059 char errMsg[ADIOI_NTFS_ERR_MSG_MAX];
00060 err = GetLastError();
00061 ADIOI_NTFS_Strerror(err, errMsg, ADIOI_NTFS_ERR_MSG_MAX);
00062 if (err != NO_ERROR)
00063 {
00064 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00065 myname, __LINE__, MPI_ERR_IO,
00066 "**io", "**io %s", errMsg);
00067 CloseHandle(pOvl->hEvent);
00068 ADIOI_Free(pOvl);
00069 return;
00070 }
00071 }
00072 }
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 err = ReadFile(fd->fd_sys, buf, len, &dwNumRead, pOvl);
00083
00084 if (err == FALSE)
00085 {
00086 char errMsg[ADIOI_NTFS_ERR_MSG_MAX];
00087 err = GetLastError();
00088 ADIOI_NTFS_Strerror(err, errMsg, ADIOI_NTFS_ERR_MSG_MAX);
00089 switch (err)
00090 {
00091 case ERROR_IO_PENDING:
00092 break;
00093 case ERROR_HANDLE_EOF:
00094
00095 SetEvent(pOvl->hEvent);
00096 break;
00097 default:
00098 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00099 myname, __LINE__, MPI_ERR_IO,
00100 "**io",
00101 "**io %s", errMsg);
00102 CloseHandle(pOvl->hEvent);
00103 ADIOI_Free(pOvl);
00104 return;
00105 }
00106 }
00107
00108 err = GetOverlappedResult(fd->fd_sys, pOvl, &dwNumRead, TRUE);
00109
00110 if (err == FALSE)
00111 {
00112 char errMsg[ADIOI_NTFS_ERR_MSG_MAX];
00113 err = GetLastError();
00114 ADIOI_NTFS_Strerror(err, errMsg, ADIOI_NTFS_ERR_MSG_MAX);
00115 if (err != ERROR_HANDLE_EOF)
00116 {
00117 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00118 MPIR_ERR_RECOVERABLE, myname,
00119 __LINE__, MPI_ERR_IO, "**io",
00120 "**io %s", errMsg);
00121 CloseHandle(pOvl->hEvent);
00122 ADIOI_Free(pOvl);
00123 return;
00124 }
00125 }
00126
00127 if (!CloseHandle(pOvl->hEvent))
00128 {
00129 char errMsg[ADIOI_NTFS_ERR_MSG_MAX];
00130 err = GetLastError();
00131 ADIOI_NTFS_Strerror(err, errMsg, ADIOI_NTFS_ERR_MSG_MAX);
00132 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00133 myname, __LINE__, MPI_ERR_IO,
00134 "**io", "**io %s", errMsg);
00135 CloseHandle(pOvl->hEvent);
00136 ADIOI_Free(pOvl);
00137 return;
00138 }
00139 ADIOI_Free(pOvl);
00140
00141 fd->fp_sys_posn = offset + (ADIO_Offset)dwNumRead;
00142
00143 }
00144 else
00145 {
00146
00147 if (fd->fp_sys_posn != fd->fp_ind)
00148 {
00149 dwTemp = DWORDHIGH(fd->fp_ind);
00150 if (SetFilePointer(fd->fd_sys, DWORDLOW(fd->fp_ind), &dwTemp, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
00151 {
00152 char errMsg[ADIOI_NTFS_ERR_MSG_MAX];
00153 err = GetLastError();
00154 ADIOI_NTFS_Strerror(err, errMsg, ADIOI_NTFS_ERR_MSG_MAX);
00155 if (err != NO_ERROR)
00156 {
00157 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00158 myname, __LINE__, MPI_ERR_IO,
00159 "**io", "**io %s", errMsg);
00160 CloseHandle(pOvl->hEvent);
00161 ADIOI_Free(pOvl);
00162 return;
00163 }
00164 }
00165 }
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 err = ReadFile(fd->fd_sys, buf, len, &dwNumRead, pOvl);
00176
00177 if (err == FALSE)
00178 {
00179 char errMsg[ADIOI_NTFS_ERR_MSG_MAX];
00180 err = GetLastError();
00181 ADIOI_NTFS_Strerror(err, errMsg, ADIOI_NTFS_ERR_MSG_MAX);
00182 switch (err)
00183 {
00184 case ERROR_IO_PENDING:
00185 break;
00186 case ERROR_HANDLE_EOF:
00187
00188 SetEvent(pOvl->hEvent);
00189 break;
00190 default:
00191 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00192 myname, __LINE__, MPI_ERR_IO,
00193 "**io",
00194 "**io %s", errMsg);
00195 CloseHandle(pOvl->hEvent);
00196 ADIOI_Free(pOvl);
00197 return;
00198 }
00199 }
00200
00201 err = GetOverlappedResult(fd->fd_sys, pOvl, &dwNumRead, TRUE);
00202
00203 if (err == FALSE)
00204 {
00205 char errMsg[ADIOI_NTFS_ERR_MSG_MAX];
00206 err = GetLastError();
00207 ADIOI_NTFS_Strerror(err, errMsg, ADIOI_NTFS_ERR_MSG_MAX);
00208 if (err != ERROR_HANDLE_EOF)
00209 {
00210 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00211 MPIR_ERR_RECOVERABLE, myname,
00212 __LINE__, MPI_ERR_IO, "**io",
00213 "**io %s", errMsg);
00214 CloseHandle(pOvl->hEvent);
00215 ADIOI_Free(pOvl);
00216 return;
00217 }
00218 }
00219
00220 if (!CloseHandle(pOvl->hEvent))
00221 {
00222 char errMsg[ADIOI_NTFS_ERR_MSG_MAX];
00223 err = GetLastError();
00224 ADIOI_NTFS_Strerror(err, errMsg, ADIOI_NTFS_ERR_MSG_MAX);
00225 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00226 myname, __LINE__, MPI_ERR_IO,
00227 "**io", "**io %s", errMsg);
00228 ADIOI_Free(pOvl);
00229 return;
00230 }
00231 ADIOI_Free(pOvl);
00232
00233 fd->fp_ind = fd->fp_ind + (ADIO_Offset)dwNumRead;
00234 fd->fp_sys_posn = fd->fp_ind;
00235 }
00236
00237 #ifdef HAVE_STATUS_SET_BYTES
00238 if (err != FALSE)
00239 {
00240 MPIR_Status_set_bytes(status, datatype, dwNumRead);
00241 }
00242 #endif
00243
00244
00245 if (err == FALSE)
00246 {
00247 char errMsg[ADIOI_NTFS_ERR_MSG_MAX];
00248 err = GetLastError();
00249 ADIOI_NTFS_Strerror(err, errMsg, ADIOI_NTFS_ERR_MSG_MAX);
00250 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00251 myname, __LINE__, MPI_ERR_IO,
00252 "**io",
00253 "**io %s", errMsg);
00254 return;
00255 }
00256
00257 *error_code = MPI_SUCCESS;
00258 }