text:
#pragma once

#pragma warning( push )
/* 'X' bytes padding added after member 'Y' */
#pragma warning( disable: 4820 )

#pragma pack( push, 8 )

#if !defined(_PCVOID_DEFINED)
typedef const void* PCVOID;
#define _PCVOID_DEFINED
#endif

#if defined(__cplusplus)
extern "C" {
#endif

#define DRYADAPI_EXT
#define DRYADAPI __stdcall

typedef struct tagDRHANDLE
{
    ULONG_PTR       Unused;
} *DRHANDLE, **PDRHANDLE;

/*++

DR_ASYNC_INFO structure

Each function that may be executed asynchronously takes pointer
to DR_ASYNC_INFO structure as last parameter.

If NULL is passed then function completes in synchronous manner
and error code is returned as return value.

If parameter is not NULL then operation is carried on in asynchronous manner.
If asynchronous operation has been successfully started then function terminates
immediately with HRESULT_FROM_WIN32(ERROR_IO_PENDING) return value.
Any other return value indicates that it was impossible to start asynchronous operation.

Fields:

    cbSize          Size of structure in bytes. Set to sizeof(DR_ASYNC_INFO).

    pOperationState Pointer to error code returned by completed operation.
                    While operation is in progress value is set to HRESULT_FROM_WIN32(ERROR_IO_PENDING).
                    Before completion is reported value is set to an error code of completed operation.
                    Cannot be NULL.

    Event           Handle to event. Event is set once operation is completed. May be NULL.

    IOCP            Handle to IO completion port. If not NULL then upon completion status is posted
                    to specified completion port.

    pOverlapped     Pointer to OVERLAPPED structure. Used in conjunction with IOCP parameter
                    to post status to IOCP.
                    Should be null if IOCP is NULL, cannot be NULL if IOCP is not NULL.

    CompletionKey   Used in conjunction with IOCP parameter to post status to IOCP.
                    Should be 0 if IOCP is NULL.

    unusedX         Fields reserved for future use.

Note that DR_ASYNC_INFO structure is not required to be available for the duration of asynchronous call
(for example, this allows to allocate DR_ASYNC_INFO structure on stack).
In contrast variable specified by pOperationState pointer is required to be available
for the duration of the asynchronous call.

--*/
typedef struct tagDR_ASYNC_INFO {
    SIZE_T          cbSize;

    DrError*        pOperationState;

    HANDLE          Event;

    HANDLE          IOCP;
    LPOVERLAPPED    pOverlapped;
    UINT_PTR        CompletionKey;

    UINT64          unused0;
    UINT64          unused1;
} DR_ASYNC_INFO, *PDR_ASYNC_INFO;
typedef const DR_ASYNC_INFO* PCDR_ASYNC_INFO;

//JC
#if 0
typedef struct tagDRSESSIONHANDLE
{
    ULONG_PTR       Unused;
} *DRSESSIONHANDLE, **PDRSESSIONHANDLE;

/*++

DR_ASYNC_INFO structure

Each function that may be executed asynchronously takes pointer
to DR_ASYNC_INFO structure as last parameter.

If NULL is passed then function completes in synchronous manner
and error code is returned as return value.

If parameter is not NULL then operation is carried on in asynchronous manner.
If asynchronous operation has been successfully started then function terminates
immediately with HRESULT_FROM_WIN32(ERROR_IO_PENDING) return value.
Any other return value indicates that it was impossible to start asynchronous operation.

Fields:

    cbSize          Size of structure in bytes. Set to sizeof(DR_ASYNC_INFO).

    pOperationState Pointer to error code returned by completed operation.
                    While operation is in progress value is set to HRESULT_FROM_WIN32(ERROR_IO_PENDING).
                    Before completion is reported value is set to an error code of completed operation.
                    Cannot be NULL.

    Event           Handle to event. Event is set once operation is completed. May be NULL.

    IOCP            Handle to IO completion port. If not NULL then upon completion status is posted
                    to specified completion port.

    pOverlapped     Pointer to OVERLAPPED structure. Used in conjunction with IOCP parameter
                    to post status to IOCP.
                    Should be null if IOCP is NULL, cannot be NULL if IOCP is not NULL.

    CompletionKey   Used in conjunction with IOCP parameter to post status to IOCP.
                    Should be 0 if IOCP is NULL.

    unusedX         Fields reserved for future use.

Note that DR_ASYNC_INFO structure is not required to be available for the duration of asynchronous call
(for example, this allows to allocate DR_ASYNC_INFO structure on stack).
In contrast variable specified by pOperationState pointer is required to be available
for the duration of the asynchronous call.

--*/
typedef struct tagDR_ASYNC_INFO {
    SIZE_T          cbSize;

    DrError*        pOperationState;

    HANDLE          Event;

    HANDLE          IOCP;
    LPOVERLAPPED    pOverlapped;
    UINT_PTR        CompletionKey;

    UINT64          unused0;
    UINT64          unused1;
} DR_ASYNC_INFO, *PDR_ASYNC_INFO;
typedef const DR_ASYNC_INFO* PCDR_ASYNC_INFO;

/*++

DR_INIT_PARAMS structure

Contains optional parameters for cosmos initialization.
Default value of all fields is zero.

Fields:

    cbSize                      Size of structure in bytes. Set to sizeof(DR_INIT_PARAMS).

    SuppressConsoleLogOutput    Set to TRUE to suppress autopilot init output to console.

--*/
typedef struct tagDR_INIT_PARAMS {
    SIZE_T          cbSize;

    BOOL            SuppressConsoleLogOutput;
    BOOL            fLogDisableMillisecondTimestamps;

    UINT64          Reserved0;
    UINT64          Reserved1;
    UINT64          Reserved2;
    UINT64          Reserved3;
    UINT64          Reserved4;
    UINT64          Reserved5;
    UINT64          Reserved6;
    UINT64          Reserved7;
} DR_INIT_PARAMS, *PDR_INIT_PARAMS;
typedef const DR_INIT_PARAMS* PCDR_INIT_PARAMS;

/*++

DR_STREAM_PROPERTIES structure

Used in DrOpenStream and DrSetStreamProperties.

Fields:

    cbSize          Size of structure in bytes. Set to sizeof(DR_STREAM_PROPERTIES).

    ExpirePeriod    Expiration period in 100-ns intervals. On server side at the time
                    of request execution stream expiration time is set to curent time
                    plus ExpirePeriod.

    ReadOffsetHint  Optimization hint. Currently not used.

    Flags           Specifies new values of modified stream flags.
                    Set to 0 for DrOpenStream.

    FlagsMask       Specifies stream flags to be modified.
                    Set to 0 for DrOpenStream.

--*/
typedef struct tagDR_STREAM_PROPERTIES {
    SIZE_T          cbSize;
    INT64           ExpirePeriod;
    UINT64          ReadOffsetHint;
    UINT            Flags;
    UINT            FlagsMask;
    UINT64          unused0;            // four attributes reserved for future extension
    UINT64          unused1;
    UINT64          unused2;
    UINT64          unused3;
} DR_STREAM_PROPERTIES, *PDR_STREAM_PROPERTIES;
typedef const DR_STREAM_PROPERTIES* PCDR_STREAM_PROPERTIES;

/*++

    Old name for DR_STREAM_PROPERTIES structure

--*/
typedef DR_STREAM_PROPERTIES DR_STREAM_PARAMS;
typedef PDR_STREAM_PROPERTIES PDR_STREAM_PARAMS;
typedef PCDR_STREAM_PROPERTIES PCDR_STREAM_PARAMS;

typedef struct tagDR_EXTENT_INSTANCE {
    SIZE_T          cbSize;

    UINT            Flags;
    PCSTR           ExtentNodeName;
    UINT64          unused0;            // two attributes reserved for future extension
    UINT64          unused1;
} DR_EXTENT_INSTANCE, *PDR_EXTENT_INSTANCE;

typedef struct tagDR_EXTENT {
    SIZE_T              cbSize;

    UINT                Flags;

    UINT64              ModificationTime;

    UINT64              Length;

    UINT64              Crc64;

    GUID                Id;

    UINT                NumberOfInstances;
    PDR_EXTENT_INSTANCE Instances;
    UINT64              unused0;        // three attributes reserved for future extension
    UINT64              unused1;
    UINT64              unused2;
    UINT64              unused3;
} DR_EXTENT, *PDR_EXTENT;

/*++
Fields:

    Flags       DR_OBJECT_STREAM or DR_OBJECT_DIRECTORY
--*/
typedef struct tagDR_STREAM {
    SIZE_T          cbSize;

    PCSTR           pName;

    UINT            Flags;

    UINT64          CreationTime;
    UINT64          ExpirationTime;
    UINT64          ModificationTime;

    UINT64          Length;
    UINT            TotalNumberOfExtents;

    GUID            Id;

    UINT            StartExtentIndex;
    UINT64          StartExtentOffset;
    UINT            ExtentsCount;
    PDR_EXTENT      pExtents;
    PCSTR           pPath;
    UINT64          unused0;              // four attributes reserved for future extension
    UINT64          unused1;
    UINT64          unused2;
    UINT64          unused3;
} DR_STREAM, *PDR_STREAM;

typedef struct tagDR_DIRECTORY {
    SIZE_T          cbSize;

    PDR_STREAM      pStreams;
    SIZE_T          StreamsCount;
    UINT64          unused0;              // four attributes reserved for future extension
    UINT64          unused1;
    UINT64          unused2;
    UINT64          unused3;
} DR_DIRECTORY, *PDR_DIRECTORY;

typedef struct tagDR_EXTENT_NODE {
    SIZE_T          cbSize;

    UINT            ExtentNodeVersion;
    PCSTR           pExtentNodeVersionText;

    PCSTR           ExtentNodeName;
    UINT            Flags;
    UINT64          StartupTime;
    UINT64          LastSyncTime;
    PCSTR           ReasonText;

    UINT            NumberOfSealedExtents;
    UINT64          SealedExtentsLength;
    UINT64          SealedExtentsSizeOnDisk;

    UINT            NumberOfUnsealedExtents;
    UINT64          UnsealedExtentsLength;
    UINT64          UnsealedExtentsSizeOnDisk;

    UINT            NumberOfUnvacatedExtents;
    UINT64          UnvacatedExtentsLength;

    UINT64          FreeSpaceSize;

    UINT16          ScaleUnit;
    UINT64          unused0;              // four attributes reserved for future extension
    UINT64          unused1;
    UINT64          unused2;
    UINT64          unused3;
} DR_EXTENT_NODE, *PDR_EXTENT_NODE;

typedef struct tagDR_HOST {
    PCSTR           HostName;
    UINT16          Port;
    PCSTR           PodName;
    UINT16          ScaleUnit;
} DR_HOST, *PDR_HOST;

typedef struct tagDR_VOLUME {
    SIZE_T          cbSize;

    UINT            DrmVersion;
    PCSTR           pDrmVersionText;

    UINT64          CurrentTime;
    UINT64          StartupTime;

    UINT64          NumberOfStreams;
    UINT64          StreamsLength;
    UINT64          NumberOfCreatedStreams;

    UINT64          NumberOfSealedExtents;
    UINT64          SealedExtentsLength;

    UINT64          NumberOfUnsealedExtents;
    UINT64          UnsealedExtentsLength;

    PCSTR           pPrimaryDRM;
    UINT            NumberOfDrmHosts;
    PDR_HOST        pDrmHostList;
    UINT64          DrmRslSequence;
    GUID            VolumeId;

    UINT64          NumberOfCreatedExtents;
    UINT            NumberOfExtentNodes;
    PDR_EXTENT_NODE pExtentNodes;
    UINT64          unused0;              // four attributes reserved for future extension
    UINT64          unused1;
    UINT64          unused2;
    UINT64          unused3;
} DR_VOLUME, *PDR_VOLUME;

typedef struct tagDR_STREAM_POSITION {
    UINT    ExtentIndex;
    UINT64  Offset;
} DR_STREAM_POSITION, *PDR_STREAM_POSITION;
typedef const DR_STREAM_POSITION* PCDR_STREAM_POSITION;

/*++

DR_MULTIMODIFY_EXTENT_RANGE structure

Used in DrMultiModifyStream to describe a contiguous range of extents to
be concatenated onto a target stream.

Fields:

    cbSize           Size of structure in bytes. Set to sizeof(DR_MULTIMODIFY_EXTENT_RANGE).

    MultiModifyStreamEntryIndex
                        The 0-based index of the DR_MULTIMODIFY_STREAM_ENTRY, provided in the call to DrMultiModifyStream, which describes
                        the source stream from which to copy extents.

    ExtentIndex
                        The index in the source stream of the first extent to be copied. 0 means beginning of stream.

    ExtentCount
                        The number of contiguous extents in the range.
                        If 0, no extents will be copied, but the operation will succeed.
                        If DR_ALL_EXTENTS, all remaining extents in the source stream will be concatenated (may be 0).
--*/

typedef struct tagDR_MULTIMODIFY_EXTENT_RANGE {
    SIZE_T      cbSize;
    UINT        MultiModifyStreamEntryIndex;
    UINT        ExtentIndex;
    UINT        ExtentCount;
} DR_MULTIMODIFY_EXTENT_RANGE, *PDR_MULTIMODIFY_EXTENT_RANGE;
typedef const DR_MULTIMODIFY_EXTENT_RANGE *PCDR_MULTIMODIFY_EXTENT_RANGE;

/*++

DR_MULTIMODIFY_STREAM_ENTRY structure

Used in DrMultiModifyStream to describe one of a set of
atomically applied stream modifications.

Combines the capabilities of DrDeleteStream, DrRenameStream, DrConcatenateStream, and
DrSetStreamProperties, with atomic compare/exchange semantics.

Note that it is explicitly possible to construct an entry that verifies the existence or size of a particular
stream without actually making any changes to the stream. This is particularly
useful when concatenating append ranges, since each source stream must be described
by a DR_MULTIMODIFY_STREAM_ENTRY even if it is not to be touched.

If this structure is set to all zeroes, and only pOldStream is initialized, the effect will be to
verify existence of stream pOldStream, but make no changes to it.

Fields:

    cbSize              Size of structure in bytes. Set to sizeof(DR_MULTIMODIFY_ENTRY).

    ModifyFlags         Options for the entry. Includes:
                        DR_MULTIMODIFY_ENTRY_SET_EXPIRE_PERIOD - the expire time is to be updated from pStreamProperties
                        DR_MULTIMODIFY_ENTRY_DELETE_STREAM -- the stream is to be deleted or recycled according to deleteFlags
                        DR_MULTIMODIFY_ENTRY_ENFORCE_EXTENT_COUNT -- fail the request with DrError_StreamChanged if requiredExtentCount does not match
                        DR_MULTIMODIFY_ENTRY_CREATE_STREAM  -- Create the new stream names in pNewStreamName

    pOldStreamName
                        Fully qualified stream existing to be verified or modified.

    pNewStreamName
                        If renaming or creating a new stream, the new fully qualified stream name. NULL otherwise. Must
                        be on the same volume.

    DeleteFlags
                        If deleting (DR_MULTIMODIFY_ENTRY_DELETE_STREAM), options for the delete (See DrDeleteStream). Must be
                        0 if not deleting.

    pStreamProperties
                        If setting stream properties (including updating expire time), the new
                        stream properties. NULL otherwise. See DrSetStreamProperties.

    RequiredStreamId
                        if not NULL_GUID, causes the entire request to fail with DrError_StreamChanged
                        if the stream does not have the specified stream ID.

    RequiredExtentCount
                        if DR_MULTIMODIFY_ENTRY_ENFORCE_EXTENT_COUNT is 1, causes the request to fail with DrError_StreamChanged if
                        the stream does not contain the specified number of extents (prior to conconcatenation).

    ConcatenateExtentRangeCount
                        The number of entries in pConcatenateExtentRanges. 0 If no concatenation is to be performed.

    pConcatenateExtentRanges
                        An array of extent range descriptors of length ConcatenateExtentRangeCount. Each entry describes a contiguous block
                        of extents to be appended onto the end of this stream, in order. NULL if no concatenation is to be performed.
                        See DrConcatenateStream.
--*/
typedef struct tagDR_MULTIMODIFY_STREAM_ENTRY {
    SIZE_T                      cbSize;
    UINT                        ModifyFlags;

    PCSTR                       pOldStreamName;
    PCSTR                       pNewStreamName;
    UINT                        DeleteFlags;

    PCDR_STREAM_PROPERTIES      pStreamProperties;
    GUID                        RequiredStreamId;
    UINT                        RequiredExtentCount;
    UINT                        ConcatenateExtentRangeCount;
    PCDR_MULTIMODIFY_EXTENT_RANGE pConcatenateExtentRanges;

    UINT64                      unused0;        // four attributes reserved for future extension
    UINT64                      unused1;
    UINT64                      unused2;
    UINT64                      unused3;
} DR_MULTIMODIFY_STREAM_ENTRY, *PDR_MULTIMODIFY_STREAM_ENTRY;
typedef const DR_MULTIMODIFY_STREAM_ENTRY *PCDR_MULTIMODIFY_STREAM_ENTRY;

//
// MultiModifyStream Entry flags
//

//
// DR_MULTIMODIFY_ENTRY_SET_EXPIRE_PERIOD  If 1, stream's expiration period will be reset from pStreamProperties
// Append, concatenate, delete, rename and shrink expiration time operations
// fail for such streams.
//
#define DR_MULTIMODIFY_ENTRY_SET_EXPIRE_PERIOD      0x00000001u

//
// DR_MULTIMODIFY_ENTRY_DELETE_STREAM  If 1, stream will be deleted according to deleteFlags
//
#define DR_MULTIMODIFY_ENTRY_DELETE_STREAM          0x00000002u

//
// DR_MULTIMODIFY_ENTRY_ENFORCE_EXTENT_COUNT  If 1, request will fail with DrError_StreamChanged if requiredExtentCount does not match current stream size
//
#define DR_MULTIMODIFY_ENTRY_ENFORCE_EXTENT_COUNT   0x00000004u

//
// DR_MULTIMODIFY_ENTRY_CREATE_STREAM  If 1, creates stream pNewStreamName. pOldStreamName should be NULL.
//
#define DR_MULTIMODIFY_ENTRY_CREATE_STREAM          0x00000008u

typedef struct tagDR_RANGE
{
    PCSTR   pStreamName;
    UINT    ExtentIndex;
    UINT    ExtentCount;
} DR_RANGE;
typedef DR_RANGE* PDR_RANGE;
typedef const DR_RANGE* PCDR_RANGE;

#define DR_CURRENT_VERSION      0x00000009u

//
// Stream open modes
//
#define DR_APPEND               0x00000001u
#define DR_READ                 0x00000002u

//
// Creation disposition
//
#define DR_OPEN                 0x00000010u
#define DR_CREATE               0x00000020u
#define DR_CREATE_OR_OPEN       (DR_OPEN | DR_CREATE)

//
// Metadata refresh policy flags for DrOpenStream and DrReadStream
// Refresh policy is set during DrOpenStream, and then may be overridden by DrReadStream
// If DrReadStream does not override, options from DrOpenStream affect DrReadStream as well
//
#define DR_REFRESH_AGGRESSIVE   0x10000000u
#define DR_REFRESH_PASSIVE      0x20000000u
#define DR_REFRESH_FROM_CACHE   0x30000000u
#define DR_REFRESH_NO_INSTANCES 0x40000000u   // permit to refresh instances (length can be refreshed always)

#define DR_REFRESH_MASK                (DR_REFRESH_AGGRESSIVE | DR_REFRESH_PASSIVE | DR_REFRESH_NO_INSTANCES) // all refresh bits
#define DR_REFRESH_MASK_MUST_HAVE      (DR_REFRESH_AGGRESSIVE | DR_REFRESH_PASSIVE) // at least one of these bits must be on
#define DR_REFRESH_DEFAULT             (DR_REFRESH_AGGRESSIVE) // default for DrOpenStream
#define DR_REFRESH_DEFAULT_STREAMINFO  (DR_REFRESH_AGGRESSIVE | DR_REFRESH_NO_INSTANCES) // default for DrOpenStreamFromStreamInfo

//
// Cache policy settings for DrOpenStream (possible future TODO: allow to be passed directly to DrReadStream)
//
#define DR_CACHE_SEQUENTIAL     0x01000000u
#define DR_CACHE_READ_AHEAD     0x02000000u   // same as DR_CACHE_SEQUENTIAL, but with optimistic read ahead in background
#define DR_CACHE_RANDOM_ACCESS  0x03000000u
#define DR_CACHE_NO_CACHE       0x04000000u   // ineffective if read boundaries do not exactly match append boundaries

#define DR_CACHE_DEFAULT        DR_CACHE_SEQUENTIAL
#define DR_CACHE_MASK           0x07000000u

//
// Object selection options
//
#define DR_OBJECT_STREAM        0x00000100u
#define DR_OBJECT_DIRECTORY     0x00000200u
#define DR_OBJECT_ANY           (DR_OBJECT_STREAM | DR_OBJECT_DIRECTORY)
#define DR_OBJECT_LOCAL         0x00000400u
#define DR_OBJECT_RECYCLED      0x00000800u

//
// Stream flags
//

//
// DR_STREAM_READ_ONLY  Stream is read-only.
// Append, concatenate, delete, rename and shrink expiration time operations
// fail for such streams.
//
#define DR_STREAM_READ_ONLY     0x00000008u

//
// DR_STREAM_SEALED  Stream is sealed.
// Append and concatenate operations
// fail for such streams. This bit cannot be cleared once set. Does not effect
// append operations to unsealed extents within the stream.
//
#define DR_STREAM_SEALED         0x00000010u

//
// Extent flags
//
#define DR_EXTENT_SEALED        0x00001000u
#define DR_EXTENT_NEEDS_SEAL    0x00002000u

//
// Extent node flags
//
#define DR_EXTENT_NODE_AVAILABLE    0x00000001u

//
// Stream append options
//
#define DR_FIXED_OFFSET_APPEND  0x01000000u
#define DR_PARTIAL_APPEND       0x02000000u
#define DR_SEAL                 0x04000000u
#define DR_UPDATE_DRM           0x08000000u

//
// Stream delete options
//
#define DR_DELETE_FORCE         0x00000001u

//
// Stream concatenation options
//
#define DR_CONCATENATE_ALLOW_CREATE_NEW     0x00100000u
#define DR_CONCATENATE_REQUIRE_CREATE_NEW   0x00200000u

#define DR_CONCATENATE_MASK                 (DR_CONCATENATE_ALLOW_CREATE_NEW | DR_CONCATENATE_REQUIRE_CREATE_NEW)

//
// Retrieve or append all extents
//
#define DR_ALL_EXTENTS          0xFFFFFFFFu

#define DR_INVALID_EXTENT_INDEX 0xFFFFFFFFu
#define DR_UNKNOWN_EXTENT_INDEX 0xFFFFFFFFu

#define DR_UNKNOWN_OFFSET       0xFFFFFFFFFFFFFFFFui64
#define DR_UNKNOWN_LENGTH       0xFFFFFFFFFFFFFFFFui64

#define DR_NEVER                0xFFFFFFFFFFFFFFFFui64
#define DR_INFINITE             0x7FFFFFFFFFFFFFFFi64

//
// Stream renaming flags
//
#define DR_RENAME_ALLOW_SUBSTITUTION    0x00000001u
#define DR_RENAME_REQUIRE_SUBSTITUTION  0x00000002u

#define DR_RENAME_MASK                  (DR_RENAME_ALLOW_SUBSTITUTION | DR_RENAME_REQUIRE_SUBSTITUTION)

//
// Get position flags
//
#define DR_ABSOLUTE_POSITION 0x00000001u

//
// Stream option constants
//

//
// DR_STREAM_OPTION_MAX_EXTENT_SIZE             UINT64
// Maximum extent size client passes to DRM and EN,
// if DRM returned smaller maximum size, the smaller
// size is used to pass to EN.
// Pass zero to use built-in default (DR_STREAM_OPTION_MAX_EXTENT_SIZE_FALLBACK).
// Set to value from the configuration file if there is any.
//
#define DR_STREAM_OPTION_MAX_EXTENT_SIZE                    1u
#define DR_STREAM_OPTION_MAX_EXTENT_SIZE_DEFAULT            0ui64
#define DR_STREAM_OPTION_MAX_EXTENT_SIZE_FALLBACK           0x6400000ui64 // 100 Mb
#define DR_STREAM_OPTION_MAX_EXTENT_SIZE_CONFIG             "ExtentSize"

//
// DR_STREAM_OPTION_MAX_PHYSICAL_EXTENT_SIZE    UINT64
// Maximum physical (compressed) extent size client passes to EN.
// Pass zero to use built-in default (DR_STREAM_OPTION_MAX_PHYSICAL_EXTENT_SIZE_FALLBACK).
// Set to value from the configuration file if there is any.
//
#define DR_STREAM_OPTION_MAX_PHYSICAL_EXTENT_SIZE           2u
#define DR_STREAM_OPTION_MAX_PHYSICAL_EXTENT_SIZE_DEFAULT   0ui64
#define DR_STREAM_OPTION_MAX_PHYSICAL_EXTENT_SIZE_FALLBACK  0xFFFFFFFFFFFFFFFFui64 // unlimited
#define DR_STREAM_OPTION_MAX_PHYSICAL_EXTENT_SIZE_CONFIG    "PhysicalExtentSize"

//
// DR_STREAM_OPTION_COMPRESSION_LEVEL           UINT
// Specifies compression level for data being appended.
// Value from 0 (fastest, no compression) to 5 (slowest, best compression ration).
// Set to value from the configuration file if there is any.
//
#define DR_STREAM_OPTION_COMPRESSION_LEVEL                  3u
#define DR_STREAM_OPTION_COMPRESSION_LEVEL_DEFAULT          2u
#define DR_STREAM_OPTION_COMPRESSION_LEVEL_MIN              0u
#define DR_STREAM_OPTION_COMPRESSION_LEVEL_MAX              5u
#define DR_STREAM_OPTION_COMPRESSION_LEVEL_CONFIG           "CompressionLevel"

//
// DR_STREAM_OPTION_MAX_APPEND_RETRY            UINT
// Specifies number of retries for unsuccessful stream append.
// Set to value from the configuration file if there is any.
//
#define DR_STREAM_OPTION_MAX_APPEND_RETRY                   4u
#define DR_STREAM_OPTION_MAX_APPEND_RETRY_DEFAULT           16u
#define DR_STREAM_OPTION_MAX_APPEND_RETRY_MIN               1u
#define DR_STREAM_OPTION_MAX_APPEND_RETRY_MAX               1023u
#define DR_STREAM_OPTION_MAX_APPEND_RETRY_CONFIG            "AppendRetry"

//
// DR_STREAM_OPTION_MAX_READ_RETRY              UINT
// Specifies number of retries for unsuccessful stream read.
// Set to value from the configuration file if there is any.
//
#define DR_STREAM_OPTION_MAX_READ_RETRY                     5u
#define DR_STREAM_OPTION_MAX_READ_RETRY_DEFAULT             16u
#define DR_STREAM_OPTION_MAX_READ_RETRY_MIN                 1u
#define DR_STREAM_OPTION_MAX_READ_RETRY_MAX                 1023u
#define DR_STREAM_OPTION_MAX_READ_RETRY_CONFIG              "ReadRetry"

//
// DR_STREAM_OPTION_FLAGS                       UINT
// Contains flags value for given handle.
// Read-only.
//
#define DR_STREAM_OPTION_FLAGS                              6u

//
// DR_STREAM_OPTION_MAX_APPEND_SIZE             UINT64
// Maxim block size for single append.
// Set to value from the configuration file if there is any.
//
#define DR_STREAM_OPTION_MAX_APPEND_SIZE                    7u
#define DR_STREAM_OPTION_MAX_APPEND_SIZE_DEFAULT            0x400000ui64 // 4 Mb
#define DR_STREAM_OPTION_MAX_APPEND_SIZE_MIN                1ui64
#define DR_STREAM_OPTION_MAX_APPEND_SIZE_MAX                0x2000000ui64 // 32 Mb
#define DR_STREAM_OPTION_MAX_APPEND_SIZE_CONFIG             "MaxAppendSize"

//
// DR_STREAM_OPTION_VERIFY_COMPRESSION          BOOL
// Set to TRUE to enable additional pass to verify compressed data
// for corruption on append.
// Should be either TRUE or FALSE.
// Set to value from the configuration file if there is any.
//
#define DR_STREAM_OPTION_VERIFY_COMPRESSION                 8u
#define DR_STREAM_OPTION_VERIFY_COMPRESSION_DEFAULT         FALSE
#define DR_STREAM_OPTION_VERIFY_COMPRESSION_CONFIG          "VerifyCompression"

//
// DR_STREAM_OPTION_GUID                        GUID
// Returns stream GUID for given handle.
// Read-only.
//
#define DR_STREAM_OPTION_GUID                               9u

//
// DR_STREAM_OPTION_SHORT_NAME                  String
// Returns stream name without path for given handle.
// Read-only.
//
#define DR_STREAM_OPTION_SHORT_NAME                         10u

//
// DR_STREAM_OPTION_PATH                        String
// Returns stream path for given handle.
// Read-only.
//
#define DR_STREAM_OPTION_PATH                               11u

//
// DR_STREAM_OPTION_VOLUME                      String
// Returns stream volume name for given handle.
// Read-only.
//
#define DR_STREAM_OPTION_VOLUME                             12u

//
// DR_STREAM_OPTION_CLUSTER                     String
// Returns stream cluster name for given handle.
// Read-only.
//
#define DR_STREAM_OPTION_CLUSTER                            13u

//
// DR_STREAM_OPTION_NAME                        String
// Returns complete stream name in URI form for given handle.
// Read-only.
//
#define DR_STREAM_OPTION_NAME                               14u

//
// DR_STREAM_OPTION_GUID_PATH                   String
// Returns .streamid stream path for given handle.
// Read-only.
//
#define DR_STREAM_OPTION_GUID_PATH                          15u

//
// DR_STREAM_OPTION_GUID_URI                    String
// Returns .streamid stream name in URI form for given handle.
// Read-only.
//
#define DR_STREAM_OPTION_GUID_URI                           16u

//
// DR_STREAM_OPTION_NAME_GUID_PATH              String
// Returns combined .streamid stream path and namespace location for given handle.
// Read-only.
//
#define DR_STREAM_OPTION_NAME_GUID_PATH                     17u

//
// DR_STREAM_OPTION_NAME_GUID_URI               String
// Returns combined .streamid stream name and namespace location in URI form for given handle.
// Read-only.
//
#define DR_STREAM_OPTION_NAME_GUID_URI                      18u

//
// DR_STREAM_OPTION_MAX_CONCURRENT_READS        UINT
// Maximum number of concurrent read request for single DrReadStream call.
// If first read attempt does not complete in DR_STREAM_OPTION_CONCURRENT_READ_TIMEOUT_1_MS
// time, second read request for the same data in sent to the different storage node.
// DR_STREAM_OPTION_CONCURRENT_READ_TIMEOUT_2_MS timeout is used for the second
// and subsequent read attempts. If this option is set to 1 no concurrent read requests are
// performed. While this option limits number of concurrent retries,
// DR_STREAM_OPTION_MAX_READ_RETRY option limits total number of retries for single API call.
// Aggressive sittings for the maximum concurrent reads number and timeouts may result in
// increased network load and cause load convoy effects during peak loads.
// Set to value from the configuration file if there is any.
//
#define DR_STREAM_OPTION_MAX_CONCURRENT_READS               19u
#define DR_STREAM_OPTION_MAX_CONCURRENT_READS_DEFAULT       2u
#define DR_STREAM_OPTION_MAX_CONCURRENT_READS_MIN           1u
#define DR_STREAM_OPTION_MAX_CONCURRENT_READS_MAX           3u
#define DR_STREAM_OPTION_MAX_CONCURRENT_READS_CONFIG        "MaxConcurrentReads"

//
// DR_STREAM_OPTION_CONCURRENT_READ_TIMEOUT_1_MS        UINT
// Wait time in milliseconds for making second concurrent read request
// if first read request is not complete. Maximum number of concurrent read
// requests is limited by DR_STREAM_OPTION_MAX_CONCURRENT_READS option.
// Set to value from the configuration file if there is any.
//
#define DR_STREAM_OPTION_CONCURRENT_READ_TIMEOUT_1_MS               20u
#define DR_STREAM_OPTION_CONCURRENT_READ_TIMEOUT_1_MS_DEFAULT       10000u
#define DR_STREAM_OPTION_CONCURRENT_READ_TIMEOUT_1_MS_MIN           0u
#define DR_STREAM_OPTION_CONCURRENT_READ_TIMEOUT_1_MS_MAX           60000u
#define DR_STREAM_OPTION_CONCURRENT_READ_TIMEOUT_1_MS_CONFIG        "ConcurrentReadTimeout1Ms"

//
// DR_STREAM_OPTION_CONCURRENT_READ_TIMEOUT_2_MS        UINT
// Wait time in milliseconds after starting second read request for making third concurrent
// read request if either first or second read request is not complete. Maximum number of
// concurrent read requests is limited by DR_STREAM_OPTION_MAX_CONCURRENT_READS option.
// Set to value from the configuration file if there is any.
//
#define DR_STREAM_OPTION_CONCURRENT_READ_TIMEOUT_2_MS               21u
#define DR_STREAM_OPTION_CONCURRENT_READ_TIMEOUT_2_MS_DEFAULT       10000u
#define DR_STREAM_OPTION_CONCURRENT_READ_TIMEOUT_2_MS_MIN           0u
#define DR_STREAM_OPTION_CONCURRENT_READ_TIMEOUT_2_MS_MAX           60000u
#define DR_STREAM_OPTION_CONCURRENT_READ_TIMEOUT_2_MS_CONFIG        "ConcurrentReadTimeout2Ms"

//
// DR_STREAM_OPTION_MAX_OUTSTANDING_APPENDS              UINT
// Maximum number of append requests sent to network at same time per stream.
// Set to value from the configuration file if there is any.
//
#define DR_STREAM_OPTION_MAX_OUTSTANDING_APPENDS                    22u
#define DR_STREAM_OPTION_MAX_OUTSTANDING_APPENDS_DEFAULT            32u
#define DR_STREAM_OPTION_MAX_OUTSTANDING_APPENDS_MIN                1u
#define DR_STREAM_OPTION_MAX_OUTSTANDING_APPENDS_MAX                128u
#define DR_STREAM_OPTION_MAX_OUTSTANDING_APPENDS_CONFIG             "MaxOutstandingAppends"

//
// DR_STREAM_OPTION_MAX_OUTSTANDING_APPEND_SIZE          UINT64
// Maximum size of data contained in append requests sent to network at same time per stream.
// Set to value from the configuration file if there is any.
//
#define DR_STREAM_OPTION_MAX_OUTSTANDING_APPEND_SIZE                23u
#define DR_STREAM_OPTION_MAX_OUTSTANDING_APPEND_SIZE_DEFAULT        0x2000000ui64 // 32 Mb
#define DR_STREAM_OPTION_MAX_OUTSTANDING_APPEND_SIZE_MIN            0x200000ui64  // 2 Mb
#define DR_STREAM_OPTION_MAX_OUTSTANDING_APPEND_SIZE_MAX            0x4000000ui64 // 64 Mb
#define DR_STREAM_OPTION_MAX_OUTSTANDING_APPEND_SIZE_CONFIG         "MaxOutstandingAppendSize"

//
// DR_STREAM_OPTION_READ_AHEAD_BLOCK_SIZE                UINT64
// Read block size to be used if handle is opened with DR_CACHE_READ_AHEAD flag.
// Set to value from the configuration file if there is any.
//
#define DR_STREAM_OPTION_READ_AHEAD_BLOCK_SIZE                      24u
#define DR_STREAM_OPTION_READ_AHEAD_BLOCK_SIZE_DEFAULT              0x200000ui64  // 2 Mb
#define DR_STREAM_OPTION_READ_AHEAD_BLOCK_SIZE_MIN                  0x4000ui64    // 16 Kb
#define DR_STREAM_OPTION_READ_AHEAD_BLOCK_SIZE_MAX                  0x2000000ui64 // 32 Mb
#define DR_STREAM_OPTION_READ_AHEAD_BLOCK_SIZE_CONFIG               "ReadAheadBlockSize"

//
// DR_STREAM_OPTION_READ_AHEAD_OUTSTANDING_COUNT         UINT
// Maximum of simultaneous optimistic read requests to issue for handles opened with DR_CACHE_READ_AHEAD flag.
// Set to value from the configuration file if there is any.
//
#define DR_STREAM_OPTION_READ_AHEAD_OUTSTANDING_COUNT               25u
#define DR_STREAM_OPTION_READ_AHEAD_OUTSTANDING_COUNT_DEFAULT       8u
#define DR_STREAM_OPTION_READ_AHEAD_OUTSTANDING_COUNT_MIN           0u
#define DR_STREAM_OPTION_READ_AHEAD_OUTSTANDING_COUNT_MAX           32u
#define DR_STREAM_OPTION_READ_AHEAD_OUTSTANDING_COUNT_CONFIG        "ReadAheadOutstandingCount"

//
// DR_STREAM_OPTION_CACHE_DEFAULT_MODE                    UINT
// Default cache operation mode for reads.
// Set to value from the configuration file if there is any.
// NOTE: this is global-only setting and it can't be changed for individual handles.
//
#define DR_STREAM_OPTION_CACHE_DEFAULT_MODE                         26u
#define DR_STREAM_OPTION_CACHE_DEFAULT_MODE_DEFAULT                 DR_CACHE_DEFAULT
#define DR_STREAM_OPTION_CACHE_DEFAULT_MODE_MIN                     DR_CACHE_SEQUENTIAL
#define DR_STREAM_OPTION_CACHE_DEFAULT_MODE_MAX                     DR_CACHE_NO_CACHE
#define DR_STREAM_OPTION_CACHE_DEFAULT_MODE_MASK                    DR_CACHE_MASK
#define DR_STREAM_OPTION_CACHE_DEFAULT_MODE_CONFIG                  "CacheDefaultMode"

//
// DR_STREAM_OPTION_CACHE_SOFT_SIZE_LIMIT                 UINT64
// Soft limit for cache size measured in bytes of uncompressed data.
// After soft limit is reached sequential and read-ahead blocks are discarded
// immediately after use while random-read blocks are kept up to hard limit.
// Set to value from the configuration file if there is any.
// NOTE: this is global-only setting and it can't be changed for individual handles.
//
#define DR_STREAM_OPTION_CACHE_SOFT_SIZE_LIMIT                      27u
#define DR_STREAM_OPTION_CACHE_SOFT_SIZE_LIMIT_DEFAULT              0x10000000ui64  // 256 Mb
#define DR_STREAM_OPTION_CACHE_SOFT_SIZE_LIMIT_MIN                  0x0ui64
#define DR_STREAM_OPTION_CACHE_SOFT_SIZE_LIMIT_MAX                  MAX_UINT64
#define DR_STREAM_OPTION_CACHE_SOFT_SIZE_LIMIT_CONFIG               "CacheSoftSizeLimit"

//
// DR_STREAM_OPTION_CACHE_HARD_SIZE_LIMIT                 UINT64
// Hard limit for cache size measured in bytes of uncompressed data.
// Set to value from the configuration file if there is any.
// NOTE: this is global-only setting and it can't be changed for individual handles.
//
#define DR_STREAM_OPTION_CACHE_HARD_SIZE_LIMIT                      28u
#define DR_STREAM_OPTION_CACHE_HARD_SIZE_LIMIT_DEFAULT              0x20000000ui64  // 512 Mb
#define DR_STREAM_OPTION_CACHE_HARD_SIZE_LIMIT_MIN                  0x0ui64
#define DR_STREAM_OPTION_CACHE_HARD_SIZE_LIMIT_MAX                  MAX_UINT64
#define DR_STREAM_OPTION_CACHE_HARD_SIZE_LIMIT_CONFIG               "CacheHardSizeLimit"

//
// Init APIs
//

/*++

DrInitialize

This function behaves like DrInitializeEx with pInitParams set to NULL.
See description of DrInitializeEx below.

--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrInitialize(
    IN  UINT    Version,
    IN  PCSTR   pDryadIniFile
    );

/*++

DrInitialize

Parameters:

    Version         Requested version number of the library. Pass DR_CURRENT_VERISON.

    pDryadIniFile  Pointer to string containing path and file name for cosmos ini file.
                    Pass NULL to use default. Default is cosmos.ini in current directory.

    pInitParams     Pointer to parametes block. May be NULL.

--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrInitializeEx(
    IN  UINT                Version,
    IN  PCSTR               pDryadIniFile,
    IN  PCDR_INIT_PARAMS    pInitParams
    );

DRYADAPI_EXT
void
DRYADAPI
DrLogPreInitialize (
    void
);

DRYADAPI_EXT
DrError
DRYADAPI
DrUninitialize( void );

//
// Free for data structures allocated by Dryad client lib
//

DRYADAPI_EXT
DrError
DRYADAPI
DrFreeMemory(
    IN  PVOID           ptr
    );

/*++

DrOpenStream

Opens or creates cosmos or local file system stream.

Parameters:

    pStreamName     UTF8 encoded fully qualified cosmos URI, file URI, UNC name, or local file name.
                    Cannot be NULL.

    Flags           Specifies if stream should be open or created and open mode.
                    Combines next values:

                        DR_APPEND               open for append   | exclusive, required
                        DR_READ                 open for read     |
                                                (one of above should be specified)

                        DR_OPEN                 open existing stream     | can be combined, required
                        DR_CREATE               create new               |
                        DR_CREATE_OR_OPEN       create or open existing
                                                (defined as DR_OPEN | DR_CREATE)
                                                (at least one of above should be specified)

                        DR_REFRESH_AGGRESSIVE   (default) Refresh metadata from DRM if EOS  | exclusive, optional
                                                is detected.                                |
                        DR_REFRESH_PASSIVE      Do not refresh metadata from DRM if EOS     |
                                                is detected.                                |
                                                (refresh flags are optional)
                        DR_REFRESH_NO_INSTANCES Do not refresh instances in case of read error

                        DR_CACHE_SEQUENTIAL     (default) Optimize data cache for           | exclusive, optional
                                                sequential access. Reading same item twice  |
                                                is not efficient.                           |
                        DR_CACHE_READ_AHEAD     Optimize data cache for                     |
                                                sequential access and enable optimistic     |
                                                background read-ahead.                      |
                        DR_CACHE_RANDOM_ACCESS  Optimize data cache for random              |
                                                access. Reading same items twice is         |
                                                efficient.                                  |
                        DR_CACHE_NO_CACHE       Do not cache data. Consumes least memory.   |
                                                Could lead to data reread if read boundaries|
                                                do not exactly match append boundaries.     |
                                                (cache flags are optional)

    pStreamParams   Pointer to DR_STREAM_PROPERTIES structure. DR_STREAM_PROPERTIES structure
                    contains additional optional parameters.

    pStreamHandle   Pointer to variable that receives handle for opened stream.
                    NOTE: if operation is asynchronous, this location should be valid
                    until completion of operation is reported.

    pAsyncInfo      Pointer to DR_ASYNC_INFO structure.
                    See description of to DR_ASYNC_INFO structure.

Examples:

// create new or open existing cosmos stream for append synchronously
DRHANDLE h;
DrError ret = DrOpenStream( "cosmos://store/volume/dir1/dir2/stream1.ext",
                DR_CREATE_OR_OPEN | DR_APPEND, NULL, &h, NULL );

// asyncronously open existing stream for read
// use event for completion notification
DrError ret;
DRHANDLE h;
DrError asyncRet;
DR_ASYNC_INFO asyncInfo;
ZeroMemory( &asyncInfo, sizeof( asyncInfo ) );
asyncInfo.cbSize = sizeof( asyncInfo );
asyncInfo.pOperationState = &asyncRet;
asyncInfo.Event = CreateEvent( NULL, TRUE, FALSE, NULL );
ret = DrOpenStream( "cosmos://store/volume/dir1/dir2/stream2.ext",
                DR_OPEN | DR_READ, NULL, &h, &asyncInfo );
if ( ret == HRESULT_FROM_WIN32( ERROR_IO_PENDING ) ) {
    WaitForSingleObject( asyncInfo.Event, INFINITE );
    if ( SUCCEEDED( asyncRet ) ) {
        // Open completed successfully
    }
}

--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrOpenStream(
    IN  PCSTR               pStreamName,
    IN  UINT                Flags,
    IN  PCDR_STREAM_PROPERTIES  pStreamParams,
    OUT PDRHANDLE           pStreamHandle,
    IN  PCDR_ASYNC_INFO     pAsyncInfo
    );

//
// Extended version of open stream which accept a session handle as parameter
//

DRYADAPI_EXT
DrError
DRYADAPI
DrOpenStreamEx(
    IN  DRSESSIONHANDLE     Session,
    IN  PCSTR               pStreamName,
    IN  UINT                Flags,
    IN  PCDR_STREAM_PROPERTIES  pStreamParams,
    OUT PDRHANDLE           pStreamHandle,
    IN  PCDR_ASYNC_INFO     pAsyncInfo
    );

/*++

DrOpenStreamFromStreamInfo

Binary verion of open stream: opening based on DR_STREAM
Data structure has the same format as the data returned by DrGetStreamInformation
Upon return from DrOpenStreamFromStreamInfo that data structure may be freed.

Parameters:

    pStreamName     UTF8 encoded fully qualified cosmos URI, file URI, UNC name, or local file name.
                    Cannot be NULL.

    pStreamInfo     Pointer to DR_STREAM structure. Cannot be NULL

    Flags           Same as for DrOpenStream, except for DR_CREATE, which is unacceptable in this API
                    Note: DR_NO_REFRESH_INSTANCES is set by default (if no DR_REFRESH_ is provided)

    pStreamHandle   Pointer to variable that receives handle for opened stream.
                    NOTE: if operation is asynchronous, this location should be valid
                    until completion of operation is reported.

    pReserved       Reserved. Must be zero.

    pAsyncInfo      Pointer to DR_ASYNC_INFO structure.
                    See description of to DR_ASYNC_INFO structure.

Example:

DrError ret;

// retrieve streaminfo
PDR_STREAM streaminfo;
ret = DrGetStreamInformation("cosmos://store/volume/dir1/dir2/stream2.ext",
                             0, 0, DR_ALL_EXTENTS, &streaminfo, NULL);

// asyncronously open existing stream for read
// use event for completion notification
DRHANDLE h;
DrError asyncRet;
DR_ASYNC_INFO asyncInfo;
ZeroMemory( &asyncInfo, sizeof( asyncInfo ) );
asyncInfo.cbSize = sizeof( asyncInfo );
asyncInfo.pOperationState = &asyncRet;
asyncInfo.Event = CreateEvent( NULL, TRUE, FALSE, NULL );
ret = DrOpenStreamFromStreamInfo (NULL, "cosmos://store/volume/dir1/dir2/stream2.ext",
                                  streaminfo, DR_OPEN | DR_READ, NULL, &h, &asyncInfo);
if ( ret == HRESULT_FROM_WIN32( ERROR_IO_PENDING ) ) {
    WaitForSingleObject( asyncInfo.Event, INFINITE );
    if ( SUCCEEDED( asyncRet ) ) {
        // Open completed successfully
    }
}

// release stream info
DrFreeMemory (streaminfo);

--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrOpenStreamFromStreamInfo (
    IN  DRSESSIONHANDLE     Session,          // may be NULL
    IN  PCSTR               pStreamName,
    IN  PDR_STREAM          pStreamInfo,
    IN  UINT                Flags,
    OUT PDRHANDLE           pStreamHandle,
    IN  PVOID               pReserved,        // for future extensions, currently NULL
    IN  PCDR_ASYNC_INFO     pAsyncInfo
    );

/*++
DrOpenSession

Remarks:

    This API lets user to create an empty session handle.

*/

DRYADAPI_EXT
DrError
DRYADAPI
DrOpenSession(
    OUT  PDRSESSIONHANDLE     pSession
    );

/*++
DrCloseSession

Remarks:

    This API lets user to close an existing session handle.

*/

DRYADAPI_EXT
DrError
DRYADAPI
DrCloseSession(
    IN  DRSESSIONHANDLE     Session
    );

/*++

DrReadStream

Parameters:

    StreamHandle    Stream handle returned by DrOpenStream.

    pBuffer         Pointer to the buffer that receives the data read from the stream.

    pBytesRead      Pointer to variable containing size of the buffer. On return this
                    variable receives number of bytes read.

    Flags           Optional, may be 0.

                        DR_REFRESH_AGGRESSIVE   (default) Refresh metadata from DRM if EOS
                                                is detected.
                        DR_REFRESH_PASSIVE      Do not refresh metadata from DRM if EOS
                                                is detected.

    pReadPosition   Pointer to DR_STREAM_POSITION structure. May be NULL.
                    Specifies position in the stream of the block to be read from.
                    If set to DR_INVALID_EXTENT_INDEX and DR_UNKNOWN_OFFSET then read is
                    performed from the current stream position and on return this variable
                    receives the position of the block read.

    pAsyncInfo      Pointer to DR_ASYNC_INFO structure.
                    See description of to DR_ASYNC_INFO structure.

Remarks:

    If pReadPosition is NULL, then current stream position is used as read position.
    Current stream position is advanced if read is successful.

    If pReadPosition is not NULL, extent index in position structure is set to DR_INVALID_EXTENT_INDEX
    and offset is set to DR_UNKNOWN_OFFSET, then current stream position is used as read position.
    If read is successfull, then read position is saved into variable specifed by pReadPosition and
    current stream position is advanced.

    If pReadPosition is not NULL, extent index in position structure is set valid extent index and
    and offset is set to valid offset, then current stream position is set to position specified by
    pReadPosition, then current read position is used as read position.
    Current stream position is advanced if read is successful.

    Queueing TODO

    If none of refresh flags is not specified in Flags, then value passed to DrOpenStream is used.

--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrReadStream(
    IN  DRHANDLE                StreamHandle,
    OUT PVOID                   pBuffer,
    IN OUT  PSIZE_T             pBytesRead,
    IN  UINT                    Flags,
    IN OUT PDR_STREAM_POSITION  pReadPosition,
    IN  PCDR_ASYNC_INFO         pAsyncInfo
    );

/*++

DrAppendStream

Parameters:

    StreamHandle    Stream handle returned by DrOpenStream.

    pData           Pointer to the buffer containing data to be appended to the stream.

    DataSize        Number of bytes to be appened to the stream.

    Flags           Specifies if append should use fixed offset and if partials append is
                    allowed. Flags can be combined.

                        DR_FIXED_OFFSET_APPEND      append at current offset
                        //TODO: DR_SEAL, DR_UPDATE_DRM

    pAppendPosition Pointer to DR_STREAM_POSITION, may be NULL.
                    If not NULL and append succeeds, then variable receives offset and base extent
                    of appended data block.

    pBytesAppended  Pointer to variable to receive number of bytes appended to the stream.
                    May be NULL.

    pAsyncInfo      Pointer to DR_ASYNC_INFO structure.
                    See description of DR_ASYNC_INFO structure.

Remarks:

    If DR_FIXED_OFFSET_APPEND flag is not specified, then data block is appended at the end of stream,
    possibly more then one time. If there is a need to seal an extent during this process and
    pAppendPosition is NULL, than data block is appended to the next extent without waiting
    for the sealing of previous extent to be completed.

    If DR_FIXED_OFFSET_APPEND flag is specified, than data block is appended to the stream at offset set
    by DrSetStreamPostition. Operation fails if offset is not equal to current length of the stream
    since it's not possible to overwrite data appended to the stream or to write beyond end of stream.
    If append succeeds then current stream position is incremented by the number of bytes appended.

    If DR_PARTIAL_APPEND flag is specified, then partial append is enabled and possibly only first part of
    the specified data block is appended. Variable pointed at by pBytesAppended receives number of bytes
    actually appended to the stream.

    TODO: Queueing

    TODO: IN/OUT append pos

--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrAppendStream(
    IN  DRHANDLE                StreamHandle,
    IN  PCVOID                  pData,
    IN  SIZE_T                  DataSize,
    IN  UINT                    Flags,
    IN OUT PDR_STREAM_POSITION  pAppendPosition,    // non-NULL pAppendPosition must be help around until completion
    OUT PSIZE_T                 pBytesAppended,     // non-NULL pBytesAppended must be held around until completion
    IN  PCDR_ASYNC_INFO         pAsyncInfo
    );

typedef struct tagDR_BUFFERLIST
{
    PCVOID  pData;
    SIZE_T  DataSize;
} DR_BUFFERLIST;
typedef DR_BUFFERLIST *PDR_BUFFERLIST;
typedef const DR_BUFFERLIST *PCDR_BUFFERLIST;

DRYADAPI_EXT
DrError
DRYADAPI
DrAppendStreamBufferList(
    IN  DRHANDLE                StreamHandle,
    IN  PCDR_BUFFERLIST         pBufferList,
    IN  SIZE_T                  BufferCount,
    IN  UINT                    Flags,
    IN OUT PDR_STREAM_POSITION  pAppendPosition,    // non-NULL pAppendPosition must be help around until completion
    OUT PSIZE_T                 pBytesAppended,     // non-NULL pBytesAppended must be held around until completion
    IN OUT void                *pReserved,          // must be set to NULL for now
    IN  PCDR_ASYNC_INFO         pAsyncInfo
    );

DRYADAPI_EXT
DrError
DRYADAPI
DrSetStreamPosition(
    IN  DRHANDLE            StreamHandle,
    IN  UINT                ExtentIndex,
    IN  UINT64              Offset
    );

DRYADAPI_EXT
DrError
DRYADAPI
DrGetStreamPosition(
    IN  DRHANDLE            StreamHandle,
    IN  UINT                Flags,
    OUT PDR_STREAM_POSITION pPosition
    );

/*++

DrTranslateStreamPosition

    Translates a stream position so that it is relative to another extent's base offset (or 0)

Parameters

    StreamHandle     Stream handle returned by DrOpenStream

    pSourcePosition  Position you want to translate

    pDestExtentIndex The extent index to translate relative to.  0 for offset relative to the stream.

    pDestOffset      Pointer to the offset that will be output.
                     Must not be NULL.

    Flags            Reserved. Must be 0.

Remarks:

    To translate into absolute stream offset pass 0 for DestExtentIndex.

    NOTE: this operation retrieves information from internal metadata cache. If you use this API to
    translate extent offset returned by DrAppendStream, then it should always return correct result
    since cache is up-to-date. In other scenarios in case if API fails you may need to refresh stream
    metadata by calling DrGetStreamLength with DR_REFRESH_AGGRESSIVE flag and retry DrTranslateStreamPosition
    after DrGetStreamLength succeeds.
--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrTranslateStreamPosition(
    IN  DRHANDLE            StreamHandle,
    IN  PDR_STREAM_POSITION pSourcePosition,
    IN  UINT                DestExtentIndex,
    OUT PUINT64             pDestOffset,
    IN  UINT                Flags
    );

/*++

DrGetStreamLength

    Gets the length of the stream.

Parameters

    StreamHandle    Stream handle returned by DrOpenStream

    pLength         Pointer to the output length variable.
                    Must not be NULL.

    Flags           One of (or pass 0 for default value):

                        DR_REFRESH_AGGRESSIVE (default)
                            - visit server to find out latest known length
                        DR_REFRESH_PASSIVE
                            - return length from local cache if available otherwise
                              visit server to find out latest known length
                        DR_REFRESH_FROM_CACHE
                            - return length from local cache
                              fail if not available

    pAsyncInfo      Pointer to DR_ASYNC_INFO structure.
                    See description of DR_ASYNC_INFO structure.

Remarks:

    Call with DR_REFRESH_FROM_CACHE always returns immediately.
    Note that if there are ongoing appends to this stream issue from this or
    other client this this function may not return precise length.

--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrGetStreamLength(
    IN  DRHANDLE            StreamHandle,
    OUT PUINT64             pLength,
    IN  UINT                Flags,
    IN  PCDR_ASYNC_INFO     pAsyncInfo
    );

DRYADAPI_EXT
DrError
DRYADAPI
DrCloseHandle(
    IN  DRHANDLE        StreamHandle
    );

/*++

DrDelete

    Deletes on recycles stream.

Parameters:

    pStreamName     Pointer to UTF8 name of the stream to be deleted.

    Flags           Specifies if stream should be deleted on recycled.

                        DR_DELETE_FORCE     delete stream

    pAsyncInfo      Pointer to DR_ASYNC_INFO structure.
                    See description of to DR_ASYNC_INFO structure.

Remarks:

    By default this operation recycles stream. Stream is renamed to
    streamName#versionNumber, where versionNumber is integer, and
    stream expiration time is set to recycle stream timeout. Recycled
    stream timeout is specified in DRM configuration file.

    To immediately delete stream set Flags to DR_DELETE_FORCE.

    @TODO: create DrDeleteEx API to return new recycled stream name.

--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrDelete(
    IN  PCSTR           pStreamName,
    IN  UINT            Flags,
    IN  PCDR_ASYNC_INFO pAsyncInfo
    );

DRYADAPI_EXT
DrError
DRYADAPI
DrDeleteEx(
    IN  DRSESSIONHANDLE Session,
    IN  PCSTR           pStreamName,
    IN  UINT            Flags,
    IN  PCDR_ASYNC_INFO pAsyncInfo
    );

/*++

DrRename and DrRenameEx

Parameters:

    Session         Session handle. May be NULL.

    pOldName        Pointer to UTF8 name of the stream to be renamed to pNewName.

    pNewName        Pointer to new UTF8 name of the pOldName stream.

    Flags           A combination of next bit values or zero.

                        DR_RENAME_ALLOW_SUBSTITUTION    Delete pNewName stream if it exists
                                                        before renaming pOldName stream.

                        DR_RENAME_REQUIRE_SUBSTITUTION  Replace existing pNewStream stream
                                                        with pOldStream stream.

    pAsyncInfo      Pointer to DR_ASYNC_INFO structure.
                    See description of to DR_ASYNC_INFO structure.

Remarks:

    If DR_RENAME_ALLOW_SUBSTITUTION and DR_RENAME_REQUIRE_SUBSTITUTION flags are not set then
    operation fails if pNewName stream already exists.

    If either DR_RENAME_ALLOW_SUBSTITUTION or DR_RENAME_REQUIRE_SUBSTITUTION flag is set then
    this function atomically deletes pNewName stream and renames pOldName stream to pNewName.
    If DR_RENAME_REQUIRE_SUBSTITUTION flag is set and pNewName stream does not exist then
    operation fails with DrError_StreamNotFound.

    In substitution mode destination stream may be specified by GUID using .streamid name.
    In this case source stream is renamed to original destination stream name.

--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrRename(
    IN  PCSTR           pOldName,
    IN  PCSTR           pNewName,
    IN  UINT            Flags,
    IN  PCDR_ASYNC_INFO pAsyncInfo
    );

DRYADAPI_EXT
DrError
DRYADAPI
DrRenameEx(
    IN  DRSESSIONHANDLE Session,
    IN  PCSTR           pOldName,
    IN  PCSTR           pNewName,
    IN  UINT            Flags,
    IN  PCDR_ASYNC_INFO pAsyncInfo
    );

/*++

DrMultiModifyStream

Parameters:

    pEntries        Array of DR_MULTIMODIFY_STREAM_ENTRY structures, one for each stream operation
                    to perform

    nEntries        Number of entries in pEntries

    Flags           Reserved. Must be 0.

    pAsyncInfo      Pointer to DR_ASYNC_INFO structure.
                    See description of to DR_ASYNC_INFO structure.

Remarks:

    This API allows you to atomically rename, delete, and set the properties of multiple
    streams on a single volume.

    It is allowed to rename streams over each other concurrently; e.g., A->B and B->A, or
    A->B, B->C, C->A.

    NOTE: in future cosmos versions, the partitioning of volumes will be less clear. To ensure
    compatibility with future versions, you should limit operations to a single directory.
--*/
DrError
DRYADAPI
DrMultiModifyStreamEx(
    IN  DRSESSIONHANDLE Session,
    IN  PCDR_MULTIMODIFY_STREAM_ENTRY pEntries,
    IN  UINT nEntries,
    IN  UINT Flags,
    IN  PCDR_ASYNC_INFO pAsyncInfo
    );

DrError
DRYADAPI
DrMultiModifyStream(
    IN  PCDR_MULTIMODIFY_STREAM_ENTRY pEntries,
    IN  UINT nEntries,
    IN  UINT Flags,
    IN  PCDR_ASYNC_INFO pAsyncInfo
    );

/*++

DrConcatenateStream

Parameters:

    pDestName       Pointer to UTF8 name of the stream to receive extents from source stream.

    pSrcName        Pointer to UTF8 name of the stream to share extents with the destination stream.

    ExtentIndex     Index of extent range to share. Pass 0 to start from the beginning of the stream.

    ExtentCount     Number of extents range to share. Pass DR_ALL_EXTENTS to share all extents from
                    the ExtentIndex to the end of the source stream.

    pDestExtentIndex    If not NULL, pointer to the expected extent index where the new extents will be appended to the destination
                    stream. If NULL, or if the value is DR_UNKOWN_EXTENT_INDEX, then the current end of the stream is used; otherwise,
                    the request fails with DrError_AppendNotAtEnd if the given value does not match the current length of the
                    stream. On return, if not NULL, the value is updated with the actual index at which the extents were appended.
                    Note: On older clusters, the returned value may be DR_UNKNOWN_EXTENT_INDEX if the DRM does not
                    support the feature.

    Flags           Reserved. Must be 0.

    pAsyncInfo      Pointer to DR_ASYNC_INFO structure.
                    See description of to DR_ASYNC_INFO structure.

Remarks:

    Appends extent range specified by ExtentIndex and ExtentCount for pSrcName stream to the end of the
    pDestName stream. No actual copy is done, both streams point to the same extents. Extent is kept
    available while all streams referencing it are present.

--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrConcatenateStream(
    IN  PCSTR           pDestName,
    IN  PCSTR           pSrcName,
    IN  UINT            ExtentIndex,
    IN  UINT            ExtentCount,
    IN OUT PUINT        pDestExtentIndex,
    IN  UINT            Flags,
    IN  PCDR_ASYNC_INFO pAsyncInfo
    );

/*++

DrConcatenateStreamEx

Parameters:

    Session         Session handle, may be NULL.

    pDestName       Pointer to UTF8 name of the stream to receive extents from source stream.

    pDestExtentIndex    If not NULL, pointer to the expected extent index where the new extents will be appended to the destination
                    stream. If NULL, or if the value is DR_UNKOWN_EXTENT_INDEX, then the current end of the stream is used; otherwise,
                    the request fails with DrError_AppendNotAtEnd if the given value does not match the current length of the
                    stream. On return, if not NULL, the value is updated with the actual index at which the extents were appended.
                    Note: On older clusters, the returned value may be DR_UNKNOWN_EXTENT_INDEX if the DRM does not
                    support the feature.

    pSrcRanges      Pointer to array of DR_RANGE structures describing source ranges. See DR_RANGE.
                    There is no need to keep this data in memory for the duration of async call, i.e. it can be allocate on the stack.

    cSrcRanges      Number of DR_RANGE stuctures in pSrcRanges array.

    Flags           Zero or combination of next values:

                        DR_CONCATENATE_ALLOW_CREATE_NEW     create new stream if pDestName stream does not exists.

                        DR_CONCATENATE_REQUIRE_CREATE_NEW   create new stream, fails if pDestName stream does not exists.

    pAsyncInfo      Pointer to DR_ASYNC_INFO structure.
                    See description of to DR_ASYNC_INFO structure.

Remarks:

    Appends extent range specified by ExtentIndex and ExtentCount for pSrcName stream to the end of the
    pDestName stream. No actual copy is done, both streams point to the same extents. Extent is kept
    available while all streams referencing it are present.

--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrConcatenateStreamEx(
    IN  DRSESSIONHANDLE Session,
    IN  PCSTR           pDestName,
    IN OUT PUINT        pDestExtentIndex,
    IN  PCDR_RANGE      pSrcRanges,
    IN  SIZE_T          cSrcRanges,
    IN  UINT            Flags,
    IN  PCDR_ASYNC_INFO pAsyncInfo
);

/*++

DrGetStreamInformation
DrGetStreamInformationEx

Retrieves stream information for stream with given name.

Parameters:

    pStreamName             UTF8 encoded fully qualified cosmos URI, file URI, UNC name, or local file name.
                            Cannot be NULL.

    Reserved0               Reserved. Must be zero.

    StartExtentIndex        Index of first stream extent to return information about.
                            Pass 0 for all extents.

    NumberOfExtentsToFill   Number of extents to return information about.
                            Pass 0 for no extent information, DR_ALL_EXTENTS for information about all
                            extents in the stream.

    ppStreamInfo            Pointer to a variable to receive pointer to DR_STREAM structure.
                            Returned structure must be freed by call to DrFreeMemory.

    pAsyncInfo              Pointer to DR_ASYNC_INFO structure.
                            See description of to DR_ASYNC_INFO structure.
--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrGetStreamInformation(
    IN  PCSTR           pStreamName,
    IN  UINT64          Reserved0,
    IN  UINT            StartExtentIndex,
    IN  UINT            NumberOfExtentsToFill,
    OUT PDR_STREAM*     ppStreamInfo,
    IN  PCDR_ASYNC_INFO pAsyncInfo
);

DRYADAPI_EXT
DrError
DRYADAPI
DrGetStreamInformationEx(
    IN  DRSESSIONHANDLE Session,
    IN  PCSTR           pStreamName,
    IN  UINT64          Reserved0,
    IN  UINT            StartExtentIndex,
    IN  UINT            NumberOfExtentsToFill,
    OUT PDR_STREAM*     ppStreamInfo,
    IN  PCDR_ASYNC_INFO pAsyncInfo
);

/*++
DrGetStreamInformationByHandle

Retrieves stream information for stream with given handle.

See DrGetStreamInformation for parameter description.
--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrGetStreamInformationByHandle(
    IN  DRHANDLE        StreamHandle,
    IN  UINT64          Reserved0,
    IN  UINT            StartExtentIndex,
    IN  UINT            NumberOfExtentsToFill,
    OUT PDR_STREAM*     ppStreamInfo,
    IN  PCDR_ASYNC_INFO pAsyncInfo
);

/*++

DrSetStreamProperties

Parameters:

    pStreamName         Pointer to UTF8 name of the stream.

    pStreamProperties   Pointer to DR_STREAM_PROPERTIES structure containing properties to change.

    pAsyncInfo          Pointer to DR_ASYNC_INFO structure.
                        See description of to DR_ASYNC_INFO structure.

Remarks:

    Attempts to changes stream properties such as expiration time or read-only attribute.

    Set pStreamProperties->ExpirePeriod to number of 100 nanoseconds ticks to change stream's
    expiration time (resulting expiration time is calculated as server current time + pStreamProperties->ExpirePeriod).
    Set to 0 leave stream's expiration time intact.
    Set to DR_INIFINTE to reset stream expiration time to never expire.
    NOTE: for read only stream it's only possible to increase expiration period. Attempt to srink it fails
    with DrError_StreamReadOnly error.

    pStreamProperties->ReadOffsetHint is not used and should be set to 0.

    pStreamProperties->FlagsMask specifies flags to be modified and pStreamProperties->Flags specifies new flag values.
    Set pStreamProperties->FlagsMask to 0 to skip flag modification.

    Available flags:
        DR_STREAM_READ_ONLY
        DR_STREAM_SEALED

    NOTE: Flag values applied before expiration period. If you attempt to set read-only flag and shrink expiration
    period in one call, stream becomes read-only and expiration period is not modified. Such call fails
    with DrError_StreamReadOnly error.

--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrSetStreamProperties(
    IN  PCSTR                   pStreamName,
    IN  PCDR_STREAM_PROPERTIES  pStreamProperties,
    IN  PCDR_ASYNC_INFO         pAsyncInfo
);

//
// Extended version of setting stream property API which caller can attach a session handle
//

DRYADAPI_EXT
DrError
DRYADAPI
DrSetStreamPropertiesEx(
    IN  DRSESSIONHANDLE         Session,
    IN  PCSTR                   pStreamName,
    IN  PCDR_STREAM_PROPERTIES  pStreamProperties,
    IN  PCDR_ASYNC_INFO         pAsyncInfo
);

/*++

DrSetStreamProperties

Parameters:

    StreamHandle    Stream handle returned by DrOpenStream.

    pStreamProperties   Pointer to DR_STREAM_PROPERTIES structure containing properties to change.

    pAsyncInfo          Pointer to DR_ASYNC_INFO structure.
                        See description of to DR_ASYNC_INFO structure.

Remarks:

    See remarks for DrSetStreamProperties function.

--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrSetStreamPropertiesByHandle(
    IN  DRHANDLE                StreamHandle,
    IN  PCDR_STREAM_PROPERTIES  pStreamProperties,
    IN  PCDR_ASYNC_INFO         pAsyncInfo
);

DRYADAPI_EXT
DrError
DRYADAPI
DrSetStreamOption(
    IN  DRHANDLE    StreamHandle,
    IN  UINT        StreamOption,
    IN  PCVOID      pData,
    IN  SIZE_T      cbData
);

DRYADAPI_EXT
DrError
DRYADAPI
DrGetStreamOption(
    IN  DRHANDLE    StreamHandle,
    IN  UINT        StreamOption,
    OUT PVOID       pBuffer,
    IN  SIZE_T      cbBuffer
);

//
// Directory APIs
//

/*++

DrEnumerateDirectory

Enumerates content of directory.

Parameters:

    pDirectoryName  UTF8 encoded fully qualified cosmos directory URI, file system directory URI,
                    UNC name, or local directory name.

    Flags

    ppDirectoryInfo Pointer to variable that receives

    pAsyncInfo      Pointer to DR_ASYNC_INFO structure.
                    See description of to DR_ASYNC_INFO structure.
--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrEnumerateDirectory(
    IN  PCSTR           pDirectoryName,
    IN  UINT            Flags,
    OUT PDR_DIRECTORY*  ppDirectoryInfo,
    IN  PCDR_ASYNC_INFO pAsyncInfo
    );

//
// Extended version of enumerating directory API which caller can attach a session handle
//

DRYADAPI_EXT
DrError
DRYADAPI
DrEnumerateDirectoryEx(
    IN  DRSESSIONHANDLE Session,
    IN  PCSTR           pDirectoryName,
    IN  UINT            Flags,
    OUT PDR_DIRECTORY*  ppDirectoryInfo,
    IN  PCDR_ASYNC_INFO pAsyncInfo
    );

//
// Volume APIs
//

DRYADAPI_EXT
DrError
DRYADAPI
DrGetVolumeInformation(
    IN  PCSTR           pVolumeName,
    OUT PDR_VOLUME*     ppVolumeInfo,
    IN  PCDR_ASYNC_INFO pAsyncInfo
);

//
// Extended version of Volume API which caller can attach a session handle
//

DRYADAPI_EXT
DrError
DRYADAPI
DrGetVolumeInformationEx(
    IN  DRSESSIONHANDLE Session,
    IN  PCSTR           pVolumeName,
    OUT PDR_VOLUME*     ppVolumeInfo,
    IN  PCDR_ASYNC_INFO pAsyncInfo
);

//
// Auxiliary APIs
//

/*++

DrGetErrorMessage

Parameters:

    StatusCode      Status code

    pBuffer         Pointer to a buffer

    cbBuffer        Size of the buffer in bytes

Remarks:

    Fills in pBuffer with UTF8 encoded error message corresponding to StatusCode.
    If cbBuffer bytes is not enough to save the whole message
    returns HRESULT_FROM_WIN32( ERROR_INSUFFICIENT_BUFFER ).

--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrGetErrorMessage(
    IN  DrError StatusCode,
    OUT PCHAR   pBuffer,
    IN  SIZE_T  cbBuffer
    );

/*++

DrSetParentId

Parameters:

    ParentId     Parent operation Id for the next client API call.

Remarks:

    Sets parent operation id for the subsequent call to the other client API function
    on the same thread.
    Provided id is logged at the start of the next client API call. It makes it possible to
    relate log statements for user operations and client library operations.

--*/
DRYADAPI_EXT
void
DRYADAPI
DrSetParentId(
    IN  UINT ParentId
    );

/*++

DrSetOpId

Parameters:

    OpId     Operation Id for the next client API call.

Remarks:

    Sets operation id for the subsequent call to the other client API function on the same thread.

    MAKE SURE that you always call DrOpidNew to generate the operation id, so that it is
    guaranteed to be unique in the process.

    NEVER generate the operation id by youself or any other way.
--*/
DRYADAPI_EXT
void
DRYADAPI
DrSetOpId(
    IN  UINT OpId
    );

/*++

DrComposeExtentStreamInfo

Parameters:

    pCluster,
    pVolume                 cluster and volume names where the extent belongs

    pExtentInfo             Extent info of the extent to become stream

    ppStreamName            Pointer to a variable to receive .extentid stream name

    ppStreamInfo            Pointer to a variable to receive pointer to DR_STREAM structure.

                            Returned structure must be freed by call to DrFreeMemory,
                            which also frees *ppStreamName.
                            DO NOT free *ppStreamName alone!

Remarks:

    Allocate and fill in fake stream information for the extent information provided here.
    *ppStreamName and *ppStreamInfo may be passed as parameters straight into
    DrOpenStreamFromStreamInfo

--*/
DRYADAPI_EXT
DrError
DRYADAPI
DrComposeExtentStreamInfo (
    IN  PCSTR        pCluster,
    IN  PCSTR        pVolume,
    IN  PDR_EXTENT   pExtentInfo,
    OUT PCSTR      * ppStreamName,
    OUT PDR_STREAM * ppStreamInfo
    );

#endif  // JC if 0

#pragma pack( pop )

#pragma warning( pop )

#if defined(__cplusplus)
}
#endif


text:
<?php

use \Jacwright\RestServer\RestException;

class SearchController
{
    /**
     * Limite por defecto para las ultimas busquedas vigentes
     */
    static $last_default_limit = 5;

    /**
     * Returns a JSON string object to the browser when hitting the root of the domain
     *
     * @url GET /search
     * @url GET /search/
     * @url GET /search/$id
     */
    public function search($id = null)
    {
        $search = $this->getSearch($id);

        if($search['id'] == '') {
            $result['status'] = 'notfound';
        }

        $result['data'] = $search;
        return $result;
    }

    /**
     * Returns a list of last missing children in JSON format
     *
     * @url GET /last
     * @url GET /last/
     * @url GET /last/$limit
     */
    public function last($limit = null)
    {
        $last = $this->getLast($limit);

        if(count($last) == 0) {
            $result['status'] = 'notfound';
        }

        $result['data'] = $last;
        return $result;
    }

    /**
     * Gets the user by id or current user
     *
     * @url GET /users/$id
     * @url GET /users/current
     */
    public function getUser($id = null)
    {
        // if ($id) {
        //     $user = User::load($id); // possible user loading method
        // } else {
        //     $user = $_SESSION['user'];
        // }

        return array("id" => $id, "name" => null); // serializes object into JSON
    }

