FOpen* 的 SQLite VFS 实施指南
我即将使用 FOpen、FRead、FWrite、FSeek 和 FClose 为 Netburner 嵌入式设备(非 Windows)实现自定义 VFS(虚拟文件系统)。我很惊讶我找不到可用的 VFS 的 FOpen* 版本。这将使它更容易移植到嵌入式设备。
我在这里找到了一些有关为 SQLite 创建 VFS 的信息 http://sqlite.org/c3ref/vfs.html 但信息非常详细,我对实施还有很多其他问题。
我在 Win、OS2、Linux 的 SQLite 源代码中有一些示例 VFS,但它们没有很多注释,只有源代码。
我可以使用上面链接中提供的信息和示例来创建我的自定义 VFS,但我确信如果我这样做的话我会错过一些东西。
我的问题是:
- 是否还有我缺少的有关 SQLite VFS 的更多文档?也许是实施指南?
- 是否有可用的 SQLite VFS 的 Fopen 版本?
- 创建自定义 SQLite VFS 后,是否有单元测试代码可用于测试它?
- 您想分享的建议、评论、实施 SQLite 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.
I found some information on creating the VFS for SQLite here
http://sqlite.org/c3ref/vfs.html
but the information is very detailed and I have lots of other questions about the implementation.
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.
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.
My questions are:
- Is there any more documentation about the SQLite VFS that I am missing? Maybe an implementation guide?
- Is there an Fopen version of the SQLite VFS that is available?
- Is there a unit testing code available to test my custom SQLite VFS once I have created it?
- Suggestions, comments, experiences with implementing SQLite VFS that you would like to share.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否注意到头文件
sqlite3.h
中有一个额外的文档来源?此外,Google 代码搜索也是您的朋友。不要太担心遗漏东西,这就是测试套件的用途。从每个方法的名称、文档和示例实现中猜测其用途;进行初稿实施;在您的目标平台上运行测试;迭代直到条变成绿色。通过粗略地阅读您引用的界面文档,以下是一些有根据的猜测:
这些是您的常规文件管理功能。您会注意到,
xOpen()
又返回一个结构sqlite3_file
,它具有自己的用于读取和写入的指针方法。这些用于共享库(请参阅 Linux 上的
dlopen()
手册页)。在嵌入式环境中,您可能可以不实现这些(尝试将它们设置为 NULL)。如果您的操作系统的标准库尚未提供随机数生成器,您可能必须实现随机数生成器。我建议使用线性反馈寄存器,它虽小但很好。
这些是时间管理功能,用于与您的操作系统连接。
您可以通过在此处始终返回 0 来逃脱:-) 请参阅 os_unix.c 中的 unixGetLastError (感谢 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:
Those are your run-off-the-mill file management functions. You'll notice that
xOpen()
in turn returns a structuresqlite3_file
, that has pointer methods of its own for reading and writing.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).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.
These are the time management functions, to hook up with your OS.
You can get away by always returning 0 here :-) See unixGetLastError in os_unix.c (thanks Google Code Search!)
Good luck!
一种选择是使用基于内存的 VFS,然后在完成后将内存转储到文件。请参阅:http://article.gmane.org/gmane.comp.db .sqlite.general/46450 用于已经支持序列化/反序列化的基于内存的 VFS。
缺点是您必须手动写出文件才能使其保留。如果您的应用程序突然终止,对数据库的任何中间更改都将不会被持久化。
One option is to use a memory based VFS then simply dump the memory to file when you are done. See: http://article.gmane.org/gmane.comp.db.sqlite.general/46450 for a memory based VFS that already supports serialization/deserialization.
The disadvantage is that you must manually write the file out for it to persist. If your application suddenly dies any intermediate changes to the DB will not be persisted.