GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fxe_media_open.c Lines: 24 24 100.0 %
Date: 2024-01-10 21:53:23 Branches: 26 26 100.0 %

Line Branch Exec Source
1
/**************************************************************************/
2
/*                                                                        */
3
/*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4
/*                                                                        */
5
/*       This software is licensed under the Microsoft Software License   */
6
/*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7
/*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8
/*       and in the root directory of this software.                      */
9
/*                                                                        */
10
/**************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** FileX Component                                                       */
17
/**                                                                       */
18
/**   Media                                                               */
19
/**                                                                       */
20
/**************************************************************************/
21
/**************************************************************************/
22
23
#define FX_SOURCE_CODE
24
25
26
/* Include necessary system files.  */
27
28
#include "fx_api.h"
29
#include "fx_media.h"
30
#include "fx_system.h"
31
32
33
FX_CALLER_CHECKING_EXTERNS
34
35
36
/**************************************************************************/
37
/*                                                                        */
38
/*  FUNCTION                                               RELEASE        */
39
/*                                                                        */
40
/*    _fxe_media_open                                     PORTABLE C      */
41
/*                                                           6.1          */
42
/*  AUTHOR                                                                */
43
/*                                                                        */
44
/*    William E. Lamie, Microsoft Corporation                             */
45
/*                                                                        */
46
/*  DESCRIPTION                                                           */
47
/*                                                                        */
48
/*    This function checks for errors in the media open call.             */
49
/*                                                                        */
50
/*  INPUT                                                                 */
51
/*                                                                        */
52
/*    media_ptr                             Media control block pointer   */
53
/*    media_name                            Pointer to media name string  */
54
/*    media_driver                          Media driver entry function   */
55
/*    driver_info_ptr                       Optional information pointer  */
56
/*                                            supplied to media driver    */
57
/*    memory_ptr                            Pointer to memory used by the */
58
/*                                            FileX for this media.       */
59
/*    memory_size                           Size of media memory - must   */
60
/*                                            at least 512 bytes and      */
61
/*                                            one sector size.            */
62
/*    media_control_block_size              Size of FX_MEDIA structure    */
63
/*                                                                        */
64
/*  OUTPUT                                                                */
65
/*                                                                        */
66
/*    FX_PTR_ERROR                          One or more input parameters  */
67
/*                                            are NULL                    */
68
/*    status                                Actual completion status      */
69
/*                                                                        */
70
/*  CALLS                                                                 */
71
/*                                                                        */
72
/*    tx_thread_identify                    Get current thread            */
73
/*    tx_thread_preemption_change           Disable/restore preemption    */
74
/*    _fx_media_open                        Actual media open service     */
75
/*                                                                        */
76
/*  CALLED BY                                                             */
77
/*                                                                        */
78
/*    Application Code                                                    */
79
/*                                                                        */
80
/*  RELEASE HISTORY                                                       */
81
/*                                                                        */
82
/*    DATE              NAME                      DESCRIPTION             */
83
/*                                                                        */
84
/*  05-19-2020     William E. Lamie         Initial Version 6.0           */
85
/*  09-30-2020     William E. Lamie         Modified comment(s),          */
86
/*                                            resulting in version 6.1    */
87
/*                                                                        */
88
/**************************************************************************/
89
8616
UINT  _fxe_media_open(FX_MEDIA *media_ptr, CHAR *media_name,
90
                      VOID (*media_driver)(FX_MEDIA *), VOID *driver_info_ptr,
91
                      VOID *memory_ptr, ULONG memory_size, UINT media_control_block_size)
92
{
93
94
UINT       status;
95
ULONG      temp;
96
FX_MEDIA  *current_media;
97
ULONG      open_count;
98
99
#ifndef FX_SINGLE_THREAD
100
TX_THREAD *current_thread;
101
UINT       old_threshold;
102
#endif
103
104
105
    /* Check for invalid input pointers.  */
106


8616
    if ((media_ptr == FX_NULL) || (media_driver == FX_NULL) || (memory_ptr == FX_NULL) || (media_control_block_size != sizeof(FX_MEDIA)))
107
    {
108
409
        return(FX_PTR_ERROR);
109
    }
110
111
    /* Check for a valid caller.  */
112

8207
    FX_CALLER_CHECKING_CODE
113
114
    /* Check for proper size of the logical sector cache.  */
115
7799
    temp =  _fx_system_media_max_sector_cache;
116
117
    /* Isolate the lowest set bit.  */
118
7799
    temp =  (temp & ((~temp) + ((ULONG) 1)));
119
120
    /* If FX_MAX_SECTOR_CACHE is a power of 2, the value of temp should be unchanged.  */
121

7799
    if ((temp == 1) || (temp != _fx_system_media_max_sector_cache))
122
    {
123
124
        /* Not a power of 2, return an error.  */
125
272
        return(FX_MEDIA_INVALID);
126
    }
127
128
    /* Check for proper size of the FAT cache.  */
129
7527
    temp =  _fx_system_media_max_fat_cache;
130
131
    /* Isolate the lowest set bit.  */
132
7527
    temp =  (temp & ((~temp) + ((ULONG) 1)));
133
134
    /* If FX_MAX_FAT_CACHE is a power of 2, the value of temp should be unchanged.  */
135

7527
    if ((temp == 1) || (temp != _fx_system_media_max_fat_cache))
136
    {
137
138
        /* Not a power of 2, return an error.  */
139
272
        return(FX_MEDIA_INVALID);
140
    }
141
142
#ifndef FX_SINGLE_THREAD
143
144
    /* Pickup current thread pointer. At this point we know the current thread pointer is non-null since
145
       it was checked by code in FX_CALLER_CHECKING_CODE macro.  */
146
7255
    current_thread =  tx_thread_identify();
147
148
    /* Disable preemption temporarily.  */
149
7255
    tx_thread_preemption_change(current_thread, 0, &old_threshold);
150
#endif
151
152
    /* Loop to check for the media already opened.  */
153
7255
    current_media =  _fx_system_media_opened_ptr;
154
7255
    open_count =     _fx_system_media_opened_count;
155
7260
    while (open_count--)
156
    {
157
158
        /* Is the new media pointer already open?  */
159
6
        if (media_ptr == current_media)
160
        {
161
162
#ifndef FX_SINGLE_THREAD
163
164
            /* Restore preemption.  */
165
1
            tx_thread_preemption_change(current_thread, old_threshold, &old_threshold);
166
#endif
167
168
            /* Duplicate media open, return an error!  */
169
1
            return(FX_PTR_ERROR);
170
        }
171
172
        /* Move to next entry.  */
173
5
        current_media =  current_media -> fx_media_opened_next;
174
    }
175
176
#ifndef FX_SINGLE_THREAD
177
178
    /* Restore preemption.  */
179
7254
    tx_thread_preemption_change(current_thread, old_threshold, &old_threshold);
180
#endif
181
182
    /* Call actual media open service.  */
183
7254
    status =  _fx_media_open(media_ptr, media_name, media_driver, driver_info_ptr,
184
                             memory_ptr, memory_size);
185
186
    /* Return status.  */
187
7254
    return(status);
188
}
189