Exemple #1
0
/** Read directory
 *
 * Given an absolute path to a directory, xmp_readdir will return
 * all the files and directories in that directory. The steps you
 * will take will be the following:
 *
 * 1. Resolve the directory entry from its absolute path to get
 *    the address of the directory block that corresponds to "path"
 *
 * 2. For each valid entry in the directory block, copy the file
 *    name into an array (buf) using the function filler. The filler
 *    is already implemeted in fuse and its sample use is shown in
 *    fusexmp.c file and you should pass the zero to the offest
 *    paramter of filler function. fuse.h file has some more infomration
 *    about how to implement this function and another way of implementing it.
 *
 * For time being ignore the fuse_file_info parameter. If you would
 * like to use please see the open function in fuse.h file for more
 * detials.
 *
 * You should return 0 on success or -1 on error (e.g., the directory
 * does not exist).
 */
static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
                       off_t offset, struct fuse_file_info *fi)
{
	DEBUG_ME;
	int* tuple;
	tuple = traverse_dir_r(path);
	PRINTPTR(tuple);
	printf("tup 0: %d, tup 1: %d", tuple[0], tuple[1]);
	//dir data no
	int datano = tuple[1];
	DEBUG_ME;
	//free(tuple);
	DEBUG_ME;
	printf("Read dir from data num number %d \n", datano);
	if(datano < 0){
		printf("Not a directory!!!\n");
		return -1;
	}
	Directory* dir_buf = (Directory*)malloc(sizeof(Directory) * DIR_AMT);
	Directory* init_d = dir_buf;
	if(dread(global_fd, datano + DATA_OFFSET, init_d) < 0){
		RFAIL;
		return -1;
	}
	for(int i = 0; i < DIR_AMT; i++){
		if(strlen(dir_buf->f_name) > 0){
			printf("Adding %s file to ls\n", dir_buf->f_name);
			filler(buf, dir_buf->f_name, NULL, 0);
		}
		dir_buf++;
	}
	free(init_d);
	return 0;
}
Exemple #2
0
void edoors_room_free(Edoors_Room *room)
{
    DBG("Room free 0x%X",PRINTPTR(room));

    edoors_iota_desinit(&room->iota);
    // TODO room->links
    eina_hash_free(room->children);

    free(room);
}
Exemple #3
0
/* return data block to read directory from it */
static int* traverse_dir_r(char* path){
	char* path_pt;
	int datano = 0; //root dir at data blck zero
	int ino = -1;
	int* tuple = (int*)malloc(sizeof(int) * 2);
	PRINTPTR(tuple);
	Inode *ibuf = (Inode *)malloc(sizeof(Inode) * INODE_AMT);
	Inode *init_ibuf = ibuf;
	if(strlen(path) < 2){
		tuple[0] = 2;
		tuple[1] = 0;
		return tuple;
	}else{
		for(path_pt=strtok(path, "/"); path_pt!=NULL; path_pt=strtok(NULL, "/") ){
			//find inum in the dir
			ino = search_dir(path_pt, datano);
			if(ino < 0){
				printf("Unabe to find the path specify \n");
				return -1;
			}
			//retreive data blck in inum
			if(dread(global_fd, INODE_OFFSET + (ino/INODE_AMT), init_ibuf) < 0){
				RFAIL;
			}
			ibuf+=ino%INODE_AMT;
			if(ibuf->f_type){
				datano = ibuf->block_pt[0];
			}
		}
		//when finish traversing return the correct datanum
		free(init_ibuf);
		tuple[0] = ino;
		tuple[1] = tuple;
		return tuple;
	}

}