📄 ramdemo.c
字号:
/* a directory. */
/* looping Checks for user input. */
/* NU_Delete Delete a file. */
/* bail_out Error reporting routine. */
/* NU_Sleep Sleep for a number of ticks.*/
/* NU_Remove_Dir Delete a directory entry. */
/* NU_Make_Dir Make a directory entry. */
/* NU_Open Open a file. */
/* NU_Write Write a file. */
/* NU_Close Close a file. */
/* NU_Resume Resume a task. */
/* */
/* INPUTS */
/* */
/* task_id ID of the task running. */
/* dir_id Name of the directory */
/* */
/* OUTPUTS */
/* NONE */
/* */
/************************************************************************/
VOID write_test( int task_id, char *dir_id)
{
INT i;
char fname_1[14];
char fname_2[14];
DSTAT statobj;
BOOL more;
PCFD fd;
/* Something to write into the file */
pc_memfill(wr_buf, 512, 'A');
/* Delete the directory if it exists. */
if (NU_Is_Dir(dir_id))
{
/* Set the current working directory. */
if (!NU_Set_Current_Dir(dir_id))
bail_out(CANT_SET_WRK_DIR);
/* Get the first file in the current directory. */
if (NU_Get_First(&statobj, "*.*"))
{
/* Go through the entire directory and delete all of the
files in it. */
do {
/* Make sure that this is not a directory. */
if (!(statobj.fattribute & ADIRENT))
{
/* Get the name of this file. */
mkname(fname_1, &statobj);
/* Get next so the DROJ is no longer open */
more = NU_Get_Next(&statobj);
/* If there are no more files to process, close the
search. */
if (!more)
NU_Done(&statobj);
/* Check for input. */
while (looping())
{
/* Delete the file. */
if (NU_Delete(fname_1))
{
/* Indicate that the file was properly deleted
and get out of the while loop. */
RAM_Files_Deleted[task_id]++;
break;
}
/* If we were unable to delete the file because
of any reason other than someone else is using
it, then we will stop processing. */
else if (fs_user->p_errno != PEACCES)
bail_out(CANT_REM_FILE);
/* Wait to see if whoever was using the file gives it
up. */
else
NU_Sleep(5);
}
}
else
{
/* Get the next file in the list. */
more = NU_Get_Next(&statobj);
/* If there are no more files to get, clean up the
search. */
if (!more)
NU_Done(&statobj);
}
} while (more);
}
/* Set the current working directory to the root. */
if (!NU_Set_Current_Dir("\\"))
bail_out(CANT_SET_WRK_DIR);
/* Delete the directory. - Note it can fail if the scanner is
inside the directory. So we loop if EACCESS is the error */
while(looping())
{
/* Delete the directory. */
if (NU_Remove_Dir(dir_id))
{
/* Indicate that the directory has been deleted. */
RAM_Directories_Deleted[task_id]++;
break;
}
/* If we cannot delete the directory for any reason other than
another user is using it, then we will quit processing. */
else if (fs_user->p_errno != PEACCES)
bail_out(CANT_REM_DIR);
/* Wait for whoever is using the directory to release it. */
else
NU_Sleep(5);
}
}
/* Check for user input. */
looping();
/* Create the directory. */
if (!NU_Make_Dir(dir_id))
bail_out(CANT_CREAT_DIR);
/* Indicate that the directory was created. */
RAM_Directories_Created[task_id]++;
/* Check for input. */
looping();
/* Set the current working directory. */
if (!NU_Set_Current_Dir(dir_id))
bail_out(CANT_SET_WRK_DIR);
/* Create 20 files */
for (i = 0; (looping() && i < 20); i++)
{
/* Create a unique file name (note that it must be in upper
case letters. */
fname_1[0] = '\0'; pc_strcat(fname_1,"FILE. ");
fname_1[5] = (char) ('A'+(char) i);
/* Now create the file. */
if ((fd = NU_Open(fname_1,(PO_BINARY|PO_WRONLY|PO_CREAT|PO_TRUNC),
(PS_IWRITE | PS_IREAD) ) ) < 0)
bail_out(CANT_OPEN_FILE);
/* Write to the file. */
if (NU_Write(fd,(UTINY*) wr_buf, (UCOUNT)512) != 512)
bail_out(CANT_WRITE_FILE);
/* Close the file. */
NU_Close(fd);
/* Indicate that a file has been created. */
RAM_Files_Created[task_id]++;
}
/* Rename the 20 files */
for (i = 0; (looping() && i < 20); i++)
{
/* Create the file names for the current file and the new
name. */
fname_1[0] = '\0';
pc_strcat(fname_1,"FILE. ");
fname_1[5] = (char) ('A'+(char) i);
fname_2[0] = '\0';pc_strcat(fname_2,"NEWFILE. ");
fname_2[8] = (char) ('A'+(char) i);
/* Rename the file. */
if (!NU_Rename(fname_1, fname_2))
bail_out(CANT_REN_FILE);
/* Indicate that the file was renamed. */
RAM_Files_Renamed[task_id]++;
}
/* Go back to the root directory. */
if (!NU_Set_Current_Dir("\\"))
bail_out(CANT_SET_WRK_DIR);
}
/************************************************************************/
/* */
/* FUNCTION "write_test" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This routine scans the whole dirve specified by drive_id. It */
/* then increments a counter indicating that it found a file. */
/* */
/* The routine simulates recursion with a local stack (to reduce) */
/* the stack requirements of the function). */
/* */
/* AUTHOR */
/* Accelerated Technology */
/* CALLED FROM */
/* */
/* nuf_task_0 Initiator task. */
/* */
/* ROUTINES CALLED */
/* */
/* pc_set_default_drive Sets RAM as default drive. */
/* error_log Records an error. */
/* pc_mpath Make a path name. */
/* pc_strcat Concatenate a sting. */
/* strcmp Compare two strings. */
/* NU_Set_Current_Dir Indicates current directory.*/
/* NU_Is_Dir Determines if the entry is */
/* a directory. */
/* NU_Get_First Gets the first file in a */
/* directory. */
/* mkname Constructs a valid file name*/
/* NU_Get_Next Gets the next file in a */
/* directory started by */
/* NU_Get_First. */
/* NU_Done Cleans up after searching */
/* a directory. */
/* looping Checks for user input. */
/* bail_out Error reporting routine. */
/* */
/* INPUTS */
/* */
/* task_id Task makeing the call. */
/* drive_id Physical ID of the drive. */
/* scan_stack Local stack for dir names. */
/* path Current path for search. */
/* */
/* OUTPUTS */
/* NONE */
/* */
/************************************************************************/
BOOL scan_drive( int task_id, char *drive_id, char scan_stack[30][13],
char *path) /*__fn__*/
{
char fname_buffer[14];
DSTAT statobj;
int i,stackp;
BOOL found_dir;
BOOL display_files;
/* Set the default drive to drive_id */
if (!pc_set_default_drive(drive_id))
return(error_log(CANT_SELECT));
/* clear our directory stack and reset the stack pointer */
for (stackp=0; stackp<30; stackp++)
scan_stack[stackp][0]='\0';
/* Initialize our pseudo stack pointer. */
stackp = 0;
/* Loop forever. traversing the file system using our own private "stack"
when the "stack" pointer drops back to zero we have scanned the whole
drive and may return */
while(looping())
{
/* Use our stack to get back to the directory we were working in.
We also build up the path name as we go. */
if (!NU_Set_Current_Dir("\\"))
return(error_log(CANT_SET_DEF));
/* Start at the root. */
path[0]='\\'; path[1] = '\0';
/* Go through our entire stack. */
for (i = 0; i < stackp; i++)
{
/* Set the current directory to the root. */
if (!NU_Set_Current_Dir(scan_stack[i]))
return(error_log(CANT_SET_DEF));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -