CDBLOCKEDREAD(3) BSD Programmer's Manual CDBLOCKEDREAD(3)
cdblockedread - seek and read with 2048-byte alignment
#include <mbfun.h>
ssize_t
cdblockedread(int fd, void *dst, size_t len, off_t ofs);
The cdblockedread() function equals the following calls:
lseek(fd, ofs, SEEK_SET);
read(fd, dst, len);
It however differs from that sequence in that it does proper error check-
ing and I/O aligned to 2048 bytes, that is ofs is truncated down to a
multiple of 2048, the difference is added to len which then is rounded up
to a multiple of 2048, a temporary buffer is allocated to which the bytes
are read, the correct bytes are then copied to dst and another lseek(2)
to the original ofs + len is done to set the file seek pointer to the
same value the above sequence of calls would have.
This function is of limited use cases; one would be to read a random
512-byte sector from a CD-ROM using the raw mode (character) device;
disklabel(8) does that.
If no error occured and the call to read(2) returned exactly len bytes in
one operation, cdblockedread() returns len. Otherwise, if the last call
to lseek(2) failed but everything else succeeded, 0 is returned, -1 oth-
erwise. This is because the seek pointer after reading is irrelevant to
most applications using it.
lseek(2), read(2), cd(4)
The cdblockedread function is an MirOS BSD extension and first appeared
in MirOS #11.
Thorsten Glaser <tg@mirbsd.org>
MirOS BSD #10-current August 14, 2010 1
Generated on 2012-02-20 02:47:02 by $MirOS: src/scripts/roff2htm,v 1.70 2011/12/03 18:21:12 tg Exp $
These manual pages and other documentation are copyrighted by their respective writers;
their source is available at our CVSweb,
AnonCVS, and other mirrors. The rest is Copyright © 2002‒2011 The MirOS Project, Germany.
This product includes material
provided by Thorsten Glaser.
This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report – diffs preferred.