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

📄 filedemo.c

📁 nucleus file NUCLEUS的文件系统源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
		{
		    Errors[task_id]++;  /* Log error */
		}

	} /* End While (1) */


}


/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "task_1"                         */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This task creates files in the root directory and writes        */
/*      512 bytes to each file.  Then it deletes all files it created   */
/*      in the root directory using a wildcard.  The creating,          */
/*      writing, and deleting are repeated in an endless loop.          */
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      kernel                              Started by task_0.          */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      bail_out                            Error reporting routine.    */
/*      NU_Become_File_User                 Registers this task as a    */
/*                                          user of the file system.    */
/*      NU_Close                            Close a file.               */
/*      NU_Delete                           Delete a file(s).           */
/*      NU_Open                             Open a file for access.     */
/*      NU_Open_Disk                        Open a disk for access.     */
/*      NU_Set_Default_Drive                Select default drive.       */
/*      NU_Write                            Write data to a file.       */
/*                                          on the disk.                */
/*                                                                      */
/*  INPUTS                                                              */
/*       NONE.                                                          */
/*                                                                      */
/*  OUTPUTS                                                             */
/*       NONE                                                           */
/*                                                                      */
/************************************************************************/
void   task_1(UNSIGNED argc, VOID *argv)
{
int fd;                         /* File descriptor for file access */                   
int ii;                         /* Local loop variable */
STATUS status;                  /* Return value from funtion calls */
int task_id = TASK1;            /* Task number for this task */
CHAR fname[] = "T1F0FILE.DOC";  /* Base file name */



    /* Access argc and argv just to avoid compilation warnings.  */
    status = (STATUS)argc + (STATUS)argv;

    /* Each task must register as a Nucleus user */
    if (!NU_Become_File_User())
    {
        PRINTF("NU_Become_File_User error!");
        bail_out();
    }

    /* Open the ramdisk for access */
    status = NU_Open_Disk(DEMO_DISK); 

	/* Set default drive for future access */
    status = NU_Set_Default_Drive(DEMO_DRIVE);

    /* do forever loop */
    while (1)
	{
		/* Create 10 files in the root directory */
		for ( ii = 0; ii < 10; ii++)
		{ 
			/* Make unique file name for each */
            fname[3] = 0x30 + ii;  /* ascii numbers 0-4 */

			/* Create File */
			fd = NU_Open(fname,(PO_TEXT|PO_RDWR|PO_CREAT|PO_TRUNC),
				               (PS_IWRITE | PS_IREAD));

            /* Write 512 bytes to the new file */
            status = NU_Write(fd, outbuf, (INT32)512);

			/* Check status for number of bytes written */
			if (status == 512)
			{
                Files_Created[task_id]++;  /* Increment Task1 Files Created */
			}
			else
			{
			    Errors[task_id]++;  /* Log error */
			}

			/* Close file */
 	        status = NU_Close(fd);

		}  /* End For (ii ) */

		/* Delete all files */
		status = NU_Delete("*.DOC"); 

		/* Check status for success */
		if( status == NU_SUCCESS )
		{
            Files_Deleted[task_id] += 10;  /* Increment Task1 Files Deleted */
		}
		else
		{
		    Errors[task_id]++;  /* Log error */
		}

	} /* End While (1) */
	
	
}



