00001
00002
00003
00004
00005
00006 #ifndef TAR_EXEC_PATH
00007 #include <libtar.h>
00008
00009 #ifdef HAVE_LIBZ
00010 # include <zlib.h>
00011 #endif
00012
00013 #include <compat.h>
00014 #endif
00015 #ifndef windows_platform
00016 #include <sys/wait.h>
00017 #else
00018 #include "Unix2Nt.h"
00019 #endif
00020 #include "tarSubStructFileDriver.h"
00021 #include "rsGlobalExtern.h"
00022 #include "modColl.h"
00023 #include "apiHeaderAll.h"
00024 #include "objMetaOpr.h"
00025 #include "dataObjOpr.h"
00026 #include "collection.h"
00027 #include "specColl.h"
00028 #include "resource.h"
00029 #include "miscServerFunct.h"
00030 #include "physPath.h"
00031
00032 int
00033 rmTmpDirAll (char *myDir);
00034
00035 #ifndef TAR_EXEC_PATH
00036
00037 int
00038 writeDirToTarStruct (rsComm_t *rsComm, char *fileDir, int fileType,
00039 specColl_t *specColl, TAR *t);
00040
00041 tartype_t irodstype = { (openfunc_t) irodsTarOpen, (closefunc_t) irodsTarClose,
00042 (readfunc_t) irodsTarRead, (writefunc_t) irodsTarWrite
00043 };
00044 #endif
00045
00046 int
00047 tarSubStructFileCreate (rsComm_t *rsComm, subFile_t *subFile)
00048 {
00049 int structFileInx;
00050 specColl_t *specColl;
00051 int subInx;
00052 int rescTypeInx;
00053 int status;
00054 fileCreateInp_t fileCreateInp;
00055
00056 specColl = subFile->specColl;
00057 structFileInx = rsTarStructFileOpen (rsComm, specColl);
00058
00059 if (structFileInx < 0) {
00060 rodsLog (LOG_NOTICE,
00061 "tarSubStructFileCreate: rsTarStructFileOpen error for %s, stat=%d",
00062 specColl->objPath, structFileInx);
00063 return (structFileInx);
00064 }
00065
00066
00067 specColl = StructFileDesc[structFileInx].specColl;
00068
00069 subInx = allocTarSubFileDesc ();
00070
00071 if (subInx < 0) return subInx;
00072
00073 TarSubFileDesc[subInx].structFileInx = structFileInx;
00074
00075 memset (&fileCreateInp, 0, sizeof (fileCreateInp));
00076 status = getSubStructFilePhyPath (fileCreateInp.fileName, specColl,
00077 subFile->subFilePath);
00078 if (status < 0) return status;
00079
00080 rescTypeInx = StructFileDesc[structFileInx].rescInfo->rescTypeInx;
00081 fileCreateInp.fileType = UNIX_FILE_TYPE;
00082 rstrcpy (fileCreateInp.addr.hostAddr,
00083 StructFileDesc[structFileInx].rescInfo->rescLoc, NAME_LEN);
00084 fileCreateInp.mode = subFile->mode;
00085 fileCreateInp.flags = subFile->flags;
00086 fileCreateInp.otherFlags = NO_CHK_PERM_FLAG;
00087
00088 status = rsFileCreate (rsComm, &fileCreateInp);
00089
00090 if (status < 0) {
00091 rodsLog (LOG_ERROR,
00092 "tarSubStructFileCreate: rsFileCreate for %s error, status = %d",
00093 fileCreateInp.fileName, status);
00094 return status;
00095 } else {
00096 TarSubFileDesc[subInx].fd = status;
00097 StructFileDesc[structFileInx].openCnt++;
00098 return (subInx);
00099 }
00100 }
00101
00102 int
00103 tarSubStructFileOpen (rsComm_t *rsComm, subFile_t *subFile)
00104 {
00105 int structFileInx;
00106 specColl_t *specColl;
00107 int subInx;
00108 int rescTypeInx;
00109 int status;
00110 fileOpenInp_t fileOpenInp;
00111
00112 specColl = subFile->specColl;
00113 structFileInx = rsTarStructFileOpen (rsComm, specColl);
00114
00115 if (structFileInx < 0) {
00116 rodsLog (LOG_NOTICE,
00117 "tarSubStructFileOpen: rsTarStructFileOpen error for %s, status = %d",
00118 specColl->objPath, structFileInx);
00119 return (structFileInx);
00120 }
00121
00122
00123 specColl = StructFileDesc[structFileInx].specColl;
00124
00125 subInx = allocTarSubFileDesc ();
00126
00127 if (subInx < 0) return subInx;
00128
00129 TarSubFileDesc[subInx].structFileInx = structFileInx;
00130
00131 memset (&fileOpenInp, 0, sizeof (fileOpenInp));
00132 status = getSubStructFilePhyPath (fileOpenInp.fileName, specColl,
00133 subFile->subFilePath);
00134 if (status < 0) return status;
00135
00136 rescTypeInx = StructFileDesc[structFileInx].rescInfo->rescTypeInx;
00137 fileOpenInp.fileType = (fileDriverType_t)UNIX_FILE_TYPE;
00138 rstrcpy (fileOpenInp.addr.hostAddr,
00139 StructFileDesc[structFileInx].rescInfo->rescLoc, NAME_LEN);
00140 fileOpenInp.mode = subFile->mode;
00141 fileOpenInp.flags = subFile->flags;
00142
00143 status = rsFileOpen (rsComm, &fileOpenInp);
00144
00145 if (status < 0) {
00146 rodsLog (LOG_ERROR,
00147 "specCollOpen: rsFileOpen for %s error, status = %d",
00148 fileOpenInp.fileName, status);
00149 return status;
00150 } else {
00151 TarSubFileDesc[subInx].fd = status;
00152 StructFileDesc[structFileInx].openCnt++;
00153 return (subInx);
00154 }
00155 }
00156
00157 int
00158 tarSubStructFileRead (rsComm_t *rsComm, int subInx, void *buf, int len)
00159 {
00160 fileReadInp_t fileReadInp;
00161 int status;
00162 bytesBuf_t fileReadOutBBuf;
00163
00164 if (subInx < 1 || subInx >= NUM_TAR_SUB_FILE_DESC ||
00165 TarSubFileDesc[subInx].inuseFlag == 0) {
00166 rodsLog (LOG_ERROR,
00167 "tarSubStructFileRead: subInx %d out of range", subInx);
00168 return (SYS_STRUCT_FILE_DESC_ERR);
00169 }
00170
00171 memset (&fileReadInp, 0, sizeof (fileReadInp));
00172 memset (&fileReadOutBBuf, 0, sizeof (fileReadOutBBuf));
00173 fileReadInp.fileInx = TarSubFileDesc[subInx].fd;
00174 fileReadInp.len = len;
00175 fileReadOutBBuf.buf = buf;
00176 status = rsFileRead (rsComm, &fileReadInp, &fileReadOutBBuf);
00177
00178 return (status);
00179 }
00180
00181 int
00182 tarSubStructFileWrite (rsComm_t *rsComm, int subInx, void *buf, int len)
00183 {
00184 fileWriteInp_t fileWriteInp;
00185 int status;
00186 bytesBuf_t fileWriteOutBBuf;
00187
00188 if (subInx < 1 || subInx >= NUM_TAR_SUB_FILE_DESC ||
00189 TarSubFileDesc[subInx].inuseFlag == 0) {
00190 rodsLog (LOG_ERROR,
00191 "tarSubStructFileWrite: subInx %d out of range", subInx);
00192 return (SYS_STRUCT_FILE_DESC_ERR);
00193 }
00194
00195 memset (&fileWriteInp, 0, sizeof (fileWriteInp));
00196 memset (&fileWriteOutBBuf, 0, sizeof (fileWriteOutBBuf));
00197 fileWriteInp.fileInx = TarSubFileDesc[subInx].fd;
00198 fileWriteInp.len = fileWriteOutBBuf.len = len;
00199 fileWriteOutBBuf.buf = buf;
00200 status = rsFileWrite (rsComm, &fileWriteInp, &fileWriteOutBBuf);
00201
00202 if (status > 0) {
00203 specColl_t *specColl;
00204 int status1;
00205 int structFileInx = TarSubFileDesc[subInx].structFileInx;
00206
00207 specColl = StructFileDesc[structFileInx].specColl;
00208 if (specColl->cacheDirty == 0) {
00209 specColl->cacheDirty = 1;
00210 status1 = modCollInfo2 (rsComm, specColl, 0);
00211 if (status1 < 0) return status1;
00212 }
00213 }
00214 return (status);
00215 }
00216
00217 int
00218 tarSubStructFileClose (rsComm_t *rsComm, int subInx)
00219 {
00220 fileCloseInp_t fileCloseInp;
00221 int structFileInx;
00222 int status;
00223
00224 if (subInx < 1 || subInx >= NUM_TAR_SUB_FILE_DESC ||
00225 TarSubFileDesc[subInx].inuseFlag == 0) {
00226 rodsLog (LOG_ERROR,
00227 "tarSubStructFileClose: subInx %d out of range",
00228 subInx);
00229 return (SYS_STRUCT_FILE_DESC_ERR);
00230 }
00231
00232 fileCloseInp.fileInx = TarSubFileDesc[subInx].fd;
00233 status = rsFileClose (rsComm, &fileCloseInp);
00234
00235 structFileInx = TarSubFileDesc[subInx].structFileInx;
00236 StructFileDesc[structFileInx].openCnt++;
00237 freeTarSubFileDesc (subInx);
00238
00239 return (status);
00240 }
00241
00242 int
00243 tarSubStructFileUnlink (rsComm_t *rsComm, subFile_t *subFile)
00244 {
00245 int structFileInx;
00246 specColl_t *specColl;
00247 int rescTypeInx;
00248 int status;
00249 fileUnlinkInp_t fileUnlinkInp;
00250
00251 specColl = subFile->specColl;
00252 structFileInx = rsTarStructFileOpen (rsComm, specColl);
00253
00254 if (structFileInx < 0) {
00255 rodsLog (LOG_NOTICE,
00256 "tarSubStructFileCreate: rsTarStructFileOpen error for %s, stat=%d",
00257 specColl->objPath, structFileInx);
00258 return (structFileInx);
00259 }
00260
00261
00262 specColl = StructFileDesc[structFileInx].specColl;
00263
00264 memset (&fileUnlinkInp, 0, sizeof (fileUnlinkInp));
00265 status = getSubStructFilePhyPath (fileUnlinkInp.fileName, specColl,
00266 subFile->subFilePath);
00267 if (status < 0) return status;
00268
00269 rescTypeInx = StructFileDesc[structFileInx].rescInfo->rescTypeInx;
00270
00271 fileUnlinkInp.fileType = UNIX_FILE_TYPE;
00272 rstrcpy (fileUnlinkInp.addr.hostAddr,
00273 StructFileDesc[structFileInx].rescInfo->rescLoc, NAME_LEN);
00274
00275 status = rsFileUnlink (rsComm, &fileUnlinkInp);
00276 if (status >= 0) {
00277 specColl_t *specColl;
00278 int status1;
00279
00280 specColl = StructFileDesc[structFileInx].specColl;
00281 if (specColl->cacheDirty == 0) {
00282 specColl->cacheDirty = 1;
00283 status1 = modCollInfo2 (rsComm, specColl, 0);
00284 if (status1 < 0) return status1;
00285 }
00286 }
00287
00288 return (0);
00289 }
00290
00291 int
00292 tarSubStructFileStat (rsComm_t *rsComm, subFile_t *subFile,
00293 rodsStat_t **subStructFileStatOut)
00294 {
00295 specColl_t *specColl;
00296 int structFileInx;
00297 int rescTypeInx;
00298 int status;
00299 fileStatInp_t fileStatInp;
00300
00301 specColl = subFile->specColl;
00302 structFileInx = rsTarStructFileOpen (rsComm, specColl);
00303
00304 if (structFileInx < 0) {
00305 rodsLog (LOG_NOTICE,
00306 "tarSubStructFileStat: rsTarStructFileOpen error for %s, status = %d",
00307 specColl->objPath, structFileInx);
00308 return (structFileInx);
00309 }
00310
00311
00312 specColl = StructFileDesc[structFileInx].specColl;
00313
00314 memset (&fileStatInp, 0, sizeof (fileStatInp));
00315
00316 status = getSubStructFilePhyPath (fileStatInp.fileName, specColl,
00317 subFile->subFilePath);
00318 if (status < 0) return status;
00319
00320 rescTypeInx = StructFileDesc[structFileInx].rescInfo->rescTypeInx;
00321 fileStatInp.fileType = UNIX_FILE_TYPE;
00322 rstrcpy (fileStatInp.addr.hostAddr,
00323 StructFileDesc[structFileInx].rescInfo->rescLoc, NAME_LEN);
00324
00325 status = rsFileStat (rsComm, &fileStatInp, subStructFileStatOut);
00326
00327 return (status);
00328 }
00329
00330 int
00331 tarSubStructFileFstat (rsComm_t *rsComm, int subInx,
00332 rodsStat_t **subStructFileStatOut)
00333 {
00334 fileFstatInp_t fileFstatInp;
00335 int status;
00336
00337 if (subInx < 1 || subInx >= NUM_TAR_SUB_FILE_DESC ||
00338 TarSubFileDesc[subInx].inuseFlag == 0) {
00339 rodsLog (LOG_ERROR,
00340 "tarSubStructFileFstat: subInx %d out of range", subInx);
00341 return (SYS_STRUCT_FILE_DESC_ERR);
00342 }
00343
00344 memset (&fileFstatInp, 0, sizeof (fileFstatInp));
00345 fileFstatInp.fileInx = TarSubFileDesc[subInx].fd;
00346 status = rsFileFstat (rsComm, &fileFstatInp, subStructFileStatOut);
00347
00348 return (status);
00349 }
00350
00351 rodsLong_t
00352 tarSubStructFileLseek (rsComm_t *rsComm, int subInx, rodsLong_t offset,
00353 int whence)
00354 {
00355 fileLseekInp_t fileLseekInp;
00356 int status;
00357 fileLseekOut_t *fileLseekOut = NULL;
00358
00359 if (subInx < 1 || subInx >= NUM_TAR_SUB_FILE_DESC ||
00360 TarSubFileDesc[subInx].inuseFlag == 0) {
00361 rodsLog (LOG_ERROR,
00362 "tarSubStructFileLseek: subInx %d out of range", subInx);
00363 return (SYS_STRUCT_FILE_DESC_ERR);
00364 }
00365
00366 memset (&fileLseekInp, 0, sizeof (fileLseekInp));
00367 fileLseekInp.fileInx = TarSubFileDesc[subInx].fd;
00368 fileLseekInp.offset = offset;
00369 fileLseekInp.whence = whence;
00370 status = rsFileLseek (rsComm, &fileLseekInp, &fileLseekOut);
00371
00372 if (status < 0 || NULL == fileLseekOut ) {
00373 return ((rodsLong_t) status);
00374 } else {
00375 rodsLong_t offset = fileLseekOut->offset;
00376 free (fileLseekOut);
00377 return (offset);
00378 }
00379 }
00380
00381 int
00382 tarSubStructFileRename (rsComm_t *rsComm, subFile_t *subFile,
00383 char *newFileName)
00384 {
00385 int structFileInx;
00386 specColl_t *specColl;
00387 int rescTypeInx;
00388 int status;
00389 fileRenameInp_t fileRenameInp;
00390
00391 specColl = subFile->specColl;
00392 structFileInx = rsTarStructFileOpen (rsComm, specColl);
00393
00394 if (structFileInx < 0) {
00395 rodsLog (LOG_NOTICE,
00396 "tarSubStructFileRename: rsTarStructFileOpen error for %s, stat=%d",
00397 specColl->objPath, structFileInx);
00398 return (structFileInx);
00399 }
00400
00401
00402 specColl = StructFileDesc[structFileInx].specColl;
00403
00404 rescTypeInx = StructFileDesc[structFileInx].rescInfo->rescTypeInx;
00405
00406 memset (&fileRenameInp, 0, sizeof (fileRenameInp));
00407 fileRenameInp.fileType = UNIX_FILE_TYPE;
00408 status = getSubStructFilePhyPath (fileRenameInp.oldFileName, specColl,
00409 subFile->subFilePath);
00410 if (status < 0) return status;
00411 status = getSubStructFilePhyPath (fileRenameInp.newFileName, specColl,
00412 newFileName);
00413 if (status < 0) return status;
00414 rstrcpy (fileRenameInp.addr.hostAddr,
00415 StructFileDesc[structFileInx].rescInfo->rescLoc, NAME_LEN);
00416 status = rsFileRename (rsComm, &fileRenameInp);
00417
00418 if (status >= 0) {
00419 int status1;
00420
00421 specColl = StructFileDesc[structFileInx].specColl;
00422
00423 if (specColl->cacheDirty == 0) {
00424 specColl->cacheDirty = 1;
00425 status1 = modCollInfo2 (rsComm, specColl, 0);
00426 if (status1 < 0) return status1;
00427 }
00428 }
00429
00430 return status;
00431 }
00432
00433 int
00434 tarSubStructFileMkdir (rsComm_t *rsComm, subFile_t *subFile)
00435 {
00436 specColl_t *specColl;
00437 int structFileInx;
00438 int rescTypeInx;
00439 int status;
00440 fileMkdirInp_t fileMkdirInp;
00441
00442 specColl = subFile->specColl;
00443 structFileInx = rsTarStructFileOpen (rsComm, specColl);
00444
00445 if (structFileInx < 0) {
00446 rodsLog (LOG_NOTICE,
00447 "tarSubStructFileMkdir: rsTarStructFileOpen error for %s,stat=%d",
00448 specColl->objPath, structFileInx);
00449 return (structFileInx);
00450 }
00451
00452
00453 specColl = StructFileDesc[structFileInx].specColl;
00454
00455 rescTypeInx = StructFileDesc[structFileInx].rescInfo->rescTypeInx;
00456 fileMkdirInp.fileType = UNIX_FILE_TYPE;
00457 status = getSubStructFilePhyPath (fileMkdirInp.dirName, specColl,
00458 subFile->subFilePath);
00459 if (status < 0) return status;
00460
00461 rstrcpy (fileMkdirInp.addr.hostAddr,
00462 StructFileDesc[structFileInx].rescInfo->rescLoc, NAME_LEN);
00463 fileMkdirInp.mode = subFile->mode;
00464 status = rsFileMkdir (rsComm, &fileMkdirInp);
00465
00466 if (status >= 0) {
00467 int status1;
00468
00469 specColl = StructFileDesc[structFileInx].specColl;
00470
00471 if (specColl->cacheDirty == 0) {
00472 specColl->cacheDirty = 1;
00473 status1 = modCollInfo2 (rsComm, specColl, 0);
00474 if (status1 < 0) return status1;
00475 }
00476 }
00477 return status;
00478 }
00479
00480 int
00481 tarSubStructFileRmdir (rsComm_t *rsComm, subFile_t *subFile)
00482 {
00483 specColl_t *specColl;
00484 int structFileInx;
00485 int rescTypeInx;
00486 int status;
00487 fileRmdirInp_t fileRmdirInp;
00488
00489 specColl = subFile->specColl;
00490 structFileInx = rsTarStructFileOpen (rsComm, specColl);
00491
00492 if (structFileInx < 0) {
00493 rodsLog (LOG_NOTICE,
00494 "tarSubStructFileRmdir: rsTarStructFileOpen error for %s,stat=%d",
00495 specColl->objPath, structFileInx);
00496 return (structFileInx);
00497 }
00498
00499
00500 specColl = StructFileDesc[structFileInx].specColl;
00501
00502 rescTypeInx = StructFileDesc[structFileInx].rescInfo->rescTypeInx;
00503 fileRmdirInp.fileType = UNIX_FILE_TYPE;
00504 status = getSubStructFilePhyPath (fileRmdirInp.dirName, specColl,
00505 subFile->subFilePath);
00506 if (status < 0) return status;
00507
00508 rstrcpy (fileRmdirInp.addr.hostAddr,
00509 StructFileDesc[structFileInx].rescInfo->rescLoc, NAME_LEN);
00510 status = rsFileRmdir (rsComm, &fileRmdirInp);
00511
00512 if (status >= 0) {
00513 int status1;
00514
00515 specColl = StructFileDesc[structFileInx].specColl;
00516
00517 if (specColl->cacheDirty == 0) {
00518 specColl->cacheDirty = 1;
00519 status1 = modCollInfo2 (rsComm, specColl, 0);
00520 if (status1 < 0) return status1;
00521 }
00522 }
00523 return status;
00524 }
00525
00526 int
00527 tarSubStructFileOpendir (rsComm_t *rsComm, subFile_t *subFile)
00528 {
00529 specColl_t *specColl;
00530 int structFileInx;
00531 int subInx;
00532 int rescTypeInx;
00533 int status;
00534 fileOpendirInp_t fileOpendirInp;
00535
00536 specColl = subFile->specColl;
00537 structFileInx = rsTarStructFileOpen (rsComm, specColl);
00538
00539 if (structFileInx < 0) {
00540 rodsLog (LOG_NOTICE,
00541 "tarSubStructFileOpendir: rsTarStructFileOpen error for %s,stat=%d",
00542 specColl->objPath, structFileInx);
00543 return (structFileInx);
00544 }
00545
00546
00547 specColl = StructFileDesc[structFileInx].specColl;
00548
00549 subInx = allocTarSubFileDesc ();
00550
00551 if (subInx < 0) return subInx;
00552
00553 TarSubFileDesc[subInx].structFileInx = structFileInx;
00554
00555 memset (&fileOpendirInp, 0, sizeof (fileOpendirInp));
00556 status = getSubStructFilePhyPath (fileOpendirInp.dirName, specColl,
00557 subFile->subFilePath);
00558 if (status < 0) return status;
00559
00560 rescTypeInx = StructFileDesc[structFileInx].rescInfo->rescTypeInx;
00561 fileOpendirInp.fileType = UNIX_FILE_TYPE;
00562 rstrcpy (fileOpendirInp.addr.hostAddr,
00563 StructFileDesc[structFileInx].rescInfo->rescLoc, NAME_LEN);
00564
00565 status = rsFileOpendir (rsComm, &fileOpendirInp);
00566 if (status < 0) {
00567 rodsLog (LOG_ERROR,
00568 "specCollOpendir: rsFileOpendir for %s error, status = %d",
00569 fileOpendirInp.dirName, status);
00570 return status;
00571 } else {
00572 TarSubFileDesc[subInx].fd = status;
00573 StructFileDesc[structFileInx].openCnt++;
00574 return (subInx);
00575 }
00576 }
00577
00578 int
00579 tarSubStructFileReaddir (rsComm_t *rsComm, int subInx,
00580 rodsDirent_t **rodsDirent)
00581 {
00582 fileReaddirInp_t fileReaddirInp;
00583 int status;
00584
00585 if (subInx < 1 || subInx >= NUM_TAR_SUB_FILE_DESC ||
00586 TarSubFileDesc[subInx].inuseFlag == 0) {
00587 rodsLog (LOG_ERROR,
00588 "tarSubStructFileReaddir: subInx %d out of range",
00589 subInx);
00590 return (SYS_STRUCT_FILE_DESC_ERR);
00591 }
00592
00593 fileReaddirInp.fileInx = TarSubFileDesc[subInx].fd;
00594 status = rsFileReaddir (rsComm, &fileReaddirInp, rodsDirent);
00595
00596 return (status);
00597 }
00598
00599 int
00600 tarSubStructFileClosedir (rsComm_t *rsComm, int subInx)
00601 {
00602 fileClosedirInp_t fileClosedirInp;
00603 int structFileInx;
00604 int status;
00605
00606 if (subInx < 1 || subInx >= NUM_TAR_SUB_FILE_DESC ||
00607 TarSubFileDesc[subInx].inuseFlag == 0) {
00608 rodsLog (LOG_ERROR,
00609 "tarSubStructFileClosedir: subInx %d out of range",
00610 subInx);
00611 return (SYS_STRUCT_FILE_DESC_ERR);
00612 }
00613
00614 fileClosedirInp.fileInx = TarSubFileDesc[subInx].fd;
00615 status = rsFileClosedir (rsComm, &fileClosedirInp);
00616
00617 structFileInx = TarSubFileDesc[subInx].structFileInx;
00618 StructFileDesc[structFileInx].openCnt++;
00619 freeTarSubFileDesc (subInx);
00620
00621 return (status);
00622 }
00623
00624 int
00625 tarSubStructFileTruncate (rsComm_t *rsComm, subFile_t *subFile)
00626 {
00627 specColl_t *specColl;
00628 int structFileInx;
00629 int rescTypeInx;
00630 int status;
00631 fileOpenInp_t fileTruncateInp;
00632
00633 specColl = subFile->specColl;
00634 structFileInx = rsTarStructFileOpen (rsComm, specColl);
00635
00636 if (structFileInx < 0) {
00637 rodsLog (LOG_NOTICE,
00638 "tarSubStructFileTruncate: rsTarStructFileOpen error for %s,stat=%d",
00639 specColl->objPath, structFileInx);
00640 return (structFileInx);
00641 }
00642
00643
00644 specColl = StructFileDesc[structFileInx].specColl;
00645
00646 rescTypeInx = StructFileDesc[structFileInx].rescInfo->rescTypeInx;
00647 fileTruncateInp.fileType = UNIX_FILE_TYPE;
00648 status = getSubStructFilePhyPath (fileTruncateInp.fileName, specColl,
00649 subFile->subFilePath);
00650 if (status < 0) return status;
00651
00652 rstrcpy (fileTruncateInp.addr.hostAddr,
00653 StructFileDesc[structFileInx].rescInfo->rescLoc, NAME_LEN);
00654 fileTruncateInp.dataSize = subFile->offset;
00655 status = rsFileTruncate (rsComm, &fileTruncateInp);
00656
00657 if (status >= 0) {
00658 int status1;
00659
00660 specColl = StructFileDesc[structFileInx].specColl;
00661
00662 if (specColl->cacheDirty == 0) {
00663 specColl->cacheDirty = 1;
00664 status1 = modCollInfo2 (rsComm, specColl, 0);
00665 if (status1 < 0) return status1;
00666 }
00667 }
00668 return status;
00669 }
00670
00671
00672 int
00673 rmTmpDirAll (char *myDir)
00674 {
00675 char childDir[MAX_NAME_LEN];
00676 DIR *dp;
00677 struct dirent *dent;
00678
00679 dp = opendir(myDir);
00680 if (dp == NULL) return -1;
00681
00682 while ((dent = readdir(dp)) != NULL) {
00683 if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0)
00684 continue;
00685
00686 snprintf(childDir, MAX_NAME_LEN, "%s/%s", myDir, dent->d_name);
00687
00688 rmTmpDirAll (childDir);
00689 }
00690 rmdir (myDir);
00691 closedir( dp );
00692 return (0);
00693 }
00694
00695
00696
00697
00698
00699
00700 int
00701 tarStructFileSync (rsComm_t *rsComm, structFileOprInp_t *structFileOprInp)
00702 {
00703 int structFileInx;
00704 specColl_t *specColl;
00705 rescInfo_t *rescInfo;
00706 fileRmdirInp_t fileRmdirInp;
00707 char *dataType;
00708 int status = 0;
00709
00710 structFileInx = rsTarStructFileOpen (rsComm, structFileOprInp->specColl);
00711
00712 if (structFileInx < 0) {
00713 rodsLog (LOG_NOTICE,
00714 "tarPhyStructFileSync: rsTarStructFileOpen error for %s, stat=%d",
00715 structFileOprInp->specColl->collection, structFileInx);
00716 return (structFileInx);
00717 }
00718
00719 if (StructFileDesc[structFileInx].openCnt > 0) {
00720 return (SYS_STRUCT_FILE_BUSY_ERR);
00721 }
00722
00723
00724 rescInfo = StructFileDesc[structFileInx].rescInfo;
00725 specColl = StructFileDesc[structFileInx].specColl;
00726 if ((structFileOprInp->oprType & DELETE_STRUCT_FILE) != 0) {
00727
00728 freeStructFileDesc (structFileInx);
00729 return (status);
00730 }
00731 if ((dataType = getValByKey (&structFileOprInp->condInput, DATA_TYPE_KW))
00732 != NULL) {
00733 rstrcpy (StructFileDesc[structFileInx].dataType, dataType, NAME_LEN);
00734 }
00735
00736 if (strlen (specColl->cacheDir) > 0) {
00737 if (specColl->cacheDirty > 0) {
00738
00739 status = syncCacheDirToTarfile (structFileInx,
00740 structFileOprInp->oprType);
00741 if (status < 0) {
00742 rodsLog (LOG_ERROR,
00743 "tarPhyStructFileSync:syncCacheDirToTarfile %s error,stat=%d",
00744 specColl->cacheDir, status);
00745 freeStructFileDesc (structFileInx);
00746 return (status);
00747 }
00748 specColl->cacheDirty = 0;
00749 if ((structFileOprInp->oprType & NO_REG_COLL_INFO) == 0) {
00750 status = modCollInfo2 (rsComm, specColl, 0);
00751 if (status < 0) {
00752 freeStructFileDesc (structFileInx);
00753 return status;
00754 }
00755 }
00756 }
00757
00758 if ((structFileOprInp->oprType & PURGE_STRUCT_FILE_CACHE) != 0) {
00759
00760 status = modCollInfo2 (rsComm, specColl, 1);
00761 if (status < 0) {
00762 freeStructFileDesc (structFileInx);
00763 return status;
00764 }
00765
00766 memset (&fileRmdirInp, 0, sizeof (fileRmdirInp));
00767 fileRmdirInp.fileType = UNIX_FILE_TYPE;
00768 rstrcpy (fileRmdirInp.dirName, specColl->cacheDir,
00769 MAX_NAME_LEN);
00770 rstrcpy (fileRmdirInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN);
00771 fileRmdirInp.flags = RMDIR_RECUR;
00772 status = rsFileRmdir (rsComm, &fileRmdirInp);
00773 if (status < 0) {
00774 rodsLog (LOG_ERROR,
00775 "tarPhyStructFileSync: XXXXX Rmdir error for %s, status = %d",
00776 specColl->cacheDir, status);
00777 freeStructFileDesc (structFileInx);
00778 return (status);
00779 }
00780 }
00781 }
00782 freeStructFileDesc (structFileInx);
00783 return (status);
00784 }
00785
00786
00787
00788
00789
00790 int
00791 tarStructFileExtract (rsComm_t *rsComm, structFileOprInp_t *structFileOprInp)
00792 {
00793 int structFileInx;
00794 int status;
00795 specColl_t *specColl;
00796 char* dataType;
00797
00798 if (rsComm == NULL || structFileOprInp == NULL ||
00799 structFileOprInp->specColl == NULL) {
00800 rodsLog (LOG_ERROR,
00801 "tarStructFileExtract: NULL input");
00802 return (SYS_INTERNAL_NULL_INPUT_ERR);
00803 }
00804
00805 specColl = structFileOprInp->specColl;
00806
00807 if ((structFileInx = allocStructFileDesc ()) < 0) {
00808 return (structFileInx);
00809 }
00810
00811 StructFileDesc[structFileInx].specColl = specColl;
00812 StructFileDesc[structFileInx].rsComm = rsComm;
00813
00814 status = resolveResc (StructFileDesc[structFileInx].specColl->resource,
00815 &StructFileDesc[structFileInx].rescInfo);
00816
00817 if (status < 0) {
00818 rodsLog (LOG_ERROR,
00819 "tarStructFileExtract: resolveResc error for %s, status = %d",
00820 specColl->resource, status);
00821 freeStructFileDesc (structFileInx);
00822 return (status);
00823 }
00824 if ((dataType = getValByKey (&structFileOprInp->condInput, DATA_TYPE_KW))
00825 != NULL) {
00826 rstrcpy (StructFileDesc[structFileInx].dataType, dataType, NAME_LEN);
00827 }
00828 status = extractTarFile (structFileInx);
00829 if (status < 0) {
00830 rodsLog (LOG_ERROR,
00831 "tarStructFileExtract:extract error for %s in cacheDir %s,errno=%d",
00832 specColl->objPath, specColl->cacheDir, errno);
00833
00834 status = SYS_TAR_STRUCT_FILE_EXTRACT_ERR - errno;
00835 }
00836 freeStructFileDesc (structFileInx);
00837 return (status);
00838 }
00839
00840 int
00841 rsTarStructFileOpen (rsComm_t *rsComm, specColl_t *specColl)
00842 {
00843 int structFileInx;
00844 int status;
00845 specCollCache_t *specCollCache;
00846
00847 if (specColl == NULL) {
00848 rodsLog (LOG_NOTICE,
00849 "rsTarStructFileOpen: NULL specColl input");
00850 return (SYS_INTERNAL_NULL_INPUT_ERR);
00851 }
00852
00853
00854
00855 structFileInx = matchStructFileDesc (specColl);
00856
00857 if (structFileInx > 0) return structFileInx;
00858
00859 if ((structFileInx = allocStructFileDesc ()) < 0) {
00860 return (structFileInx);
00861 }
00862
00863
00864 if ((status = getSpecCollCache (rsComm, specColl->collection, 0,
00865 &specCollCache)) >= 0) {
00866 StructFileDesc[structFileInx].specColl = &specCollCache->specColl;
00867
00868 if (strlen (specColl->phyPath) > 0) {
00869 rstrcpy (specCollCache->specColl.phyPath, specColl->phyPath, MAX_NAME_LEN);
00870 }
00871 if (strlen (specCollCache->specColl.resource) == 0) {
00872 rstrcpy (specCollCache->specColl.resource, specColl->resource,
00873 NAME_LEN);
00874 }
00875 } else {
00876 StructFileDesc[structFileInx].specColl = specColl;
00877 }
00878
00879 StructFileDesc[structFileInx].rsComm = rsComm;
00880
00881 status = resolveResc (StructFileDesc[structFileInx].specColl->resource,
00882 &StructFileDesc[structFileInx].rescInfo);
00883
00884 if (status < 0) {
00885 rodsLog (LOG_NOTICE,
00886 "rsTarStructFileOpen: resolveResc error for %s, status = %d",
00887 specColl->resource, status);
00888 freeStructFileDesc (structFileInx);
00889 return (status);
00890 }
00891
00892
00893
00894 status = stageTarStructFile (structFileInx);
00895
00896 if (status < 0) {
00897 freeStructFileDesc (structFileInx);
00898 return status;
00899 }
00900
00901 return (structFileInx);
00902 }
00903
00904 int
00905 matchStructFileDesc (specColl_t *specColl)
00906 {
00907 int i;
00908
00909 for (i = 1; i < NUM_STRUCT_FILE_DESC; i++) {
00910 if (StructFileDesc[i].inuseFlag == FD_INUSE &&
00911 StructFileDesc[i].specColl != NULL &&
00912 strcmp (StructFileDesc[i].specColl->collection, specColl->collection) == 0 &&
00913 strcmp (StructFileDesc[i].specColl->objPath, specColl->objPath)
00914 == 0) {
00915 return (i);
00916 };
00917 }
00918
00919 return (SYS_OUT_OF_FILE_DESC);
00920
00921 }
00922
00923 int
00924 stageTarStructFile (int structFileInx)
00925 {
00926 int status;
00927 specColl_t *specColl;
00928 rsComm_t *rsComm;
00929
00930 rsComm = StructFileDesc[structFileInx].rsComm;
00931 specColl = StructFileDesc[structFileInx].specColl;
00932 if (specColl == NULL) {
00933 rodsLog (LOG_NOTICE,
00934 "stageTarStructFile: NULL specColl input");
00935 return (SYS_INTERNAL_NULL_INPUT_ERR);
00936 }
00937
00938 if (strlen (specColl->cacheDir) == 0) {
00939
00940 status = mkTarCacheDir (structFileInx);
00941 if (status < 0) return status;
00942
00943 status = extractTarFile (structFileInx);
00944 if (status < 0) {
00945 rodsLog (LOG_NOTICE,
00946 "stageTarStructFile:extract error for %s in cacheDir %s,errno=%d",
00947 specColl->objPath, specColl->cacheDir, errno);
00948
00949 return SYS_TAR_STRUCT_FILE_EXTRACT_ERR - errno;
00950 }
00951
00952 status = modCollInfo2 (rsComm, specColl, 0);
00953 if (status < 0) return status;
00954 }
00955 return (0);
00956 }
00957
00958 int
00959 mkTarCacheDir (int structFileInx)
00960 {
00961 int i = 0;
00962 int status;
00963 fileMkdirInp_t fileMkdirInp;
00964 int rescTypeInx;
00965 rescInfo_t *rescInfo;
00966 rsComm_t *rsComm = StructFileDesc[structFileInx].rsComm;
00967 specColl_t *specColl = StructFileDesc[structFileInx].specColl;
00968
00969 if (specColl == NULL) {
00970 rodsLog (LOG_NOTICE, "mkTarCacheDir: NULL specColl input");
00971 return (SYS_INTERNAL_NULL_INPUT_ERR);
00972 }
00973
00974 rescInfo = StructFileDesc[structFileInx].rescInfo;
00975
00976 memset (&fileMkdirInp, 0, sizeof (fileMkdirInp));
00977 rescTypeInx = rescInfo->rescTypeInx;
00978 fileMkdirInp.fileType = UNIX_FILE_TYPE;
00979 fileMkdirInp.mode = DEFAULT_DIR_MODE;
00980 rstrcpy (fileMkdirInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN);
00981
00982 while (1) {
00983 snprintf (fileMkdirInp.dirName, MAX_NAME_LEN, "%s.%s%d",
00984 specColl->phyPath, CACHE_DIR_STR, i);
00985 status = rsFileMkdir (rsComm, &fileMkdirInp);
00986 if (status >= 0) {
00987 break;
00988 } else {
00989 if (getErrno (status) == EEXIST) {
00990 i++;
00991 continue;
00992 } else {
00993 return (status);
00994 }
00995 }
00996 }
00997 rstrcpy (specColl->cacheDir, fileMkdirInp.dirName, MAX_NAME_LEN);
00998
00999 return (0);
01000 }
01001
01002
01003
01004
01005 int
01006 irodsTarOpen (char *pathname, int oflags, int mode)
01007 {
01008 int structFileInx;
01009 int myMode;
01010 int status;
01011 fileOpenInp_t fileOpenInp;
01012 rescInfo_t *rescInfo;
01013 specColl_t *specColl = NULL;
01014 int rescTypeInx;
01015 int l3descInx;
01016
01017
01018 decodeIrodsTarfd (mode, &structFileInx, &myMode);
01019 status = verifyStructFileDesc (structFileInx, pathname, &specColl);
01020 if (status < 0 || NULL == specColl ) return -1;
01021
01022 rescInfo = StructFileDesc[structFileInx].rescInfo;
01023 rescTypeInx = rescInfo->rescTypeInx;
01024
01025 memset (&fileOpenInp, 0, sizeof (fileOpenInp));
01026 fileOpenInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType;
01027 rstrcpy (fileOpenInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN);
01028 rstrcpy (fileOpenInp.fileName, specColl->phyPath, MAX_NAME_LEN);
01029 fileOpenInp.mode = myMode;
01030 fileOpenInp.flags = oflags;
01031 l3descInx = rsFileOpen (StructFileDesc[structFileInx].rsComm,
01032 &fileOpenInp);
01033
01034 if (l3descInx < 0) {
01035 rodsLog (LOG_NOTICE,
01036 "irodsTarOpen: rsFileOpen of %s in Resc %s error, status = %d",
01037 fileOpenInp.fileName, rescInfo->rescName, l3descInx);
01038 return (-1);
01039 }
01040 return (encodeIrodsTarfd (structFileInx, l3descInx));
01041 }
01042
01043 int
01044 encodeIrodsTarfd (int upperInt, int lowerInt)
01045 {
01046
01047
01048 if (upperInt > 60) {
01049 rodsLog (LOG_NOTICE,
01050 "encodeIrodsTarfd: upperInt %d larger than 60", lowerInt);
01051 return (SYS_STRUCT_FILE_DESC_ERR);
01052 }
01053
01054 if ((lowerInt & 0xfc000000) != 0) {
01055 rodsLog (LOG_NOTICE,
01056 "encodeIrodsTarfd: lowerInt %d too large", lowerInt);
01057 return (SYS_STRUCT_FILE_DESC_ERR);
01058 }
01059
01060 return (lowerInt | (upperInt << 26));
01061
01062 }
01063
01064 int
01065 decodeIrodsTarfd (int inpInt, int *upperInt, int *lowerInt)
01066 {
01067 *lowerInt = inpInt & 0x03ffffff;
01068 *upperInt = (inpInt & 0x7c000000) >> 26;
01069
01070 return (0);
01071 }
01072
01073 int
01074 irodsTarClose (int fd)
01075 {
01076 fileCloseInp_t fileCloseInp;
01077 int structFileInx, l3descInx;
01078 int status;
01079
01080 decodeIrodsTarfd (fd, &structFileInx, &l3descInx);
01081 memset (&fileCloseInp, 0, sizeof (fileCloseInp));
01082 fileCloseInp.fileInx = l3descInx;
01083 status = rsFileClose (StructFileDesc[structFileInx].rsComm,
01084 &fileCloseInp);
01085
01086 return (status);
01087 }
01088
01089 int
01090 irodsTarRead (int fd, char *buf, int len)
01091 {
01092 fileReadInp_t fileReadInp;
01093 int structFileInx, l3descInx;
01094 int status;
01095 bytesBuf_t readOutBBuf;
01096
01097 decodeIrodsTarfd (fd, &structFileInx, &l3descInx);
01098 memset (&fileReadInp, 0, sizeof (fileReadInp));
01099 fileReadInp.fileInx = l3descInx;
01100 fileReadInp.len = len;
01101 memset (&readOutBBuf, 0, sizeof (readOutBBuf));
01102 readOutBBuf.buf = buf;
01103 status = rsFileRead (StructFileDesc[structFileInx].rsComm,
01104 &fileReadInp, &readOutBBuf);
01105
01106 return (status);
01107
01108 }
01109
01110 int
01111 irodsTarWrite (int fd, char *buf, int len)
01112 {
01113 fileWriteInp_t fileWriteInp;
01114 int structFileInx, l3descInx;
01115 int status;
01116 bytesBuf_t writeInpBBuf;
01117
01118 decodeIrodsTarfd (fd, &structFileInx, &l3descInx);
01119 memset (&fileWriteInp, 0, sizeof (fileWriteInp));
01120 fileWriteInp.fileInx = l3descInx;
01121 fileWriteInp.len = len;
01122 memset (&writeInpBBuf, 0, sizeof (writeInpBBuf));
01123 writeInpBBuf.buf = buf;
01124 status = rsFileWrite (StructFileDesc[structFileInx].rsComm,
01125 &fileWriteInp, &writeInpBBuf);
01126
01127 return (status);
01128 }
01129
01130 int
01131 verifyStructFileDesc (int structFileInx, char *tarPathname,
01132 specColl_t **specColl)
01133 {
01134 if (StructFileDesc[structFileInx].inuseFlag <= 0) {
01135 rodsLog (LOG_NOTICE,
01136 "verifyStructFileDesc: structFileInx %d not in use", structFileInx);
01137 return (SYS_STRUCT_FILE_DESC_ERR);
01138 }
01139 if (StructFileDesc[structFileInx].specColl == NULL) {
01140 rodsLog (LOG_NOTICE,
01141 "verifyStructFileDesc: NULL specColl for structFileInx %d",
01142 structFileInx);
01143 return (SYS_STRUCT_FILE_DESC_ERR);
01144 }
01145 if (strcmp (StructFileDesc[structFileInx].specColl->phyPath, tarPathname)
01146 != 0) {
01147 rodsLog (LOG_NOTICE,
01148 "verifyStructFileDesc: phyPath %s in Inx %d does not match %s",
01149 StructFileDesc[structFileInx].specColl->phyPath, structFileInx,
01150 tarPathname);
01151 return (SYS_STRUCT_FILE_DESC_ERR);
01152 }
01153 if (specColl != NULL) {
01154 *specColl = StructFileDesc[structFileInx].specColl;
01155 }
01156
01157 return 0;
01158 }
01159
01160 int
01161 extractTarFile (int structFileInx)
01162 {
01163 int status;
01164 if( strcmp( StructFileDesc[structFileInx].dataType, ZIP_DT_STR ) == NULL) {
01165 #ifdef UNZIP_EXEC_PATH // JMC - backport 4639
01166 status = extractFileWithUnzip (structFileInx);
01167 #else
01168 return SYS_ZIP_FORMAT_NOT_SUPPORTED;
01169 #endif
01170 } else {
01171 #ifdef TAR_EXEC_PATH
01172 status = extractTarFileWithExec (structFileInx);
01173 #else
01174 status = extractTarFileWithLib (structFileInx);
01175 #endif
01176 }
01177 return status;
01178 }
01179
01180 #ifdef TAR_EXEC_PATH
01181 int
01182 extractTarFileWithExec (int structFileInx)
01183 {
01184 int status;
01185 char *av[NAME_LEN];
01186 #ifndef GNU_TAR
01187 char tmpPath[MAX_NAME_LEN];
01188 #endif
01189 int inx = 0;
01190
01191 specColl_t *specColl = StructFileDesc[structFileInx].specColl;
01192 char *dataType = StructFileDesc[structFileInx].dataType;
01193
01194 if (StructFileDesc[structFileInx].inuseFlag <= 0) {
01195 rodsLog (LOG_NOTICE,
01196 "extractTarFileWithExec: structFileInx %d not in use",
01197 structFileInx);
01198 return (SYS_STRUCT_FILE_DESC_ERR);
01199 }
01200
01201 if (specColl == NULL || strlen (specColl->cacheDir) == 0 ||
01202 strlen (specColl->phyPath) == 0) {
01203 rodsLog (LOG_NOTICE,
01204 "extractTarFileWithExec: Bad specColl for structFileInx %d ",
01205 structFileInx);
01206 return (SYS_STRUCT_FILE_DESC_ERR);
01207 }
01208 bzero (av, sizeof (av));
01209
01210
01211 av[inx] = TAR_EXEC_PATH;
01212 inx++;
01213 #ifdef GNU_TAR
01214 av[inx] = "-x";
01215 inx++;
01216 if (strstr (dataType, GZIP_TAR_DT_STR) != NULL) {
01217 av[inx] = "-z";
01218 inx++;
01219 } else if (strstr (dataType, BZIP2_TAR_DT_STR) != NULL) {
01220 av[inx] = "-j";
01221 inx++;
01222 }
01223 #ifdef TAR_EXTENDED_HDR // JMC - backport 4596
01224 av[inx] = "-E";
01225 inx++;
01226 #endif
01227 av[inx] = "-f";
01228 inx++;
01229 av[inx] = specColl->phyPath;
01230 inx++;
01231 av[inx] = "-C";
01232 inx++;
01233 av[inx] = specColl->cacheDir;
01234 #else
01235 if( strstr (dataType, GZIP_TAR_DT_STR) != NULL ||
01236 strstr (dataType, BZIP2_TAR_DT_STR) != NULL) {
01237
01238 rodsLog (LOG_ERROR,
01239 "extractTarFileWithExec:gzip/bzip2 %s not supported by non-GNU_TAR",
01240 specColl->phyPath);
01241 }
01242 mkdir (specColl->cacheDir, getDefDirMode ());
01243 if (getcwd (tmpPath, MAX_NAME_LEN) == NULL) {
01244 rodsLog (LOG_ERROR,
01245 "extractTarFileWithExec:: getcwd failed. errno = %d", errno);
01246 return SYS_EXEC_TAR_ERR - errno;
01247 }
01248 chdir (specColl->cacheDir);
01249 #ifdef TAR_EXTENDED_HDR // JMC - backport 4596
01250 av[inx] = "-xEf";
01251 #else
01252 av[inx] = "-xf";
01253 #endif
01254 inx++;
01255 av[inx] = specColl->phyPath;
01256 #endif
01257 status = forkAndExec (av);
01258 #ifndef GNU_TAR
01259 chdir (tmpPath);
01260 #endif
01261
01262 return status;
01263 }
01264
01265 #else
01266 int
01267 extractTarFileWithLib (int structFileInx)
01268 {
01269 TAR *t;
01270 specColl_t *specColl = StructFileDesc[structFileInx].specColl;
01271 int myMode;
01272 int status;
01273
01274
01275 if (StructFileDesc[structFileInx].inuseFlag <= 0) {
01276 rodsLog (LOG_NOTICE,
01277 "extractTarFile: structFileInx %d not in use", structFileInx);
01278 return (SYS_STRUCT_FILE_DESC_ERR);
01279 }
01280
01281 if (specColl == NULL || strlen (specColl->cacheDir) == 0 ||
01282 strlen (specColl->phyPath) == 0) {
01283 rodsLog (LOG_NOTICE,
01284 "extractTarFile: Bad specColl for structFileInx %d ",
01285 structFileInx);
01286 return (SYS_STRUCT_FILE_DESC_ERR);
01287 }
01288 myMode = encodeIrodsTarfd (structFileInx, getDefFileMode ());
01289
01290 if (myMode < 0) {
01291 return (myMode);
01292 }
01293
01294 status = tar_open (&t, specColl->phyPath, &irodstype,
01295 O_RDONLY, myMode, TAR_GNU);
01296
01297 if (status < 0) {
01298 rodsLog (LOG_NOTICE,
01299 "extractTarFile: tar_open error for %s, errno = %d",
01300 specColl->phyPath, errno);
01301 return (SYS_TAR_OPEN_ERR - errno);
01302 }
01303
01304 if (tar_extract_all (t, specColl->cacheDir) != 0) {
01305 rodsLog (LOG_NOTICE,
01306 "extractTarFile: tar_extract_all error for %s, errno = %d",
01307 specColl->phyPath, errno);
01308 return (SYS_TAR_EXTRACT_ALL_ERR - errno);
01309 }
01310
01311 if (tar_close(t) != 0) {
01312 rodsLog (LOG_NOTICE,
01313 "extractTarFile: tar_close error for %s, errno = %d",
01314 specColl->phyPath, errno);
01315 return (SYS_TAR_CLOSE_ERR - errno);
01316 }
01317
01318 return 0;
01319 }
01320 #endif
01321
01322
01323 int
01324 getSubStructFilePhyPath (char *phyPath, specColl_t *specColl,
01325 char *subFilePath)
01326 {
01327 int len;
01328
01329
01330
01331
01332
01333 len = strlen (specColl->collection);
01334 if (strncmp (specColl->collection, subFilePath, len) != 0) {
01335 rodsLog (LOG_NOTICE,
01336 "getSubStructFilePhyPath: collection %s subFilePath %s mismatch",
01337 specColl->collection, subFilePath);
01338 return (SYS_STRUCT_FILE_PATH_ERR);
01339 }
01340
01341 snprintf (phyPath, MAX_NAME_LEN, "%s%s", specColl->cacheDir,
01342 subFilePath + len);
01343
01344
01345 return (0);
01346 }
01347
01348 int
01349 syncCacheDirToTarfile (int structFileInx, int oprType)
01350 {
01351 int status;
01352 int rescTypeInx;
01353 fileStatInp_t fileStatInp;
01354 rodsStat_t *fileStatOut = NULL;
01355 specColl_t *specColl = StructFileDesc[structFileInx].specColl;
01356 rsComm_t *rsComm = StructFileDesc[structFileInx].rsComm;
01357
01358 if (strstr (StructFileDesc[structFileInx].dataType, ZIP_DT_STR) != 0) {
01359 #ifdef ZIP_EXEC_PATH
01360 status = bundleCacheDirWithZip (structFileInx );
01361 #else
01362 return SYS_ZIP_FORMAT_NOT_SUPPORTED;
01363 #endif
01364 } else {
01365 #ifdef TAR_EXEC_PATH
01366 status = bundleCacheDirWithExec (structFileInx, oprType);
01367 #else
01368 if ((oprType & ADD_TO_TAR_OPR) != 0)
01369 return SYS_ADD_TO_ARCH_OPR_NOT_SUPPORTED;
01370 status = bundleCacheDirWithLib (structFileInx);
01371 #endif
01372 }
01373 if (status < 0) return status;
01374
01375
01376 memset (&fileStatInp, 0, sizeof (fileStatInp));
01377 rstrcpy (fileStatInp.fileName, specColl->phyPath, MAX_NAME_LEN);
01378 rescTypeInx = StructFileDesc[structFileInx].rescInfo->rescTypeInx;
01379 fileStatInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType;
01380 rstrcpy (fileStatInp.addr.hostAddr,
01381 StructFileDesc[structFileInx].rescInfo->rescLoc, NAME_LEN);
01382
01383 status = rsFileStat (rsComm, &fileStatInp, &fileStatOut);
01384
01385 if (status < 0 || NULL == fileStatOut ) {
01386 rodsLog (LOG_ERROR,
01387 "syncCacheDirToTarfile: rsFileStat error for %s, status = %d",
01388 specColl->phyPath, status);
01389 return (status);
01390 }
01391
01392 if ((oprType & NO_REG_COLL_INFO) == 0) {
01393
01394 status = regNewObjSize (rsComm, specColl->objPath, specColl->replNum,
01395 fileStatOut->st_size);
01396 }
01397
01398 free (fileStatOut);
01399
01400 return (status);
01401 }
01402
01403 #ifdef TAR_EXEC_PATH
01404 int
01405 bundleCacheDirWithExec (int structFileInx, int oprType)
01406 {
01407 int status;
01408 char *av[NAME_LEN];
01409
01410 #ifndef GNU_TAR // JMC - backport 4643
01411 char optStr[NAME_LEN];
01412 #endif
01413
01414 char *dataType;
01415 int inx = 0;
01416
01417 specColl_t *specColl = StructFileDesc[structFileInx].specColl;
01418 if (specColl == NULL || specColl->cacheDirty <= 0 ||
01419 strlen (specColl->cacheDir) == 0) return 0;
01420
01421
01422
01423 dataType = StructFileDesc[structFileInx].dataType;
01424 bzero (av, sizeof (av));
01425 av[inx] = TAR_EXEC_PATH;
01426 inx++;
01427 #ifdef GNU_TAR
01428 if ((oprType & ADD_TO_TAR_OPR) == 0) {
01429 av[inx] = "-c";
01430 } else {
01431 av[inx] = "-r";
01432 }
01433
01434 inx++;
01435 av[inx] = "-h";
01436 inx++;
01437 if (strstr (dataType, GZIP_TAR_DT_STR) != NULL) {
01438 if ((oprType & ADD_TO_TAR_OPR) != 0)
01439 return SYS_ADD_TO_ARCH_OPR_NOT_SUPPORTED;
01440 av[inx] = "-z";
01441 inx++;
01442 } else if (strstr (dataType, BZIP2_TAR_DT_STR) != NULL) {
01443 if ((oprType & ADD_TO_TAR_OPR) != 0)
01444 return SYS_ADD_TO_ARCH_OPR_NOT_SUPPORTED;
01445 av[inx] = "-j";
01446 inx++;
01447 }
01448 #ifdef TAR_EXTENDED_HDR // JMC - backport 4596
01449 av[inx] = "-E";
01450 #endif
01451 av[inx] = "-f";
01452 inx++;
01453 #else
01454 if( strstr (dataType, GZIP_TAR_DT_STR ) != NULL ||
01455 strstr (dataType, BZIP2_TAR_DT_STR) != NULL) {
01456 rodsLog (LOG_ERROR,
01457 "bundleCacheDirWithExec: gzip/bzip2 %s not supported for non-GNU_TAR",
01458 specColl->phyPath);
01459 return SYS_ZIP_FORMAT_NOT_SUPPORTED;
01460 }
01461 rstrcpy (optStr, "-h", NAME_LEN);
01462 #ifdef TAR_EXTENDED_HDR
01463 strcat (optStr, "E");
01464 #endif
01465 if ((oprType & ADD_TO_TAR_OPR) != 0) {
01466
01467 strcat (optStr, "u");
01468 } else {
01469 strcat (optStr, "c");
01470 }
01471
01472 strcat (optStr, "f");
01473 av[inx] = optStr;
01474 inx++;
01475 #endif
01476 av[inx] = specColl->phyPath;
01477 inx++;
01478 av[inx] = "-C";
01479 inx++;
01480 av[inx] = specColl->cacheDir;
01481 inx++;
01482 av[inx] = ".";
01483 status = forkAndExec (av);
01484
01485
01486 return status;
01487 }
01488
01489 #else
01490 int
01491 bundleCacheDirWithLib (int structFileInx)
01492 {
01493 TAR *t;
01494 int status;
01495 int myMode;
01496
01497 specColl_t *specColl = StructFileDesc[structFileInx].specColl;
01498 if (specColl == NULL || specColl->cacheDirty <= 0 ||
01499 strlen (specColl->cacheDir) == 0) return 0;
01500
01501 myMode = encodeIrodsTarfd (structFileInx, getDefFileMode ());
01502
01503 status = tar_open (&t, specColl->phyPath, &irodstype,
01504 O_WRONLY, myMode, TAR_GNU);
01505
01506 if (status < 0) {
01507 rodsLog (LOG_NOTICE,
01508 "syncCacheDirToTarfile: tar_open error for %s, errno = %d",
01509 specColl->phyPath, errno);
01510 return (SYS_TAR_OPEN_ERR - errno);
01511 }
01512 status = tar_append_tree (t, specColl->cacheDir, ".");
01513
01514 if (status != 0) {
01515 rodsLog (LOG_NOTICE,
01516 "syncCacheDirToTarfile: tar_append_tree error for %s, errno = %d",
01517 specColl->cacheDir, errno);
01518 if (status < 0) {
01519 return (status);
01520 } else {
01521 return (SYS_TAR_APPEND_ERR - errno);
01522 }
01523 }
01524
01525 if ((status = tar_close(t)) != 0) {
01526 rodsLog (LOG_NOTICE,
01527 "syncCacheDirToTarfile: tar_close error for %s, errno = %d",
01528 specColl->phyPath, errno);
01529 if (status < 0) {
01530 return (status);
01531 } else {
01532 return (SYS_TAR_CLOSE_ERR - errno);
01533 }
01534 }
01535
01536 return 0;
01537 }
01538 #endif
01539
01540 int
01541 initTarSubFileDesc ()
01542 {
01543 memset (TarSubFileDesc, 0,
01544 sizeof (tarSubFileDesc_t) * NUM_TAR_SUB_FILE_DESC);
01545 return (0);
01546 }
01547
01548 int
01549 allocTarSubFileDesc ()
01550 {
01551 int i;
01552
01553 for (i = 1; i < NUM_TAR_SUB_FILE_DESC; i++) {
01554 if (TarSubFileDesc[i].inuseFlag == FD_FREE) {
01555 TarSubFileDesc[i].inuseFlag = FD_INUSE;
01556 return (i);
01557 };
01558 }
01559
01560 rodsLog (LOG_NOTICE,
01561 "allocTarSubFileDesc: out of TarSubFileDesc");
01562
01563 return (SYS_OUT_OF_FILE_DESC);
01564 }
01565
01566 int
01567 freeTarSubFileDesc (int tarSubFileInx)
01568 {
01569 if (tarSubFileInx < 0 || tarSubFileInx >= NUM_TAR_SUB_FILE_DESC) {
01570 rodsLog (LOG_NOTICE,
01571 "freeTarSubFileDesc: tarSubFileInx %d out of range", tarSubFileInx);
01572 return (SYS_FILE_DESC_OUT_OF_RANGE);
01573 }
01574
01575 memset (&TarSubFileDesc[tarSubFileInx], 0, sizeof (tarSubFileDesc_t));
01576
01577 return (0);
01578 }
01579
01580
01581 #ifdef ZIP_EXEC_PATH // JMC - backport 4639
01582
01583
01584 int
01585 bundleCacheDirWithZip (int structFileInx)
01586 {
01587 char *av[NAME_LEN];
01588 char tmpPath[MAX_NAME_LEN];
01589 int status;
01590 int inx = 0;
01591
01592 specColl_t *specColl = StructFileDesc[structFileInx].specColl;
01593
01594 if (specColl == NULL || specColl->cacheDirty <= 0 ||
01595 strlen (specColl->cacheDir) == 0) return 0;
01596
01597
01598 if (getcwd (tmpPath, MAX_NAME_LEN) == NULL) {
01599 rodsLog (LOG_ERROR,
01600 "bundleCacheDirWithZip: getcwd failed. errno = %d", errno);
01601 return SYS_EXEC_TAR_ERR - errno;
01602 }
01603 chdir (specColl->cacheDir);
01604 bzero (av, sizeof (av));
01605 av[inx] = ZIP_EXEC_PATH;
01606 inx++;
01607 av[inx] = "-r";
01608 inx++;
01609 av[inx] = "-q";
01610 inx++;
01611 av[inx] = specColl->phyPath;
01612 inx++;
01613 av[inx] = ".";
01614 status = forkAndExec (av);
01615 chdir (tmpPath);
01616
01617 return status;
01618 }
01619 #endif // JMC - backport 4639
01620
01621 #ifdef ZIP_EXEC_PATH // JMC - backport 4639
01622 int
01623 extractFileWithUnzip (int structFileInx)
01624 {
01625 char *av[NAME_LEN];
01626 int status;
01627 int inx = 0;
01628
01629 specColl_t *specColl = StructFileDesc[structFileInx].specColl;
01630 if (StructFileDesc[structFileInx].inuseFlag <= 0) {
01631 rodsLog (LOG_NOTICE,
01632 "extractFileWithUnzip: structFileInx %d not in use",
01633 structFileInx);
01634 return (SYS_STRUCT_FILE_DESC_ERR);
01635 }
01636
01637 if (specColl == NULL || strlen (specColl->cacheDir) == 0 ||
01638 strlen (specColl->phyPath) == 0) {
01639 rodsLog (LOG_NOTICE,
01640 "extractFileWithUnzip: Bad specColl for structFileInx %d ",
01641 structFileInx);
01642 return (SYS_STRUCT_FILE_DESC_ERR);
01643 }
01644
01645
01646 bzero (av, sizeof (av));
01647 av[inx] = UNZIP_EXEC_PATH;
01648 inx++;
01649 av[inx] = "-q";
01650 inx++;
01651 av[inx] = "-d";
01652 inx++;
01653 av[inx] = specColl->cacheDir;
01654 inx++;
01655 av[inx] = specColl->phyPath;
01656 status = forkAndExec (av);
01657
01658 return status;
01659 }
01660 #endif // JMC - backport 4639
01661