Skip to contentSkip to conversation

`disk` level IO: how it works?

DISCUSSION Oleg Strikov 2 participants 2 messages Jan 22, 2008

lore
Share & tools
lore
#0 lore raw

Good day!
I'm trying to look into grub low-level disk IO.
I've started exploration with my own low-level FS block reader, but it works too strange:

/* I know that such code is incorrect due to low-level FS operations but i'm trying to understand some principals of low level IO :) */

file = grub_file_open (FILE);
fs_data = (struct grub_ext2_data *) file->data;
disk = fs_data->disk;

fsize = grub_file_size(file);
block_num = (fsize >> LOG2_BLOCK_SIZE (fs_data));
if (((grub_off_t) block_num << LOG2_BLOCK_SIZE (fs_data)) != fsize)

    block_num++;

log2_blksz = LOG2_EXT2_BLOCK_SIZE (fs_data);

blocks = grub_malloc (sizeof (int) * block_num);

fshelp_node = &fs_data->diropen;

for (i = 0; i < block_num; i++)

  {
    blocks[i] = grub_ext2_read_block_wrapper (fshelp_node, i);

}

grub_disk_read(fs_data->disk,

  \
           grub_le_to_cpu32 (blocks[i]) << log2_blksz,               \
           0,
                                                                    \
           sizeof (struct my_entry),
         \
           (char *) entry);

grub_ext2_read_block_wrapper its my exported wrapper from ext2.c that calls original grub_ext2_read_block with the same parameters.

Problem: I have extended partition with two logical (hd0,5) & (hd0,6) If I place FILE on (hd0,5) (at the begining of my physical disk) - all is OK If I place FILE on (hd0,6) i get out of partition at grub_disk_read.

I run grub2 using qemu and gdb block num seems to be correct (smth like 4500), but i don't pass grub_ext_read_block range check :(

P.S. I'm right that disk represents one partition (logical or primary), not a group?

Thanks!

#1 lore raw
Quoted 37 lines · Oleg Strikov

Good day!
I'm trying to look into grub low-level disk IO.
I've started exploration with my own low-level FS block reader, but it works too strange:

/* I know that such code is incorrect due to low-level FS operations but i'm trying to understand some principals of low level IO :) */

file = grub_file_open (FILE);
fs_data = (struct grub_ext2_data *) file->data;
disk = fs_data->disk;

fsize = grub_file_size(file);
block_num = (fsize >> LOG2_BLOCK_SIZE (fs_data));
if (((grub_off_t) block_num << LOG2_BLOCK_SIZE (fs_data)) != fsize)

    block_num++;

log2_blksz = LOG2_EXT2_BLOCK_SIZE (fs_data);

blocks = grub_malloc (sizeof (int) * block_num);

fshelp_node = &fs_data->diropen;

for (i = 0; i < block_num; i++)

  {
    blocks[i] = grub_ext2_read_block_wrapper (fshelp_node, i);

}

grub_disk_read(fs_data->disk,

  \
           grub_le_to_cpu32 (blocks[i]) << log2_blksz,               \
           0,
                                                                    \
           sizeof (struct my_entry),
         \
           (char *) entry);
Quoted 2 lines

grub_ext2_read_block_wrapper its my exported wrapper from ext2.c that calls original grub_ext2_read_block with the same parameters.

I find this very confusing. Could you rephrase your question to make it more specific? Like, what are you trying to do or which function you don't understand.

Quoted 3 lines

Problem: I have extended partition with two logical (hd0,5) & (hd0,6) If I place FILE on (hd0,5) (at the begining of my physical disk) - all is OK If I place FILE on (hd0,6) i get out of partition at grub_disk_read.

Did you check if debug options give you anything useful? Try "set debug=disk", and maybe also "set debug=fs".

What's the size of your disk, and your partitions?

Quoted 2 lines

P.S. I'm right that disk represents one partition (logical or primary), not a group?

I think grub_disk_t can either be a partition or a disk.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)