/************************************************************************/
/*                                                                      */
/*  FUNCTION                           "task_2"                         */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This task creates a group of nested subdirectories each         */
/*      containing a file.  Then it walks back up through the           */
/*      directories, deleting the files and subdirectories.  The        */
/*      creating, writing, and deleting are repeated in an endless      */
/*      loop.                                                           */
/*                                                                      */
/*  AUTHOR                                                              */
/*                      Accelerated Technology                          */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      kernel                              Started by task_0.          */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      bail_out                            Error reporting routine.    */
/*      NU_Become_File_User                 Registers this task as a    */
/*                                          user of the file system.    */
/*      NU_Close                            Close a file.               */
/*      NU_Delete                           Delete a file(s).           */
/*      NU_Make_Dir                         Create a new directory.     */
/*      NU_Open                             Open a file for access.     */
/*      NU_Open_Disk                        Open a disk for access.     */
/*      NU_Remove_Dir                       Remove a directory.         */
/*      NU_Set_Current_Dir                  Set default directory.      */
/*      NU_Set_Default_Drive                Select default drive.       */
/*      NU_Write                            Write data to a file.       */
/*                                          on the disk.                */
/*                                                                      */
/*  INPUTS                                                              */
/*       NONE.                                                          */
/*                                                                      */
/*  OUTPUTS                                                             */
/*       NONE                                                           */
/*                                                                      */
/************************************************************************/
void   task_2(UNSIGNED argc, VOID *argv)
{
int fd;                         /* File descriptor for file access */                   
int ii;                         /* Local loop variable */
STATUS status;                  /* Return value from funtion calls */
int task_id = TASK2;            /* Task number for this task */
CHAR fname[] = "T2FILE0.TXT";   /* Base file name */
CHAR dname[] = "T2SUB0";        /* Base directory name */



    /* Access argc and argv just to avoid compilation warnings.  */
    status = (STATUS)argc + (STATUS)argv;

    /* Each task must register as a Nucleus user */
    if (!NU_Become_File_User())
    {
        PRINTF("NU_Become_File_User error!");
        bail_out();
    }

    /* Open the ramdisk for access */
    status = NU_Open_Disk(DEMO_DISK); 

	/* Set default drive for future access */
    status = NU_Set_Default_Drive(DEMO_DRIVE);

	
	/* do forever loop */
    while (1)
	{
        /* Set directory to root */
		status = NU_Set_Current_Dir (DEMO_ROOT);

        /* Create 5 nested directories and 5 files */
		for ( ii = 0; ii < 5; ii++) 
		{
            /* Make directory names unique */
			dname[5] = 0x30 + ii;  /* ascii numbers 0-4 */

            /* Create the directory */
			status = NU_Make_Dir (dname);

			/* Check status for success */
			if( status == NU_SUCCESS )
			{
                Directories_Created[task_id]++;  /* Increment Task2 Directories Created */
			}
			else
			{
			    Errors[task_id]++;         /* Log error */
			}

			/* Set current directory to new directory */
			status = NU_Set_Current_Dir (dname);

            /* Make filename unique */
			fname[6] = 0x30 + ii;  /* ascii numbers 0-4 */

			/* Create File */
			fd = NU_Open(fname,(PO_TEXT|PO_RDWR|PO_CREAT|PO_TRUNC),
				               (PS_IWRITE | PS_IREAD));

			/* Write 512 bytes to the new file */
            status = NU_Write(fd, outbuf, 512);

			/* Check status for number of bytes written */
			if (status == 512)
			{
                Files_Created[task_id]++;  /* Increment Task2 Files Created */
			}
			else
			{
			    Errors[task_id]++;
			}

            /* Close file */  
 	        status = NU_Close(fd);


		} /* End For (ii create ) */

        /* Walk back up through directories */
		/* while deleting files and sub directories */
		for ( ii = 4; ii >= 0; ii--) 
		{
			/* Delete the file */
			status = NU_Delete("*.TXT");

			/* Check status for success */
			if( status == NU_SUCCESS )
			{
                Files_Deleted[task_id]++;  /* Increment Task2 Files Deleted */
			}
			else
			{
			    Errors[task_id]++;         /* Log error */
			}

            /* Create current directory name */
			dname[5] = 0x30 + ii;  /* ascii numbers 0-4 */

			/* Change directory to parent directory */
			status = NU_Set_Current_Dir ("..");

			/* Delete the subdirectory */
			status = NU_Remove_Dir(dname);

			/* Check status for success */
			if( status == NU_SUCCESS )
			{
                Directories_Deleted[task_id]++;  /* Increment Task2 Directories Deleted */
			}
			else
			{
			    Errors[task_id]++;         /* Log error */
			}
            
		} /* End For (ii delete ) */


	}  /* End While (1) */
		
}



/************************************************************************/
/*                                                                      */

⌨️ 快捷键说明

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