genode/repos/os/src/server/part_blk
Norman Feske eba9c15746 Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:

* A class with virtual functions can no longer publicly inherit base
  classed without a vtable. The inherited object may either be moved
  to a member variable, or inherited privately. The latter would be
  used for classes that inherit 'List::Element' or 'Avl_node'. In order
  to enable the 'List' and 'Avl_tree' to access the meta data, the
  'List' must become a friend.

* Instead of adding a virtual destructor to abstract base classes,
  we inherit the new 'Interface' class, which contains a virtual
  destructor. This way, single-line abstract base classes can stay
  as compact as they are now. The 'Interface' utility resides in
  base/include/util/interface.h.

* With the new warnings enabled, all member variables must be explicitly
  initialized. Basic types may be initialized with '='. All other types
  are initialized with braces '{ ... }' or as class initializers. If
  basic types and non-basic types appear in a row, it is nice to only
  use the brace syntax (also for basic types) and align the braces.

* If a class contains pointers as members, it must now also provide a
  copy constructor and assignment operator. In the most cases, one
  would make them private, effectively disallowing the objects to be
  copied. Unfortunately, this warning cannot be fixed be inheriting
  our existing 'Noncopyable' class (the compiler fails to detect that
  the inheriting class cannot be copied and still gives the error).
  For now, we have to manually add declarations for both the copy
  constructor and assignment operator as private class members. Those
  declarations should be prepended with a comment like this:

        /*
         * Noncopyable
         */
        Thread(Thread const &);
        Thread &operator = (Thread const &);

  In the future, we should revisit these places and try to replace
  the pointers with references. In the presence of at least one
  reference member, the compiler would no longer implicitly generate
  a copy constructor. So we could remove the manual declaration.

Issue #465
2018-01-17 12:14:35 +01:00
..
component.h Follow practices suggested by "Effective C++" 2018-01-17 12:14:35 +01:00
driver.h Follow practices suggested by "Effective C++" 2018-01-17 12:14:35 +01:00
gpt.h part_blk: added optional partitions report 2017-05-31 13:16:16 +02:00
main.cc part_blk: prevent deprecated warning 2017-05-31 13:16:18 +02:00
mbr.h part_blk: added optional partitions report 2017-05-31 13:16:16 +02:00
partition_table.h Follow practices suggested by "Effective C++" 2018-01-17 12:14:35 +01:00
README default ahci_drv and part_blk Block sessions to read-only 2017-08-28 16:49:51 +02:00
target.mk os: removal of deprecated os/config.h (fix #2431) 2017-05-31 13:16:22 +02:00

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). If the
config attribute 'use_gpt' is set to 'yes' it will first try to parse any
existing GPT. In case there is no GPT it will fall back to parsing the MBR.

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_blk 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_blk">
!  <resource name="RAM" quantum="10M" />
!  <provides><service name="Block" /></provides>
!
!  <!-- route part_blk 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_blk clients -->
!<start name="test-part1">
!  <binary name="test-part"/>
!  <resource name="RAM" quantum="10M" />
!  <route>
!    <any-service> <child name="part_blk" /> <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_blk" /> <parent/> <any-child/> </any-service>
!  </route>
!</start>