ATMEL: fat_unusual.c File Reference

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

# fat_unusual.c File Reference

FAT services. More...

`#include "conf_explorer.h"`
`#include "fs_com.h"`
`#include "fat.h"`
`#include <LIB_MEM>`
`#include <LIB_CTRLACCESS>`

Include dependency graph for fat_unusual.c:

Go to the source code of this file.

## Functions

Bool | fat_select_filesystem (U8 u8_fat_type, Bool b_MBR)
Bool | fat_write_MBR (void)
Bool | fat_write_PBR (Bool b_MBR)
Bool | fat_clean_zone (Bool b_MBR)
Bool | fat_initialize_fat (void)
Bool | fat_mount (void)
| This function mounts a partition file system (FAT12, FAT16 or FAT32) of selected drive.
void | fat_get_date (FS_STRING sz_date, Bool type_date)
| This function reads the information about a date.
U32 | fat_getfreespace (void)
| This function returns the space free in the partition.
U8 | fat_getfreespace_percent (void)
| This function returns the space free in percent.
Sub routines used by date read-write routines
void | fat_translatedate_number_to_ascii (FS_STRING sz_date, PTR_CACHE ptr_date, Bool enable_ms)
| This function translates a date FAT value to ascii string.
void | fat_translate_number_to_ascii (FS_STRING sz_ascii_number, U8 u8_size_number_ascii, U8 u8_nb_increment)
| This function translates a digital number to a ASCII number.
void | fat_translatedate_ascii_to_number (const FS_STRING sz_date, PTR_CACHE ptr_date, Bool enable_ms)
U16 | fat_translate_ascii_to_number (const FS_STRING sz_ascii_number, U8 u8_size_number_ascii)
Sub routine used to create a entry file
void | fat_create_long_name_entry (FS_STRING sz_name, U8 u8_crc, U8 u8_id)
U8 | fat_create_short_entry_name (FS_STRING sz_name, FS_STRING short_name, U8 nb, Bool mode)
U8 | fat_find_short_entry_name (FS_STRING sz_name)
Bool | fat_entry_shortname_compare (FS_STRING short_name)
U8 | fat_check_name (FS_STRING sz_name)
U8 | fat_translate_char_shortname (U8 character)
Bool | fat_alloc_entry_free (U8 u8_nb_entry)
Bool | fat_garbage_collector_entry (void)

## Detailed Description

FAT services.

This file is a set of rarely-used FAT functions.

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

Definition in file fat_unusual.c.

## Function Documentation

Bool fat_select_filesystem | ( | U8 | u8_fat_type,
|  | Bool | b_MBR |
| ) |  |  |

Bool fat_write_MBR | ( | void |  | ) |

Bool fat_write_PBR | ( | Bool | b_MBR | ) |

Bool fat_clean_zone | ( | Bool | b_MBR | ) |

Bool fat_initialize_fat | ( | void |  | ) |

void fat_translatedate_number_to_ascii | ( | FS_STRING | sz_date,
|  | PTR_CACHE | ptr_date,
|  | Bool | enable_ms |
| ) |  |  |

This function translates a date FAT value to ascii string.

Parameters:

  | sz_date | table to store the date information storage format (ASCII) = "YYYYMMDDHHMMSSMS" = year, month, day, hour, minute, seconde, miliseconde
  | ptr_date | pointer on date in internal cache
  | enable_ms | TRUE, translate the millisecond field

Definition at line 1244 of file fat_unusual.c.

References fat_translate_number_to_ascii().

Referenced by fat_get_date().

    01245 {
    01246    FS_STRING ptr_string_date;
    01247    U8 u8_i;
    01248    U8 msb_date, lsb_date, msb_time, lsb_time, u8_ms = 0;
    01249
    01250    // Read entry value of date and time
    01251    if( enable_ms )
    01252    {
    01253       u8_ms = *ptr_date;
    01254       ptr_date++;
    01255    }
    01256    lsb_time = *ptr_date;
    01257    ptr_date++;
    01258    msb_time = *ptr_date;
    01259    ptr_date++;
    01260    lsb_date = *ptr_date;
    01261    ptr_date++;
    01262    msb_date = *ptr_date;
    01263
    01264    // Initialise the string with "1980000000000000" (Year = 1980 and other at 0)
    01265    ptr_string_date = sz_date;
    01266    *ptr_string_date = '1';
    01267    ptr_string_date++;
    01268    *ptr_string_date = '9';
    01269    ptr_string_date++;
    01270    *ptr_string_date = '8';
    01271    ptr_string_date++;
    01272    for( u8_i=(15-2) ; u8_i!=0 ; u8_i-- )
    01273    {
    01274       *ptr_string_date = '0';
    01275       ptr_string_date++;
    01276    }
    01277
    01278    // Get the year
    01279    fat_translate_number_to_ascii( sz_date, 4 , msb_date>>1 );
    01280
    01281    // Get the month
    01282    fat_translate_number_to_ascii( &sz_date[4] , 2 , ((msb_date & 0x01)<<3) + (lsb_date>>5) );
    01283
    01284    // Get the day
    01285    fat_translate_number_to_ascii( &sz_date[6] , 2 , lsb_date & 0x1F );
    01286
    01287    // Get the hour
    01288    fat_translate_number_to_ascii( &sz_date[8] , 2 , msb_time >> (11-8) );
    01289
    01290    // Get the minute
    01291    fat_translate_number_to_ascii( &sz_date[10] , 2 , ((msb_time & 0x07)<<3) + (lsb_time>>5) );
    01292
    01293    // Get the seconde
    01294    fat_translate_number_to_ascii( &sz_date[12] , 2 , (lsb_time & 0x1F)<<1 );
    01295    if( 99 < u8_ms )
    01296    {
    01297      // Add one seconde
    01298      fat_translate_number_to_ascii( &sz_date[12] , 2 , 1 );
    01299      u8_ms -= 100;
    01300    }
    01301
    01302    // Get the miliseconde
    01303    fat_translate_number_to_ascii( &sz_date[14] , 2 , u8_ms );
    01304 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fat_translate_number_to_ascii | ( | FS_STRING | sz_ascii_number,
|  | U8 | u8_size_number_ascii,
|  | U8 | u8_nb_increment |
| ) |  |  |

This function translates a digital number to a ASCII number.

Parameters:

  | sz_ascii_number | ascii string to increment (ex:"1907")
  | u8_size_number_ascii | number of digit (ex:4)
  | u8_nb_increment | number to add (ex:"102")

    //! OUT, Update sz_ascii_number (ex:"2009")
    //!

Definition at line 1317 of file fat_unusual.c.

Referenced by fat_translatedate_number_to_ascii().

    01318 {
    01319    FS_STRING ptr_sz_ascii_number;
    01320
    01321    u8_size_number_ascii--;
    01322
    01323    for( ; u8_nb_increment != 0 ; u8_nb_increment-- )
    01324    {
    01325       ptr_sz_ascii_number = sz_ascii_number + u8_size_number_ascii;
    01326       ptr_sz_ascii_number[0]++;
    01327       while( ('9'+1) == *ptr_sz_ascii_number )
    01328       {
    01329          *ptr_sz_ascii_number = '0';
    01330          ptr_sz_ascii_number--;
    01331          ptr_sz_ascii_number[0]++;
    01332       }
    01333    }
    01334 }

Here is the caller graph for this function:

void fat_translatedate_ascii_to_number | ( | const FS_STRING | sz_date,
|  | PTR_CACHE | ptr_date,
|  | Bool | enable_ms |
| ) |  |  |

U16 fat_translate_ascii_to_number | ( | const FS_STRING | sz_ascii_number,
|  | U8 | u8_size_number_ascii |
| ) |  |  |

void fat_create_long_name_entry | ( | FS_STRING | sz_name,
|  | U8 | u8_crc,
|  | U8 | u8_id |
| ) |  |  |

U8 fat_create_short_entry_name | ( | FS_STRING | sz_name,
|  | FS_STRING | short_name,
|  | U8 | nb,
|  | Bool | mode |
| ) |  |  |

U8 fat_find_short_entry_name | ( | FS_STRING | sz_name | ) |

Bool fat_entry_shortname_compare | ( | FS_STRING | short_name | ) |

U8 fat_check_name | ( | FS_STRING | sz_name | ) |

U8 fat_translate_char_shortname | ( | U8 | character | ) |

Bool fat_alloc_entry_free | ( | U8 | u8_nb_entry | ) |

Bool fat_garbage_collector_entry | ( | void |  | ) |

Bool fat_mount | ( | void |  | ) |

This function mounts a partition file system (FAT12, FAT16 or FAT32) of selected drive.

This function mounts a partition.

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

  TRUE otherwise

    //! Global variables used
    //! IN :
    //!   fs_g_nav.u8_lun            Indicate the drive to mount
    //!   fs_g_nav.u8_partition      Indicate the partition to mount (if FS_MULTI_PARTITION =  ENABLED )
    //! OUT:
    //!   fs_g_nav                   update structure
    //! If the FS_MULTI_PARTITION option is disabled
    //! then the mount routine selects the first partition supported by file system. <br>
    //!

Definition at line 105 of file fat_unusual.c.

References FALSE, fat_cache_read_sector(), fat_check_device(), fat_clear_entry_info_and_ptr(), FS_512B, FS_BR_SIGNATURE_HIGH, FS_BR_SIGNATURE_LOW, FS_ERR_NO_FORMAT, FS_ERR_NO_PART, FS_ERR_NO_SUPPORT_PART, FS_FAT12_MAX_CLUSTERS, FS_FAT16_MAX_CLUSTERS, fs_g_nav, fs_g_nav_fast, fs_g_sector, fs_g_status, fs_gu32_addrsector, FS_MBR_OFFSET_PART_ENTRY, FS_NB_FAT, FS_PART_BOOTABLE, FS_PART_NO_BOOTABLE, FS_PART_TYPE_FAT12, FS_PART_TYPE_FAT16_INF32M, FS_PART_TYPE_FAT16_SUP32M, FS_PART_TYPE_FAT16_SUP32M_BIS, FS_PART_TYPE_FAT32, FS_PART_TYPE_FAT32_BIS, FS_SIZE_FILE_ENTRY, FS_TYPE_FAT_12, FS_TYPE_FAT_16, FS_TYPE_FAT_32, FS_TYPE_FAT_UNM, HIGH_16_BPB_BytsPerSec, HIGH_16_BPB_FATSz16, HIGH_16_BPB_ResvSecCnt, HIGH_16_BPB_RootEntCnt, HIGH_16_BPB_TotSec16, LOW0_32_BPB_FATSz32, LOW0_32_BPB_RootClus, LOW0_32_BPB_TotSec32, LOW1_32_BPB_FATSz32, LOW1_32_BPB_RootClus, LOW1_32_BPB_TotSec32, LOW2_32_BPB_FATSz32, LOW2_32_BPB_RootClus, LOW2_32_BPB_TotSec32, LOW3_32_BPB_FATSz32, LOW3_32_BPB_RootClus, LOW3_32_BPB_TotSec32, LOW_16_BPB_FATSz16, LOW_16_BPB_FSInfo, LOW_16_BPB_ResvSecCnt, LOW_16_BPB_RootEntCnt, LOW_16_BPB_TotSec16, LSB, LSB0, LSB1, LSB2, LSB3, mem_sector_size(), MSB, Fs_management::rootdir, Fs_rootdir::seg, TRUE, Fs_management::u16_fat_size, Fs_management::u16_offset_FSInfo, Fs_rootdir::u16_pos, Fs_rootdir::u16_size, Fs_rootdir::u32_cluster, Fs_management::u32_cluster_sel_dir, Fs_management::u32_CountofCluster, Fs_management::u32_offset_data, Fs_management::u32_ptr_fat, U8_BPB_SecPerClus, Fs_management::u8_BPB_SecPerClus, Fs_management::u8_lun, Fs_management::u8_partition, and Fs_management_fast::u8_type_fat.

    00106 {
    00107    U8  u8_sector_size;
    00108    U8  u8_tmp;
    00109    U16 u16_tmp;
    00110    U32 u32_tmp;
    00111
    00112    // Select the root directory
    00113    fs_g_nav.u32_cluster_sel_dir   = 0;
    00114    // No selected file
    00115    fat_clear_entry_info_and_ptr();
    00116
    00117    fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_UNM;
    00118    fs_gu32_addrsector = 0;    // Start read at the beginning of memory
    00119
    00120    // Check if the drive is availabled
    00121    if( !fat_check_device() )
    00122       return FALSE;
    00123
    00124    while( 1 )  // Search a valid partition
    00125    {
    00126       // Read one sector
    00127       if( !fat_cache_read_sector( TRUE ))
    00128          return FALSE;
    00129
    00130       // Check PBR/MBR signature
    00131       if ( (fs_g_sector[510] != FS_BR_SIGNATURE_LOW  )
    00132       &&   (fs_g_sector[511] != FS_BR_SIGNATURE_HIGH ) )
    00133       {
    00134          fs_g_status = FS_ERR_NO_FORMAT;
    00135          return FALSE;
    00136       }
    00137
    00138       if ( 0 == fs_gu32_addrsector )
    00139       {
    00140          //** first sector then check a MBR structure
    00141          // Search the first partition supported
    00142 #if (FS_MULTI_PARTITION == ENABLED)
    00143          u16_tmp=0;  // Init to "no valid partition found"
    00144 #endif
    00145          for( u8_tmp=0 ; u8_tmp!=4 ; u8_tmp++ )
    00146          {
    00147             // The first sector must be a MBR, then check the partition entry in the MBR
    00148             if ( ((fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+0] == FS_PART_BOOTABLE             )||
    00149                   (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+0] == FS_PART_NO_BOOTABLE          )  )
    00150             &&   ((fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT12           )||
    00151                   (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT16_INF32M    )||
    00152                   (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT16_SUP32M    )||
    00153                   (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT16_SUP32M_BIS)||
    00154                   (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT32           )||
    00155                   (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT32_BIS       )) )
    00156             {
    00157                // A valid partition is found
    00158 #if (FS_MULTI_PARTITION == ENABLED)
    00159                if( u16_tmp == fs_g_nav.u8_partition )
    00160                   break;   // The selected partition is valid
    00161                u16_tmp++;
    00162 #else
    00163                break;
    00164 #endif
    00165             }
    00166          }
    00167          if( u8_tmp != 4 )
    00168          {
    00169             // Partition found -> Get partition position (unit sector) at offset 8
    00170             LSB0(fs_gu32_addrsector) = fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+8];
    00171             LSB1(fs_gu32_addrsector) = fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+9];
    00172             LSB2(fs_gu32_addrsector) = fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+10];
    00173             LSB3(fs_gu32_addrsector) = fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+11];
    00174             fs_gu32_addrsector *= mem_sector_size( fs_g_nav.u8_lun );
    00175             continue;   // Go to check PBR of partition
    00176          }
    00177
    00178          // No MBR found then check PBR
    00179 #if (FS_MULTI_PARTITION == ENABLED)
    00180          // The device don't have mutli partition, but only one
    00181          if ( 0 != fs_g_nav.u8_partition )
    00182          {
    00183             fs_g_status = FS_ERR_NO_PART;
    00184             return FALSE;
    00185          }
    00186 #endif
    00187       }
    00188
    00189       //** Check a PBR structure
    00190       if ( (fs_g_sector[0] == 0xEB) &&          // PBR Byte 0
    00191            (fs_g_sector[2] == 0x90) &&          // PBR Byte 2
    00192            ((fs_g_sector[21] & 0xF0) == 0xF0) ) // PBR Byte 21 : Media byte
    00193       {
    00194          break;   // valid PBR found
    00195       }
    00196       // PBR not found
    00197       fs_g_status = FS_ERR_NO_PART;
    00198       return FALSE;
    00199    }
    00200
    00201    fs_g_status = FS_ERR_NO_SUPPORT_PART;  // by default partition no supported
    00202
    00203    // Get sector size of File System (unit 512B)
    00204    // To translate from sector disk unit to sector 512B unit
    00205    u8_sector_size = HIGH_16_BPB_BytsPerSec/2;
    00206
    00207    // Read BPB_SecPerClus (unit sector)
    00208    fs_g_nav.u8_BPB_SecPerClus = U8_BPB_SecPerClus * u8_sector_size;
    00209
    00210    //** FAT Type determination (algorithm of "Hardware White Paper FAT")
    00211    // Get FAT size (unit sector)
    00212    LSB( u16_tmp ) = LOW_16_BPB_FATSz16;
    00213    MSB( u16_tmp ) = HIGH_16_BPB_FATSz16;
    00214    if ( 0==u16_tmp )
    00215    {
    00216       LSB( u16_tmp ) = LOW0_32_BPB_FATSz32;
    00217       MSB( u16_tmp ) = LOW1_32_BPB_FATSz32;
    00218       // a large FAT32 isn't supported by this file system
    00219       if( (0 != LOW2_32_BPB_FATSz32 )
    00220       ||  (0 != LOW3_32_BPB_FATSz32 ) )
    00221       {
    00222          return FALSE;
    00223       }
    00224    }
    00225    fs_g_nav.u16_fat_size = u16_tmp * u8_sector_size;
    00226
    00227    // Get total count of sectors in partition
    00228    if ( (0==LOW_16_BPB_TotSec16) && (0==HIGH_16_BPB_TotSec16) )
    00229    {
    00230       LSB0( u32_tmp ) = LOW0_32_BPB_TotSec32;
    00231       LSB1( u32_tmp ) = LOW1_32_BPB_TotSec32;
    00232       LSB2( u32_tmp ) = LOW2_32_BPB_TotSec32;
    00233       LSB3( u32_tmp ) = LOW3_32_BPB_TotSec32;
    00234    }
    00235    else
    00236    {
    00237       LSB0( u32_tmp ) = LOW_16_BPB_TotSec16;
    00238       LSB1( u32_tmp ) = HIGH_16_BPB_TotSec16;
    00239       LSB2( u32_tmp ) = 0;
    00240       LSB3( u32_tmp ) = 0;
    00241    }
    00242    u32_tmp *= u8_sector_size;   // Translate from sector disk unit to sector 512B unit
    00243
    00244    // Compute the offset (unit 512B) between the end of FAT (beginning of root dir in FAT1x) and the beginning of PBR
    00245    fs_g_nav.rootdir.seg.u16_pos = FS_NB_FAT * fs_g_nav.u16_fat_size;
    00246
    00247    // Compute the root directory size (unit sector), for FAT32 is always 0
    00248    LSB( u16_tmp ) = LOW_16_BPB_RootEntCnt;
    00249    MSB( u16_tmp ) = HIGH_16_BPB_RootEntCnt;
    00250    fs_g_nav.rootdir.seg.u16_size = ((u16_tmp * FS_SIZE_FILE_ENTRY) + ((FS_512B*u8_sector_size)-1)) / (FS_512B*u8_sector_size);
    00251    fs_g_nav.rootdir.seg.u16_size *= u8_sector_size;
    00252
    00253    // Get number of reserved sector
    00254    LSB( u16_tmp ) = LOW_16_BPB_ResvSecCnt;
    00255    MSB( u16_tmp ) = HIGH_16_BPB_ResvSecCnt;
    00256    // Get FSInfo position
    00257    fs_g_nav.u16_offset_FSInfo = (u16_tmp-LOW_16_BPB_FSInfo)*u8_sector_size;
    00258    u16_tmp *= u8_sector_size; // number of reserved sector translated in unit 512B
    00259
    00260    // Compute the FAT address (unit 512B)
    00261    fs_g_nav.u32_ptr_fat = fs_gu32_addrsector + u16_tmp;
    00262
    00263    // Compute the offset (unit 512B) between the first data cluster and the FAT beginning
    00264    fs_g_nav.u32_offset_data = (FS_NB_FAT * (U32)fs_g_nav.u16_fat_size) + (U32)fs_g_nav.rootdir.seg.u16_size;
    00265
    00266    // Compute the data region (clusters space = Total - Sector used) size (unit 512B)
    00267    u32_tmp -= ((U32)u16_tmp + fs_g_nav.u32_offset_data);
    00268
    00269    // Compute the count of CLUSTER in the data region
    00270    // !!!Optimization -> u32_CountofCluster (unit 512B)/ fs_g_nav.u8_BPB_SecPerClus (unit 512B & power of 2)
    00271    if (!fs_g_nav.u8_BPB_SecPerClus)
    00272      return FALSE;
    00273    for( u8_tmp = fs_g_nav.u8_BPB_SecPerClus; u8_tmp!=1 ; u8_tmp >>= 1 )
    00274    {
    00275      u32_tmp  >>= 1;   // This computation round down
    00276    }
    00277    fs_g_nav.u32_CountofCluster = u32_tmp+2; // The total of cluster include the two reserved clusters
    00278
    00279    // Determine the FAT type
    00280    if (u32_tmp < FS_FAT12_MAX_CLUSTERS)
    00281    {
    00282       // Is FAT 12
    00283 #if (FS_FAT_12 == DISABLED)
    00284       return FALSE;
    00285 #endif
    00286       fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_12;
    00287    } else {
    00288    if (u32_tmp < FS_FAT16_MAX_CLUSTERS)
    00289    {
    00290       // Is FAT 16
    00291 #if (FS_FAT_16 == DISABLED)
    00292       return FS_NO_SUPPORT_PART;
    00293 #endif
    00294       fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_16;
    00295    } else {
    00296       // Is FAT 32
    00297 #if (FS_FAT_32 == DISABLED)
    00298       return FALSE;
    00299 #endif
    00300       fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_32;
    00301       // In FAT32, the root dir is like another directory, this one have a cluster list
    00302       // Get the first cluster number of root
    00303       LSB0( fs_g_nav.rootdir.u32_cluster ) = LOW0_32_BPB_RootClus;
    00304       LSB1( fs_g_nav.rootdir.u32_cluster ) = LOW1_32_BPB_RootClus;
    00305       LSB2( fs_g_nav.rootdir.u32_cluster ) = LOW2_32_BPB_RootClus;
    00306       LSB3( fs_g_nav.rootdir.u32_cluster ) = LOW3_32_BPB_RootClus;
    00307    }
    00308    }
    00309
    00310    return TRUE;
    00311 }

Here is the call graph for this function:

void fat_get_date | ( | FS_STRING | sz_date,
|  | Bool | type_date |
| ) |  |  |

This function reads the information about a date.

Parameters:

  | type_date | choose the date type (FS_DATE_LAST_WRITE or FS_DATE_CREATION)
  | sz_date | table to store the date storage format (ASCII) = "YYYYMMDDHHMMSSMS" = year, month, day, hour, minute, seconde, miliseconde

Definition at line 1221 of file fat_unusual.c.

References FALSE, fat_get_ptr_entry(), fat_translatedate_number_to_ascii(), FS_DATE_LAST_WRITE, and TRUE.

    01222 {
    01223    PTR_CACHE ptr_entry;
    01224
    01225    ptr_entry = fat_get_ptr_entry();
    01226    if( FS_DATE_LAST_WRITE == type_date )
    01227    {
    01228       fat_translatedate_number_to_ascii( sz_date , &ptr_entry[22] , FALSE );
    01229    }
    01230    else
    01231    {
    01232       fat_translatedate_number_to_ascii( sz_date , &ptr_entry[13] , TRUE );
    01233    }
    01234 }

Here is the call graph for this function:

U32 fat_getfreespace | ( | void |  | ) |

This function returns the space free in the partition.

Returns:
  the number of sector free
  if 0, then error or full

Definition at line 2132 of file fat_unusual.c.

References FALSE, fat_cluster_readnext(), fat_cluster_val(), fat_read_fat32_FSInfo(), fat_write_fat32_FSInfo(), FS_CLUST_VAL_READ, fs_g_cluster, fs_g_nav, Is_fat12, Is_fat32, Fs_management::u32_CountofCluster, Fs_cluster::u32_pos, Fs_cluster::u32_val, and Fs_management::u8_BPB_SecPerClus.

    02133 {
    02134    U32 u32_nb_free_cluster = 0;
    02135
    02136    // Read ALL FAT1
    02137    fs_g_cluster.u32_pos = 2;
    02138
    02139    if( Is_fat12 )
    02140    {  // FAT12 only
    02141       for(
    02142       ;     fs_g_cluster.u32_pos < fs_g_nav.u32_CountofCluster
    02143       ;     fs_g_cluster.u32_pos++ )
    02144       {
    02145          // Get the value of the cluster
    02146          if ( !fat_cluster_val( FS_CLUST_VAL_READ ) )
    02147             return 0;
    02148
    02149          if ( 0 == fs_g_cluster.u32_val )
    02150             u32_nb_free_cluster++;
    02151       }
    02152    }
    02153    else
    02154    {
    02155       if( Is_fat32 )
    02156       {
    02157          u32_nb_free_cluster = fat_read_fat32_FSInfo();
    02158          if( 0xFFFFFFFF != u32_nb_free_cluster )
    02159             goto endof_fat_getfreespace;
    02160          u32_nb_free_cluster = 0;
    02161       }
    02162       // Speed optimization only for FAT16 and FAT32
    02163       // init first value used by fat_cluster_readnext()
    02164       if( !fat_cluster_val( FS_CLUST_VAL_READ ))
    02165          return FALSE;
    02166       for(
    02167       ;     fs_g_cluster.u32_pos < fs_g_nav.u32_CountofCluster
    02168       ;     fs_g_cluster.u32_pos++ )
    02169       {
    02170          if ( 0 == fs_g_cluster.u32_val )
    02171             u32_nb_free_cluster++;
    02172          if( !fat_cluster_readnext() )
    02173             return FALSE;
    02174       }
    02175 #if (FSFEATURE_WRITE_COMPLET == (FS_LEVEL_FEATURES & FSFEATURE_WRITE_COMPLET) )
    02176       if( Is_fat32 )
    02177       {
    02178          // Save value for the future call
    02179          fat_write_fat32_FSInfo( u32_nb_free_cluster );
    02180       }
    02181 #endif
    02182    }
    02183 endof_fat_getfreespace:
    02184    return (u32_nb_free_cluster * fs_g_nav.u8_BPB_SecPerClus);
    02185 }

Here is the call graph for this function:

U8 fat_getfreespace_percent | ( | void |  | ) |

This function returns the space free in percent.

Returns:
  percent of free space (1 to 100) if 0, then error or full

    //! More speed than fat_getfreespace() routine but error delta 1%
    //!

Definition at line 2197 of file fat_unusual.c.

References FALSE, fat_cache_read_sector(), fat_cluster_val(), fat_getfreespace(), fat_read_fat32_FSInfo(), FS_CLUST_VAL_READ, fs_g_cluster, fs_g_nav, fs_g_sector, fs_gu32_addrsector, Is_fat12, Is_fat16, Is_fat32, TRUE, Fs_management::u16_fat_size, Fs_management::u32_CountofCluster, Fs_cluster::u32_pos, and Fs_management::u8_BPB_SecPerClus.

    02198 {
    02199    U32 u32_nb_free_cluster = 0;
    02200    U16 u16_tmp, u16_pos;
    02201
    02202    if( Is_fat12 )
    02203    {  // No speed optimization necessary on FAT12
    02204       return (((fat_getfreespace()/fs_g_nav.u8_BPB_SecPerClus)*100) / fs_g_nav.u32_CountofCluster);
    02205    }
    02206
    02207
    02208    fs_g_cluster.u32_pos = 2;
    02209    // Init first value used by fat_cluster_readnext()
    02210    if( !fat_cluster_val( FS_CLUST_VAL_READ ))
    02211       return FALSE;
    02212
    02213    // The optimization is to
    02214    // - read only the LSB byte of cluster
    02215    // - read only 1 cluster for 2 clusters
    02216    if( Is_fat32 )
    02217    {
    02218       u32_nb_free_cluster = fat_read_fat32_FSInfo();
    02219       if( 0xFFFFFFFF != u32_nb_free_cluster )
    02220          goto endof_fat_getfreespace_percent;
    02221       u32_nb_free_cluster = 0;
    02222
    02223       u16_pos = 2*4;
    02224       for(  u16_tmp = fs_g_nav.u16_fat_size
    02225       ;     u16_tmp!=0
    02226       ;     u16_tmp-- )
    02227       {
    02228          for( ; u16_pos < 512 ; u16_pos += (2*4) )
    02229          {
    02230             if( 0 == fs_g_sector[u16_pos] )
    02231                u32_nb_free_cluster+=2;
    02232          }
    02233          // Read next sector in FAT
    02234          u16_pos = 0;
    02235          fs_gu32_addrsector++;
    02236          if( !fat_cache_read_sector( TRUE ))
    02237             return 0;
    02238       }
    02239    }
    02240
    02241    if ( Is_fat16 )
    02242    {
    02243       u16_pos = 2*2;
    02244
    02245       for(  u16_tmp = fs_g_nav.u16_fat_size
    02246       ;     u16_tmp!=0
    02247       ;     u16_tmp-- )
    02248       {
    02249          for( ; u16_pos < 512 ; u16_pos += (2*2) )
    02250          {
    02251             if( 0 == fs_g_sector[u16_pos] )
    02252                u32_nb_free_cluster+=2;
    02253          }
    02254          // Read next sector in FAT
    02255          u16_pos = 0;
    02256          fs_gu32_addrsector++;
    02257          if( !fat_cache_read_sector( TRUE ))
    02258             return 0;
    02259       }
    02260    }
    02261
    02262    // Compute percent
    02263    if( u32_nb_free_cluster > fs_g_nav.u32_CountofCluster )
    02264       return 100;
    02265    if( u32_nb_free_cluster > ((fs_g_nav.u32_CountofCluster-u32_nb_free_cluster)/256) )
    02266    {
    02267       // Compute and add a delta error
    02268       u32_nb_free_cluster -= ((fs_g_nav.u32_CountofCluster-u32_nb_free_cluster)/256);
    02269    }
    02270 endof_fat_getfreespace_percent:
    02271    return ((u32_nb_free_cluster * 100) / fs_g_nav.u32_CountofCluster);
    02272 }

Here is the call graph for this function: