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


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