00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "ad_ntfs.h"
00015 #include "adio_extern.h"
00016
00017 void ADIOI_NTFS_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct, int *error_code)
00018 {
00019 DWORD dwTemp;
00020 MPI_Datatype copy_etype, copy_filetype;
00021 int combiner, i, j, k, filetype_is_contig, ntimes, err;
00022 ADIOI_Flatlist_node *flat_file;
00023 ADIO_Offset curr_fsize, alloc_size, size, len, done;
00024 ADIO_Status status;
00025 char *buf;
00026 #ifndef PRINT_ERR_MSG
00027 static char myname[] = "ADIOI_NTFS_FCNTL";
00028 #endif
00029
00030 switch(flag) {
00031 case ADIO_FCNTL_SET_VIEW:
00032
00033
00034
00035 MPI_Type_get_envelope(fd->etype, &i, &j, &k, &combiner);
00036 if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->etype));
00037
00038 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00039 if (!filetype_is_contig) ADIOI_Delete_flattened(fd->filetype);
00040
00041 MPI_Type_get_envelope(fd->filetype, &i, &j, &k, &combiner);
00042 if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->filetype));
00043
00044
00045 ADIO_SetInfo(fd, fcntl_struct->info, &err);
00046
00047
00048
00049 MPI_Type_get_envelope(fcntl_struct->etype, &i, &j, &k, &combiner);
00050 if (combiner == MPI_COMBINER_NAMED) fd->etype = fcntl_struct->etype;
00051 else {
00052 MPI_Type_contiguous(1, fcntl_struct->etype, ©_etype);
00053 MPI_Type_commit(©_etype);
00054 fd->etype = copy_etype;
00055 }
00056 MPI_Type_get_envelope(fcntl_struct->filetype, &i, &j, &k, &combiner);
00057 if (combiner == MPI_COMBINER_NAMED)
00058 fd->filetype = fcntl_struct->filetype;
00059 else {
00060 MPI_Type_contiguous(1, fcntl_struct->filetype, ©_filetype);
00061 MPI_Type_commit(©_filetype);
00062 fd->filetype = copy_filetype;
00063 ADIOI_Flatten_datatype(fd->filetype);
00064
00065
00066 }
00067
00068 MPI_Type_size(fd->etype, &(fd->etype_size));
00069 fd->disp = fcntl_struct->disp;
00070
00071
00072
00073
00074 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00075 if (filetype_is_contig) fd->fp_ind = fcntl_struct->disp;
00076 else {
00077 flat_file = ADIOI_Flatlist;
00078 while (flat_file->type != fd->filetype)
00079 flat_file = flat_file->next;
00080 for (i=0; i<flat_file->count; i++) {
00081 if (flat_file->blocklens[i]) {
00082 fd->fp_ind = fcntl_struct->disp + flat_file->indices[i];
00083 break;
00084 }
00085 }
00086 }
00087 *error_code = MPI_SUCCESS;
00088 break;
00089
00090 case ADIO_FCNTL_GET_FSIZE:
00091 fcntl_struct->fsize = SetFilePointer(fd->fd_sys, 0, 0, FILE_END);
00092 if (fd->fp_sys_posn != -1)
00093 {
00094 dwTemp = DWORDHIGH(fd->fp_sys_posn);
00095 SetFilePointer(fd->fd_sys, DWORDLOW(fd->fp_sys_posn), &dwTemp, FILE_BEGIN);
00096 }
00097 #ifdef PRINT_ERR_MSG
00098 *error_code = (fcntl_struct->fsize == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS;
00099 #else
00100 if (fcntl_struct->fsize == -1) {
00101 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00102 myname, "I/O Error", "%s", strerror(errno));
00103 ADIOI_Error(fd, *error_code, myname);
00104 }
00105 else *error_code = MPI_SUCCESS;
00106 #endif
00107 break;
00108
00109 case ADIO_FCNTL_SET_DISKSPACE:
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 curr_fsize = SetFilePointer(fd->fd_sys, 0, 0, FILE_END);
00120 alloc_size = fcntl_struct->diskspace;
00121
00122 size = ADIOI_MIN(curr_fsize, alloc_size);
00123
00124 ntimes = ((int)size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
00125 buf = (char *) ADIOI_Malloc(ADIOI_PREALLOC_BUFSZ);
00126 done = 0;
00127
00128 for (i=0; i<ntimes; i++) {
00129 len = ADIOI_MIN(size-done, ADIOI_PREALLOC_BUFSZ);
00130 ADIO_ReadContig(fd, buf, (int)len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, (ADIO_Offset)done,
00131 &status, error_code);
00132 if (*error_code != MPI_SUCCESS) {
00133 #ifdef PRINT_ERR_MSG
00134 FPRINTF(stderr, "ADIOI_NTFS_Fcntl: To preallocate disk space, ROMIO needs to read the file and write it back, but is unable to read the file. Please give the file read permission and open it with MPI_MODE_RDWR.\n");
00135 MPI_Abort(MPI_COMM_WORLD, 1);
00136 #else
00137 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_PREALLOC_PERM,
00138 myname, (char *) 0, (char *) 0);
00139 ADIOI_Error(fd, *error_code, myname);
00140 return;
00141 #endif
00142 }
00143 ADIO_WriteContig(fd, buf, (int)len, MPI_BYTE, ADIO_EXPLICIT_OFFSET,
00144 (ADIO_Offset)done, &status, error_code);
00145 if (*error_code != MPI_SUCCESS) return;
00146 done += len;
00147 }
00148
00149 if (alloc_size > curr_fsize) {
00150 memset(buf, 0, ADIOI_PREALLOC_BUFSZ);
00151 size = alloc_size - curr_fsize;
00152 ntimes = ((int)size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
00153 for (i=0; i<ntimes; i++) {
00154 len = ADIOI_MIN(alloc_size-done, ADIOI_PREALLOC_BUFSZ);
00155 ADIO_WriteContig(fd, buf, (int)len, MPI_BYTE, ADIO_EXPLICIT_OFFSET,
00156 (ADIO_Offset)done, &status, error_code);
00157 if (*error_code != MPI_SUCCESS) return;
00158 done += len;
00159 }
00160 }
00161 ADIOI_Free(buf);
00162 if (fd->fp_sys_posn != -1)
00163 {
00164 dwTemp = DWORDHIGH(fd->fp_sys_posn);
00165 SetFilePointer(fd->fd_sys, DWORDLOW(fd->fp_sys_posn), &dwTemp, FILE_BEGIN);
00166 }
00167 *error_code = MPI_SUCCESS;
00168 break;
00169
00170 case ADIO_FCNTL_SET_IOMODE:
00171
00172
00173 if (fd->iomode != fcntl_struct->iomode) {
00174 fd->iomode = fcntl_struct->iomode;
00175 MPI_Barrier(MPI_COMM_WORLD);
00176 }
00177 *error_code = MPI_SUCCESS;
00178 break;
00179
00180 case ADIO_FCNTL_SET_ATOMICITY:
00181
00182
00183 fd->atomicity = 0;
00184 *error_code = MPI_ERR_UNSUPPORTED_OPERATION;
00185 break;
00186
00187 default:
00188 FPRINTF(stderr, "Unknown flag passed to ADIOI_NTFS_Fcntl\n");
00189 MPI_Abort(MPI_COMM_WORLD, 1);
00190 }
00191 }