问题描述
我将使用FOpen,FRead,FWrite,FSeek和FClose为Netburner嵌入式设备(非Windows)实现自定义VFS(虚拟文件系统).令我惊讶的是,我找不到可用的FOpen *版本的VFS.这将使其更易于移植到嵌入式设备.
I am about to implement a custom VFS (virtual file system) for a Netburner embedded device (non windows) using FOpen, FRead, FWrite, FSeek, and FClose. I was surprised that i could not find a FOpen* version of the VFS available. It would make it a lot more portable to embedded devices.
我在这里找到了有关为SQLite创建VFS的一些信息 http://sqlite.org/c3ref/vfs.html 但是信息非常详细,我对实现还有很多其他疑问.
I found some information on creating the VFS for SQLite herehttp://sqlite.org/c3ref/vfs.htmlbut the information is very detailed and I have lots of other questions about the implementation.
我在Win,OS2,Linux的SQLite源代码中有一些示例VFS,但是它们没有很多注释,只有源代码.
I have some example VFS in the SQLite source code for Win, OS2, Linux but they don't have a lot of comments, only source code.
我可以使用上面的链接和示例中提供的信息来创建我的自定义VFS,但是我敢肯定,如果这样做的话,我会漏掉一些东西的.
I could use the information provided in the link above and the examples to create my custom VFS but i'm sure that I would miss something if I did it that way.
我的问题是:
- 是否还缺少有关SQLite VFS的其他文档?也许是实施指南?
- 是否有可用的Fite版本的SQLite VFS?
- 创建我的自定义SQLite VFS后,是否可以使用单元测试代码进行测试?
- 要共享的实施SQLite VFS的建议,意见和经验.
推荐答案
您是否注意到头文件sqlite3.h
中还有其他文档来源?另外,Google代码搜索是您的朋友.
Did you notice that there is an additional source of documentation in the header file sqlite3.h
? Also, Google code search is your friend.
不必太担心丢失的东西,这就是测试套件的目的.从它们的名称,文档和示例实现中猜出每种方法的目的;进行初稿实施;在目标平台上运行测试;反复进行,直到条变为绿色.通过粗略阅读您引用的接口文档,可以得出一些有根据的猜测:
Don't worry too much about missing things, this is what the test suite is for. Take a guess at the purpose of every method from their name, the documentation and the example implementations; go for a first-draft implementation; run the tests on your target platform; iterate until the bar is green. From a cursory reading of the interface doc that you quoted, here are some educated guesses:
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);
这些是您日常运行的文件管理功能.您会注意到,xOpen()
依次返回结构sqlite3_file
,该结构具有自己的用于读取和写入的指针方法.
Those are your run-off-the-mill file management functions. You'll notice that xOpen()
in turn returns a structure sqlite3_file
, that has pointer methods of its own for reading and writing.
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*);
这些用于共享库(请参见Linux上的dlopen()
手册页).在嵌入式环境中,您可能可以保留这些未实现的功能(尝试将其设置为NULL).
Those are for shared libraries (see the dlopen()
man page on Linux). In an embedded environment, you probably can leave these unimplemented (try setting these to NULL).
int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
如果操作系统的标准库尚未提供一个随机数生成器,则可能必须实现它.我建议使用一个线性反馈寄存器,它虽然小巧却很好.
You might have to implement a random number generator, if your OS' standard library doesn't provide one already. I suggest a linear feedback register, which is small yet good.
int (*xSleep)(sqlite3_vfs*, int microseconds);
int (*xCurrentTime)(sqlite3_vfs*, double*);
int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
这些是与您的操作系统挂钩的时间管理功能.
These are the time management functions, to hook up with your OS.
int (*xGetLastError)(sqlite3_vfs*, int, char *);
您可以通过始终在此处返回0来逃脱:-)参见os_unix.c中的unixGetLastError(感谢Google代码搜索!)
You can get away by always returning 0 here :-) See unixGetLastError in os_unix.c (thanks Google Code Search!)
祝你好运!
这篇关于使用FOpen *的SQLite VFS实施指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!