File system hangs.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
zevvi
Posts: 18
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

File system hangs.

Post by zevvi »

github.com/Zeviraty/AOPOS is the code
after fs_init
it hangs and it happens at every return statement it just hangs not executing the next code i dont know what to do
roast me or stuff but just help me
User avatar
iansjack
Member
Member
Posts: 4787
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: File system hangs.

Post by iansjack »

What debugging have you done? For starters, enabling the qemu monitor will allow you to inspect the machine state when it hangs. You could gain even more info by running under gdb. A hang ought to be easier to trace than a triple-fault.
zevvi
Posts: 18
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: File system hangs.

Post by zevvi »

Sorry but i cant figure it out :(
User avatar
iansjack
Member
Member
Posts: 4787
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: File system hangs.

Post by iansjack »

If you are getting stuck at this stage of the proceedings and are not prepared, or able, to use common debugging techniques then perhaps you should consider whether OS development is a suitable hobby.

It's not going to get any easier when you move on to more advanced stuff.

I don't mean to be rude, but this sort of programming is not for everyone.
zevvi
Posts: 18
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: File system hangs.

Post by zevvi »

Yeah i get it but this is my first time working with c and its ecosystem so im new to that but i have created a wordle os in rust and more projects in python & rust so its just that the c ecosystem is new to me
nullplan
Member
Member
Posts: 1893
Joined: Wed Aug 30, 2017 8:24 am

Re: File system hangs.

Post by nullplan »

If the C ecosystem is new to you, the most sensible place to start would be to try your hand at userspace first. There will be plenty of reason to use debuggers doing that, and you would gain valuable experience doing so.

In this case, you have already identified the function that is doing something wrong. It is fs_init(). Here's a hint: How big is the single variable that function declares, and how many bytes does the code attempt to write in it?
Carpe diem!
User avatar
iansjack
Member
Member
Posts: 4787
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: File system hangs.

Post by iansjack »

The process of debugging is pretty much the same whichever language - high level or low level - you use. I agree that if you are not comfortable with programming in C then an OS is not the place to learn.

If you’re good at Rust then that’s a fine language to write an OS in.
zevvi
Posts: 18
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: File system hangs.

Post by zevvi »

I am not uncomfortable [-X just unfamiliar and the programming is also no problem because the syntax is very similar to other programming languages. Just the debugging is completely different than normal :oops: so i would love for some help :?: on where to begin to debug this issue.
iansjack wrote: Mon Jun 02, 2025 10:25 am If you’re good at Rust then that’s a fine language to write an OS in.
Because i already did that :mrgreen: i want to do it in another programming language :idea: that is lower level to learn more of the stuff that happens below the abstraction layer :mrgreen:.
Octocontrabass
Member
Member
Posts: 5815
Joined: Mon Mar 25, 2013 7:01 pm

Re: File system hangs.

Post by Octocontrabass »

zevvi wrote: Mon Jun 02, 2025 10:50 amJust the debugging is completely different than normal
How did you debug your Rust OS?
User avatar
iansjack
Member
Member
Posts: 4787
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: File system hangs.

Post by iansjack »

In what way is debugging C different from debugging Rust?

You can use the same tool (gdb) or you can use the same simpler techniques (e.g. inserting statements to print the value of variables at certain points of the program or to show how far a program progresses before ceasing to work). And use of the qemu monitor is the same whatever language the program is written in. If anything it should be easier with C code as it’s closer to the underlying machine than Rust is.

I’m afraid I don’t see any evidence that you have done this sort of debugging. You simply say “my program hangs - help”. That’s not much information. You tell us you know where the program hangs but give no evidence of how you came to that conclusion.

As has already been suggested, postpone writing an OS in C until you are familiar, or better still comfortable - which to me indicates a greater level of competence - with the language. Write some straightforward user programs and learn how to use the toolset and debugger - learn to walk (in C) before trying to run.
thewrongchristian
Member
Member
Posts: 450
Joined: Tue Apr 03, 2018 2:44 am

Re: File system hangs.

Post by thewrongchristian »

iansjack wrote: Mon Jun 02, 2025 11:11 am As has already been suggested, postpone writing an OS in C until you are familiar, or better still comfortable - which to me indicates a greater level of competence - with the language. Write some straightforward user programs and learn how to use the toolset and debugger - learn to walk (in C) before trying to run.
Further to this, I'd recommend writing a useful runtime toolkit that you can use in user and kernel mode. The C runtime is pitiful, providing little in the way of abstractions or containers.

I'd recommend writing standard methods of organizing data, as OSes need to do a lot of that.

My goto runtime interface is the Map, using pointer sized integer keys and values, which can be wrapped and used as pointers if required. A Map can be:
  • Ordered - Ordered key maps allow you to quickly and efficiently search using binary search, implemented as a sorted array or a binary search tree. Ordered key maps are also suitable for range searching.
  • Unordered - Unordered key maps are typically hash tables, less useful for ranges, but in the absence of hash collisions, look-ups are O(1).
  • Arrays - Indexed by key, I wrap my arrays in a Map interface to hide things such as resizing the array, obviating the need for client code to implement range checking (my wrapper does that.) Slower than a raw array, but much safer.
The other main data structure I rely on is the List. My lists are intrusive data structures, and used for lists of threads (scheduler list, lock waiting list), lists of memory regions (used in my heap implementation,) and timer lists.

Almost all my code uses ordered key maps and lists, and I don't even actually implement hash based map yet.

But implementing all this in a manner that is platform independent will give you a good grounding in C, and you can use it in user space tools. I use my data structures in both my kernel and build time tools used to implement domain specific languages used to generate boiler plate code such as my system call interface.

You can also implement in user space things like threading libraries, implementing task switching in a user process to implement threads will give you a good springboard into implementing such functionality in a kernel.
zevvi
Posts: 18
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: File system hangs.

Post by zevvi »

iansjack wrote: Mon Jun 02, 2025 11:11 am In what way is debugging C different from debugging Rust?
Well we ere talking about gdt and (of course) that doesnt exist in rust.
iansjack wrote: Mon Jun 02, 2025 11:11 am I’m afraid I don’t see any evidence that you have done this sort of debugging. You simply say “my program hangs - help”. That’s not much information. You tell us you know where the program hangs but give no evidence of how you came to that conclusion.
I came to that conclusion because i added debug statements and found out thats where it hangs it executes before the return statement and not after. And sorry if i dont give much evidence english is not my main language im dutch and that makes it hard to communicate.
iansjack wrote: Mon Jun 02, 2025 11:11 am As has already been suggested, postpone writing an OS in C until you are familiar, or better still comfortable - which to me indicates a greater level of competence - with the language. Write some straightforward user programs and learn how to use the toolset and debugger - learn to walk (in C) before trying to run.
Sorry for me trying something new you dont have to be rude about it and instead of constantly saying what i shouldn't do say where i can begin and help me to start instead of gatekeeping it and saying that i shouldn't do this.
User avatar
iansjack
Member
Member
Posts: 4787
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: File system hangs.

Post by iansjack »

I'm not sure what you mean by "gdt". If you mean Global Descriptor Table then of course it exists, for x86 processors, whatever implementation language you use. If you meant "gdb", well that does exist for Rust - and is a very useful tool.

OK, good to see that you used debugging statements (though not so good that you didn't give us any information about what debugging you had done). As with computer languages, I don't see that English not being your native language is relevant to this lack of information.

I'm sorry that you take umbrage at what is intended as constructive criticism and suggestion as to how you can improve your proficiency in C before attempting complex projects. But this site is not really intended to be a learning resource for basic C - there are plenty of those available - and assumes a certain level of knowledge and willingness to learn rather than just asking for solutions to problems.

So, rather than annoy you further I'll bow out at this stage.
Octocontrabass
Member
Member
Posts: 5815
Joined: Mon Mar 25, 2013 7:01 pm

Re: File system hangs.

Post by Octocontrabass »

zevvi wrote: Tue Jun 03, 2025 2:26 amWell we ere talking about gdt and (of course) that doesnt exist in rust.
Which debugger do you use for Rust?
sebihepp
Member
Member
Posts: 229
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: File system hangs.

Post by sebihepp »

Octocontrabass wrote: Tue Jun 03, 2025 9:25 am
zevvi wrote: Tue Jun 03, 2025 2:26 amWell we ere talking about gdt and (of course) that doesnt exist in rust.
Which debugger do you use for Rust?
I think he is used to GUI-debuggers. When I started learning C/C++, I used Microsoft Visual Studio C/C++ and learned debugging with the UI there. I am still learning to use gdb as a command line tool. The Visual Studio UI back then you just clicked on a line to set a breakpoint and if you hovered your mouse above a variable in the code, it showed its value.

I am still working on my hobby OS project and learned gdb just half a year ago. Well, with the built-in help I got comfortable rather fast and easy. My problem with gdb and OS dev in general is, that often if I want to watch a variable, it was optimized out and therefore I can't see the value anymore. :D
Post Reply