Beispiel #1
0
int main(int argc, char **argv)
{
		char input[64+16+16+16+LARGE_FILE];
		char comm[64], arg1[16], arg2[16], arg3[16], arg4[LARGE_FILE];

		srand(time(NULL));

		if(argc < 2) {
				fprintf(stderr, "usage: ./fs disk_name\n");
				return -1;
		}
		srand (time(NULL));	

		fs_mount(argv[1]);
		printf("%% ");
		while(fgets(input, 256, stdin))
		{
				bzero(comm,64); bzero(arg1,16); bzero(arg2,16); bzero(arg3,16); bzero(arg4, LARGE_FILE);
				int numArg = sscanf(input, "%s %s %s %s %s", comm, arg1, arg2, arg3, arg4);
				if(command(comm, "quit")) break;
				else if(command(comm, "exit")) break;
				else execute_command(comm, arg1, arg2, arg3, arg4, numArg - 1);

				printf("%% ");
		}
		
		fs_umount(argv[1]);
}
Beispiel #2
0
int 
main (int argc, char *argv[])
{
    if (argc == 6 && !strcmp (argv[1], "format"))
    {
		u_int nb_b = atoi (argv[3]);
		u_int size_b = atoi (argv[4]);
		u_int nb_i = atoi (argv[5]);
		return fs_format (argv[2], nb_b, size_b, nb_i) == -1;
    }

    if ((argc == 3 || argc == 4) && !strcmp (argv[1], "mount"))
    {
    	FileSystem fs;
		size size_cache = 0;
		if (argc == 4)
			size_cache = atoi (argv[3]);

		if (fs_mount (&fs, argv[2], size_cache) == -1)
			return 1;

		launch_interface (&fs);
		return fs_umount (&fs) == -1;
    }

    usage (argv[0]);
    return 1;
}
Beispiel #3
0
int main(int argc, char **argv)
{
    EmbeddedFileSystem efs;

    if(argc<3){
	fprintf(stderr,"Argument error : mkdir <fs> <dirname>\n");
	exit(-1);
    }
    
    if(efs_init(&efs,argv[1])!=0){
	printf("Could not open filesystem.\n");
	return(-1);
    }
    
    if(!mkdir(&(efs.myFs),argv[2])){
	printf("Unable to make directory\n");
	fs_umount(&(efs.myFs));
	exit(-1);
    }
    fs_umount(&(efs.myFs));
    return(0);
}
/**
*******************************************************************************
  Function Name : delete_file()

  Description :	 

  Input :	

  Output :	none

  Note : 
*******************************************************************************
*/
U8 delete_file(U8 *name)
{
  DirList list;
  U8 retval = FILE_DELETED_SUCCESS;

  ls_openDir(&list,&efs.myFs,"/");
  if(rmfile(&efs.myFs,name) == -1)
  {
    retval = FILE_DELETED_NO_SUCH_FILE;
  }
  fs_umount(&efs.myFs);

  return retval;
}
Beispiel #5
0
PROCESS_THREAD(sdcard_process, ev , data)
{
  static struct etimer timer;
  PROCESS_BEGIN();
  *AT91C_PIOA_PER = AT91C_PIO_PA20 | AT91C_PIO_PA1;
  *AT91C_PIOA_ODR = AT91C_PIO_PA20 | AT91C_PIO_PA1;
  
  
  /* Card not inserted */
  sdcard_efs.myCard.sectorCount = 0;
  init_spi();
  
  while(1) {
    if (!(*AT91C_PIOA_PDSR & AT91C_PA20_IRQ0)) {
      if (sdcard_efs.myCard.sectorCount == 0) {
	if (efs_init(&sdcard_efs,0) == 0) {
	  if (event_process) {
	    process_post(event_process, sdcard_inserted_event, NULL);
	  }
	  printf("SD card inserted\n");
	} else {
	  printf("SD card insertion failed\n");
	}
      }
    } else {
      if (sdcard_efs.myCard.sectorCount != 0) {
	/* Card removed */
	  fs_umount(&sdcard_efs.myFs);
	  sdcard_efs.myCard.sectorCount = 0;
	  if (event_process) {
	    process_post(event_process, sdcard_removed_event, NULL);
	  }
	  printf("SD card removed\n");
      }
    }
    
    etimer_set(&timer, CLOCK_SECOND);
    PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXIT ||
			     ev == PROCESS_EVENT_TIMER);
    if (ev == PROCESS_EVENT_EXIT) break;
    if (!(*AT91C_PIOA_PDSR & AT91C_PA20_IRQ0)) {
      /* Wait for card to be preperly inserted */
      etimer_set(&timer,CLOCK_SECOND/2);
      PROCESS_WAIT_EVENT_UNTIL(ev== PROCESS_EVENT_TIMER);
    }
    
  }
  PROCESS_END();
}
Beispiel #6
0
PROCESS_THREAD(sdcard_process, ev , data)
{
  int fd;
  static struct etimer timer;
  PROCESS_BEGIN();
  /* Mark all file descriptors as free */
  for (fd = 0; fd < MAX_FDS; fd++) {
    file_setAttr(&file_descriptors[fd], FILE_STATUS_OPEN,0);
  }
  /* Card not inserted */
  sdcard_efs.myCard.sectorCount = 0;
  init_spi();

  etimer_set(&timer, CLOCK_SECOND);
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXIT ||
			     ev== PROCESS_EVENT_TIMER || ev == PROCESS_EVENT_POLL);
    if (ev == PROCESS_EVENT_EXIT) break;
    if (ev == PROCESS_EVENT_TIMER) {
      if (!(GPIOA->IDR & (1<<0))) {
	if (sdcard_efs.myCard.sectorCount == 0) {
	  etimer_set(&timer,CLOCK_SECOND/2);
	  PROCESS_WAIT_EVENT_UNTIL(ev== PROCESS_EVENT_TIMER);
	  if (efs_init(&sdcard_efs,0) == 0) {
	    if (event_process) {
	      process_post(event_process, sdcard_inserted_event, NULL);
	    }
	    printf("SD card inserted\n");
	  } else {
	    printf("SD card insertion failed\n");
	  }
	}
      } else {
	if (sdcard_efs.myCard.sectorCount != 0) {
	  /* Card removed */
	  fs_umount(&sdcard_efs.myFs);
	  sdcard_efs.myCard.sectorCount = 0;
	  if (event_process) {
	    process_post(event_process, sdcard_removed_event, NULL);
	  }
	  printf("SD card removed\n");
	}
      }
      etimer_set(&timer, CLOCK_SECOND);
      
    }
  }
  PROCESS_END();
}
Beispiel #7
0
/* close the file sent, disconnect and close the connection */
void tftp_cleanup_rd(struct udp_pcb *upcb, tftp_connection_args *args)
{
  /* close the filesystem */
  file_fclose(&file_SD);
  fs_umount(&efs1.myFs);
  /* Free the tftp_connection_args structure reserverd for */
  mem_free(args);

  /* Disconnect the udp_pcb*/
  udp_disconnect(upcb);

  /* close the connection */
  udp_remove(upcb);

  udp_recv(UDPpcb, recv_callback_tftp, NULL);
}
Beispiel #8
0
int main(int argc, char** argv)
{
	EmbeddedFileSystem efs;
	EmbeddedFile file;	
	unsigned short e;
	unsigned short bufsize;
	signed short ret;
	char *buf;
	FILE *localfile;
	
	if(argc<4){
		fprintf(stderr,"Argument error : cpa <fs> <local_read> <file_append> [bufsize]\n");
		exit(-1);
	}

	if(argc==5)
		bufsize=atoi(argv[4]);
	else
		bufsize=4096;
	buf=malloc(bufsize);
	
	if(efs_init(&efs,argv[1])!=0){
		printf("Could not open filesystem.\n");
		return(-1);
	}
	
	ret=file_fopen(&file,&efs.myFs,argv[3],'a');
	if((ret!=0)){
		printf("Could not open file %s (return value: %d).\n",argv[3],ret);
		return(-2);
	}

	if(!(localfile=fopen(argv[2],"r"))){
		printf("Could not open local file.\n");
		return(-3);
	}
	
	while((e=fread(buf,1,bufsize,localfile))){
		file_write(&file,e,buf);
	}

	file_fclose(&file);
	fclose(localfile);
	fs_umount(&(efs.myFs));

	return(0);
}
Beispiel #9
0
static int wrap_fs_unmountfs(struct _reent *r, const char *pathname)
{
    if (!fs) {
	r->_errno = EINVAL;
	return -1;
    }
    fs_umount(fs);
    free(part);
    free(disc);
    free(ioman);
    free(fs);
    if_finiInterface(lfile);
    free(lfile);
    fs = NULL;
    lfile = NULL;
    return 0;
}
Beispiel #10
0
static int local_ct_wait(ct_handler_t h)
{
	struct container *ct = cth2ct(h);
	int ret, status;

	if (ct->state != CT_RUNNING)
		return -LCTERR_BADCTSTATE;

	if (ct->p.pid > 0) {
		ret = libct_process_wait(&ct->p.h, &status);
		if (ret < 0)
			return -1;
	}

	fs_umount(ct);
	cgroups_destroy(ct); /* FIXME -- can be held accross restarts */
	net_stop(ct);

	ct->state = CT_STOPPED;
	return 0;
}
Beispiel #11
0
/*
 * Delete subsystem
 */
