BREAD(3)
π
BREAD(3) β the bread, bwrite, berase era πβ¨
okay so bestie, this one's from the Library Functions Manual, and honestly? it's giving "tiny API, huge responsibility." let's get into it π«Ά
πΈ NAME
bread, bwrite β read and write blocks of a UFS file system πΎ (and yes there's a berase in here too, she's in the synopsis, don't worry, we'll get to her π)
π LIBRARY
UFS File System Access Library (libufs, -lufs) β literally the whole vibe check for talking to UFS from userland π
β¨ SYNOPSIS
like, first you gotta summon the headers, no cap:
#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>
then the actual main characters π₯:
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);
look at them. so compact. so iconic. π
π¦ DESCRIPTION
so bread(), bwrite() and berase() are the block read / write / erase API for libufs(3) girlies π. they do exactly what they say on the tin β they operate on a userland UFS disk structure, and they do the read and the write at a given block address, which honestly is just using the current d_bsize value of that structure π
. that's the whole plot, no plot twists, fr fr.
π RETURN VALUES
bread()andbwrite()β return the amount read or written. and if literally anything goes wrong?-1. and yes, a short read counts as an error, so don't come crying to me when you get-1back πberase()β returns non-zero on error. (so zero = we slayed, non-zero = we did not π« )
π ERRORS
okay so this is the "when things go sideways" section, pay attention bestie:
bread()may fail and seterrnofor any of the errors specified for the library functionsufs_disk_write(3)orpread(2).bwrite()may fail and seterrnofor any of the errors specified for the library functionpwrite(2).berase()may fail and seterrnofor any of the errors specified for the library functionioctl(2).
π¨ and additionally, all three of these functions may follow the libufs(3) error methodologies in situations where the amount of data written is not equal to the amount requested, or in case of a device error. that's the scary part, ngl. keep an eye on your return values, they're telling you something π
π SEE ALSO
go read those too, iykyk π
π§ HISTORY
these functions first appeared as part of libufs(3) in FreeBSD 5.0 β β so yeah, they've been serving for a minute π
π AUTHORS
Juli Mallett <jmallett@FreeBSD.org> β we stan π«Ά
and that's the page!! π
this beauty is from the Debian edition, dated June 4, 2003, and it's filed under BREAD(3). periodt. πΈβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms