📄 sysioctl.c
字号:
}
/*-----------------------------------------------------------*/
/* Else we are looking for a file and it can never be in the */
/* root directory so return error. */
/*-----------------------------------------------------------*/
else
{
set_errno(ENOENT);
return NULL;
}
}
/*-------------------------------------------------------------*/
/* Find path's root name among the mounted file systems. */
/*-------------------------------------------------------------*/
for (fsys = MountedList.head;; fsys = fsys->next)
{
/*-----------------------------------------------------------*/
/* If file system not found, return error. */
/*-----------------------------------------------------------*/
if (fsys == NULL)
{
r_value = (void *)-1;
set_errno(ENXIO);
break;
}
/*-----------------------------------------------------------*/
/* If the names match, we found the entry. */
/*-----------------------------------------------------------*/
if (!strncmp(FSPath, fsys->name, len) &&
strlen(fsys->name) == len)
{
/*---------------------------------------------------------*/
/* Set the volume pointer before doing FSEARCH. */
/*---------------------------------------------------------*/
file->volume = fsys->volume;
/*---------------------------------------------------------*/
/* Adjust the path. */
/*---------------------------------------------------------*/
FSPath += incr;
/*---------------------------------------------------------*/
/* Call the file system's ioctl with FSEARCH to continue */
/* the look up process inside the file system. */
/*---------------------------------------------------------*/
r_value = fsys->ioctl(file, FSEARCH, dir_lookup, FIRST_DIR);
break;
}
}
}
/*---------------------------------------------------------------*/
/* Else there are no mounted systems, return error. */
/*---------------------------------------------------------------*/
else
{
set_errno(EINVAL);
return NULL;
}
}
/*-----------------------------------------------------------------*/
/* Else call the current ioctl. */
/*-----------------------------------------------------------------*/
else
{
file->volume = volume;
r_value = volume->sys.ioctl(file, FSEARCH, dir_lookup, CURR_DIR);
}
}
while (r_value == NULL);
/*-------------------------------------------------------------------*/
/* Set *path to the value of FSPath. */
/*-------------------------------------------------------------------*/
*path = FSPath;
return (r_value == (void *)-1) ? NULL : r_value;
}
/***********************************************************************/
/* InvalidName: Check that name is a valid dir or file name */
/* */
/* Inputs: name = name to be checked */
/* ignore_last = flag to ignore last chars if '/' */
/* */
/* Returns: TRUE if invalid, FALSE if valid */
/* */
/***********************************************************************/
int InvalidName(const char *name, int ignore_last)
{
#if UTF_ENABLED
return !ValidUTF8((const ui8 *)name, strlen(name));
#else
int i, j;
uint len = strlen(name);
/*-------------------------------------------------------------------*/
/* First character must be '.', '_', '$', '#', or alphanumeric. */
/*-------------------------------------------------------------------*/
if (name[0] != '.' && name[0] != '_' && name[0] != '$' &&
name[0] != '#' && !isalnum(name[0]))
{
set_errno(EINVAL);
return TRUE;
}
/*-------------------------------------------------------------------*/
/* The remaining chars must be alnum or '.', '_', '-', '$', or '#'. */
/*-------------------------------------------------------------------*/
for (i = 1; i < len; ++i)
{
/*-----------------------------------------------------------------*/
/* Check if the character is invalid. */
/*-----------------------------------------------------------------*/
if (!isalnum(name[i]) && name[i] != '.' && name[i] != '_' &&
name[i] != '-' && name[i] != '$' && name[i] != '#')
{
/*---------------------------------------------------------------*/
/* Ignore the last characters if they are '/' and flag is set. */
/*---------------------------------------------------------------*/
if (name[i] == '/' && ignore_last)
{
for (j = i; j < len && name[j] == '/'; ++j) ;
if (j < len)
{
set_errno(EINVAL);
return TRUE;
}
}
else
{
set_errno(EINVAL);
return TRUE;
}
}
}
return FALSE;
#endif /* UTF_ENABLED */
}
/***********************************************************************/
/* mount_all: Mount all installed volumes */
/* */
/* Input: verbose = flag to display status of each mount */
/* */
/* Returns: 0 if all volumes mounted successfully, otherwise -1 */
/* */
/***********************************************************************/
int mount_all(int verbose)
{
FileSys *volume;
char *name;
int i, r_value, mount_cnt;
/*-------------------------------------------------------------------*/
/* Get exclusive access to file system. */
/*-------------------------------------------------------------------*/
semPend(FileSysSem, WAIT_FOREVER);
/*-------------------------------------------------------------------*/
/* Loop through module list. */
/*-------------------------------------------------------------------*/
for (i = r_value = mount_cnt = 0; ModuleList[i];)
{
/*-----------------------------------------------------------------*/
/* Pass mount command to each module, with NULL volume name. */
/*-----------------------------------------------------------------*/
volume = ModuleList[i](kMount, NULL, &name);
/*-----------------------------------------------------------------*/
/* If current module is done, go to next one. */
/*-----------------------------------------------------------------*/
if (volume == NULL)
{
++i;
continue;
}
/*-----------------------------------------------------------------*/
/* If verbose and this is first mount, announce our intent. */
/*-----------------------------------------------------------------*/
if (verbose && ++mount_cnt == 1)
printf("Mounting all installed volumes\n");
/*-----------------------------------------------------------------*/
/* If error occurred, display message and move to next mount. */
/*-----------------------------------------------------------------*/
if (volume == (FileSys *)-1)
{
r_value = -1;
if (verbose)
printf("Volume \"/%s\" failed to mount\n", name);
++i;
}
/*-----------------------------------------------------------------*/
/* Else add device to list of mounted volumes. */
/*-----------------------------------------------------------------*/
else
{
/*---------------------------------------------------------------*/
/* If in verbose mode, display successful mount message. */
/*---------------------------------------------------------------*/
if (verbose)
printf("Volume \"/%s\" mounted successfully\n", name);
/*---------------------------------------------------------------*/
/* If there's already mounted volumes, append this one. */
/*---------------------------------------------------------------*/
if (MountedList.head)
{
volume->prev = MountedList.tail;
MountedList.tail->next = volume;
}
/*---------------------------------------------------------------*/
/* Else, set this device as the first mounted device. */
/*---------------------------------------------------------------*/
else
{
volume->prev = NULL;
MountedList.head = volume;
}
/*---------------------------------------------------------------*/
/* Set the tail of the list of mounted volumes. */
/*---------------------------------------------------------------*/
volume->next = NULL;
MountedList.tail = volume;
}
}
/*-------------------------------------------------------------------*/
/* Release exclusive access to file system and return. */
/*-------------------------------------------------------------------*/
semPost(FileSysSem);
return r_value;
}
/***********************************************************************/
/* FsInitFCB: Initialize a file control block */
/* */
/* Inputs: file = pointer to file/dir control block */
/* type = type of control block (file or dir) */
/* */
/***********************************************************************/
void FsInitFCB(FILE *file, ui32 type)
{
file->flags = type;
if (type == FCB_DIR)
{
file->write = dir_file_write;
file->read = dir_file_read;
}
else if (type == FCB_FILE)
{
file->write = NULL;
file->read = NULL;
}
else if (type == FCB_TTY)
{
return;
}
file->acquire = file->release = do_nothing;
file->ioctl = file->volume = file->handle = file->pos = NULL;
file->hold_char = file->errcode = 0;
file->cached = NULL;
}
#if 0
/*
** Included for easy incorporation in applications if user hasn't yet
** implemented or doesn't need per-task current working directories.
*/
static ui32 Word1, Word2;
/***********************************************************************/
/* FsSaveCWD: Save current working directory state information */
/* */
/* Inputs: word1 = 1 of 2 words to save */
/* word2 = 2 of 2 words to save */
/* */
/***********************************************************************/
void FsSaveCWD(ui32 word1, ui32 word2)
{
Word1 = word1;
Word2 = word2;
}
/***********************************************************************/
/* FsReadCWD: Read current working directory state information */
/* */
/* Outputs: word1 = 1 of 2 words to retrieve */
/* word2 = 2 of 2 words to retrieve */
/* */
/***********************************************************************/
void FsReadCWD(ui32 *word1, ui32 *word2)
{
*word1 = Word1;
*word2 = Word2;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -