| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2007-2009, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bfile_buffer.h $ |
|---|
| 11 | * $brcm_Revision: 6 $ |
|---|
| 12 | * $brcm_Date: 6/2/09 7:38p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Block based cached file I/O |
|---|
| 17 | * |
|---|
| 18 | * Revision History: |
|---|
| 19 | * |
|---|
| 20 | * $brcm_Log: /BSEAV/lib/bfile/bfile_buffer.h $ |
|---|
| 21 | * |
|---|
| 22 | * 6 6/2/09 7:38p vsilyaev |
|---|
| 23 | * PR 55417: Added support for read method returning no data or completing |
|---|
| 24 | * with a partial read |
|---|
| 25 | * |
|---|
| 26 | * 5 12/18/08 7:04p vsilyaev |
|---|
| 27 | * PR 47854: Improved handling of conditions where asynchronous read |
|---|
| 28 | * exhaust allocated buffer |
|---|
| 29 | * |
|---|
| 30 | * 4 11/26/08 3:56p vsilyaev |
|---|
| 31 | * PR 47650: Added function to get bounds |
|---|
| 32 | * |
|---|
| 33 | * 3 9/18/08 3:27p vsilyaev |
|---|
| 34 | * PR 47105: Added support for layered buffer cache |
|---|
| 35 | * |
|---|
| 36 | * 2 6/14/07 12:49p vsilyaev |
|---|
| 37 | * PR 32162: Serializes async disk I/O for bfile_buffer. Fixed unitilized |
|---|
| 38 | * ref_cnt in bfile_buffer.c |
|---|
| 39 | * |
|---|
| 40 | * 1 5/16/07 9:53p vsilyaev |
|---|
| 41 | * PR 28631: Added block based file cache/buffer |
|---|
| 42 | * |
|---|
| 43 | *******************************************************************************/ |
|---|
| 44 | #ifndef _BFILE_BUFFER_H__ |
|---|
| 45 | #define _BFILE_BUFFER_H__ |
|---|
| 46 | |
|---|
| 47 | #include "bfile_io.h" |
|---|
| 48 | #include "bioatom.h" |
|---|
| 49 | |
|---|
| 50 | #ifdef __cplusplus |
|---|
| 51 | extern "C" |
|---|
| 52 | { |
|---|
| 53 | #endif |
|---|
| 54 | |
|---|
| 55 | typedef struct bfile_buffer *bfile_buffer_t; |
|---|
| 56 | |
|---|
| 57 | typedef enum bfile_buffer_overflow_action { |
|---|
| 58 | bfile_buffer_overflow_action_wait, |
|---|
| 59 | bfile_buffer_overflow_action_abort |
|---|
| 60 | } bfile_buffer_overflow_action; |
|---|
| 61 | |
|---|
| 62 | typedef struct bfile_buffer_cfg { |
|---|
| 63 | bool async; |
|---|
| 64 | unsigned nsegs; |
|---|
| 65 | size_t buf_len; |
|---|
| 66 | void *buf; |
|---|
| 67 | void *sync_cnxt; |
|---|
| 68 | bfile_io_read_t fd; |
|---|
| 69 | void (*async_read)(void *sync_cnxt, bfile_io_read_t fd, void *buf, size_t length, void (*read_cont)(void *cont, ssize_t size), void *cntx); |
|---|
| 70 | bfile_buffer_overflow_action (*async_overflow)(void *sync_cnxt); |
|---|
| 71 | } bfile_buffer_cfg; |
|---|
| 72 | |
|---|
| 73 | typedef enum bfile_buffer_result { |
|---|
| 74 | bfile_buffer_result_ok, |
|---|
| 75 | bfile_buffer_result_read_error, |
|---|
| 76 | bfile_buffer_result_eof, |
|---|
| 77 | bfile_buffer_result_no_data, /* temporary no data in the file */ |
|---|
| 78 | bfile_buffer_result_async, |
|---|
| 79 | bfile_buffer_result_buffer_overflow |
|---|
| 80 | } bfile_buffer_result; |
|---|
| 81 | |
|---|
| 82 | void bfile_buffer_default_cfg(bfile_buffer_cfg *cfg); |
|---|
| 83 | bfile_buffer_t bfile_buffer_create(batom_factory_t factory, bfile_buffer_cfg *cfg); |
|---|
| 84 | void bfile_buffer_clear(bfile_buffer_t buf); |
|---|
| 85 | void bfile_buffer_destroy(bfile_buffer_t buf); |
|---|
| 86 | |
|---|
| 87 | batom_t bfile_buffer_async_read(bfile_buffer_t buf, off_t off, size_t length, bfile_buffer_result *result, void (*read_complete)(void *, batom_t, bfile_buffer_result ), void *cntx); |
|---|
| 88 | batom_t bfile_buffer_read(bfile_buffer_t buf, off_t off, size_t length, bfile_buffer_result *result); |
|---|
| 89 | int bfile_buffer_get_bounds(bfile_buffer_t buf, off_t *first, off_t *last); |
|---|
| 90 | |
|---|
| 91 | #ifdef __cplusplus |
|---|
| 92 | } |
|---|
| 93 | #endif |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | #endif /* _BFILE_BUFFER_H__ */ |
|---|
| 97 | |
|---|
| 98 | |
|---|