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);
72 panic(
"Attempting to fork system with read-write raw disk image.");
76 open(
p.image_file,
p.read_only);
82 if (!filename.empty()) {
87 std::ios::openmode
mode = std::ios::in | std::ios::binary;
89 mode |= std::ios::out;
92 panic(
"Error opening %s", filename);
107 panic(
"file not open!\n");
108 stream.seekg(0, std::ios::end);
119 panic(
"RawDiskImage not initialized");
122 panic(
"file not open!\n");
126 panic(
"Could not seek to location in file");
128 std::streampos pos =
stream.tellg();
131 DPRINTF(DiskImageRead,
"read: offset=%d\n", (uint64_t)
offset);
134 return stream.tellg() - pos;
141 panic(
"RawDiskImage not initialized");
144 panic(
"Cannot write to a read only disk image");
147 panic(
"file not open!\n");
151 panic(
"Could not seek to location in file");
153 DPRINTF(DiskImageWrite,
"write: offset=%d\n", (uint64_t)
offset);
156 std::streampos pos =
stream.tellp();
158 return stream.tellp() - pos;
176 fatal(
"could not open read-only file");
187 SectorTable::iterator
i =
table->begin();
188 SectorTable::iterator end =
table->end();
199 if (!
dynamic_cast<const Params &
>(
params()).read_only &&
201 inform(
"Disabling saving of COW image in forked child process.\n");
210 if (!stream.is_open())
211 panic(
"file not open");
214 panic(
"premature end-of-file");
216 if (stream.bad() || stream.fail())
217 panic(
"error reading cowdisk image");
238 std::ifstream stream(file.c_str());
239 if (!stream.is_open())
242 if (stream.fail() || stream.bad())
243 panic(
"Error opening %s", file);
248 if (memcmp(&magic,
"COWDISK!",
sizeof(magic)) != 0)
249 panic(
"Could not open %s: Invalid magic", file);
251 uint32_t major, minor;
256 panic(
"Could not open %s: invalid version %d.%d != %d.%d",
259 uint64_t sector_count;
264 for (uint64_t
i = 0;
i < sector_count;
i++) {
272 (*table)[
offset] = sector;
293 if (!stream.is_open())
294 panic(
"file not open");
297 panic(
"premature end-of-file");
299 if (stream.bad() || stream.fail())
300 panic(
"error reading cowdisk image");
331 panic(
"RawDiskImage not initialized");
333 std::ofstream stream(file.c_str());
334 if (!stream.is_open() || stream.fail() || stream.bad())
335 panic(
"Error opening %s", file);
338 memcpy(&magic,
"COWDISK!",
sizeof(magic));
346 SectorTable::iterator iter =
table->begin();
347 SectorTable::iterator end =
table->end();
349 for (uint64_t
i = 0;
i <
size;
i++) {
351 panic(
"Incorrect Table Size during save of COW disk image");
364 SectorTable::iterator
i =
table->begin();
365 SectorTable::iterator end =
table->end();
381 panic(
"CowDiskImage not initialized");
384 panic(
"access out of bounds");
391 DPRINTF(DiskImageRead,
"read: offset=%d\n", (uint64_t)
offset);
401 panic(
"RawDiskImage not initialized");
404 panic(
"access out of bounds");
415 DPRINTF(DiskImageWrite,
"write: offset=%d\n", (uint64_t)
offset);
424 std::string cowFilename =
name() +
".cow";
432 std::string cowFilename;
434 cowFilename =
cp.getCptDir() +
"/" + cowFilename;
#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
#define UNSERIALIZE_SCALAR(scalar)
void SafeRead(std::ifstream &stream, void *data, int count)
void notifyFork() override
Notify a child process of a fork.
std::streampos size() const override
virtual std::streampos size() const =0
void registerExitCallback(const std::function< void()> &callback)
Register an exit callback.
Basic interface for accessing a disk image.
std::streampos size() const override
std::streampos read(uint8_t *data, std::streampos offset) const override
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void SafeWriteSwap(std::ofstream &stream, const T &data)
void SafeReadSwap(std::ifstream &stream, T &data)
RawDiskImage(const Params &p)
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
#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 const uint32_t VersionMajor
static const uint32_t VersionMinor
void SafeWrite(std::ofstream &stream, const void *data, int count)
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)
static std::string dir()
Get the current checkout directory name.
const Params & params() const
CowDiskImage(const Params &p)
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 Tue Mar 23 2021 19:41:26 for gem5 by doxygen 1.8.17