Duplicated reqs in win32+linux

This commit is contained in:
parth21999 2020-07-02 19:35:55 -04:00
Родитель e7a9a43799
Коммит e9b7d8de0c
5 изменённых файлов: 118 добавлений и 31 удалений

Просмотреть файл

@ -14,6 +14,25 @@ The `file` module provides a platform-independent API for asynchronous file oper
## Exposed API
```c
#define FILE_WRITE_ASYNC_VALUES \
FILE_WRITE_ASYNC_INVALID_ARGS, \
FILE_WRITE_ASYNC_WRITE_ERROR, \
FILE_WRITE_ASYNC_ERROR,\
FILE_WRITE_ASYNC_OK
MU_DEFINE_ENUM(FILE_WRITE_ASYNC_RESULT, FILE_WRITE_ASYNC_VALUES);
#define FILE_READ_ASYNC_VALUES \
FILE_READ_ASYNC_INVALID_ARGS, \
FILE_READ_ASYNC_READ_ERROR, \
FILE_READ_ASYNC_ERROR,\
FILE_READ_ASYNC_OK
MU_DEFINE_ENUM(FILE_READ_ASYNC_RESULT, FILE_READ_ASYNC_VALUES);
typedef struct FILE_HANDLE_DATA_TAG* FILE_HANDLE;
typedef void(*FILE_REPORT_FAULT)(void* user_report_fault_context, const char* information);
typedef void(*FILE_WRITE_CB)(void* user_context, bool is_successful);
typedef void(*FILE_READ_CB)(void* user_context, bool is_successful, CONSTBUFFER_HANDLE content);
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create,FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name);
MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(0, MU_FAILURE);
@ -27,8 +46,7 @@ MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend_filesize, FILE_HANDLE, handle,
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create,FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name);
```
`file_create` opens an existing file by the name of `full_file_name` or creates a file of `desired_file_size` if it doesn't exist and returns the file handle.
`file_create` creates a file by the name of `full_file_name` it doesn't exist. `file_create` opens a file by the name `full_file_name` and returns its file handle.
**SRS_FILE_43_033: [** If `execution_engine` is `NULL`, `file_create` shall fail and return `NULL`. **]**
@ -48,7 +66,7 @@ MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
`file_destroy` closes the given file handle.
**SRS_FILE_43_005: [** If `handle` is null, `file_destroy` shall return. **]**
**SRS_FILE_43_005: [** If `handle` is `NULL`, `file_destroy` shall return. **]**
**SRS_FILE_43_006: [** `file_destroy` shall wait for all pending I/O operations to complete. **]**

Просмотреть файл

@ -33,14 +33,14 @@ MU_DEFINE_ENUM(FILE_WRITE_ASYNC_RESULT, FILE_WRITE_ASYNC_VALUES);
FILE_READ_ASYNC_OK
MU_DEFINE_ENUM(FILE_READ_ASYNC_RESULT, FILE_READ_ASYNC_VALUES);
typedef FILE_HANDLE_DATA_TAG* FILE_HANDLE;
typedef struct FILE_HANDLE_DATA_TAG* FILE_HANDLE;
typedef void(*FILE_REPORT_FAULT)(void* user_report_fault_context, const char* information);
typedef void(*FILE_WRITE_CB)(void* user_context, bool is_successful);
typedef void(*FILE_READ_CB)(void* user_context, bool is_successful, CONSTBUFFER_HANDLE content);
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create,FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name);
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name, FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context);
MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(FILE_WRITE_ASYNC_OK, FILE_WRITE_ASYNC_ERROR);

Просмотреть файл

