1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Unmount a File System |
---|
5 | * @ingroup libcsupport |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2010. |
---|
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 |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <errno.h> |
---|
22 | |
---|
23 | #include <rtems/libio_.h> |
---|
24 | |
---|
25 | static 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 | |
---|
37 | /** |
---|
38 | * This routine is not defined in the POSIX 1003.1b standard but |
---|
39 | * in some form is supported on most UNIX and POSIX systems. This |
---|
40 | * routine is necessary to mount instantiations of a file system |
---|
41 | * into the file system name space. |
---|
42 | */ |
---|
43 | int unmount( const char *path ) |
---|
44 | { |
---|
45 | int rv = 0; |
---|
46 | rtems_filesystem_eval_path_context_t ctx; |
---|
47 | int eval_flags = RTEMS_FS_FOLLOW_LINK; |
---|
48 | const rtems_filesystem_location_info_t *currentloc = |
---|
49 | rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); |
---|
50 | rtems_filesystem_mount_table_entry_t *mt_entry = currentloc->mt_entry; |
---|
51 | |
---|
52 | if ( rtems_filesystem_location_is_instance_root( currentloc ) ) { |
---|
53 | if ( !contains_root_or_current_directory( mt_entry ) ) { |
---|
54 | const rtems_filesystem_operations_table *mt_point_ops = |
---|
55 | mt_entry->mt_point_node->location.mt_entry->ops; |
---|
56 | |
---|
57 | rv = (*mt_point_ops->unmount_h)( mt_entry ); |
---|
58 | if ( rv == 0 ) { |
---|
59 | rtems_id self_task_id = rtems_task_self(); |
---|
60 | rtems_filesystem_mt_entry_declare_lock_context( lock_context ); |
---|
61 | |
---|
62 | rtems_filesystem_mt_entry_lock( lock_context ); |
---|
63 | mt_entry->unmount_task = self_task_id; |
---|
64 | mt_entry->mounted = false; |
---|
65 | rtems_filesystem_mt_entry_unlock( lock_context ); |
---|
66 | } |
---|
67 | } else { |
---|
68 | errno = EBUSY; |
---|
69 | rv = -1; |
---|
70 | } |
---|
71 | } else { |
---|
72 | errno = EACCES; |
---|
73 | rv = -1; |
---|
74 | } |
---|
75 | |
---|
76 | rtems_filesystem_eval_path_cleanup( &ctx ); |
---|
77 | |
---|
78 | if ( rv == 0 ) { |
---|
79 | rtems_status_code sc = rtems_event_transient_receive( |
---|
80 | RTEMS_WAIT, |
---|
81 | RTEMS_NO_TIMEOUT |
---|
82 | ); |
---|
83 | |
---|
84 | if ( sc != RTEMS_SUCCESSFUL ) { |
---|
85 | rtems_fatal_error_occurred( 0xdeadbeef ); |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | return rv; |
---|
90 | } |
---|