parallels.rst 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. Parallels Expandable Image File Format
  2. ======================================
  3. ..
  4. Copyright (c) 2015 Denis Lunev
  5. Copyright (c) 2015 Vladimir Sementsov-Ogievskiy
  6. This work is licensed under the terms of the GNU GPL, version 2 or later.
  7. See the COPYING file in the top-level directory.
  8. A Parallels expandable image file consists of three consecutive parts:
  9. * header
  10. * BAT
  11. * data area
  12. All numbers in a Parallels expandable image are stored in little-endian byte
  13. order.
  14. Definitions
  15. -----------
  16. Sector
  17. A 512-byte data chunk.
  18. Cluster
  19. A data chunk of the size specified in the image header.
  20. Currently, the default size is 1MiB (2048 sectors). In previous
  21. versions, cluster sizes of 63 sectors, 256 and 252 kilobytes were used.
  22. BAT
  23. Block Allocation Table, an entity that contains information for
  24. guest-to-host I/O data address translation.
  25. Header
  26. ------
  27. The header is placed at the start of an image and contains the following
  28. fields::
  29. Bytes:
  30. 0 - 15: magic
  31. Must contain "WithoutFreeSpace" or "WithouFreSpacExt".
  32. 16 - 19: version
  33. Must be 2.
  34. 20 - 23: heads
  35. Disk geometry parameter for guest.
  36. 24 - 27: cylinders
  37. Disk geometry parameter for guest.
  38. 28 - 31: tracks
  39. Cluster size, in sectors.
  40. 32 - 35: nb_bat_entries
  41. Disk size, in clusters (BAT size).
  42. 36 - 43: nb_sectors
  43. Disk size, in sectors.
  44. For "WithoutFreeSpace" images:
  45. Only the lowest 4 bytes are used. The highest 4 bytes must be
  46. cleared in this case.
  47. For "WithouFreSpacExt" images, there are no such
  48. restrictions.
  49. 44 - 47: in_use
  50. Set to 0x746F6E59 when the image is opened by software in R/W
  51. mode; set to 0x312e3276 when the image is closed.
  52. A zero in this field means that the image was opened by an old
  53. version of the software that doesn't support Format Extension
  54. (see below).
  55. Other values are not allowed.
  56. 48 - 51: data_off
  57. An offset, in sectors, from the start of the file to the start of
  58. the data area.
  59. For "WithoutFreeSpace" images:
  60. - If data_off is zero, the offset is calculated as the end of BAT
  61. table plus some padding to ensure sector size alignment.
  62. - If data_off is non-zero, the offset should be aligned to sector
  63. size. However it is recommended to align it to cluster size for
  64. newly created images.
  65. For "WithouFreSpacExt" images:
  66. data_off must be non-zero and aligned to cluster size.
  67. 52 - 55: flags
  68. Miscellaneous flags.
  69. Bit 0: Empty Image bit. If set, the image should be
  70. considered clear.
  71. Bits 1-31: Unused.
  72. 56 - 63: ext_off
  73. Format Extension offset, an offset, in sectors, from the start of
  74. the file to the start of the Format Extension Cluster.
  75. ext_off must meet the same requirements as cluster offsets
  76. defined by BAT entries (see below).
  77. BAT
  78. ---
  79. BAT is placed immediately after the image header. In the file, BAT is a
  80. contiguous array of 32-bit unsigned little-endian integers with
  81. ``(bat_entries * 4)`` bytes size.
  82. Each BAT entry contains an offset from the start of the file to the
  83. corresponding cluster. The offset set in clusters for ``WithouFreSpacExt``
  84. images and in sectors for ``WithoutFreeSpace`` images.
  85. If a BAT entry is zero, the corresponding cluster is not allocated and should
  86. be considered as filled with zeroes.
  87. Cluster offsets specified by BAT entries must meet the following requirements:
  88. - the value must not be lower than data offset (provided by ``header.data_off``
  89. or calculated as specified above)
  90. - the value must be lower than the desired file size
  91. - the value must be unique among all BAT entries
  92. - the result of ``(cluster offset - data offset)`` must be aligned to
  93. cluster size
  94. Data Area
  95. ---------
  96. The data area is an area from the data offset (provided by ``header.data_off``
  97. or calculated as specified above) to the end of the file. It represents a
  98. contiguous array of clusters. Most of them are allocated by the BAT, some may
  99. be allocated by the ``ext_off`` field in the header while other may be
  100. allocated by extensions. All clusters allocated by ``ext_off`` and extensions
  101. should meet the same requirements as clusters specified by BAT entries.
  102. Format Extension
  103. ----------------
  104. The Format Extension is an area 1 cluster in size that provides additional
  105. format features. This cluster is addressed by the ext_off field in the header.
  106. The format of the Format Extension area is the following::
  107. 0 - 7: magic
  108. Must be 0xAB234CEF23DCEA87
  109. 8 - 23: m_CheckSum
  110. The MD5 checksum of the entire Header Extension cluster except
  111. the first 24 bytes.
  112. The above are followed by feature sections or "extensions". The last
  113. extension must be "End of features" (see below).
  114. Each feature section has the following format::
  115. 0 - 7: magic
  116. The identifier of the feature:
  117. 0x0000000000000000 - End of features
  118. 0x20385FAE252CB34A - Dirty bitmap
  119. 8 - 15: flags
  120. External flags for extension:
  121. Bit 0: NECESSARY
  122. If the software cannot load the extension (due to an
  123. unknown magic number or error), the file should not be
  124. changed. If this flag is unset and there is an error on
  125. loading the extension, said extension should be dropped.
  126. Bit 1: TRANSIT
  127. If there is an unknown extension with this flag set,
  128. said extension should be left as is.
  129. If neither NECESSARY nor TRANSIT are set, the extension should be
  130. dropped.
  131. 16 - 19: data_size
  132. The size of the following feature data, in bytes.
  133. 20 - 23: unused32
  134. Align header to 8 bytes boundary.
  135. variable: data (data_size bytes)
  136. The above is followed by padding to the next 8 bytes boundary, then the
  137. next extension starts.
  138. The last extension must be "End of features" with all the fields set to 0.
  139. Dirty bitmaps feature
  140. ---------------------
  141. This feature provides a way of storing dirty bitmaps in the image. The fields
  142. of its data area are::
  143. 0 - 7: size
  144. The bitmap size, should be equal to disk size in sectors.
  145. 8 - 23: id
  146. An identifier for backup consistency checking.
  147. 24 - 27: granularity
  148. Bitmap granularity, in sectors. I.e., the number of sectors
  149. corresponding to one bit of the bitmap. Granularity must be
  150. a power of 2.
  151. 28 - 31: l1_size
  152. The number of entries in the L1 table of the bitmap.
  153. variable: L1 offset table (l1_table), size: 8 * l1_size bytes
  154. The dirty bitmap described by this feature extension is stored in a set of
  155. clusters inside the Parallels image file. The offsets of these clusters are
  156. saved in the L1 offset table specified by the feature extension. Each L1 table
  157. entry is a 64 bit integer as described below:
  158. Given an offset in bytes into the bitmap data, corresponding L1 entry is::
  159. l1_table[offset / cluster_size]
  160. If an L1 table entry is 0, all bits in the corresponding cluster of the bitmap
  161. are assumed to be 0.
  162. If an L1 table entry is 1, all bits in the corresponding cluster of the bitmap
  163. are assumed to be 1.
  164. If an L1 table entry is not 0 or 1, it contains the corresponding cluster
  165. offset (in 512b sectors). Given an offset in bytes into the bitmap data the
  166. offset in bytes into the image file can be obtained as follows::
  167. offset = l1_table[offset / cluster_size] * 512 + (offset % cluster_size)