navigation.c File Reference

FAT 12/16/32 Services. More...

#include <ctype.h>
#include "conf_explorer.h"
#include "navigation.h"
#include "file.h"
#include <LIB_CTRLACCESS>

Include dependency graph for navigation.c:

Go to the source code of this file.

Defines

#define SIZE_OF_SPLIT_COPY   ((1*1024*1024L)/512L)

Functions

void nav_string_unicode (void)
 This function selects the UNICODE mode for all routines with FS_STRING parameter.
void nav_string_ascii (void)
 This function selects the ASCII mode for all routines with FS_STRING parameter.
void nav_string_length_enable (void)
 This function selects the LENGTH string mode for all routines with FS_STRING parameter.
void nav_string_length_disable (void)
 This function deselects the LENGTH string mode for all routines with FS_STRING parameter.
void nav_checkdisk_disable (void)
 This function disables the disk check before each actions on disk.
void nav_checkdisk_enable (void)
 This function enables the disk check before each actions on disk.
void nav_reset (void)
 This function resets ALL navigations to init file system core.
void nav_exit (void)
 This function flush ALL navigations before exit of file system core.
Bool nav_select (U8 u8_idnav)
 This function selects the navigation to use.
U8 nav_get (void)
 This function returns the navigation identifier used.
Bool nav_copy (U8 u8_idnav)
 This function copys the navigator information to another navigator.
U8 nav_drive_nb (void)
 This function returns the number of devices availabled.
Bool nav_drive_set (U8 u8_number)
 This function selects a drive in navigator but don't mount the disk partition.
U8 nav_drive_get (void)
 This function returns the selected drive number.
U8 nav_drive_getname (void)
 This function returns the selected drive letter.
U8 nav_partition_nb (void)
 This function returns the number of partitions present on drive.
Bool nav_partition_set (U8 partition_number)
 This function selects a partition on drive.
Bool nav_partition_mount (void)
 This function mounts the selected partition.
U8 nav_partition_type (void)
 This function gives the partition type.
Bool nav_partition_serialnumber (Bool b_action, U8 _MEM_TYPE_SLOW_ *a_u8_sn)
 This function reads or writes the serial number on the selected partition.
Bool nav_partition_label (Bool b_action, FS_STRING sz_label)
 This function reads or writes the label of selected partition.
U32 nav_partition_space (void)
 This function returns partition total space.
U8 nav_partition_cluster_size (void)
 This function returns the partition cluster size.
U32 nav_partition_freespace (void)
 This function returns the partition free space.
U8 nav_partition_freespace_percent (void)
 This function returns the partition space free in percent.
Bool nav_filelist_single_enable (Bool b_type)
 To display in File List only the files OR directories.
Bool nav_filelist_single_disable (void)
 To display in File List the directories AND files.
Bool nav_filelist_reset (void)
 This function resets the selection pointer, so "no file selected" in file list.
Bool nav_filelist_validpos (void)
 This function checks if a file is selected.
Bool nav_filelist_fileisnotopen (void)
 This function checks if no file is open.
Bool nav_filelist_set (U16 u16_nb, Bool b_direction)
 This function moves the selection pointer in file list.
U16 nav_filelist_get (void)
 This function returns the position of selected file in file list.
Bool nav_filelist_goto (U16 u16_newpos)
 This function goes at a position in file list.
Bool nav_filelist_findname (const FS_STRING sz_name, Bool b_match_case)
 This function searchs a file name in file list.
Bool nav_filelist_eol (void)
 This function checks the end of file list.
Bool nav_filelist_bol (void)
 This function checks the beginning of file list.
Bool nav_filelist_exist (Bool b_type)
 This function checks the presence of files or directories in file list.
U16 nav_filelist_nb (Bool b_type)
 This function computes the number of files or directories in file list.
Bool nav_filelist_first (Bool b_type)
 This function goes to at the first file or directory in file list.
Bool nav_filelist_last (Bool b_type)
 This function goes to at the last file or directory in file list.
Fs_index nav_getindex (void)
 This function returns a small index on the selected file.
Bool nav_gotoindex (const Fs_index _MEM_TYPE_SLOW_ *index)
 This function selects a file in the navigator via a file index.
Bool nav_dir_root (void)
 This function initializes the file list on the root directory.
Bool nav_dir_is_root (void)
 This function check the current directory.
Bool nav_dir_cd (void)
 This function enters in the selected directory in file list.
Bool nav_dir_gotoparent (void)
 This function goes to the parent directory.
Bool nav_dir_name (FS_STRING sz_path, U8 u8_size_max)
 This function returns the directory name corresponding at the file list.
Bool nav_getcwd (FS_STRING sz_path, U8 u8_size_path, Bool b_view_file_select)
 This function returns the full path of the selection.
Bool nav_setcwd (FS_STRING sz_path, Bool b_match_case, Bool b_create)
 This function selects a disk position via a path.
Bool nav_file_getname (FS_STRING sz_name, U8 u8_size_max)
 This function returns the name of selected file.
Bool nav_file_name (FS_STRING sz_name, U8 u8_size_max, Bool b_mode, Bool b_match_case)
 This function returns the name of selected file or checks the string with the name of selected file.
U32 nav_file_lgt (void)
 This function returns the size of selected file (unit byte).
U16 nav_file_lgtsector (void)
 This function returns the size of selected file (unit sector).
Bool nav_file_isreadonly (void)
 This function checks the write protection of disk and the attribut "read only" of selected file.
Bool nav_file_isdir (void)
 This function returns the type of selected file.
Bool nav_file_checkext (const FS_STRING sz_filterext)
 This function checks the extension of selected file.
Bool nav_file_dateget (FS_STRING sz_date, Bool type_date)
 This function returns the date of selected file.
U8 nav_file_attributget (void)
 This function returns the attribut of selected file.


Detailed Description

FAT 12/16/32 Services.

This file defines a useful set of functions for file navigation.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file navigation.c.


Define Documentation

#define SIZE_OF_SPLIT_COPY   ((1*1024*1024L)/512L)

Definition at line 72 of file navigation.c.


Function Documentation

void nav_string_unicode ( void   ) 

This function selects the UNICODE mode for all routines with FS_STRING parameter.

//! If you have enabled the FS_ASCII AND FS_UNICODE define
//! then FS_STRING parameter can be a ASCII or UNICODE string.
//! 

Definition at line 87 of file navigation.c.

00088 {
00089    g_b_unicode = TRUE;
00090 }

void nav_string_ascii ( void   ) 

This function selects the ASCII mode for all routines with FS_STRING parameter.

//! If you have enabled the FS_ASCII AND FS_UNICODE define
//! then FS_STRING parameter can be a ASCII or UNICODE string.
//! 

Definition at line 98 of file navigation.c.

00099 {
00100    g_b_unicode = FALSE;
00101 }

void nav_string_length_enable ( void   ) 

This function selects the LENGTH string mode for all routines with FS_STRING parameter.

//! In LENGTH string mode when you call a routine with FS_STRING parameter
//! only the size (16bits, unit ASCII or UNICODE) is returned in the first 16bits of string array.
//! 

Definition at line 111 of file navigation.c.

00112 {
00113    g_b_string_length = TRUE;
00114 }

void nav_string_length_disable ( void   ) 

This function deselects the LENGTH string mode for all routines with FS_STRING parameter.

//! In LENGTH string mode when you call a routine with FS_STRING parameter
//! only the size (16bits, unit ASCII or UNICODE) is returned in the first 16bits of string array.
//! 

Definition at line 122 of file navigation.c.

00123 {
00124    g_b_string_length = FALSE;
00125 }

void nav_checkdisk_disable ( void   ) 

This function disables the disk check before each actions on disk.

//! By default, between each read/write access a check disk (test unit ready) is sended at device.
//! This check can reduce the speed access on specific disk.
//! 

Definition at line 137 of file navigation.c.

00138 {
00139    g_b_no_check_disk = TRUE;
00140 }

void nav_checkdisk_enable ( void   ) 

This function enables the disk check before each actions on disk.

//! By default, between each read/write access a check disk (test unit ready) is sended at device.
//! This check can reduce the speed access on specific disk.
//! 

Definition at line 149 of file navigation.c.

00150 {
00151    g_b_no_check_disk = FALSE;
00152 }

void nav_reset ( void   ) 

This function resets ALL navigations to init file system core.

//! Call this at the program startup or before a new session (e.g. USB Device exit)
//! 

Definition at line 165 of file navigation.c.

Referenced by ushell_task().

