20 #define LIBSMBIOS_SOURCE
35 using namespace factory;
55 data->
fd = fopen( data->
filename.c_str(),
"rb" );
58 AccessErrorImpl accessError;
59 accessError.setMessageString(
_(
"Unable to open memory. File: %(file)s, OS Error: %(err)s") );
60 accessError.setParameter(
"file", data->
filename );
61 accessError.setParameter(
"err", strerror(errno) );
82 MemoryFactoryImpl::MemoryFactoryImpl()
84 setParameter(
"memFile",
"/dev/mem");
87 MemoryOsSpecific::MemoryOsSpecific(
const string filename )
97 osData =
static_cast<void *
>(data);
122 unsigned int bytesCopied = 0;
126 while( bytesCopied < length )
136 if ((data->
lastMapping) == reinterpret_cast<void *>(-1))
137 throw AccessErrorImpl(
_(
"mmap failed."));
140 unsigned long toCopy = length - bytesCopied;
144 memcpy(buffer + bytesCopied, (reinterpret_cast<const u8 *>(data->
lastMapping) + mmoff), toCopy);
146 bytesCopied += toCopy;
165 int ret = fseek( data->
fd, offset, 0 );
168 OutOfBoundsImpl outOfBounds;
169 outOfBounds.setMessageString(
_(
"Seek error trying to seek to memory location. OS Error: %(err)s"));
170 outOfBounds.setParameter(
"err", strerror(errno) );
174 ret = fwrite( &value, 1, 1, data->
fd );
177 AccessErrorImpl accessError;
178 accessError.setMessageString(
_(
"Error trying to write memory. OS Error: %(err)s"));
179 accessError.setParameter(
"err", strerror(errno) );