- added instructions how to update the online documentation
[bochs-mirror.git] / iodev / vmware3.h
blob2a84e98d57b37763d88db01cd30390451491031e
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: vmware3.h,v 1.12 2008/01/26 22:24:03 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
5 /*
6 * This file provides the interface for using VMWare's virtual
7 * disk image format under Bochs.
9 * Author: Sharvil Nanavati, for Net Integration Technologies, Inc.
10 * Contact: snrrrub@yahoo.com
12 * Copyright (C) 2003 Net Integration Technologies, Inc.
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #ifndef _COWDISK_H
30 #define _COWDISK_H 1
32 class vmware3_image_t : public device_image_t
34 public:
35 vmware3_image_t() : FL_SHIFT(25), FL_MASK(0xFE000000)
36 { };
37 int open(const char* pathname);
38 void close();
39 Bit64s lseek(Bit64s offset, int whence);
40 ssize_t read(void* buf, size_t count);
41 ssize_t write(const void* buf, size_t count);
43 private:
44 static const off_t INVALID_OFFSET;
46 #if defined(_MSC_VER) && (_MSC_VER<1300)
47 #pragma pack(push, 1)
48 #elif defined(__MWERKS__) && defined(macintosh)
49 #pragma options align=packed
50 #endif
51 typedef
52 #if defined(_MSC_VER) && (_MSC_VER>=1300)
53 __declspec(align(1))
54 #endif
55 struct _COW_Header {
56 Bit8u id[4];
57 Bit32u header_version;
58 Bit32u flags;
59 Bit32u total_sectors;
60 Bit32u tlb_size_sectors;
61 Bit32u flb_offset_sectors;
62 Bit32u flb_count;
63 Bit32u next_sector_to_allocate;
64 Bit32u cylinders;
65 Bit32u heads;
66 Bit32u sectors;
67 Bit8u PAD0[1016];
68 Bit32u last_modified_time;
69 Bit8u PAD1[572];
70 Bit32u last_modified_time_save;
71 Bit8u label[8];
72 Bit32u chain_id;
73 Bit32u number_of_chains;
74 Bit32u cylinders_in_disk;
75 Bit32u heads_in_disk;
76 Bit32u sectors_in_disk;
77 Bit32u total_sectors_in_disk;
78 Bit8u PAD2[8];
79 Bit32u vmware_version;
80 Bit8u PAD3[364];
82 #if !defined(_MSC_VER)
83 GCC_ATTRIBUTE((packed))
84 #endif
85 COW_Header
87 #if defined(_MSC_VER) && (_MSC_VER<1300)
88 #pragma pack(pop)
89 #elif defined(__MWERKS__) && defined(macintosh)
90 #pragma options align=reset
91 #endif
93 struct COW_Image;
94 friend struct COW_Image;
95 struct COW_Image {
96 int fd;
97 COW_Header header;
98 Bit32u * flb;
99 Bit32u ** slb;
100 Bit8u * tlb;
101 off_t offset;
102 off_t min_offset;
103 off_t max_offset;
104 bool synced;
105 } * images, * current;
107 int read_header(int fd, COW_Header & header);
108 int write_header(int fd, COW_Header & header);
110 int read_ints(int fd, Bit32u *buffer, size_t count);
111 int write_ints(int fd, Bit32u *buffer, size_t count);
113 char * generate_cow_name(const char * filename, Bit32u chain);
114 bool is_valid_header(COW_Header & header);
115 off_t perform_seek();
116 bool sync();
118 const Bit32u FL_SHIFT;
119 const Bit32u FL_MASK;
121 off_t requested_offset;
122 Bit32u slb_count;
123 Bit32u tlb_size;
125 #endif