int l3Mkdir( rsComm_t *rsComm, dataObjInfo_t *dataObjInfo ) { //int rescTypeInx; fileMkdirInp_t fileMkdirInp; int status; // =-=-=-=-=-=-=- // 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( "l3Mkdir - 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 ); subFile.mode = getDefDirMode(); //rstrcpy (subFile.addr.hostAddr, dataObjInfo->rescInfo->rescLoc, NAME_LEN ); rstrcpy( subFile.addr.hostAddr, location.c_str(), NAME_LEN ); subFile.specColl = dataObjInfo->specColl; status = rsSubStructFileMkdir( rsComm, &subFile ); } else { memset( &fileMkdirInp, 0, sizeof( fileMkdirInp ) ); rstrcpy( fileMkdirInp.dirName, dataObjInfo->filePath, MAX_NAME_LEN ); rstrcpy( fileMkdirInp.rescHier, dataObjInfo->rescHier, MAX_NAME_LEN ); rstrcpy( fileMkdirInp.addr.hostAddr, location.c_str(), NAME_LEN ); fileMkdirInp.mode = getDefDirMode(); status = rsFileMkdir( rsComm, &fileMkdirInp ); } return status; }
int mountFileDir (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp, char *filePath, rescInfo_t *rescInfo) { collInp_t collCreateInp; int rescTypeInx; int status; fileStatInp_t fileStatInp; rodsStat_t *myStat = NULL; rodsObjStat_t *rodsObjStatOut = NULL; if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL); status = collStat (rsComm, phyPathRegInp, &rodsObjStatOut); if (status < 0) return status; if (rodsObjStatOut->specColl != NULL) { freeRodsObjStat (rodsObjStatOut); rodsLog (LOG_ERROR, "mountFileDir: %s already mounted", phyPathRegInp->objPath); return (SYS_MOUNT_MOUNTED_COLL_ERR); } freeRodsObjStat (rodsObjStatOut); if (isCollEmpty (rsComm, phyPathRegInp->objPath) == False) { rodsLog (LOG_ERROR, "mountFileDir: collection %s not empty", phyPathRegInp->objPath); return (SYS_COLLECTION_NOT_EMPTY); } memset (&fileStatInp, 0, sizeof (fileStatInp)); rstrcpy (fileStatInp.fileName, filePath, MAX_NAME_LEN); rescTypeInx = rescInfo->rescTypeInx; fileStatInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType; rstrcpy (fileStatInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); status = rsFileStat (rsComm, &fileStatInp, &myStat); if (status < 0) { fileMkdirInp_t fileMkdirInp; rodsLog (LOG_NOTICE, "mountFileDir: rsFileStat failed for %s, status = %d, create it", fileStatInp.fileName, status); memset (&fileMkdirInp, 0, sizeof (fileMkdirInp)); rstrcpy (fileMkdirInp.dirName, filePath, MAX_NAME_LEN); fileMkdirInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType; fileMkdirInp.mode = getDefDirMode (); rstrcpy (fileMkdirInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); status = rsFileMkdir (rsComm, &fileMkdirInp); if (status < 0) { return (status); } } else if ((myStat->st_mode & S_IFDIR) == 0) { rodsLog (LOG_ERROR, "mountFileDir: phyPath %s is not a directory", fileStatInp.fileName); free (myStat); return (USER_FILE_DOES_NOT_EXIST); } free (myStat); /* mk the collection */ memset (&collCreateInp, 0, sizeof (collCreateInp)); rstrcpy (collCreateInp.collName, phyPathRegInp->objPath, MAX_NAME_LEN); addKeyVal (&collCreateInp.condInput, COLLECTION_TYPE_KW, MOUNT_POINT_STR); addKeyVal (&collCreateInp.condInput, COLLECTION_INFO1_KW, filePath); addKeyVal (&collCreateInp.condInput, COLLECTION_INFO2_KW, rescInfo->rescName); /* try to mod the coll first */ status = rsModColl (rsComm, &collCreateInp); if (status < 0) { /* try to create it */ status = rsRegColl (rsComm, &collCreateInp); } if (status >= 0) { char outLogPath[MAX_NAME_LEN]; int status1; /* see if the phyPath is mapped into a real collection */ if (getLogPathFromPhyPath (filePath, rescInfo, outLogPath) >= 0 && strcmp (outLogPath, phyPathRegInp->objPath) != 0) { /* log path not the same as input objPath */ if (isColl (rsComm, outLogPath, NULL) >= 0) { modAccessControlInp_t modAccessControl; /* it is a real collection. better set the collection * to read-only mode because any modification to files * through this mounted collection can be trouble */ bzero (&modAccessControl, sizeof (modAccessControl)); modAccessControl.accessLevel = "read"; modAccessControl.userName = rsComm->clientUser.userName; modAccessControl.zone = rsComm->clientUser.rodsZone; modAccessControl.path = phyPathRegInp->objPath; status1 = rsModAccessControl(rsComm, &modAccessControl); if (status1 < 0) { rodsLog (LOG_NOTICE, "mountFileDir: rsModAccessControl err for %s, stat = %d", phyPathRegInp->objPath, status1); } } } } return (status); }
int mountFileDir (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp, char *filePath, rescInfo_t *rescInfo) { collInp_t collCreateInp; int rescTypeInx; int status; fileStatInp_t fileStatInp; rodsStat_t *myStat = NULL; rodsObjStat_t *rodsObjStatOut = NULL; status = collStat (rsComm, phyPathRegInp, &rodsObjStatOut); if (status < 0) return status; if (rodsObjStatOut->specColl != NULL) { free (rodsObjStatOut); rodsLog (LOG_ERROR, "mountFileDir: %s already mounted", phyPathRegInp->objPath); return (SYS_MOUNT_MOUNTED_COLL_ERR); } free (rodsObjStatOut); if (isCollEmpty (rsComm, phyPathRegInp->objPath) == False) { rodsLog (LOG_ERROR, "mountFileDir: collection %s not empty", phyPathRegInp->objPath); return (SYS_COLLECTION_NOT_EMPTY); } memset (&fileStatInp, 0, sizeof (fileStatInp)); rstrcpy (fileStatInp.fileName, filePath, MAX_NAME_LEN); rescTypeInx = rescInfo->rescTypeInx; fileStatInp.fileType = RescTypeDef[rescTypeInx].driverType; rstrcpy (fileStatInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); status = rsFileStat (rsComm, &fileStatInp, &myStat); if (status < 0) { fileMkdirInp_t fileMkdirInp; rodsLog (LOG_NOTICE, "mountFileDir: rsFileStat failed for %s, status = %d, create it", fileStatInp.fileName, status); memset (&fileMkdirInp, 0, sizeof (fileMkdirInp)); rstrcpy (fileMkdirInp.dirName, filePath, MAX_NAME_LEN); fileMkdirInp.fileType = RescTypeDef[rescTypeInx].driverType; fileMkdirInp.mode = DEFAULT_DIR_MODE; rstrcpy (fileMkdirInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); status = rsFileMkdir (rsComm, &fileMkdirInp); if (status < 0) { return (status); } } else if ((myStat->st_mode & S_IFDIR) == 0) { rodsLog (LOG_ERROR, "mountFileDir: phyPath %s is not a directory", fileStatInp.fileName); free (myStat); return (USER_FILE_DOES_NOT_EXIST); } free (myStat); /* mk the collection */ memset (&collCreateInp, 0, sizeof (collCreateInp)); rstrcpy (collCreateInp.collName, phyPathRegInp->objPath, MAX_NAME_LEN); addKeyVal (&collCreateInp.condInput, COLLECTION_TYPE_KW, MOUNT_POINT_STR); addKeyVal (&collCreateInp.condInput, COLLECTION_INFO1_KW, filePath); addKeyVal (&collCreateInp.condInput, COLLECTION_INFO2_KW, rescInfo->rescName); /* try to mod the coll first */ status = rsModColl (rsComm, &collCreateInp); if (status < 0) { /* try to create it */ status = rsRegColl (rsComm, &collCreateInp); } return (status); }