00166 {
00167 #if ( (FS_ASCII   == ENABLED) && (FS_UNICODE == ENABLED))
00168    g_b_unicode = TRUE;
00169 #endif
00170    g_b_string_length = FALSE;
00171    g_b_no_check_disk = FALSE;
00172 
00173    fat_cache_reset();
00174    fat_cache_clusterlist_reset();
00175 
00176 #if (FS_NB_NAVIGATOR > 1)
00177    {
00178    U8 i;
00179    // Reset variables of each navigators
00180    for( i=0 ; i!=FS_NB_NAVIGATOR ; i++ )
00181    {
00182       nav_select(i);
00183       fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_UNM; // By default the fat isn't mounted
00184       fs_g_nav.u8_lun = 0xFF;                      // By default don't select a drive
00185 #if (FS_MULTI_PARTITION  ==  ENABLED)
00186       fs_g_nav.u8_partition=0;                     // By default select the first partition
00187 #endif
00188       Fat_file_close();                            // By default no file is opened
00189       fs_g_nav.b_mode_nav_single = FALSE;          // By default display files and directories
00190    }
00191    // By default select the navigator 0
00192    fs_g_u8_nav_selected = 0;
00193    }
00194 #else
00195    fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_UNM;    // By default the fat isn't mounted
00196    fs_g_nav.u8_lun = 0xFF;                         // By default don't select a drive
00197 #  if (FS_MULTI_PARTITION  ==  ENABLED)
00198    fs_g_nav.u8_partition=0;                        // By default select the first partition
00199 #  endif
00200    Fat_file_close();                               // By default no file is opened
00201 #endif // (FS_NB_NAVIGATOR > 1)
00202 }

Here is the caller graph for this function:

void nav_exit ( void   ) 

This function flush ALL navigations before exit of file system core.

//! Call this at the program exit or before a USB Device session
//! 

Definition at line 211 of file navigation.c.

Referenced by ushell_task().

00212 {
00213    // If you have opened files then close them
00214 #if (FS_NB_NAVIGATOR > 1)
00215    U8 u8_i;
00216    for( u8_i=0; u8_i<FS_NB_NAVIGATOR; u8_i++)
00217    {
00218       nav_select(u8_i);
00219       file_close();
00220    }
00221 #else
00222    nav_select(0);
00223    file_close();
00224 #endif
00225    // Flush data eventually present in FAT cache
00226    fat_cache_flush();
00227 }

Here is the caller graph for this function:

Bool nav_select ( U8  u8_idnav  ) 

This function selects the navigation to use.

Parameters:
u8_idnav navigator identifier to select (0 to FS_NB_NAVIGATOR-1)
Returns:
FALSE if ID navigator don't exist

TRUE otherwise

Definition at line 237 of file navigation.c.

Referenced by copy_dir(), nav_exit(), nav_reset(), ushell_cmd_perform(), ushell_cmd_sync(), and ushell_task().

00238 {
00239    if( FS_NB_NAVIGATOR <= u8_idnav )
00240    {
00241       fs_g_status = FS_ERR_BAD_NAV;             // The navigator doesn't exist
00242       return FALSE;
00243    }
00244 #if (FS_NB_NAVIGATOR > 1)
00245    if( fs_g_u8_nav_selected != u8_idnav )
00246    {
00247       fat_invert_nav( fs_g_u8_nav_selected );   // Deselect previous navigator = Select default navigator
00248       fat_invert_nav( u8_idnav );               // Select new navigator
00249       fs_g_u8_nav_selected = u8_idnav;
00250    }
00251 #endif
00252    return TRUE;
00253 }

Here is the caller graph for this function:

U8 nav_get ( void   ) 

This function returns the navigation identifier used.

Returns:
u8_idnav navigator identifier selected

Definition at line 260 of file navigation.c.

00261 {
00262 #if (FS_NB_NAVIGATOR > 1)
00263    return fs_g_u8_nav_selected;
00264 #else
00265    return 0;
00266 #endif
00267 }

Bool nav_copy ( U8  u8_idnav  ) 

This function copys the navigator information to another navigator.

Parameters:
u8_idnav navigator identifier where the main navigator will be copied
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

//! Use this routine to select quickly the same file in another navigator
//! 

Definition at line 281 of file navigation.c.

00282 {
00283 #if (FS_NB_NAVIGATOR > 1)
00284    if( fs_g_u8_nav_selected == u8_idnav )
00285       return FALSE;                    // It is the source and destination is the same navigator
00286    if( 0 == u8_idnav )
00287       u8_idnav = fs_g_u8_nav_selected; // the default navigator is invert with the current navigator
00288    if( 0 == u8_idnav)
00289       return FALSE;                    // It is the source and destination is the same navigator
00290    fat_copy_nav( u8_idnav );
00291    return TRUE;
00292 #else
00293    u8_idnav++;
00294    return FALSE;                       // Copy impossible because only one navigator is available
00295 #endif
00296 }

U8 nav_drive_nb ( void   ) 

This function returns the number of devices availabled.

Returns:
number of devices, 0 = NO DEVICE AVAILABLED
//! This value may be dynamic because it depends of memory drivers (e.g. Mass Storage disk on USB host mode)
//! 

Definition at line 311 of file navigation.c.

Referenced by ushell_cmd_free_space(), ushell_cmd_mount(), and ushell_cmd_nb_drive().

00312 {
00313    return get_nb_lun(); // Number of devices = Number of lun
00314 }

Here is the caller graph for this function:

Bool nav_drive_set ( U8  u8_number  ) 

This function selects a drive in navigator but don't mount the disk partition.

Parameters:
u8_number device number (0 to nav_drive_nb()-1 )
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 324 of file navigation.c.

Referenced by nav_gotoindex(), nav_setcwd(), ushell_cmd_format(), ushell_cmd_free_space(), ushell_cmd_mount(), and ushell_cmd_perform_alloc().

00325 {
00326    if ( !fat_check_noopen() )
00327       return FALSE;
00328 
00329    if (u8_number >= get_nb_lun() )
00330    {
00331       fs_g_status = FS_ERR_END_OF_DRIVE;   // The drive number is bad
00332       return FALSE;
00333    }
00334 
00335    if ( fs_g_nav.u8_lun == u8_number)
00336       return TRUE;   // It is the same drive number
00337 
00338    // Go to the device
00339    fs_g_nav.u8_lun = u8_number;
00340    fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_UNM;
00341 #if (FS_MULTI_PARTITION  ==  ENABLED)
00342    fs_g_nav.u8_partition=0;   // by default select the first partition
00343 #endif
00344    return TRUE;
00345 }

Here is the caller graph for this function:

U8 nav_drive_get ( void   ) 

This function returns the selected drive number.

Returns:
0 to nav_drive_nb()-1

0xFF in case of no drive selected

Definition at line 353 of file navigation.c.

Referenced by ushell_cmd_ls(), ushell_cmd_perform(), and ushell_cmd_space().

00354 {
00355 #if (FS_MULTI_PARTITION  ==  ENABLED)
00356    if(0xFF == fs_g_nav.u8_lun)
00357       return 0xFF;
00358    return ((fs_g_nav.u8_lun*4) + fs_g_nav.u8_partition); // Maximum 4 partitions per device
00359 #else
00360    return (fs_g_nav.u8_lun);
00361 #endif
00362 }

Here is the caller graph for this function:

U8 nav_drive_getname ( void   ) 

This function returns the selected drive letter.

Returns:
'A','B',...

'X', in case of no drive selected

Definition at line 370 of file navigation.c.

Referenced by nav_dir_name(), and nav_getcwd().

00371 {
00372    if(0xFF == fs_g_nav.u8_lun)
00373       return 'X';
00374 #if (FS_MULTI_PARTITION  ==  ENABLED)
00375    return ('A' + (fs_g_nav.u8_lun*4) + fs_g_nav.u8_partition); // Maximum 4 partitions per device
00376 #else
00377    return ('A' + fs_g_nav.u8_lun);
00378 #endif
00379 }

Here is the caller graph for this function:

U8 nav_partition_nb ( void   ) 

This function returns the number of partitions present on drive.

Returns:
u8_number number of partitions

Definition at line 421 of file navigation.c.

00422 {
00423    return fat_get_nbpartition();
00424 }

Bool nav_partition_set ( U8  partition_number  ) 

This function selects a partition on drive.

Parameters:
partition_number partition number (0 to 3)
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 434 of file navigation.c.

Referenced by nav_gotoindex().

00435 {
00436    if ( fs_g_nav.u8_partition == partition_number)
00437       return TRUE;   // It is the same
00438 
00439    if ( !fat_check_noopen() )
00440       return FALSE;
00441 
00442    // Go to partition
00443    fs_g_nav.u8_partition = partition_number;
00444    fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_UNM;
00445    return TRUE;
00446 }

Here is the caller graph for this function:

Bool nav_partition_mount ( void   ) 

This function mounts the selected partition.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

//! If the FS_MULTI_PARTITION option is disabled
//! then the mount routine selects the first partition supported by file system. <br>
//! After mount, the file list contains files and directories of ROOT directory
//! 

Definition at line 461 of file navigation.c.

Referenced by nav_dir_root(), nav_gotoindex(), nav_partition_type(), nav_setcwd(), ushell_cmd_free_space(), ushell_cmd_mount(), and ushell_cmd_perform_alloc().

