00001
00002
00003
00004
00005
00006
00007
00008 #include "ad_hfs.h"
00009 #include "adio_extern.h"
00010
00011 #ifndef HAVE_LSEEK64
00012 #define lseek64 lseek
00013 #endif
00014 void ADIOI_HFS_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct, int *error_code)
00015 {
00016 int i, ntimes, err;
00017 ADIO_Offset curr_fsize, alloc_size, size, len, done;
00018 ADIO_Status status;
00019 char *buf;
00020 #ifndef PRINT_ERR_MSG
00021 static char myname[] = "ADIOI_HFS_FCNTL";
00022 #endif
00023
00024 switch(flag) {
00025 case ADIO_FCNTL_GET_FSIZE:
00026 fcntl_struct->fsize = lseek64(fd->fd_sys, 0, SEEK_END);
00027 #ifdef HPUX
00028 if (fd->fp_sys_posn != -1)
00029 lseek64(fd->fd_sys, fd->fp_sys_posn, SEEK_SET);
00030
00031 #endif
00032 if (fcntl_struct->fsize == -1) {
00033 #ifdef MPICH2
00034 *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
00035 "**io %s", strerror(errno));
00036 #elif defined(PRINT_ERR_MSG)
00037 *error_code = MPI_ERR_UNKNOWN;
00038 #else
00039 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00040 myname, "I/O Error", "%s", strerror(errno));
00041 ADIOI_Error(fd, *error_code, myname);
00042 #endif
00043 }
00044 else *error_code = MPI_SUCCESS;
00045 break;
00046
00047 case ADIO_FCNTL_SET_DISKSPACE:
00048
00049
00050 #ifdef HPUX
00051 err = prealloc64(fd->fd_sys, fcntl_struct->diskspace);
00052
00053 if (err && (errno != ENOTEMPTY)) {
00054 #ifdef MPICH2
00055 *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
00056 "**io %s", strerror(errno));
00057 #elif defined(PRINT_ERR_MSG)
00058 *error_code = MPI_ERR_UNKNOWN;
00059 #else
00060 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00061 myname, "I/O Error", "%s", strerror(errno));
00062 ADIOI_Error(fd, *error_code, myname);
00063 #endif
00064 return;
00065 }
00066 if (err && (errno == ENOTEMPTY)) {
00067 #endif
00068
00069 #ifdef SPPUX
00070
00071
00072 if (fcntl_struct->diskspace <= 2147483647) {
00073 err = prealloc(fd->fd_sys, (off_t) fcntl_struct->diskspace);
00074 if (err && (errno != ENOTEMPTY)) {
00075 #ifdef MPICH2
00076 *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
00077 "**io %s", strerror(errno));
00078 #elif defined(PRINT_ERR_MSG)
00079 *error_code = MPI_ERR_UNKNOWN;
00080 #else
00081 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00082 myname, "I/O Error", "%s", strerror(errno));
00083 ADIOI_Error(fd, *error_code, myname);
00084 #endif
00085 return;
00086 }
00087 }
00088
00089 if ((fcntl_struct->diskspace > 2147483647) ||
00090 (err && (errno == ENOTEMPTY))) {
00091 #endif
00092 ADIOI_GEN_Prealloc(fd,fcntl_struct->diskspace, error_code);
00093 }
00094 ADIOI_Free(buf);
00095 #ifdef HPUX
00096 if (fd->fp_sys_posn != -1)
00097 lseek64(fd->fd_sys, fd->fp_sys_posn, SEEK_SET);
00098
00099 #endif
00100 }
00101 *error_code = MPI_SUCCESS;
00102 break;
00103
00104 case ADIO_FCNTL_SET_ATOMICITY:
00105 fd->atomicity = (fcntl_struct->atomicity == 0) ? 0 : 1;
00106 *error_code = MPI_SUCCESS;
00107 break;
00108
00109 default:
00110 FPRINTF(stderr, "Unknown flag passed to ADIOI_HFS_Fcntl\n");
00111 MPI_Abort(MPI_COMM_WORLD, 1);
00112 }
00113 }