Astral OS banner

Astral OS

21 devlogs
79h 30m 44s

Updated Project: An EXT4 Semi-Unix Like OS that is being built from scratch. Only works on Windows and Linux, but easier on Linux.
If you cannot run the qcow2 image, then you can use the web demo but…

Updated Project: An EXT4 Semi-Unix Like OS that is being built from scratch. Only works on Windows and Linux, but easier on Linux.
If you cannot run the qcow2 image, then you can use the web demo but you won’t be able to type anything or use the console.

This project uses AI

Used GPT for debugging and to write stubbed funcs which will be replaced later. Main stuff like GDT isn’t written by GPT.

Demo Repository

Loading README...

CT5

Shipped this project!

Hours: 79.51
Cookies: 🍪 2164
Multiplier: 27.22 cookies/hr

I built an Operating System in C++ from Scratch making my own Kernel and EXT4 Kernel Drivers. The EXT4 Kernel Drivers were the hardest part to figure out but I was able to use the Linux Kernel Docs to finish it. I really like how Its turned out, and how it’s almost finished.

CT5

I haven’t worked on AstralOS for a long time, and I wanted to ship it since Im now working on WinDurango. Anyway, I created a simple input func for basicConsole. The irq handler then calls the input helper functions which add a char or remove a char or end the input. And then I was able to use the Input func to create the console which only does read and write for now.

Attachment
0
CT5

Im probably not going to work on the EXT4 Driver anymore, bc it was supposed to be a really basic driver, that can just read. And since it can read, we probably don’t need to do anything else. Also it can now create files. Im going to start working on multithreading tomorrow.

Attachment
0
CT5

So now you can List Directories and Create Dirs. I haven’t yet implemented creating a file (which is very easy) or removing files/dirs yet, so thats for tomorrow. I also noticed some other errors, like the List Dir not printing the right name. Right now, It is just stuck at closing the newly created dir, Ill fix that tomorrow or maybe even the day after because Im going to be taking a break;

Attachment
0
CT5

So I was able to fix the write function, except for the wrong block count in fsck. I still need to figure out how to create a file, and how to implement a create file function. There are also a few conditions I haven’t accounted for in the AddExtent function, because while adding an Extent seems easy, it is a difficult algorithm to implement.

Attachment
Attachment
0
CT5

I was able to fix the Write function, but the 7zip doesn’t show the full data that I wrote. When I looked at the fs in fsck, it gives me a bunch of random inodes that have weird flags and stuff. I think the Allocate Blocks Function is broken and is causing a bunch of random inodes to be written. Ill fix that tomorrow.

Attachment
0
CT5

So first, I added the code for Chown, Utimes and Chmod in the EXT4 Driver and then I added more functions in the VFS abstraction for better control over files and dirs. There still isn’t code to create dirs/files in the VFS abstraction, but at least there is code to write to files in the EXT4 and VFS abstractions. Ill finish off the Write func tomorrow.

Attachment
0
CT5

So I was able to move the mounting code from main.cpp to my VFS abstraction, and I also added a few fixes for ResolvePath. Then I was able to add some missing functions in the GPT Partition Driver to create the open function in my VFS abstraction.

Attachment
1

Comments

theinfamousben
theinfamousben 2 months ago

im confused, i love it

CT5

Ok, so I was able to fix the bug from earlier and I even found and fixed some other bugs. It works well now, but Im going to move the mounting code from main.cpp to the VFS abstraction in Filesystem.cpp.

Attachment
0
CT5

The photo shows that the kernel is crashing, but I’m not sure why. Anyway, Ill debug that tomorrow. I was able to fix the Driver System by splitting the Partition and Block Devices into Block Controllers and Devices and Partition Controllers and Devices.
Here is how it works now:

  • Block Controller
    • Block Device #1
      • Partition Controller
        • Partition Device #1
          • EXT4 Driver
        • Partition Device #2
          • EXT4 Driver
Attachment
2

Comments

captaintriton167
captaintriton167 2 months ago

That is very impressive. Are you writing it in C?

CT5
CT5 6 days ago

Yep, C++

CT5

So I looked at the DriverSystem and saw that it was pretty broken, so Im fixing that. First, Im splitting the Block Device into a Block Controller which makes multiple BlockDevices per drive. Im not fully done with it just yet, but ill probably finish it tomorrow. Ive gotten the DriverSystem.h file structs fixed.

