Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/RawAPI/rawapin.c

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

Generated on Tue Nov 8 10:56:09 2005 for Go4-v2.10-5 by doxygen1.2.15