1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Delete Partition |
---|
5 | * @ingroup ClassicPart |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2014. |
---|
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 <rtems/rtems/partimpl.h> |
---|
22 | #include <rtems/rtems/attrimpl.h> |
---|
23 | |
---|
24 | rtems_status_code rtems_partition_delete( |
---|
25 | rtems_id id |
---|
26 | ) |
---|
27 | { |
---|
28 | Partition_Control *the_partition; |
---|
29 | ISR_lock_Context lock_context; |
---|
30 | |
---|
31 | _Objects_Allocator_lock(); |
---|
32 | the_partition = _Partition_Get( id, &lock_context ); |
---|
33 | |
---|
34 | if ( the_partition == NULL ) { |
---|
35 | _Objects_Allocator_unlock(); |
---|
36 | |
---|
37 | #if defined(RTEMS_MULTIPROCESSING) |
---|
38 | if ( _Partition_MP_Is_remote( id ) ) { |
---|
39 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
40 | } |
---|
41 | #endif |
---|
42 | |
---|
43 | return RTEMS_INVALID_ID; |
---|
44 | } |
---|
45 | |
---|
46 | _Partition_Acquire_critical( the_partition, &lock_context ); |
---|
47 | |
---|
48 | if ( the_partition->number_of_used_blocks != 0 ) { |
---|
49 | _Partition_Release( the_partition, &lock_context ); |
---|
50 | _Objects_Allocator_unlock(); |
---|
51 | return RTEMS_RESOURCE_IN_USE; |
---|
52 | } |
---|
53 | |
---|
54 | _Objects_Close( &_Partition_Information, &the_partition->Object ); |
---|
55 | _Partition_Release( the_partition, &lock_context ); |
---|
56 | |
---|
57 | #if defined(RTEMS_MULTIPROCESSING) |
---|
58 | if ( _Attributes_Is_global( the_partition->attribute_set ) ) { |
---|
59 | _Objects_MP_Close( |
---|
60 | &_Partition_Information, |
---|
61 | the_partition->Object.id |
---|
62 | ); |
---|
63 | |
---|
64 | _Partition_MP_Send_process_packet( |
---|
65 | PARTITION_MP_ANNOUNCE_DELETE, |
---|
66 | the_partition->Object.id, |
---|
67 | 0, /* Not used */ |
---|
68 | 0 /* Not used */ |
---|
69 | ); |
---|
70 | } |
---|
71 | #endif |
---|
72 | |
---|
73 | _Partition_Destroy( the_partition ); |
---|
74 | _Partition_Free( the_partition ); |
---|
75 | _Objects_Allocator_unlock(); |
---|
76 | return RTEMS_SUCCESSFUL; |
---|
77 | } |
---|