📄 pc_memry.c
字号:
nu_to_rtfs_task_map = Task_Map;
/* Allocate user file structures. Set each structure's is_free
field to YES. The file structure allocator uses this field to
determine if a file is available for use */
pool_size = sizeof(PC_FILE);
pool_size *= NUSERFILES;
if (NU_Allocate_Memory(&System_Memory,
(VOID **)&mem_file_pool,
pool_size,
NU_NO_SUSPEND) != NU_SUCCESS)
{
mem_file_pool = NULL;
goto meminit_failed;
}
for (i = 0; i < NUSERFILES; i++)
mem_file_pool[i].is_free = YES;
/* Allocate block buffer pool and make a null terminated list
linked with pnext. The block buffer pool code manages this list
directly */
pool_size = sizeof(BLKBUFF);
pool_size *= NBLKBUFFS;
if (NU_Allocate_Memory(&System_Memory,
(VOID **)&mem_block_pool,
pool_size,
NU_NO_SUSPEND) != NU_SUCCESS)
{
mem_block_pool = NULL;
goto meminit_failed;
}
for (i = 0, j = 1; i < (NBLKBUFFS-1); i++, j++)
{
pc_memfill(&mem_block_pool[i], sizeof(BLKBUFF), (UINT8) 0);
mem_block_pool[i].pnext = mem_block_pool + j;
}
pc_memfill(&mem_block_pool[NBLKBUFFS-1], sizeof(BLKBUFF), (UINT8) 0);
mem_block_pool[NBLKBUFFS-1].pnext = NULL;
/* Allocate DROBJ structures and make a NULL terminated freelist using
pdrive as the link. This linked freelist structure is used by the
DROBJ memory allocator routine. */
pool_size = sizeof(DROBJ);
pool_size *= NDROBJS;
if (NU_Allocate_Memory(&System_Memory,
(VOID **)&mem_drobj_pool,
pool_size,
NU_NO_SUSPEND) != NU_SUCCESS)
{
mem_drobj_pool = NULL;
goto meminit_failed;
}
mem_drobj_freelist = mem_drobj_pool;
for (i = 0, j = 1; i < (NDROBJS-1); i++, j++)
{
pobj = mem_drobj_freelist + j;
mem_drobj_freelist[i].pdrive = (DDRIVE *) pobj;
}
mem_drobj_freelist[NDROBJS-1].pdrive = (DDRIVE *) NULL;
/* Allocate FINODE structures and make a NULL terminated freelist using
pnext as the link. This linked freelist is used by the FINODE
memory allocator routine */
pool_size = sizeof(FINODE);
pool_size *= NFINODES;
if (NU_Allocate_Memory(&System_Memory,
(VOID **)&mem_finode_pool,
pool_size,
NU_NO_SUSPEND) != NU_SUCCESS)
{
mem_finode_pool = NULL;
goto meminit_failed;
}
mem_finode_freelist = mem_finode_pool;
#if (LOCK_METHOD == 2)
/* Copy lock handles into our new finode structures */
for (i = 0,pfi = mem_finode_freelist; i < NFINODES; i++, pfi++)
pfi->lock_object.wait_handle = finode_lock_handles[i];
#endif
pfi = mem_finode_freelist = mem_finode_pool;
for (i = 0; i < (NFINODES-1); i++)
{
pfi++;
mem_finode_freelist->pnext = pfi;
mem_finode_freelist++;
mem_finode_freelist->pnext = NULL;
}
mem_finode_freelist = mem_finode_pool;
NU_Change_Preemption(preempt_status);
return(YES);
meminit_failed:
if (mem_block_pool)
NU_Deallocate_Memory((VOID *)mem_block_pool);
if (mem_file_pool)
NU_Deallocate_Memory((VOID *)mem_file_pool);
if (mem_drobj_pool)
NU_Deallocate_Memory((VOID *)mem_drobj_pool);
if (mem_finode_pool)
NU_Deallocate_Memory((VOID *)mem_finode_pool);
if (user_heap)
NU_Deallocate_Memory((VOID *)user_heap);
user_heap = NULL;
nu_to_rtfs_task_map = NULL;
mem_block_pool = NULL;
mem_file_pool = NULL;
mem_drobj_pool = NULL;
mem_drobj_freelist = NULL;
mem_finode_pool = NULL;
mem_finode_freelist = NULL;
/* NUCLEUS - The current user is a macro not a constant */
NU_Change_Preemption(preempt_status);
pc_report_error(PCERR_INITALLOC);
return(NO);
}
/************************************************************************
* FUNCTION
*
* pc_memory_close
*
* DESCRIPTION
*
* Free all memory used by the file system and make it ready to run
* again.
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* None.
*
* OUTPUTS
*
* None.
*
*************************************************************************/
VOID pc_memory_close(VOID) /*__fn__*/
{
/* Clear a few values. This allows us to close down all memory used by
the file system an then re-activate it by calling pc_memory_init. */
inoroot = NULL;
/* SPR214 07-21-01 Removed unused array */
/* pc_memfill(drv_array, (sizeof(DDRIVE *) * NDRIVES), (UINT8) 0); */
/* Now deallocate all of our internal structures */
if (mem_block_pool)
NU_Deallocate_Partition((VOID *)mem_block_pool);
if (mem_file_pool)
NU_Deallocate_Partition((VOID *)mem_file_pool);
if (mem_drobj_pool)
NU_Deallocate_Partition((VOID *)mem_drobj_pool);
if (mem_finode_pool)
NU_Deallocate_Partition((VOID *)mem_finode_pool);
if (user_heap)
NU_Deallocate_Partition((VOID *)user_heap);
user_heap = NULL;
nu_to_rtfs_task_map = NULL;
mem_block_pool = NULL;
mem_file_pool = NULL;
mem_drobj_pool = NULL;
mem_drobj_freelist = NULL;
mem_finode_pool = NULL;
mem_finode_freelist = NULL;
/* NUCLEUS - The current user is a macro not a constant */
}
/************************************************************************
* FUNCTION
*
* pc_memory_drobj
*
* DESCRIPTION
*
* If called with a null pointer, allocates and zeroes the space
* needed to store a DROBJ structure. If called with a NON-NULL
* pointer the DROBJ structure is returned to the heap.
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* *pobj Drive object structure
*
* OUTPUTS
*
* If an ALLOC returns a valid pointer or NULL if no more core.
* If a free the return value is the input.
*
*************************************************************************/
DROBJ *pc_memory_drobj(DROBJ *pobj)
{
DROBJ *preturn;
if (pobj)
{
/* Free it by putting it at the head of the freelist
NOTE: pdrive is used to link the freelist */
pobj->pdrive = (DDRIVE *) mem_drobj_freelist;
mem_drobj_freelist = pobj;
return(pobj);
}
else
{
/* Alloc: return the first structure from the freelist */
preturn = mem_drobj_freelist;
if (preturn)
{
mem_drobj_freelist = (DROBJ *) preturn->pdrive;
pc_memfill(preturn, sizeof(DROBJ), (UINT8) 0);
return(preturn);
}
else
{
pc_report_error(PCERR_DROBJALLOC);
return(NULL);
}
}
}
/************************************************************************
* FUNCTION
*
* pc_memory_finode
*
* DESCRIPTION
*
* If called with a null pointer, allocates and zeroes the space
* needed to store a FINODE structure. If called with a NON-NULL
* pointer the FINODE structure is returned to the heap.
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* *pinode If NULL is specified, it
* allocate FINODE memory.
* If valid pointer is input,
* it is freed.
*
* OUTPUTS
*
* If an ALLOC returns a valid pointer or NULL if no more core.
* If a free the return value is the input.
*
*************************************************************************/
FINODE *pc_memory_finode(FINODE *pinode)
{
FINODE *preturn;
#if (LOCK_METHOD == 2)
WAIT_HANDLE_TYPE wait_handle;
#endif
if (pinode)
{
/* Free it by putting it at the head of the freelist */
pinode->pnext = mem_finode_freelist;
mem_finode_freelist = pinode;
#ifdef DEBUG_FI
DEBUG_PRINT ("Free FINODE 0x%08x \n",(unsigned int)pinode);
#endif
return(pinode);
}
else
{
/* Alloc: return the first structure from the freelist */
preturn = mem_finode_freelist;
if (preturn)
{
mem_finode_freelist = preturn->pnext;
/* Zero the structure. wait_handle can't be zeroed so
push it and pop it after zeroeing */
#if (LOCK_METHOD == 2)
wait_handle = preturn->lock_object.wait_handle;
pc_memfill(preturn, sizeof(FINODE), (UINT8) 0);
preturn->lock_object.wait_handle = wait_handle;
#else
pc_memfill(preturn, sizeof(FINODE), (UINT8) 0);
#endif
#ifdef DEBUG_FI
DEBUG_PRINT ("Alloc FINODE 0x%08x \n",(unsigned int)preturn);
#endif
return(preturn);
}
else
{
pc_report_error(PCERR_FINODEALLOC);
return(NULL);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -