예제 #1
0
int do_open(char * filename, int flags, int mode) {

	iNode * posible_file = search_directory(filename, current);

	int fd;
	if (posible_file != NULL)
	{
		if (posible_file->gid < currentUsr.group)
			return -2;

		if (posible_file->identifier == LINK) {
			posible_file = fs_get_inode(posible_file->link);
		}
		if ((fd = search_for_inode(posible_file->iNode_number)) != -1) {
			return fd;
		} else {
			return insert_fd(posible_file->iNode_number);
		}
	} else {
		if (flags == 0) {
			do_creat(filename, mode);
		} else {
			return -1;
		}

	}

}
예제 #2
0
파일: ecmd.c 프로젝트: EtherGraf/ethersex
int16_t
parse_cmd_fs_list (char *cmd, char *output, uint16_t len)
{
  char name[FS_FILENAME + 1];

  if (cmd[0] != 0x05) 
    {
      /* first function entry */
      cmd[0] = 0x05;		/* set magic byte ... */
      cmd[1] = 0x00;

      return ECMD_AGAIN(snprintf_P(output, len, PSTR("name  :inode :size\n"
						     "----------------------")));
    }
  else
    {
      if (fs_list (&fs, NULL, name, cmd[1] ++) != FS_OK)
	return ECMD_FINAL_OK;		/* no repare, out. */
      
      name[FS_FILENAME] = 0;

      fs_inode_t inode = fs_get_inode (&fs, name);
      fs_size_t size = fs_size (&fs, inode);

      return ECMD_AGAIN(snprintf_P(output, len, PSTR("%-6s:0x%04x:0x%04x"),
			            name, inode, size));
    }
}
예제 #3
0
int recursive_remove(iNode * current) {

	int ret;

	if (current->gid < currentUsr.group)
		return 1;

	if (is_base_case(current)) //CASOBASE QUE ES QUE EL DIRECTORIO ESTE VACIO O SEA UN ARCHIVO)
		return 0;

	int init_block = current->data.direct_blocks[0];
	directoryEntry * dr = (directoryEntry*) calloc(sizeof(directoryEntry), 96);
	read_disk(0, init_block, dr, BLOCK_SIZE * 12, 0);
	int i;
	for (i = 2; i < 96; i++) {
		if (dr[i].type != 0) {
			ret = recursive_remove(fs_get_inode(dr[i].inode));
			if (!ret) {
				dr[i].type = 0;
				dr[i].inode = 0;
				dr[i].lenght = 0;
			}

		}
	}
	write_disk(0, init_block, dr, BLOCK_SIZE * 12, 0);

	return ret;
}
예제 #4
0
/* Main */
void 
main(){

	/* Init Disco Virtual */
	vDisk = (virtualDisk*)malloc(sizeof(virtualDisk));
	vDisk->disk = (void *)malloc(DISK_SIZE);

	/* Init Global Variables */	
	masterBootRecord * mbr = (masterBootRecord *)malloc(512);
	superblock = (masterBlock*)malloc(512);		
	bitmap = (BM*)calloc(BITMAP_SIZE,1);	
	inodemap = (IM*)calloc(INODEMAP_SIZE,1);
	
	
	
	/* Create & Init File System */
	mbr = (masterBootRecord *)read_disk(vDisk->disk,0,mbr,BLOCK_SIZE,0);

	if ( mbr->existFS == 0 ){
		init_filesystem("Chinux", mbr);
	}else{
		load_filesystem();
	}

	printf("mbr:%d\n",mbr->existFS);
	superblock = read_disk(vDisk->disk,1,superblock,BLOCK_SIZE,0);
	printf("name:%s\nblock:%d\nfreeBlocks:%d\nusedBlocks:%d\n",superblock->name, superblock->blockSize, superblock->freeBlocks, superblock->usedBlocks);
	printf("InodeSize:%d\n",sizeof(iNode));
	printf("Directory:%d\n",sizeof(directoryEntry));//16 Directorios o archivos en bloques directos..

	iNode * nodo = fs_creat_inode(DIRECTORY,777,512,superblock->root);
	fs_insert_inode(nodo);
	iNode * nodo3 = fs_creat_inode(DIRECTORY,737,512,superblock->root);
	fs_insert_inode(nodo3);

	//nodo->iNode_number = 20;
	printf("\n\nTABLA DATOS\n");
	printf("inode-number:%d\n",nodo->iNode_number);		
	printf("mode:%d\n",nodo->mode);
	printf("size:%d\n",nodo->size);
	printf("iden:%d\n",nodo->identifier);

	
	iNode * nodo2 = fs_get_inode(nodo->iNode_number);
	printf("inode-number:%d\n",nodo->iNode_number);		
	printf("mode:%d\n",nodo2->mode);
	printf("size:%d\n",nodo2->size);
	printf("iden:%d\n",nodo2->identifier);

	insert_directory("Hola",superblock->root);
	//ls("asd");
	makeDir("comostas");
	print_directories(superblock->root);
	makeDir("Hola/Comocomo");
	cd("Hola");
	print_directories(current);

	
}
예제 #5
0
void recursive_cp(char * filename, iNode * origin, iNode * destination)
{
	int i;
	iNode * path;

	if(origin->gid < currentUsr.group)
		return ;

	cp_dir(filename, destination);

	//get new path
	int init_block = destination->data.direct_blocks[0];
	directoryEntry * dr = (directoryEntry*)calloc(64 * 96, 1);
	read_disk(0, init_block, dr, (BLOCK_SIZE * 12), 0);
	for(i = 2; i < 96; i++){
		if( strcmp(filename, dr[i].name)){
			path = fs_get_inode(dr[i].inode);
			break;
		}
	}

	//search for files and folders
	init_block = origin->data.direct_blocks[0];
	dr = (directoryEntry*)calloc(sizeof(directoryEntry), 96);
	read_disk(0, init_block, dr, BLOCK_SIZE * 12, 0);
	for ( i = 2; i < 96; i++)
	{
		if (dr[i].type == FILE)
		{
			cp_file(dr[i].name, origin, path);
		}
		else if(dr[i].type == DIRECTORY)
		{
			recursive_cp(dr[i].name, fs_get_inode(dr[i].inode), path);
		}
	}
	write_disk(0, init_block, dr, BLOCK_SIZE * 12, 0);

	return ;
}
예제 #6
0
iNode * search_directory(char * name, iNode * actual_node){
	int init_block = actual_node->data.direct_blocks[0];
	directoryEntry * dr = (directoryEntry*)calloc(sizeof(directoryEntry),96);
	read_disk(vDisk->disk,init_block,dr,BLOCK_SIZE*12,0);
	
	int i;
	for(i=0;i<96;i++){
		if( strcmp(name,dr[i].name) == 0){
			return fs_get_inode(dr[i].inode);
		}
	}
	return NULL;
}
예제 #7
0
int do_write(int fd, char * buf, int n) {

	//_Cli();
	int inode_number = search_for_fd(fd); //search fd in inode;
	if (inode_number == -1) {
		return -1;
	}
	iNode * inode = fs_get_inode(inode_number);
	return write_inode(inode, buf, n);
	//_Sti();	
	//return 1;

}
예제 #8
0
iNode * search_directory(char * name, iNode * actual_node) {

	int init_block = actual_node->data.direct_blocks[0];
	directoryEntry * dr = (directoryEntry*) calloc(64 * 96, 1);
	read_disk(0, init_block, dr, (BLOCK_SIZE * 12), 0);
	int i;
	for (i = 1; i < 96; i++) {
		if (strcmp(name, dr[i].name) == 1) {
			return fs_get_inode(dr[i].inode);
		}
	}
	return NULL;
}
예제 #9
0
int do_read(int fd, char * buf, int n) {

	int inode_number, quant;
	inode_number = search_for_fd(fd);
	if (inode_number == -1) {
		return -1;
	}
	iNode * inode = fs_get_inode(inode_number);
	if (n == -1) { //to read all the file.
		n = inode->size;
	}
	quant = read_inode(inode, buf, n);
	return quant;
}
예제 #10
0
파일: ecmd.c 프로젝트: EtherGraf/ethersex
int16_t
parse_cmd_fs_mkfile (char *cmd, char *output, uint16_t len)
{
  /* ignore leading spaces */
  while (*cmd == ' ')
    cmd ++;

  fs_status_t ret = fs_create (&fs, cmd);
  
  if (ret != FS_OK)
    return ECMD_FINAL(snprintf_P(output, len, PSTR("fs_create: returned 0x%02x"), ret));

  fs_inode_t i = fs_get_inode (&fs, cmd);
  return ECMD_FINAL(snprintf_P(output, len, PSTR("fs_create: inode 0x%04x"), i));
}
예제 #11
0
파일: ecmd.c 프로젝트: EtherGraf/ethersex
int16_t
parse_cmd_fs_truncate (char *cmd, char *output, uint16_t len)
{
  /* Ignore leading spaces. */
  while (* cmd == ' ') cmd ++;

  char *ptr = strchr (cmd, ' ');
  if (ptr == NULL) return ECMD_ERR_PARSE_ERROR;	/* invalid args. */

  *(ptr ++) = 0;		/* Zero terminate filename. */

  fs_inode_t i = fs_get_inode (&fs, cmd);

  if (i == 0xffff)
    return ECMD_FINAL(snprintf_P(output, len, PSTR("no such file.")));

  fs_status_t ret = fs_truncate (&fs, i, strtoul (ptr, NULL, 10));
  return (ret == FS_OK) ? ECMD_FINAL_OK : ECMD_ERR_PARSE_ERROR;
}
예제 #12
0
파일: menu.c 프로젝트: jknofe/a-culfw
void
menu_init()
{
    // Parse the MENU file, cache the menu offsets
    minode = fs_get_inode(&fs, "MENU");
    if(minode == 0xffff)
        return;
    menu_filelen = (uint16_t)fs_size(&fs, minode);
    uint16_t nextoffset, offset = 0;
    uint8_t menu_line[8], idx = 0;

    while((nextoffset = menu_get_line(offset,menu_line,sizeof(menu_line))) != 0) {
        if(menu_line[0] == 'M' || menu_line[0] == 'D') {    // Menu or Macro-def
            menu_offset[idx] = offset;
            if(idx < NMENUS)
                idx++;
        }
        offset = nextoffset;
    }
    menu_stackidx = 0;
    joyfunc = menu_handle_joystick;       // parse input
    menu_push(0);
}
예제 #13
0
void rmDir(char * path) {

	int i, j, ret;
	iNode * posible_inode = current;
	posible_inode = parser_path(path, posible_inode);

	if (posible_inode == NULL) {
		printf("Wrong name or path\n");
		return;
	}

	if (posible_inode->gid < currentUsr.group) {
		printf("\nCan not remove %s. Permission denied.", path);
		return;
	}
	if (posible_inode->identifier != DIRECTORY) {

		int inode_number = posible_inode->iNode_number;
		int init_block = current->data.direct_blocks[0];
		directoryEntry * dr = (directoryEntry*) calloc(sizeof(directoryEntry),
				96);
		read_disk(0, init_block, dr, BLOCK_SIZE * 12, 0);
		for (i = 2; i < 96; i++) {
			if (dr[i].inode == inode_number) {
				char * empty_name = "\0";
				dr[i].type = 0;
				dr[i].inode = 0;
				dr[i].lenght = 0;
				strcopy(dr[i].name, empty_name, 1);
				break;
			}
		}
		write_disk(0, init_block, dr, BLOCK_SIZE * 12, 0);
	} else {
		//BORRADO RECURSIVO.
		ret = recursive_remove(posible_inode);

		if (ret)
			return;
		int inode_number = posible_inode->iNode_number;
		int init_block = current->data.direct_blocks[0];
		directoryEntry * dr = (directoryEntry*) calloc(sizeof(directoryEntry),
				96);
		read_disk(0, init_block, dr, BLOCK_SIZE * 12, 0);
		iNode * parent = fs_get_inode(dr[1].inode);
		int father_init_block = current->data.direct_blocks[0];
		directoryEntry * father_dr = (directoryEntry*) calloc(
				sizeof(directoryEntry), 96);
		read_disk(0, father_init_block, father_dr, BLOCK_SIZE * 12, 0);

		for (i = 2; i < 96; i++) {
			if (father_dr[i].inode == inode_number) {
				char * empty_name = "\0";
				dr[i].type = 0;
				dr[i].inode = 0;
				dr[i].lenght = 0;
				strcopy(dr[i].name, empty_name, 1);
				break;
			}
		}
		write_disk(0, init_block, dr, BLOCK_SIZE * 12, 0);
	}
	return;
}
예제 #14
0
void mv(char * filename, char * path)
{
	int i, name_length, type;
	filename[str_len(filename) - 1] = 0;
	iNode * path_inode = current;
	path_inode = parser_path(path, path_inode);
	iNode * filename_inode = current;
	filename_inode = parser_path(filename, filename_inode);

	if(filename_inode->gid < currentUsr.group)
	{
		printf("\nCan not move '%s'. Permission denied.", filename);
		return ;
	}

	if(filename_inode == NULL)
	{
		printf("\nCan not move '%s'. File doesn't exist.", filename);
		return ;
	}

	if(path_inode == NULL)
	{
		name_length = str_len(path);
		for(i = 0; i < name_length; i++)
			if(path[i] == '/')
			{
				printf("\nCan not move '%s' to '%s'. Directory doesn't exist.", filename, path);
				return;
			}
		rename_file(filename_inode->iNode_number, path);
		return ;
	}

	int init_block = current->data.direct_blocks[0];
	directoryEntry * dr = (directoryEntry*)calloc(64 * 96, 1);
	read_disk(0, init_block, dr, (BLOCK_SIZE * 12), 0);
	for(i = 1; i < 96; i++){
		if( strcmp(filename, dr[i].name) == 1){
			type = dr[i].type;
			break;
		}
	}

	if(type == DIRECTORY)
	{
		insert_directory_entry(filename_inode, path_inode, filename);

		int inode_number = filename_inode->iNode_number;
		init_block = current->data.direct_blocks[0];
		directoryEntry * dr = (directoryEntry*)calloc(sizeof(directoryEntry),96);
		read_disk(0,init_block,dr,BLOCK_SIZE*12,0);
		iNode * parent = fs_get_inode(dr[1].inode);
		int father_init_block = current->data.direct_blocks[0];
		directoryEntry * father_dr = (directoryEntry*)calloc(sizeof(directoryEntry),96);
		read_disk(0,father_init_block,father_dr,BLOCK_SIZE*12,0);

		for ( i = 2; i < 96; i++){
			if ( father_dr[i].inode == inode_number){
				dr[i].type = 0;
				dr[i].inode = 0;
				dr[i].lenght = 0;
				strcopy(dr[i].name,"\0",1 );
				break;
			}
		}
		write_disk(0,init_block,dr,BLOCK_SIZE*12,0);
	}
	else if( type == FILE)
	{
		insert_file(filename, 777, path_inode);
		rmDir(filename);
	}

	return ;
}
예제 #15
0
int getidentifier(int filedescriptor) {
	iNode * nodo = fs_get_inode(search_for_fd(filedescriptor));
	return nodo->identifier;
}
예제 #16
0
int getsize(int filedescriptor) {

	iNode * nodo = fs_get_inode(search_for_fd(filedescriptor));
	return nodo->size;

}