我已经使用 FUSE 实现了基本文件系统,并实现了所有可预见的 POSIX 功能[自然地,我甚至还没有简介;)]。目前我可以在常规文件 (st_mode & S_IFREG) 上运行文件系统
,但开发的下一步是将其托管在实际的块设备上。按原样运行我的代码,在调用 st_size
设备上的 >fstat。当然,我不希望问题就此停止:
- 与常规文件相比,在块设备上操作需要进行哪些更改?
- 关于性能、限制、特殊功能等,我需要考虑哪些特殊因素?
- 是否有处理块特殊文件的教程和参考?谷歌搜索并没有什么用处。我只有背景知识(讽刺的是,在我黑暗的过去,来自 MSDN)和联机帮助页中的一些很少的信息。
Update0
- 我已经指出了“常规文件”的含义。
- 我不想专注于获取设备大小,我想要关于常规文件和设备文件在性能和使用方面的差异的一般准则。
I've implemented a basic filesystem using FUSE, with all foreseeable POSIX functionality implemented [naturally I haven't even profiled yet ;)]. Currently I'm able to run the filesystem on a regular file (st_mode & S_IFREG)
, but the next step in development is to host it on an actual block device. Running my code as is, immediately fails on reading st_size
after calling fstat
on the device. Of course I don't expect the problems to stop there so:
- What changes are required to operate on block devices as opposed to regular files?
- What are some special considerations I need to make with regard to performance, limitations, special features and the like?
- Are there any tutorials and references with dealing with block special files? Googling has turned up very little useful; I only have background knowledge (ironically from MSDN in my dark past) and some scanty information in the manpages.
Update0
- I've pointed out what I mean by "regular file".
- I don't want to concentrate on getting the device size, I want general guidelines for differences between regular files and device files with respect to performance and usage.
发布评论
评论(2)
我不完全理解您的意思 - 我假设您是说“您当前将文件系统数据保存到正常安装的文件系统上的纯文件中 - 但现在希望使用原始块设备您的数据存储”。
如果是这样 - 已经这样做了几次 - 我建议如下:
fstat“失败”是什么意思?这是一个试图确定块设备长度的 fstat?您收到错误吗?它是什么?
I don't completely understand what you mean - I assume you are saying that "you currently save your filesystem data to a plain file on a normally mounted filesystem - but now wish to use a raw block device for your data storage".
If so - having done this a few times - I'd advise the following:
What do you mean that the fstat "fails"? This is an fstat trying to determing the length of the block device? Do you receive an error? What is it?
块设备的行为与文件非常相似 - 像 dd 这样的工具可以对它们进行操作,而无需任何特殊处理。不过,fstat 返回有关特殊文件节点的信息,而不是它引用的 blockdev。您可能想使用 BLKGETSIZE64 ioctl 来读取大小。
不过,没有特别的理由在原始设备上使用分区 - blockdev 就是 blockdev。假设您的工作负载不会产生重复访问,O_DIRECT 也很好。不过,不要将它与确保文件系统的持久性和原子性的真正协议(fsync、障碍等)混淆。
block devices behave very much like files - tools like dd can operate on them without any special handling. fstat, though, returns information about the special-file node, not the blockdev it refers to. you probably want to use the BLKGETSIZE64 ioctl to read the size.
there's no particular reason to use a partition over a raw device, though - a blockdev is a blockdev. O_DIRECT is good, as well, assuming your workload won't generate repeated accesses. don't confuse it with a real protocol for ensuring the permanence and atomicity of your filesystem, though (fsync, barriers, etc).