00001
00002
00003
00004
00005
00006
00007
00008 #include "fileOpen.h"
00009 #include "fileOpr.h"
00010 #include "miscServerFunct.h"
00011
00012 int
00013 rsFileOpen (rsComm_t *rsComm, fileOpenInp_t *fileOpenInp)
00014 {
00015 rodsServerHost_t *rodsServerHost;
00016 int remoteFlag;
00017 int fileInx;
00018
00019 remoteFlag = resolveHost (&fileOpenInp->addr, &rodsServerHost);
00020
00021 if (remoteFlag < 0) {
00022 return (remoteFlag);
00023 } else {
00024 fileInx = rsFileOpenByHost (rsComm, fileOpenInp, rodsServerHost);
00025 return (fileInx);
00026 }
00027 }
00028
00029 int
00030 rsFileOpenByHost (rsComm_t *rsComm, fileOpenInp_t *fileOpenInp,
00031 rodsServerHost_t *rodsServerHost)
00032 {
00033 int fileInx;
00034 int fd;
00035 int remoteFlag;
00036
00037 if (rodsServerHost == NULL) {
00038 rodsLog (LOG_NOTICE,
00039 "rsFileOpenByHost: Input NULL rodsServerHost");
00040 return (SYS_INTERNAL_NULL_INPUT_ERR);
00041 }
00042
00043 remoteFlag = rodsServerHost->localFlag;
00044
00045 if (remoteFlag == LOCAL_HOST) {
00046 fd = _rsFileOpen (rsComm, fileOpenInp);
00047 } else if (remoteFlag == REMOTE_HOST) {
00048 fd = remoteFileOpen (rsComm, fileOpenInp, rodsServerHost);
00049 } else {
00050 if (remoteFlag < 0) {
00051 return (remoteFlag);
00052 } else {
00053 rodsLog (LOG_NOTICE,
00054 "rsFileOpenByHost: resolveHost returned unrecognized value %d",
00055 remoteFlag);
00056 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00057 }
00058 }
00059
00060 if (fd < 0) {
00061 return (fd);
00062 }
00063
00064 fileInx = allocAndFillFileDesc (rodsServerHost, fileOpenInp->fileName,
00065 fileOpenInp->fileType, fd, fileOpenInp->mode);
00066
00067 return (fileInx);
00068 }
00069
00070 int
00071 remoteFileOpen (rsComm_t *rsComm, fileOpenInp_t *fileOpenInp,
00072 rodsServerHost_t *rodsServerHost)
00073 {
00074 int fileInx;
00075 int status;
00076
00077 if (rodsServerHost == NULL) {
00078 rodsLog (LOG_NOTICE,
00079 "remoteFileOpen: Invalid rodsServerHost");
00080 return SYS_INVALID_SERVER_HOST;
00081 }
00082
00083 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00084 return status;
00085 }
00086
00087 fileInx = rcFileOpen (rodsServerHost->conn, fileOpenInp);
00088
00089 if (fileInx < 0) {
00090 rodsLog (LOG_NOTICE,
00091 "remoteFileOpen: rcFileOpen failed for %s",
00092 fileOpenInp->fileName);
00093 }
00094
00095 return fileInx;
00096 }
00097
00098
00099
00100
00101 int
00102 _rsFileOpen (rsComm_t *rsComm, fileOpenInp_t *fileOpenInp)
00103 {
00104 int fd;
00105
00106
00107
00108
00109
00110 if ((fileOpenInp->flags & O_WRONLY) && (fileOpenInp->flags & O_RDWR)) {
00111
00112 fileOpenInp->flags &= ~(O_WRONLY);
00113 }
00114 fd = fileOpen (fileOpenInp->fileType, rsComm, fileOpenInp->fileName,
00115 fileOpenInp->flags, fileOpenInp->mode);
00116
00117 if (fd < 0) {
00118 rodsLog (LOG_NOTICE,
00119 "_rsFileOpen: fileOpen for %s, status = %d",
00120 fileOpenInp->fileName, fd);
00121 return (fd);
00122 }
00123
00124 return (fd);
00125 }
00126