    /**
     * Saves a user to the database
     *
     * @url POST /users
     * @url PUT /users/$id
     */
    public function saveUser($id = null, $data)
    {
        // ... validate $data properties such as $data->username, $data->firstName, etc.
        // $data->id = $id;
        // $user = User::saveUser($data); // saving the user to the database
        $user = array("id" => $id, "name" => null);
        return $user; // returning the updated or newly created user object
    }

    /**
     * Get Charts
     *
     * @url GET /charts
     * @url GET /charts/$id
     * @url GET /charts/$id/$date
     * @url GET /charts/$id/$date/$interval/
     * @url GET /charts/$id/$date/$interval/$interval_months
     */
    public function getCharts($id=null, $date=null, $interval = 30, $interval_months = 12)
    {
        echo "$id, $date, $interval, $interval_months";
    }

    /**
     * Throws an error
     *
     * @url GET /error
     */
    public function throwError() {
        throw new RestException(401, "Empty password not allowed");
    }

    /**
     * Devuelve una busqueda de un chico
     */
    function getSearch($id = null) {

        $busquedas = json_decode(file_get_contents('../../missing.json'), TRUE);

        foreach($busquedas as $key => $busqueda) {
            if($busqueda['id'] == '') {
                $busquedas[$key] = array_merge(
                    array( 'id' => md5($busqueda['nombre'].' '.$busqueda['apellido'].' '.$busqueda['fecha_desaparicion']) ),
                    $busqueda
                );
            }

            // Calcular Edad desde fecha de nacimiento
            if($busqueda["fecha_nacimiento"] != '') {
                if($busqueda['edad'] == '')
                $dt_now = new DateTime("now");
                $dt_nacimiento = new DateTime($busqueda["fecha_nacimiento"]);
                $dt_foto = new DateTime($busqueda["fecha_foto"]);
                $edad = $dt_nacimiento->diff($dt_now);
                $edad_foto = $dt_nacimiento->diff($dt_foto);

                if($busqueda["edad"] == '')
                    $busquedas[$key]["edad"] = intval($edad->format("%y"));
                if($busqueda["edad_foto"] == '')
                    $busquedas[$key]["edad_foto"] = intval($edad_foto->format("%y"));
            }
        }

        $result = array();
        if($id != '') {
            foreach($busquedas as $search)
                if($search["id"] == $id) {
                    $result = $search;
                    break;
                }

            return $result;
        }

        return $busquedas[array_rand($busquedas,1)];
    }

    /**
     * Devuelve las ultimas busquedas vigentes
     */
    function getLast($limit = null) {

        if ($limit == '') {
            $limit = static::$last_default_limit;
        }

        $busquedas = (array) json_decode(file_get_contents('../../missing.json'), TRUE);

        // Oredenamos las busquedas por fecha de desaparicion descendente
        usort($busquedas, function($a, $b){
            return -strcmp($a['fecha_desaparicion'], $b['fecha_desaparicion']);
        });

        $last = array_slice($busquedas, 0, $limit, true);

        foreach($last as $key => $busqueda) {
            if($busqueda['id'] == '') {
                $last[$key] = array_merge(
                    array( 'id' => md5($busqueda['nombre'].' '.$busqueda['apellido'].' '.$busqueda['fecha_desaparicion']) ),
                    $busqueda
                );
            }

            // Calcular Edad desde fecha de nacimiento
            if($busqueda["fecha_nacimiento"] != '') {
                if($busqueda['edad'] == '')
                $dt_now = new DateTime("now");
                $dt_nacimiento = new DateTime($busqueda["fecha_nacimiento"]);
                $dt_foto = new DateTime($busqueda["fecha_foto"]);
                $edad = $dt_nacimiento->diff($dt_now);
                $edad_foto = $dt_nacimiento->diff($dt_foto);

                if($busqueda['edad'] == '')
                    $last[$key]['edad'] = intval($edad->format("%y"));
                if($busqueda['edad_foto'] == '')
                    $last[$key]['edad_foto'] = intval($edad_foto->format("%y"));
            }
        }

        return $last;
    }
}

