int rsStreamRead (rsComm_t *rsComm, fileReadInp_t *streamReadInp, bytesBuf_t *streamReadOutBBuf) { int fileInx = streamReadInp->fileInx; int status; if (fileInx < 3 || fileInx >= NUM_FILE_DESC) { rodsLog (LOG_ERROR, "rsStreamRead: fileInx %d out of range", fileInx); return (SYS_FILE_DESC_OUT_OF_RANGE); } if (FileDesc[fileInx].inuseFlag != FD_INUSE) return SYS_BAD_FILE_DESCRIPTOR; if (FileDesc[fileInx].fileName == NULL) return SYS_INVALID_FILE_PATH; if (strcmp (FileDesc[fileInx].fileName, STREAM_FILE_NAME) != 0) { rodsLog (LOG_ERROR, "rsStreamRead: fileName %s is invalid for stream", FileDesc[fileInx].fileName); return SYS_INVALID_FILE_PATH; } status = rsFileRead (rsComm, streamReadInp, streamReadOutBBuf); #if 0 /* need to close explicitly */ if (status <= 0) { fileCloseInp_t fileCloseInp; /* the end or error */ fileCloseInp.fileInx = fileInx; rsFileClose (rsComm, &fileCloseInp); } #endif return status; }
pathnamePatterns_t * readPathnamePatternsFromFile(rsComm_t *rsComm, char *filename, rescInfo_t *rescInfo) { int status; rodsStat_t *stbuf; fileStatInp_t fileStatInp; bytesBuf_t fileReadBuf; fileOpenInp_t fileOpenInp; fileReadInp_t fileReadInp; fileCloseInp_t fileCloseInp; int buf_len, fd; pathnamePatterns_t *pp; if (rsComm == NULL || filename == NULL || rescInfo == NULL) { return NULL; } memset(&fileStatInp, 0, sizeof(fileStatInp)); rstrcpy(fileStatInp.fileName, filename, MAX_NAME_LEN); fileStatInp.fileType = (fileDriverType_t)RescTypeDef[rescInfo->rescTypeInx].driverType; rstrcpy(fileStatInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); status = rsFileStat(rsComm, &fileStatInp, &stbuf); if (status != 0) { if (status != UNIX_FILE_STAT_ERR - ENOENT) { rodsLog(LOG_DEBUG, "readPathnamePatternsFromFile: can't stat %s. status = %d", fileStatInp.fileName, status); } return NULL; } buf_len = stbuf->st_size; free(stbuf); memset(&fileOpenInp, 0, sizeof(fileOpenInp)); rstrcpy(fileOpenInp.fileName, filename, MAX_NAME_LEN); fileOpenInp.fileType = (fileDriverType_t)RescTypeDef[rescInfo->rescTypeInx].driverType; rstrcpy(fileOpenInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); fileOpenInp.flags = O_RDONLY; fd = rsFileOpen(rsComm, &fileOpenInp); if (fd < 0) { rodsLog(LOG_NOTICE, "readPathnamePatternsFromFile: can't open %s for reading. status = %d", fileOpenInp.fileName, fd); return NULL; } memset(&fileReadBuf, 0, sizeof(fileReadBuf)); fileReadBuf.buf = malloc(buf_len); if (fileReadBuf.buf == NULL) { rodsLog(LOG_NOTICE, "readPathnamePatternsFromFile: could not malloc buffer"); return NULL; } memset(&fileReadInp, 0, sizeof(fileReadInp)); fileReadInp.fileInx = fd; fileReadInp.len = buf_len; status = rsFileRead(rsComm, &fileReadInp, &fileReadBuf); memset(&fileCloseInp, 0, sizeof(fileCloseInp)); fileCloseInp.fileInx = fd; rsFileClose(rsComm, &fileCloseInp); if (status < 0) { rodsLog(LOG_NOTICE, "readPathnamePatternsFromFile: could not read %s. status = %d", fileOpenInp.fileName, status); free(fileReadBuf.buf); return NULL; } pp = readPathnamePatterns((char*)fileReadBuf.buf, buf_len); return pp; }
irods::error test_source_replica_for_write_permissions( rsComm_t* _comm, dataObjInfo_t* _data_obj_info ) { if( !_comm || !_data_obj_info ) { return ERROR( SYS_INTERNAL_NULL_INPUT_ERR, "null _data_obj_info or _comm" ); } std::string location; irods::error ret = irods::get_loc_for_hier_string( _data_obj_info->rescHier, location ); if ( !ret.ok() ) { return PASS( ret ); } // test the source hier to determine if we have write access to the data // stored. if not then we cannot unlink that replica and should throw an // error. fileOpenInp_t open_inp; memset( &open_inp, 0, sizeof( open_inp ) ); open_inp.mode = getDefFileMode(); open_inp.flags = O_WRONLY; rstrcpy( open_inp.resc_name_, _data_obj_info->rescName, MAX_NAME_LEN ); rstrcpy( open_inp.resc_hier_, _data_obj_info->rescHier, MAX_NAME_LEN ); rstrcpy( open_inp.objPath, _data_obj_info->objPath, MAX_NAME_LEN ); rstrcpy( open_inp.addr.hostAddr, location.c_str(), NAME_LEN ); rstrcpy( open_inp.fileName, _data_obj_info->filePath, MAX_NAME_LEN ); rstrcpy( open_inp.in_pdmo, _data_obj_info->in_pdmo, MAX_NAME_LEN ); // kv passthru copyKeyVal( &_data_obj_info->condInput, &open_inp.condInput ); int l3_idx = rsFileOpen( _comm, &open_inp ); clearKeyVal( &open_inp.condInput ); if( l3_idx < 0 ) { std::string msg = "unable to open "; msg += _data_obj_info->objPath; msg += " for unlink"; addRErrorMsg( &_comm->rError, SYS_USER_NO_PERMISSION, msg.c_str() ); return ERROR( SYS_USER_NO_PERMISSION, msg ); } fileCloseInp_t close_inp; memset( &close_inp, 0, sizeof( close_inp ) ); close_inp.fileInx = l3_idx; int status = rsFileClose( _comm, &close_inp ); if( status < 0 ) { std::string msg = "failed to close "; msg += _data_obj_info->objPath; return ERROR( status, msg ); } return SUCCESS(); } // test_source_replica_for_write_permissions