| [2] | 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2006-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_io.h $ |
|---|
| 11 | * $brcm_Revision: 7 $ |
|---|
| 12 | * $brcm_Date: 8/14/09 3:09p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /BSEAV/lib/bfile/bfile_io.h $ |
|---|
| 19 | * |
|---|
| 20 | * 7 8/14/09 3:09p erickson |
|---|
| 21 | * PR55994: update comments |
|---|
| 22 | * |
|---|
| 23 | * 6 6/2/09 7:38p vsilyaev |
|---|
| 24 | * PR 55417: Added support for read method returning no data or completing |
|---|
| 25 | * with a partial read |
|---|
| 26 | * |
|---|
| 27 | * 5 7/26/07 4:18p vsilyaev |
|---|
| 28 | * PR 32813: Added documentation |
|---|
| 29 | * |
|---|
| 30 | * 4 7/10/07 12:45p erickson |
|---|
| 31 | * PR32813: file compilation issues while integrating with Brutus |
|---|
| 32 | * |
|---|
| 33 | * 3 5/1/06 5:19p vsilyaev |
|---|
| 34 | * PR 20680: Addeed BIO_BLOCK_SIZE |
|---|
| 35 | * |
|---|
| 36 | * 2 4/7/06 3:49p vsilyaev |
|---|
| 37 | * PR 20680: Added bfile library |
|---|
| 38 | * |
|---|
| 39 | * 1 4/7/06 12:31p vsilyaev |
|---|
| 40 | * PR 20680: Added bfile library |
|---|
| 41 | * |
|---|
| 42 | * |
|---|
| 43 | ***************************************************************************/ |
|---|
| 44 | #ifndef __BFILE_IO_H__ |
|---|
| 45 | #define __BFILE_IO_H__ |
|---|
| 46 | |
|---|
| 47 | #include "bfile_types.h" |
|---|
| 48 | |
|---|
| 49 | #ifdef __cplusplus |
|---|
| 50 | extern "C" |
|---|
| 51 | { |
|---|
| 52 | #endif |
|---|
| 53 | |
|---|
| 54 | /** |
|---|
| 55 | Summary: |
|---|
| 56 | bfile_io_read_t is used for the I/O read interface |
|---|
| 57 | |
|---|
| 58 | Description: |
|---|
| 59 | The following is one example using bfile_stdio.h: |
|---|
| 60 | |
|---|
| 61 | FILE *file = fopen(filename, "r+"); |
|---|
| 62 | bfile_io_read_t readfile = bfile_stdio_read_attach(file); |
|---|
| 63 | readfile->seek(readfile, offset, SEEK_SET); // a generic seek |
|---|
| 64 | readfile->read(readfile, buffer, length); // a generic read |
|---|
| 65 | bfile_stdio_read_detach(readfile); |
|---|
| 66 | fclose(file); |
|---|
| 67 | |
|---|
| 68 | **/ |
|---|
| 69 | typedef struct bfile_io_read *bfile_io_read_t; |
|---|
| 70 | |
|---|
| 71 | /** |
|---|
| 72 | Summary: |
|---|
| 73 | bfile_io_read_t is used for the I/O write interface |
|---|
| 74 | **/ |
|---|
| 75 | typedef struct bfile_io_write *bfile_io_write_t; |
|---|
| 76 | |
|---|
| 77 | /** |
|---|
| 78 | Summary: |
|---|
| 79 | bio_get_priority is a function typedef used to get the priority of an I/O transaction |
|---|
| 80 | **/ |
|---|
| 81 | typedef int (*bio_get_priority)(void *cntx); |
|---|
| 82 | |
|---|
| 83 | /** |
|---|
| 84 | Summary: |
|---|
| 85 | bfile_io_priority is used to get the priority of an I/O transaction |
|---|
| 86 | **/ |
|---|
| 87 | typedef struct bfile_io_priority { |
|---|
| 88 | bio_get_priority get; |
|---|
| 89 | void *cntx; |
|---|
| 90 | } bfile_io_priority; |
|---|
| 91 | |
|---|
| 92 | /** |
|---|
| 93 | Summary: |
|---|
| 94 | Return the default priority of an I/O transaction |
|---|
| 95 | **/ |
|---|
| 96 | int bio_default_priority(void *cntx); |
|---|
| 97 | |
|---|
| 98 | /** |
|---|
| 99 | Summary: |
|---|
| 100 | Initialize an I/O interface with the default priortity |
|---|
| 101 | **/ |
|---|
| 102 | #define BIO_DEFAULT_PRIORITY {bio_default_priority, NULL} |
|---|
| 103 | |
|---|
| 104 | /** |
|---|
| 105 | Summary: |
|---|
| 106 | bfile_io_read defines the methods for an I/O read interface |
|---|
| 107 | **/ |
|---|
| 108 | struct bfile_io_read { |
|---|
| 109 | ssize_t (*read)(bfile_io_read_t fd, void *buf, size_t length); /* this method is used to read data, it returns number of bytes read, where 0 means end of file, negative return code means an error, and BFILE_ERROR_NO_DATA means that there is temporary no data in the file */ |
|---|
| 110 | off_t (*seek)(bfile_io_read_t fd, off_t offset, int whence); /* this method is used to move next read location */ |
|---|
| 111 | int (*bounds)(bfile_io_read_t fd, off_t *first, off_t *last); /* this method is used to return size of the file */ |
|---|
| 112 | bfile_io_priority priority; /* this member is used to request current priority of I/O transaction */ |
|---|
| 113 | }; |
|---|
| 114 | |
|---|
| 115 | /** |
|---|
| 116 | Summary: |
|---|
| 117 | bfile_io_write defines the methods for an I/O write interface |
|---|
| 118 | **/ |
|---|
| 119 | struct bfile_io_write { |
|---|
| 120 | ssize_t (*write)(bfile_io_write_t fd, const void *buf, size_t length); /* this method is used to write data, it returns number of bytes written */ |
|---|
| 121 | off_t (*trim)(bfile_io_write_t fd, off_t trim_pos); /* this method is used to truncate file */ |
|---|
| 122 | bfile_io_priority priority; /* this member is used to request current priority of I/O transaction */ |
|---|
| 123 | }; |
|---|
| 124 | |
|---|
| 125 | /** |
|---|
| 126 | Summary: |
|---|
| 127 | Attach a new priority function to the I/O read interface |
|---|
| 128 | **/ |
|---|
| 129 | void bio_read_attach_priority(bfile_io_read_t fd, bio_get_priority priority, void *cntx); |
|---|
| 130 | |
|---|
| 131 | /** |
|---|
| 132 | Summary: |
|---|
| 133 | Attach a new priority function to the I/O write interface |
|---|
| 134 | **/ |
|---|
| 135 | void bio_write_attach_priority(bfile_io_write_t fd, bio_get_priority priority, void *cntx); |
|---|
| 136 | |
|---|
| 137 | /** |
|---|
| 138 | Summary: |
|---|
| 139 | This constant defines the default block size for I/O |
|---|
| 140 | |
|---|
| 141 | Description: |
|---|
| 142 | The BIO_BLOCK_SIZE constant is used to optimize I/O. It enables a best effort scheme to have the size of all I/O transactions be a multiplier of the PAGE size. |
|---|
| 143 | BIO_BLOCK_SIZE shall be power of 2. |
|---|
| 144 | **/ |
|---|
| 145 | #define BIO_BLOCK_SIZE 4096 |
|---|
| 146 | |
|---|
| 147 | #ifdef __cplusplus |
|---|
| 148 | } |
|---|
| 149 | #endif |
|---|
| 150 | |
|---|
| 151 | #endif /* __BFILE_IO_H__ */ |
|---|
| 152 | |
|---|
| 153 | |
|---|