source: rtems/cpukit/libcsupport/src/mount-mgr.c @ 0b701e6

4.104.115
Last change on this file since 0b701e6 was 14724574, checked in by Chris Johns <chrisj@…>, on 05/31/10 at 14:03:41

2010-05-31 Chris Johns <chrisj@…>

  • libcsupport/Makefile.am: Add mount-mgr.c.
  • libcsupport/src/mount-mgr.c: New.
  • include/rtems/fs.h: Added rtems_filesystem_location_mount.
  • libcsupport/include/rtems/libio.h, libcsupport/src/mount.c: New mount interface. It is similar to Linux.
  • libcsupport/include/rtems/libio_.h: Remove the init_fs_mount_table call.
  • libcsupport/src/base_fs.c: Remove init_fs_mount_table_call. Use the new mount call. Remove setting the root node in the global pathloc. Mount does this now.
  • libcsupport/src/privateenv.c: Remove the hack to set the root mount table entry in the environment.
  • libcsupport/src/unmount.cL Free the target string.
  • libblock/src/bdpart-mount.c: New mount API.
  • libfs/src/devfs/devfs.h, libfs/src/devfs/devfs_init.c, libfs/src/dosfs/dosfs.h, libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_init.c, libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c, libfs/src/imfs/imfs_init.c, libfs/src/imfs/miniimfs_init.c, libfs/src/nfsclient/src/librtemsNfs.h, libfs/src/rfs/rtems-rfs-rtems.c, libfs/src/rfs/rtems-rfs.h, libnetworking/lib/ftpfs.c, libnetworking/rtems/ftpfs.h, libnetworking/rtems/tftp.h: New mount_h API.
  • libfs/src/devfs/devfs_eval.c: Local include of extern ops.
  • libfs/src/nfsclient/src/nfs.c: New mount API. Removed the mount me call and fixed the initialisation to happen when mounting.
  • libmisc/Makefile.am, libmisc/shell/shellconfig.h: Remove mount filesystem files.
  • libmisc/fsmount/fsmount.c, libmisc/fsmount/fsmount.h: Updated to the new mount table values.
  • libmisc/shell/main_mount_ftp.c, libmisc/shell/main_mount_msdos.c, libmisc/shell/main_mount_rfs.c, libmisc/shell/main_mount_tftp.c: Removed.
  • libmisc/shell/main_mount.c: Use the new mount API. Also access the file system table for the file system types.
  • libnetworking/lib/tftpDriver.c: Updated to the new mount API. Fixed to allow mounting from any mount point. Also can now have more than file system mounted.
  • sapi/include/confdefs.h: Add file system configuration support.
  • Property mode set to 100644
