📄 ramdemo.c
字号:
/*************************************************************************/
/* */
/* Copyright (c) 1999 Accelerated Technology, Inc. */
/* */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the */
/* subject matter of this material. All manufacturing, reproduction, */
/* use, and sales rights pertaining to this subject matter are governed */
/* by the license agreement. The recipient of this software implicitly */
/* accepts the terms of the license. */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* FILE NAME ramdemo.c VERSION */
/* 1 */
/* */
/* COMPONENT */
/* */
/* DESCRIPTION */
/* Demonstrates the use of Nucleus FILE with the RAM */
/* device driver. */
/* */
/* AUTHOR -- Accelerated Technology */
/* EDITED BY Neil Henderson */
/* */
/* DATA STRUCTURES */
/* */
/* */
/* FUNCTIONS */
/* */
/* */
/* DEPENDENCIES */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* Neil Henderson 11-08-94 Original version. */
/*************************************************************************/
/* Include necessary Nucleus definitions. */
#include "nucleus.h"
/* Other includes. */
#include "pcdisk.h"
/* if a pcmcia controller needs to be initialized, define this to 1 */
#define INIT_PCMCIA 0
/* If printf facilities are available set this macro to 1 otherwise, use 0. */
#define PRINT_OUT 1
#if (PRINT_OUT)
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#endif
/* otherwise, for protected mode, if you want to use puts, define this to 1 */
#define USE_PUTS 0
/* when using PUTS, it's also setup not to expect keyboard input, but to run through 10 times */
#if (USE_PUTS)
UNSIGNED gPutsCounter;
#endif
// define this to use keyboard input for control - calls kbhit() and getchar()
#define ACCEPT_KEYS 0
/* Declare the RAM disk as the only disk. This affects which FAT calculation
is used. Please see pcdisk.h for more information. */
/* mcj modified to use the defines from pcdisk.h - now, set those defines, and this will
work for both the ram disk or the ata/ide driver. This also jibes with what devtable.c is doing */
#if (EBS_IDE)
#define __RAM "C:"
#else
#define __RAM "A:"
#endif
/* Non fatal manifest constants used in conjunction with the following
table. */
#define CANT_SELECT 0
#define INVALID_DIR 1
#define CANT_SET_DEF 2
#define TOO_MANY_SUBS 3
/* Non fatal error strings. */
char RAM_NON_FATAL[4][32] = {
"Can't select default disk",
"Invalid Directory",
"Can't set default directory",
"Too many subdirs for this build"
};
/* Fatal manifest constants used in conjunction with the following table. */
#define MEM_FAILURE 0
#define CANT_REGISTER 1
#define CANT_OPEN_DISK 2
#define CANT_SEL_DEF_DSK 3
#define CANT_SET_WRK_DIR 4
#define CANT_REM_FILE 5
#define CANT_REM_DIR 6
#define CANT_CREAT_DIR 7
#define CANT_OPEN_FILE 8
#define CANT_WRITE_FILE 9
#define CANT_REN_FILE 10
/* Fatal error strings. */
char RAM_FATAL[11][35] = {
"Memory Failure",
"Can't register as file system user",
"Can't open Floppy",
"Can't select default disk",
"Can't Set working directory",
"Can't remove file",
"Can't remove directory",
"Can't create directory",
"Can't open file",
"Can't write file",
"Can't rename File"
};
/* Declare the error arrays and counters. */
long RAM_Errors[10];
long RAM_Fatal_Errors[10];
long RAM_Errors_Index;
long RAM_Fatal_Errors_Index;
/* Forward references. */
void mkname(char *buffer, DSTAT *pstat);
BOOL scan_drive( int task_id, char *drive_id, char scan_stack[][13],
char *path);
int error_log(int error_no);
void bail_out(int error_no);
BOOL looping(void);
void display_task(void);
VOID write_test( int task_id, char *dir_id);
/* External references. */
signed int NUIP_Current_Task_ID(void);
/* Externally define the table used for Task ID to Task Pointer. */
IMPORT NU_TASK *NUIP_PLUS_To_RTX[5];
IMPORT NU_TASK display_task_CB;
IMPORT PFILE_SYSTEM_USER fs_current_user_structure(void);
/* Manifest constants used to identify the task usage and reporting. */
#define TASK0 0
#define TASK1 (TASK0 + 1)
#define TASK2 (TASK0 + 2)
#define HIGHEST_TASK TASK2
#define NUM_TASKS (HIGHEST_TASK + 1)
/* Global data. */
BOOL task_is_running[NUM_TASKS];
char wr_buf[512];
/* Declarations for global counters. */
int RAM_Files_Created[NUM_TASKS];
int RAM_Files_Renamed[NUM_TASKS];
int RAM_Files_Deleted[NUM_TASKS];
int RAM_Directories_Created[NUM_TASKS];
int RAM_Directories_Deleted[NUM_TASKS];
int RAM_Directories_Scanned[NUM_TASKS];
int RAM_Files_Scanned[NUM_TASKS];
/* a local strcpy to avoid pulling in stdio for the protected mode port */
void my_strcpy(char*, char*);
void my_strcpy(char* to, char* from)
{
int i;
i = 0;
while (from[i] != 0)
{
to[i] = from[i];
i = i + 1;
}
/* null term */
to[i] = 0;
}
int bad_strcmp (char*, char*);
/* it's only bad in the sense that it doesn't tell you greater or less than, just not equal.
returns 0 if equal, 1 if not equal */
int bad_strcmp (char* to, char* from)
{
int i;
i = 0;
while (from[i] != 0)
{
if (to[i] != from[i])
{
/* nope */
return 1;
}
i = i + 1;
}
/* yep */
return (0);
}
/************************************************************************/
/* */
/* FUNCTION "RAM_disk_init" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This routine low level formats the disk, opens the disk for */
/* Nucleus FILE usage, and high level formats the disk. */
/* */
/* AUTHOR */
/* Accelerated Technology */
/* CALLED FROM */
/* */
/* nuf_task_0 Initiator task. */
/* */
/* ROUTINES CALLED */
/* */
/* NU_Change_Preemption Changes task to non-preempt */
/* during formatting and back */
/* to original state after. */
/* pc_bdevsw[].open_proc Nucleus FILE open routine. */
/* NU_Format High level disk formatting. */
/* */
/* INPUTS */
/* NONE. */
/* */
/* OUTPUTS */
/* NONE */
/* */
/************************************************************************/
BOOL RAM_disk_init()
{
IMPORT _PC_BDEVSW pc_bdevsw[];
FMTPARMS fmt;
UCOUNT driveno;
BOOL ret_val;
OPTION preempt_status;
/* Don't allow other tasks to start until we are done. */
preempt_status = NU_Change_Preemption(NU_NO_PREEMPT);
/* Initialize return value. */
ret_val = NO;
/* mcj: this now lines up with the __RAM define above */
#if (EBS_IDE)
driveno = (UCOUNT) 2; /* C: */
#else
driveno = (UCOUNT) 0; /* A: - the ram disk */
#endif
/* Build the format table. This table is used by NU_Format to
write the boot block, fat, and main directory to the disk. */
/* The name in the boot block will be NUFILE to identify this disk
as one formatted by Nucleus FILE. */
my_strcpy(&fmt.oemname[0], "NUFILE");
fmt.secpalloc = (UTINY) 2; /* must be a multiple of 2. This
number indicates the number of
sectors (blocks) per cluster.
This value is the minimum number
of bytes that are written to or
read from the disk at a time. */
fmt.secreserved = (UCOUNT) 1;
fmt.numfats = (UTINY) 1; /* since redundant fats aren't used
only have one fat. */
fmt.secpfat = (UCOUNT) 1;
fmt.numroot = (UCOUNT) 16;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -