GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_directory_attributes_set.c Lines: 21 21 100.0 %
Date: 2024-01-10 21:53:23 Branches: 8 8 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
/**   Directory                                                           */
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_system.h"
30
#include "fx_directory.h"
31
#include "fx_file.h"
32
#include "fx_utility.h"
33
#ifdef FX_ENABLE_FAULT_TOLERANT
34
#include "fx_fault_tolerant.h"
35
#endif /* FX_ENABLE_FAULT_TOLERANT */
36
37
38
/**************************************************************************/
39
/*                                                                        */
40
/*  FUNCTION                                               RELEASE        */
41
/*                                                                        */
42
/*    _fx_directory_attributes_set                        PORTABLE C      */
43
/*                                                           6.1          */
44
/*  AUTHOR                                                                */
45
/*                                                                        */
46
/*    William E. Lamie, Microsoft Corporation                             */
47
/*                                                                        */
48
/*  DESCRIPTION                                                           */
49
/*                                                                        */
50
/*    This function first attempts to find the specified directory.  If   */
51
/*    found, the attribute set request is valid and the directory will    */
52
/*    be modified with the new attributes.  Otherwise, if the directory   */
53
/*    is not found, the appropriate error code is returned to the caller. */
54
/*                                                                        */
55
/*  INPUT                                                                 */
56
/*                                                                        */
57
/*    media_ptr                             Media control block pointer   */
58
/*    directory_name                        Directory name pointer        */
59
/*    attributes                            New dir attributes            */
60
/*                                                                        */
61
/*  OUTPUT                                                                */
62
/*                                                                        */
63
/*    return status                                                       */
64
/*                                                                        */
65
/*  CALLS                                                                 */
66
/*                                                                        */
67
/*    _fx_directory_entry_write             Write the new directory entry */
68
/*    _fx_directory_search                  Search for the file name in   */
69
/*                                            the directory structure     */
70
/*    _fx_fault_tolerant_transaction_start  Start fault tolerant          */
71
/*                                            transaction                 */
72
/*    _fx_fault_tolerant_transaction_end    End fault tolerant transaction*/
73
/*    _fx_fault_tolerant_recover            Recover FAT chain             */
74
/*    _fx_fault_tolerant_reset_log_file     Reset the log file            */
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
7
UINT  _fx_directory_attributes_set(FX_MEDIA *media_ptr, CHAR *directory_name, UINT attributes)
90
{
91
92
UINT         status;
93
FX_DIR_ENTRY dir_entry;
94
95
#ifndef FX_MEDIA_STATISTICS_DISABLE
96
97
    /* Increment the number of times this service has been called.  */
98
7
    media_ptr -> fx_media_directory_attributes_sets++;
99
#endif
100
101
    /* Setup pointer to media name buffer.  */
102
7
    dir_entry.fx_dir_entry_name =  media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
103
104
    /* Clear the short name string.  */
105
7
    dir_entry.fx_dir_entry_short_name[0] =  0;
106
107
    /* Check the media to make sure it is open.  */
108
7
    if (media_ptr -> fx_media_id != FX_MEDIA_ID)
109
    {
110
111
        /* Return the media not opened error.  */
112
1
        return(FX_MEDIA_NOT_OPEN);
113
    }
114
115
    /* If trace is enabled, insert this event into the trace buffer.  */
116
    FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_ATTRIBUTES_SET, media_ptr, directory_name, attributes, 0, FX_TRACE_DIRECTORY_EVENTS, 0, 0)
117
118
    /* Protect against other threads accessing the media.  */
119
6
    FX_PROTECT
120
121
    /* Check for write protect at the media level (set by driver).  */
122
6
    if (media_ptr -> fx_media_driver_write_protect)
123
    {
124
125
        /* Release media protection.  */
126
1
        FX_UNPROTECT
127
128
        /* Return write protect error.  */
129
1
        return(FX_WRITE_PROTECT);
130
    }
131
132
    /* Search the system for the supplied file name.  */
133
5
    status =  _fx_directory_search(media_ptr, directory_name, &dir_entry, FX_NULL, FX_NULL);
134
135
    /* Determine if the search was successful.  */
136
5
    if (status != FX_SUCCESS)
137
    {
138
139
        /* Release media protection.  */
140
1
        FX_UNPROTECT
141
142
        /* Return the error code.  */
143
1
        return(status);
144
    }
145
146
    /* Check to make sure the found entry is a directory.  */
147
4
    if ((dir_entry.fx_dir_entry_attributes & (UCHAR)(FX_DIRECTORY)) == 0)
148
    {
149
150
        /* Release media protection.  */
151
1
        FX_UNPROTECT
152
153
        /* Return the not a file error code.  */
154
1
        return(FX_NOT_DIRECTORY);
155
    }
156
157
    /* Place the new attributes in the directory entry. Make sure that the
158
       directory bit of the attributes is never changed. */
159
3
    dir_entry.fx_dir_entry_attributes =  (UCHAR)(attributes | FX_DIRECTORY);
160
161
#ifdef FX_ENABLE_FAULT_TOLERANT
162
    /* Start transaction. */
163
    _fx_fault_tolerant_transaction_start(media_ptr);
164
#endif /* FX_ENABLE_FAULT_TOLERANT */
165
166
    /* Now write out the directory entry.  */
167
#ifdef FX_ENABLE_EXFAT
168
    if (media_ptr -> fx_media_FAT_type == FX_exFAT)
169
    {
170
171
        status = _fx_directory_exFAT_entry_write(media_ptr, &dir_entry, UPDATE_FILE);
172
    }
173
    else
174
    {
175
#endif /* FX_ENABLE_EXFAT */
176
177
3
        status = _fx_directory_entry_write(media_ptr, &dir_entry);
178
179
#ifdef FX_ENABLE_EXFAT
180
    }
181
#endif /* FX_ENABLE_EXFAT */
182
183
#ifdef FX_ENABLE_FAULT_TOLERANT
184
    /* Check for a bad status.  If the return status is not FX_SUCCESS, finish
185
       the fault tolerant transaction without flushing the logs. */
186
    if (status != FX_SUCCESS)
187
    {
188
        FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
189
    }
190
    else
191
    {
192
193
        /* End transaction. */
194
        status = _fx_fault_tolerant_transaction_end(media_ptr);
195
    }
196
197
#endif /* FX_ENABLE_FAULT_TOLERANT */
198
199
    /* Release media protection.  */
200
3
    FX_UNPROTECT
201
202
    /* File attribute set is complete, return status.  */
203
3
    return(status);
204
}
205