00001
00002
00003
00004
00005
00006
00007
00008 #include "adio.h"
00009 #include "adio_extern.h"
00010
00011
00012
00013
00014 void ADIOI_Get_eof_offset(ADIO_File fd, ADIO_Offset *eof_offset)
00015 {
00016 unsigned filetype_size;
00017 int error_code, filetype_is_contig, etype_size;
00018 ADIO_Offset fsize, disp, sum=0, size_in_file, n_filetypes, rem;
00019 int flag, i;
00020 ADIO_Fcntl_t *fcntl_struct;
00021 MPI_Aint filetype_extent;
00022 ADIOI_Flatlist_node *flat_file;
00023
00024
00025 fcntl_struct = (ADIO_Fcntl_t *) ADIOI_Malloc(sizeof(ADIO_Fcntl_t));
00026 ADIO_Fcntl(fd, ADIO_FCNTL_GET_FSIZE, fcntl_struct, &error_code);
00027 fsize = fcntl_struct->fsize;
00028 ADIOI_Free(fcntl_struct);
00029
00030
00031
00032
00033
00034
00035 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00036 etype_size = fd->etype_size;
00037
00038 if (filetype_is_contig)
00039 *eof_offset = (fsize - fd->disp + etype_size - 1)/etype_size;
00040
00041 else {
00042
00043 flat_file = CtvAccess(ADIOI_Flatlist);
00044 while (flat_file->type != fd->filetype)
00045 flat_file = flat_file->next;
00046
00047 MPI_Type_size(fd->filetype, (int*)&filetype_size);
00048 MPI_Type_extent(fd->filetype, &filetype_extent);
00049
00050 disp = fd->disp;
00051 n_filetypes = -1;
00052 flag = 0;
00053 while (!flag) {
00054 sum = 0;
00055 n_filetypes++;
00056 for (i=0; i<flat_file->count; i++) {
00057 sum += flat_file->blocklens[i];
00058 if (disp + flat_file->indices[i] +
00059 n_filetypes* ADIOI_AINT_CAST_TO_OFFSET filetype_extent +
00060 flat_file->blocklens[i] >= fsize) {
00061 if (disp + flat_file->indices[i] +
00062 n_filetypes * ADIOI_AINT_CAST_TO_OFFSET filetype_extent >= fsize)
00063 sum -= flat_file->blocklens[i];
00064 else {
00065 rem = (disp + flat_file->indices[i] +
00066 n_filetypes* ADIOI_AINT_CAST_TO_OFFSET filetype_extent
00067 + flat_file->blocklens[i] - fsize);
00068 sum -= rem;
00069 }
00070 flag = 1;
00071 break;
00072 }
00073 }
00074 }
00075 size_in_file = n_filetypes*(ADIO_Offset)filetype_size + sum;
00076 *eof_offset = (size_in_file+etype_size-1)/etype_size;
00077 }
00078 }