Go to the documentation of this file.
35 #include <sys/types.h>
47 #include "debug/DiskImageRead.hh"
48 #include "debug/DiskImageWrite.hh"
60 {
open(
p->image_file,
p->read_only); }
69 panic(
"Attempting to fork system with read-write raw disk image.");
73 open(
p->image_file,
p->read_only);
79 if (!filename.empty()) {
84 ios::openmode
mode = ios::in | ios::binary;
89 panic(
"Error opening %s", filename);
104 panic(
"file not open!\n");
105 stream.seekg(0, ios::end);
116 panic(
"RawDiskImage not initialized");
119 panic(
"file not open!\n");
123 panic(
"Could not seek to location in file");
125 streampos pos =
stream.tellg();
128 DPRINTF(DiskImageRead,
"read: offset=%d\n", (uint64_t)
offset);
131 return stream.tellg() - pos;
138 panic(
"RawDiskImage not initialized");
141 panic(
"Cannot write to a read only disk image");
144 panic(
"file not open!\n");
148 panic(
"Could not seek to location in file");
150 DPRINTF(DiskImageWrite,
"write: offset=%d\n", (uint64_t)
offset);
153 streampos pos =
stream.tellp();
155 return stream.tellp() - pos;
159 RawDiskImageParams::create()
179 fatal(
"could not open read-only file");
190 SectorTable::iterator
i =
table->begin();
191 SectorTable::iterator end =
table->end();
202 if (!
dynamic_cast<const Params *
>(
params())->read_only &&
204 inform(
"Disabling saving of COW image in forked child process.\n");
213 if (!stream.is_open())
214 panic(
"file not open");
217 panic(
"premature end-of-file");
219 if (stream.bad() || stream.fail())
220 panic(
"error reading cowdisk image");
241 ifstream stream(file.c_str());
242 if (!stream.is_open())
245 if (stream.fail() || stream.bad())
246 panic(
"Error opening %s", file);
251 if (memcmp(&magic,
"COWDISK!",
sizeof(magic)) != 0)
252 panic(
"Could not open %s: Invalid magic", file);
254 uint32_t major, minor;
259 panic(
"Could not open %s: invalid version %d.%d != %d.%d",
262 uint64_t sector_count;
267 for (uint64_t
i = 0;
i < sector_count;
i++) {
275 (*table)[
offset] = sector;
296 if (!stream.is_open())
297 panic(
"file not open");
300 panic(
"premature end-of-file");
302 if (stream.bad() || stream.fail())
303 panic(
"error reading cowdisk image");
334 panic(
"RawDiskImage not initialized");
336 ofstream stream(file.c_str());
337 if (!stream.is_open() || stream.fail() || stream.bad())
338 panic(
"Error opening %s", file);
341 memcpy(&magic,
"COWDISK!",
sizeof(magic));
349 SectorTable::iterator iter =
table->begin();
350 SectorTable::iterator end =
table->end();
352 for (uint64_t
i = 0;
i <
size;
i++) {
354 panic(
"Incorrect Table Size during save of COW disk image");
357 SafeWrite(stream, (*iter).second->data,
sizeof(Sector));
367 SectorTable::iterator
i =
table->begin();
368 SectorTable::iterator end =
table->end();
384 panic(
"CowDiskImage not initialized");
387 panic(
"access out of bounds");
394 DPRINTF(DiskImageRead,
"read: offset=%d\n", (uint64_t)
offset);
404 panic(
"RawDiskImage not initialized");
407 panic(
"access out of bounds");
418 DPRINTF(DiskImageWrite,
"write: offset=%d\n", (uint64_t)
offset);
427 string cowFilename =
name() +
".cow";
437 cowFilename =
cp.getCptDir() +
"/" + cowFilename;
442 CowDiskImageParams::create()
Specialization for accessing a raw disk image.
#define fatal(...)
This implements a cprintf based fatal() function.
virtual std::streampos write(const uint8_t *data, std::streampos offset)=0
std::streampos write(const uint8_t *data, std::streampos offset) override
void SafeReadSwap(ifstream &stream, T &data)
#define UNSERIALIZE_SCALAR(scalar)
void notifyFork() override
Notify a child process of a fork.
std::streampos size() const override
void SafeWriteSwap(ofstream &stream, const T &data)
virtual std::streampos size() const =0
CowDiskImage(const Params *p)
void SafeRead(ifstream &stream, void *data, int count)
void registerExitCallback(const std::function< void()> &callback)
Register an exit callback.
Basic interface for accessing a disk image.
std::streampos size() const override
RawDiskImage(const Params *p)
std::streampos read(uint8_t *data, std::streampos offset) const override
Specialization for accessing a copy-on-write disk image layer.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void SafeWrite(ofstream &stream, const void *data, int count)
void notifyFork() override
Notify a child process of a fork.
bool open(const std::string &file)
std::streampos write(const uint8_t *data, std::streampos offset) override
const Params * params() const
#define SERIALIZE_SCALAR(scalar)
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
virtual const std::string name() const
static std::string dir()
Get the current checkout directory name.
static const uint32_t VersionMajor
Overload hash function for BasicBlockRange type.
static const uint32_t VersionMinor
virtual std::streampos read(uint8_t *data, std::streampos offset) const =0
std::ostream CheckpointOut
void open(const std::string &filename, bool rd_only=false)
const uint8_t image_file[]
This image file contains the text "This is a test image.\n" 31 times.
std::unordered_map< uint64_t, Sector * > SectorTable
void serialize(CheckpointOut &cp) const override
Serialize an object.
std::streampos read(uint8_t *data, std::streampos offset) const override
#define panic(...)
This implements a cprintf based panic() function.
void initSectorTable(int hash_size)
Generated on Wed Sep 30 2020 14:02:11 for gem5 by doxygen 1.8.17