Files

156 lines
3.9 KiB
C

#include "stdio.h"
#include "stdlib.h"
#include "quec_secota_filesys.h"
#include "quec_include.h"
#include "quec_common.h"
#include "quec_cust_feature.h"
#ifdef QUECTEL_OPEN_CPU
#include "ql_fs.h"
#endif
#include "FDI_FILE.h"
#define QUEC_SECOTA_FILE_LOG(fmt, ...) quec_log("[QUEC][SECOTA_FILE][%s][%d]:" fmt "\r\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)
#ifdef QUECTEL_OPEN_CPU
static int secota_filesys_type = QUEC_SECOTA_QLLFS;
#else
static int secota_filesys_type = QUEC_SECOTA_FDIFS;
#endif
void quec_secota_filesys_init(quec_secota_filesys_t type)
{
secota_filesys_type = type;
QUEC_SECOTA_FILE_LOG("quec_secota_filesys_init type:%d", type);
}
static quec_secota_filesys_t quec_secota_filesys_get_type(void)
{
return secota_filesys_type;
}
quec_secota_std_fhandle_t quec_secota_fopen(const char *path, const char *mode)
{
#ifdef QL_NAND_YAFFS
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLYAFS)
return ql_yaffs_open(path, mode);
#endif
#ifdef QUECTEL_OPEN_CPU
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLLFS)
return (quec_secota_std_fhandle_t)ql_fopen(path, mode);
#endif
return quec_secota_std_fopen(path, mode);
}
int quec_secota_fclose(quec_secota_std_fhandle_t fd)
{
#ifdef QL_NAND_YAFFS
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLYAFS)
return ql_yaffs_close(fd);
#endif
#ifdef QUECTEL_OPEN_CPU
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLLFS)
return ql_fclose((QFILE* )fd);
#endif
return quec_secota_std_fclose(fd);
}
int quec_secota_fread(void *ptr, int size, int count, quec_secota_std_fhandle_t fd)
{
#ifdef QL_NAND_YAFFS
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLYAFS)
return ql_yaffs_read(ptr, size, count, fd);
#endif
#ifdef QUECTEL_OPEN_CPU
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLLFS)
return ql_fread(ptr, size, count, (QFILE* )fd);
#endif
return quec_secota_std_fread(ptr, size, count, fd);
}
int quec_secota_fwrite(const void *ptr, int size, int count, quec_secota_std_fhandle_t fd)
{
#ifdef QL_NAND_YAFFS
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLYAFS)
return ql_yaffs_write(ptr, size, count, fd);
#endif
#ifdef QUECTEL_OPEN_CPU
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLLFS)
return ql_fwrite(ptr, size, count, (QFILE* )fd);
#endif
return quec_secota_std_fwrite(ptr, size, count, fd);
}
int quec_secota_fseek(quec_secota_std_fhandle_t fd, int offset, int whence)
{
#ifdef QL_NAND_YAFFS
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLYAFS)
return ql_yaffs_lseek(fd, offset, whence);
#endif
#ifdef QUECTEL_OPEN_CPU
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLLFS)
return ql_fseek((QFILE* )fd, offset, whence);
#endif
return quec_secota_std_fseek(fd, offset, whence);
}
int quec_secota_remove(const char *path)
{
#ifdef QL_NAND_YAFFS
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLYAFS)
return ql_yaffs_unlink(path);
#endif
#ifdef QUECTEL_OPEN_CPU
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLLFS)
return ql_remove(path);
#endif
return quec_secota_std_remove(path);
}
int quec_secota_ftell(quec_secota_std_fhandle_t fd)
{
#ifdef QL_NAND_YAFFS
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLYAFS)
return ql_yaffs_ftell(fd);
#endif
#ifdef QUECTEL_OPEN_CPU
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLLFS)
return ql_ftell((QFILE* )fd);
#endif
return quec_secota_std_ftell(fd);
}
int quec_secota_fd_check_valid(quec_secota_std_fhandle_t fd)
{
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLYAFS)
{
if(fd < 0)
return 0;
else
return 1;
}
if(quec_secota_filesys_get_type() == QUEC_SECOTA_QLLFS)
{
if(fd == NULL)
return 0;
else
return 1;
}
if(fd < 0)
return 0;
else
return 1;
}