-/*
- * return data to the caller. Results unpredictable.
- */
-int
-random_read(__unused dev_t dev, struct uio *uio, __unused int ioflag)
-{
- int retCode = 0;
-
- if (gRandomError != 0)
- return (ENOTSUP);
-
- /* lock down the mutex */
- lck_mtx_lock(gYarrowMutex);
-
- int bytes_remaining = uio_resid(uio);
- while (bytes_remaining > 0 && retCode == 0) {
- /* get the user's data */
- int bytes_to_read = 0;
-
- int bytes_available = kBlockSize - g_bytes_used;
- if (bytes_available == 0)
- {
- random_block(g_random_data, TRUE);
- g_bytes_used = 0;
- bytes_available = kBlockSize;
- }
-
- bytes_to_read = min (bytes_remaining, bytes_available);
-
- retCode = uiomove(((caddr_t)g_random_data)+ g_bytes_used, bytes_to_read, uio);
- g_bytes_used += bytes_to_read;
-
- if (retCode != 0)
- goto error_exit;
-
- bytes_remaining = uio_resid(uio);
- }
-
- retCode = 0;
-
-error_exit:
- lck_mtx_unlock(gYarrowMutex);
- return retCode;
-}