• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define _GNU_SOURCE
32 
33 #include "los_config.h"
34 #include <errno.h>
35 #include <stdarg.h>
36 #include <dirent.h>
37 #include <sys/mount.h>
38 #include <sys/statfs.h>
39 #include <sys/stat.h>
40 #include <unistd.h>
41 
42 #ifdef LOSCFG_LIBC_MUSL_FS
43 #include "los_fs.h"
44 
mount(const char * source,const char * target,const char * filesystemtype,unsigned long mountflags,const void * data)45 int mount(const char *source, const char *target,
46           const char *filesystemtype, unsigned long mountflags,
47           const void *data)
48 {
49     return LOS_FsMount(source, target, filesystemtype, mountflags, data);
50 }
51 
umount(const char * target)52 int umount(const char *target)
53 {
54     return LOS_FsUmount(target);
55 }
56 
umount2(const char * target,int flag)57 int umount2(const char *target, int flag)
58 {
59     return LOS_FsUmount2(target, flag);
60 }
61 
open(const char * path,int oflag,...)62 int open(const char *path, int oflag, ...)
63 {
64     va_list vaList;
65     va_start(vaList, oflag);
66     int ret;
67     ret = LOS_Open(path, oflag, vaList);
68     va_end(vaList);
69     return ret;
70 }
71 
close(int fd)72 int close(int fd)
73 {
74     return LOS_Close(fd);
75 }
76 
read(int fd,void * buf,size_t nbyte)77 ssize_t read(int fd, void *buf, size_t nbyte)
78 {
79     return LOS_Read(fd, buf, nbyte);
80 }
81 
write(int fd,const void * buf,size_t nbyte)82 ssize_t write(int fd, const void *buf, size_t nbyte)
83 {
84     return LOS_Write(fd, buf, nbyte);
85 }
86 
lseek(int fd,off_t offset,int whence)87 off_t lseek(int fd, off_t offset, int whence)
88 {
89     return LOS_Lseek(fd, offset, whence);
90 }
91 
unlink(const char * path)92 int unlink(const char *path)
93 {
94     return LOS_Unlink(path);
95 }
96 
fstat(int fd,struct stat * buf)97 int fstat(int fd, struct stat *buf)
98 {
99     return LOS_Fstat(fd, buf);
100 }
101 
stat(const char * path,struct stat * buf)102 int stat(const char *path, struct stat *buf)
103 {
104     return LOS_Stat(path, buf);
105 }
106 
fsync(int fd)107 int fsync(int fd)
108 {
109     return LOS_Fsync(fd);
110 }
111 
mkdir(const char * path,mode_t mode)112 int mkdir(const char *path, mode_t mode)
113 {
114     return LOS_Mkdir(path, mode);
115 }
116 
opendir(const char * dirName)117 DIR *opendir(const char *dirName)
118 {
119     return LOS_Opendir(dirName);
120 }
121 
readdir(DIR * dir)122 struct dirent *readdir(DIR *dir)
123 {
124     return LOS_Readdir(dir);
125 }
126 
closedir(DIR * dir)127 int closedir(DIR *dir)
128 {
129     return LOS_Closedir(dir);
130 }
131 
rmdir(const char * path)132 int rmdir(const char *path)
133 {
134     return LOS_Unlink(path);
135 }
136 
rename(const char * oldName,const char * newName)137 int rename(const char *oldName, const char *newName)
138 {
139     return LOS_Rename(oldName, newName);
140 }
141 
statfs(const char * path,struct statfs * buf)142 int statfs(const char *path, struct statfs *buf)
143 {
144     return LOS_Statfs(path, buf);
145 }
146 
ftruncate(int fd,off_t length)147 int ftruncate(int fd, off_t length)
148 {
149     return LOS_Ftruncate(fd, length);
150 }
151 
pread(int fd,void * buf,size_t nbyte,off_t offset)152 ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset)
153 {
154     return LOS_Pread(fd, buf, nbyte, offset);
155 }
156 
pwrite(int fd,const void * buf,size_t nbyte,off_t offset)157 ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
158 {
159     return LOS_Pwrite(fd, buf, nbyte, offset);
160 }
161 
access(const char * path,int mode)162 int access(const char *path, int mode)
163 {
164     struct stat st;
165 
166     if (stat(path, &st) < 0) {
167         return -1;
168     }
169     if ((st.st_mode & S_IFDIR) || (st.st_mode & S_IFREG)) {
170         return 0;
171     }
172     if ((mode & W_OK) && !(st.st_mode & S_IWRITE)) {
173         return -1;
174     }
175 
176     return 0;
177 }
178 
fcntl(int fd,int cmd,...)179 int fcntl(int fd, int cmd, ...)
180 {
181     int ret;
182     va_list vaList;
183 
184     va_start(vaList, cmd);
185     ret = OsFcntl(fd, cmd, vaList);
186     va_end(vaList);
187     return ret;
188 }
189 
ioctl(int fd,int req,...)190 int ioctl(int fd, int req, ...)
191 {
192     int ret;
193     va_list vaList;
194 
195     va_start(vaList, req);
196     ret = OsIoctl(fd, req, vaList);
197     va_end(vaList);
198     return ret;
199 }
200 
201 #else /* #ifdef LOSCFG_FS_VFS */
202 
mount(const char * source,const char * target,const char * filesystemtype,unsigned long mountflags,const void * data)203 int mount(const char *source, const char *target,
204           const char *filesystemtype, unsigned long mountflags,
205           const void *data)
206 {
207     return -1;
208 }
209 
umount(const char * target)210 int umount(const char *target)
211 {
212     return -1;
213 }
214 
umount2(const char * target,int flag)215 int umount2(const char *target, int flag)
216 {
217     return -1;
218 }
219 
open(const char * path,int oflag,...)220 int open(const char *path, int oflag, ...)
221 {
222     return -1;
223 }
224 
close(int fd)225 int close(int fd)
226 {
227     return -1;
228 }
229 
read(int fd,void * buf,size_t nbyte)230 ssize_t read(int fd, void *buf, size_t nbyte)
231 {
232     return -1;
233 }
234 
write(int fd,const void * buf,size_t nbyte)235 ssize_t write(int fd, const void *buf, size_t nbyte)
236 {
237     return -1;
238 }
239 
lseek(int fd,off_t offset,int whence)240 off_t lseek(int fd, off_t offset, int whence)
241 {
242     return -1;
243 }
244 
unlink(const char * path)245 int unlink(const char *path)
246 {
247     return -1;
248 }
249 
fstat(int fd,struct stat * buf)250 int fstat(int fd, struct stat *buf)
251 {
252     return -1;
253 }
254 
stat(const char * path,struct stat * buf)255 int stat(const char *path, struct stat *buf)
256 {
257     return -1;
258 }
259 
fsync(int fd)260 int fsync(int fd)
261 {
262     return -1;
263 }
264 
mkdir(const char * path,mode_t mode)265 int mkdir(const char *path, mode_t mode)
266 {
267     return -1;
268 }
269 
opendir(const char * dirName)270 DIR *opendir(const char *dirName)
271 {
272     return NULL;
273 }
274 
readdir(DIR * dir)275 struct dirent *readdir(DIR *dir)
276 {
277     return NULL;
278 }
279 
closedir(DIR * dir)280 int closedir(DIR *dir)
281 {
282     return -1;
283 }
284 
rmdir(const char * path)285 int rmdir(const char *path)
286 {
287     return -1;
288 }
289 
rename(const char * oldName,const char * newName)290 int rename(const char *oldName, const char *newName)
291 {
292     return -1;
293 }
294 
statfs(const char * path,struct statfs * buf)295 int statfs(const char *path, struct statfs *buf)
296 {
297     return -1;
298 }
299 
ftruncate(int fd,off_t length)300 int ftruncate(int fd, off_t length)
301 {
302     return -1;
303 }
304 
pread(int fd,void * buf,size_t nbyte,off_t offset)305 ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset)
306 {
307     return -1;
308 }
309 
pwrite(int fd,const void * buf,size_t nbyte,off_t offset)310 ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
311 {
312     return -1;
313 }
314 
access(const char * path,int mode)315 int access(const char *path, int mode)
316 {
317     return -1;
318 }
319 
fcntl(int fd,int cmd,...)320 int fcntl(int fd, int cmd, ...)
321 {
322     return -1;
323 }
324 
ioctl(int fd,int req,...)325 int ioctl(int fd, int req, ...)
326 {
327     return -1;
328 }
329 #endif
330