Ste*_*rst 14 sqlite fopen vfs freertos netburner
我将使用FOpen,FRead,FWrite,FSeek和FClose为Netburner嵌入式设备(非Windows)实现自定义VFS(虚拟文件系统).我很惊讶我找不到可用的VFS的FOpen*版本.这将使嵌入式设备的便携性更高.
我在http://sqlite.org/c3ref/vfs.html上找到了有关为SQLite创建VFS的一些信息, 但信息非常详细,我还有很多关于实现的问题.
我在Winite,OS2,Linux的SQLite源代码中有一些示例VFS,但它们没有很多注释,只有源代码.
我可以使用上面链接中提供的信息和示例来创建我的自定义VFS,但我确信如果我这样做,我会错过一些东西.
我的问题是:
您是否注意到头文件中还有一个额外的文档来源sqlite3.h?此外,Google 代码搜索是您的朋友。
不要太担心丢失的东西,这就是测试套件的用途。从名称、文档和示例实现中猜测每个方法的用途;进行第一稿实施;在目标平台上运行测试;迭代直到条形变为绿色。通过粗略阅读您引用的界面文档,以下是一些有根据的猜测:
int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
int flags, int *pOutFlags);
int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
Run Code Online (Sandbox Code Playgroud)
这些是您常用的文件管理功能。你会注意到它xOpen()反过来返回一个结构sqlite3_file,它有自己的指针方法来读取和写入。
void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
void (*xDlClose)(sqlite3_vfs*, void*);
Run Code Online (Sandbox Code Playgroud)
这些用于共享库(请参阅dlopen()Linux 上的手册页)。在嵌入式环境中,您可能可以不实现这些(尝试将它们设置为 NULL)。
int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
Run Code Online (Sandbox Code Playgroud)
如果您的操作系统的标准库没有提供随机数生成器,您可能需要实现一个随机数生成器。我建议使用一个线性反馈寄存器,它小而好。
int (*xSleep)(sqlite3_vfs*, int microseconds);
int (*xCurrentTime)(sqlite3_vfs*, double*);
int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
Run Code Online (Sandbox Code Playgroud)
这些是时间管理功能,用于连接您的操作系统。
int (*xGetLastError)(sqlite3_vfs*, int, char *);
Run Code Online (Sandbox Code Playgroud)
您可以通过始终在此处返回 0 来逃脱:-) 请参阅 os_unix.c 中的 unixGetLastError(感谢 Google 代码搜索!)
祝你好运!