Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

rawapin.c

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 /********************************************************************
00017  * Copyright:
00018  *   GSI, Gesellschaft fuer Schwerionenforschung mbH
00019  *   Planckstr. 1
00020  *   D-64291 Darmstadt
00021  *   Germany
00022  * created  4.12.2000 by Horst Goeringer
00023  ********************************************************************
00024  * rawapin.c
00025  *   procedures for tsmcli client API (RFIO syntax)
00026  *   new version
00027  ********************************************************************
00028  *  5. 8.2002, H.G.: new argument list in rawGetLLName
00029  *  6. 8.2002, H.G.: connect to master server and data mover
00030  *                   enhanced error handling
00031  *  8. 8.2002, H.G.: shutdown of server processes after CTL C
00032  *  9. 9.2002, H.G.: rfiosetopt added
00033  * 17. 9.2002, H.G.: server node name added
00034  * 23. 9.2002, H.G.: RFIO write functions added (for RFIO disk server)
00035  * 14.10.2002, H.G.: ported to Lynx
00036  * 18. 3.2003, H.G.: rawdef.h -> rawdefn.h
00037  * 18. 7.2003, H.G.: remove CTL_C-handling
00038  * 28. 8.2003, H.G.: add rfio_closedir, rfio_mkdir, rfio_opendir,
00039  *                   rfio_readdir, rfio_stat
00040  * 25. 9.2003, H.G.: take synchronization into account
00041  * 29. 4.2004, H.G.: catch action without open in advance
00042  ********************************************************************
00043  */
00044 
00045 #ifdef WIN32
00046 #include <winsock.h>
00047 #else
00048 #include <sys/socket.h>
00049 #endif
00050 
00051 #include <stdio.h>
00052 #include <ctype.h>
00053 #include <string.h>
00054 #include <fcntl.h>
00055 #include <stdlib.h>
00056 
00057 #ifdef Linux
00058 #include <sys/stat.h>
00059 #endif
00060 
00061 #include "rawdefn.h"
00062 #include "rawapin.h"    /* has includes for rawcommn.c and rawclin.h */
00063 #include "rawentn.h"
00064 
00065 #include "rawapitd.h"
00066 #include "rawapitd-gsi.h"
00067 #include "rawapplcli.h"
00068 
00069 int* piEntryList;              /* external in some utility functions */
00070 int imySigS;         /* if = 1: CTL C specified (extern in rconnect) */
00071 FILE *fLogFile;                /* external in some utility functions */
00072 
00073 /* externals for ROOT: TRFIOFile.cxx */
00074 int serrno;                               /* id system error message */
00075 int rfio_errno;                             /* id RFIO error message */
00076 
00077 static char rfio_errmsg[256] = "";    /* RFIO related msg for stderr */
00078 
00079 static int iint = sizeof(int);
00080 static int irawComm = sizeof(srawComm);
00081 static int irawFileSystem = sizeof(srawFileSystem);
00082 static int irawAPIFile = sizeof(srawAPIFile);
00083                                            /* API file control block */
00084 
00085 static int iFileCount = 0;            /* currently open remote files */
00086 static int iFileMax = 10;       /* API file control blocks available */
00087 static RFILE *pAPIFile[10] =      /* ptrs to API file control blocks */
00088    {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
00089 
00090 /********************************************************************
00091  * rfio_open: open remote file in mass store managed by tsmcli
00092  *
00093  * created  4.12.2000, Horst Goeringer
00094  ********************************************************************
00095  */
00096 
00097 int rfio_open(char *pcFile,                           /* file name */
00098               int iFlags,
00099               int iMode)
00100 {
00101    char cModule[32] = "rfio_open";
00102    int iDebug = 0;
00103    int iRC;
00104    int iMaxConnect = 0;            /* try connection to servers once */
00105 
00106    int iMassSto = 1;   /* =1: contact GSI mass storage (default)
00107                           =0: contact RFIO read/write server         */
00108    int iStage = 0;                        /* = 1: file in stage pool */
00109    int iCache = 0;                       /* = 1: file in write cache */
00110    int iStatus = 0;
00111    int iStatusLen = 0;
00112    int iIdent;
00113    int iBufl;
00114    int iDataMoverSelect = 0;
00115 
00116    int iAction = 0;                           /* =1: read, =2: write */
00117    int iError = 0;
00118    int iSendEOS = 0;
00119      /* =1: send EOS to connected servers (master and/or data mover) */
00120 
00121    int iFileId;             /* file identifier for server connection */
00122    char cServer[24] = "";
00123    char cNodeMaster[MAX_NODE] = "adsmexp";
00124    int iSockMaster = -1;          /* socket for connection to master */
00125    int iSockMaster1 = -1;      /* for connection to alternate master */
00126    char cNodeMover[MAX_NODE] = "";
00127    int iSockMover = -1;            /* socket for connection to mover */
00128 
00129    int iSeekMode = -1;                           /* default: no seek */
00130    int iOffset = 0;                              /* default: no seek */
00131    int iBufsizeAct = 0;
00132    int iBufnoServ = 0;   /* no. of buffers transfered from/to server */
00133    int iDataServ = 0;      /* no. of bytes transfered from/to server */
00134 
00135    int ii;
00136    char *pcc, *pcc1;
00137    char cTemp[256] = "";
00138    char cMsg[128] = "                                                                                                                              ";
00139 
00140    char cNamefs[MAX_OBJ_FS] = "", *pcNamefs;      /* filespace name */
00141    char cNamehl[MAX_OBJ_HL] = "", *pcNamehl;     /* high level name */
00142    char cNamell[MAX_OBJ_LL] = "", *pcNamell;     /* low  level name */
00143 
00144    char cOwner[DSM_MAX_OWNER_LENGTH] = "";
00145    char cliNode[MAX_NODE] = "";
00146 
00147    srawDataMover sDataMoverSelect;
00148                       /* buffer with data mover attrs sent by server */
00149    srawDataMoverAttr *pDataMoverSelect;       /* selected data mover */
00150 
00151    srawStatus sStatus;
00152    srawAPIFile *pcurAPIFile;
00153    srawComm *pCommAPI;  /* communication buffer in API control block */
00154    srawComm *pCommServ;            /* copy for servers in net format */
00155    srawObjAttr *pQueryAPI;                      /* query information */
00156 
00157    srawFileSystem sFileSystemServ;
00158        /* if file in ArchivePool: FS infos for servers in net format */
00159 
00160    char *pBufQuery;
00161    srawQueryResult sQuery;
00162    srawObjAttr *pQAttr;
00163 
00164    fLogFile = stdout;
00165 
00166    pcNamefs = cNamefs;
00167    pcNamehl = cNamehl;
00168    pcNamell = cNamell;
00169 
00170    if (iFlags == O_RDONLY)
00171       iAction = 1;
00172    else
00173       iAction = 2;
00174 
00175    if (iDebug)
00176    {
00177       printf("\n-D- begin %s", cModule);
00178       if (iAction == 1) printf(
00179          " for read\n    %d remote files currently open\n",
00180          iFileCount);
00181       else printf(
00182          " for write\n    %d remote files currently open\n",
00183          iFileCount);
00184    }
00185 
00186    ii = 0;
00187    if (iFileCount > 0) while (ii < iFileMax)
00188    {
00189       if (pAPIFile[ii] == NULL)
00190          break;
00191       ii++;
00192    }
00193 
00194    if (ii == iFileMax)
00195    {
00196       printf("-E- max %d remote files may be open simultaneously\n",
00197              iFileMax);
00198       return -1;
00199    }
00200 
00201    pAPIFile[ii] = (srawAPIFile *) malloc(irawAPIFile);
00202    if (pAPIFile[ii] == NULL)
00203    {
00204       printf("-E- allocating file control block no. %d (%d byte)\n",
00205              ii, irawAPIFile);
00206       perror("    ");
00207       return -1;
00208    }
00209 
00210    iFileId = ii;
00211    iFileCount++;
00212    if (iDebug) printf(
00213       "    file control block no. %d allocated (%d byte)\n",
00214       ii, irawAPIFile);
00215 
00216    pcurAPIFile = pAPIFile[ii];
00217    pcurAPIFile->iFileId = iFileId;
00218    pcurAPIFile->iFlags = iFlags;
00219    pcurAPIFile->iMode = iMode;
00220    pcurAPIFile->iSockMaster = -1;
00221    pcurAPIFile->iSockMover = -1;
00222    pcurAPIFile->iSeekMode = iSeekMode;
00223    pcurAPIFile->iOffset = iOffset;
00224    pcurAPIFile->iBufsizeAct = iBufsizeAct;
00225    pcurAPIFile->iBufnoServ = iBufnoServ;
00226    pcurAPIFile->iDataServ = iDataServ;
00227 
00228    pCommAPI = &(pcurAPIFile->sCommAPI);
00229    pCommAPI->iIdent = IDENT_COMM;
00230    pCommAPI->iCommLen = irawComm - HEAD_LEN;
00231 
00232    pQueryAPI = &(pcurAPIFile->sQueryAPI);
00233    pCommServ = &(pcurAPIFile->sCommServ);
00234 
00235    /**************** analyze remote file specification **************/
00236 
00237    if ( (strchr(pcFile, *pcStar) != NULL) ||
00238         (strchr(pcFile, *pcQM) != NULL) ||
00239         (strchr(pcFile, *pcPerc) != NULL) )
00240    {
00241       printf("-E- generic TSM representation '%s' not allowed\n",
00242              pcFile);
00243       return -1;
00244    }
00245 
00246    /* handle prefixes to object name */
00247    pcc = (char *) strchr(pcFile, *pcDevDelim);
00248    if (pcc != NULL)
00249    {
00250       pcc++;                                /* skip device delimiter */
00251       /* check for "rfio:" */
00252       strncpy(cTemp, pcFile, 8);
00253       pcc1 = cTemp;
00254       while (*pcc1 != '\0')
00255       { *pcc1++ = tolower(*pcc1); }
00256 
00257       iRC = strncmp(cTemp, "rfio", 4);
00258       if (iRC == 0)
00259           /* rfiocopy:node:object or rfio:node:object or rfio:object */
00260       {
00261          iRC = strcmp(cTemp, "rfiocopy");
00262          if (iRC == 0)
00263          {
00264             iMassSto = 0;
00265             strcpy(cServer, "RFIO server");
00266             iPortMaster = PORT_RFIO_SERV;
00267             iPortMover = PORT_RFIO_SERV;
00268          }
00269 
00270          pcc1 = (char *) strchr(pcc, *pcDevDelim);
00271          if (pcc1 != NULL)                       /* pcc: node:object */
00272          {
00273             strcpy(cTemp, pcc);             /* starts with node name */
00274             pcc1++;                         /* skip device delimiter */
00275             if (iMassSto == 0)
00276                strcpy(pcNamehl, pcc1);     /* fs name has no meaning */
00277             else
00278                strcpy(pcNamefs, pcc1);
00279          }
00280          else                                         /* pcc: object */
00281          {
00282             if (iMassSto == 0)
00283             {
00284                printf("-E- node name RFIO server missing\n");
00285                return -1;
00286             }
00287             strcpy(cTemp, "");
00288             strcpy(pcNamefs, pcc);
00289          }
00290       }
00291       else                                       /* type node:object */
00292       {
00293          if (iDebug)
00294          {
00295             iPortMaster -= 10;                        /* test system */
00296             iPortMover -= 10;
00297          }
00298          strcpy(cTemp, pcFile);             /* starts with node name */
00299          strcpy(pcNamefs, pcc);
00300       }
00301 
00302       pcc = (char *) strchr(cTemp, *pcDevDelim);
00303       if (pcc != NULL)
00304       {
00305          strncpy(pcc, "\0", 1);              /* terminates node name */
00306          if (strlen(cTemp) <= 1)
00307          {
00308             if (iMassSto == 0)
00309             {
00310                printf("-E- node name RFIO server missing\n");
00311                return -1;
00312             }
00313          }
00314          else
00315             strcpy(cNodeMaster, cTemp);
00316       }
00317    }
00318    else /* no prefix (node name and/or rfio */
00319       strcpy(pcNamefs, pcFile);
00320 
00321    if (iMassSto == 0)
00322       strcpy(cTemp, pcNamehl);
00323    else
00324    {
00325       strcpy(cTemp, pcNamefs);
00326       strcpy(cServer, "mass storage");
00327    }
00328 
00329    pcc = cTemp;
00330    while (*pcc == *pcDevDelim)
00331    {
00332       pcc++;
00333    }
00334    strcpy(cTemp, pcc);
00335 
00336    if (iDebug) printf("    %s node '%s', TSM object '%s'\n",
00337       cServer, cNodeMaster, cTemp);
00338 
00339    /* now handle object name */
00340    pcc = (char *) strchr(cTemp, *pcObjDelim);
00341    if (iMassSto == 1)
00342    {
00343       if (pcc == NULL)
00344       {
00345          printf("-E- invalid remote file name '%s'\n", pcFile);
00346          return -1;
00347       }
00348 
00349       if (strncmp(pcc, cTemp, 1) == 0) /* skip leading obj delimiter */
00350          pcc++;
00351       pcc = (char *) strchr(pcc, *pcObjDelim);
00352       if (pcc == NULL)
00353       {
00354          printf("-E- invalid remote file name '%s'\n", pcFile);
00355          return -1;
00356       }
00357 
00358       strcpy(pcNamehl, pcc);   /* starts with high level object name */
00359       strncpy(pcc, "\0", 1);                   /* terminates FS name */
00360       strcpy(pcNamefs, cTemp);
00361 
00362       if (strlen(cNamefs) <= 1)
00363       {
00364          printf("-E- invalid archive '%s' in remote file name '%s'\n",
00365                 pcNamefs,  pcFile);
00366          return -1;
00367       }
00368 
00369       strcpy(pCommAPI->cNamefs, rawGetFSName(pcNamefs));
00370       pcc = pcNamehl;
00371       pcc++;                              /* skip leading delimiter */
00372       pcc = (char *) strrchr(pcc, *pcObjDelim);
00373       if (pcc == NULL)
00374       {
00375          printf("-E- invalid remote file name '%s'\n", pcFile);
00376          return -1;
00377       }
00378       strcpy(pcNamell, pcc);   /* starts with low level object name */
00379       strncpy(pcc, "\0", 1);   /* terminates high level object name */
00380 
00381       strcpy(pCommAPI->cNamehl, rawGetHLName(pcNamehl));
00382       iRC = rawGetLLName(pcNamell, pcObjDelim, pCommAPI->cNamell);
00383       if (iRC)
00384       {
00385          printf("-E- checking low level object name: %s\n",
00386                 pCommAPI->cNamell);
00387          return -1;
00388       }
00389    } /* (iMassSto == 1) */
00390    else
00391    {
00392       strcpy(pcNamefs, "");                /* fs name has no meaning */
00393       strcpy(pCommAPI->cNamefs, "");
00394 
00395       if (pcc == NULL)                 /* rel file name without path */
00396       {
00397          strcpy(pcNamehl, "");             /* fs name has no meaning */
00398          strcpy(pCommAPI->cNamehl, "");
00399          strcpy(pcNamell, cTemp);
00400       }
00401       else                               /* full file name with path */
00402       {
00403          strcpy(pcNamehl, cTemp);
00404          pcc = (char *) strrchr(pcNamehl, *pcObjDelim);
00405          strcpy(pcNamell, pcc);                /* low level obj name */
00406          strncpy(pcc, "\0", 1);     /* terminate high level obj name */
00407          strcpy(pCommAPI->cNamehl, pcNamehl);
00408       }
00409       strcpy(pCommAPI->cNamell, pcNamell);
00410 
00411    } /* (iMassSto == 0) */
00412 
00413    strcpy(pCommAPI->cTapeLib, "0");          /* default tape library */
00414 
00415    if ( iAction == 1)
00416       pCommAPI->iAction = QUERY_RETRIEVE_API;      /* at first query */
00417    else
00418    {
00419       if (iMassSto)
00420          pCommAPI->iAction = QUERY_ARCHIVE_RECORD; /* at first query */
00421       else
00422          pCommAPI->iAction = ARCHIVE;       /* RFIO server: no query */
00423    }
00424 
00425    if (iDebug) printf(
00426       "    FS name '%s', HL name '%s', LL name '%s', action %d\n",
00427       pCommAPI->cNamefs, pCommAPI->cNamehl, pCommAPI->cNamell,
00428       pCommAPI->iAction);
00429 
00430    /******************** get client information *********************/
00431 
00432    strcpy(cOwner, rawGetUserid());
00433    iRC = gethostname(cliNode, MAX_NODE);
00434    if (iRC)
00435    {
00436       printf("-E- getting client host name: %s\n", strerror(iRC));
00437       return -1;
00438    }
00439 
00440    if (iDebug)
00441       printf("    user %s on node %s, platform %s\n",
00442              cOwner, cliNode, cOS);            /* cOS from rawcli.h */
00443 
00444    strcpy(pCommAPI->cApplType, cApplType);
00445    strcpy(pCommAPI->cOwner,  cOwner);
00446    strcpy(pCommAPI->cliNode, cliNode);
00447    strcpy(pCommAPI->cOS, cOS);
00448    pCommAPI->iSynchId = 0;
00449 
00450    pCommServ->iIdent = htonl(pCommAPI->iIdent);
00451    pCommServ->iAction = htonl(pCommAPI->iAction);
00452    pCommServ->iCommLen = htonl(pCommAPI->iCommLen);
00453    pCommServ->iBufsizeFile = htonl(0);
00454    pCommServ->iSynchId = htonl(0);
00455    strcpy(pCommServ->cNamefs, pCommAPI->cNamefs);
00456    strcpy(pCommServ->cNamehl, pCommAPI->cNamehl);
00457    strcpy(pCommServ->cNamell, pCommAPI->cNamell);
00458    strcpy(pCommServ->cOwner,  pCommAPI->cOwner);
00459    strcpy(pCommServ->cOS, pCommAPI->cOS);
00460    strcpy(pCommServ->cApplType, pCommAPI->cApplType);
00461    strcpy(pCommServ->cliNode, pCommAPI->cliNode);
00462    strcpy(pCommServ->cTapeLib, pCommAPI->cTapeLib);
00463 
00464    /***************** connect to alternate master ********************/
00465 
00466    if ( (iMassSto == 1) && (iAction == 2) )
00467    {
00468       strcpy(cServer, "alternate server");
00469 
00470       if (iDebug) printf(
00471          "-D- trying to connect to %s %s:%d\n",
00472          cServer, cNodeMaster1, iPortMaster);
00473 
00474       iRC = rconnect(cNodeMaster1, iPortMaster,
00475                      &iMaxConnect, &iSockMaster1);
00476       if (iRC)
00477       {
00478          printf("-E- cannot connect to %s %s:%d\n",
00479                 cServer, cNodeMaster1, iPortMaster);
00480          printf(
00481             "-W- check if file %s in alternate ATL already exists not possible\n",
00482             pcFile);
00483 
00484          goto gRequServer;
00485       }
00486 
00487       if (iDebug)
00488       {
00489          printf("    successfully connected to %s %s:%d",
00490                 cServer, cNodeMaster1, iPortMaster);
00491          if (iMaxConnect) printf(" after %ds", iMaxConnect);
00492          printf(" (socket %d)\n", iSockMaster1);
00493       }
00494 
00495       /********************* perform query **************************/
00496 
00497       if (iDebug) printf(
00498          "    query file %s in alternate mass storage\n", pcFile);
00499 
00500       pBufQuery = (char *) &sQuery;
00501       pQAttr = &(sQuery.objAttr);
00502       iRC = rawQueryFile(iSockMaster1, pCommServ, (void *) &pBufQuery);
00503       if (iRC < 0)
00504       {
00505          printf(
00506             "-W- file %s: query in alternate mass storage failed, rc = %d\n",
00507             pcFile, iRC);
00508          goto gRequServer;
00509       }
00510 
00511       if (iRC == 0)
00512       {
00513          if (iDebug) printf(
00514             "    file %s not yet available in alternate mass storage\n",
00515             pcFile);
00516       }
00517       else
00518       {
00519          sprintf(rfio_errmsg,
00520             "-E- file %s already available in alternate mass storage\n",
00521             pcFile);
00522          fprintf(stdout, "%s", rfio_errmsg);
00523 
00524          iSendEOS = 1;
00525          iError = 1;
00526          goto gClose;
00527       }
00528    } /* (iMassSto == 1) && (iAction == 2) */
00529 
00530    /********************** connect to server *************************/
00531 
00532 gRequServer:
00533    if (iMassSto)
00534    {
00535       if (iSockMaster1 >= 0)
00536       {
00537          iStatus = STA_END_OF_SESSION;
00538          iRC = rawSendStatus(iSockMaster1, iStatus, NULL);
00539          if (iRC <= 0) printf(
00540             "-E- sending status buffer (EOS) to alternate server %s\n",
00541             cNodeMaster1);
00542          else if (iDebug) printf(
00543            "    status buffer (EOS) sent to master server %s (%d bytes)\n",
00544            cNodeMaster1, iRC);
00545 
00546          if (iDebug)
00547             printf("    close connection to master %s:%d, socket %d\n",
00548                    cNodeMaster1, iPortMaster, iSockMaster1);
00549          iRC = shutdown(iSockMaster1, 2);
00550          if (iDebug)
00551             printf("    rc shutdown = %d\n", iRC);
00552          iRC = close(iSockMaster1);
00553          if (iDebug)
00554             printf("    rc close = %d\n", iRC);
00555 
00556          iSockMaster1 = -1;
00557 
00558       } /* (iSockMaster1 >= 0) */
00559 
00560       strcpy(cServer, "master");
00561    }
00562 
00563    if (iDebug) printf(
00564       "-D- trying to connect to %s %s:%d\n",
00565       cServer, cNodeMaster, iPortMaster);
00566 
00567    iRC = rconnect(cNodeMaster, iPortMaster, &iMaxConnect, &iSockMaster);
00568    if (iRC)
00569    {
00570       printf("-E- cannot connect to %s %s:%d\n",
00571              cServer, cNodeMaster, iPortMaster);
00572       iSendEOS = 0;
00573       iError = 1;
00574       goto gClose;
00575    }
00576 
00577    strcpy(pcurAPIFile->cNodeMaster, cNodeMaster);
00578    pcurAPIFile->iSockMaster = iSockMaster;
00579 
00580    if (iDebug)
00581    {
00582       printf("    successfully connected to %s %s:%d",
00583              cServer, cNodeMaster, iPortMaster);
00584       if (iMaxConnect) printf(" after %ds", iMaxConnect);
00585       printf(" (socket %d)\n", iSockMaster);
00586    }
00587 
00588    if (iMassSto == 0)
00589    {
00590       if (iAction == 1)
00591       {
00592          sprintf(rfio_errmsg,
00593             "-E- RFIO read not supported for RFIO write server\n");
00594          fprintf(stdout, "%s", rfio_errmsg);
00595 
00596          iSendEOS = 1;
00597          iError = 1;
00598          goto gClose;
00599       }
00600 
00601       /* write: master and mover identical */
00602       strcpy(cNodeMover, cNodeMaster);
00603       strcpy(pcurAPIFile->cNodeMover, cNodeMaster);
00604       iSockMover = iSockMaster;
00605       pcurAPIFile->iSockMover = iSockMaster;
00606 
00607       iSockMaster = -1;
00608       pcurAPIFile->iSockMaster = -1;
00609 
00610    } /* (iMassSto == 0) */
00611    else
00612    {
00613       /********************* perform query **************************/
00614 
00615       if (iDebug)
00616          printf( "    query file %s in mass storage\n", pcFile);
00617 
00618       pBufQuery = (char *) &sQuery;
00619       pQAttr = &(sQuery.objAttr);
00620       iRC = rawQueryFile(iSockMaster, pCommServ, (void *) &pBufQuery);
00621       if (iRC < 0)
00622       {
00623          sprintf(rfio_errmsg,
00624                 "-E- file %s: query failed, rc = %d\n", pcFile, iRC);
00625          fprintf(stdout, "%s", rfio_errmsg);
00626 
00627          iSendEOS = 1;
00628          iError = 1;
00629          goto gClose;
00630       }
00631 
00632       if (iRC == 0)
00633       {
00634          if (iAction == 1)                                   /* read */
00635          {
00636             sprintf(rfio_errmsg,
00637                "-E- file %s not available in mass storage\n", pcFile);
00638             fprintf(stdout, "%s", rfio_errmsg);
00639 
00640             iSendEOS = 1;
00641             iError = 1;
00642             goto gClose;
00643          }
00644 
00645          if (iDebug) printf(
00646             "    file %s not yet available in mass store\n", pcFile);
00647       }
00648       else
00649       {
00650          if (iAction == 2)                                  /* write */
00651          {
00652             sprintf(rfio_errmsg,
00653                "-E- file %s already available in mass storage\n",
00654                pcFile);
00655             fprintf(stdout, "%s", rfio_errmsg);
00656 
00657             iSendEOS = 1;
00658             iError = 1;
00659             goto gClose;
00660          }
00661 
00662          memcpy(pQueryAPI, pQAttr, sizeof(srawObjAttr));
00663          if (iDebug)
00664          {
00665             printf("    file %s available in mass store:\n", pcFile);
00666 
00667             if (iRC > 1)
00668                printf("-W- %d versions of file %s exist\n",
00669                       iRC, pcFile);
00670             rawQueryString(pQueryAPI, 0, cMsg);
00671             printf("    %s", cMsg);
00672          }
00673 
00674          if ( (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_STAGE) ||
00675               (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_INCOMPLETE) ||
00676               (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_LOCKED) )
00677          {
00678             strcpy(cNodeMover, pQAttr->cNode);
00679             iStage = ntohl(pQAttr->iFS);
00680             if (iDebug)
00681             {
00682                printf("    file %s staged in FS %d of DM %s",
00683                    pcFile, iStage, cNodeMover);
00684                if (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_INCOMPLETE)
00685                   printf(", still incomplete)\n");
00686                else if (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_LOCKED)
00687                   printf(", already locked)\n");
00688                else printf("\n");
00689             }
00690          }
00691          else if (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_CACHE)
00692          {
00693             iCache = 1;
00694 
00695             /* specify location of cache data */
00696             strcpy(sFileSystemServ.cOS, "Windows");  /* DDD */
00697             strcpy(sFileSystemServ.cNode, pQAttr->cNode);
00698             sFileSystemServ.iFileSystem = pQAttr->iFS; /* net format */
00699             strcpy(sFileSystemServ.cArchiveDate, pQAttr->cDate);
00700                                                      /* archive date */
00701             strcpy(sFileSystemServ.cArchiveUser, pQAttr->cOwner);
00702                                                 /* user who archived */
00703 
00704             strcpy(cNodeMover, pQAttr->cNode);
00705             iStage = ntohl(pQAttr->iFS);
00706             if (iDebug) printf(
00707                "    file %s cached in FS %d of DM %s\n",
00708                pcFile, iStage, cNodeMover);
00709          }
00710          else
00711          {
00712             iStage = 0;
00713             if (iDebug)
00714                printf("    file %s not yet staged\n", pcFile);
00715          }
00716       } /* iRC(rawQueryFile) > 0 */
00717 
00718       /********* get name of data mover selected by master ***********/
00719 
00720       if ( ( (iAction == 1) &&
00721              ((iStage == 0) || (iCache == 1)) ) ||
00722            (iAction == 2) )
00723       {
00724          if (iDebug) printf(
00725             "-D- receiving attributes of data mover selected by master\n");
00726 
00727          pcc = (char *) &sDataMoverSelect;
00728          iIdent = IDENT_MOVER_ATTR;                      /* expected */
00729          iStatus = STA_SWITCH_SERVER;                    /* expected */
00730          iRC = rawRecvHeadC(iSockMaster, pcc,
00731                             iIdent, iStatus, cMsg);
00732          if (iRC != HEAD_LEN)
00733          {
00734             if (iRC < 0)
00735                printf("-E- %s: receiving data mover attr header\n%s",
00736                       cModule, cMsg);
00737             else
00738             {
00739                printf("-E- %s: received error status from master server",
00740                       cModule);
00741                if (iRC)
00742                   printf("\n%s" , cMsg);
00743                else
00744                   printf("\n");
00745             }
00746 
00747             iSendEOS = 1;
00748             iError = 1;
00749             goto gClose;
00750          }
00751          if (iDebug) printf(
00752             "    header of data mover attr received (%d bytes)\n", iRC);
00753 
00754          iStatusLen = ntohl(sDataMoverSelect.iStatusLen);
00755 
00756          /* get data part of data mover info */
00757          pcc = (char *) &(sDataMoverSelect.sDataMoverAttr);
00758          iBufl = sizeof(srawDataMover) - HEAD_LEN;
00759          ii = iBufl;
00760          while(iBufl > 0)
00761          {
00762             if ( (iRC = recv( iSockMaster, pcc, iBufl, 0 )) < 0 )
00763             {
00764                printf("-E- %s: receiving data part of data mover info\n",
00765                       cModule);
00766                perror("-E- receiving data part of data mover info");
00767 
00768                iSendEOS = 1;                       /* may also fail! */
00769                iError = 1;
00770                goto gClose;
00771             }
00772             iBufl -= iRC;
00773             pcc += iRC;
00774          }
00775 
00776          pDataMoverSelect = &(sDataMoverSelect.sDataMoverAttr);
00777          iDataMoverSelect = ii / sizeof(srawDataMoverAttr);
00778                              /* no. of data movers sent: should be 1 */
00779          strcpy(cNodeMover, pDataMoverSelect->cNode);
00780 
00781          if (iDebug)
00782          {
00783             printf(
00784                "    data part of data mover info received (%d byte)\n",
00785                ii);
00786             printf("    %d data mover selected: %s",
00787                    iDataMoverSelect, cNodeMover);
00788             if (ntohl(pDataMoverSelect->iSynchId)) printf(
00789                ", synchId %d, status %d, wait for %d seconds\n",
00790                ntohl(pDataMoverSelect->iSynchId),
00791                ntohl(pDataMoverSelect->iExecStatus),
00792                ntohl(pDataMoverSelect->iWaitTime));
00793             else
00794                printf("\n");
00795 
00796          }
00797          else printf(
00798             "-I- staging file to data mover %s ...\n", cNodeMover);
00799 
00800          if (iDataMoverSelect != 1)
00801          {
00802             printf(
00803                "-W- expected 1 selected data mover, ignore remaining %d\n",
00804                --iDataMoverSelect);
00805              iDataMoverSelect = 1;
00806          }
00807       } /* ( ( (iAction == 1) && ((iStage == 0) || (iCache == 1)) ) ||
00808              (iAction == 2) */
00809 
00810       /* update communication buffer with query infos */
00811       if (iAction == 1)
00812       {
00813          pCommServ->iFileType = pQAttr->iFileType;
00814          pCommServ->iBufsizeFile = pQAttr->iBufsizeFile;
00815          pCommServ->iFileSize = pQAttr->iFileSize;
00816          pCommServ->iObjHigh = pQAttr->iObjHigh;
00817          pCommServ->iObjLow = pQAttr->iObjLow;
00818          pCommServ->iStageFSid = htonl(iStage);
00819       }
00820       else
00821       {
00822          pCommServ->iFileType = htonl(STREAM);
00823          pCommServ->iBufsizeFile = htonl(0);
00824          pCommServ->iFileSize = htonl(0);
00825          pCommServ->iObjHigh = htonl(0);
00826          pCommServ->iObjLow = htonl(0);
00827          pCommServ->iStageFSid = htonl(0);
00828       }
00829 
00830       /* provide query infos to other API procedures */
00831       pCommAPI->iFileType = ntohl(pCommServ->iFileType);
00832       pCommAPI->iBufsizeFile = ntohl(pCommServ->iBufsizeFile);
00833       pCommAPI->iFileSize = ntohl(pCommServ->iFileSize);
00834       pCommAPI->iObjHigh = ntohl(pCommServ->iObjHigh);
00835       pCommAPI->iObjLow = ntohl(pCommServ->iObjLow);
00836       pCommAPI->iStageFSid = ntohl(pCommServ->iStageFSid);
00837 
00838       if (iStage)
00839       {
00840          pCommServ->iExecStatus = htonl(0);
00841          pCommServ->iSynchId = htonl(0);
00842 
00843          pCommAPI->iExecStatus = 0;
00844          pCommAPI->iSynchId = 0;
00845       }
00846       else
00847       {
00848          pCommServ->iExecStatus = pDataMoverSelect->iExecStatus;
00849          pCommServ->iWaitTime = pDataMoverSelect->iWaitTime;
00850          pCommServ->iSynchId = pDataMoverSelect->iSynchId;
00851 
00852          pCommAPI->iExecStatus = ntohl(pDataMoverSelect->iExecStatus);
00853          pCommAPI->iWaitTime = ntohl(pDataMoverSelect->iWaitTime);
00854          pCommAPI->iSynchId = ntohl(pDataMoverSelect->iSynchId);
00855       }
00856 
00857       /********************* connect to data mover *******************/
00858 
00859       if (iDebug) printf(
00860          "-D- trying to connect to data mover %s:%d\n",
00861          cNodeMover, iPortMover);
00862 
00863       iRC = rconnect(cNodeMover, iPortMover, &iMaxConnect, &iSockMover);
00864       if (iRC)
00865       {
00866          printf("-E- cannot connect to data mover %s:%d\n",
00867                 cNodeMover, iPortMover);
00868          iSendEOS = 1;
00869          iError = 1;
00870          goto gClose;
00871       }
00872 
00873       if (iDebug)
00874       {
00875          printf("    successfully connected to data mover %s:%d",
00876                 cNodeMover, iPortMover);
00877          if (iMaxConnect)
00878             printf(" after %ds", iMaxConnect);
00879          printf(" (socket %d)\n", iSockMover);
00880       }
00881 
00882       strcpy(pcurAPIFile->cNodeMover, cNodeMover);
00883       pcurAPIFile->iSockMover = iSockMover;
00884       strcpy(cServer, "data mover");
00885 
00886       /******************** close connection to master ***************/
00887 
00888       /* because read from data mover may take a long time! */
00889       if (iSockMaster)
00890       {
00891          if (iDebug)
00892             printf("-D- close connection %d to master\n", iSockMaster);
00893          iRC = shutdown(iSockMaster, 2);
00894          if (iDebug)
00895             printf("    rc shutdown = %d\n", iRC);
00896          iRC = close(iSockMaster);
00897          if (iDebug)
00898             printf("    rc close = %d\n", iRC);
00899 
00900          iSockMaster = -1;
00901          pcurAPIFile->iSockMaster = -1;
00902 
00903       } /* (iSockMaster) */
00904    } /* (iMassSto) */
00905 
00906    if (iAction == 1)
00907    {
00908       if (iCache == 1)
00909       {
00910          /* request file copy from write cache to stage pool */
00911          pCommAPI->iAction = RETRIEVE_RECORD;
00912          pCommAPI->iCommLen += irawFileSystem;
00913 
00914          pCommServ->iAction = htonl(RETRIEVE_RECORD);
00915          pCommServ->iCommLen = htonl(pCommAPI->iCommLen);
00916       }
00917       else
00918       {
00919          /* prepare reading of records from data mover */
00920          pCommAPI->iAction = RETRIEVE_RECORD;
00921          pCommServ->iAction = htonl(RETRIEVE_RECORD);
00922       }
00923    }
00924    else
00925    {
00926       /* prepare writing of records to server/data mover */
00927       pCommAPI->iAction = ARCHIVE_RECORD;
00928       pCommAPI->iArchDev = ARCH_DISK;
00929 
00930       pCommServ->iAction = htonl(pCommAPI->iAction);
00931       pCommServ->iArchDev = htonl(pCommAPI->iArchDev);
00932    }
00933 
00934    if (iDebug)
00935    {
00936       printf(
00937          "-D- send command buffer to %s: id: %d, action %d, len %d\n",
00938          cServer, pCommAPI->iIdent,
00939          pCommAPI->iAction,
00940          pCommAPI->iCommLen);
00941       if ( (iMassSto) && (iAction == 1) )
00942          printf("    size %d bytes, record size %d, obj id %d-%d\n",
00943                 pCommAPI->iFileSize,
00944                 pCommAPI->iBufsizeFile,
00945                 pCommAPI->iObjHigh,
00946                 pCommAPI->iObjLow);
00947    }
00948 
00949    pcc = (char *) pCommServ;
00950    if ( (iRC = send(iSockMover, pcc, irawComm, 0 )) < 0 )
00951    {
00952       printf("-E- sending command buffer to %s (rc = %d)\n",
00953              cServer, iRC);
00954       perror("    ");
00955 
00956       iSendEOS = 1;
00957       iError = 1;
00958       goto gClose;
00959    }
00960    if (irawComm != iRC)
00961    {
00962       printf(
00963          "-E- incomplete command buffer sent to %s (%d of %d bytes)\n",
00964          cServer, iRC, irawComm);
00965 
00966       iSendEOS = 1;
00967       iError = 1;
00968       goto gClose;
00969    }
00970 
00971    if (iDebug) printf(
00972       "    command buffer sent to %s (%d byte)\n", cServer, irawComm);
00973 
00974    /* append filesystem buffer */
00975    if (iCache == 1)
00976    {
00977       pcc = (char *) &sFileSystemServ;
00978       iRC = send(iSockMover, pcc, irawFileSystem, 0);
00979       if (irawFileSystem != iRC)
00980       {
00981          if (iRC < 0)
00982          {
00983             printf(
00984               "-E- sending filesystem buffer to data mover %s failed\n",
00985               cNodeMover);
00986             perror("    ");
00987          }
00988          else printf(
00989             "-E- incomplete filesystem buffer sent to data mover %s\n",
00990             cNodeMover);
00991 
00992          iSendEOS = 1;
00993          iError = 1;
00994          goto gClose;
00995       }
00996 
00997      if (iDebug) printf(
00998         "    write cache info (%d bytes) sent to data mover %s\n",
00999         irawFileSystem, cNodeMover);
01000 
01001    } /* (iCache == 1) */
01002 
01003    /* look for reply from server/data mover */
01004    memset(&sStatus, 0X00, sizeof(srawStatus));
01005    pcc = (char *) &sStatus;
01006    iRC = rawRecvStatus(iSockMover, &pcc);
01007    if (iRC < HEAD_LEN)
01008    {
01009       printf("-E- receiving status buffer from %s", cServer);
01010       if (iRC > 0)
01011          printf(": (%d byte)\n", iRC);
01012       else
01013          printf("\n");
01014       perror("    ");
01015 
01016       iSendEOS = 1;
01017       iError = 1;
01018       goto gClose;
01019    }
01020 
01021    iStatus = ntohl(sStatus.iStatus);
01022    if (iRC > HEAD_LEN)
01023    {
01024       printf("\n-E- message received from %s:\n", cServer);
01025       printf("    %s\n", sStatus.cStatus);
01026 
01027       iSendEOS = 1;
01028       iError = 1;
01029       goto gClose;
01030    }
01031 
01032    iError = 0;
01033    if (iDebug)
01034       printf("    status (%d) received from %s (%d bytes)\n",
01035              iStatus, cServer, iRC);
01036 
01037 gClose:
01038    if (iSockMaster >= 0)
01039    {
01040       /* stop server process */
01041       if (iSendEOS)
01042       {
01043          iStatus = STA_END_OF_SESSION;
01044          iRC = rawSendStatus(iSockMaster, iStatus, NULL);
01045          if (iRC <= 0)
01046             printf("-E- %s: sending status buffer to master (EOS)\n",
01047                    cModule);
01048          else if (iDebug) printf(
01049             "    status buffer (EOS) sent to master (%d bytes)\n", iRC);
01050       }
01051 
01052       if (iDebug)
01053          printf("    close connection %d to master\n", iSockMaster);
01054       iRC = shutdown(iSockMaster, 2);
01055       if (iDebug)
01056          printf("    rc shutdown = %d\n", iRC);
01057       iRC = close(iSockMaster);
01058       if (iDebug)
01059          printf("    rc close = %d\n", iRC);
01060    }
01061 
01062    if (iSockMaster1 >= 0)
01063    {
01064       iRC = rawSendStatus(iSockMaster1, iStatus, NULL);
01065       if (iRC <= 0) printf(
01066          "-E- sending status buffer (EOS) to alternate server %s\n",
01067          cNodeMaster1);
01068       else if (iDebug) printf(
01069         "-D- status buffer (EOS) sent to master server %s (%d bytes)\n",
01070         cNodeMaster1, iRC);
01071 
01072       if (iDebug)
01073          printf("    close connection to master %s:%d, socket %d\n",
01074                 cNodeMaster1, iPortMaster, iSockMaster1);
01075       iRC = shutdown(iSockMaster1, 2);
01076       if (iDebug)
01077          printf("    rc shutdown = %d\n", iRC);
01078       iRC = close(iSockMaster1);
01079       if (iDebug)
01080          printf("    rc close = %d\n", iRC);
01081 
01082    } /* (iSockMaster1 >= 0) */
01083 
01084    if ( (iError) && (iSockMover >= 0) )
01085    {
01086       if (iSendEOS)
01087       {
01088          /* stop server/data mover process */
01089          iStatus = STA_END_OF_SESSION;
01090          iRC = rawSendStatus(iSockMover, iStatus, NULL);
01091          if (iRC <= 0)
01092             printf("-E- %s: sending status buffer (EOS) to %s\n",
01093                    cModule, cServer);
01094          else if (iDebug) printf(
01095             "    status buffer (EOS) sent to %s (%d bytes)\n",
01096             cServer, iRC);
01097       }
01098 
01099       if (iDebug)
01100          printf("    close connection %d to %s\n", iSockMover, cServer);
01101       iRC = shutdown(iSockMover, 2);
01102       if (iDebug)
01103          printf("    rc shutdown = %d\n", iRC);
01104       iRC = close(iSockMover);
01105       if (iDebug)
01106          printf("    rc close = %d\n", iRC);
01107    }
01108 
01109    if (iDebug)
01110       printf("-D- end %s\n\n", cModule);
01111 
01112    if (iError)
01113       return -1;
01114    else
01115       return iFileId;
01116 
01117 } /* rfio_open */
01118 
01119 /********************************************************************
01120  * rfio_close: close remote file in mass store managed by tsmcli
01121  *
01122  * created  4.12.2000, Horst Goeringer
01123  ********************************************************************
01124  */
01125 
01126 int rfio_close(int iFileId)                              /* file id */
01127 {
01128    char cModule[32] = "rfio_close";
01129    int iDebug = 0;
01130    int iRC;
01131    int iSockMaster;               /* socket for connection to master */
01132    int iSockMover;                 /* socket for connection to mover */
01133    int iStatus = STA_END_OF_SESSION;
01134    int ii = 0;
01135    char cServer[16] = "server";
01136    srawAPIFile *pcurAPIFile;
01137 
01138    if (iDebug) printf("\n-D- begin %s: close remote file %d\n",
01139       cModule, iFileId);
01140 
01141    if (iFileCount == 0)
01142    {
01143       printf("-E- no remote file available for close\n");
01144       return -1;
01145    }
01146 
01147    while (ii < iFileMax)
01148    {
01149       if (pAPIFile[ii])
01150       {
01151          if (pAPIFile[ii]->iFileId == iFileId)
01152             break;
01153       }
01154       ii++;
01155    }
01156 
01157    if (ii == iFileMax)
01158    {
01159       printf("-E- remote file %d cannot be closed: not found\n",
01160              iFileId);
01161       return -1;
01162    }
01163 
01164    pcurAPIFile = pAPIFile[iFileId];
01165 
01166    iSockMover = pcurAPIFile->iSockMover;
01167    if (iSockMover)
01168    {
01169       /* stop server/data mover process */
01170       iStatus = STA_END_OF_SESSION;
01171       iRC = rawSendStatus(iSockMover, iStatus, NULL);
01172       if (iRC <= 0)
01173          printf("-E- %s: sending status buffer (EOS) to %s\n",
01174                 cModule, cServer);
01175       else if (iDebug) printf(
01176         "    status buffer (EOS) sent to %s (%d bytes)\n",
01177         cServer, iRC);
01178 
01179       if (iDebug)
01180          printf("    close connection %d to %s\n", iSockMover, cServer);
01181       iRC = shutdown(iSockMover, 2);
01182       if (iDebug)
01183          printf("    rc shutdown = %d\n", iRC);
01184       iRC = close(iSockMover);
01185       if (iDebug)
01186          printf("    rc close = %d\n", iRC);
01187    }
01188 
01189    free( pAPIFile[iFileId] );
01190    pAPIFile[iFileId] = NULL;
01191    iFileCount--;
01192 
01193    if (iDebug)
01194    {
01195       printf(
01196          "    remote file control block deleted (%d still active)\n",
01197          iFileCount);
01198       printf("-D- end %s\n\n", cModule);
01199    }
01200 
01201    return 0;
01202 
01203 } /* rfio_close */
01204 
01205 /********************************************************************
01206  * rfio_read: read remote file in mass store managed by tsmcli
01207  *
01208  * created  4.12.2000, Horst Goeringer
01209  ********************************************************************
01210  */
01211 
01212 int rfio_read(int iFileId,                               /* file id */
01213               char *pcBuffer,                        /* data buffer */
01214               int iItems)                   /* number of data bytes */
01215 {
01216    char cModule[32] = "rfio_read";
01217    int iDebug = 0;
01218    int iRC;
01219 
01220    int iSockMover;                 /* socket for connection to mover */
01221    int iSeekMode;
01222    int iOffset;
01223    int iBufsizeRead;
01224    int iBufnoServ;      /* no. of buffers transfered from/to server */
01225    int iDataServ;         /* no. of bytes transfered from/to server */
01226 
01227    int iStatus;
01228    int iStatusLen;
01229    int iBufsizeRecv;
01230 
01231    char cMsg[128] = "";
01232    char *pcc;
01233    int ii = 0;
01234    int iBuf;
01235    int *pint;
01236 
01237    srawAPIFile *pcurAPIFile;
01238    srawComm *pCommAPI;  /* communication buffer in API control block */
01239    srawComm *pCommServ;            /* copy for servers in net format */
01240 
01241    if (iDebug)
01242       printf("\n-D- begin %s\n", cModule);
01243 
01244    if (iFileCount == 0)
01245    {
01246       printf("-E- no remote file open for read\n");
01247       return -1;
01248    }
01249 
01250    while (ii < iFileMax)
01251    {
01252       if (pAPIFile[ii])
01253       {
01254          if (pAPIFile[ii]->iFileId == iFileId)
01255             break;
01256       }
01257       ii++;
01258    }
01259 
01260    if (ii == iFileMax)
01261    {
01262       printf("-E- remote file %d cannot be read: not opened\n",
01263              iFileId);
01264       return -1;
01265    }
01266 
01267    pcurAPIFile = pAPIFile[iFileId];
01268    pCommAPI = &(pcurAPIFile->sCommAPI);
01269    pCommServ = &(pcurAPIFile->sCommServ);
01270 
01271    iBufnoServ = pcurAPIFile->iBufnoServ;
01272    iDataServ = pcurAPIFile->iDataServ;
01273 
01274    iBufnoServ++;
01275    if (iDebug)
01276    {
01277       printf("    remote file control block %d selected\n", ii);
01278       printf("    file %d, buffer %d: read %d bytes\n",
01279              iFileId, iBufnoServ, iItems);
01280    }
01281 
01282    iBufsizeRead = pcurAPIFile->iBufsizeAct;
01283    if (iDebug)
01284    {
01285       if (iBufsizeRead != iItems)
01286          printf( "    new buffer size %d\n", iItems);
01287       printf("    send request for new buffer\n");
01288    }
01289 
01290    iSockMover = pcurAPIFile->iSockMover;
01291    iSeekMode = pcurAPIFile->iSeekMode;
01292    iOffset = pcurAPIFile->iOffset;
01293    iRC = rawSendRequest(iSockMover, iSeekMode, iOffset, iItems);
01294    if (iRC != 0)
01295    {
01296       printf("-E- sending request for next data buffer\n");
01297       return -1;
01298    }
01299 
01300    /* reset seek options to default (no seek) */
01301    if (iSeekMode != -1)
01302    {
01303       pcurAPIFile->iSeekMode = -1;
01304       pcurAPIFile->iOffset = 0;
01305    }
01306 
01307    pcurAPIFile->iBufsizeAct = iItems;          /* keep current value */
01308 
01309    /********************** retrieve next buffer **********************/
01310 
01311    /* get size retrieve buffer */
01312    pcc = (char *) &iBufsizeRecv;
01313    iBuf = iint;
01314    while(iBuf > 0)
01315    {
01316 gRetryLen:
01317       if ( (iRC = recv( iSockMover, pcc, iBuf, 0 )) < 0 )
01318       {
01319          if (iDebug)
01320          {
01321             printf("-E- receiving data length from server (buffer %d)",
01322                    iBufnoServ);
01323             perror("EEE ");
01324          }
01325          goto gRetryLen;
01326       }
01327       iBuf -= iRC;
01328       pcc += iRC;
01329 
01330       if (iDebug == 2)
01331       {
01332          printf("%d.", iRC);
01333          fflush(stdout);
01334       }
01335    } /* recv loop data length */
01336 
01337    iBufsizeRecv = ntohl(iBufsizeRecv);
01338    if (iDebug == 2) printf("%d_", iBufsizeRecv);
01339 
01340    if (iBufsizeRecv < 0)
01341    {
01342       if (iBufsizeRecv != IDENT_STATUS)
01343       {
01344          printf("-E- invalid status header received (%d)\n",
01345                 iBufsizeRecv);
01346          return -1;
01347       }
01348       if (iDebug) printf("-D- status header found\n");
01349 
01350       /* receive remainder of status header */
01351       pcc = pcBuffer;
01352       iBuf = HEAD_LEN - 4;                   /* iIdent already read */
01353       while(iBuf > 0)             /* get remainder of status header */
01354       {
01355          if ( (iRC = recv( iSockMover, pcc, iBuf, 0 )) < 0 )
01356          {
01357            printf(
01358               "-E- receiving status header from data mover (buffer %d)",
01359               iBufnoServ);
01360            perror("    ");
01361            return -1;
01362          }
01363          if (iDebug == 2) printf("%d.", iRC);
01364 
01365          iBuf -= iRC;
01366          pcc += iRC;
01367       }
01368 
01369       pint = (int *) pcBuffer;              /* points to status word */
01370       iStatus = ntohl(*pint);                     /* status received */
01371       if ( (iStatus != STA_END_OF_FILE)    &&
01372            (iStatus != STA_END_OF_SESSION) &&
01373            (iStatus != STA_ERROR) &&
01374            (iStatus != STA_ERROR_EOF) )
01375       {
01376          printf("-E- unexpected status from data mover: %d\n", iStatus);
01377          return -1;
01378       }
01379 
01380       if ( (iStatus == STA_END_OF_FILE) ||
01381            (iStatus == STA_END_OF_SESSION) )
01382       {
01383          if (iDebug) printf("    EOF on input\n");
01384 
01385          if (iDataServ == 0)                          /* empty file */
01386          {
01387             printf("\n-E- %s%s%s empty\n",
01388                    pCommServ->cNamefs,
01389                    pCommServ->cNamehl,
01390                    pCommServ->cNamell);
01391             return -1;
01392          }
01393          else return 0;
01394       }
01395       else
01396       {
01397          pint++;                           /* points to status size */
01398          iStatusLen = ntohl(pint);
01399          if (iStatusLen > 0)
01400          {
01401             iRC = rawRecvError(iSockMover, iStatusLen, &pcc);
01402             if (iRC < 0)
01403             {
01404               printf(
01405                  "-E- receiving status message from data mover, rc = %d\n",
01406                  iRC);
01407               return -1;
01408             }
01409 
01410             if ( (iStatus == STA_ERROR) ||
01411                  (iStatus == STA_ERROR_EOF) )
01412             {
01413                printf("-E- received error status from data mover:\n");
01414                printf("%s\n", pcc);
01415                return -1;
01416             }
01417 
01418             /* warning from data mover */
01419             printf("%s\n", pcc);
01420 
01421          } /* (iStatusLen > 0) */
01422       } /* (iStatus != STA_END_OF_FILE) &&
01423            (iStatus != STA_END_OF_SESSION) */
01424    } /* (iBufsizeRecv < 0) */
01425    else if (iBufsizeRecv != iItems)
01426    {
01427       if (iDebug)
01428       {
01429          if (iBufsizeRecv) printf(
01430             "-W- requested %d bytes, received buffer length %d bytes\n",
01431             iItems, iBufsizeRecv);
01432          else printf("-W- EOF reached\n");
01433       }
01434       iItems = iBufsizeRecv;
01435    }
01436 
01437    /* recv loop over buffers of size iBufsizeRecv */
01438    iBuf = iBufsizeRecv;
01439    pcc = pcBuffer;
01440    while(iBuf > 0)
01441    {
01442 gRetryData:
01443       if ( (iRC = recv( iSockMover, pcc, iBuf, 0 )) < 0 )
01444       {
01445          if (iDebug)
01446          {
01447             printf("-E- receiving data from data mover (buffer %d)\n",
01448                    iBufnoServ);
01449             perror("EEE ");
01450          }
01451          goto gRetryData;
01452       }
01453 
01454       if (iDebug == 2)
01455       {
01456          printf("%d:", iRC);
01457          fflush(stdout);
01458       }
01459 
01460       if (iRC == 0)               /* connection closed by data mover */
01461       {
01462          printf("-E- data transfer incomplete\n");
01463          return -1;
01464       }
01465 
01466       iBuf -= iRC;
01467       pcc += iRC;
01468       pcurAPIFile->iDataServ += iRC;
01469 
01470    } /* while(iBuf > 0) */
01471 
01472    if (iBufsizeRecv)
01473    {
01474       pcurAPIFile->iBufnoServ++;
01475       if (iDebug == 2)
01476          printf(" buffer %d received\n", pcurAPIFile->iBufnoServ);
01477    }
01478 
01479    if (iDebug)
01480       printf("-D- end %s\n\n", cModule);
01481 
01482    return iBufsizeRecv;
01483 
01484 } /* rfio_read */
01485 
01486 /********************************************************************
01487  * rfio_write: write remote file in mass store managed by tsmcli
01488  *
01489  * created  4.12.2000, Horst Goeringer
01490  ********************************************************************
01491  */
01492 
01493 int rfio_write(int iFileId,                              /* file id */
01494                char *pcBuffer,                       /* data buffer */
01495                int iItems)                  /* number of data bytes */
01496 {
01497    char cModule[32] = "rfio_write";
01498    int iDebug = 0;
01499 
01500    int iRC;
01501    char cMsg[128] = "";
01502    char *pcc;
01503    int ii = 0;
01504    int iBuf;
01505    int *pint;
01506 
01507    int iMassSto = 0;   /* =1: contact GSI mass storage (first query)
01508                           =0: contact RFIO read/write server         */
01509    int iSockMover;                 /* socket for connection to mover */
01510    int iBufsizeWrite;
01511    int iBufnoServ;       /* no. of buffers transfered from/to server */
01512 
01513    srawAPIFile *pcurAPIFile;
01514 
01515    srawComm *pCommAPI;
01516    srawComm *pCommServ;            /* copy for servers in net format */
01517 
01518    if (iDebug)
01519       printf("-D- begin %s\n", cModule);
01520 
01521    if (iItems <= 0)
01522    {
01523       printf("-W- invalid no. of bytes to write: %d\n", iItems);
01524       return 0;
01525    }
01526 
01527    if (iFileCount == 0)
01528    {
01529       printf("-E- no remote file open for write\n");
01530       return -1;
01531    }
01532 
01533    ii = 0;
01534    while (ii < iFileMax)
01535    {
01536       if (pAPIFile[ii])
01537       {
01538          if (pAPIFile[ii]->iFileId == iFileId)
01539             break;
01540       }
01541       ii++;
01542    }
01543 
01544    if (ii == iFileMax)
01545    {
01546       printf("-E- remote file %d cannot be written: not opened\n",
01547              iFileId);
01548       return -1;
01549    }
01550 
01551    pcurAPIFile = pAPIFile[iFileId];
01552    pCommServ = &(pcurAPIFile->sCommServ);
01553    pCommAPI = &(pcurAPIFile->sCommAPI);
01554 
01555    iBufnoServ = pcurAPIFile->iBufnoServ;
01556    iBufnoServ++;
01557 
01558    if (iDebug)
01559    {
01560       printf("    remote file control block %d selected\n", ii);
01561       printf("    file %d, buffer %d: write %d bytes\n",
01562              iFileId, iBufnoServ, iItems);
01563    }
01564 
01565    pCommServ->iBufsizeFile = htonl(iItems);
01566    pCommAPI->iBufsizeFile = iItems;
01567    iBufsizeWrite = pcurAPIFile->iBufsizeAct;
01568    if (iDebug)
01569    {
01570       if (iBufsizeWrite != iItems)
01571          printf( "    new buffer size %d\n", iItems);
01572       printf("    send new buffer\n");
01573    }
01574 
01575    pcurAPIFile->iBufsizeAct = iItems;          /* keep current value */
01576    iSockMover = pcurAPIFile->iSockMover;
01577 
01578    /*********************** write next buffer ************************/
01579 
01580    iBufsizeWrite = htonl(iItems);
01581    iBuf = iint;
01582    pcc = (char *) &iBufsizeWrite;
01583    while (iBuf)
01584    {
01585       iRC = send( iSockMover, pcc, iBuf, 0 );
01586       if (iRC <= 0)
01587       {
01588          if (iRC == 0)
01589             printf("-E- send of data length to server broken\n");
01590          else
01591          {
01592             printf("-E- sending data length to server (buffer %d)",
01593                    iBufnoServ);
01594             perror("EEE ");
01595          }
01596          return -1;
01597       }
01598 
01599       iBuf -= iRC;
01600       pcc += iRC;
01601 
01602       if (iDebug == 2)
01603       {
01604          printf("%d(%d)_", iRC, iItems);
01605          fflush(stdout);
01606       }
01607 
01608    } /* while (iBuf) */
01609 
01610    iBuf = iItems;
01611    pcc = pcBuffer;
01612    while (iBuf)
01613    {
01614       iRC = send( iSockMover, pcc, iBuf, 0 );
01615       if (iRC <= 0)
01616       {
01617          if (iRC == 0)
01618             printf("-E- send of data to server broken\n");
01619          else
01620          {
01621             printf("-E- sending data to server (buffer %d, %d bytes)",
01622                    iBufnoServ, iBuf);
01623             perror("EEE ");
01624          }
01625          return -1;
01626       }
01627 
01628       iBuf -= iRC;
01629       pcc += iRC;
01630       pcurAPIFile->iDataServ += iRC;
01631 
01632       if (iDebug == 2)
01633       {
01634          printf("%d.", iRC);
01635          fflush(stdout);
01636       }
01637 
01638    } /* while (iBuf) */
01639 
01640    if (iItems)
01641    {
01642       pcurAPIFile->iBufnoServ++;
01643       if (iDebug == 2)
01644          printf(" buffer %d sent\n", pcurAPIFile->iBufnoServ);
01645    }
01646 
01647    if (iDebug)
01648       printf("-D- end %s\n", cModule);
01649 
01650    return iItems;
01651 
01652 } /* rfio_write */
01653 
01654 /********************************************************************
01655  * rfio_lseek: in remote file in mass store managed by tsmcli:
01656  *    move read/write file mark
01657  *
01658  * created  4.12.2000, Horst Goeringer
01659  ********************************************************************
01660  */
01661 
01662 int rfio_lseek(int iFileId,                              /* file id */
01663                int ilocOffset,
01664                int ilocSeekMode)
01665 {
01666    char cModule[32] = "rfio_lseek";
01667    int iDebug = 0;
01668    int iRC;
01669    int iSockMover;                 /* socket for connection to mover */
01670    int iSeekMode;
01671    int iOffset;
01672 
01673    srawAPIFile *pcurAPIFile;
01674 
01675    if (iDebug)
01676    {
01677       printf("\n-D- begin %s: file %d\n", cModule, iFileId);
01678       if (ilocSeekMode == SEEK_SET)
01679          printf("    position to %d bytes, \n", ilocOffset);
01680       else if (ilocSeekMode == SEEK_CUR)
01681          printf("    position to current + %d bytes, \n", ilocOffset);
01682       else if (ilocSeekMode == SEEK_END)
01683          printf("    position to file size + %d bytes, \n", ilocOffset);
01684       else
01685       {
01686          printf("-E- unexpected offset (%d)\n", ilocSeekMode);
01687          return -1;
01688       }
01689    }
01690 
01691    pcurAPIFile = pAPIFile[iFileId];
01692    iSeekMode = pcurAPIFile->iSeekMode;
01693 
01694    /* check if still seek request pending */
01695    if (iSeekMode != -1)
01696    {
01697       iSockMover = pcurAPIFile->iSockMover;
01698       iOffset = pcurAPIFile->iOffset;
01699       iRC = rawSendRequest(iSockMover, iSeekMode, iOffset, 0);
01700       if (iRC != 0)
01701       {
01702          printf("-E- sending request for seek\n");
01703          return -1;
01704       }
01705    }
01706 
01707    pcurAPIFile->iSeekMode = ilocSeekMode;
01708    pcurAPIFile->iOffset = ilocOffset;
01709 
01710    if (iDebug)
01711       printf("-D- end %s\n\n", cModule);
01712 
01713    return 0;
01714 
01715 } /* rfio_lseek */
01716 
01717 /********************************************************************
01718  * rfio_fopen: open remote file in mass store managed by tsmcli
01719  *
01720  * created  4.12.2000, Horst Goeringer
01721  ********************************************************************
01722  */
01723 
01724 RFILE *rfio_fopen(char *pcFile,                       /* file name */
01725                  char *pcOptions)                       /* options */
01726 {
01727    char cModule[32] = "rfio_fopen";
01728    int iDebug = 0;
01729    int iRC;
01730    int iFileId;           /* file identifier for server connection */
01731 
01732    if (iDebug)
01733       printf("-D- begin %s\n", cModule);
01734 
01735    if (*pcOptions == 'r')
01736    {
01737       iFileId = rfio_open(pcFile, O_RDONLY, 0);
01738    }
01739    if (*pcOptions == 'w')
01740    {
01741       iFileId = rfio_open(pcFile, O_WRONLY | O_CREAT, 0);
01742    }
01743 
01744    if (iDebug)
01745       printf("-D- end %s\n\n", cModule);
01746 
01747    if (iFileId < 0)
01748       return NULL;
01749 
01750    return pAPIFile[iFileId];        /* global, filled in rfio_open */
01751 
01752 } /* rfio_fopen */
01753 
01754 /********************************************************************
01755  * rfio_fread: read remote file in mass store managed by tsmcli
01756  *
01757  * created  4.12.2000, Horst Goeringer
01758  ********************************************************************
01759  */
01760 
01761 int rfio_fread(char *pcBuffer,                      /* data buffer */
01762               int iSize,                      /* size of data item */
01763               int iItems,                  /* number of data items */
01764               RFILE *pRemFile)        /* remote file control block */
01765 {
01766    char cModule[32]="rfio_fread";
01767    int iDebug = 0;
01768    int iRC;
01769    int iFileId;           /* file identifier for server connection */
01770    int iBytes;
01771 
01772    if (iDebug)
01773       printf("-D- begin %s\n", cModule);
01774 
01775    if (pRemFile == NULL)
01776    {
01777       printf("-E- Remote file not open for read\n");
01778       return -1;
01779    }
01780 
01781    iFileId = pRemFile->iFileId;
01782    iBytes = iSize*iItems;
01783    iRC = rfio_read(iFileId, pcBuffer, iBytes);
01784 
01785    if (iDebug)
01786       printf("-D- end %s\n", cModule);
01787 
01788    return iRC;
01789 
01790 } /* rfio_fread */
01791 
01792 /********************************************************************
01793  * rfio_fwrite: write remote file to mass store managed by tsmcli
01794  *
01795  * created  4.12.2000, Horst Goeringer
01796  ********************************************************************
01797  */
01798 
01799 int rfio_fwrite(char *pcBuffer,                      /* data buffer */
01800               int iSize,                       /* size of data item */
01801               int iItems,                   /* number of data items */
01802               RFILE *pRemFile)         /* remote file control block */
01803 {
01804    char cModule[32]="rfio_fwrite";
01805    int iDebug = 0;
01806    int iFileId;           /* file identifier for server connection */
01807    int iBytes;
01808    int iRC;
01809 
01810    if (iDebug)
01811       printf("\n-D- begin %s\n", cModule);
01812 
01813    if (pRemFile == NULL)
01814    {
01815       printf("-E- Remote file not open for write\n");
01816       return -1;
01817    }
01818 
01819    iFileId = pRemFile->iFileId;
01820    iBytes = iSize*iItems;
01821    iRC = rfio_write(iFileId, pcBuffer, iBytes);
01822 
01823    if (iDebug)
01824       printf("-D- end %s\n", cModule);
01825 
01826    return iRC;
01827 
01828 } /* rfio_fwrite */
01829 
01830 /********************************************************************
01831  * rfio_fclose: close remote file in mass store managed by tsmcli
01832  *
01833  * created  4.12.2000, Horst Goeringer
01834  ********************************************************************
01835  */
01836 
01837 int rfio_fclose(RFILE *pRemFile)      /* remote file control block */
01838 {
01839    char cModule[32] = "rfio_fclose";
01840    int iDebug = 0;
01841    int iFileId;           /* file identifier for server connection */
01842    int iRC;
01843    int iStatus = STA_END_OF_SESSION;
01844 
01845    if (iDebug)
01846       printf("-D- begin %s\n", cModule);
01847 
01848    iFileId = pRemFile->iFileId;
01849    iRC = rfio_close(iFileId);
01850 
01851    return iRC;
01852 
01853 } /* rfio_fclose */
01854 
01855 /********************************************************************
01856  * rfio_access: for remote file in mass store managed by tsmcli:
01857  *   get access status
01858  *
01859  * created  4.12.2000, Horst Goeringer
01860  ********************************************************************
01861  */
01862 
01863 int rfio_access(char *pcFile,                         /* file name */
01864                 int iMode)
01865 {
01866    char cModule[32] = "rfio_access";
01867    int iDebug = 0;
01868    int iRC;
01869 
01870    if (iDebug)
01871       printf("-D- begin %s\n", cModule);
01872 
01873    return 0;
01874 
01875 } /* rfio_access */
01876 
01877 /********************************************************************
01878  * rfio_fstat: for remote file in mass store managed by tsmcli:
01879  *   get file status
01880  *
01881  * created 26. 2.2001, Horst Goeringer
01882  ********************************************************************
01883  */
01884 
01885 int rfio_fstat(int iFileId,                              /* file id */
01886                void* fBufStat) /* buffer with file statistics */
01887 {
01888    char cModule[32] = "rfio_fstat";
01889    int iDebug = 0;
01890    int iRC = 0;
01891 
01892    if (iDebug)
01893       printf("-D- begin %s\n", cModule);
01894 
01895    return iRC;
01896 
01897 } /* rfio_fstat */
01898 
01899 /********************************************************************
01900  * rfio_parse: for remote file in mass store managed by tsmcli:
01901  *   parse name to host and path
01902  *
01903  * created  4.12.2000, Horst Goeringer
01904  ********************************************************************
01905  */
01906 
01907 int rfio_parse(char *pcFile,                           /* file name */
01908                char **pcNode,
01909                char **pcPath)
01910 {
01911    char cModule[32] = "rfio_parse";
01912    int iDebug = 0;
01913    int iRC;
01914 
01915    if (iDebug)
01916       printf("-D- begin %s\n", cModule);
01917 
01918    return 0;
01919 
01920 } /* rfio_parse */
01921 
01922 /********************************************************************
01923  * rfio_perror: for remote file in mass store managed by tsmcli:
01924  *   print error message to stderr
01925  *
01926  * created 26. 2.2001, Horst Goeringer
01927  ********************************************************************
01928  */
01929 
01930 void rfio_perror(const char *pUMsg)  /* user prefix to error message */
01931 {
01932    char cModule[32] = "rfio_perror";
01933    int iDebug = 0;
01934    int iRC;
01935 
01936    if (iDebug)
01937       printf("-D- begin %s\n", cModule);
01938 
01939    if (strlen(rfio_errmsg) == 0)
01940       fprintf(stderr, "%s : No error message\n", pUMsg);
01941    else
01942       fprintf(stderr, "%s : %s\n", pUMsg, rfio_errmsg);
01943 
01944 } /* rfio_perror */
01945 
01946 /********************************************************************
01947  * rfio_serror: for remote file in mass store managed by tsmcli:
01948  *   print last RFIO related error message to string
01949  *
01950  * created 26. 2.2001, Horst Goeringer
01951  ********************************************************************
01952  */
01953 
01954 char * rfio_serror()
01955 {
01956    char cModule[32] = "rfio_serror";
01957    int iDebug = 0;
01958    int iRC;
01959 
01960    if (iDebug) printf(
01961       "-D- begin %s: errlen %d\n", cModule, strlen(rfio_errmsg));
01962 
01963    if (strlen(rfio_errmsg) == 0)
01964       return NULL;
01965 
01966    return rfio_errmsg;
01967 
01968 } /* rfio_serror */
01969 
01970 /********************************************************************
01971  * rfio_unlink: for remote file in mass store managed by tsmcli:
01972  *
01973  * created  4.12.2000, Horst Goeringer
01974  ********************************************************************
01975  */
01976 
01977 int rfio_unlink(char *pcFile)                         /* file name */
01978 {
01979    char cModule[32] = "rfio_unlink";
01980    int iDebug = 0;
01981    int iRC;
01982 
01983    if (iDebug)
01984       printf("-D- begin %s\n", cModule);
01985 
01986    return 0;
01987 
01988 } /* rfio_unlink */
01989 
01990 /********************************************************************
01991  * rfiosetopt: for remote file in mass store managed by tsmcli:
01992  *
01993  * created  9. 9.2002, Horst Goeringer
01994  ********************************************************************
01995  */
01996 
01997 int rfiosetopt(int iopt, int *pival, int ilen)
01998 {
01999    char cModule[32] = "rfiosetopt";
02000    int iDebug = 0;
02001    int iRC;
02002 
02003    if (iDebug)
02004       printf("-D- begin %s\n", cModule);
02005 
02006    return 0;
02007 
02008 } /* rfiosetopt */
02009 
02010 /********************************************************************
02011  * rfio_mkdir: for remote file in mass store managed by tsmcli:
02012  *
02013  * created 28. 8.2003, Horst Goeringer
02014  ********************************************************************
02015  */
02016 
02017 int rfio_mkdir(const char *path, int mode)
02018 {
02019    char cModule[32] = "rfio_mkdir";
02020    int iDebug = 0;
02021    int iRC;
02022 
02023    if (iDebug)
02024       printf("-D- begin %s\n", cModule);
02025 
02026    return 0;
02027 
02028 } /* rfio_mkdir */
02029 
02030 /********************************************************************
02031  * rfio_opendir: for remote file in mass store managed by tsmcli:
02032  *
02033  * created 28. 8.2003, Horst Goeringer
02034  ********************************************************************
02035  */
02036 
02037 void *rfio_opendir(const char *dirpath)
02038 {
02039    char cModule[32] = "rfio_opendir";
02040    int iDebug = 0;
02041    int iRC;
02042 
02043    if (iDebug)
02044       printf("-D- begin %s\n", cModule);
02045 
02046    return 0;
02047 
02048 } /* rfio_opendir */
02049 
02050 /********************************************************************
02051  * rfio_readdir: for remote file in mass store managed by tsmcli:
02052  *
02053  * created 28. 8.2003, Horst Goeringer
02054  ********************************************************************
02055  */
02056 
02057 void *rfio_readdir(void *dirp)
02058 {
02059    char cModule[32] = "rfio_readdir";
02060    int iDebug = 0;
02061    int iRC;
02062 
02063    if (iDebug)
02064       printf("-D- begin %s\n", cModule);
02065 
02066    return 0;
02067 
02068 } /* rfio_readdir */
02069 
02070 /********************************************************************
02071  * rfio_closedir: for remote file in mass store managed by tsmcli:
02072  *
02073  * created 28. 8.2003, Horst Goeringer
02074  ********************************************************************
02075  */
02076 
02077 int rfio_closedir(void *dirp)
02078 {
02079    char cModule[32] = "rfio_closedir";
02080    int iDebug = 0;
02081    int iRC;
02082 
02083    if (iDebug)
02084       printf("-D- begin %s\n", cModule);
02085 
02086    return 0;
02087 
02088 } /* rfio_closedir */
02089 
02090 /********************************************************************
02091  * rfio_stat: for remote file in mass store managed by tsmcli:
02092  *
02093  * created 28. 8.2003, Horst Goeringer
02094  ********************************************************************
02095  */
02096 
02097 int rfio_stat(const char *path, struct stat *statbuf)
02098 {
02099    char cModule[32] = "rfio_stat";
02100    int iDebug = 0;
02101    int iRC;
02102 
02103    if (iDebug)
02104       printf("-D- begin %s\n", cModule);
02105 
02106    return 0;
02107 
02108 } /* rfio_stat */
02109 
02110 /********************************************************************
02111  * rfio_gsi_query: query file information of opened remote file
02112  *
02113  * created  7. 2.2001, Horst Goeringer
02114  ********************************************************************
02115  */
02116 
02117 int rfio_gsi_query(int iFileId,                          /* file id */
02118                    int iFull,                          /* verbosity */
02119                    char *pInfo)                      /* info string */
02120 {
02121    char cModule[32] = "rfio_gsi_query";
02122    int iDebug = 0;
02123    int iRC = 0;
02124    int ii = 0;
02125 
02126    srawAPIFile *pcurAPIFile;
02127    srawObjAttr *pQueryAPI;                      /* query information */
02128 
02129    if (iFileCount == 0)
02130    {
02131       printf("-E- %s: no remote file available\n", cModule);
02132       return -1;
02133    }
02134 
02135    while (ii < iFileMax)
02136    {
02137       if (pAPIFile[ii])
02138       {
02139          if (pAPIFile[ii]->iFileId == iFileId)
02140             break;
02141       }
02142       ii++;
02143    }
02144 
02145    if (ii == iFileMax)
02146    {
02147       printf("-E- %s: remote file %d not found\n",
02148              cModule, iFileId);
02149       return -1;
02150    }
02151 
02152    pcurAPIFile = pAPIFile[iFileId];
02153    pQueryAPI = &(pcurAPIFile->sQueryAPI);
02154    iRC = rawQueryString(pQueryAPI, iFull, pInfo);
02155    if (iDebug)
02156       printf("-D- %s (%d byte)\n", pInfo, iRC);
02157 
02158    return iRC;
02159 
02160 } /* rfio_gsi_query */
02161 
02162 
02163 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:34 2008 for Go4-v3.04-1 by  doxygen 1.4.2