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

📄 rtfsdem.c

📁 ertfs文件系统里面既有完整ucos程序
💻 C
📖 第 1 页 / 共 2 页
字号:
                    truncate
                    close                   
                end loop
                loop
                    rename
                    delete                  
                end loop
            now delete all of the subdirectories

*/      
    
char get_test(void)
{
char option;
char io_buf[10];
char drive;
int driveno;

    while(1)
    {
        tm_printf("Select test to run where:\n");
        tm_printf("S) RTFS Test Shell\n");
        tm_printf("R) Regression Test only\n");
        tm_printf("Q) Quit\n");
        tm_printf("Enter choice: ");
        tm_gets(io_buf);
        option = io_buf[0];
        if (option == 'R')
        {
            //tm_printf("Select Drive (A, B, C, ..):\n");
            //tm_printf("Enter choice: ");
            //tm_gets(io_buf);
            //drive = io_buf[0];
            //driveno = (int) (drive - 'A');
            driveno = 7;
            if (driveno < 0 || driveno >= NDRIVES)
            {
                tm_printf("Invalid Drive number\n");
            }
            else
            {
                //test_drive[0] = drive;
                break;
            }
        }   
        else
            break;
    }

    return(option);
}

void do_test()                                        /* __fn__ */
{
    int i;
    int j;
#if (VFAT)
    char buffer[256];
    char home[64];
    char buffer3[256];
#else
    char buffer[132];
    char home[32];
    char buffer3[132];
#endif
    char c;
    char *p;
    char *p2;

    DIAG_OUT("Creating Subdirectory", test_dir)
    if (!pc_mkdir(test_dir))
        regress_error(RGE_MKDIR);
    if (!pc_set_cwd(test_dir))
        regress_error(RGE_SCWD);

    /* Make the top level subdirs and subdirs down to layer SUBDIRDEPTH */  
    home[0] = '\0';
    tc_strcat(home, test_drive);
    tc_strcat(home, "\\");
    tc_strcat(home, test_dir);

    for (i = 0; i < NSUBDIRS; i++)
    {
        if (!pc_set_cwd(home))
            regress_error(RGE_SCWD);
        /* Make the top level subdirs */    
        buffer[0] = '\0';              /* These two lines are strcpy() */
#if (VFAT)
        tc_strcat(buffer, "Subdirectory_?");
#else
        tc_strcat(buffer, "SUB_?");
#endif
        c = 'A';
        c = (char) (c + i);
#if (VFAT)
        buffer[13] = c;
#else
        buffer[4] = c;
#endif
		DIAG_OUT("	Creating Subdirectory", buffer)

        if (!pc_mkdir(buffer))
            regress_error(RGE_MKDIR);
        for (j = 0; j < SUBDIRDEPTH; j++)
        {
            if (!pc_set_cwd(home))
                regress_error(RGE_SCWD);
#if (VFAT)
            tc_strcat(buffer,"\\Subdirectory");
#else
            tc_strcat(buffer,"\\SUBDIR");
#endif
			DIAG_OUT("		Creating Subdirectory", buffer)

            if (!pc_mkdir(buffer))
                regress_error(RGE_MKDIR);
            /* Create a dir. We know this will fail. Force error recovery */
            if (pc_mkdir(buffer))
                regress_error(RGE_MKDIRERR);
            /* Go into the new directory */
            if (!pc_set_cwd(buffer))
                regress_error(RGE_SCWD);
            /* Get the dir string */
            if (!pc_pwd(test_drive, buffer3))
                regress_error(RGE_PWD);
            DIAG_OUT("PWD Returns", buffer3)
            /* Funky. skip D:\RTFSTEST\ and then compare pwd with what we 
               set. Should match */
            p = buffer3;
            p2 = home;
            p2 += 2;
            while (*p2) { p++; p2++; };
            p++;
            if (tc_strcmp(p, buffer) != 0)
                regress_error(RGE_PWD);
        }
    }       

    /* Do the file test */
    do_file_test();

#if 0

    /* DELETE the  subdirs */   
    if (!pc_set_cwd(home))
        regress_error(RGE_SCWD);
    for (i = 0; i < NSUBDIRS; i++)
    {
        /* Delete sub directories SUB_?\SUBDIR\SUBDIR ... */
        for (j = SUBDIRDEPTH; j > 0; j--)
        {
            buffer[0] = '\0';              /* These two lines are strcpy() */
#if (VFAT)
            tc_strcat(buffer, "Subdirectory_?");
#else
            tc_strcat(buffer, "SUB_?");
#endif
            c = 'A';
            c = (char) (c + i);
#if (VFAT)
            buffer[13] = c;
#else
            buffer[4] = c;
#endif

            do_rm(buffer, j);
        }
        /* Delete sub directories SUB_? */
        buffer[0] = '\0';              /* These two lines are strcpy() */
#if (VFAT)
        tc_strcat(buffer, "Subdirectory_?");
#else
        tc_strcat(buffer, "SUB_?");
#endif
        c = 'A';
        c = (char) (c + i);
#if (VFAT)
        buffer[13] = c;
#else
        buffer[4] = c;
#endif
        if (!pc_rmdir(buffer))
           regress_error(RGE_RMDIR);
    }       
    
    /* Delete the test dir */
    if (!pc_set_cwd("..\\"))
        regress_error(RGE_SCWD);
    if (!pc_rmdir(test_dir))
        regress_error(RGE_RMDIR);

#endif

}

