source: rtems/cpukit/libcsupport/src/unmount.c @ 847ad44

4.115
Last change on this file since 847ad44 was 847ad44, checked in by Sebastian Huber <sebastian.huber@…>, on 05/23/12 at 09:39:50

Filesystem: Wait for unmount() to finish

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[07a3253d]1/*
2 *  unmount() - Unmount a File System
3 *
[50f32b11]4 *  This routine is not defined in the POSIX 1003.1b standard but
[07a3253d]5 *  in some form is supported on most UNIX and POSIX systems.  This
6 *  routine is necessary to mount instantiations of a file system
7 *  into the file system name space.
8 *
[71c012af]9 *  COPYRIGHT (c) 1989-2010.
[07a3253d]10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
[0eae36c7]14 *  http://www.rtems.com/license/LICENSE.
[07a3253d]15 */
16
[9c49db4]17#if HAVE_CONFIG_H
[3b7c123]18  #include "config.h"
[9c49db4]19#endif
20
[07a3253d]21#include <errno.h>
22
[3ba74c73]23#include <rtems/libio_.h>
[07a3253d]24
[847ad44]25static bool contains_root_or_current_directory(
26  const rtems_filesystem_mount_table_entry_t *mt_entry
27)
28{
29  const rtems_filesystem_location_info_t *root =
30    &rtems_filesystem_root->location;
31  const rtems_filesystem_location_info_t *current =
32    &rtems_filesystem_current->location;
33
34  return mt_entry == root->mt_entry || mt_entry == current->mt_entry;
35}
36
[3b7c123]37int unmount( const char *path )
[9c30d6a9]38{
[3b7c123]39  int rv = 0;
40  rtems_filesystem_eval_path_context_t ctx;
[2563410]41  int eval_flags = RTEMS_FS_FOLLOW_LINK;
[3b7c123]42  const rtems_filesystem_location_info_t *currentloc =
43    rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
44  rtems_filesystem_mount_table_entry_t *mt_entry = currentloc->mt_entry;
45
46  if ( rtems_filesystem_location_is_root( currentloc ) ) {
[847ad44]47    if ( !contains_root_or_current_directory( mt_entry ) ) {
48      const rtems_filesystem_operations_table *mt_point_ops =
49        mt_entry->mt_point_node->location.mt_entry->ops;
[da154e14]50
[847ad44]51      rv = (*mt_point_ops->unmount_h)( mt_entry );
52      if ( rv == 0 ) {
53        rtems_id self_task_id = rtems_task_self();
54        rtems_filesystem_mt_entry_declare_lock_context( lock_context );
[3b7c123]55
[847ad44]56        rtems_filesystem_mt_entry_lock( lock_context );
57        mt_entry->unmount_task = self_task_id;
58        mt_entry->mounted = false;
59        rtems_filesystem_mt_entry_unlock( lock_context );
60      }
61    } else {
62      errno = EBUSY;
63      rv = -1;
[3b7c123]64    }
65  } else {
66    errno = EACCES;
67    rv = -1;
[9c30d6a9]68  }
69
[3b7c123]70  rtems_filesystem_eval_path_cleanup( &ctx );
[07a3253d]71
[847ad44]72  if ( rv == 0 ) {
73    rtems_event_set out;
74    rtems_status_code sc = rtems_event_receive(
75      RTEMS_FILESYSTEM_UNMOUNT_EVENT,
76      RTEMS_EVENT_ALL | RTEMS_WAIT,
77      RTEMS_NO_TIMEOUT,
78      &out
79    );
80
81    if ( sc != RTEMS_SUCCESSFUL ) {
82      rtems_fatal_error_occurred( 0xdeadbeef );
83    }
84  }
85
[3b7c123]86  return rv;
[07a3253d]87}
Note: See TracBrowser for help on using the repository browser.