void ss_delete(int32_t ss_idx)
{
  ss_idx = ss_idx;

  /*
   * Delete history
   */
  ss_del_history();

  /*
   * Umount filesystem
   */
  if (fs_type >= 0 && fs_type < FS_TYPE_NUM_MAX) {
    fs_umount(fs_type);
    fs_type = -1;

    info("umount filesystem successfully.");
  }

  /*
   * Unregister filesystem
   */
  fs_unregister();
}
Beispiel #12
0
int main()
{
	int8_t res;
    uint32_t n, m, p, cnt;

//	SystemInit();
    SysTick_Config(SystemCoreClock/1000 - 1); /* Generate interrupt each 1 ms   */

	LPC17xx_UART_Init(115200); // UART0
    xfunc_out = LPC17xx_UART_PutChar;
	xfunc_in  = LPC17xx_UART_GetChar; 

	xprintf("\nMMC/SD Card Filesystem Test (P:LPC1768 L:EFSL)\n");

	xprintf("\nCARD init...");

	// init file system
	if ( ( res = efs_init( &efs, 0 ) ) != 0 ) {
		xprintf("failed with %i\n",res);
	}
	else 
	{
		xprintf("ok\n");

        xprintf("Card type: ");
        switch (CardType)
        {
            case CARDTYPE_MMC:
                xprintf("MMC\n");
                break;
            case CARDTYPE_SDV1:
                xprintf("Version 1.x Standard Capacity SD card.\n");
                break;
            case CARDTYPE_SDV2_SC:
                xprintf("Version 2.0 or later Standard Capacity SD card.\n");
                break;
            case CARDTYPE_SDV2_HC:
                xprintf("Version 2.0 or later High/eXtended Capacity SD card.\n");
                break;
            default:
                break;            
        }
        xprintf("Sector size: %d bytes\n", CardConfig.sectorsize);
        xprintf("Sector count: %d\n", CardConfig.sectorcnt);
        xprintf("Block size: %d sectors\n", CardConfig.blocksize);
        xprintf("Card capacity: %d MByte\n\n", (((CardConfig.sectorcnt >> 10) * CardConfig.sectorsize)) >> 10);

		xprintf("\nDirectory of 'root':\n");
		
		/* list files in root directory */
		ls_openDir( &list, &(efs.myFs) , "/");
		while ( ls_getNext( &list ) == 0 ) {
			// list.currentEntry is the current file
			list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0';
			xprintf("%s, 0x%x bytes\n", list.currentEntry.FileName, list.currentEntry.FileSize ) ;
		}

#if WRITE_TEST_ENABLED!=0
        /* Write test*/  
        xprintf("\nFile write test:\n");
        xprintf("Open file %s ...", FILE_NAME);
        if (file_fopen( &filew, &efs.myFs , FILE_NAME , 'a' ) == 0 )
        {
            xprintf(" OK. \nWriting %lu bytes ...\n", FILE_RW_SIZE);

            xmemset(Buff, 0xAA, blen);
            n=FILE_RW_SIZE;
            m = 0;
            Timer = 0;
            while (n)
            {
                if (n>=blen) {
                    cnt = blen;
                    n -= blen;
                } else {
                    cnt = n;
                    n = 0;
                }
                p = file_write( &filew, cnt, Buff );
                m += p;
                if (p != cnt) break;
            }
            xprintf("%lu bytes written with %lu kB/sec.\n", m, Timer ? (m / Timer) : 0);

            file_fclose( &filew );                          

        } else {
            xprintf (" Failed.\n");
        }
#endif

#if READ_TEST_ENABLED!=0
        /* Read test */
        xprintf("\nFile read test:\n");
        xprintf("Open file %s ...", FILE_NAME);
        if (file_fopen( &filer, &efs.myFs , FILE_NAME , 'r' ) == 0 )
        {
            xprintf(" OK. \nReading %lu bytes ...\n", FILE_RW_SIZE);

            n=FILE_RW_SIZE; 
            m = 0;
            Timer = 0;
            while (n)
            {
                if (n>=blen) {cnt = blen; n -= blen;}
                else         {cnt = n; n = 0;}

                p =  file_read( &filer, cnt, Buff );
                m += p;
                if (p != cnt) break;                
            }
            xprintf("%lu bytes read with %lu kB/sec.\n", m, Timer ? (m / Timer) : 0);

            file_fclose( &filer ); 

        } else
        {
            xprintf (" Failed.\n");    
        }
#endif

        /* close file system */
	    fs_umount( &efs.myFs ) ;
    }

	xprintf("\nEFSL test complete.\n");

	while (1);
}
int main()
{
	int8_t res;
    uint32_t n, m, p, cnt;
    uint32_t cclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU);
    uint32_t filesize = 0;
    uint32_t time_end;

