int l3Open( rsComm_t *rsComm, int l1descInx ) { dataObjInfo_t *dataObjInfo; int l3descInx; int mode, flags; dataObjInfo = L1desc[l1descInx].dataObjInfo; std::string location; irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location ); if ( !ret.ok() ) { irods::log( PASSMSG( "l3Open - failed in get_loc_for_hier_string", ret ) ); return -1; } if ( getStructFileType( dataObjInfo->specColl ) >= 0 ) { subFile_t subFile; memset( &subFile, 0, sizeof( subFile ) ); rstrcpy( subFile.subFilePath, dataObjInfo->subPath, MAX_NAME_LEN ); rstrcpy( subFile.addr.hostAddr, location.c_str(), NAME_LEN ); subFile.specColl = dataObjInfo->specColl; subFile.mode = getFileMode( L1desc[l1descInx].dataObjInp ); subFile.flags = getFileFlags( l1descInx ); l3descInx = rsSubStructFileOpen( rsComm, &subFile ); } else { mode = getFileMode( L1desc[l1descInx].dataObjInp ); flags = getFileFlags( l1descInx ); l3descInx = _l3Open( rsComm, dataObjInfo, mode, flags ); } return l3descInx; }
int l3FileGetSingleBuf (rsComm_t *rsComm, int l1descInx, bytesBuf_t *dataObjOutBBuf) { dataObjInfo_t *dataObjInfo; int rescTypeInx; fileOpenInp_t fileGetInp; int bytesRead; dataObjInp_t *dataObjInp; dataObjInfo = L1desc[l1descInx].dataObjInfo; if (getStructFileType (dataObjInfo->specColl) >= 0) { subFile_t subFile; memset (&subFile, 0, sizeof (subFile)); rstrcpy (subFile.subFilePath, dataObjInfo->subPath, MAX_NAME_LEN); rstrcpy (subFile.addr.hostAddr, dataObjInfo->rescInfo->rescLoc, NAME_LEN); subFile.specColl = dataObjInfo->specColl; subFile.mode = getFileMode (L1desc[l1descInx].dataObjInp); subFile.flags = O_RDONLY; subFile.offset = dataObjInfo->dataSize; bytesRead = rsSubStructFileGet (rsComm, &subFile, dataObjOutBBuf); return (bytesRead); } rescTypeInx = dataObjInfo->rescInfo->rescTypeInx; switch (RescTypeDef[rescTypeInx].rescCat) { case FILE_CAT: memset (&fileGetInp, 0, sizeof (fileGetInp)); dataObjInp = L1desc[l1descInx].dataObjInp; fileGetInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType; rstrcpy (fileGetInp.addr.hostAddr, dataObjInfo->rescInfo->rescLoc, NAME_LEN); rstrcpy (fileGetInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN); fileGetInp.mode = getFileMode (dataObjInp); fileGetInp.flags = O_RDONLY; fileGetInp.dataSize = dataObjInfo->dataSize; /* XXXXX need to be able to handle structured file */ bytesRead = rsFileGet (rsComm, &fileGetInp, dataObjOutBBuf); break; default: rodsLog (LOG_NOTICE, "l3Open: rescCat type %d is not recognized", RescTypeDef[rescTypeInx].rescCat); bytesRead = SYS_INVALID_RESC_TYPE; break; } return (bytesRead); }
int l3FileGetSingleBuf( rsComm_t *rsComm, int l1descInx, bytesBuf_t *dataObjOutBBuf ) { dataObjInfo_t *dataObjInfo; fileOpenInp_t fileGetInp; int bytesRead; dataObjInp_t *dataObjInp; dataObjInfo = L1desc[l1descInx].dataObjInfo; // =-=-=-=-=-=-=- // extract the host location from the resource hierarchy std::string location; irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location ); if ( !ret.ok() ) { irods::log( PASSMSG( "l3FileGetSingleBuf - failed in get_loc_for_hier_String", ret ) ); return -1; } if ( getStructFileType( dataObjInfo->specColl ) >= 0 ) { subFile_t subFile; memset( &subFile, 0, sizeof( subFile ) ); rstrcpy( subFile.subFilePath, dataObjInfo->subPath, MAX_NAME_LEN ); //rstrcpy (subFile.addr.hostAddr, dataObjInfo->rescInfo->rescLoc,NAME_LEN); rstrcpy( subFile.addr.hostAddr, location.c_str(), NAME_LEN ); subFile.specColl = dataObjInfo->specColl; subFile.mode = getFileMode( L1desc[l1descInx].dataObjInp ); subFile.flags = O_RDONLY; subFile.offset = dataObjInfo->dataSize; bytesRead = rsSubStructFileGet( rsComm, &subFile, dataObjOutBBuf ); return bytesRead; } memset( &fileGetInp, 0, sizeof( fileGetInp ) ); dataObjInp = L1desc[l1descInx].dataObjInp; rstrcpy( fileGetInp.addr.hostAddr, location.c_str(), NAME_LEN ); rstrcpy( fileGetInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN ); rstrcpy( fileGetInp.resc_name_, dataObjInfo->rescInfo->rescName, MAX_NAME_LEN ); rstrcpy( fileGetInp.resc_hier_, dataObjInfo->rescHier, MAX_NAME_LEN ); rstrcpy( fileGetInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN ); fileGetInp.mode = getFileMode( dataObjInp ); fileGetInp.flags = O_RDONLY; fileGetInp.dataSize = dataObjInfo->dataSize; /* XXXXX need to be able to handle structured file */ bytesRead = rsFileGet( rsComm, &fileGetInp, dataObjOutBBuf ); return bytesRead; }
int l3Create( rsComm_t *rsComm, int l1descInx ) { dataObjInfo_t *dataObjInfo; int l3descInx; dataObjInfo = L1desc[l1descInx].dataObjInfo; // =-=-=-=-=-=-=- // extract the host location from the resource hierarchy std::string location; irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location ); if ( !ret.ok() ) { irods::log( PASSMSG( "l3Create - failed in get_loc_for_hier_String", ret ) ); return -1; } if ( getStructFileType( dataObjInfo->specColl ) >= 0 ) { subFile_t subFile; memset( &subFile, 0, sizeof( subFile ) ); rstrcpy( subFile.subFilePath, dataObjInfo->subPath, MAX_NAME_LEN ); rstrcpy( subFile.addr.hostAddr, location.c_str(), NAME_LEN ); subFile.specColl = dataObjInfo->specColl; subFile.mode = getFileMode( L1desc[l1descInx].dataObjInp ); l3descInx = rsSubStructFileCreate( rsComm, &subFile ); } else { /* normal or mounted file */ l3descInx = l3CreateByObjInfo( rsComm, L1desc[l1descInx].dataObjInp, L1desc[l1descInx].dataObjInfo ); } return ( l3descInx ); }
void my_list(int data_conn_sock ,char *filepath) { char mymode[11]= "----------"; struct stat buf; struct dirent *p = NULL; struct passwd *passwd; char uname[50]; char gname[50]; char mtime[50]; DIR *mydir = NULL; char buffer[100]; chdir(filepath); mydir = opendir(filepath); while( (p = readdir(mydir)) != NULL ) { memset( &buf, 0, sizeof(buf)); stat(p->d_name,&buf); getFileMode(buf.st_mode, mymode); getUserName(buf.st_uid, uname); getGroupName(buf.st_gid, gname); getTime(buf.st_mtime, mtime); sprintf(buffer,"%s %d %s %s %10d %s %s\r\n", mymode, buf.st_nlink, uname, gname, buf.st_size, mtime, p->d_name); if (data_conn_sock != 0) { write_loop(data_conn_sock, buffer, strlen(buffer)); } } closedir(mydir); }
void parseFileBlock( char *source, file_block *fb) { fb->size_before = getFileSizeBefore( source); fb->size_after = getFileSizeAfter( source); strcpy(fb->path, getFilePath( source)); fb->st_mode = getFileMode( source); }
int l3FilePutSingleBuf( rsComm_t *rsComm, int l1descInx, bytesBuf_t *dataObjInpBBuf ) { dataObjInfo_t *dataObjInfo; fileOpenInp_t filePutInp; int bytesWritten; dataObjInp_t *dataObjInp; int retryCnt = 0; int chkType = 0; // JMC - backport 4774 dataObjInfo = L1desc[l1descInx].dataObjInfo; dataObjInp = L1desc[l1descInx].dataObjInp; // =-=-=-=-=-=-=- // extract the host location from the resource hierarchy std::string location; irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location ); if ( !ret.ok() ) { irods::log( PASSMSG( "l3FilePutSingleBuf - failed in get_loc_for_hier_string", ret ) ); return -1; } if ( getStructFileType( dataObjInfo->specColl ) >= 0 ) { subFile_t subFile; memset( &subFile, 0, sizeof( subFile ) ); rstrcpy( subFile.subFilePath, dataObjInfo->subPath, MAX_NAME_LEN ); rstrcpy( subFile.addr.hostAddr, location.c_str(), NAME_LEN ); subFile.specColl = dataObjInfo->specColl; subFile.mode = getFileMode( dataObjInp ); subFile.flags = O_WRONLY | dataObjInp->openFlags; if ( ( L1desc[l1descInx].replStatus & OPEN_EXISTING_COPY ) != 0 ) { subFile.flags |= FORCE_FLAG; } bytesWritten = rsSubStructFilePut( rsComm, &subFile, dataObjInpBBuf ); return bytesWritten; } // struct file type >= 0 std::string prev_resc_hier; memset( &filePutInp, 0, sizeof( filePutInp ) ); rstrcpy( filePutInp.resc_hier_, dataObjInfo->rescHier, MAX_NAME_LEN ); rstrcpy( filePutInp.objPath, dataObjInp->objPath, MAX_NAME_LEN ); if ( ( L1desc[l1descInx].replStatus & OPEN_EXISTING_COPY ) != 0 ) { filePutInp.otherFlags |= FORCE_FLAG; } rstrcpy( filePutInp.addr.hostAddr, location.c_str(), NAME_LEN ); rstrcpy( filePutInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN ); filePutInp.mode = getFileMode( dataObjInp ); filePutInp.flags = O_WRONLY | dataObjInp->openFlags; rstrcpy( filePutInp.in_pdmo, L1desc[l1descInx].in_pdmo, MAX_NAME_LEN ); // kv pasthru copyKeyVal( &dataObjInfo->condInput, &filePutInp.condInput ); // =-=-=-=-=-=-=- // JMC - backport 4774 chkType = getchkPathPerm( rsComm, L1desc[l1descInx].dataObjInp, L1desc[l1descInx].dataObjInfo ); if ( chkType == DISALLOW_PATH_REG ) { clearKeyVal( &filePutInp.condInput ); return PATH_REG_NOT_ALLOWED; } else if ( chkType == NO_CHK_PATH_PERM ) { // =-=-=-=-=-=-=- filePutInp.otherFlags |= NO_CHK_PERM_FLAG; // JMC - backport 4758 } filePutOut_t* put_out = 0; prev_resc_hier = filePutInp.resc_hier_; bytesWritten = rsFilePut( rsComm, &filePutInp, dataObjInpBBuf, &put_out ); // update the dataObjInfo with the potential changes made by the resource - hcj rstrcpy( dataObjInfo->rescHier, filePutInp.resc_hier_, MAX_NAME_LEN ); if ( put_out ) { rstrcpy( dataObjInfo->filePath, put_out->file_name, MAX_NAME_LEN ); free( put_out ); } /* file already exists ? */ while ( bytesWritten < 0 && retryCnt < 10 && ( filePutInp.otherFlags & FORCE_FLAG ) == 0 && getErrno( bytesWritten ) == EEXIST ) { if ( resolveDupFilePath( rsComm, dataObjInfo, dataObjInp ) < 0 ) { break; } rstrcpy( filePutInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN ); filePutOut_t* put_out = 0; bytesWritten = rsFilePut( rsComm, &filePutInp, dataObjInpBBuf, &put_out ); // update the dataObjInfo with the potential changes made by the resource - hcj rstrcpy( dataObjInfo->rescHier, filePutInp.resc_hier_, MAX_NAME_LEN ); if ( put_out ) { rstrcpy( dataObjInfo->filePath, put_out->file_name, MAX_NAME_LEN ); free( put_out ); } retryCnt ++; } // while clearKeyVal( &filePutInp.condInput ); return bytesWritten; } // l3FilePutSingleBuf
int l3CreateByObjInfo( rsComm_t *rsComm, dataObjInp_t *dataObjInp, dataObjInfo_t *dataObjInfo ) { int l3descInx; int retryCnt = 0; int chkType = 0; // JMC - backport 4774 // =-=-=-=-=-=-=- // extract the host location from the resource hierarchy std::string location; irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location ); if ( !ret.ok() ) { irods::log( PASSMSG( "l3CreateByObjInfo - failed in get_loc_for_hier_String", ret ) ); return -1; } fileCreateInp_t fileCreateInp; memset( &fileCreateInp, 0, sizeof( fileCreateInp ) ); rstrcpy( fileCreateInp.resc_name_, location.c_str(), MAX_NAME_LEN ); rstrcpy( fileCreateInp.resc_hier_, dataObjInfo->rescHier, MAX_NAME_LEN ); rstrcpy( fileCreateInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN ); rstrcpy( fileCreateInp.addr.hostAddr, location.c_str(), NAME_LEN ); rstrcpy( fileCreateInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN ); fileCreateInp.mode = getFileMode( dataObjInp ); // =-=-=-=-=-=-=- // JMC - backport 4774 chkType = getchkPathPerm( rsComm, dataObjInp, dataObjInfo ); copyFilesystemMetadata( &dataObjInfo->condInput, &fileCreateInp.condInput ); if ( chkType == DISALLOW_PATH_REG ) { clearKeyVal( &fileCreateInp.condInput ); return PATH_REG_NOT_ALLOWED; } else if ( chkType == NO_CHK_PATH_PERM ) { fileCreateInp.otherFlags |= NO_CHK_PERM_FLAG; // JMC - backport 4758 } rstrcpy( fileCreateInp.in_pdmo, dataObjInfo->in_pdmo, MAX_NAME_LEN ); // =-=-=-=-=-=-=- // fileCreateOut_t* create_out = 0; std::string prev_resc_hier = fileCreateInp.resc_hier_; l3descInx = rsFileCreate( rsComm, &fileCreateInp, &create_out ); // update the dataObjInfo with the potential changes made by the resource - hcj rstrcpy( dataObjInfo->rescHier, fileCreateInp.resc_hier_, MAX_NAME_LEN ); rstrcpy( dataObjInfo->filePath, create_out->file_name, MAX_NAME_LEN ); /* file already exists ? */ while ( l3descInx <= 2 && retryCnt < 100 && getErrno( l3descInx ) == EEXIST ) { if ( resolveDupFilePath( rsComm, dataObjInfo, dataObjInp ) < 0 ) { break; } rstrcpy( fileCreateInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN ); free( create_out ); l3descInx = rsFileCreate( rsComm, &fileCreateInp, &create_out ); // update the dataObjInfo with the potential changes made by the resource - hcj rstrcpy( dataObjInfo->rescHier, fileCreateInp.resc_hier_, MAX_NAME_LEN ); rstrcpy( dataObjInfo->filePath, create_out->file_name, MAX_NAME_LEN ); retryCnt ++; } clearKeyVal( &fileCreateInp.condInput ); return ( l3descInx ); }
int l3FilePutSingleBuf (rsComm_t *rsComm, int l1descInx, bytesBuf_t *dataObjInpBBuf) { dataObjInfo_t *dataObjInfo; int rescTypeInx; fileOpenInp_t filePutInp; int bytesWritten; dataObjInp_t *dataObjInp; int retryCnt = 0; int chkType; dataObjInfo = L1desc[l1descInx].dataObjInfo; dataObjInp = L1desc[l1descInx].dataObjInp; if (getStructFileType (dataObjInfo->specColl) >= 0) { subFile_t subFile; memset (&subFile, 0, sizeof (subFile)); rstrcpy (subFile.subFilePath, dataObjInfo->subPath, MAX_NAME_LEN); rstrcpy (subFile.addr.hostAddr, dataObjInfo->rescInfo->rescLoc, NAME_LEN); subFile.specColl = dataObjInfo->specColl; subFile.mode = getFileMode (dataObjInp); subFile.flags = O_WRONLY | dataObjInp->openFlags; #if 0 if (getValByKey (&dataObjInp->condInput, FORCE_FLAG_KW) != NULL) { #else if ((L1desc[l1descInx].replStatus & OPEN_EXISTING_COPY) != 0) { #endif subFile.flags |= FORCE_FLAG; } bytesWritten = rsSubStructFilePut (rsComm, &subFile, dataObjInpBBuf); return (bytesWritten); } rescTypeInx = dataObjInfo->rescInfo->rescTypeInx; switch (RescTypeDef[rescTypeInx].rescCat) { case FILE_CAT: memset (&filePutInp, 0, sizeof (filePutInp)); #if 0 if (getValByKey (&dataObjInp->condInput, FORCE_FLAG_KW) != NULL) { #else if ((L1desc[l1descInx].replStatus & OPEN_EXISTING_COPY) != 0) { #endif filePutInp.otherFlags |= FORCE_FLAG; } filePutInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType; rstrcpy (filePutInp.addr.hostAddr, dataObjInfo->rescInfo->rescLoc, NAME_LEN); rstrcpy (filePutInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN); filePutInp.mode = getFileMode (dataObjInp); #ifdef FILESYSTEM_META copyFilesystemMetadata(&dataObjInfo->condInput, &filePutInp.condInput); #endif filePutInp.flags = O_WRONLY | dataObjInp->openFlags; chkType = getchkPathPerm (rsComm, L1desc[l1descInx].dataObjInp, L1desc[l1descInx].dataObjInfo); if (chkType == DISALLOW_PATH_REG) { return PATH_REG_NOT_ALLOWED; } else if (chkType == NO_CHK_PATH_PERM) { filePutInp.otherFlags |= NO_CHK_PERM_FLAG; } bytesWritten = rsFilePut (rsComm, &filePutInp, dataObjInpBBuf); /* file already exists ? */ while (bytesWritten < 0 && retryCnt < 10 && (filePutInp.otherFlags & FORCE_FLAG) == 0 && getErrno (bytesWritten) == EEXIST) { if (resolveDupFilePath (rsComm, dataObjInfo, dataObjInp) < 0) { break; } rstrcpy (filePutInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN); bytesWritten = rsFilePut (rsComm, &filePutInp, dataObjInpBBuf); retryCnt ++; } break; default: rodsLog (LOG_NOTICE, "l3Open: rescCat type %d is not recognized", RescTypeDef[rescTypeInx].rescCat); bytesWritten = SYS_INVALID_RESC_TYPE; break; } return (bytesWritten); }
int l3CreateByObjInfo( rsComm_t *rsComm, dataObjInp_t *dataObjInp, dataObjInfo_t *dataObjInfo ) { int chkType = 0; // JMC - backport 4774 // =-=-=-=-=-=-=- // extract the host location from the resource hierarchy std::string location; irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location ); if ( !ret.ok() ) { irods::log( PASSMSG( "l3CreateByObjInfo - failed in get_loc_for_hier_string", ret ) ); return -1; } fileCreateInp_t fileCreateInp; memset( &fileCreateInp, 0, sizeof( fileCreateInp ) ); rstrcpy( fileCreateInp.resc_name_, location.c_str(), MAX_NAME_LEN ); rstrcpy( fileCreateInp.resc_hier_, dataObjInfo->rescHier, MAX_NAME_LEN ); rstrcpy( fileCreateInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN ); rstrcpy( fileCreateInp.addr.hostAddr, location.c_str(), NAME_LEN ); rstrcpy( fileCreateInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN ); fileCreateInp.mode = getFileMode( dataObjInp ); // =-=-=-=-=-=-=- // JMC - backport 4774 chkType = getchkPathPerm( rsComm, dataObjInp, dataObjInfo ); if ( chkType == DISALLOW_PATH_REG ) { clearKeyVal( &fileCreateInp.condInput ); return PATH_REG_NOT_ALLOWED; } else if ( chkType == NO_CHK_PATH_PERM ) { fileCreateInp.otherFlags |= NO_CHK_PERM_FLAG; // JMC - backport 4758 } rstrcpy( fileCreateInp.in_pdmo, dataObjInfo->in_pdmo, MAX_NAME_LEN ); //loop until we find a valid filename int retryCnt = 0; int l3descInx; do { fileCreateOut_t* create_out = NULL; l3descInx = rsFileCreate( rsComm, &fileCreateInp, &create_out ); // update the dataObjInfo with the potential changes made by the resource - hcj if ( create_out != NULL ) { rstrcpy( dataObjInfo->rescHier, fileCreateInp.resc_hier_, MAX_NAME_LEN ); rstrcpy( dataObjInfo->filePath, create_out->file_name, MAX_NAME_LEN ); free( create_out ); } //update the filename in case of a retry rstrcpy( fileCreateInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN ); retryCnt++; } while ( getErrno( l3descInx ) == EEXIST && resolveDupFilePath( rsComm, dataObjInfo, dataObjInp ) >= 0 && l3descInx <= 2 && retryCnt < 100 ); clearKeyVal( &fileCreateInp.condInput ); return l3descInx; }