00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ad_hfs.h"
00010 #include "adio_extern.h"
00011
00012 ADIO_Offset ADIOI_HFS_SeekIndividual(ADIO_File fd, ADIO_Offset offset,
00013 int whence, int *error_code)
00014 {
00015
00016
00017
00018
00019
00020 ADIO_Offset off;
00021 ADIOI_Flatlist_node *flat_file;
00022 #ifndef PRINT_ERR_MSG
00023 static char myname[] = "ADIOI_HFS_SEEKINDIVIDUAL";
00024 #endif
00025
00026 int i, n_etypes_in_filetype, n_filetypes, etype_in_filetype;
00027 ADIO_Offset abs_off_in_filetype=0;
00028 int size_in_filetype, sum;
00029 int filetype_size, etype_size, filetype_is_contig;
00030 MPI_Aint filetype_extent;
00031
00032 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00033 etype_size = fd->etype_size;
00034
00035 if (filetype_is_contig) off = fd->disp + etype_size * offset;
00036 else {
00037 flat_file = ADIOI_Flatlist;
00038 while (flat_file->type != fd->filetype) flat_file = flat_file->next;
00039
00040 MPI_Type_extent(fd->filetype, &filetype_extent);
00041 MPI_Type_size(fd->filetype, &filetype_size);
00042 if ( ! filetype_size ) {
00043 *error_code = MPI_SUCCESS;
00044 return;
00045 }
00046
00047 n_etypes_in_filetype = filetype_size/etype_size;
00048 n_filetypes = (int) (offset / n_etypes_in_filetype);
00049 etype_in_filetype = (int) (offset % n_etypes_in_filetype);
00050 size_in_filetype = etype_in_filetype * etype_size;
00051
00052 sum = 0;
00053 for (i=0; i<flat_file->count; i++) {
00054 sum += flat_file->blocklens[i];
00055 if (sum > size_in_filetype) {
00056 abs_off_in_filetype = flat_file->indices[i] +
00057 size_in_filetype - (sum - flat_file->blocklens[i]);
00058 break;
00059 }
00060 }
00061
00062
00063 off = fd->disp + (ADIO_Offset) n_filetypes * filetype_extent +
00064 abs_off_in_filetype;
00065 }
00066
00067 fd->fp_ind = off;
00068
00069 #ifdef HPUX
00070 fd->fp_sys_posn = lseek64(fd->fd_sys, off, SEEK_SET);
00071 #ifdef PRINT_ERR_MSG
00072 *error_code = (fd->fp_sys_posn == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS;
00073 #else
00074 if (fd->fp_sys_posn == -1) {
00075 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00076 myname, "I/O Error", "%s", strerror(errno));
00077 ADIOI_Error(fd, *error_code, myname);
00078 }
00079 else *error_code = MPI_SUCCESS;
00080 #endif
00081 #endif
00082
00083 #ifdef SPPUX
00084 fd->fp_sys_posn = -1;
00085 *error_code = MPI_SUCCESS;
00086 #endif
00087
00088 return off;
00089 }