File size: 4.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 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 *  $Id$
14 */
15
16#if HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include <sys/types.h>
21#include <sys/stat.h>
22#include <rtems/chain.h>
23#include <rtems/seterr.h>
24#include <fcntl.h>
25#include <unistd.h>
26#include <errno.h>
27#include <stdlib.h>
28#include <string.h>
29#include <assert.h>
30
31#include <rtems/libio_.h>
32
33/*
34 * External defined by confdefs.h or the user.
35 */
36extern const rtems_filesystem_table_t configuration_filesystem_table[];
37
38/*
39 * Points to a list of filesystems added at runtime.
40 */
41extern rtems_chain_control *rtems_filesystem_table;
42
43/*
44 * Mount table list.
45 */
46extern rtems_chain_control rtems_filesystem_mount_table_control;
47extern bool                rtems_filesystem_mount_table_control_init;
48
49/*
50 * Get the first entry in the filesystem table.
51 */
52const rtems_filesystem_table_t*
53rtems_filesystem_table_first(
54  void
55)
56{
57  /*
58   * We can assume this because it is the root file system.
59   */
60  return &configuration_filesystem_table[0];
61}
62
63/*
64 * Get the next entry in the file system table.
65 */
66const rtems_filesystem_table_t*
67rtems_filesystem_table_next(
68  rtems_filesystem_table_t *entry
69)
70{
71  const rtems_filesystem_table_t* fs;
72
73  fs = rtems_filesystem_table_first( );
74 
75  while ( fs->type && ( fs != entry ) )
76    ++fs;
77 
78  if ( fs->type ) {
79    ++fs;
80    if ( fs->type )
81      return fs;
82  }
83
84  if ( rtems_filesystem_table ) {
85    rtems_chain_node* node;
86    for (node = rtems_chain_first( rtems_filesystem_table );
87         !rtems_chain_is_tail( rtems_filesystem_table, node);
88         node = rtems_chain_next( node )) {
89      rtems_filesystem_table_node_t* tnode;
90      tnode = (rtems_filesystem_table_node_t*) node;
91      if ( entry == &tnode->entry ) {
92        node = rtems_chain_next( node );
93        if ( !rtems_chain_is_tail( rtems_filesystem_table, node ) ) {
94          tnode = (rtems_filesystem_table_node_t*) node;
95          return &tnode->entry;
96        }
97      }
98    }
99  }
100 
101  return NULL;
102}
103
104/*
105 * Get the first entry in the mount table.
106 */
107rtems_filesystem_mount_table_entry_t*
108rtems_filesystem_mounts_first(
109  void
110)
111{
112  rtems_filesystem_mount_table_entry_t* entry = NULL;
113  if ( rtems_filesystem_mount_table_control_init ) {
114    if ( !rtems_chain_is_empty( &rtems_filesystem_mount_table_control ) )
115      entry = (rtems_filesystem_mount_table_entry_t*)
116        rtems_chain_first( &rtems_filesystem_mount_table_control );
117  }
118  return entry;
119}
120
121/*
122 * Get the next entry in the mount table.
123 */
124rtems_filesystem_mount_table_entry_t*
125rtems_filesystem_mounts_next(
126  rtems_filesystem_mount_table_entry_t *entry
127)
128{
129  if ( !rtems_filesystem_mount_table_control_init || !entry )
130    return NULL;
131  return (rtems_filesystem_mount_table_entry_t*) rtems_chain_next( &entry->Node );
132}
133
134/*
135 * Register a file system.
136 */
137int
138rtems_filesystem_register(
139  const char                    *type,
140  rtems_filesystem_fsmount_me_t  mount_h
141)
142{
143  rtems_filesystem_table_node_t *fs;
144  if ( !rtems_filesystem_table ) {
145    rtems_filesystem_table = malloc( sizeof( rtems_chain_control ) );
146    if ( !rtems_filesystem_table )
147      rtems_set_errno_and_return_minus_one( ENOMEM );
148    rtems_chain_initialize_empty ( rtems_filesystem_table );
149  }
150  fs = malloc( sizeof( rtems_filesystem_table_node_t ) );
151  if ( !fs )
152    rtems_set_errno_and_return_minus_one( ENOMEM );
153  fs->entry.type = strdup( type );
154  if ( !fs->entry.type ) {
155    free( fs );
156    rtems_set_errno_and_return_minus_one( ENOMEM );
157  }   
158  fs->entry.mount_h = mount_h;
159  rtems_chain_append( rtems_filesystem_table, &fs->node );
160  return 0;
161}
162
163/*
164 * Unregister a file system.
165 */
166int
167rtems_filesystem_unregister(
168  const char *type
169)
170{
171  if ( rtems_filesystem_table ) {
172    rtems_chain_node *node;
173    for (node = rtems_chain_first( rtems_filesystem_table );
174         !rtems_chain_is_tail( rtems_filesystem_table, node );
175         node = rtems_chain_next( node ) ) {
176      rtems_filesystem_table_node_t *fs;
177      fs = (rtems_filesystem_table_node_t*) node;
178      if ( strcmp( fs->entry.type, type ) == 0 ) {
179        rtems_chain_extract( node );
180        free( (void*) fs->entry.type );
181        free( fs );
182        return 0;
183      }
184    }
185  }
186  rtems_set_errno_and_return_minus_one( ENOENT );
187}
Note: See TracBrowser for help on using the repository browser.