Building an OS - 3 - The FAT file system
Вставка
- Опубліковано 22 сер 2024
- We continue writing our bootloader, and we learn to read a file from a FAT disk.
Part 2: • Building an OS - 2 - R...
Part 1: • Building an OS - 1 - H...
Source code: github.com/nan...
Tools:
- Bochs: bochs.sourcefor...
- mtools: www.gnu.org/so...
- VSCode: code.visualstu...
- Okteta (Linux): apps.kde.org/e...
- HxD hex editor (Windows): mh-nexus.de/en...
Documentation:
- FAT12 file system: wiki.osdev.org...
- INT 13h: www.stanislavs...
- x86 instruction reference: c9x.me/x86/
You actually move faster than I can type. I type pretty fast. I actually find this refreshing compared to other channels that I have to pump up to double-speed to keep up with me.
Also, thanks for going beyond the bootloader section of teaching OS development. Not many video series' make it that far.
The coding part is sped up a bit. I'm glad you're enjoying it.
@@nanobyte-dev I actually built the i686-gcc environment first before starting the series. Then I got stuck on the video on setting up the Watcom compiler. I just didn't feel ready to setup yet another compiler on my system. That's what I get for going out of order.
@@treytomes You can skip the watcom stuff... just watch 2 more videos until I return to GCC's loving arms.
these videos are amazing, the best osdev content on youtube!
awesome job!!
This is incredible, thank you :) I just wanted to see some of how an OS is built in practise, as in university it was all quite abstract. I will not ever build one myself, unless for the fun of it. But my curiosity is being sparked perfectly by this
Great series, hope to see more!
Thank you, more is definitely coming :)
This has been so far a most enjoyable series. Thank you. I'll be interested to see how far you take it, and whether you delve into real-time. I'm a retired software engineer who has written bare metal OSs (no file systems!) for embedded instrumentation starting with a 6502 microprocessor in the 1980s. I also wrote an OS for an 80186-based WiFi product in about 1995 (well, it was 802.11 frequency hopping, before the WiFi term was coined) - this was an example in how *not* to write a real-time OS/application because I became unnecessarily mired in locks/semaphores protecting unnecessary critical regions. Eventually I pursuaded my bosses to let me re-engineer it, and the company was almost immediately sold off. Not sure what that says about life, the universe and everything.
42!
This is definitely the best os development content i have seen so far, where did you find out how to do all this?
most likely by studying up on file systems, assembly, c, bioses and everything else required
I started just like you, reading tutorials (10 years ago there wasn't much on UA-cam). Then I went to university, got a job, got good at programming, and now I show others how to do it. There are plenty of resources on OS development if you know where to look. And if something isn't well documented, I can check the sources of open source kernels like linux, bsd etc.
If you're patient enough you just need Wikipedia honestly
@@legacywolf443 Wikipedia helps, but it lacks a lot of information. But there are plenty of resources available online. Some can be pretty hard to read (like manuals, datasheets), so reading source code from Linux or BSD can help a lot.
@@nanobyte-dev Well, but how to you find the right stuff in the source code? Me, being a computer science student myself, finds it very hard to even get an oversight about the code structure of Linux (or other open source projects, Darwin, Minix, FreeBSD, ...)
Thank you, very great article. I remember writing my own OS 25 years ago. You are master BTW ;)
That's interesting!
I want to take a minute to appreciate your music choice 🤩
Thank you, your explanation is one of the best and it serves perfectly as a complementary to other materials
Unfortunately my job and my kids won't let me work during the day...
I think I have lost track. It could be that code part is going really fast and I am not totally sure why we do the things we do. I felt the same in episode 2. Maybe it would benefit to keep reminding us why we do the things we are doing to not loose track.
Otherwise, I Imagine that it takes a lot of time what you are doing and I gratefully thank you to put in the effort and creating such helpful videos. Cheers.
Thanks for the feedback. I agree that the code is a bit too sped up in the earlier videos like this one.
Continu please, you are awesome 😎
Ah, the wonderful days of bios interrupts.
At least it saves you from spending a week writing a disk driver 🤣
trust me, one time it took me a month writing a disk driver
Interrupts are your friend... till you load the kernel :D
I love how the number of comments is dropping off the further in we get :D Just about hanging in there on the understanding of these.
Many people start watching, but not that many finish. It happens will any series like this.
You intro movie is very cool!
Please, make tutorial series about building an UEFI-based OS.
Awesome videos!
I just subscribed to your channel.
kindly dont fast forward the coding part. its the best part
Amazing job!
this is an awesome series and i'm learning a huge amount, however it would be helpful to not speed up the code-writing phase as much, I personally find it quite difficult to keep up.
Thank you, I've learned from my mistake and it gets better in newer videos.
@@nanobyte-dev awesome, thanks for taking the time to read my comment
Awesome tutorial so far! Though I would stop with the speeding up the videos! 😁
nanobyte: 'and ofc, c doesn't have boolean types'
stdbool.h: 'what?'
yeah I got confused by that and googled the standard to check lol. it was introduced in C99
@@pebble24 yep.
i dont get it, how do i get "root dir size"?
I hope the file system can lose weight…
😭
great work i love this
I think there's a mistake. in 6:32 the table shows 1 sectors per cluster, but in 9:51 you wrote that we have 2 sectors per cluster.
@ncurses.h nice catch!
Apologies for the late and somewhat unrelated comment, but which OS and theme are you using for these videos? I really like the clean and simplistic look.
Judging by the icon in the top left corner of the screen this would be Linux with the KDE desktop and I reckon he could be using the Breeze Dark theme?
In the first part of the series he said which OS he uses, it's Ubuntu if I'm not mistaken.
@@toslaw9615 In the comments of episode 2 he said he uses Kubuntu
@@Sebwazhere it's just Ubuntu with KDE instead of GNOME.
@@toslaw9615 oh ok
On a Mac, whenever I try to run your code I get:
gcc -g -o -v build/tools tools/fat/fat.c
ld: file cannot be mmap()ed, errno=22 path=build/tools in 'build/tools'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [build/tools/fat] Error 1
Any tips?
In this particular video, I was using Kubuntu. In later videos, I switched to Fedora.
Hi, where can I learn more about Assembly?
This is a very good series but i find it both difficult and irritating that the coding is spead up. I personally like when the person in the video explains what things does and when it is coded live and you do not have a voice over. but this is a good series and a good channel so i just wanted to give you a tip that you could better if you 1. code live(not recording and then make a voice over) and explain what things does. 2. dont speed it up.
I understand that, but for me, I script my videos because I can explain things better by not trying to explain at the same time that I'm coding. I also want to reduce how long the videos are, because if I didn't speed anything up the videos would be 1-2h long. In any case, at least in newer videos, I speed up a lot less aggressively and do my best to keep it easy to follow.
@@nanobyte-dev i understand you. And great 👍.
Even ChatGPT (Artificient Intelligence) suggested me this Video! Very good tutorial!!!
I get segment fault when running the fat program
I fixed it.
if you have this problem make sure your doing
ok = ok && (fread(bufferOut , g_BootSector.BytesPerSector, count, disk ) == count);
instead of
ok = ok && (fread(bufferOut , g_BootSector.BytesPerSector, count, SEEK_SET) == count);
XD
@@Shadowblitz16 i got the same problem, after use disk instead of seek_set the segment fault is gone. but readSectors will return false do you fix this ?
@@ningleizhang9060 I would recommend going to his github on this video's commit and comparing your code to his. It is most likely a typo somewhere on your end. I make typos all the time and have to compare my code to his. although if you can't even compile his version it could be a issue with one of the libraries, I had to update my gcc and binutils versions in one of the later videos I followed because they caused a segfault
@@Shadowblitz16 yes, after i replaced some code, everything is fine, thinks just somewhere typos.haha
wait WHAT? i had the same issue before. And never realised that this was the solution. Thanks
Hey , do you implement journaling for the filesystem in your series ?
i think this series is over man'
It's not, I promise. It just takes a lot of time to finish a video. I've been trying to keep a monthly schedule, but with kids it's hard to keep to it. I'm currently editing part 9, hoping to release it in maybe 2-3 weeks.
What did I do wrong? I can't get the OS to work anymore. :\
I'm sorry to hear that. If come to our discord channel, we can help you solve the problem.
@@nanobyte-dev okay, thanks.
Why do we have to write fat.c in assembly ?
fat.c is just writing the complicated assembly code into c so you can understand it and then you type the assembly code because its easier
12:53
when will be the next episode ??
you should user input in next episode
Next episode is in work, and I'm hoping to finish it within the next 2-3 weeks, these take a lot of time to do. It will be about writing code in C.
User input is not actually that hard in real mode, you can find this information online. Look for int16 ah=00 bios interrupt. My focus is to get to 64bit protected mode and cover all the basics, after which we will write some drivers for keyboard, storage, maybe even graphics.
could you say something more about user input or link a documentation or some tutorial
@@majkus5224 Join me on discord, and we can talk more about it :) discord.gg/RgHc5XrCEw
Timestamp for tommorow
13:37
18:25
Why do people like do have a bunch of spaces in a for loop? like 18:31 i would write that for loop like this:
for(uint32_t i=0;i
Personally, I disagree. I think spacing things out makes code much more readable.
@@nanobyte-dev in some cases but for the most parti like to compress the code.
If it helps you read and understand it better, sure, I have no problem with that. Me, and in my experience most other people, prefer using lots of spaces. A long time ago, screens were really small and you couldn't fit a lot of code which is why old code tends to be more compressed.
@@nanobyte-dev yeah it does. When i add a bunch of spacing the everything it starts to feel like python or something lol.
@@mastergamer4335 What's wrong if it feels like python? I love python.
i get the error src/bootloader/boot.asm:228: error: TIMES value -129 is negative
make: *** [Makefile:23: build/bootloader.bin] Error 1, and this is the code: times 510-($-$$) db 0 can you help?
just try to strip out the unnecessary code if you have some.
@@IlliaZhdanov wdym?
@@unixity_WasTaken This is mainly because your code is getting 129 bits beyond the 512 range, thus making it out of bound and creating this "negative times value", remove some unecessary instructions, use lower registers and lower the number of variables or the size of them, for instance, using AL instead of AX could make your code smaller ONLY if you are insterested in the lower bits of AX, and shrinking any variables can make a HUGE impact on the size too.
@@MiraiMindz i dont know alot of asm so can you show me an example
You either have too much code, or strings that are too long. 512 bytes fill up fast.
When i use the ./build/tools/fat build/main_floppy.img TEST TXT this gives me "Could Not read FAT!" all the time, it doesn't matter if the file doesn't exist, it always puts that or when I put ./build/tools/fat build/main_floppy.img "TEST TXT" I get a syntax error that generates Fat.c, please help
can you send the code?
im still on 19:37, but I always got:
[1] 3873 segmentation fault ./build/tools/fat build/main_floppy.img "TEST TXT"
idk why
what's your code?
Check the github repo linked in the description, you might have a typo