<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Thanks for catching that :) I knew it would be something simple.<br>
<br>
On 10/19/2011 10:00 PM, rohan puri wrote:
<blockquote
cite="mid:CALJfu6NM4dfkKxeKgttqUnq3u=F+eHqds7ajh5CzshAH3nvH_w@mail.gmail.com"
type="cite"><br>
<br>
<div class="gmail_quote">On Thu, Oct 20, 2011 at 3:04 AM, Kai
Meyer <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:kai@gnukai.com">kai@gnukai.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
0.8ex; border-left: 1px solid rgb(204, 204, 204);
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 moz-do-not-send="true"
href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a moz-do-not-send="true"
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>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Kernelnewbies mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a>
<a class="moz-txt-link-freetext" href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a>
</pre>
</blockquote>
</body>
</html>