This directory contains an implementation of a block-device-partition server.

Behavior
--------

The server uses Genode's block-session interfaces as both front and back end,
leading to the most common use case where this server will reside "between" a
block-driver server and a higher level component like a file-system server.

At startup, the partition server will try to parse the master boot record (MBR)
of its back-end block session. If no partition table is found, the whole block
device is exported as partition '0'. In the other case, the MBR and possible
extended boot records (EBRs) are parsed and offered as separate block sessions
to the front-end clients. The four primary partitions will receive partition
numbers '1' to '4' whereas the first logical partition will be assigned to '5'.

The partition server also understands the GUID partition table (GPT). It will
always try to read the MBR as well as the GPT and will bail out if both are
considered valid. It is up to the user to choose the right table. To do so,
the 'ignore_mbr' or 'ignore_gpt' config attribute may be specified. Using both
at the same time is a configuration error. Apart from that, the server will
show a warning in case a protective MBR is found but GPT is ignored and abort.
If valid GPT was encountered without a proper protective MBR it will use the
GPT but show a diagnostic warning.


In order to route a client to the right partition, the server parses its
configuration section looking for 'policy' tags.

XML Syntax:
! <policy label="<program name>" partition="<partition number>"  writeable="<boolean>"/>

part_block supports partition reporting, which can be enabled via the
<report> configuration node. See below for an example. The report
looks like follows (for MBR resp. GPT).

! <partitions type="mbr">
!   <partition number="1" type="12" start="2048" length="2048"/>
!   <partition number="2" type="15" start="4096" length="16384"/>
!   <partition number="5" type="12" start="6144" length="4096"/>
!   <partition number="6" type="12" start="12288" length="8192"/>
! </partitions>
! <partitions type="gpt">
!   <partition number="1" name="one" type="ebd0a0a2-b9e5-4433-87c0-68b6b72699c7"
!     guid="5f4061cc-8d4a-4e6f-ad15-10b881b79aee" start="2048" length="2048"/>
!   <partition number="2" name="two" type="ebd0a0a2-b9e5-4433-87c0-68b6b72699c7"
!     guid="87199a83-d0f4-4a01-b9e3-6516a8579d61" start="4096" length="16351"/>
! </partitions>

Clients have read-only access to partitions unless overriden by a 'writeable'
policy attribute.

Usage
-----

Configuration snippet with two clients and an (hypothetical) IDE driver:
!<start name="ata_driver">
!  <resource name="RAM" quantum="1M" />
!  <provides><service name="Block"/></provides>
!  <config ata="yes" />
!</start>
!
!<start name="part_block">
!  <resource name="RAM" quantum="10M" />
!  <provides><service name="Block" /></provides>
!
!  <!-- route part_block to the ata_driver -->
!  <route>
!    <any-service><child name="ata_driver"/> <parent/><any-child/></any-service>
!  </route>
!
!  <!-- allow program 'test-part1' to access logical partition '6', while program
!      'test-part2' receives access to primary partition 1 -->
!  <config>
!    <report partitions="yes"/>
!    <policy label_prefix="test-part1" partition="6" writeable="yes"/>
!    <policy label_prefix="test-part2" partition="1" writeable="yes"/>
!  </config>
!</start>
!
!<!-- part_block clients -->
!<start name="test-part1">
!  <binary name="test-part"/>
!  <resource name="RAM" quantum="10M" />
!  <route>
!    <any-service> <child name="part_block" /> <parent/> <any-child/> </any-service>
!  </route>
!</start>
!
!<start name="test-part2">
!  <binary name="test-part"/>
!  <resource name="RAM" quantum="10M" />
!  <route>
!    <any-service> <child name="part_block" /> <parent/> <any-child/> </any-service>
!  </route>
!</start>
