📄 pc_memry.c
字号:
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);
#else
if (mem_drives_structures)
NU_Dealloc_Partition( (unsigned int *)mem_drives_structures);
if (mem_block_pool)
NU_Dealloc_Partition( (unsigned int *)mem_block_pool);
if (mem_file_pool)
NU_Dealloc_Partition( (unsigned int *)mem_file_pool);
if (mem_drobj_pool)
NU_Dealloc_Partition( (unsigned int *)mem_drobj_pool);
if (mem_finode_pool)
NU_Dealloc_Partition( (unsigned int *)mem_finode_pool);
if (user_heap)
NU_Dealloc_Partition( (unsigned int *)user_heap);
if (nu_to_rtfs_task_map)
NU_Dealloc_Memory( (unsigned int *)nu_to_rtfs_task_map);
#endif /* PLUS */
user_heap = NULL;
nu_to_rtfs_task_map = NULL;
mem_drives_structures = 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 */
#if (PLUS)
NU_Change_Preemption(preempt_status);
#else
NU_Enable_Preemption();
#endif /* PLUS */
pc_report_error(PCERR_INITALLOC);
return(NO);
}
/**************************************************************************
PC_MEMORY_CLOSE - Close out memory used by the file system.
Description
Free all memory used by the file system and make it ready to run
again.
This routine is optional but might come in handy in applications where
you may need to swap the file system's core out so it may be used for
something else.
Note: We don't de-allocate any FAT buffers here. Calling pc_dskclose
for each open drive will do that.
Returns
NOTHING
*****************************************************************************/
VOID pc_memory_close() /*__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;
pc_memfill(drv_array, (sizeof(DDRIVE *) * NDRIVES), (UTINY) 0);
/* Now deallocate all of our internal structures */
#if (PLUS)
if (mem_drives_structures)
NU_Deallocate_Partition( (VOID *)mem_drives_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);
#else
if (mem_drives_structures)
NU_Dealloc_Partition( (unsigned int *)mem_drives_structures);
if (mem_block_pool)
NU_Dealloc_Partition( (unsigned int *)mem_block_pool);
if (mem_file_pool)
NU_Dealloc_Partition( (unsigned int *)mem_file_pool);
if (mem_drobj_pool)
NU_Dealloc_Partition( (unsigned int *)mem_drobj_pool);
if (mem_finode_pool)
NU_Dealloc_Partition( (unsigned int *)mem_finode_pool);
if (user_heap)
NU_Dealloc_Partition( (unsigned int *)user_heap);
if (nu_to_rtfs_task_map)
NU_Dealloc_Memory( (unsigned int *)nu_to_rtfs_task_map);
#endif /* PLUS */
user_heap = NULL;
nu_to_rtfs_task_map = NULL;
mem_drives_structures = 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 */
}
/**************************************************************************
PC_MEMORY_DROBJ - Allocate a DROBJ structure
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.
Returns
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) /*__fn__*/
{
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) , (UTINY) 0);
return(preturn);
}
else
{
pc_report_error(PCERR_DROBJALLOC);
return(NULL);
}
}
}
/**************************************************************************
PC_MEMORY_FINODE - Allocate a FINODE structure
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.
Returns
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) /*__fn__*/
{
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;
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) , (UTINY) 0);
preturn->lock_object.wait_handle = wait_handle;
#else
pc_memfill(preturn, sizeof(FINODE) , (UTINY) 0);
#endif
return(preturn);
}
else
{
pc_report_error(PCERR_FINODEALLOC);
return(NULL);
}
}
}
/**************************************************************************
PC_MEMORY_FAT_BLOCKS_ALLOC - Allocate blocks for in memory FAT
Description
This function is called by the file system when it needs space for
file allocation table buffering. It is provided the minimum and maximum
blocks needed. It allocates as much core as posiible between these extremes
and returns a pointer to the core and by reference the number of blocks
allocated.
If at least MIN blocks can't be allocated, return NULL.
Returns
A pointer to the allocated core plus through the third argument
the number of blocks allocated.
Note: In the reference port we limit the allocation to > 64 blocks.
(32K). This amount of memroy should usually be available. On larger
systems allocate as much as you wish.
Note: We call FARMALLOC() here with a UCOUNT argument. You should
use some other means if allocaing > 64K.
*****************************************************************************/
UTINY FAR *pc_memory_fat_blocks_alloc(COUNT driveno, UCOUNT min, UCOUNT max, UCOUNT *p_nalloced) /*__fn__*/
{
UTINY FAR *p;
UCOUNT size;
UCOUNT *mem_address;
#if (PLUS)
NU_PARTITION_POOL *partno;
#else
int partno;
#endif /* PLUS */
/* Get the partition number and partition size in blocks */
switch(driveno)
{
case 0:
size = NUF_FATSIZE_A;
#if (PLUS)
partno = &NUF_FAT_PARTITION_A;
#else
partno = NUF_FAT_PARTITION_A;
#endif /* PLUS */
break;
case 1:
size = NUF_FATSIZE_B;
#if (PLUS)
partno = &NUF_FAT_PARTITION_B;
#else
partno = NUF_FAT_PARTITION_B;
#endif /* PLUS */
break;
case 2:
size = NUF_FATSIZE_C;
#if (PLUS)
partno = &NUF_FAT_PARTITION_C;
#else
partno = NUF_FAT_PARTITION_C;
#endif /* PLUS */
break;
case 3:
size = NUF_FATSIZE_D;
#if (PLUS)
partno = &NUF_FAT_PARTITION_D;
#else
partno = NUF_FAT_PARTITION_D;
#endif /* PLUS */
break;
case 4:
size = NUF_FATSIZE_E;
#if (PLUS)
partno = &NUF_FAT_PARTITION_E;
#else
partno = NUF_FAT_PARTITION_E;
#endif /* PLUS */
break;
default:
goto did_not_work;
}
if (size < min)
goto did_not_work;
if (size > max)
size = max;
#if (PLUS)
if (NU_Allocate_Partition(partno, (VOID **)&mem_address,
NU_NO_SUSPEND) == NU_SUCCESS)
#else
if( NU_Alloc_Partition(partno, (unsigned int **)&mem_address,
NU_NO_TIMEOUT) == NU_SUCCESS )
#endif /* PLUS */
{
p = (UTINY FAR *) mem_address;
*p_nalloced = size;
return(p);
}
did_not_work:
return((UTINY FAR *) 0);
}
/**************************************************************************
PC_MEMORY_FAT_BLOCKS_FREE - Free in memory FAT blocks.
Description
This function is called by the file system when it no longer needs
the core it got from pc_memory_fat_blocks_alloc.
Returns
Nothing
*****************************************************************************/
VOID pc_memory_fat_blocks_free(COUNT driveno, UTINY FAR *pdata, UCOUNT nblocks) /*__fn__*/
{
nblocks = nblocks;
driveno = driveno;
#if (PLUS)
NU_Deallocate_Partition((VOID *)pdata);
#else
NU_Dealloc_Partition((unsigned int *)pdata);
#endif /* PLUS */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -