/** format [<mount>] */
static int cmd_format(int argc, char *argv[])
{
	URET ret;
	const char *mount = "/";
	uffs_Device *dev;
	UBOOL force = U_FALSE;

	if (argc > 1) {
		mount = argv[1];
		if (argc > 2 && strcmp(argv[2], "-f") == 0)
			force = U_TRUE;
	}
	MSGLN("Formating %s ... ", mount);

	dev = uffs_GetDeviceFromMountPoint(mount);
	if (dev == NULL) {
		MSGLN("Can't get device from mount point.");
		return -1;
	}
	else {
		ret = uffs_FormatDevice(dev, force);
		if (ret != U_SUCC) {
			MSGLN("Format fail.");
			return -1;
		}
		else {
			MSGLN("Format succ.");
		}
		uffs_PutDevice(dev);
	}

	return 0;
}
Exemple #2
0
/*
 * 函数功能: 格式化分区
 * 输入参数: 分区名称
 * 返回参数: 
 */
int uffs_format(const char *name)
{
	int ret;
	const char *mount = "/";
	uffs_Device *dev;

	if(name) 
	{
		mount = name;
	}

	dev = uffs_GetDeviceFromMountPoint(mount);
	if(dev == NULL) 
	{
		uffs_Perror(UFFS_ERR_NORMAL, "Can't get device from mount point.");
	}
	else 
	{
		if(dev->ref_count == 1) 
		{
			ret = uffs_FormatDevice(dev);
			uffs_Perror(UFFS_ERR_NORMAL, "Format %s.",ret==RT_EOK?"succ":"fail");
		}
		else 
		{
			uffs_Perror(UFFS_ERR_NORMAL, "dev->ref_count: %d, can't format this device.", dev->ref_count);
		}
		uffs_PutDevice(dev);
	}
	return TRUE;	
}
int uffs_format(const char *mount_point)
{
	uffs_Device *dev = NULL;
	URET ret = U_FAIL;

	dev = uffs_GetDeviceFromMountPoint(mount_point);
	if (dev) {
		uffs_GlobalFsLockLock();
		ret = uffs_FormatDevice(dev, U_TRUE);
		uffs_GlobalFsLockUnlock();
	}

	return ret == U_SUCC ? 0 : -1;
}
Exemple #4
0
/* t_format : test format partition */
static int cmd_TestFormat(int argc, char *argv[])
{
	URET ret;
	const char *mount = "/";
	uffs_Device *dev;
	UBOOL force = U_FALSE;
	const char *test_file = "/a.txt";
	int fd;
	int rc = -1;

	if (argc > 1) {
		mount = argv[1];
		if (argc > 2 && strcmp(argv[2], "-f") == 0)
			force = U_TRUE;
	}

	fd = uffs_open(test_file, UO_RDWR | UO_CREATE);
	if (fd < 0) {
		MSGLN("can't create test file %s", test_file);
		goto ext;
	}

	MSGLN("Formating %s ... ", mount);

	dev = uffs_GetDeviceFromMountPoint(mount);
	if (dev == NULL) {
		MSGLN("Can't get device from mount point.");
		goto ext;
	}
	else {
		ret = uffs_FormatDevice(dev, force);
		if (ret != U_SUCC) {
			MSGLN("Format fail.");
		}
		else {
			MSGLN("Format succ.");
			rc = 0;
		}
		uffs_PutDevice(dev);
	}

	uffs_close(fd);  // this should fail on signature check !
ext:
	return rc;
}
Exemple #5
0
static BOOL cmdTestFormat(const char *tail)
{
	URET ret;
	const char *mount = "/";
	uffs_Device *dev;
	const char *next;
	UBOOL force = U_FALSE;
	const char *test_file = "/a.txt";
	int fd;

	if (tail) {
		mount = cli_getparam(tail, &next);
		if (next && strcmp(next, "-f") == 0)
			force = U_TRUE;
	}

	fd = uffs_open(test_file, UO_RDWR | UO_CREATE);
	if (fd < 0) {
		MSGLN("can't create test file %s", test_file);
		return U_TRUE;
	}

	MSGLN("Formating %s ... ", mount);

	dev = uffs_GetDeviceFromMountPoint(mount);
	if (dev == NULL) {
		MSGLN("Can't get device from mount point.");
	}
	else {
		ret = uffs_FormatDevice(dev, force);
		if (ret != U_SUCC) {
			MSGLN("Format fail.");
		}
		else {
			MSGLN("Format succ.");
		}
		uffs_PutDevice(dev);
	}

	uffs_close(fd);  // this should fail on signature check !

	return TRUE;
}