/**************************************************************************//* *//* Copyright (c) Microsoft Corporation. All rights reserved. *//* *//* This software is licensed under the Microsoft Software License *//* Terms for Microsoft Azure RTOS. Full text of the license can be *//* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA *//* and in the root directory of this software. *//* */.../**************************************************************************/.../**************************************************************************//**************************************************************************//** *//** FileX Component *//** *//** Fault Tolerant *//** */.../**************************************************************************//**************************************************************************/.../**************************************************************************//* *//* COMPONENT DEFINITION RELEASE *//* *//* fx_fault_tolerant.h PORTABLE C *//* 6.1 *//* AUTHOR *//* *//* William E. Lamie, Microsoft Corporation *//* *//* DESCRIPTION *//* *//* This file defines the FileX Fault Tolerant component constants, *//* data definitions, and external references. It is assumed that *//* fx_api.h (and fx_port.h) have already been included. *//* *//* RELEASE HISTORY *//* *//* DATE NAME DESCRIPTION *//* *//* 05-19-2020 William E. Lamie Initial Version 6.0 *//* 09-30-2020 William E. Lamie Modified comment(s), *//* resulting in version 6.1 *//* */.../**************************************************************************/#ifndef_FX_FAULT_TOLERANT_H_#define_FX_FAULT_TOLERANT_H_#ifdefFX_ENABLE_FAULT_TOLERANT#ifndefFX_FAULT_TOLERANT#error"FX_FAULT_TOLERANT must be defined with FX_ENABLE_FAULT_TOLERANT"#endif/* FX_FAULT_TOLERANT *//* Define ID of fault tolerant. */#defineFX_FAULT_TOLERANT_ID0x46544C52/* Define fault tolerant version. */#defineFX_FAULT_TOLERANT_VERSION_MAJOR0x01#defineFX_FAULT_TOLERANT_VERSION_MINOR0x00/* Define byte offset in boot sector where the cluster number of the Fault Tolerant Log file is. Note that this field (byte 116 to 119) is marked as reserved by FAT 12/16/32/exFAT specification. *//* ... */#ifndefFX_FAULT_TOLERANT_BOOT_INDEX#defineFX_FAULT_TOLERANT_BOOT_INDEX116#endif/* FX_FAULT_TOLERANT_BOOT_INDEX *//* Define the extension invoked when fault tolerant log is recovered or applied during enable API. */#ifndefFX_FAULT_TOLERANT_ENABLE_EXTENSION#defineFX_FAULT_TOLERANT_ENABLE_EXTENSION#endif/* FX_FAULT_TOLERANT_ENABLE_EXTENSION *//* Define the extension invoked when fault tolerant log is applied. */#ifndefFX_FAULT_TOLERANT_APPLY_LOGS_EXTENSION#defineFX_FAULT_TOLERANT_APPLY_LOGS_EXTENSION#endif/* FX_FAULT_TOLERANT_APPLY_LOGS_EXTENSION *//* If not-defined, default port-specific processing extensions to white space. */#ifndefFX_FAULT_TOLERANT_WRITE_LOG_FILE_EXTENSION#defineFX_FAULT_TOLERANT_WRITE_LOG_FILE_EXTENSION#endif/* FX_FAULT_TOLERANT_WRITE_LOG_FILE_EXTENSION *//* Define the maximum size of log file. */#defineFX_FAULT_TOLERANT_MAXIMUM_LOG_FILE_SIZE3072/* For backward compatibility, map the symbols deprecated to FX_FAULT_TOLERANT_MINIMAL_BUFFER_SIZE. */#ifndefFX_FAULT_TOLERANT_MINIMAL_CLUSTER#defineFX_FAULT_TOLERANT_MINIMAL_CLUSTERFX_FAULT_TOLERANT_MAXIMUM_LOG_FILE_SIZE#endif/* FX_FAULT_TOLERANT_MINIMAL_CLUSTER */#ifndefFX_FAULT_TOLERANT_MINIMAL_BUFFER_SIZE#defineFX_FAULT_TOLERANT_MINIMAL_BUFFER_SIZEFX_FAULT_TOLERANT_MAXIMUM_LOG_FILE_SIZE#endif/* FX_FAULT_TOLERANT_MINIMAL_BUFFER_SIZE *//* Define the states of the fault tolerant module. */#defineFX_FAULT_TOLERANT_STATE_IDLE0x00u#defineFX_FAULT_TOLERANT_STATE_STARTED0x01u#defineFX_FAULT_TOLERANT_STATE_SET_FAT_CHAIN0x02u/* Define types of logs. */#defineFX_FAULT_TOLERANT_FAT_LOG_TYPE1#defineFX_FAULT_TOLERANT_DIR_LOG_TYPE2#defineFX_FAULT_TOLERANT_BITMAP_LOG_TYPE3/* Define operations of FAT chain. */#defineFX_FAULT_TOLERANT_FAT_CHAIN_RECOVER0/* Recover new FAT chain. */#defineFX_FAULT_TOLERANT_FAT_CHAIN_CLEANUP1/* Cleanup old FAT chain. *//* Define flags for FAT chain log. */#defineFX_FAULT_TOLERANT_FLAG_FAT_CHAIN_VALID0x01#defineFX_FAULT_TOLERANT_FLAG_BITMAP_USED0x02/* Define size of each section in log file. */#defineFX_FAULT_TOLERANT_LOG_HEADER_SIZEsizeof(FX_FAULT_TOLERANT_LOG_HEADER)#defineFX_FAULT_TOLERANT_FAT_CHAIN_SIZEsizeof(FX_FAULT_TOLERANT_FAT_CHAIN)#defineFX_FAULT_TOLERANT_LOG_CONTENT_HEADER_SIZEsizeof(FX_FAULT_TOLERANT_LOG_CONTENT)/* Define offset of each section in log file. */#defineFX_FAULT_TOLERANT_FAT_CHAIN_OFFSET(FX_FAULT_TOLERANT_LOG_HEADER_SIZE)#defineFX_FAULT_TOLERANT_LOG_CONTENT_OFFSET(FX_FAULT_TOLERANT_LOG_HEADER_SIZE+FX_FAULT_TOLERANT_FAT_CHAIN_SIZE)/* Define size of log entries. *//* The total size of DIR log entry is variable. 16 is the fixed size of DIR log entry. */#defineFX_FAULT_TOLERANT_FAT_LOG_ENTRY_SIZEsizeof(FX_FAULT_TOLERANT_FAT_LOG)#defineFX_FAULT_TOLERANT_BITMAP_LOG_ENTRY_SIZEsizeof(FX_FAULT_TOLERANT_BITMAP_LOG)#defineFX_FAULT_TOLERANT_DIR_LOG_ENTRY_SIZEsizeof(FX_FAULT_TOLERANT_DIR_LOG)18 defines#ifdefFX_FAULT_TOLERANT_TRANSACTION_FAIL_FUNCTION#defineFX_FAULT_TOLERANT_TRANSACTION_FAIL_fx_fault_tolerant_transaction_fail#else/* Define transaction fail for fault tolerant. */#defineFX_FAULT_TOLERANT_TRANSACTION_FAIL(m)\if((m)->fx_media_fault_tolerant_enabled==FX_TRUE)\{\(m)->fx_media_fault_tolerant_transaction_count--;\if((m)->fx_media_fault_tolerant_transaction_count==0)\{\_fx_fault_tolerant_recover(m);\_fx_fault_tolerant_reset_log_file(m);\...}\...}.../* ... */#endif/* FX_FAULT_TOLERANT_TRANSACTION_FAIL_FUNCTION *//* Log file format * The entire log file fits into one cluster. * * 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + ID + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + Total Log Size (in Bytes) + Header Checksum + Log Header * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + version major + version minor + reserved + * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + Checksum of FAT chain + Flag | Reserved + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + Insertion Point - Front + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + Head cluster of newly created FAT chain + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ FAT Chain * + Head cluster of original FAT chain + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + Insertion Point - Back + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + Next Deletion Point + * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + checksum of log content + count of log entries + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + (log 0) . + * + . + * + . + * + . + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + (log 1) . + * + . + Log Entries * + . + * + . + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + ... + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + (log N) . + * + . + * + . + * + . + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * * * Log Header * * * ID: It is fixed value FX_FAULT_TOLERANT_ID. * * Total Size: Total size (in bytes) of the log file, including Log Header, FAT Chain and Log Entries * * Header Checksum: It is the checksum of all data in log header. * * Version Major: The major version number. * * Version Minor: The minor version number. * * Reserved: Reserved for future use. * * FAT Chain * * * Checksum of FAT chain: It is the checksum of all data in the FAT Chain section. * * Flag: 8 bits. The 1-6 bits are not used (from left to right). * bit 7: When set, bitmap is used in old FAT chain. * bit 8: When set, FAT chain is valid. * * Reserved: Reserved for future use. * * Insertion Point - Front: The cluster where the newly created chain is attached to * * Head cluster of new FAT chain. It is the head cluster of new FAT chain. * * Head cluster of oritinal FAT chain. It is the head cluster of the original FAT chain, * which will be removed. * * Inswertion Point - Back: The original cluster right after the newly created chain is inserted. * * Next Deletion Point: next session of cluster to delete. It is used during deleting FAT chain. * The deltion is carried out in stages for perofmrance reasons. When delting a FAT chain, the * Next Deletion Point is chosen, and the chain between head and the Next Deletion Point is deleted. * * Log Entries: * * * Checksum of log entries: It is the checksum of all data in Log Entries * * Counter of log entries: It is the counter of all log entries in Log content. * * log 0 ... log N: Log entries. The formats are described below. *//* ... *//* Defined structure of log header. *//* ... */typedefstructFX_FAULT_TOLERANT_LOG_HEADER_STRUCT{ULONGfx_fault_tolerant_log_header_id;USHORTfx_fault_tolerant_log_header_total_size;USHORTfx_fault_tolerant_log_header_checksum;UCHARfx_fault_tolerant_log_header_version_major;UCHARfx_fault_tolerant_log_header_version_minor;USHORTfx_fault_tolerant_log_header_reserved;...}FX_FAULT_TOLERANT_LOG_HEADER;/* Define structure of FAT chain. */typedefstructFX_FAULT_TOLERANT_FAT_CHAIN_STRUCT{USHORTfx_fault_tolerant_FAT_chain_checksumm;UCHARfx_fault_tolerant_FAT_chain_flag;UCHARfx_fault_tolerant_FAT_chain_reserved;ULONGfx_fault_tolerant_FAT_chain_insertion_front;ULONGfx_fault_tolerant_FAT_chain_head_new;ULONGfx_fault_tolerant_FAT_chain_head_original;ULONGfx_fault_tolerant_FAT_chain_insertion_back;ULONGfx_fault_tolerant_FAT_chain_next_deletion;...}FX_FAULT_TOLERANT_FAT_CHAIN;/* Define structure of Log content. */typedefstructFX_FAULT_TOLERANT_LOG_CONTENT_STRUCT{USHORTfx_fault_tolerant_log_content_checksum;USHORTfx_fault_tolerant_log_content_count;...}FX_FAULT_TOLERANT_LOG_CONTENT;/* 3 types of log entries are defined. *//* FAT log format * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + type + size + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + cluster + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + value + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * * Description: * * Type: FX_FAULT_TOLERANT_FAT_LOG. * Size: The size of this log entry. * Cluster: The cluster number in FAT. * Value: The value of cluster in FAT. * *//* ... */typedefstructFX_FAULT_TOLERANT_FAT_LOG_STRUCT{USHORTfx_fault_tolerant_FAT_log_type;USHORTfx_fault_tolerant_FAT_log_size;ULONGfx_fault_tolerant_FAT_log_cluster;ULONGfx_fault_tolerant_FAT_log_value;...}FX_FAULT_TOLERANT_FAT_LOG;/* DIR log format * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + type + size + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + sector offset + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + log sector + * + + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + log data + * + . + * + . + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * * Fields description, * * Type: FX_FAULT_TOLERANT_DIRECTORY_LOG * Size: The size of this log entry. * Sector Offset: The offset in original sector this DIR is trying to write to. * Log Sector: The original sector this DIR is trying to write to. * Log Data: Content of DIR entries. * *//* ... */typedefstructFX_FAULT_TOLERANT_DIR_LOG_STRUCT{USHORTfx_fault_tolerant_dir_log_type;USHORTfx_fault_tolerant_dir_log_size;ULONGfx_fault_tolerant_dir_log_offset;ULONG64fx_fault_tolerant_dir_log_sector;...}FX_FAULT_TOLERANT_DIR_LOG;/* Bitmap log format * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + type + size + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + cluster + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * + value + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * * Description, * * Type: FX_FAULT_TOLERANT_BITMAP_LOG. * Size: The size of this log entry. * Cluster: The cluster number in FAT. * Value: The value of cluster in FAT. *//* ... */typedefstructFX_FAULT_TOLERANT_BITMAP_LOG_STRUCT{USHORTfx_fault_tolerant_bitmap_log_type;USHORTfx_fault_tolerant_bitmap_log_size;ULONGfx_fault_tolerant_bitmap_log_cluster;ULONGfx_fault_tolerant_bitmap_log_value;...}FX_FAULT_TOLERANT_BITMAP_LOG;/* This function checks whether or not the log file exists, and creates the log file if it does not exist. */UINT_fx_fault_tolerant_enable(FX_MEDIA*media_ptr,VOID*memory_buffer,UINTmemory_size);UINT_fxe_fault_tolerant_enable(FX_MEDIA*media_ptr,VOID*memory_buffer,UINTmemory_size);/* This function resets statistics and marks the start of a transaction. */UINT_fx_fault_tolerant_transaction_start(FX_MEDIA*media_ptr);/* This function marks the end of a transaction and completes the log file. * Then it applies all data in the log file to the file system. * Finally it resets the log header section. *//* ... */UINT_fx_fault_tolerant_transaction_end(FX_MEDIA*media_ptr);/* This function resets the log file. */UINT_fx_fault_tolerant_reset_log_file(FX_MEDIA*media_ptr);/* This function applies the log file to the file system. */UINT_fx_fault_tolerant_apply_logs(FX_MEDIA*media_ptr);/* This function recovers FAT chain. */UINT_fx_fault_tolerant_recover(FX_MEDIA*media_ptr);/* This function adds a FAT log entry. */UINT_fx_fault_tolerant_add_FAT_log(FX_MEDIA*media_ptr,ULONGcluster,ULONGvalue);/* This function adds a directory log entry. */UINT_fx_fault_tolerant_add_dir_log(FX_MEDIA*media_ptr,ULONG64logical_sector,ULONGoffset,UCHAR*data,ULONGdata_size);#ifdefFX_ENABLE_EXFAT/* This function adds a bitmap log entry. */UINT_fx_fault_tolerant_add_bitmap_log(FX_MEDIA*media_ptr,ULONGcluster,ULONGvalue);/* This function adds a checksum log entry. */UINT_fx_fault_tolerant_add_checksum_log(FX_MEDIA*media_ptr,ULONG64logical_sector,ULONGoffset,USHORTchecksum);/* ... */#endif/* FX_ENABLE_EXFAT *//* This function sets the FAT chain. */UINT_fx_fault_tolerant_set_FAT_chain(FX_MEDIA*media_ptr,UINTuse_bitmap,ULONGinsertion_front,ULONGnew_head_cluster,ULONGoriginal_head_cluster,ULONGinsertion_back);/* This function reads a FAT entry from log file. If it doesn't exist in log file, return and read from FAT entry directly. */UINT_fx_fault_tolerant_read_FAT(FX_MEDIA*media_ptr,ULONGcluster,ULONG*value,ULONGlog_type);/* This function reads directory sector from log file. */UINT_fx_fault_tolerant_read_directory_sector(FX_MEDIA*media_ptr,ULONG64logical_sector,VOID*buffer_ptr,ULONG64sectors);/* This function calculates the checksum of the log header. */USHORT_fx_fault_tolerant_calculate_checksum(UCHAR*data,UINTlen);/* This function cleans up FAT chain. */UINT_fx_fault_tolerant_cleanup_FAT_chain(FX_MEDIA*media_ptr,UINToperation);/* This function reads log file from file system to memory buffer. */UINT_fx_fault_tolerant_read_log_file(FX_MEDIA*media_ptr);/* This function writes data of one sector from memory to log file in file system. */UINT_fx_fault_tolerant_write_log_file(FX_MEDIA*media_ptr,ULONGrelative_sector);/* This function creates log file. */UINT_fx_fault_tolerant_create_log_file(FX_MEDIA*media_ptr);#ifdefFX_FAULT_TOLERANT_TRANSACTION_FAIL_FUNCTION/* This function cleans up resources created by fault tolerant when transaction fails. */UINT_fx_fault_tolerant_transaction_fail(FX_MEDIA*media_ptr);/* ... */#endif/* FX_FAULT_TOLERANT_TRANSACTION_FAIL_FUNCTION *//* ... */#endif/* FX_ENABLE_FAULT_TOLERANT *//* ... */#endif/* _FX_FAULT_TOLERANT_H_ */...
Details
Show: from
Types: Columns:
All items filtered out
All items filtered out
This file uses the notable symbols shown below. Click anywhere in the file to view more details.