1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* |
4 |
|
|
* This program and the accompanying materials are made available under the |
5 |
|
|
* terms of the MIT License which is available at |
6 |
|
|
* https://opensource.org/licenses/MIT. |
7 |
|
|
* |
8 |
|
|
* SPDX-License-Identifier: MIT |
9 |
|
|
**************************************************************************/ |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
/**************************************************************************/ |
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/** */ |
15 |
|
|
/** FileX Component */ |
16 |
|
|
/** */ |
17 |
|
|
/** File */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define FX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Include necessary system files. */ |
26 |
|
|
|
27 |
|
|
#include "fx_api.h" |
28 |
|
|
#include "fx_file.h" |
29 |
|
|
|
30 |
|
|
|
31 |
|
|
FX_CALLER_CHECKING_EXTERNS |
32 |
|
|
|
33 |
|
|
|
34 |
|
|
/**************************************************************************/ |
35 |
|
|
/* */ |
36 |
|
|
/* FUNCTION RELEASE */ |
37 |
|
|
/* */ |
38 |
|
|
/* _fxe_file_open PORTABLE C */ |
39 |
|
|
/* 6.1 */ |
40 |
|
|
/* AUTHOR */ |
41 |
|
|
/* */ |
42 |
|
|
/* William E. Lamie, Microsoft Corporation */ |
43 |
|
|
/* */ |
44 |
|
|
/* DESCRIPTION */ |
45 |
|
|
/* */ |
46 |
|
|
/* This function checks for errors in the file open call. */ |
47 |
|
|
/* */ |
48 |
|
|
/* INPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* media_ptr Media control block pointer */ |
51 |
|
|
/* file_ptr File control block pointer */ |
52 |
|
|
/* file_name Name pointer */ |
53 |
|
|
/* open_type Type of open requested */ |
54 |
|
|
/* file_control_block_size Size of FX_FILE structure */ |
55 |
|
|
/* */ |
56 |
|
|
/* OUTPUT */ |
57 |
|
|
/* */ |
58 |
|
|
/* return status */ |
59 |
|
|
/* */ |
60 |
|
|
/* CALLS */ |
61 |
|
|
/* */ |
62 |
|
|
/* _fx_file_open Actual open file service */ |
63 |
|
|
/* */ |
64 |
|
|
/* CALLED BY */ |
65 |
|
|
/* */ |
66 |
|
|
/* Application Code */ |
67 |
|
|
/* */ |
68 |
|
|
/* RELEASE HISTORY */ |
69 |
|
|
/* */ |
70 |
|
|
/* DATE NAME DESCRIPTION */ |
71 |
|
|
/* */ |
72 |
|
|
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ |
73 |
|
|
/* 09-30-2020 William E. Lamie Modified comment(s), */ |
74 |
|
|
/* resulting in version 6.1 */ |
75 |
|
|
/* */ |
76 |
|
|
/**************************************************************************/ |
77 |
|
19141 |
UINT _fxe_file_open(FX_MEDIA *media_ptr, FX_FILE *file_ptr, CHAR *file_name, UINT open_type, UINT file_control_block_size) |
78 |
|
|
{ |
79 |
|
|
|
80 |
|
|
UINT status; |
81 |
|
|
FX_FILE *current_file; |
82 |
|
|
ULONG open_count; |
83 |
|
|
|
84 |
|
|
|
85 |
|
|
/* Check for a null media or file pointer. */ |
86 |
✓✓✓✓ ✓✓✓✓
|
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))) |
87 |
|
|
{ |
88 |
|
274 |
return(FX_PTR_ERROR); |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
/* Check for an invalid open type. */ |
92 |
✓✓✓✓ ✓✓ |
18867 |
if ((open_type != FX_OPEN_FOR_READ) && (open_type != FX_OPEN_FOR_READ_FAST) && (open_type != FX_OPEN_FOR_WRITE)) |
93 |
|
|
{ |
94 |
|
136 |
return(FX_ACCESS_ERROR); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
/* Check for a valid caller. */ |
98 |
✓✓✓✓ ✓✓ |
18731 |
FX_CALLER_CHECKING_CODE |
99 |
|
|
|
100 |
|
|
/* Get protection. */ |
101 |
|
18323 |
FX_PROTECT |
102 |
|
|
|
103 |
|
|
/* Check for a duplicate file open. */ |
104 |
|
|
|
105 |
|
|
/* Loop to search the list for the same file handle. */ |
106 |
|
18323 |
current_file = media_ptr -> fx_media_opened_file_list; |
107 |
|
18323 |
open_count = media_ptr -> fx_media_opened_file_count; |
108 |
|
|
|
109 |
✓✓ |
85410 |
while (open_count--) |
110 |
|
|
{ |
111 |
|
|
|
112 |
|
|
/* See if a match exists. */ |
113 |
✓✓ |
67089 |
if (file_ptr == current_file) |
114 |
|
|
{ |
115 |
|
|
|
116 |
|
|
/* Release protection. */ |
117 |
|
2 |
FX_UNPROTECT |
118 |
|
|
|
119 |
|
|
/* Return error. */ |
120 |
|
2 |
return(FX_PTR_ERROR); |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
/* Move to the next opened file. */ |
124 |
|
67087 |
current_file = current_file -> fx_file_opened_next; |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
/* Release protection. */ |
128 |
|
18321 |
FX_UNPROTECT |
129 |
|
|
|
130 |
|
|
/* Call actual file open service. */ |
131 |
|
18321 |
status = _fx_file_open(media_ptr, file_ptr, file_name, open_type); |
132 |
|
|
|
133 |
|
|
/* Open is complete, return status. */ |
134 |
|
18321 |
return(status); |
135 |
|
|
} |
136 |
|
|
|