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

📄 rtfsdem.c

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

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

#if (EBSENV)
    // start the background console task again 
    // (in order to capture ESC, q and Q)
    aos_stop_console_tasks();
#endif

    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');
            if (driveno < 0 || driveno >= NDRIVES)
            {
                tm_printf("Invalid Drive number\n");
            }
            else
            {
                test_drive[0] = drive;
                break;
            }
        }   
        else
            break;
    }

#if (EBSENV)
    // start the background console task again 
    // (in order to capture ESC, q and Q)
    aos_resume_console_tasks();
#endif

    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();

    /* 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);
}

/* 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;

#if USEPRINTF
#if (!VERBOSE)
    tm_printf("-");
#endif
#endif
	DIAG_OUT("		Performing File io test", " ")

#if (VFAT)
    fdarray[0] = po_open("Long File Name", PO_RDWR|PO_CREAT|PO_EXCL, PS_IWRITE|PS_IREAD);
#else
    fdarray[0] = po_open("FILE", PO_RDWR|PO_CREAT|PO_EXCL, PS_IWRITE|PS_IREAD);
#endif
    if (fdarray[0] < 0)
        regress_error(RGE_OPEN);
    for (i = 1; i < NTESTFILES;i++)
    {
        /* This should fail */
#if (VFAT)
        fdarray[i] = po_open("Long File Name", PO_RDWR|PO_CREAT|PO_EXCL, PS_IWRITE|PS_IREAD);
#else
        fdarray[i] = po_open("FILE", PO_RDWR|PO_CREAT|PO_EXCL, PS_IWRITE|PS_IREAD);
#endif
        if (fdarray[i] >= 0)
            regress_error(RGE_OPEN);

        /* This should work */
#if (VFAT)
        fdarray[i] = po_open("Long File Name", PO_RDWR, PS_IWRITE|PS_IREAD);
#else                          
        fdarray[i] = po_open("FILE", PO_RDWR, PS_IWRITE|PS_IREAD);
#endif
        if (fdarray[i] < 0)
            regress_error(RGE_OPEN);
    }
    /* Write into the file using all file descriptors */
    index = 0;
    for (i = 0; i < NTESTFILES;i++)
    {
        if (po_lseek(fdarray[i], 0L, PSEEK_END) == ~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 */
    index = 0;
    for (i = 0; i < NTESTFILES;i++)
    {
        if (po_lseek(fdarray[i], (dword) (index*4), PSEEK_SET) != (long) (index*4))
            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);
        }
    }
    
    /* This should fail */  
    if (po_truncate(fdarray[0], 256))
        regress_error(RGE_TRUNC);

    if (!po_flush(fdarray[0]))
        regress_error(RGE_FLUSH);

    /* Close all secondary files */
    for (i = 1; i < NTESTFILES;i++)
    {
        if (po_close(fdarray[i]) != 0)
            regress_error(RGE_CLOSE);
    }
    /* This should work */  
    if (!po_truncate(fdarray[0], 256))
        regress_error(RGE_TRUNC);

    /* This should fail */  
    if (pc_unlink("FILE"))
        regress_error(RGE_UNLINK);

    if (po_close(fdarray[0]) != 0)
        regress_error(RGE_CLOSE);

#if (VFAT)
    if (!pc_mv("Long File Name", "New Long File Name"))
#else
    if (!pc_mv("FILE", "NEWFILE"))
#endif
        regress_error(RGE_MV);

    /* This should work */  
#if (VFAT)
    if (!pc_unlink("New Long File Name"))
#else
    if (!pc_unlink("NEWFILE"))
#endif
        regress_error(RGE_UNLINK);
}


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

// ********************************************************************
// APPLICATION INITIALIZATION
// ********************************************************************
#if (!defined(ERTFS_SA))
void  application_init()                             /* __fn__ */
{
    which_demo_running = RTFS_DEMO;
}
#endif

// ********************************************************************
// 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);

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

#if (EBSENV)
// ********************************************************************
// process_key() - process an input character
//
//    This routine is called to process input characters by the console
//    task.    
//    NOTE: for POLLOS this is called from the RTIP state machine stepping
//          routine
//
//    Returns nothing.
//

void process_key(unsigned int key)                             /* __fn__ */
{
#if (TEST_MODE)
PIFACE pi;
#endif

    if (key == 27 /* KEY_ESC */)
    {
        aos_exit();
    }
}
#endif

#if (RTXCNET)
// ********************************************************************
/* Resolves the dummy task we put in ctask.c */
void dummy (void)
{
}
#endif

⌨️ 快捷键说明

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