ext2“图像”文件与真实的 ext2 设备
我的任务是为 Windows 编写一个能够读取 ext2 分区的读取器程序。
在我的测试中,我使用一个格式化为 ext2 的驱动器和一个使用 mkfs 创建的文件(一个在 Linux 下安装并运行良好的文件)。
出于某种原因,当我从驱动器(真正的驱动器)读取超级块时,我得到了所有正确的元数据(即块大小、inode 计数等),但对文件执行完全相同的操作会返回错误结果(这没有意义)。
2之间有区别吗?
我使用 \.\X 打开驱动器: 我使用 mkfs 制作文件。
I'm tasked with writing a reader program for windows that is able read an ext2 partition.
For my testing I'm using a drive I formatted to ext2 and a file I created using mkfs (a file that does mount and work well under linux)
For some reason when I read the superblock from the drive (the real one) I get all the right meta-data (i.e. block size, inode count etc..) but doing the exact same thing to the file returns bad results (which make no sense).
is there a difference between the 2?
I open the drive using \.\X:
and I make the file using mkfs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
分区上的 ext2 和存储在文件中的 ext2 之间不应该有任何区别(实际上没有;我刚刚检查过);但是,IIRC,如果 ext2 安装在裸盘上(例如
/dev/sda
而不是/),则主超级块的偏移量为 2048 而不是 1024 dev/sda1
)。这是为了容纳 MBR 和其他垃圾。 (我现在在略读的文档中找不到它,但这在我的脑海中挥之不去,因为我遇到了这种情况。)但是,安装到裸驱动器上有点不寻常,所以我怀疑这是你的问题。几年前,我编写了一些 ext2 实用程序,在开始手工编写之后,我转而使用 Ted Ts'o(ext2 文件系统创建者)的 e2fsprogs,带有标头/库/等。以更灵活、更可靠的方式完成这一切。
您可能还需要在文件/分区的偏移量
0x438
处检查幻数0xEF53
,如果不存在,则在拉取之前将其视为不是 ext2/3 文件系统在整个超级块中,就像健全性检查一样。以下是一些可能会有所帮助的文档: http://www.nongnu.org/ext2- doc/ext2.html
There shouldn't be any difference between ext2 on a partition and stored within a file (and indeed there isn't; I just checked); however, IIRC, the offset of the primary superblock is 2048 instead of 1024, if ext2 is installed on a bare disk (e.g.
/dev/sda
instead of/dev/sda1
). This is to accomodate the MBR and other junk. (I can't find it in the docs from skimming just now, but this sticks out in my mind as something I ran into.) However, it's somewhat unusual to install to a bare drive, so I doubt this is your problem.I wrote some ext2 utilities a few years ago, and after starting writing it by hand, I switched to using Ted Ts'o (the ext2 filesystem creator)'s e2fsprogs, which come with headers/libraries/etc. for doing all this in a more flexible and reliable fashion.
You may also want to check at offset
0x438
into the file/partition for the magic number0xEF53
, and consider it not an ext2/3 filesystem if that's not there, before pulling in the entire superblock, just as a sanity check.Here's some docs that will probably be helpful: http://www.nongnu.org/ext2-doc/ext2.html