/* Delete a subdir at level */
void do_rm(char *buffer, int level)                              /*__fn__*/
{
int i;
    for (i = 0; i < level; i++)
#if (VFAT)
         tc_strcat(buffer,"\\Subdirectory");
#else
         tc_strcat(buffer,"\\SUBDIR");
#endif
    DIAG_OUT("      Removing Directory", buffer)
    if (!pc_rmdir(buffer))
        regress_error(RGE_RMDIR);
}


/* Test file manipulation routines */
void do_file_test()                                          /*__fn__*/
{
PCFD fdarray[NTESTFILES];
int i;
int j;
dword index;
char buffer[512];
char c;

#if USEPRINTF
#if (!VERBOSE)
    tm_printf("-");
#endif
#endif
	DIAG_OUT("		Performing File io test", " ")
	for (i = 0; i < NTESTFILES;i++)
    {
    	/* Make the filenames */    
        buffer[0] = '\0';              /* These two lines are strcpy() */
#if (VFAT)
        tc_strcat(buffer, "Long File Name_?");
#else
        tc_strcat(buffer, "FILE_?");
#endif
        c = 'A';
        c = (char) (c + i);
#if (VFAT)
        buffer[15] = c;
#else
        buffer[5] = c;
#endif
    	DIAG_OUT("		Create File : ", buffer)
    	fdarray[i] = po_open(buffer, PO_RDWR|PO_CREAT|PO_EXCL, PS_IWRITE|PS_IREAD);
    	
    	if (fdarray[i] < 0)
        	regress_error(RGE_OPEN);
    }

    /* Write into the file using all file descriptors */
    for (i = 0; i < NTESTFILES;i++)
    {
        index = 0;
        if (po_lseek(fdarray[i], 0L, PSEEK_SET) == ~0L)
            regress_error(RGE_SEEK);
        for (j = 0; j < NLONGS; j++)
            test_rtfs_buf[j] = index++;
        if (po_write(fdarray[i], (byte *) test_rtfs_buf, (NLONGS*4)) != (NLONGS*4))
            regress_error(RGE_WRITE);
    }
    
    /* Read file using all fds */
    for (i = 0; i < NTESTFILES;i++)
    {
        index = 0;
        
        if (po_lseek(fdarray[i], 0, PSEEK_SET) != 0)
            regress_error(RGE_SEEK);
        if (po_read(fdarray[i], (byte *) test_rtfs_buf, (NLONGS*4)) != (NLONGS*4))
            regress_error(RGE_READ);
        for (j = 0; j < NLONGS; j++)
        {
            if (test_rtfs_buf[j] != index++)
                regress_error(RGE_READ);
        }
    }

    /* Close all secondary files */
    for (i = 0; i < NTESTFILES;i++)
    {
        if (!po_flush(fdarray[i]))
        	regress_error(RGE_FLUSH);
        
        if (po_close(fdarray[i]) != 0)
            regress_error(RGE_CLOSE);
    }
}


void regress_error(int error)                                   /*__fn__*/
{
#if USEPRINTF
    tm_printf_2("Error number : %d\n", error);
#endif
    aos_exit();
}
#endif /* #if (INCLUDE_REGRESS) */


// ********************************************************************
// tcd_error() - process a fatal error
//
//   This routine is called to exit the program when a fatal error has
//   been detected.
//
//   This routine never returns.
//

void tcd_error(int tasknumber, char *p)
{
char buf[10];
    ARGSUSED_INT(tasknumber);

    tm_printf_2("%s\n", p);
    tm_printf("Press any key to exit program");
    tm_gets(buf);
    aos_exit();
}

⌨️ 快捷键说明

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