Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

types used to store the block size of linux `struct super_block`

struct super_block {
    struct list_head    s_list;        /* Keep this first */
    dev_t            s_dev;        /* search index; _not_ kdev_t */
    unsigned char        s_blocksize_bits;
    unsigned long        s_blocksize;
    ...

from what I read, s_blocksize and s_blocksize_bits contain the size of the block in bytes and bits respectively.
the number of bits are bigger than the number of bytes, so wouldn’t it make more sense if their types were the opposite way around? Like this:

    unsigned char        s_blocksize_bits;
    unsigned long        s_blocksize;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

s_blocksize_bits is not the size of the block in bits. It’s the number of bits in the blocksize. If you search the code to see how it’s used, it’s often in bit shifting, e.g.

            elen = (etype << 30) |
                    (elen +
                    (count << sb->s_blocksize_bits));

So, given a block number, you shift it by this many bits to get the corresponding offset (they assumed that blocks are always a power of 2 in size).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading