source: rtems/cpukit/libfs/src/imfs/imfs_make_generic_node.c @ c5392ef9

4.115
Last change on this file since c5392ef9 was c5392ef9, checked in by Sebastian Huber <sebastian.huber@…>, on 03/01/12 at 10:51:34

IMFS: Add make generic node support

Generic nodes are an alternative to standard drivers in RTEMS. The
handlers of a generic node are called with less overhead compared to the
standard driver operations. The usage of file system node handlers
enable more features like support for fsync() and fdatasync(). The
generic nodes use the reference counting of the IMFS. This provides
automatic node destruction when the last reference vanishes.

Extend type IMFS_types_union by new type IMFS_generic_t.

Extend enum IMFS_jnode_types_t by IMFS_GENERIC.

Add functions

o IMFS_make_generic_node(),
o IMFS_is_imfs_instance(),
o IMFS_generic_get_context_by_node(),
o IMFS_generic_get_context_by_location(), and
o IMFS_generic_get_context_by_iop().

New test fstests/fsimfsgeneric01.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Obere Lagerstr. 30
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.com/license/LICENSE.
13 */
14
15#if HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include "imfs.h"
20
21IMFS_jnode_t *IMFS_node_initialize_generic(
22  IMFS_jnode_t *node,
23  const IMFS_types_union *info
24)
25{
26  node->info.generic.context = info->generic.context;
27
28  return node;
29}
30
31bool IMFS_is_imfs_instance(
32  const rtems_filesystem_location_info_t *loc
33)
34{
35  const char *type = loc->mt_entry->type;
36
37  return strcmp(type, RTEMS_FILESYSTEM_TYPE_IMFS) == 0
38    || strcmp(type, RTEMS_FILESYSTEM_TYPE_MINIIMFS) == 0;
39}
40
41int IMFS_make_generic_node(
42  const char *path,
43  mode_t mode,
44  const IMFS_node_control *node_control,
45  void *context
46)
47{
48  int rv = 0;
49
50  mode &= ~rtems_filesystem_umask;
51
52  switch (mode & S_IFMT) {
53    case S_IFBLK:
54    case S_IFCHR:
55    case S_IFIFO:
56    case S_IFREG:
57      break;
58    default:
59      errno = EINVAL;
60      rv = -1;
61      break;
62  }
63 
64  if ( rv == 0 ) {
65    if ( node_control->imfs_type == IMFS_GENERIC ) {
66      rtems_filesystem_eval_path_context_t ctx;
67      int eval_flags = RTEMS_FS_FOLLOW_LINK
68        | RTEMS_FS_MAKE
69        | RTEMS_FS_EXCLUSIVE;
70      const rtems_filesystem_location_info_t *currentloc =
71        rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
72
73      if ( IMFS_is_imfs_instance( currentloc ) ) {
74        IMFS_types_union info;
75        IMFS_jnode_t *new_node;
76
77        info.generic.context = context;
78        new_node = IMFS_create_node_with_control(
79          currentloc,
80          node_control,
81          rtems_filesystem_eval_path_get_token( &ctx ),
82          rtems_filesystem_eval_path_get_tokenlen( &ctx ),
83          mode,
84          &info
85        );
86
87        if ( new_node != NULL ) {
88          IMFS_jnode_t *parent = currentloc->node_access;
89
90          IMFS_update_ctime( parent );
91          IMFS_update_mtime( parent );
92        } else {
93          rv = -1;
94        }
95      } else {
96        rtems_filesystem_eval_path_error( &ctx, ENOTSUP );
97        rv = -1;
98      }
99
100      rtems_filesystem_eval_path_cleanup( &ctx );
101    } else {
102      errno = EINVAL;
103      rv = -1;
104    }
105  }
106
107  return rv;
108}
Note: See TracBrowser for help on using the repository browser.