00462 {
00463    if ( !fat_check_noopen() )
00464       return FALSE;
00465 
00466    if( FS_TYPE_FAT_UNM != fs_g_nav_fast.u8_type_fat)
00467    {
00468       // Already mounted
00469       // Go to root directory
00470       fs_g_nav.u32_cluster_sel_dir   = 0;
00471       // No file is selected by default
00472       fat_clear_entry_info_and_ptr();
00473       return TRUE;
00474    }
00475 
00476    return fat_mount();
00477 }

Here is the caller graph for this function:

U8 nav_partition_type ( void   ) 

This function gives the partition type.

Returns:
partition type: FS_TYPE_FAT_12, FS_TYPE_FAT_16, FS_TYPE_FAT_32

FS_TYPE_FAT_UNM, in case of error or unknow format

Definition at line 485 of file navigation.c.

Referenced by ushell_cmd_ls().

00486 {
00487    fat_check_device();
00488    if( FS_TYPE_FAT_UNM == fs_g_nav_fast.u8_type_fat)
00489    {
00490       nav_partition_mount();
00491    }
00492    return fs_g_nav_fast.u8_type_fat;
00493 }

Here is the caller graph for this function:

Bool nav_partition_serialnumber ( Bool  b_action,
U8 _MEM_TYPE_SLOW_ *  a_u8_sn 
)

This function reads or writes the serial number on the selected partition.

Parameters:
b_action to select the action
FS_SN_READ to read serial number
FS_SN_WRITE to write serial number
a_u8_sn pointer on an array (4 bytes)
if FS_SN_READ, then the array is used to store the serial number
if FS_SN_WRITE, then the array is used to give the new serial number
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 508 of file navigation.c.

00509 {
00510    if( !fat_check_mount())
00511       return FALSE;
00512 
00513    return fat_serialnumber( b_action , a_u8_sn );
00514 }

Bool nav_partition_label ( Bool  b_action,
FS_STRING  sz_label 
)

This function reads or writes the label of selected partition.

Parameters:
b_action to select the action
FS_LABEL_READ to read label
FS_LABEL_WRITE to write label
sz_label pointer on a ASCII string (11 chars + NULL terminator =12 bytes)
if FS_LABEL_READ, then the string is used to store label
if FS_LABEL_WRITE, then the string is used to give the new label
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 529 of file navigation.c.

00530 {
00531    _MEM_TYPE_SLOW_   Fs_index index;
00532    Bool status = TRUE;
00533 
00534    index = nav_getindex();    // Save current position
00535 
00536    // Go to root dir
00537    if( nav_dir_root())
00538    {
00539       // Find field label
00540       fs_g_nav_fast.u16_entry_pos_sel_file = 0; // Go to first entry
00541       while( 1 )
00542       {
00543          if ( !fat_read_dir())
00544          {
00545             status = FALSE;
00546             break;               // error
00547          }
00548          if( fat_entry_label( FS_LABEL_READ , NULL ) )
00549             break;
00550          if( FS_ERR_ENTRY_EMPTY == fs_g_status )
00551             break;
00552          fs_g_nav_fast.u16_entry_pos_sel_file++;
00553       }
00554       if( TRUE == status )
00555       {
00556          // Find OK
00557          if( FS_LABEL_READ == b_action )
00558          {
00559             // Read field label
00560             if( !fat_entry_label( FS_LABEL_READ , sz_label ) )
00561                sz_label[0]=0;    // empty name
00562          }else{
00563             // Change field label
00564             status = fat_entry_label( FS_LABEL_WRITE , sz_label );
00565          }
00566       }
00567    }
00568    nav_gotoindex( &index );   // Restore the position
00569    return status;
00570 }

U32 nav_partition_space ( void   ) 

This function returns partition total space.

Returns:
number of sectors

0, in case of error

//! You shall mounted the partition before call this routine
//! 

Definition at line 582 of file navigation.c.

Referenced by ushell_cmd_free_space(), and ushell_cmd_space().

00583 {
00584    fat_check_device();
00585    if (FS_TYPE_FAT_UNM == fs_g_nav_fast.u8_type_fat)
00586       return 0;
00587    return (fs_g_nav.u32_CountofCluster * fs_g_nav.u8_BPB_SecPerClus);
00588 }

Here is the caller graph for this function:

U8 nav_partition_cluster_size ( void   ) 

This function returns the partition cluster size.

Returns:
cluster size (unit sector)

Definition at line 595 of file navigation.c.

00596 {
00597    return fs_g_nav.u8_BPB_SecPerClus;
00598 }

U32 nav_partition_freespace ( void   ) 

This function returns the partition free space.

Returns:
number of free sectors

0 in case of error or full partition

//! You shall mounted the partition before call this routine
//! 

Definition at line 609 of file navigation.c.

Referenced by ushell_cmd_free_space().

00610 {
00611    fat_check_device();
00612    if (FS_TYPE_FAT_UNM == fs_g_nav_fast.u8_type_fat)
00613       return 0;
00614    return fat_getfreespace();
00615 }

Here is the caller graph for this function:

U8 nav_partition_freespace_percent ( void   ) 

This function returns the partition space free in percent.

Returns:
percent of free space (0% to 100%)

0% in case of error or full partition

//! To speed up the compute, the resultat have an error delta of 1%
//! 

Definition at line 627 of file navigation.c.

Referenced by ushell_cmd_free_space().

00628 {
00629    fat_check_device();
00630    if (FS_TYPE_FAT_UNM == fs_g_nav_fast.u8_type_fat)
00631       return 0;
00632    return fat_getfreespace_percent();
00633 }

Here is the caller graph for this function:

Bool nav_filelist_single_enable ( Bool  b_type  ) 

To display in File List only the files OR directories.

Parameters:
b_type FS_DIR to display only directories presence
FS_FILE to dispaly only files presence
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 648 of file navigation.c.

00649 {
00650    if ( !nav_filelist_reset())
00651       return FALSE;
00652 
00653    fs_g_nav.b_mode_nav_single = TRUE;
00654    fs_g_nav.b_mode_nav        = b_type;
00655    return TRUE;
00656 }

Bool nav_filelist_single_disable ( void   ) 

To display in File List the directories AND files.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 664 of file navigation.c.

00665 {
00666    fs_g_nav.b_mode_nav_single = FALSE;
00667    return nav_filelist_reset();
00668 }

Bool nav_filelist_reset ( void   ) 

This function resets the selection pointer, so "no file selected" in file list.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 676 of file navigation.c.

Referenced by copy_dir(), nav_dir_cd(), nav_dir_gotoparent(), nav_filelist_exist(), nav_filelist_first(), nav_filelist_goto(), nav_filelist_nb(), nav_filelist_single_disable(), nav_filelist_single_enable(), nav_gotoindex(), nav_setcwd(), ushell_cmd_ls(), and ushell_cmd_sync().

00677 {
00678    if ( !fat_check_mount_noopen())
00679       return FALSE;
00680 
00681    // No file selected and reset navigation
00682    fat_clear_entry_info_and_ptr();
00683    return TRUE;
00684 }

Here is the caller graph for this function:

Bool nav_filelist_validpos ( void   ) 

This function checks if a file is selected.

Returns:
TRUE if a file is selected

FALSE if no file is selected

Definition at line 692 of file navigation.c.

00693 {
00694    return fat_check_mount_select_noopen();
00695 }

Bool nav_filelist_fileisnotopen ( void   ) 

This function checks if no file is open.

Returns:
TRUE if no file is open

FALSE if a file is open

Definition at line 703 of file navigation.c.

00704 {
00705    return fat_check_noopen();
00706 }

Bool nav_filelist_set ( U16  u16_nb,
Bool  b_direction 
)

This function moves the selection pointer in file list.

Parameters:
u16_nb numbers of file to jump before stopping action
0, stop at the first file found
1, stop at the second file found
b_direction search direction
FS_FIND_NEXT, move to next file or directory FS_FIND_PREV, move to previous file or directory
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

//! Note: if no file is selected then nav_filelist_set( 0 , FS_NEXT ) goes to the first entry of the file list.
//! 

Definition at line 726 of file navigation.c.

Referenced by copy_dir(), nav_dir_gotoparent(), nav_filelist_bol(), nav_filelist_eol(), nav_filelist_exist(), nav_filelist_findname(), nav_filelist_first(), nav_filelist_goto(), nav_filelist_last(), nav_filelist_nb(), nav_gotoindex(), ushell_cmd_ls(), and ushell_cmd_sync().

