📄 main.c
字号:
return -1;
}
if (close(fid))
{
perror("Error closing file");
return -1;
}
if (unlink("notdir"))
{
perror("Error removing file");
return -1;
}
/*-------------------------------------------------------------------*/
/* Skip test for access and permission errors if TargetFAT volume. */
/*-------------------------------------------------------------------*/
vstat(vol_name, &stats);
if (stats.fat.vol_type != FAT_VOL)
{
/*-----------------------------------------------------------------*/
/* Check detection of EACCES errors. */
/*-----------------------------------------------------------------*/
fid = creat("diru/file", 0666);
if (fid == -1)
{
perror("Error creating file");
return -1;
}
if (chmod("diru", S_IRGRP | S_IWGRP))
{
perror("Error changing permissions");
return -1;
}
if (utime("diru/file", NULL) == 0)
{
perror("Missed need for dir execute permission");
return -1;
}
if (errno != EACCES)
{
perror("Set wrong errno value");
return -1;
}
if (chmod("diru", S_IRGRP | S_IWGRP | S_IXGRP))
{
perror("Error changing permissions");
return -1;
}
/*-----------------------------------------------------------------*/
/* Check detection of EPERM errors. */
/*-----------------------------------------------------------------*/
FsGetId(&uid, &gid);
FsSetId(uid + 1, gid);
if (utime("diru/file", NULL) == 0)
{
perror("Missed need for file permission");
return -1;
}
if (errno != EPERM)
{
perror("Set wrong errno value");
return -1;
}
FsSetId(uid, gid);
if (close(fid))
{
perror("Error closing file");
return -1;
}
if (unlink("diru/file"))
{
perror("Error removing file");
return -1;
}
}
/*-------------------------------------------------------------------*/
/* Check detection of ENAMETOOLONG errors. */
/*-------------------------------------------------------------------*/
{
static char too_long[PATH_MAX + 2];
memset(too_long, 'A', PATH_MAX + 1);
if (utime(too_long, NULL) == 0)
{
perror("Missed overly long file name");
return -1;
}
if (errno != ENAMETOOLONG)
{
perror("Set wrong errno value");
return -1;
}
}
/*-------------------------------------------------------------------*/
/* Clean up. */
/*-------------------------------------------------------------------*/
if (rmdir("diru"))
{
perror("Error removing directory");
return -1;
}
/*-------------------------------------------------------------------*/
/* Return success. */
/*-------------------------------------------------------------------*/
return 0;
}
/***********************************************************************/
/* Global Function Definitions */
/***********************************************************************/
/***********************************************************************/
/* main: Application Entry Point */
/* */
/***********************************************************************/
void main(ui32 unused)
{
int i;
char *vol_name;
union vstat stats;
/*-------------------------------------------------------------------*/
/* Lower interrupt mask and start scheduling. */
/*-------------------------------------------------------------------*/
OsStart();
/*-------------------------------------------------------------------*/
/* Lower our priority. */
/*-------------------------------------------------------------------*/
taskSetPri(RunningTask, 20);
/*-------------------------------------------------------------------*/
/* Null CWD variables and assign this task's user and group ID. */
/*-------------------------------------------------------------------*/
FsSetId(0, 0);
FsSaveCWD(0, 0);
/*-------------------------------------------------------------------*/
/* Initialize the file system. */
/*-------------------------------------------------------------------*/
if (InitFFS())
SysFatalError(errno);
#if NUM_RFS_VOLS
/*-------------------------------------------------------------------*/
/* Add the TargetRFS volume. */
/*-------------------------------------------------------------------*/
if (RfsAddVol(RFS_NAME))
SysFatalError(errno);
#endif
/*-------------------------------------------------------------------*/
/* Run the test programs in an endless loop. */
/*-------------------------------------------------------------------*/
for (i = 1;; ++i)
{
printf("\n****************** Test Loop %u ******************\n", i);
vol_name = Volume[i % (sizeof(Volume) / sizeof(char *))];
printf("Volume = %s\n", vol_name);
/*-----------------------------------------------------------------*/
/* Format each volume on its first loop. */
/*-----------------------------------------------------------------*/
if (i <= (sizeof(Volume) / sizeof(char *)))
if (format(vol_name))
SysFatalError(errno);
/*-----------------------------------------------------------------*/
/* Mount the volume and change to its root directory. */
/*-----------------------------------------------------------------*/
if (mount(vol_name))
SysFatalError(errno);
if (chdir(vol_name))
SysFatalError(errno);
/*-----------------------------------------------------------------*/
/* Test file postion after reads and seeks. */
/*-----------------------------------------------------------------*/
if (seek_test())
SysFatalError(errno);
/*-----------------------------------------------------------------*/
/* Test seeks that hit and cross sector boundaries. */
/*-----------------------------------------------------------------*/
if (seek_test2())
SysFatalError(errno);
/*-----------------------------------------------------------------*/
/* Test utime(). */
/*-----------------------------------------------------------------*/
if (utime_test(vol_name))
SysFatalError(errno);
/*-----------------------------------------------------------------*/
/* Test assorted file system calls. */
/*-----------------------------------------------------------------*/
if (file_test(vol_name))
SysFatalError(errno);
/*-----------------------------------------------------------------*/
/* Test the creatn() function if flash file system. */
/*-----------------------------------------------------------------*/
vstat(vol_name, &stats);
if (stats.fat.vol_type == FFS_VOL)
{
if (creatn_test(vol_name))
SysFatalError(errno);
}
/*-----------------------------------------------------------------*/
/* Test directory entry sorting for flash and RAM file systems. */
/*-----------------------------------------------------------------*/
if (stats.fat.vol_type == FFS_VOL || stats.fat.vol_type == RFS_VOL)
{
if (sort_test(vol_name))
SysFatalError(errno);
}
/*-----------------------------------------------------------------*/
/* Unmount volume before starting next test. */
/*-----------------------------------------------------------------*/
if (unmount(vol_name))
SysFatalError(errno);
printf("Success!\n");
}
}
/***********************************************************************/
/* OsIdleTask: kernel idle task */
/* */
/***********************************************************************/
void OsIdleTask(ui32 unused)
{
/*-------------------------------------------------------------------*/
/* Loop forever. Feel free to add code here, but nothing that could */
/* block (Don't try a printf()). */
/*-------------------------------------------------------------------*/
for (;;) OsAuditStacks();
}
/***********************************************************************/
/* AppModule: Application interface to software module manager */
/* */
/* Input: req = module request code */
/* ... = additional parameters specific to request */
/* */
/***********************************************************************/
void *AppModule(int req, ...)
{
switch (req)
{
#if PCCARD_SUPPORT
va_list ap;
pccSocket *sock;
case kCardInserted:
printf("Known card inserted\n");
/*---------------------------------------------------------------*/
/* Use va_arg mechanism to fetch pointer to command string. */
/*---------------------------------------------------------------*/
va_start(ap, req);
sock = va_arg(ap, pccSocket *);
va_end(ap);
/*---------------------------------------------------------------*/
/* Parse card type. */
/*---------------------------------------------------------------*/
switch (sock->card.type)
{
case PCCC_ATA:
printf("ATA Drive\n");
if (pccAddATA(sock, "ata"))
{
perror("pccAddATA");
break;
}
break;
default:
printf("unk type = %d\n", sock->card.type);
break;
}
break;
case kCardRemoved:
printf("Card removed\n");
break;
#endif
}
return NULL;
}
/***********************************************************************/
/* FsGetId: Get the user and group ID of process */
/* */
/* Inputs: uid = place to store user ID */
/* gid = place to store group ID */
/* */
/***********************************************************************/
void FsGetId(uid_t *uid, gid_t *gid)
{
ui32 id = taskGetReg(RunningTask, ID_REG);
*uid = (uid_t)id;
*gid = id >> 16;
}
/***********************************************************************/
/* FsSetId: Set the user and group ID of process */
/* */
/* Inputs: uid = user ID */
/* gid = group ID */
/* */
/***********************************************************************/
void FsSetId(uid_t uid, gid_t gid)
{
ui32 id = (gid << 16) | uid;
taskSetReg(RunningTask, ID_REG, id);
}
/***********************************************************************/
/* FsSaveCWD: Save per-task current working directory state */
/* */
/* Inputs: word1 = 1 of 2 words to save */
/* word2 = 2 of 2 words to save */
/* */
/***********************************************************************/
void FsSaveCWD(ui32 word1, ui32 word2)
{
taskSetReg(RunningTask, CWD_WD1, word1);
taskSetReg(RunningTask, CWD_WD2, word2);
}
/***********************************************************************/
/* FsReadCWD: Read per-task current working directory state */
/* */
/* Outputs: word1 = 1 of 2 words to retrieve */
/* word2 = 2 of 2 words to retrieve */
/* */
/***********************************************************************/
void FsReadCWD(ui32 *word1, ui32 *word2)
{
*word1 = taskGetReg(RunningTask, CWD_WD1);
*word2 = taskGetReg(RunningTask, CWD_WD2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -