if (stream.seekg(offset * SectorSize, ios::beg) < 0)
panic("Could not seek to location in file");
- off_t pos = stream.tellg();
+ streampos pos = stream.tellg();
stream.read((char *)data, SectorSize);
DPRINTF(DiskImageRead, "read: offset=%d\n", (uint64_t)offset);
DPRINTF(DiskImageWrite, "write: offset=%d\n", (uint64_t)offset);
DDUMP(DiskImageWrite, data, SectorSize);
- off_t pos = stream.tellp();
+ streampos pos = stream.tellp();
stream.write((const char *)data, SectorSize);
return stream.tellp() - pos;
}
const string &file, bool read_only)
: DiskImage(name), filename(file), child(kid), table(NULL)
{
- if (!open()) {
+ if (!open(filename)) {
assert(!read_only && "why have a non-existent read only file?");
init(hash_size);
}
{ SafeRead(stream, &data, sizeof(data)); }
bool
-CowDiskImage::open()
+CowDiskImage::open(const string &file)
{
- ifstream stream(filename.c_str());
+ ifstream stream(file.c_str());
if (!stream.is_open())
return false;
if (stream.fail() || stream.bad())
- panic("Error opening %s", filename);
+ panic("Error opening %s", file);
uint64_t magic;
SafeRead(stream, magic);
if (memcmp(&magic, "COWDISK!", sizeof(magic)) != 0)
- panic("Could not open %s: Invalid magic", filename);
+ panic("Could not open %s: Invalid magic", file);
uint32_t major, minor;
SafeRead(stream, major);
if (major != VersionMajor && minor != VersionMinor)
panic("Could not open %s: invalid version %d.%d != %d.%d",
- filename, major, minor, VersionMajor, VersionMinor);
+ file, major, minor, VersionMajor, VersionMinor);
uint64_t sector_count;
SafeRead(stream, sector_count);
void
CowDiskImage::save()
+{
+ save(filename);
+}
+
+void
+CowDiskImage::save(const string &file)
{
if (!initialized)
panic("RawDiskImage not initialized");
- ofstream stream(filename.c_str());
+ ofstream stream(file.c_str());
if (!stream.is_open() || stream.fail() || stream.bad())
- panic("Error opening %s", filename);
+ panic("Error opening %s", file);
uint64_t magic;
memcpy(&magic, "COWDISK!", sizeof(magic));
return SectorSize;
}
+void
+CowDiskImage::serialize(ostream &os)
+{
+ string cowFilename = Checkpoint::dir() + name() + ".cow";
+ SERIALIZE_SCALAR(cowFilename);
+ save(cowFilename);
+}
+
+void
+CowDiskImage::unserialize(Checkpoint *cp, const string §ion)
+{
+ string cowFilename;
+ UNSERIALIZE_SCALAR(cowFilename);
+ open(cowFilename);
+}
+
BEGIN_DECLARE_SIM_OBJECT_PARAMS(CowDiskImage)
SimObjectParam<DiskImage *> child;