00001
00002
00003
00004
00005
00006 #include "fileFstat.h"
00007 #include "miscServerFunct.h"
00008 #include "rsGlobalExtern.h"
00009
00010 int
00011 rsFileFstat (rsComm_t *rsComm, fileFstatInp_t *fileFstatInp,
00012 rodsStat_t **fileFstatOut)
00013 {
00014 rodsServerHost_t *rodsServerHost;
00015 int remoteFlag;
00016 int status;
00017
00018 *fileFstatOut = NULL;
00019
00020 remoteFlag = getServerHostByFileInx (fileFstatInp->fileInx,
00021 &rodsServerHost);
00022
00023 if (remoteFlag == LOCAL_HOST) {
00024 status = _rsFileFstat (rsComm, fileFstatInp, fileFstatOut);
00025 } else if (remoteFlag == REMOTE_HOST) {
00026 status = remoteFileFstat (rsComm, fileFstatInp, fileFstatOut,
00027 rodsServerHost);
00028 } else {
00029 if (remoteFlag < 0) {
00030 return (remoteFlag);
00031 } else {
00032 rodsLog (LOG_NOTICE,
00033 "rsFileFstat: resolveHost returned unrecognized value %d",
00034 remoteFlag);
00035 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00036 }
00037 }
00038
00039
00040
00041 return (status);
00042 }
00043
00044 int
00045 remoteFileFstat (rsComm_t *rsComm, fileFstatInp_t *fileFstatInp,
00046 rodsStat_t **fileFstatOut, rodsServerHost_t *rodsServerHost)
00047 {
00048 int status;
00049
00050 if (rodsServerHost == NULL) {
00051 rodsLog (LOG_NOTICE,
00052 "remoteFileFstat: Invalid rodsServerHost");
00053 return SYS_INVALID_SERVER_HOST;
00054 }
00055
00056 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00057 return status;
00058 }
00059
00060
00061 fileFstatInp->fileInx = convL3descInx (fileFstatInp->fileInx);
00062 status = rcFileFstat (rodsServerHost->conn, fileFstatInp, fileFstatOut);
00063
00064 if (status < 0) {
00065 rodsLog (LOG_NOTICE,
00066 "remoteFileFstat: rcFileFstat failed for %s",
00067 FileDesc[fileFstatInp->fileInx].fileName);
00068 }
00069
00070 return status;
00071 }
00072
00073 int
00074 _rsFileFstat (rsComm_t *rsComm, fileFstatInp_t *fileFstatInp,
00075 rodsStat_t **fileFstatOut)
00076 {
00077 int status;
00078 struct stat myFileStat;
00079
00080 status = fileFstat (FileDesc[fileFstatInp->fileInx].fileType, rsComm,
00081 FileDesc[fileFstatInp->fileInx].fd, &myFileStat);
00082
00083 if (status < 0) {
00084 rodsLog (LOG_NOTICE,
00085 "_rsFileFstat: fileFstat for %s, status = %d",
00086 FileDesc[fileFstatInp->fileInx].fileName, status);
00087 return (status);
00088 }
00089
00090 *fileFstatOut = (rodsStat_t*)malloc (sizeof (rodsStat_t));
00091
00092 status = statToRodsStat (*fileFstatOut, &myFileStat);
00093
00094 if (status < 0) {
00095 free (*fileFstatOut);
00096 *fileFstatOut = NULL;
00097 }
00098
00099 return (status);
00100 }