buf_bread
Synchronously read a block of a file.
Declaration
errno_t buf_bread(vnode_t vp, daddr64_t blkno, int size, kauth_cred_t cred, buf_t *bpp);Parameters
- vp:
The file from which to read.
- blkno:
The logical (filesystem) block number to read.
- size:
Size of block; do not use for sizes > 4K.
- cred:
Credential to store and use for reading from disk if data are not already in core.
- bpp:
Destination pointer for buffer.
Return Value
0 for success, or an error from buf_biowait().
Discussion
buf_bread() is the traditional way to read a single logical block of a file through the buffer cache. It tries to find the buffer and corresponding page(s) in core, calls VNOP_STRATEGY if necessary to bring the data into memory, and waits for I/O to complete. It should not be used to read blocks of greater than 4K (one VM page) in size; use cluster routines for large reads. Indeed, the cluster layer is a more efficient choice for reading DATA unless you need some finely-tuned semantics that it cannot provide.
See Also
Buffers
buf_allocbuf_attrbuf_bawritebuf_bdwritebuf_biodonebuf_biowaitbuf_blknobuf_breadnbuf_brelsebuf_bwritebuf_callbackbuf_clearbuf_clear_redundancy_flagsbuf_clearflagsbuf_clonebuf_countbuf_create_shadowbuf_dataptrbuf_devicebuf_dirtyendbuf_dirtyoffbuf_drvdatabuf_errorbuf_flagsbuf_flushdirtyblksbuf_freebuf_fromcachebuf_fsprivatebuf_fuabuf_getblkbuf_geteblkbuf_invalblknobuf_invalidateblksbuf_iteratebuf_lblknobuf_mapbuf_markagedbuf_markcleanbuf_markdelayedbuf_markeintrbuf_markfuabuf_markinvalidbuf_markstaticbuf_meta_breadbuf_meta_breadnbuf_procbuf_rcredbuf_redundancy_flagsbuf_resetbuf_residbuf_set_redundancy_flagsbuf_setblknobuf_setcallbackbuf_setcountbuf_setdataptrbuf_setdevicebuf_setdirtyendbuf_setdirtyoffbuf_setdrvdatabuf_seterrorbuf_setflagsbuf_setfsprivatebuf_setlblknobuf_setresidbuf_setsizebuf_setuplbuf_setvnodebuf_shadowbuf_sizebuf_staticbuf_strategybuf_unmapbuf_uplbuf_uploffsetbuf_validbuf_vnodebuf_wcredbufattr_ioscheduledbufattr_markioscheduled