Esempio n. 1
0
/**
 * @brief getatt_aux Fills a fattr3_atributes with iRODS object attributes.
 * Unfortunately only two attributes were possible to be mapped, until now.
 * @param comm Connection variable
 * @param path Path to the corresponding object (directory or file)
 * @param fattr3_atributes
 *
 * Example of use:
 *  fattr3 fattr3_atributes;
    rcComm_t* comm = rodsConnect();
    int i = rodsLogin(comm);
    char* path = "tempZone/home/desiredFile.txt");
    getatt_aux(comm, path, &fattr3_atributes);
    printf("Type: %d\n", fattr3_atributes.type);
    printf("Size: %d\n", fattr3_atributes.size);
 */
int getatt_aux(nfs_fh3 fh, fattr3 fat, rcComm_t* comm, char *path, int *size)
{
    dataObjInp_t dataObjInp;
    rodsObjStat_t *rodsObjStatOut = NULL;
    bzero (&dataObjInp, sizeof (dataObjInp));
    rstrcpy (dataObjInp.objPath, path, MAX_NAME_LEN);
    int status = rcObjStat (comm, &dataObjInp, &rodsObjStatOut);

    if (status < 0)
    {
        debug("GETATT - Error - The call to iRODS was unsuccessful searching the file %s.\n", path);
    }
    else
    {
        *size = rodsObjStatOut->objSize;

        /*It is necessary to change the attributes locally (executing a SETATT)
         *  to avoid the NFS Stale File Handle error.*/
        set_aux(fh, fat, path, size);

    }
    return status;

    freeRodsObjStat (rodsObjStatOut);
}
Esempio n. 2
0
int irods_reli_stat ( const char *host, const char *path, struct pfs_stat *info )
{
	int result;
	dataObjInp_t request;
	rodsObjStat_t *response = 0;

	/* Special case: /irods looks like an empty dir */

	if(!host[0]) {
		memset(info,0,sizeof(*info));
		info->st_ino = 2;
		info->st_dev = -1;
		info->st_mode = S_IFDIR | 0755;
		info->st_size = 4096;
		info->st_blocks = 8;
		info->st_nlink = 1;
		return 0;
	}

	struct irods_server *server = connect_to_host(host);
	if(!server) return -1;

	memset(&request,0,sizeof(request));
	strcpy(request.objPath,path);

	debug(D_IRODS,"rcObjStat %s %s",host,path);
	result = rcObjStat (server->conn,&request,&response);
	debug(D_IRODS,"= %d",result);

	if(result<0) {
		errno = irods_reli_errno(result);
		return -1;
	}

	memset(info,0,sizeof(*info));

	info->st_ino = hash_string(path);
	info->st_dev = -1;

	if (response->objType == COLL_OBJ_T) {
		info->st_mode = S_IFDIR | 0755;
		info->st_size = 4096;
		info->st_blocks = 8;
		info->st_ctime = atoi (response->createTime);
		info->st_mtime = atoi (response->modifyTime);
		info->st_nlink = 1;
	} else {
		info->st_mode = S_IFREG | 0755;
		info->st_size = response->objSize;
		info->st_blocks = info->st_size/512+1;
		info->st_nlink = 1;
	}

	info->st_blksize = 4096;
	info->st_ctime = atoi(response->createTime);
	info->st_mtime = atoi(response->modifyTime);
	info->st_atime = atoi(response->modifyTime);

	free(response);

	return 0;
}
Esempio n. 3
0
int
rsObjStat (rsComm_t *rsComm, dataObjInp_t *dataObjInp,
rodsObjStat_t **rodsObjStatOut)
{
    int status;
    rodsServerHost_t *rodsServerHost = NULL;
    specCollCache_t *specCollCache = NULL;
    int linkCnt;

    linkCnt = resolveLinkedPath (rsComm, dataObjInp->objPath, &specCollCache, 
      NULL);

    *rodsObjStatOut = NULL;
    status = getAndConnRcatHost (rsComm, SLAVE_RCAT, dataObjInp->objPath,
      &rodsServerHost);
    if (status < 0) {
       return(status);
    }
    if (rodsServerHost->localFlag == LOCAL_HOST) {
#ifdef RODS_CAT
        status = _rsObjStat (rsComm, dataObjInp, rodsObjStatOut);
#else
        status = SYS_NO_RCAT_SERVER_ERR;
#endif
    } else {
	if (isLocalZone (dataObjInp->objPath)) {
	    /* Since the iCat is on a remote host, see if it is a sub path of 
             * a cached specColl locally first. If it is, it will save time 
             * resolving it */
            status = statPathInSpecColl (rsComm, dataObjInp->objPath, 1,
              rodsObjStatOut);
	    if (status >= 0) {
		/* the path is in a specColl */
		return status;
	    } else if (status != SYS_SPEC_COLL_NOT_IN_CACHE) {
		/* path is in the path of specColl cache but does not exist */
                if (linkCnt > 0 && *rodsObjStatOut != NULL) {
		    /* a soft link - returns specColl */
                    if ((*rodsObjStatOut)->specColl == NULL) {
                        replSpecColl (&specCollCache->specColl,
                          &(*rodsObjStatOut)->specColl);
                    }
                    rstrcpy ((*rodsObjStatOut)->specColl->objPath, 
		      dataObjInp->objPath, MAX_NAME_LEN);
                }
		return status;
	    }
	    /* falls through if the path is not in a cached specColl */
	}
	/* not in cache, need to do a remote call */
        status = rcObjStat (rodsServerHost->conn, dataObjInp, 
	  rodsObjStatOut);
	if (status >= 0 && (*rodsObjStatOut)->specColl != NULL) {
	    /* queue it in cache */
	    queueSpecCollCacheWithObjStat (*rodsObjStatOut);
	}
    }

    if (linkCnt > 0 && *rodsObjStatOut != NULL) {
	/* fill in (*rodsObjStatOut)->specColl if it is linked */
        if ((*rodsObjStatOut)->specColl == NULL) {
            replSpecColl (&specCollCache->specColl,
              &(*rodsObjStatOut)->specColl);
	}
	rstrcpy ((*rodsObjStatOut)->specColl->objPath, dataObjInp->objPath, 
	  MAX_NAME_LEN);
    }
    return (status);
}
Esempio n. 4
0
int
_irodsGetattr (iFuseConn_t *iFuseConn, const char *path, struct stat *stbuf)
{
    int status;
    dataObjInp_t dataObjInp;
    rodsObjStat_t *rodsObjStatOut = NULL;
#ifdef CACHE_FUSE_PATH
    pathCache_t *tmpPathCache;
#endif

    rodsLog (LOG_DEBUG, "_irodsGetattr: %s", path);

#ifdef CACHE_FUSE_PATH

    /*if (lookupPathNotExist( (char *) path) == 1) {
        rodsLog (LOG_DEBUG, "irodsGetattr: a match for non existing path %s", path);
        return -ENOENT;
    }*/

    if (matchAndLockPathCache ((char *) path, &tmpPathCache) == 1) {
        rodsLog (LOG_DEBUG, "irodsGetattr: a match for path %s", path);
        if (tmpPathCache->fileCache != NULL) {
            LOCK_STRUCT(*(tmpPathCache->fileCache));
            if(tmpPathCache->fileCache->state == HAVE_NEWLY_CREATED_CACHE) {
                status = _updatePathCacheStatFromFileCache (tmpPathCache);
                UNLOCK_STRUCT(*(tmpPathCache->fileCache));
                UNLOCK_STRUCT(*tmpPathCache);
                if (status < 0) {
                    clearPathFromCache ((char *) path);
                } else {
                    *stbuf = tmpPathCache->stbuf;
                    return (0);
                }
            } else {
                UNLOCK_STRUCT(*(tmpPathCache->fileCache));
                UNLOCK_STRUCT(*tmpPathCache);
            }
        } else {
            UNLOCK_STRUCT(*tmpPathCache);
        }
    }
#endif

    memset (stbuf, 0, sizeof (struct stat));
    memset (&dataObjInp, 0, sizeof (dataObjInp));
    status = parseRodsPathStr ((char *) (path + 1) , &MyRodsEnv, dataObjInp.objPath);
    if (status < 0) {
        rodsLogError (LOG_ERROR, status,
                      "irodsGetattr: parseRodsPathStr of %s error", path);
        /* use ENOTDIR for this type of error */
        return -ENOTDIR;
    }
    status = rcObjStat (iFuseConn->conn, &dataObjInp, &rodsObjStatOut);
    if (status < 0) {
        if (isReadMsgError (status)) {
            ifuseReconnect (iFuseConn);
            status = rcObjStat (iFuseConn->conn, &dataObjInp, &rodsObjStatOut);
        }
        if (status < 0) {
            if (status != USER_FILE_DOES_NOT_EXIST) {
                rodsLogError (LOG_ERROR, status,
                              "irodsGetattr: rcObjStat of %s error", path);
            }
#ifdef CACHE_FUSE_PATH
            pathNotExist ((char *) path);
#endif
            return -ENOENT;
        }
    }

    if (rodsObjStatOut->objType == COLL_OBJ_T) {
        fillDirStat (stbuf,
                     atoi (rodsObjStatOut->createTime), atoi (rodsObjStatOut->modifyTime),
                     atoi (rodsObjStatOut->modifyTime));
    } else if (rodsObjStatOut->objType == UNKNOWN_OBJ_T) {
        pathNotExist ((char *) path);
        if (rodsObjStatOut != NULL) freeRodsObjStat (rodsObjStatOut);
        return -ENOENT;
    } else {
        fillFileStat (stbuf, rodsObjStatOut->dataMode, rodsObjStatOut->objSize,
                      atoi (rodsObjStatOut->createTime), atoi (rodsObjStatOut->modifyTime),
                      atoi (rodsObjStatOut->modifyTime));
    }

    if (rodsObjStatOut != NULL)
        freeRodsObjStat (rodsObjStatOut);

    /* don't set file cache */
    pathExist ((char *) path, NULL, stbuf, &tmpPathCache);
    return 0;
}