玩具OS文件系统 [英] Toy OS Filesystem

查看:231
本文介绍了玩具OS文件系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了装配/ C运行一个基本的终端基本内核。我已经将它设置为关闭使用GRUB的ISO的运行。

I have developed a basic kernel in assembly/c that runs a basic terminal. I have set it up to run off of an iso with grub.

我想继续这样的操作系统,但没有一个文件系统,我觉得好像没什么好说别的我可以做的。后在互联网上太多的时间,我都拿出了真没什么,我可以做些什么来实现这一点。

I would like to continue this OS, but without a file system, I feel as if there's really nothing else I could do. After much time on the internet, I have come up with really nothing I can do to implement this.

人们说实现FAT或作出VFS,但没有任何进一步的,也没有教程,也没有在任何地方的任何引用。

People have said implement FAT or make a VFS, but nothing any further, nor tutorials, nor any references to anywhere.

有人能解释一个文件系统是如何工作的,在那里我可以开始/我在哪里可以连接pre-制作系统,以及如何使用它?

Could someone explain how a file system works, where I can get started/where I can connect a pre-made system, and how to use it?

另外,我不编译我的操作系统时,可以使用标准库。我用gcc,NASM,LD和蛴螬mkrescue(磁盘映像)。我用QEMU进行仿真。

Also, I do not have access to standard libraries when compiling my os. I use gcc, nasm, ld, and grub-mkrescue(for the disk image). I use qemu for emulation.

编辑以少OT

有人能详细描述了一个文件系统是如何工作的,所以当我看着已经实现,如FAT文件系统的来源,我可以理解如何将其应用到我自己的操作系统?

Can someone describe, in detail how a file system works, so when I look at the sources of file systems that have been implemented, like FAT, I can understand how to apply it to my own operating system?

编辑 - 简单

更容易。我怎么能直接访问硬盘驱动器?我的内核在保护模式下运行完全,这样我就可以切换出并直接写入到硬盘驱动器。文件系统可以用一个文件看起来像这样实现:

Even easier. How could I directly access the hard drive? My kernel runs completely in protected mode, so could I switch out and write directly to the hard drive. A file system could be implemented with a file looking like this:

名称 特殊字符 文本 特殊字符

name special char text special char

例如:

你好world.script 0×00 的println你好,世界! 0×00

hello world.script 0x00 println "Hello, world!!" 0x00

如果你不需要特殊的分割,你只是看,直到找到文件名和特殊字符(而不是像一串东西'\\ 0'),然后看,直到你找到第二个非字符串的字符

Where you wouldn't need special segmentation, you would just look until you find the file name and the special character (something not in a string like '\0') and then read until you find the second non-string character.

会不会有通过切换进出保护模式来访问硬盘驱动器或写入硬盘驱动器,以实现这个办法?

Would there be a way to access the hard drive by switching in and out of protected mode or write a hard disk driver in order to implement this?

推荐答案

首先,阅读文件系统WIKIPAGE 有一些开阔的视野。

First, read wikipage on file systems to have some broad view.

了解操作系统开发相关资源的 OSdev (但也许你的问题是题外话这里)。 Kernelnewbies 也可以帮助(解释的Linux是如何做的)。 OSdev有wikipages解释 FAT &安培; 的Ext2 的详细。

The relevant resource about operating system development is OSdev (but perhaps your question is off-topic here). Kernelnewbies could also help (explaining how Linux is doing). OSdev have wikipages explaining FAT & Ext2 in details.

您可以设计没有任何文件的OS(但一些其他的持久机械)。请参见这个答案。你可以有持续性的过程(也了解应用程序检查点,的垃圾收集,的延续的,休眠)。

You could design an OS without any files (but some other persistence machinery). See this answer. You could have persistent processes (read also about application checkpointing, garbage collection, continuations, hibernation).

但你应该了解操作系统的一些好的书籍(如由Tanenbaum的)。流利与一些现有的免费软件的操作系统,例如Linux的(安培; POSIX),所以读高级Linux编程(至少要了解很多概念并获得良好的术语)。

But you should read some good books about Operating Systems (e.g. by Tanenbaum). Be fluent with some existing free software OS, e.g. Linux (& POSIX), so read Advanced Linux Programming (at least to understand many concepts and get a good terminology).

恕我直言,在 FAT 是如此丑陋和低效的文件系统,这是不值得期待成(除传统和兼容性的原因)。 的ext4 (见的这里)应该更好地与放大器;在 Ext2的WIKIPAGE 有一个漂亮的图片。

IMHO, the FAT is such an ugly and inefficient file system that it is not worth looking into (except for legacy and compatibility reasons). Ext4 (see here) should be better & the wikipage on Ext2 has a nice picture.

您可以适应某些库提供了一个文件系统(例如: libext2 )到你的内核。

You could adapt some library providing a file system (e.g. libext2) to your kernel.

您也许可以适应 sqlite的在原始磁盘分区的工作。

You could perhaps adapt sqlite to work on a raw disk partition.

您可能必须文件的概念这是不喜欢MSDOS(或Windows)或POSIX或<&stdio.h中GT; 文件。例如,它可能是固定大小记录的序列(例如1K字节)的,而不是字节流

You might have a notion of file which is not like MSDOS (or Windows) or POSIX or <stdio.h> files. For example, it might be a sequence of fixed size records (e.g. of 1Kbyte), not a stream of bytes.

您可以组织你的操作系统为微内核并已文件系统通过应用$ C $给出C。考虑 VSTA 并的 HURD

You could organize your OS as a microkernel and have file systems given by application code. Look into VSTa and HURD.

您需要当然是一个磁盘驱动器,它获取/从你的驱动器写入(4K的)块(磁盘I / O始终由块或的磁盘扇区。旧盘小有512字节的块。新的大型磁盘具有4K字节的人,看到的高级格式)。应该中断驱动,并使用 DMA 。你需要一个任务调度。 AFAIU,你不会用于此的BIOS(也许是的 UEFI );你需要了解通用的硬件( SATA &放大器;的 AHCI )的作品。

You need of course a disk driver, which fetches/writes blocks (of 4Kbytes) from your drive (disk I/O is always by blocks or disk sectors. Old small disks had 512 bytes blocks. New large disks have 4Kbytes ones, see advanced format). It should be interrupt driven and uses DMA. You need a task scheduler. AFAIU, you won't use the BIOS for this (perhaps the UEFI); you need to understand how common hardware (SATA & AHCI) works.

您应该发布(的今天!的),你的玩具作为操作系统免费软件(例如,在 GPLv3的 +上的 github上),以获得反馈和贡献。

You should publish (today!) your toy OS as free software (e.g. under GPLv3+ on github) to get feedbacks and contributions.

您可以复制(如许可证兼容)现有的其他免费软件操作系统,你肯定会研究他们的源$ C ​​$ C明白的事情。

You might copy (if licenses are compatible) existing code from other free software operating systems, and you certainly will study their source code to understand things.

所以,code一些任务调度器,页面错误处理程序,一个的虚拟内存,再加入中断驱动磁盘IO,以及一些文件系统code上面。然后你就开始明白一个操作系统不能是的的玩具....你可能会考虑一个微内核或的外核方法。

So code some task scheduler, a page fault handler, a virtual memory, then add interrupt driven disk IO, and some file system code above that. Then you'll beginning to understand that an OS cannot be a small toy.... You might consider a microkernel or exokernel approach.

这篇关于玩具OS文件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