2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Nathan Binkert
32 * Disk Image Interfaces
35 #ifndef __DISK_IMAGE_HH__
36 #define __DISK_IMAGE_HH__
40 #include "base/hashmap.hh"
41 #include "sim/sim_object.hh"
42 #include "params/DiskImage.hh"
43 #include "params/CowDiskImage.hh"
44 #include "params/RawDiskImage.hh"
46 #define SectorSize (512)
49 * Basic interface for accessing a disk image.
51 class DiskImage : public SimObject
57 typedef DiskImageParams Params;
58 DiskImage(const Params *p) : SimObject(p), initialized(false) {}
59 virtual ~DiskImage() {}
61 virtual off_t size() const = 0;
63 virtual off_t read(uint8_t *data, off_t offset) const = 0;
64 virtual off_t write(const uint8_t *data, off_t offset) = 0;
68 * Specialization for accessing a raw disk image
70 class RawDiskImage : public DiskImage
73 mutable std::fstream stream;
76 mutable off_t disk_size;
79 typedef RawDiskImageParams Params;
80 RawDiskImage(const Params *p);
84 void open(const std::string &filename, bool rd_only = false);
86 virtual off_t size() const;
88 virtual off_t read(uint8_t *data, off_t offset) const;
89 virtual off_t write(const uint8_t *data, off_t offset);
93 * Specialization for accessing a copy-on-write disk image layer.
94 * A copy-on-write(COW) layer must be stacked on top of another disk
95 * image layer this layer can be another CowDiskImage, or a
98 * This object is designed to provide a mechanism for persistant
99 * changes to a main disk image, or to provide a place for temporary
100 * changes to the image to take place that later may be thrown away.
102 class CowDiskImage : public DiskImage
105 static const uint32_t VersionMajor;
106 static const uint32_t VersionMinor;
110 uint8_t data[SectorSize];
112 typedef m5::hash_map<uint64_t, Sector *> SectorTable;
115 std::string filename;
120 typedef CowDiskImageParams Params;
121 CowDiskImage(const Params *p);
124 void init(int hash_size);
125 bool open(const std::string &file);
127 void save(const std::string &file);
129 void serialize(std::ostream &os);
130 void unserialize(Checkpoint *cp, const std::string §ion);
132 virtual off_t size() const;
134 virtual off_t read(uint8_t *data, off_t offset) const;
135 virtual off_t write(const uint8_t *data, off_t offset);
138 #endif // __DISK_IMAGE_HH__