//	SystemInit();
    SysTick_Config(cclk/1000 - 1); /* Generate interrupt each 1 ms   */

	debug_frmwrk_init(); // UART0
    xfunc_out = put_char;
	xfunc_in  = get_char; 

    xprintf("%s",mciFsMenu);

	xprintf("\nMMC/SD Card Filesystem Test (P:LPC1788 L:EFSL)\n");

	xprintf("\nCARD init...");

	// init file system
	if ( ( res = efs_init( &efs, 0 ) ) != 0 ) {
		xprintf("failed with %d\n",res);
	}
	else 
	{
		xprintf("ok\n");

        xprintf("Card type: ");
        switch (CardConfig.CardType)
        {
            case MCI_MMC_CARD:
                xprintf("MMC\n");
                break;
            case MCI_SDSC_V1_CARD:
                xprintf("Version 1.x Standard Capacity SD card.\n");
                break;
            case MCI_SDSC_V2_CARD:
                xprintf("Version 2.0 or later Standard Capacity SD card.\n");
                break;
            case MCI_SDHC_SDXC_CARD:
                xprintf("Version 2.0 or later High/eXtended Capacity SD card.\n");
                break;
            default:
                break;            
        }
        xprintf("Sector size: %d bytes\n", CardConfig.SectorSize);
        xprintf("Sector count: %d\n", CardConfig.SectorCount);
        xprintf("Block size: %d sectors\n", CardConfig.BlockSize);
        xprintf("Card capacity: %d MByte\n\n", (((CardConfig.SectorCount >> 10) * CardConfig.SectorSize)) >> 10);
		xprintf("\nDirectory of 'root':\n");
		
		/* list files in root directory */
		ls_openDir( &list, &(efs.myFs) , "/");
		while ( ls_getNext( &list ) == 0 ) {
			// list.currentEntry is the current file
			list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0';
			xprintf("%s, 0x%x bytes\n", list.currentEntry.FileName, list.currentEntry.FileSize ) ;
		}
#if READ_TEST_ENABLED!=0
        /* Read test */
        xprintf("\nFile read test:\n");
        xprintf("Open file %s ...", FILE_NAME_R);
        xmemset(Buff,0,sizeof(Buff));
        if (file_fopen( &filer, &efs.myFs , FILE_NAME_R , 'r' ) == 0 )
        {
            xprintf(" OK. \nReading %lu bytes ...\n", FILE_RW_SIZE);

            n=FILE_RW_SIZE; 
            m = 0;
            Timer = 0;
            xprintf("File's content:\n");
            while (n)
            {
                if (n>=blen) {cnt = blen; n -= blen;}
                else         {cnt = n; n = 0;}

                p =  file_read( &filer, cnt, &Buff[m] );
                xprintf("%s",&Buff[m]);
                m += p;
                if (p != cnt) break;                
            }
            filesize = m;
            time_end = Timer;
            xprintf("\n%lu bytes read in %lu milisec.\n", m, time_end);
            file_fclose( &filer ); 

        } else
        {
            xprintf (" Failed.\n");    
        }
#endif
#if WRITE_TEST_ENABLED!=0
        /* Write test*/  
        xprintf("\nFile write test:\n");
        xprintf("Open file %s ...", FILE_NAME_W);
        if (file_fopen( &filew, &efs.myFs , FILE_NAME_W , 'a' ) == 0 )
        {
            xprintf(" OK. \nWriting %lu bytes ...\n", filesize);
            n=filesize;
            m = 0;
            Timer = 0;
            while (n)
            {
                if (n>=blen) {
                    cnt = blen;
                    n -= blen;
                } else {
                    cnt = n;
                    n = 0;
                }
                p = file_write( &filew, cnt, &Buff[m] );
                m += p;
                if (p != cnt) break;
            }
            time_end = Timer;
            xprintf("%lu bytes written in %lu milisec.\n", m, time_end);

            file_fclose( &filew );                          

        } else {
            xprintf (" Failed.\n");
        }
#endif
#if READ_TEST_ENABLED!=0
        /* Read test */
        xprintf("\nFile read test:\n");
        xprintf("Open file %s ...", FILE_NAME_W);
        xmemset(Buff,0,sizeof(Buff));
        if (file_fopen( &filer, &efs.myFs , FILE_NAME_W , 'r' ) == 0 )
        {
            xprintf(" OK. \nReading %lu bytes ...\n", FILE_RW_SIZE);

            n=FILE_RW_SIZE; 
            m = 0;
            Timer = 0;
            xprintf("File's content:\n");
            while (n)
            {
                if (n>=blen) {cnt = blen; n -= blen;}
                else         {cnt = n; n = 0;}

                p =  file_read( &filer, cnt, &Buff[m] );
                xprintf("%s",&Buff[m]);
                m += p;
                if (p != cnt) break;                
            }
            filesize = m;
            time_end = Timer;
            xprintf("\n%lu bytes read in %lumiliseconds.\n", m, time_end);
            file_fclose( &filer ); 

        } else
        {
            xprintf (" Failed.\n");    
        }
#endif
        /* close file system */
	    fs_umount( &efs.myFs ) ;
    }

	xprintf("\nEFSL test complete.\n");

	while (1);
}
Beispiel #14
0
cgi_status cgi_write_upload_data_prepare(cs_uint8 type, cs_uint32 img_len)
{
    memset(&g_upload_cb, 0, sizeof(g_upload_cb));
    g_upload_cb.img_len = img_len;

    if(type == CGI_UPLOAD_JFFS2_TYPE)
    {
        cyg_uint32 part_index = flash_part_id_to_part_index(IROS_FLASH_PARTITION_JFFS2_ID);
        cs_uint8 *flash_des;
        cs_uint8 loop = 0;
        cs_uint32 part_size = 0;

        if(IROS_FLASH_PARTITION_INDEX_ANY == part_index)
        {
            return CGI_SDL_FAILED;
        }

        fs_umount();

        g_upload_cb.part_index = part_index;
        flash_des = flash_dev.info.super_block.part_tab[part_index].part_loc;

        /*eraise this part first*/
        part_size = flash_dev.info.super_block.part_tab[part_index].part_size;
        while(loop*flash_dev.info.super_block.block_size < part_size)
        {
            oper_flash_erase_block(flash_des+(loop*flash_dev.info.super_block.block_size));
            cs_thread_delay(150);
            loop++;
        }

        if(flash_part_write_init(part_index, flash_des))
        {
            return CGI_OK;
        }
        else
        {
            return CGI_SDL_FAILED;
        }

    }
    else if(type == CGI_UPLOAD_WLB_TYPE)
    {
        if(CS_E_OK != img_upgrade_download_start(CGI_HTTP_BUF_SIZE,
                              cgi_img_upgrade_download_callback, IMG_UPGRADE_WRITE_PART))
        {
            return CGI_SDL_FAILED;
        }
        else
        {
            img_upgrade_set_mif_support(FALSE);
            return CGI_OK;
        }
    }
    else
    {
        /*for mif*/
        if(0 != prepare_mif_upgrade(IROS_MID_WEB, FALSE))
        {
            return CGI_SDL_FAILED;
        }
        else
        {
            return CGI_OK;
        }
    }

}
Beispiel #15
0
int main(void)
{
	int ch;
	int8_t res;
	
	systemInit();
	gpioInit();
	
	uart1Init(UART_BAUD(BAUD), UART_8N1, UART_FIFO_8); // setup the UART
		
	uart1Puts("\r\nMMC/SD Card Filesystem Test (P:LPC2138 L:EFSL)\r\n");
	uart1Puts("efsl LPC2000-port and this Demo-Application\r\n");
	uart1Puts("done by Martin Thomas, Kaiserslautern, Germany\r\n");
	
	/* init efsl debug-output */
	lpc2000_debug_devopen(uart1Putch);
		
	ledToggle();
	
	rprintf("CARD init...");
	if ( ( res = efs_init( &efs, 0 ) ) != 0 ) {
		rprintf("failed with %i\n",res);
	}
	else {
		rprintf("ok\n");
		rprintf("Directory of 'root':\n");
		ls_openDir( &list, &(efs.myFs) , "/");
		while ( ls_getNext( &list ) == 0 ) {
			list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0';
			rprintf( "%s ( %li bytes )\n" ,
				list.currentEntry.FileName,
				list.currentEntry.FileSize ) ;
		}
		
		if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) {
			rprintf("File %s open. Content:\n", LogFileName);
			while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) {
				buf[e]='\0';
				uart1Puts((char*)buf);
			}
			rprintf("\n");
			file_fclose( &filer );
		}
		
		if ( file_fopen( &filew, &efs.myFs , LogFileName , 'a' ) == 0 ) {
			rprintf("File %s open for append. Appending...", LogFileName);
			strcpy((char*)buf, "Martin hat's angehaengt\r\n");
			if ( file_write( &filew, strlen((char*)buf), buf ) == strlen((char*)buf) ) {
				rprintf("ok\n");
			}
			else {
				rprintf("fail\n");
			}
			file_fclose( &filew );
		}
		
		if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) {
			rprintf("File %s open. Content:\n", LogFileName);
			while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) {
				buf[e]='\0';
				uart1Puts((char*)buf);
			}
			rprintf("\n");
			file_fclose( &filer );
		}
		
		fs_umount( &efs.myFs ) ;
	}
	
	while(1) {
		if ((ch = uart1Getch()) >= 0) {
			uart1Puts("You pressed : ");
			uart1Putch(ch);
			uart1Puts("\r\n");
			if ( ch == 'M' ) {
				rprintf("Creating FS\n");
				mkfs_makevfat(&efs.myPart);
			}
			ledToggle();
		}
	}
	
	return 0; /* never reached */
}
Beispiel #16
0
int main( int argc, char *argv[] )
{
	char line[1024];
	char cmd[1024];
	char arg1[1024];
	char arg2[1024];
	int inumber, result, args;

	if(argc!=3) {
		printf("use: %s <diskfile> <nblocks>\n",argv[0]);
		return 1;
	}

	if(!disk_init(argv[1],atoi(argv[2]))) {
		printf("couldn't initialize %s: %s\n",argv[1],strerror(errno));
		return 1;
	}

	printf("opened emulated disk image %s with %d blocks\n",argv[1],disk_size());

	while(1) {
		printf(" prompt> ");
		fflush(stdout);

		if(!fgets(line,sizeof(line),stdin)) break;

		if(line[0]=='\n') continue;
		line[strlen(line)-1] = 0;

		args = sscanf(line,"%s %s %s",cmd,arg1,arg2);
		if(args==0) continue;

		if(!strcmp(cmd,"format")) {
			if(args==1) {
				if(fs_format()) {
					printf("disk formatted.\n");
				} else {
					printf("format failed!\n");
				}
			} else {
				printf("use: format\n");
			}
		} else if(!strcmp(cmd,"mount")) {
			if(args==1) {
				if(fs_mount()) {
					printf("disk mounted.\n");
				} else {
					printf("mount failed!\n");
				}
			} else {
				printf("use: mount\n");
			}
		} else if(!strcmp(cmd,"umount")) {
			if(args==1) {
				if(fs_umount()) {
					printf("disk umounted.\n");
				} else {
					printf("umount failed!\n");
				}
			} else {
				printf("use: mount\n");
			}
		} else if(!strcmp(cmd,"debug")) {
			if(args==1) {
				fs_debug();
			} else {
				printf("use: debug\n");
			}
		} else if(!strcmp(cmd,"getsize")) {
			if(args==2) {
				inumber = atoi(arg1);
				result = fs_getsize(inumber);
				if(result>=0) {
					printf("inode %d has size %d\n",inumber,result);
				} else {
					printf("getsize failed!\n");
				}
			} else {
				printf("use: getsize <inumber>\n");
			}
			
		} else if(!strcmp(cmd,"create")) {
			if(args==1) {
				inumber = fs_create();
				if(inumber>=0) {
					printf("created inode %d\n",inumber);
				} else {
					printf("create failed!\n");
				}
			} else {
				printf("use: create\n");
			}
		} else if(!strcmp(cmd,"delete")) {
			if(args==2) {
				inumber = atoi(arg1);
				if(fs_delete(inumber)) {
					printf("inode %d deleted.\n",inumber);
				} else {
					printf("delete failed!\n");	
				}
			} else {
				printf("use: delete <inumber>\n");
			}
		} else if(!strcmp(cmd,"cat")) {
			if(args==2) {
				inumber = atoi(arg1);
				if(!do_copyout(inumber,"/dev/stdout")) {
					printf("cat failed!\n");
				}
			} else {
				printf("use: cat <inumber>\n");
			}

		} else if(!strcmp(cmd,"copyin")) {
			if(args==3) {
				inumber = atoi(arg2);
				if(do_copyin(arg1,inumber)) {
					printf("copied file %s to inode %d\n",arg1,inumber);
				} else {
					printf("copy failed!\n");
				}
			} else {
				printf("use: copyin <filename> <inumber>\n");
			}

		} else if(!strcmp(cmd,"copyout")) {
			if(args==3) {
				inumber = atoi(arg1);
				if(do_copyout(inumber,arg2)) {
					printf("copied inode %d to file %s\n",inumber,arg2);
				} else {
					printf("copy failed!\n");
				}
			} else {
				printf("use: copyout <inumber> <filename>\n");
			}

		} else if(!strcmp(cmd,"help")) {
			printf("Commands are:\n");
			printf("    format\n");
			printf("    mount\n");
			printf("    umount\n");
			printf("    debug\n");
			printf("    create\n");
			printf("    delete  <inode>\n");
			printf("    getsize  <inode>\n");
			printf("    cat     <inode>\n");
			printf("    copyin  <file> <inode>\n");
			printf("    copyout <inode> <file>\n");
			printf("    help\n");
			printf("    quit\n");
			printf("    exit\n");
		} else if(!strcmp(cmd,"quit")) {
			break;
		} else if(!strcmp(cmd,"exit")) {
			break;
		} else {
			printf("unknown command: %s\n",cmd);
			printf("type 'help' for a list of commands.\n");
			result = 1;
		}
	}

	printf("closing emulated disk.\n");
	disk_close();

	return 0;
}
Beispiel #17
0
/*
 * Execute command line for filesystem
 */
static void ss_exec_line(char *line)
{
  fs_opt_handle_t handle = NULL;
  int32_t argc = 0;
  const char* argv[FS_OPT_CMD_ARG_NUM_MAX] = {NULL};
  int32_t len_s1 = 0, len_s2 = 0;
  int32_t ret = -1;

  ret = ss_parse_line(line, &argc, argv);
  if (ret != 0) {
    fprintf(stdout, "press 'help' for more info.\n");
    return;
  }

  handle = ss_opt_hdl_match(argv[0]);
  if (handle != NULL) {
    ret = handle(argc, argv);
    if (ret != 0) {
      goto ss_exec_line_fail;
    }
    return;
  }

  len_s1 = strlen(argv[0]);
  len_s2 = strlen(FS_OPT_CMD_MOUNT);

  if (len_s1 == len_s2) {
    if (strncmp(argv[0], FS_OPT_CMD_MOUNT, len_s1) == 0) {
      if (fs_type < 0 || fs_type >= FS_TYPE_NUM_MAX) {
        fs_type = fs_mount(argv[1]);
        if (fs_type >= 0 && fs_type < FS_TYPE_NUM_MAX) {
          info("mount filesystem successfully.");
        } else {
          info("failed to mount filesystem.");
        }
      } else {
        info("umount filesystem first.");
      }
      return;
    }
  }

  len_s1 = strlen(argv[0]);
  len_s2 = strlen(FS_OPT_CMD_UMOUNT);

  if (len_s1 == len_s2) {
    if (strncmp(argv[0], FS_OPT_CMD_UMOUNT, len_s1) == 0) {
      if (fs_type >= 0 && fs_type < FS_TYPE_NUM_MAX) {
        fs_umount(fs_type);
        fs_type = -1;

        info("umount filesystem successfully.");
      }
      return;
    }
  }

  handle = fs_opt_hdl_match(fs_type, (const char *)argv[0]);
  if (handle != NULL) {
    ret = handle(argc, argv);
  }

  return;

ss_exec_line_fail:
  fprintf(stdout, "press 'help' for more info.\n");
  return;
}
Beispiel #18
0
/**
********************************************************************************************
 Function Name : fs_close()

 Description   :	

 Input         :	

 Output        : Void

 Note          :
********************************************************************************************
*/
S32 fs_close(void)
{
  return  fs_umount(&efs.myFs);
}
Beispiel #19
0
static ct_process_t __local_spawn_cb(ct_handler_t h, ct_process_desc_t ph, int (*cb)(void *), void *arg, bool is_exec)
{
	struct container *ct = cth2ct(h);
	struct process_desc *p = prh2pr(ph);
	int ret = -1, pid, aux;
	struct ct_clone_arg ca;

	if (ct->state != CT_STOPPED)
		return ERR_PTR(-LCTERR_BADCTSTATE);

	ret = fs_mount(ct);
	if (ret)
		return ERR_PTR(ret);

	if ((ct->flags & CT_KILLABLE) && !(ct->nsmask & CLONE_NEWPID)) {
		if (add_service_controller(ct))
			goto err_cg;
	}

	ret = cgroups_create(ct);
	if (ret)
		goto err_cg;

	ret = -1;
	if (pipe(ca.child_wait_pipe))
		goto err_pipe;
	if (pipe(ca.parent_wait_pipe))
		goto err_pipe2;

	ca.cb = cb;
	ca.arg = arg;
	ca.ct = ct;
	ca.p = p;
	ca.is_exec = is_exec;
	pid = clone(ct_clone, &ca.stack_ptr, ct->nsmask | SIGCHLD, &ca);
	if (pid < 0)
		goto err_clone;

	ct->p.pid = pid;

	close(ca.child_wait_pipe[0]);
	close(ca.parent_wait_pipe[1]);

	if (ct->nsmask & CLONE_NEWUSER) {
		if (write_id_mappings(pid, &ct->uid_map, "uid_map"))
			goto err_net;

		if (write_id_mappings(pid, &ct->gid_map, "gid_map"))
			goto err_net;
	}

	if (net_start(ct))
		goto err_net;

	spawn_wake_and_close(ca.child_wait_pipe, 0);

	aux = spawn_wait(ca.parent_wait_pipe);
	if (aux != 0) {
		ret = aux;
		goto err_ch;
	}

	aux = spawn_wait_and_close(ca.parent_wait_pipe);
	if (aux != INT_MIN) {
		ret = -1;
		goto err_ch;
	}

	ct->state = CT_RUNNING;
	return &ct->p.h;

err_ch:
	net_stop(ct);
err_net:
	spawn_wake_and_close(ca.child_wait_pipe, -1);
	libct_process_wait(&ct->p.h, NULL);
err_clone:
	close(ca.parent_wait_pipe[0]);
	close(ca.parent_wait_pipe[1]);
err_pipe2:
	close(ca.child_wait_pipe[0]);
	close(ca.child_wait_pipe[1]);
err_pipe:
	cgroups_destroy(ct);
err_cg:
	fs_umount(ct);
	return ERR_PTR(ret);
}
Beispiel #20
0
void main(void)
{
	EmbeddedFileSystem efs;
	EmbeddedFile file_w;
	unsigned short i;
	unsigned char e;
	unsigned char t;
	signed char err;
	unsigned char offset1;
	unsigned char offset2;
	char path[100];

	debug_init();
	
	DBG((TXT("Welcome (2).\n-------------\n\n")));
	if(efs_init(&efs,0)!=0){
		DBG((TXT("Could not init filesystem.\n")));
		hang();
	}

	for(i=1;i<=4;i++){
		offset1=c2str(1,path);
		path[offset1++]='/';
		for(e=1;e<=12;e++){
			offset2=offset1;
			offset2+=c2str(e,path+offset1);
			DBG((TXT("Dir name: %s.\n"),path));
		}
	}
	/*for(i=1;i<10;i++){	
		path[0]='D';
		path[1]='I';
		path[2]='R';
		path[3]=0x30+((i%10000)/1000);
		path[4]=0x30+((i%1000)/100);
		path[5]=0x30+((i%100)/10);
		path[6]=0x30+((i%10)/1);
		path[7]='\0';
		err=mkdir(&efs.myFs,path);
		if(err!=0){
			DBG((TXT("ERROR: Could not create directory %s (%d) - returned ERR %d.\n"),path,i,err));
			hang();
		}
		DBG((TXT("DIR %s created.\n"),path));
		for(e=1;e<6;e++){
			path[7]='/';
			path[8]=0x40+e;
			path[9]='\0';
			err=mkdir(&efs.myFs,path);
			if(err!=0){
				DBG((TXT("ERROR: Could not create directory %s (%d) - returned ERR %d.\n"),path,i,err));
				hang();
			}
			DBG((TXT("DIR %s created.\n"),path));
			for(t=0;t<26;t++){
				path[9]='/';
				path[10]='t';
				path[11]='e';
				path[12]='s';
				path[13]='t';
				path[14]='-';
				path[15]=0x41+t;
				path[16]='.';
				path[17]='t';
				path[18]='x';
				path[19]='t';
				path[20]='\0';
				if(file_fopen(&file_w,&efs.myFs,path,'w')!=0){
					DBG((TXT("Could not open file %s for writing.\n"),path));		
					hang();
				}
				file_write(&file_w,15,"Dit is een test");
				file_fclose(&file_w);
			}
		}
	}*/

	file_fclose(&file_w);
	fs_umount(&efs.myFs);

	DBG((TXT("Done :-)\n\n")));
	
	hang();
}
Beispiel #21
0
static void __fs_unmount_all_applic(struct linkedentry *entry)
{
	if(entry->obj != devfs)
		fs_umount(entry->obj);
}