redpajama_set_name: RedPajamaGithub


text:
import { ReactUnityEventParameter } from "../source/types/react-unity-event-parameters";
import { UnityArguments } from "../source/types/unity-arguments";
import { UnityInstance } from "./unity-instance";

/**
 * Type declaration for global types.
 */
declare global {
  /**
   * Dispatches an event that has been registered to all event systems.
   * @param eventName The name of the event.
   * @param parameters The parameters to pass to the event.
   */
  function dispatchReactUnityEvent(
    eventName: string,
    ...parameters: ReactUnityEventParameter[]
  ): void;

  /**
   * Creates a new UnityInstance.
   * @param canvasHtmlElement The target html canvas element.
   * @param arguments The arguments needed to load Unity.
   * @param onProgress The on progress event listener.
   * @returns A promise resolving when instantiated successfully.
   */
  function createUnityInstance(
    canvasHtmlElement: HTMLCanvasElement,
    arguments: UnityArguments,
    onProgress?: (progression: number) => void
  ): Promise<UnityInstance>;

  /**
   * Due to some developers wanting to use the window object as a global scope
   * in order to invoke the create Unity Instance and dispatch React Unity Event
   * functions, we need to declare the window object as a global type.
   */
  interface Window {
    /**
     * Dispatches an event that has been registered to all event systems.
     * @param eventName The name of the event.
     * @param parameters The parameters to pass to the event.
     */
    dispatchReactUnityEvent: typeof dispatchReactUnityEvent;

    /**
     * Creates a new UnityInstance.
     * @param canvasHtmlElement The target html canvas element.
     * @param arguments The arguments needed to load Unity.
     * @param onProgress The on progress event listener.
     * @returns A promise resolving when instantiated successfully.
     */
    createUnityInstance: typeof createUnityInstance;
  }
}


text:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*============================================================
**
  Type:  MissingRuntimeArtifactException
**
==============================================================*/

using global::System;

namespace System.Reflection
{
    internal sealed class MissingRuntimeArtifactException : MemberAccessException
    {
        public MissingRuntimeArtifactException()
        {
        }

        public MissingRuntimeArtifactException(String message)
            : base(message)
        {
        }
    }
}


text:
layout: post
microblog: true
audio:
photo:
date: 2012-06-14 09:53:23 -0600
guid: http://craigmcclellan.micro.blog/2012/06/14/t213298096262746114.html
---
I don't care to be a ridiculously rich producer. I just want to be able to afford to pay someone else to tune vocals for me. #dreams


text:
class Addprintstofrugles < ActiveRecord::Migration
  def self.up
    add_column :frugles, :prints, :integer, :default => 0
  end

  def self.down
  end
end


text:
namespace thinkyoung {
    namespace client {

        StreamApiLogger::StreamApiLogger(fc::ostream_ptr output)
        {
            this->output = output;
            this->is_first_item = true;
            this->is_closed = false;
            (*this->output) << "[\n";
            return;
        }

        StreamApiLogger::~StreamApiLogger()
        {
            this->disconnect();
            this->close();
            return;
        }

        void StreamApiLogger::close()
        {
            fc::scoped_lock<fc::mutex> lock(this->output_mutex);
            if (this->is_closed)
                return;
            (*this->output) << "\n]\n";
            this->output->close();
            return;
        }

