2006-04-27 19:11:45 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2009-02-08 12:05:52 +03:00
|
|
|
// $Id: vmware3.h,v 1.14 2009-02-08 09:05:52 vruppert Exp $
|
2006-04-27 19:11:45 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2003-05-03 20:37:18 +04:00
|
|
|
/*
|
|
|
|
* This file provides the interface for using VMWare's virtual
|
|
|
|
* disk image format under Bochs.
|
|
|
|
*
|
|
|
|
* Author: Sharvil Nanavati, for Net Integration Technologies, Inc.
|
|
|
|
* Contact: snrrrub@yahoo.com
|
2008-01-27 01:24:03 +03:00
|
|
|
*
|
2003-05-03 20:37:18 +04:00
|
|
|
* Copyright (C) 2003 Net Integration Technologies, Inc.
|
2008-01-27 01:24:03 +03:00
|
|
|
*
|
2003-05-03 20:37:18 +04:00
|
|
|
* 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.
|
2008-01-27 01:24:03 +03:00
|
|
|
*
|
2003-05-03 20:37:18 +04:00
|
|
|
* 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.
|
2008-01-27 01:24:03 +03:00
|
|
|
*
|
2003-05-03 20:37:18 +04:00
|
|
|
* 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
|
2003-05-03 20:37:18 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _COWDISK_H
|
|
|
|
#define _COWDISK_H 1
|
|
|
|
|
|
|
|
class vmware3_image_t : public device_image_t
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
vmware3_image_t() : FL_SHIFT(25), FL_MASK(0xFE000000)
|
|
|
|
{ };
|
2006-11-19 12:55:23 +03:00
|
|
|
int open(const char* pathname);
|
2003-05-03 20:37:18 +04:00
|
|
|
void close();
|
2006-11-19 12:55:23 +03:00
|
|
|
Bit64s lseek(Bit64s offset, int whence);
|
|
|
|
ssize_t read(void* buf, size_t count);
|
|
|
|
ssize_t write(const void* buf, size_t count);
|
2003-05-03 20:37:18 +04:00
|
|
|
|
|
|
|
private:
|
2003-08-03 21:04:02 +04:00
|
|
|
static const off_t INVALID_OFFSET;
|
2003-05-03 20:37:18 +04:00
|
|
|
|
2003-06-10 19:54:52 +04:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER<1300)
|
|
|
|
#pragma pack(push, 1)
|
2004-02-07 01:28:00 +03:00
|
|
|
#elif defined(__MWERKS__) && defined(macintosh)
|
|
|
|
#pragma options align=packed
|
2003-06-10 19:54:52 +04:00
|
|
|
#endif
|
|
|
|
typedef
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER>=1300)
|
|
|
|
__declspec(align(1))
|
|
|
|
#endif
|
|
|
|
struct _COW_Header {
|
2004-01-18 19:39:02 +03:00
|
|
|
Bit8u id[4];
|
|
|
|
Bit32u header_version;
|
|
|
|
Bit32u flags;
|
|
|
|
Bit32u total_sectors;
|
|
|
|
Bit32u tlb_size_sectors;
|
|
|
|
Bit32u flb_offset_sectors;
|
|
|
|
Bit32u flb_count;
|
|
|
|
Bit32u next_sector_to_allocate;
|
|
|
|
Bit32u cylinders;
|
|
|
|
Bit32u heads;
|
|
|
|
Bit32u sectors;
|
|
|
|
Bit8u PAD0[1016];
|
|
|
|
Bit32u last_modified_time;
|
|
|
|
Bit8u PAD1[572];
|
|
|
|
Bit32u last_modified_time_save;
|
|
|
|
Bit8u label[8];
|
|
|
|
Bit32u chain_id;
|
|
|
|
Bit32u number_of_chains;
|
|
|
|
Bit32u cylinders_in_disk;
|
|
|
|
Bit32u heads_in_disk;
|
|
|
|
Bit32u sectors_in_disk;
|
|
|
|
Bit32u total_sectors_in_disk;
|
|
|
|
Bit8u PAD2[8];
|
|
|
|
Bit32u vmware_version;
|
|
|
|
Bit8u PAD3[364];
|
2006-01-28 11:52:16 +03:00
|
|
|
}
|
2003-06-10 19:54:52 +04:00
|
|
|
#if !defined(_MSC_VER)
|
2004-02-07 01:28:00 +03:00
|
|
|
GCC_ATTRIBUTE((packed))
|
2003-06-10 19:54:52 +04:00
|
|
|
#endif
|
2006-01-28 11:52:16 +03:00
|
|
|
COW_Header
|
2003-06-10 19:54:52 +04:00
|
|
|
;
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER<1300)
|
|
|
|
#pragma pack(pop)
|
2004-02-07 01:28:00 +03:00
|
|
|
#elif defined(__MWERKS__) && defined(macintosh)
|
|
|
|
#pragma options align=reset
|
2003-06-10 19:54:52 +04:00
|
|
|
#endif
|
2003-05-03 20:37:18 +04:00
|
|
|
|
2004-08-11 15:09:01 +04:00
|
|
|
struct COW_Image;
|
|
|
|
friend struct COW_Image;
|
2003-05-03 20:37:18 +04:00
|
|
|
struct COW_Image {
|
|
|
|
int fd;
|
|
|
|
COW_Header header;
|
2004-01-18 19:39:02 +03:00
|
|
|
Bit32u * flb;
|
|
|
|
Bit32u ** slb;
|
|
|
|
Bit8u * tlb;
|
2003-05-03 20:37:18 +04:00
|
|
|
off_t offset;
|
|
|
|
off_t min_offset;
|
|
|
|
off_t max_offset;
|
|
|
|
bool synced;
|
2008-01-27 01:24:03 +03:00
|
|
|
} * images, * current;
|
2003-05-03 20:37:18 +04:00
|
|
|
|
2004-01-18 19:39:02 +03:00
|
|
|
int read_header(int fd, COW_Header & header);
|
|
|
|
int write_header(int fd, COW_Header & header);
|
|
|
|
|
|
|
|
int read_ints(int fd, Bit32u *buffer, size_t count);
|
|
|
|
int write_ints(int fd, Bit32u *buffer, size_t count);
|
|
|
|
|
|
|
|
char * generate_cow_name(const char * filename, Bit32u chain);
|
2003-05-03 20:37:18 +04:00
|
|
|
bool is_valid_header(COW_Header & header);
|
|
|
|
off_t perform_seek();
|
|
|
|
bool sync();
|
|
|
|
|
2004-01-18 19:39:02 +03:00
|
|
|
const Bit32u FL_SHIFT;
|
|
|
|
const Bit32u FL_MASK;
|
2003-05-03 20:37:18 +04:00
|
|
|
|
|
|
|
off_t requested_offset;
|
2004-01-18 19:39:02 +03:00
|
|
|
Bit32u slb_count;
|
|
|
|
Bit32u tlb_size;
|
2003-05-03 20:37:18 +04:00
|
|
|
};
|
|
|
|
#endif
|