From 3a7335232ab6f54912f76dac3c3fca12e6e73e8a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 14 Dec 2020 14:08:20 +0000 Subject: [PATCH] Implement buffered OS read command for FreeBSD. --- freebsd/device.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/freebsd/device.c b/freebsd/device.c index f01375b..bbdbee1 100644 --- a/freebsd/device.c +++ b/freebsd/device.c @@ -115,3 +115,23 @@ int32_t ReOpen(void* device_ctx, uint32_t* closeFailed) return ctx->device == 0 ? errno : 0; } + +int32_t OsRead(void* device_ctx, char* buffer, uint64_t offset, uint32_t length, uint32_t* duration) +{ + DeviceContext* ctx = device_ctx; + ssize_t ret; + *duration = 0; + off_t pos; + + if(!ctx) return -1; + + // TODO: Timing + pos = lseek(ctx->device.fd, (off_t)offset, SEEK_SET); + + if(pos < 0) return errno; + + // TODO: Timing + ret = read(ctx->device.fd, (void*)buffer, (size_t)length); + + return ret < 0 ? errno : 0; +} \ No newline at end of file