int irodsTruncate (const char *path, off_t size) { dataObjInp_t dataObjInp; int status; pathCache_t *tmpPathCache; iFuseConn_t *iFuseConn = NULL; rodsLog (LOG_DEBUG, "irodsTruncate: %s", path); if (matchAndLockPathCache ((char *) path, &tmpPathCache) == 1) { if(tmpPathCache->fileCache != NULL) { LOCK_STRUCT(*tmpPathCache->fileCache); if(tmpPathCache->fileCache->state == HAVE_NEWLY_CREATED_CACHE) { status = truncate (tmpPathCache->fileCache->fileCachePath, size); if (status >= 0) { updatePathCacheStatFromFileCache (tmpPathCache); UNLOCK_STRUCT(*(tmpPathCache->fileCache)); UNLOCK_STRUCT(*tmpPathCache); return (0); } } UNLOCK_STRUCT(*(tmpPathCache->fileCache)); } } UNLOCK_STRUCT(*tmpPathCache); memset (&dataObjInp, 0, sizeof (dataObjInp)); status = parseRodsPathStr ((char *) (path + 1) , &MyRodsEnv, dataObjInp.objPath); if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsTruncate: parseRodsPathStr of %s error", path); /* use ENOTDIR for this type of error */ return -ENOTDIR; } dataObjInp.dataSize = size; getAndUseIFuseConn (&iFuseConn, &MyRodsEnv); RECONNECT_IF_NECESSARY(status, iFuseConn, rcDataObjTruncate (iFuseConn->conn, &dataObjInp)); if (status >= 0) { pathCache_t *tmpPathCache; if (matchAndLockPathCache ((char *) path, &tmpPathCache) == 1) { tmpPathCache->stbuf.st_size = size; } UNLOCK_STRUCT(*tmpPathCache); status = 0; } else { rodsLogError (LOG_ERROR, status, "irodsTruncate: rcDataObjTruncate of %s error", path); status = -ENOENT; } unuseIFuseConn (iFuseConn); return (status); }
int irodsRmdir (const char *path) { collInp_t collInp; int status; iFuseConn_t *iFuseConn = NULL; rodsLog (LOG_DEBUG, "irodsRmdir: %s", path); memset (&collInp, 0, sizeof (collInp)); status = parseRodsPathStr ((char *) (path + 1) , &MyRodsEnv, collInp.collName); if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsRmdir: parseRodsPathStr of %s error", path); /* use ENOTDIR for this type of error */ return -ENOTDIR; } addKeyVal (&collInp.condInput, FORCE_FLAG_KW, ""); getAndUseIFuseConn (&iFuseConn, &MyRodsEnv); RECONNECT_IF_NECESSARY(status, iFuseConn, rcRmColl (iFuseConn->conn, &collInp, 0)); if (status >= 0) { #ifdef CACHE_FUSE_PATH pathNotExist ((char *) path); #endif status = 0; } else { rodsLogError (LOG_ERROR, status, "irodsRmdir: rcRmColl of %s error", path); status = -ENOENT; } unuseIFuseConn (iFuseConn); clearKeyVal (&collInp.condInput); return (status); }
int _iFuseFileCacheFlush( fileCache_t *fileCache ) { int status = 0; int objFd; /* simply return if no file cache or the file cache hasn't been updated */ if ( fileCache->state != HAVE_NEWLY_CREATED_CACHE ) { //UNLOCK_STRUCT( *fileCache ); return 0; } /* no need to flush cache file as we are using low-level io */ /*status = fsync (fileCache->iFd); if (status < 0) { status = (errno ? (-1 * errno) : -1); rodsLog (LOG_ERROR, "ifuseFlush: flush of cache file for %s error, status = %d", fileCache->localPath, status); return -EBADF; }*/ struct stat stbuf; int error_code = stat( fileCache->fileCachePath, &stbuf ); if ( error_code != 0 ) { rodsLog( LOG_ERROR, "stat failed in _iFuseFileCacheFlush with status %d", error_code ); } /* put cache file to server */ //UNLOCK_STRUCT( *fileCache ); iFuseConn_t *conn = getAndUseConnByPath( fileCache->localPath, &status ); //LOCK_STRUCT( *fileCache ); RECONNECT_IF_NECESSARY( status, conn, ifusePut( conn->conn, fileCache->objPath, fileCache->fileCachePath, fileCache->mode, stbuf.st_size ) ); unuseIFuseConn( conn ); if ( status < 0 ) { rodsLog( LOG_ERROR, "ifuseClose: ifusePut of %s error, status = %d", fileCache->localPath, status ); status = -EBADF; return status; } objFd = status; if ( stbuf.st_size > MAX_READ_CACHE_SIZE ) { /* too big to keep */ /* close cache file */ status = close( fileCache->iFd ); if ( status < 0 ) { status = ( errno ? ( -1 * errno ) : -1 ); rodsLog( LOG_ERROR, "ifuseClose: close of cache file for %s error, status = %d", fileCache->localPath, status ); return -EBADF; } fileCache->iFd = objFd; fileCache->state = NO_FILE_CACHE; fileCache->offset = 0; status = objFd; } else { fileCache->state = HAVE_READ_CACHE; } return status; }
int irodsChmod (const char *path, mode_t mode) { int status; modDataObjMeta_t modDataObjMetaInp; keyValPair_t regParam; dataObjInfo_t dataObjInfo; char dataMode[SHORT_STR_LEN]; pathCache_t *tmpPathCache; iFuseConn_t *iFuseConn = NULL; rodsLog (LOG_DEBUG, "irodsChmod: %s", path); matchAndLockPathCache((char *) path, &tmpPathCache); if (tmpPathCache->fileCache != NULL) { LOCK_STRUCT(*tmpPathCache->fileCache); if(tmpPathCache->fileCache->state == HAVE_NEWLY_CREATED_CACHE) { /* has not actually been created yet */ tmpPathCache->fileCache->mode = mode; UNLOCK_STRUCT(*tmpPathCache->fileCache); UNLOCK_STRUCT(*tmpPathCache); return (0); } UNLOCK_STRUCT(*tmpPathCache->fileCache); } UNLOCK_STRUCT(*tmpPathCache); if(tmpPathCache->stbuf.st_nlink != 1) { rodsLog (LOG_NOTICE, "irodsChmod: modification of the mode of non file object is currently not supported", path); return 0; } memset (®Param, 0, sizeof (regParam)); snprintf (dataMode, SHORT_STR_LEN, "%d", mode); addKeyVal (®Param, DATA_MODE_KW, dataMode); addKeyVal (®Param, ALL_KW, ""); memset(&dataObjInfo, 0, sizeof(dataObjInfo)); status = parseRodsPathStr ((char *) (path + 1) , &MyRodsEnv, dataObjInfo.objPath); if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsChmod: parseRodsPathStr of %s error", path); /* use ENOTDIR for this type of error */ return -ENOTDIR; } modDataObjMetaInp.regParam = ®Param; modDataObjMetaInp.dataObjInfo = &dataObjInfo; getAndUseIFuseConn (&iFuseConn, &MyRodsEnv); RECONNECT_IF_NECESSARY(status, iFuseConn, rcModDataObjMeta(iFuseConn->conn, &modDataObjMetaInp)); if (status >= 0) { #ifdef CACHE_FUSE_PATH pathCache_t *tmpPathCache; if (matchAndLockPathCache ((char *) path, &tmpPathCache) == 1) { tmpPathCache->stbuf.st_mode &= 0xfffffe00; tmpPathCache->stbuf.st_mode |= (mode & 0777); UNLOCK_STRUCT(*tmpPathCache); } #endif status = 0; } else { rodsLogError(LOG_ERROR, status, "irodsChmod: rcModDataObjMeta failure"); status = -ENOENT; } unuseIFuseConn (iFuseConn); clearKeyVal (®Param); return(status); }