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

📄 drobj.c

📁 NUcleus plus 支持的文件系统。 是学习文件系统的很好参考资料。
💻 C
📖 第 1 页 / 共 5 页
字号:
    {
        *filename++ = '.';
        while (*fext)
        {
            if (*fext == ' ')
                break;
            else
            {
                *filename++ = *fext++;
                i++;
            }
            if (i == 3)
                break;
        }
    }

    len += i;

    /* Get rid of trailing '.' s */
    if ( (i == 0) && (*(filename-1) == '.') && (*top!= '.') )
        filename--;
    *filename = '\0';

    return(len);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       lnam_clean                                                      
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Clearn long filname information structure. This functoin does   
*       not free the block that contain short file name entry of this   
*       long filename.                                                  
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi                         
*                                                                       
* INPUTS                                                                
*                                                                       
*       *linfo                              Clear long file name        
*                                            information                
*       *rbuf                               Clear long file name block  
*                                            buffer                     
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       None.                                                           
*                                                                       
*************************************************************************/
VOID lnam_clean(LNAMINFO *linfo, BLKBUFF *rbuf)
{

    if (linfo->lnamblk1 != rbuf) /* Previous block */
    {
        pc_free_buf(linfo->lnamblk1, NO);
        linfo->lnamblk1 = (BLKBUFF *)0;
    }

    if ( (linfo->lnamblk2 ) && (linfo->lnamblk2 != rbuf) )/* Previous block */
    {
        pc_free_buf(linfo->lnamblk2, NO);
        linfo->lnamblk2 = (BLKBUFF *)0;
    }

    /* Clear long file name start block */
    linfo->lnament = 0;

}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_findin                                                       
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Find a filename in the same directory as the argument.          
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi                         
*                                                                       
* INPUTS                                                                
*                                                                       
*       *pobj                               Drive object structure      
*       *filename                           Search file name            
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       NU_SUCCESS                          Found the file.             
*       NUF_NOFILE                          The specified file not      
*                                            found.                     
*       NUF_NO_BLOCK                        No block buffer available.  
*       NUF_NO_FINODE                       No FINODE buffer available. 
*       NUF_IO_ERROR                        Driver IO error.            
*       NUF_INTERNAL                        Nucleus FILE internal error.
*                                                                       
*************************************************************************/
STATUS pc_findin(DROBJ *pobj, UINT8 *filename)
{
STATUS      ret_stat;
BLKBUFF     *rbuf;
DIRBLK      *pd;
DOSINODE    *pi;
FINODE      *pfi;
INT         found_flag = 0;
LNAMINFO    *linfo;
UINT8       ckval;
UINT8       namebuf[EMAXPATH+1];
INT16       lent_cou;
INT         len;
INT         short_name;


    /* For convenience. We want to get at block info here */
    pd = &pobj->blkinfo;

    /* Move input long filename infomation pointer into internal pointer.  */
    linfo = &pobj->linfo;

    /* First, clear the number of long file name entry */
    linfo->lnament = 0;

    /* Read the data */
    ret_stat = pc_read_blk(&rbuf, pobj->pdrive, pobj->blkinfo.my_block);
    pobj->pblkbuff = rbuf;

    while (ret_stat == NU_SUCCESS)
    {
        /* Move input directory entry pointer into internal pointer */
        pi = (DOSINODE *) &rbuf->data[0];

        /* Look at the current inode */
        pi += pd->my_index;

        /* And look for a match */
        while ( pd->my_index < INOPBLOCK )
        {
            /* End of dir if name is 0 */
            if (!pi->fname[0])
            {
                /* Is there longfilename infomation in buffer */
                if (linfo->lnament)
                {
                    /* Clean long filename information */
                    lnam_clean(linfo, rbuf);
                }
                /* Free work block */
                pc_free_buf(rbuf, NO);
                return(NUF_NOFILE);
            }

            /* This entry is long file name entry */
            if ( *((UINT8 *)pi + 0x0b) == 0x0f )
            {
                short_name = 0;

                /* It is not first entry of this long file name */
                if (linfo->lnament)
                {
                    /* Long file name entry number are between 1 and 14h */
                    if ( (*((UINT8 *)pi) == 0x00) || (*((UINT8 *)pi) > 0x14) )
                    {
#ifdef DEBUG2
                        if (*((UINT8 *)pi) != PCDELETE)
                                DEBUG_PRINT("pc_findin  long file name error \r\n");
#endif
                        /* Clean long filename information */
                        lnam_clean(linfo, rbuf);
                    }
                    /* Checking the check value of short file name */
                    else if ( linfo->lnamchk != *((UINT8 *)pi + 0x0d) )
                    {
#ifdef DEBUG2
                        DEBUG_PRINT("pc_findin  long file name check value error \r\n");
#endif

                        /* Clean long filename information */
                        lnam_clean(linfo, rbuf);
                    }
                    /* Checking the long filename entry number */
                    else if ( (lent_cou ) != *((UINT8 *)pi) )
                    {
#ifdef DEBUG2
                        DEBUG_PRINT("pc_findin  long file name entry number error \r\n");
#endif

                        /* Clean long filename information */
                        lnam_clean(linfo, rbuf);
                    }
                    else
                    {
                        /* Increment the number of long file name entry */
                        linfo->lnament++;

                        /* Decrement the seqence number of long file name entry */
                        lent_cou--;

                        /* Save BLKBUFF pointer into longfilename info structure */
                        /* BLKBUFF pointer 2 is not used yet */
                        if (linfo->lnamblk2 == 0)
                        {
                            /* Read block is changed */
                            if (linfo->lnamblk1 != rbuf)
                            {
                                /* Save new BLKBUFF pointer into longfilename info structure */
                                linfo->lnamblk2 = rbuf;
                            }
                        }
                        /* BLKBUFF pointer 2 is used and BLKBUFF pointer 3 is not used yet */
                        else if (linfo->lnamblk3 == 0)
                        {
                            /* Read block is changed */
                            if (linfo->lnamblk2 != rbuf)
                            {
                                /* Save new BLKBUFF pointer into longfilename info structure */
                                linfo->lnamblk3 = rbuf;
                            }
                        }
                    }
                }
                else /* Long file name first entry */
                {
                    /* Long file name first entry must be added 0x40 */
                    if ( ((*((UINT8 *)pi) & 0xF0) != 0x40) &&
                                    ((*((UINT8 *)pi) & 0xF0) != 0x50) )
                    {
#ifdef DEBUG2
                        if (*((UINT8 *)pi) != PCDELETE)
                                DEBUG_PRINT("pc_findin  long file name error \r\n");
#endif

                        /* Clean long filename information */
                        lnam_clean(linfo, rbuf);
                    }
                    else
                    {
                        /* Set long file name start block */
                        linfo->lnamblk1 = rbuf;
                        linfo->lnamblk2 = NULL;
                        linfo->lnamblk3 = NULL;

                        /* Set long file name start index */
                        linfo->lnam_index = pd->my_index;

                        /* Set check value of short file name */
                        linfo->lnamchk = *((UINT8 *)pi + 0x0d);

                        /* Increment long file name entry */
                        linfo->lnament++;

                        /* Save long filename entry number */
                        lent_cou = *((UINT8 *)pi) - 0x40;

                        /* Next entry number */
                        lent_cou--;
                    }
                }
            }
            /* Short file name entry of the long file name, */
            else if (linfo->lnament)
            {
                if (*((UINT8 *)pi) == PCDELETE)
                {
#ifdef DEBUG2
                    DEBUG_PRINT("pc_findin short filename of long file name deleted \r\n");
#endif

                    /* Clean long filename information */
                    lnam_clean(linfo, rbuf);
                }
                else
                {
                    /* Calculate check value of short file name */
                    ckval = chk_sum((UINT8 *)pi);

                    /* Checking the check value of short file name */
                    if (linfo->lnamchk != ckval)
                    {
#ifdef DEBUG2
                        DEBUG_PRINT("pc_findin  long file name check value error %s %d\r\n",
                                                        __FILE__, __LINE__);
#endif

                        /* Clean long filename information */
                        lnam_clean(linfo, rbuf);
                    }
                    /* The sequence number of Long filename entry must be 0 */
                    else if (lent_cou)
                    {
#ifdef DEBUG2
                        DEBUG_PRINT("pc_findin  long file name entry number error %s %d\r\n",
                                                        __FILE__, __LINE__);
#endif

                        /* Clean long filename information */
                        lnam_clean(linfo, rbuf);
                    }
                    else
                    {

⌨️ 快捷键说明

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