-
Notifications
You must be signed in to change notification settings - Fork 39
/
dir.h
173 lines (160 loc) · 7.2 KB
/
dir.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/****************************************************************************
**
** Copyright (C) ${COPYRIGHT_YEAR} MikroElektronika d.o.o.
** Contact: https://www.mikroe.com/contact
**
** This file is part of the mikroSDK package
**
** Commercial License Usage
**
** Licensees holding valid commercial NECTO compilers AI licenses may use this
** file in accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The MikroElektronika Company.
** For licensing terms and conditions see
** https://www.mikroe.com/legal/software-license-agreement.
** For further information use the contact form at
** https://www.mikroe.com/contact.
**
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used for
** non-commercial projects under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** The above copyright notice and this permission notice shall be
** included in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
****************************************************************************/
/*!
* @file dir.h
* @brief File System Directory Access and Management.
*/
#ifndef _DIR_H_
#define _DIR_H_
#ifdef __cplusplus
extern "C"{
#endif
#include "file_system.h"
/**
* @defgroup directory_data_group Directory Data
* @ingroup directory_group
* @brief Directory Data Structure Reference.
*/
/**
* @ingroup directory_data_group
*
* @brief Directory Data Structure.
*
* @details The struct is used to link file system specific directory data structure @c fs_dir,
* to the logical drive struct where the directory is located.
* It is used as identifier for the directory in Directory Access API functions.
*
* @note The directory is considered closed or uninitialized when both of its elements are NULL,
* and if both elements are set the directory is considered to be open.
* If one element is NULL while the other is not, the directory is considered to be uninitialized.
*/
typedef struct {
logical_drive_t * logical_drive; /**< A pointer to base Logical drive structure where the directory is located. See @ref logical_drive_t for detailed explanation. */
fs_dir_t fs_dir; /**< Directory data structure specific to the particular file system in which @c logical_drive is initialized. */
} dir_t;
/**
* @addtogroup directory_group Directory Access
* @brief Directory Access and Management.
* @{
*/
/**
* @brief Open a Directory.
*
* @details This API function will open an existing @c dir in a location specified by the parameter @c path,
* on the logical drive identified by the drive number found also in the @c path parameter.
* The directory data structure specific to the particular file system implementation @c fs_specific_dir,
* and @c dir structure will be initialized too.
*
* @param[inout] dir A pointer to the directory data structure, that acts as the directory identifier.
* See @ref dir_t, structure for detailed explanation.
* @param[in] fs_specific_dir A pointer to the directory data structure specific to the particular file system.
* See @ref fs_dir_t structure for detailed explanation.
* @param[in] path A null terminated string, that specifies the absolute path to the directory that needs to be opened.
* It should contain the the logical drive identifying drive number and semicolon at the beginning of the string, eg @c "3:/".
* If it does not, the default logical drive, @c 0:, will be assumed.
*
* @retval FSS_OK If the directory was opened successfully,
* @retval FSS_GENERAL_ERROR If too many directories or files are opened already,
* if directory identified by the @c dir paramater does not exist on the logical drive identified by the parameter @c path, etc.
*
* @pre A logical drive must be mounted to the file system to the location specified by the @c path
* See @ref file_system_mount function for detailed explanation.
*
* @post Other directory access APIs can now be called, using the @c dir structure as identifier,
* allowing various operations with the opened directory.
*
* @note Maximum 10 files and/or directories can be opened at one time. See @ref FS_MAX_OBJECTS.
*/
fs_status_t dir_open(dir_t *dir, fs_dir_t fs_specific_dir, const char* __generic_ptr path);
/**
* @brief Close an Opened Directory.
*
* @details This API function will close an open @c dir object.
*
* @param[inout] dir A pointer to the directory data structure, that acts as the opened directory identifier.
* See @ref dir_t, structure for detailed explanation.
*
* @retval FSS_OK If the directory was closed successfully,
* @retval FSS_GENERAL_ERROR If the @c dir was not opened, or if there was an error
* on the physical drive linked to the logical drive, etc.
*
* @pre The @c dir must be opened first, before calling this function.
* See @ref dir_open, function for detailed explanation.
*/
fs_status_t dir_close(dir_t *dir);
/**
* @brief Read Directory Entry.
*
* @details This API function will read an directory entry, from the opened @c dir.
*
* @param[in] dir A pointer to the directory data structure, that acts as the opened directory identifier.
* See @ref dir_t, structure for detailed explanation.
* @param[in] file_information A pointer to the structure, where the read directory entry will be stored.
*
* @retval FSS_OK If the directory entry was read successfully.
* @retval FSS_END_OF_DIRECTORY If read directory was null .
* @retval FSS_GENERAL_ERROR If the @c dir was not opened, or if there was an error
* on the physical drive linked to the logical drive, etc.
*
* @pre The @c dir must be opened first, before calling this function.
* See @ref dir_open, function for detailed explanation.
*/
fs_status_t dir_read(dir_t *dir, void * file_information);
/**
* @brief Move Read/Write Offset to the beginning of the Directory.
*
* @details This API function will will move read/write offset of the opened @c dir,
* to the beginning of the opened @c dir.
*
* @param[in] dir A pointer to the directory data structure, that acts as the opened directory identifier.
* See @ref dir_t, structure for detailed explanation.
*
* @retval FSS_OK If read/write offset of the @c dir was moved to the desired offset successfully.
* @retval FSS_GENERAL_ERROR If the @c dir was not opened, or if there was an error
* on the physical drive linked to the logical drive, etc.
*
* @pre The @c dir must be opened first, before calling this function.
* See @ref dir_open, function for detailed explanation.
*/
fs_status_t dir_rewind(dir_t *dir);
/*! @} */ // directory_group
#ifdef __cplusplus
}
#endif
#endif // !_DIR_H_