📄 drobj.c
字号:
/************************************************************************
*
* Copyright (c) 2001 by 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 VERSION
*
* DROBJ.C FILE 2.3
*
* COMPONENT
*
* Nucleus File
*
* DESCRIPTION
*
* Directory object manipulation routines.
*
*
* DATA STRUCTURES
*
* None.
*
* FUNCTIONS
*
* pc_fndnode Find a file or directory on
* disk and return a DROBJ.
* pc_get_inode Find a filename within a
* subdirectory.
* pc_next_inode Find a next file or
* directory on disk and
* return a DROBJ.
* chk_sum Calculating short file name
* check byte.
* uni2asc Convert unicode to ascii
* code.
* asc2uni Convert ascii to unicode.
* pc_cre_longlen Create long-filename ascii
* strings.
* pc_cre_shortfilename Create short-filename ascii
* strings.
* lnam_clean Clearn long filname
* information structure.
* pc_findin Find a filename in the same
* directory as argument.
* pc_get_mom Find the parent inode of a
* subdirectory.
* pc_mkchild Allocate a DROBJ and fill
* int based on parent object.
* pc_mknode Create an empty subdirectory
* or file.
* pc_insert_inode Called only by pc_mknode.
* pc_del_lname_block Delete a long filename
* entry.
* pc_renameinode Rename an inode.
* pc_rmnode Delete an inode
* unconditionally.
* pc_update_inode Flush an inode to disk.
* pc_get_root Create the special ROOT
* object for a drive.
* pc_firstblock Return the absolute block
* number of a directory.
* pc_next_block Calculate the next block
* owned by an object.
* pc_l_next_block Calculate the next block in
* a chain.
* pc_marki Set dr:sec:index, + stitch
* FINODE info the inode list.
* pc_scani Search for an inode in the
* internal inode list.
* pc_allocobj Alocates and zeroes the
* space needed to store a
* DROBJ structure.
* pc_alloci Allocates and zeroes a
* FINODE structure.
* pc_free_all_i Release all inode buffers.
* pc_freei Release FINODE structure.
* pc_freeobj Return a drobj structure to
* the heap.
* pc_dos2inode Take the data from pbuff
* which is a raw disk
* directory entry.
* pc_ino2dos Take in memory native format
* inode information.
* pc_init_inode Take an uninitialized inode.
* pc_isadir Check the root or
* subdirectory.
* pc_isroot Check the root directory.
*
* DEPENDENCIES
*
* pcdisk.h File common definitions
*
*************************************************************************/
#include "file\pcdisk.h"
extern FINODE *inoroot;
/************************************************************************
* FUNCTION
*
* pc_fndnode
*
* DESCRIPTION
*
* Take a full path name and traverse the path until we get to the
* file or subdir at the end of the path spec. When found allocate
* and init-ialize (OPEN) a DROBJ.
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* driveno Drive number
* **pobj Drive object structure
* path Path name
*
* OUTPUTS
*
* NU_SUCCESS File was found.
* NUF_BADDRIVE Invalid drive specified.
* NUF_LONGPATH Path or directory name too
* long.
* NUF_NOFILE The specified file not
* found.
* NUF_NO_FINODE No FINODE buffer available.
* NUF_NO_DROBJ No DROBJ buffer available.
* NUF_IO_ERROR Driver IO error.
* NUF_INTERNAL Nucleus FILE internal error.
*
*************************************************************************/
STATUS pc_fndnode(INT16 driveno, DROBJ **pobj, UINT8 *path)
{
STATUS ret_stat;
DROBJ *pmom;
DROBJ *pchild;
DDRIVE *pdrive;
UINT8 *childpath;
/* Find the drive */
pdrive = pc_drno2dr(driveno);
if (!pdrive)
return(NUF_BADDRIVE);
/* Get the top of the current path */
if (path)
{
if ( *path == BACKSLASH )
{
*pobj = pc_get_root(pdrive);
if (!*pobj)
return(NUF_NO_DROBJ);
path++;
}
else
{
*pobj = pc_get_cwd(pdrive);
if (!*pobj)
return(NUF_NO_DROBJ);
}
}
else
{
*pobj = pc_get_cwd(pdrive);
if (!*pobj)
return(NUF_NO_DROBJ);
return(NU_SUCCESS);
}
ret_stat = NU_SUCCESS;
/* Search through the path til exausted */
while (*path)
{
childpath = pc_nibbleparse(path);
if (!childpath)
{
break;
}
/* is dot */
if ( (*path == '.') && ((*(path+1) == BACKSLASH) || (*(path+1) == '\0')) )
;
else
{
/* Find Filename in pobj. and initialize lpobj with result */
PC_INODE_ENTER((*pobj)->finode, NO)
pchild = NULL;
ret_stat = pc_get_inode(&pchild, (*pobj), path);
if (ret_stat != NU_SUCCESS)
{
PC_INODE_EXIT((*pobj)->finode)
pc_freeobj(*pobj);
break;
}
/* We found it. We have one special case. if "..". we need
to shift up a level so we are not the child of mom
but of grand mom. */
if ( (*path == '.') && (*(path+1) == '.') &&
((*(path+2) == BACKSLASH) || (*(path+2) == '\0')) )
{
/* Find pobj's parent. By looking back from ".." */
ret_stat = pc_get_mom(&pmom, pchild);
PC_INODE_EXIT((*pobj)->finode)
/* We're done with pobj for now */
pc_freeobj(*pobj);
if (ret_stat != NU_SUCCESS)
{
pc_freeobj(pchild);
break;
}
else
{
/* We found the parent now free the child */
*pobj = pmom;
pc_freeobj(pchild);
}
}
else
{
PC_INODE_EXIT((*pobj)->finode)
/* We're done with pobj for now */
pc_freeobj(*pobj);
/* Make sure pobj points at the next inode */
*pobj = pchild;
}
}
path = childpath;
}
return(ret_stat);
}
/************************************************************************
* FUNCTION
*
* pc_get_inode
*
* DESCRIPTION
*
* Search the directory for the pattern or name in filename.
* If pobj is NULL start the search at the top of pmom (getfirst)
* and allocate pobj before returning it.
* Otherwise start the search at pobj .
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* **pobj Output search drive object
* *pmom Search the drive object
* *filename Search file name
*
* OUTPUTS
*
* NU_SUCCESS Search successful.
* NUF_LONGPATH Path or directory name too
* long.
* NUF_NOFILE The specified file not
* found.
* NUF_NO_BLOCK No block buffer available.
* NUF_NO_FINODE No FINODE buffer available.
* NUF_NO_DROBJ No DROBJ buffer available.
* NUF_IO_ERROR Driver IO error.
* NUF_INTERNAL Nucleus FILE internal error.
*
*************************************************************************/
STATUS pc_get_inode(DROBJ **pobj, DROBJ *pmom, UINT8 *filename)
{
INT starting = NO;
INT len;
STATUS ret_stat;
/* measure long file name length */
for (len = 0; *(filename+len); len++);
if ((len + pmom->finode->abs_length) > EMAXPATH)
{
pc_report_error(PCERR_PATHL);
return(NUF_LONGPATH);
}
/* Create the child if just starting */
if (!*pobj)
{
starting = YES;
*pobj = pc_mkchild(pmom);
if (!*pobj)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -