?? fat32.c
字號:
lfn_name[i++] = ' ';
lfn_name[i++] = lfn_name[0];
lfn_name[i++] = lfn_name[1];
lfn_name[i++] = lfn_name[2];
lfn_name[i++] = lfn_name[3];
lfn_name[i++] = lfn_name[4];
lfn_name[i++] = lfn_name[5];
lfn_name[i++] = lfn_name[6];
lfn_name[i++] = lfn_name[7];
lfn_name[i++] = lfn_name[8];
lfn_name[i++] = lfn_name[9];
lfn_name[i++] = lfn_name[10];
lfn_name[i++] = lfn_name[11];
lfn_name[i++] = lfn_name[12];
}
lfn_name[i] = '\0'; /* end of name */
}
else
{
/* true DOS 8.3 entry format */
for (i = 0; i < 8; i++)
{
lfn_name[i] = gl_buffer[i];
if (lfn_name[i] == ' ')
{ /* space is end of name */
break;
}
}
if ((gl_buffer[8] == ' ') &&
(gl_buffer[9] == ' ') &&
(gl_buffer[10] == ' '))
lfn_name[i++] = ' ';
else
lfn_name[i++] = '.'; /* append extension */
lfn_name[i++] = gl_buffer[8];
lfn_name[i++] = gl_buffer[9];
lfn_name[i++] = gl_buffer[10];
for (; i != 14; i++)
{
lfn_name[i] = ' '; /* append spaces for display reason */
}
lfn_name[i] = '\0'; /* end of string */
}
fat_cache.current.attributes = gl_buffer[11]; /* filter on the file type */
ext[0]= gl_buffer[8]; /* store extension */
ext[1]= gl_buffer[9];
ext[2]= gl_buffer[10];
fat_current_end_entry_position++;
if ((fat_check_ext() & current_ext) == FILE_XXX)
{
fat_dir_current_offs += ((fat_current_end_entry_position - fat_current_start_entry_position) << 5);
}
}
while ((fat_check_ext() & current_ext) == FILE_XXX);
entry->start_cluster = gl_buffer[26]; /* starting cluster value */
entry->start_cluster += ((Uint32) gl_buffer[27]) << 8;
entry->start_cluster += ((Uint32) gl_buffer[20]) << 16;
entry->start_cluster += ((Uint32) gl_buffer[21]) << 24;
entry->size.b[3] = gl_buffer[28]; /* file size value */
entry->size.b[2] = gl_buffer[29];
entry->size.b[1] = gl_buffer[30];
entry->size.b[0] = gl_buffer[31];
Hard_read_close(); /* close physical read */
}
/*F**************************************************************************
* NAME: fat_get_root_directory
*----------------------------------------------------------------------------
* PARAMS:
* id: file extension to select
*
* return:
* - OK: file available
* - KO: no requested file found
* - KO: low_level memory error
*----------------------------------------------------------------------------
* PURPOSE:
* Select first available file/dir in root diretory
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* Fill all the cache information for the first time
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit fat_get_root_directory (Byte id)
{
dir_is_root = TRUE; /* set directory root flag */
fat_cache.current.start_cluster = fat_rootclus_fat32 ; /* #cluster root directory */
fat_get_clusters(&dclusters, MAX_DIR_FRAGMENT_NUMBER); /* Construct root directory cluster chain */
fat_last_dclust_index = fat_last_clust_index; /* save last index position for chain cluster */
/* computes sector address from allocation table */
fat_dir_current_sect = (((Uint32)(dclusters[0].cluster)) * fat_cluster_size)
+ fat_ptr_data;
fat_get_dir_file_list(id); /* create list of entries */
if (fat_dir_list_last == 0)
return KO; /* no requested (id) entry */
fat_dir_list_index = 1; /* point on first root entry */
fat_current_start_entry_position = 0;
fat_current_end_entry_position = 0;
fat_fetch_file_info(&fat_cache.current, FETCH_NEXT);
fat_cache.parent.start_cluster = fat_rootclus_fat32; /* parent dir is also root */
fat_cache.parent.attributes = ATTR_DIRECTORY; /* mark as directory */
return OK;
}
/*F**************************************************************************
* NAME: fat_goto_next
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
* - OK: next file available
* - KO: last file reached
* - KO: low_level memory error
*----------------------------------------------------------------------------
* PURPOSE:
* Fetch the next dir/file info in cache
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit fat_goto_next (void)
{
if (fat_dir_list_index < fat_dir_list_last)
{
fat_dir_list_index++;
fat_fetch_file_info(&fat_cache.current, FETCH_NEXT);
return OK;
}
else
return KO; /* already on last file */
}
/*F**************************************************************************
* NAME: fat_goto_prev
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
* - OK: previous file available
* - KO: first file reached
* - KO: low_level memory error
*----------------------------------------------------------------------------
* PURPOSE:
* Fetch the previous directory info in cache
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit fat_goto_prev (void)
{
Byte min;
if (dir_is_root)
min = 1;
else
min = 3;
if (fat_dir_list_index != min) /* first file of the directory? */
{
fat_dir_list_index--;
fat_fetch_file_info(&fat_cache.current, FETCH_PREV);
return OK;
}
else
return KO; /* already on first file */
}
/*F**************************************************************************
* NAME: fat_seek_last
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
* OK: last file available
* KO: low level error
*----------------------------------------------------------------------------
* PURPOSE:
* Fetch the last directory info in cache
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit fat_seek_last (void)
{
bit result;
do
{
result = fat_goto_next();
}
while (result == OK);
return result;
}
/*F**************************************************************************
* NAME: fat_seek_entry_record
*----------------------------------------------------------------------------
* PARAMS:
* fat_dir_list_index : # of the fetched entry
*
* return:
* OK: file available
* KO: low level error
*----------------------------------------------------------------------------
* PURPOSE:
* Fetch the selected entry
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit fat_seek_entry_record (void)
{
bit result;
Uint16 temp;
temp = fat_dir_list_index - 1;
fat_seek_first();
for (; temp != 0; temp--)
result = fat_goto_next();
return result;
}
/*F**************************************************************************
* NAME: fat_seek_first
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
* - OK: first file found
* - KO: low level error
*----------------------------------------------------------------------------
* PURPOSE:
* Fetch the first directory info in cache
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit fat_seek_first (void)
{
fat_clear_dir_info();
fat_dir_current_sect = fat_dir_start_sect;
fat_current_start_entry_position = 0;
fat_current_end_entry_position = 0;
if (dir_is_root)
{ /* root diretory */
fat_dir_list_index = 1;
fat_fetch_file_info(&fat_cache.current, FETCH_NEXT); /* fetch first root entry */
return OK;
}
else
{ /* not root dir */
fat_fetch_file_info(&fat_cache.parent, FETCH_NEXT); /* dot entry */
fat_fetch_file_info(&fat_cache.parent, FETCH_NEXT); /* dotdot entry */
fat_dir_list_index = 2; /* update entry index */
return fat_goto_next(); /* update first file info */
}
}
/*F**************************************************************************
* NAME: fat_goto_subdir
*----------------------------------------------------------------------------
* PARAMS:
* id: file extension to select
*
* return:
* - OK: subdir selected
* - KO: current entry not a directory
* - KO: low level error
*----------------------------------------------------------------------------
* PURPOSE:
* Go to the subdir if current is a directory
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* Also called by goto_parentdir() with current info from parent info
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit fat_goto_subdir (Byte id)
{
/* check if current file is a directory */
if ((fat_cache.current.attributes & ATTR_DIRECTORY) == ATTR_DIRECTORY)
{
/* computes the sector address (RELATIVE) */
if (fat_cache.current.start_cluster == fat_rootclus_fat32)
{
return fat_get_root_directory(id); /* go to root dir */
}
/* go to not root dir */
fat_get_clusters(&dclusters, MAX_DIR_FRAGMENT_NUMBER); /* get directory allocation table */
fat_last_dclust_index = fat_last_clust_index; /* save last index position for chain cluster */
fat_dir_current_sect = (((Uint32)(dclusters[0].cluster)) * fat_cluster_size) /* computes sector address from allocation table */
+ fat_ptr_data;
fat_get_dir_file_list(id); /* create list of entries */
fat_dir_list_index = 1; /* point on first root entry */
fat_current_start_entry_position = 0;
fat_current_end_entry_position = 0;
fat_fetch_file_info(&fat_cache.current, FETCH_NEXT); /* dot entry */
fat_fetch_file_info(&fat_cache.parent, FETCH_NEXT); /* dotdot entry */
fat_dir_list_index = 2; /* update index position entry */
if(fat_cache.parent.start_cluster == 0x00) /* if parent dir is root */
{
fat_cache.parent.start_cluster = fat_rootclus_fat32; /* then update start cluster value */
}
dir_is_root = FALSE;
return fat_goto_next();
}
else
return KO; /* current entry is not a dir */
}
/*F**************************************************************************
* NAME: fat_goto_parentdir
*----------------------------------------------------------------------------
* PARAMS:
* id: file extension to select
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Go to the parent directory
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -