source: rtems/cpukit/libcsupport/src/mount-mgr.c @ 00bf6744

4.10
Last change on this file since 00bf6744 was 00bf6744, checked in by Sebastian Huber <sebastian.huber@…>, on Jul 1, 2010 at 2:10:54 PM

2010-06-07 Sebastian Huber <sebastian.huber@…>

  • libcsupport/include/rtems/libio_.h: Declare rtems_filesystem_mount_table_control.
  • libcsupport/include/rtems/libio.h: Removed rtems_filesystem_table_first(), rtems_filesystem_table_next() and rtems_filesystem_table_node_t declarations. Declare rtems_per_filesystem_routine, rtems_filesystem_iterate() and rtems_filesystem_get_mount_handler().
  • libcsupport/src/mount.c: Added rtems_filesystem_mounts_first() and rtems_filesystem_mounts_next(). Simplify mount(). Removed rtems_filesystem_mount_table_control_init. Use rtems_filesystem_get_mount_handler().
  • libcsupport/src/mount-mgr.c: Removed rtems_filesystem_mounts_first() and rtems_filesystem_mounts_next(). Added rtems_filesystem_iterate() and rtems_filesystem_get_mount_handler(). Use rtems_libio_lock() and rtems_libio_unlock();
  • sapi/include/confdefs.h, libmisc/shell/main_mount.c: Update for mount API changes.

2010-06-07 Bharath Suri <bharath.s.jois@…>

  • libcsupport/include/rtems/libio_.h: Removed macros rtems_filesystem_is_separator rtems_filesystem_get_start_loc rtems_filesystem_get_sym_start_loc and added them as files under libcsupport/src/
  • libcsupport/src/: Added new files libcsupport/src/sup_fs_get_start_loc.c libcsupport/src/sup_fs_get_sym_start_loc.c libcsupport/src/sup_fs_is_separator.c
  • libcsupport/Makefile.am: Changes to accommodate new files under libcsupport/src/
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 *  mount()
3 *
4 *  Mange the mount table. You can iterate on mounts and file systems, as well
5 *  as add and remove file systems not in the file system confiration table.
6 *
7 *  COPYRIGHT (c) Chris Johns <chrisj@rtems.org> 2010.
8 *
9 *  Copyright (c) 2010 embedded brains GmbH.
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 *  $Id$
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <sys/types.h>
23#include <sys/stat.h>
24#include <rtems/chain.h>
25#include <rtems/seterr.h>
26#include <fcntl.h>
27#include <unistd.h>
28#include <errno.h>
29#include <stdlib.h>
30#include <string.h>
31#include <assert.h>
32
33#include <rtems/libio_.h>
34
35typedef struct {
36  rtems_chain_node node;
37  rtems_filesystem_table_t entry;
38} filesystem_node;
39
40RTEMS_CHAIN_DEFINE_EMPTY(filesystem_chain);
41
42void
43rtems_filesystem_iterate(
44  rtems_per_filesystem_routine routine,
45  void *routine_arg
46)
47{
48  const rtems_filesystem_table_t *table_entry = &rtems_filesystem_table [0];
49  rtems_chain_node *node = NULL;
50
51  while ( table_entry->type ) {
52    if ( !(*routine)( table_entry, routine_arg ) ) {
53      break;
54    }
55
56    ++table_entry;
57  }
58
59  rtems_libio_lock();
60  for (
61    node = rtems_chain_first( &filesystem_chain );
62    !rtems_chain_is_tail( &filesystem_chain, node );
63    node = rtems_chain_next( node )
64  ) {
65    const filesystem_node *fsn = (filesystem_node *) node;
66
67    if ( !(*routine)( &fsn->entry, routine_arg ) ) {
68      break;
69    }
70  }
71  rtems_libio_unlock();
72}
73
74typedef struct {
75  const char *type;
76  rtems_filesystem_fsmount_me_t mount_h;
77} find_arg;
78
79static bool find_handler(const rtems_filesystem_table_t *entry, void *arg)
80{
81  find_arg *fa = arg;
82
83  if ( strcmp( entry->type, fa->type ) != 0 ) {
84    return true;
85  } else {
86    fa->mount_h = entry->mount_h;
87
88    return true;
89  }
90}
91
92rtems_filesystem_fsmount_me_t
93rtems_filesystem_get_mount_handler(
94  const char *type
95)
96{
97  find_arg fa = {
98    .type = type,
99    .mount_h = NULL
100  };
101
102  if ( type != NULL ) {
103    rtems_filesystem_iterate( find_handler, &fa );
104  }
105
106  return fa.mount_h;
107}
108
109int
110rtems_filesystem_register(
111  const char                    *type,
112  rtems_filesystem_fsmount_me_t  mount_h
113)
114{
115  size_t fsn_size = sizeof( filesystem_node ) + strlen(type) + 1;
116  filesystem_node *fsn = malloc( fsn_size );
117  char *type_storage = (char *) fsn + sizeof( filesystem_node );
118
119  if ( fsn == NULL )
120    rtems_set_errno_and_return_minus_one( ENOMEM );
121
122  strcpy(type_storage, type);
123  fsn->entry.type = type_storage;
124  fsn->entry.mount_h = mount_h;
125
126  rtems_libio_lock();
127  if ( rtems_filesystem_get_mount_handler( type ) == NULL ) {
128    rtems_chain_append( &filesystem_chain, &fsn->node );
129  } else {
130    rtems_libio_unlock();
131    free( fsn );
132
133    rtems_set_errno_and_return_minus_one( EINVAL );
134  }
135  rtems_libio_unlock();
136
137  return 0;
138}
139
140int
141rtems_filesystem_unregister(
142  const char *type
143)
144{
145  rtems_chain_node *node = NULL;
146
147  if ( type == NULL ) {
148    rtems_set_errno_and_return_minus_one( EINVAL );
149  }
150
151  rtems_libio_lock();
152  for (
153    node = rtems_chain_first( &filesystem_chain );
154    !rtems_chain_is_tail( &filesystem_chain, node );
155    node = rtems_chain_next( node )
156  ) {
157    filesystem_node *fsn = (filesystem_node *) node;
158
159    if ( strcmp( fsn->entry.type, type ) == 0 ) {
160      rtems_chain_extract( node );
161      free( fsn );
162      rtems_libio_unlock();
163
164      return 0;
165    }
166  }
167  rtems_libio_unlock();
168
169  rtems_set_errno_and_return_minus_one( ENOENT );
170}
Note: See TracBrowser for help on using the repository browser.