forked from acozzette/BUSE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuseRAMDevice.cpp
31 lines (26 loc) · 862 Bytes
/
buseRAMDevice.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* buseRAMDevice.cpp
*
* Created on: Jan 25, 2015
* Author: andras
*/
#include "buseRAMDevice.h"
#include <stdlib.h>
#include <string.h>
#include <errno.h>
namespace buse {
buseRAMDevice::buseRAMDevice(uint64_t size) : buseOperations(size) { data = malloc(size); }
buseRAMDevice::~buseRAMDevice() { DEBUGPRINTLN("Destroying buseRAMDevice."); free(data); }
int buseRAMDevice::read(void* buf, size_t len, off64_t offset) {
buseOperations::read(buf, len, offset);
if(unlikely(len + (uint64_t)offset > this->getSize())) return EFBIG;
memcpy(buf, (char *) data + offset, len);
return 0;
}
int buseRAMDevice::write(const void* buf, size_t len, off64_t offset) {
buseOperations::write(buf, len, offset);
if(unlikely(len + (uint64_t)offset > this->getSize())) return EFBIG;
memcpy((char *) data + offset, buf, len);
return 0;
}
}