Home | History | Annotate | Download | only in hdr
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /*
     18  *  DESCRIPTION:
     19  *      The xpl_File.h header file contains constants and function prototypes
     20  *      for filesystem operations
     21  */
     22 
     23 #ifndef XPL_FILE_H
     24 #define XPL_FILE_H
     25 
     26 #include "xpl_Time.h"
     27 
     28 #ifdef __cplusplus
     29 extern "C" {
     30 #endif
     31 
     32 /************** CONSTANTS ****************************************************/
     33 
     34 #define XPL_FS_MAX_FILE_NAME_LENGTH  255
     35 #define XPL_FS_SIZE_INVALID (0)
     36 #define XPL_FS_HANDLE_INVALID (-1)
     37 #define XPL_FS_SHANDLE_INVALID (-1)
     38 
     39 /************** STRUCTURES, ENUMS, AND TYPEDEFS ******************************/
     40 
     41 typedef INT32 XPL_FS_HANDLE_T;
     42 typedef INT32  XPL_FS_SHANDLE_T;
     43 typedef INT32 XPL_FS_COUNT_T;
     44 typedef INT32 XPL_FS_SEEK_OFFSET_T;
     45 typedef UINT32 XPL_FS_SIZE_T;
     46 typedef char XPL_FS_SEARCH_FILE[XPL_FS_MAX_FILE_NAME_LENGTH];
     47 
     48 /* This are internal flags */
     49 enum
     50 {
     51      XPL_FS_RDONLY_MODE = 1,  /* open for reading only */
     52      XPL_FS_WRONLY_MODE = 2,  /* open for writing only */
     53      XPL_FS_TRUNC_MODE = 4,   /* length is truncated to 0 */
     54      XPL_FS_CREAT_MODE = 8,   /* create if file doesn't exist */
     55      XPL_FS_RDWR_MODE = 16,   /* open for reading and writing */
     56      XPL_FS_APPEND_MODE= 32   /* offeset is set to the end of the file
     57                                *   prior each write */
     58 };
     59 typedef UINT8 XPL_FS_OPEN_MODE_T;
     60 
     61 enum
     62 {
     63      XPL_FS_SEEK_SET =0,  /* set offset to offset */
     64      XPL_FS_SEEK_CUR,     /* set offset to current plus offset */
     65      XPL_FS_SEEK_END      /* set fileoffset to EOF plus offset */
     66  };
     67 typedef UINT8 XPL_FS_SEEK_MODE_T;
     68 
     69 enum
     70 {
     71      XPL_FS_RET_SUCCESS  = 0,     /* operation successfully completed */
     72      XPL_FS_RET_FAIL = 1,         /* operation failed */
     73      XPL_FS_RET_TRYAGAIN = 2,     /* try later */
     74      XPL_FS_RET_NOT_FOUND = 3,    /* not found */
     75      XPL_FS_RET_BADARGUMENT = 4,  /* bad argument */
     76      XPL_FS_RET_NOT_SUPPORTED = 5,/* not supported */
     77      XPL_FS_RET_PERM_FAIL = 6     /* permission failed */
     78 
     79 };
     80 typedef UINT8  XPL_FS_RET_STATUS_T;
     81 
     82 /************** CONSTANTS ****************************************************/
     83 
     84 /*Thise are public used flags passed to XPL_FS_OpenFile */
     85 #define XPL_FS_FILE_READ XPL_FS_RDONLY_MODE
     86 #define XPL_FS_FILE_WRITE (XPL_FS_WRONLY_MODE|XPL_FS_TRUNC_MODE|XPL_FS_CREAT_MODE)
     87 #define XPL_FS_FILE_RDWR  (XPL_FS_RDWR_MODE|XPL_FS_CREAT_MODE)
     88 #define XPL_FS_FILE_APPEND (XPL_FS_WRONLY_MODE|XPL_FS_APPEND_MODE|XPL_FS_CREAT_MODE)
     89 
     90 /*=================================================================================
     91                                      FUNCTION PROTOTYPES
     92 ==================================================================================*/
     93 /* Function returns an integer value, which is used to refer to the file.
     94  * If un- successful, it returns -1, and sets the result to
     95  * indicate the error type. */
     96 XPL_FS_HANDLE_T XPL_FS_Open(CPCHAR file_uri,
     97                                 const XPL_FS_OPEN_MODE_T open_mode,
     98                                 XPL_FS_RET_STATUS_T * result);
     99 
    100 
    101 /* Function closes the file associated with handle.
    102 * The function returns 0 if successful, or error code set appropriately. */
    103 XPL_FS_RET_STATUS_T XPL_FS_Close(XPL_FS_HANDLE_T file_handle);
    104 
    105 /* Function deletes file */
    106 XPL_FS_RET_STATUS_T XPL_FS_Remove(CPCHAR path);
    107 
    108 /* Attempts to change name of a file */
    109 XPL_FS_RET_STATUS_T XPL_FS_Rename(CPCHAR old_name, CPCHAR new_name);
    110 
    111 /* Returns TRUE if file with specified name exist */
    112 BOOLEAN XPL_FS_Exist(CPCHAR match_uri);
    113 
    114 /* Returns TRUE if file has permission */
    115 BOOLEAN XPL_FS_CheckPermission(CPCHAR match_uri, XPL_FS_OPEN_MODE_T permission);
    116 
    117 /* Returns file size */
    118 XPL_FS_SIZE_T XPL_FS_GetSize(XPL_FS_HANDLE_T file_handle);
    119 
    120 /* Returns time of last modifiction */
    121 XPL_CLK_CLOCK_T XPL_FS_GetModTime(CPCHAR file_uri);
    122 
    123 /*Function attempts to read count from the file associated with file_handle,
    124 * and places the characters read into buffer.
    125 * The function returns the number of bytes read. On end-of-file, 0 is returned, on error it returns -1
    126 * setting result to indicate the type of error that occurred */
    127 XPL_FS_COUNT_T XPL_FS_Read(XPL_FS_HANDLE_T file_handle,
    128                                void* buffer,
    129                                const XPL_FS_COUNT_T count,
    130                                XPL_FS_RET_STATUS_T * result);
    131 
    132 /* Function attempts to write count of byte from buffer to the file associated with handle.
    133 * The function returns the count of bytes written to the file.
    134 * A return value of -1 indicates an error, with result set appropriately. */
    135 XPL_FS_COUNT_T XPL_FS_Write(XPL_FS_HANDLE_T file_handle,
    136                                void* buffer,
    137                                const XPL_FS_COUNT_T count,
    138                                XPL_FS_RET_STATUS_T * result);
    139 
    140 /* Function shall set the file offset for the open file description associated with file_handle
    141 * Upon successful completion, the resulting offset, as measured in bytes from the beginning of
    142 * the file, shall be returned. Otherwise, -1 shall be returned, result shall be set to indicate the error. */
    143 XPL_FS_SEEK_OFFSET_T XPL_FS_Seek(XPL_FS_HANDLE_T file_handle,
    144                                 XPL_FS_SEEK_OFFSET_T offset,
    145                                 XPL_FS_SEEK_MODE_T whence,
    146                                 XPL_FS_RET_STATUS_T * result);
    147 
    148 
    149 /* Functionon search files in the directory and returns handler of search results */
    150 XPL_FS_SHANDLE_T XPL_FS_StartSearch(CPCHAR dir_uri,
    151                                     CPCHAR extension,
    152                                     BOOLEAN bFullName,
    153                                     XPL_FS_RET_STATUS_T * result);
    154 
    155 /* Returns result of search. */
    156 XPL_FS_RET_STATUS_T XPL_FS_GetSearchResult(XPL_FS_SHANDLE_T search_handle,
    157                                            XPL_FS_SEARCH_FILE file_name);
    158 
    159 /* Closes search */
    160 XPL_FS_RET_STATUS_T XPL_FS_EndSearch(XPL_FS_SHANDLE_T dir_handle);
    161 
    162 /* Attempts to create the directory. */
    163 XPL_FS_RET_STATUS_T XPL_FS_MkDir(CPCHAR dir_uri);
    164 
    165 /* locks the open file */
    166 XPL_FS_RET_STATUS_T XPL_FS_Lock(XPL_FS_HANDLE_T file_handle, BOOLEAN bLockExclusive );
    167 
    168 /* unlocks file */
    169 XPL_FS_RET_STATUS_T XPL_FS_Unlock(XPL_FS_HANDLE_T file_handle);
    170 
    171 /* unlinks file */
    172 XPL_FS_RET_STATUS_T XPL_FS_Unlink(CPCHAR name);
    173 
    174 
    175 /* establishes a mapping between a process address space and a file for read only operation. */
    176 UINT8 * XPL_FS_MemMap(XPL_FS_HANDLE_T file_handle, UINT32 size, UINT32 offset, XPL_FS_RET_STATUS_T * result);
    177 
    178 /* cancel mapping between a process address space and a file */
    179 XPL_FS_RET_STATUS_T XPL_FS_MemUnMap(UINT8 * pBuffer, UINT32 size);
    180 #ifdef LOB_SUPPORT
    181 /* Return the temporary ESN file directory */
    182 CPCHAR XPL_FS_TempEsnDir();
    183 /* Return free disk space */
    184 XPL_FS_SIZE_T XPL_FS_FreeDiskSpace(CPCHAR pEsnDir);
    185 #endif
    186 
    187 #ifdef __cplusplus
    188 }
    189 #endif
    190 
    191 #endif /* XPL_FILE_H */
    192