📄 dtest_old_1.c
字号:
/*
* Test file for s3c2410b
*/
#include "yaffsfs.h"
int dumpDir(const char * path);
int crtFile(const char * path,int s);
int main()
{
int i;
char str[64];
yaffs_StartUp();
yaffs_mount("/boot");
dumpDir("/boot");
printf("free spaces %d left in /boot\n",yaffs_freespace("/boot"));
}
int crtFile(const char * path,int s)
{
int fd;
char buf[1024];
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)
{
printf("Cannot create file %s\n",path);
return 0;
}
printf("file %s created\n",path);
for(i=0;i<s;i++)ret=yaffs_write(fd,buf,1024);
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);
printf("DumpDir %s\n",path);
ydrent=yaffs_readdir(ydir);
while(ydrent)
{
sprintf(buf,"%s/%s",path,ydrent->d_name);
yaffs_stat(buf,&stat);
printf(" %s Length:%d Mode:%X ",ydrent->d_name,stat.st_size,stat.st_mode);
switch (stat.st_mode&S_IFMT)
{
case S_IFREG: printf("data file"); break;
case S_IFDIR: printf("directory"); break;
case S_IFLNK: printf("symlink -->");
if(yaffs_readlink(buf,buf,100) < 0)
printf("no alias");
else
printf("\"%s\"",buf);
break;
default: printf("unknown"); break;
}
printf("\n");
ydrent=yaffs_readdir(ydir);
}
yaffs_closedir(ydir);
}
int fillWithFiles(const char * path)
{
}
int main_1()
{
int f;
int fda,fdb;
int fd;
char buf[600];
int i;
char c;
int ret;
struct yaffs_stat stat;
yaffs_StartUp();
yaffs_mount("/boot");
c='a';
for (i=0;i<600 ;i++ )
{
buf[i]=c;
c++;
if (c>'z')
{
c='a';
}
}
for (i=0;i<26 ;i++ )
{
printf("%c",buf[i]);
};printf("\n");
fda=yaffs_open("/boot/test_a",O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
printf("file /boot/test_a open %d \n",fda);
ret=yaffs_write(fda,buf,600);
printf("write %d bytes to /boot/test_a\n",ret);
ret=yaffs_fstat(fda,&stat);
printf("file stat return %d\n",ret);
printf("file size %d\n",stat.st_size);
fdb=yaffs_open("/boot/test_b",O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
printf("file /boot/test_b open %d \n",fdb);
ret=yaffs_write(fdb,buf,600);
printf("write %d bytes to /boot/test_b\n",ret);
yaffs_close(fda);
yaffs_close(fdb);
////////////////////////
printf("\n");
memset(buf,0,600);
fda=yaffs_open("/boot/test_a",O_RDWR , 0);
printf("file /boot/test_a open %d\n",fda);
ret=yaffs_fstat(fda,&stat);
printf("file stat return %d\n",ret);
printf("file size %d\n",stat.st_size);
ret=yaffs_lseek(fda,0,SEEK_SET);
ret=yaffs_read(fda,buf,400);
printf("read %d bytes from /boot/test_a\n",ret);
for (i=0;i<26 ;i++ )
{
printf("%c",buf[i]);
}printf("\n");
//////////////////////////
memset(buf,0,600);
fdb=yaffs_open("/boot/test_b",O_RDWR , 0);
printf("file /boot/test_b open %d\n",fdb);
ret=yaffs_lseek(fdb,100,SEEK_SET);
ret=yaffs_read(fdb,buf,100);
printf("read %d bytes from /boot/test_b\n",ret);
for (i=0;i<26 ;i++ )
{
printf("%c",buf[i]);
}printf("\n");
yaffs_close(fda);
yaffs_close(fdb);
c='1';
for (i=0;i<600 ;i++ )
{
buf[i]=c;
c++;
if(c>'9')c='1';
}
fda=yaffs_open("/boot/test_a",O_WRONLY | O_APPEND,0);
printf("write to /boot/test_a ");
for (i=0;i<100 ;i++ )
{
ret=yaffs_write(fda,buf,600);
printf(".");
};printf("\n");
yaffs_close(fda);
fda=yaffs_open("/boot/test_a",O_RDWR,0);
ret=yaffs_fstat(fda,&stat);
printf("\n/boot/test_a filesize is %d\n",stat.st_size);
ret=yaffs_lseek(fda,1000,SEEK_SET);
ret=yaffs_read(fda,buf,100);
printf("\n");
for(i=0;i<30;i++)printf("%c",buf[i]);
printf("\n");
yaffs_close(fda);
f = yaffs_freespace("/boot");
printf("\n%d free when disk full\n",f);
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -