Ignore:
Timestamp:
Jul 12, 2017, 8:12:41 PM (7 years ago)
Author:
alain
Message:

Redefine the PIC device API.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/vfs/fatfs.h

    r23 r188  
    160160typedef struct fatfs_ctx_s
    161161{
     162    uint32_t          fat_sectors_count;     /*! number of sectors in FAT region        */
     163    uint32_t          bytes_per_sector;      /*! number of bytes per sector             */
     164    uint32_t          sectors_per_cluster;   /*! number of sectors per cluster          */
    162165    uint32_t          fat_begin_lba;         /*! lba of FAT region                      */
    163     uint32_t          fat_sectors_count;     /*! number of sectors in FAT region        */
    164     uint32_t          bytes_per_sector;      /*!                                        */
    165     uint32_t          bytes_per_cluster;     /*!                                        */
    166166    uint32_t          cluster_begin_lba;     /*! lba of data region                     */
    167     uint32_t          sectors_per_cluster;   /*! cluster index for root directory       */
    168     uint32_t          root_dir_cluster;      /*!                                        */
     167    uint32_t          root_dir_cluster;      /*! cluster index for the root directory   */
    169168    uint32_t          last_allocated_sector; /*! TODO ???                               */
    170169    uint32_t          last_allocated_index;  /*! TODO ???                               */
     
    173172fatfs_ctx_t;
    174173
    175 /*****************************************************************************************
    176  * This structure defines the FATFS specific inode (extension to VFS inode).
    177  ****************************************************************************************/
    178 
    179 typedef struct fatfs_inode_s
    180 {
    181         uint32_t          first_cluster;         /*! first cluster for this file/dir        */
    182 }
    183 fatfs_inode_t;
    184 
    185 
    186 
    187 
    188174//////////////////////////////////////////////////////////////////////////////////////////
    189 // These functions are specific to the FATFS, and cannot be called by the VFS.
     175// Generic API: These functions are called by the kernel,
     176//              and must be implemented by all File Systems.
    190177//////////////////////////////////////////////////////////////////////////////////////////
    191178
    192 /*****************************************************************************************
    193  * This function returns the LBA of the first sector of a FAT cluster.
    194  * This function can be called by any thread running in any cluster.
    195  *****************************************************************************************
    196  * @ ctx          :     pointer on FATFS context.
    197  * @ cluster  : cluster index in FATFS.
    198  * @ return the lba value.
    199  ****************************************************************************************/
    200 inline uint32_t fatfs_lba_from_cluster( fatfs_ctx_t * ctx,
    201                                         uint32_t      cluster );
     179/******************************************************************************************
     180 * This fuction allocates memory from local cluster for a FATFS context descriptor.
     181 ******************************************************************************************
     182 * @ return a pointer on the created context / return NULL if failure.
     183 *****************************************************************************************/
     184fatfs_ctx_t * fatfs_ctx_alloc();
     185
     186/*****************************************************************************************
     187 * This function access the external boot device, and initialises it
     188 * from informations contained in the boot record.
     189 *****************************************************************************************
     190 * @ vfs_ctx   : local pointer on VFS context for FATFS.
     191 ****************************************************************************************/
     192void fatfs_ctx_init( fatfs_ctx_t * fatfs_ctx );
     193
     194/*****************************************************************************************
     195 * This function releases memory dynamically allocated for the FATFS context extension.
     196 *****************************************************************************************
     197 * @ vfs_ctx   : local pointer on VFS context.
     198 ****************************************************************************************/
     199void fatfs_ctx_destroy( fatfs_ctx_t * fatfs_ctx );
     200
     201/*****************************************************************************************
     202 * This function moves a page from the mapper to the FATFS file system on device.
     203 * It must be called by a thread running in cluster containing the mapper.
     204 * The pointer on the mapper and the page index in file are registered
     205 * in the page descriptor.
     206 *****************************************************************************************
     207 * @ page    : local pointer on page descriptor.
     208 * @ return 0 if success / return EIO if error.
     209 ****************************************************************************************/
     210error_t fatfs_write_page( struct page_s * page );
     211
     212/*****************************************************************************************
     213 * This function moves a page from the FATFS file system on device to the mapper.
     214 * It must be called by a thread running in cluster containing the mapper.
     215 * The pointer on the mapper and the page index in file are registered
     216 * in the page descriptor.
     217 *****************************************************************************************
     218 * @ page    : local pointer on page descriptor.
     219 * @ return 0 if success / return EIO if error.
     220 ****************************************************************************************/
     221error_t fatfs_read_page( struct page_s * page );
    202222
    203223/*****************************************************************************************
     
    214234 * automatically updates the FAT mapper from informations stored on device in case of miss.
    215235 *****************************************************************************************
    216  * @ mapper      : local pointer on the FAT mapper.
    217  * @ first       : index of the first FATFS cluster allocated to the file.
    218  * @ page    : index of searched page in the file.
    219  * @ cluster : [out] pointer on buffer for the found FATFS cluster index.
     236 * @ mapper              : local pointer on the FAT mapper.
     237 * @ first_cluster       : index of the first FATFS cluster allocated to the file.
     238 * @ searched_page   : index of searched page in the file.
     239 * @ cluster         : [out] pointer on buffer for the found FATFS cluster index.
    220240 * @ return 0 if success / return EIO if FAT mapper miss cannot be solved.
    221241 ****************************************************************************************/
     
    223243                           uint32_t          first_cluster,
    224244                           uint32_t          searched_page,
    225                            uint32_t        * cluster );
    226 
    227 
    228 
    229 
    230 //////////////////////////////////////////////////////////////////////////////////////////
    231 // These functions are called by the VFS, and must be implemented by all File Systems.
    232 //////////////////////////////////////////////////////////////////////////////////////////
    233 
    234 /******************************************************************************************
    235  * This function initializes the FATFS file system as the root FS.
    236  * It is executed cooperatively during kernel init by all CP0s in all clusters.
    237  * The initilisation is made in three phases, separated by synchronisation barrier:     
    238  * - phase 1 : all CP0s in all clusters allocate memory for the local copy of
    239  *   the FATFS context.
    240  * - phase 2 : cluster_0 only creates the root inode descriptor, access the external
    241  *   device to get information stored on the boot record, and initialises both
    242  *   the VFS context, and the FATFS context.
    243  * - phase 3 : all other clusters initialize their local VFS context and FATFS context
    244  *   from values contained in cluster_0, using hal_remote_memcpy().
    245  ******************************************************************************************
    246  * @ return an extended pointer on the created root inode / return XPTR_NULL if failure.
    247  *****************************************************************************************/
    248 xptr_t fatfs_init();
    249 
    250 /******************************************************************************************
    251  * This function mount the FATFS on the root FS.
    252  * TODO not implemented [AG]
    253  ******************************************************************************************
    254  * @ parent_inode_xp : extended pointer on the parent inode.
    255  *****************************************************************************************/
    256 error_t fatfs_mount( xptr_t parent_inode_xp );
    257 
    258 
    259 /*****************************************************************************************
    260  * This function  initializes both the VFS context and the FATFS context.
    261  * Both the VFS context and the FATFS context must have been previously allocated.
    262  * It access the device to read the boot record, and is supposed to be called only
    263  * in cluster_0 (in other clusters these contexts are replicated from values
    264  * contained in cluster_0).
    265  *****************************************************************************************
    266  * @ vfs_ctx        : local pointer on VFS context for FATFS.
    267  * @ fatfs_ctx      : local pointer on specific FATFS context.
    268  * @ root_inode_xp  : extended pointer on VFS root inode.
    269  ****************************************************************************************/
    270 error_t fatfs_ctx_init( struct vfs_ctx_s   * vfs_ctx,
    271                         struct fatfs_ctx_s * fatfs_ctx,
    272                         xptr_t               root_inode_xp );
    273 
    274 /*****************************************************************************************
    275  * This function releases memory dynamically allocated for the FATFS context extension.
    276  *****************************************************************************************
    277  * @ vfs_ctx   : local pointer on VFS context.
    278  ****************************************************************************************/
    279 void fatfs_ctx_destroy( struct vfs_ctx_s * vfs_ctx );
    280 
    281 
    282 
    283 /*****************************************************************************************
    284  * This function allocates memory for a FATFS inode, initializes it,
    285  * and link it to the VFS inode.
    286  *****************************************************************************************
    287  * @ inode         : local pointer on the VFS inode.
    288  * @ first_cluster : first cluster index in the FAT32.
    289  * @ return 0 if success / return ENOMEM if error.
    290  ****************************************************************************************/
    291 error_t fatfs_inode_create( struct vfs_inode_s * inode,
    292                             uint32_t             first_cluster);
    293 
    294 /*****************************************************************************************
    295  * This function releases memory allocated for a FATFS inode.
    296  *****************************************************************************************
    297  * @ inode   : local pointer on vfs_inode.
    298  ****************************************************************************************/
    299 void fatfs_inode_destroy( struct vfs_inode_s * inode );
    300 
    301 
    302 
    303 /*****************************************************************************************
    304  * This function moves a page from the mapper to the FATFS file system on device.
    305  * It must be called by a thread running in cluster containing the mapper.
    306  * The pointer on the mapper and the page index in file are registered
    307  * in the page descriptor.
    308  *****************************************************************************************
    309  * @ page    : local pointer on page descriptor.
    310  * @ return 0 if success / return EIO if error.
    311  ****************************************************************************************/
    312 error_t fatfs_write_page( struct page_s * page );
    313 
    314 /*****************************************************************************************
    315  * This function moves a page from the FATFS file system on device to the mapper.
    316  * It must be called by a thread running in cluster containing the mapper.
    317  * The pointer on the mapper and the page index in file are registered
    318  * in the page descriptor.
    319  *****************************************************************************************
    320  * @ page    : local pointer on page descriptor.
    321  * @ return 0 if success / return EIO if error.
    322  ****************************************************************************************/
    323 error_t fatfs_read_page( struct page_s * page );
    324 
    325 
    326 
     245                           uint32_t *        cluster );
    327246
    328247#endif  /* _FATFS_H_ */
Note: See TracChangeset for help on using the changeset viewer.