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
42 #define PERSIST_FILEAPI_INTERFACE_VERSION (0x01000000U)
47 * @brief close the given POSIX file descriptor
49 * @param fd the file descriptor to close
51 * @return zero on success. On error, -1 is returned, and errno is set appropriately
53 int file_close(int fd);
58 * @brief get the size of the file given by the file descriptor
60 * @param fd the POSIX file descriptor
62 * @return positive value. On error, -1 is returned, and errno is set appropriately
64 int file_get_size(int fd);
69 * @brief map a file into the memory
71 * @param addr if NULL, kernel chooses address
72 * @param size the size in bytes to map into the memory
73 * @param offset in the file to map
74 * @param fd the POSIX file descriptor of the file to map
76 * @return a pointer to the mapped area, or on error the value MAP_FAILED
78 void* file_map_data(void* addr, long size, long offset, int fd);
85 * @param ldbid logical database ID
86 * @param resource_id the resource ID
87 * @param user_no the user ID
88 * @param seat_no the seat number (seat 0 to 3)
90 * @return positive value: the POSIX file descriptor; negative value: Error code
92 int file_open(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no);
97 * @brief read persistent data from a file
99 * @param fd POSIX file descriptor
100 * @param buffer buffer to read the data
101 * @param buffer_size the size buffer for reading
103 * @return positive value: the size read; negative value: error code
105 int file_read_data(int fd, void * buffer, unsigned long buffer_size);
110 * @brief remove the file
112 * @param ldbid logical database ID
113 * @param resource_id the resource ID
114 * @param user_no the user ID
115 * @param seat_no the seat number (seat 0 to 3)
117 * @return positive value: success; negative value: error code
120 int file_remove(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no);
125 * @brief reposition the file descriptor
127 * @param fd the POSIX file descriptor
128 * @param offset the reposition offset
129 * @param whence the direction to reposition
131 The offset is set to offset bytes.
133 The offset is set to its current location plus offset bytes.
135 The offset is set to the size of the file plus offset bytes.
137 * @return positive value: resulting offset location; negative value: error code
139 int file_seek(int fd, long int offset, int whence);
144 * @brief unmap the file from the memory
146 * @param address the address to unmap
147 * @param size the size in bytes to unmap
149 * @return on success 0; negative value: error code
151 int file_unmap_data(void* address, long size);
156 * @brief write persistent data to file
158 * @param fd the POSIX file descriptor
159 * @param buffer the buffer to write
160 * @param buffer_size the size of the buffer to write in bytes
162 * @return positive value: bytes written; negative value: error code
164 int file_write_data(int fd, const void * buffer, unsigned long buffer_size);
177 #endif /* PERSISTENCY_CLIENT_LIBRARY_FILE_H */