函数源码

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source File:fs\mpage.c Create Date:2022-07-29 10:46:57
首页 Copyright©Brick

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * support function for mpage_readpages.  The fs supplied get_block might
 * return an up to date buffer.  This is used to map that buffer into
 * the page, which allows readpage to avoid triggering a duplicate call
 * to get_block.
 *
 * The idea is to avoid adding buffers to pages that don't already have
 * them.  So when the buffer is up to date and the page size == block size,
 * this marks the page up to date instead of adding new buffers.
 */
static void
map_buffer_to_page(struct page *page, struct buffer_head *bh, int page_block)
{
    struct inode *inode = page->mapping->host;
    struct buffer_head *page_bh, *head;
    int block = 0;
 
    if (!page_has_buffers(page)) {
        /*
         * don't make any buffers if there is only one buffer on
         * the page and the page just needs to be set up to date
         */
        if (inode->i_blkbits == PAGE_SHIFT &&
            buffer_uptodate(bh)) {
            SetPageUptodate(page);   
            return;
        }
        create_empty_buffers(page, i_blocksize(inode), 0);
    }
    head = page_buffers(page);
    page_bh = head;
    do {
        if (block == page_block) {
            page_bh->b_state = bh->b_state;
            page_bh->b_bdev = bh->b_bdev;
            page_bh->b_blocknr = bh->b_blocknr;
            break;
        }
        page_bh = page_bh->b_this_page;
        block++;
    } while (page_bh != head);
}