Ejemplo n.º 1
0
/*********************************************************************************************************
** 函数名称: _GetFDTInfo
** 功能描述: 获取FDT所在的目录的开始簇号及系统内名称,内部使用
**
** 输 入: DirFileName:用户使用的FDT名(包括路径)
**         FDTName:用于返回系统使用的FDT名(不包括路径)
** 输 出: FDT所在的目录的开始簇号,BAD_CLUS表示找不到路径
**         
** 全局变量: 无
** 调用模块: GetDirClusIndex,StrToFDTName
********************************************************************************************************/
        acoral_u32 _GetFDTInfo(acoral_char *FDTName, acoral_char *DirFileName)
{
    acoral_u32 Rt;
    acoral_char *temp;
    acoral_u8 i;

    /* 获取字符串结束位置 */
    temp = DirFileName;
    while (*temp != 0)
    {
         temp++;
    }
    temp--;
    if (*temp == '\\' || *temp == '/')  /* 最后字符为\不是有效文件/目录名 */
    {
        return BAD_CLUS;
    }

    
    /* 获取目录开始簇号 */
    Rt = BAD_CLUS;
    while (1)
    {
        if (*temp == '\\' || *temp == '/' || *temp == ':')
        {
            /* 找到目录分割符号'\' 或 */
            /* 找到逻辑盘分割符号':',表明是指定逻辑盘当前目录 */
            temp++;
            i = *temp;
            *temp = 0;
            Rt = GetDirClusIndex(DirFileName);
            *temp = i;
            break;
        }
        if (temp == DirFileName)
        {
            /* 只有文件\目录名,表明是当前逻辑盘当前目录 */
            Rt = GetDirClusIndex(".");
            break;
        }
        temp--;
    }
    /* 获取系统内文件\目录名 */
    if (StrToFDTName(FDTName, temp) != RETURN_OK)
    {
        Rt = BAD_CLUS;
    }
    return Rt;
}
Ejemplo n.º 2
0
/*********************************************************************************************************
** 函数名称: ChangeDir
** 功能描述: 改变当前目录
**
** 输 入: Path:路径名
**
** 输 出: RETURN_OK:成功
**        其它参考fat.h中关于返回值的说明
** 全局变量: 无
** 调用模块: GetDirClusIndex,GetDiskInfo
********************************************************************************************************/
        acoral_u8 ChangeDir(acoral_char *Path)
{
    acoral_u32 ClusIndex;
    acoral_u8 Rt, Drive;
    Disk_Info *Disk;

    Rt = PATH_NOT_FIND;
    ClusIndex = GetDirClusIndex(Path);
    if (ClusIndex != BAD_CLUS)
    {
        Drive = GetDrive(Path);
        Disk = GetDiskInfo(Drive);
        Rt = NOT_FIND_DISK;
        if (Disk != NULL)
        {
            Rt = RETURN_OK;
            Disk->PathClusIndex = ClusIndex;
        }
    }
    return Rt;
}
Ejemplo n.º 3
0
/*********************************************************************************************************
** Name        :GetTotalSubDir
** Description :get the total number of child direction.
** Input       :Path
** Output      :child direction number
** global      :CurDirClus
** call module : null
********************************************************************************************************/
_ATTR_FAT_FIND_CODE_
uint16 GetTotalSubDir(uint8 *Path)
{
    FDT Rt;
    uint32 index;
    uint32 DirClus;
    uint16 TotSubDir=0;

    DirClus = GetDirClusIndex(Path);
    
    if (DirClus == BAD_CLUS)
    {
        return (0);
    }
    
    for (index = 0; ; index++)
    {
        if (RETURN_OK != GetFDTInfo(&Rt, DirClus, index))
        {
            break;
        }
        
        if (Rt.Name[0] == FILE_NOT_EXIST)   //找到空的意为结束
        {
            break;
        }
        
        if (Rt.Name[0] == FILE_DELETED)     //已删除
        {
            continue;
        }
        
        if ((Rt.Attr & ATTR_DIRECTORY) == ATTR_DIRECTORY)
        {
            TotSubDir++;
        }
    }
    return (TotSubDir);
}
Ejemplo n.º 4
0
/*********************************************************************************************************
** Name        :MakeDir
** Description :create direction
** Input       :Path: DirFileName the path name use the 8.3 format.
** Output      :RETURN_OK:成功
** other reference the return value explain in file fat.h
** global :FileInfo
** call module :AddFDT, GetDirClusIndex
********************************************************************************************************/
IRAM_ENCODE
uint8 MakeDir(uint8 *Path, uint8 *DirFileName)
{
    uint8 Rt;
    uint8 i;
    uint32 ClusIndex, Temp1;
    FDT temp;
    
    StrUprCase(Path);
    ClusIndex = GetDirClusIndex(Path);
    
    Rt = PATH_NOT_FIND;
    if (ClusIndex != BAD_CLUS)
    {
        for (i = 0; i < 11; i++)        //目录项填空格
        {
            temp.Name[i] = ' ';
        }
        
        for (i = 0; i < 11; i++)
        {
            if (*DirFileName == '\0')   //到路径结束
            {
                break;
            }
            
            temp.Name[i] = *DirFileName++;
        }

        /* FDT是否存在 */
        Rt = FDTIsLie(ClusIndex, temp.Name);
        if (Rt == NOT_FIND_FDT)
        {
            /* 不存在 */
            Temp1 = FATAddClus(0);                  /* 获取目录所需磁盘空间 */
            Rt    = DISK_FULL;                      /* 没有空闲空间 */

            if ((Temp1 > EMPTY_CLUS_1) && (Temp1 < BAD_CLUS))
            {
                ClearClus(Temp1);                       /* 清空簇 */

                /* 设置FDT属性 */
                temp.Attr         = ATTR_DIRECTORY;
                temp.FileSize     = 0;
                temp.NTRes        = 0;
                temp.CrtTimeTenth = 0;
                temp.CrtTime      = 0;
                temp.CrtDate      = 0;
                temp.LstAccDate   = 0;
                temp.WrtTime      = 0;
                temp.WrtDate      = 0;
                temp.FstClusLO    = Temp1 & 0xffff;
                temp.FstClusHI    = Temp1 / 0x10000;

                Rt = AddFDT(ClusIndex, &temp);       /* 增加目录项 */
                
                if (Rt == RETURN_OK)
                {
                    /* 建立'.'目录 */
                    temp.Name[0] = '.';
                    for (i = 1; i < 11; i++)
                    {
                        temp.Name[i] = ' ';
                    }
                    AddFDT(Temp1, &temp);

                    /* 建立'..'目录 */
                    temp.Name[1] = '.';
                    if (ClusIndex == BootSector.BPB_RootClus)
                    {
                        ClusIndex = 0;
                    }
                    
                    temp.FstClusLO = ClusIndex & 0xffff;
                    temp.FstClusHI = ClusIndex / 0x10000;
                    Rt = AddFDT(Temp1, &temp);
                }
                else
                {
                    FATDelClusChain(Temp1);
                }
                
                Rt = RETURN_OK;
            }
        }
    }
    
    ///////////////////////////////////////////////////////////
    //回写FAT Cache
    if (gFatCache.Sec!=0 && gFatCache.Flag!=0)
    {
        gFatCache.Flag=0;
        FATWriteSector(gFatCache.Sec, gFatCache.Buf);
    }
    ///////////////////////////////////////////////////////////
    
    return (Rt);
}