コード例 #1
0
int init_fs(struct v7 *v7) {
  struct fs_info fs0, fs1;
  int r, r0, r1;

  r0 = fs_get_info(0, &fs0);
  r1 = fs_get_info(1, &fs1);

  dprintf(("r0 = %d, r1 = %d\n", r0, r1));

  if (r0 == 0 && r1 == 0) {
    if (fs0.seq < fs1.seq) {
      r1 = -1;
    } else {
      r0 = -1;
    }
  }
  if (r0 == 0) {
    r = fs_mount(0, &s_fsm);
  } else if (r1 == 0) {
    r = fs_mount(1, &s_fsm);
  } else {
    r = fs_format(0);
    if (r != 0) return r;
    r = fs_mount(0, &s_fsm);
  }

  return r;
}
コード例 #2
0
ファイル: main.c プロジェクト: ebayol/systemeDeFichiers
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;
}
コード例 #3
0
ファイル: fs_sim.c プロジェクト: jiak94/operatingsystem
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]);
}
コード例 #4
0
ファイル: infofs.cpp プロジェクト: mallardtheduck/osdev
void infofs_init(){
	if(!info_items) info_items=new map<string, info_function>();
	fs_registerfs(infofs_driver);
	fs_mount("INFO", NULL, "INFOFS");
	infofs_register("VERSION", &info_kernel);
	infofs_register("CPUID", &info_cpu);
}
コード例 #5
0
ファイル: create_devdir.c プロジェクト: dzavalishin/oskit
/*
 * Create a /dev directory in the bmod filesystem, and mount the virtual
 * directory on top of it.
 */
oskit_error_t
oskit_create_slashdev()
{
        struct fs_dir	*newfsd;
	int		rc;
	void		find_rootdisk();

	if (mkdir("/dev", 0666) < 0)
		if (errno != OSKIT_EEXIST)
			panic("oskit_create_slashdev: "
			      "Could not create /dev");

	/*
	 * Create the virtual top level directory, and mount it.
	 */
        if ((newfsd = fs_dir_allocate("/devices")) == NULL)
		panic("oskit_create_slashdev: Out of memory");		
	
	if ((rc = fs_mount("/dev", (oskit_file_t *) &newfsd->diri.ops)) != 0)
		panic("oskit_create_slashdev: fs_mount failed errno %d\n", rc);

	oskit_dir_release(&newfsd->diri);

	return 0;
}
コード例 #6
0
ファイル: subsystem.c プロジェクト: tegrak/Fricando
/*
 * Listen for reading line in subsystem
 */
