/*
 *            Copyright (c) 1998-2003 by NETsilicon Inc.
 *
 *  This software is copyrighted by and is the sole property of 
 *  NETsilicon.  All rights, title, ownership, or other interests
 *  in the software remain the property of NETsilicon.  This
 *  software may only be used in accordance with the corresponding
 *  license agreement.  Any unauthorized use, duplication, transmission,  
 *  distribution, or disclosure of this software is expressly forbidden.
 *
 *  This Copyright notice may not be removed or modified without prior
 *  written consent of NETsilicon.
 *
 *  NETsilicon, reserves the right to modify this software
 *  without notice.
 *
 *  NETsilicon
 *  411 Waverley Oaks Road                  USA 781.647.1234
 *  Suite 304                               http://www.netsilicon.com
 *  Waltham, MA 02452                       AmericaSales@netsilicon.com
 *
 *************************************************************************/
 /*
  * Edit History
  *
  * Initials		Date		Change Description
  * jzw				8/31/04		Added a note to the File system group ID masks entry
  *                             to more fully describe the way group IDs work
  *                             Reference vantive 14058
  */


#ifndef fs_h

#define fs_h

#include <tx_api.h>
#include <time.h>
#ifdef __cplusplus
extern "C"
{
#endif
/**
 * Flash Storage Services options
 *
 * @external
 * @category fileSystem
 * @since 6.0
 * @name flash_options    "File System Flash Services Options"
 *
 * @param NAFS_MOST_DIRTY_SECTOR                   Transfer the sector with the most dirty blocks.
 * @param NAFS_RANDOM_DIRTY_SECTOR                 Transfer a randomly selected sector with dirty blocks.
 * @param NAFS_TRACK_SECTOR_ERASES                 Enable sector erase tracking.                          
 * @param NAFS_BACKGROUND_COMPACTING               Enable the background sector compacting thread.
 */
#define NAFS_MOST_DIRTY_SECTOR                 (unsigned int)0x1      
#define NAFS_RANDOM_DIRTY_SECTOR               (unsigned int)0x2      
#define NAFS_TRACK_SECTOR_ERASES               (unsigned int)0x4      
#define NAFS_BACKGROUND_COMPACTING             (unsigned int)0x8      


/**
 * File system configuration
 *
 * @external
 * @category fileSystem
 * @since 6.0
 * @name file_sys_volume    "File System Configuration Options"
 *
 * @param NAFS_VOLUME_NAME_SIZE                  16                     
 * @param NAFS_VOLUMES_PER_MEDIA                 8                      
 * @param NAFS_BLOCK_SIZE_512                    512                    
 * @param NAFS_BLOCK_SIZE_1K                     1024                   
 * @param NAFS_BLOCK_SIZE_2K                     2048    
 * @param NAFS_BLOCK_SIZE_4K                     4096
 * @param NAFS_ENABLE_POWER_LOSS_RECOVERY        Bitmask to enable the power loss recovery option.
 * @param NAFS_NO_RTC                            Bitmask to disable using the time() function for timestamps.
 * @param NAFS_INIT_STATUS                       Bitmask to return SUPER BLOCK status from NAFScreate_volume().
 *
 */
#define NAFS_VOLUME_NAME_SIZE                  16
#define NAFS_VOLUMES_PER_MEDIA                 8                       
#define NAFS_BLOCK_SIZE_512                    512                     
#define NAFS_BLOCK_SIZE_1K                     1024                    
#define NAFS_BLOCK_SIZE_2K                     2 * NAFS_BLOCK_SIZE_1K       
#define NAFS_BLOCK_SIZE_4K                     4 * NAFS_BLOCK_SIZE_1K
#define NAFS_ENABLE_POWER_LOSS_RECOVERY        (unsigned int)0x1
#define NAFS_NO_RTC                            (unsigned int)0x2
#define NAFS_INIT_STATUS                       (unsigned int)0x4

#define NAFS_MIN_BLOCK_SIZE                    NAFS_BLOCK_SIZE_512     /* mininum block size                         */
#define NAFS_MAX_BLOCK_SIZE                    NAFS_BLOCK_SIZE_4K      /* maximum block size                         */
#define NAFS_MAX_OPEN_DIRS                     64                      /* maximum number of open directories         */
#define NAFS_MAX_OPEN_FILES                    64                      /* maximum number of open files per directory */

    
/*
 * Media type definitions
 */
#define NAFS_MAX_MEDIA_TYPES                   8                       /* maximum number of media types supported  */


/**
 * Write options
 *
 * @external
 * @category fileSystem
 * @since 6.0
 * @name write_options    "File System NAFSwrite_file() Options"
 *
 * @param NAFS_RANDOM_WRITE         Random file write and append.
 * @param NAFS_ZERO_OFFSET_ERASE    Overwrite and erase file if file offset is zero.
 * @param NAFS_ERASE_DATA           Erase the file's data.
 */
#define NAFS_RANDOM_WRITE           0
#define NAFS_ZERO_OFFSET_ERASE      1
#define NAFS_ERASE_DATA             2

    
/**
 * Media Type Definitions
 *
 * @external
 * @category fileSystem
 * @since 6.0
 * @name media_type    "File System Media Types"
 *
 * @param NAFS_MEDIA0         Media type 0.
 * @param NAFS_MEDIA1         Media type 1.
 * @param NAFS_MEDIA2         Media type 2.
 * @param NAFS_MEDIA3         Media type 3.
 * @param NAFS_MEDIA4         Media type 4.
 * @param NAFS_MEDIA5         Media type 5.
 * @param NAFS_MEDIA6         Media type 6.
 * @param NAFS_MEDIA7         Media type 7.
 */
#define NAFS_MEDIA0                            0
#define NAFS_MEDIA1                            1
#define NAFS_MEDIA2                            2
#define NAFS_MEDIA3                            3
#define NAFS_MEDIA4                            4
#define NAFS_MEDIA5                            5
#define NAFS_MEDIA6                            6
#define NAFS_MEDIA7                            7

/**
 * File system manifest constant
 *
 * @external
 * @category fileSystem
 * @since 6.0  
 * @name file_sys_media    "File System Internal Thread and Queue Name Sizes"
 *
 * @param  NAFS_MEDIA_THREAD_NAME_SIZE    The maximum size of the thread name string.
 * @param  NAFS_MEDIA_QUEUE_NAME_SIZE     The maximum size of the queue name string.
 */
#define NAFS_MEDIA_THREAD_NAME_SIZE            16                    
#define NAFS_MEDIA_QUEUE_NAME_SIZE             16

/**
 * File system manifest constant
 *
 * @external
 * @category fileSystem
 * @since 6.0  
 * @name file_sys_size    "File System Memory Allocation Limits"
 *
 * @param NAFS_MAX_BUFFER_POOL_SIZE       The maximum size of the buffer pool.
 * @param NAFS_MIN_BUFFER_POOL_SIZE       The mininum size of the buffer pool.
 * @param NAFS_MIN_STACK_SIZE             The mininum stack size.
 * @param NAFS_MIN_MSG_QUEUE_SIZE         The mininum message queue size.
 */
#define NAFS_MAX_BUFFER_POOL_SIZE              256                    
#define NAFS_MIN_BUFFER_POOL_SIZE              16                     
#define NAFS_MIN_STACK_SIZE                    8 * 1024               
#define NAFS_MIN_MSG_QUEUE_SIZE                4                      

/*
 * Directory and file definitions
 */
#define NAFS_MAX_DIR_PATH_SIZE                 256                     /* maximum size of the directory path string */
#define NAFS_DIRECTORY_PATH_SIZE               NAFS_MAX_DIR_PATH_SIZE
#define NAFS_MIN_DIR_PATH_SIZE                 2                       /* minimum size of the directory path string */
#define NAFS_DIR_NAME_SIZE                     64                      /* maximum size of a file or directory name  */
#define NAFS_FILE_NAME_SIZE                    NAFS_DIR_NAME_SIZE      /* maximum file name size                    */

/*
 * Inode file types
 */
#define NAFS_FILE_TYPE_UNUSED                  0                       /* flag to indicate file is unused           */
#define NAFS_FILE_TYPE_FILE                    1                       /* flag to indicate a file                   */
#define NAFS_FILE_TYPE_DIR                     2                       /* flag to indicate a directory              */

    
/**
 * IO request control block "status" definitions
 *
 * @external
 * @category fileSystem
 * @since 6.0
 * @name status_types    "File System I/O Request Status"
 *
 * @param NAFS_IO_REQUEST_FREE                       The I/O request control block is not being used.
 * @param NAFS_IO_REQUEST_PENDING                    The I/O request is in the message queue.
 * @param NAFS_IO_REQUEST_PROCESSING                 The I/O request is being processed.
 * @param NAFS_IO_REQUEST_COMPLETED                  The I/O request was completed.
 * @param NAFS_IO_REQUEST_TERMINATED                 The I/O request was terminated.
 */
#define NAFS_IO_REQUEST_FREE                   0                      
#define NAFS_IO_REQUEST_PENDING                1                      
#define NAFS_IO_REQUEST_PROCESSING             2                      
#define NAFS_IO_REQUEST_COMPLETED              3                      
#define NAFS_IO_REQUEST_TERMINATED             4                      

/**
 * I/O request control block request types.
 * @category fileSystem
 * @external
 * @since 6.0
 * @name request_types    "File System I/O Request Types"
 *
 * @param NAFS_REQUEST_CREATE_FILE               Create file request.
 * @param NAFS_REQUEST_DELETE_FILE               Delete file request.
 * @param NAFS_REQUEST_RENAME_FILE               Rename file request.
 * @param NAFS_REQUEST_OPEN_FILE                 Open file request.
 * @param NAFS_REQUEST_WRITE_FILE                Write file request.
 * @param NAFS_REQUEST_READ_FILE                 Read file request.
 * @param NAFS_REQUEST_CLOSE_FILE                Close file request.
 * @param NAFS_REQUEST_CREATE_DIR                Create dir request.
 * @param NAFS_REQUEST_DELETE_DIR                Delete dir request.
 * @param NAFS_REQUEST_RENAME_DIR                Rename file request.
 * @param NAFS_REQUEST_DIR_ENTRY_COUNT           Directory entry count request.
 * @param NAFS_REQUEST_LIST_DIR                  List directory request.
 * @param NAFS_REQUEST_OPEN_FILE_SIZE            Opened file size request.
 */
#define NAFS_REQUEST_CREATE_FILE               0                       
#define NAFS_REQUEST_DELETE_FILE               1                       
#define NAFS_REQUEST_RENAME_FILE               2                       
#define NAFS_REQUEST_OPEN_FILE                 3                       
#define NAFS_REQUEST_WRITE_FILE                4                       
#define NAFS_REQUEST_READ_FILE                 5                       
#define NAFS_REQUEST_CLOSE_FILE                6                       
#define NAFS_REQUEST_CREATE_DIR                7                       
#define NAFS_REQUEST_DELETE_DIR                8                       
#define NAFS_REQUEST_RENAME_DIR                9                       
#define NAFS_REQUEST_DIR_ENTRY_COUNT           10                      
#define NAFS_REQUEST_LIST_DIR                  11                      
#define NAFS_REQUEST_OPEN_FILE_SIZE            12

/**
 * File system group ID masks
 *
 * @external
 * @category fileSystem
 * @since 6.0
 * @name group_masks    "File System Group ID Numbers"
 *
 * @note	Group ID numbers are stored as bit positions within a
 *			bit mask. Each group ID number "n" is represented by
 *			the "nth" bit position being turned on. As you can see
 *			from the included table (above), group 1 has bit one turned on, 
 *			group 2 has bit 2 turned on, group 3 has bit 3 turned on 
 *			and so on. When users perform file operations such as dir 
 *			or ls, the group ID number that is displayed will be 
 *			representitive of this masking approach.
 *
 * @param NAFS_FS_GROUP1                       0x00000001
 * @param NAFS_FS_GROUP2                       0x00000002
 * @param NAFS_FS_GROUP3                       0x00000004
 * @param NAFS_FS_GROUP4                       0x00000008
 * @param NAFS_FS_GROUP5                       0x00000010
 * @param NAFS_FS_GROUP6                       0x00000020
 * @param NAFS_FS_GROUP7                       0x00000040
 * @param NAFS_FS_GROUP8                       0x00000080
 */
#define NAFS_FS_GROUP1                       (unsigned int)0x00000001
#define NAFS_FS_GROUP2                       (unsigned int)0x00000002
#define NAFS_FS_GROUP3                       (unsigned int)0x00000004
#define NAFS_FS_GROUP4                       (unsigned int)0x00000008
#define NAFS_FS_GROUP5                       (unsigned int)0x00000010
#define NAFS_FS_GROUP6                       (unsigned int)0x00000020
#define NAFS_FS_GROUP7                       (unsigned int)0x00000040
#define NAFS_FS_GROUP8                       (unsigned int)0x00000080

/**
 * File system error codes
 *
 * @external
 * @category fileSystem
 * @since 6.0
 * @name file_sys_errors    "File System Error Codes"
 *
 * @param NAFS_SUCCESS                            0
 * @param NAFS_INVALID_VOLUME_NAME               -1
 * @param NAFS_INVALID_BLOCK_NUMBER              -2
 * @param NAFS_SERVICES_NOT_READY                -3
 * @param NAFS_BLOCK_NOT_MAPPED                  -4
 * @param NAFS_NO_FREE_BLOCKS                    -5
 * @param NAFS_WRITE_FAILED                      -6
 * @param NAFS_INVALID_BLOCK                     -7
 * @param NAFS_DELETE_FAILED                     -8
 * @param NAFS_NULL_POINTER                      -9
 * @param NAFS_INVALID_RAM_VOLUME                -10
 * @param NAFS_INVALID_FLASH_VOLUME              -11
 * @param NAFS_UNKNOWN_FLASH                     -12
 * @param NAFS_MALLOC_FAILED                     -13
 * @param NAFS_ALREADY_INITIALIZED               -14
 * @param NAFS_INVALID_WRITE_OPTION              -15
 * @param NAFS_BLOCK_SCAN_FAILED                 -16
 * @param NAFS_NO_TRANSFER_SECTOR                -17
 * @param NAFS_READ_FAILED                       -18
 * @param NAFS_SEMAPHORE_CREATE_FAILED           -19
 * @param NAFS_THREAD_CREATE_FAILED              -20
 * @param NAFS_IBLOCK_ARRAY_ENTRY_INCONSISTENT   -21
 * @param NAFS_IBLOCK_ARRAY_ENTRY_NOT_FOUND      -22
 * @param NAFS_END_OF_FILE                       -23
 * @param NAFS_SUPER_BLOCK_CORRUPTED             -24
 * @param NAFS_DATA_CORRUPTED                    -25
 * @param NAFS_SERVICES_TABLE_FULL               -26
 * @param NAFS_INVALID_VOLUME_NAME_LENGTH        -27
 * @param NAFS_VOLUME_NAME_MISMATCH              -28
 * @param NAFS_IO_INTF_TABLE_FULL                -29
 * @param NAFS_IO_INTF_ENTRY_NOT_FOUND           -30
 * @param NAFS_DUPLICATE_VOLUME_NAME             -31
 * @param NAFS_INVALID_MEDIA_TYPE                -32
 * @param NAFS_INVALID_BLOCK_SIZE                -33
 * @param NAFS_INVALID_STACK_SIZE                -34
 * @param NAFS_INVALID_MSG_QUEUE_SIZE            -35
 * @param NAFS_QUEUE_CREATE_FAILED               -36
 * @param NAFS_INVALID_BUFFER_POOL_SIZE          -37
 * @param NAFS_MEDIA_TYPE_MISMATCH               -38
 * @param NAFS_MEDIA_CB_VOLUME_TABLE_FULL        -39
 * @param NAFS_INVALID_DIR_PATH_LENGTH           -40
 * @param NAFS_DIR_PATH_LENGTH_MISMATCH          -41
 * @param NAFS_MEDIA_CB_ALREADY_INSTALLED        -42
 * @param NAFS_MEDIA_CB_NOT_INSTALLED            -43
 * @param NAFS_BUFFER_POOL_ALREADY_INSTALLED     -44
 * @param NAFS_INVALID_PATH_NAME                 -45
 * @param NAFS_MEDIA_TYPE_INTF_MISMATCH          -46
 * @param NAFS_BUFFER_POOL_EMPTY                 -47
 * @param NAFS_INVALID_FILE_NAME_LENGTH          -48
 * @param NAFS_INVALID_FILE_TYPE                 -49
 * @param NAFS_INVALID_FILE_ACCESS_TYPE          -50
 * @param NAFS_INVALID_FILE_NAME                 -51
 * @param NAFS_IO_REQUEST_CB_BUSY                -52
 * @param NAFS_FILE_CB_BUSY                      -53
 * @param NAFS_DIR_PATH_CB_BUSY                  -54
 * @param NAFS_IO_REQUEST_CB_NOT_INITIALIZED     -55
 * @param NAFS_SEND_IO_REQUEST_FAILED            -56
 * @param NAFS_MSG_QUEUE_FULL                    -57
 * @param NAFS_INVALID_ROOT_DIR_INODE            -58
 * @param NAFS_INVALID_DIR_NAME_LENGTH           -59
 * @param NAFS_INODE_TYPE_MISMATCH               -60
 * @param NAFS_INVALID_INODE_DIR_SIZE            -61
 * @param NAFS_INODE_DATA_SIZE_MISMATCH          -62
 * @param NAFS_INVALID_USER_PERMISSIONS          -63
 * @param NAFS_INVALID_GROUP_ID                  -64
 * @param NAFS_NO_WRITE_PERMISSION               -65
 * @param NAFS_NO_READ_PERMISSION                -66
 * @param NAFS_DIR_ENTRY_TYPE_MISMATCH           -67
 * @param NAFS_NULL_DIR_ENTRY_NAME               -68
 * @param NAFS_NO_FREE_INODES                    -69
 * @param NAFS_DUPLICATE_DIR_ENTRY               -70
 * @param NAFS_DIR_ENTRY_NOT_FOUND               -71
 * @param NAFS_INVALID_FILE_OFFSET               -72
 * @param NAFS_INVALID_BYTES_TO_READ             -73
 * @param NAFS_INVALID_BYTES_TO_WRITE            -74
 * @param NAFS_INVALID_SS_TABLE_INDEX            -75
 * @param NAFS_INVALID_MAX_OPEN_DIRS             -76
 * @param NAFS_INVALID_MAX_OPEN_FILES            -77
 * @param NAFS_INVALID_FILE_HANDLE               -78
 * @param NAFS_RENAME_DIR_ENTRY_FAILED           -79
 * @param NAFS_FILE_IS_OPEN                      -80
 * @param NAFS_DIR_HAS_OPEN_FILES                -81
 * @param NAFS_DIR_TABLE_FULL                    -82
 * @param NAFS_FILE_TABLE_FULL                   -83
 * @param NAFS_DIR_NOT_EMPTY                     -84
 * @param NAFS_BLOCK_COUNT_MISMATCH              -85
 * @param NAFS_INVALID_DIR_ENTRY_BUFFER_SIZE     -86
 * @param NAFS_REMOVE_VOLUME_FAILED              -87
 * @param NAFS_SERVICES_CB_NOT_ALLOCATED         -88
 * @param NAFS_VOLUME_NOT_INITIALIZED            -89
 * @param NAFS_THREAD_DELETE_FAILED              -90
 * @param NAFS_THREAD_TERMINATE_FAILED           -91
 * @param NAFS_SEMAPHORE_DELETE_FAILED           -92
 * @param NAFS_FLASH_VOLUME_SECTORS_MISMATCH     -93
 * @param NAFS_SERVICES_CB_NOT_INITIALIZED       -94
 * @param NAFS_INODE_NUMBER_MISMATCH             -95
 * @param NAFS_SHUTDOWN_MODE                     -96
 * @param NAFS_THREAD_GET_INFO_FAILED            -97
 */

#define NAFS_SUCCESS                            0
#define NAFS_INVALID_VOLUME_NAME               -1
#define NAFS_INVALID_BLOCK_NUMBER              -2
#define NAFS_SERVICES_NOT_READY                -3
#define NAFS_BLOCK_NOT_MAPPED                  -4
#define NAFS_NO_FREE_BLOCKS                    -5
#define NAFS_WRITE_FAILED                      -6
#define NAFS_INVALID_BLOCK                     -7
#define NAFS_DELETE_FAILED                     -8
#define NAFS_NULL_POINTER                      -9
#define NAFS_INVALID_RAM_VOLUME                -10
#define NAFS_INVALID_FLASH_VOLUME              -11
#define NAFS_UNKNOWN_FLASH                     -12
#define NAFS_MALLOC_FAILED                     -13
#define NAFS_ALREADY_INITIALIZED               -14
#define NAFS_INVALID_WRITE_OPTION              -15
#define NAFS_BLOCK_SCAN_FAILED                 -16
#define NAFS_NO_TRANSFER_SECTOR                -17
#define NAFS_READ_FAILED                       -18
#define NAFS_SEMAPHORE_CREATE_FAILED           -19
#define NAFS_THREAD_CREATE_FAILED              -20
#define NAFS_IBLOCK_ARRAY_ENTRY_INCONSISTENT   -21
#define NAFS_IBLOCK_ARRAY_ENTRY_NOT_FOUND      -22
#define NAFS_END_OF_FILE                       -23
#define NAFS_SUPER_BLOCK_CORRUPTED             -24
#define NAFS_DATA_CORRUPTED                    -25
#define NAFS_SERVICES_TABLE_FULL               -26
#define NAFS_INVALID_VOLUME_NAME_LENGTH        -27
#define NAFS_VOLUME_NAME_MISMATCH              -28
#define NAFS_IO_INTF_TABLE_FULL                -29
#define NAFS_IO_INTF_ENTRY_NOT_FOUND           -30
#define NAFS_DUPLICATE_VOLUME_NAME             -31
#define NAFS_INVALID_MEDIA_TYPE                -32
#define NAFS_INVALID_BLOCK_SIZE                -33
#define NAFS_INVALID_STACK_SIZE                -34
#define NAFS_INVALID_MSG_QUEUE_SIZE            -35
#define NAFS_QUEUE_CREATE_FAILED               -36
#define NAFS_INVALID_BUFFER_POOL_SIZE          -37
#define NAFS_MEDIA_TYPE_MISMATCH               -38
#define NAFS_MEDIA_CB_VOLUME_TABLE_FULL        -39
#define NAFS_INVALID_DIR_PATH_LENGTH           -40
#define NAFS_DIR_PATH_LENGTH_MISMATCH          -41
#define NAFS_MEDIA_CB_ALREADY_INSTALLED        -42
#define NAFS_MEDIA_CB_NOT_INSTALLED            -43
#define NAFS_BUFFER_POOL_ALREADY_INSTALLED     -44
#define NAFS_INVALID_PATH_NAME                 -45
#define NAFS_MEDIA_TYPE_INTF_MISMATCH          -46
#define NAFS_BUFFER_POOL_EMPTY                 -47
#define NAFS_INVALID_FILE_NAME_LENGTH          -48
#define NAFS_INVALID_FILE_TYPE                 -49
#define NAFS_INVALID_FILE_ACCESS_TYPE          -50
#define NAFS_INVALID_FILE_NAME                 -51
#define NAFS_IO_REQUEST_CB_BUSY                -52
#define NAFS_FILE_CB_BUSY                      -53
#define NAFS_DIR_PATH_CB_BUSY                  -54
#define NAFS_IO_REQUEST_CB_NOT_INITIALIZED     -55
#define NAFS_SEND_IO_REQUEST_FAILED            -56
#define NAFS_MSG_QUEUE_FULL                    -57
#define NAFS_INVALID_ROOT_DIR_INODE            -58
#define NAFS_INVALID_DIR_NAME_LENGTH           -59
#define NAFS_INODE_TYPE_MISMATCH               -60
#define NAFS_INVALID_INODE_DIR_SIZE            -61
#define NAFS_INODE_DATA_SIZE_MISMATCH          -62
#define NAFS_INVALID_USER_PERMISSIONS          -63
#define NAFS_INVALID_GROUP_ID                  -64
#define NAFS_NO_WRITE_PERMISSION               -65
#define NAFS_NO_READ_PERMISSION                -66
#define NAFS_DIR_ENTRY_TYPE_MISMATCH           -67
#define NAFS_NULL_DIR_ENTRY_NAME               -68
#define NAFS_NO_FREE_INODES                    -69
#define NAFS_DUPLICATE_DIR_ENTRY               -70
#define NAFS_DIR_ENTRY_NOT_FOUND               -71
#define NAFS_INVALID_FILE_OFFSET               -72
#define NAFS_INVALID_BYTES_TO_READ             -73
#define NAFS_INVALID_BYTES_TO_WRITE            -74
#define NAFS_INVALID_SS_TABLE_INDEX            -75
#define NAFS_INVALID_MAX_OPEN_DIRS             -76
#define NAFS_INVALID_MAX_OPEN_FILES            -77
#define NAFS_INVALID_FILE_HANDLE               -78
#define NAFS_RENAME_DIR_ENTRY_FAILED           -79
#define NAFS_FILE_IS_OPEN                      -80
#define NAFS_DIR_HAS_OPEN_FILES                -81
#define NAFS_DIR_TABLE_FULL                    -82
#define NAFS_FILE_TABLE_FULL                   -83
#define NAFS_DIR_NOT_EMPTY                     -84
#define NAFS_BLOCK_COUNT_MISMATCH              -85
#define NAFS_INVALID_DIR_ENTRY_BUFFER_SIZE     -86
#define NAFS_REMOVE_VOLUME_FAILED              -87
#define NAFS_SERVICES_CB_NOT_ALLOCATED         -88
#define NAFS_VOLUME_NOT_INITIALIZED            -89
#define NAFS_THREAD_DELETE_FAILED              -90
#define NAFS_THREAD_TERMINATE_FAILED           -91
#define NAFS_SEMAPHORE_DELETE_FAILED           -92
#define NAFS_FLASH_VOLUME_SECTORS_MISMATCH     -93
#define NAFS_SERVICES_CB_NOT_INITIALIZED       -94
#define NAFS_INODE_NUMBER_MISMATCH             -95
#define NAFS_SHUTDOWN_MODE                     -96
#define NAFS_THREAD_GET_INFO_FAILED            -97


/**
 * Volume configuration block
 *
 * @external
 * @category fileSystem
 * @since 6.0
 *
 * @param  volume_name           An array to store the name of a volume.
 * @param  media_type            The media type number.
 * @param  block_size            The block size for the media type.
 * @param  inode_block_limit     The limit on the inode blocks to allocate.
 * @param  max_open_dirs         The maximum open directories limit.
 * @param  max_open_files        The maximum open files per directory limit.
 * @param  options               The optional features to use.
 * @param  reserved              Reserved for future enhancements.
 * @param  arg1                  Stores a Services module's initialization parameter.
 * @param  arg2			 Stores a Services module's initialization parameter.
 * @param  arg3			 Stores a Services module's initialization parameter.
 * @param  arg4			 Stores a Services module's initialization parameter.
 * @param  arg5			 Stores a Services module's initialization parameter.
 * @param  arg6			 Stores a Services module's initialization parameter.
 * @param  arg7			 Stores a Services module's initialization parameter.
 * @param  arg8			 Stores a Services module's initialization parameter.
 *
 * @see @link file_sys_volume
 */
typedef struct volume_config_block
{
    char volume_name[NAFS_VOLUME_NAME_SIZE + 1]; 
    unsigned char media_type;              
    unsigned int block_size;                
    unsigned int inode_block_limit;         
    unsigned int max_open_dirs;             
    unsigned int max_open_files;            
    unsigned int options;                   
    unsigned int reserved;                  
    unsigned int arg1;                      
    unsigned int arg2;                      
    unsigned int arg3;                      
    unsigned int arg4;                      
    unsigned int arg5;
    unsigned int arg6;
    unsigned int arg7;
    unsigned int arg8;
} NAFS_VOLUME_CB;

/**
 * Function pointer definition for the I/O Services layer
 *
 * @external
 * @category fileSystem
 * @since 6.0
 *
 * @param  data_block_ptr   The double pointer to the specific I/O Services layer's data block.
 * @param  config_block     The pointer to the NAFS_VOLUME_CB block that stores configuration parameters. 
 *
 * @return integer          The return code is implementation specific.
 *
 * @see @link NAFS_VOLUME_CB
 */
typedef int (* ss_create_fn)(void ** data_block_ptr, NAFS_VOLUME_CB * config_block);

/**
 * Function pointer definition for the I/O Services layer
 *
 * @external
 * @category fileSystem
 * @since 6.0
 *
 * @param  data_block_ptr   The double pointer to the specific I/O Services layer's data block.
 * @param  config_block     The pointer to the NAFS_VOLUME_CB block that stores configuration parameters. 
 *
 * @return integer          The return code is implementation specific.
 *
 * @see @link NAFS_VOLUME_CB
 */
typedef int (* ss_remove_fn)(void ** data_block_ptr, NAFS_VOLUME_CB * config_block);

/**
 * Function pointer definition for the I/O Services layer
 *
 * @external
 * @category fileSystem
 * @since 6.0
 *
 * @param  data_block_ptr   The pointer to the specific I/O Services layer's data block.
 * @param  block_number     The logical block number to write.
 * @param  buffer           The pointer to the buffer where write data is stored.
 *
 * @return integer          The return code is implementation specific.
 */
typedef int (* ss_write_block_fn)(void * data_block_ptr, int block_number, char * buffer);

/**
 * Function pointer definition for the I/O Services layer
 *
 * @external
 * @category fileSystem
 * @since 6.0
 *
 * @param  data_block_ptr   The pointer to the specific I/O Services layer's data block.
 * @param  block_number     The logical block number to read.
 * @param  buffer           The pointer to the buffer that stores the block data.
 *
 * @return integer          The return code is implementation specific.
 */
typedef int (* ss_read_block_fn)(void * data_block_ptr, int block_number, char * buffer);

/**
 * Function pointer definition for the I/O Services layer
 *
 * @external
 * @category fileSystem
 * @since 6.0
 *
 * @param  data_block_ptr   The pointer to the specific I/O Services layer's data block.
 * @param  block_number     The logical block number to delete.
 *
 * @return integer          The return code is implementation specific.
 */
typedef int (* ss_delete_block_fn)(void * data_block_ptr, int block_number);

/**
 * Function pointer definition for the I/O Services layer
 *
 * @external
 * @category fileSystem
 * @since 6.0
 *
 * @param  data_block_ptr   The pointer to the specific I/O Services layer's data block. 
 * @param  block_count      The pointer to the variable that stores the number of blocks in the volume.
 *
 * @return integer          The return code is implementation specific.
 */
typedef int (* ss_get_block_count_fn)(void * data_block_ptr, int * block_count);

/**
 * Storage Services Interface structure
 *
 * @external
 * @category fileSystem
 * @since 6.0
 *
 * @param volume_name		An array to store the name of the volume.
 * @param media_type		The media type of the volume.
 * @param ss_create		The pointer to the function that initializes the volume.
 * @param ss_remove		The pointer to the function that removes the volume.
 * @param ss_write_block	The pointer to the function that writes a block.
 * @param ss_read_block		The pointer to the function that reads a block.
 * @param ss_delete_block	The pointer to the function that deletes a block.
 * @param ss_get_block_count	The pointer to the function that retrieves the block count.
 * @param data_block_ptr	The pointer to the data block for the I/O Services module.
 * @param volume_cb_ptr		The pointer to the volume configuration block.
 *
 * @see @link NAFS_VOLUME_CB	 
 */
typedef struct ss_io_intf
{
    char volume_name[NAFS_VOLUME_NAME_SIZE + 1];                                            
    unsigned char media_type;
    ss_create_fn ss_create;
    ss_remove_fn ss_remove;
    ss_write_block_fn ss_write_block;
    ss_read_block_fn ss_read_block;
    ss_delete_block_fn ss_delete_block;                   
    ss_get_block_count_fn ss_get_block_count;
    void * data_block_ptr;
    NAFS_VOLUME_CB * volume_cb_ptr;                                                    
} NAFS_IO_INTF;

/**
 * Media buffer pool
 *
 * @external
 * @category fileSystem
 * @since 6.0
 *
 * @param  buffer_array     A circular array of pointers to memory buffers.
 * @param  front_ptr        Pointer to the front of the circular array.
 * @param  back_ptr         Pointer to the back of the circular array.
 * @param  count            Number of buffers stored in the array.
 *
 * @see @link file_sys_size
 */
typedef struct buffer_pool
{
    void * buffer_array[NAFS_MAX_BUFFER_POOL_SIZE + 1];  
    int front_ptr;                                  
    int back_ptr;                                   
    unsigned int count;                             
} NAFS_BUFFER_POOL;

/**
 * Function pointer definition for NAFS_MEDIA_CB thread entry point.
 *
 * @external
 * @category fileSystem
 * @since 6.0
 *
 * @param  media_cb    The address of the corresponding media control block.
 */
typedef void (* media_cb_thread_entry_fn)(unsigned long media_cb);

/**
 * Media type control block
 *
 * @external
 * @category fileSystem
 * @since 6.0
 * 
 * @param  media_type            The media type number.
 * @param  block_size            The block size for the media type.
 * @param  media_thread          The thread that processes I/O requests to the media type.
 * @param  thread_name           The buffer to store the thread name string.
 * @param  stack_start           The address where the thread stack starts.
 * @param  stack_size            The stack size for the thread.
 * @param  thread_entry          The thread entry function.
 * @param  media_queue           The message queue to receive I/O requests for the media type.
 * @param  queue_name            The buffer to store the queue name string.
 * @param  queue_start           The address where the message queue starts.
 * @param  queue_size            The size of the message queue.
 * @param  volume_data           An array of pointers to volume data blocks.
 * @param  buffer_pool           The pointer to the buffer pool for the media control block.
 *
 * @see @link NAFS_BUFFER_POOL
 * @see @link file_sys_media
 * @see @link file_sys_volume
 */
typedef struct media_control_block
{
    unsigned char media_type;                            
    unsigned int block_size;                             

    TX_THREAD * media_thread;                            
                                                         
    char thread_name[NAFS_MEDIA_THREAD_NAME_SIZE];            
    void * stack_start;                                  
    unsigned int stack_size;                             
    media_cb_thread_entry_fn thread_entry;

    TX_QUEUE * media_queue;                              
                                                         
    char queue_name[NAFS_MEDIA_QUEUE_NAME_SIZE];              
    void * queue_start;                                  
    unsigned int queue_size;                             

    void * volume_data[NAFS_VOLUMES_PER_MEDIA];               
    NAFS_BUFFER_POOL * buffer_pool;                      
} NAFS_MEDIA_CB;

/**
 * Directory information block
 *
 * @external
 * @category fileSystem
 * @since 6.0
 *
 * @param entry_name            The file or directory name string.
 * @param entry_type            File type: directory or data file.
 * @param file_size             The size of the file in bytes.
 * @param group_id              The group ID of the directory entry.
 * @param last_modified_time    The timestamp value of the directory entry.
 * 
 */
typedef struct dir_info_block
{
    char entry_name[NAFS_FILE_NAME_SIZE + 1];   
    unsigned char entry_type;              
    unsigned int file_size;                
    unsigned int group_id;                 
    time_t last_modified_time;             
} NAFS_DIR_ENTRY_INFO;

/**
 * Function pointer definition for the I/O request control block.
 * Callback function must cast "io_request_cb" to a NAFS_IO_REQUEST_CB
 * type to check for the completion or termination status of the
 * I/O request.
 *
 * @external
 * @category fileSystem
 * @since 6.0
 *
 * @param io_request_cb    The pointer to the I/O request control block.
 *
 * @see @link NAFS_IO_REQUEST_CB
 */
typedef void (* fs_io_request_callback_fn)(void * io_request_cb);

/**
 * I/O request block
 *
 * @external
 * @category fileSystem
 * @since 6.0
 *
 * @param  request_type					The I/O request type.
 * @param  status					The status of the I/O request.
 * @param  error_code					The completion or termination error code.
 * @param  bytes_transferred				The numbers of bytes transferred for file read or write requests.
 * @param  callback_function				The callback function to execute upon completion or termination.
 * @param  io_request_cb				The address of this I/O request block.
 * @param  dir_path					The pointer to the directory path string.
 * @param  file_name					The pointer to a file or directory name string.
 * @param  buffer					A general purpose pointer used internally.
 * @param  user_permissions				The user's read /write permissions.
 * @param  file_handle					The handle to the file.
 * @param  user_data                                    The user data value used in the callback function.
 * @param  arg1						A general purpose variable used internally.
 * @param  arg2						A general purpose variable used internally.
 * @param  arg3						A general purpose variable used internally.
 * @param  arg4						A general purpose variable used internally.
 * @param  arg5						A general purpose variable used internally.
 */
typedef struct io_request_control_block
{
    volatile unsigned int request_type;
    volatile unsigned int status;
    volatile int error_code;
    volatile unsigned int bytes_transferred;
    fs_io_request_callback_fn callback_function;
    void * io_request_cb;
    char * dir_path;
    char * file_name;
    void * buffer;
    unsigned int user_permissions;
    unsigned int file_handle;
    unsigned int user_data;
    unsigned int arg1;
    unsigned int arg2;
    unsigned int arg3;
    unsigned int arg4;
    unsigned int arg5;
} NAFS_IO_REQUEST_CB;

#ifdef __cplusplus
}
#endif

#endif
