00001
00002
00003
00004
00005 #include "univMSSDriver.h"
00006
00007
00008
00009
00010
00011 int univMSSSyncToArch (rsComm_t *rsComm, fileDriverType_t cacheFileType,
00012 int mode, int flags, char *filename,
00013 char *cacheFilename, rodsLong_t dataSize, keyValPair_t *condInput) {
00014
00015 int lenDir, rc, status;
00016 execCmd_t execCmdInp;
00017 char *lastpart;
00018 char cmdArgv[HUGE_NAME_LEN] = "";
00019 char dirname[MAX_NAME_LEN] = "";
00020 execCmdOut_t *execCmdOut = NULL;
00021
00022 bzero (&execCmdInp, sizeof (execCmdInp));
00023
00024 lastpart = strrchr(filename, '/');
00025 lenDir = strlen(filename) - strlen(lastpart);
00026 strncpy(dirname, filename, lenDir);
00027
00028 status = univMSSFileMkdir (rsComm, dirname, mode);
00029 if ( status == 0 ) {
00030 rstrcpy(execCmdInp.cmd, UNIV_MSS_INTERF_SCRIPT, LONG_NAME_LEN);
00031 strcat(cmdArgv, "syncToArch");
00032 strcat(cmdArgv, " ");
00033 strcat(cmdArgv, cacheFilename);
00034 strcat(cmdArgv, " ");
00035 strcat(cmdArgv, filename);
00036 rstrcpy(execCmdInp.cmdArgv, cmdArgv, HUGE_NAME_LEN);
00037 rstrcpy(execCmdInp.execAddr, "localhost", LONG_NAME_LEN);
00038 status = _rsExecCmd(rsComm, &execCmdInp, &execCmdOut);
00039 if ( status == 0 ) {
00040 rc = univMSSFileChmod (rsComm, filename, mode);
00041 }
00042 else {
00043 status = UNIV_MSS_SYNCTOARCH_ERR - errno;
00044 rodsLog (LOG_ERROR, "univMSSSyncToArch: copy of %s to %s failed, status = %d",
00045 cacheFilename, filename, status);
00046 }
00047 }
00048 return (status);
00049 }
00050
00051
00052
00053
00054 int univMSSStageToCache (rsComm_t *rsComm, fileDriverType_t cacheFileType,
00055 int mode, int flags, char *filename,
00056 char *cacheFilename, rodsLong_t dataSize, keyValPair_t *condInput) {
00057
00058 int status;
00059 execCmd_t execCmdInp;
00060 char cmdArgv[HUGE_NAME_LEN] = "";
00061 execCmdOut_t *execCmdOut = NULL;
00062
00063 bzero (&execCmdInp, sizeof (execCmdInp));
00064 rstrcpy(execCmdInp.cmd, UNIV_MSS_INTERF_SCRIPT, LONG_NAME_LEN);
00065 strcat(cmdArgv, "stageToCache");
00066 strcat(cmdArgv, " ");
00067 strcat(cmdArgv, filename);
00068 strcat(cmdArgv, " ");
00069 strcat(cmdArgv, cacheFilename);
00070 rstrcpy(execCmdInp.cmdArgv, cmdArgv, HUGE_NAME_LEN);
00071 rstrcpy(execCmdInp.execAddr, "localhost", LONG_NAME_LEN);
00072 status = _rsExecCmd(rsComm, &execCmdInp, &execCmdOut);
00073
00074 if (status < 0) {
00075 status = UNIV_MSS_STAGETOCACHE_ERR - errno;
00076 rodsLog (LOG_ERROR, "univMSSStageToCache: staging from %s to %s failed, status = %d",
00077 filename, cacheFilename, status);
00078 }
00079
00080 return (status);
00081
00082 }
00083
00084
00085
00086 int univMSSFileUnlink (rsComm_t *rsComm, char *filename) {
00087
00088 int status;
00089 execCmd_t execCmdInp;
00090 char cmdArgv[HUGE_NAME_LEN] = "";
00091 execCmdOut_t *execCmdOut = NULL;
00092
00093 bzero (&execCmdInp, sizeof (execCmdInp));
00094 rstrcpy(execCmdInp.cmd, UNIV_MSS_INTERF_SCRIPT, LONG_NAME_LEN);
00095 strcat(cmdArgv, "rm");
00096 strcat(cmdArgv, " ");
00097 strcat(cmdArgv, filename);
00098 rstrcpy(execCmdInp.cmdArgv, cmdArgv, HUGE_NAME_LEN);
00099 rstrcpy(execCmdInp.execAddr, "localhost", LONG_NAME_LEN);
00100 status = _rsExecCmd(rsComm, &execCmdInp, &execCmdOut);
00101
00102 if (status < 0) {
00103 status = UNIV_MSS_UNLINK_ERR - errno;
00104 rodsLog (LOG_ERROR, "univMSSFileUnlink: unlink of %s error, status = %d",
00105 filename, status);
00106 }
00107
00108 return (status);
00109 }
00110
00111
00112
00113 int univMSSFileMkdir (rsComm_t *rsComm, char *dirname, int mode) {
00114
00115 int status;
00116 execCmd_t execCmdInp;
00117 char cmdArgv[HUGE_NAME_LEN] = "";
00118 execCmdOut_t *execCmdOut = NULL;
00119
00120 bzero (&execCmdInp, sizeof (execCmdInp));
00121 rstrcpy(execCmdInp.cmd, UNIV_MSS_INTERF_SCRIPT, LONG_NAME_LEN);
00122 strcat(cmdArgv, "mkdir");
00123 strcat(cmdArgv, " ");
00124 strcat(cmdArgv, dirname);
00125 rstrcpy(execCmdInp.cmdArgv, cmdArgv, HUGE_NAME_LEN);
00126 rstrcpy(execCmdInp.execAddr, "localhost", LONG_NAME_LEN);
00127 status = _rsExecCmd(rsComm, &execCmdInp, &execCmdOut);
00128
00129 if (status < 0) {
00130 status = UNIV_MSS_MKDIR_ERR - errno;
00131 rodsLog (LOG_ERROR, "univMSSFileMkdir: cannot create directory for %s error, status = %d",
00132 dirname, status);
00133 }
00134
00135 mode = getDefDirMode();
00136 status = univMSSFileChmod(rsComm, dirname, mode);
00137
00138 return (status);
00139 }
00140
00141
00142
00143 int univMSSFileChmod (rsComm_t *rsComm, char *name, int mode) {
00144
00145 int status;
00146 execCmd_t execCmdInp;
00147 char cmdArgv[HUGE_NAME_LEN] = "";
00148 char strmode[4];
00149 execCmdOut_t *execCmdOut = NULL;
00150
00151 if ( mode != getDefDirMode() ) {
00152 mode = getDefFileMode();
00153 }
00154 bzero (&execCmdInp, sizeof (execCmdInp));
00155 rstrcpy(execCmdInp.cmd, UNIV_MSS_INTERF_SCRIPT, LONG_NAME_LEN);
00156 strcat(cmdArgv, "chmod");
00157 strcat(cmdArgv, " ");
00158 strcat(cmdArgv, name);
00159 strcat(cmdArgv, " ");
00160 sprintf (strmode, "%o", mode);
00161 strcat(cmdArgv, strmode);
00162 rstrcpy(execCmdInp.cmdArgv, cmdArgv, HUGE_NAME_LEN);
00163 rstrcpy(execCmdInp.execAddr, "localhost", LONG_NAME_LEN);
00164 status = _rsExecCmd(rsComm, &execCmdInp, &execCmdOut);
00165
00166 if (status < 0) {
00167 status = UNIV_MSS_CHMOD_ERR - errno;
00168 rodsLog (LOG_ERROR, "univMSSFileChmod: cannot chmod for %s, status = %d",
00169 name, status);
00170 }
00171
00172 return (status);
00173 }
00174
00175
00176
00177 int univMSSFileStat (rsComm_t *rsComm, char *filename, struct stat *statbuf) {
00178
00179 int i, status;
00180 execCmd_t execCmdInp;
00181 char cmdArgv[HUGE_NAME_LEN] = "";
00182 char splchain1[13][MAX_NAME_LEN], splchain2[4][MAX_NAME_LEN], splchain3[3][MAX_NAME_LEN];
00183 char *outputStr;
00184 const char *delim1 = ":\n";
00185 const char *delim2 = "-";
00186 const char *delim3 = ".";
00187 execCmdOut_t *execCmdOut = NULL;
00188 struct tm mytm;
00189 time_t myTime;
00190
00191 bzero (&execCmdInp, sizeof (execCmdInp));
00192 rstrcpy(execCmdInp.cmd, UNIV_MSS_INTERF_SCRIPT, LONG_NAME_LEN);
00193 strcat(cmdArgv, "stat");
00194 strcat(cmdArgv, " ");
00195 strcat(cmdArgv, filename);
00196 rstrcpy(execCmdInp.cmdArgv, cmdArgv, HUGE_NAME_LEN);
00197 rstrcpy(execCmdInp.execAddr, "localhost", LONG_NAME_LEN);
00198 status = _rsExecCmd(rsComm, &execCmdInp, &execCmdOut);
00199
00200 if (status == 0 && NULL != execCmdOut ) {
00201 if ( execCmdOut->stdoutBuf.buf != NULL) {
00202 outputStr = (char*)execCmdOut->stdoutBuf.buf;
00203 memset(&splchain1, 0, sizeof(splchain1));
00204 strSplit(outputStr, delim1, splchain1);
00205 statbuf->st_dev = atoi(splchain1[0]);
00206 statbuf->st_ino = atoi(splchain1[1]);
00207 statbuf->st_mode = atoi(splchain1[2]);
00208 statbuf->st_nlink = atoi(splchain1[3]);
00209 statbuf->st_uid = atoi(splchain1[4]);
00210 statbuf->st_gid = atoi(splchain1[5]);
00211 statbuf->st_rdev = atoi(splchain1[6]);
00212 statbuf->st_size = atoll(splchain1[7]);
00213 statbuf->st_blksize = atoi(splchain1[8]);
00214 statbuf->st_blocks = atoi(splchain1[9]);
00215 for (i = 0; i < 3; i++) {
00216 memset(&splchain2, 0, sizeof(splchain2));
00217 memset(&splchain3, 0, sizeof(splchain3));
00218 strSplit(splchain1[10+i], delim2, splchain2);
00219 mytm.tm_year = atoi(splchain2[0]) - 1900;
00220 mytm.tm_mon = atoi(splchain2[1]) - 1;
00221 mytm.tm_mday = atoi(splchain2[2]);
00222 strSplit(splchain2[3], delim3, splchain3);
00223 mytm.tm_hour = atoi(splchain3[0]);
00224 mytm.tm_min = atoi(splchain3[1]);
00225 mytm.tm_sec = atoi(splchain3[2]);
00226 myTime = mktime(&mytm);
00227 switch (i) {
00228 case 0:
00229 statbuf->st_atime = myTime;
00230 break;
00231 case 1:
00232 statbuf->st_mtime = myTime;
00233 break;
00234 case 2:
00235 statbuf->st_ctime = myTime;
00236 break;
00237 }
00238 }
00239 }
00240 }
00241 else {
00242 status = UNIV_MSS_STAT_ERR - errno;
00243 rodsLog (LOG_ERROR, "univMSSFileStat: cannot have stat informations for %s, status = %d",
00244 filename, status);
00245 }
00246
00247 return (status);
00248
00249 }
00250
00251
00252
00253 int univMSSFileRename (rsComm_t *rsComm, char *oldFileName, char *newFileName) {
00254
00255 int status;
00256 execCmd_t execCmdInp;
00257 char cmdArgv[HUGE_NAME_LEN] = "";
00258 execCmdOut_t *execCmdOut = NULL;
00259
00260 bzero (&execCmdInp, sizeof (execCmdInp));
00261 rstrcpy(execCmdInp.cmd, UNIV_MSS_INTERF_SCRIPT, LONG_NAME_LEN);
00262 strcat(cmdArgv, "mv");
00263 strcat(cmdArgv, " ");
00264 strcat(cmdArgv, oldFileName);
00265 strcat(cmdArgv, " ");
00266 strcat(cmdArgv, newFileName);
00267 rstrcpy(execCmdInp.cmdArgv, cmdArgv, HUGE_NAME_LEN);
00268 rstrcpy(execCmdInp.execAddr, "localhost", LONG_NAME_LEN);
00269 status = _rsExecCmd(rsComm, &execCmdInp, &execCmdOut);
00270
00271 if (status < 0) {
00272 status = UNIV_MSS_RENAME_ERR - errno;
00273 rodsLog (LOG_ERROR, "univMSSFileRename: rename of %s to error, status = %d",
00274 oldFileName, newFileName, status);
00275 }
00276
00277 return (status);
00278 }