[4d3017a] | 1 | /** |
---|
[9da9cf4a] | 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @ingroup LibIO |
---|
| 5 | * |
---|
| 6 | * @brief Basic IO API. |
---|
[4d3017a] | 7 | */ |
---|
| 8 | |
---|
[b06e68ef] | 9 | /* |
---|
[ad78965d] | 10 | * COPYRIGHT (c) 1989-2008. |
---|
[07a3253d] | 11 | * On-Line Applications Research Corporation (OAR). |
---|
| 12 | * |
---|
[3b7c123] | 13 | * Modifications to support reference counting in the file system are |
---|
| 14 | * Copyright (c) 2012 embedded brains GmbH. |
---|
| 15 | * |
---|
[07a3253d] | 16 | * The license and distribution terms for this file may be |
---|
| 17 | * found in the file LICENSE in this distribution or at |
---|
[0eae36c7] | 18 | * http://www.rtems.com/license/LICENSE. |
---|
[b06e68ef] | 19 | */ |
---|
| 20 | |
---|
[7945944] | 21 | #ifndef _RTEMS_RTEMS_LIBIO_H |
---|
| 22 | #define _RTEMS_RTEMS_LIBIO_H |
---|
[b06e68ef] | 23 | |
---|
[7a3878b] | 24 | #include <sys/types.h> |
---|
[dcec5a4] | 25 | #include <sys/stat.h> |
---|
[9b05600] | 26 | #include <sys/ioctl.h> |
---|
[eb649786] | 27 | #include <sys/statvfs.h> |
---|
[dcec5a4] | 28 | |
---|
[9da9cf4a] | 29 | #include <unistd.h> |
---|
| 30 | #include <termios.h> |
---|
[07a3253d] | 31 | |
---|
[9da9cf4a] | 32 | #include <rtems.h> |
---|
[d09ad1f0] | 33 | #include <rtems/fs.h> |
---|
[9da9cf4a] | 34 | #include <rtems/chain.h> |
---|
[07a3253d] | 35 | |
---|
[80c2966] | 36 | #ifdef __cplusplus |
---|
| 37 | extern "C" { |
---|
| 38 | #endif |
---|
| 39 | |
---|
[9da9cf4a] | 40 | /** |
---|
[3b7c123] | 41 | * @defgroup LibIOFSOps File System Operations |
---|
[9da9cf4a] | 42 | * |
---|
[3b7c123] | 43 | * @ingroup LibIO |
---|
[9da9cf4a] | 44 | * |
---|
[3b7c123] | 45 | * @brief File system operations. |
---|
[9da9cf4a] | 46 | * |
---|
| 47 | * @{ |
---|
| 48 | */ |
---|
| 49 | |
---|
| 50 | /** |
---|
[1e01385] | 51 | * @brief File system node types. |
---|
[07a3253d] | 52 | */ |
---|
[1e01385] | 53 | typedef enum { |
---|
| 54 | RTEMS_FILESYSTEM_DIRECTORY, |
---|
| 55 | RTEMS_FILESYSTEM_DEVICE, |
---|
| 56 | RTEMS_FILESYSTEM_HARD_LINK, |
---|
| 57 | RTEMS_FILESYSTEM_SYM_LINK, |
---|
[bea7043c] | 58 | RTEMS_FILESYSTEM_MEMORY_FILE, |
---|
| 59 | RTEMS_FILESYSTEM_INVALID_NODE_TYPE |
---|
[1e01385] | 60 | } rtems_filesystem_node_types_t; |
---|
[07a3253d] | 61 | |
---|
[9da9cf4a] | 62 | /** |
---|
[3b7c123] | 63 | * @brief Locks a file system instance. |
---|
[9da9cf4a] | 64 | * |
---|
[3b7c123] | 65 | * This lock must allow nesting. |
---|
| 66 | * |
---|
| 67 | * @param[in, out] mt_entry The mount table entry of the file system instance. |
---|
| 68 | * |
---|
| 69 | * @see rtems_filesystem_default_lock(). |
---|
[07a3253d] | 70 | */ |
---|
[3b7c123] | 71 | typedef void (*rtems_filesystem_mt_entry_lock_t)( |
---|
[7666afc] | 72 | const rtems_filesystem_mount_table_entry_t *mt_entry |
---|
[3b7c123] | 73 | ); |
---|
[9da9cf4a] | 74 | |
---|
[f9a4e80] | 75 | /** |
---|
[3b7c123] | 76 | * @brief Unlocks a file system instance. |
---|
| 77 | * |
---|
| 78 | * @param[in, out] mt_entry The mount table entry of the file system instance. |
---|
| 79 | * |
---|
| 80 | * @see rtems_filesystem_default_unlock(). |
---|
[f9a4e80] | 81 | */ |
---|
[3b7c123] | 82 | typedef void (*rtems_filesystem_mt_entry_unlock_t)( |
---|
[7666afc] | 83 | const rtems_filesystem_mount_table_entry_t *mt_entry |
---|
[07a3253d] | 84 | ); |
---|
| 85 | |
---|
[f9a4e80] | 86 | /** |
---|
[3b7c123] | 87 | * @brief Path evaluation context. |
---|
[f9a4e80] | 88 | */ |
---|
[3b7c123] | 89 | typedef struct { |
---|
| 90 | /** |
---|
| 91 | * The contents of the remaining path to be evaluated. |
---|
| 92 | */ |
---|
| 93 | const char *path; |
---|
| 94 | |
---|
| 95 | /** |
---|
| 96 | * The length of the remaining path to be evaluated. |
---|
| 97 | */ |
---|
| 98 | size_t pathlen; |
---|
| 99 | |
---|
| 100 | /** |
---|
| 101 | * The contents of the token to be evaluated with respect to the current |
---|
| 102 | * location. |
---|
| 103 | */ |
---|
| 104 | const char *token; |
---|
| 105 | |
---|
| 106 | /** |
---|
| 107 | * The length of the token to be evaluated with respect to the current |
---|
| 108 | * location. |
---|
| 109 | */ |
---|
| 110 | size_t tokenlen; |
---|
| 111 | |
---|
| 112 | /** |
---|
| 113 | * The path evaluation is controlled by the following flags |
---|
[2563410] | 114 | * - RTEMS_FS_PERMS_READ, |
---|
| 115 | * - RTEMS_FS_PERMS_WRITE, |
---|
| 116 | * - RTEMS_FS_PERMS_EXEC, |
---|
| 117 | * - RTEMS_FS_FOLLOW_HARD_LINK, |
---|
| 118 | * - RTEMS_FS_FOLLOW_SYM_LINK, |
---|
| 119 | * - RTEMS_FS_MAKE, |
---|
| 120 | * - RTEMS_FS_EXCLUSIVE, |
---|
| 121 | * - RTEMS_FS_ACCEPT_RESIDUAL_DELIMITERS, and |
---|
| 122 | * - RTEMS_FS_REJECT_TERMINAL_DOT. |
---|
[3b7c123] | 123 | */ |
---|
| 124 | int flags; |
---|
| 125 | |
---|
| 126 | /** |
---|
| 127 | * Symbolic link evaluation is a recursive operation. This field helps to |
---|
| 128 | * limit the recursion level and thus prevents a stack overflow. The |
---|
| 129 | * recursion level is limited by RTEMS_FILESYSTEM_SYMLOOP_MAX. |
---|
| 130 | */ |
---|
| 131 | int recursionlevel; |
---|
| 132 | |
---|
| 133 | /** |
---|
| 134 | * This is the current file system location of the evaluation process. |
---|
| 135 | * Tokens are evaluated with respect to the current location. The token |
---|
| 136 | * interpretation may change the current location. The purpose of the path |
---|
| 137 | * evaluation is to change the start location into a final current location |
---|
| 138 | * according to the path. |
---|
| 139 | */ |
---|
| 140 | rtems_filesystem_location_info_t currentloc; |
---|
| 141 | |
---|
| 142 | /** |
---|
| 143 | * The location of the root directory of the user environment during the |
---|
| 144 | * evaluation start. |
---|
| 145 | */ |
---|
| 146 | rtems_filesystem_global_location_t *rootloc; |
---|
| 147 | |
---|
| 148 | /** |
---|
| 149 | * The start location of the evaluation process. The start location my |
---|
| 150 | * change during symbolic link evaluation. |
---|
| 151 | */ |
---|
| 152 | rtems_filesystem_global_location_t *startloc; |
---|
| 153 | } rtems_filesystem_eval_path_context_t; |
---|
[07a3253d] | 154 | |
---|
[f9a4e80] | 155 | /** |
---|
[3b7c123] | 156 | * @brief Path evaluation. |
---|
| 157 | * |
---|
| 158 | * @param[in, out] ctx The path evaluation context. |
---|
| 159 | * |
---|
| 160 | * @see rtems_filesystem_default_eval_path(). |
---|
[f9a4e80] | 161 | */ |
---|
[3b7c123] | 162 | typedef void (*rtems_filesystem_eval_path_t)( |
---|
| 163 | rtems_filesystem_eval_path_context_t *ctx |
---|
[07a3253d] | 164 | ); |
---|
| 165 | |
---|
[f9a4e80] | 166 | /** |
---|
[3b7c123] | 167 | * @brief Creates a new link for the existing file. |
---|
| 168 | * |
---|
| 169 | * @param[in] parentloc The location of the parent of the new link. |
---|
| 170 | * @param[in] targetloc The location of the target file. |
---|
| 171 | * @param[in] name Name for the new link. |
---|
| 172 | * @param[in] namelen Length of the name for the new link in characters. |
---|
| 173 | * |
---|
| 174 | * @retval 0 Successful operation. |
---|
| 175 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 176 | * |
---|
| 177 | * @see rtems_filesystem_default_link(). |
---|
[f9a4e80] | 178 | */ |
---|
[3b7c123] | 179 | typedef int (*rtems_filesystem_link_t)( |
---|
| 180 | const rtems_filesystem_location_info_t *parentloc, |
---|
| 181 | const rtems_filesystem_location_info_t *targetloc, |
---|
| 182 | const char *name, |
---|
| 183 | size_t namelen |
---|
[07a3253d] | 184 | ); |
---|
| 185 | |
---|
[f9a4e80] | 186 | /** |
---|
[3b7c123] | 187 | * @brief Changes the mode of a node. |
---|
| 188 | * |
---|
| 189 | * @param[in] loc The location of the node. |
---|
| 190 | * @param[in] mode The new mode of the node |
---|
| 191 | * |
---|
| 192 | * @retval 0 Successful operation. |
---|
| 193 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 194 | * |
---|
| 195 | * @see rtems_filesystem_default_fchmod(). |
---|
[f9a4e80] | 196 | */ |
---|
[3b7c123] | 197 | typedef int (*rtems_filesystem_fchmod_t)( |
---|
| 198 | const rtems_filesystem_location_info_t *loc, |
---|
| 199 | mode_t mode |
---|
[07a3253d] | 200 | ); |
---|
| 201 | |
---|
[f9a4e80] | 202 | /** |
---|
[3b7c123] | 203 | * @brief Changes owner and group of a node. |
---|
| 204 | * |
---|
| 205 | * @param[in] loc The location of the node. |
---|
| 206 | * @param[in] owner User ID for the node. |
---|
| 207 | * @param[in] group Group ID for the node. |
---|
| 208 | * |
---|
| 209 | * @retval 0 Successful operation. |
---|
| 210 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 211 | * |
---|
| 212 | * @see rtems_filesystem_default_chown(). |
---|
[f9a4e80] | 213 | */ |
---|
[3b7c123] | 214 | typedef int (*rtems_filesystem_chown_t)( |
---|
| 215 | const rtems_filesystem_location_info_t *loc, |
---|
| 216 | uid_t owner, |
---|
| 217 | gid_t group |
---|
[07a3253d] | 218 | ); |
---|
| 219 | |
---|
[f9a4e80] | 220 | /** |
---|
[3b7c123] | 221 | * @brief Clones a location. |
---|
| 222 | * |
---|
| 223 | * The location is initialized with a bitwise copy of an existing location. |
---|
| 224 | * The caller must ensure that this location is protected from a release during |
---|
| 225 | * the clone operation. After a successful clone operation the clone will be |
---|
| 226 | * added to the location chain of the corresponding mount table entry. |
---|
| 227 | * |
---|
| 228 | * @param[in, out] loc Location to clone. |
---|
| 229 | * |
---|
| 230 | * @retval 0 Successful operation. |
---|
| 231 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 232 | * |
---|
| 233 | * @see rtems_filesystem_default_clonenode(). |
---|
[f9a4e80] | 234 | */ |
---|
[3b7c123] | 235 | typedef int (*rtems_filesystem_clonenode_t)( |
---|
| 236 | rtems_filesystem_location_info_t *loc |
---|
[07a3253d] | 237 | ); |
---|
| 238 | |
---|
[f9a4e80] | 239 | /** |
---|
[3b7c123] | 240 | * @brief Frees the location of a node. |
---|
| 241 | * |
---|
| 242 | * @param[in] loc The location of the node. |
---|
| 243 | * |
---|
| 244 | * @see rtems_filesystem_default_freenode(). |
---|
[f9a4e80] | 245 | */ |
---|
[3b7c123] | 246 | typedef void (*rtems_filesystem_freenode_t)( |
---|
| 247 | const rtems_filesystem_location_info_t *loc |
---|
[07a3253d] | 248 | ); |
---|
| 249 | |
---|
[f9a4e80] | 250 | /** |
---|
[3b7c123] | 251 | * @brief Mounts a file system instance in a mount point (directory). |
---|
| 252 | * |
---|
| 253 | * The mount point belongs to the file system instance of the handler and is |
---|
| 254 | * specified by a field of the mount table entry. The handler must check that |
---|
| 255 | * the mount point is capable of mounting a file system instance. This is the |
---|
| 256 | * last step during the mount process. The file system instance is fully |
---|
| 257 | * initialized at this point. |
---|
| 258 | * |
---|
| 259 | * @param[in] mt_entry The mount table entry. |
---|
| 260 | * |
---|
| 261 | * @retval 0 Successful operation. |
---|
| 262 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 263 | * |
---|
| 264 | * @see rtems_filesystem_default_mount(). |
---|
[f9a4e80] | 265 | */ |
---|
[3b7c123] | 266 | typedef int (*rtems_filesystem_mount_t) ( |
---|
| 267 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
[07a3253d] | 268 | ); |
---|
| 269 | |
---|
[f9a4e80] | 270 | /** |
---|
[3b7c123] | 271 | * @brief Initializes a file system instance. |
---|
| 272 | * |
---|
| 273 | * This function must initialize the file system root node in the mount table |
---|
| 274 | * entry. |
---|
| 275 | * |
---|
| 276 | * @param[in] mt_entry The mount table entry. |
---|
| 277 | * @param[in] data The data provided by the user. |
---|
| 278 | * |
---|
| 279 | * @retval 0 Successful operation. |
---|
| 280 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
[f9a4e80] | 281 | */ |
---|
[3b7c123] | 282 | typedef int (*rtems_filesystem_fsmount_me_t)( |
---|
| 283 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
| 284 | const void *data |
---|
[07a3253d] | 285 | ); |
---|
| 286 | |
---|
[f9a4e80] | 287 | /** |
---|
[3b7c123] | 288 | * @brief Unmounts a file system instance in a mount point (directory). |
---|
| 289 | * |
---|
| 290 | * In case this function is successful the file system instance will be marked |
---|
| 291 | * as unmounted. The file system instance will be destroyed when the last |
---|
| 292 | * reference to it vanishes. |
---|
| 293 | * |
---|
| 294 | * @param[in] mt_entry The mount table entry. |
---|
| 295 | * |
---|
| 296 | * @retval 0 Successful operation. |
---|
| 297 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 298 | * |
---|
| 299 | * @see rtems_filesystem_default_unmount(). |
---|
[f9a4e80] | 300 | */ |
---|
[3b7c123] | 301 | typedef int (*rtems_filesystem_unmount_t) ( |
---|
| 302 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
[07a3253d] | 303 | ); |
---|
| 304 | |
---|
[f9a4e80] | 305 | /** |
---|
[3b7c123] | 306 | * @brief Destroys a file system instance. |
---|
| 307 | * |
---|
| 308 | * The mount point node location of the mount table entry is invalid. This |
---|
| 309 | * handler must free the file system root location and all remaining resources |
---|
| 310 | * of the file system instance. |
---|
| 311 | * |
---|
| 312 | * @param[in] mt_entry The mount table entry. |
---|
| 313 | * |
---|
| 314 | * @see rtems_filesystem_default_fsunmount(). |
---|
[f9a4e80] | 315 | */ |
---|
[3b7c123] | 316 | typedef void (*rtems_filesystem_fsunmount_me_t)( |
---|
| 317 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
[af020036] | 318 | ); |
---|
| 319 | |
---|
[3b7c123] | 320 | /** |
---|
| 321 | * @brief Tests if the node of one location is equal to the node of the other |
---|
| 322 | * location. |
---|
| 323 | * |
---|
| 324 | * The caller ensures that both nodes are within the same file system instance. |
---|
| 325 | * |
---|
| 326 | * @param[in] a The one location. |
---|
| 327 | * @param[in] b The other location. |
---|
| 328 | * |
---|
| 329 | * @retval true The nodes of the locations are equal. |
---|
| 330 | * @retval false Otherwise. |
---|
| 331 | * |
---|
| 332 | * @see rtems_filesystem_default_are_nodes_equal(). |
---|
| 333 | */ |
---|
| 334 | typedef bool (*rtems_filesystem_are_nodes_equal_t)( |
---|
| 335 | const rtems_filesystem_location_info_t *a, |
---|
| 336 | const rtems_filesystem_location_info_t *b |
---|
[4a07d2b] | 337 | ); |
---|
| 338 | |
---|
[9da9cf4a] | 339 | /** |
---|
[3b7c123] | 340 | * @brief Returns the node type. |
---|
| 341 | * |
---|
| 342 | * @param[in] loc The location of the node. |
---|
| 343 | * |
---|
| 344 | * @return Type of the node. |
---|
| 345 | * |
---|
| 346 | * @see rtems_filesystem_default_node_type(). |
---|
[9da9cf4a] | 347 | */ |
---|
[3b7c123] | 348 | typedef rtems_filesystem_node_types_t (*rtems_filesystem_node_type_t)( |
---|
| 349 | const rtems_filesystem_location_info_t *loc |
---|
| 350 | ); |
---|
[f9a4e80] | 351 | |
---|
[3b7c123] | 352 | /** |
---|
| 353 | * @brief Creates a new node. |
---|
| 354 | * |
---|
| 355 | * This handler should create a new node according to the parameters. |
---|
| 356 | * |
---|
| 357 | * @param[in] parentloc The location of the parent of the new node. |
---|
| 358 | * @param[in] name Name for the new node. |
---|
| 359 | * @param[in] namelen Length of the name for the new node in characters. |
---|
| 360 | * @param[in] mode Mode for the new node. |
---|
| 361 | * @param[in] dev Optional device identifier for the new node. |
---|
| 362 | * |
---|
| 363 | * @retval 0 Successful operation. |
---|
| 364 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 365 | * |
---|
| 366 | * @see rtems_filesystem_default_mknod(). |
---|
| 367 | */ |
---|
| 368 | typedef int (*rtems_filesystem_mknod_t)( |
---|
| 369 | const rtems_filesystem_location_info_t *parentloc, |
---|
| 370 | const char *name, |
---|
| 371 | size_t namelen, |
---|
| 372 | mode_t mode, |
---|
| 373 | dev_t dev |
---|
| 374 | ); |
---|
[f9a4e80] | 375 | |
---|
[3b7c123] | 376 | /** |
---|
| 377 | * @brief Removes a node. |
---|
| 378 | * |
---|
| 379 | * @param[in] parentloc The location of the parent of the node. |
---|
| 380 | * @param[in] loc The location of the node. |
---|
| 381 | * |
---|
| 382 | * @retval 0 Successful operation. |
---|
| 383 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 384 | * |
---|
| 385 | * @see rtems_filesystem_default_rmnod(). |
---|
| 386 | */ |
---|
| 387 | typedef int (*rtems_filesystem_rmnod_t)( |
---|
| 388 | const rtems_filesystem_location_info_t *parentloc, |
---|
| 389 | const rtems_filesystem_location_info_t *loc |
---|
| 390 | ); |
---|
[f9a4e80] | 391 | |
---|
[3b7c123] | 392 | /** |
---|
| 393 | * @brief Set node access and modification times. |
---|
| 394 | * |
---|
| 395 | * @param[in] loc The location of the node. |
---|
| 396 | * @param[in] actime Access time for the node. |
---|
| 397 | * @param[in] modtime Modification for the node. |
---|
| 398 | * |
---|
| 399 | * @retval 0 Successful operation. |
---|
| 400 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 401 | * |
---|
| 402 | * @see rtems_filesystem_default_utime(). |
---|
| 403 | */ |
---|
| 404 | typedef int (*rtems_filesystem_utime_t)( |
---|
| 405 | const rtems_filesystem_location_info_t *loc, |
---|
| 406 | time_t actime, |
---|
| 407 | time_t modtime |
---|
| 408 | ); |
---|
[f9a4e80] | 409 | |
---|
[3b7c123] | 410 | /** |
---|
| 411 | * @brief Makes a symbolic link to a node. |
---|
| 412 | * |
---|
| 413 | * @param[in] parentloc The location of the parent of the new symbolic link. |
---|
| 414 | * @param[in] name Name for the new symbolic link. |
---|
| 415 | * @param[in] namelen Length of the name for the new symbolic link in |
---|
| 416 | * characters. |
---|
| 417 | * @param[in] target Contents for the symbolic link. |
---|
| 418 | * |
---|
| 419 | * @retval 0 Successful operation. |
---|
| 420 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 421 | * |
---|
| 422 | * @see rtems_filesystem_default_symlink(). |
---|
| 423 | */ |
---|
| 424 | typedef int (*rtems_filesystem_symlink_t)( |
---|
| 425 | const rtems_filesystem_location_info_t *parentloc, |
---|
| 426 | const char *name, |
---|
| 427 | size_t namelen, |
---|
| 428 | const char *target |
---|
| 429 | ); |
---|
[1e01385] | 430 | |
---|
[3b7c123] | 431 | /** |
---|
| 432 | * @brief Reads the contents of a symbolic link. |
---|
| 433 | * |
---|
| 434 | * @param[in] loc The location of the symbolic link. |
---|
| 435 | * @param[out] buf The buffer for the contents. |
---|
| 436 | * @param[in] bufsize The size of the buffer in characters. |
---|
| 437 | * |
---|
| 438 | * @retval non-negative Size of the actual contents in characters. |
---|
| 439 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 440 | * |
---|
| 441 | * @see rtems_filesystem_default_readlink(). |
---|
| 442 | */ |
---|
| 443 | typedef ssize_t (*rtems_filesystem_readlink_t)( |
---|
| 444 | const rtems_filesystem_location_info_t *loc, |
---|
| 445 | char *buf, |
---|
| 446 | size_t bufsize |
---|
| 447 | ); |
---|
[1e01385] | 448 | |
---|
[dace9ed1] | 449 | /** |
---|
[3b7c123] | 450 | * @brief Renames a node. |
---|
| 451 | * |
---|
| 452 | * @param[in] oldparentloc The location of the parent of the old node. |
---|
| 453 | * @param[in] oldloc The location of the old node. |
---|
| 454 | * @param[in] newparentloc The location of the parent of the new node. |
---|
| 455 | * @param[in] name Name for the new node. |
---|
| 456 | * @param[in] namelen Length of the name for the new node in characters. |
---|
| 457 | * |
---|
| 458 | * @retval 0 Successful operation. |
---|
| 459 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 460 | * |
---|
| 461 | * @see rtems_filesystem_default_rename(). |
---|
[dace9ed1] | 462 | */ |
---|
[3b7c123] | 463 | typedef int (*rtems_filesystem_rename_t)( |
---|
| 464 | const rtems_filesystem_location_info_t *oldparentloc, |
---|
| 465 | const rtems_filesystem_location_info_t *oldloc, |
---|
| 466 | const rtems_filesystem_location_info_t *newparentloc, |
---|
| 467 | const char *name, |
---|
| 468 | size_t namelen |
---|
[dace9ed1] | 469 | ); |
---|
| 470 | |
---|
| 471 | /** |
---|
[3b7c123] | 472 | * @brief Gets file system information. |
---|
| 473 | * |
---|
| 474 | * @param[in] loc The location of a node. |
---|
| 475 | * @param[out] buf Buffer for file system information. |
---|
| 476 | * |
---|
| 477 | * @retval 0 Successful operation. |
---|
| 478 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 479 | * |
---|
| 480 | * @see rtems_filesystem_default_statvfs(). |
---|
[dace9ed1] | 481 | */ |
---|
[3b7c123] | 482 | typedef int (*rtems_filesystem_statvfs_t)( |
---|
| 483 | const rtems_filesystem_location_info_t *loc, |
---|
| 484 | struct statvfs *buf |
---|
[dace9ed1] | 485 | ); |
---|
| 486 | |
---|
[3b7c123] | 487 | /** |
---|
| 488 | * @brief File system operations table. |
---|
| 489 | */ |
---|
| 490 | struct _rtems_filesystem_operations_table { |
---|
| 491 | rtems_filesystem_mt_entry_lock_t lock_h; |
---|
| 492 | rtems_filesystem_mt_entry_unlock_t unlock_h; |
---|
| 493 | rtems_filesystem_eval_path_t eval_path_h; |
---|
| 494 | rtems_filesystem_link_t link_h; |
---|
| 495 | rtems_filesystem_are_nodes_equal_t are_nodes_equal_h; |
---|
| 496 | rtems_filesystem_node_type_t node_type_h; |
---|
| 497 | rtems_filesystem_mknod_t mknod_h; |
---|
| 498 | rtems_filesystem_rmnod_t rmnod_h; |
---|
| 499 | rtems_filesystem_fchmod_t fchmod_h; |
---|
| 500 | rtems_filesystem_chown_t chown_h; |
---|
| 501 | rtems_filesystem_clonenode_t clonenod_h; |
---|
| 502 | rtems_filesystem_freenode_t freenod_h; |
---|
| 503 | rtems_filesystem_mount_t mount_h; |
---|
| 504 | rtems_filesystem_fsmount_me_t fsmount_me_h; |
---|
| 505 | rtems_filesystem_unmount_t unmount_h; |
---|
| 506 | rtems_filesystem_fsunmount_me_t fsunmount_me_h; |
---|
| 507 | rtems_filesystem_utime_t utime_h; |
---|
| 508 | rtems_filesystem_symlink_t symlink_h; |
---|
| 509 | rtems_filesystem_readlink_t readlink_h; |
---|
| 510 | rtems_filesystem_rename_t rename_h; |
---|
| 511 | rtems_filesystem_statvfs_t statvfs_h; |
---|
| 512 | }; |
---|
[07a3253d] | 513 | |
---|
[f9a4e80] | 514 | /** |
---|
[3b7c123] | 515 | * @brief File system operations table with default operations. |
---|
[f9a4e80] | 516 | */ |
---|
[3b7c123] | 517 | extern const rtems_filesystem_operations_table |
---|
| 518 | rtems_filesystem_operations_default; |
---|
[f9a4e80] | 519 | |
---|
| 520 | /** |
---|
[3b7c123] | 521 | * @brief Obtains the IO library mutex. |
---|
| 522 | * |
---|
| 523 | * @see rtems_filesystem_mt_entry_lock_t. |
---|
[f9a4e80] | 524 | */ |
---|
[3b7c123] | 525 | void rtems_filesystem_default_lock( |
---|
[7666afc] | 526 | const rtems_filesystem_mount_table_entry_t *mt_entry |
---|
[f9a4e80] | 527 | ); |
---|
| 528 | |
---|
| 529 | /** |
---|
[3b7c123] | 530 | * @brief Releases the IO library mutex. |
---|
| 531 | * |
---|
| 532 | * @see rtems_filesystem_mt_entry_unlock_t. |
---|
[f9a4e80] | 533 | */ |
---|
[3b7c123] | 534 | void rtems_filesystem_default_unlock( |
---|
[7666afc] | 535 | const rtems_filesystem_mount_table_entry_t *mt_entry |
---|
[f9a4e80] | 536 | ); |
---|
| 537 | |
---|
| 538 | /** |
---|
[3b7c123] | 539 | * @brief Terminates the path evaluation and replaces the current location with |
---|
| 540 | * the null location. |
---|
| 541 | * |
---|
| 542 | * @see rtems_filesystem_eval_path_t. |
---|
[f9a4e80] | 543 | */ |
---|
[3b7c123] | 544 | void rtems_filesystem_default_eval_path( |
---|
| 545 | rtems_filesystem_eval_path_context_t *ctx |
---|
[f9a4e80] | 546 | ); |
---|
| 547 | |
---|
| 548 | /** |
---|
[3b7c123] | 549 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 550 | * |
---|
| 551 | * @see rtems_filesystem_link_t. |
---|
[f9a4e80] | 552 | */ |
---|
[3b7c123] | 553 | int rtems_filesystem_default_link( |
---|
| 554 | const rtems_filesystem_location_info_t *parentloc, |
---|
| 555 | const rtems_filesystem_location_info_t *targetloc, |
---|
| 556 | const char *name, |
---|
| 557 | size_t namelen |
---|
[f9a4e80] | 558 | ); |
---|
| 559 | |
---|
| 560 | /** |
---|
[3b7c123] | 561 | * @brief Tests if the node access pointer of one location is equal to |
---|
| 562 | * the node access pointer of the other location. |
---|
| 563 | * |
---|
| 564 | * @param[in] a The one location. |
---|
| 565 | * @param[in] b The other location. |
---|
| 566 | * |
---|
| 567 | * @retval true The node access pointers of the locations are equal. |
---|
| 568 | * @retval false Otherwise. |
---|
| 569 | * |
---|
| 570 | * @see rtems_filesystem_are_nodes_equal_t. |
---|
[f9a4e80] | 571 | */ |
---|
[3b7c123] | 572 | bool rtems_filesystem_default_are_nodes_equal( |
---|
| 573 | const rtems_filesystem_location_info_t *a, |
---|
| 574 | const rtems_filesystem_location_info_t *b |
---|
[f9a4e80] | 575 | ); |
---|
| 576 | |
---|
| 577 | /** |
---|
[3b7c123] | 578 | * @retval RTEMS_FILESYSTEM_INVALID_NODE_TYPE Always. |
---|
| 579 | * |
---|
| 580 | * @see rtems_filesystem_node_type_t. |
---|
[f9a4e80] | 581 | */ |
---|
[3b7c123] | 582 | rtems_filesystem_node_types_t rtems_filesystem_default_node_type( |
---|
| 583 | const rtems_filesystem_location_info_t *pathloc |
---|
[f9a4e80] | 584 | ); |
---|
| 585 | |
---|
| 586 | /** |
---|
[3b7c123] | 587 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 588 | * |
---|
| 589 | * @see rtems_filesystem_mknod_t. |
---|
[f9a4e80] | 590 | */ |
---|
[3b7c123] | 591 | int rtems_filesystem_default_mknod( |
---|
| 592 | const rtems_filesystem_location_info_t *parentloc, |
---|
| 593 | const char *name, |
---|
| 594 | size_t namelen, |
---|
| 595 | mode_t mode, |
---|
| 596 | dev_t dev |
---|
[f9a4e80] | 597 | ); |
---|
| 598 | |
---|
| 599 | /** |
---|
[3b7c123] | 600 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 601 | * |
---|
| 602 | * @see rtems_filesystem_rmnod_t. |
---|
[f9a4e80] | 603 | */ |
---|
[3b7c123] | 604 | int rtems_filesystem_default_rmnod( |
---|
| 605 | const rtems_filesystem_location_info_t *parentloc, |
---|
| 606 | const rtems_filesystem_location_info_t *loc |
---|
[f9a4e80] | 607 | ); |
---|
| 608 | |
---|
| 609 | /** |
---|
[3b7c123] | 610 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 611 | * |
---|
| 612 | * @see rtems_filesystem_fchmod_t. |
---|
[f9a4e80] | 613 | */ |
---|
[3b7c123] | 614 | int rtems_filesystem_default_fchmod( |
---|
| 615 | const rtems_filesystem_location_info_t *loc, |
---|
| 616 | mode_t mode |
---|
[f9a4e80] | 617 | ); |
---|
| 618 | |
---|
| 619 | /** |
---|
[3b7c123] | 620 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 621 | * |
---|
| 622 | * @see rtems_filesystem_chown_t. |
---|
[f9a4e80] | 623 | */ |
---|
[3b7c123] | 624 | int rtems_filesystem_default_chown( |
---|
| 625 | const rtems_filesystem_location_info_t *loc, |
---|
| 626 | uid_t owner, |
---|
| 627 | gid_t group |
---|
[f9a4e80] | 628 | ); |
---|
| 629 | |
---|
[9da9cf4a] | 630 | /** |
---|
[3b7c123] | 631 | * @retval 0 Always. |
---|
[9da9cf4a] | 632 | * |
---|
[3b7c123] | 633 | * @see rtems_filesystem_clonenode_t. |
---|
[07a3253d] | 634 | */ |
---|
[3b7c123] | 635 | int rtems_filesystem_default_clonenode( |
---|
| 636 | rtems_filesystem_location_info_t *loc |
---|
| 637 | ); |
---|
[07a3253d] | 638 | |
---|
[f9a4e80] | 639 | /** |
---|
[3b7c123] | 640 | * @see rtems_filesystem_freenode_t. |
---|
[07a3253d] | 641 | */ |
---|
[3b7c123] | 642 | void rtems_filesystem_default_freenode( |
---|
| 643 | const rtems_filesystem_location_info_t *loc |
---|
[07a3253d] | 644 | ); |
---|
| 645 | |
---|
[f9a4e80] | 646 | /** |
---|
[3b7c123] | 647 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
[f9a4e80] | 648 | * |
---|
[3b7c123] | 649 | * @see rtems_filesystem_mount_t. |
---|
[07a3253d] | 650 | */ |
---|
[3b7c123] | 651 | int rtems_filesystem_default_mount ( |
---|
| 652 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
[07a3253d] | 653 | ); |
---|
| 654 | |
---|
[f9a4e80] | 655 | /** |
---|
[3b7c123] | 656 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
[f9a4e80] | 657 | * |
---|
[3b7c123] | 658 | * @see rtems_filesystem_fsmount_me_t. |
---|
[f9a4e80] | 659 | */ |
---|
[3b7c123] | 660 | int rtems_filesystem_default_fsmount( |
---|
| 661 | rtems_filesystem_mount_table_entry_t *mt_entry, /* IN */ |
---|
| 662 | const void *data /* IN */ |
---|
[07a3253d] | 663 | ); |
---|
| 664 | |
---|
[f9a4e80] | 665 | /** |
---|
[3b7c123] | 666 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 667 | * |
---|
| 668 | * @see rtems_filesystem_unmount_t. |
---|
| 669 | */ |
---|
| 670 | int rtems_filesystem_default_unmount( |
---|
| 671 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
[07a3253d] | 672 | ); |
---|
| 673 | |
---|
[f9a4e80] | 674 | /** |
---|
[3b7c123] | 675 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 676 | * |
---|
| 677 | * @see rtems_filesystem_fsunmount_me_t. |
---|
| 678 | */ |
---|
| 679 | void rtems_filesystem_default_fsunmount( |
---|
| 680 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
[07a3253d] | 681 | ); |
---|
| 682 | |
---|
[f9a4e80] | 683 | /** |
---|
[3b7c123] | 684 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 685 | * |
---|
| 686 | * @see rtems_filesystem_utime_t. |
---|
| 687 | */ |
---|
| 688 | int rtems_filesystem_default_utime( |
---|
| 689 | const rtems_filesystem_location_info_t *loc, |
---|
| 690 | time_t actime, |
---|
| 691 | time_t modtime |
---|
[07a3253d] | 692 | ); |
---|
| 693 | |
---|
[f9a4e80] | 694 | /** |
---|
[3b7c123] | 695 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 696 | * |
---|
| 697 | * @see rtems_filesystem_symlink_t. |
---|
| 698 | */ |
---|
| 699 | int rtems_filesystem_default_symlink( |
---|
| 700 | const rtems_filesystem_location_info_t *parentloc, |
---|
| 701 | const char *name, |
---|
| 702 | size_t namelen, |
---|
| 703 | const char *target |
---|
[07a3253d] | 704 | ); |
---|
| 705 | |
---|
[f9a4e80] | 706 | /** |
---|
[3b7c123] | 707 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 708 | * |
---|
| 709 | * @see rtems_filesystem_readlink_t. |
---|
| 710 | */ |
---|
| 711 | ssize_t rtems_filesystem_default_readlink( |
---|
| 712 | const rtems_filesystem_location_info_t *loc, |
---|
| 713 | char *buf, |
---|
| 714 | size_t bufsize |
---|
[07a3253d] | 715 | ); |
---|
| 716 | |
---|
[f9a4e80] | 717 | /** |
---|
[3b7c123] | 718 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 719 | * |
---|
| 720 | * @see rtems_filesystem_rename_t. |
---|
| 721 | */ |
---|
| 722 | int rtems_filesystem_default_rename( |
---|
| 723 | const rtems_filesystem_location_info_t *oldparentloc, |
---|
| 724 | const rtems_filesystem_location_info_t *oldloc, |
---|
| 725 | const rtems_filesystem_location_info_t *newparentloc, |
---|
| 726 | const char *name, |
---|
| 727 | size_t namelen |
---|
[07a3253d] | 728 | ); |
---|
| 729 | |
---|
[f9a4e80] | 730 | /** |
---|
[3b7c123] | 731 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 732 | * |
---|
| 733 | * @see rtems_filesystem_statvfs_t. |
---|
| 734 | */ |
---|
| 735 | int rtems_filesystem_default_statvfs( |
---|
| 736 | const rtems_filesystem_location_info_t *loc, |
---|
| 737 | struct statvfs *buf |
---|
[07a3253d] | 738 | ); |
---|
| 739 | |
---|
[3b7c123] | 740 | /** @} */ |
---|
| 741 | |
---|
[f9a4e80] | 742 | /** |
---|
[3b7c123] | 743 | * @defgroup LibIOFSHandler File System Node Handler |
---|
| 744 | * |
---|
| 745 | * @ingroup LibIO |
---|
| 746 | * |
---|
| 747 | * @brief File system node handler. |
---|
| 748 | * |
---|
| 749 | * @{ |
---|
| 750 | */ |
---|
[07a3253d] | 751 | |
---|
[f9a4e80] | 752 | /** |
---|
[3b7c123] | 753 | * @brief Opens a node. |
---|
| 754 | * |
---|
| 755 | * @param[in, out] iop The IO pointer. |
---|
| 756 | * @param[in] path The path. |
---|
| 757 | * @param[in] oflag The open flags. |
---|
| 758 | * @param[in] mode Optional mode for node creation. |
---|
| 759 | * |
---|
| 760 | * @retval 0 Successful operation. |
---|
| 761 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 762 | * |
---|
| 763 | * @see rtems_filesystem_default_open(). |
---|
| 764 | */ |
---|
| 765 | typedef int (*rtems_filesystem_open_t)( |
---|
| 766 | rtems_libio_t *iop, |
---|
| 767 | const char *path, |
---|
| 768 | int oflag, |
---|
| 769 | mode_t mode |
---|
[07a3253d] | 770 | ); |
---|
| 771 | |
---|
[f9a4e80] | 772 | /** |
---|
[3b7c123] | 773 | * @brief Closes a node. |
---|
| 774 | * |
---|
| 775 | * @param[in, out] iop The IO pointer. |
---|
| 776 | * |
---|
| 777 | * @retval 0 Successful operation. |
---|
| 778 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 779 | * |
---|
| 780 | * @see rtems_filesystem_default_close(). |
---|
| 781 | */ |
---|
| 782 | typedef int (*rtems_filesystem_close_t)( |
---|
| 783 | rtems_libio_t *iop |
---|
[07a3253d] | 784 | ); |
---|
| 785 | |
---|
[f9a4e80] | 786 | /** |
---|
[3b7c123] | 787 | * @brief Reads from a node. |
---|
| 788 | * |
---|
[53da07e] | 789 | * This handler is responsible to update the offset field of the IO descriptor. |
---|
| 790 | * |
---|
[3b7c123] | 791 | * @param[in, out] iop The IO pointer. |
---|
| 792 | * @param[out] buffer The buffer for read data. |
---|
| 793 | * @param[in] count The size of the buffer in characters. |
---|
| 794 | * |
---|
| 795 | * @retval non-negative Count of read characters. |
---|
| 796 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 797 | * |
---|
| 798 | * @see rtems_filesystem_default_read(). |
---|
| 799 | */ |
---|
| 800 | typedef ssize_t (*rtems_filesystem_read_t)( |
---|
| 801 | rtems_libio_t *iop, |
---|
| 802 | void *buffer, |
---|
| 803 | size_t count |
---|
[07a3253d] | 804 | ); |
---|
| 805 | |
---|
[f9a4e80] | 806 | /** |
---|
[3b7c123] | 807 | * @brief Writes to a node. |
---|
| 808 | * |
---|
[53da07e] | 809 | * This handler is responsible to update the offset field of the IO descriptor. |
---|
| 810 | * |
---|
[3b7c123] | 811 | * @param[in, out] iop The IO pointer. |
---|
| 812 | * @param[out] buffer The buffer for write data. |
---|
| 813 | * @param[in] count The size of the buffer in characters. |
---|
| 814 | * |
---|
| 815 | * @retval non-negative Count of written characters. |
---|
| 816 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 817 | * |
---|
| 818 | * @see rtems_filesystem_default_write(). |
---|
| 819 | */ |
---|
| 820 | typedef ssize_t (*rtems_filesystem_write_t)( |
---|
| 821 | rtems_libio_t *iop, |
---|
| 822 | const void *buffer, |
---|
| 823 | size_t count |
---|
[07a3253d] | 824 | ); |
---|
| 825 | |
---|
[f9a4e80] | 826 | /** |
---|
[3b7c123] | 827 | * @brief IO control of a node. |
---|
| 828 | * |
---|
| 829 | * @param[in, out] iop The IO pointer. |
---|
| 830 | * @param[in] request The IO control request. |
---|
| 831 | * @param[in, out] buffer The buffer for IO control request data. |
---|
| 832 | * |
---|
| 833 | * @retval 0 Successful operation. |
---|
| 834 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 835 | * |
---|
| 836 | * @see rtems_filesystem_default_ioctl(). |
---|
| 837 | */ |
---|
| 838 | typedef int (*rtems_filesystem_ioctl_t)( |
---|
[df01da67] | 839 | rtems_libio_t *iop, |
---|
| 840 | ioctl_command_t request, |
---|
| 841 | void *buffer |
---|
[07a3253d] | 842 | ); |
---|
| 843 | |
---|
[f9a4e80] | 844 | /** |
---|
[3b7c123] | 845 | * @brief Moves the read/write file offset. |
---|
| 846 | * |
---|
| 847 | * @param[in, out] iop The IO pointer. |
---|
[adef4e4] | 848 | * @param[in] offset The offset. |
---|
| 849 | * @param[in] whence The reference position for the offset. |
---|
[3b7c123] | 850 | * |
---|
| 851 | * @retval non-negative The new offset from the beginning of the file. |
---|
| 852 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 853 | * |
---|
[30d4124] | 854 | * @see rtems_filesystem_default_lseek(), |
---|
| 855 | * rtems_filesystem_default_lseek_file(), and |
---|
| 856 | * rtems_filesystem_default_lseek_directory(). |
---|
[3b7c123] | 857 | */ |
---|
| 858 | typedef off_t (*rtems_filesystem_lseek_t)( |
---|
| 859 | rtems_libio_t *iop, |
---|
| 860 | off_t offset, |
---|
| 861 | int whence |
---|
[8ec7abb] | 862 | ); |
---|
| 863 | |
---|
[f9a4e80] | 864 | /** |
---|
[3b7c123] | 865 | * @brief Gets a node status. |
---|
| 866 | * |
---|
| 867 | * @param[in, out] iop The IO pointer. |
---|
| 868 | * @param[out] stat The buffer to status information. |
---|
| 869 | * |
---|
| 870 | * @retval 0 Successful operation. |
---|
| 871 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 872 | * |
---|
| 873 | * @see rtems_filesystem_default_fstat(). |
---|
| 874 | */ |
---|
| 875 | typedef int (*rtems_filesystem_fstat_t)( |
---|
| 876 | const rtems_filesystem_location_info_t *loc, |
---|
| 877 | struct stat *buf |
---|
[eb649786] | 878 | ); |
---|
| 879 | |
---|
[9da9cf4a] | 880 | /** |
---|
[3b7c123] | 881 | * @brief Truncates a file to a specified length. |
---|
| 882 | * |
---|
| 883 | * @param[in, out] iop The IO pointer. |
---|
| 884 | * @param[in] length The new length in characters. |
---|
| 885 | * |
---|
| 886 | * @retval 0 Successful operation. |
---|
| 887 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 888 | * |
---|
| 889 | * @see rtems_filesystem_default_ftruncate() and |
---|
| 890 | * rtems_filesystem_default_ftruncate_directory(). |
---|
[07a3253d] | 891 | */ |
---|
[3b7c123] | 892 | typedef int (*rtems_filesystem_ftruncate_t)( |
---|
| 893 | rtems_libio_t *iop, |
---|
| 894 | off_t length |
---|
| 895 | ); |
---|
[1e01385] | 896 | |
---|
| 897 | /** |
---|
[3b7c123] | 898 | * @brief Synchronizes changes to a file. |
---|
| 899 | * |
---|
| 900 | * @param[in, out] iop The IO pointer. |
---|
| 901 | * |
---|
| 902 | * @retval 0 Successful operation. |
---|
| 903 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 904 | * |
---|
[4116fce6] | 905 | * @see rtems_filesystem_default_fsync_or_fdatasync() and |
---|
| 906 | * rtems_filesystem_default_fsync_or_fdatasync_success(). |
---|
[f9a4e80] | 907 | */ |
---|
[3b7c123] | 908 | typedef int (*rtems_filesystem_fsync_t)( |
---|
| 909 | rtems_libio_t *iop |
---|
[1e01385] | 910 | ); |
---|
[f9a4e80] | 911 | |
---|
[1e01385] | 912 | /** |
---|
[3b7c123] | 913 | * @brief Synchronizes the data of a file. |
---|
| 914 | * |
---|
| 915 | * @param[in, out] iop The IO pointer. |
---|
| 916 | * |
---|
| 917 | * @retval 0 Successful operation. |
---|
| 918 | * @retval -1 An error occured. The errno is set to indicate the error. |
---|
| 919 | * |
---|
[4116fce6] | 920 | * @see rtems_filesystem_default_fsync_or_fdatasync() and |
---|
| 921 | * rtems_filesystem_default_fsync_or_fdatasync_success(). |
---|
[1e01385] | 922 | */ |
---|
[3b7c123] | 923 | typedef int (*rtems_filesystem_fdatasync_t)( |
---|
| 924 | rtems_libio_t *iop |
---|
[1e01385] | 925 | ); |
---|
[f9a4e80] | 926 | |
---|
| 927 | /** |
---|
[3b7c123] | 928 | * @brief File control. |
---|
| 929 | * |
---|
| 930 | * @param[in, out] iop The IO pointer. |
---|
| 931 | * @param[in] cmd Control command. |
---|
| 932 | * |
---|
| 933 | * @retval 0 Successful operation. |
---|
| 934 | * @retval errno An error occured. This value is assigned to errno. |
---|
| 935 | * |
---|
| 936 | * @see rtems_filesystem_default_fcntl(). |
---|
[f9a4e80] | 937 | */ |
---|
[3b7c123] | 938 | typedef int (*rtems_filesystem_fcntl_t)( |
---|
| 939 | rtems_libio_t *iop, |
---|
| 940 | int cmd |
---|
[f9a4e80] | 941 | ); |
---|
| 942 | |
---|
| 943 | /** |
---|
[3b7c123] | 944 | * @brief File system node operations table. |
---|
[f9a4e80] | 945 | */ |
---|
[3b7c123] | 946 | struct _rtems_filesystem_file_handlers_r { |
---|
| 947 | rtems_filesystem_open_t open_h; |
---|
| 948 | rtems_filesystem_close_t close_h; |
---|
| 949 | rtems_filesystem_read_t read_h; |
---|
| 950 | rtems_filesystem_write_t write_h; |
---|
| 951 | rtems_filesystem_ioctl_t ioctl_h; |
---|
| 952 | rtems_filesystem_lseek_t lseek_h; |
---|
| 953 | rtems_filesystem_fstat_t fstat_h; |
---|
| 954 | rtems_filesystem_ftruncate_t ftruncate_h; |
---|
| 955 | rtems_filesystem_fsync_t fsync_h; |
---|
| 956 | rtems_filesystem_fdatasync_t fdatasync_h; |
---|
| 957 | rtems_filesystem_fcntl_t fcntl_h; |
---|
| 958 | }; |
---|
[f9a4e80] | 959 | |
---|
[1e01385] | 960 | /** |
---|
[3b7c123] | 961 | * @brief File system node handler table with default node handlers. |
---|
[1e01385] | 962 | */ |
---|
[3b7c123] | 963 | extern const rtems_filesystem_file_handlers_r |
---|
| 964 | rtems_filesystem_handlers_default; |
---|
[1e01385] | 965 | |
---|
[6683a58] | 966 | /** |
---|
[3b7c123] | 967 | * @retval 0 Always. |
---|
| 968 | * |
---|
| 969 | * @see rtems_filesystem_open_t. |
---|
[6683a58] | 970 | */ |
---|
[3b7c123] | 971 | int rtems_filesystem_default_open( |
---|
| 972 | rtems_libio_t *iop, |
---|
| 973 | const char *path, |
---|
| 974 | int oflag, |
---|
| 975 | mode_t mode |
---|
[6683a58] | 976 | ); |
---|
| 977 | |
---|
[f9a4e80] | 978 | /** |
---|
[3b7c123] | 979 | * @retval 0 Always. |
---|
| 980 | * |
---|
| 981 | * @see rtems_filesystem_close_t. |
---|
[f9a4e80] | 982 | */ |
---|
[3b7c123] | 983 | int rtems_filesystem_default_close( |
---|
| 984 | rtems_libio_t *iop |
---|
[f9a4e80] | 985 | ); |
---|
| 986 | |
---|
| 987 | /** |
---|
[3b7c123] | 988 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 989 | * |
---|
| 990 | * @see rtems_filesystem_read_t. |
---|
[f9a4e80] | 991 | */ |
---|
[3b7c123] | 992 | ssize_t rtems_filesystem_default_read( |
---|
| 993 | rtems_libio_t *iop, |
---|
| 994 | void *buffer, |
---|
| 995 | size_t count |
---|
[f9a4e80] | 996 | ); |
---|
| 997 | |
---|
| 998 | /** |
---|
[3b7c123] | 999 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 1000 | * |
---|
| 1001 | * @see rtems_filesystem_write_t. |
---|
[f9a4e80] | 1002 | */ |
---|
[3b7c123] | 1003 | ssize_t rtems_filesystem_default_write( |
---|
| 1004 | rtems_libio_t *iop, |
---|
| 1005 | const void *buffer, |
---|
| 1006 | size_t count |
---|
[f9a4e80] | 1007 | ); |
---|
| 1008 | |
---|
| 1009 | /** |
---|
[3b7c123] | 1010 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 1011 | * |
---|
| 1012 | * @see rtems_filesystem_ioctl_t. |
---|
[f9a4e80] | 1013 | */ |
---|
[3b7c123] | 1014 | int rtems_filesystem_default_ioctl( |
---|
[df01da67] | 1015 | rtems_libio_t *iop, |
---|
| 1016 | ioctl_command_t request, |
---|
| 1017 | void *buffer |
---|
[f9a4e80] | 1018 | ); |
---|
| 1019 | |
---|
| 1020 | /** |
---|
[a76c2373] | 1021 | * @retval -1 Always. The errno is set to ESPIPE. |
---|
[3b7c123] | 1022 | * |
---|
| 1023 | * @see rtems_filesystem_lseek_t. |
---|
[f9a4e80] | 1024 | */ |
---|
[3b7c123] | 1025 | off_t rtems_filesystem_default_lseek( |
---|
| 1026 | rtems_libio_t *iop, |
---|
[adef4e4] | 1027 | off_t offset, |
---|
| 1028 | int whence |
---|
| 1029 | ); |
---|
| 1030 | |
---|
[30d4124] | 1031 | /** |
---|
| 1032 | * @brief An offset 0 with a whence of SEEK_SET will perform a directory rewind |
---|
| 1033 | * operation. |
---|
| 1034 | * |
---|
| 1035 | * This function has no protection against concurrent access. |
---|
| 1036 | * |
---|
| 1037 | * @retval -1 The offset is not zero or the whence is not SEEK_SET. |
---|
| 1038 | * @retval 0 Successful rewind operation. |
---|
| 1039 | * |
---|
| 1040 | * @see rtems_filesystem_lseek_t. |
---|
| 1041 | */ |
---|
| 1042 | off_t rtems_filesystem_default_lseek_directory( |
---|
| 1043 | rtems_libio_t *iop, |
---|
| 1044 | off_t offset, |
---|
| 1045 | int whence |
---|
| 1046 | ); |
---|
| 1047 | |
---|
| 1048 | /** |
---|
| 1049 | * @brief Default lseek() handler for files. |
---|
| 1050 | * |
---|
| 1051 | * The fstat() handler will be used to obtain the file size in case whence is |
---|
| 1052 | * SEEK_END. |
---|
| 1053 | * |
---|
| 1054 | * This function has no protection against concurrent access. |
---|
| 1055 | * |
---|
| 1056 | * @retval -1 An error occured. In case an integer overflow occured, then the |
---|
| 1057 | * errno will be set to EOVERFLOW. In case the new offset is negative, then |
---|
| 1058 | * the errno will be set to EINVAL. In case the whence is SEEK_END and the |
---|
| 1059 | * fstat() handler to obtain the current file size returned an error status, |
---|
| 1060 | * then the errno will be set by the fstat() handler. |
---|
| 1061 | * @retval offset The new offset. |
---|
| 1062 | * |
---|
| 1063 | * @see rtems_filesystem_lseek_t. |
---|
| 1064 | */ |
---|
| 1065 | off_t rtems_filesystem_default_lseek_file( |
---|
| 1066 | rtems_libio_t *iop, |
---|
| 1067 | off_t offset, |
---|
| 1068 | int whence |
---|
| 1069 | ); |
---|
| 1070 | |
---|
[f9a4e80] | 1071 | /** |
---|
[3b7c123] | 1072 | * @brief Sets the mode to S_IRWXU | S_IRWXG | S_IRWXO. |
---|
| 1073 | * |
---|
| 1074 | * @retval 0 Always. |
---|
| 1075 | * |
---|
| 1076 | * @see rtems_filesystem_fstat_t. |
---|
[f9a4e80] | 1077 | */ |
---|
[3b7c123] | 1078 | int rtems_filesystem_default_fstat( |
---|
| 1079 | const rtems_filesystem_location_info_t *loc, |
---|
| 1080 | struct stat *buf |
---|
[f9a4e80] | 1081 | ); |
---|
| 1082 | |
---|
| 1083 | /** |
---|
[3b7c123] | 1084 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
| 1085 | * |
---|
| 1086 | * @see rtems_filesystem_ftruncate_t. |
---|
[f9a4e80] | 1087 | */ |
---|
[3b7c123] | 1088 | int rtems_filesystem_default_ftruncate( |
---|
| 1089 | rtems_libio_t *iop, |
---|
| 1090 | off_t length |
---|
[f9a4e80] | 1091 | ); |
---|
| 1092 | |
---|
| 1093 | /** |
---|
[3b7c123] | 1094 | * @retval -1 Always. The errno is set to EISDIR. |
---|
| 1095 | * |
---|
| 1096 | * @see rtems_filesystem_ftruncate_t. |
---|
[f9a4e80] | 1097 | */ |
---|
[3b7c123] | 1098 | int rtems_filesystem_default_ftruncate_directory( |
---|
| 1099 | rtems_libio_t *iop, |
---|
| 1100 | off_t length |
---|
[f9a4e80] | 1101 | ); |
---|
| 1102 | |
---|
| 1103 | /** |
---|
[4116fce6] | 1104 | * @retval -1 Always. The errno is set to EINVAL. |
---|
[3b7c123] | 1105 | * |
---|
[4116fce6] | 1106 | * @see rtems_filesystem_fsync_t and rtems_filesystem_fdatasync_t. |
---|
[f9a4e80] | 1107 | */ |
---|
[4116fce6] | 1108 | int rtems_filesystem_default_fsync_or_fdatasync( |
---|
[3b7c123] | 1109 | rtems_libio_t *iop |
---|
[f9a4e80] | 1110 | ); |
---|
| 1111 | |
---|
| 1112 | /** |
---|
[4116fce6] | 1113 | * @retval 0 Always. |
---|
[3b7c123] | 1114 | * |
---|
[4116fce6] | 1115 | * @see rtems_filesystem_fsync_t and rtems_filesystem_fdatasync_t. |
---|
[f9a4e80] | 1116 | */ |
---|
[4116fce6] | 1117 | int rtems_filesystem_default_fsync_or_fdatasync_success( |
---|
[3b7c123] | 1118 | rtems_libio_t *iop |
---|
[f9a4e80] | 1119 | ); |
---|
| 1120 | |
---|
| 1121 | /** |
---|
[3b7c123] | 1122 | * @retval 0 Always. |
---|
| 1123 | * |
---|
| 1124 | * @see rtems_filesystem_fcntl_t. |
---|
[f9a4e80] | 1125 | */ |
---|
[3b7c123] | 1126 | int rtems_filesystem_default_fcntl( |
---|
| 1127 | rtems_libio_t *iop, |
---|
| 1128 | int cmd |
---|
[f9a4e80] | 1129 | ); |
---|
| 1130 | |
---|
[3b7c123] | 1131 | /** @} */ |
---|
| 1132 | |
---|
[f9a4e80] | 1133 | /** |
---|
[3b7c123] | 1134 | * @defgroup LibIO IO Library |
---|
| 1135 | * |
---|
| 1136 | * @brief Provides system call and file system interface definitions. |
---|
| 1137 | * |
---|
| 1138 | * General purpose communication channel for RTEMS to allow UNIX/POSIX |
---|
| 1139 | * system call behavior under RTEMS. Initially this supported only |
---|
| 1140 | * IO to devices but has since been enhanced to support networking |
---|
| 1141 | * and support for mounted file systems. |
---|
| 1142 | * |
---|
| 1143 | * @{ |
---|
[f9a4e80] | 1144 | */ |
---|
[3b7c123] | 1145 | |
---|
| 1146 | typedef off_t rtems_off64_t __attribute__((deprecated)); |
---|
[f9a4e80] | 1147 | |
---|
[7d01d244] | 1148 | /** |
---|
[9da9cf4a] | 1149 | * @brief Gets the mount handler for the file system @a type. |
---|
| 1150 | * |
---|
| 1151 | * @return The file system mount handler associated with the @a type, or |
---|
[7d01d244] | 1152 | * @c NULL if no such association exists. |
---|
[29e92b0] | 1153 | */ |
---|
[7d01d244] | 1154 | rtems_filesystem_fsmount_me_t |
---|
| 1155 | rtems_filesystem_get_mount_handler( |
---|
| 1156 | const char *type |
---|
| 1157 | ); |
---|
[29e92b0] | 1158 | |
---|
[9da9cf4a] | 1159 | /** |
---|
| 1160 | * @brief Contain file system specific information which is required to support |
---|
| 1161 | * fpathconf(). |
---|
[b06e68ef] | 1162 | */ |
---|
| 1163 | typedef struct { |
---|
[29e92b0] | 1164 | int link_max; /* count */ |
---|
| 1165 | int max_canon; /* max formatted input line size */ |
---|
| 1166 | int max_input; /* max input line size */ |
---|
| 1167 | int name_max; /* max name length */ |
---|
| 1168 | int path_max; /* max path */ |
---|
| 1169 | int pipe_buf; /* pipe buffer size */ |
---|
| 1170 | int posix_async_io; /* async IO supported on fs, 0=no, 1=yes */ |
---|
| 1171 | int posix_chown_restrictions; /* can chown: 0=no, 1=yes */ |
---|
| 1172 | int posix_no_trunc; /* error on names > max name, 0=no, 1=yes */ |
---|
| 1173 | int posix_prio_io; /* priority IO, 0=no, 1=yes */ |
---|
| 1174 | int posix_sync_io; /* file can be sync'ed, 0=no, 1=yes */ |
---|
| 1175 | int posix_vdisable; /* special char processing, 0=no, 1=yes */ |
---|
[07a3253d] | 1176 | } rtems_filesystem_limits_and_options_t; |
---|
| 1177 | |
---|
[9da9cf4a] | 1178 | /** |
---|
| 1179 | * @brief Default pathconf settings. |
---|
| 1180 | * |
---|
| 1181 | * Override in a filesystem. |
---|
[29e92b0] | 1182 | */ |
---|
[3b7c123] | 1183 | extern const rtems_filesystem_limits_and_options_t |
---|
| 1184 | rtems_filesystem_default_pathconf; |
---|
[29e92b0] | 1185 | |
---|
[9da9cf4a] | 1186 | /** |
---|
| 1187 | * @brief An open file data structure. |
---|
| 1188 | * |
---|
| 1189 | * It will be indexed by 'fd'. |
---|
| 1190 | * |
---|
| 1191 | * @todo Should really have a separate per/file data structure that this points |
---|
[30d4124] | 1192 | * to (eg: offset, driver, pathname should be in that) |
---|
[07a3253d] | 1193 | */ |
---|
| 1194 | struct rtems_libio_tt { |
---|
[aa61d53] | 1195 | rtems_driver_name_t *driver; |
---|
[b799e4eb] | 1196 | off_t offset; /* current offset into file */ |
---|
[aa61d53] | 1197 | uint32_t flags; |
---|
| 1198 | rtems_filesystem_location_info_t pathinfo; |
---|
| 1199 | uint32_t data0; /* private to "driver" */ |
---|
| 1200 | void *data1; /* ... */ |
---|
[07a3253d] | 1201 | }; |
---|
| 1202 | |
---|
[9da9cf4a] | 1203 | /** |
---|
| 1204 | * @brief Paramameter block for read/write. |
---|
| 1205 | * |
---|
| 1206 | * It must include 'offset' instead of using iop's offset since we can have |
---|
| 1207 | * multiple outstanding i/o's on a device. |
---|
[b06e68ef] | 1208 | */ |
---|
| 1209 | typedef struct { |
---|
[aa61d53] | 1210 | rtems_libio_t *iop; |
---|
[b799e4eb] | 1211 | off_t offset; |
---|
[aa61d53] | 1212 | char *buffer; |
---|
| 1213 | uint32_t count; |
---|
| 1214 | uint32_t flags; |
---|
| 1215 | uint32_t bytes_moved; |
---|
[b06e68ef] | 1216 | } rtems_libio_rw_args_t; |
---|
| 1217 | |
---|
[9da9cf4a] | 1218 | /** |
---|
| 1219 | * @brief Parameter block for open/close. |
---|
[b06e68ef] | 1220 | */ |
---|
| 1221 | typedef struct { |
---|
[aa61d53] | 1222 | rtems_libio_t *iop; |
---|
| 1223 | uint32_t flags; |
---|
| 1224 | uint32_t mode; |
---|
[b06e68ef] | 1225 | } rtems_libio_open_close_args_t; |
---|
| 1226 | |
---|
[9da9cf4a] | 1227 | /** |
---|
| 1228 | * @brief Parameter block for ioctl. |
---|
[b06e68ef] | 1229 | */ |
---|
| 1230 | typedef struct { |
---|
[aa61d53] | 1231 | rtems_libio_t *iop; |
---|
[df01da67] | 1232 | ioctl_command_t command; |
---|
[aa61d53] | 1233 | void *buffer; |
---|
[5b045eb] | 1234 | int ioctl_return; |
---|
[b06e68ef] | 1235 | } rtems_libio_ioctl_args_t; |
---|
| 1236 | |
---|
[9da9cf4a] | 1237 | /** |
---|
| 1238 | * @name Flag Values |
---|
| 1239 | * |
---|
| 1240 | * @{ |
---|
[b06e68ef] | 1241 | */ |
---|
[9da9cf4a] | 1242 | |
---|
[145c9343] | 1243 | #define LIBIO_FLAGS_NO_DELAY 0x0001U /* return immediately if no data */ |
---|
| 1244 | #define LIBIO_FLAGS_READ 0x0002U /* reading */ |
---|
| 1245 | #define LIBIO_FLAGS_WRITE 0x0004U /* writing */ |
---|
| 1246 | #define LIBIO_FLAGS_OPEN 0x0100U /* device is open */ |
---|
| 1247 | #define LIBIO_FLAGS_APPEND 0x0200U /* all writes append */ |
---|
| 1248 | #define LIBIO_FLAGS_CREATE 0x0400U /* create file */ |
---|
| 1249 | #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800U /* close on process exec() */ |
---|
[b06e68ef] | 1250 | #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) |
---|
| 1251 | |
---|
[9da9cf4a] | 1252 | /** @} */ |
---|
| 1253 | |
---|
[07a3253d] | 1254 | void rtems_libio_init(void); |
---|
[b06e68ef] | 1255 | |
---|
[9da9cf4a] | 1256 | /** |
---|
| 1257 | * @name External I/O Handlers |
---|
| 1258 | * |
---|
| 1259 | * @{ |
---|
[e2d79559] | 1260 | */ |
---|
[07a3253d] | 1261 | |
---|
| 1262 | typedef int (*rtems_libio_open_t)( |
---|
| 1263 | const char *pathname, |
---|
[83c5fc1] | 1264 | uint32_t flag, |
---|
| 1265 | uint32_t mode |
---|
[07a3253d] | 1266 | ); |
---|
| 1267 | |
---|
| 1268 | typedef int (*rtems_libio_close_t)( |
---|
| 1269 | int fd |
---|
| 1270 | ); |
---|
| 1271 | |
---|
[b637dbb] | 1272 | typedef ssize_t (*rtems_libio_read_t)( |
---|
[07a3253d] | 1273 | int fd, |
---|
| 1274 | void *buffer, |
---|
[b637dbb] | 1275 | size_t count |
---|
[07a3253d] | 1276 | ); |
---|
| 1277 | |
---|
[b637dbb] | 1278 | typedef ssize_t (*rtems_libio_write_t)( |
---|
[07a3253d] | 1279 | int fd, |
---|
| 1280 | const void *buffer, |
---|
[b637dbb] | 1281 | size_t count |
---|
[07a3253d] | 1282 | ); |
---|
| 1283 | |
---|
| 1284 | typedef int (*rtems_libio_ioctl_t)( |
---|
| 1285 | int fd, |
---|
[83c5fc1] | 1286 | uint32_t command, |
---|
[07a3253d] | 1287 | void *buffer |
---|
| 1288 | ); |
---|
| 1289 | |
---|
[b799e4eb] | 1290 | typedef off_t (*rtems_libio_lseek_t)( |
---|
[07d6fd5] | 1291 | int fd, |
---|
[b799e4eb] | 1292 | off_t offset, |
---|
[07d6fd5] | 1293 | int whence |
---|
[07a3253d] | 1294 | ); |
---|
| 1295 | |
---|
[9da9cf4a] | 1296 | /** @} */ |
---|
| 1297 | |
---|
| 1298 | /** |
---|
| 1299 | * @name Permission Macros |
---|
| 1300 | * |
---|
| 1301 | * @{ |
---|
| 1302 | */ |
---|
| 1303 | |
---|
[07a3253d] | 1304 | /* |
---|
| 1305 | * The following macros are used to build up the permissions sets |
---|
| 1306 | * used to check permissions. These are similar in style to the |
---|
| 1307 | * mode_t bits and should stay compatible with them. |
---|
| 1308 | */ |
---|
[2563410] | 1309 | #define RTEMS_FS_PERMS_READ 0x4 |
---|
| 1310 | #define RTEMS_FS_PERMS_WRITE 0x2 |
---|
| 1311 | #define RTEMS_FS_PERMS_EXEC 0x1 |
---|
| 1312 | #define RTEMS_FS_PERMS_RWX \ |
---|
| 1313 | (RTEMS_FS_PERMS_READ | RTEMS_FS_PERMS_WRITE | RTEMS_FS_PERMS_EXEC) |
---|
| 1314 | #define RTEMS_FS_FOLLOW_HARD_LINK 0x8 |
---|
| 1315 | #define RTEMS_FS_FOLLOW_SYM_LINK 0x10 |
---|
| 1316 | #define RTEMS_FS_FOLLOW_LINK \ |
---|
| 1317 | (RTEMS_FS_FOLLOW_HARD_LINK | RTEMS_FS_FOLLOW_SYM_LINK) |
---|
| 1318 | #define RTEMS_FS_MAKE 0x20 |
---|
| 1319 | #define RTEMS_FS_EXCLUSIVE 0x40 |
---|
| 1320 | #define RTEMS_FS_ACCEPT_RESIDUAL_DELIMITERS 0x80 |
---|
| 1321 | #define RTEMS_FS_REJECT_TERMINAL_DOT 0x100 |
---|
[07a3253d] | 1322 | |
---|
[9da9cf4a] | 1323 | /** @} */ |
---|
[7e476f0] | 1324 | |
---|
[0b178f04] | 1325 | union __rtems_dev_t { |
---|
[7e476f0] | 1326 | dev_t device; |
---|
| 1327 | struct { |
---|
| 1328 | rtems_device_major_number major; |
---|
| 1329 | rtems_device_minor_number minor; |
---|
| 1330 | } __overlay; |
---|
| 1331 | }; |
---|
| 1332 | |
---|
[50f32b11] | 1333 | static inline dev_t rtems_filesystem_make_dev_t( |
---|
| 1334 | rtems_device_major_number _major, |
---|
[7e476f0] | 1335 | rtems_device_minor_number _minor |
---|
| 1336 | ) |
---|
| 1337 | { |
---|
[0b178f04] | 1338 | union __rtems_dev_t temp; |
---|
[7e476f0] | 1339 | |
---|
| 1340 | temp.__overlay.major = _major; |
---|
| 1341 | temp.__overlay.minor = _minor; |
---|
| 1342 | return temp.device; |
---|
| 1343 | } |
---|
| 1344 | |
---|
| 1345 | static inline rtems_device_major_number rtems_filesystem_dev_major_t( |
---|
| 1346 | dev_t device |
---|
| 1347 | ) |
---|
| 1348 | { |
---|
[0b178f04] | 1349 | union __rtems_dev_t temp; |
---|
[7e476f0] | 1350 | |
---|
| 1351 | temp.device = device; |
---|
| 1352 | return temp.__overlay.major; |
---|
| 1353 | } |
---|
| 1354 | |
---|
| 1355 | |
---|
| 1356 | static inline rtems_device_minor_number rtems_filesystem_dev_minor_t( |
---|
| 1357 | dev_t device |
---|
| 1358 | ) |
---|
| 1359 | { |
---|
[0b178f04] | 1360 | union __rtems_dev_t temp; |
---|
[7e476f0] | 1361 | |
---|
| 1362 | temp.device = device; |
---|
| 1363 | return temp.__overlay.minor; |
---|
| 1364 | } |
---|
| 1365 | |
---|
[07a3253d] | 1366 | #define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \ |
---|
| 1367 | do { \ |
---|
[dd19c0b] | 1368 | (_major) = rtems_filesystem_dev_major_t ( _dev ); \ |
---|
| 1369 | (_minor) = rtems_filesystem_dev_minor_t( _dev ); \ |
---|
[07a3253d] | 1370 | } while(0) |
---|
| 1371 | |
---|
[6c0fcd4] | 1372 | /* |
---|
| 1373 | * Prototypes for filesystem |
---|
| 1374 | */ |
---|
| 1375 | |
---|
| 1376 | void rtems_filesystem_initialize( void ); |
---|
| 1377 | |
---|
| 1378 | typedef void (*rtems_libio_init_functions_t)(void); |
---|
| 1379 | extern rtems_libio_init_functions_t rtems_libio_init_helper; |
---|
| 1380 | |
---|
| 1381 | void open_dev_console(void); |
---|
| 1382 | |
---|
| 1383 | typedef void (*rtems_libio_supp_functions_t)(void); |
---|
| 1384 | extern rtems_libio_supp_functions_t rtems_libio_supp_helper; |
---|
| 1385 | |
---|
| 1386 | typedef void (*rtems_fs_init_functions_t)(void); |
---|
| 1387 | extern rtems_fs_init_functions_t rtems_fs_init_helper; |
---|
| 1388 | |
---|
| 1389 | /** |
---|
| 1390 | * @brief Creates a directory and all its parent directories according to |
---|
| 1391 | * @a path. |
---|
| 1392 | * |
---|
| 1393 | * The @a mode value selects the access permissions of the directory. |
---|
| 1394 | * |
---|
| 1395 | * @retval 0 Successful operation. |
---|
| 1396 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
| 1397 | */ |
---|
| 1398 | extern int rtems_mkdir(const char *path, mode_t mode); |
---|
| 1399 | |
---|
| 1400 | /** @} */ |
---|
| 1401 | |
---|
| 1402 | /** |
---|
| 1403 | * @defgroup FileSystemTypesAndMount File System Types and Mount |
---|
| 1404 | * |
---|
| 1405 | * @ingroup LibIO |
---|
| 1406 | * |
---|
| 1407 | * @brief File system types and mount. |
---|
| 1408 | * |
---|
| 1409 | * @{ |
---|
| 1410 | */ |
---|
| 1411 | |
---|
[14fc3a77] | 1412 | /** |
---|
| 1413 | * @name File System Types |
---|
| 1414 | * |
---|
| 1415 | * @{ |
---|
| 1416 | */ |
---|
| 1417 | |
---|
| 1418 | #define RTEMS_FILESYSTEM_TYPE_IMFS "imfs" |
---|
| 1419 | #define RTEMS_FILESYSTEM_TYPE_MINIIMFS "mimfs" |
---|
| 1420 | #define RTEMS_FILESYSTEM_TYPE_DEVFS "devfs" |
---|
| 1421 | #define RTEMS_FILESYSTEM_TYPE_FTPFS "ftpfs" |
---|
| 1422 | #define RTEMS_FILESYSTEM_TYPE_TFTPFS "tftpfs" |
---|
| 1423 | #define RTEMS_FILESYSTEM_TYPE_NFS "nfs" |
---|
| 1424 | #define RTEMS_FILESYSTEM_TYPE_DOSFS "dosfs" |
---|
| 1425 | #define RTEMS_FILESYSTEM_TYPE_RFS "rfs" |
---|
| 1426 | |
---|
| 1427 | /** @} */ |
---|
| 1428 | |
---|
[6c0fcd4] | 1429 | /** |
---|
| 1430 | * @brief Mount table entry. |
---|
| 1431 | */ |
---|
| 1432 | struct rtems_filesystem_mount_table_entry_tt { |
---|
[3b7c123] | 1433 | rtems_chain_node mt_node; |
---|
| 1434 | rtems_chain_control location_chain; |
---|
| 1435 | rtems_filesystem_global_location_t *mt_point_node; |
---|
| 1436 | rtems_filesystem_global_location_t *mt_fs_root; |
---|
| 1437 | bool mounted; |
---|
| 1438 | bool writeable; |
---|
[6c0fcd4] | 1439 | void *fs_info; |
---|
[3b7c123] | 1440 | const void *immutable_fs_info; |
---|
[6c0fcd4] | 1441 | rtems_filesystem_limits_and_options_t pathconf_limits_and_options; |
---|
| 1442 | |
---|
| 1443 | /* |
---|
| 1444 | * The target or mount point of the file system. |
---|
| 1445 | */ |
---|
| 1446 | const char *target; |
---|
| 1447 | |
---|
| 1448 | /* |
---|
| 1449 | * The type of filesystem or the name of the filesystem. |
---|
| 1450 | */ |
---|
| 1451 | const char *type; |
---|
| 1452 | |
---|
| 1453 | /* |
---|
| 1454 | * When someone adds a mounted filesystem on a real device, |
---|
| 1455 | * this will need to be used. |
---|
| 1456 | * |
---|
| 1457 | * The lower layers can manage how this is managed. Leave as a |
---|
| 1458 | * string. |
---|
| 1459 | */ |
---|
| 1460 | char *dev; |
---|
| 1461 | }; |
---|
| 1462 | |
---|
| 1463 | /** |
---|
| 1464 | * @brief File system options. |
---|
[07a3253d] | 1465 | */ |
---|
[6c0fcd4] | 1466 | typedef enum { |
---|
| 1467 | RTEMS_FILESYSTEM_READ_ONLY, |
---|
| 1468 | RTEMS_FILESYSTEM_READ_WRITE, |
---|
| 1469 | RTEMS_FILESYSTEM_BAD_OPTIONS |
---|
| 1470 | } rtems_filesystem_options_t; |
---|
[07a3253d] | 1471 | |
---|
[6c0fcd4] | 1472 | /** |
---|
| 1473 | * @brief File system table entry. |
---|
| 1474 | */ |
---|
| 1475 | typedef struct rtems_filesystem_table_t { |
---|
| 1476 | const char *type; |
---|
| 1477 | rtems_filesystem_fsmount_me_t mount_h; |
---|
| 1478 | } rtems_filesystem_table_t; |
---|
[07a3253d] | 1479 | |
---|
[6c0fcd4] | 1480 | /** |
---|
| 1481 | * @brief Static table of file systems. |
---|
| 1482 | * |
---|
| 1483 | * Externally defined by confdefs.h or the user. |
---|
| 1484 | */ |
---|
| 1485 | extern const rtems_filesystem_table_t rtems_filesystem_table []; |
---|
| 1486 | |
---|
[3b7c123] | 1487 | extern rtems_chain_control rtems_filesystem_mount_table; |
---|
| 1488 | |
---|
[6c0fcd4] | 1489 | /** |
---|
| 1490 | * @brief Registers a file system @a type. |
---|
| 1491 | * |
---|
| 1492 | * The @a mount_h handler will be used to mount a file system of this @a type. |
---|
| 1493 | * |
---|
| 1494 | * @retval 0 Successful operation. |
---|
| 1495 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
| 1496 | */ |
---|
| 1497 | int rtems_filesystem_register( |
---|
| 1498 | const char *type, |
---|
| 1499 | rtems_filesystem_fsmount_me_t mount_h |
---|
| 1500 | ); |
---|
| 1501 | |
---|
| 1502 | /** |
---|
| 1503 | * @brief Unregisters a file system @a type. |
---|
| 1504 | * |
---|
| 1505 | * @retval 0 Successful operation. |
---|
| 1506 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
| 1507 | */ |
---|
| 1508 | int rtems_filesystem_unregister( |
---|
| 1509 | const char *type |
---|
| 1510 | ); |
---|
| 1511 | |
---|
| 1512 | /** |
---|
| 1513 | * @brief Unmounts the file system at @a mount_path. |
---|
| 1514 | * |
---|
| 1515 | * @todo Due to file system implementation shortcomings it is possible to |
---|
| 1516 | * unmount file systems in use. This likely leads to heap corruption. Unmount |
---|
| 1517 | * only file systems which are not in use by the application. |
---|
| 1518 | * |
---|
| 1519 | * @retval 0 Successful operation. |
---|
| 1520 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
| 1521 | */ |
---|
[9da9cf4a] | 1522 | int unmount( |
---|
| 1523 | const char *mount_path |
---|
| 1524 | ); |
---|
| 1525 | |
---|
[6c0fcd4] | 1526 | /** |
---|
| 1527 | * @brief Mounts a file system at @a target. |
---|
| 1528 | * |
---|
| 1529 | * The @a source may be a path to the corresponding device file, or @c NULL. |
---|
| 1530 | * The @a target path must lead to an existing directory, or @c NULL. In case |
---|
| 1531 | * @a target is @c NULL, the root file system will be mounted. The @a data |
---|
| 1532 | * parameter will be forwarded to the file system initialization handler. The |
---|
| 1533 | * file system type is selected by @a filesystemtype and may be one of |
---|
| 1534 | * - RTEMS_FILESYSTEM_TYPE_DEVFS, |
---|
| 1535 | * - RTEMS_FILESYSTEM_TYPE_DOSFS, |
---|
| 1536 | * - RTEMS_FILESYSTEM_TYPE_FTPFS, |
---|
| 1537 | * - RTEMS_FILESYSTEM_TYPE_IMFS, |
---|
| 1538 | * - RTEMS_FILESYSTEM_TYPE_MINIIMFS, |
---|
| 1539 | * - RTEMS_FILESYSTEM_TYPE_NFS, |
---|
| 1540 | * - RTEMS_FILESYSTEM_TYPE_RFS, or |
---|
| 1541 | * - RTEMS_FILESYSTEM_TYPE_TFTPFS. |
---|
| 1542 | * |
---|
| 1543 | * Only configured or registered file system types are available. You can add |
---|
| 1544 | * file system types to your application configuration with |
---|
| 1545 | * - CONFIGURE_FILESYSTEM_DEVFS, |
---|
| 1546 | * - CONFIGURE_FILESYSTEM_DOSFS, |
---|
| 1547 | * - CONFIGURE_FILESYSTEM_FTPFS, |
---|
| 1548 | * - CONFIGURE_FILESYSTEM_IMFS, |
---|
| 1549 | * - CONFIGURE_FILESYSTEM_MINIIMFS, |
---|
| 1550 | * - CONFIGURE_FILESYSTEM_NFS, |
---|
| 1551 | * - CONFIGURE_FILESYSTEM_RFS, and |
---|
| 1552 | * - CONFIGURE_FILESYSTEM_TFTPFS. |
---|
| 1553 | * |
---|
| 1554 | * @see rtems_filesystem_register() and mount_and_make_target_path(). |
---|
| 1555 | * |
---|
| 1556 | * @retval 0 Successful operation. |
---|
| 1557 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
| 1558 | */ |
---|
[9da9cf4a] | 1559 | int mount( |
---|
| 1560 | const char *source, |
---|
| 1561 | const char *target, |
---|
| 1562 | const char *filesystemtype, |
---|
| 1563 | rtems_filesystem_options_t options, |
---|
| 1564 | const void *data |
---|
| 1565 | ); |
---|
| 1566 | |
---|
[b813d632] | 1567 | /** |
---|
| 1568 | * @brief Mounts a file system and makes the @a target path. |
---|
| 1569 | * |
---|
| 1570 | * The @a target path will be created with rtems_mkdir() and must not be |
---|
| 1571 | * @c NULL. |
---|
| 1572 | * |
---|
| 1573 | * @see mount(). |
---|
| 1574 | * |
---|
| 1575 | * @retval 0 Successful operation. |
---|
| 1576 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
| 1577 | */ |
---|
| 1578 | int mount_and_make_target_path( |
---|
| 1579 | const char *source, |
---|
| 1580 | const char *target, |
---|
| 1581 | const char *filesystemtype, |
---|
| 1582 | rtems_filesystem_options_t options, |
---|
| 1583 | const void *data |
---|
| 1584 | ); |
---|
| 1585 | |
---|
[6c0fcd4] | 1586 | /** |
---|
| 1587 | * @brief Per file system type routine. |
---|
| 1588 | * |
---|
| 1589 | * @see rtems_filesystem_iterate(). |
---|
| 1590 | * |
---|
| 1591 | * @retval true Stop the iteration. |
---|
| 1592 | * @retval false Continue the iteration. |
---|
| 1593 | */ |
---|
| 1594 | typedef bool (*rtems_per_filesystem_routine)( |
---|
| 1595 | const rtems_filesystem_table_t *fs_entry, |
---|
| 1596 | void *arg |
---|
| 1597 | ); |
---|
| 1598 | |
---|
| 1599 | /** |
---|
| 1600 | * @brief Iterates over all file system types. |
---|
| 1601 | * |
---|
| 1602 | * For each file system type the @a routine will be called with the entry and |
---|
| 1603 | * the @a routine_arg parameter. |
---|
| 1604 | * |
---|
| 1605 | * Do not register or unregister file system types in @a routine. |
---|
| 1606 | * |
---|
| 1607 | * The iteration is protected by the IO library mutex. |
---|
| 1608 | * |
---|
| 1609 | * @retval true Iteration stopped due to @a routine return status. |
---|
| 1610 | * @retval false Iteration through all entries. |
---|
[9da9cf4a] | 1611 | */ |
---|
[6c0fcd4] | 1612 | bool rtems_filesystem_iterate( |
---|
| 1613 | rtems_per_filesystem_routine routine, |
---|
| 1614 | void *routine_arg |
---|
| 1615 | ); |
---|
[9da9cf4a] | 1616 | |
---|
[6c0fcd4] | 1617 | /** |
---|
[3b7c123] | 1618 | * @brief Mount table entry visitor. |
---|
[6c0fcd4] | 1619 | * |
---|
| 1620 | * @retval true Stop the iteration. |
---|
| 1621 | * @retval false Continue the iteration. |
---|
[3b7c123] | 1622 | * |
---|
| 1623 | * @see rtems_filesystem_mount_iterate(). |
---|
[6c0fcd4] | 1624 | */ |
---|
[3b7c123] | 1625 | typedef bool (*rtems_filesystem_mt_entry_visitor)( |
---|
[6c0fcd4] | 1626 | const rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
| 1627 | void *arg |
---|
| 1628 | ); |
---|
| 1629 | |
---|
| 1630 | /** |
---|
[3b7c123] | 1631 | * @brief Iterates over all file system mount entries. |
---|
[6c0fcd4] | 1632 | * |
---|
[3b7c123] | 1633 | * The iteration is protected by the IO library mutex. Do not mount or unmount |
---|
| 1634 | * file systems in the visitor function. |
---|
[6c0fcd4] | 1635 | * |
---|
[3b7c123] | 1636 | * @param[in] visitor For each file system mount entry the visitor function |
---|
| 1637 | * will be called with the entry and the visitor argument as parameters. |
---|
| 1638 | * @param[in] visitor_arg The second parameter for the visitor function. |
---|
[6c0fcd4] | 1639 | * |
---|
[3b7c123] | 1640 | * @retval true Iteration stopped due to visitor function return status. |
---|
[6c0fcd4] | 1641 | * @retval false Iteration through all entries. |
---|
| 1642 | */ |
---|
[3b7c123] | 1643 | bool rtems_filesystem_mount_iterate( |
---|
| 1644 | rtems_filesystem_mt_entry_visitor visitor, |
---|
| 1645 | void *visitor_arg |
---|
[6c0fcd4] | 1646 | ); |
---|
| 1647 | |
---|
[9da9cf4a] | 1648 | typedef struct { |
---|
[3b7c123] | 1649 | const char *source; |
---|
| 1650 | const char *target; |
---|
| 1651 | const char *filesystemtype; |
---|
| 1652 | rtems_filesystem_options_t options; |
---|
| 1653 | const void *data; |
---|
| 1654 | } rtems_filesystem_mount_configuration; |
---|
| 1655 | |
---|
| 1656 | extern const rtems_filesystem_mount_configuration |
---|
| 1657 | rtems_filesystem_root_configuration; |
---|
[9da9cf4a] | 1658 | |
---|
| 1659 | /** @} */ |
---|
| 1660 | |
---|
| 1661 | /** |
---|
| 1662 | * @defgroup Termios Termios |
---|
| 1663 | * |
---|
| 1664 | * @ingroup LibIO |
---|
| 1665 | * |
---|
| 1666 | * @brief Termios |
---|
| 1667 | * |
---|
| 1668 | * @{ |
---|
[161e1b3f] | 1669 | */ |
---|
[07a3253d] | 1670 | |
---|
[161e1b3f] | 1671 | typedef struct rtems_termios_callbacks { |
---|
[07a3253d] | 1672 | int (*firstOpen)(int major, int minor, void *arg); |
---|
| 1673 | int (*lastClose)(int major, int minor, void *arg); |
---|
| 1674 | int (*pollRead)(int minor); |
---|
[89926c9] | 1675 | ssize_t (*write)(int minor, const char *buf, size_t len); |
---|
[07a3253d] | 1676 | int (*setAttributes)(int minor, const struct termios *t); |
---|
| 1677 | int (*stopRemoteTx)(int minor); |
---|
| 1678 | int (*startRemoteTx)(int minor); |
---|
| 1679 | int outputUsesInterrupts; |
---|
[161e1b3f] | 1680 | } rtems_termios_callbacks; |
---|
| 1681 | |
---|
[ae35953d] | 1682 | void rtems_termios_initialize (void); |
---|
[07a3253d] | 1683 | |
---|
[1f5d2ba] | 1684 | /* |
---|
| 1685 | * CCJ: Change before opening a tty. Newer code from Eric is coming |
---|
| 1686 | * so extra work to handle an open tty is not worth it. If the tty |
---|
| 1687 | * is open, close then open it again. |
---|
| 1688 | */ |
---|
| 1689 | rtems_status_code rtems_termios_bufsize ( |
---|
[96406152] | 1690 | size_t cbufsize, /* cooked buffer size */ |
---|
| 1691 | size_t raw_input, /* raw input buffer size */ |
---|
| 1692 | size_t raw_output /* raw output buffer size */ |
---|
[1f5d2ba] | 1693 | ); |
---|
| 1694 | |
---|
[ae35953d] | 1695 | rtems_status_code rtems_termios_open ( |
---|
[161e1b3f] | 1696 | rtems_device_major_number major, |
---|
| 1697 | rtems_device_minor_number minor, |
---|
| 1698 | void *arg, |
---|
| 1699 | const rtems_termios_callbacks *callbacks |
---|
[07a3253d] | 1700 | ); |
---|
| 1701 | |
---|
| 1702 | rtems_status_code rtems_termios_close( |
---|
| 1703 | void *arg |
---|
| 1704 | ); |
---|
| 1705 | |
---|
| 1706 | rtems_status_code rtems_termios_read( |
---|
| 1707 | void *arg |
---|
| 1708 | ); |
---|
| 1709 | |
---|
| 1710 | rtems_status_code rtems_termios_write( |
---|
| 1711 | void *arg |
---|
| 1712 | ); |
---|
| 1713 | |
---|
| 1714 | rtems_status_code rtems_termios_ioctl( |
---|
| 1715 | void *arg |
---|
| 1716 | ); |
---|
| 1717 | |
---|
| 1718 | int rtems_termios_enqueue_raw_characters( |
---|
| 1719 | void *ttyp, |
---|
[18124551] | 1720 | const char *buf, |
---|
[07a3253d] | 1721 | int len |
---|
| 1722 | ); |
---|
| 1723 | |
---|
| 1724 | int rtems_termios_dequeue_characters( |
---|
| 1725 | void *ttyp, |
---|
| 1726 | int len |
---|
| 1727 | ); |
---|
| 1728 | |
---|
[9da9cf4a] | 1729 | /** @} */ |
---|
[eaee27b] | 1730 | |
---|
[6c0fcd4] | 1731 | /** |
---|
| 1732 | * @brief The pathconf setting for a file system. |
---|
| 1733 | */ |
---|
| 1734 | #define rtems_filesystem_pathconf(_mte) ((_mte)->pathconf_limits_and_options) |
---|
| 1735 | |
---|
| 1736 | /** |
---|
| 1737 | * @brief The type of file system. Its name. |
---|
| 1738 | */ |
---|
| 1739 | #define rtems_filesystem_type(_mte) ((_mte)->type) |
---|
| 1740 | |
---|
| 1741 | /** |
---|
| 1742 | * @brief The mount point of a file system. |
---|
| 1743 | */ |
---|
| 1744 | #define rtems_filesystem_mount_point(_mte) ((_mte)->target) |
---|
| 1745 | |
---|
| 1746 | /** |
---|
| 1747 | * @brief The device entry of a file system. |
---|
| 1748 | */ |
---|
| 1749 | #define rtems_filesystem_mount_device(_mte) ((_mte)->dev) |
---|
| 1750 | |
---|
[80c2966] | 1751 | #ifdef __cplusplus |
---|
| 1752 | } |
---|
| 1753 | #endif |
---|
| 1754 | |
---|
[b06e68ef] | 1755 | #endif /* _RTEMS_LIBIO_H */ |
---|