<br><br><div class="gmail_quote">On Thu, Oct 20, 2011 at 3:04 AM, Kai Meyer <span dir="ltr"><<a href="mailto:kai@gnukai.com">kai@gnukai.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I'm trying to poke around an ext4 file system. I can submit a bio for<br>
the correct block, and read in what seems to be the correct information,<br>
but when I try to memcpy my char *buffer to a reference to a struct I've<br>
made, it just doesn't seem to work. The relevant code looks like this:<br>
<br>
typedef struct ext2_superblock {<br>
/* 00-03 */ uint32_t e2sb_inode_count;<br>
/* 04-07 */ uint32_t e2sb_block_count;<br>
/* 08-11 */ uint32_t e2sb_blocks_reserved;<br>
/* 12-15 */ uint32_t e2sb_unallocated_blocks;<br>
/* 16-19 */ uint32_t e2sb_unallocated_inodes;<br>
/* 20-23 */ uint32_t e2sb_sb_block;<br>
/* 24-27 */ uint32_t e2sb_log_block_size;<br>
/* 28-31 */ uint32_t e2sb_log_fragment_size;<br>
/* 32-35 */ uint32_t e2sb_num_blocks_per_group;<br>
/* 36-39 */ uint32_t e2sb_num_frag_per_group;<br>
/* 40-43 */ uint32_t e2sb_num_inodes_per_group;<br>
/* 44-47 */ uint32_t e2sb_last_mount_time;<br>
/* 48-51 */ uint32_t e2sb_last_written_time;<br>
/* 52-53 */ uint16_t e2sb_num_mounted;<br>
/* 54-55 */ uint16_t e2sb_num_allowed_mounts;<br>
/* 56-57 */ uint16_t e2sb_signature;<br>
/* 58-59 */ uint16_t e2sb_fs_state;<br>
/* 60-61 */ uint16_t e2sb_error_action;<br>
/* 62-63 */ uint16_t e2sb_ver_minor;<br>
/* 64-67 */ uint32_t e2sb_last_check;<br>
/* 68-71 */ uint32_t e2sb_time_between_checks;<br>
/* 72-75 */ uint32_t e2sb_os_id;<br>
/* 76-79 */ uint32_t e2sb_ver_major;<br>
/* 80-81 */ uint16_t e2sb_uid;<br>
/* 82-83 */ uint16_t e2sb_gid;<br>
} e2sb;<br>
<br>
<br>
char *buffer;<br>
uint32_t *pointer;<br>
e2sb sb;<br>
buffer = __bio_kmap_atomic(bio, 0, KM_USER0);<br>
pointer = (uint32_t *)buffer;<br>
printk(KERN_DEBUG "sizeof pbd->sb %lu\n", sizeof(bpd->sb));<br>
printk(KERN_DEBUG "Inode Count: %u\n", pointer[0]); /* Works! */<br>
printk(KERN_DEBUG "Block Count: %u\n", pointer[1]); /* Works! */<br>
printk(KERN_DEBUG "Block Reserved: %u\n", pointer[2]); /* Works! */<br>
printk(KERN_DEBUG "Unallocated blocks: %u\n", pointer[3]); /* Works! */<br>
printk(KERN_DEBUG "Unallocated inodes: %u\n", pointer[4]); /* Works! */<br>
memcpy(buffer, &sb, sizeof(sb));<br></blockquote><div>This should be : -<br>memcpy(&sb, buffer, sizeof(sb));<br> <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
__bio_kunmap_atomic(bio, KM_USER0);<br>
printk(KERN_DEBUG "e2sb_debug: Total number of inodes in file system<br>
%u\n", sb->e2sb_inode_count);/* Doesn't work! */<br>
printk(KERN_DEBUG "e2sb_debug: Total number of blocks in file<br>
system%u\n", sb->e2sb_block_count); /* Doesn't work! */<br>
<br>
My code is actually much more verbose. The values I get from indexing<br>
into pointer are correct, and match what I get from dumpe2fs. The values<br>
I get from the e2sb struct are not. They are usually 0. I would imagine<br>
that memcpy is the fastest way to copy data from buffer instead of<br>
casting the pointer to something else, and using array indexing to get<br>
the values.<br>
<br>
I struggled to find where ext4 actually does this, so I'm making this up<br>
as I go along. Any thing that you see that I should be doing a different<br>
way that isn't actually part of my question is welcome too.<br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</blockquote></div><br>Regards,<br>Rohan Puri<br>