Page 3 of 3

Re: Ext2: reading directory entries reads zeros.

Posted: Sun Oct 02, 2016 12:47 pm
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.

Re: Ext2: reading directory entries reads zeros.

Posted: Sun Oct 02, 2016 1:39 pm
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 :( :|

Re: Ext2: reading directory entries reads zeros.

Posted: Sun Oct 02, 2016 2:19 pm
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

Re: Ext2: reading directory entries reads zeros.

Posted: Mon Oct 03, 2016 4:59 am
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!