00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ad_xfs.h"
00010 #include "adio_extern.h"
00011
00012 ADIO_Offset ADIOI_XFS_SeekIndividual(ADIO_File fd, ADIO_Offset offset,
00013 int whence, int *error_code)
00014 {
00015
00016
00017
00018
00019
00020 ADIO_Offset abs_off_in_filetype=0, off;
00021 ADIOI_Flatlist_node *flat_file;
00022
00023 int i, n_etypes_in_filetype, n_filetypes, etype_in_filetype;
00024 int size_in_filetype, sum;
00025 int filetype_size, etype_size, filetype_is_contig;
00026 MPI_Aint filetype_extent;
00027
00028 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00029 etype_size = fd->etype_size;
00030
00031 if (filetype_is_contig) off = fd->disp + etype_size * offset;
00032 else {
00033 flat_file = ADIOI_Flatlist;
00034 while (flat_file->type != fd->filetype) flat_file = flat_file->next;
00035
00036 MPI_Type_extent(fd->filetype, &filetype_extent);
00037 MPI_Type_size(fd->filetype, &filetype_size);
00038 if ( ! filetype_size ) {
00039
00040
00041
00042 *error_code = MPI_SUCCESS;
00043 return 0;
00044 }
00045
00046 n_etypes_in_filetype = filetype_size/etype_size;
00047 n_filetypes = (int) (offset / n_etypes_in_filetype);
00048 etype_in_filetype = (int) (offset % n_etypes_in_filetype);
00049 size_in_filetype = etype_in_filetype * etype_size;
00050
00051 sum = 0;
00052 for (i=0; i<flat_file->count; i++) {
00053 sum += flat_file->blocklens[i];
00054 if (sum > size_in_filetype) {
00055 abs_off_in_filetype = flat_file->indices[i] +
00056 size_in_filetype - (sum - flat_file->blocklens[i]);
00057 break;
00058 }
00059 }
00060
00061
00062 off = fd->disp + (ADIO_Offset) n_filetypes * filetype_extent +
00063 abs_off_in_filetype;
00064 }
00065
00066
00067
00068
00069 fd->fp_ind = off;
00070 fd->fp_sys_posn = -1;
00071
00072 *error_code = MPI_SUCCESS;
00073 return off;
00074 }