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 |
|
|
/** 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 |
|
|
/* RELEASE HISTORY */ |
70 |
|
|
/* */ |
71 |
|
|
/* DATE NAME DESCRIPTION */ |
72 |
|
|
/* */ |
73 |
|
|
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ |
74 |
|
|
/* 09-30-2020 William E. Lamie Modified comment(s), */ |
75 |
|
|
/* resulting in version 6.1 */ |
76 |
|
|
/* */ |
77 |
|
|
/**************************************************************************/ |
78 |
|
19141 |
UINT _fxe_file_open(FX_MEDIA *media_ptr, FX_FILE *file_ptr, CHAR *file_name, UINT open_type, UINT file_control_block_size) |
79 |
|
|
{ |
80 |
|
|
|
81 |
|
|
UINT status; |
82 |
|
|
FX_FILE *current_file; |
83 |
|
|
ULONG open_count; |
84 |
|
|
|
85 |
|
|
|
86 |
|
|
/* Check for a null media or file pointer. */ |
87 |
✓✓✓✓ ✓✓✓✓
|
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))) |
88 |
|
|
{ |
89 |
|
274 |
return(FX_PTR_ERROR); |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
/* Check for an invalid open type. */ |
93 |
✓✓✓✓ ✓✓ |
18867 |
if ((open_type != FX_OPEN_FOR_READ) && (open_type != FX_OPEN_FOR_READ_FAST) && (open_type != FX_OPEN_FOR_WRITE)) |
94 |
|
|
{ |
95 |
|
136 |
return(FX_ACCESS_ERROR); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
/* Check for a valid caller. */ |
99 |
✓✓✓✓ ✓✓ |
18731 |
FX_CALLER_CHECKING_CODE |
100 |
|
|
|
101 |
|
|
/* Get protection. */ |
102 |
|
18323 |
FX_PROTECT |
103 |
|
|
|
104 |
|
|
/* Check for a duplicate file open. */ |
105 |
|
|
|
106 |
|
|
/* Loop to search the list for the same file handle. */ |
107 |
|
18323 |
current_file = media_ptr -> fx_media_opened_file_list; |
108 |
|
18323 |
open_count = media_ptr -> fx_media_opened_file_count; |
109 |
|
|
|
110 |
✓✓ |
85410 |
while (open_count--) |
111 |
|
|
{ |
112 |
|
|
|
113 |
|
|
/* See if a match exists. */ |
114 |
✓✓ |
67089 |
if (file_ptr == current_file) |
115 |
|
|
{ |
116 |
|
|
|
117 |
|
|
/* Release protection. */ |
118 |
|
2 |
FX_UNPROTECT |
119 |
|
|
|
120 |
|
|
/* Return error. */ |
121 |
|
2 |
return(FX_PTR_ERROR); |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
/* Move to the next opened file. */ |
125 |
|
67087 |
current_file = current_file -> fx_file_opened_next; |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
/* Release protection. */ |
129 |
|
18321 |
FX_UNPROTECT |
130 |
|
|
|
131 |
|
|
/* Call actual file open service. */ |
132 |
|
18321 |
status = _fx_file_open(media_ptr, file_ptr, file_name, open_type); |
133 |
|
|
|
134 |
|
|
/* Open is complete, return status. */ |
135 |
|
18321 |
return(status); |
136 |
|
|
} |
137 |
|
|
|