-+void ADIOI_LUSTRE_Calc_my_off_len(ADIO_File fd, int bufcount,
-+ MPI_Datatype datatype, int file_ptr_type,
-+ ADIO_Offset offset,
-+ ADIO_Offset **offset_list_ptr,
-+ int **len_list_ptr,
-+ ADIO_Offset *start_offset_ptr,
-+ ADIO_Offset *end_offset_ptr,
-+ int *contig_access_count_ptr)
-+{
-+ int filetype_size, buftype_size, etype_size;
-+ int i, j, k, frd_size = 0, old_frd_size = 0, st_index = 0;
-+ int n_filetypes, etype_in_filetype;
-+ ADIO_Offset abs_off_in_filetype = 0;
-+ int bufsize, sum, n_etypes_in_filetype, size_in_filetype;
-+ int contig_access_count, *len_list, flag, filetype_is_contig;
-+ MPI_Aint filetype_extent, filetype_lb;
-+ ADIOI_Flatlist_node *flat_file;
-+ ADIO_Offset *offset_list, off, end_offset = 0, disp;
-+
-+ /* For this process's request, calculate the list of offsets and
-+ lengths in the file and determine the start and end offsets. */
-+
-+ ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
-+
-+ MPI_Type_size(fd->filetype, &filetype_size);
-+ MPI_Type_extent(fd->filetype, &filetype_extent);
-+ MPI_Type_lb(fd->filetype, &filetype_lb);
-+ MPI_Type_size(datatype, &buftype_size);
-+ etype_size = fd->etype_size;
-+
-+ if (!filetype_size) {
-+ *contig_access_count_ptr = 0;
-+ *offset_list_ptr = (ADIO_Offset *) ADIOI_Malloc(2*sizeof(ADIO_Offset));
-+ *len_list_ptr = (int *) ADIOI_Malloc(2 * sizeof(int));
-+ /* 2 is for consistency. everywhere I malloc one more than needed */
-+
-+ offset_list = *offset_list_ptr;
-+ len_list = *len_list_ptr;
-+ offset_list[0] = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind :
-+ fd->disp + etype_size * offset;
-+ len_list[0] = 0;
-+ *start_offset_ptr = offset_list[0];
-+ *end_offset_ptr = offset_list[0] + len_list[0] - 1;
-+ return;
-+ }
-+
-+ if (filetype_is_contig) {
-+ *contig_access_count_ptr = 1;
-+ *offset_list_ptr = (ADIO_Offset *) ADIOI_Malloc(2*sizeof(ADIO_Offset));
-+ *len_list_ptr = (int *) ADIOI_Malloc(2 * sizeof(int));
-+ /* 2 is for consistency. everywhere I malloc one more than needed */
-+
-+ offset_list = *offset_list_ptr;
-+ len_list = *len_list_ptr;
-+ offset_list[0] = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind :
-+ fd->disp + etype_size * offset;
-+ len_list[0] = bufcount * buftype_size;
-+ *start_offset_ptr = offset_list[0];
-+ *end_offset_ptr = offset_list[0] + len_list[0] - 1;
-+
-+ /* update file pointer */
-+ if (file_ptr_type == ADIO_INDIVIDUAL)
-+ fd->fp_ind = *end_offset_ptr + 1;
-+ } else {
-+ /* First calculate what size of offset_list and len_list to allocate */
-+ /* filetype already flattened in ADIO_Open or ADIO_Fcntl */
-+ flat_file = ADIOI_Flatlist;
-+ while (flat_file->type != fd->filetype)
-+ flat_file = flat_file->next;
-+ disp = fd->disp;
-+
-+ if (file_ptr_type == ADIO_INDIVIDUAL) {
-+ offset = fd->fp_ind; /* in bytes */
-+ n_filetypes = -1;
-+ flag = 0;
-+ while (!flag) {
-+ n_filetypes++;
-+ for (i = 0; i < flat_file->count; i++) {
-+ if (disp + flat_file->indices[i] +
-+ (ADIO_Offset) n_filetypes * filetype_extent +
-+ flat_file->blocklens[i] >= offset) {
-+ st_index = i;
-+ frd_size = (int) (disp + flat_file->indices[i] +
-+ (ADIO_Offset) n_filetypes *
-+ filetype_extent +
-+ flat_file->blocklens[i] -
-+ offset);
-+ flag = 1;
-+ break;
-+ }
-+ }
-+ }
-+ } else {
-+ n_etypes_in_filetype = filetype_size / etype_size;
-+ n_filetypes = (int) (offset / n_etypes_in_filetype);
-+ etype_in_filetype = (int) (offset % n_etypes_in_filetype);
-+ size_in_filetype = etype_in_filetype * etype_size;
-+
-+ sum = 0;
-+ for (i = 0; i < flat_file->count; i++) {
-+ sum += flat_file->blocklens[i];
-+ if (sum > size_in_filetype) {
-+ st_index = i;
-+ frd_size = sum - size_in_filetype;
-+ abs_off_in_filetype = flat_file->indices[i] +
-+ size_in_filetype -
-+ (sum - flat_file->blocklens[i]);
-+ break;
-+ }
-+ }
-+
-+ /* abs. offset in bytes in the file */
-+ offset = disp + (ADIO_Offset) n_filetypes *filetype_extent +
-+ abs_off_in_filetype;
-+ }
-+
-+ /* calculate how much space to allocate for offset_list, len_list */
-+
-+ old_frd_size = frd_size;
-+ contig_access_count = i = 0;
-+ j = st_index;
-+ bufsize = buftype_size * bufcount;
-+ frd_size = ADIOI_MIN(frd_size, bufsize);
-+ while (i < bufsize) {
-+ if (frd_size)
-+ contig_access_count++;
-+ i += frd_size;
-+ j = (j + 1) % flat_file->count;
-+ frd_size = ADIOI_MIN(flat_file->blocklens[j], bufsize - i);
-+ }
-+
-+ /* allocate space for offset_list and len_list */
-+
-+ *offset_list_ptr = (ADIO_Offset *) ADIOI_Malloc((contig_access_count+1) *
-+ sizeof(ADIO_Offset));
-+ *len_list_ptr = (int *) ADIOI_Malloc((contig_access_count + 1) *
-+ sizeof(int));
-+ /* +1 to avoid a 0-size malloc */
-+
-+ offset_list = *offset_list_ptr;
-+ len_list = *len_list_ptr;
-+
-+ /* find start offset, end offset, and fill in offset_list and len_list */
-+
-+ *start_offset_ptr = offset; /* calculated above */
-+
-+ i = k = 0;
-+ j = st_index;
-+ off = offset;
-+ frd_size = ADIOI_MIN(old_frd_size, bufsize);
-+ while (i < bufsize) {
-+ if (frd_size) {
-+ offset_list[k] = off;
-+ len_list[k] = frd_size;
-+ k++;
-+ }
-+ i += frd_size;
-+ end_offset = off + frd_size - 1;
-+
-+ /* Note: end_offset points to the last byte-offset that will be accessed.
-+ e.g., if start_offset=0 and 100 bytes to be read, end_offset=99 */
-+
-+ if (off + frd_size < disp + flat_file->indices[j] +
-+ flat_file->blocklens[j] +
-+ (ADIO_Offset) n_filetypes * filetype_extent) {
-+ off += frd_size;
-+ /* did not reach end of contiguous block in filetype.
-+ * no more I/O needed. off is incremented by frd_size.
-+ */
-+ } else {
-+ if (j < (flat_file->count - 1))
-+ j++;
-+ else {
-+ /* hit end of flattened filetype;
-+ * start at beginning again
-+ */
-+ j = 0;
-+ n_filetypes++;
-+ }
-+ off = disp + flat_file->indices[j] + (ADIO_Offset) n_filetypes *
-+ filetype_extent;
-+ frd_size = ADIOI_MIN(flat_file->blocklens[j], bufsize - i);
-+ }
-+ }
-+
-+ /* update file pointer */
-+ if (file_ptr_type == ADIO_INDIVIDUAL)
-+ fd->fp_ind = off;
-+
-+ *contig_access_count_ptr = contig_access_count;
-+ *end_offset_ptr = end_offset;
-+ }
-+}
-+