static void ss_listen(const char *ss_prompt, const char *fs_name)
{
  char *line = NULL;

  /*
   * Mount filesystem
   */
  if (fs_name != NULL) {
    fs_type = fs_mount(fs_name);
    if (fs_type >= 0 && fs_type < FS_TYPE_NUM_MAX) {
      info("mount filesystem successfully.");
    } else {
      info("failed to mount filesystem.");
    }
  } else {
    fs_type = -1;
  }

  /*
   * Init auto completion callback
   */
  rl_attempted_completion_function = ss_attempted_completion;

  /*
   * Read line
   */
  ss_data.abort = 0;

  while (ss_data.abort == 0) {
    /*
     * Init auto completion
     */
    rl_bind_key('\t', rl_complete);

    /*
     * Line processing
     */
    line = readline((const char *)ss_prompt);

    if (line != NULL && strlen(line) > 0) {
      ss_add_history(line);
      ss_exec_line(line);
    }

    if (line != NULL) {
      free((void *)line);
      line = NULL;
    }
  }
}
コード例 #7
0
ファイル: cgi_upgrade.c プロジェクト: Undrizzle/yolanda
cgi_status cgi_write_upload_data_end(cs_uint8 type, cs_boolean succ)
{
    cs_uint8 tmp[4];
    if(type == CGI_UPLOAD_JFFS2_TYPE)
    {
        flash_part_write_done(g_upload_cb.part_index);
        if(succ)
        {
            fs_mount();
            g_verify_img_flag = 1;
        }
        return CGI_OK;
    }
    else if(type == CGI_UPLOAD_WLB_TYPE)
    {
        img_upgrade_download_stop(0);
        if(succ)
        {
            g_verify_img_flag = 2;
        }
        return CGI_OK;
    }
    else
    {
        if(0 != mif_upgrade(IROS_MID_WEB, tmp, 0, &mif_state, TRUE))
        {
            return CGI_INNER_ERROR;
        }
        else
        {
            if(succ)
            {
                if(mif_state.tlv_update_successed & 0x1 ||
                    mif_state.tlv_update_successed & 0x4 ||
                    mif_state.tlv_update_successed & 0x200)
                {
                    CGI_DEBUG("need reset\n");
                    g_verify_img_flag = 2;
                }
                else
                {
                    g_verify_img_flag = 1;
                }
            }
            return CGI_OK;
        }
    }
}
コード例 #8
0
ファイル: init.c プロジェクト: XRobinHe/lk
void target_init(void)
{
    stm32_debug_init();

    qspi_flash_init(N25Q128A_FLASH_SIZE);

#if ENABLE_LCD
    memory_lcd_init();
#endif

#if WITH_LIB_MINIP
    uint8_t mac_addr[6];
    gen_random_mac_address(mac_addr);
    eth_init(mac_addr, PHY_KSZ8721);

    /* start minip */
    minip_set_macaddr(mac_addr);

    uint32_t ip_addr = IPV4(192, 168, 0, 98);
    uint32_t ip_mask = IPV4(255, 255, 255, 0);
    uint32_t ip_gateway = IPV4_NONE;

    minip_init(stm32_eth_send_minip_pkt, NULL, ip_addr, ip_mask, ip_gateway);
#endif

#if WITH_LIB_FS_SPIFS
    status_t mount_success = fs_mount(DEAULT_SPIFS_MOUNT_POINT,
                                      DEAULT_SPIFS_NAME, SPIFS_TARGET_DEVICE);
    if (mount_success != NO_ERROR) {
        printf("failed to mount '%s' at path '%s' on '%s'."
               " Make sure that device is formatted\n",
               DEAULT_SPIFS_NAME, DEAULT_SPIFS_MOUNT_POINT,
               SPIFS_TARGET_DEVICE);
    }

#endif

    // start usb
    target_usb_setup();

#if ENABLE_SENSORBUS
    sensor_bus_init();
#endif
}
コード例 #9
0
void nodemcu_init(void)
{
    NODE_ERR("\n");
    // Initialize platform first for lua modules.
    if( platform_init() != PLATFORM_OK )
    {
        // This should never happen
        NODE_DBG("Can not init platform for modules.\n");
        return;
    }

#if defined(FLASH_SAFE_API)
    if( flash_safe_get_size_byte() != flash_rom_get_size_byte()) {
        NODE_ERR("Self adjust flash size.\n");
        // Fit hardware real flash size.
        flash_rom_set_size_byte(flash_safe_get_size_byte());

        if( !fs_format() )
        {
            NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" );
            NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" );
        }
        else {
            NODE_ERR( "format done.\n" );
        }
        fs_unmount();   // mounted by format.

        // Reboot to get SDK to use (or write) init data at new location
        system_restart ();

        // Don't post the start_lua task, we're about to reboot...
        return;
    }
#endif // defined(FLASH_SAFE_API)

#if defined ( BUILD_SPIFFS )
    fs_mount();
    // test_spiffs();
#endif
    // endpoint_setup();

    task_post_low(task_get_id(start_lua),'s');
}
コード例 #10
0
ファイル: fs_syscall.c プロジェクト: tjjh89017/zeke
static int sys_mount(void * user_args)
{
    struct _fs_mount_args * args = 0;
    vnode_t * mpt;
    int err;
    int retval = -1;

    err = copyinstruct(user_args, (void **)(&args),
            sizeof(struct _fs_mount_args),
            GET_STRUCT_OFFSETS(struct _fs_mount_args,
                source, source_len,
                target, target_len,
                parm,   parm_len));
    if (err) {
        set_errno(-err);
        goto out;
    }

    /* Validate path strings */
    if (!strvalid(args->source, args->source_len) ||
        !strvalid(args->target, args->target_len)) {
        set_errno(ENAMETOOLONG);
        goto out;
    }

    if (fs_namei_proc(&mpt, -1, (char *)args->target, AT_FDCWD)) {
        set_errno(ENOENT); /* Mount point doesn't exist */
        goto out;
    }

    err = fs_mount(mpt, args->source, args->fsname, args->flags,
                   args->parm, args->parm_len);
    if (err) {
        set_errno(-err);
        goto out;
    }

    retval = 0;
out:
    freecpystruct(args);
    return retval;
}
コード例 #11
0
ファイル: main.c プロジェクト: sonicyang/freertos-stm32
int main()
{
	init_rs232();
	enable_rs232_interrupts();
	enable_rs232();
	
	fs_init();
	fio_init();
    
    //register_fs(&ramfs_r);
    register_devfs();
    register_ramfs();
    fs_mount(NULL, RAMFS_TYPE, NULL);

//	register_romfs("romfs", &_sromfs);
//	register_ramfs("ramfs");
	
	/* Create the queue used by the serial task.  Messages for write to
	 * the RS232. */
	vSemaphoreCreateBinary(serial_tx_wait_sem);
	/* Add for serial input 
	 * Reference: www.freertos.org/a00116.html */
	serial_rx_queue = xQueueCreate(1, sizeof(char));

	/* Create a task to output text read from romfs. */
	xTaskCreate(command_prompt,
	            "CLI",
	            512 /* stack size */, NULL, tskIDLE_PRIORITY + 2, NULL);

#if 0
	/* Create a task to record system log. */
	xTaskCreate(system_logger,
	            (signed portCHAR *) "Logger",
	            1024 /* stack size */, NULL, tskIDLE_PRIORITY + 1, NULL);
#endif

	/* Start running the tasks. */
	vTaskStartScheduler();

	return 0;
}
コード例 #12
0
ファイル: fs_util.c プロジェクト: Zeke-OS/zeke
vnode_t * fs_create_pseudofs_root(fs_t * newfs, int majornum)
{
    int err;
    vnode_t * rootnode;

    /*
     * We use a little trick here and create a temporary vnode that will be
     * destroyed after succesful mount.
     */

    rootnode = kzalloc(sizeof(vnode_t));
    if (!rootnode)
        return NULL;

    /* Temp root dir */
    rootnode->vn_next_mountpoint = rootnode;
    vrefset(rootnode, 1);
    mtx_init(&rootnode->vn_lock, VN_LOCK_TYPE, VN_LOCK_OPT);

    err = fs_mount(rootnode, "", "ramfs", 0, "", 1);
    if (err) {
        KERROR(KERROR_ERR,
               "Unable to create a pseudo fs root vnode for %s (%i)\n",
               newfs->fsname, err);

        return NULL;
    }
    rootnode = rootnode->vn_next_mountpoint;
    kfree(rootnode->vn_prev_mountpoint);
    rootnode->vn_prev_mountpoint = rootnode;
    rootnode->vn_next_mountpoint = rootnode;

    newfs->fs_majornum = majornum;
    newfs->sblist_head = rootnode->sb->fs->sblist_head;
    rootnode->sb->fs = newfs;

    rootnode->sb->vdev_id = DEV_MMTODEV(majornum, 0);

    return rootnode;
}
コード例 #13
0
ファイル: fs_main.c プロジェクト: alkap007/ali3606
static int mount_device(const char *dev_name, const char *vol_name)
{
	int result = 0;
	
	result = fs_mkdir(vol_name, 0);
	if(result < 0)
	{
		FS_PRINTF("mkdir: %s failed! ret = %d\n", vol_name, result);
		return result;
	}
	FS_PRINTF("mount: %s -> %s...", dev_name, vol_name);
	result = fs_mount(vol_name, dev_name, "FAT", 0, NULL);
	if(result == -EINVAL)
	{
		result = fs_mount(vol_name, dev_name, "NTFS", 0, NULL);
        if (result == -EBUSY)
		{
			fs_unmount(vol_name, 1);
			result = fs_mount(vol_name, dev_name, "NTFS", 0, NULL);    
		}
	}
	else if(result == -EBUSY)
	{
		fs_unmount(vol_name, 1);
		result = fs_mount(vol_name, dev_name, "FAT", 0, NULL);
		if(result == -EINVAL)
		{
			result = fs_mount(vol_name, dev_name, "NTFS", 0, NULL);
			if(result == -EBUSY)
			{
				fs_unmount(vol_name, 1);
				result = fs_mount(vol_name, dev_name, "NTFS", 0, NULL);    
			}
		}
	}
	if(result >= 0)
	{
		FS_PRINTF("successed!\n");
	}
	else
	{
		FS_PRINTF("failed! err = %d\n", result);
		fs_rmdir(vol_name);
	}

	return result;	
}
コード例 #14
0
ファイル: kinit.c プロジェクト: Zeke-OS/zeke
static void mount_tmp_rootfs(void)
{
    const char failed[] = "Failed to mount rootfs";
    vnode_t * tmp = NULL;
    struct proc_info * kernel_proc;
    int ret;

    kernel_proc = proc_ref(0);
    if (!kernel_proc) {
        panic(failed);
    }
    /* No need to keep the ref because it won't go away. */
    proc_unref(kernel_proc);

    /* Root dir */
    tmp = kzalloc_crit(sizeof(vnode_t));
    kernel_proc->croot = tmp;
    kernel_proc->croot->vn_next_mountpoint = kernel_proc->croot;
    kernel_proc->croot->vn_prev_mountpoint = kernel_proc->croot;
    mtx_init(&tmp->vn_lock, MTX_TYPE_SPIN, 0);
    vrefset(kernel_proc->croot, 2);

    ret = fs_mount(kernel_proc->croot, "", "ramfs", 0, "", 1);
    if (ret) {
        KERROR(KERROR_ERR, "%s : %i\n", failed, ret);
        goto out;
    }

    kernel_proc->croot->vn_next_mountpoint->vn_prev_mountpoint =
        kernel_proc->croot->vn_next_mountpoint;
    kernel_proc->croot = kernel_proc->croot->vn_next_mountpoint;
    kernel_proc->cwd = kernel_proc->croot;

out:
    kfree(tmp);
}
コード例 #15
0
ファイル: ext2util.c プロジェクト: MaddTheSane/ext2fsx
int main(int argc, char **argv)
{
    char		rawdevpath[MAXPATHLEN];
    char		blockdevpath[MAXPATHLEN];
    char		opt;
    struct stat	sb;
    int			ret = FSUR_INVAL;

    /* save & strip off program name */
    progname = argv[0];
    argc--;
    argv++;

    /* secret debug flag - must be 1st flag */
    debug = (argc > 0 && !strcmp(argv[0], "-D"));
    if (debug) { /* strip off debug flag argument */
        argc--;
        argv++;
    }

    if (argc < 2 || argv[0][0] != '-')
        usage();
    opt = argv[0][1];
    if (opt != FSUC_PROBE && opt != FSUC_MOUNT && opt != FSUC_UNMOUNT && opt != FSUC_LABEL
         && FSUC_GETUUID != opt) {
        usage(); /* Not supported action */
    }
    if ((opt == FSUC_MOUNT || opt == FSUC_UNMOUNT || opt == FSUC_LABEL) && argc < 3)
        usage(); /* mountpoint arg missing! */

    snprintf(rawdevpath, MAXPATHLEN, "%s%s", RAWDEV_PREFIX, argv[1]);
    if (stat(rawdevpath, &sb) != 0) {
        fprintf(stderr, "%s: stat %s failed, %s\n", progname, rawdevpath,
                strerror(errno));
        exit(FSUR_INVAL);
    }

    snprintf(blockdevpath, MAXPATHLEN, "%s%s", BLOCKDEV_PREFIX, argv[1]);
    if (stat(blockdevpath, &sb) != 0) {
        fprintf(stderr, "%s: stat %s failed, %s\n", progname, blockdevpath,
                strerror(errno));
        exit(FSUR_INVAL);
    }

    switch (opt) {
        case FSUC_PROBE: {
            if (argc != 4)
                usage();
            ret = fs_probe(rawdevpath,
                        strcmp(argv[2], DEVICE_FIXED),
                        strcmp(argv[3], DEVICE_READONLY));
            break;
        }

        case FSUC_MOUNT:
        case FSUC_MOUNT_FORCE:
            if (argc != 7)
                usage();
            if (strcmp(argv[3], DEVICE_FIXED) && strcmp(argv[3], DEVICE_REMOVABLE)) {
                printf("ext2fs.util: ERROR: unrecognized flag (removable/fixed) argv[%d]='%s'\n",3,argv[3]);
                usage();
            }
                if (strcmp(argv[4], DEVICE_READONLY) && strcmp(argv[4], DEVICE_WRITABLE)) {
                    printf("ext2fs.util: ERROR: unrecognized flag (readonly/writable) argv[%d]='%s'\n",4,argv[4]);
                    usage();
                }
                if (strcmp(argv[5], DEVICE_SUID) && strcmp(argv[5], DEVICE_NOSUID)) {
                    printf("ext2fs.util: ERROR: unrecognized flag (suid/nosuid) argv[%d]='%s'\n",5,argv[5]);
                    usage();
                }
                if (strcmp(argv[6], DEVICE_DEV) && strcmp(argv[6], DEVICE_NODEV)) {
                    printf("ext2fs.util: ERROR: unrecognized flag (dev/nodev) argv[%d]='%s'\n",6,argv[6]);
                    usage();
                }
                ret = fs_mount(blockdevpath,
                            argv[2],
                            strcmp(argv[3], DEVICE_FIXED),
                            strcmp(argv[4], DEVICE_READONLY),
                            strcmp(argv[5], DEVICE_NOSUID),
                            strcmp(argv[6], DEVICE_NODEV));
            break;
        case FSUC_UNMOUNT:
            ret = fs_unmount(rawdevpath);
            break;
        case FSUC_LABEL:
            if (argc != 3)
               usage();
               
            ret = fs_label(blockdevpath, argv[2]);
            break;
         case FSUC_GETUUID:
            {
               CFStringRef uuid;
               
               if (argc != 2)
                  usage();
               
               ret = FSUR_INVAL;
               uuid = extsuper_uuid(blockdevpath);
               if (uuid) {
                  char pruuid[40];
                  ret = FSUR_IO_SUCCESS;
                  /* Convert to UTF8 */
                  (void) CFStringGetCString(uuid, pruuid, sizeof(pruuid),
                     kCFStringEncodingUTF8);
                  CFRelease(uuid);
                  /* Write to stdout */
                  write(1, pruuid, strlen(pruuid));
               }
            }
            break;
         case FSUC_SETUUID:
            /* This is done at volume creation time */
         case FSUC_ADOPT:
         case FSUC_DISOWN:
         case FSUC_MKJNL:
         case FSUC_UNJNL:
            ret = FSUR_INVAL;
            break;
        default:
            usage();
    }

    #ifdef DEBUG
    report_exit_code(ret);
    #endif
    exit(ret);

    return(ret);
}
コード例 #16
0
void nodemcu_init(void)
{
    NODE_ERR("\n");
    // Initialize platform first for lua modules.   
    if( platform_init() != PLATFORM_OK )
    {
        // This should never happen
        NODE_DBG("Can not init platform for modules.\n");
        return;
    }

#if defined(FLASH_SAFE_API)
    if( flash_safe_get_size_byte() != flash_rom_get_size_byte()) {
        NODE_ERR("Self adjust flash size.\n");
        // Fit hardware real flash size.
        flash_rom_set_size_byte(flash_safe_get_size_byte());
        // Flash init data at FLASHSIZE - 0x04000 Byte.
        flash_init_data_default();
        // Flash blank data at FLASHSIZE - 0x02000 Byte.
        flash_init_data_blank();
        if( !fs_format() )
        {
            NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" );
            NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" );
        }
        else{
            NODE_ERR( "format done.\n" );
        }
        fs_unmount();   // mounted by format.
    }
#endif // defined(FLASH_SAFE_API)

    if( !flash_init_data_written() ){
        NODE_ERR("Restore init data.\n");
        // Flash init data at FLASHSIZE - 0x04000 Byte.
        flash_init_data_default();
        // Flash blank data at FLASHSIZE - 0x02000 Byte.
        flash_init_data_blank(); 
    }

#if defined( BUILD_WOFS )
    romfs_init();

    // if( !wofs_format() )
    // {
    //     NODE_ERR( "\ni*** ERROR ***: unable to erase the flash. WOFS might be compromised.\n" );
    //     NODE_ERR( "It is advised to re-flash the NodeWifi image.\n" );
    // }
    // else
    //     NODE_ERR( "format done.\n" );

    // test_romfs();
#elif defined ( BUILD_SPIFFS )
    fs_mount();
    // test_spiffs();
#endif
    // endpoint_setup();

    // char* lua_argv[] = { (char *)"lua", (char *)"-e", (char *)"print(collectgarbage'count');ttt={};for i=1,100 do table.insert(ttt,i*2 -1);print(i);end for k, v in pairs(ttt) do print('<'..k..' '..v..'>') end print(collectgarbage'count');", NULL };
    // lua_main( 3, lua_argv );
    // char* lua_argv[] = { (char *)"lua", (char *)"-i", NULL };
    // lua_main( 2, lua_argv );
    // char* lua_argv[] = { (char *)"lua", (char *)"-e", (char *)"pwm.setup(0,100,50) pwm.start(0) pwm.stop(0)", NULL };
    // lua_main( 3, lua_argv );
    // NODE_DBG("Flash sec num: 0x%x\n", flash_get_sec_num());
    task_init();
    system_os_post(USER_TASK_PRIO_0,SIG_LUA,'s');
}
コード例 #17
0
ファイル: main.c プロジェクト: niroren22/testFAT
int main(void)
{
	unsigned long ulPeriod;
	unsigned long ulDelay;

	unsigned long recvData = 11;

	volatile int status = 0;

	char buffer[40];
	unsigned int bytesdRead;

	FRESULT res;
	FIL fileobj;

	SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);

	//Initialize pins
	init_pins();

	//Initialize peripherals
	init_periph();

	I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false);//false for 100kHz mode
	    //0x68 is the 7-bit address of the DS1307
	I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, 0x68, false);//true for a read action
	I2CMasterDataPut(I2C0_MASTER_BASE, 0x10);      //first Date/Time Register
	I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
	while(I2CMasterBusy(I2C0_MASTER_BASE)){}
	I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
	while(I2CMasterBusy(I2C0_MASTER_BASE)){}
	recvData = I2CMasterDataGet(I2C0_MASTER_BASE);
	while(I2CMasterBusy(I2C0_MASTER_BASE)){}

	fs_mount();

	if(disk_status(0) == 0)
	{
		status++;
	}
	else
	{
	    status--;
	}

	if (status == 1) {
		res = f_open(&fileobj, "config.txt", FA_OPEN_EXISTING | FA_READ);
		res = f_read(&fileobj, buffer, 6, &bytesdRead);
	}

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

	GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0);

	ulPeriod = SysCtlClockGet() / 10;
	ulDelay = ((ulPeriod / 2) / 3) - 4 ;

	while(1)
	{
		// Turn on the LED
		GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0x01);

		// Delay for a bit
		SysCtlDelay(ulDelay);

		// Turn off the LED
		GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0x00);

		// Delay for a bit
		SysCtlDelay(ulDelay);
	}
}
コード例 #18
0
int main (int argc, char **argv) {
	
	srand(time(NULL));
	unsigned char test_data[TEST_DATA_SIZE] = {0};
	unsigned char cmp_test_data[TEST_DATA_SIZE] = {0};
	createRandomData(test_data,TEST_DATA_SIZE);
	memcpy(&cmp_test_data, &test_data,TEST_DATA_SIZE);
	
	int PASSES = 0;

	assert (fs_mount() >= 0);
	assert (fs_create_file("/testDir", DIR_FILE) >= 0);
	assert (fs_unmount() >= 0);

PASS_OK

	assert (fs_mount() >= 0);
	assert (fs_create_file("/testDir", DIR_FILE) >= 0);
	assert (fs_create_file("/testDir/checkMe.txt", REG_FILE) >= 0);
	assert (fs_unmount() >= 0);
	
PASS_OK


	assert (fs_mount() >= 0);
	assert (fs_create_file("/testDir", DIR_FILE) >= 0);
	assert (fs_create_file("/testDir/checkMe.txt", REG_FILE) >= 0);
	assert (fs_write_file("/testDir/checkMe.txt", test_data, TEST_DATA_SIZE) >= 0);
	assert (fs_unmount() >= 0);
	
PASS_OK

	unsigned char readResults[TEST_DATA_SIZE] = {0};
	
	assert (fs_mount() >= 0);
	assert (fs_create_file("/testDir", DIR_FILE) >= 0);
	assert (fs_create_file("/testDir/checkMe.txt", REG_FILE) >= 0);
	assert (fs_write_file("/testDir/checkMe.txt", test_data, TEST_DATA_SIZE) >= 0);
	assert (fs_read_file("/testDir/checkMe.txt", readResults, TEST_DATA_SIZE) >= 0);
	int i = 0;
	for (;i < TEST_DATA_SIZE; ++i) {
		assert(readResults[i] == cmp_test_data[i]);
	}
	assert (fs_unmount() >= 0);
	
PASS_OK
	
	assert (fs_mount() >= 0);
	assert (fs_create_file("/testDir", DIR_FILE) >= 0);
	assert (fs_create_file("/testDir/checkMe.txt", REG_FILE) >= 0);
	assert (fs_create_file("/testDir/secondMe.txt", REG_FILE) >= 0);
	assert (fs_create_file("/testDir/thirdMe.txt", REG_FILE) >= 0);
	
	Directory_t dir;
	assert (fs_get_directory("/testDir/", &dir) >= 0);
	assert (dir.size == 3);
	assert(strncmp(dir.entries[0].filename,"checkMe.txt",strlen("checkMe.txt")) == 0);
	assert(strncmp(dir.entries[1].filename,"secondMe.txt",strlen("secondMe.txt")) == 0);
	assert(strncmp(dir.entries[2].filename,"thirdMe.txt",strlen("thirdMe.txt")) == 0);
	assert (fs_unmount() >= 0);
	
PASS_OK
	/*NEW TEST ADDED */
	assert (fs_mount() >= 0);
	assert (fs_create_file("/testDir", DIR_FILE) >= 0);
	assert (fs_create_file("/testDir/checkMe.txt", REG_FILE) >= 0);
	assert (fs_create_file("/testDir/secondMe.txt", REG_FILE) >= 0);
	assert (fs_create_file("/testDir/thirdMe.txt", REG_FILE) >= 0);
	assert (fs_remove_file("/testDir/thirdMe.txt") >= 0);
	
	assert (fs_get_directory("/testDir/", &dir) >= 0);
	assert (dir.size == 2);
	assert(strncmp(dir.entries[0].filename,"checkMe.txt",strlen("checkMe.txt")) == 0);
	assert(strncmp(dir.entries[1].filename,"secondMe.txt",strlen("secondMe.txt")) == 0);
	assert (fs_unmount() >= 0);
	

	return 0;
}
コード例 #19
0
ファイル: esp_fs.c プロジェクト: amid0/smart.js
int fs_init(uint32_t addr, uint32_t size) {
  return fs_mount(&fs, addr, size, spiffs_work_buf, spiffs_fds,
                  sizeof(spiffs_fds));
}
コード例 #20
0
ファイル: moboot.c プロジェクト: LetsUnlockiPhone/moboot
void moboot_init(const struct app_descriptor *app)
{
	int rv, keys_pressed;
	unsigned act;
	menu_entry_t *real_entries[32];

	char *ptr;
	int rc;
	char path[256];
	char *newpath;
	char *newtitle;
	char *newname;

	unsigned xoff, yoff;

	unsigned ramdisk_mounted, ramdisk_start, ramdisk_size;

	unsigned i, j;

	unsigned default_menu_entry = 0;
	unsigned next_menu_entry = 0;

	char default_image[256];
	char next_image[256];

	unsigned default_timeout;
	unsigned counted_images;
	unsigned use_next;
	ssize_t splash_sz;
	void *splash_ptr = NULL;
	ssize_t background_sz;
	void *background_ptr;
	ssize_t tile_sz;
	void *tile_ptr;
	char splash_path[256];

	unsigned boot_flags;

	ssize_t rdmsgsz;
	char *rdmsg;

	keys_pressed = 0;

	display_surface = NULL;

	entries = real_entries;

	gfx_trans = 0;

	gfxconsole_clear();
	gfxconsole_setpos(0,0);

	ramdisk_mounted = 0;
	atags_get_ramdisk(&ramdisk_start, &ramdisk_size);
	if (ramdisk_size && ramdisk_start) {
		ramdisk_init((void*)ramdisk_start, ramdisk_size);
		if (fs_mount("/ramdisk", "/dev/ramdisk")) {
			printf("Ramdisk start=%08x size=%08x\n", ramdisk_start, ramdisk_size);
			printf("Unable to mount /ramdisk\n");
			printf("Press SELECT to continue\n");
			gpiokeys_wait_select();
		} else {
			ramdisk_mounted = 1;
		}
	}


    if (fs_mount("/boot", "/dev/mmcblk0p13")) {
		printf("\nUnable to mount /boot, exiting.\n");
		while (1) {
			thread_sleep(20);
		}
	}

	default_timeout = 5;
	if ((rv = fs_load_file("/boot/moboot.timeout", &default_image, 256)) > 0) {
		default_image[rv] = 0;
		if (default_image[rv - 1] == '\n') default_image[rv - 1] = 0;
		default_timeout = atoui(default_image);
	}
	default_image[0] = 0;
	rv = fs_load_file("/boot/moboot.default", &default_image, 256);
	if (rv > 0) {
		default_image[rv] = 0;
		if (default_image[rv - 1] == '\n') default_image[rv - 1] = 0;
	}
	use_next = 0;
	next_image[0] = 0;
	rv = fs_load_file("/boot/moboot.next", &next_image, 256);
	if (rv > 0) {
		next_image[rv] = 0;
		if (next_image[rv - 1] == '\n') next_image[rv - 1] = 0;
	}

	tile_sz = fs_load_file_mem("/boot/moboot.background.tga", &tile_ptr);

	background_surface = NULL;
	tile_surface = NULL;

	if (tile_sz > 0) {
		tile_surface = tga_decode(tile_ptr, tile_sz,
									GFX_FORMAT_RGB_x888);
		struct display_info disp_info;
		if (!display_surface) {
			display_get_info(&disp_info);
			display_surface = gfx_create_surface_from_display(&disp_info);
		}
		background_surface = gfx_create_surface(NULL,
								display_surface->width,
								display_surface->height,
								display_surface->stride,
								display_surface->format);
		for (i = 0; i < display_surface->width; i += tile_surface->width) {
			for (j = 0; j < display_surface->height;
							j += tile_surface->height) {
				gfx_surface_blend(background_surface,
									tile_surface,
									i, j);
			}
		}
	}


	num_menu_entries = 0;

	i = 0;
	counted_images = 0;
	while ((rc = fs_dirent("/boot", i, &ptr)) > 0) {
		sprintf(path, "/boot/%s", ptr);
		if (strncmp("uImage.", ptr, 7) == 0) {
			if (strncmp("uImage.moboot", ptr, 13) != 0) {
				newtitle = malloc(strlen(ptr) - 7 + 5 + 1);
				sprintf(newtitle, "boot %s", ptr + 7);
				newpath = malloc(strlen(ptr) + 6 + 1);
				sprintf(newpath, "/boot/%s", ptr);
				newname = malloc(strlen(ptr) - 7 + 1);
				sprintf(newname, "%s", ptr + 7);
				if (strcmp(default_image, ptr + 7) == 0) {
					default_menu_entry = num_menu_entries;
				}
				if (strcmp(next_image, ptr + 7) == 0) {
					next_menu_entry = num_menu_entries;
					use_next = 1;
				}
				set_menu_entry(newtitle, BOOT_FS, newpath, newname);
				counted_images++;
			}
		}
		free(ptr);
		i++;
	}
	if (rc < 0) {
		dprintf(SPEW, "/boot dirList ERROR rc = %d\n", rc);
	}
	i = 0;
	while ((rc = fs_dirent("/ramdisk/boot", i, &ptr)) > 0) {
		sprintf(path, "/ramdisk/boot/%s", ptr);
		if (strncmp("uImage.", ptr, 7) == 0) {
			if (strncmp("uImage.moboot", ptr, 13) != 0) {
				newtitle = malloc(strlen(ptr) - 7 + 5 + 1);
				sprintf(newtitle, "boot %s", ptr + 7);
				newpath = malloc(strlen(ptr) + 14 + 1);
				sprintf(newpath, "/ramdisk/boot/%s", ptr);
				newname = malloc(strlen(ptr) - 7 + 1);
				sprintf(newname, "%s", ptr + 7);
				if (strcmp(default_image, ptr + 7) == 0) {
					default_menu_entry = num_menu_entries;
				}
				if (strcmp(next_image, ptr + 7) == 0) {
					next_menu_entry = num_menu_entries;
					use_next = 1;
				}
				set_menu_entry(newtitle, BOOT_FS, newpath, newname);
				counted_images++;
			}
		}
		free(ptr);
		i++;
	}
	if (rc < 0) {
		dprintf(SPEW, "/ramdisk/boot dirList ERROR rc = %d\n", rc);
	}
	
	if (counted_images == 0) {
		set_menu_entry("boot", BOOT_FS, "/boot/uImage-2.6.35-palm-tenderloin", "default");
	}


	if (gpiokeys_poll(KEY_ALL)) {
		keys_pressed = 1;
		printf("\nPlease release key(s)...");
		while (1) {
			thread_sleep(20);
			if (!gpiokeys_poll(KEY_ALL)) {
				break;
			}
		}
	}

	gfx_trans = 0;
	if (tile_surface) {
		gfx_trans = 1;
	}


	set_menu_entry("boot webOS Recovery", BOOT_RECOVER, "", "recover");
	set_menu_entry("reboot", BOOT_REBOOT, "", "reboot");
	// set_menu_entry("DFU", BOOT_DFU, "", "");
	set_menu_entry("shutdown", BOOT_SHUTDOWN, "", "shutdown");

	xoff = (gfxconsole_getwidth() - 16 ) / 2;
	if (num_menu_entries < 10) {
		yoff = (gfxconsole_getheight() - 12) / 2;
	} else {
		yoff = (gfxconsole_getheight() - (num_menu_entries + 4)) / 2;
	}

#if 0
	tgasz = fs_load_file_mem("/boot/moboot.tga", &tgaptr);

	tga_surface = NULL;

	if (tgasz > 0) {
		tga_surface = tga_decode(tgaptr, tgasz, GFX_FORMAT_RGB_x888);
		struct display_info disp_info;
		if (!display_surface) {
			display_get_info(&disp_info);
			display_surface = gfx_create_surface_from_display(&disp_info);
		}
	}
#endif

	while (1) {
		gfxconsole_clear();

		show_background();

		if (background_surface) {
			gfxconsole_setbackground(background_surface);
		}

		gfxconsole_settrans(gfx_trans);

		gfxconsole_setpos(xoff,yoff);
		if (gfx_trans) {
			gfxconsole_set_colors(0xffffffff, 0x00000000);
			printf("moboot %s", MOBOOT_VERSION);
			gfxconsole_setpos(xoff,yoff);
			gfxconsole_set_colors(0x00000000, 0x00000000);
		} else {
			gfxconsole_set_colors(0x00000000, 0xffffffff);
			printf("moboot %s", MOBOOT_VERSION);
			gfxconsole_set_colors(0x00000000, 0x000000ff);
		}

		if (!use_next || keys_pressed) {
			act = moboot_menu(xoff, yoff + 2, entries, default_menu_entry, num_menu_entries, keys_pressed ? 0 : default_timeout);
		} else {
			act = next_menu_entry;
			use_next = 0;
		}

		keys_pressed = 1;

		gfxconsole_setpos(xoff, yoff + 2 + num_menu_entries + 2);

		boot_flags = BOOTLINUX_NOFLAGS;

		switch (entries[act]->type) {
			case BOOT_RECOVER:
				reboot_device(RESTART_REASON_RECOVER);
				break;
			case BOOT_REBOOT:
				reboot_device(RESTART_REASON_REBOOT);
				break;
			case BOOT_DFU:
				reboot_device(RESTART_REASON_DFU);
				break;
			case BOOT_SHUTDOWN:
				reboot_device(RESTART_REASON_SHUTDOWN);
				break;
			case BOOT_FS:
				gfxconsole_clear();
				gfxconsole_settrans(gfx_trans);
				show_background();
				gfxconsole_setpos(0,0);

				if (gfx_trans) {
					gfxconsole_set_colors(0x00000000, 0x00000000);
				} else {
					gfxconsole_set_colors(0x00000000, 0x000000ff);
				}

				printf("Selected: '%s'\n\n", entries[act]->title);
				printf("Loading '%s'... ", entries[act]->arg);
				if ((rv = fs_load_file(entries[act]->arg,
							(void *)SCRATCH_ADDR, 
							SCRATCH_SIZE * 1024 * 1024)) < 0) {
					printf("FAILED\n");
				} else {
					printf("OK\n");

					/* check for verbose boot */
					sprintf(splash_path, "/boot/moboot.verbose.%s", 
								entries[act]->name);

					splash_sz = fs_load_file_mem(splash_path, &splash_ptr);

					if (splash_sz > 0) {
						if (strncmp(splash_ptr, "yes", 3) == 0) {
							boot_flags |= BOOTLINUX_VERBOSE;
						}
					}

					/* check for sercon boot */
					sprintf(splash_path, "/boot/moboot.sercon.%s", 
								entries[act]->name);

					splash_sz = fs_load_file_mem(splash_path, &splash_ptr);

					if (splash_sz > 0) {
						if (strncmp(splash_ptr, "yes", 3) == 0) {
							boot_flags |= BOOTLINUX_SERCON;
						}
					}

					if (splash_ptr) free(splash_ptr);

					/* check for splash image */
					sprintf(splash_path, "/boot/moboot.splash.%s.tga", 
								entries[act]->name);

					splash_sz = fs_load_file_mem(splash_path, &splash_ptr);

					splash_surface = NULL;

					if (splash_sz > 0) {
						splash_surface = tga_decode(splash_ptr, splash_sz,
													GFX_FORMAT_RGB_x888);
						struct display_info disp_info;
						if (!display_surface) {
							display_get_info(&disp_info);
							display_surface = gfx_create_surface_from_display(
													&disp_info);
						}
					}

					/* do it to it! */
					bootlinux_uimage_mem((void *)SCRATCH_ADDR, rv, boot_splash,
							boot_flags);
				}

				gfxconsole_set_colors(0x00000000, 0x00ff0000);
				printf("\n\nBOOT FAILED!\n\nPress SELECT to continue\n");
				gfxconsole_set_colors(0x00000000, 0x000000ff);
				gpiokeys_wait_select();
				break;
		}
	}
}
コード例 #21
0
ファイル: ct.c プロジェクト: mkatkar/libct
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);
}
コード例 #22
0
int init_fs(const char *container_prefix) {
  return fs_mount(container_prefix, &s_fsm);
}
コード例 #23
0
ファイル: main.c プロジェクト: Gitsyshk/iDove
int main(int argc, CmdArg* argv) {
	int i = 0;
	char result[0x10];
	if(!gGpHasInit || gCmdCount == 0) {
		if(gp_init()) {
			puts("Unable to initialize greenpois0n!!\n");
			return -1;
		}
		puts("=========================\n");
		puts("iFaith Thanks & Credits:\n");
		puts("=========================\n");
		puts("* AKi_nG\n");
		puts("* bile\n");
		puts("* Chronic Dev-Team\n");
		puts("* CPICH\n");
		puts("* cj\n");
		puts("* demize\n");
		puts("* geohot\n");
		puts("* GreySyntax\n");
		puts("* iFish12\n");
		puts("* msftguy\n");
		puts("* MuscleNerd\n");
		puts("* Neal\n");
		puts("* planetbeing\n");
		puts("* pod2g\n");
		puts("* posixninja\n");
		puts("* qwertyoruiop\n");
		puts("* sbingner\n");
		puts("* ThePirate\n");
		puts("* vonswanko\n");
		puts("=========================\n");
		cmd_detect();
		fs_mount("nand0a", "hfs", "/boot");		
		//puts("HFS+ filesystem mounted.\n")
		//puts("=========================\n");		
		return 0;
	}

	for(i = 1; i < argc; i++) {
		if(!strcmp(argv[i].string, "$_")) {
			NvramVar* retval = nvram_find_var("?");
			argv[i].string = retval->string;
			continue;
		}
		if(argv[i].string[0] == '$') {
			NvramVar* var = nvram_find_var(&(argv[i].string[1]));
			if(var == NULL) {
				printf("Unable to find nvram var for %s\n", &(argv[i].string[1]));
			} else {
				argv[i].string = var->string;
			}
		}
	}

	if(argc > 1) {
		int i = 0;
		char* command = argv[1].string;
		for(i = 0; i < gCmdCount; i++) {
			if(!strcmp(gCmdCommands[i]->name, command)) {
				int ret = gCmdCommands[i]->handler(argc-1, &argv[1]);
				snprintf(result, 0xF, "0x%x", ret);
				nvram_set_var("cmd-results", result);
				return ret;
			}
		}

		printf("Command %s not found.\n\n", command);
		return -1;
	}

	return 0;
}
コード例 #24
0
ファイル: shell.c プロジェクト: joaoelvas/File-System
int main( int argc, char *argv[] )
{
	char line[1024];
	char cmd[1024];
	char arg1[1024];
	char arg2[1024];
	int 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,"debug")) {
			if(args==1) {
				fs_debug();
			} else {
				printf("use: debug\n");
			}
		} else if(!strcmp(cmd,"getsize")) {
			if(args==2) {
				result = fs_getsize(arg1);
				if(result>=0) {
					printf("file %s has size %d\n",arg1,result);
				} else {
					printf("getsize failed!\n");
				}
			} else {
				printf("use: getsize <filename>\n");
			}
			
		} else if(!strcmp(cmd,"create")) {
			if(args==2) {
				result = fs_create(arg1);
				if(result==0) {
					printf("created file %s\n",arg1);
				} else {
					printf("create failed!\n");
				}
			} else {
				printf("use: create <filename>\n");
			}
		} else if(!strcmp(cmd,"delete")) {
			if(args==2) {
				if(!fs_delete(arg1)) {
					printf("file %s deleted.\n",arg1);
				} else {
					printf("delete failed!\n");	
				}
			} else {
				printf("use: delete <filename>\n");
			}
		} else if(!strcmp(cmd,"cat")) {
			if(args==2) {
				if(!do_copyout(arg1,"/dev/stdout")) {
					printf("cat failed!\n");
				}
			} else {
				printf("use: cat <name>\n");
			}

		} else if(!strcmp(cmd,"copyin")) {
			if(args==3) {
				if(do_copyin(arg1,arg2)) {
					printf("copied file %s to  %s\n",arg1,arg2);
				} else {
					printf("copy failed!\n");
				}
			} else {
				printf("use: copyin <filename in host system> <filename in fs-miei-02>\n");
			}

		} else if(!strcmp(cmd,"copyout")) {
			if(args==3) {
				if(do_copyout(arg1,arg2)) {
					printf("copied myfs_file %s to file %s\n", arg1,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("    debug\n");
			printf("    create\n");
			printf("    delete  <filename>\n");
			printf("    cat     <filename>\n");
			printf("    getsize <filename>\n");
			printf("    copyin  <file name in host system> <miei02-filename>\n");
			printf("    copyout <miei02-filename> <file name in host system>\n");
			printf("	dump <number_of_block_with_text_contents>\n");
			printf("    help\n");
			printf("    quit\n");
			printf("    exit\n");
		} else if(!strcmp(cmd,"quit")) {
			break;
		} else if(!strcmp(cmd,"exit")) {
			break;
		} else if (!strcmp(cmd, "dump")){
			if(args==2) {
				int blNo = atoi(arg1);
				printf("Dumping disk block %d\n", blNo);
				char b[4096];
				disk_read( blNo, b);
				printf("------------------------------\n");
				printf("%s", b);
				printf("\n------------------------------\n");
			}
			else {
				printf("use: dump <block_number>\n");
			}
		} 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;
}
コード例 #25
0
ファイル: esp_wisleep.c プロジェクト: pellepl/wisleep
void user_init(void) {
    uart_set_baud(0, 921600);

    printf("\n\nESP8266 UMAC\n\n");

    bridge_init();
    umac_cfg um_cfg = {
        .timer_fn = umac_impl_request_future_tick,
        .cancel_timer_fn = umac_impl_cancel_future_tick,
        .now_fn = umac_impl_now_tick,
        .tx_byte_fn = umac_impl_tx_byte,
        .tx_buf_fn = umac_impl_tx_buf,
        .rx_pkt_fn = umac_impl_rx_pkt,
        .rx_pkt_ack_fn = bridge_pkt_acked,
        .timeout_fn = bridge_timeout,
        .nonprotocol_data_fn = NULL
    };
    umac_init(&um, &um_cfg, rx_buf);

    um_tim_hdl = xTimerCreate(
                     (signed char *)"umac_tim",
                     10,
                     false,
                     (void *)um_tim_id, um_tim_cb);

    char ap_cred[128];
    struct sdk_station_config config;
    bool setup_ap = true;

    systask_init();
    device_id = 0;
    fs_init();
    if (fs_mount() >= 0) {
#if 0
        spiffs_DIR d;
        struct spiffs_dirent e;
        struct spiffs_dirent *pe = &e;

        fs_opendir("/", &d);
        while ((pe = fs_readdir(&d, pe))) {
            printf("%s [%04x] size:%i\n", pe->name, pe->obj_id, pe->size);
        }
        fs_closedir(&d);
#endif

        // read preferred ssid
        spiffs_file fd_ssid = fs_open(".ssid", SPIFFS_RDONLY, 0);
        if (fd_ssid > 0) {
            if (fs_read(fd_ssid, (uint8_t *)ap_cred, sizeof(ap_cred)) > 0) {
                fs_close(fd_ssid);
                char *nl_ix = strchr(ap_cred, '\n');
                if (nl_ix > 0) {
                    memset(&config, 0, sizeof(struct sdk_station_config));
                    strncpy((char *)&config.ssid, ap_cred, nl_ix - ap_cred);
                    char *nl_ix2 = strchr(nl_ix + 1, '\n');
                    if (nl_ix2 > 0) {
                        strncpy((char *)&config.password, nl_ix + 1, nl_ix2 - (nl_ix + 1));
                        setup_ap = false;
                    }
                }
                printf("ssid:%s\n", config.ssid);
            } // if read
            else {
                printf("could not read .ssid\n");
            }
        } // if fs_ssid
        else {
            printf("no .ssid found, running softAP\n");
        }
        // find device id or create one
        spiffs_file fd_devid = fs_open(".devid", SPIFFS_RDONLY, 0);
        if (fd_devid < 0) {
            device_id = hwrand();
            fd_devid = fs_open(".devid", SPIFFS_O_CREAT | SPIFFS_O_TRUNC | SPIFFS_O_WRONLY | SPIFFS_O_APPEND, 0);
            fs_write(fd_devid, &device_id, 4);
            printf("create devid\n");
        } else {
            fs_read(fd_devid, &device_id, 4);
        }
        fs_close(fd_devid);
        printf("devid %08x\n", device_id);

        // remove previous scan results
        fs_remove(SYSTASK_AP_SCAN_FILENAME);
    } // if mount

    if (setup_ap) {
        sdk_wifi_set_opmode(SOFTAP_MODE);

        struct ip_info ap_ip;
        IP4_ADDR(&ap_ip.ip, 192, 169, 1, 1);
        IP4_ADDR(&ap_ip.gw, 0, 0, 0, 0);
        IP4_ADDR(&ap_ip.netmask, 255, 255, 255, 0);
        sdk_wifi_set_ip_info(1, &ap_ip);


        struct sdk_softap_config ap_cfg = {
            .ssid = "WISLEEP",
            .password = "",
            .ssid_len = 7,
            .channel = 1,
            .authmode = AUTH_OPEN,
            .ssid_hidden = false,
            .max_connection = 255,
            .beacon_interval = 100
        };

        sdk_wifi_softap_set_config(&ap_cfg);

        ip_addr_t first_client_ip;
        IP4_ADDR(&first_client_ip, 192, 169, 1, 100);
        dhcpserver_start(&first_client_ip, 4);
    } else {
        // required to call wifi_set_opmode before station_set_config
        sdk_wifi_set_opmode(STATION_MODE);
        sdk_wifi_station_set_config(&config);
    }

    server_init(server_actions);
    um_mutex = xSemaphoreCreateMutex();
    xTaskCreate(uart_task, (signed char * )"uart_task", 512, NULL, 2, NULL);
    xTaskCreate(server_task, (signed char *)"server_task", 1024, NULL, 2, NULL);
}
コード例 #26
0
ファイル: shell.c プロジェクト: gmsconstantino/aiso2014
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;
}
コード例 #27
0
ファイル: subsystem.c プロジェクト: tegrak/Fricando
/*
 * 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;
}