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

4.115
Last change on this file since 40d062f5 was 40d062f5, checked in by Sebastian Huber <sebastian.huber@…>, on 01/28/15 at 17:47:19

IMFS: Reduce IMFS node types

Provide only types used by IMFS_mknod().

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