static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
		       off_t offset, struct fuse_file_info *fi)
{
	fprintf(stderr, "in readdir\n");
	DIR *dp;
	struct dirent *de;

	char fullPath[PATH_MAX];
	stopPath(fullPath, path);

	(void) offset;
	(void) fi;

	dp = opendir(fullPath);
	if (dp == NULL)
		return -errno;

	while ((de = readdir(dp)) != NULL) {
		struct stat st;
		memset(&st, 0, sizeof(st));
		st.st_ino = de->d_ino;
		st.st_mode = de->d_type << 12;
		if (filler(buf, de->d_name, &st, 0))
			break;
	}

	closedir(dp);
	return 0;
}
static int xmp_listxattr(const char *path, char *list, size_t size)
{

	char fullPath[PATH_MAX];
	stopPath(fullPath, path);  
	int res = llistxattr(fullPath, list, size);
	if (res == -1)
		return -errno;
	return res;
}
static int xmp_removexattr(const char *path, const char *name)
{

	char fullPath[PATH_MAX];
	stopPath(fullPath, path);  
	int res = lremovexattr(fullPath, name);
	if (res == -1)
		return -errno;
	return 0;
}
static int xmp_setxattr(const char *path, const char *name, const char *value,
			size_t size, int flags)
{

	char fullPath[PATH_MAX];
	stopPath(fullPath, path);  

	int res = lsetxattr(fullPath, name, value, size, flags);
	if (res == -1)
		return -errno;
	return 0;
}
static int xmp_access(const char *path, int mask)
{
	int res;
	fprintf(stderr, "in access\n");
	char fullPath[PATH_MAX];
	stopPath(fullPath, path);
	res = access(fullPath, mask);
	if (res == -1)
		return -errno;

	return 0;
}
static int xmp_statfs(const char *path, struct statvfs *stbuf)
{
	char fullPath[PATH_MAX];
	stopPath(fullPath, path);  
	int res;

	res = statvfs(fullPath, stbuf);
	if (res == -1)
		return -errno;

	return 0;
}
static int xmp_unlink(const char *path)
{
	char fullPath[PATH_MAX];
	stopPath(fullPath, path);

	int res;

	res = unlink(fullPath);
	if (res == -1)
		return -errno;

	return 0;
}
static int xmp_mkdir(const char *path, mode_t mode)
{
	fprintf(stderr, "in mkdir\n");
	int res;
	char fullPath[PATH_MAX];
	stopPath(fullPath, path);

	res = mkdir(fullPath, mode);
	if (res == -1)
		return -errno;

	return 0;
}
static int xmp_open(const char *path, struct fuse_file_info *fi)
{
	fprintf(stderr, "in get open\n");
	int res;
	char fullPath[PATH_MAX];
	stopPath(fullPath, path);

	res = open(fullPath, fi->flags);
	if (res == -1)
		return -errno;

	close(res);
	return 0;
}
static int xmp_truncate(const char *path, off_t size)
{
	fprintf(stderr, "in truncate\n");
	int res;

	char fullPath[PATH_MAX];
	stopPath(fullPath, path);

	res = truncate(fullPath, size);
	if (res == -1)
		return -errno;

	return 0;
}
static int xmp_chown(const char *path, uid_t uid, gid_t gid)
{
	fprintf(stderr, "in get chown\n");
	int res;

	char fullPath[PATH_MAX];
	stopPath(fullPath, path);

	res = lchown(fullPath, uid, gid);
	if (res == -1)
		return -errno;

	return 0;
}
static int xmp_readlink(const char *path, char *buf, size_t size)
{
	fprintf(stderr, "in get readlink\n");
	int res;
	char fullPath[PATH_MAX];
	stopPath(fullPath, path);

	res = readlink(fullPath, buf, size - 1);//place fullPath into buf and gets rid of the null character
	if (res == -1)
		return -errno;

	buf[res] = '\0';
	return 0;
}
static int xmp_getxattr(const char *path, const char *name, char *value,
			size_t size)
{


	fprintf(stderr, "in get xattr\n");
	char fullPath[PATH_MAX];
	stopPath(fullPath, path);  
	int res = lgetxattr(fullPath, name, value, size);
	if (res == -1)
		return -errno;

	fprintf(stderr, "leaving get xattr\n");
	return res;
}
Example #14
0
void InterpolatedVector::updatePath(float dt)
{
	InterpolatedVectorData *data = ensureData();
	if (data->pathTimer > data->pathTime)
	{
		Vector value = data->path.getPathNode(data->path.getNumPathNodes()-1)->value;
		this->x = value.x;
		this->y = value.y;
		this->z = value.z;
		if (data->loopType != 0)
		{
			if (data->loopType > 0)
				data->loopType -= 1;

			int oldLoopType = data->loopType;

			if (data->pingPong)
			{
				// flip path
				data->path.flip();
				startPath(data->pathTime);
				data->loopType = oldLoopType;
			}
			else
			{
				startPath(data->pathTime);
				data->loopType = oldLoopType;
			}
		}
		else
		{
			stopPath();
		}
	}
	else
	{
		data->pathTimer += dt * data->pathTimeMultiplier;

		float perc = data->pathTimer/data->pathTime;
		Vector value = data->path.getValue(perc);
		this->x = value.x;
		this->y = value.y;
		this->z = value.z;
	}
}
static int xmp_utimens(const char *path, const struct timespec ts[2])
{
	fprintf(stderr, "in utimes\n");
	char fullPath[PATH_MAX];
	stopPath(fullPath, path);
	int res;
	struct timeval tv[2];

	tv[0].tv_sec = ts[0].tv_sec;
	tv[0].tv_usec = ts[0].tv_nsec / 1000;
	tv[1].tv_sec = ts[1].tv_sec;
	tv[1].tv_usec = ts[1].tv_nsec / 1000;

	res = utimes(fullPath, tv);
	if (res == -1)
		return -errno;

	return 0;
}
static int xmp_mknod(const char *path, mode_t mode, dev_t rdev)
{
	fprintf(stderr, "in mknod\n");
	int res;
	char fullPath[PATH_MAX];
	stopPath(fullPath, path);

	/* On Linux this could just be 'mknod(path, mode, rdev)' but this
	   is more portable */
	if (S_ISREG(mode)) {
		res = open(fullPath, O_CREAT | O_EXCL | O_WRONLY, mode);
		if (res >= 0)
			res = close(res);
	} else if (S_ISFIFO(mode))
		res = mkfifo(path, mode);
	else
		res = mknod(path, mode, rdev);
	if (res == -1)
		return -errno;

	return 0;
}
static int xmp_create(const char* path, mode_t mode, struct fuse_file_info* fi) {
	fprintf(stderr, "in create\n");
	FILE *newFile;
	char fullPath[PATH_MAX];
	stopPath(fullPath, path);
	//FILE* outFile;
	//char *outFileText;
	//size_t outFileSize;

	(void)mode;
    (void) fi;

   // int res;
	//outFile=open_memstream(&outFileText,&outFileSize);
	newFile=fopen(fullPath,"w");

	fprintf(stderr, "do_crypts is happening\n\n\n\n");
	if(!do_crypt(newFile, newFile, ENC,key)){
		fprintf(stderr, "do_cryptfailedd\n\n\n\n");
	}


   /* if(res == -1){
	return -errno;
	}*/
	fclose(newFile);

	if(setxattr(fullPath,NAME,"true",strlen("true"),0)){
		fprintf(stderr, "error in xpm create\n\n\n\n\n");

	}
	fprintf(stderr, "leaving create\n");
    

	   //sets attributeds cnositnet name is encrypted failes if the attribute alreads excists could be XATTR_REPLACE should really matter excpeted for maybe deaper security reasons

    return 0;
}
Example #18
0
void InterpolatedVector::updatePath(float dt)
{
	if (!speedPath)
	{
		if (pathTimer > pathTime)
		{
			Vector value = path.getPathNode(path.getNumPathNodes()-1)->value;
			this->x = value.x;
			this->y = value.y;
			this->z = value.z;
			if (loopType != 0)
			{
    			if (loopType > 0)
    				loopType -= 1;

				int oldLoopType = loopType;
				
				if (pingPong)
				{
					// flip path
					path.flip();				
					startPath(pathTime);
					loopType = oldLoopType;
				}
				else
				{
					startPath(pathTime);
					loopType = oldLoopType;
				}
			}
			else
			{
				stopPath();
				endOfPathEvent.call();
			}
		}
		else
		{
			pathTimer += dt * pathTimeMultiplier;
				
			//	;//dt*timeSpeedMultiplier;
			float perc = pathTimer/pathTime;
			Vector value = path.getValue(perc);
			this->x = value.x;
			this->y = value.y;
			this->z = value.z;

			

			/*
			std::ostringstream os;
			os << "nodes: " << path.getNumPathNodes() << " pathTimer: " << pathTimer << " pathTime: " << pathTime << " perc: " << perc << " p(" << x << ", " << y << ")";
			debugLog(os.str());
			*/
			/*
			float diff = pathTime - pathTimer;
			if (timeSpeedEase > 0)
			{
				float secs = 1.0/timeSpeedEase;
				if (diff <= secs)
				{
					timeSpeedMultiplier -= dt*timeSpeedEase;
					if (timeSpeedMultiplier < 0.1)
						timeSpeedMultiplier = 0.1;
				}
			}
			if (timeSpeedMultiplier < 1)
			{
				timeSpeedMultiplier += dt*timeSpeedEase;
				if (timeSpeedMultiplier >= 1)
					timeSpeedMultiplier = 1;
			}
			*/
			
		}
	}
	else
	{
		if (!isInterpolating())
		{
			currentPathNode++;
			VectorPathNode *node = path.getPathNode(currentPathNode);
			/*
			if (node)
			{
				
			}
			else
			{
				stopPath();
				endOfPathEvent.call();
			}
			*/
			if (node)
			{
				interpolateTo(node->value, (node->value - Vector(this->x, this->y, this->z)).getLength3D()*(1.0/pathSpeed));
			}
			else
			{
				// handle looping etc
				stopPath();
				endOfPathEvent.call();
			}
		}
	}
}
static int xmp_getattr(const char *path, struct stat *stbuf)
{
	struct stat *tmpFileStats;
	tmpFileStats=(struct stat *) malloc(sizeof(struct stat));	
	fprintf(stderr, "in getattr\n");
	FILE* posEnc;
	FILE* decrypedFile;
	int action;
	ssize_t size;
	int res;
	char fullPath[PATH_MAX];
	stopPath(fullPath, path);
	fprintf(stderr, "full path %s\n",fullPath);
	res = lstat(fullPath, stbuf);
	if(res==-1){
		return -errno;
	}



	//for now do with a tmparary file there has got to be a better way
	char tPath[PATH_MAX];
	stopPath(tPath,"/tFile.txt");
	

	
	if (res == -1){
		fprintf(stderr, "leaving getattr with error\n");
		return -errno;

	}

	if(S_ISREG(stbuf->st_mode)){
		//size=getxattr(fullPath, NAME,NULL,0);
		size=getxattr(fullPath,NAME,NULL,0);
		char *attr;
		if(size<0){
			if(errno==ENODATA){
				return 0;
			}else{
				fprintf(stderr,"major issure here ////////////////////////////////////\n");
				exit(EXIT_FAILURE);
			}
		}
		attr= malloc(sizeof(*attr)*(size+1));
		//char att[4];//might have to malloc
		size=getxattr(fullPath,NAME,attr,size);
		attr[size]='\0';

		if(strcmp(attr, "true")){


			fprintf(stderr,"why have the attirbute equal to anything but true/////////////\n\n\n\n");
			action=-1;

		}else{
			action =DEC;
		
		}
		posEnc=fopen(fullPath,"r");
		decrypedFile=fopen(tPath,"w");

		if(!do_crypt(posEnc,decrypedFile,action,key)){
			fprintf(stderr,"do crypt failed in getattr////////////////\n");
		
		}
		fclose(posEnc);
		fclose(decrypedFile);
		free(attr);

	

		
			int tmpres=lstat(tPath,tmpFileStats);
			if(tmpres==-1){
				fprintf(stderr,"tmppres in getattr was -1\n");
				return -errno;
			
			stbuf->st_size=tmpFileStats->st_size;
			stbuf->st_blocks=tmpFileStats->st_blocks;
			stbuf->st_blksize=tmpFileStats->st_blksize;
			
		}
		
		


	}

	remove(tPath);

	//free(tmpFileStats);//do i need this?
	fprintf(stderr, "leaving getattr\n");
	
	return 0;
}
static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
		    struct fuse_file_info *fi)
{
	fprintf(stderr, "In read\n");
	int fd;
	int res;
	//int action=DEC;
	FILE* inFile;
	//char* outFileStart;
	//size_t outFileSize;
	//FILE* outFile;




	//findif better way to do this
	char pathT[PATH_MAX];
	stopPath(pathT,"/tmpreadfile.txt");
	FILE *fileT;
	

	char fullPath[PATH_MAX];
	stopPath(fullPath, path);

	(void) fi;
	
	if(isEncrypted(fullPath)){
		//action=DEC;
		inFile=fopen(fullPath, "r");
		fileT=fopen(pathT,"w");
		do_crypt(inFile,fileT,DEC,key);
		fclose(inFile);
		fclose(fileT);
		fd=open(pathT,O_RDONLY);
		res=pread(fd,buf,size,offset);
		if(res==-1){
			res=-errno;
		}
		close(fd);
		remove(pathT);
		return res;

	}else{
		fd=open(fullPath,O_RDONLY);
		res=pread(fd,buf,size,offset);
		if(res==-1){
			res=-errno;
		}
		close(fd);
		remove(pathT);
		return res;
		
	}
/*
	inFile = fopen(fullPath, "r");
	fileT=fopen(pathT,"w");
	//outFile=open_memstream(&outFileStart,&outFileSize);//opens stream to be written t
	fprintf(stderr, "do_crypts is happening\n\n\n\n");
	if(!do_crypt(inFile,fileT,action,key)){
		fprintf(stderr, "do_cryptfailrd\n\n\n\n");
		
	}//come back to

	fclose(inFile);
	fclose(fileT);

	fd=open(tmpPath,O_RDONLY);


	//if (fd == -1)
		//return -errno;
	//fseek(fd,offset,SEEK_SET);
	res = pread(fd,buf,size,offset);
	if (res == -1)
		res = -errno;
	close(fd);
	remove(tmpPath);
	return res;//return number of bytes written*/
}
static int xmp_write(const char *path, const char *buf, size_t size,
		     off_t offset, struct fuse_file_info *fi)
{
	fprintf(stderr, "in Write\n");
	int fd;
	int res;
	//size_t inFileSize;
	char fullPath[PATH_MAX];
	stopPath(fullPath, path);  
 	//int action=0;
	//int revAction=1;
	//char* inFileStart;

	FILE* inFile;
	//FILE* outFile;
	FILE* fileT;

	char pathT[PATH_MAX];
	stopPath(pathT,"/tmpFile");
	


	(void) fi;
	//inFile=fopen(fullPath,"r");
	 //fileT=fopen(pathT,"w");

	//outFile=fopen(fullPath,"r");
	
	//fd = open(path, O_WRONLY);
	//inFile=open_memstream(&inFileStart,&inFileSize);
	//fwrite(buf,size,sizeof(char),inFile);//write to the infile	
	//outFile= fopen(fullPath,"r");

	//res = pwrite(fd, buf, size, offset);
	if(isEncrypted(fullPath)){

		//action=DEC;
		//revAction=ENC;

		inFile = fopen(fullPath,"r");
		fileT = fopen(pathT,"w");

		do_crypt(inFile,fileT,DEC,key);
		//do_crypt(outFile,inFile,0,key);//come back to latter
		fclose(inFile);
		fclose(fileT);

		fd=open(pathT,O_WRONLY);
		//fd=open(fullPath,O_WRONLY);
		res = pwrite(fd, buf, size, offset);

		close(fd);

		inFile = fopen(fullPath,"w");
		fileT = fopen(pathT,"r");



		do_crypt(fileT,inFile,ENC,key);
		fclose(inFile);
		fclose(fileT);
		remove(pathT);
		return res;
		//fd=open(fullPath,O_WRONLY);
		
	}else{
		fd=open(fullPath,O_WRONLY);

		//fd=open(pathT,O_WRONLY);

		res =pwrite(fd,buf,size,offset);
		close(fd);
		remove(pathT);
		return res;
		//fd=open(fullPath, O_WRONLY);

	}
	fprintf(stderr, "do_crypts is happening\n\n\n\n");
	

	fclose(inFile);
	fclose(fileT);

	fd=open(pathT, O_WRONLY);

	//fseek(inFile,offset,SEEK_SET);
	//res=pwrite(fd,buf,size,offset);
	//res=fwrite(buf,1,size,inFile);
	//close(outFile);

	if (fd == -1)
		return -errno;

	//res=pwrite(fd,buf,size,offset);

	close(fd);
	//apend to doc
	inFile=fopen(fullPath,"w");
	 fileT=fopen(pathT,"r");
	if (res == -1)
		res = -errno;
	//fflush(inFile);

	//outFile=fopen(fullPath,"w");
	//fseek(inFile,0,SEEK_SET);
	fprintf(stderr, "do_crypts is happening\n\n\n\n");
	do_crypt(fileT,inFile,ENC, key);

	//fclose(outFile);
	fclose(inFile);
	fclose(fileT);
	remove(pathT);
	return res;
}