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