New release 0.2.3, for changes see ChangeLog
[profile/ivi/persistence-client-library.git] / include / persistence_client_library_file.h
1 #ifndef PERSISTENCE_CLIENT_LIBRARY_FILE_H
2 #define PERSISTENCE_CLIENT_LIBRARY_FILE_H
3
4 /******************************************************************************
5  * Project         Persistency
6  * (c) copyright   2011
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:
16
17    The above copyright notice and this permission notice shall be included
18    in all copies or substantial portions of the Software.
19
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 ******************************************************************************/
28  /**
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
34  * @see            
35  */
36 /** \ingroup SSW_PERS */
37 /** \defgroup SSW_PERS_FILE Client: File access
38  *  \{
39  */
40 /** \defgroup SSW_PERS_FILE_INTERFACE API document
41  *  \{
42  */
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47
48 #define         PERSIST_FILEAPI_INTERFACE_VERSION   (0x01000000U)
49
50
51
52 /**
53  * @brief close the given POSIX file descriptor
54  *
55  * @param fd the file descriptor to close
56  *
57  * @return zero on success. On error a negative value will be returned with th follwoing error codes:
58  *                          EPERS_LOCKFS
59  */
60 int file_close(int fd);
61
62
63
64 /**
65  * @brief get the size of the file given by the file descriptor
66  *
67  * @param fd the POSIX file descriptor
68  *
69  * @return positive value. On error the negative value -1 will be returned
70  */
71 int file_get_size(int fd);
72
73
74
75 /**
76  * @brief map a file into the memory
77  *
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
82  *
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
85  */
86 void* file_map_data(void* addr, long size, long offset, int fd);
87
88
89
90 /**
91  * @brief open a file
92  *
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)
97  *
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,
101  */
102 int file_open(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no);
103
104
105
106 /**
107  * @brief read persistent data from a file
108  *
109  * @param fd POSIX file descriptor
110  * @param buffer buffer to read the data
111  * @param buffer_size the size buffer for reading
112  *
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
116  */
117 int file_read_data(int fd, void * buffer, unsigned long buffer_size);
118
119
120
121 /**
122  * @brief remove the file
123  *
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)
128  *
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
132  */
133 int file_remove(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no);
134
135
136
137 /**
138  * @brief reposition the file descriptor
139  *
140  * @param fd the POSIX file descriptor
141  * @param offset the reposition offset
142  * @param whence the direction to reposition
143                  SEEK_SET
144                       The offset is set to offset bytes.
145                  SEEK_CUR
146                       The offset is set to its current location plus offset bytes.
147                  SEEK_END
148                       The offset is set to the size of the file plus offset bytes.
149  *
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
153  */
154 int file_seek(int fd, long int offset, int whence);
155
156
157
158 /**
159  * @brief unmap the file from the memory
160  *
161  * @param address the address to unmap
162  * @param size the size in bytes to unmap
163  *
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
167  */
168 int file_unmap_data(void* address, long size);
169
170
171
172 /**
173  * @brief write persistent data to file
174  *
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
178  *
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
182  */
183 int file_write_data(int fd, const void * buffer, unsigned long buffer_size);
184
185
186
187
188
189
190
191 #ifdef __cplusplus
192 }
193 #endif
194
195
196 /** \} */ /* End of API */
197 /** \} */ /* End of MODULE */
198
199
200 #endif /* PERSISTENCY_CLIENT_LIBRARY_FILE_H */
201