@ -14,7 +14,27 @@ Linux implementation of the `file` module.
## Exposed API
```c
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create,FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name);
#define FILE_WRITE_ASYNC_VALUES \
FILE_WRITE_ASYNC_INVALID_ARGS, \
FILE_WRITE_ASYNC_WRITE_ERROR, \
FILE_WRITE_ASYNC_ERROR,\
FILE_WRITE_ASYNC_OK
MU_DEFINE_ENUM(FILE_WRITE_ASYNC_RESULT, FILE_WRITE_ASYNC_VALUES);
#define FILE_READ_ASYNC_VALUES \
FILE_READ_ASYNC_INVALID_ARGS, \
FILE_READ_ASYNC_READ_ERROR, \
FILE_READ_ASYNC_ERROR,\
FILE_READ_ASYNC_OK
MU_DEFINE_ENUM(FILE_READ_ASYNC_RESULT, FILE_READ_ASYNC_VALUES);
typedef struct FILE_HANDLE_DATA_TAG* FILE_HANDLE;
typedef void(*FILE_REPORT_FAULT)(void* user_report_fault_context, const char* information);
typedef void(*FILE_WRITE_CB)(void* user_context, bool is_successful);
typedef void(*FILE_READ_CB)(void* user_context, bool is_successful, CONSTBUFFER_HANDLE content);
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name, FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context);
MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(0, MU_FAILURE);
@ -24,9 +44,13 @@ MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend_filesize, FILE_HANDLE, handle,
## file_create
```c
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create,FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name);
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name, FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context);
```
**SRS_FILE_LINUX_43_037: [** If `execution_engine` is `NULL`, `file_create` shall fail and return `NULL`. **]**
**SRS_FILE_LINUX_43_038: [** If `full_file_name` is `NULL` then `file_create` shall fail and return `NULL`. **]**
**SRS_FILE_LINUX_43_029: [** `file_create` shall allocate a `FILE_HANDLE`. **]**
**SRS_FILE_LINUX_43_001: [** `file_create` shall call `open` with `full_file_name` as `pathname` and flags `O_CREAT` and `O_RDWR`. **]**
@ -39,6 +63,8 @@ MOCKABLE_FUNCTION(, FILE_HANDLE, file_create,FILE_REPORT_FAULT, user_report_faul
MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
```
**SRS_FILE_LINUX_43_036: [** If `handle` is `NULL`, `file_destroy` shall return. **]**
**SRS_FILE_LINUX_43_003: [** `file_destroy` shall call `close` with `fd` as `handle`.**]**
**SRS_FILE_LINUX_43_030: [** `file_destroy` shall free the `FILE_HANDLE`. **]**
@ -50,6 +76,12 @@ MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(0, MU_FAILURE);
```
**SRS_FILE_LINUX_43_031: [** If `handle` is `NULL` then `file_write_async` shall fail and return `FILE_WRITE_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_LINUX_43_032: [** If `source` is `NULL` then `file_write_async` shall fail and return `FILE_WRITE_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_LINUX_43_033: [** If `user_callback` is `NULL` then `file_write_async` shall fail and return `FILE_WRITE_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_LINUX_43_019: [** `file_write_async` shall create a `FILE_LINUX_IO` struct with `handle` as `handle`, `FILE_ASYNC_WRITE` as `type`. **]**
**SRS_FILE_LINUX_43_020: [** `file_write_async` shall populate the `data` field of the `FILE_LINUX_IO` struct using `source`, `user_callback` and `user_context`. **]**
@ -72,6 +104,10 @@ MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(0, MU_FAILURE);
```
**SRS_FILE_LINUX_43_034: [** If `handle` is `NULL` then `file_read_async` shall fail and return `FILE_READ_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_LINUX_43_035: [** If `user_callback` is `NULL` then `file_read_async` shall fail and return `FILE_READ_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_LINUX_43_016: [** `file_read_async` shall create a `FILE_LINUX_IO` struct with `handle` as `handle`, `FILE_ASYNC_READ` as `type`. **]**
**SRS_FILE_LINUX_43_017: [** `file_read_async` shall populate the `data` field of the `FILE_LINUX_IO` struct using `user_callback` and `user_context`. **]**
@ -110,7 +146,7 @@ static void on_file_io_complete_linux( FILE_LINUX_IO* io);
**SRS_FILE_LINUX_43_022: [** `on_file_io_complete_linux` shall call `aio_return` to determine if the asynchronous operation succeeded. **]**
**SRS_FILE_LINUX_43_023: [** If the asynchronous operation did not succeed, `on_file_io_complete_linux` shall call `user_report_fault_callback` with `user_report_fault_context` which were specified when `file_create` was called. **]**
**SRS_FILE_LINUX_43_023: [** If the asynchronous operation did not succeed, `on_file_io_complete_linux` shall call `user_callback` with `false` as `is_successful`. **]**
**SRS_FILE_LINUX_43_024: [** If the type of the asynchronous operation is read, `on_file_io_complete_linux` shall construct a `CONSTBUFFER_HANDLE` by calling `CONSTBUFFER_CreateWithMoveMemory` from the bytes read by `ReadFile`. **]**

Просмотреть файл

@ -8,7 +8,26 @@ Windows implementation of the `file` module.
## Exposed API
```c
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create,FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name);
#define FILE_WRITE_ASYNC_VALUES \
FILE_WRITE_ASYNC_INVALID_ARGS, \
FILE_WRITE_ASYNC_WRITE_ERROR, \
FILE_WRITE_ASYNC_ERROR,\
FILE_WRITE_ASYNC_OK
MU_DEFINE_ENUM(FILE_WRITE_ASYNC_RESULT, FILE_WRITE_ASYNC_VALUES);
#define FILE_READ_ASYNC_VALUES \
FILE_READ_ASYNC_INVALID_ARGS, \
FILE_READ_ASYNC_READ_ERROR, \
FILE_READ_ASYNC_ERROR,\
FILE_READ_ASYNC_OK
MU_DEFINE_ENUM(FILE_READ_ASYNC_RESULT, FILE_READ_ASYNC_VALUES);
typedef struct FILE_HANDLE_DATA_TAG* FILE_HANDLE;
typedef void(*FILE_REPORT_FAULT)(void* user_report_fault_context, const char* information);
typedef void(*FILE_WRITE_CB)(void* user_context, bool is_successful);
typedef void(*FILE_READ_CB)(void* user_context, bool is_successful, CONSTBUFFER_HANDLE content);
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name, FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context);
MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(0, MU_FAILURE);
@ -18,9 +37,13 @@ MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend_filesize, FILE_HANDLE, handle,
## file_create
```c
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create,FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name);
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name, FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context);
```
**SRS_FILE_WIN32_43_040: [** If `execution_engine` is `NULL`, `file_create` shall fail and return `NULL`. **]**
**SRS_FILE_WIN32_43_041: [** If `full_file_name` is `NULL` then `file_create` shall fail and return `NULL`. **]**
**SRS_FILE_WIN32_43_001: [** `file_create` shall call `CreateFileA` with `full_file_name` as `lpFileName`, `GENERIC_READ|GENERIC_WRITE` as `dwDesiredAccess`, `FILE_SHARED_READ` as `dwShareMode`, `NULL` as `lpSecurityAttributes`, `OPEN_ALWAYS` as `dwCreationDisposition`, `FILE_FLAG_OVERLAPPED|FILE_FLAG_WRITE_THROUGH` as `dwFlagsAndAttributes` and `NULL` as `hTemplateFiles`. **]**
**SRS_FILE_WIN32_43_041: [** `file_create` shall allocate a `FILE_HANDLE`. **]**
@ -37,7 +60,7 @@ MOCKABLE_FUNCTION(, FILE_HANDLE, file_create,FILE_REPORT_FAULT, user_report_faul
**SRS_FILE_WIN32_43_007: [** `file_create` shall register the cleanup group with the threadpool environment. **]**
**SRS_FILE_WIN32_43_033: [** `file_create` shall create a threadpool io and use `onFileIoComplete` as a callback. **]**
**SRS_FILE_WIN32_43_033: [** `file_create` shall create a threadpool io and use `on_file_io_complete_win32` as a callback. **]**
**SRS_FILE_WIN32_43_008: [** If there are any failures, `file_create` shall return `NULL`. **]**
@ -49,6 +72,8 @@ MOCKABLE_FUNCTION(, FILE_HANDLE, file_create,FILE_REPORT_FAULT, user_report_faul
MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
```
**SRS_FILE_WIN32_43_042: [** If `handle` is `NULL`, `file_destroy` shall return. **]**
**SRS_FILE_WIN32_43_011: [** `file_destroy` shall wait for all I/O to complete. **]**
**SRS_FILE_WIN32_43_012: [** `file_destroy` shall close the cleanup group. **]**
@ -68,6 +93,12 @@ MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(0, MU_FAILURE);
```
**SRS_FILE_WIN32_43_043: [** If `handle` is `NULL` then `file_write_async` shall fail and return `FILE_WRITE_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_WIN32_43_044: [** If `source` is `NULL` then `file_write_async` shall fail and return `FILE_WRITE_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_WIN32_43_045: [** If `user_callback` is `NULL` then `file_write_async` shall fail and return `FILE_WRITE_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_WIN32_43_017: [** `file_write_async` shall call `StartThreadpoolIo`. **]**
**SRS_FILE_WIN32_43_018: [** `file_write_async` shall allocate a context to store `handle`, write as the type of asyncronous operation, `source`, `user_callback` and `user_context. **]**
@ -88,6 +119,10 @@ MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(0, MU_FAILURE);
```
**SRS_FILE_WIN32_43_046: [** If `handle` is `NULL` then `file_read_async` shall fail and return `FILE_READ_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_WIN32_43_047: [** If `user_callback` is `NULL` then `file_read_async` shall fail and return `FILE_READ_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_WIN32_43_025: [** `file_read_async` shall call `StartThreadpoolIo`. **]**
**SRS_FILE_WIN32_43_026: [** `file_read_async` shall allocate a context to store `handle`, read as the type of asynchronous operation, `user_callback` and `user_context` **]**
@ -106,21 +141,21 @@ MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_H
## on_file_io_complete_win32
```c
static VOID CALLBACK on_file_io_complete_win32( /*called when some read/write operation is finished*/
_Inout_ PTP_CALLBACK_INSTANCE Instance,
_Inout_opt_ PVOID Context,
_Inout_opt_ PVOID Overlapped,
_In_ ULONG IoResult,
_In_ ULONG_PTR NumberOfBytesTransferred,
_Inout_ PTP_IO Io
static void on_file_io_complete_win32(
PTP_CALLBACK_INSTANCE instance,
PVOID context,
PVOID overlapped,
ULONG io_result,
ULONG_PTR number_of_bytes_transferred,
PTP_IO io
);
```
`on_file_io_complete_win32` is called when a file operation completes asynchronously.
**SRS_FILE_WIN32_43_034: [** `on_file_io_complete_win32` shall recover the context containing `Overlapped`. **]**
**SRS_FILE_WIN32_43_034: [** `on_file_io_complete_win32` shall recover the context containing `overlapped`. **]**
**SRS_FILE_WIN32_43_035: [** If `IoResult` is not `NO_ERROR`, `on_file_io_complete_win32` shall call `user_report_fault_callback` with `user_report_fault_context` which were specified when `file_create` was called. **]**
**SRS_FILE_WIN32_43_035: [** If `io_result` is not `NO_ERROR`, `on_file_io_complete_win32` shall call `user_callback` with `false` as `is_successful`. **]**
**SRS_FILE_WIN32_43_036: [** If the type of the asynchronous operation is read, `on_file_io_complete_win32` shall construct a `CONSTBUFFER_HANDLE` by calling `CONSTBUFFER_CreateWithMoveMemory` from the bytes read by `ReadFile`. **]**
@ -128,6 +163,4 @@ static VOID CALLBACK on_file_io_complete_win32( /*called when some read/write op
**SRS_FILE_WIN32_43_038: [** If the construction of the `CONSTBUFFER_HANDLE` succeeds, `on_file_io_complete_win32` shall call `user_callback` with `user_context`, `true` as `is_successful` and the created `CONSTBUFFER_HANDLE` as `content`. **]**
**SRS_FILE_WIN32_43_039: [** If the type of the asynchronous operation is write, `on_file_io_complete_win32` shall call `user_callback` with `user_context` and `true` as `is_successful`. **]**
**SRS_FILE_WIN32_43_040: [** If the type of asynchronous operation is neither read nor write, `on_file_io_complete_win32` shall call `user_report_fault_callback` with `user_report_fault_context` which were specified when `file_create` was called. **]**
**SRS_FILE_WIN32_43_039: [** If the type of the asynchronous operation is write, `on_file_io_complete_win32` shall call `user_callback` with `user_context` and `true` as `is_successful`. **]**

Просмотреть файл

@ -27,11 +27,11 @@ typedef struct FILE_WIN32_IO_TAG
FILE_IO_DATA data;
}FILE_WIN32_IO;
static VOID CALLBACK on_file_io_complete_win32( /*called when some read/write operation is finished*/
_Inout_ PTP_CALLBACK_INSTANCE Instance,
_Inout_opt_ PVOID Context,
_Inout_opt_ PVOID Overlapped,
_In_ ULONG IoResult,
_In_ ULONG_PTR NumberOfBytesTransferred,
_Inout_ PTP_IO Io
);
static void on_file_io_complete_win32(
PTP_CALLBACK_INSTANCE instance,
PVOID context,
PVOID overlapped,
ULONG io_result,
ULONG_PTR number_of_bytes_transferred,
PTP_IO io
);