00727 {
00728    U16   u16_ptr_save_entry;
00729    U16   u16_save_pos_sel_file;
00730    Bool  b_save_entry_type;
00731    Bool  b_find_last_entry = FALSE;
00732 
00733    if ( !fat_check_mount_noopen())
00734       return FALSE;
00735 
00736    // Save the current selection
00737    u16_ptr_save_entry      = fs_g_nav_fast.u16_entry_pos_sel_file;
00738    u16_save_pos_sel_file   = fs_g_nav.u16_pos_sel_file;
00739    b_save_entry_type       = fs_g_nav.b_mode_nav;
00740 
00741    // Loop in directory
00742    while( 1 )
00743    {
00744       if(( FS_FIND_NEXT == b_direction )
00745       || ( b_find_last_entry ) )
00746       {
00747          if ( FS_END_FIND == fs_g_nav_fast.u16_entry_pos_sel_file )
00748          {
00749             // Too many files in directory (case impossible)
00750             fs_g_status = FS_ERR_FS;
00751             break;
00752          }
00753          fs_g_nav_fast.u16_entry_pos_sel_file++;      // Update entry position
00754       }
00755       else
00756       {
00757          if ( FS_NO_SEL == fs_g_nav_fast.u16_entry_pos_sel_file )
00758          {
00759             // No selected file then previous action impossible
00760             fs_g_status = FS_ERR_NO_FIND;
00761             break;
00762          }
00763          if ( 0 == fs_g_nav_fast.u16_entry_pos_sel_file )
00764          {
00765             // beginning of directory
00766             if ( (FS_DIR == fs_g_nav.b_mode_nav ) || fs_g_nav.b_mode_nav_single )
00767             {
00768                // End of directory scan, then no previous action possible
00769                fs_g_status = FS_ERR_NO_FIND;
00770                break;
00771             }
00772             // End of file scan, then find last directory
00773             b_find_last_entry = TRUE;
00774          }else{
00775             fs_g_nav_fast.u16_entry_pos_sel_file--;   // Update entry position
00776          }
00777       }
00778 
00779       if( !fat_read_dir())
00780       {
00781          if( FS_ERR_OUT_LIST != fs_g_status )
00782             break; // Error
00783       }else{
00784          if ( fat_entry_check( fs_g_nav.b_mode_nav ) )
00785          {
00786            // HERE, the file entry match with the type seached
00787 
00788            if( b_find_last_entry )
00789              continue;  // The search of last directory is on going then continue the search
00790 
00791            // Update position in directory
00792            if ( FS_FIND_NEXT == b_direction )
00793               fs_g_nav.u16_pos_sel_file++;
00794            else
00795               fs_g_nav.u16_pos_sel_file--;
00796 
00797            if (0 == u16_nb)
00798            {
00799               // It is the end of move then update file information
00800               fat_get_entry_info();
00801               return TRUE;         // NB FILE FIND
00802            }
00803            u16_nb--;
00804            continue;
00805          }
00806       }
00807 
00808       // Here error, check type of error
00809       if(( FS_ERR_ENTRY_EMPTY == fs_g_status )
00810       || ( FS_ERR_OUT_LIST    == fs_g_status ) )
00811       {
00812          // Here, end of the directory
00813          if( b_find_last_entry )
00814          {
00815             // Re enable the previous command at the end of directory to find the last directory entry
00816             b_find_last_entry = FALSE;
00817             fs_g_nav.b_mode_nav = FS_DIR;
00818             continue;
00819          }
00820          // Here, a next action is on going
00821          if ( (FS_FILE == fs_g_nav.b_mode_nav) || fs_g_nav.b_mode_nav_single )
00822          {
00823             // End of next file action then end of next action
00824             fs_g_status = FS_ERR_NO_FIND; // No file found
00825             break;                        // end of search
00826          }else{
00827             // End of next dir action then starts the next file action at the beginning of directory
00828             fs_g_nav_fast.u16_entry_pos_sel_file = 0xFFFF;
00829             fs_g_nav.b_mode_nav = FS_FILE;
00830          }
00831       }
00832    }  // end of loop while(1)
00833 
00834    fs_g_nav.b_mode_nav                    = b_save_entry_type;
00835    fs_g_nav_fast.u16_entry_pos_sel_file   = u16_ptr_save_entry;
00836    fs_g_nav.u16_pos_sel_file              = u16_save_pos_sel_file;
00837    return FALSE;
00838 }

Here is the caller graph for this function:

U16 nav_filelist_get ( void   ) 

This function returns the position of selected file in file list.

Returns:
position of selected file (0 is the first position)

FS_NO_SEL, in case of no file selected

Definition at line 846 of file navigation.c.

Referenced by nav_filelist_goto().

00847 {
00848    return fs_g_nav.u16_pos_sel_file;
00849 }

Here is the caller graph for this function:

Bool nav_filelist_goto ( U16  u16_newpos  ) 

This function goes at a position in file list.

Parameters:
u16_newpos new position to select (0 is the first position)
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 859 of file navigation.c.

00860 {
00861    U16 u16_current_pos;
00862 
00863    if( FS_NO_SEL == u16_newpos )
00864       return nav_filelist_reset();
00865 
00866    u16_current_pos = nav_filelist_get();
00867    if( u16_newpos < (u16_current_pos/2) )
00868    {
00869       // Restart at the beginning of list to accelerate the search
00870       if( !nav_filelist_reset() )
00871          return FALSE;
00872       u16_current_pos = FS_NO_SEL;
00873    }
00874    if (FS_NO_SEL == u16_current_pos)
00875    {
00876       return nav_filelist_set( u16_newpos, FS_FIND_NEXT );
00877    }
00878    else
00879    {
00880       if (u16_newpos < u16_current_pos)
00881       {
00882          return nav_filelist_set( u16_current_pos -u16_newpos -1 , FS_FIND_PREV );
00883       }
00884       if (u16_newpos > u16_current_pos)
00885       {
00886          return nav_filelist_set( u16_newpos -u16_current_pos - 1 , FS_FIND_NEXT );
00887       }
00888    }
00889    return TRUE;
00890 }

Bool nav_filelist_findname ( const FS_STRING  sz_name,
Bool  b_match_case 
)

This function searchs a file name in file list.

Parameters:
sz_name name to search (UNICODE or ASCII)
It must be terminate by NULL or '*' value
b_match_case FALSE to ignore the case
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

//! This function starts a search at the next position of the current in file list
//! 

Definition at line 906 of file navigation.c.

Referenced by nav_setcwd().

00907 {
00908    while( 1 )
00909    {
00910       if ( !nav_filelist_set( 0, FS_FIND_NEXT ))
00911          return FALSE;
00912       if ( nav_file_name( sz_name , 0 , FS_NAME_CHECK , b_match_case ))
00913          return TRUE;
00914    }
00915 }

Here is the caller graph for this function:

Bool nav_filelist_eol ( void   ) 

This function checks the end of file list.

Returns:
FALSE, NO end of file list

TRUE, in case of end of list or error

Definition at line 923 of file navigation.c.

00924 {
00925    if( FALSE == nav_filelist_set( 0 , FS_FIND_NEXT ) )
00926       return TRUE;   // End of list or error (remark: the position haven't changed)
00927 
00928    if( 0 != fs_g_nav.u16_pos_sel_file )
00929    {
00930       // Go to previous position
00931       nav_filelist_set( 0 , FS_FIND_PREV );
00932    }else{
00933       // No select file before, then reset position
00934       fs_g_nav_fast.u16_entry_pos_sel_file= FS_NO_SEL;
00935       fs_g_nav.u16_pos_sel_file           = FS_NO_SEL;
00936       fs_g_nav.b_mode_nav                 = FS_DIR;
00937    }
00938    return FALSE;
00939 }

Bool nav_filelist_bol ( void   ) 

This function checks the beginning of file list.

Returns:
FALSE, it is not the beginning of file list

TRUE, in case of the file selected is the first file, or in case of error

Definition at line 947 of file navigation.c.

00948 {
00949    if( FALSE == nav_filelist_set( 0 , FS_FIND_PREV ) )
00950       return TRUE;   // End of list or error (remark: the position haven't changed)
00951    // Go to previous position
00952    nav_filelist_set( 0 , FS_FIND_NEXT );
00953    return FALSE;
00954 }

Bool nav_filelist_exist ( Bool  b_type  ) 

This function checks the presence of files or directories in file list.

Parameters:
b_type FS_DIR to check the directory presence
FS_FILE to check the file presence
Returns:
TRUE, in case of a file or a directory exists

FALSE, in case of no file or no directory exists, or error

Definition at line 965 of file navigation.c.

00966 {
00967    Bool status;
00968    U16   u16_save_position;
00969 
00970    // Save current position
00971    u16_save_position = fs_g_nav.u16_pos_sel_file;
00972    // Go to first file or directory
00973    status = nav_filelist_first( b_type );
00974    // Restore previous position
00975    nav_filelist_reset();
00976    if ( u16_save_position != FS_NO_SEL )
00977    {
00978       nav_filelist_set( u16_save_position , FS_FIND_NEXT );
00979    }
00980    return status;
00981 }

U16 nav_filelist_nb ( Bool  b_type  ) 

This function computes the number of files or directories in file list.

Parameters:
b_type FS_DIR to compute the number of directories
FS_FILE to compute the number of files
Returns:
number of files or directories in file list

Definition at line 991 of file navigation.c.

Referenced by nav_filelist_last().

00992 {
00993    U16   u16_save_position;
00994    U16   u16_save_number_dir;
00995    U16   u16_save_number_file;
00996 
00997    // Save current position
00998    u16_save_position = fs_g_nav.u16_pos_sel_file;
00999    // Reset position
01000    if ( !nav_filelist_reset())
01001       return 0;
01002    // Scan all directory
01003    u16_save_number_dir  = 0;
01004    u16_save_number_file = 0;
01005    while( nav_filelist_set( 0 , FS_FIND_NEXT ) )
01006    {
01007       if( FS_FILE == fs_g_nav.b_mode_nav )
01008          u16_save_number_file++;    // It is a file
01009       else
01010          u16_save_number_dir++;     // It is a directory
01011    }
01012    // Restore previous position
01013    nav_filelist_reset();
01014    if ( u16_save_position != FS_NO_SEL )
01015    {
01016       nav_filelist_set( u16_save_position , FS_FIND_NEXT );
01017    }
01018    // Return the value asked
01019    if( FS_FILE == b_type )
01020       return u16_save_number_file;
01021    else
01022       return u16_save_number_dir;
01023 }

Here is the caller graph for this function:

Bool nav_filelist_first ( Bool  b_type  ) 

This function goes to at the first file or directory in file list.

Parameters:
b_type FS_DIR to go at the first directory
FS_FILE to go at the first file
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 1034 of file navigation.c.

Referenced by nav_filelist_exist(), and nav_filelist_last().

01035 {
01036    // Reset position
01037    if ( !nav_filelist_reset())
01038       return FALSE;
01039    // Find the first file or directory
01040    while( nav_filelist_set( 0 , FS_FIND_NEXT ) )
01041    {
01042       if( b_type == fs_g_nav.b_mode_nav )
01043          return TRUE;   // First file or directory found
01044    }
01045    fs_g_status = FS_ERR_NO_FIND;
01046    return FALSE;
01047 }

Here is the caller graph for this function:

Bool nav_filelist_last ( Bool  b_type  ) 

This function goes to at the last file or directory in file list.

Parameters:
b_type FS_DIR to go at the last directory
FS_FILE to go at the last file
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 1058 of file navigation.c.

01059 {
01060    U16 u16_nb;
01061 
01062    // Get number of file or directory
01063    u16_nb = nav_filelist_nb( b_type  );
01064    if( 0 == u16_nb )
01065    {
01066       fs_g_status = FS_ERR_NO_FIND;
01067       return FALSE;  // NO FILE FOUND
01068    }
01069    // Go to the first file or directory
01070    if ( !nav_filelist_first( b_type ))
01071       return FALSE;
01072    // If there are more one file or directory, then go to at the last of list
01073    if( 1 == u16_nb )
01074       return TRUE;
01075    u16_nb -= 2;
01076    return nav_filelist_set( u16_nb , FS_FIND_NEXT );
01077 }

Fs_index nav_getindex ( void   ) 

This function returns a small index on the selected file.

Returns:
It is a small index structure with information on selected file (disk, partition, dir, file/dir selected)
//! This routine is interresting to save a file position in small variable.
//! This pointer allow to reinit a navigator quickly with nav_gotoindex() routine.
//! 

Definition at line 1093 of file navigation.c.

Referenced by copy_dir(), nav_getcwd(), nav_partition_label(), nav_setcwd(), ushell_cmd_copy(), ushell_cmd_free_space(), ushell_cmd_mount(), ushell_cmd_perform(), ushell_cmd_rm(), ushell_cmd_sync(), and ushell_task().

01094 {
01095    Fs_index index;
01096 
01097    // Fill index structure
01098    index.u8_lun                  = fs_g_nav.u8_lun;
01099 #if (FS_MULTI_PARTITION  ==  ENABLED)
01100    index.u8_partition            = fs_g_nav.u8_partition;
01101 #endif
01102    index.u32_cluster_sel_dir     = fs_g_nav.u32_cluster_sel_dir;
01103    index.u16_entry_pos_sel_file  = fs_g_nav_fast.u16_entry_pos_sel_file;
01104    return index;
01105 }

Here is the caller graph for this function:

Bool nav_gotoindex ( const Fs_index _MEM_TYPE_SLOW_ *  index  ) 

This function selects a file in the navigator via a file index.

Parameters:
index structure with information about file to select (disk, partition, dir, file/dir selected )
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

//! This routine allow to reinit a navigator quickly via a file index (disk, partition, dir, file/dir selected )
//! To get a file index, you shall used the routine nav_getindex().
//! 

Definition at line 1120 of file navigation.c.

Referenced by copy_dir(), nav_getcwd(), nav_partition_label(), nav_setcwd(), ushell_cmd_copy(), ushell_cmd_free_space(), ushell_cmd_mount(), ushell_cmd_perform(), ushell_cmd_rm(), ushell_cmd_sync(), and ushell_task().

01121 {
01122    // Select the drive and partition corresponding at file index
01123    if( !nav_drive_set( index->u8_lun ))
01124       return FALSE;
01125 #if (FS_MULTI_PARTITION  ==  ENABLED)
01126    if( !nav_partition_set(index->u8_partition))
01127       return FALSE;
01128 #endif
01129    if( !nav_partition_mount())
01130       return FALSE;
01131 
01132    // Select the directory corresponding at file index
01133    fs_g_nav.u32_cluster_sel_dir   = index->u32_cluster_sel_dir;
01134 
01135    // Search the file position corresponding at file index
01136    if ( !nav_filelist_reset())
01137       return FALSE;
01138    while( fs_g_nav_fast.u16_entry_pos_sel_file != index->u16_entry_pos_sel_file )
01139    {
01140       if( !nav_filelist_set( 0 , FS_FIND_NEXT ) )
01141       {
01142          nav_filelist_reset();
01143          return FALSE;
01144       }
01145    }
01146    return TRUE;
01147 }

Here is the caller graph for this function:

Bool nav_dir_root ( void   ) 

This function initializes the file list on the root directory.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 1159 of file navigation.c.

Referenced by nav_partition_label(), and nav_setcwd().

01160 {
01161    return nav_partition_mount();
01162 }

Here is the caller graph for this function:

Bool nav_dir_is_root ( void   ) 

This function check the current directory.

Returns:
FALSE the current directory selected is not the root directory

TRUE the current directory selected is the root directory

Definition at line 1170 of file navigation.c.

01171 {
01172    if (!fat_check_mount_noopen())
01173       return FALSE;
01174 
01175    return (0 == fs_g_nav.u32_cluster_sel_dir);
01176 }

Bool nav_dir_cd ( void   ) 

This function enters in the selected directory in file list.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

//! After this routine the file list changes and contains the files and directories of the new directory.
//! By default no file is selected.
//! 

Definition at line 1189 of file navigation.c.

Referenced by copy_dir(), nav_setcwd(), and ushell_cmd_sync().

01190 {
01191    if ( !fat_check_mount_select_noopen())
01192       return FALSE;
01193 
01194    // The current selection, is it a directory ?
01195    if ( !fat_entry_is_dir())
01196       return FALSE;
01197 
01198    // Select the current directory
01199    fs_g_nav.u16_entry_pos_sel_dir = fs_g_nav_fast.u16_entry_pos_sel_file;
01200    fs_g_nav.u32_cluster_sel_dir = fs_g_nav_entry.u32_cluster;
01201 
01202    // Reset file list
01203    if( FALSE == nav_filelist_reset())
01204       return FALSE;
01205    return TRUE;
01206 }

Here is the caller graph for this function:

Bool nav_dir_gotoparent ( void   ) 

This function goes to the parent directory.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

//! After, the file list changes and contains the files and directories of the new directory.
//! By default, the file selected in file list is the previous (children) directory.
//! 

Definition at line 1219 of file navigation.c.

Referenced by copy_dir(), nav_dir_name(), nav_getcwd(), nav_setcwd(), ushell_cmd_gotoparent(), and ushell_cmd_sync().

