• 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 
32 #ifndef _LFS_API_H_
33 #define _LFS_API_H_
34 
35 #include "fcntl.h"
36 #include "sys/stat.h"
37 
38 #include "dirent.h"
39 #include "errno.h"
40 #include "fs_operations.h"
41 #include "lfs.h"
42 #include "lfs_conf.h"
43 #include "lfs_util.h"
44 #include "memory.h"
45 
46 #define INVALID_FD (-1)
47 
48 #ifndef VFS_ERROR
49 #define VFS_ERROR (-1)
50 #endif
51 
52 #ifndef VFS_OK
53 #define VFS_OK  0
54 #endif
55 
56 typedef struct {
57     uint8_t useFlag;
58     const char *pathName;
59     lfs_t *lfsHandle;
60     lfs_file_t file;
61 } LittleFsHandleStruct;
62 
63 struct FileOpInfo {
64     uint8_t useFlag;
65     const struct FileOps *fsVops;
66     char *dirName;
67     lfs_t lfsInfo;
68 };
69 
70 typedef struct {
71     uint8_t useFlag;
72     char *dirName;
73     lfs_t *lfsHandle;
74     lfs_dir_t dir;
75 } FileDirInfo;
76 
77 LittleFsHandleStruct *GetFreeFd(int *fd);
78 
79 int LfsMount(const char *source, const char *target, const char *fileSystemType, unsigned long mountflags,
80     const void *data);
81 
82 int LfsUmount(const char *target);
83 int LfsUnlink(const char *fileName);
84 int LfsMkdir(const char *dirName, mode_t mode);
85 int LfsRmdir(const char *dirName);
86 DIR *LfsOpendir(const char *dirName);
87 struct dirent *LfsReaddir(DIR *dir);
88 int LfsClosedir(DIR *dir);
89 int LfsOpen(const char *pathName, int openFlag, ...);
90 int LfsRead(int fd, void *buf, unsigned int len);
91 int LfsWrite(int fd, const void *buf, unsigned int len);
92 off_t LfsSeek(int fd, off_t offset, int whence);
93 int LfsClose(int fd);
94 int LfsRename(const char *oldName, const char *newName);
95 int LfsStat(const char *path, struct stat *buf);
96 int LfsFsync(int fd);
97 int LfsFstat(int fd, struct stat *buf);
98 int SetDefaultMountPath(int pathNameIndex, const char* target);
99 int LfsPread(int fd, void *buf, size_t nbyte, off_t offset);
100 int LfsPwrite(int fd, const void *buf, size_t nbyte, off_t offset);
101 
102 #endif /* _LFS_API_H_ */
103 
104