        void StreamApiLogger::log_call_started(uint64_t call_id, const thinkyoung::api::CommonApi* target, const fc::string& name, const fc::variants& args)
        {
            fc::scoped_lock<fc::mutex> lock(this->output_mutex);
            std::string cname = target->debug_get_client_name();

            FC_ASSERT(!this->is_closed);

            if (this->is_first_item)
                this->is_first_item = false;
            else
                (*this->output) << ",\n";
            (*this->output) << "    [\"s\", " << call_id << ", \"" << cname << "\", \"" << name << "\", ";
            fc::json::to_stream((*this->output), args);
            (*this->output) << "]";
            return;
        }

        void StreamApiLogger::log_call_finished(uint64_t call_id, const thinkyoung::api::CommonApi* target, const fc::string& name, const fc::variants& args, const fc::variant& result)
        {
            fc::scoped_lock<fc::mutex> lock(this->output_mutex);
            std::string cname = target->debug_get_client_name();

            FC_ASSERT(!this->is_closed);
            FC_ASSERT(!this->is_first_item);
            (*this->output) << ",\n    [\"f\", " << call_id << ", \"" << cname << "\", \"" << name << "\", ";
            fc::json::to_stream((*this->output), args);
            (*this->output) << ", ";
            fc::json::to_stream((*this->output), result);
            (*this->output) << "]";
            return;
        }

    }
}

