Reading fragments on disk (kernel programming)

I want to read the first (s) fragments of my disk. I am currently developing a driver, and I want to store (and retrieve) some metadata (the amount of time that all pieces are allowed) in the first fragment of my disk

I see How to read a sector using the bio query in the Linux kernel and then I start writing code for the read part:

struct bio *bio = bio_alloc(GFP_NOIO, 1);
struct page *page =  alloc_page(GFP_KERNEL)
struct completion event;
bio->bi_bdev = conf->disks[0].rdev;
bio->bi_sector = (sector_t) 0; 
bio_add_page(bio, page, (sizeof(struct nuda_table)) * conf->nbr_chunk, 0);
init_completion(&event);            
bio->bi_private = &event;
bio->bi_end_io = readComplete;

submit_bio(READ | REQ_SYNC, bio);
wait_for_completion(&event);
bio_put(bio);

But then I do not know where the data that I read is stored. In struct page? One more question: is there a parameter length in bio_add_page(), does this mean that these are bytes? or pieces? or other things?

Thank you in advance

+4
source share
1 answer

page_address (void *), . , , .

kmap , :

void *kmap(struct page *page)
{
        might_sleep();
        if (!PageHighMem(page))
               return page_address(page);
        return kmap_high(page);
}
+2

Source: https://habr.com/ru/post/1584755/


All Articles