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 | int unmount( const char *path ) |
---|
26 | { |
---|
27 | int rv = 0; |
---|
28 | rtems_filesystem_eval_path_context_t ctx; |
---|
29 | int eval_flags = RTEMS_FS_FOLLOW_LINK; |
---|
30 | const rtems_filesystem_location_info_t *currentloc = |
---|
31 | rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); |
---|
32 | rtems_filesystem_mount_table_entry_t *mt_entry = currentloc->mt_entry; |
---|
33 | |
---|
34 | if ( rtems_filesystem_location_is_root( currentloc ) ) { |
---|
35 | const rtems_filesystem_operations_table *mt_point_ops = |
---|
36 | mt_entry->mt_point_node->location.mt_entry->ops; |
---|
37 | |
---|
38 | rv = (*mt_point_ops->unmount_h)( mt_entry ); |
---|
39 | if ( rv == 0 ) { |
---|
40 | rtems_filesystem_mt_entry_declare_lock_context( lock_context ); |
---|
41 | |
---|
42 | rtems_filesystem_mt_entry_lock( lock_context ); |
---|
43 | mt_entry->mounted = false; |
---|
44 | rtems_filesystem_mt_entry_unlock( lock_context ); |
---|
45 | } |
---|
46 | } else { |
---|
47 | errno = EACCES; |
---|
48 | rv = -1; |
---|
49 | } |
---|
50 | |
---|
51 | rtems_filesystem_eval_path_cleanup( &ctx ); |
---|
52 | |
---|
53 | return rv; |
---|
54 | } |
---|