Attachment
2

Comments

zwecc
zwecc 2 months ago

Cool! When will there be Desktop Environment? XD

CT5
CT5 6 days ago

Not sure yet, still need to add multithreading and stuff like that

CT5

So the GetExtents function wasn’t actually broken, I just had 2 variables with the same name, which the compiler hadn’t told me about. So once I fixed that it started working. I then used GetExtents in the Read function so that I could read large files like the usermode or the kernel. In the demo, you can see Ive just opened up hello.txt. I decided not to do more of the EXT4 Driver, since Im only going to be only reading anyway in the kernel. I’ve started the VFS abstration. Most of the code Ive written before,isn’t going to futureproof well, so Im going to rewrite it in another update. So after the VFS, I need to add multithreading and then add a simple usermode app.

Attachment
0
CT5

I was trying to fix the Read function today and turns out it was bc it was reading the wrong inode. So I fixed the ReadInode function and then it was able to read correctly. Then I added some code for reading when not using extents. After that I started to work on GetExtents so that I can easily read huge files using multiple Extents. The logic behind GetExtents is solid, but the function crashes when used with a kernel panic. Ill fix that tomorrow.

Attachment
0
CT5

Since I couldn’t find any documentation online on how extents work, I had to ask GPT for help since I couldn’t understand how the linux kernel did it. GPT kept saying you have to iterate extents by doing DBP + i, when instead you needed to do DBP + sizeof(ExtentHeader) + i * sizeof(Extent). I had a feeling that was the right way, but I wasn’t too sure. After I got that working, I was able to fix the ListDir func.

Attachment
0
CT5

I was able to figure out why the ListDir thing wasn’t working properly. But first I had to get Extents working for the ListDir func, so I got that working.

Attachment
1

Comments

lu2000luk
lu2000luk 3 months ago

The demo is kinda broken for me )=

CT5

I found a lot of bugs and inconsistencies when testing the OS for example when I wanted to add Opening and Reading Files in the driver or when I tried to fix ListDir, which is still somewhat broken btw. I decided to restart and look at the linux kernel documentation and code to understand EXT4 and get my Driver to work. So currently, I’ve re-done the Superblock, Inode and Block Group Descriptor structs and enums. I also noticed a bunch of fields I should’ve been using like the s_first_ino or s_rev_level. The superblock was also the wrong size, like having a uint64_t[32] array which would’ve really misaligned the superblock struct. I also added a ton of nice comments explaining how various parts of EXT4 work.

Attachment
0
CT5

Added CreateDir

The cool easter egg value I was putting into a reserved EXT4 OSVal2 var caused the whole thing to fail and caused some weird issues like corrupted creation time and corrupted ExtraBlocks. After I fixed that I realised that the InodeType Enums were wrong so I found the correct one from the Gitlab Page which helped me to enable Extents in my inode. After that I tested it with debugfs and it worked! Although List Dir Still doesnt work properly.

Attachment
0
CT5

I was following the OSDev Wiki before, but it only had stuff on EXT2 which was vastly different compared to EXT4. I underestimated how different those two filesystems were which caused a lot of issues. Today (23rd) I discovered that the Inode struct I was using was wrong for EXT4, so I found this nice Gitlab Page which explained how EXT4 works and the structs that were involved. Unfortunatly it didn’t tell me how to checksum things which was a big issue because fsck was complaining about checksums, so I had to look at the Linux Kernel Source. I still havent gotten to checksuming the Group Descriptors. I was able to checksum the superblock though. With the help of debugfs using this command sudo debugfs /dev/nbd0p2 I was able to identify issues with the Inode Table.

Attachment
0
CT5

tbh I can’t even bother to get this function working, and there is barely any info online or in the OSDev Wiki to understand how to create a dir in EXT4. Right now, it just creates a dir, but if you go inside, there are 2 of the dirs you just created and all the dirs in the parent.

Attachment
0
CT5

Ive gotten the Create Dir Func to work but it is very very buggy and Ill probably fix it tmrw. You can’t even boot the image after it modifies the fs once.

Attachment
0
CT5

Currently I’ve been working on the EXT4 Driver, one function at a time. Im still working on the CreateDir function, but here is the FindDir (Find in Directory) function I made.

Attachment
0