GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fxe_file_open.c Lines: 17 17 100.0 %
Date: 2026-03-06 18:49:02 Branches: 24 24 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** FileX Component                                                       */
17
/**                                                                       */
18
/**   File                                                                */
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_file.h"
30
31
32
FX_CALLER_CHECKING_EXTERNS
33
34
35
/**************************************************************************/
36
/*                                                                        */
37
/*  FUNCTION                                               RELEASE        */
38
/*                                                                        */
39
/*    _fxe_file_open                                      PORTABLE C      */
40
/*                                                           6.1          */
41
/*  AUTHOR                                                                */
42
/*                                                                        */
43
/*    William E. Lamie, Microsoft Corporation                             */
44
/*                                                                        */
45
/*  DESCRIPTION                                                           */
46
/*                                                                        */
47
/*    This function checks for errors in the file open call.              */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    media_ptr                             Media control block pointer   */
52
/*    file_ptr                              File control block pointer    */
53
/*    file_name                             Name pointer                  */
54
/*    open_type                             Type of open requested        */
55
/*    file_control_block_size               Size of FX_FILE structure     */
56
/*                                                                        */
57
/*  OUTPUT                                                                */
58
/*                                                                        */
59
/*    return status                                                       */
60
/*                                                                        */
61
/*  CALLS                                                                 */
62
/*                                                                        */
63
/*    _fx_file_open                         Actual open file service      */
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    Application Code                                                    */
68
/*                                                                        */
69
/**************************************************************************/
70
19141
UINT  _fxe_file_open(FX_MEDIA *media_ptr, FX_FILE *file_ptr, CHAR *file_name, UINT open_type, UINT file_control_block_size)
71
{
72
73
UINT     status;
74
FX_FILE *current_file;
75
ULONG    open_count;
76
77
78
    /* Check for a null media or file pointer.  */
79


19141
    if ((media_ptr == FX_NULL) || (media_ptr -> fx_media_id != FX_MEDIA_ID) || (file_ptr == FX_NULL) || (file_control_block_size != sizeof(FX_FILE)))
80
    {
81
274
        return(FX_PTR_ERROR);
82
    }
83
84
    /* Check for an invalid open type.  */
85

18867
    if ((open_type != FX_OPEN_FOR_READ) && (open_type != FX_OPEN_FOR_READ_FAST) && (open_type != FX_OPEN_FOR_WRITE))
86
    {
87
136
        return(FX_ACCESS_ERROR);
88
    }
89
90
    /* Check for a valid caller.  */
91

18731
    FX_CALLER_CHECKING_CODE
92
93
    /* Get protection.  */
94
18323
    FX_PROTECT
95
96
    /* Check for a duplicate file open.  */
97
98
    /* Loop to search the list for the same file handle.  */
99
18323
    current_file =  media_ptr -> fx_media_opened_file_list;
100
18323
    open_count =    media_ptr -> fx_media_opened_file_count;
101
102
85410
    while (open_count--)
103
    {
104
105
        /* See if a match exists.  */
106
67089
        if (file_ptr == current_file)
107
        {
108
109
            /* Release protection.  */
110
2
            FX_UNPROTECT
111
112
            /* Return error.  */
113
2
            return(FX_PTR_ERROR);
114
        }
115
116
        /* Move to the next opened file.  */
117
67087
        current_file =  current_file -> fx_file_opened_next;
118
    }
119
120
    /* Release protection.  */
121
18321
    FX_UNPROTECT
122
123
    /* Call actual file open service.  */
124
18321
    status =  _fx_file_open(media_ptr, file_ptr, file_name, open_type);
125
126
    /* Open is complete, return status.  */
127
18321
    return(status);
128
}
129