• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: OS Abstract Layer.
15  */
16 
17 /**
18  * @defgroup osal_fileops osal_fileops
19  */
20 #ifndef __OSAL_FILEOPS_H__
21 #define __OSAL_FILEOPS_H__
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif
28 
29 #define OSAL_O_RDONLY 00000000
30 #define OSAL_O_WRONLY 00000001
31 #define OSAL_O_RDWR 00000002
32 #define OSAL_O_ACCMODE 00000003
33 
34 #define OSAL_O_CREAT 00000100
35 #define OSAL_O_EXCL 00000200
36 #define OSAL_O_TRUNC 00001000
37 #define OSAL_O_APPEND 00002000
38 #define OSAL_O_CLOEXEC 02000000
39 
40 #define OSAL_SEEK_SET 0
41 #define OSAL_SEEK_CUR 1
42 #define OSAL_SEEK_END 2
43 
44 /**
45  * @ingroup osal_fileops
46  * @brief open file and return file pointer.
47  * @param file [in] the filename of file
48  * @param flags [in] the opreation flag example: OSAL_O_CREAT
49  * @param mode [in] the mode example: OSAL_O_RDONLY
50  * @return void* / null
51  *
52  * @par Support System:
53  * linux liteos seliteos freertos.
54  */
55 void *osal_klib_fopen(const char *file, int flags, int mode);
56 
57 /**
58  * @ingroup osal_fileops
59  * @brief close file.
60  * @param filp [in] the result of osal_klib_fopen
61  * @par Support System:
62  * linux liteos seliteos freertos.
63  */
64 void osal_klib_fclose(void *filp);
65 
66 /**
67  * @ingroup osal_fileops
68  * @brief kernel write function.
69  * @param buf [in] the buffer you want to write
70  * @param size [in] the size of buffer
71  * @param filp [in] the result of osal_klib_fopen
72  * @return The length that has been written.
73  *
74  * @par Support System:
75  * linux liteos seliteos freertos.
76  */
77 int osal_klib_fwrite(const char *buf, unsigned long size, void *filp);
78 
79 /**
80  * @ingroup osal_fileops
81  * @brief Kernel read function.
82  * @param buf [out] the buffer you want to read in
83  * @param size [in] the size of buffer
84  * @param filp [in] the result of osal_klib_fopen
85  * @return The length that has been read.
86  *
87  * @par Support System:
88  * linux liteos seliteos freertos.
89  */
90 int osal_klib_fread(char *buf, unsigned long size, void *filp);
91 
92 /**
93  * @ingroup osal_fileops
94  * @brief Perform a fsync or fdatasync on a file
95  * @param filp [in] the result of osal_klib_fopen
96  * @return The value 0 indicates success, and other values indicate failure.
97  * @par Support System:
98  * linux liteos.
99  */
100 void osal_klib_fsync(void *filp);
101 
102 /**
103  * @ingroup osal_fileops
104  * @brief Kernel file seek function.
105  * @param offset [in] the new position of file
106  * @param whence [in] the method of lseek,example:OSAL_SEEK_SET
107  * @param filp [in] the result of osal_klib_fopen
108  * @par Support System:
109  * linux liteos seliteos freertos.
110  */
111 int osal_klib_fseek(long long offset, int whence, void *filp);
112 
113 /**
114  * @ingroup osal_fileops
115  * @brief Removes a file or directory.
116  * @param path [in] the file path of file
117  * @attention If removing a directory, the directory must be empty.
118  *
119  * @return The value 0 indicates success, and other values indicate failure.
120  *
121  * @par Support System:
122  * seliteos.
123  */
124 int osal_klib_unlink(const char *path);
125 
126 /**
127  * @ingroup osal_fileops
128  * @brief Truncates the size of the file to the specified size.
129  * @param filp [in] the result of osal_klib_fopen
130  * @param len [in] the len of ftruncate
131  * @return The value 0 indicates success, and other values indicate failure.
132  *
133  * @par Support System:
134  * seliteos.
135  */
136 int osal_klib_ftruncate(void *filp, unsigned long len);
137 
138 #ifdef __cplusplus
139 #if __cplusplus
140 }
141 #endif
142 #endif
143 #endif /* __OSAL_FILEOPS_H__ */