如何实现一个非常简单的文件系统?

发布于 2024-10-12 13:24:51 字数 123 浏览 2 评论 0原文

我想知道操作系统如何读取/写入硬盘。
我想作为练习来实现一个简单的文件系统,没有可以读写文件的目录。
我从哪里开始?
C/C++ 可以解决问题还是我必须采用更底层的方法?
一个人处理的事情是否太多了?

I am wondering how the OS is reading/writing to the hard drive.
I would like as an exercise to implement a simple filesystem with no directories that can read and write files.
Where do I start?
Will C/C++ do the trick or do I have to go with a more low level approach?
Is it too much for one person to handle?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

冰雪梦之恋 2024-10-19 13:24:51

看一下 FUSE:http://fuse.sourceforge.net/

这将允许您编写文件系统无需实际编写设备驱动程序。从那里开始,我将从一个文件开始。基本上创建一个(例如)长度为 100MB 的文件,然后编写例程以从该文件读取和写入。

一旦您对结果感到满意,您就可以考虑编写设备驱动程序,并使驱动程序针对物理磁盘运行。

好处是您可以通过 FUSE 使用几乎任何语言,而不仅仅是 C/C++。

Take a look at FUSE: http://fuse.sourceforge.net/

This will allow you to write a filesystem without having to actually write a device driver. From there, I'd start with a single file. Basically create a file that's (for example) 100MB in length, then write your routines to read and write from that file.

Once you're happy with the results, then you can look into writing a device driver, and making your driver run against a physical disk.

The nice thing is you can use almost any language with FUSE, not just C/C++.

想你的星星会说话 2024-10-19 13:24:51

我发现在 avr 微控制器上使用 fat 文件系统时,理解简单的文件系统非常容易。

http://elm-chan.org/fsw/ff/00index_e.html

看一下代码你就会明白脂肪是如何运作的。

I found it quite easy to understand a simple filesystem while using the fat filesystem on the avr microcontroller.

http://elm-chan.org/fsw/ff/00index_e.html

Take look at the code you will figure out how fat works.

我要还你自由 2024-10-19 13:24:51

我认为,为了学习文件系统的思想,实际上并不需要使用磁盘。只需创建一个 512 字节字节数组的数组。想象一下,这是您的硬盘,是进行一些实验的开始。
另外,您可能想看看一些标准操作系统教科书,例如 http://codex.cs.yale.edu/avi/os-book/OS8/os8c/index.html

For learning the ideas of a file system it's not really necessary to use a disk i think. Just create an array of 512 byte byte-arrays. Just imagine this a your Harddisk an start to experiment a bit.
Also you may want to hava a look at some of the standard OS textbooks like http://codex.cs.yale.edu/avi/os-book/OS8/os8c/index.html

沫雨熙 2024-10-19 13:24:51

你的第一个问题的答案是,除了像其他人告诉你的那样,除了 Fuse 之外,你还可以使用 Dokan,它对 Windows 执行相同的操作,并且从那里开始只需要对物理分区进行读取和写入操作(http://msdn.microsoft.com/en-us/library /aa363858%28v=vs.85%29.aspx(特别阅读有关物理磁盘和卷的部分)。

当然,在 Linux 或 Unix 中,除了使用 Fuse 之类的东西之外,您只需要发出对 /dev/xxx 中所需设备的读或写调用(如果您是 root),从这些角度来看,Unices 更友好或更友好。不安全取决于你的观点。

从那里尝试实现一个简单的文件系统,如 Fat,或者更奇特的文件系统,如 tar 文件系统,甚至一些基于 Unix 概念的简单文件系统,如 UFS 或 Minux,或者只是记录所进行的调用及其参数到日志文件(这将帮助您了解在常规使用计算机期间对文件系统驱动程序进行的调用)。

现在你的第二个问题(回答起来要简单得多),是的,C/C++ 可以解决问题,因为它们是系统开发的通用语言,而且你的很多示例代码都将使用 C/C++,所以你将在在你的开发中最少读过 C/C++。

现在对于你的第三个问题,是的,这是一个人可以做到的,例如 ext 文件系统(在 Linux 世界中以其后继者 ext2 或 ext3 广为人知)是由一位开发人员 Theodore Ts'o 制作的,所以不要认为这些事情不是一个人就能完成的。

现在是最后的注意事项,请记住,真正的文件系统与常规内核中的许多其他子系统交互,例如,如果您有一台笔记本电脑并将其休眠,则文件系统必须刷新对打开文件所做的所有更改,如果您有分区上的页面文件,或者即使页面文件有自己的文件系统,这也会影响您的文件系统,特别是块大小,因为它们往往等于​​页面块大小或页面块大小的幂,因为很容易从内存上的文件系统恰好等于页面大小(因为这只是一次传输)。

还有安全性,因为您需要控制用户以及他们读/写的文件,这通常意味着在打开文件之前,您必须知道哪个用户登录了,以及他对该文件拥有什么权限。显然,如果没有文件系统,用户就无法运行任何程序或与机器交互。由于存在网络和分布式文件系统,现代文件系统层还与网络子系统交互。

因此,如果你想学习内核文件系统,这些是你必须担心的一些事情(除了了解 VFS 接口之外)

PS:如果你想让 Unix 权限在 Windows 上工作,你可以使用类似的东西MS 在 Windows 服务器版本上使用什么 NFS (http://support.microsoft.com/kb/262965 )

The answer to your first question, is that besides Fuse as someone else told you, you can also use Dokan that does the same for Windows, and from there is just a question of doing Reads and Writes to a physical partition (http://msdn.microsoft.com/en-us/library/aa363858%28v=vs.85%29.aspx (read particularly the section on Physical Disks and Volumes)).

Of course that in Linux or Unix besides using something like Fuse you only have to issue, a read or write call to the wanted device in /dev/xxx (if you are root), and in these terms the Unices are more friendly or more insecure depending on your point of view.

From there try to implement a simple filesystem like Fat, or something more exoteric like an tar filesystem, or even some simple filesystem based on Unix concepts like UFS or Minux, or just something that only logs the calls that are made and their arguments to a log file (and this will help you understand, the calls that are made to the filesystem driver during the regular use of your computer).

Now your second question (that is much more simple to answer), yes C/C++ will do the trick, since they are the lingua franca of system development, also a lot of your example code will be in C/C++ so you will at least read C/C++ in your development.

Now for your third question, yes, this is doable by one person, for example the ext filesystem (widely known in Linux world by it's successors as ext2 or ext3) was made by a single developer Theodore Ts'o, so don't think that these things aren't doable by a single person.

Now the final notes, remember that a real filesystem interacts with a lot of other subsystems in a regular kernel, for example, if you have a laptop and hibernate it the filesystem has to flush all changes made to the open files, if you have a pagefile on the partition or even if the pagefile has it's own filesystem, that will affect your filesystem, particularly the block sizes, since they will tend to be equal or powers of the page block size, because it's easy to just place a block from the filesystem on memory that by coincidence is equal to the page size (because that's just one transfer).

And also, security, since you will want to control the users and what files they read/write and that usually means that before opening a file, you will have to know what user is logged on, and what permissions he has for that file. And obviously without filesystem, users can't run any program or interact with the machine. Modern filesystem layers, also interact with the network subsystem due to the fact that there are network and distributed filesystems.

So if you want to go and learn about doing kernel filesystems, those are some of the things you will have to worry about (besides knowing a VFS interface)

P.S.: If you want to make Unix permissions work on Windows, you can use something like what MS uses for NFS on the server versions of windows (http://support.microsoft.com/kb/262965)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文