1 | /* |
---|
2 | * unmount() - Unmount a File System |
---|
3 | * |
---|
4 | * This routine is not defined in the POSIX 1003.1b standard but |
---|
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 | * |
---|
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.com/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 | int unmount( const char *path ) |
---|
38 | { |
---|
39 | int rv = 0; |
---|
40 | rtems_filesystem_eval_path_context_t ctx; |
---|
41 | int eval_flags = RTEMS_FS_FOLLOW_LINK; |
---|
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 ) ) { |
---|
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; |
---|
50 | |
---|
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 ); |
---|
55 | |
---|
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; |
---|
64 | } |
---|
65 | } else { |
---|
66 | errno = EACCES; |
---|
67 | rv = -1; |
---|
68 | } |
---|
69 | |
---|
70 | rtems_filesystem_eval_path_cleanup( &ctx ); |
---|
71 | |
---|
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 | |
---|
86 | return rv; |
---|
87 | } |
---|