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

📄 drobj.c

📁 NUcleus plus 支持的文件系统。 是学习文件系统的很好参考资料。
💻 C
📖 第 1 页 / 共 5 页
字号:
                        /* Create long filename string from directory entry */
                        pc_cre_longname(namebuf, linfo);

                        /* Compare long file name */
                        if (YES == pc_patcmp(namebuf, filename ))
                        {
                            /* measure long file name length */
                            for (len = 0; *(namebuf+len); len++);

                            /* Set the file found flag */
                            found_flag = 1;
                        }
                    }
                }
                short_name = 1;
            }

            /* Short file name entry */
            if ( (!linfo->lnament) || (short_name) )
            {
                /* The file is not deleted */
                if (*((UINT8 *)pi) != PCDELETE)
                {
                    if (!found_flag)
                    {
                        /* Create short filename string from directory entry */
                        len = pc_cre_shortname((UINT8 *)namebuf, pi->fname, pi->fext);
                        if (len)
                        {
                            /* Compare the file name */
                            if (YES == pc_patcmp(namebuf, filename ))
                            {
                                /* Set the file found flag */
                                found_flag = 1;
                            }
                            else if (linfo->lnament)
                            {
                                /* Clean long filename information */
                                lnam_clean(linfo, rbuf);
                            }
                       }
                    }
                }
            }
            /* The file is found */
            if (found_flag)
            {
#ifdef DEBUG1
                DEBUG_PRINT("pc_findin  file found my_block=%d  my_index=%d my_first=%d\r\n",
                                pd->my_block, pd->my_index, pd->my_frstblock );
#endif
                /* We found it */
                /* See if it already exists in the inode list.
                   If so.. we use the copy from the inode list */
                pfi = pc_scani(pobj->pdrive, rbuf->blockno, pd->my_index);

                if (pfi)
                {
                    pc_freei(pobj->finode);
                    pobj->finode = pfi;
                }
                else
                {
                    /* No inode in the inode list. Copy the data over
                           and mark where it came from */
                    pfi = pc_alloci();
                    if (pfi)
                    {
                        /* Calculate Absolute path length */
                        pfi->abs_length = pobj->finode->abs_length + len;

                        pc_freei(pobj->finode); /* Release the current */
                        pobj->finode = pfi;
                        pc_dos2inode(pobj->finode, pi);
                        pc_marki(pobj->finode, pobj->pdrive, pd->my_block, 
                                  pd->my_index);
                    }
                    else
                    {
                        /* Is there longfilename infomation in buffer */
                        if (linfo->lnament)
                        {
                            /* Clean long filename information */
                            lnam_clean(linfo, rbuf);
                        }
                        pc_free_buf(rbuf, NO);
                        return(NUF_NO_FINODE);
                    }
                }
                /* This is not long filename */
                if (!linfo->lnament)
                {
                    pc_free_buf(rbuf, NO);
                }
                return(NU_SUCCESS);
            }                   /* if (found_flag) */
            pd->my_index++;
            pi++;
        }
        /* Is there longfilename infomation in buffer */
        if (!linfo->lnament)
        {
            pc_free_buf(rbuf, NO);
        }

        /* Update the objects block pointer */
        ret_stat = pc_next_block(pobj);
        if (ret_stat != NU_SUCCESS)
        {
            if (ret_stat == NUF_NOSPC)
                ret_stat = NUF_NOFILE;
            break;
        }

        pd->my_index = 0;

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

    }

    /* Is there longfilename infomation in buffer 
        Note: Shortfilename buffer is already free */
    if (linfo->lnament)
    {
        /* Clean long filename information */
        lnam_clean(linfo, rbuf);
    }

    /* Always error return */
    return(ret_stat);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_get_mom                                                      
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Given a DROBJ initialized with the contents of a subdirectory's 
*       ".." entry, initialize a DROBJ which is the parent of the       
*       current directory.                                              
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi                         
*                                                                       
* INPUTS                                                                
*                                                                       
*       **pmom                              Output parent drive object  
*       **pdotdot                           ".." entry drive object     
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       NU_SUCCESS                          If service is successful.   
*       NUF_NO_BLOCK                        No block buffer available.  
*       NUF_NO_DROBJ                        No DROBJ buffer available.  
*       NUF_IO_ERROR                        Driver IO error.            
*       NUF_INTERNAL                        Nucleus FILE internal error.
*                                                                       
*************************************************************************/
STATUS pc_get_mom(DROBJ **pmom, DROBJ *pdotdot)
{
STATUS      ret_stat;
DDRIVE      *pdrive = pdotdot->pdrive;
UINT32      sectorno;
BLKBUFF     *rbuf;
DIRBLK      *pd;
DOSINODE    *pi;
FINODE      *pfi;


    /* We have to be a subdir */
    if (!pc_isadir(pdotdot))
        return(NUF_INTERNAL);

    /* If ..->cluster is zero then parent is root */
    if (!pdotdot->finode->fcluster)
    {
        *pmom = pc_get_root(pdrive);
        if (!*pmom)
            return(NUF_NO_DROBJ);
        else
            return(NU_SUCCESS);
    }
    /* Otherwise : cluster points to the beginning of our parent.
                   we also need the position of our parent in it's parent   */

    *pmom = pc_allocobj();
    if (!*pmom)
        return(NUF_NO_DROBJ);

    (*pmom)->pdrive = pdrive;
    /* Find .. in our parent's directory */
    sectorno = pc_cl2sector(pdrive, (UINT32)pdotdot->finode->fcluster);
    /* We found .. in our parents dir. */
    (*pmom)->pdrive = pdrive;
    (*pmom)->blkinfo.my_frstblock =  sectorno; 
    (*pmom)->blkinfo.my_block     =  sectorno;
    (*pmom)->blkinfo.my_index     =  0;
    (*pmom)->isroot = NO;

    /* Read the data */
    ret_stat = pc_read_blk(&rbuf, (*pmom)->pdrive, (*pmom)->blkinfo.my_block);
    (*pmom)->pblkbuff = rbuf;
    if (ret_stat == NU_SUCCESS)
    {
        pi = (DOSINODE *) &rbuf->data[0];
        pc_dos2inode((*pmom)->finode, pi);
        pc_free_buf(rbuf, NO);

        /* See if the inode is in the buffers */
        pfi = pc_scani(pdrive, sectorno, 0);
        if (pfi)
        {
            pc_freei((*pmom)->finode);
            (*pmom)->finode = pfi;
        }
        else
        {
            pd = &((*pmom)->blkinfo);
            pc_marki((*pmom)->finode, (*pmom)->pdrive, pd->my_block, 
                     pd->my_index);
        }
    }
    else    /* Error, something didn't work */
    {
        pc_freeobj(*pmom);
    }
    return(ret_stat);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_mkchild                                                      
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Allocate an object and fill in as much of the the block pointer 
*       section as possible based on the parent.                        
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi                         
*                                                                       
* INPUTS                                                                
*                                                                       
*       *pmom                               Drive object                
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       Returns a partially initialized DROBJ if enough core available  
*       and pmom was a valid subdirectory.                              
*                                                                       
*************************************************************************/
DROBJ *pc_mkchild(DROBJ *pmom)
{
DROBJ       *pobj;
DIRBLK      *pd;


   /* init the object - */
    pobj = pc_allocobj();
    if (!pobj)
        return(NULL);

    pd = &pobj->blkinfo;


    pobj->isroot = NO;              /* Child can not be root */
    pobj->pdrive =  pmom->pdrive;   /* Child inherets moms drive */

    /* Now initialize the fields storing where the child inode lives */
    pd->my_index = 0;
    pd->my_block = pd->my_frstblock = pc_firstblock(pmom);

    if (!pd->my_block)
    {
        pc_freeobj(pobj);
        return(NULL);
    }

    pobj->finode->abs_length = pmom->finode->abs_length + 1;
    return(pobj);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_mknode                                                       
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Creates a file or subdirectory ("inode") depending on the flag  
*       values in attributes. A pointer to an inode is returned for     
*       further processing.                                             
*       Note: After processing, the DROBJ must be released by calling   
*       pc_freeobj.                                                     
*                                                                       
* AUTHOR                                                                

⌨️ 快捷键说明

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