fastwriter.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef _FASTWRITER_H
  2. #define _FASTWRITER_H
  3. typedef struct fastwrtier_s fastwriter_t;
  4. typedef enum {
  5. FASTWRITER_FLAGS_DEFAULT = 0,
  6. FASTWRITER_FLAGS_BLOCK = 1, /**< by default the error will be returned if there is no space in the buffer to accomodate the data */
  7. FASTWRITER_FLAGS_OVERWRITE = 2 /**< overwrite the data currently in the storage */
  8. } fastwriter_flags_t;
  9. typedef struct {
  10. size_t buffer_size; /**< buffer size in bytes */
  11. size_t buffer_used; /**< amount of data currently in the buffer */
  12. size_t buffer_max; /**< maximal amount of data in the buffer */
  13. size_t commited; /**< total commited data for current file */
  14. size_t written; /**< total written data for currrent file */
  15. } fastwriter_stats_t;
  16. #define FASTWRITER_BUFFER_DEFAULT 0
  17. #define FASTWRITER_BUFFER_MAX ((size_t)-1)
  18. /*
  19. * @fs - defines which writter implementation will be actually used. One can
  20. * pass just a file name, then a type of partition will be autodetected.
  21. * Otherwise, it is possible to pass the name of storage device. In this
  22. * case either RingFS will be used or data will be pushed to the RAW device.
  23. */
  24. fastwriter_t *fastwriter_init(const char *fs, fastwriter_flags_t flags);
  25. void fastwriter_destroy(fastwriter_t *ctx);
  26. int fastwriter_set_buffer_size(fastwriter_t *ctx, size_t buffer_size);
  27. int fastwriter_get_stats(fastwriter_t *ctx, fastwriter_stats_t *stats);
  28. int fastwriter_open(fastwriter_t *ctx, const char *name, fastwriter_flags_t flags);
  29. int fastwriter_close(fastwriter_t *ctx);
  30. int fastwriter_push(fastwriter_t *ctx, size_t size, const void *buf);
  31. int fastwriter_commit(fastwriter_t *ctx);
  32. int fastwriter_cancel(fastwriter_t *ctx);
  33. int fastwriter_push_data(fastwriter_t *ctx, size_t size, const void *buf);
  34. #endif /* _FASTWRITER_H */