#endif


text:
<!DOCTYPE html>

<title>Canvas test: 2d.shadow.offset.negativeX</title>

<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">

2d.shadow.offset.negativeX

Shadows can be offset with negative x

Actual output:

<canvas id="c" class="output" width="100" height="50">
FAIL (fallback content)
</canvas>

Expected output:


text:
from django.db import migrations, models
import martor.models

class Migration(migrations.Migration):

    dependencies = [
        ('flatpages_i18n', '0001_initial'),
    ]

    operations = [
        migrations.AlterField(
            model_name='flatpage_i18n',
            name='content',
            field=martor.models.MartorField(blank=True, verbose_name='content'),
        ),
        migrations.AlterField(
            model_name='menuitem',
            name='title',
            field=models.CharField(blank=True, max_length=100, verbose_name='title'),
        ),
    ]


text:
using System;
using System.Collections;
using System.Collections.Generic;
using Zirpl.AppEngine.Model;

namespace Zirpl.Examples.CodeGeneration.VS2013.Commerce.Model.Metadata.Orders
{
    public partial class OrderStatusTypeMetadataConstants : DictionaryEntityBaseMetadataConstantsBase
    {
        public const string Name_Name = "Name";
		public const bool Name_IsRequired = true;
		public const bool Name_IsMaxLength = false;
        public const int Name_MinLength = 1;
		public const int Name_MaxLength = 100;

        public const string CustomerFacingName_Name = "CustomerFacingName";
		public const bool CustomerFacingName_IsRequired = true;
		public const bool CustomerFacingName_IsMaxLength = false;
        public const int CustomerFacingName_MinLength = 1;
		public const int CustomerFacingName_MaxLength = 100;

	}
}


text:
import abc
from urllib.parse import urljoin
import asyncio

from typing import Any, Callable, Sequence, List

TRELLO_URL_BASE = 'https://api.trello.com/1/'

def join_url(part: str) -> str:
	"""
	Adds `part` to  API base url.  Always returns url without trailing slash.

	:param part:
	:return: url
	"""
	part = part.strip('/')
	newpath = urljoin(TRELLO_URL_BASE, part)

	while newpath.endswith('/'):
		newpath = newpath[:-1]

	return newpath

def make_sequence_attrgetter(attr_name: str) -> Callable[Sequence[object]]:
	"""
	Get a callable which takes a sequence of objects and returns a list of
	``attr_name`` from each object in the sequence.

	:param attr_name: The name of the attribute to get from objects provided the the
		returned callable.
	:return: A callable which returns a list of attributes specified by ``attr_name``.
	"""

	def sequence_attrgetter(seq: Sequence[object]) -> List[object]:
		"""
		Returns a list of attributes from the provided sequence of objects.

		:param seq: The sequence to query.
		:return: List of attribute values.
		"""
		return [getattr(obj, attr_name, None) for obj in seq]

	return sequence_attrgetter

class _Synchronizer(abc.ABCMeta):
	"""
	This metaclass functions as a replacement for abc.ABCMeta that adds a synchronous
	version of every asynchronous method in	the class.

	Finds every coroutine method by checking every method with
	:func:`asyncio.iscoroutinefunction`.  It then creates a synchronous version with
	'_s' appended to the method name.
	"""

	def __new__(cls, clsname, bases, dct):
		new_dct = {}
		for name, val in dct.items():
			# Make a sync version of all coroutine functions
			if asyncio.iscoroutinefunction(val):
				meth = cls.sync_maker(name)
				syncname = '{}_s'.format(name)
				meth.__name__ = syncname
				meth.__qualname__ = '{}.{}'.format(clsname, syncname)
				new_dct[syncname] = meth
			elif isinstance(val, classmethod) and asyncio.iscoroutinefunction(val.__func__):
				meth = cls.sync_maker(val.__func__.__name__)
				syncname = '{}_s'.format(name)
				meth.__name__ = syncname
				meth.__qualname__ = '{}.{}'.format(clsname, syncname)
				new_dct[syncname] = classmethod(meth)

		dct.update(new_dct)
		return super().__new__(cls, clsname, bases, dct)

	@staticmethod
	def sync_maker(func):
		def sync_func(self, *args, **kwargs):
			meth = getattr(self, func)
			return asyncio.get_event_loop().run_until_complete(meth(*args, **kwargs))

		return sync_func

class Synchronizer(metaclass=_Synchronizer):
	pass

def is_valid_website(website: str) -> bool:
		return website.startswith('http://') or website.startswith('https://')

def get_child_obj_id(obj: object, obj_attr_name: str, obj_id_attr_name: str) -> str:
	"""
	:raises AttributeError: If don't have child object or child object does not have an id and object does not have obj_id_attr_name.
	"""
	if hasattr(obj, obj_attr_name):
		child_obj = getattr(obj, obj_attr_name, None)
		if hasattr(child_obj, 'id'):
			child_obj_id = getattr(child_obj, 'id', None)
			if child_obj_id:
				return child_obj_id

	return getattr(obj, obj_id_attr_name)


text:
<?php
declare(strict_types=1);

namespace TestApp\Test;

use BootstrapUI\View\Helper\OptionsAwareTrait;

/**
 * TestOptionsAware
 */
class TestOptionsAware
{
    use OptionsAwareTrait;
}


text:
cargo build
cargo run $1 $2 2> stderr.log


text:
namespace Calamari.Commands.Support
{
    public interface ICommandLocator
    {
        ICommandMetadata[] List();
        ICommand Find(string name);
    }
}


text:
package com.headius.jo;

import java.io.IOException;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import org.jruby.Finalizable;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyHash;
import org.jruby.RubyKernel;
import org.jruby.RubyModule;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.anno.JRubyMethod;
import org.jruby.exceptions.RaiseException;
import org.jruby.runtime.Block;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.load.Library;

public class JoLibrary implements Library{
    public void load(Ruby runtime, boolean wrap) throws IOException {
        RubyModule jo = runtime.defineModule("Jo");
        final ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactory() {
            public Thread newThread(Runnable r) {
                Thread t = new Thread(r);
                t.setDaemon(true);
                return t;
            }
        });
        jo.setInternalVariable("executor", executor);
        RubyClass joFuture = jo.defineClassUnder("Future", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
        RubyClass joChannel = jo.defineClassUnder("Channel", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);

        jo.defineAnnotatedMethods(JoMethods.class);
        joFuture.defineAnnotatedMethods(JoFuture.class);
        joChannel.defineAnnotatedMethods(JoChannel.class);

        runtime.addFinalizer(new Finalizable() {
            public void finalize() {
                executor.shutdown();
            }
        });
    }

    public static class JoRoutine implements Callable<IRubyObject> {
        public JoRoutine(Ruby runtime, Block body) {
            this.runtime = runtime;
            this.body = body;
        }

        public IRubyObject call() throws Exception {
            ThreadContext context = runtime.getCurrentContext();
            try {
                return body.call(context);
            } catch (RaiseException re) {
                RubyKernel.puts(context, body.getBinding().getSelf(), new IRubyObject[] {
                        RubyString.newString(runtime, "joroutine terminated with error: " + re.getMessage())});
                RubyKernel.puts(context, body.getBinding().getSelf(), new IRubyObject[] {re.getException().backtrace()});
                throw re;
            }
        }

        private final Ruby runtime;
        private final Block body;
    }

    public static class JoChannel extends RubyObject {
        public JoChannel(Ruby runtime, RubyClass klass, BlockingQueue<IRubyObject> queue) {
            super(runtime, klass);
            this.queue = queue;
        }

        @JRubyMethod(name = "<<")
        public IRubyObject append(ThreadContext context, IRubyObject value) throws InterruptedException {
            queue.put(value);
            return this;
        }

        @JRubyMethod
        public IRubyObject take(ThreadContext context) throws InterruptedException {
            return queue.take();
        }

        private final BlockingQueue<IRubyObject> queue;
    }

    public static class JoFuture extends RubyObject {
        public JoFuture(Ruby runtime, RubyClass klass, Future<IRubyObject> future) {
            super(runtime, klass);

            this.future = future;
        }

        @JRubyMethod
        public IRubyObject get(ThreadContext context) throws ExecutionException, InterruptedException {
            return future.get();
        }

        @JRubyMethod
        public IRubyObject cancel(ThreadContext context) {
            return context.runtime.newBoolean(future.cancel(true));
        }

        private final Future<IRubyObject> future;
    }

    public static class JoMethods {
        @JRubyMethod(module = true)
        public static IRubyObject jo(ThreadContext context, IRubyObject self, Block block) {
            Ruby runtime = context.runtime;
            RubyModule jo = runtime.getModule("Jo");
            ExecutorService executor = (ExecutorService)jo.getInternalVariable("executor");
            Future<IRubyObject> future = executor.submit(new JoRoutine(runtime, block));
            return new JoFuture(runtime, jo.getClass("Future"), future);
        }

        @JRubyMethod(module = true)
        public static IRubyObject chan(ThreadContext context, IRubyObject self) {
            Ruby runtime = context.runtime;
            return new JoChannel(runtime, (RubyClass)runtime.getClassFromPath("Jo::Channel"), new SynchronousQueue<IRubyObject>(true));
        }

        @JRubyMethod(module = true)
        public static IRubyObject chan(ThreadContext context, IRubyObject self, IRubyObject size) {
            Ruby runtime = context.runtime;
            int capacity = (int)size.convertToInteger().getLongValue();
            return new JoChannel(runtime, (RubyClass)runtime.getClassFromPath("Jo::Channel"), new ArrayBlockingQueue<IRubyObject>(capacity, true));
        }

        @JRubyMethod(module = true)
        public static IRubyObject select(ThreadContext context, IRubyObject self, IRubyObject hash) {
            Ruby runtime = context.runtime;
            RubyHash cases = hash.convertToHash();

            Set<RubyHash.RubyHashEntry> entries = (Set<RubyHash.RubyHashEntry>)cases.directEntrySet();
            Object[] entryArray = entries.toArray();
            OUTER: while (true) {
                for (Object _entry : entryArray) {
                    RubyHash.RubyHashEntry entry = (RubyHash.RubyHashEntry)_entry;
                    IRubyObject _channel = (IRubyObject)entry.getKey();
                    if (!(_channel instanceof JoChannel)) throw runtime.newTypeError(_channel, runtime.getClassFromPath("Jo::Channel"));
                    IRubyObject _proc = (IRubyObject)entry.getValue();
                    IRubyObject value;
                    if ((value = ((JoChannel)_channel).queue.poll()) != null) {
                        _proc.callMethod(context, "call", value);
                        break OUTER;
                    }
                    Thread.yield();
                }
            }
            return context.nil;
        }
    }
}


text:
package engine.event;
import java.util.Collection;

import engine.charr.Character;

/**
 * Created by filipebraida on 31/05/16.
 */
public class BlankEvent extends Event{
    public BlankEvent(String description, Collection<Choice> choices) {
        super(description, choices);
    }

    @Override
    public void applyHistory(Character character) {

    }
}


text:
package es.giiis.pi.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class LogoutServlet
 */
@WebServlet("/LogoutServlet")
public class LogoutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public LogoutServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(false);
		if (session != null)
			session.invalidate();
		response.sendRedirect(request.getContextPath()+"/LoginServlet");
	}

}


text:
sample
==========

* [sample-client](sample-client)
* [sample-shared](sample-shared)
* [sample-server](sample-server)

Live demo: [https://gwt-oauth2.appspot.com/](https://gwt-oauth2.appspot.com/)

Quick start
-------------
First of all, under the root sample module, run:
```mvn
mvn clean install -Denv=dev
```

Then open 2 terminals:

- In the first one, under the [sample-server](sample-server) module, run:
```mvn
mvn appengine:devserver -am -Denv=dev
```

- In the second one, under the root sample module, run:
```mvn
mvn gwt:codeserver -pl sample-client -am -Denv=dev
```

Then access http://localhost:8080/ in your browser.