source: rtems/cpukit/libcsupport/src/privateenv.c @ 29e92b0

4.104.115
Last change on this file since 29e92b0 was 29e92b0, checked in by Chris Johns <chrisj@…>, on 05/31/10 at 13:56:37

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.2 KB
Line 
1/*
2 *  Instantiate a private user environment for the calling thread.
3 *
4 *  Submitted by: fernando.ruiz@ctv.es (correo@fernando-ruiz.com)
5 *
6 *  COPYRIGHT (c) 1989-2000.
7 *  On-Line Applications Research Corporation (OAR).
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 <stdlib.h>     /* free */
21
22#include <rtems.h>
23#include <rtems/chain.h>
24#include <rtems/libio.h>
25#include <rtems/libio_.h>
26
27/* cleanup a user environment
28 * NOTE: this must be called with
29 *       thread dispatching disabled!
30 */
31static void
32free_user_env(void *venv)
33{
34  rtems_user_env_t *env = (rtems_user_env_t*) venv ;
35
36        if (env != &rtems_global_user_env
37#ifdef HAVE_USERENV_REFCNT
38                && --env->refcnt <= 0
39#endif
40                ) {
41                rtems_filesystem_freenode( &env->current_directory);
42                rtems_filesystem_freenode( &env->root_directory);
43                free(env);
44        }
45}
46
47rtems_status_code rtems_libio_set_private_env(void) {
48  rtems_status_code                                     sc;
49  rtems_id                                              task_id;
50  rtems_filesystem_location_info_t              loc;
51
52  sc=rtems_task_ident(RTEMS_SELF,0,&task_id);
53  if (sc != RTEMS_SUCCESSFUL) return sc;
54
55  /* Only for the first time a malloc is necesary */
56  if (rtems_current_user_env==&rtems_global_user_env) {
57   rtems_user_env_t     *tmp = malloc(sizeof(rtems_user_env_t));
58   if (!tmp)
59     return RTEMS_NO_MEMORY;
60
61#ifdef HAVE_USERENV_REFCNT
62   tmp->refcnt = 1;
63#endif
64
65   sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,(void(*)(void *))free_user_env);
66   if (sc != RTEMS_SUCCESSFUL) {
67         /* don't use free_user_env because the pathlocs are
68          * not initialized yet
69          */
70     free(tmp);
71     return sc;
72   }
73   rtems_current_user_env = tmp;
74  };
75
76  *rtems_current_user_env = rtems_global_user_env; /* get the global values*/
77  rtems_current_user_env->task_id=task_id;         /* mark the local values*/
78
79  /* Clone the pathlocs. In contrast to most other
80   * code we must _not_ free the original locs because
81   * what we are trying to do here is forking off
82   * clones. The reason is a pathloc can be allocated by the
83   * file system and needs to be freed when deleting the environment.
84   */
85
86  rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0);
87  rtems_filesystem_root    = loc;
88  rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0);
89  rtems_filesystem_current = loc;
90
91  return RTEMS_SUCCESSFUL;
92}
93
94/*
95 *  Share a same private environment beetween two task:
96 *   Task_id (remote) and RTEMS_SELF(current).
97 */
98
99/* NOTE:
100 *
101 * THIS CODE HAS NO PROTECTION IMPLEMENTED
102 *
103 * Tasks who wish to share their environments must
104 *
105 *  a) assert that no participants are concurrently
106 *     executing
107 *     libio_share_private_env() and/or libio_set_private_env()
108 *
109 *  b) mutex access to rtems_filesystem_current, rtems_filesytem_root
110 *     while changing any of those (chdir(), chroot()).
111 */
112
113#ifndef HAVE_USERENV_REFCNT
114rtems_status_code rtems_libio_share_private_env(rtems_id task_id) {
115  rtems_status_code  sc;
116  rtems_user_env_t * shared_user_env;
117  rtems_id           current_task_id;
118
119  sc=rtems_task_ident(RTEMS_SELF,0,&current_task_id);
120  if (sc != RTEMS_SUCCESSFUL) return sc;
121
122  if (rtems_current_user_env->task_id==current_task_id) {
123   /* kill the current user env & task_var*/
124        rtems_user_env_t        *tmp = rtems_current_user_env;
125   sc = rtems_task_variable_delete(RTEMS_SELF,(void*)&rtems_current_user_env);
126   if (sc != RTEMS_SUCCESSFUL) return sc;
127   free_user_env(tmp);
128  };
129
130  /* AT THIS POINT, rtems_current_user_env is DANGLING */
131
132  sc = rtems_task_variable_get(task_id,(void*)&rtems_current_user_env,
133                                       (void*)&shared_user_env       );
134  if (sc != RTEMS_SUCCESSFUL)
135    goto bailout;
136
137  sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,free_user_env);
138  if (sc != RTEMS_SUCCESSFUL)
139    goto bailout;
140
141  /* the current_user_env is the same pointer that remote env */
142  rtems_current_user_env = shared_user_env;
143
144  /* increase the reference count */
145#ifdef HAVE_USERENV_REFCNT
146  rtems_current_user_env->refcnt++;
147#endif
148
149  return RTEMS_SUCCESSFUL;
150
151bailout:
152  /* fallback to the global env */
153  rtems_current_user_env = &rtems_global_user_env;
154  return sc;
155}
156#endif
Note: See TracBrowser for help on using the repository browser.