/*
 * bsk_tftp_pfs.h: Pseudo file system
 *
 */

#ifndef BSK_TFTP_PFS_H_
#define BSK_TFTP_PFS_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif
#if 0
struct bsk_pfs_partition_t
{
    const char name[32];
    const char pn[32];
    const char partition_name;
};

struct bsk_pfs_partition_set_t
{
    enum { k_max_subitems=32};

    const char* name;
    const char* pn;

    unsigned int num_of_subitems;

    bsk_pfs_partition_t subitems[k_max_subitems];
};
#endif
struct bsk_pfs_partition_contents_t
{
    uint32_t valid;
    uint32_t crc32;

    char file_name[32];
    char version[16];
};

struct bsk_download_partition_t
{
    enum { part_null=0, part_fsbl=1, part_recovery=2, part_operative=3, part_default=0x1000, part_hidden=0x2000};
    char name[16];
    uint32_t flags;
    uint32_t max_size;

    uint32_t pard_id;
    uint32_t subaddress;

    uint64_t handle;

    bsk_pfs_partition_contents_t contents;
};

struct bsk_download_site_t
{
    enum { k_max_partitions=32};

    char name[16];

    char address[16];

    uint32_t media_address;
    int media_port;

    uint64_t handle;

    //int num_of_partitions;
    bsk_download_partition_t partitions[k_max_partitions];
};

extern const char bsk_tftpd_mfs_status_query[];
extern const char bsk_tftpd_mfs_list_query[];

extern int bsk_tftpd_mfs_set_site(struct bsk_download_site_t* s, int n);

extern int bsk_tftp_mfs_decode_site(bsk_download_site_t* site, const char* str);

#define bsk_tftp_mfs_invalid_partition ((bsk_download_partition_t*)(-1))

extern bsk_download_partition_t* bsk_tftp_mfs_decode_filename(unsigned int entry_id, const char* name, const char **fname);

extern const char* bsk_tftpd_mfs_get_list(int n);

extern int bsk_tftp_mfs_add_entry(unsigned int entry_id, const char* partition_name, unsigned int max_size);
extern int bsk_tftp_mfs_set_entry(unsigned int entry_id, const char* actual_filename, unsigned int actual_size, unsigned long crc32, const char* version_string, unsigned int flags);

//The external interface
const char* bsk_tftp_mfs_rtg_store(unsigned int entry_id, const void* data, unsigned int size, unsigned long crc32);

const char* bsk_tftp_mfs_rtg_retrive_start(unsigned int entry_id, const void** data, unsigned int* size);

#ifdef __cplusplus
}
#endif

#endif /* BSK_TFTP_PFS_H_ */
