CDBLOCKEDREAD(3) BSD Programmer's Manual CDBLOCKEDREAD(3)NAME
cdblockedread - seek and read with 2048-byte alignment
SYNOPSIS
#include <mbfun.h>
ssize_t
cdblockedread(int fd, void *dst, size_t len, off_t ofs);
DESCRIPTION
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.
RETURN VALUES
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.
SEE ALSOlseek(2), read(2), cd(4)HISTORY
The cdblockedread function is an MirOS BSD extension and first appeared
in MirOS #11.
AUTHORS
Thorsten Glaser <tg@mirbsd.org>
MirOS BSD #10-current August 14, 2010 1