⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apiutil.c

📁 NUcleus plus 支持的文件系统。 是学习文件系统的很好参考资料。
💻 C
📖 第 1 页 / 共 3 页
字号:
        }
    }
    /* Invalid FD */
    return(NULL);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_allocfile                                                    
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Allocate PC_FILE structure.                                     
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi                         
*                                                                       
* INPUTS                                                                
*                                                                       
*       None                                                            
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       File descriptor.                                                
*       -1                                  Over the NUSERFILES.        
*                                                                       
*************************************************************************/
INT pc_allocfile(VOID)
{
PC_FILE     *pfile;
INT         i;


    pfile = mem_file_pool;

    for (i = 0; i < NUSERFILES; i++, pfile++)
    {
        if (pfile->is_free)
        {
            pc_memfill(pfile, sizeof(PC_FILE), (UINT8) 0);
            return(i);
        }
    }
    return(-1);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_freefile                                                     
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Free all core associated with a file descriptor and make the    
*       descriptor available for future calls to allocfile.             
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi                         
*                                                                       
* INPUTS                                                                
*                                                                       
*       fd                                  File descriptor.            
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       None.                                                           
*                                                                       
*************************************************************************/
VOID pc_freefile(INT fd)
{
PC_FILE     *pfile;


    if ((pfile = pc_fd2file(fd)) == NULL)
        return;
    if (pfile->pobj)
        pc_freeobj(pfile->pobj);
    pfile->is_free = YES;
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_free_all_fil                                                 
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Release all file descriptors associated with a drive and free   
*       up all core associated with the files called by dsk_close       
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi                         
*                                                                       
* INPUTS                                                                
*                                                                       
*       pdrive                              Drive management structure  
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       None.                                                           
*                                                                       
*************************************************************************/
VOID pc_free_all_fil(DDRIVE *pdrive)
{
PC_FILE     *pfile;
INT         i;


    for (i = 0; i < NUSERFILES; i++)
    {
        pfile = pc_fd2file(i);
        if (pfile != NULL)
        {
            if ( (pfile->pobj) && (pfile->pobj->pdrive == pdrive) )
            {
                /* print a debug message since in normal operation 
                   all files should be close closed before closing the drive */
                pc_report_error(PCERR_FSTOPEN);
                pc_freefile(i);
            }
        }
    }
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_log_base_2                                                   
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Calculate log2(N).                                              
*                                                                       
* AUTHOR                                                                
*                                                                       
*      Takahiro Takahashi                          
*                                                                       
* INPUTS                                                                
*                                                                       
*       n                                   Sector per cluster          
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       log2(N)                                                         
*                                                                       
*************************************************************************/
INT16 pc_log_base_2(UINT16 n)                                   /*__fn__*/
{
INT16       log;


    log = 0;
    if (n <= 1)
        return(log);

    while (n)
    {
        log += 1;
        n >>= 1;
    }
    return((INT16)(log-1));
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_get_cwd                                                      
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Return the current directory inode for the drive represented    
*       by ddrive.                                                      
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi                         
*                                                                       
* INPUTS                                                                
*                                                                       
*       pdr                                 Drive management structure. 
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       DROBJ pointer                                                   
*       Return NULL on error.                                           
*                                                                       
*************************************************************************/
DROBJ *pc_get_cwd(DDRIVE *pdrive)
{
DROBJ       *pcwd;
DROBJ       *pobj;


    pobj = NULL;

    pcwd = fs_user->lcwd[pdrive->driveno];

    /* If no current working dir set it to the root */
    if (!pcwd)
    {
        pcwd = pc_get_root(pdrive);
        fs_user->lcwd[pdrive->driveno] = pcwd;
    }

    if (pcwd)
    {
        pobj = pc_allocobj();
        if (!pobj)
            return(NULL);
        /* Free the inode that comes with allocobj */
        pc_freei(pobj->finode);
        copybuff(pobj, pcwd, sizeof(DROBJ));
        pobj->finode->opencount += 1;

        return(pobj);
    }
    else    /* If no cwd is set error */
    {
        return(NULL);
    }
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_upstat                                                       
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Given a pointer to a DSTAT structure that contains a pointer to 
*       an initialized DROBJ structure, load the public elements of     
*       DSTAT with name filesize, date of modification et al.           
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi                         
*                                                                       
* INPUTS                                                                
*                                                                       
*       statobj                             Caller's buffer to put file 
*                                            info.                      
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       None.                                                           
*                                                                       
*************************************************************************/
VOID pc_upstat(DSTAT *statobj)
{
DROBJ       *pobj;
FINODE      *pi;
INT         ii; 


    pobj = statobj->pobj;

    pi = pobj->finode;
    copybuff(statobj->sfname, pi->fname, 8);
    statobj->sfname[8] = '\0';
    copybuff(statobj->fext, pi->fext, 3);
    statobj->fext[3] = '\0';
    statobj->lfname[0] = '\0';
    statobj->fattribute = pi->fattribute;
    if (statobj->pobj->linfo.lnament) /* long file name */
    {                   
        pc_cre_longname((UINT8 *)statobj->lfname, &statobj->pobj->linfo);
    } 
	else  /* Copy short file name to long name field */
	{
		/* No copy on a volume label */
		if(!(statobj->fattribute & AVOLUME)) 
		{
		    ii = 0;
		    while( statobj->sfname[ii] != '\0' && 
				        statobj->sfname[ii] != ' ')
			{

                statobj->lfname[ii] = statobj->sfname[ii];
		        ii++;
			}
            
            /* Put a dot in lfname */
			statobj->lfname[ii] = (UINT8)'.';
            ii++;

			/* If there is an extension, copy it */
            if( statobj->fext[0] != ' ')
			{

                statobj->lfname[ii] = statobj->fext[0];
		        ii++;
                statobj->lfname[ii] = statobj->fext[1];
		        ii++;
                statobj->lfname[ii] = statobj->fext[2];
		        ii++;
                statobj->lfname[ii] = '\0';
			}
			else /* No extension, remove dot */
			{
				ii--;
                statobj->lfname[ii] = (UINT8)0;
			}

		}
	}


    statobj->fcrcmsec = pi->fcrcmsec;
    statobj->fcrtime = pi->fcrtime;
    statobj->fcrdate = pi->fcrdate;

    statobj->faccdate = pi->faccdate;

    statobj->fuptime = pi->fuptime;
    statobj->fupdate = pi->fupdate;

    statobj->fsize = pi->fsize;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -