include/linux/bvec.h

Source file repositories/reference/linux-study-clean/include/linux/bvec.h

File Facts

System
Linux kernel
Corpus path
include/linux/bvec.h
Extension
.h
Size
9156 bytes
Lines
347
Domain
Core OS
Bucket
Core Kernel Interface
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct bio_vec {
	struct page	*bv_page;
	unsigned int	bv_len;
	unsigned int	bv_offset;
};

/**
 * bvec_set_page - initialize a bvec based off a struct page
 * @bv:		bvec to initialize
 * @page:	page the bvec should point to
 * @len:	length of the bvec
 * @offset:	offset into the page
 */
static inline void bvec_set_page(struct bio_vec *bv, struct page *page,
		unsigned int len, unsigned int offset)
{
	bv->bv_page = page;
	bv->bv_len = len;
	bv->bv_offset = offset;
}

/**
 * bvec_set_folio - initialize a bvec based off a struct folio
 * @bv:		bvec to initialize
 * @folio:	folio the bvec should point to
 * @len:	length of the bvec
 * @offset:	offset into the folio
 */
static inline void bvec_set_folio(struct bio_vec *bv, struct folio *folio,
		size_t len, size_t offset)
{
	unsigned long nr = offset / PAGE_SIZE;

	WARN_ON_ONCE(len > UINT_MAX);
	bvec_set_page(bv, folio_page(folio, nr), len, offset % PAGE_SIZE);
}

/**
 * bvec_set_virt - initialize a bvec based on a virtual address
 * @bv:		bvec to initialize
 * @vaddr:	virtual address to set the bvec to
 * @len:	length of the bvec
 */
static inline void bvec_set_virt(struct bio_vec *bv, void *vaddr,
		unsigned int len)
{
	bvec_set_page(bv, virt_to_page(vaddr), len, offset_in_page(vaddr));
}

/**
 * bvec_folio - Return the first folio referenced by this bvec
 * @bv: bvec to access
 *
 * A bvec can contain non-folio memory, so this should only be called by
 * the creator of the bvec; drivers have no business looking at the owner
 * of the memory.  It may not even be the right interface for the caller
 * to use as a bvec can span multiple folios.  You may be better off using
 * something like bio_for_each_folio_all() which iterates over all folios.
 */
static inline struct folio *bvec_folio(const struct bio_vec *bv)
{
	return page_folio(bv->bv_page);
}

struct bvec_iter {
	/*
	 * Current device address in 512 byte sectors. Only updated by the bio
	 * iter wrappers and not the bvec iterator helpers themselves.
	 */
	sector_t		bi_sector;

	/*
	 * Remaining size in bytes.
	 */
	unsigned int		bi_size;

	/*
	 * Current index into the bvec array. This indexes into `bi_io_vec` when
	 * iterating a bvec array that is part of a `bio`.
	 */
	unsigned int		bi_idx;

	/*
	 * Current offset in the bvec entry pointed to by `bi_idx`.
	 */
	unsigned int		bi_bvec_done;
} __packed __aligned(4);

struct bvec_iter_all {
	struct bio_vec	bv;

Annotation

Implementation Notes