⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dtest.c

📁 USB_ON_s3c2410 USB_ON_s3c2410
💻 C
字号:
#include "def.h"
#include "option.h"
#include "2410addr.h"
#include "2410lib.h"
#include "2410slib.h"


#include "yaffsfs.h"

int dumpDir(const char * path);
int crtFile(const char * path,int s);

int Main()
{
	int i;
	char str[64];

	//init the CPU
    MMU_Init();
    ChangeClockDivider(1,1);          // 1:2:4       
    ChangeMPllValue(0xa1,0x3,0x1);    // FCLK=202.8MHz  
	Port_Init();
    Uart_Select(0);
    Uart_Init(0,115200);
#if 1
	Uart_Printf("Enter the main Routine\n");

	k9_test();

	Uart_Printf("Exit the main Routine\n");

	//return 0;
#endif
	yaffs_StartUp();
	yaffs_mount("/boot");
	dumpDir("/boot");

	crtFile("/boot/test_file_a",10);
	crtFile("/boot/test_file_b",33);

	yaffs_mkdir("/boot/test_dir",0);

	crtFile("/boot/test_dir/test_file_c",44);

	yaffs_symlink("/boot/test_file_a","/boot/test_dir/test_symlink_a");

	dumpDir("/boot");
	Uart_Printf("\n");
	dumpDir("/boot/test_dir");

	yaffs_readlink("/boot/test_dir/test_symlink_a",str,64);
	Uart_Printf("the real file of test_symlink_a is %s\n",str);
	
	Uart_Printf("free spaces %d left in /boot\n",yaffs_freespace("/boot"));

	yaffs_unlink("/boot/test_file_a");
	//yaffs_unlink("/boot/test_dir/test_symlink_a");

	Uart_Printf("\n");
	dumpDir("/boot");
	Uart_Printf("\n");
	dumpDir("/boot/test_dir");
		
	yaffs_readlink("/boot/test_dir/test_symlink_a",str,64);
	Uart_Printf("the real file of test_symlink_a is %s\n",str);

	Uart_Printf("free spaces %d left in /boot\n",yaffs_freespace("/boot"));

	return 0;
}

int crtFile(const char * path,int s)
{
	int fd;
	char buf[999];
	int i;
	char c;
	int ret;

	c='a';
	for (i=0;i<256 ;i++ )
	{
		buf[i]=c;
		c++;
		if(c>'z')c='a';
	}
	
	fd=yaffs_open(path,O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
	if (fd<0)
	{
		Uart_Printf("Cannot create file %s\n",path);
		return 0;
	}
	Uart_Printf("file %s created\n",path);
	for(i=0;i<s;i++)ret=yaffs_write(fd,buf,999);
	Uart_Printf("write %d bytes to /boot/test_b\n",ret);
	yaffs_close(fd);

}

int dumpDir(const char * path)
{
	//dump dir
	int fd;
	char buf[1024];
	int ret;
	int i;
	struct yaffs_stat stat;
	yaffs_DIR * ydir;
	struct yaffs_dirent * ydrent;

	ydir=yaffs_opendir(path);

	Uart_Printf("DumpDir %s\n",path);
	ydrent=yaffs_readdir(ydir);
	while(ydrent)
	{
		sprintf(buf,"%s/%s",path,ydrent->d_name);

		yaffs_lstat(buf,&stat);

		Uart_Printf("  %s Length:%d  Mode:%X  ",ydrent->d_name,stat.st_size,stat.st_mode);
		switch (stat.st_mode&S_IFMT)
		{
			case S_IFREG: Uart_Printf("data file"); break;
			case S_IFDIR: Uart_Printf("directory"); break;
			case S_IFLNK: Uart_Printf("symlink -->");
						  if(yaffs_readlink(buf,buf,100) < 0)
						  	Uart_Printf("no alias");
						  else
							Uart_Printf("\"%s\"",buf);	 
						  break;
			default: Uart_Printf("unknown"); break;
		}
		Uart_Printf("\n");
		ydrent=yaffs_readdir(ydir);
	}
	yaffs_closedir(ydir);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -