00001
00002
00003
00004
00005
00006
00007
00008 #include "ad_xfs.h"
00009 #include "adio_extern.h"
00010 #include <sys/ioctl.h>
00011
00012 #ifndef HAVE_LSEEK64
00013 #define lseek64 lseek
00014 #endif
00015
00016 void ADIOI_XFS_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct, int *error_code)
00017 {
00018 int i, err;
00019 #if defined(LINUX) && defined(MPISGI)
00020 struct xfs_flock64 fl;
00021 #else
00022 struct flock64 fl;
00023 #endif
00024 static char myname[] = "ADIOI_XFS_FCNTL";
00025
00026 switch(flag) {
00027 case ADIO_FCNTL_GET_FSIZE:
00028 fcntl_struct->fsize = lseek64(fd->fd_sys, 0, SEEK_END);
00029 if (fcntl_struct->fsize == -1) {
00030 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00031 MPIR_ERR_RECOVERABLE, myname,
00032 __LINE__, MPI_ERR_IO, "**io",
00033 "**io %s", strerror(errno));
00034 }
00035 else *error_code = MPI_SUCCESS;
00036 break;
00037
00038 case ADIO_FCNTL_SET_DISKSPACE:
00039 i = 0;
00040 fl.l_start = 0;
00041 fl.l_whence = SEEK_SET;
00042 fl.l_len = fcntl_struct->diskspace;
00043
00044 #if defined(LINUX) && defined(MPISGI)
00045 err = ioctl(fd->fd_sys, XFS_IOC_RESVSP64, &fl);
00046 #else
00047 err = fcntl(fd->fd_sys, F_RESVSP64, &fl);
00048 #endif
00049
00050 if (err) i = 1;
00051 if (fcntl_struct->diskspace > lseek64(fd->fd_sys, 0, SEEK_END)) {
00052
00053 err = ftruncate64(fd->fd_sys, fcntl_struct->diskspace);
00054 if (err) i = 1;
00055 }
00056
00057 if (i == 1) {
00058 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00059 MPIR_ERR_RECOVERABLE, myname,
00060 __LINE__, MPI_ERR_IO, "**io",
00061 "**io %s", strerror(errno));
00062 }
00063 else *error_code = MPI_SUCCESS;
00064 break;
00065
00066 case ADIO_FCNTL_SET_ATOMICITY:
00067 fd->atomicity = (fcntl_struct->atomicity == 0) ? 0 : 1;
00068 *error_code = MPI_SUCCESS;
00069 break;
00070
00071 default:
00072
00073 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00074 MPIR_ERR_RECOVERABLE,
00075 myname, __LINE__,
00076 MPI_ERR_ARG,
00077 "**flag", "**flag %d", flag);
00078 return;
00079
00080 }
00081 }