01220 {
01221    U32 u32_cluster_old_dir;
01222 
01223    if (!fat_check_mount_noopen())
01224       return FALSE;
01225 
01226    if (0 == fs_g_nav.u32_cluster_sel_dir)
01227    {
01228       fs_g_status = FS_ERR_IS_ROOT;        // There aren't parent
01229       return FALSE;
01230    }
01231 
01232    // Select and read information about directory ".."
01233    fs_g_nav_fast.u16_entry_pos_sel_file = 1;
01234    if ( !fat_read_dir())
01235       return FALSE;
01236    fat_get_entry_info();
01237    // Save the children directory cluster
01238    u32_cluster_old_dir = fs_g_nav.u32_cluster_sel_dir;
01239 
01240    // Select the parent directory via information present in the current directory ".."
01241    fs_g_nav.u32_cluster_sel_dir = fs_g_nav_entry.u32_cluster;
01242 
01243    // Select the children directory in new directory (=parent directory)
01244    if( FALSE == nav_filelist_reset())
01245       return FALSE;
01246    if( fs_g_nav.b_mode_nav_single && (FS_DIR != fs_g_nav.b_mode_nav) )
01247       return TRUE;
01248    
01249    while( nav_filelist_set( 0 , FS_FIND_NEXT ) )
01250    {
01251       if (fs_g_nav_entry.u32_cluster == u32_cluster_old_dir)
01252          return TRUE;         // It is the children directory
01253    }
01254    fs_g_status = FS_ERR_FS;
01255    return FALSE;
01256 }

Here is the caller graph for this function:

Bool nav_dir_name ( FS_STRING  sz_path,
U8  u8_size_max 
)

This function returns the directory name corresponding at the file list.

Parameters:
sz_path string to store the name (ASCII or UNICODE )
u8_size_max string size (unit ASCII or UNICODE )
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 1267 of file navigation.c.

Referenced by ushell_cmd_ls().

01268 {
01269    U8 u8_i, u8_character;
01270    Bool status = FALSE;
01271    U16 save_u16_entry_pos_sel_file;
01272    U32 save_u32_cluster_sel_dir;
01273    U8  save_u8_attr          ;
01274    U32 save_u32_cluster      ;
01275    U32 save_u32_size         ;
01276    Bool b_mode_nav_single_save;
01277    Bool b_mode_nav_mode_save;
01278 
01279    if ( !fat_check_mount_noopen())
01280       return FALSE;
01281 
01282    if (0 != fs_g_nav.u32_cluster_sel_dir)
01283    {
01284       // Save context
01285       save_u16_entry_pos_sel_file= fs_g_nav_fast.u16_entry_pos_sel_file;
01286       save_u32_cluster_sel_dir   = fs_g_nav.u32_cluster_sel_dir        ;
01287       save_u8_attr               = fs_g_nav_entry.u8_attr              ;
01288       save_u32_cluster           = fs_g_nav_entry.u32_cluster          ;
01289       save_u32_size              = fs_g_nav_entry.u32_size             ;
01290       b_mode_nav_single_save = fs_g_nav.b_mode_nav_single;
01291       b_mode_nav_mode_save   = fs_g_nav.b_mode_nav;
01292       fs_g_nav.b_mode_nav_single = TRUE;
01293       fs_g_nav.b_mode_nav = FS_FILE;
01294       // Go to parent directory and select the children directory
01295       if( !nav_dir_gotoparent() )
01296       {
01297          fs_g_nav.b_mode_nav_single = b_mode_nav_single_save;
01298          fs_g_nav.b_mode_nav = b_mode_nav_mode_save;
01299          return FALSE;
01300       }
01301       fs_g_nav.b_mode_nav_single = b_mode_nav_single_save ;
01302       fs_g_nav.b_mode_nav = b_mode_nav_mode_save;
01303       // Go to directory name position
01304       fs_g_nav_fast.u16_entry_pos_sel_file = fs_g_nav.u16_entry_pos_sel_dir;
01305       status = nav_file_name( sz_path  , u8_size_max , FS_NAME_GET , FALSE  );
01306       // Restore previous context
01307       fs_g_nav_fast.u16_entry_pos_sel_file= save_u16_entry_pos_sel_file;
01308       fs_g_nav.u32_cluster_sel_dir        = save_u32_cluster_sel_dir   ;
01309       fs_g_nav_entry.u8_attr              = save_u8_attr               ;
01310       fs_g_nav_entry.u32_cluster          = save_u32_cluster           ;
01311       fs_g_nav_entry.u32_size             = save_u32_size              ;
01312    }
01313    else
01314    {
01315       // No parent directory, then it is the root directory
01316       if( g_b_string_length )
01317       {
01318          ((FS_STR_UNICODE)sz_path )[0] = 3;  // 3 chars for path "x:"
01319          status = TRUE;
01320       }else
01321 
01322       // Create a device name
01323       for( u8_i = 0 ; u8_i<3 ; u8_i++ )
01324       {
01325          switch( u8_i )
01326          {
01327             case 0:
01328             u8_character = nav_drive_getname();    // Letter
01329             break;
01330             case 1:
01331             u8_character = ':';                     // ":"
01332             break;
01333             case 2:
01334             default:
01335             u8_character = 0;                       // end of string
01336             break;
01337          }
01338          if( Is_unicode )
01339          {
01340             ((FS_STR_UNICODE)sz_path )[0] = u8_character;
01341          }else{
01342             sz_path [0] = u8_character;
01343          }
01344          sz_path  += (Is_unicode? 2 : 1 );
01345       }
01346       status = TRUE;
01347 
01348    }
01349    return status;
01350 }

Here is the caller graph for this function:

Bool nav_getcwd ( FS_STRING  sz_path,
U8  u8_size_path,
Bool  b_view_file_select 
)

This function returns the full path of the selection.

Parameters:
sz_path string to store the path (ASCII or UNICODE )
u8_size_path string size (unit ASCII or UNICODE )
b_view_file_select TRUE, to include in path the selected file name
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 1411 of file navigation.c.

01412 {
01413    _MEM_TYPE_SLOW_   Fs_index index;
01414    _MEM_TYPE_SLOW_   U16 u16_lgt=0;    // Only used if LENGTH string mode enabled
01415    U8 u8_save_size_path=0, u8_i;
01416    Bool status = FALSE;                // Error by default
01417 
01418    if ( !fat_check_mount_noopen())
01419       return FALSE;
01420 
01421    index = nav_getindex();             // Save current position
01422 
01423    if( g_b_string_length )
01424    {
01425       u16_lgt = 1;   // 1 for NULL terminate
01426    }
01427    else
01428    {
01429       u8_save_size_path = u8_size_path;
01430       // Set NULL terminator at the end of path
01431       u8_size_path--;
01432       if( Is_unicode )
01433       {
01434          ((FS_STR_UNICODE)sz_path )[u8_size_path] = 0;
01435       }else{
01436          sz_path [u8_size_path]   = 0;
01437       }
01438    }
01439 
01440    // For each directory of path
01441    while( 1 )
01442    {
01443       if( b_view_file_select )
01444       {
01445          // Write the selected file or directory in path
01446          b_view_file_select = FALSE;
01447          if( !fat_check_select() )
01448             continue;   // No selected file or directory, then restart loop to go at the first directory of path
01449       }
01450       else
01451       {
01452          // Go to parent directory and selects the children directory
01453          if( !nav_dir_gotoparent() )
01454             break;
01455       }
01456 
01457       // Read name of selected file or directory
01458       if( !nav_file_name( sz_path  , u8_size_path , FS_NAME_GET, FALSE  ))
01459          break;
01460 
01461       if( g_b_string_length )
01462       {
01463          // Update total length
01464          u16_lgt += ((FS_STR_UNICODE)sz_path )[0]; // 0 = -1 to remove NULL terminated and +1 for '\\'
01465          continue;
01466       }
01467 
01468       // Compute the size of name
01469       u8_i = 0;
01470       while( 1 )
01471       {
01472          if( Is_unicode )
01473          {
01474             if( 0 == ((FS_STR_UNICODE)sz_path )[u8_i])
01475                break;
01476          }else{
01477             if( 0 == sz_path [u8_i])
01478                break;
01479          }
01480          u8_i++;
01481       }
01482 
01483       // Check the string size
01484       if( (u8_i+1) == u8_size_path )
01485       {
01486          fs_g_status = FS_ERR_BUFFER_FULL;   // The path string is full
01487          break;
01488       }
01489 
01490       // Move the name at the end of path
01491       while( 0 != u8_i )
01492       {
01493          u8_i--;
01494          u8_size_path--;
01495          if( Is_unicode )
01496          {
01497             ((FS_STR_UNICODE)sz_path )[u8_size_path] = ((FS_STR_UNICODE)sz_path )[u8_i];
01498          }else{
01499             sz_path [u8_size_path]   = sz_path [u8_i];
01500          }
01501       }
01502       // Set '\' char before the name
01503       u8_size_path--;
01504       if( Is_unicode )
01505       {
01506          ((FS_STR_UNICODE)sz_path )[u8_size_path] = '\\';
01507       }else{
01508          sz_path [u8_size_path]   = '\\';
01509       }
01510    }
01511 
01512    if ( FS_ERR_IS_ROOT == fs_g_status )
01513    {
01514       if( g_b_string_length )
01515       {
01516          // Update and write total length
01517          ((FS_STR_UNICODE)sz_path )[0] = u16_lgt +2 ; //+2 for "x:"
01518          status = TRUE;
01519       }
01520       else
01521       {
01522          // End of path then add device name
01523          if( 2 > u8_size_path )
01524          {
01525             fs_g_status = FS_ERR_BUFFER_FULL;   // The path string is full
01526          }
01527          else
01528          {
01529             // Create a device name
01530             if( Is_unicode )
01531             {
01532                ((FS_STR_UNICODE)sz_path )[0] = nav_drive_getname();    // Letter
01533                ((FS_STR_UNICODE)sz_path )[1] = ':';                   // ":"
01534             }else{
01535                sz_path [0] = nav_drive_getname();    // Letter
01536                sz_path [1] = ':';                      // ":"
01537             }
01538 
01539             // The path is stored at the end, then move the path at the beginning
01540             u8_i = 2;
01541             while( u8_save_size_path != u8_size_path )
01542             {
01543                if( Is_unicode )
01544                {
01545                   ((FS_STR_UNICODE)sz_path )[u8_i] = ((FS_STR_UNICODE)sz_path )[u8_size_path];
01546                }else{
01547                   sz_path [u8_i] = sz_path [u8_size_path];
01548                }
01549                u8_i++;
01550                u8_size_path++;
01551             }
01552             status = TRUE;
01553          }
01554       }
01555    } // else Error system
01556 
01557    nav_gotoindex( &index );   // Restore the position
01558    return status;
01559 }

Bool nav_setcwd ( FS_STRING  sz_path,
Bool  b_match_case,
Bool  b_create 
)

This function selects a disk position via a path.

Parameters:
sz_path path string (ASCII or UNICODE )
b_match_case FALSE to ignore the case
b_create TRUE, if path no exists then create it
FALSE, no create path
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

//! The syntact "./../../file_name" is supported.
//! With syntact "./dir_parent/directory_name"  the file list corresponding at "dir_parent" and "directory_name" is selected.
//! With syntact "./dir_parent/directory_name/" the file list corresponding at "directory_name" and no file is selected.
//! 

Definition at line 1578 of file navigation.c.

Referenced by goto_code_name(), ushell_cmd_append_file(), ushell_cmd_cat(), ushell_cmd_cd(), ushell_cmd_copy(), ushell_cmd_rename(), ushell_cmd_rm(), ushell_cmd_sync(), and ushell_cmddfu_load().

01579 {
01580    _MEM_TYPE_SLOW_   Fs_index index;
01581 #if (FSFEATURE_WRITE == (FS_LEVEL_FEATURES & FSFEATURE_WRITE)) ||              \
01582     (FSFEATURE_WRITE_COMPLET == (FS_LEVEL_FEATURES & FSFEATURE_WRITE_COMPLET))
01583    FS_STRING sz_save_path = 0;
01584 #endif
01585    Bool b_create_name = FALSE;
01586 
01587    if ( !fat_check_noopen())
01588       return FALSE;
01589 
01590    index = nav_getindex();             // Save current position
01591 
01592    // Check syntact "\path..."
01593    if( (( Is_unicode) && (('\\'  == ((FS_STR_UNICODE)sz_path )[0]) || ('/'  == ((FS_STR_UNICODE)sz_path )[0])) )
01594    ||  ((!Is_unicode) && (('\\'  == sz_path [0]) || ('/'  == sz_path [0])) ) )
01595    {
01596       // Go to the root of current drive
01597       if( !nav_dir_root())
01598          goto nav_setcwd_fail;
01599       sz_path  += (Is_unicode? 2 : 1 );
01600    }else
01601 
01602    // Check syntact "x:\path..."
01603    if( (( Is_unicode) && (( ':'  == ((FS_STR_UNICODE)sz_path )[1] ) && (('\\'  == ((FS_STR_UNICODE)sz_path )[2] ) || ('/'  == ((FS_STR_UNICODE)sz_path )[2]))) )
01604    ||  ((!Is_unicode) && (( ':'  == sz_path [1] ) && (('\\'  == sz_path [2] ) || ('/'  == sz_path [2]))) ) )
01605    {
01606       // Go to the drive
01607       if( Is_unicode )
01608       {
01609          if( !nav_drive_set( toupper(((FS_STR_UNICODE)sz_path )[0])-'A' ) )
01610             goto nav_setcwd_fail;
01611       }else{
01612          if( !nav_drive_set( toupper(sz_path [0])-'A' ) )
01613             goto nav_setcwd_fail;
01614       }
01615       if( !nav_partition_mount())
01616          goto nav_setcwd_fail;
01617       sz_path  += 3*(Is_unicode? 2 : 1 );
01618    }else
01619 
01620    // Check syntact ".\path..."
01621    if( (( Is_unicode) && (( '.'  == ((FS_STR_UNICODE)sz_path )[0] ) && (('\\'  == ((FS_STR_UNICODE)sz_path )[1] ) || ('/'  == ((FS_STR_UNICODE)sz_path )[1] ))) )
01622    ||  ((!Is_unicode) && (( '.'  == sz_path [0] ) && (('\\'  == sz_path [1] ) || ('/'  == sz_path [1] ))) ) )
01623    {
01624       // Search in current directory
01625       sz_path  += 2*(Is_unicode? 2 : 1 );
01626    }else
01627 
01628    {
01629       // Check syntact "..\..\path..."
01630       if( Is_unicode )
01631       {
01632          while(( '.'  == ((FS_STR_UNICODE)sz_path )[0] )
01633          &&    ( '.'  == ((FS_STR_UNICODE)sz_path )[1] )
01634          &&    (('\\'  == ((FS_STR_UNICODE)sz_path )[2]) || ('/'  == ((FS_STR_UNICODE)sz_path )[2]) || (0  == ((FS_STR_UNICODE)sz_path )[2])) )
01635          {
01636             // Go to parent directory
01637             if( !nav_dir_gotoparent() )
01638                goto nav_setcwd_fail;
01639             sz_path  += (2*2); // jump ".."
01640             if( 0 != ((FS_STR_UNICODE)sz_path )[0])
01641                sz_path  += (2*1); // jump "/"
01642          }
01643       }else{
01644          while(( '.'  == sz_path [0] )
01645          &&    ( '.'  == sz_path [1] )
01646          &&    (('\\'  == sz_path [2]) || ('/'  == sz_path [2]) || (0  == sz_path [2])) )
01647          {
01648          // Go to parent directory
01649          if( !nav_dir_gotoparent() )
01650             goto nav_setcwd_fail;
01651             sz_path  += 2; // jump ".."
01652             if( 0 != sz_path [0])
01653                sz_path  +=1; // jump "/"
01654          }
01655       }
01656    }
01657 
01658    // Reset list to start the search at the beginning
01659    if( !nav_filelist_reset())
01660       goto nav_setcwd_fail;
01661 
01662    while( 1 )
01663    {
01664       if( (( Is_unicode) && ( 0 == ((FS_STR_UNICODE)sz_path )[0] ) )
01665       ||  ((!Is_unicode) && ( 0 == sz_path [0] ) ) )
01666       {
01667          return TRUE;   // path (without file) is found or create
01668       }
01669       if( !nav_filelist_findname( sz_path  , b_match_case  ))
01670       {
01671          // The file or directory is not found
01672          if( !b_create )
01673             goto nav_setcwd_fail;   // don't creat the directory then exit
01674          // Set flag to create the directory
01675          b_create_name = TRUE;
01676 #if (FSFEATURE_WRITE == (FS_LEVEL_FEATURES & FSFEATURE_WRITE)) ||              \
01677     (FSFEATURE_WRITE_COMPLET == (FS_LEVEL_FEATURES & FSFEATURE_WRITE_COMPLET))
01678          sz_save_path = sz_path;
01679 #endif
01680       }
01681 
01682       while( 1 )
01683       {
01684          sz_path  += (Is_unicode? 2 : 1 );
01685          if( (( Is_unicode) && ( 0 == ((FS_STR_UNICODE)sz_path )[0] ) )
01686          ||  ((!Is_unicode) && ( 0 == sz_path [0] ) ) )
01687          {
01688             // Is it the last name of path and it is a file
01689             if( b_create_name )
01690             {
01691 #if (FSFEATURE_WRITE == (FS_LEVEL_FEATURES & FSFEATURE_WRITE))
01692                // The file must be created
01693                if( !nav_file_create( sz_save_path ) )
01694                   goto nav_setcwd_fail;
01695 #else
01696                goto nav_setcwd_fail;
01697 #endif
01698             }
01699             break;   // The file include in path is found or created, then end of set_cwd
01700          }
01701 
01702          if( (( Is_unicode) && (('\\' == ((FS_STR_UNICODE)sz_path )[0] ) || ('/' == ((FS_STR_UNICODE)sz_path )[0] )) )
01703          ||  ((!Is_unicode) && (('\\' == sz_path [0] ) || ('/' == sz_path [0] )) ) )
01704          {
01705             // Is it a folder name
01706             if( b_create_name )
01707             {
01708 #if (FSFEATURE_WRITE_COMPLET == (FS_LEVEL_FEATURES & FSFEATURE_WRITE_COMPLET))
01709                // The folder doesn't exist and it must be created
01710                if( !nav_dir_make( sz_save_path ))
01711                   goto nav_setcwd_fail;
01712 #else
01713                goto nav_setcwd_fail;
01714 #endif
01715             }
01716             if( !fat_entry_is_dir() )
01717                goto nav_setcwd_fail;
01718             // jump '\'
01719             sz_path  += (Is_unicode? 2 : 1 );
01720             if( !nav_dir_cd())
01721                goto nav_setcwd_fail;
01722             break;
01723          }
01724       }
01725 
01726    }
01727 
01728 nav_setcwd_fail:
01729    nav_gotoindex( &index );   // Restore the position
01730    return FALSE;
01731 }

