Changeset 626 for trunk/kernel/fs/fatfs.h
- Timestamp:
- Apr 29, 2019, 7:25:09 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/fs/fatfs.h
r625 r626 173 173 /***************************************************************************************** 174 174 * This structure defines a FATFS specific context (extension to VFS context). 175 * This extension is replicated in all clusters. 176 * 177 * WARNING : Almost all fields are constant values, but the <free_cluster_hint> and 178 * <free_clusters> are shared variables. All kernel instances use the variables 179 * in cluster 0, using the <free_lock> remote busy_lock for exclusive access. 175 * This fatfs context is replicated in all clusters. 176 * 177 * WARNING : Almost all fields are constant values, but the <free_cluster_hint>, 178 * <free_clusters> and <free_lock> are shared variables. Moreover, the <fs_info_buffer>, 179 * only allocated in cluster 0, contains a copy of the FS_INFO sector. It is used by all 180 * kernel instances to synchronously update the free clusters info on IOC device. 181 * For these four variables, all kernel instances must use the values in cluster 0, 182 * and take the <free_lock> stored in this cluster for exclusive access to FAT. 180 183 ****************************************************************************************/ 181 184 182 185 typedef struct fatfs_ctx_s 183 186 { 187 /* read-only constants replicated in all clusters */ 184 188 uint32_t fat_sectors_count; /*! number of sectors in FAT region */ 185 189 uint32_t bytes_per_sector; /*! number of bytes per sector */ … … 190 194 uint32_t root_dir_cluster; /*! cluster index for root directory */ 191 195 xptr_t fat_mapper_xp; /*! extended pointer on FAT mapper */ 196 197 /* shared variables (only the copy in FAT cluster must be used) */ 192 198 uint32_t free_cluster_hint; /*! cluster[hint+1] is the first free */ 193 199 uint32_t free_clusters; /*! free clusters number */ 194 remote_queuelock_t free_lock; /*! exclusive access to hint & number */ 200 remote_queuelock_t free_lock; /*! exclusive access to FAT */ 201 uint8_t * fs_info_buffer; /*! local pointer on FS_INFO buffer */ 195 202 } 196 203 fatfs_ctx_t; … … 224 231 225 232 /***************************************************************************************** 226 * This function display the content of the local FATFS context. 227 ***************************************************************************************** 228 * @ ctx : local pointer on the context. 229 ****************************************************************************************/ 230 void fatfs_ctx_display( fatfs_ctx_t * ctx ); 231 232 /***************************************************************************************** 233 * This function displays the content of a part of the File Allocation Table. 234 * It loads the requested page fom device to mapper if required. 235 ***************************************************************************************** 236 * @ page_id : page index in FAT mapper (one page is 4 Kbytes). 237 * @ nentries : number of entries (one entry is 4 bytes). 233 * This function display the content of the FATFS context copy in cluster identified 234 * by the <cxy> argument. 235 * This function can be called by a thread running in any cluster. 236 ***************************************************************************************** 237 * @ cxy : target cluster identifier. 238 ****************************************************************************************/ 239 void fatfs_display_ctx( cxy_t cxy ); 240 241 /***************************************************************************************** 242 * This function access the FAT mapper to display one page of the File Allocation Table. 243 * It loads the requested page fom IOC device to FAT mapper if required. 244 * This function can be called by a thread running in any cluster. 245 ***************************************************************************************** 246 * @ page_id : page index in FAT mapper (one page is 4 Kbytes). 247 * @ nb_entries : number of entries (one entry is 4 bytes). 238 248 ****************************************************************************************/ 239 249 void fatfs_display_fat( uint32_t page_id, 240 uint32_t n entries );250 uint32_t nb_entries ); 241 251 242 252 … … 254 264 255 265 /***************************************************************************************** 256 * This function access the boot device, and initialises the local FATFS context 257 * from informations contained in the boot record. 266 * This function access the boot device, and initialises the local FATFS context, 267 * from informations contained in the boot record. This initialisation includes the 268 * creation of the FAT mapper in cluster 0. 258 269 ***************************************************************************************** 259 270 * @ vfs_ctx : local pointer on VFS context for FATFS. … … 271 282 * This function implements the generic vfs_fs_add_dentry() function for the FATFS. 272 283 ***************************************************************************************** 273 * This function updates a directory identified by the <inode> argument284 * This function updates a directory mapper identified by the <inode> argument 274 285 * to add a new directory entry identified by the <dentry> argument. 275 * All modified pages in directory mapper are synchronously updated on IOC device.276 * It must be called by a thread running in the cluster containing the inode.286 * All modified pages in the directory mapper are synchronously updated on IOC device. 287 * It must be called by a thread running in the cluster containing the directory inode. 277 288 * 278 289 * Implementation note : this function works in two steps: … … 313 324 * This function implements the generic vfs_fs_new_dentry() function for the FATFS. 314 325 ***************************************************************************************** 315 * It initializes a new inode/dentry couple in Inode Tree, attached to the directory316 * identified by the <parent_inode> argument. The directory entry is identified317 * by the <name> argument. The child inode descriptor, identified by the <child_inode_xp>318 * argument, and the associated dentry descriptor must have been previously allocated.319 * It scan the parent mapper to find the <name> argument.320 * It set the "type", "size", and "extend" fields in the child inode descriptor.321 * It set the " extend" field in the dentry descriptor.326 * It scan a parent directory mapper, identified by the <parent_inode> argument to find 327 * a directory entry identified by the <name> argument. In case of success, it 328 * initializes the inode/dentry couple, identified by the <child_inode_xp> argument 329 * in the Inode Tree. The child inode descriptor, and the associated dentry descriptor 330 * must have been previously allocated by the caller. 331 * - It set the "type", "size", and "extend" fields in the child inode descriptor. 332 * - It set the " extend" field in the dentry descriptor. 322 333 * It must be called by a thread running in the cluster containing the parent inode. 323 334 ***************************************************************************************** … … 325 336 * @ name : child name. 326 337 * @ child_inode_xp : extended pointer on remote child inode (file or directory). 327 * @ return 0 if success / return ENOENTif child not found.338 * @ return 0 if success / return -1 if child not found. 328 339 ****************************************************************************************/ 329 340 error_t fatfs_new_dentry( struct vfs_inode_s * parent_inode, … … 392 403 ***************************************************************************************** 393 404 * @ inode : local pointer on inode. 394 * @ return 0 if success / return EIO if failure duringdevice access.405 * @ return 0 if success / return -1 if failure during IOC device access. 395 406 ****************************************************************************************/ 396 407 error_t fatfs_sync_inode( struct vfs_inode_s * inode ); … … 399 410 * This function implements the generic vfs_fs_sync_fat() function for the FATFS. 400 411 ***************************************************************************************** 401 * It updates the FAT FSon the IOC device for the FAT itself.412 * It updates the FAT on the IOC device for the FAT itself. 402 413 * It scan all clusters registered in the FAT mapper, and copies from mapper to device 403 414 * each page marked as dirty. … … 408 419 * variables defining the smallest/largest dirty page index in FAT mapper... 409 420 ***************************************************************************************** 410 * @ return 0 if success / return EIO if failure duringdevice access.421 * @ return 0 if success / return -1 if failure during IOC device access. 411 422 ****************************************************************************************/ 412 423 error_t fatfs_sync_fat( void ); … … 415 426 * This function implements the generic vfs_fs_sync_fsinfo() function for the FATFS. 416 427 ***************************************************************************************** 417 * It updates the FS_INFO sector on the IOC device. 418 * It copies the <free_cluster_hint> and <free_clusters> variables from 419 * the FATFS context in cluster 0 to the FS_INFO sector on device. 420 ***************************************************************************************** 421 * @ return 0 if success / return EIO if failure during device access. 428 * It checks the current values of the "free_clusters" and "free_cluster_hint" variables 429 * in the FS_INFO sector on IOC, versus the values stored in the fatfs context. 430 * As these values are synchronously updated on IOC device at each modification, 431 * it does nothing if the values are equal. It updates the FS_INFO sector on IOC device, 432 * and displays a warning message on TXT0 if they are not equal. 433 * This function can be called by any thread running in any cluster. 434 ***************************************************************************************** 435 * @ return 0 if success / return -1 if failure during IOC device access. 422 436 ****************************************************************************************/ 423 437 error_t fatfs_sync_free_info( void ); … … 430 444 * It can be called by a thread running in any cluster, as it uses remote access 431 445 * primitives when the FAT mapper is remote. It takes the queuelock stored in the FATFS 432 * context (located in the same cluster as the FAT mapper itself), to get exclusive433 * access to the FAT. It uses the <free_cluster_hint> and <free_clusters> variables434 * stored in this FATFS context.446 * context located in the same cluster as the FAT mapper itself, to get exclusive 447 * access to the FAT. It uses and updates the <free_cluster_hint> and <free_clusters> 448 * variables stored in this FATFS context. 435 449 * - it updates the <free_cluster_hint> and <free_clusters> variables in FATFS context. 436 450 * - it updates the FAT mapper (handling miss from IOC device if required). … … 445 459 /***************************************************************************************** 446 460 * This function implements the generic vfs_fs_release_inode() function for the FATFS. 447 *****************************************************************************************461 ***************************************************************************************** 448 462 * It releases all clusters allocated to a file/directory identified by the <inode_xp> 449 463 * argument. All released clusters are marked FREE_CLUSTER in the FAT mapper. … … 466 480 * The pointer on the mapper and the page index in file are found in the page descriptor. 467 481 * It is used for both a regular file/directory mapper, and the FAT mapper. 468 * For the FAT mapper, it access the FATFS to get the location on IOC device.469 * For a regular file, it access the FAT mapper to get the cluster index on IOC device.482 * - For the FAT mapper, it updates the FAT region on IOC device. 483 * - For a regular file, it access the FAT mapper to get the cluster index on IOC device. 470 484 * It can be called by any thread running in any cluster. 471 485 *
Note: See TracChangeset
for help on using the changeset viewer.