thanks! your reply it's very useful to me!!<br><br>yes, it' security purposes! i just trust dom0 , but not trust domU. i want to save the blocks of improtant files of domU into dom0, when write operation happend in domU, domU will send the request struct , which contain the sectors need to write, to dom0, next, in dom0 compare the sector number. if the sector numbers is which i want to protect, the write operation will be stoped by dom0. even if intruder  get the root privilege in domU, he can't change the file (for example :files in /bin dir) which i protected. <br>

<br>now, another question confused me:<br><br>in the request struct , there are two group of sector info. and i don't know what's the diff between them. and how to get the all sector numbers of a request for a file?<br>

<br>    sector_t sector;        /* next sector to submit */<br>    unsigned long nr_sectors;    /* no. of sectors left to submit */<br>    /* no. of sectors left to submit in the current segment */<br>    unsigned int current_nr_sectors;<br>

/***************************************************************************************************/<br>    sector_t hard_sector;        /* next sector to complete */<br>    unsigned long hard_nr_sectors;    /* no. of sectors left to complete */<br>

    /* no. of sectors left to complete in the current segment */<br>    unsigned int hard_cur_sectors;<br><br>Thanks very much!<br><br><div class="gmail_quote">2009/6/2 Theodore Tso <span dir="ltr"><<a href="mailto:tytso@mit.edu">tytso@mit.edu</a>></span><br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On Tue, Jun 02, 2009 at 08:05:48PM +0800, Zhang Shukun wrote:<br>
> thanks for your answer!<br>
><br>
> my goal is : in kernel space , get the specific disk block numbers(or sector<br>
> number) of a file(such as /bin/ls).<br>
><br>
> because i want to use the block number in DomU, which is a VM in xen. when i<br>
> read or write a file in DomU, front end driver will send the block number to<br>
> back-end driver Dom0 , and then in dom0 i can check if the block could be<br>
> write or not.<br>
<br>
</div>The filesystem does that already (send the block number to the<br>
back-end driver) when it wants to read or write the block form the<br>
filesystem.  If the goal is to do this for security purposes, you<br>
should be calculating the inode->block mapping in dom0, *not* in domU.<br>
After all, if you don't trust the domU to enforce the normal security<br>
restrictions which the kernel enforces, why would you trust domU to<br>
give you the correct inode->block mapping so that dom0 can do some<br>
kind of security access check?<br>
<br>
In any case, to answer your specific question, to convert from a<br>
struct inode to a struct ext3_inode_info, *if* you know that a<br>
particular struct inode from an ext3 filesystem (as opposed to an ext2<br>
filesystem, ext4 filesystem, FAT filesystem, a networking socket,<br>
etc.) you can use the EXT3_I function to get from an struct inode to<br>
struct ext3_inode_info:<br>
<br>
static inline struct ext3_inode_info *EXT3_I(struct inode *inode)<br>
{<br>
        return container_of(inode, struct ext3_inode_info, vfs_inode);<br>
}<br>
<br>
What happens here is that the struct inode is actually embedded inside<br>
the ext3_inode_info structure, and what is cached is the<br>
ext3_inode_info structure.  So container_of() basically takes a<br>
pointer to the struct inode, and substracts the offset from the<br>
beginning of ext3_inode_info and the vfs_inode element in<br>
ext3_inode_info, to get a pointer to the struct ext3_inode_info.<br>
<br>
If this isn't an ext3 inode, though, your kernel code will likely<br>
crash from the nonsense it will get when it tries to interpret data<br>
that isn't a struct ext3_inode_info.  In general, the *only* place<br>
where well-written, maintainable, kernel code should try to use EXT3_I<br>
is inside fs/ext3/*.c.<br>
<br>
                                        - Ted<br>
</blockquote></div><br><br clear="all"><br>-- <br>Best regards,<br>张树坤<br>北京理工大学,计算机科学技术学院<br>Sucan<br>Computer Department,Beijing Institute of Technology,China<br>