• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2022 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
40 extern "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 
64 void los_vfs_init(void);
65 
66 void CloseOnExec(struct files_struct *files);
67 void SetCloexecFlag(int procFd);
68 bool CheckCloexecFlag(int procFd);
69 void ClearCloexecFlag(int procFd);
70 
71 void 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 
95 extern 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 variable,
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 
118 extern 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 
150 extern 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 
174 extern 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 
201 extern 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 
235 struct IATTR;
236 extern 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
248  * Nuttx vfs operation.</li>
249  *
250  * @par Dependency:
251  * <ul><li>fs.h</li></ul>
252  * @see None
253  */
254 
255 extern int VfsFcntl(int fd, int cmd, ...);
256 /**
257  * @ingroup fs
258  *
259  * @par Description:
260  * The LOS_BcacheSyncByName() function shall sync all the data in the cache corresponding to the disk name to the disk.
261  *
262  * @param name  [IN] name of the disk
263  *
264  * @attention
265  * <ul>
266  * <li>Now only fat filesystem support this function.</li>
267  * </ul>
268  *
269  * @retval #0      On success.
270  * @retval #INT32  On failure.
271  *
272  * @par Dependency:
273  * <ul><li>fs.h</li></ul>
274  * @see None
275  */
276 
277 extern INT32 LOS_BcacheSyncByName(const CHAR *name);
278 
279 /**
280  * @ingroup fs
281  *
282  * @par Description:
283  * The LOS_GetDirtyRatioByName() function shall return the percentage of dirty blocks in the cache corresponding
284  * to the disk name.
285  *
286  * @param name  [IN] name of the disk
287  *
288  * @attention
289  * <ul>
290  * <li>Now only fat filesystem support this function.</li>
291  * </ul>
292  *
293  * @retval #INT32  the percentage of dirty blocks.
294  * @retval #-1     On failure.
295  *
296  * @par Dependency:
297  * <ul><li>fs.h</li></ul>
298  * @see None
299  */
300 
301 extern INT32 LOS_GetDirtyRatioByName(const CHAR *name);
302 
303 #ifdef LOSCFG_FS_FAT_CACHE_SYNC_THREAD
304 /**
305  * @ingroup fs
306  *
307  * @par Description:
308  * The LOS_SetDirtyRatioThreshold() function shall set the dirty ratio threshold of bcache. When the percentage
309  * of dirty blocks in the cache is greater than the threshold, write back data to disk.
310  *
311  * @param dirtyRatio  [IN] Threshold of the percentage of dirty blocks, expressed in %.
312  *
313  * @attention
314  * <ul>
315  * <li>The dirtyRatio must be less than or equal to 100, or the setting is invalid.</li>
316  * </ul>
317  *
318  * @retval #VOID  None.
319  *
320  * @par Dependency:
321  * <ul><li>fs.h</li></ul>
322  * @see LOS_SetSyncThreadInterval | LOS_SetSyncThreadPrio
323  */
324 
325 extern VOID LOS_SetDirtyRatioThreshold(UINT32 dirtyRatio);
326 
327 /**
328  * @ingroup fs
329  *
330  * @par Description:
331  * The LOS_SetSyncThreadInterval() function shall set the interval for the sync thread to wake up.
332  *
333  * @param interval [IN] the interval time for the sync thread to wake up, in milliseconds, accuracy is 10ms.
334  *
335  * @attention
336  * <ul>
337  * <li>None</li>
338  * </ul>
339  *
340  * @retval #VOID  None.
341  *
342  * @par Dependency:
343  * <ul><li>fs.h</li></ul>
344  * @see LOS_SetDirtyRatioThreshold | LOS_SetSyncThreadPrio
345  */
346 
347 extern VOID LOS_SetSyncThreadInterval(UINT32 interval);
348 
349 /**
350  * @ingroup fs
351  *
352  * @par Description:
353  * The LOS_SetSyncThreadPrio() function shall set the priority of the sync thread.
354  *
355  * @param prio  [IN] priority of sync thread to be set
356  * @param name  [IN] name of the disk
357  *
358  * @attention
359  * <ul>
360  * <li>The prio must be less than 31 and be greater than 0, or the setting is invalid.</li>
361  * <li>If the parameter name is NULL, it only set the value of a global variable, and take effect the next time the
362  * thread is created. If name is not NULL and can't find the disk corresponding to name, it shall return an error.</li>
363  * </ul>
364  *
365  * @retval #INT32  On failure.
366  * @retval 0       On success.
367  *
368  * @par Dependency:
369  * <ul><li>fs.h</li></ul>
370  * @see LOS_SetDirtyRatioThreshold | LOS_SetSyncThreadInterval | LOS_TaskPriSet
371  */
372 
373 extern INT32 LOS_SetSyncThreadPrio(UINT32 prio, const CHAR *name);
374 
375 #endif
376 
377 #ifdef __cplusplus
378 #if __cplusplus
379 }
380 #endif /* __cplusplus */
381 #endif /* __cplusplus */
382 #endif
383