yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [diff] [blame^] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2005 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /******************************************************************************* |
| 37 | * |
| 38 | * Filename: |
| 39 | * --------- |
| 40 | * fsal.h |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * MAUI |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * File System Abstraction Layer, with buffered read/write. |
| 49 | * |
| 50 | * Author: |
| 51 | * ------- |
| 52 | * ------- |
| 53 | * |
| 54 | *============================================================================== |
| 55 | * HISTORY |
| 56 | * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 57 | *------------------------------------------------------------------------------ |
| 58 | * removed! |
| 59 | * removed! |
| 60 | * removed! |
| 61 | * |
| 62 | * removed! |
| 63 | * removed! |
| 64 | * removed! |
| 65 | * |
| 66 | * removed! |
| 67 | * removed! |
| 68 | * removed! |
| 69 | * |
| 70 | * removed! |
| 71 | * removed! |
| 72 | * removed! |
| 73 | * |
| 74 | * removed! |
| 75 | * removed! |
| 76 | * removed! |
| 77 | * |
| 78 | * removed! |
| 79 | * removed! |
| 80 | * removed! |
| 81 | * |
| 82 | * removed! |
| 83 | * removed! |
| 84 | * removed! |
| 85 | * |
| 86 | * removed! |
| 87 | * removed! |
| 88 | * removed! |
| 89 | * |
| 90 | * removed! |
| 91 | * removed! |
| 92 | * removed! |
| 93 | * |
| 94 | * removed! |
| 95 | * removed! |
| 96 | * removed! |
| 97 | * |
| 98 | * removed! |
| 99 | * removed! |
| 100 | * removed! |
| 101 | * |
| 102 | * removed! |
| 103 | * removed! |
| 104 | * removed! |
| 105 | * |
| 106 | * removed! |
| 107 | * removed! |
| 108 | * |
| 109 | * |
| 110 | * removed! |
| 111 | * removed! |
| 112 | * |
| 113 | * |
| 114 | * removed! |
| 115 | * removed! |
| 116 | * |
| 117 | * |
| 118 | * removed! |
| 119 | * removed! |
| 120 | * |
| 121 | * |
| 122 | * removed! |
| 123 | * removed! |
| 124 | * |
| 125 | * |
| 126 | * removed! |
| 127 | * removed! |
| 128 | * removed! |
| 129 | * |
| 130 | * removed! |
| 131 | * removed! |
| 132 | * removed! |
| 133 | * |
| 134 | * removed! |
| 135 | * removed! |
| 136 | * removed! |
| 137 | * |
| 138 | * removed! |
| 139 | * removed! |
| 140 | * |
| 141 | * |
| 142 | * removed! |
| 143 | * removed! |
| 144 | * removed! |
| 145 | * |
| 146 | * removed! |
| 147 | * removed! |
| 148 | * removed! |
| 149 | * |
| 150 | * removed! |
| 151 | * removed! |
| 152 | * |
| 153 | * |
| 154 | * removed! |
| 155 | * removed! |
| 156 | * |
| 157 | * |
| 158 | * removed! |
| 159 | * removed! |
| 160 | * removed! |
| 161 | * |
| 162 | * removed! |
| 163 | * removed! |
| 164 | * removed! |
| 165 | * |
| 166 | * removed! |
| 167 | * removed! |
| 168 | * removed! |
| 169 | * |
| 170 | * removed! |
| 171 | * removed! |
| 172 | * removed! |
| 173 | * |
| 174 | * removed! |
| 175 | * removed! |
| 176 | * |
| 177 | * removed! |
| 178 | * removed! |
| 179 | * |
| 180 | * removed! |
| 181 | * removed! |
| 182 | * |
| 183 | * removed! |
| 184 | * removed! |
| 185 | * |
| 186 | * removed! |
| 187 | * removed! |
| 188 | * |
| 189 | * removed! |
| 190 | * removed! |
| 191 | * |
| 192 | * removed! |
| 193 | * removed! |
| 194 | * |
| 195 | * removed! |
| 196 | * removed! |
| 197 | * |
| 198 | * removed! |
| 199 | * removed! |
| 200 | * |
| 201 | * removed! |
| 202 | * removed! |
| 203 | * |
| 204 | * removed! |
| 205 | * removed! |
| 206 | * |
| 207 | * removed! |
| 208 | * removed! |
| 209 | * |
| 210 | * removed! |
| 211 | * removed! |
| 212 | * |
| 213 | * removed! |
| 214 | * removed! |
| 215 | * |
| 216 | * removed! |
| 217 | * removed! |
| 218 | * |
| 219 | * removed! |
| 220 | * removed! |
| 221 | * removed! |
| 222 | * |
| 223 | * removed! |
| 224 | * removed! |
| 225 | * |
| 226 | * removed! |
| 227 | * removed! |
| 228 | * |
| 229 | * removed! |
| 230 | * removed! |
| 231 | * |
| 232 | * removed! |
| 233 | * removed! |
| 234 | * |
| 235 | * removed! |
| 236 | * removed! |
| 237 | * |
| 238 | * removed! |
| 239 | * removed! |
| 240 | * |
| 241 | * removed! |
| 242 | * removed! |
| 243 | * |
| 244 | * removed! |
| 245 | * removed! |
| 246 | * |
| 247 | * removed! |
| 248 | * removed! |
| 249 | * |
| 250 | * removed! |
| 251 | * removed! |
| 252 | * |
| 253 | *------------------------------------------------------------------------------ |
| 254 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 255 | *============================================================================== |
| 256 | *******************************************************************************/ |
| 257 | |
| 258 | /** |
| 259 | * \file fsal.h |
| 260 | * \author Murphy Chen |
| 261 | * \version $Revision: 1.26 $ |
| 262 | * \date $Modtime: May 16 2005 23:18:18 $ |
| 263 | * |
| 264 | * FSAL stands for File System Abstraction Layer. |
| 265 | * This layer provides the following functionalities: |
| 266 | * - Isolate the underlying file systems. |
| 267 | * - Provide buffered read/write operations. |
| 268 | * - Provide bits/bytes accessing functions. |
| 269 | */ |
| 270 | |
| 271 | #ifndef __FSAL_BUFFER_H__ |
| 272 | #define __FSAL_BUFFER_H__ |
| 273 | |
| 274 | #ifdef __cplusplus |
| 275 | extern "C" |
| 276 | { |
| 277 | #endif /* __cplusplus */ |
| 278 | |
| 279 | #ifndef FSAL_STANDALONE |
| 280 | /// For target and MoDIS |
| 281 | #define FSAL_VERBOSE 0 |
| 282 | #include "fs_gprot.h" |
| 283 | #include "kal_general_types.h" |
| 284 | #define FSAL_PLATFORM_KAL 1 |
| 285 | #define FSAL_PLATFORM_WIN32 0 |
| 286 | #define FSAL_PLATFORM_MEMORY 0 |
| 287 | #else |
| 288 | /// For Win32 standalone application, unit test and PC Simulator |
| 289 | #include <stdio.h> |
| 290 | #include <assert.h> |
| 291 | #include <string.h> |
| 292 | #ifndef ASSERT |
| 293 | #define ASSERT(x) assert(x) |
| 294 | #endif |
| 295 | #define FSAL_VERBOSE 0 |
| 296 | #define kal_mem_cpy(a,b,c) memcpy(a,b,c) |
| 297 | #include "kal_general_types.h" |
| 298 | #define MED_STAT_FSAL_START 0 |
| 299 | #define FSAL_PLATFORM_KAL 0 |
| 300 | #define FSAL_PLATFORM_WIN32 1 |
| 301 | #define FSAL_PLATFORM_MEMORY 0 |
| 302 | #endif |
| 303 | |
| 304 | typedef enum { |
| 305 | FSAL_OK = 0, |
| 306 | FSAL_OPEN_ERROR, |
| 307 | FSAL_READ_ERROR, |
| 308 | FSAL_WRITE_ERROR, |
| 309 | FSAL_SEEK_ERROR, |
| 310 | FSAL_CLOSE_ERROR, |
| 311 | FSAL_INVALID_ARGUMENT, |
| 312 | /// The field of the structure is invalid. Possibly caused by memory corruption. |
| 313 | FSAL_MEMORY_CORRUPTION, |
| 314 | FSAL_FATAL_ERROR, |
| 315 | FSAL_DEVICE_BUSY, |
| 316 | FSAL_READ_OVER_EOF, |
| 317 | FSAL_SEEK_OVER_EOF |
| 318 | } FSAL_Status; |
| 319 | |
| 320 | |
| 321 | |
| 322 | typedef enum { |
| 323 | /// Open for reading. |
| 324 | FSAL_READ = 0, |
| 325 | /// Open for reading and writing. |
| 326 | /// The file is created if it is not existed, otherwise it is truncated. |
| 327 | FSAL_WRITE, |
| 328 | /// Open for reading and appending. |
| 329 | /// The file is created if it is not existed. |
| 330 | FSAL_APPEND, |
| 331 | /// Open a ROM file for reading. |
| 332 | /// FSAL_Direct_SetRamFileSize shall be called before calling FSAL_Open. |
| 333 | FSAL_ROMFILE, |
| 334 | /// |
| 335 | FSAL_READ_SHARED, |
| 336 | FSAL_NONBLOCKING = 0x80 |
| 337 | } FSAL_FileMode; |
| 338 | |
| 339 | |
| 340 | typedef enum { |
| 341 | FSAL_BIG_ENDIAN = 0, |
| 342 | FSAL_LITTLE_ENDIAN |
| 343 | } FSAL_ByteOrder; |
| 344 | |
| 345 | /** |
| 346 | * The memory space of the FSAL structure is prepared by the caller. |
| 347 | * Accesses to each file requires a separate instance of each FSAL structure. |
| 348 | * The content of the structuer will be initialized via the FSAL_Open |
| 349 | * function call. |
| 350 | * And the pointer to the structure need to be passed as the first argument |
| 351 | * to each FSAL function invocations. |
| 352 | */ |
| 353 | typedef struct { |
| 354 | /* file system abstration layer*/ |
| 355 | #if FSAL_PLATFORM_KAL |
| 356 | FS_HANDLE hFile; |
| 357 | /// error code from file system |
| 358 | kal_int32 iFSErrorCode; |
| 359 | #elif FSAL_PLATFORM_MEMORY |
| 360 | kal_uint32 uMaxRamFileSize; |
| 361 | #elif FSAL_PLATFORM_WIN32 |
| 362 | FILE *hFile; |
| 363 | #endif |
| 364 | /// For ROM file. Point to the start memory address of the file. |
| 365 | kal_uint8 *pbFile; |
| 366 | kal_uint32 uRamFileSize; |
| 367 | kal_uint32 uRamFileOffset; |
| 368 | kal_uint32 uFileSize; |
| 369 | kal_uint32 uFileOffset; |
| 370 | kal_bool bBuffering; |
| 371 | kal_uint8 *pbBuf; |
| 372 | kal_uint32 uBufSize; |
| 373 | kal_uint32 uCachedBlock; |
| 374 | kal_uint32 uCachedFileSize; |
| 375 | kal_bool bDirty; /* whether the cache has been written to */ |
| 376 | kal_bool bPartialCached; /* whether the cache bloch isn't entire */ |
| 377 | kal_uint32 uLastReadCount; |
| 378 | kal_uint32 uDRMpermission; |
| 379 | |
| 380 | FSAL_ByteOrder uByteOrder; |
| 381 | } STFSAL; |
| 382 | |
| 383 | /* ------ Private Macros ------ */ |
| 384 | |
| 385 | #define FSAL_CHECK_ARG(exp) \ |
| 386 | if (!(exp)) \ |
| 387 | return FSAL_INVALID_ARGUMENT |
| 388 | |
| 389 | #define FSAL_ASSERT(exp) \ |
| 390 | if (!(exp)) \ |
| 391 | return FSAL_FATAL_ERROR |
| 392 | |
| 393 | #define FSAL_ASSERT_NO_RET_VAL(exp) \ |
| 394 | if (!(exp)) \ |
| 395 | return |
| 396 | |
| 397 | /* ------ public functions ------ */ |
| 398 | |
| 399 | /** |
| 400 | * Open the file. |
| 401 | * |
| 402 | * @param pstFSAL pointer to FSAL structure prepared by caller. |
| 403 | * FSAL will initialize the structure. |
| 404 | * @param szFile pointer to a string contained the file name when opened in FSAL_READ, |
| 405 | * FSAL_WRITE, or FSAL_APPEND mode; pointer to the start memory address of the file |
| 406 | * when opened in FSAL_ROMFILE mode. |
| 407 | * @param eMode file operation mode. |
| 408 | * |
| 409 | * @return If the function succeeds, the return value is FSAL_OK. |
| 410 | * Otherwise, an error code is returned. |
| 411 | */ |
| 412 | FSAL_Status FSAL_Open(STFSAL *pstFSAL, void *szFile, FSAL_FileMode eMode); |
| 413 | |
| 414 | /** |
| 415 | * Open the file which has been opened via file I/O API with its file handle. |
| 416 | * Please do not call FSAL_Close for this handle. |
| 417 | * |
| 418 | * @param pstFSAL pointer to FSAL structure prepared by caller. |
| 419 | * FSAL will initialize the structure. |
| 420 | * @param pFileHandle file handle of the underlying file I/O API. |
| 421 | * |
| 422 | * @return If the function succeeds, the return value is FSAL_OK. |
| 423 | * Otherwise, an error code is returned. |
| 424 | */ |
| 425 | FSAL_Status FSAL_Open_WithHandle(STFSAL *pstFSAL, void *pFileHandle); |
| 426 | |
| 427 | /** |
| 428 | * Open an existing file. When using this interface, you need to consider |
| 429 | * about the issues of multiple access to the same file. |
| 430 | * Please do not call FSAL_Close for this handle. |
| 431 | * |
| 432 | * @param pstFSAL pointer to FSAL structure prepared by caller. |
| 433 | * FSAL will initialize the structure. |
| 434 | * @param pstFSAL_Existing pointer to an existing FSAL structure, |
| 435 | * FSAL will access file opened via the file handle in that structure. |
| 436 | * |
| 437 | * @return If the function succeeds, the return value is FSAL_OK. |
| 438 | * Otherwise, an error code is returned. |
| 439 | */ |
| 440 | FSAL_Status FSAL_Open_Attach(STFSAL *pstFSAL, STFSAL *pstFSAL_Existing); |
| 441 | |
| 442 | /** |
| 443 | * Client prepares its own buffer and call this function |
| 444 | * to set buffer for FSAL cache. |
| 445 | * |
| 446 | * @param pstFSAL pointer to FSAL structure. |
| 447 | * @param uBufferSize size of the buffer in unit of byte. |
| 448 | * @param pbBuf memory location of the buffer |
| 449 | * |
| 450 | * @return None. |
| 451 | */ |
| 452 | void FSAL_SetBuffer(STFSAL *pstFSAL, kal_uint32 uBufferSize, kal_uint8 *pbBuf); |
| 453 | |
| 454 | /** |
| 455 | * Flush FSAL cache and close the file. |
| 456 | * |
| 457 | * @param pstFSAL pointer to FSAL structure. |
| 458 | * |
| 459 | * @return None. |
| 460 | */ |
| 461 | FSAL_Status FSAL_Close(STFSAL *pstFSAL); |
| 462 | |
| 463 | /* ------ buffering functions (fsal_buffer.c) ------ */ |
| 464 | |
| 465 | /** |
| 466 | * Read data from the file. |
| 467 | * |
| 468 | * @param pstFSAL pointer to FSAL structure. |
| 469 | * @param pbBuf memory location of the data. |
| 470 | * @param uSize number of bytes to read. uSize must be larger than 0. |
| 471 | * |
| 472 | * @return If the function succeeds, the return value is FSAL_OK. |
| 473 | * Otherwise, an error code is returned. |
| 474 | */ |
| 475 | FSAL_Status FSAL_Read(STFSAL *pstFSAL, kal_uint8* pbBuf, kal_uint32 uSize); |
| 476 | |
| 477 | /** |
| 478 | * Write data to the file. |
| 479 | * |
| 480 | * @param pstFSAL pointer to FSAL structure. |
| 481 | * @param pbBuf memory location of the data. |
| 482 | * @param uSize number of bytes to write. uSize must be larger than 0. |
| 483 | * |
| 484 | * @return If the function succeeds, the return value is FSAL_OK. |
| 485 | * Otherwise, an error code is returned. |
| 486 | */ |
| 487 | FSAL_Status FSAL_Write(STFSAL *pstFSAL, kal_uint8 *pbBuf, kal_uint32 uSize); |
| 488 | |
| 489 | /** |
| 490 | * Change file offset. |
| 491 | * |
| 492 | * @param pstFSAL pointer to FSAL structure. |
| 493 | * @param uOffset offsets in unit of bytes. |
| 494 | * |
| 495 | * @return If the function succeeds, the return value is FSAL_OK. |
| 496 | * Otherwise, an error code is returned. |
| 497 | */ |
| 498 | FSAL_Status FSAL_Seek(STFSAL *pstFSAL, kal_uint32 uOffset); |
| 499 | |
| 500 | /** |
| 501 | * Flush FSAL cache to the underlying file system. |
| 502 | * |
| 503 | * @param pstFSAL pointer to FSAL structure. |
| 504 | * |
| 505 | * @return None. |
| 506 | */ |
| 507 | FSAL_Status FSAL_CacheFlush(STFSAL *pstFSAL); |
| 508 | |
| 509 | /** |
| 510 | * Get the current file position. |
| 511 | * |
| 512 | * @param pstFSAL pointer to FSAL structure. |
| 513 | * @param puPosition memory location for retrieving the file position. |
| 514 | * |
| 515 | * @return If the function succeeds, the return value is FSAL_OK. |
| 516 | * Otherwise, an error code is returned. |
| 517 | */ |
| 518 | FSAL_Status FSAL_GetCurPos(STFSAL *pstFSAL, kal_uint32 *puPosition); |
| 519 | |
| 520 | /** |
| 521 | * Get the file size. |
| 522 | * The current file position remains the same after invocation. |
| 523 | * |
| 524 | * @param pstFSAL pointer to FSAL structure. |
| 525 | * @param puFileSize memory location for retrieving the file size. |
| 526 | * |
| 527 | * @return If the function succeeds, the return value is FSAL_OK. |
| 528 | * Otherwise, an error code is returned. |
| 529 | */ |
| 530 | FSAL_Status FSAL_GetFileSize(STFSAL *pstFSAL, kal_uint32 *puFileSize); |
| 531 | |
| 532 | |
| 533 | |
| 534 | /* ------ bits/bytes read access functions (fsal_read.c) ------ */ |
| 535 | |
| 536 | /** |
| 537 | * Read n bytes. |
| 538 | * |
| 539 | * @param pstFSAL pointer to FSAL structure. |
| 540 | * @param pbData memory location for storing the result bytes |
| 541 | * @param uLen number of bytes to read |
| 542 | * |
| 543 | * @return If the function succeeds, the return value is FSAL_OK. |
| 544 | * Otherwise, an error code is returned. |
| 545 | */ |
| 546 | FSAL_Status FSAL_Read_Bytes(STFSAL *pstFSAL, kal_uint8 *pbData, kal_uint32 uLen); |
| 547 | |
| 548 | /** |
| 549 | * Read n bits. |
| 550 | * When calling this function for the first time, *puBitCnt must be 0. |
| 551 | * *puBitCnt will be updated after each invocation. |
| 552 | * |
| 553 | * @param pstFSAL pointer to FSAL structure. |
| 554 | * @param puBitCnt memory location for storing the bit offset. |
| 555 | * @param pbValue memory location for storing the result bits. |
| 556 | * @param uBitLen number of bits to read (1~8). |
| 557 | * |
| 558 | * @return If the function succeeds, the return value is FSAL_OK. |
| 559 | * Otherwise, an error code is returned. |
| 560 | */ |
| 561 | FSAL_Status FSAL_Read_Bits(STFSAL *pstFSAL, kal_uint32 *puBitCnt, kal_uint8 *pbValue, kal_uint32 uBitLen); |
| 562 | |
| 563 | /** |
| 564 | * Read 4 bytes representing an unsigned integer. |
| 565 | * The content stored on the file is assumed to be big-endian. |
| 566 | * This function will handle the endian-conversion issue. |
| 567 | * |
| 568 | * @param pstFSAL pointer to FSAL structure. |
| 569 | * @param puValue memory location for storing the result unsigned integer |
| 570 | * |
| 571 | * @return If the function succeeds, the return value is FSAL_OK. |
| 572 | * Otherwise, an error code is returned. |
| 573 | */ |
| 574 | FSAL_Status FSAL_Read_UINT(STFSAL *pstFSAL, kal_uint32 *puValue); |
| 575 | |
| 576 | /** |
| 577 | * Read 3 bytes representing an unsigned integer. |
| 578 | * The content stored on the file is assumed to be big-endian. |
| 579 | * This function will handle the endian-conversion issue. |
| 580 | * |
| 581 | * @param pstFSAL pointer to FSAL structure. |
| 582 | * @param puValue memory location for storing the result unsigned integer |
| 583 | * |
| 584 | * @return If the function succeeds, the return value is FSAL_OK. |
| 585 | * Otherwise, an error code is returned. |
| 586 | */ |
| 587 | FSAL_Status FSAL_Read_UINT24(STFSAL *pstFSAL, kal_uint32 *puValue); |
| 588 | |
| 589 | /** |
| 590 | * Read 2 bytes representing an unsigned integer. |
| 591 | * The content stored on the file is assumed to be big-endian. |
| 592 | * This function will handle the endian-conversion issue. |
| 593 | * |
| 594 | * @param pstFSAL pointer to FSAL structure. |
| 595 | * @param pwValue memory location for storing the result unsigned integer |
| 596 | * |
| 597 | * @return If the function succeeds, the return value is FSAL_OK. |
| 598 | * Otherwise, an error code is returned. |
| 599 | */ |
| 600 | FSAL_Status FSAL_Read_UINT16(STFSAL *pstFSAL, kal_uint16 *pwValue); |
| 601 | |
| 602 | /** |
| 603 | * Skip n bytes. |
| 604 | * |
| 605 | * @param pstFSAL pointer to FSAL structure. |
| 606 | * @param uLen number of bytes to skip |
| 607 | * |
| 608 | * @return If the function succeeds, the return value is FSAL_OK. |
| 609 | * Otherwise, an error code is returned. |
| 610 | */ |
| 611 | FSAL_Status FSAL_Skip_Bytes(STFSAL *pstFSAL, kal_uint32 uLen); |
| 612 | |
| 613 | /** |
| 614 | * Get next n bytes. The file offset does not change after invocation. |
| 615 | * |
| 616 | * @param pstFSAL pointer to FSAL structure. |
| 617 | * @param pbValue memory location for storing the result bytes |
| 618 | * @param uLen number of bytes to peek |
| 619 | * |
| 620 | * @return If the function succeeds, the return value is FSAL_OK. |
| 621 | * Otherwise, an error code is returned. |
| 622 | */ |
| 623 | FSAL_Status FSAL_Peek_Bytes(STFSAL *pstFSAL, kal_uint8 *pbValue, kal_uint32 uLen); |
| 624 | |
| 625 | /** |
| 626 | * Get next unsinged integer. The file offset does not change after invocation. |
| 627 | * |
| 628 | * @param pstFSAL pointer to FSAL structure. |
| 629 | * @param puValue memory location for storing the result unsigned integer |
| 630 | * |
| 631 | * @return If the function succeeds, the return value is FSAL_OK. |
| 632 | * Otherwise, an error code is returned. |
| 633 | */ |
| 634 | FSAL_Status FSAL_Peek_UINT(STFSAL *pstFSAL, kal_uint32 *puValue); |
| 635 | |
| 636 | |
| 637 | /* ------ bits/bytes write access functions (fsal_write.c) ------ */ |
| 638 | |
| 639 | /** |
| 640 | * Write n bytes. |
| 641 | * |
| 642 | * @param pstFSAL pointer to FSAL structure. |
| 643 | * @param pbData memory location of the bytes |
| 644 | * @param uLen number of bytes to write |
| 645 | * |
| 646 | * @return If the function succeeds, the return value is FSAL_OK. |
| 647 | * Otherwise, an error code is returned. |
| 648 | */ |
| 649 | FSAL_Status FSAL_Write_Bytes(STFSAL *pstFSAL, kal_uint8 *pbData, kal_uint32 uLen); |
| 650 | |
| 651 | /** |
| 652 | * Write 4 bytes representing an unsigned integer. |
| 653 | * The value written to the file will be stored as big-endian. |
| 654 | * This function will handle the endian-conversion issue. |
| 655 | * |
| 656 | * @param pstFSAL pointer to FSAL structure. |
| 657 | * @param uValue The value to be written to the file. |
| 658 | * |
| 659 | * @return If the function succeeds, the return value is FSAL_OK. |
| 660 | * Otherwise, an error code is returned. |
| 661 | */ |
| 662 | FSAL_Status FSAL_Write_UINT(STFSAL *pstFSAL, kal_uint32 uValue); |
| 663 | |
| 664 | /** |
| 665 | * Write 2 bytes representing an unsigned integer. |
| 666 | * The value written to the file will be stored as big-endian. |
| 667 | * This function will handle the endian-conversion issue. |
| 668 | * |
| 669 | * @param pstFSAL pointer to FSAL structure. |
| 670 | * @param wValue The value to be written to the file. |
| 671 | * |
| 672 | * @return If the function succeeds, the return value is FSAL_OK. |
| 673 | * Otherwise, an error code is returned. |
| 674 | */ |
| 675 | FSAL_Status FSAL_Write_UINT16(STFSAL* pstFSAL, kal_uint16 wValue); |
| 676 | |
| 677 | /** |
| 678 | * Write 1 byte representing an unsigned character. |
| 679 | * |
| 680 | * @param pstFSAL pointer to FSAL structure. |
| 681 | * @param bValue The value to be written to the file. |
| 682 | * |
| 683 | * @return If the function succeeds, the return value is FSAL_OK. |
| 684 | * Otherwise, an error code is returned. |
| 685 | */ |
| 686 | FSAL_Status FSAL_Write_UINT8(STFSAL* pstFSAL, kal_uint8 bValue); |
| 687 | |
| 688 | /** |
| 689 | * Write 4 bytes representing an unsigned integer at a given file offset. |
| 690 | * File position remains the same after the invocation. |
| 691 | * The value written to the file will be stored as big-endian. |
| 692 | * This function will handle the endian-conversion issue. |
| 693 | * |
| 694 | * @param pstFSAL pointer to FSAL structure. |
| 695 | * @param uValue The value to be written to the file. |
| 696 | * @param uOffset The file offset to write to. |
| 697 | * |
| 698 | * @return If the function succeeds, the return value is FSAL_OK. |
| 699 | * Otherwise, an error code is returned. |
| 700 | */ |
| 701 | FSAL_Status FSAL_Write_UINT_AT(STFSAL* pstFSAL, kal_uint32 uValue, kal_uint32 uOffset); |
| 702 | |
| 703 | /* ------ direct access functions (bypass buffering mechanism) ------ */ |
| 704 | |
| 705 | /** |
| 706 | * Open the file. (Internal Use by FSAL Only) |
| 707 | * |
| 708 | * @param pstFSAL pointer to FSAL structure. |
| 709 | * @param szFile pointer to a string contained the file name. |
| 710 | * @param eMode file operation mode. |
| 711 | * |
| 712 | * @return If the function succeeds, the return value is FSAL_OK. |
| 713 | * Otherwise, an error code is returned. |
| 714 | */ |
| 715 | FSAL_Status FSAL_Direct_Open(STFSAL *pstFSAL, void *szFile, FSAL_FileMode eMode); |
| 716 | |
| 717 | /** |
| 718 | * Close the file. (Internal Use by FSAL Only) |
| 719 | * |
| 720 | * @param pstFSAL pointer to FSAL structure. |
| 721 | * |
| 722 | * @return If the function succeeds, the return value is FSAL_OK. |
| 723 | * Otherwise, an error code is returned. |
| 724 | */ |
| 725 | FSAL_Status FSAL_Direct_Close(STFSAL *pstFSAL); |
| 726 | |
| 727 | /** |
| 728 | * Read data from the file directly. |
| 729 | * |
| 730 | * Use with caution. Becuase the file offset will be out-of-sync |
| 731 | * between FSAL and underlying file system. |
| 732 | * |
| 733 | * @param pstFSAL pointer to FSAL structure. |
| 734 | * @param pbBuf memory location of the data. |
| 735 | * @param uSize number of bytes to read. uSize must be larger than 0. |
| 736 | * |
| 737 | * @return If the function succeeds, the return value is FSAL_OK. |
| 738 | * Otherwise, an error code is returned. |
| 739 | */ |
| 740 | FSAL_Status FSAL_Direct_Read(STFSAL *pstFSAL, kal_uint8* pbBuf, kal_uint32 uSize); |
| 741 | |
| 742 | /** |
| 743 | * Write data to the file directly. |
| 744 | * |
| 745 | * Use with caution. Becuase the file offset will be out-of-sync |
| 746 | * between FSAL and underlying file system. |
| 747 | * |
| 748 | * @param pstFSAL pointer to FSAL structure. |
| 749 | * @param pbBuf memory location of the data. |
| 750 | * @param uSize number of bytes to write. uSize must be larger than 0. |
| 751 | * |
| 752 | * @return If the function succeeds, the return value is FSAL_OK. |
| 753 | * Otherwise, an error code is returned. |
| 754 | */ |
| 755 | FSAL_Status FSAL_Direct_Write(STFSAL *pstFSAL, kal_uint8* pbBuf, kal_uint32 uSize); |
| 756 | |
| 757 | /** |
| 758 | * Change file offset of the underlying file system directly. |
| 759 | * |
| 760 | * Use with caution. Becuase the file offset will be out-of-sync |
| 761 | * between FSAL and underlying file system. |
| 762 | * |
| 763 | * @param pstFSAL pointer to FSAL structure. |
| 764 | * @param uOffset offsets in unit of bytes. |
| 765 | * |
| 766 | * @return If the function succeeds, the return value is FSAL_OK. |
| 767 | * Otherwise, an error code is returned. |
| 768 | */ |
| 769 | FSAL_Status FSAL_Direct_Seek(STFSAL *pstFSAL, kal_uint32 uOffset); |
| 770 | |
| 771 | /** |
| 772 | * Get the current file position of the underlying file system directly. |
| 773 | * |
| 774 | * Use with caution. Becuase the file offset may be out-of-sync |
| 775 | * between FSAL and underlying file system. |
| 776 | * |
| 777 | * @param pstFSAL pointer to FSAL structure. |
| 778 | * @param puPosition memory location for retrieving the file position. |
| 779 | * |
| 780 | * @return If the function succeeds, the return value is FSAL_OK. |
| 781 | * Otherwise, an error code is returned. |
| 782 | */ |
| 783 | FSAL_Status FSAL_Direct_GetCurPos(STFSAL *pstFSAL, kal_uint32* puPosition); |
| 784 | |
| 785 | /** |
| 786 | * Get the file size of the underlying file system directly. |
| 787 | * The current file position remains the same after invocation. |
| 788 | * |
| 789 | * Use with caution. Becuase the file size may be out-of-sync |
| 790 | * between FSAL and underlying file system. |
| 791 | * |
| 792 | * @param pstFSAL pointer to FSAL structure. |
| 793 | * @param puFileSize memory location for retrieving the file size. |
| 794 | * |
| 795 | * @return If the function succeeds, the return value is FSAL_OK. |
| 796 | * Otherwise, an error code is returned. |
| 797 | */ |
| 798 | FSAL_Status FSAL_Direct_GetFileSize(STFSAL *pstFSAL, kal_uint32 *puFileSize); |
| 799 | |
| 800 | /** |
| 801 | * When using ram file, this funtion shall be called before calling FSAL_Open. |
| 802 | */ |
| 803 | void FSAL_Direct_SetRamFileSize(STFSAL *pstFSAL, kal_uint32 uSize); |
| 804 | |
| 805 | /** |
| 806 | * When writing to ram file, if after a write operation, the file offset exceeds |
| 807 | * the specified ram file size, an assertion will be issued in order to detect |
| 808 | * memory corruption. |
| 809 | */ |
| 810 | void FSAL_Direct_SetMaxRamFileSize(STFSAL *pstFSAL, kal_uint32 uSize); |
| 811 | |
| 812 | /** |
| 813 | * Get the last file system error. |
| 814 | */ |
| 815 | int FSAL_GetLastError(STFSAL *pstFSAL); |
| 816 | |
| 817 | /** |
| 818 | * If the pstFSAL is a handle of ram file, return KAL_TRUE; otherwise return KAL_FALSE. |
| 819 | */ |
| 820 | kal_bool FSAL_IsRamFile(STFSAL *pstFSAL); |
| 821 | |
| 822 | /** |
| 823 | * If the pstFSAL is a handle of ram file, return pointer to the memory block; otherwise return NULL. |
| 824 | */ |
| 825 | kal_uint8* FSAL_GetRamFilePointer(STFSAL *pstFSAL); |
| 826 | |
| 827 | /** |
| 828 | * Get the data count (in bytes) read in the previous read operation. |
| 829 | * Generally, call this function if the return value of the previous read operation if FSAL_READ_OVER_EOF. |
| 830 | */ |
| 831 | int FSAL_GetLastReadCount(STFSAL *pstFSAL); |
| 832 | |
| 833 | |
| 834 | FSAL_Status FSAL_SetByteOrder(STFSAL *pstFSAL, FSAL_ByteOrder byteOrder); |
| 835 | |
| 836 | kal_int32 FSAL_SetSeekHint(STFSAL *pstFSAL, kal_uint32 hint_num, void *hint); |
| 837 | |
| 838 | typedef struct |
| 839 | { |
| 840 | FS_HANDLE (* open_file) (kal_wchar *file_path, kal_uint32 flags, kal_uint8 permission); |
| 841 | kal_int32 (* close_file) (FS_HANDLE object); |
| 842 | kal_int32 (* read_file) (FS_HANDLE source, void *buffer, kal_uint32 size, kal_uint32 *length); |
| 843 | kal_int64 (* seek_file) (FS_HANDLE source, kal_int64 offset, kal_uint8 ref); |
| 844 | kal_int32 (* file_size) (FS_HANDLE source, kal_uint32 *size); |
| 845 | kal_int32 (* file_pos) (FS_HANDLE source, kal_uint32 *pos); |
| 846 | kal_int32 (* seek_hint) (FS_HANDLE source, kal_uint32 hint_num, void *hint); |
| 847 | }fsal_fsop_func_type; |
| 848 | |
| 849 | int FSAL_SetFSOperations(fsal_fsop_func_type *fs_operations); |
| 850 | |
| 851 | #ifdef __cplusplus |
| 852 | } |
| 853 | #endif /* __cplusplus */ |
| 854 | |
| 855 | #endif |
| 856 | |