Here is the caller graph for this function:

Bool nav_file_getname ( FS_STRING  sz_name,
U8  u8_size_max 
)

This function returns the name of selected file.

Parameters:
sz_name string to store the name file (ASCII or UNICODE )
u8_size_max string size (unit ASCII or UNICODE )
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 1748 of file navigation.c.

01749 {
01750    return nav_file_name( sz_name, u8_size_max, FS_NAME_GET, FALSE );
01751 }

Bool nav_file_name ( FS_STRING  sz_name,
U8  u8_size_max,
Bool  b_mode,
Bool  b_match_case 
)

This function returns the name of selected file or checks the string with the name of selected file.

Parameters:
b_mode action mode:
FS_NAME_GET to get the name of selected file
FS_NAME_CHECK to check the name of selected file
sz_name if FS_NAME_GET then string to store the file name (ASCII or UNICODE )
if FS_NAME_CHECK then string to match with file name (ASCII or UNICODE), it must be terminated by NULL or '*' value
b_match_case FALSE, ignore the case (only used in "FS_NAME_CHECK" action)
u8_size_max string size (unit ASCII or UNICODE ), only used in "FS_NAME_GET" action
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 1769 of file navigation.c.

Referenced by copy_dir(), nav_dir_name(), nav_file_getname(), nav_filelist_findname(), nav_getcwd(), ushell_cmd_copy(), ushell_cmd_ls(), and ushell_cmd_sync().

01770 {
01771    _MEM_TYPE_SLOW_   U16 u16_lgt;   // Only used if LENGTH string mode enabled
01772    U16  u16_ptr_save_entry;
01773    Bool  b_readshortname = FALSE;
01774 
01775    if ( !fat_check_mount_select())
01776       return FALSE;
01777 
01778    // Check if the string size is not 0
01779    if( (FS_NAME_GET == b_mode)
01780    &&  (0 == u8_size_max) )
01781    {
01782       return TRUE;
01783    }
01784 
01785    // Save the current entry position
01786    u16_ptr_save_entry = fs_g_nav_fast.u16_entry_pos_sel_file;
01787    // if it is the beginning of the directory
01788    if ( 0 == fs_g_nav_fast.u16_entry_pos_sel_file )
01789    {
01790       b_readshortname = TRUE;                   // It isn't possibled to have a long name
01791    }
01792    else
01793    {
01794       fs_g_nav_fast.u16_entry_pos_sel_file--;   // Initialize entry position to search the first long name entry
01795    }
01796 
01797    // Loop in directory entry
01798    u16_lgt = 0;
01799    while( 1 )
01800    {
01801       if ( !fat_read_dir())
01802          break; // error
01803 
01804       if ( b_readshortname )
01805       {
01806          // No long name present then read short name
01807          return fat_entry_shortname( sz_name , u8_size_max , b_mode  );
01808       }
01809 
01810       // Check or read the part of long file name in this entry
01811       if ( fat_entry_longname( sz_name , u8_size_max , b_mode , b_match_case  ))
01812       {
01813          if( g_b_string_length )
01814          {
01815             ((FS_STR_UNICODE)sz_name )[0] += u16_lgt;
01816          }
01817          fs_g_nav_fast.u16_entry_pos_sel_file = u16_ptr_save_entry;
01818          return TRUE;
01819       }
01820 
01821       if ( FS_NO_LAST_LFN_ENTRY != fs_g_status )
01822       {
01823          // Go to the main entry file (=short name entry)
01824          fs_g_nav_fast.u16_entry_pos_sel_file = u16_ptr_save_entry;
01825 
01826          if ( FS_ERR_ENTRY_BAD == fs_g_status )
01827          {
01828             // It isn't a long name entry then there aren't long file name
01829             b_readshortname = TRUE;   // It is mandatory to use the short name
01830             continue;                 // restart the loop
01831          }
01832          // here, it is a error system or the string don't match with the file name
01833          break;
01834       }
01835       if( g_b_string_length )
01836       {
01837          u16_lgt += FS_SIZE_LFN_ENTRY;
01838       }
01839       else
01840       {
01841          // Increment the string to store the next part of file name
01842          sz_name += FS_SIZE_LFN_ENTRY * (Is_unicode? 2 : 1 );
01843          u8_size_max -= FS_SIZE_LFN_ENTRY;
01844       }
01845       fs_g_nav_fast.u16_entry_pos_sel_file--;   // Go to the next part of long file name
01846 
01847    }  // end of loop while(1)
01848    return FALSE;
01849 }

Here is the caller graph for this function:

U32 nav_file_lgt ( void   ) 

This function returns the size of selected file (unit byte).

Returns:
Size of selected file (unit byte)

Definition at line 1856 of file navigation.c.

Referenced by ushell_cmd_ls().

01857 {
01858    return fs_g_nav_entry.u32_size;
01859 }

Here is the caller graph for this function:

U16 nav_file_lgtsector ( void   ) 

This function returns the size of selected file (unit sector).

Returns:
Size of selected file (unit 512B)

Definition at line 1866 of file navigation.c.

01867 {
01868    return (fs_g_nav_entry.u32_size >> FS_512B_SHIFT_BIT);
01869 }

Bool nav_file_isreadonly ( void   ) 

This function checks the write protection of disk and the attribut "read only" of selected file.

Returns:
FALSE, it is possible to modify the selected file

TRUE, in other case

Definition at line 1877 of file navigation.c.

01878 {
01879    if( !fat_check_mount_select() )
01880       return TRUE;   // No file selected
01881    if( mem_wr_protect( fs_g_nav.u8_lun ) )
01882       return TRUE;   // Disk protected
01883    return (0!=(FS_ATTR_READ_ONLY & fs_g_nav_entry.u8_attr));   // Check attribut "read only"
01884 }

Bool nav_file_isdir ( void   ) 

This function returns the type of selected file.

Returns:
TRUE, it is a directory

FALSE, in other case

Definition at line 1892 of file navigation.c.

Referenced by copy_dir(), ushell_cmd_ls(), and ushell_cmd_sync().

01893 {
01894    return fat_entry_is_dir();
01895 }

Here is the caller graph for this function:

Bool nav_file_checkext ( const FS_STRING  sz_filterext  ) 

This function checks the extension of selected file.

Parameters:
sz_filterext extension filter (ASCII format, e.g.: "txt" or "txt,d*,wk" )
Returns:
TRUE, the file extension match with extension filter

FALSE, in other case

Definition at line 1905 of file navigation.c.

Referenced by ushell_cmd_ls().

01906 {
01907    if ( fat_check_mount_select() )
01908    {
01909       // Read selected entry (=short name entry) in directory
01910       if ( fat_read_dir())
01911       {
01912          // Check the extension with filter
01913          if ( fat_entry_checkext( (FS_STRING) sz_filterext ) )
01914             return TRUE;
01915       }
01916    }
01917    return FALSE;
01918 }

Here is the caller graph for this function:

Bool nav_file_dateget ( FS_STRING  sz_date,
Bool  type_date 
)

This function returns the date of selected file.

Parameters:
type_date FS_DATE_LAST_WRITE, to get the date of last write access
FS_DATE_CREATION, to get the date of file creation
sz_date ASCCI string (>17B) to store the information about date
"YYYYMMDDHHMMSSMS" = year, month, day, hour, minute, seconde, miliseconde
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 1931 of file navigation.c.

01932 {
01933    if ( !fat_check_mount_select())
01934       return FALSE;
01935 
01936    // Read selected entry in directory
01937    if ( !fat_read_dir())
01938       return FALSE;
01939    fat_get_date( sz_date , type_date );
01940    return TRUE;
01941 }

U8 nav_file_attributget ( void   ) 

This function returns the attribut of selected file.

Returns:
attribut of selected file, see masks "FS_ATTR_" in fs_com.h file.

Definition at line 1948 of file navigation.c.

01949 {
01950    return fs_g_nav_entry.u8_attr;
01951 }


Generated on Wed Sep 23 09:17:11 2009 for ATMEL by  doxygen 1.5.3