libbrufs/src/iohelp.cpp
/**
 * Reads a number of bytes from a certain offset from disk.
 * Guarantees that exactly `count` bytes are read.
 *
 * @param dsk the disk to read from
 * @param buf the buffer to store the bytes in
 * @param count the number of bytes to read
 * @param offset the offset to read from
 * @return either `count`, BRUFS_E_DISK_TRUNCATED if not enough bytes could be read or any error
 *   returned by the disk I/O abstraction layer
 */
Reads a number of bytes from a certain offset from disk.
Guarantees that exactly `count` bytes are read.


Reads a number of bytes from a certain offset from disk . Guarantees that exactly ` count ` bytes are read .
Brufs::SSize Brufs::dread(Disk *dsk, void *buf, Size count, Address offset) {
    char *cbuf = static_cast<char *>(buf);
    Size total = 0;
    while (total < count) {
        SSize num_read = dsk->io->read(cbuf + total, count - total, offset + total);
        if (num_read == 0) break;
        if (num_read < 0) return num_read;
        total += num_read;
    }
    if (total < count) {
        return Status::E_DISK_TRUNCATED;
    }
    return static_cast<SSize>(total);
}
Brufs :: SSize Brufs :: dread ( Disk * dsk , void * buf , Size count , Address offset ) { char * cbuf = static_cast < char * > ( buf ) ; Size total = 0 ; while ( total < count ) { SSize num_read = dsk -> io -> read ( cbuf + total , count - total , offset + total ) ; if ( num_read == 0 ) break ; if ( num_read < 0 ) return num_read ; total += num_read ; } if ( total < count ) { return Status :: E_DISK_TRUNCATED ; } return static_cast < SSize > ( total ) ; }
Reads a number of bytes from a certain offset from disk.
Reads a number of bytes from a certain offset from disk .