Ext2: reading directory entries reads zeros.

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.
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: Ext2: reading directory entries reads zeros.

Post by jnc100 »

ch3ll0v3k wrote:I have also strange extra characters at the end of each "file_name". can"t figure out what can it be.
I see two possibilities:
- You are not reading the length of the name correctly.
- You are reading the length of the name correctly but not null-terminating the actual name after this length.

Regards,
John.
User avatar
osdever
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am
Contact:

Re: Ext2: reading directory entries reads zeros.

Post by osdever »

ch3ll0v3k wrote:I have also strange extra characters at the end of each "file_name". can"t figure out what can it be.
#-o

on the second screenshot it is better visible
It must be:

Code: Select all

/.
/ ..
/.Trash-1000
/bin
/.Trash-0
/usr
/src
/boot
/os.iso
/root_dir_12
/root_dir_11
/root_dir_13
/lib
/var
/etc
/dev
/tmp
/run
/root_dir_15
/root_dir_14
At least your Ext2 code works :( :|
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing

OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
User avatar
crunch
Member
Member
Posts: 81
Joined: Wed Aug 31, 2016 9:53 pm
Libera.chat IRC: crunch
Location: San Diego, CA

Re: Ext2: reading directory entries reads zeros.

Post by crunch »

ch3ll0v3k wrote:I have also strange extra characters at the end of each "file_name". can"t figure out what can it be.
#-o

on the second screenshot it is better visible
It must be:

Code: Select all

/.
/ ..
/.Trash-1000
/bin
/.Trash-0
/usr
/src
/boot
/os.iso
/root_dir_12
/root_dir_11
/root_dir_13
/lib
/var
/etc
/dev
/tmp
/run
/root_dir_15
/root_dir_14
d->name[d->name_len] = '\0';

or you're not incrementing your directory entries by the right amount
ch3ll0v3k
Posts: 10
Joined: Sat Oct 01, 2016 1:26 am

Re: Ext2: reading directory entries reads zeros.

Post by ch3ll0v3k »

Finally found it: [-o< :D

My structure to store directory info was wrong.

Code: Select all

// this was wrong
typedef struct {
    // --------------------------------------------------------------
    uint32_t    inode;                      // [DIR] Inode number
    uint16_t    rec_len;                    // [DIR] Directory entry length
    uint16_t     name_len;                   // [DIR] Name length
    int8_t      name[ 255 ];                // [DIR] File name
    // --------------------------------------------------------------
} __attribute__ ((packed)) ext2_dir_entry_t;

Code: Select all

// and now it is
typedef struct {
    // --------------------------------------------------------------
    uint32_t    inode;                      // [DIR] Inode number
    uint16_t    rec_len;                    // [DIR] Directory entry length
    uint8_t     name_len;                   // [DIR] Name length
    uint8_t     file_type;                  // [DIR] file type
    int8_t      name[ 255 ];                // [DIR] File name
    // --------------------------------------------------------------
} __attribute__ ((packed)) ext2_dir_entry_t;
thx everyone!
Post Reply