1 #ifndef PERSISTENCE_CLIENT_LIBRARY_FILE_H
2 #define PERSISTENCE_CLIENT_LIBRARY_FILE_H
4 /******************************************************************************
7 * Company XS Embedded GmbH
8 *****************************************************************************/
9 /******************************************************************************
10 Permission is hereby granted, free of charge, to any person obtaining
11 a copy of this software and associated documentation files (the "Software"),
12 to deal in the Software without restriction, including without limitation
13 the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 and/or sell copies of the Software, and to permit persons to whom the
15 Software is furnished to do so, subject to the following conditions:
17 The above copyright notice and this permission notice shall be included
18 in all copies or substantial portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
24 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 ******************************************************************************/
29 * @file persistence_client_library_file.h
30 * @ingroup Persistence client library
31 * @author Ingo Huerner (XSe) / Guy Sagnes (Continental)
32 * @brief Header of the persistence client library.
33 * Library provides an API to access persistent data
36 /** \ingroup SSW_PERS */
37 /** \defgroup SSW_PERS_FILE Client: File access
40 /** \defgroup SSW_PERS_FILE_INTERFACE API document
48 #define PERSIST_FILEAPI_INTERFACE_VERSION (0x01000000U)
53 * @brief close the given POSIX file descriptor
55 * @param fd the file descriptor to close
57 * @return zero on success. On error a negative value will be returned with th follwoing error codes:
60 int file_close(int fd);
65 * @brief get the size of the file given by the file descriptor
67 * @param fd the POSIX file descriptor
69 * @return positive value. On error the negative value -1 will be returned
71 int file_get_size(int fd);
76 * @brief map a file into the memory
78 * @param addr if NULL, kernel chooses address
79 * @param size the size in bytes to map into the memory
80 * @param offset in the file to map
81 * @param fd the POSIX file descriptor of the file to map
83 * @return a pointer to the mapped area, or on error the value MAP_FAILED or
84 * EPERS_MAP_FAILEDLOCK if filesystem is currrently locked
86 void* file_map_data(void* addr, long size, long offset, int fd);
93 * @param ldbid logical database ID
94 * @param resource_id the resource ID
95 * @param user_no the user ID
96 * @param seat_no the seat number (seat 0 to 3)
98 * @return positive value: the POSIX file descriptor;
99 * On error a negative value will be returned with th follwoing error codes:
100 * EPERS_LOCKFS, EPERS_MAXHANDLE, EPERS_NOKEY, EPERS_NOKEYDATA, EPERS_NOPRCTABLE or EPERS_COMMON,
102 int file_open(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no);
107 * @brief read persistent data from a file
109 * @param fd POSIX file descriptor
110 * @param buffer buffer to read the data
111 * @param buffer_size the size buffer for reading
113 * @return positive value: the size read;
114 * On error a negative value will be returned with th follwoing error codes:
115 * EPERS_LOCKFS or EPERS_COMMON
117 int file_read_data(int fd, void * buffer, unsigned long buffer_size);
122 * @brief remove the file
124 * @param ldbid logical database ID
125 * @param resource_id the resource ID
126 * @param user_no the user ID
127 * @param seat_no the seat number (seat 0 to 3)
129 * @return positive value: success;
130 * On error a negative value will be returned with th follwoing error codes:
131 * EPERS_LOCKFS or EPERS_COMMON
133 int file_remove(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no);
138 * @brief reposition the file descriptor
140 * @param fd the POSIX file descriptor
141 * @param offset the reposition offset
142 * @param whence the direction to reposition
144 The offset is set to offset bytes.
146 The offset is set to its current location plus offset bytes.
148 The offset is set to the size of the file plus offset bytes.
150 * @return positive value: resulting offset location;
151 * On error a negative value will be returned with th follwoing error codes:
152 * EPERS_LOCKFS or EPERS_COMMON
154 int file_seek(int fd, long int offset, int whence);
159 * @brief unmap the file from the memory
161 * @param address the address to unmap
162 * @param size the size in bytes to unmap
164 * @return on success 0;
165 * On error a negative value will be returned with th follwoing error codes:
166 * EPERS_LOCKFS or EPERS_COMMON
168 int file_unmap_data(void* address, long size);
173 * @brief write persistent data to file
175 * @param fd the POSIX file descriptor
176 * @param buffer the buffer to write
177 * @param buffer_size the size of the buffer to write in bytes
179 * @return positive value: bytes written;
180 * On error a negative value will be returned with th follwoing error codes:
181 * EPERS_LOCKFS or EPERS_COMMON
183 int file_write_data(int fd, const void * buffer, unsigned long buffer_size);
196 /** \} */ /* End of API */
197 /** \} */ /* End of MODULE */
200 #endif /* PERSISTENCY_CLIENT_LIBRARY_FILE_H */