Fix open flags.
Devel commit.

Lot of changes:

    * added new api
    * error handling