Esempio n. 1
0
static int dfs_uffs_mkfs(const char* device_name)
{
	rt_base_t index;
	rt_uint32_t block;
	struct rt_mtd_nand_device * mtd;

	/*1. find the device index */
	for (index = 0; index < UFFS_DEVICE_MAX; index++)
	{
		if (rt_strncmp(nand_part[index].dev->parent.parent.name,
				       device_name, RT_NAME_MAX) == 0)
			break;
	}

	if (index == UFFS_DEVICE_MAX)
	{
		/* can't find device driver */
		rt_kprintf("can not find device driver: %s\n", device_name);
		return -DFS_STATUS_ENOENT;
	}

	/*2. then unmount the partition */
	uffs_Mount(nand_part[index].mount_path);
	mtd = nand_part[index].dev;

	/*3. erase all blocks on the partition */
	block = mtd->block_start;
	for (; block <= mtd->block_end; block++)
	{
		rt_mtd_nand_erase_block(mtd, block);
		if (rt_mtd_nand_check_block(mtd, block) != RT_EOK)
		{
			rt_kprintf("found bad block %d\n", block);
			rt_mtd_nand_mark_badblock(mtd, block);
		}
	}

	/*4. remount it */
	if (init_uffs_fs(&nand_part[index]) < 0)
	{
		return uffs_result_to_dfs(uffs_get_error());
	}
	return DFS_STATUS_OK;
}
int main(int argc, char *argv[])
{
	int ret;

	ret = init_uffs_fs();

	if (ret != 0) {
		printf ("Init file system fail: %d\n", ret);
		return -1;
	}

	cli_add_commandset(get_helper_cmds());
	cli_add_commandset(get_test_cmds());
	cliMain();

	release_uffs_fs();

	return 0;
}
Esempio n. 3
0
static int dfs_uffs_mount(
	struct dfs_filesystem* fs,
    unsigned long rwflag,
    const void* data)
{
	rt_base_t index;
	uffs_MountTable * mount_part;
	struct rt_mtd_nand_device * dev;
	
	RT_ASSERT(rt_strlen(fs->path) < (UFFS_MOUNT_PATH_MAX-1));
	dev = RT_MTD_NAND_DEVICE(fs->dev_id);

	/*1. find a empty entry in partition table */
	for (index = 0; index < UFFS_DEVICE_MAX ; index ++)
	{
		if (nand_part[index].dev == RT_NULL)
			break;
	}
	if (index == UFFS_DEVICE_MAX)
		return -DFS_STATUS_ENOENT;

	/*2. fill partition structure */
	nand_part[index].dev = dev;

	/* make a right mount path for uffs, end with '/' */
	rt_snprintf(nand_part[index].mount_path, UFFS_MOUNT_PATH_MAX, "%s/", fs->path);
	if (nand_part[index].mount_path[1] == '/')
		nand_part[index].mount_path[1] = 0;

	mount_part = &(nand_part[index].mount_table);
	mount_part->mount	= nand_part[index].mount_path;
	mount_part->dev = &(nand_part[index].uffs_dev);
	rt_memset(mount_part->dev, 0, sizeof(uffs_Device));//in order to make uffs happy.
	mount_part->dev->_private = dev;   /* save dev_id into uffs */
	mount_part->start_block = dev->block_start;
	mount_part->end_block = dev->block_end;
	/*3. mount uffs */
	if (init_uffs_fs(&nand_part[index]) < 0)
	{
		return uffs_result_to_dfs(uffs_get_error());
	}
	return 0;
}
Esempio n. 4
0
static int dfs_uffs_mkfs(rt_device_t dev_id)
{
    rt_base_t index;
    rt_uint32_t block;
    struct rt_mtd_nand_device * mtd;

    /*1. find the device index */
    for (index = 0; index < UFFS_DEVICE_MAX; index++)
    {
        if (nand_part[index].dev == (struct rt_mtd_nand_device *)dev_id)
            break;
    }

    if (index == UFFS_DEVICE_MAX)
    {
        /* can't find device driver */
        return -ENOENT;
    }

    /*2. then unmount the partition */
    uffs_Mount(nand_part[index].mount_path);
    mtd = nand_part[index].dev;

    /*3. erase all blocks on the partition */
    block = mtd->block_start;
    for (; block <= mtd->block_end; block++)
    {
        rt_mtd_nand_erase_block(mtd, block);
        if (rt_mtd_nand_check_block(mtd, block) != RT_EOK)
        {
            rt_kprintf("found bad block %d\n", block);
            rt_mtd_nand_mark_badblock(mtd, block);
        }
    }

    /*4. remount it */
    if (init_uffs_fs(&nand_part[index]) < 0)
    {
        return uffs_result_to_dfs(uffs_get_error());
    }
    return RT_EOK;
}
int main(int argc, char *argv[])
{
	int ret;

#ifdef UNIX
	signal(SIGSEGV, crash_handler);
#endif

	uffs_SetupDebugOutput(); 	// setup debug output as early as possible

	if (parse_options(argc, argv) < 0) {
		return -1;
	}
	
	if (conf_verbose_mode) {
		#if 1
		MSGLN("Internal data structure size:");
		MSGLN("  TreeNode: %d", sizeof(TreeNode));
		MSGLN("  struct BlockListSt: %d", sizeof(struct BlockListSt));
		MSGLN("  struct DirhSt: %d", sizeof(struct DirhSt));
		MSGLN("  struct FilehSt: %d", sizeof(struct FilehSt));
		MSGLN("  struct FdataSt: %d", sizeof(struct FdataSt));
		MSGLN("  struct uffs_TagStoreSt: %d", sizeof(struct uffs_TagStoreSt));
		MSGLN("  uffs_Buf: %d", sizeof(uffs_Buf));
		MSGLN("  struct uffs_BlockInfoSt: %d", sizeof(struct uffs_BlockInfoSt));
		MSGLN("");
		#endif
		print_params();
		print_mount_points();
	}

	// setup file emulator storage with parameters from command line
	setup_storage(femu_GetStorage());

	// setup file emulator private data
	setup_emu_private(femu_GetPrivate());

	ret = init_uffs_fs();
	if (ret != 0) {
		MSGLN ("Init file system fail: %d", ret);
		return -1;
	}

	cli_add_commandset(get_helper_cmds());
	cli_add_commandset(get_test_cmds());
	if (conf_command_line_mode) {
		if (conf_exec_script) {
			cli_interpret(script_command);
		}
		cli_main_entry();
	}
	else {
		if (conf_exec_script) {
			cli_interpret(script_command);
		}
		else {
			cli_main_entry();
		}
	}

	release_uffs_fs();

	return 0;
}