更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
fs_operation.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef FS_OPERATION_H
33#define FS_OPERATION_H
34
35#include "fs/file.h"
36#include "fs/fd_table.h"
37
38#ifdef __cplusplus
39#if __cplusplus
40extern "C" {
41#endif /* __cplusplus */
42#endif /* __cplusplus */
43
44/**
45 * @ingroup fs
46 * @brief Initializes the vfs filesystem
47 *
48 * @par Description:
49 * This API is used to initializes the vfs filesystem
50 *
51 * @attention
52 * <ul>
53 * <li>Called only once, multiple calls will cause file system error.</li>
54 * </ul>
55 *
56 * @param none
57 *
58 * @retval none
59 * @par Dependency:
60 * <ul><li>fs.h: the header file that contains the API declaration.</li></ul>
61 * @see NULL
62 */
63
64void los_vfs_init(void);
65
66void CloseOnExec(struct files_struct *files);
67void SetCloexecFlag(int procFd);
68bool CheckCloexecFlag(int procFd);
69void ClearCloexecFlag(int procFd);
70
71void clear_fd(int fd);
72
73/**
74 * @ingroup fs
75 * @brief locate character in string.
76 *
77 * @par Description:
78 * The API function returns a pointer to the last occurrence of the character c in the string s.
79 *
80 * @attention
81 * <ul>
82 * <li>The parameter s must point a valid string, which end with the terminating null byte.</li>
83 * </ul>
84 *
85 * @param s [IN] Type #const char* A pointer to string.
86 * @param c [IN] Type #int The character.
87 *
88 * @retval #char* a pointer to the matched character or NULL if the character is not found.
89 *
90 * @par Dependency:
91 * <ul><li>fs.h: the header file that contains the API declaration.</li></ul>
92 * @see rindex
93 */
94
95extern char *rindex(const char *s, int c);
96
97/**
98 * @ingroup fs
99 *
100 * @par Description:
101 * The set_label() function shall set the value of a global varible,
102 * the value will be used to set the label of SD card in format().
103 *
104 * @param name [IN] label to set, the length must be less than 12
105 *
106 * @attention
107 * <ul>
108 * <li>The function must be called before format().</li>
109 * </ul>
110 *
111 * @retval #void None.
112 *
113 * @par Dependency:
114 * <ul><li>fs.h</li></ul>
115 * @see format
116 */
117
118extern void set_label(const char *name);
119
120/**
121 * @ingroup fs
122 * @brief formatting sd card
123 *
124 * @par Description:
125 * formatting sd card.
126 *
127 * @attention
128 * <ul>
129 * <li>The prefix of the parameter dev must be "/dev", and the length must be less than the value defined by PATH_MAX.
130 * There are four kind of format option: FMT_FAT16, FMT_FAT32, FMT_ANY, FMT_ERASE. If users input anything else,
131 * the default format option is FMT_ANY. Format option is decided by the number of clusters. Choosing the wrong
132 * option will cause error of format. The detailed information of (FAT16,FAT32) is ff.h.
133 * </li>
134 * </ul>
135 *
136 * @param dev [IN] Type #const char* path of the block device to format, which must be a really
137 * existing block device node.
138 * @param sectors [IN] Type #int number of sectors per cluster.
139 * @param option [IN] Type #int option of format.
140 *
141 * @retval #0 Format success.
142 * @retval #-1 Format failed.
143 *
144 * @par Dependency:
145 * <ul><li>unistd.h: the header file that contains the API declaration.</li></ul>
146 * @see
147 *
148 */
149
150extern int format(const char *dev, int sectors, int option);
151
152/**
153 * @ingroup fs
154 * @brief list directory contents.
155 *
156 * @par Description:
157 * List information about the FILEs (the current directory by default).
158 *
159 * @attention
160 * <ul>
161 * <li>The total length of parameter pathname must be less than the value defined by PATH_MAX.</li>
162 * </ul>
163 *
164 * @param pathname [IN] Type #const char* The file pathname.
165 *
166 * @retval
167 * <ul>None.</ul>
168 *
169 * @par Dependency:
170 * <ul><li>fs.h: the header file that contains the API declaration.</li></ul>
171 * @see ls
172 */
173
174extern void ls(const char *pathname);
175
176/**
177 * @ingroup fs
178 * @brief set current system time is valid or invalid for FAT file system.
179 *
180 * @par Description:
181 * The function is used for setting current system time is valid or invalid for FAT file system.
182 * The value can be set as FAT_SYSTEM_TIME_ENABLE/FAT_SYSTEM_TIME_DISABLE.
183 *
184 * @attention
185 * <ul>
186 * <li>When the system time is valid, it should set FAT_SYSTEM_TIME_ENABLE.</li>
187 * <li>When the system time is invalid, it should set FAT_SYSTEM_TIME_DISABLE.</li>
188 * </ul>
189 *
190 * @param b_status [IN] Type #BOOL system time status.
191 *
192 * @retval #0 set status success
193 * @retval #-22 Invalid argument
194 *
195 * @par Dependency:
196 * <ul><li>fs.h: the header file that contains the API declaration.</li></ul>
197 * @see
198 *
199 */
200
201extern int los_set_systime_status(BOOL b_status);
202
203/**
204 * @ingroup fs
205 *
206 * @par Description:
207 * The chattr() function shall change the mode of file named by the pathname pointed to by the path argument.
208 *
209 * @attention
210 * <ul>
211 * <li>Now only fat filesystem support this function.</li>
212 * </ul>
213 *
214 * @retval #0 On success.
215 * @retval #-1 On failure with errno set.
216 *
217 * @par Errors
218 * <ul>
219 * <li><b>EINVAL</b>: The path is a null pointer or points to an empty string.</li>
220 * <li><b>ENAMETOOLONG</b>: The length of a component of a pathname is longer than {NAME_MAX}.</li>
221 * <li><b>ENOENT</b>: A component of the path does not exist.</li>
222 * <li><b>EPERM</b>: The entry represented by the path is a mount point.</li>
223 * <li><b>ENOSYS</b>: The file system doesn't support this function.</li>
224 * <li><b>EACCES</b>: It is a read-only file system.</li>
225 * <li><b>ENOMEM</b>: Out of memory.</li>
226 * <li><b>EIO</b>: A hard error occurred in the low level disk I/O layer or the physical drive cannot work.</li>
227 * <li><b>ENODEV</b>: The device is not existed.</li>
228 * </ul>
229 *
230 * @par Dependency:
231 * <ul><li>fs.h</li></ul>
232 * @see None
233 */
234
235struct IATTR;
236extern int chattr(const char *pathname, struct IATTR *attr);
237
238#define CONTINE_NUTTX_FCNTL 0XFF0F
239/**
240 * @ingroup fs
241 *
242 * @par Description:
243 * The VfsFcntl function shall manipulate file descriptor.
244 *
245 * @retval #0 On success.
246 * @retval #-1 On failure with errno set.
247 * @retval CONTINE_NUTTX_FCNTL doesn't support some cmds in VfsFcntl, needs to continue going through Nuttx vfs operation.</li>
248 *
249 * @par Dependency:
250 * <ul><li>fs.h</li></ul>
251 * @see None
252 */
253
254extern int VfsFcntl(int fd, int cmd, ...);
255/**
256 * @ingroup fs
257 *
258 * @par Description:
259 * The LOS_BcacheSyncByName() function shall sync all the data in the cache corresponding to the disk name to the disk.
260 *
261 * @param name [IN] name of the disk
262 *
263 * @attention
264 * <ul>
265 * <li>Now only fat filesystem support this function.</li>
266 * </ul>
267 *
268 * @retval #0 On success.
269 * @retval #INT32 On failure.
270 *
271 * @par Dependency:
272 * <ul><li>fs.h</li></ul>
273 * @see None
274 */
275
276extern INT32 LOS_BcacheSyncByName(const CHAR *name);
277
278/**
279 * @ingroup fs
280 *
281 * @par Description:
282 * The LOS_GetDirtyRatioByName() function shall return the percentage of dirty blocks in the cache corresponding
283 * to the disk name.
284 *
285 * @param name [IN] name of the disk
286 *
287 * @attention
288 * <ul>
289 * <li>Now only fat filesystem support this function.</li>
290 * </ul>
291 *
292 * @retval #INT32 the percentage of dirty blocks.
293 * @retval #-1 On failure.
294 *
295 * @par Dependency:
296 * <ul><li>fs.h</li></ul>
297 * @see None
298 */
299
300extern INT32 LOS_GetDirtyRatioByName(const CHAR *name);
301
302#ifdef LOSCFG_FS_FAT_CACHE_SYNC_THREAD
303/**
304 * @ingroup fs
305 *
306 * @par Description:
307 * The LOS_SetDirtyRatioThreshold() function shall set the dirty ratio threshold of bcache. When the percentage
308 * of dirty blocks in the cache is greater than the threshold, write back data to disk.
309 *
310 * @param dirtyRatio [IN] Threshold of the percentage of dirty blocks, expressed in %.
311 *
312 * @attention
313 * <ul>
314 * <li>The dirtyRatio must be less than or equal to 100, or the setting is invalid.</li>
315 * </ul>
316 *
317 * @retval #VOID None.
318 *
319 * @par Dependency:
320 * <ul><li>fs.h</li></ul>
321 * @see LOS_SetSyncThreadInterval | LOS_SetSyncThreadPrio
322 */
323
324extern VOID LOS_SetDirtyRatioThreshold(UINT32 dirtyRatio);
325
326/**
327 * @ingroup fs
328 *
329 * @par Description:
330 * The LOS_SetSyncThreadInterval() function shall set the interval for the sync thread to wake up.
331 *
332 * @param interval [IN] the interval time for the sync thread to wake up, in milliseconds, accuracy is 10ms.
333 *
334 * @attention
335 * <ul>
336 * <li>None</li>
337 * </ul>
338 *
339 * @retval #VOID None.
340 *
341 * @par Dependency:
342 * <ul><li>fs.h</li></ul>
343 * @see LOS_SetDirtyRatioThreshold | LOS_SetSyncThreadPrio
344 */
345
346extern VOID LOS_SetSyncThreadInterval(UINT32 interval);
347
348/**
349 * @ingroup fs
350 *
351 * @par Description:
352 * The LOS_SetSyncThreadPrio() function shall set the priority of the sync thread.
353 *
354 * @param prio [IN] priority of sync thread to be set
355 * @param name [IN] name of the disk
356 *
357 * @attention
358 * <ul>
359 * <li>The prio must be less than 31 and be greater than 0, or the setting is invalid.</li>
360 * <li>If the parameter name is NULL, it only set the value of a global variable, and take effect the next time the
361 * thread is created. If name is not NULL and can't find the disk corresponding to name, it shall return an error.</li>
362 * </ul>
363 *
364 * @retval #INT32 On failure.
365 * @retval 0 On success.
366 *
367 * @par Dependency:
368 * <ul><li>fs.h</li></ul>
369 * @see LOS_SetDirtyRatioThreshold | LOS_SetSyncThreadInterval | LOS_TaskPriSet
370 */
371
372extern INT32 LOS_SetSyncThreadPrio(UINT32 prio, const CHAR *name);
373
374#endif
375
376#ifdef __cplusplus
377#if __cplusplus
378}
379#endif /* __cplusplus */
380#endif /* __cplusplus */
381#endif
int VfsFcntl(int fd, int cmd,...)
Definition: vfs_fcntl.c:68
void set_label(const char *name)
Definition: format.c:94
int format(const char *dev, int sectors, int option)
formatting sd card
Definition: format.c:44
void ls(const char *pathname)
list directory contents.
Definition: vfs_other.c:600
VOID LOS_SetSyncThreadInterval(UINT32 interval)
设置同步间隔,5秒
Definition: bcache.c:92
char * rindex(const char *s, int c)
locate character in string.
Definition: vfs_other.c:432
INT32 LOS_SetSyncThreadPrio(UINT32 prio, const CHAR *name)
设置同步任务优先级,10
Definition: bcache.c:97
void SetCloexecFlag(int procFd)
Definition: vfs_cloexec.c:62
INT32 LOS_GetDirtyRatioByName(const CHAR *name)
Definition: bcache.c:1017
void CloseOnExec(struct files_struct *files)
Definition: vfs_cloexec.c:42
bool CheckCloexecFlag(int procFd)
Definition: vfs_cloexec.c:75
int chattr(const char *pathname, struct IATTR *attr)
Definition: vfs_chattr.c:58
void ClearCloexecFlag(int procFd)
Definition: vfs_cloexec.c:89
int los_set_systime_status(BOOL b_status)
set current system time is valid or invalid for FAT file system.
VOID LOS_SetDirtyRatioThreshold(UINT32 dirtyRatio)
Definition: bcache.c:85
void los_vfs_init(void)
Initializes the vfs filesystem
Definition: vfs_init.c:70
void clear_fd(int fd)
INT32 LOS_BcacheSyncByName(const CHAR *name)
Definition: bcache.c:983
signed int INT32
Definition: los_typedef.h:60
unsigned int UINT32
Definition: los_typedef.h:57
char CHAR
Definition: los_typedef.h:63
size_t BOOL
Definition: los_typedef.h:88
此结构用于记录 vnode 的属性
Definition: vnode.h:81