source: rtems/cpukit/libcsupport/include/rtems/libio.h @ 8cb2882

4.115
Last change on this file since 8cb2882 was 8cb2882, checked in by Sebastian Huber <sebastian.huber@…>, on 10/31/13 at 14:00:20

Filesystem: Add kernel event filter handler

This handler is necessary to implement the KQUEUE(2) system calls.

Add <sys/event.h> from FreeBSD 8.4.

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