2006-12-17 11:17:28 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2006-12-17 11:17:28 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file provides support for VMWare's virtual disk image
|
|
|
|
* format version 4 and above.
|
|
|
|
*
|
|
|
|
* Author: Sharvil Nanavati
|
|
|
|
* Contact: snrrrub@gmail.com
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Sharvil Nanavati.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-02-08 12:05:52 +03:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-12-17 11:17:28 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _VMWARE4_H
|
|
|
|
#define _VMWARE4_H 1
|
|
|
|
|
|
|
|
class vmware4_image_t : public device_image_t
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
vmware4_image_t();
|
|
|
|
virtual ~vmware4_image_t();
|
|
|
|
|
|
|
|
int open(const char* pathname);
|
|
|
|
void close();
|
|
|
|
Bit64s lseek(Bit64s offset, int whence);
|
|
|
|
ssize_t read(void* buf, size_t count);
|
|
|
|
ssize_t write(const void* buf, size_t count);
|
2010-12-22 00:47:41 +03:00
|
|
|
Bit32u get_capabilities();
|
2012-09-20 01:05:18 +04:00
|
|
|
bx_bool save_state(const char *backup_fname);
|
2012-09-25 20:24:19 +04:00
|
|
|
void restore_state(const char *backup_fname);
|
2006-12-17 11:17:28 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
static const off_t INVALID_OFFSET;
|
|
|
|
static const int SECTOR_SIZE;
|
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
#elif defined(__MWERKS__) && defined(macintosh)
|
|
|
|
#pragma options align=packed
|
|
|
|
#endif
|
|
|
|
typedef struct _VM4_Header
|
|
|
|
{
|
|
|
|
Bit8u id[4];
|
|
|
|
Bit32u version;
|
|
|
|
Bit32u flags;
|
|
|
|
Bit64u total_sectors;
|
|
|
|
Bit64u tlb_size_sectors;
|
|
|
|
Bit64u description_offset_sectors;
|
|
|
|
Bit64u description_size_sectors;
|
|
|
|
Bit32u slb_count;
|
|
|
|
Bit64u flb_offset_sectors;
|
|
|
|
Bit64u flb_copy_offset_sectors;
|
|
|
|
Bit64u tlb_offset_sectors;
|
|
|
|
}
|
|
|
|
#if !defined(_MSC_VER)
|
|
|
|
GCC_ATTRIBUTE((packed))
|
|
|
|
#endif
|
|
|
|
VM4_Header;
|
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma pack(pop)
|
|
|
|
#elif defined(__MWERKS__) && defined(macintosh)
|
|
|
|
#pragma options align=reset
|
|
|
|
#endif
|
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
bx_bool is_open() const;
|
|
|
|
bx_bool is_valid_header() const;
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
bx_bool read_header();
|
2006-12-17 11:17:28 +03:00
|
|
|
off_t perform_seek();
|
|
|
|
void flush();
|
|
|
|
Bit32u read_block_index(Bit64u sector, Bit32u index);
|
|
|
|
void write_block_index(Bit64u sector, Bit32u index, Bit32u block_sector);
|
|
|
|
|
|
|
|
int file_descriptor;
|
|
|
|
VM4_Header header;
|
|
|
|
Bit8u* tlb;
|
|
|
|
off_t tlb_offset;
|
|
|
|
off_t current_offset;
|
2012-09-20 01:05:18 +04:00
|
|
|
bx_bool is_dirty;
|
2012-09-25 20:24:19 +04:00
|
|
|
const char *pathname;
|
2006-12-17 11:17:28 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|