📄 fat_dir.c
字号:
/*computes gathered data
/* check if we have a LFN entry */
if (gl_buffer[11+j] != ATTR_LFN_ENTRY)
{
if (!lfn_entry_found)
{
/* true DOS 8.3 entry format */
for (i = 0; i < 8; i++)
{
lfn_name[i] = gl_buffer[i+j];
if (lfn_name[i] == ' ')
{ /* space is end of name */
break;
}
}
/* append extension */
if((gl_buffer[11+j] & ATTR_DIRECTORY )!= ATTR_DIRECTORY)
{
lfn_name[i++] = '.';
}
lfn_name[i++] = gl_buffer[8+j];
lfn_name[i++] = gl_buffer[9+j];
lfn_name[i++] = gl_buffer[10+j];
lfn_name[i] = '\0'; /* end of string */
}
else
{ // LFN name treatment //
i = 0;
while((lfn_name[i] != '\0') && (lfn_name[i] != 0xff))
{
i++;
}
lfn_name[i] = '\0';
}
/* store extension */
ext[0]= gl_buffer[8+j];
ext[1]= gl_buffer[9+j];
ext[2]= gl_buffer[10+j];
/* standard computing for normal entry */
entry->attributes = gl_buffer[11+j];
entry->start_cluster.b[3] = gl_buffer[26+j];
entry->start_cluster.b[2] = gl_buffer[27+j];
entry->start_cluster.b[1] = gl_buffer[20+j];
entry->start_cluster.b[0] = gl_buffer[21+j];
//entry->start_cluster += ((Uint16) gl_buffer[27+j]) << 8;
entry->size.b[3] = gl_buffer[28+j];
entry->size.b[2] = gl_buffer[29+j];
entry->size.b[1] = gl_buffer[30+j];
entry->size.b[0] = gl_buffer[31+j];
/* now it's time to stop */
exit_flag = TRUE;
}// end if (name_buffer[11] != ATTR_LFN_ENTRY)
else
{
lfn_entry_found = TRUE;
//lfn_name[0] = 'L';
if(count < 5)
{
if((gl_buffer[0 + j] & LFN_SEQ_MASK) <= MAX_LFN_ENTRIES)
{
for(i=0; i<5; i++)
{
lfn_name[i*2 + 26*((gl_buffer[0+j] & LFN_SEQ_MASK) - 1) + 1] = gl_buffer[2*i + 1 +j];
lfn_name[i*2 + 26*((gl_buffer[0+j] & LFN_SEQ_MASK) - 1)] = gl_buffer[2*i + 2 +j];
}
for(i=0; i<6; i++)
{
lfn_name[i*2 + 10 + 26*((gl_buffer[0+j] & LFN_SEQ_MASK) - 1) + 1] = gl_buffer[2*i + 14 +j];
lfn_name[i*2 + 10 + 26*((gl_buffer[0+j] & LFN_SEQ_MASK) - 1)] = gl_buffer[2*i + 15 +j];
}
for(i=0; i<2; i++)
{
lfn_name[i*2 + 22 + 26*((gl_buffer[0+j] & LFN_SEQ_MASK) - 1) + 1] = gl_buffer[2*i + 28 +j];
lfn_name[i*2 + 22 + 26*((gl_buffer[0+j] & LFN_SEQ_MASK) - 1)] = gl_buffer[2*i + 29 +j];
}
}
}
count++;
}
}//end while
phy_read_close(); /* close physical read */
}
/*F**************************************************************************
* NAME: fat_scan_dir
*----------------------------------------------------------------------------
* PARAMS:
* id: file extension to select
* return: none
*----------------------------------------------------------------------------
* PURPOSE:
* Construct the file directory list
*----------------------------------------------------------------------------
* NOTE:
* The value are relative position with the previous file.
* Call to this function assume that the dir fragment chain has been created
*----------------------------------------------------------------------------
* REQUIREMENTS:
* Maximum of 256 entries between 2 authorized file (id extension)
* because the relative position is stored on one byte.
* To allow more than 256 entries (-> 32768), change type of
* fat_dir_entry_list[] from Byte to Uint16 (no overflow management)
* and change MAX_DIRECTORY_GAP_FILE from 255 to 32767
*****************************************************************************/
void fat_scan_dir(Byte flag)
{
Uint16 counter_entry; /* entry counter: 0..MAX_DIRECTORY_FILE */
//data Uint16 entry_pos; /* relative entry position */
//data Uint16 entry_pos_saved; /* used when the file is not the id extension */
Byte i;
Uint16 num=0;
Uint16 nb_cluster;
Uint16 counter_dir;
Byte ready;
// bit del_exist;
Uint16 j;
Uint16 dir_count;
Uint16 dir_offset;
// del_exist = 0;
// index = 0;
ready = 0;
counter_entry = 0;
dir_count = 0;
if((dir_is_root == TRUE) && (fat_type_id != FAT_IS_32))
{
phy_read_open(fat_ptr_rdir);
counter_dir = fat_root_entries;
}
else
{
nb_cluster = 0;
fat_dclust_byte_count = 0;
fat_dchain_nb_clust = 0;
fat_dchain_index = 0;
for(i=0;i<MAX_DIR_FRAGMENT_NUMBER;i++)
{
if(dclusters[i].number == 0)
{
nb_cluster++;
break;
}
else
{
nb_cluster = nb_cluster + dclusters[i].number;
}
}
counter_dir = ((Uint32)nb_cluster * fat_cluster_size * fat_sector_size) / 32;
}
do /* scan all entries */
{
if ((dir_is_root == TRUE) && (fat_type_id != FAT_IS_32))
{
if(num%fat_sector_size==0)
{
phy_read_sector();
num=0;
}
}
else
{ /* subdir can be fragmented -> dgetc() */
if(num % fat_sector_size == 0 )
{
fat_dgetsector();
num=0;
}
}
j = num;
num += DIR_SIZE;
if((gl_buffer[0+j] != FILE_DELETED) && (gl_buffer[0+j] != FILE_NOT_EXIST))
{
dir_count++;
// index++;
dir_offset = counter_entry;
while (gl_buffer[11+j] == ATTR_LFN_ENTRY) /* LFN entry ? */
{ /* then read all the LFN entry */
if (dir_is_root == TRUE)
{ /* root dir is linear */
if(num%fat_sector_size==0)
{
phy_read_sector();
num = 0;
}
}
else
{ /* subdir can be fragmented -> dgetc() */
if(num % fat_sector_size == 0 )
{
fat_dgetsector();
num=0;
}
}
j=num;
num += DIR_SIZE;
counter_entry++;
}
/* filter on the file type */
fat_cache.current.attributes = gl_buffer[11+j];
ext[0] = gl_buffer[8+j];
ext[1] = gl_buffer[9+j];
ext[2] = gl_buffer[10+j];
if ((fat_check_ext() & fat_global_id) == FILE_XXX)
{ /* Don't valid the entry */
dir_count--;
}
if((flag == 0)&&(ready == 0))
{
if(dir_count == (fat_dir_list_index + 1))
{
fat_dir_all_count = dir_offset;//counter_entry;
ready = 1;
}
}
}
counter_entry++;
if ((gl_buffer[0+j] == FILE_NOT_EXIST) || (counter_dir == counter_entry))
break;
}while(1);
fat_dir_list_last = dir_count;
if(flag == 1)
{
fat_dir_all_count = counter_entry;
if(gl_buffer[0+j] == FILE_NOT_EXIST)
fat_dir_all_count--;
if(fat_dir_list_last == 0)
fat_no_file = 1;
else
fat_no_file = 0;
}
phy_read_close();
}
/*F**************************************************************************
* NAME: fat_check_ext
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Return the type of the file
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
Uint32 fat_check_ext (void)
{
// char ext_bak[3];
if ((fat_cache.current.attributes & ATTR_DIRECTORY) == ATTR_DIRECTORY)
{
return FILE_DIR;
}
if ((ext[0] == 'M') &&
(ext[1] == 'P') &&
(ext[2] == '3'))
{
return FILE_MP3;
}
if ((ext[0] == 'A') &&
(ext[1] == 'V') &&
(ext[2] == '6'))
{
return FILE_AV6;
}
if(((ext[0] == 'W')&&
(ext[1] == 'M')&&
(ext[2] == 'A'))||
((ext[0] == 'A')&&
(ext[1] == 'S')&&
(ext[2] == 'F'))||
((ext[0] == 'W')&&
(ext[1] == 'M')&&
(ext[2] == 'V')))
{
return FILE_WMA;
}
if((ext[0] == 'W')&&
(ext[1] == 'A')&&
(ext[2] == 'V'))
{
return FILE_WAV;
}
if((ext[0] == 'L')&&
(ext[1] == 'R')&&
(ext[2] == 'C'))
{
return FILE_LRC;
}
if ((ext[0] == 'I') &&
(ext[1] == 'M') &&
(ext[2] == 'V'))
{
return FILE_IMV;
}
if ((ext[0] == 'B') &&
(ext[1] == 'M') &&
(ext[2] == 'P'))
{
return FILE_BMP;
}
if ((ext[0] == 'J') &&
(ext[1] == 'P') &&
(ext[2] == 'G'))
{
return FILE_JPG;
}
if ((ext[0] == 'T') &&
(ext[1] == 'X') &&
(ext[2] == 'T'))
{
return FILE_TXT;
}
if ((ext[0] == 'A') &&
(ext[1] == 'A') &&
(ext[2] == 'C'))
{
return FILE_AAC;
}
if ((ext[0] == 'O') &&
(ext[1] == 'G') &&
(ext[2] == 'G'))
{
return FILE_OGG;
}
if ((ext[0] == 'I') &&
(ext[1] == 'M') &&
(ext[2] == 'A'))
{
return FILE_IMA;
}
return FILE_XXX;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -