---
name: "bwrite"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/berase"
---

# bwrite(3)

read and write blocks of a UFS file system

Part of [berase(3)](/berase/3.md).

## NAME

**bread**, **bwrite** – read and write blocks of a UFS file system

## LIBRARY

library “libufs”

## SYNOPSIS

**#include \<sys/param.h\>**

**#include \<sys/mount.h\>**

**#include \<ufs/ufs/ufsmount.h\>**

**#include \<ufs/ufs/dinode.h\>**

**#include \<ufs/ffs/fs.h\>**

**#include \<libufs.h\>**

*ssize\_t*\

**bread**(*struct uufsd \*disk*, *ufs2\_daddr\_t blockno*, *void \*data*, *size\_t size*);

*ssize\_t*\

**bwrite**(*struct uufsd \*disk*, *ufs2\_daddr\_t blockno*, *const void \*data*, *size\_t size*);

*int*\

**berase**(*struct uufsd \*disk*, *ufs2\_daddr\_t blockno*, *ufs2\_daddr\_t size*);

## DESCRIPTION

The **bread**(), **bwrite**() and **berase**() functions provide a block read, write and erase API for [libufs(3)](/libufs/3.md) consumers. They operate on a userland UFS disk structure, and perform the read and write at a given block address, which uses the current *d\_bsize* value of the structure.

## RETURN VALUES

The **bread**() and **bwrite**() functions return the amount read or written, or -1 in case of any error, including short read.

The **berase**() function returns non-zero on error.

## ERRORS

The function **bread**() may fail and set *errno* for any of the errors specified for the library functions [ufs\_disk\_write(3)](/ufs_disk_write/3.md) or [pread(2)](/pread/2.md).

The function **bwrite**() may fail and set *errno* for any of the errors specified for the library function [pwrite(2)](/pwrite/2.md).

The function **berase**() may fail and set *errno* for any of the errors specified for the library function [ioctl(2)](/ioctl/2.md).

Additionally all three functions may follow the [libufs(3)](/libufs/3.md) error methodologies in situations where the amount of data written is not equal to the amount requested, or in case of a device error.

## SEE ALSO

[libufs(3)](/libufs/3.md), [ufs\_disk\_write(3)](/ufs_disk_write/3.md)

## HISTORY

These functions first appeared as part of [libufs(3)](/libufs/3.md) in FreeBSD 5.0.

## AUTHORS

Juli Mallett ⟨*jmallett@FreeBSD.org*⟩
