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.
User avatar
iansjack
Member
Member
Posts: 4789
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: File system hangs.

Post by iansjack »

There are visual front ends to gdb. ddd is pretty good. It looks old fashioned but it can give you a better view into your program than VSCode or Eclipse. It’s often best to compile with optimizations disabled when debugging. Of course things are a bit tricky if enabling optimisation brings to light fresh bugs. Using objdump to provide a complete assembler listing of your program is also a great help.

As I said before, debugging is pretty much the same whatever language you use (although maybe superficially different for languages like Prolog, Lisp, or Smalltalk +p- not mainstream languages for OS development). It’s a question of being methodical and inspecting the machine state at appropriate points. It also helps to RTFM so that you know what any error codes signify.

I think most of my gripes with this thread could be solved by reading the forum rules, most specifically https://wiki.osdev.org/Getting_Started# ... _Knowledge and http://www.catb.org/~esr/faqs/smart-questions.html .
zevvi
Posts: 21
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: File system hangs.

Post by zevvi »

Thanks :D
zevvi
Posts: 21
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: File system hangs.

Post by zevvi »

Ok i tried the tools learned some more about gdb & ddd :D and figured out that the return address probably gets thrown off :arrow: the stack (overflown probably) atleast from what i can gather by looking at the stack :shock: . Because after the return statement it tries returning to 0x000000 #-o but ofcourse there is no code there so it just hangs. But im stuck there so i would like some more help please [-o< !
nullplan
Member
Member
Posts: 1894
Joined: Wed Aug 30, 2017 8:24 am

Re: File system hangs.

Post by nullplan »

I already told you to look at the function you already identified. How big is the variable it declares, and how much do you write to it?
Carpe diem!
zevvi
Posts: 21
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: File system hangs.

Post by zevvi »

Sorry didnt see your post haha 😅

Code: Select all

(gdb) target remote 127.0.0.1:1234
Remote debugging using 127.0.0.1:1234
0x0000fff0 in ?? ()
(gdb) break fs_init
Breakpoint 1 at 0x200560: file src/fs/fs.c, line 13.
(gdb) ptype fs_root
type = struct {
    char name[32];
    uint32_t start_address;
    uint32_t end_address;
    uint8_t used;
} [256]
(gdb) print sizeof(fs_root)
$1 = 10496
(gdb) c
Breakpoint 1, fs_init () at src/fs/fs.c:13
13          char signature[6] = {0};
(gdb) dump binary memory fs_before.dump fs_root fs_root+10496
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
0x53fb5491 in ?? ()
(gdb) dump binary memory fs_after.dump fs_root fs_root+10496
(gdb) exit

Code: Select all

cmp -l fs_before.dump fs_after.dump | tail
 10505   0   3
so it writes 9 bytes over the limit of fs_root
but using gdb watches never catches it?
zevvi
Posts: 21
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: File system hangs.

Post by zevvi »

sebihepp wrote: Tue Jun 03, 2025 12:04 pm
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.
i Actually didnt i just used logging and debug statements and tests
(sorry i didnt mean gdt i meant gdb and i didnt know that was used for rust never heard of it)
sebihepp
Member
Member
Posts: 232
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: File system hangs.

Post by sebihepp »

Have a look at these lines of code:

Code: Select all

void fs_init() {
    char signature[6] = {0};
    ata_read_sectors(FS_SECTOR, 1, signature);
    (...)
zevvi
Posts: 21
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: File system hangs.

Post by zevvi »

sebihepp wrote: Wed Jun 04, 2025 6:04 am Have a look at these lines of code:

Code: Select all

void fs_init() {
    char signature[6] = {0};
    ata_read_sectors(FS_SECTOR, 1, signature);
    (...)
:?:
zevvi
Posts: 21
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: File system hangs.

Post by zevvi »

zevvi wrote: Wed Jun 04, 2025 7:52 am
sebihepp wrote: Wed Jun 04, 2025 6:04 am Have a look at these lines of code:

Code: Select all

void fs_init() {
    char signature[6] = {0};
    ata_read_sectors(FS_SECTOR, 1, signature);
    (...)
I dont see anything wrong?
sebihepp
Member
Member
Posts: 232
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: File system hangs.

Post by sebihepp »

zevvi wrote: Wed Jun 04, 2025 8:08 am
zevvi wrote: Wed Jun 04, 2025 7:52 am
sebihepp wrote: Wed Jun 04, 2025 6:04 am Have a look at these lines of code:

Code: Select all

void fs_init() {
    char signature[6] = {0};
    ata_read_sectors(FS_SECTOR, 1, signature);
    (...)
I dont see anything wrong?
How many bytes does ata_read_sectors() read? And how big is the variable signature?
zevvi
Posts: 21
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: File system hangs.

Post by zevvi »

sebihepp wrote: Wed Jun 04, 2025 8:18 am
zevvi wrote: Wed Jun 04, 2025 8:08 am
zevvi wrote: Wed Jun 04, 2025 7:52 am
I dont see anything wrong?
How many bytes does ata_read_sectors() read? And how big is the variable signature?

Code: Select all

(gdb) print sizeof(signature)
$1 = 6
(gdb)
(correct :mrgreen:)

and ata_lba_read reads 512 bytes 😅 (overflow could corrupt memory)
fix:

Code: Select all

    unsigned char temp[512] = {0};
    char signature[6] = {0};
    ata_read_sectors(FS_SECTOR, 1, temp);
    memcpy(signature, temp, 6);
sadly enough that doesnt fix the hang after

Code: Select all

Done reading fs sectors...
sebihepp
Member
Member
Posts: 232
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: File system hangs.

Post by sebihepp »

You can simply do this:

Code: Select all

void fs_init() {
    char temp[512] = {0};
    ata_read_sectors(FS_SECTOR, 1, temp);
    terminal_writestring("Checking signature...\n");
    if (strncmp(temp, FS_SIGNATURE, 5) == 0) {
Next, I am not sure why you add 511 to sizeof(fs_root)?

Code: Select all

ata_read_sectors(FS_SECTOR + 1, (sizeof(fs_root) + 511) / 512, fs_root);
Why not just divide by 512? What is you train of thought?

I am also not sure what filesystem you use... did you develop your own?
zevvi
Posts: 21
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: File system hangs.

Post by zevvi »

sebihepp wrote: Wed Jun 04, 2025 10:34 am You can simply do this:

Code: Select all

void fs_init() {
    char temp[512] = {0};
    ata_read_sectors(FS_SECTOR, 1, temp);
    terminal_writestring("Checking signature...\n");
    if (strncmp(temp, FS_SIGNATURE, 5) == 0) {
thanks :P :!:
sebihepp wrote: Wed Jun 04, 2025 10:34 am Next, I am not sure why you add 511 to sizeof(fs_root)?

Code: Select all

ata_read_sectors(FS_SECTOR + 1, (sizeof(fs_root) + 511) / 512, fs_root);
Why not just divide by 512? What is you train of thought?
yeah dont know late at night programming.
sebihepp wrote: Wed Jun 04, 2025 10:34 am I am also not sure what filesystem you use... did you develop your own?
yes very simple just:

Code: Select all

typedef struct __attribute__((packed)) {
    char name[FS_NAME_MAX];
    uint32_t start_address;
    uint32_t end_address;
    uint8_t used;
} fs_entry_t;

static fs_entry_t fs_root[FS_MAX_ENTRIES];
thats all.
zevvi
Posts: 21
Joined: Wed May 28, 2025 8:20 am
GitHub: https://github.com/Zeviraty

Re: File system hangs.

Post by zevvi »

I still cant figure it out :(
sebihepp
Member
Member
Posts: 232
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: File system hangs.

Post by sebihepp »

Did you removed that "+ 511"?
Post Reply